@baique/pi-web-sky 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -0
- package/.next/app-path-routes-manifest.json +48 -0
- package/.next/build-manifest.json +20 -0
- package/.next/diagnostics/build-diagnostics.json +6 -0
- package/.next/diagnostics/framework.json +1 -0
- package/.next/export-marker.json +6 -0
- package/.next/images-manifest.json +68 -0
- package/.next/next-minimal-server.js.nft.json +1 -0
- package/.next/next-server.js.nft.json +1 -0
- package/.next/package.json +1 -0
- package/.next/prerender-manifest.json +161 -0
- package/.next/react-loadable-manifest.json +2367 -0
- package/.next/required-server-files.js +369 -0
- package/.next/required-server-files.json +369 -0
- package/.next/routes-manifest.json +386 -0
- package/.next/server/app/_global-error/page.js +31 -0
- package/.next/server/app/_global-error/page.js.nft.json +1 -0
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -0
- package/.next/server/app/_global-error.html +1 -0
- package/.next/server/app/_global-error.meta +27 -0
- package/.next/server/app/_global-error.rsc +14 -0
- package/.next/server/app/_global-error.segments/_full.segment.rsc +14 -0
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +20 -0
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -0
- package/.next/server/app/_not-found/page.js +1 -0
- package/.next/server/app/_not-found/page.js.nft.json +1 -0
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
- package/.next/server/app/_not-found.html +1 -0
- package/.next/server/app/_not-found.meta +27 -0
- package/.next/server/app/_not-found.rsc +20 -0
- package/.next/server/app/_not-found.segments/_full.segment.rsc +20 -0
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +24 -0
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +5 -0
- package/.next/server/app/api/agent/[id]/bash-output/route.js +1 -0
- package/.next/server/app/api/agent/[id]/bash-output/route.js.nft.json +1 -0
- package/.next/server/app/api/agent/[id]/bash-output/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/agent/[id]/events/route.js +3 -0
- package/.next/server/app/api/agent/[id]/events/route.js.nft.json +1 -0
- package/.next/server/app/api/agent/[id]/events/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/agent/[id]/route.js +1 -0
- package/.next/server/app/api/agent/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/agent/[id]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/agent/new/route.js +1 -0
- package/.next/server/app/api/agent/new/route.js.nft.json +1 -0
- package/.next/server/app/api/agent/new/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/agent/running/events/route.js +3 -0
- package/.next/server/app/api/agent/running/events/route.js.nft.json +1 -0
- package/.next/server/app/api/agent/running/events/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/agent/running/route.js +1 -0
- package/.next/server/app/api/agent/running/route.js.nft.json +1 -0
- package/.next/server/app/api/agent/running/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/app-update/route.js +1 -0
- package/.next/server/app/api/app-update/route.js.nft.json +1 -0
- package/.next/server/app/api/app-update/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/all-providers/route.js +1 -0
- package/.next/server/app/api/auth/all-providers/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/all-providers/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -0
- package/.next/server/app/api/auth/api-key/[provider]/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/api-key/[provider]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/login/[provider]/route.js +3 -0
- package/.next/server/app/api/auth/login/[provider]/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/login/[provider]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/logout/[provider]/route.js +1 -0
- package/.next/server/app/api/auth/logout/[provider]/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/logout/[provider]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/providers/route.js +1 -0
- package/.next/server/app/api/auth/providers/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/providers/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/cwd/browse/route.js +1 -0
- package/.next/server/app/api/cwd/browse/route.js.nft.json +1 -0
- package/.next/server/app/api/cwd/browse/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/cwd/validate/route.js +1 -0
- package/.next/server/app/api/cwd/validate/route.js.nft.json +1 -0
- package/.next/server/app/api/cwd/validate/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/default-cwd/route.js +1 -0
- package/.next/server/app/api/default-cwd/route.js.nft.json +1 -0
- package/.next/server/app/api/default-cwd/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/file-index/route.js +1 -0
- package/.next/server/app/api/file-index/route.js.nft.json +1 -0
- package/.next/server/app/api/file-index/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/files/[...path]/route.js +49 -0
- package/.next/server/app/api/files/[...path]/route.js.nft.json +1 -0
- package/.next/server/app/api/files/[...path]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/git/diff/route.js +6 -0
- package/.next/server/app/api/git/diff/route.js.nft.json +1 -0
- package/.next/server/app/api/git/diff/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/git/status/route.js +6 -0
- package/.next/server/app/api/git/status/route.js.nft.json +1 -0
- package/.next/server/app/api/git/status/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/home/route.js +1 -0
- package/.next/server/app/api/home/route.js.nft.json +1 -0
- package/.next/server/app/api/home/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models/route.js +1 -0
- package/.next/server/app/api/models/route.js.nft.json +1 -0
- package/.next/server/app/api/models/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models-config/catalog/route.js +1 -0
- package/.next/server/app/api/models-config/catalog/route.js.nft.json +1 -0
- package/.next/server/app/api/models-config/catalog/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models-config/discover/route.js +1 -0
- package/.next/server/app/api/models-config/discover/route.js.nft.json +1 -0
- package/.next/server/app/api/models-config/discover/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models-config/route.js +1 -0
- package/.next/server/app/api/models-config/route.js.nft.json +1 -0
- package/.next/server/app/api/models-config/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models-config/test/route.js +1 -0
- package/.next/server/app/api/models-config/test/route.js.nft.json +1 -0
- package/.next/server/app/api/models-config/test/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/plugins/route.js +1 -0
- package/.next/server/app/api/plugins/route.js.nft.json +1 -0
- package/.next/server/app/api/plugins/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/project-trust/route.js +1 -0
- package/.next/server/app/api/project-trust/route.js.nft.json +1 -0
- package/.next/server/app/api/project-trust/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/auto-name/route.js +10 -0
- package/.next/server/app/api/sessions/[id]/auto-name/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/auto-name/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/context/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/context/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/context/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/export/route.js +54 -0
- package/.next/server/app/api/sessions/[id]/export/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/export/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/state/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/state/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/state/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/todos/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/todos/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/todos/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/route.js +1 -0
- package/.next/server/app/api/sessions/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/skills/check/route.js +1 -0
- package/.next/server/app/api/skills/check/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/check/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/skills/install/route.js +1 -0
- package/.next/server/app/api/skills/install/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/install/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/skills/route.js +6 -0
- package/.next/server/app/api/skills/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/skills/search/route.js +1 -0
- package/.next/server/app/api/skills/search/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/search/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/skills/update/route.js +1 -0
- package/.next/server/app/api/skills/update/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/update/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/worktrees/route.js +1 -0
- package/.next/server/app/api/worktrees/route.js.nft.json +1 -0
- package/.next/server/app/api/worktrees/route_client-reference-manifest.js +1 -0
- package/.next/server/app/favicon.ico/route.js +1 -0
- package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
- package/.next/server/app/favicon.ico.body +0 -0
- package/.next/server/app/favicon.ico.meta +1 -0
- package/.next/server/app/index.html +1 -0
- package/.next/server/app/index.meta +21 -0
- package/.next/server/app/index.rsc +21 -0
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +24 -0
- package/.next/server/app/index.segments/_full.segment.rsc +21 -0
- package/.next/server/app/index.segments/_tree.segment.rsc +6 -0
- package/.next/server/app/manifest.webmanifest/route.js +17 -0
- package/.next/server/app/manifest.webmanifest/route.js.nft.json +1 -0
- package/.next/server/app/manifest.webmanifest/route_client-reference-manifest.js +1 -0
- package/.next/server/app/manifest.webmanifest.body +1 -0
- package/.next/server/app/manifest.webmanifest.meta +1 -0
- package/.next/server/app/page.js +93 -0
- package/.next/server/app/page.js.nft.json +1 -0
- package/.next/server/app/page_client-reference-manifest.js +1 -0
- package/.next/server/app-paths-manifest.json +48 -0
- package/.next/server/chunks/1094.js +160 -0
- package/.next/server/chunks/1515.js +1 -0
- package/.next/server/chunks/1555.js +1 -0
- package/.next/server/chunks/1601.js +24 -0
- package/.next/server/chunks/1625.js +1 -0
- package/.next/server/chunks/1800.js +1 -0
- package/.next/server/chunks/1813.js +1 -0
- package/.next/server/chunks/1860.js +1 -0
- package/.next/server/chunks/2075.js +23 -0
- package/.next/server/chunks/2106.js +1 -0
- package/.next/server/chunks/2169.js +36 -0
- package/.next/server/chunks/2190.js +1 -0
- package/.next/server/chunks/2325.js +82 -0
- package/.next/server/chunks/2349.js +1 -0
- package/.next/server/chunks/2408.js +1 -0
- package/.next/server/chunks/2430.js +193 -0
- package/.next/server/chunks/2452.js +93 -0
- package/.next/server/chunks/2744.js +1 -0
- package/.next/server/chunks/2903.js +1 -0
- package/.next/server/chunks/295.js +1 -0
- package/.next/server/chunks/3012.js +1 -0
- package/.next/server/chunks/3186.js +86 -0
- package/.next/server/chunks/3379.js +1 -0
- package/.next/server/chunks/3383.js +27 -0
- package/.next/server/chunks/3569.js +1 -0
- package/.next/server/chunks/3869.js +8 -0
- package/.next/server/chunks/3894.js +1 -0
- package/.next/server/chunks/4267.js +1 -0
- package/.next/server/chunks/4315.js +1 -0
- package/.next/server/chunks/4367.js +1 -0
- package/.next/server/chunks/4372.js +1 -0
- package/.next/server/chunks/4538.js +24 -0
- package/.next/server/chunks/4548.js +1 -0
- package/.next/server/chunks/4563.js +38 -0
- package/.next/server/chunks/4674.js +1 -0
- package/.next/server/chunks/4741.js +165 -0
- package/.next/server/chunks/4980.js +1 -0
- package/.next/server/chunks/5029.js +1 -0
- package/.next/server/chunks/5318.js +1 -0
- package/.next/server/chunks/5582.js +3 -0
- package/.next/server/chunks/5974.js +77 -0
- package/.next/server/chunks/6052.js +141 -0
- package/.next/server/chunks/611.js +1 -0
- package/.next/server/chunks/6253.js +104 -0
- package/.next/server/chunks/6337.js +1 -0
- package/.next/server/chunks/6366.js +80 -0
- package/.next/server/chunks/6429.js +1 -0
- package/.next/server/chunks/673.js +287 -0
- package/.next/server/chunks/6916.js +226 -0
- package/.next/server/chunks/703.js +1 -0
- package/.next/server/chunks/7233.js +1 -0
- package/.next/server/chunks/7265.js +215 -0
- package/.next/server/chunks/7307.js +1 -0
- package/.next/server/chunks/7561.js +1 -0
- package/.next/server/chunks/7710.js +1 -0
- package/.next/server/chunks/7744.js +64 -0
- package/.next/server/chunks/7790.js +1 -0
- package/.next/server/chunks/7799.js +34 -0
- package/.next/server/chunks/7872.js +1 -0
- package/.next/server/chunks/8106.js +1 -0
- package/.next/server/chunks/8294.js +1 -0
- package/.next/server/chunks/8333.js +79 -0
- package/.next/server/chunks/835.js +1 -0
- package/.next/server/chunks/8397.js +41 -0
- package/.next/server/chunks/8604.js +115 -0
- package/.next/server/chunks/8713.js +148 -0
- package/.next/server/chunks/8782.js +153 -0
- package/.next/server/chunks/8920.js +62 -0
- package/.next/server/chunks/922.js +5 -0
- package/.next/server/chunks/9280.js +255 -0
- package/.next/server/chunks/9486.js +1 -0
- package/.next/server/chunks/9509.js +1 -0
- package/.next/server/chunks/9510.js +90 -0
- package/.next/server/chunks/974.js +1 -0
- package/.next/server/functions-config-manifest.json +19 -0
- package/.next/server/instrumentation.js +1 -0
- package/.next/server/instrumentation.js.nft.json +1 -0
- package/.next/server/interception-route-rewrite-manifest.js +1 -0
- package/.next/server/middleware-build-manifest.js +1 -0
- package/.next/server/middleware-manifest.json +6 -0
- package/.next/server/middleware-react-loadable-manifest.js +1 -0
- package/.next/server/middleware.js +163 -0
- package/.next/server/middleware.js.nft.json +1 -0
- package/.next/server/next-font-manifest.js +1 -0
- package/.next/server/next-font-manifest.json +1 -0
- package/.next/server/pages/404.html +1 -0
- package/.next/server/pages/500.html +1 -0
- package/.next/server/pages-manifest.json +4 -0
- package/.next/server/prefetch-hints.json +39 -0
- package/.next/server/server-reference-manifest.js +1 -0
- package/.next/server/server-reference-manifest.json +1 -0
- package/.next/server/webpack-runtime.js +1 -0
- package/.next/static/chunks/103.23142a67b02246a8.js +215 -0
- package/.next/static/chunks/1032.12b382a9096ab2a4.js +1 -0
- package/.next/static/chunks/1063.775c442bdbeef08b.js +1 -0
- package/.next/static/chunks/1327.09252bb80616cc3a.js +1 -0
- package/.next/static/chunks/1708.d029f8776e4578de.js +1 -0
- package/.next/static/chunks/1781.866132cea8e77cd0.js +1 -0
- package/.next/static/chunks/1ba63609.b2ae90f43319a29e.js +153 -0
- package/.next/static/chunks/2081.47b6e9391094055f.js +1 -0
- package/.next/static/chunks/2181.ba21239d3ac39f81.js +1 -0
- package/.next/static/chunks/2258.4defa30121ef44a5.js +1 -0
- package/.next/static/chunks/2325.23caf22075e51aa5.js +1 -0
- package/.next/static/chunks/2356.523277bb8c6bf72a.js +23 -0
- package/.next/static/chunks/2418.b5d9e177e10a686e.js +1 -0
- package/.next/static/chunks/2480.cf27ca02e5b19761.js +24 -0
- package/.next/static/chunks/2539.c5a4f2fd8e421c70.js +41 -0
- package/.next/static/chunks/2619.9431a3f48da8eef4.js +1 -0
- package/.next/static/chunks/268.72794ee2773c2060.js +80 -0
- package/.next/static/chunks/2695.6f49435bae1e6f33.js +90 -0
- package/.next/static/chunks/2703.495a65ed14b2f094.js +36 -0
- package/.next/static/chunks/2821.934bcf60fbdc28c6.js +1 -0
- package/.next/static/chunks/3249-d891ccff87c62b6d.js +7 -0
- package/.next/static/chunks/3251.0dce7a0a0ff67235.js +1 -0
- package/.next/static/chunks/3308.be8762955e7155d1.js +73 -0
- package/.next/static/chunks/3336.a76f9485fe7cb762.js +1 -0
- package/.next/static/chunks/370.8e8f3cf8eb0e29dd.js +1 -0
- package/.next/static/chunks/3716.72bf4c9d7325debd.js +1 -0
- package/.next/static/chunks/3794-d29203733ca4633c.js +52 -0
- package/.next/static/chunks/398.ffa02af9062a3950.js +77 -0
- package/.next/static/chunks/3995.eca0f5bef1fc3ae5.js +38 -0
- package/.next/static/chunks/4004.74b9bcf5478b1663.js +160 -0
- package/.next/static/chunks/4202.8440832386f023c7.js +226 -0
- package/.next/static/chunks/4238.6f102dcbcf2ae339.js +141 -0
- package/.next/static/chunks/4405.7a19458960a1058e.js +287 -0
- package/.next/static/chunks/4424.fd0c93a807a333e1.js +1 -0
- package/.next/static/chunks/4866.d1060b4faf2ae1e2.js +1 -0
- package/.next/static/chunks/4970.8a63b4953b0e4946.js +1 -0
- package/.next/static/chunks/4bd1b696-8a4ab4fdf0ae305a.js +1 -0
- package/.next/static/chunks/5020.9ac8d0dc8390bb6e.js +1 -0
- package/.next/static/chunks/5137.f163e94c74a94d01.js +1 -0
- package/.next/static/chunks/5242.7b643c6b3394cac1.js +1 -0
- package/.next/static/chunks/5361.afc00ab2626bacbf.js +1 -0
- package/.next/static/chunks/5521.cfdf2cfc6db31407.js +1 -0
- package/.next/static/chunks/5526.ff46471041fdcb79.js +86 -0
- package/.next/static/chunks/5681.dd0e66b0de16e54b.js +27 -0
- package/.next/static/chunks/6121.eb9023b1cbc78ee2.js +1 -0
- package/.next/static/chunks/6161.4836cd7d031026bf.js +1 -0
- package/.next/static/chunks/6195.1153369f5f8b13a2.js +24 -0
- package/.next/static/chunks/6294.24f510c0c3e3714c.js +1 -0
- package/.next/static/chunks/6654.16f727522ec47f5a.js +1 -0
- package/.next/static/chunks/6794.f746d8fbbf248ecf.js +93 -0
- package/.next/static/chunks/7256.e07cf52d87d40252.js +1 -0
- package/.next/static/chunks/7268.236544be8e242c16.js +1 -0
- package/.next/static/chunks/7331.2add3c4e125a2dba.js +104 -0
- package/.next/static/chunks/7543.89f7b805ed0f2901.js +1 -0
- package/.next/static/chunks/8200.a36b9f8c983c6b9e.js +5 -0
- package/.next/static/chunks/869.7152372b662e31af.js +1 -0
- package/.next/static/chunks/8863.fa0320ea586efb3b.js +1 -0
- package/.next/static/chunks/8885.cf60cac98bf8b70c.js +79 -0
- package/.next/static/chunks/8901.e117d206a917bda0.js +1 -0
- package/.next/static/chunks/90542734.ae439f2382f58c51.js +1 -0
- package/.next/static/chunks/918.6a9bbe564e4a2d0f.js +115 -0
- package/.next/static/chunks/934.9006461bd0548660.js +1 -0
- package/.next/static/chunks/9522.c7c6e9c330f9ba6b.js +1 -0
- package/.next/static/chunks/9614.3221013d7f0af27f.js +64 -0
- package/.next/static/chunks/9698.4d09a99b9d99f3e5.js +148 -0
- package/.next/static/chunks/9705.40a82b97f214e28b.js +1 -0
- package/.next/static/chunks/973.88e865b52eff479a.js +8 -0
- package/.next/static/chunks/9764.2669775c6e107a01.js +62 -0
- package/.next/static/chunks/9793.4567af813117ad25.js +1 -0
- package/.next/static/chunks/993e5495.8797001fcfcf2889.js +62 -0
- package/.next/static/chunks/9974.9a0f79beca65e8c4.js +34 -0
- package/.next/static/chunks/app/_global-error/page-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/_not-found/page-af4fe23994cb3d66.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/bash-output/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/events/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/agent/new/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/agent/running/events/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/agent/running/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/app-update/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/auth/all-providers/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/auth/api-key/[provider]/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/auth/login/[provider]/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/auth/logout/[provider]/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/auth/providers/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/cwd/browse/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/cwd/validate/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/default-cwd/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/file-index/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/files/[...path]/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/git/diff/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/git/status/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/home/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/models/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/models-config/catalog/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/models-config/discover/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/models-config/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/models-config/test/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/plugins/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/project-trust/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/auto-name/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/context/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/entries/[entryId]/thinking/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/export/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/state/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/todos/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/sessions/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/skills/check/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/skills/install/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/skills/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/skills/search/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/skills/update/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/api/worktrees/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/layout-e13da2c32b9945e1.js +1 -0
- package/.next/static/chunks/app/manifest.webmanifest/route-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/app/page-b99ee1f741615942.js +87 -0
- package/.next/static/chunks/bf2ff291.3a109dffc1fe84af.js +122 -0
- package/.next/static/chunks/d3ac728e-7964f816a1ca64e5.js +1 -0
- package/.next/static/chunks/da12927c.476aa688a637649c.js +82 -0
- package/.next/static/chunks/db9d41be.e72ce090a86a3691.js +1 -0
- package/.next/static/chunks/framework-b33a8f5d57cd8d87.js +1 -0
- package/.next/static/chunks/main-430d592a1108ec6e.js +5 -0
- package/.next/static/chunks/main-app-b3e8a8d15d83e1f0.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/global-error-00a4badaccb388e6.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-13f6e99c6fd8ad23.js +1 -0
- package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/.next/static/chunks/webpack-84e477ecef987e5c.js +1 -0
- package/.next/static/css/4cbedad236d913cb.css +1 -0
- package/.next/static/css/4f1c05a951b42320.css +1 -0
- package/.next/static/css/88714c00e109ce28.css +1 -0
- package/.next/static/media/15605e25b523335c-s.woff2 +0 -0
- package/.next/static/media/1a3dce5cfb5f7760-s.woff2 +0 -0
- package/.next/static/media/1cdd02902f937a18-s.woff2 +0 -0
- package/.next/static/media/4c4b3b30b6bcb2be-s.woff2 +0 -0
- package/.next/static/media/641a7b8a5800ee0e-s.woff2 +0 -0
- package/.next/static/media/7deddc85b7ffd1dc-s.p.woff2 +0 -0
- package/.next/static/media/KaTeX_AMS-Regular.1608a09b.woff +0 -0
- package/.next/static/media/KaTeX_AMS-Regular.4aafdb68.ttf +0 -0
- package/.next/static/media/KaTeX_AMS-Regular.a79f1c31.woff2 +0 -0
- package/.next/static/media/KaTeX_Caligraphic-Bold.b6770918.woff +0 -0
- package/.next/static/media/KaTeX_Caligraphic-Bold.cce5b8ec.ttf +0 -0
- package/.next/static/media/KaTeX_Caligraphic-Bold.ec17d132.woff2 +0 -0
- package/.next/static/media/KaTeX_Caligraphic-Regular.07ef19e7.ttf +0 -0
- package/.next/static/media/KaTeX_Caligraphic-Regular.55fac258.woff2 +0 -0
- package/.next/static/media/KaTeX_Caligraphic-Regular.dad44a7f.woff +0 -0
- package/.next/static/media/KaTeX_Fraktur-Bold.9f256b85.woff +0 -0
- package/.next/static/media/KaTeX_Fraktur-Bold.b18f59e1.ttf +0 -0
- package/.next/static/media/KaTeX_Fraktur-Bold.d42a5579.woff2 +0 -0
- package/.next/static/media/KaTeX_Fraktur-Regular.7c187121.woff +0 -0
- package/.next/static/media/KaTeX_Fraktur-Regular.d3c882a6.woff2 +0 -0
- package/.next/static/media/KaTeX_Fraktur-Regular.ed38e79f.ttf +0 -0
- package/.next/static/media/KaTeX_Main-Bold.b74a1a8b.ttf +0 -0
- package/.next/static/media/KaTeX_Main-Bold.c3fb5ac2.woff2 +0 -0
- package/.next/static/media/KaTeX_Main-Bold.d181c465.woff +0 -0
- package/.next/static/media/KaTeX_Main-BoldItalic.6f2bb1df.woff2 +0 -0
- package/.next/static/media/KaTeX_Main-BoldItalic.70d8b0a5.ttf +0 -0
- package/.next/static/media/KaTeX_Main-BoldItalic.e3f82f9d.woff +0 -0
- package/.next/static/media/KaTeX_Main-Italic.47373d1e.ttf +0 -0
- package/.next/static/media/KaTeX_Main-Italic.8916142b.woff2 +0 -0
- package/.next/static/media/KaTeX_Main-Italic.9024d815.woff +0 -0
- package/.next/static/media/KaTeX_Main-Regular.0462f03b.woff2 +0 -0
- package/.next/static/media/KaTeX_Main-Regular.7f51fe03.woff +0 -0
- package/.next/static/media/KaTeX_Main-Regular.b7f8fe9b.ttf +0 -0
- package/.next/static/media/KaTeX_Math-BoldItalic.572d331f.woff2 +0 -0
- package/.next/static/media/KaTeX_Math-BoldItalic.a879cf83.ttf +0 -0
- package/.next/static/media/KaTeX_Math-BoldItalic.f1035d8d.woff +0 -0
- package/.next/static/media/KaTeX_Math-Italic.5295ba48.woff +0 -0
- package/.next/static/media/KaTeX_Math-Italic.939bc644.ttf +0 -0
- package/.next/static/media/KaTeX_Math-Italic.f28c23ac.woff2 +0 -0
- package/.next/static/media/KaTeX_SansSerif-Bold.8c5b5494.woff2 +0 -0
- package/.next/static/media/KaTeX_SansSerif-Bold.94e1e8dc.ttf +0 -0
- package/.next/static/media/KaTeX_SansSerif-Bold.bf59d231.woff +0 -0
- package/.next/static/media/KaTeX_SansSerif-Italic.3b1e59b3.woff2 +0 -0
- package/.next/static/media/KaTeX_SansSerif-Italic.7c9bc82b.woff +0 -0
- package/.next/static/media/KaTeX_SansSerif-Italic.b4c20c84.ttf +0 -0
- package/.next/static/media/KaTeX_SansSerif-Regular.74048478.woff +0 -0
- package/.next/static/media/KaTeX_SansSerif-Regular.ba21ed5f.woff2 +0 -0
- package/.next/static/media/KaTeX_SansSerif-Regular.d4d7ba48.ttf +0 -0
- package/.next/static/media/KaTeX_Script-Regular.03e9641d.woff2 +0 -0
- package/.next/static/media/KaTeX_Script-Regular.07505710.woff +0 -0
- package/.next/static/media/KaTeX_Script-Regular.fe9cbbe1.ttf +0 -0
- package/.next/static/media/KaTeX_Size1-Regular.e1e279cb.woff +0 -0
- package/.next/static/media/KaTeX_Size1-Regular.eae34984.woff2 +0 -0
- package/.next/static/media/KaTeX_Size1-Regular.fabc004a.ttf +0 -0
- package/.next/static/media/KaTeX_Size2-Regular.57727022.woff +0 -0
- package/.next/static/media/KaTeX_Size2-Regular.5916a24f.woff2 +0 -0
- package/.next/static/media/KaTeX_Size2-Regular.d6b476ec.ttf +0 -0
- package/.next/static/media/KaTeX_Size3-Regular.9acaf01c.woff +0 -0
- package/.next/static/media/KaTeX_Size3-Regular.a144ef58.ttf +0 -0
- package/.next/static/media/KaTeX_Size3-Regular.b4230e7e.woff2 +0 -0
- package/.next/static/media/KaTeX_Size4-Regular.10d95fd3.woff2 +0 -0
- package/.next/static/media/KaTeX_Size4-Regular.7a996c9d.woff +0 -0
- package/.next/static/media/KaTeX_Size4-Regular.fbccdabe.ttf +0 -0
- package/.next/static/media/KaTeX_Typewriter-Regular.6258592b.woff +0 -0
- package/.next/static/media/KaTeX_Typewriter-Regular.a8709e36.woff2 +0 -0
- package/.next/static/media/KaTeX_Typewriter-Regular.d97aaf4a.ttf +0 -0
- package/.next/static/media/ec14413c594b3356-s.p.woff2 +0 -0
- package/.next/static/zL8d0yAvyIXQ8s3Kyfvnp/_buildManifest.js +1 -0
- package/.next/static/zL8d0yAvyIXQ8s3Kyfvnp/_ssgManifest.js +1 -0
- package/.next/trace +42 -0
- package/.next/trace-build +1 -0
- package/.next/types/app/api/agent/[id]/bash-output/route.ts +353 -0
- package/.next/types/app/api/agent/[id]/events/route.ts +353 -0
- package/.next/types/app/api/agent/[id]/route.ts +353 -0
- package/.next/types/app/api/agent/new/route.ts +353 -0
- package/.next/types/app/api/agent/running/events/route.ts +353 -0
- package/.next/types/app/api/agent/running/route.ts +353 -0
- package/.next/types/app/api/app-update/route.ts +353 -0
- package/.next/types/app/api/auth/all-providers/route.ts +353 -0
- package/.next/types/app/api/auth/api-key/[provider]/route.ts +353 -0
- package/.next/types/app/api/auth/login/[provider]/route.ts +353 -0
- package/.next/types/app/api/auth/logout/[provider]/route.ts +353 -0
- package/.next/types/app/api/auth/providers/route.ts +353 -0
- package/.next/types/app/api/cwd/browse/route.ts +353 -0
- package/.next/types/app/api/cwd/validate/route.ts +353 -0
- package/.next/types/app/api/default-cwd/route.ts +353 -0
- package/.next/types/app/api/file-index/route.ts +353 -0
- package/.next/types/app/api/files/[...path]/route.ts +353 -0
- package/.next/types/app/api/git/diff/route.ts +353 -0
- package/.next/types/app/api/git/status/route.ts +353 -0
- package/.next/types/app/api/home/route.ts +353 -0
- package/.next/types/app/api/models/route.ts +353 -0
- package/.next/types/app/api/models-config/catalog/route.ts +353 -0
- package/.next/types/app/api/models-config/discover/route.ts +353 -0
- package/.next/types/app/api/models-config/route.ts +353 -0
- package/.next/types/app/api/models-config/test/route.ts +353 -0
- package/.next/types/app/api/plugins/route.ts +353 -0
- package/.next/types/app/api/project-trust/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/auto-name/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/context/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/entries/[entryId]/thinking/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/export/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/state/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/todos/route.ts +353 -0
- package/.next/types/app/api/sessions/route.ts +353 -0
- package/.next/types/app/api/skills/check/route.ts +353 -0
- package/.next/types/app/api/skills/install/route.ts +353 -0
- package/.next/types/app/api/skills/route.ts +353 -0
- package/.next/types/app/api/skills/search/route.ts +353 -0
- package/.next/types/app/api/skills/update/route.ts +353 -0
- package/.next/types/app/api/worktrees/route.ts +353 -0
- package/.next/types/app/layout.ts +89 -0
- package/.next/types/app/page.ts +89 -0
- package/.next/types/cache-life.d.ts +146 -0
- package/.next/types/package.json +1 -0
- package/.next/types/root-params.d.ts +3 -0
- package/.next/types/routes.d.ts +113 -0
- package/.next/types/validator.ts +439 -0
- package/LICENSE +25 -0
- package/README.ja.md +132 -0
- package/README.md +168 -0
- package/README.ru.md +132 -0
- package/README.zh-CN.md +137 -0
- package/bin/node-version.js +35 -0
- package/bin/pi-web-options.js +43 -0
- package/bin/pi-web-sky.js +115 -0
- package/bin/pi-web.js +115 -0
- package/bin/process-lifecycle.js +46 -0
- package/next.config.ts +56 -0
- package/package.json +83 -0
- package/public/icons/apple-touch-icon.png +0 -0
- package/public/icons/catppuccin/LICENSE +22 -0
- package/public/icons/catppuccin/README.md +10 -0
- package/public/icons/catppuccin/latte/_file.svg +3 -0
- package/public/icons/catppuccin/latte/_folder.svg +3 -0
- package/public/icons/catppuccin/latte/_folder_open.svg +3 -0
- package/public/icons/catppuccin/latte/bash.svg +7 -0
- package/public/icons/catppuccin/latte/bun-lock.svg +8 -0
- package/public/icons/catppuccin/latte/config.svg +3 -0
- package/public/icons/catppuccin/latte/css.svg +6 -0
- package/public/icons/catppuccin/latte/database.svg +3 -0
- package/public/icons/catppuccin/latte/docker.svg +3 -0
- package/public/icons/catppuccin/latte/env.svg +3 -0
- package/public/icons/catppuccin/latte/eslint.svg +6 -0
- package/public/icons/catppuccin/latte/git.svg +6 -0
- package/public/icons/catppuccin/latte/go.svg +3 -0
- package/public/icons/catppuccin/latte/graphql.svg +3 -0
- package/public/icons/catppuccin/latte/html.svg +6 -0
- package/public/icons/catppuccin/latte/javascript-react.svg +8 -0
- package/public/icons/catppuccin/latte/javascript.svg +6 -0
- package/public/icons/catppuccin/latte/json.svg +3 -0
- package/public/icons/catppuccin/latte/lock.svg +3 -0
- package/public/icons/catppuccin/latte/markdown.svg +3 -0
- package/public/icons/catppuccin/latte/ms-word.svg +6 -0
- package/public/icons/catppuccin/latte/next.svg +6 -0
- package/public/icons/catppuccin/latte/npm-lock.svg +7 -0
- package/public/icons/catppuccin/latte/pdf.svg +3 -0
- package/public/icons/catppuccin/latte/python.svg +8 -0
- package/public/icons/catppuccin/latte/rust.svg +6 -0
- package/public/icons/catppuccin/latte/sass.svg +3 -0
- package/public/icons/catppuccin/latte/terraform.svg +3 -0
- package/public/icons/catppuccin/latte/toml.svg +3 -0
- package/public/icons/catppuccin/latte/typescript-react.svg +8 -0
- package/public/icons/catppuccin/latte/typescript.svg +6 -0
- package/public/icons/catppuccin/latte/yaml.svg +3 -0
- package/public/icons/catppuccin/mocha/_file.svg +3 -0
- package/public/icons/catppuccin/mocha/_folder.svg +3 -0
- package/public/icons/catppuccin/mocha/_folder_open.svg +3 -0
- package/public/icons/catppuccin/mocha/bash.svg +7 -0
- package/public/icons/catppuccin/mocha/bun-lock.svg +8 -0
- package/public/icons/catppuccin/mocha/config.svg +3 -0
- package/public/icons/catppuccin/mocha/css.svg +6 -0
- package/public/icons/catppuccin/mocha/database.svg +3 -0
- package/public/icons/catppuccin/mocha/docker.svg +3 -0
- package/public/icons/catppuccin/mocha/env.svg +3 -0
- package/public/icons/catppuccin/mocha/eslint.svg +6 -0
- package/public/icons/catppuccin/mocha/git.svg +6 -0
- package/public/icons/catppuccin/mocha/go.svg +3 -0
- package/public/icons/catppuccin/mocha/graphql.svg +3 -0
- package/public/icons/catppuccin/mocha/html.svg +6 -0
- package/public/icons/catppuccin/mocha/javascript-react.svg +8 -0
- package/public/icons/catppuccin/mocha/javascript.svg +6 -0
- package/public/icons/catppuccin/mocha/json.svg +3 -0
- package/public/icons/catppuccin/mocha/lock.svg +3 -0
- package/public/icons/catppuccin/mocha/markdown.svg +3 -0
- package/public/icons/catppuccin/mocha/ms-word.svg +6 -0
- package/public/icons/catppuccin/mocha/next.svg +6 -0
- package/public/icons/catppuccin/mocha/npm-lock.svg +7 -0
- package/public/icons/catppuccin/mocha/pdf.svg +3 -0
- package/public/icons/catppuccin/mocha/python.svg +8 -0
- package/public/icons/catppuccin/mocha/rust.svg +6 -0
- package/public/icons/catppuccin/mocha/sass.svg +3 -0
- package/public/icons/catppuccin/mocha/terraform.svg +3 -0
- package/public/icons/catppuccin/mocha/toml.svg +3 -0
- package/public/icons/catppuccin/mocha/typescript-react.svg +8 -0
- package/public/icons/catppuccin/mocha/typescript.svg +6 -0
- package/public/icons/catppuccin/mocha/yaml.svg +3 -0
- package/public/icons/icon-192.png +0 -0
- package/public/icons/icon-512.png +0 -0
- package/public/offline.html +83 -0
- package/public/sw.js +118 -0
- package/public/sw.test.mjs +86 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{14755:(e,t,n)=>{"use strict";n.d(t,{getPresetFromTools:()=>c,sn:()=>d,xG:()=>u});let r=["none","read-only","default","full"],i=[],o=["read","grep","find","ls"],l=["read","bash","edit","write"],s=["bash","read","edit","write","grep","find","ls"],a=new Set(s);function d(e){return"string"==typeof e&&r.includes(e)}function c(e){let t=e.filter(e=>e.active);if(0===t.length)return"none";let n=t.map(e=>e.name).filter(e=>a.has(e)).sort().join(",");return n===[...o].sort().join(",")?"read-only":n===[...l].sort().join(",")?"default":n===[...s].sort().join(",")?"full":"default"}function u(e){return"none"===e?[...i]:"read-only"===e?[...o]:"full"===e?[...s]:[...l]}},27150:(e,t,n)=>{"use strict";n.d(t,{AppShell:()=>iY});var r=n(95155),i=n(12115),o=n(73321);let l=null,s="pi-web:file-explorer:open";function a(){try{return window.localStorage}catch{return null}}let d=/^<skill name="([^"\n]+)" location="([^"\n]+)">\nReferences are relative to [^\n]+\.\n\n([\s\S]*)\n<\/skill>(?:\n\n([\s\S]+))?$/;function c(e){let t=e.match(d);if(!t)return null;let[,n,,,r]=t;return r?`/skill:${n} ${r}`:`/skill:${n}`}let u="pi-web:last-open-by-workspace";function p(){try{return window.localStorage}catch{return null}}function h(e){let t=e.getItem(u);if(!t)return{};try{let e=JSON.parse(t);return null===e||"object"!=typeof e||Array.isArray(e)?{}:e}catch{return{}}}function g(e,t=p()){if(t)try{let n=h(t);if(!(e in n))return;delete n[e],0===Object.keys(n).length?t.removeItem(u):t.setItem(u,JSON.stringify(n))}catch{}}function x(e){return e.projectKey??e.projectRoot??e.cwd}function f(e){let t=new Map;for(let n of e){let e=n.projectRoot??n.cwd;if(!e)continue;let r=x(n),i=t.get(r);(!i||n.modified>i.modified)&&t.set(r,{root:e,modified:n.modified})}return[...t.entries()].sort((e,t)=>t[1].modified.localeCompare(e[1].modified)).map(([e,{root:t}])=>({key:e,root:t}))}var m=n(39247),v=n(47650);async function y(e){let t=e?`?path=${encodeURIComponent(e)}`:"",n=await fetch(`/api/cwd/browse${t}`),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);return r}function b(){return(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M1.5 3h4l1.5 2h7.5v7.5h-13z"})})}function k(){return(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.5"}),(0,r.jsx)("path",{d:"M2 9h12"}),(0,r.jsx)("circle",{cx:"11.5",cy:"11",r:"0.6",fill:"currentColor",stroke:"none"})]})}function w({onCancel:e,onSelect:t,busy:n=!1,error:o}){let{t:l}=(0,m.s)(),[s,a]=(0,i.useState)(null),[d,c]=(0,i.useState)(""),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(""),[x,f]=(0,i.useState)([]),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[R,M]=(0,i.useState)(!0),I=(0,i.useCallback)(async e=>{M(!0),T(null);try{let t=await y(e),n=t.path??e??"/";c(n),p(t.parentPath??null),g(n),f(t.directories??[]),S(t.drives??null)}catch(e){T(e instanceof Error?e.message:String(e))}finally{M(!1)}},[]);(0,i.useEffect)(()=>{a(document.body),I()},[I]);let L=h.trim()!==d,W=!!d&&!L&&!n,E=!!u||/^[a-zA-Z]:[\\/]?$/.test(d);return s?(0,v.createPortal)((0,r.jsx)("div",{className:"directory-picker-backdrop",role:"dialog","aria-modal":"true","aria-label":l("directoryPicker.selectDirectory"),onClick:t=>{t.target!==t.currentTarget||n||e()},onKeyDown:t=>{"Escape"!==t.key||n||e()},style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.35)"},children:(0,r.jsxs)("div",{className:"directory-picker-panel",style:{width:520,maxWidth:"calc(100vw - 16px)",height:"min(620px, calc(100dvh - 16px))",maxHeight:"calc(100dvh - 16px)",display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 8px 32px rgba(0,0,0,0.18)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0,padding:"12px 18px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{minWidth:0,flex:1},children:(0,r.jsx)("div",{style:{color:"var(--text)",fontWeight:700,fontSize:15},children:l("directoryPicker.selectDirectory")})}),(0,r.jsx)("button",{type:"button",onClick:e,disabled:n,title:l("i18n.close"),"aria-label":l("i18n.close"),style:{padding:"2px 6px",border:0,background:"none",color:"var(--text-muted)",fontSize:20,lineHeight:1,cursor:n?"default":"pointer",opacity:n?.5:1},children:"\xd7"})]}),(0,r.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=h.trim();t&&I(t)},style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,padding:"10px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("button",{className:"directory-picker-back",type:"button",onClick:()=>void I(u??void 0),disabled:R||!E,title:l("directoryPicker.goToParent"),"aria-label":l("directoryPicker.goToParent"),style:{width:36,height:36,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:E?"pointer":"default",opacity:E?1:.45},children:(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m18 15-6-6-6 6"})})}),(0,r.jsx)("label",{htmlFor:"directory-path",style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:l("directoryPicker.directoryPath")}),(0,r.jsx)("input",{className:"directory-picker-path",id:"directory-path",type:"text",value:h,placeholder:"/path/to/project or ~/project",autoFocus:!0,autoComplete:"off",spellCheck:!1,onChange:e=>{g(e.target.value),T(null)},style:{minWidth:0,flex:1,height:36,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,outline:"none",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12}}),(0,r.jsx)("button",{className:"directory-picker-action",type:"submit",disabled:R||!h.trim(),title:l("directoryPicker.goToDirectory"),style:{minWidth:58,height:36,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:R||!h.trim()?"default":"pointer",opacity:R||!h.trim()?.6:1},children:l("directoryPicker.go")})]}),(0,r.jsxs)("div",{className:"directory-picker-list",style:{flex:1,minHeight:0,overflow:"auto",padding:"8px 10px"},children:[R?(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:l("directoryPicker.loadingDirectories")}):null!==j?(0,r.jsx)(r.Fragment,{children:j.length>0?j.map(e=>(0,r.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void I(e.path),title:e.path,style:{width:"100%",minHeight:34,display:"flex",alignItems:"center",gap:7,padding:"6px 8px",border:0,borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)",fontSize:11},children:[(0,r.jsx)(k,{}),(0,r.jsx)("span",{children:e.name})]},e.path)):(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:l("directoryPicker.noDrives")})}):x.length>0?x.map(e=>(0,r.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void I(e.path),title:e.path,style:{width:"100%",minHeight:30,display:"flex",alignItems:"center",gap:7,padding:"5px 8px",border:0,borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)",fontSize:11},children:[(0,r.jsx)(b,{}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.path)):(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:l("directoryPicker.noSubdirectories")}),(C||o)&&(0,r.jsx)("div",{style:{padding:"8px",color:"#dc2626",fontSize:11},children:C??o})]}),(0,r.jsxs)("div",{className:"directory-picker-footer",style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:10,flexShrink:0,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,r.jsx)("button",{className:"directory-picker-action",type:"button",onClick:e,disabled:n,style:{padding:"6px 14px",border:"1px solid var(--border)",borderRadius:6,background:"none",color:"var(--text-muted)",cursor:n?"default":"pointer",fontSize:13},children:l("i18n.cancel")}),(0,r.jsx)("button",{className:"directory-picker-action",type:"button",onClick:()=>t(d),disabled:!W,title:l(L?"directoryPicker.openBeforeSelecting":"directoryPicker.selectCurrentDirectory"),style:{padding:"6px 16px",border:0,borderRadius:6,background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,opacity:W?1:.6,cursor:W?"pointer":"default"},children:l(n?"i18n.checking":"directoryPicker.selectThisFolder")})]})]})}),s):null}let j="/icons/catppuccin";function S({name:e,size:t=14}){let n={width:t,height:t,"--catppuccin-icon-light":`url(${j}/latte/${e}.svg)`,"--catppuccin-icon-dark":`url(${j}/mocha/${e}.svg)`};return(0,r.jsx)("span",{"aria-hidden":"true",className:"catppuccin-file-icon",style:n})}function C({size:e=14,open:t=!1}){return(0,r.jsx)(S,{name:t?"_folder_open":"_folder",size:e})}function T({size:e=14}){return(0,r.jsx)(S,{name:"_file",size:e})}let R={ts:"typescript",tsx:"typescript-react",js:"javascript",mjs:"javascript",cjs:"javascript",jsx:"javascript-react",py:"python",json:"json",jsonl:"json",css:"css",less:"css",scss:"sass",html:"html",htm:"html",md:"markdown",mdx:"markdown",yaml:"yaml",yml:"yaml",toml:"toml",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",rs:"rust",go:"go",sql:"database",graphql:"graphql",gql:"graphql",tf:"terraform",hcl:"terraform",docx:"ms-word",pdf:"pdf",lock:"lock"};function M(e,t=14){let n=e.toLowerCase(),i="dockerfile"===n||n.startsWith("dockerfile.")?"docker":".env"===n||n.startsWith(".env.")?"env":[".gitignore",".gitattributes",".gitmodules"].includes(n)?"git":"package-lock.json"===n?"npm-lock":"bun.lock"===n?"bun-lock":["next.config.js","next.config.mjs","next.config.cjs","next.config.ts"].includes(n)?"next":[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(n)?"eslint":["yarn.lock","pnpm-lock.yaml","cargo.lock"].includes(n)?"lock":n.endsWith(".config.ts")||n.endsWith(".config.js")||n.endsWith(".config.mjs")||n.endsWith(".config.cjs")?"config":void 0;if(i)return(0,r.jsx)(S,{name:i,size:t});let o=R[n.split(".").pop()??""];return o?(0,r.jsx)(S,{name:o,size:t}):(0,r.jsx)(T,{size:t})}function I(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function L(e){return I(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function W(e){let t=I(e).replace(/\/+$/,"");return t.split("/").pop()??t}function E(e){let t=I(e).replace(/\/+$/,""),n=t.lastIndexOf("/");return n<0?"":0===n?"/":2===n&&/^[a-zA-Z]:\//.test(t)?t.slice(0,3):t.slice(0,n)}function z(e,t){if(!t)return e;let n=I(e),r=I(t).replace(/\/$/,"");return n.startsWith(r+"/")?n.slice(r.length+1):e}function $(e,t){return`${I(e).replace(/\/$/,"")}/${t}`}async function P(e){let t=L(e),n=await fetch(`/api/files/${t}?type=list`);if(!n.ok){let e=`Failed to load files (HTTP ${n.status})`;try{let t=await n.json();t.error&&(e=t.error)}catch{}throw Error(e)}return((await n.json()).entries??[]).map(t=>({name:t.name,fullPath:$(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function F(e){let t=new URLSearchParams({cwd:e}),n=await fetch(`/api/git/status?${t.toString()}`);if(!n.ok)throw Error(`Failed to load Git status (HTTP ${n.status})`);return n.json()}let N={modified:"files.modified",added:"files.added",deleted:"files.deleted",renamed:"files.renamed",untracked:"files.untracked",conflict:"files.conflict"},A={modified:"#d6a84b",added:"#4ade80",deleted:"#f87171",renamed:"#60a5fa",untracked:"#4ade80",conflict:"#f87171"};function D({status:e,t}){return(0,r.jsx)("span",{title:t(N[e.status]),"aria-label":t(N[e.status]),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",color:A[e.status],fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600},children:e.code})}function B({size:e=11}){return(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function H({onClick:e,title:t}){return(0,r.jsx)("button",{type:"button",onClick:e,title:t,"aria-label":t,style:{width:24,height:24,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"none",borderRadius:4,background:"none",color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"m6 6 12 12"}),(0,r.jsx)("path",{d:"m18 6-12 12"})]})})}function O({node:e,depth:t,cwd:n,onOpenFile:o,onAtMention:l,expandedPaths:s,onToggleExpanded:a,refreshToken:d,highlightedPaths:c,gitStatusByPath:u,changedDirectoryPaths:p,t:h}){let g=s.has(e.fullPath),x=c.has(e.fullPath),f=I(e.fullPath),m=u.get(f),v=e.isDir&&(void 0!==m||p.has(f)),[y,b]=(0,i.useState)(e.children??[]),[k,w]=(0,i.useState)(e.loaded??!1),[j,S]=(0,i.useState)(!1),[T,R]=(0,i.useState)(!1),W=(0,i.useCallback)(async(t=!1)=>{if(!k||t){S(!0);try{let t=await P(e.fullPath);b(t),w(!0)}catch{}finally{S(!1)}}},[k,e.fullPath]);(0,i.useEffect)(()=>{g&&k&&W(!0)},[d]);let E=(0,i.useCallback)(()=>{if(e.isDir){let t=!g;a(e.fullPath,t),t&&!k&&W()}else o(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,k,g,W,o,a]);return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{onClick:E,onMouseEnter:()=>R(!0),onMouseLeave:()=>R(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:T?"var(--bg-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[e.isDir&&(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:g?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,r.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,r.jsx)(C,{size:14,open:g}):M(e.name,14)}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),x&&(0,r.jsx)("span",{title:h("files.newlyUploaded"),"aria-label":h("files.newlyUploaded"),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"#3b82f6"}})}),!T&&!e.isDir&&m&&(0,r.jsx)(D,{status:m,t:h}),!T&&v&&(0,r.jsx)("span",{title:h("files.containsChangedFiles"),"aria-label":h("files.containsChangedFiles"),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"#d6a84b"}})}),j&&(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,r.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),l&&T&&(0,r.jsxs)("button",{onClick:t=>{t.stopPropagation(),l(z(e.fullPath,n),e.isDir)},title:h("files.insertPath"),style:{position:"absolute",right:e.isDir?4:28,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)(B,{}),h("files.mention")]}),T&&!e.isDir&&(0,r.jsx)("a",{href:`/api/files/${L(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:h("files.download"),style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 5px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap",textDecoration:"none"},children:(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),e.isDir&&g&&(0,r.jsxs)("div",{children:[y.map(e=>(0,r.jsx)(O,{node:e,depth:t+1,cwd:n,onOpenFile:o,onAtMention:l,expandedPaths:s,onToggleExpanded:a,refreshToken:d,highlightedPaths:c,gitStatusByPath:u,changedDirectoryPaths:p,t:h},e.fullPath)),0===y.length&&k&&(0,r.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function U({status:e,cwd:t,onOpenFile:n,t:o}){let[l,s]=(0,i.useState)(!1),a=W(e.filePath),d=z(e.filePath,t);return(0,r.jsxs)("div",{onClick:()=>n(e.filePath,a,{modeHint:"diff"}),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),title:e.filePath,style:{display:"flex",alignItems:"center",gap:6,paddingLeft:10,paddingRight:8,height:24,cursor:"pointer",background:l?"var(--bg-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[(0,r.jsx)(D,{status:e,t:o}),(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center",opacity:.85},children:M(a,13)}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:d})]})}let _=(0,i.forwardRef)(function({cwd:e,onOpenFile:t,refreshKey:n,onAtMention:o,onAtMentions:l,onUploadBusyChange:s,changesCollapsed:a,onChangesCountChange:d},c){let{t:u}=(0,m.s)(),[p,h]=(0,i.useState)([]),[g,x]=(0,i.useState)(!0),[f,v]=(0,i.useState)(null),[y,b]=(0,i.useState)(new Set),[k,w]=(0,i.useState)(0),[j,S]=(0,i.useState)(new Set),[C,T]=(0,i.useState)([]),[R,M]=(0,i.useState)({additions:0,deletions:0}),[W,N]=(0,i.useState)("idle"),[D,_]=(0,i.useState)(0),[q,K]=(0,i.useState)(null),[V,Y]=(0,i.useState)(null),[J,Z]=(0,i.useState)(null),G=(0,i.useRef)(null),X=(0,i.useRef)(null),Q=`${n??0}:${k}`,ee="idle"!==W,et=(0,i.useMemo)(()=>new Map(C.map(e=>[I(e.filePath),e])),[C]),en=(0,i.useMemo)(()=>{let t=new Set,n=I(e).replace(/\/$/,"");for(let e of C){let r=E(I(e.filePath));for(;(r===n||r.startsWith(`${n}/`))&&(t.add(r),r!==n);){let e=E(r);if(e===r)break;r=e}}return t},[e,C]),er=(0,i.useCallback)((e,t)=>{b(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),ei=(0,i.useCallback)(t=>{let n=t.uploaded??[];Y({uploaded:n,skipped:t.skipped??[],errors:t.errors??[]}),n.length>0&&(S(new Set(n.map(t=>$(e,t)))),w(e=>e+1))},[e]),eo=(0,i.useCallback)(async(t,n)=>{Z(null),K(null),_(0),N("uploading");try{let{status:r,data:i}=await new Promise((r,i)=>{let o=new FormData;t.forEach(e=>o.append("files",e,e.name));let l=new XMLHttpRequest;l.open("POST",`/api/files/${L(e)}?type=upload&conflict=${n}`),l.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&_(Math.round(e.loaded/e.total*100))},l.onerror=()=>i(Error("Network error while uploading files")),l.onabort=()=>i(Error("Upload cancelled")),l.onload=()=>{let e={};try{e=JSON.parse(l.responseText)}catch{l.responseText&&(e.error=l.responseText)}r({status:l.status,data:e})},l.send(o)});if(409===r&&i.conflicts?.length)return void Z({files:t,conflicts:i.conflicts,nonReplaceable:i.nonReplaceable??[]});if(r<200||r>=300)throw Error(i.error??`Upload failed (HTTP ${r})`);_(100),ei(i)}catch(e){K(e instanceof Error?e.message:String(e))}finally{N("idle")}},[ei,e]),el=(0,i.useCallback)(async t=>{if(0!==t.length&&!ee){Y(null),S(new Set),Z(null),K(null),_(0),N("checking");try{let n=await fetch(`/api/files/${L(e)}?type=upload-check`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileNames:t.map(e=>e.name)})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error??`Upload check failed (HTTP ${n.status})`);if(r.conflicts?.length)return void Z({files:t,conflicts:r.conflicts,nonReplaceable:r.nonReplaceable??[]});await eo(t,"error")}catch(e){K(e instanceof Error?e.message:String(e))}finally{N("idle")}}},[e,eo,ee]),es=(0,i.useCallback)(e=>{let t=Array.from(e.target.files??[]);e.target.value="",el(t)},[el]);(0,i.useImperativeHandle)(c,()=>({openUploadPicker(){ee||X.current?.click()}}),[ee]),(0,i.useEffect)(()=>{s?.(ee)},[s,ee]),(0,i.useEffect)(()=>()=>s?.(!1),[s]),(0,i.useEffect)(()=>{let t=G.current!==e;G.current=e,t&&(b(new Set),S(new Set),Y(null),Z(null),K(null)),x(t),v(null);let n=!1;return P(e).then(e=>{n||h(e)}).catch(e=>{n||v(e instanceof Error?e.message:String(e))}).finally(()=>{n||x(!1)}),()=>{n=!0}},[e,n,k]),(0,i.useEffect)(()=>{let t=!1;return F(e).then(e=>{t||(T(e.isGitRepository?e.files:[]),M(e.isGitRepository?{additions:e.additions,deletions:e.deletions}:{additions:0,deletions:0}))}).catch(()=>{t||(T([]),M({additions:0,deletions:0}))}),()=>{t=!0}},[e,n,k]),(0,i.useEffect)(()=>{d?.(C.length)},[C,d]);let ea=ee||null!==J||null!==q||null!==V,ed=(0,i.useCallback)(()=>{V&&0!==V.uploaded.length&&l?.(V.uploaded.map(t=>z($(e,t),e)))},[e,l,V]);return(0,r.jsxs)("div",{style:{minHeight:"100%"},children:[(0,r.jsx)("input",{ref:X,type:"file",multiple:!0,hidden:!0,onChange:es}),ea&&(0,r.jsxs)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:[ee&&(0,r.jsxs)("div",{role:"status","aria-live":"polite","aria-label":"checking"===W?u("files.checking"):u("files.uploading",{progress:D}),children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,minHeight:14,color:"var(--text-muted)"},children:["checking"===W?(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-5.7-8.4"})}):(0,r.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:[(0,r.jsx)("path",{d:"M12 16V4"}),(0,r.jsx)("path",{d:"m7 9 5-5 5 5"}),(0,r.jsx)("path",{d:"M5 20h14"})]}),"uploading"===W&&(0,r.jsxs)("span",{style:{fontSize:10},children:[D,"%"]})]}),"uploading"===W&&(0,r.jsx)("div",{style:{height:3,marginTop:4,overflow:"hidden",borderRadius:2,background:"var(--border)"},children:(0,r.jsx)("div",{style:{width:`${D}%`,height:"100%",background:"var(--text-muted)",transition:"width 120ms ease"}})})]}),J&&(0,r.jsxs)("div",{role:"alert",style:{padding:7,border:"1px solid color-mix(in srgb, #f59e0b 55%, var(--border))",borderRadius:4,background:"color-mix(in srgb, #f59e0b 9%, var(--bg-panel))"},children:[(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:1.35,overflowWrap:"anywhere"},children:u("files.conflictSummary",{count:J.conflicts.length,countSuffix:1===J.conflicts.length?"":"s",files:J.conflicts.join(", ")})}),J.nonReplaceable.length>0&&(0,r.jsx)("div",{style:{marginTop:3,fontSize:10,color:"#f59e0b",lineHeight:1.35,overflowWrap:"anywhere"},children:u("files.cannotReplace",{files:J.nonReplaceable.join(", ")})}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:7},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void eo(J.files,"overwrite"),style:{height:22,padding:"0 7px",border:"1px solid #ef4444",borderRadius:4,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:10},children:u("files.replace")}),(0,r.jsx)("button",{type:"button",onClick:()=>void eo(J.files,"skip"),style:{height:22,padding:"0 7px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",fontSize:10},children:u("files.skipExisting")}),(0,r.jsx)("button",{type:"button",onClick:()=>Z(null),style:{height:22,padding:"0 7px",border:"none",borderRadius:4,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:10},children:u("files.cancel")})]})]}),q&&(0,r.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:11,lineHeight:1.35,color:"#f87171"},children:[(0,r.jsx)("span",{style:{minWidth:0,flex:1,overflowWrap:"anywhere"},children:q}),(0,r.jsx)(H,{onClick:()=>K(null),title:u("files.dismissError")})]}),V&&(0,r.jsxs)("div",{"aria-live":"polite",children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minHeight:22,fontSize:11},children:[(0,r.jsxs)("div",{style:{minWidth:0,flex:1,display:"flex",alignItems:"center",gap:8},children:[V.uploaded.length>0&&(0,r.jsxs)("span",{title:`${V.uploaded.length} uploaded`,"aria-label":`${V.uploaded.length} uploaded`,style:{display:"flex",alignItems:"center",gap:3,color:"#22c55e"},children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m5 12 4 4L19 6"})}),(0,r.jsx)("span",{children:V.uploaded.length})]}),V.skipped.length>0&&(0,r.jsxs)("span",{title:`${V.skipped.length} skipped`,"aria-label":`${V.skipped.length} skipped`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--text-dim)"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"M8 12h8"})]}),(0,r.jsx)("span",{children:V.skipped.length})]}),V.errors.length>0&&(0,r.jsxs)("span",{title:`${V.errors.length} failed`,"aria-label":`${V.errors.length} failed`,style:{display:"flex",alignItems:"center",gap:3,color:"#f87171"},children:[(0,r.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:[(0,r.jsx)("path",{d:"M12 3 2.5 20h19L12 3Z"}),(0,r.jsx)("path",{d:"M12 9v4"}),(0,r.jsx)("path",{d:"M12 17h.01"})]}),(0,r.jsx)("span",{children:V.errors.length})]})]}),V.uploaded.length>0&&l&&(0,r.jsxs)("button",{type:"button",onClick:ed,title:1===V.uploaded.length?u("files.addUploadedFile"):u("files.addAllUploadedFiles"),"aria-label":1===V.uploaded.length?u("files.addUploadedFile"):u("files.addAllUploadedFiles"),style:{height:22,padding:"0 7px",display:"flex",alignItems:"center",justifyContent:"center",gap:4,flexShrink:0,border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)(B,{}),u("files.mention")]}),(0,r.jsx)(H,{onClick:()=>Y(null),title:u("files.dismissUploadResults")})]}),V.errors.map(e=>(0,r.jsxs)("div",{title:e.error,style:{display:"flex",alignItems:"center",gap:4,marginTop:3,minWidth:0,fontSize:10,color:"#f87171"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"M12 8v5"}),(0,r.jsx)("path",{d:"M12 17h.01"})]}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.name))]})]}),!a&&C.length>0&&(0,r.jsxs)("div",{style:{padding:"0 4px 2px"},children:[(0,r.jsxs)("div",{"aria-label":u("files.changeStats",{count:C.length,additions:R.additions,deletions:R.deletions}),style:{display:"flex",alignItems:"center",gap:6,height:24,padding:"0 10px",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:u("files.changedCount",{count:C.length})}),(0,r.jsxs)("span",{style:{color:A.added,fontFamily:"var(--font-mono)"},children:["+",R.additions]}),(0,r.jsxs)("span",{style:{color:A.deleted,fontFamily:"var(--font-mono)"},children:["-",R.deletions]})]}),C.map(n=>(0,r.jsx)(U,{status:n,cwd:e,onOpenFile:t,t:u},n.filePath))]}),(a||0===C.length)&&(0,r.jsxs)("div",{style:{padding:"2px 4px"},children:[g?(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}):f?(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:f}):p.map(n=>(0,r.jsx)(O,{node:n,depth:0,cwd:e,onOpenFile:t,onAtMention:o,expandedPaths:y,onToggleExpanded:er,refreshToken:Q,highlightedPaths:j,gitStatusByPath:et,changedDirectoryPaths:en,t:u},n.fullPath)),!g&&!f&&0===p.length&&(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:u("files.noFiles")})]})]})});function q({onClick:e,title:t,disabled:n,skipHover:i,color:o,background:l="none",marginRight:s,ariaPressed:a,children:d}){return(0,r.jsx)("button",{onClick:e,disabled:n,title:t,"aria-label":t,"aria-pressed":a,style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:s,background:l,border:"none",color:o,cursor:n?"default":"pointer",borderRadius:5,flexShrink:0,opacity:n?.6:1,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{n||i||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{n||i||(e.currentTarget.style.color=o,e.currentTarget.style.background=l)},children:d})}let K="pi-web:unread-session-ids";function V(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function Y({text:e,style:t}){return(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",minWidth:0,lineHeight:1.35,direction:"rtl",textAlign:"left",...t},children:(0,r.jsx)("span",{style:{unicodeBidi:"plaintext"},children:e})})}function J({open:e,children:t,style:n}){let[o,l]=(0,i.useState)(e),[s,a]=(0,i.useState)(e);return((0,i.useEffect)(()=>{let t,n;return e?(l(!0),a(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>a(!0))})):(a(!1),n=setTimeout(()=>l(!1),140)),()=>{void 0!==t&&window.cancelAnimationFrame(t),n&&clearTimeout(n)}},[e]),o)?(0,r.jsx)("div",{style:{...n,opacity:+!!s,transform:s?"translateY(0) scale(1)":"translateY(-8px) scale(0.96)",transformOrigin:"top center",transition:"opacity 140ms ease, transform 140ms ease",pointerEvents:e?"auto":"none"},children:t}):null}let Z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function G(){let[e,t]=(0,i.useState)(!1),[n,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),s=function(e,t){let[n,r]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void r(e);l.current=0;let n=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/n*e.length);r(e.split("").map((e,n)=>" "===e?" ":n<t?e:Z[Math.floor(Math.random()*Z.length)]).join("")),l.current<n?o.current=requestAnimationFrame(i):r(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),n}(e?"0.1.0p0.84.2":"Pi Web",n),a=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,r.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"6ch"},children:s})}function X({selectedSessionId:e,onSelectSession:t,onNewSession:n,initialSessionId:o,skipInitialProjectSelection:l,onInitialRestoreDone:d,refreshKey:c,onSessionDeleted:u,selectedCwd:p,onCwdChange:h,onOpenFile:g,explorerRefreshKey:v,onExplorerRefresh:y,onAtMention:b,onAtMentions:k,onBackgroundTaskDone:j,onRunningSessionIdsChange:S}){var C;let{t:T}=(0,m.s)(),[R,M]=(0,i.useState)([]),[I,L]=(0,i.useState)(!0),[W,E]=(0,i.useState)(null),[z,$]=(0,i.useState)(null),[P,F]=(0,i.useState)(""),[N,A]=(0,i.useState)(!1),[D,B]=(0,i.useState)(""),[H,O]=(0,i.useState)(""),[U,Z]=(0,i.useState)(!1),[ee,et]=(0,i.useState)(""),[en,er]=(0,i.useState)(null),[ei,eo]=(0,i.useState)(!1),[el,es]=(0,i.useState)(null),ea=(0,i.useRef)(null),[ed,ec]=(0,i.useState)(null),[eu,ep]=(0,i.useState)(!1),[eh,eg]=(0,i.useState)(!1),[ex,ef]=(0,i.useState)(""),[em,ev]=(0,i.useState)(null),[ey,eb]=(0,i.useState)(!1),[ek,ew]=(0,i.useState)(null),[ej,eS]=(0,i.useState)(null),eC=(0,i.useRef)(null),eT=(0,i.useRef)(null),[eR,eM]=(0,i.useState)(!0),[eI,eL]=(0,i.useState)(0),[eW,eE]=(0,i.useState)(!1),[ez,e$]=(0,i.useState)(0),[eP,eF]=(0,i.useState)(!0),[eN,eA]=(0,i.useState)(!1),[eD,eB]=(0,i.useState)(!1),[eH,eO]=(0,i.useState)(()=>new Set),[eU,e_]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(K);if(!e)return new Set;let t=JSON.parse(e);if(Array.isArray(t))return new Set(t.filter(e=>"string"==typeof e));return new Set}catch{return new Set}})()),eq=(0,i.useRef)(new Set),eK=(0,i.useRef)(!1),eV=(0,i.useRef)(null),eY=(0,i.useRef)(null),eJ=(0,i.useRef)(null),eZ=(0,i.useCallback)(async(e=!1,t=!1)=>{try{e&&L(!0);let n=await fetch(t?"/api/sessions?force=1":"/api/sessions",{cache:"no-store"});if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.json();M(r.sessions),eK.current||eO(new Set(r.runningSessionIds??[]));let i=new Set(r.sessions.map(e=>e.id));e_(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>i.has(e)));return t.size===e.size?e:t}),E(null),e||(eA(!0),eV.current&&clearTimeout(eV.current),eV.current=setTimeout(()=>eA(!1),2e3))}catch(e){E(String(e))}finally{e&&L(!1)}},[]),eG=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eG.current;eG.current=!0,eZ(e,!e)},[eZ,c]),(0,i.useEffect)(()=>{eM(function(e=a()){if(!e)return!0;try{return"false"!==e.getItem(s)}catch{return!0}}())},[]),(0,i.useEffect)(()=>{try{0===eU.size?window.localStorage.removeItem(K):window.localStorage.setItem(K,JSON.stringify([...eU]))}catch{}},[eU]),(0,i.useEffect)(()=>{let e=!1,t=null,n=null,r=()=>{t&&clearTimeout(t),t=null},i=async()=>{if(e||"visible"!==document.visibilityState)return;let o=new AbortController;n?.abort(),n=o;try{let t=await fetch("/api/agent/running",{cache:"no-store",signal:o.signal});if(!t.ok)return;let r=await t.json();if(e||n!==o)return;eK.current=!0,eO(new Set(r.runningSessionIds??[]))}catch{}finally{n===o&&(n=null),r(),e||"visible"!==document.visibilityState||(t=setTimeout(()=>void i(),2500))}},o=()=>{"visible"===document.visibilityState?i():(r(),n?.abort(),n=null)};return i(),document.addEventListener("visibilitychange",o),()=>{e=!0,r(),n?.abort(),document.removeEventListener("visibilitychange",o)}},[]),(0,i.useEffect)(()=>{S?.(eH)},[S,eH]),(0,i.useEffect)(()=>{let t=eq.current,n=[...t].filter(t=>!eH.has(t)&&t!==e),r=[...eH].filter(e=>!t.has(e));(n.length>0||r.length>0)&&e_(e=>{let t=new Set(e);return eH.forEach(e=>t.delete(e)),n.forEach(e=>t.add(e)),t});let i=r.some(e=>!R.some(t=>t.id===e));(n.length>0||i)&&eZ(!1,!0),n.length>0&&j?.(),eq.current=eH},[eH,e,R,eZ,j]),(0,i.useEffect)(()=>{e&&e_(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[e]),(0,i.useEffect)(()=>{void 0!==v&&eL(e=>e+1)},[v]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&F(e.home)}).catch(()=>{})},[]);let eX=(0,i.useRef)(!1),eQ=(0,i.useCallback)((e,t)=>({root:e,key:t}),[]),e0=(0,i.useCallback)(e=>{if(!e)return null;if(el?.cwd===e)return eQ(el.root,el.key);if(ed&&ed.forCwd===e||ed?.worktrees.some(t=>t.path===e))return eQ(ed.projectRoot,ed.projectKey);let t=R.find(t=>t.cwd===e||(t.projectRoot??t.cwd)===e);return t?eQ(t.projectRoot??t.cwd,x(t)):eQ(e,e)},[el,ed,R,eQ]),e1=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e0(z),t=e1.current;(t?.cwd!==z||t.key!==(e?.key??null))&&(e1.current={cwd:z,key:e?.key??null},h?.(z,e?.root??null,e?.key??null))},[z,h,e0]);let e2=(0,i.useRef)(null);(0,i.useEffect)(()=>{p&&p!==e2.current&&(e2.current=p,$(p))},[p]);let[e8,e4]=(0,i.useState)(0);(0,i.useLayoutEffect)(()=>{if(!z){ec(null),eS(null);return}let e=!1;return eS(z),fetch(`/api/worktrees?cwd=${encodeURIComponent(z)}`).then(e=>e.json()).then(t=>{if(!e){if(eS(null),t.error||!t.projectRoot)return void ec(null);ec({forCwd:z,projectRoot:t.projectRoot,projectKey:t.projectKey??t.projectRoot,isGit:t.isGit??!1,isTopLevel:t.isTopLevel??!1,currentWorktreePath:t.currentWorktreePath??null,worktrees:t.worktrees??[]})}}).catch(()=>{e||(eS(null),ec(null))}),()=>{e=!0}},[z,e8,c]),(0,i.useEffect)(()=>{if(0!==R.length&&!l&&null===z){if(o&&!eX.current){eX.current=!0;let e=R.find(e=>e.id===o);if(e){$(e.cwd),t(e,!0);return}d?.()}let e=f(R);e.length>0&&$(e[0].root)}},[R,z,o,l,t,d]);let e6=ed?ed.worktrees.find(e=>e.path===z)??(ed.forCwd===z&&ed.currentWorktreePath?ed.worktrees.find(e=>e.path===ed.currentWorktreePath):void 0)??ed.worktrees.find(e=>e.isMain):void 0,e5=e6?.path??null,e3=(0,i.useCallback)(async e=>{let t=(e??ee).trim();if(t&&!ei){eo(!0),er(null);try{let e=await fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t})}),n=await e.json().catch(()=>({}));if(!e.ok||n.error||!n.cwd||!n.projectRoot||!n.projectKey)return void er(n.error??`HTTP ${e.status}`);es({cwd:n.cwd,root:n.projectRoot,key:n.projectKey}),$(n.cwd),Z(!1),et(""),A(!1)}catch(e){er(e instanceof Error?e.message:String(e))}finally{eo(!1)}}},[ee,ei]),e7=(0,i.useCallback)(()=>{Z(!0),er(null),A(!1)},[]),e9=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&($(t.cwd),Z(!1),et(""),er(null),A(!1))}catch{}},[]),te=(0,i.useCallback)(async()=>{let e=ex.trim();if(e&&!ey&&ed){eb(!0),ev(null);try{let t=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ed.projectRoot,branch:e})}),n=await t.json().catch(()=>({}));if(!t.ok||n.error||!n.path)return void ev(n.error??`HTTP ${t.status}`);eg(!1),ef(""),ep(!1),ec(t=>t?{...t,forCwd:n.path,currentWorktreePath:n.path,worktrees:[...t.worktrees,{path:n.path,branch:e,isMain:!1}]}:t),$(n.path),e4(e=>e+1)}catch(e){ev(e instanceof Error?e.message:String(e))}finally{eb(!1)}}},[ex,ey,ed]),tt=(0,i.useCallback)(async(e,t)=>{if(ed&&!ey){eb(!0),ev(null);try{let n=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ed.projectRoot,path:e,force:t})}),r=await n.json().catch(()=>({}));if(!n.ok){if(r.dirty&&!t)return void ew(e);ev(r.error??`HTTP ${n.status}`);return}ew(null),e5===e&&$(ed.projectRoot),e4(e=>e+1)}catch(e){ev(e instanceof Error?e.message:String(e))}finally{eb(!1)}}},[ed,ey,e5]);(0,i.useEffect)(()=>{let e=e=>{ea.current&&!ea.current.contains(e.target)&&(A(!1),B("")),eC.current&&!eC.current.contains(e.target)&&(ep(!1),eg(!1),ef(""),ev(null),ew(null),O(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let tn=(0,i.useCallback)(e=>{e.cwd&&$(e.cwd),t(e)},[t]),tr=(0,i.useCallback)(()=>{if(!z)return;let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;n?.(e,z)},[z,n]),ti=f(R),to=ti.length>8,tl=D.trim()?ti.filter(e=>e.root.toLowerCase().includes(D.trim().toLowerCase())):ti,ts=e0(z),ta=(0,i.useMemo)(()=>(function(e,t,n){let r=new Map;for(let i of e){let e=x(i);if(!e)continue;let o=r.get(e);o||(o={running:0,unread:0},r.set(e,o)),t.has(i.id)&&o.running++,n.has(i.id)&&o.unread++}return r})(R,eH,eU),[R,eH,eU]),td=(0,i.useMemo)(()=>[...ta.entries()].some(([e,{running:t,unread:n}])=>e!==ts?.key&&(t>0||n>0)),[ta,ts]),tc=ts?(C=ts.key,R.filter(e=>x(e)===C)):R,tu=!!(ed?.isGit&&ed.isTopLevel&&z&&ts?.key===ed.projectKey),tp=z&&ed&&ts?.key===ed.projectKey&&!tu?ed.isGit?{label:T("sidebar.openRepoRoot"),title:T("sidebar.openRepoRootTitle")}:{label:T("sidebar.gitRepoRootOnly"),title:T("sidebar.gitRepoRootOnlyTitle")}:null,th=!!(z&&ej===z),tg=tp??(th&&!tu?{label:T("sidebar.worktrees"),title:T("sidebar.checkingWorktrees")}:null),tx=function(e){let t=new Map;for(let n of e)t.set(n.id,{session:n,children:[]});let n=new Map;for(let t of e)t.parentSessionId&&n.set(t.id,t.parentSessionId);let r=[];for(let e of t.values()){let i=function(e){let r=n.get(e),i=new Set;for(;r&&!i.has(r);){if(i.add(r),t.has(r))return r;r=n.get(r)}return null}(e.session.id);i?t.get(i).children.push(e):r.push(e)}let i=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>i(e.children))};return i(r),r}(tc);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[U&&(0,r.jsx)(w,{busy:ei,error:en,onCancel:()=>{Z(!1),er(null)},onSelect:e=>void e3(e)}),(0,r.jsxs)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10},children:[(0,r.jsx)(G,{}),(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsxs)("button",{onClick:tr,disabled:!z,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:z?"var(--text-muted)":"var(--text-dim)",cursor:z?"pointer":"not-allowed",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:z?T("sidebar.newSessionTitle",{path:z}):T("sidebar.selectProject"),onMouseEnter:e=>{z&&(e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)")},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=z?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,r.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),T("sidebar.new")]}),(0,r.jsx)("button",{onClick:()=>eZ(!1,!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:eN?"rgba(74,222,128,0.18)":"var(--bg-hover)",border:`1px solid ${eN?"rgba(74,222,128,0.4)":"var(--border)"}`,color:eN?"#4ade80":"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.3s, color 0.3s, border-color 0.3s"},onMouseEnter:e=>{eN||(e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)")},onMouseLeave:e=>{eN||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)")},title:T("sidebar.refresh"),children:eN?(0,r.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"})]})})]})]}),(0,r.jsxs)("div",{ref:ea,style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>A(e=>!e),title:ts?.root??z??"",style:{width:"100%",display:"flex",alignItems:"center",padding:"6px 10px",background:z?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:z?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left",transition:"border-color 0.15s, background 0.15s"},children:[z?(0,r.jsx)(Y,{text:V(ts?.root??z,P),style:{flex:1,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text)"}}):(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:o&&!eX.current?"":T("sidebar.selectProject")}),td&&(0,r.jsx)("span",{title:T("sidebar.newActivity"),"aria-label":T("sidebar.newActivity"),style:{width:8,height:8,borderRadius:"50%",flexShrink:0,marginLeft:6,background:"var(--accent)"}})]}),(0,r.jsxs)(J,{open:N,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[to&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:D,onChange:e=>B(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(B(""),A(!1))},placeholder:T("sidebar.filterProjects"),autoFocus:!0,style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}})}),(0,r.jsxs)("div",{style:{maxHeight:"min(50vh, 380px)",overflowY:"auto"},children:[tl.map(e=>{var t,n;return(0,r.jsxs)("button",{onClick:()=>{$(e.root),B(""),Z(!1),et(""),er(null),A(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"var(--bg)",border:"none",borderBottom:"1px solid var(--border)",color:e.key===ts?.key?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.root,children:[e.key===ts?.key&&(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}),e.key!==ts?.key&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(Y,{text:V(e.root,P),style:{flex:1}}),(t=ta.get(e.key),n=T,t&&(0!==t.running||0!==t.unread)?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5,flexShrink:0,marginLeft:6},children:[t.running>0&&(0,r.jsxs)("span",{title:n("sidebar.agentRunning"),"aria-label":`${n("sidebar.agentRunning")} (${t.running})`,style:{display:"inline-flex",alignItems:"center",gap:3,color:"var(--accent)",fontSize:10,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,r.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})}),t.running]}),t.unread>0&&(0,r.jsxs)("span",{title:n("sidebar.newSessionActivity"),"aria-label":`${n("sidebar.newSessionActivity")} (${t.unread})`,style:{display:"inline-flex",alignItems:"center",gap:3,color:"#0891b2",fontSize:10,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"currentColor",display:"inline-block"}}),t.unread]})]}):null)]},e.key)}),0===tl.length&&D.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:T("sidebar.noMatchingProjects")})]}),!U&&(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),e9()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:tl.length>0?"1px solid var(--border)":"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2H4L5 3.5H8.5a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-7A.5.5 0 0 1 1 8V3Z"})}),(0,r.jsx)("span",{children:T("sidebar.useDefaultDirectory")})]}),(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),e7()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,r.jsx)("span",{children:T("sidebar.customPath")})]})]})]}),tu&&(()=>{if(!ed)return null;let e=ed.worktrees.length>=8,t=e&&H.trim()?ed.worktrees.filter(e=>(e.branch??V(e.path,P)).toLowerCase().includes(H.trim().toLowerCase())):ed.worktrees;return(0,r.jsxs)("div",{ref:eC,style:{position:"relative",marginTop:6},children:[(0,r.jsxs)("button",{onClick:()=>ep(e=>!e),title:e6?T("sidebar.switchWorktreeTitle",{path:e6.path}):T("sidebar.switchWorktree"),style:{width:"100%",height:29,boxSizing:"border-box",display:"flex",alignItems:"center",gap:6,padding:"0 10px",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",fontSize:11,lineHeight:1.35,color:"var(--text-muted)",textAlign:"left"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:e6&&!e6.isMain?"var(--accent)":"var(--text-dim)"},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,r.jsx)(Y,{text:e6?e6.branch??V(e6.path,P):"…",style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)"}}),e6?.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:T("sidebar.main")}),ed.worktrees.length>1&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:ed.worktrees.length}),(0,r.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),(0,r.jsxs)(J,{open:eu,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[e&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{value:H,onChange:e=>O(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(O(""),ep(!1))},placeholder:T("sidebar.filterWorktrees"),autoFocus:!0,style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}})}),(0,r.jsxs)("div",{style:{maxHeight:"min(40vh, 300px)",overflowY:"auto"},children:[t.map(e=>{let t=e.path===e5;return ek===e.path?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"rgba(239,68,68,0.06)"},children:[(0,r.jsx)("span",{style:{flex:1,fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T("sidebar.forceRemoveCheckout")}),(0,r.jsx)("button",{onClick:()=>void tt(e.path,!0),disabled:ey,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:T("sidebar.force")}),(0,r.jsx)("button",{onClick:()=>ew(null),style:{padding:"3px 9px",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer",flexShrink:0},children:T("sidebar.cancel")})]},e.path):(0,r.jsxs)("div",{className:"wt-row",style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{onClick:()=>{$(e.path),ep(!1),ev(null),O("")},title:e.path,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px",background:"var(--bg)",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[t?(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(Y,{text:e.branch??V(e.path,P),style:{flex:1}}),e.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:T("sidebar.main")})]}),!e.isMain&&(0,r.jsx)("button",{onClick:()=>void tt(e.path,!1),disabled:ey,title:T("sidebar.removeWorktreeTitle",{path:e.path}),style:{display:"flex",alignItems:"center",justifyContent:"center",width:34,height:28,padding:0,marginRight:4,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="#ef4444",e.currentTarget.style.background="rgba(239,68,68,0.08)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]},e.path)}),e&&0===t.length&&H.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:T("sidebar.noMatchingWorktrees")})]}),eh?(0,r.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,r.jsx)("input",{ref:eT,value:ex,onChange:e=>{ef(e.target.value),ev(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),te()),"Escape"===e.key&&(eg(!1),ef(""),ev(null))},placeholder:T("sidebar.branchName"),style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,r.jsx)("button",{onClick:()=>void te(),disabled:ey||!ex.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:ey||!ex.trim()?"not-allowed":"pointer",opacity:ey||!ex.trim()?.65:1},children:ey?T("sidebar.creating"):T("sidebar.create")}),(0,r.jsx)("button",{onClick:()=>{eg(!1),ef(""),ev(null)},style:{flex:1,padding:"4px 0",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:T("sidebar.cancel")})]})]}):(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),eg(!0),ev(null),setTimeout(()=>eT.current?.focus(),0)},title:T("sidebar.createWorktreeTitle"),style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,r.jsx)("span",{children:T("sidebar.newWorktree")})]}),em&&(0,r.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:em})]})]})})(),tg&&(0,r.jsxs)("button",{type:"button","aria-disabled":"true",tabIndex:-1,title:tg.title,style:{width:"100%",height:29,boxSizing:"border-box",marginTop:6,display:"flex",alignItems:"center",gap:6,padding:"0 10px",border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-hover)",color:"var(--text-dim)",fontSize:11,lineHeight:1.35,whiteSpace:"nowrap",textAlign:"left",cursor:"default",opacity:.82},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:tg.label})]})]}),(0,r.jsxs)("div",{style:{flex:eR&&(p||z)?"1 1 0":"1 1 auto",overflowY:"auto",padding:"0",minHeight:80},children:[I&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:T("sidebar.loading")}),W&&(0,r.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:W}),!I&&!W&&0===tc.length&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:T("sidebar.noSessions")}),tx.map(t=>(0,r.jsx)(Q,{node:t,selectedSessionId:e,runningSessionIds:eH,unreadSessionIds:eU,onSelectSession:tn,onRenamed:eZ,onSessionDeleted:e=>{u?.(e),eZ()},depth:0},t.session.id))]}),(p||z)&&(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:eR?"1 1 0":"0 0 auto",minHeight:0,overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0},children:[(0,r.jsxs)("button",{onClick:()=>eM(e=>{let t=!e;return!function(e,t=a()){if(t)try{t.setItem(s,String(e))}catch{}}(t),t}),style:{display:"flex",alignItems:"center",gap:6,flex:1,padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,r.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:eR?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,r.jsx)("polyline",{points:"3 2 7 5 3 8"})}),T("files.explorer")]}),eR&&ez>0&&(0,r.jsx)(q,{onClick:()=>eF(e=>!e),title:T("sidebar.changedFiles",{count:ez}),ariaPressed:!eP,color:eP?"var(--text-dim)":"var(--accent)",background:eP?"none":"var(--bg-selected)",children:(0,r.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:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,r.jsx)("path",{d:"M3 12h6"}),(0,r.jsx)("path",{d:"M15 12h6"})]})}),eR&&(0,r.jsx)(q,{onClick:()=>eJ.current?.openUploadPicker(),disabled:eW,title:T("sidebar.uploadFilesTitle"),color:"var(--text-dim)",children:(0,r.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:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("path",{d:"m17 8-5-5-5 5"}),(0,r.jsx)("path",{d:"M12 3v12"})]})}),(0,r.jsx)(q,{onClick:()=>{y?y():eL(e=>e+1),eB(!0),eY.current&&clearTimeout(eY.current),eY.current=setTimeout(()=>eB(!1),2e3)},title:T("sidebar.refreshExplorer"),skipHover:eD,color:eD?"#4ade80":"var(--text-dim)",background:eD?"rgba(74,222,128,0.18)":"none",marginRight:6,children:eD?(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"})]})})]}),eR&&(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",overflowX:"hidden"},children:(0,r.jsx)(_,{ref:eJ,cwd:z??p,onOpenFile:g??(()=>{}),refreshKey:eI,onAtMention:b,onAtMentions:k,onUploadBusyChange:eE,changesCollapsed:eP,onChangesCountChange:e$})})]})]})}function Q({node:e,selectedSessionId:t,runningSessionIds:n,unreadSessionIds:o,onSelectSession:l,onRenamed:s,onSessionDeleted:a,depth:d}){let[c,u]=(0,i.useState)(!1),p=e.children.length>0;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{position:"relative"},children:[d>0&&(0,r.jsx)("div",{style:{position:"absolute",left:12*d+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,r.jsx)(en,{session:e.session,isSelected:e.session.id===t,isRunning:n.has(e.session.id),isUnread:o.has(e.session.id),onClick:()=>l(e.session),onRenamed:s,onDeleted:e=>a?.(e),depth:d,hasChildren:p,collapsed:c,onToggleCollapse:()=>u(e=>!e)})]}),p&&!c&&(0,r.jsx)("div",{children:e.children.map(e=>(0,r.jsx)(Q,{node:e,selectedSessionId:t,runningSessionIds:n,unreadSessionIds:o,onSelectSession:l,onRenamed:s,onSessionDeleted:a,depth:d+1},e.session.id))})]})}function ee(){let{t:e}=(0,m.s)();return(0,r.jsx)("span",{title:e("sidebar.agentRunning"),"aria-label":e("sidebar.agentRunning"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"var(--accent)"},children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,r.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})})})}function et(){let{t:e}=(0,m.s)();return(0,r.jsx)("span",{title:e("sidebar.newActivity"),"aria-label":e("sidebar.newSessionActivity"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#0891b2"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",style:{display:"block"},children:[(0,r.jsx)("circle",{cx:"7",cy:"7",r:"2.5",fill:"currentColor"}),(0,r.jsxs)("circle",{cx:"7",cy:"7",r:"3",stroke:"currentColor",strokeWidth:"1.4",opacity:"0.32",children:[(0,r.jsx)("animate",{attributeName:"r",values:"3;6;3",dur:"1.6s",repeatCount:"indefinite"}),(0,r.jsx)("animate",{attributeName:"opacity",values:"0.32;0;0.32",dur:"1.6s",repeatCount:"indefinite"})]})]})})}function en({session:e,isSelected:t,isRunning:n,isUnread:o,onClick:l,onRenamed:s,onDeleted:a,depth:d=0,hasChildren:u=!1,collapsed:p=!1,onToggleCollapse:h}){let g,x,f,v,y,{t:b}=(0,m.s)(),[k,w]=(0,i.useState)(!1),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(""),[R,M]=(0,i.useState)(!1),[I,L]=(0,i.useState)(!1),W=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(j){let e=requestAnimationFrame(()=>W.current?.select());return()=>cancelAnimationFrame(e)}},[j]);let E=c(e.firstMessage)??e.firstMessage,z=e.name||E.slice(0,50)||e.id.slice(0,12),$=(0,i.useCallback)(t=>{t.stopPropagation(),e.transient||(T(e.name||E.slice(0,50)||e.id.slice(0,12)),S(!0))},[e.name,e.transient,E,e.id]),P=(0,i.useCallback)(async()=>{let t=C.trim();if(S(!1),C!==z&&t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),s?.()}catch{}},[C,e.id,e.name,s,z]),F=(0,i.useCallback)(async()=>{if(!e.transient){M(!1),L(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),a?.(e.id)}catch{L(!1)}}},[e.id,e.transient,a]),N=(0,i.useCallback)(e=>{e.stopPropagation(),e.shiftKey?F():M(!0)},[F]),A=(0,i.useCallback)(e=>{e.stopPropagation(),F()},[F]),D=(0,i.useCallback)(e=>{e.stopPropagation(),M(!1)},[]),B=(0,i.useCallback)(t=>{(function(e,t=window){let n=new CustomEvent("pi-web:session-row-contextmenu",{cancelable:!0,detail:e});return!t.dispatchEvent(n)})({id:e.id,path:e.path,cwd:e.cwd,name:e.name,clientX:t.clientX,clientY:t.clientY,refresh:()=>{s?.()}})&&(t.preventDefault(),t.stopPropagation())},[s,e.cwd,e.id,e.name,e.path]);return(0,r.jsx)("div",{onClick:R||j?void 0:l,onContextMenu:R||j?void 0:B,onMouseEnter:()=>w(!0),onMouseLeave:()=>{w(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:d>0?12*d+14:14,paddingRight:8,cursor:R||j?"default":"pointer",background:R?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":k?"var(--bg-hover)":"transparent",borderLeft:R?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:I?.5:1,gap:6,overflow:"hidden"},children:R?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b("sidebar.deleteSession",{title:z.slice(0,22)+(z.length>22?"…":"")})}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,r.jsxs)("button",{onClick:A,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),b("sidebar.delete")]}),(0,r.jsx)("button",{onClick:D,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:b("sidebar.cancel")})]})]}):j?(0,r.jsx)("input",{ref:W,value:C,onChange:e=>T(e.target.value),onBlur:P,onKeyDown:e=>{"Enter"===e.key&&P(),"Escape"===e.key&&S(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:30}}):(0,r.jsxs)(r.Fragment,{children:[d>0&&(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",gap:5,minWidth:0,fontSize:12,fontWeight:t?500:400,lineHeight:1.4,color:"var(--text)"},title:z,children:(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:z})}),(0,r.jsxs)("div",{style:{marginTop:2,display:"flex",alignItems:"center",gap:8,color:"var(--text-dim)",fontSize:11,minWidth:0},children:[n?(0,r.jsx)(ee,{}):o?(0,r.jsx)(et,{}):(0,r.jsx)("span",{title:e.modified,children:(g=new Date(e.modified),f=Math.floor((x=new Date().getTime()-g.getTime())/6e4),v=Math.floor(x/36e5),y=Math.floor(x/864e5),f<1?"just now":f<60?`${f}m ago`:v<24?`${v}h ago`:y<7?`${y}d ago`:g.toLocaleDateString())}),(0,r.jsx)("span",{children:b("sidebar.messagesCount",{count:e.messageCount})}),e.worktreeBranch&&(0,r.jsxs)("span",{title:`Worktree: ${e.cwd}`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--accent)",minWidth:0,overflow:"hidden"},children:[(0,r.jsxs)("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.worktreeBranch})]})]})]}),u&&(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),h?.()},title:p?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:p?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),k&&!e.transient&&(0,r.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,r.jsx)("button",{onClick:$,title:b("sidebar.rename"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,r.jsx)("button",{onClick:N,title:b("sidebar.deleteWithShiftClick"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}let er=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,ei=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,eo=/\x1B\[([0-9;]*)m/g,el=/\x1B_pi:c\x07/g,es=["#1f2937","#dc2626","#16a34a","#d97706","#2563eb","#9333ea","#0891b2","#6b7280"],ea=["#9ca3af","#ef4444","#22c55e","#f59e0b","#3b82f6","#a855f7","#06b6d4","#e5e7eb"];function ed(e){return e.replace(el,"").replace(er,"")}function ec(e){let t=[],n=0;for(;n<e.length;){if(27===e.charCodeAt(n)){let t=e.slice(n).match(ei);if(t){n+=t[0].length;continue}}let r=e.codePointAt(n);if(void 0===r)break;let i=String.fromCodePoint(r);t.push({start:n,end:n+i.length,char:i}),n+=i.length}return t}function eu(e,t){let n=ec(e)[t];return n?e.slice(0,n.start)+e.slice(n.end):e}function ep(e){return ec(e)[0]?.char}function eh(e){let t,n=[],r={},i=0;for(eo.lastIndex=0;null!==(t=eo.exec(e));)t.index>i&&n.push({text:e.slice(i,t.index),style:r}),r=function(e,t){let n={...e};for(let e=0;e<t.length;e++){let r=t[e];if(0===r)for(let e of Object.keys(n))delete n[e];else if(1===r)n.fontWeight=700;else if(2===r)n.opacity=.65;else if(3===r)n.fontStyle="italic";else if(4===r)n.textDecoration="underline";else if(22===r)delete n.fontWeight,delete n.opacity;else if(23===r)delete n.fontStyle;else if(24===r)delete n.textDecoration;else if(39===r)delete n.color;else if(49===r)delete n.backgroundColor;else if(r>=30&&r<=37)n.color=es[r-30];else if(r>=90&&r<=97)n.color=ea[r-90];else if(r>=40&&r<=47)n.backgroundColor=es[r-40];else if(r>=100&&r<=107)n.backgroundColor=ea[r-100];else if((38===r||48===r)&&2===t[e+1]){let[i,o,l]=[t[e+2],t[e+3],t[e+4]];[i,o,l].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===r?n.color=`rgb(${i}, ${o}, ${l})`:n.backgroundColor=`rgb(${i}, ${o}, ${l})`),e+=4}else if((38===r||48===r)&&5===t[e+1]){let i=function(e){if(e>=0&&e<8)return es[e];if(e>=8&&e<16)return ea[e-8];if(e>=16&&e<=231){let t=e-16,n=Math.floor(t/36),r=Math.floor(t%36/6),i=e=>0===e?0:55+40*e;return`rgb(${i(n)}, ${i(r)}, ${i(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);i&&(38===r?n.color=i:n.backgroundColor=i),e+=2}}return n}(r,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),i=t.index+t[0].length;return i<e.length&&n.push({text:e.slice(i),style:r}),n}let eg={ArrowUp:"\x1b[A",ArrowDown:"\x1b[B",ArrowRight:"\x1b[C",ArrowLeft:"\x1b[D",Home:"\x1b[H",End:"\x1b[F",Insert:"\x1b[2~",Delete:"\x1b[3~",PageUp:"\x1b[5~",PageDown:"\x1b[6~",Escape:"\x1b",Backspace:""},ex={ArrowLeft:"\x1bb",ArrowRight:"\x1bf",ArrowUp:"\x1bp",ArrowDown:"\x1bn"};function ef(e,t={}){return"thinking"===e.type&&!e.deferred&&!t.isStreaming&&""===e.thinking.trim()}function em(e,t={}){return(e.content??[]).filter(e=>!ef(e,t))}function ev(e,t={}){return t.isStreaming||"error"!==e.stopReason?null:e.errorMessage?.trim()||"Unknown provider error"}function ey(e,t={}){let n=em(e,t),r=n.findLastIndex(e=>"text"!==e.type&&"image"!==e.type);return -1===r?{answerBlocks:n,processBlocks:[]}:{answerBlocks:n.slice(r+1),processBlocks:n.slice(0,r+1)}}function eb(e){return e.filter(e=>"toolCall"===e.type).length}function ek(e){try{return decodeURIComponent(e)}catch{return e}}function ew(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function ej(e){let t=ew(e),n=/^[a-zA-Z]:\//.test(t),r=t.startsWith("//"),i=t.startsWith("/")&&!n&&!r,o=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){o.length>0&&".."!==o[o.length-1]?o.pop():i||n||r||o.push(e);continue}o.push(e)}let l=o.join("/");return n?l:r?`//${l}`:i?`/${l}`:l}function eS(e,t,n=t){let r,i,o,l,s;if(!e)return null;let a=e.split("#",1)[0].split("?",1)[0].trim();if(!a)return null;let d=null,c=null,u=ek(a),p=u.startsWith("\\\\"),h=ew(u),g=h.toLowerCase();if(g.startsWith("/api/")||g.startsWith("/_next/")||!p&&h.startsWith("//")||/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(h)&&!g.startsWith("file:")&&!/^[a-zA-Z]:\//.test(h))return null;if(g.startsWith("file:")?c=(d=function(e){try{let t=new URL(e);if("file:"!==t.protocol)return null;let n=ek(t.pathname);if(t.hostname)return`//${t.hostname}${n.startsWith("/")?n:`/${n}`}`;if(/^\/[a-zA-Z]:\//.test(n))return n.slice(1);return n}catch{return null}}(h))?"absolute":null:/^[a-zA-Z]:\//.test(h)||h.startsWith("/")?(d=h,c="absolute"):t&&!(h.startsWith("#")||h.startsWith("?"))&&(h.startsWith("./")||h.startsWith("../")||h.includes("/")||/(^|\/)\.?[^/]+\.[^/.]+$/.test(h))&&(d=`${ew(t).replace(/\/+$/,"")}/${h}`,c="relative"),!d)return null;let x=ej(d).replace(/:\d+(?::\d+)?$/,"");return"relative"===c&&n&&(r=ej(x).replace(/\/+$/,""),i=ej(n).replace(/\/+$/,""),l=(o=/^[a-zA-Z]:\//.test(r)||/^[a-zA-Z]:\//.test(i))?r.toLowerCase():r,!(l===(s=o?i.toLowerCase():i)||l.startsWith(`${s}/`)))?null:x}function eC(e){let t=e.toLowerCase();return"edit"===t||t.startsWith("edit_")||t.endsWith(".edit")||t.endsWith("_edit")||t.includes("str_replace")||t.includes("replace_editor")}var eT=n(32316),eR=n(88374),eM=n(5924),eI=n(94764),eL=n(63835),eW=n(54152),eE=n(84678),ez=n(98164);let e$={...eI.j,attributes:{...eI.j.attributes,code:[["className",/^language-./,"math-inline","math-display"]]},strip:[...eI.j.strip||[],"iframe","object","style","form"]};function eP(e){let t=e.includes("\r\n")?"\r\n":"\n",n=e.split(/\r?\n/),r=[],i=null,o=0,l=null,s=new Map;for(let e=0;e<n.length;e++){var a;let t=n[e];if(l){r.push(t),RegExp(`</${l}\\s*>`,"i").test(t)&&(l=null);continue}let d=t.match(/^ {0,3}(`{3,}|~{3,})/);if(d){let e=d[1][0],n=d[1].length;i?e===i.marker&&n>=i.size&&(i=null):i={marker:e,size:n},o=0,r.push(t);continue}if(i){r.push(t);continue}let c=t.match(/<(code|pre|script|style)\b/i);if(c){let e=c[1].toLowerCase(),n=t.slice((c.index??0)+c[0].length);RegExp(`</${e}\\s*>`,"i").test(n)||(l=e),o=0,r.push(t);continue}if(/^(?: {4}|\t)/.test(t)||""===t.trim()){o=0,r.push(t);continue}if(o||t.includes("`")){o=function(e,t){let n=t;for(let t=0;t<e.length;){if("`"!==e[t]){t++;continue}let r=t+1;for(;"`"===e[r];)r++;let i=r-t;0===n?n=i:i===n&&(n=0),t=r}return n}(t,o),r.push(t);continue}let u=t.match(/^([ ]{0,3})\\\[[ \t]*(.+?)[ \t]*\\\][ \t]*$/);if(u){let e=u[2].trim();if(e){r.push(`${u[1]}$$`,`${u[1]}${e}`,`${u[1]}$$`);continue}}let p=t.match(/^([ ]{0,3})\\\[[ \t]*$/);if(p){let t=function(e,t){for(let n=t;n<e.length;n++){let t=e[n];if(/^ {0,3}\\\][ \t]*$/.test(t))return n;if(/^ {0,3}(`{3,}|~{3,})/.test(t)||/^ {0,3}\\\[[ \t]*$/.test(t)||/<(code|pre|script|style)\b/i.test(t))break}return -1}(n,e+1);if(-1!==t){r.push(`${p[1]}$$`,...n.slice(e+1,t).map(e=>eN(e,p[1])),`${p[1]}$$`),e=t;continue}}let h=t.match(/^([ \t]{0,3})\$\$(.+)\$\$[ \t]*$/);if(h){let e=h[2].trim();if(e){r.push(`${h[1]}$$`,`${h[1]}${e}`,`${h[1]}$$`);continue}}let g=t.match(/^([ \t]{0,3})\$\$(.+)$/);if(g){let t=g[1],i=g[2].trimEnd();if(i&&!i.includes("$$")){let o=eF(n,e+1,t,s);if(o){r.push(`${t}$$`,`${t}${i}`);for(let i=e+1;i<o.index;i++)r.push(eN(n[i],t));o.content&&r.push(`${t}${o.content}`),r.push(`${t}$$`),e=o.index;continue}}}let x=t.match(/^([ \t]{0,3})\$\$\s*$/);if(x){let t=x[1],i=eF(n,e+1,t,s);if(i&&(i.glued||""!==t)){r.push(`${t}$$`);for(let o=e+1;o<i.index;o++)r.push(eN(n[o],t));i.content&&r.push(`${t}${i.content}`),r.push(`${t}$$`),e=i.index;continue}}r.push((a=t,/^\s{0,3}\[[^\]]+\]:/.test(a)||/]\s*\(/.test(a)||/<(?:!--|\/?[A-Za-z][^>]*>)/.test(a)||/\b(?:https?|file|mailto):/i.test(a)||/\b[A-Za-z]:\\/.test(a)?a:a.replace(/(?<!\\)\\\(([^`\r\n$]+?)(?<!\\)\\\)/g,(e,t)=>t.trim()?`$${t}$`:e)))}return r.join(t)}function eF(e,t,n,r){let i=r.get(n);if(void 0!==i&&t<i)return null;for(let i=t;i<e.length;i++){var o,l,s,a;let t=e[i];if(o=t,""===(l=n)?/^ {0,3}\$\$\s*$/.test(o):o.startsWith(l)&&/^\$\$\s*$/.test(o.slice(l.length)))return{index:i,content:"",glued:!1};if(s=t,/^ {0,3}(`{3,}|~{3,})/.test(s)||/^[ \t]*(?:[-+*]|\d{1,9}[.)])(?:[ \t]+|$)/.test(s)||/^ {0,3}#{1,6}(?:[ \t]+|$)/.test(s)||/^ {0,3}>/.test(s)||/<(code|pre|script|style)\b/i.test(s)||(a=t,/^ {0,3}\$\$(?:\S|[ \t]+\S)/.test(a)))return r.set(n,i),null;let d=function(e,t){if(!e.startsWith(t))return null;let n=e.slice(t.length).match(/^(.+?)\$\$\s*$/);if(!n)return null;let r=n[1].trimEnd();return r&&!r.includes("$$")?r:null}(t,n);if(null!==d)return{index:i,content:d,glued:!0}}return r.set(n,e.length),null}function eN(e,t){if(!t||!e||e.startsWith(" "))return e;let n=e.match(/^ */)?.[0].length??0;return n>=t.length?e:`${t.slice(n)}${e}`}let eA={singleTilde:!1},eD=[[eW.A,["yaml"]],[eE.A,eA],ez.A],eB=[[eW.A,["yaml"]],[eE.A,eA],ez.A],eH=[eM.A,[eL.A,e$],[eR.A,{throwOnError:!1,strict:!1}]],eO=[eM.A,[eL.A,e$],[eR.A,{throwOnError:!1,strict:!1}]];var eU=n(65063),e_=n(7644);let eq="pi-theme",eK=["light","dark","auto"],eV={preference:"auto",theme:"light"},eY=new Set,eJ=null,eZ=!1;function eG(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function eX(e){return"auto"===e?eG():e}function eQ(e){"u">typeof document&&document.documentElement.classList.toggle("dark","dark"===e)}function e0(){if(eJ)return eJ;let e=function(){try{let e=localStorage.getItem(eq);if("light"===e||"dark"===e||"auto"===e)return e}catch{}return"auto"}(),t=eX(e);return eQ(t),eJ={preference:e,theme:t}}function e1(e,t,n){if(eQ(t),n)try{localStorage.setItem(eq,e)}catch{}eJ={preference:e,theme:t},eY.forEach(e=>e())}function e2(){let e=e0();if("auto"!==e.preference)return;let t=eG();t!==e.theme&&e1("auto",t,!1)}function e8(e){return eY.add(e),e0(),eZ||!window.matchMedia||(window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e2),window.addEventListener("focus",e2),document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&e2()}),eZ=!0),e2(),()=>{eY.delete(e)}}function e4(){return e0()}function e6(){return eV}function e5(){let e=(0,i.useSyncExternalStore)(e8,e4,e6),t=(0,i.useCallback)(e=>{var t;let n,r=(t=e0().preference,n=eK.indexOf(t),eK[(n+1)%eK.length]),i=eX(r),o=()=>{e1(r,i,!0)},l=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||l)return void o();let s=e?.x??window.innerWidth/2,a=e?.y??window.innerHeight/2,d=Math.hypot(Math.max(s,window.innerWidth-s),Math.max(a,window.innerHeight-a));document.startViewTransition(o).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${s}px ${a}px)`,`circle(${d}px at ${s}px ${a}px)`]},{duration:450,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})}).catch(()=>{})},[]);return{theme:e.theme,preference:e.preference,toggleTheme:t,isDark:"dark"===e.theme}}function e3(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);try{let t=document.createElement("textarea");return t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch{return Promise.reject()}}function e7({code:e,isStreaming:t,defaultPreview:o=!1}){let{isDark:l}=e5(),{t:s}=(0,m.s)(),[a,d]=(0,i.useState)(o),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),g=`${l?"dark":"light"}
|
|
2
|
+
${e}`,x=a&&!t;(0,i.useEffect)(()=>{if(!x)return;let t=!1;return u({key:g,status:"loading"}),(async()=>{let{default:r}=await Promise.all([n.e(988),n.e(9425),n.e(3308)]).then(n.bind(n,43328));if(r.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:l?"dark":"default"}),!await r.parse(e,{suppressErrors:!0}))throw Error("Invalid Mermaid diagram");let i="u">typeof crypto&&"randomUUID"in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,o=await r.render(i,e);t||u({key:g,status:"ready",svg:o.svg})})().catch(()=>{t||u({key:g,status:"error"})}),()=>{t=!0}},[e,g,l,x]);let f=(0,i.useMemo)(()=>(0,r.jsx)("button",{type:"button",onClick:()=>d(e=>!e),disabled:t,title:t?s("i18n.previewAfterStreaming"):x?s("i18n.showMermaidSource"):s("i18n.previewMermaid"),className:["markdown-code-action",x?"is-active":""].filter(Boolean).join(" "),children:x?s("i18n.source"):s("i18n.preview")}),[t,x,s]);if(!x)return(0,r.jsx)(te,{code:e,lang:"mermaid",headerAction:f,isStreaming:t});let v=c?.key===g&&"error"===c.status?(0,r.jsx)("div",{className:"mermaid-block mermaid-block-error",children:s("i18n.invalidMermaid")}):c?.key!==g||"ready"!==c.status?(0,r.jsx)("div",{className:"mermaid-block mermaid-block-loading","aria-label":s("i18n.renderingMermaid")}):(0,r.jsxs)(r.Fragment,{children:[!p&&(0,r.jsx)("button",{type:"button",className:"mermaid-block mermaid-preview-button",title:s("i18n.openMermaidViewer"),"aria-label":s("i18n.openMermaidViewer"),onClick:()=>h(!0),dangerouslySetInnerHTML:{__html:c.svg}}),p&&(0,r.jsx)(e9,{svg:c.svg,onClose:()=>h(!1)})]});return(0,r.jsxs)("div",{className:"markdown-code-block",children:[(0,r.jsxs)("div",{className:"markdown-code-header",children:[(0,r.jsx)("span",{className:"markdown-code-lang",children:"mermaid"}),f]}),v]})}function e9({svg:e,onClose:t}){let{t:n}=(0,m.s)(),o=(0,i.useRef)(null),[l,s]=(0,i.useState)(1);return(0,i.useEffect)(()=>{let e=o.current;if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),()=>{document.body.style.overflow=t,e.open&&e.close()}},[]),(0,r.jsx)("dialog",{ref:o,className:"mermaid-zoom-dialog","aria-label":n("i18n.mermaidViewer"),onCancel:e=>{e.preventDefault(),t()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),t())},children:(0,r.jsxs)("div",{className:"mermaid-zoom-layout",children:[(0,r.jsxs)("div",{className:"mermaid-zoom-toolbar",children:[(0,r.jsx)("span",{className:"mermaid-zoom-title",children:n("i18n.mermaidDiagram")}),(0,r.jsxs)("div",{className:"mermaid-zoom-actions",children:[(0,r.jsxs)("div",{className:"mermaid-zoom-stepper",children:[(0,r.jsx)("button",{type:"button",onClick:()=>s(e=>Math.max(.5,e-.25)),disabled:l<=.5,title:n("i18n.zoomOut"),"aria-label":n("i18n.zoomOut"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M5 12h14"})})}),(0,r.jsxs)("span",{className:"mermaid-zoom-value",children:[Math.round(100*l),"%"]}),(0,r.jsx)("button",{type:"button",onClick:()=>s(e=>Math.min(3,e+.25)),disabled:l>=3,title:n("i18n.zoomIn"),"aria-label":n("i18n.zoomIn"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M12 5v14M5 12h14"})})})]}),(0,r.jsx)("button",{type:"button",className:"mermaid-zoom-icon-button",onClick:()=>s(1),title:n("i18n.fitToWidth"),"aria-label":n("i18n.fitToWidth"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M8 3H3v5M16 3h5v5M8 21H3v-5M16 21h5v-5"})})}),(0,r.jsx)("button",{type:"button",className:"mermaid-zoom-icon-button",onClick:t,title:n("i18n.close"),"aria-label":n("i18n.close"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})]})]}),(0,r.jsx)("div",{className:"mermaid-zoom-viewport",onClick:e=>{e.target===e.currentTarget&&t()},children:(0,r.jsx)("div",{className:"mermaid-zoom-canvas",style:{width:`${100*l}%`},dangerouslySetInnerHTML:{__html:e}})})]})})}let te=(0,i.memo)(function({code:e,lang:t,headerAction:n,isStreaming:o}){let{isDark:l}=e5(),{t:s}=(0,m.s)(),[a,d]=(0,i.useState)(!1);return(0,r.jsxs)("div",{className:"markdown-code-block",children:[(0,r.jsxs)("div",{className:"markdown-code-header",children:[(0,r.jsx)("span",{className:"markdown-code-lang",children:t||"text"}),(0,r.jsxs)("div",{className:"markdown-code-actions",children:[n,(0,r.jsx)("button",{onClick:()=>{e3(e).then(()=>{d(!0),setTimeout(()=>d(!1),1500)})},className:"markdown-code-action",children:s(a?"i18n.copied":"i18n.copy")})]})]}),o?(0,r.jsx)("pre",{style:{margin:0,padding:"11px 13px",fontSize:12.5,lineHeight:1.62,overflowX:"auto",background:"color-mix(in srgb, var(--bg) 92%, var(--bg-panel))"},children:(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:e})}):(0,r.jsx)(eU.A,{language:t||"text",style:l?e_.xJ:e_.vs,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal"},customStyle:{margin:0,padding:"11px 13px",fontSize:12.5,lineHeight:1.62,borderRadius:0,background:"color-mix(in srgb, var(--bg) 92%, var(--bg-panel))"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})});function tt({children:e,className:t,isStreaming:n,cwd:o,onOpenFile:l}){let s=(0,i.useMemo)(()=>eP(e),[e]),a=(0,i.useMemo)(()=>({code({className:e,children:t,...i}){let o=e?.replace("language-","").toLowerCase()??"",l=String(t);return e?.includes("language-")||l.includes("\n")?"mermaid"===o?(0,r.jsx)(e7,{code:l.replace(/\n$/,""),isStreaming:n}):(0,r.jsx)(te,{code:l.replace(/\n$/,""),lang:o,isStreaming:n}):(0,r.jsx)("code",{className:"markdown-inline-code",...i,children:t})},pre:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),a({href:e,children:t,...n}){delete n.node;let i=l?eS(e,o):null;return i&&l?(0,r.jsx)("a",{href:e,...n,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),l(i))},children:t}):(0,r.jsx)("a",{href:e,...n,target:"_blank",rel:"noopener noreferrer",children:t})},img({src:e,alt:t,...n}){delete n.node;let i="string"==typeof e?eS(e,o):null,l=i?`/api/files/${L(i)}?type=read`:e;return(0,r.jsx)("img",{src:l,alt:t??"",loading:"lazy",...n})},table:({children:e})=>(0,r.jsx)("div",{className:"markdown-table-wrap",children:(0,r.jsx)("table",{children:e})})}),[o,n,l]);return(0,r.jsx)("div",{className:["markdown-body",t].filter(Boolean).join(" "),children:(0,r.jsx)(eT.oz,{remarkPlugins:eD,rehypePlugins:eH,components:a,children:s})})}function tn({src:e,alt:t="",children:n,className:o,style:l}){let{t:s}=(0,m.s)(),[a,d]=(0,i.useState)(!1),c=(0,i.useRef)(null),u=(0,i.useRef)(null),p=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!a)return;let e=u.current;if(!e)return;let t=c.current,n=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),p.current?.focus({preventScroll:!0}),()=>{document.body.style.overflow=n,e.open&&e.close(),t?.isConnected&&t.focus({preventScroll:!0})}},[a]);let h=()=>{u.current?.open&&u.current.close(),d(!1)};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:c,type:"button",className:o,style:{display:"block",padding:0,border:"none",background:"none",color:"inherit",cursor:"zoom-in",...l},onClick:()=>d(!0),"aria-label":s("chat.previewImage"),"aria-haspopup":"dialog","aria-expanded":a,title:s("chat.previewImage"),children:n}),a&&(0,r.jsxs)("dialog",{ref:u,className:"image-preview-dialog","aria-label":s("chat.previewImage"),onCancel:e=>{e.preventDefault(),e.stopPropagation(),h()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),h())},onClick:e=>{e.target===e.currentTarget&&h()},children:[(0,r.jsx)("img",{className:"image-preview-image",src:e,alt:t}),(0,r.jsx)("button",{ref:p,type:"button",className:"image-preview-close",onClick:h,"aria-label":s("chat.close"),title:s("chat.close"),children:(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})]})]})}let tr=/<(read-files|modified-files)>\s*([\s\S]*?)\s*<\/\1>/g,ti=/(?:\r?\n){2,}((?:[ \t]*<(?:read-files|modified-files)>[ \t]*\r?\n[\s\S]*?\r?\n[ \t]*<\/(?:read-files|modified-files)>[ \t]*(?:\r?\n)?)+)\s*$/;function to(e){let t,n=[],r=null,i=0,o=0,l=0,s=0,a=[],d=[],c=()=>({lineNo:null,text:"",type:"empty"}),u=()=>{if(!r){a=[],d=[];return}let e=Math.max(a.length,d.length);for(let t=0;t<e;t++){let e=a[t]?{lineNo:a[t].lineNo,text:a[t].text,type:"removed"}:c(),n=d[t]?{lineNo:d[t].lineNo,text:d[t].text,type:"added"}:c();r.rows.push({type:"line",left:e,right:n})}a=[],d=[]};for(let c of e.split(/\r?\n/)){if(!(l>0||s>0)){if(c.startsWith("--- ")){u(),t=tl(c.slice(4));continue}if(c.startsWith("+++ ")){u(),r={oldPath:t,newPath:tl(c.slice(4)),rows:[]},n.push(r);continue}}let e=c.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(e){r||(r={rows:[]},n.push(r)),u(),i=Number(e[1]),o=Number(e[3]),l=void 0===e[2]?1:Number(e[2]),s=void 0===e[4]?1:Number(e[4]),r.rows.push({type:"hunk",text:c});continue}if(!r)continue;if(c.startsWith("\\ ")){u(),r.rows.push({type:"hunk",text:c});continue}let p=c[0],h=c.slice(1);" "===p?(u(),r.rows.push({type:"line",left:{lineNo:i++,text:h,type:"context"},right:{lineNo:o++,text:h,type:"context"}}),l>0&&l--,s>0&&s--):"-"===p?(a.push({lineNo:i++,text:h}),l>0&&l--):"+"===p?(d.push({lineNo:o++,text:h}),s>0&&s--):""!==c&&(u(),r.rows.push({type:"hunk",text:c}))}u();let p=n.filter(e=>e.rows.some(e=>"line"===e.type));return p.length>0?p:null}function tl(e){return e.split(" ")[0].trim()}function ts({files:e,onOpenFile:t}){let{t:n}=(0,m.s)();return 0===e.length?null:(0,r.jsx)("div",{"aria-label":n("chat.filesWritten"),style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,marginTop:6},children:e.map(({filePath:e})=>{let i=W(e);return(0,r.jsxs)("button",{type:"button",title:e,"aria-label":n("chat.openWrittenFile",{name:i}),onClick:()=>t?.(e),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",fontSize:12,fontFamily:"var(--font-mono)",color:"var(--text)",background:"var(--bg-subtle)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer"},children:[M(i,12),(0,r.jsx)("span",{children:i})]},e)})})}let ta=/[\u3000-\u30ff\u3400-\u9fff\uf900-\ufaff\u{20000}-\u{2fa1f}\uac00-\ud7af]/u;function td(e){let t=0,n=0;for(let r of e)ta.test(r)?t++:n++;return t+n/4}let tc=new Map;function tu({children:e,className:t,...n}){let{t:o}=(0,m.s)(),[l,s]=(0,i.useState)(!1);if(e.length<=1e5)return(0,r.jsx)(tt,{className:t,...n,children:e});if(!l){var a;return(0,r.jsxs)("button",{onClick:()=>s(!0),style:{display:"block",width:"100%",margin:"4px 0",padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:["⚠ ",o("i18n.largeMessageReveal",{size:(a=e.length)>=1e6?`${(a/1e6).toFixed(1)} MB`:a>=1e3?`${Math.round(a/1e3)} KB`:`${a} B`})]})}return(0,r.jsx)("div",{className:t,style:{maxHeight:420,overflow:"auto",fontSize:12,lineHeight:1.5},children:(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)",color:"var(--text-muted)"},children:e})})}function tp(e){if(!e)return null;let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate(),i=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(r)return i;let o=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==n.getFullYear()?"numeric":void 0});return`${o} ${i}`}let th=(0,i.memo)(function({message:e,isStreaming:t,toolResults:n,modelNames:i,cwd:o,onOpenFile:l,entryId:s,onFork:a,forking:d,onNavigate:c,prevAssistantEntryId:u,onEditContent:p,showTimestamp:h,prevTimestamp:g,sessionId:x,writtenFiles:f}){return"user"===e.role?(0,r.jsx)(tg,{message:e,cwd:o,onOpenFile:l,entryId:s,onFork:a,forking:d,onNavigate:c,prevAssistantEntryId:u,onEditContent:p}):"assistant"===e.role?(0,r.jsx)(tx,{message:e,isStreaming:t,toolResults:n,modelNames:i,cwd:o,onOpenFile:l,showTimestamp:h,prevTimestamp:g,sessionId:x,entryId:s,writtenFiles:f}):"toolResult"===e.role?null:"custom"===e.role?"compaction"===e.customType?(0,r.jsx)(tT,{message:e}):(0,r.jsx)(tI,{message:e,cwd:o,onOpenFile:l}):"bashExecution"===e.role?(0,r.jsx)(tW,{message:e,sessionId:x}):null},(e,t)=>e.message===t.message&&e.isStreaming===t.isStreaming&&function(e,t,n){if(t===n||"assistant"!==e.role)return!0;for(let r of e.content??[])if("toolCall"===r.type&&t?.get(r.toolCallId)!==n?.get(r.toolCallId))return!1;return!0}(e.message,e.toolResults,t.toolResults)&&e.modelNames===t.modelNames&&e.cwd===t.cwd&&e.onOpenFile===t.onOpenFile&&e.entryId===t.entryId&&e.onFork===t.onFork&&e.forking===t.forking&&e.onNavigate===t.onNavigate&&e.prevAssistantEntryId===t.prevAssistantEntryId&&e.onEditContent===t.onEditContent&&e.showTimestamp===t.showTimestamp&&e.prevTimestamp===t.prevTimestamp&&e.sessionId===t.sessionId);function tg({message:e,cwd:t,onOpenFile:n,entryId:o,onFork:l,forking:s,onNavigate:a,prevAssistantEntryId:d,onEditContent:u}){let{t:p}=(0,m.s)(),[h,g]=(0,i.useState)(!1),[x,f]=(0,i.useState)(!1),[v,y]=(0,i.useState)(!1),b="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),k="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),w=c(b),j=w?.search(/\s/)??-1,S=w?-1===j?w:w.slice(0,j):"",C=w&&-1!==j?w.slice(j+1):"",T=tp(e.timestamp),R=!!o&&!!l,M=w??b,I=w?function(e,t){if("string"==typeof e.content)return{...e,content:t};let n=[],r=!1;for(let i of e.content){if("text"!==i.type){n.push(i);continue}r||(n.push({...i,text:t}),r=!0)}return r||n.unshift({type:"text",text:t}),{...e,content:n}}(e,w):e,L=k.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!b},children:k.map((e,t)=>{let n=e.source?"base64"===e.source.type?`data:${e.source.media_type};base64,${e.source.data}`:e.source.url??"":e.data?`data:${e.mimeType};base64,${e.data}`:"";return(0,r.jsx)(tn,{src:n,children:(0,r.jsx)("img",{src:n,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)"}})},t)})}),W=!!d&&!!a;return(0,r.jsxs)("div",{style:{marginBottom:16,display:"flex",flexDirection:"column",alignItems:"flex-end"},onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:6,maxWidth:"85%"},children:(0,r.jsx)("div",{style:{flex:1,minWidth:0,background:"var(--user-bg-glass)",backdropFilter:"blur(10px) saturate(140%)",WebkitBackdropFilter:"blur(10px) saturate(140%)",border:"1px solid var(--user-border-glass)",borderRadius:12,padding:"8px 12px",fontSize:14,lineHeight:1.6,color:"var(--text)",wordBreak:"break-word",maxHeight:300,overflowY:"auto"},children:w?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,minWidth:0},children:[L,(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,flexWrap:"wrap"},children:[(0,r.jsxs)("button",{onClick:()=>y(e=>!e),title:p(v?"i18n.collapse":"i18n.expand"),"aria-expanded":v,style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,padding:0,background:"none",border:"none",cursor:"pointer",color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:13,textAlign:"left"},children:[(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S}),(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.75,transform:v?"rotate(180deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),C&&(0,r.jsx)("span",{style:{color:"var(--text)",fontSize:14,lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word",minWidth:0,flex:1},children:C})]}),v&&(0,r.jsx)(tt,{className:"markdown-user-message",cwd:t,onOpenFile:n,children:b})]}):(0,r.jsxs)(r.Fragment,{children:[L,b&&(0,r.jsx)(tu,{className:"markdown-user-message",cwd:t,onOpenFile:n,children:b})]})})}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3},children:[(0,r.jsx)("div",{style:{display:"flex",gap:3,opacity:+!!h,pointerEvents:h?"auto":"none",transition:"opacity 0.12s"},children:(0,r.jsxs)("button",{onClick:()=>{e3(M).then(()=>{f(!0),setTimeout(()=>f(!1),1500)})},title:p("i18n.copyMessage"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:x?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{x||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{x||(e.currentTarget.style.color="var(--text-dim)")},children:[x?(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),p(x?"i18n.copied":"i18n.copy")]})}),(R||W)&&(0,r.jsxs)("div",{style:{display:"flex",gap:3,opacity:h||s?1:0,pointerEvents:h||s?"auto":"none",transition:"opacity 0.12s"},children:[W&&(0,r.jsxs)("button",{onClick:()=>{a(d),u?.(I)},title:p("i18n.editFromHereTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"15 10 20 15 15 20"}),(0,r.jsx)("path",{d:"M4 4v7a4 4 0 0 0 4 4h12"})]}),p("i18n.editFromHere")]}),R&&(0,r.jsxs)("button",{onClick:()=>{l(o)},disabled:s,title:p(s?"i18n.creatingSession":"i18n.newSessionTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:s?"var(--accent)":"var(--text-dim)",cursor:s?"not-allowed":"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{s||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{s||(e.currentTarget.style.color="var(--text-dim)")},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),p(s?"i18n.creating":"i18n.newSession")]})]}),T&&(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:T})]})]})}function tx({message:e,isStreaming:t,toolResults:n,modelNames:o,cwd:l,onOpenFile:s,showTimestamp:a,prevTimestamp:d,sessionId:c,entryId:u,writtenFiles:p}){var h;let g,x,f,{t:v}=(0,m.s)(),y=a?tp(e.timestamp):null,b=(0,i.useMemo)(()=>(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!ef(e,{isStreaming:t})),[e.content,t]),k=(0,i.useMemo)(()=>b.map(({block:e})=>e),[b]),w=ev(e,{isStreaming:t}),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!1),R=(0,i.useRef)(null),[M,I]=(0,i.useState)(null),L=(0,i.useRef)(b);L.current=b;let W=(0,i.useRef)(new Map),E=(0,i.useMemo)(()=>{if(!t)return W.current=new Map,0;let e=new Map,n=0;for(let{block:t,originalIndex:r}of b){let i="text"===t.type?t.text:"thinking"===t.type?t.thinking:"toolCall"===t.type?t.rawInput??JSON.stringify(t.input??{})??"":null;if(null===i)continue;let o=function(e,t){var n,r;if(!e||!t.startsWith(e.text))return td(t);let i=e.tokens,o=e.text.length;return o>0&&o<t.length&&(n=e.text.charCodeAt(o-1))>=55296&&n<=56319&&(r=t.charCodeAt(o))>=56320&&r<=57343&&(i-=1/4,o--),i+td(t.slice(o))}(W.current.get(r),i);e.set(r,{text:i,tokens:o}),n+=o}return W.current=e,n},[b,t]),z=(0,i.useRef)(E);z.current=E;let $=(0,i.useRef)(new Map),[P,F]=(0,i.useState)(new Map),N=(0,i.useMemo)(()=>{if(!e.timestamp||!d)return;let t=Math.round((e.timestamp-d)/1e3);return t>0?t:void 0},[e.timestamp,d]),A=(0,i.useMemo)(()=>{let t=new Map;if(!n||!e.timestamp)return t;for(let[r,i]of n)if(i.timestamp&&e.timestamp){let n=Math.round((i.timestamp-e.timestamp)/1e3);n>0&&t.set(r,n)}return t},[n,e.timestamp]),D=k.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if((0,i.useEffect)(()=>{if(!t){let e=new Date().getTime();F(t=>{let n=new Map(t);for(let[t,r]of $.current)n.has(t)||n.set(t,Math.round((e-r)/1e3));return n}),R.current=null,I(null);return}let e=setInterval(()=>{let e=L.current,t=Date.now();e.forEach(({originalIndex:e})=>{$.current.has(e)||$.current.set(e,t)}),F(n=>{let r=!1,i=new Map(n);for(let n=0;n<e.length-1;n++){let o=e[n].originalIndex,l=e[n+1].originalIndex;if(!i.has(o)&&$.current.has(o)){let e=$.current.get(o),n=$.current.get(l)??t;i.set(o,Math.round((n-e)/1e3)),r=!0}}return r?i:n});let n=z.current;if(0===n)return;null===R.current&&(R.current=t);let r=(t-R.current)/1e3;r>.5&&I(n/r)},300);return()=>clearInterval(e)},[t]),0===k.length&&!t&&!w)return null;return(0,r.jsx)("div",{style:{marginBottom:16},onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"10px 14px",borderRadius:12,background:"var(--assistant-card-glass)",backdropFilter:"blur(10px) saturate(140%)",WebkitBackdropFilter:"blur(10px) saturate(140%)",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)"},children:[(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-meta)",display:"flex",alignItems:"center",gap:6},children:[e.provider&&(0,r.jsx)("span",{children:o?.[`${e.provider}:${e.model}`]??o?.[e.model]??e.model}),t&&(x=Math.round(E),(0,r.jsx)(r.Fragment,{children:x>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--text)"},title:v("i18n.estimatedTokens"),children:[(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2,fontSize:11,fontWeight:400},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,r.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),x]}),null!==M&&(f=M>=50?"#53b3cb":M>=30?"#9bc53d":M>=15?"#f9c22e":"#e01a4f",(0,r.jsxs)("span",{style:{marginLeft:6,padding:"1px 6px",borderRadius:4,background:f,color:"#fff",fontSize:11,fontWeight:400},children:[M.toFixed(1)," t/s"]}))]})}))]}),(0,r.jsx)("div",{style:{height:1,background:"color-mix(in srgb, var(--border) 55%, transparent)",margin:"6px -14px 0"}}),b.map(({block:e,originalIndex:i})=>(0,r.jsx)(tf,{block:e,toolResults:n,isStreaming:t,streamingDuration:P.get(i)??("thinking"===e.type?N:void 0),toolCallDurations:A,cwd:l,onOpenFile:s,sessionId:c,entryId:u,blockIndex:i},`${u??"stream"}-${i}`)),w&&(0,r.jsxs)("div",{role:"alert",style:{marginTop:(b.length,0),padding:"7px 10px",border:"1px solid rgba(239,68,68,0.3)",borderRadius:6,background:"rgba(239,68,68,0.07)",color:"#ef4444",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:["Error: ",w]}),p&&p.length>0&&(0,r.jsx)(ts,{files:p,onOpenFile:s}),!t&&(e.usage||y||D)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{height:1,background:"color-mix(in srgb, var(--border) 55%, transparent)",margin:"2px -14px 0"}}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,paddingTop:2},children:[e.usage&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-meta)"},children:(h=e.usage,g=[],h.input&&g.push(`${h.input.toLocaleString()} in`),h.output&&g.push(`${h.output.toLocaleString()} out`),h.cacheRead&&g.push(`${h.cacheRead.toLocaleString()} cache R`),h.cacheWrite&&g.push(`${h.cacheWrite.toLocaleString()} cache W`),h.cost?.total&&g.push(`$${h.cost.total.toFixed(4)}`),g.join(" \xb7 "))}),D&&(0,r.jsxs)("button",{onClick:()=>{e3(D).then(()=>{T(!0),setTimeout(()=>T(!1),1500)})},title:v("i18n.copyMessage"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:C?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:+!!j,pointerEvents:j?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{C||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{C||(e.currentTarget.style.color="var(--text-dim)")},children:[C?(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),v(C?"i18n.copied":"i18n.copy")]}),y&&(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-meta)",marginLeft:"auto"},children:y})]})]})]})})}function tf({block:e,toolResults:t,isStreaming:n,streamingDuration:i,toolCallDurations:o,cwd:l,onOpenFile:s,sessionId:a,entryId:d,blockIndex:c}){if("text"===e.type)return(0,r.jsx)(tm,{block:e,isStreaming:n,cwd:l,onOpenFile:s});if("thinking"===e.type)return(0,r.jsx)(tv,{block:e,duration:i,sessionId:a,entryId:d,blockIndex:c});if("toolCall"===e.type){let n=t?.get(e.toolCallId),i=o?.get(e.toolCallId);return(0,r.jsx)(ty,{block:e,result:n,duration:i})}return null}function tm({block:e,isStreaming:t,cwd:n,onOpenFile:i}){return(0,r.jsx)(tu,{isStreaming:t,cwd:n,onOpenFile:i,children:e.text})}function tv({block:e,duration:t,sessionId:n,entryId:o,blockIndex:l}){let{t:s}=(0,m.s)(),[a,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(null),f=async()=>{let t=!a;if(d(t),t&&e.deferred&&null===c){if(!n||!o)return void x(s("i18n.thinkingUnavailable"));h(!0),x(null);try{u(await function(e,t,n){let r=`${e}:${t}:${n}`,i=tc.get(r);if(i)return tc.delete(r),tc.set(r,i),i;let o=fetch(`/api/sessions/${encodeURIComponent(e)}/entries/${encodeURIComponent(t)}/thinking?blockIndex=${n}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if("string"!=typeof t.thinking)throw Error("Invalid thinking response");return t.thinking}).catch(e=>{throw tc.delete(r),e});if(tc.set(r,o),tc.size>100){let e=tc.keys().next().value;e&&tc.delete(e)}return o}(n,o,l))}catch(e){x(e instanceof Error?e.message:String(e))}finally{h(!1)}}};return(0,r.jsxs)("div",{style:{border:"1px solid color-mix(in srgb, var(--border) 50%, transparent)",borderRadius:10,overflow:"hidden",fontSize:13,background:"color-mix(in srgb, var(--tool-bg-glass) 62%, transparent)",boxShadow:"0 1px 3px rgba(15,23,42,0.05)"},children:[(0,r.jsxs)("button",{onClick:()=>void f(),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"7px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,r.jsx)("span",{children:s("i18n.thinking")}),void 0!==t&&(0,r.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]})]}),a&&(0,r.jsx)("div",{style:{padding:"8px 10px",color:g?"#f87171":"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",background:"color-mix(in srgb, var(--tool-bg-glass) 66%, transparent)",borderTop:"1px solid color-mix(in srgb, var(--border) 45%, transparent)"},children:p?s("i18n.loadingThinking"):g??(e.deferred?c:e.thinking)})]})}function ty({block:e,result:t,duration:n}){var o;let{t:l}=(0,m.s)(),[s,a]=(0,i.useState)(!1),d=(o=e).rawInput??JSON.stringify(o.input,null,2),c=void 0!==e.rawInput,u=eC(e.toolName),p=t&&!t.isError?function(e){var t;let n=e.details;if(!("object"==typeof(t=n)&&null!==t&&!Array.isArray(t)))return null;let r="string"==typeof n.patch?n.patch:null;if(r)return{text:r};let i="string"==typeof n.diff?n.diff:null;return i?{text:i}:null}(t):null,h=t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,g=null!==h&&("(no output)"===h.trim()||""===h.trim()),x=t?.isError??!1;return(0,r.jsxs)("div",{style:{borderRadius:7,overflow:"hidden",fontSize:12,border:x?"1px solid rgba(248,113,113,0.45)":"1px solid rgba(34,197,94,0.25)",background:x?"rgba(248,113,113,0.05)":"rgba(34,197,94,0.04)"},children:[(0,r.jsxs)("button",{onClick:()=>a(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",minWidth:0},children:[(0,r.jsx)("span",{style:{color:x?"#f87171":"#16a34a",fontFamily:"var(--font-mono)",fontWeight:600,fontSize:11,flexShrink:0},children:e.toolName}),(0,r.jsx)("span",{style:{color:"var(--text-meta)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:c?l("chat.generatingToolInput"):function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let n=Object.keys(t);return 0===n.length?"":"command"in t?String(t.command).slice(0,120):"path"in t?String(t.path).slice(0,120):"file_path"in t?String(t.file_path).slice(0,120):"pattern"in t?String(t.pattern).slice(0,120):"query"in t?String(t.query).slice(0,120):String(t[n[0]]).slice(0,120)}(e)}),void 0!==n&&(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[n,"s"]}),(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:s?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),s&&(c||!u)&&(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",background:"var(--bg-subtle)",borderTop:x?"1px solid rgba(248,113,113,0.25)":"1px solid rgba(34,197,94,0.2)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:d}),s&&t&&(p?(0,r.jsx)(tb,{diff:p}):(0,r.jsx)(tC,{text:h??"",isEmpty:g,isError:x}))]})}function tb({diff:e}){return(0,r.jsx)("div",{style:{borderTop:"1px solid rgba(34,197,94,0.15)",background:"var(--bg)"},children:(0,r.jsx)(tk,{text:e.text})})}function tk({text:e}){let{t}=(0,m.s)(),n=(0,i.useMemo)(()=>to(e),[e]);if(!n)return(0,r.jsx)(tS,{text:e});let o=n.length>1;return(0,r.jsx)("div",{style:{maxHeight:560,overflowY:"auto",overflowX:"hidden",background:"var(--bg)"},children:n.map((e,n)=>(0,r.jsxs)("div",{style:{minWidth:0,borderTop:0===n?"none":"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55},children:[o&&(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",position:"sticky",top:0,zIndex:1,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)(tw,{title:e.oldPath||t("i18n.before"),side:"left"}),(0,r.jsx)(tw,{title:e.newPath||t("i18n.after"),side:"right"})]}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)"},children:e.rows.map((e,t)=>"hunk"===e.type?null:(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)(tj,{cell:e.left,side:"left"}),(0,r.jsx)(tj,{cell:e.right,side:"right"})]},t))})]},n))})}function tw({title:e,side:t}){return(0,r.jsx)("div",{title:e,style:{padding:"5px 10px",color:"var(--text-dim)",borderRight:"left"===t?"1px solid var(--border)":"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})}function tj({cell:e,side:t}){let n="added"===e.type?"rgba(34,197,94,0.12)":"removed"===e.type?"rgba(248,113,113,0.13)":"empty"===e.type?"var(--bg-subtle)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",o="added"===e.type?"#22c55e":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",minWidth:0,background:n,borderRight:"left"===t?"1px solid var(--border)":"none"},children:[(0,r.jsx)("span",{style:{width:42,padding:"0 6px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",flexShrink:0},children:e.lineNo??""}),(0,r.jsx)("span",{style:{width:18,padding:"0 5px",color:o,userSelect:"none",fontWeight:"context"===e.type||"empty"===e.type?400:700,flexShrink:0},children:i}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 10px 0 0",color:"empty"===e.type?"var(--text-dim)":"var(--text)",whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:e.text||"\xa0"})]})}function tS({text:e}){let t=e.split(/\r?\n/);return(0,r.jsx)("div",{style:{maxHeight:520,overflowY:"auto",overflowX:"hidden",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:0},children:t.map((e,t)=>{let n=e.startsWith("@@")?"hunk":e.startsWith("+")&&!e.startsWith("+++")?"added":e.startsWith("-")&&!e.startsWith("---")?"removed":"context";return(0,r.jsxs)("div",{style:{display:"flex",background:"added"===n?"rgba(34,197,94,0.12)":"removed"===n?"rgba(248,113,113,0.13)":"hunk"===n?"rgba(96,165,250,0.12)":"transparent",borderLeft:"added"===n?"3px solid #22c55e":"removed"===n?"3px solid #f87171":"hunk"===n?"3px solid var(--accent)":"3px solid transparent"},children:[(0,r.jsx)("span",{style:{width:48,padding:"0 8px",color:"var(--text-dim)",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",textAlign:"right",userSelect:"none",flexShrink:0},children:t+1}),(0,r.jsx)("span",{style:{padding:"0 10px",whiteSpace:"pre-wrap",overflowWrap:"anywhere",color:"added"===n?"#22c55e":"removed"===n?"#f87171":"hunk"===n?"var(--accent)":"var(--text)"},children:e||"\xa0"})]},t)})})}function tC({text:e,isEmpty:t,isError:n}){let{t:i}=(0,m.s)();return(0,r.jsx)("div",{style:{borderTop:`1px solid ${n?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:n?"rgba(248,113,113,0.04)":"var(--bg-subtle)"},children:(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:n?"#f87171":t?"var(--text-dim)":"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",maxHeight:400,background:"var(--bg)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontStyle:t?"italic":"normal",opacity:t?.6:1},children:t?i("i18n.noOutput"):e})})}function tT({message:e}){let{t}=(0,m.s)(),n=tL(e.content),o=(0,i.useMemo)(()=>{let e,t,r,i,o;return e=[],t=[],r=n.match(ti),i=r?.[1]??"",o=r?.index===void 0?n:n.slice(0,r.index),i.replace(tr,(n,r,i)=>{let o=i.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return"read-files"===r?e.push(...o):t.push(...o),""}),{body:o.trim(),readFiles:e,modifiedFiles:t}},[n]),l=tp(e.timestamp);return(0,r.jsx)("div",{style:{marginBottom:16},children:(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:"compaction"}),l&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:l})]}),(0,r.jsxs)("div",{style:{padding:"11px 13px 12px"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700,lineHeight:1.35},children:t("i18n.conversationCompacted")}),(0,r.jsx)("div",{style:{marginTop:3,marginBottom:10,color:"var(--text)",fontSize:14,lineHeight:1.5},children:t("i18n.compactionDescription")}),o.body?(0,r.jsx)(tt,{className:"markdown-compaction-message",children:o.body}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:t("i18n.noSummary")}),(0,r.jsx)(tR,{readFiles:o.readFiles,modifiedFiles:o.modifiedFiles})]})]})})}function tR({readFiles:e,modifiedFiles:t}){let{t:n}=(0,m.s)();if(0===e.length+t.length)return null;let i=[];return e.length>0&&i.push(`${e.length} read`),t.length>0&&i.push(`${t.length} modified`),(0,r.jsxs)("details",{className:"compaction-file-details",children:[(0,r.jsx)("summary",{children:n("i18n.fileContext",{details:i.join(", ")})}),t.length>0&&(0,r.jsx)(tM,{title:n("i18n.modifiedFiles"),files:t}),e.length>0&&(0,r.jsx)(tM,{title:n("i18n.readFiles"),files:e})]})}function tM({title:e,files:t}){return(0,r.jsxs)("div",{className:"compaction-file-section",children:[(0,r.jsx)("div",{className:"compaction-file-title",children:e}),(0,r.jsx)("ul",{className:"compaction-file-list",children:t.map(e=>(0,r.jsx)("li",{children:e},e))})]})}function tI({message:e,cwd:t,onOpenFile:n}){var o;let l,{t:s}=(0,m.s)(),a=!1===e.display,[d,c]=(0,i.useState)(!a),[u,p]=(0,i.useState)(!1),[h,g]=(0,i.useState)(!1),x=tL(e.content),f="string"==typeof(o=e.content)?[]:o.filter(e=>"image"===e.type),v=void 0!==e.details,y=v?function(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.details):"",b=e.customType||"extension",k=tp(e.timestamp);return(0,r.jsx)("div",{style:{marginBottom:16},children:(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:a?"var(--bg-subtle)":"var(--bg)",opacity:a&&!d?.82:1},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:b}),a&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s("i18n.hiddenExtensionMessage")}),k&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:k})]}),d?(0,r.jsxs)("div",{style:{padding:"6px 9px"},children:[f.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!x},children:f.map((e,t)=>{var n;let i=(n=e).source?"base64"===n.source.type?`data:${n.source.media_type};base64,${n.source.data}`:n.source.url??"":n.data?`data:${n.mimeType};base64,${n.data}`:"";return i?(0,r.jsx)(tn,{src:i,children:(0,r.jsx)("img",{src:i,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})},t):null})}),x?(0,r.jsx)(tt,{className:"markdown-custom-message",cwd:t,onOpenFile:n,children:x}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:s("i18n.noMessage")})]}):(0,r.jsx)("button",{onClick:()=>c(!0),style:{display:"block",width:"100%",padding:"8px 10px",border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",fontSize:12,textAlign:"left"},children:x?(l=x.replace(/\s+/g," ").trim())?l.length>140?`${l.slice(0,140)}...`:l:"Show extension message":s("i18n.showExtensionMessage")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 9px",borderTop:"1px solid var(--border)",background:"var(--bg-subtle)"},children:[x||y?(0,r.jsx)("button",{onClick:()=>{e3(x||y).then(()=>{g(!0),setTimeout(()=>g(!1),1500)})},style:{padding:"3px 7px",border:"none",background:"none",color:h?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11},children:s(h?"i18n.copied":"i18n.copy")}):null,(v||a)&&(0,r.jsx)("button",{onClick:()=>{a?c(e=>!e):p(e=>!e)},style:{marginLeft:"auto",padding:"3px 7px",border:"none",background:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11},children:s(a?d?"i18n.collapse":"i18n.expand":u?"i18n.hideDetails":"i18n.showDetails")})]}),v&&(a&&d||!a&&u)&&(0,r.jsx)("pre",{style:{margin:0,padding:"9px 10px",borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:360,overflow:"auto",fontFamily:"var(--font-mono)"},children:y})]})})}function tL(e){return"string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n")}function tW({message:e,sessionId:t}){let[n,o]=(0,i.useState)(null),[l,s]=(0,i.useState)(!1),[a,d]=(0,i.useState)(null),c=!e.output&&void 0===e.exitCode&&!e.cancelled,u=e.cancelled||void 0!==e.exitCode&&0!==e.exitCode,p=t&&e.fullOutputPath?`/api/agent/${encodeURIComponent(t)}/bash-output?path=${encodeURIComponent(e.fullOutputPath)}`:null,h=e.truncated&&p&&null===n,g=n??e.output;async function x(){if(p){s(!0),d(null);try{let e=await fetch(p),t=await e.json();t.success?o(t.data?.output??""):d(t.error??"failed")}catch(e){d(String(e))}finally{s(!1)}}}let f=e.excludeFromContext?"bash (local)":"bash",m={type:"toolCall",toolCallId:`bash-${e.timestamp??""}`,toolName:f,input:{command:e.command}},v=c?void 0:{role:"toolResult",toolCallId:m.toolCallId,toolName:f,content:g?[{type:"text",text:g}]:[],isError:u,timestamp:e.timestamp};return(0,r.jsxs)("div",{style:{margin:"6px 0"},children:[(0,r.jsx)(ty,{block:m,result:v}),e.truncated&&p&&(0,r.jsxs)("div",{style:{padding:"4px 10px",fontSize:11,marginTop:-1},children:[h&&(0,r.jsx)("button",{onClick:x,disabled:l,style:{background:"none",border:"none",color:"var(--accent)",cursor:l?"default":"pointer",fontSize:11,padding:0,textDecoration:"underline"},children:l?"loading…":"view full output"}),(0,r.jsx)("a",{href:`${p}&download=1`,style:{marginLeft:10*!!h,color:"var(--accent)",fontSize:11,textDecoration:"underline"},children:"download full output"}),a&&(0,r.jsxs)("span",{style:{marginLeft:6,color:"var(--text-dim)",fontSize:11},children:["(",a,")"]})]})]})}function tE(e){if(!e||"object"!=typeof e||"string"!=typeof e.data||"string"!=typeof e.mimeType||!e.mimeType.startsWith("image/"))return!1;let t=function(e){if(!e||e.length%4!=0)return null;let t=e.endsWith("==")?2:+!!e.endsWith("="),n=e.length-t;for(let t=0;t<n;t+=1){var r;if(!((r=e.charCodeAt(t))>=65&&r<=90||r>=97&&r<=122||r>=48&&r<=57||43===r||47===r))return null}for(let t=n;t<e.length;t+=1)if("="!==e[t])return null;return e.length/4*3-t}(e.data);return null!==t&&t<=0xa00000}let tz=new Map;function t$(e){return{value:e.value,images:e.images.map(e=>({...e}))}}function tP(e){return!e.value&&0===e.images.length}function tF(e){let t=tz.get(e);return t?t$(t):null}function tN(e,t){tP(t)?tz.delete(e):tz.set(e,t$(t))}function tA(e){tz.delete(e)}function tD(e,t){return e.trim()?t.trim()?`${e}
|
|
3
|
+
|
|
4
|
+
${t}`:e:t}function tB(e,t,n,r){let i=[...t??[],...r].filter(tE).slice(0,10).map(({data:e,mimeType:t})=>({data:e,mimeType:t}));return{value:tD(e,n),images:i}}function tH(e,t,n){if(e===t)return n?t$(n):tF(t);let r=tF(e),i=n&&!tP(n)?t$(n):r??(n?t$(n):null),o=tF(t);if(tA(e),!i)return o;let l=o?tB(o.value,o.images,i.value,i.images):i;return tN(t,l),t$(l)}function tO(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let n=/(?:^|\s)@([^\s"]*)$/.exec(e);return n?{start:e.length-(n[1].length+1),query:n[1],quoted:!1}:null}function tU(e){let t=0;for(let n=0;n<e.length;n++)"/"===e[n]&&t++;return t}function t_(e,t){if(!e)return!0;let n=0;for(let r=0;r<t.length&&n<e.length;r++)t[r]===e[n]&&n++;return n===e.length}function tq(e,t){let n=t?`${e}/`:e;return n.includes(" ")?`@"${n}" `:`@${n} `}let tK="(max-width: 640px)";function tV(e){if(!window.matchMedia)return()=>{};let t=window.matchMedia(tK);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)}function tY(){return!!window.matchMedia&&window.matchMedia(tK).matches}function tJ(){return!1}function tZ(){return(0,i.useSyncExternalStore)(tV,tY,tJ)}let tG=["off","read-only","default","full"],tX={off:"none","read-only":"read-only",default:"default",full:"full"},tQ=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function t0(e,t){return tQ.compare(e.name||e.modelId,t.name||t.modelId)||tQ.compare(e.provider,t.provider)||tQ.compare(e.modelId,t.modelId)}let t1=["auto","off","minimal","low","medium","high","xhigh","max"],t2={auto:"chat.thinkingUseDefault",off:"chat.thinkingOff",minimal:"chat.thinkingMinimal",low:"chat.thinkingLow",medium:"chat.thinkingMedium",high:"chat.thinkingHigh",xhigh:"chat.thinkingXhigh",max:"chat.thinkingMax"};function t8(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}let t4=[{name:"compact",description:"chat.commandCompact",source:"builtin"},{name:"reload",description:"chat.commandReload",source:"builtin"},{name:"name",description:"chat.commandName",source:"builtin"},{name:"session",description:"chat.commandSession",source:"builtin"},{name:"copy",description:"chat.commandCopy",source:"builtin"}],t6=["builtin","extension","prompt","skill"],t5={builtin:"chat.builtIn",extension:"chat.extensions",prompt:"chat.prompts",skill:"chat.skills"},t3={builtin:0,extension:1,prompt:2,skill:3};function t7(e,t,n){let r=e.name.toLowerCase(),i=t9(e,n).toLowerCase();return r===t?0:r.startsWith(t)?1:r.includes(t)?2:i.includes(t)?3:4}function t9(e,t){return"builtin"===e.source?t(e.description):e.description??""}function ne(e,t){return"skill"===e.source&&!!e.name.startsWith("skill:")&&!0===t[e.name.slice(6)]}function nt(e){return{data:e.data,mimeType:e.mimeType}}function nn(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function nr(e){return(e??[]).filter(tE).slice(0,10).map(nn)}function ni(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function no({kind:e,text:t}){return(0,r.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",padding:"1px 7px",borderRadius:999,border:`1px solid ${"steer"===e?"color-mix(in srgb, var(--accent) 45%, transparent)":"var(--border)"}`,color:"steer"===e?"var(--accent)":"var(--text-dim)"},children:e}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})}function nl({tone:e,title:t,body:n}){let i="error"===e?"239,68,68":"234,179,8";return(0,r.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"flex-start",gap:8,maxHeight:120,marginBottom:8,padding:"7px 10px",overflowY:"auto",border:`1px solid rgba(${i},0.3)`,borderRadius:6,background:`rgba(${i},0.07)`,color:`rgb(${i})`,fontSize:11,lineHeight:1.45},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:1},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M10.3 2.9 1.8 17a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 2.9a2 2 0 0 0-3.4 0Z"}),(0,r.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,r.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontWeight:600},children:t}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:n})]})]})}function ns({error:e}){return e?(0,r.jsx)(nl,{tone:"error",title:"Model error",body:e}):null}function na({warnings:e}){return e&&0!==e.length?(0,r.jsx)(nl,{tone:"warning",title:e.length>1?"Model scope warnings":"Model scope warning",body:e.join("\n")}):null}let nd=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:n,onFollowUp:o,isStreaming:l,model:s,isAutoModelSelection:a,modelNames:d,modelList:c,modelError:u,modelScopeWarnings:p,onModelChange:h,modelSwitching:g,onCompact:x,onAbortCompaction:f,isCompacting:v,compactError:y,compactResult:b,toolPreset:k,onToolPresetChange:w,thinkingLevel:j,onThinkingLevelChange:S,availableThinkingLevels:T,thinkingLevelMap:R,retryInfo:I,queuedMessages:L,inputHistory:W=[],onRecallQueue:E,slashCommands:z,slashCommandsLoading:$,onLoadSlashCommands:P,onBuiltinCommand:F,soundEnabled:N,onSoundToggle:A,onAudioUnlock:D,onPromptWithStreamingBehavior:B,draftKey:H,cwd:O,atBottom:U=!0,onScrollToBottom:_},q){let K,V,Y,J,Z,G,X,Q,ee,et,en,{t:er}=(0,m.s)(),ei=tZ(),[eo,el]=(0,i.useState)(()=>H?tF(H)?.value??"":""),[es,ea]=(0,i.useState)(!1),[ed,ec]=(0,i.useState)(null),[eu,ep]=(0,i.useState)(""),[eh,eg]=(0,i.useState)(!1),[ex,ef]=(0,i.useState)(!1),[em,ev]=(0,i.useState)(!1),[ey,eb]=(0,i.useState)(()=>H?nr(tF(H)?.images):[]),ek=eo.trimStart(),ew=0===ey.length&&ek.startsWith("!"),ej=ew&&ek.startsWith("!!"),[eS,eC]=(0,i.useState)(!1),[eT,eR]=(0,i.useState)(0),[eM,eI]=(0,i.useState)(null),[eL,eW]=(0,i.useState)(null),[eE,ez]=(0,i.useState)(!1),[e$,eP]=(0,i.useState)(0),[eF,eN]=(0,i.useState)(!1),[eA,eD]=(0,i.useState)(0),[eB,eH]=(0,i.useState)(null),[eO,eU]=(0,i.useState)(!1),[e_,eq]=(0,i.useState)(null),[eK,eV]=(0,i.useState)(null),eY=O&&eK?.cwd===O?eK.values:{},eJ=(0,i.useRef)(null),eZ=(0,i.useRef)(null),eG=(0,i.useRef)(null),eX=(0,i.useRef)(null),eQ=(0,i.useRef)(null),e0=(0,i.useRef)(null),e1=(0,i.useRef)(null),e2=(0,i.useRef)(null),e8=(0,i.useRef)(!1),e4=(0,i.useRef)(0),e6=(0,i.useRef)(!1),e5=(0,i.useRef)(null),e3=(0,i.useRef)([]),e7=(0,i.useRef)([]),e9=(0,i.useRef)([]),te=(0,i.useRef)(null),tt=(0,i.useRef)(null),tn=(0,i.useRef)(H),tr=(0,i.useRef)(eo),ti=(0,i.useRef)(ey),to=(0,i.useRef)(0);tr.current=eo,ti.current=ey,(0,i.useImperativeHandle)(q,()=>({insertIfEmpty(e){let t=eJ.current;(t?t.value:eo).trim()||(tr.current=e,el(e),eW(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},replaceMessage(e){var t,n,r;let i=eJ.current;if(t=i?i.value:eo,n=ti.current.length,r=to.current,t.trim()||0!==n||0!==r)return;let o="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),l=nr("string"==typeof e.content?[]:e.content.flatMap(e=>{if("image"!==e.type)return[];let t=e.source?.type==="base64"?e.source.data:e.data,n=e.source?.type==="base64"?e.source.media_type:e.mimeType;if("string"!=typeof t||"string"!=typeof n)return[];let r={data:t,mimeType:n};return tE(r)?[r]:[]}));tr.current=o,ti.current=l,el(o),eW(null),eN(!1),eb(e=>(e.forEach(ni),l)),requestAnimationFrame(()=>{i&&(i.focus(),i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight,200)}px`)})},prependText(e){if(!e.trim())return;let t=eJ.current,n=[e,t?t.value:eo].filter(e=>e.trim()).join("\n\n");tr.current=n,el(n),eW(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(n.length,n.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},rekeyDraft(e,t){if(e===t)return;if(tn.current!==e)return void tH(e,t);let n={value:tr.current,images:ti.current.map(nt)},r=tH(e,t,n)??{value:"",images:[]},i=r.value===n.value&&r.images.length===n.images.length&&r.images.every((e,t)=>e.data===n.images[t]?.data&&e.mimeType===n.images[t]?.mimeType);if(tn.current=t,i)return;let o=nr(r.images);tr.current=r.value,ti.current=o,el(r.value),eb(e=>(e.forEach(ni),o)),eW(null),eN(!1)},restoreSubmission(e,t,n){if(!e.trim()&&!t?.length)return;let r=tn.current,i=n??r,o=i===r,l=!o&&i?tF(i):null,s=tB(e,t,o?tr.current:l?.value??"",o?ti.current.map(nt):l?.images??[]);if(i&&tN(i,s),!o)return;let a=t?.length?[...nr(t).slice(0,Math.max(0,10-ti.current.length)),...ti.current].slice(0,10):ti.current;tr.current=s.value,ti.current=a,el(t=>{let n=tD(e,t);return tr.current=n,n}),eW(null),eN(!1),t?.length&&eb(e=>{let n=Math.max(0,10-e.length),r=nr(t).slice(0,n),i=r.length>0?[...r,...e]:e;return ti.current=i,i}),requestAnimationFrame(()=>{let e=eJ.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},insertText(e){let t=eJ.current;if(!t)return void el(t=>t+(t?" ":"")+e);let n=t.selectionStart??t.value.length,r=t.selectionEnd??t.value.length,i=t.value.slice(0,n),o=t.value.slice(r),l=i.length>0&&!i.endsWith(" ")?" ":"",s=i+l+e+o;tr.current=s,el(s),eW(null),requestAnimationFrame(()=>{if(!t)return;let r=n+l.length+e.length;t.setSelectionRange(r,r),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},addImages(e){tl(e)}}));let tl=(0,i.useCallback)(async e=>{let t=Math.max(0,10-ti.current.length-to.current),n=e.filter(e=>e.type.startsWith("image/")&&e.size<=0xa00000).slice(0,t);if(n.length){to.current+=n.length;try{let e=await Promise.all(n.map(e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let n=r.result.split(",")[1];t({data:n,mimeType:e.type,previewUrl:URL.createObjectURL(e)})},r.onerror=n,r.readAsDataURL(e)})));eb(t=>{let n=e.slice(0,Math.max(0,10-t.length));e.slice(n.length).forEach(ni);let r=[...t,...n];return ti.current=r,r})}finally{to.current-=n.length}}},[]),ts=(0,i.useCallback)(e=>{eb(t=>{let n=[...t],[r]=n.splice(e,1);return r&&ni(r),ti.current=n,n})},[]),ta=(0,i.useCallback)(()=>{ti.current=[],eb(e=>(e.forEach(ni),[]))},[]),td=(0,i.useCallback)(()=>{tr.current="",el(""),eW(null),eN(!1),H&&tA(H),tn.current&&tn.current!==H&&tA(tn.current),ta(),eJ.current&&(eJ.current.style.height="auto")},[ta,H]);(0,i.useEffect)(()=>{H&&tn.current===H&&tN(H,{value:eo,images:ey.map(nt)})},[ey,H,eo]),(0,i.useEffect)(()=>{let e=tn.current;if(e===H)return;e&&tN(e,{value:tr.current,images:ti.current.map(nt)});let t=H?tF(H):null;tn.current=H;let n=t?.value??"",r=nr(t?.images);tr.current=n,ti.current=r,el(n),eW(null),eN(!1),eb(e=>(e.forEach(ni),r))},[H]),(0,i.useEffect)(()=>{let e=eJ.current;e&&(e.style.height="auto",eo&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[eo]),(0,i.useEffect)(()=>()=>{ti.current.forEach(ni)},[]);let tc=(0,i.useCallback)(async()=>{let t=eo.trim();if((t||ey.length)&&!l){if(D?.(),!ey.length&&t.startsWith("/")&&F){let e=await F(t);if(e.handled){e.error||td();return}}td(),e(t,ey.length?ey:void 0)}},[eo,ey,l,F,e,td,D]),tu=eo.startsWith("/")&&!/\s/.test(eo.slice(1))?eo.slice(1).toLowerCase():null,tp=null===tu?[]:[...l?[]:t4,...z??[]].filter(e=>{let t=e.name.toLowerCase(),n=t9(e,er).toLowerCase();return t.includes(tu)||n.includes(tu)}).sort((e,t)=>{let n=t7(e,tu,er)-t7(t,tu,er);return 0!==n?n:t3[e.source]-t3[t.source]||tQ.compare(e.name,t.name)}),{commands:th,groups:tg}=(K=0,{commands:(V=t6.map(e=>{let t=tp.filter(t=>t.source===e),n="skill"===e?[...t.filter(e=>!ne(e,eY)),...t.filter(e=>ne(e,eY))]:t;return{source:e,items:n.map(e=>({command:e,index:K++}))}}).filter(e=>e.items.length>0)).flatMap(e=>e.items.map(({command:e})=>e)),groups:V}),tx=1===tp.length?er(tu?"chat.match":"chat.command"):er(tu?"chat.matches":"chat.commands",{count:tp.length}),tf=!!eo.trim()||ey.length>0,tm=(0,i.useCallback)((e,t)=>{if(!O)return void eW(null);let n=t??e.length;eW(tO(e.slice(0,n)))},[O]),tv=eL?.query??null,ty=i.useMemo(()=>null!==tv&&eB&&eB.cwd===O?function(e,t,n=20){let r=t.toLowerCase();if(!r)return e.slice(0,n);let i=[];for(let t of e){let e=function(e,t){let n=e.path.toLowerCase(),r=0;if(t.includes("/"))n===t?r=100:n.startsWith(t)?r=80:n.includes(t)?r=50:t_(t,n)&&(r=10);else{let e=n.lastIndexOf("/"),i=-1===e?n:n.slice(e+1);i===t?r=100:i.startsWith(t)?r=80:i.includes(t)?r=50:n.includes(t)?r=30:t_(t,n)&&(r=10)}return e.isDir&&r>0&&(r+=10),r}(t,r);e>0&&i.push({entry:t,score:e})}return i.sort((e,t)=>t.score-e.score||tU(e.entry.path)-tU(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),i.slice(0,n).map(e=>e.entry)}(eB.entries,tv):[],[tv,eB,O]),tb=!!(tv&&eB?.truncated&&eB.cwd===O);(0,i.useEffect)(()=>{if(!tb||!O||!tv)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(O)}&q=${encodeURIComponent(tv)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>eq({cwd:O,query:tv,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[tb,tv,O]);let tk=tb&&null!==e_&&e_.cwd===O&&e_.query===tv,tw=tk?e_.matches:ty,tj=null===eL?null:`${eL.start}:${+!!eL.quoted}:${eL.query}`;(0,i.useEffect)(()=>{if(null===tj){ez(!1),eP(0);return}ez(!0),eP(0)},[tj]);let tS=null!==eL;(0,i.useEffect)(()=>{if(!tS||!O)return;let e=te.current;e&&e.cwd===O&&Date.now()-e.fetchedAt<1e4||tt.current===O||(tt.current=O,eU(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(O)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{eH({cwd:O,entries:function(e){let t=new Set;for(let n of e){let e=n.indexOf("/");for(;-1!==e;)t.add(n.slice(0,e)),e=n.indexOf("/",e+1)}let n=[];for(let e of t)n.push({path:e,isDir:!0});for(let t of e)t&&n.push({path:t,isDir:!1});return n.sort((e,t)=>tU(e.path)-tU(t.path)||e.path.localeCompare(t.path)),n}(e.files??[]),truncated:!!e.truncated}),te.current={cwd:O,fetchedAt:Date.now()}}).catch(()=>{te.current=null}).finally(()=>{tt.current=null,eU(!1)}))},[tS,O]);let tC=(0,i.useCallback)(e=>{if(!eL)return;let t=eJ.current,n=t?.selectionStart??eo.length,r=eo.slice(0,eL.start),i=eo.slice(n);eL.quoted&&i.startsWith('"')&&(i=i.slice(1));let o=function(e,t,n=!1){let r=t?`${e}/`:e,i=n||r.includes(" ");if(t){let e=i?`@"${r}"`:`@${r}`;return{text:e,cursorOffset:i?e.length-1:e.length}}let o=i?`@"${r}" `:`@${r} `;return{text:o,cursorOffset:o.length}}(e.path,e.isDir,eL.quoted),l=r+o.text+i,s=r.length+o.cursorOffset;el(l),eW(tO(l.slice(0,s))),requestAnimationFrame(()=>{let e=eJ.current;e&&(e.focus(),e.setSelectionRange(s,s),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[eL,eo]);(0,i.useEffect)(()=>{e$>=tw.length&&eP(Math.max(0,tw.length-1))},[tw.length,e$]),(0,i.useEffect)(()=>{e7.current.length=tw.length},[tw.length]),(0,i.useEffect)(()=>{eE&&e7.current[e$]?.scrollIntoView({block:"nearest",inline:"nearest"})},[e$,eE]),(0,i.useEffect)(()=>{eA>=W.length&&eD(Math.max(0,W.length-1))},[W.length,eA]),(0,i.useEffect)(()=>{e9.current.length=W.length},[W.length]),(0,i.useEffect)(()=>{eF&&e9.current[eA]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eA,eF]);let tT=(0,i.useCallback)(e=>{el(e),eN(!1),eD(0),eW(null),requestAnimationFrame(()=>{let t=eJ.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},[]),tR=(0,i.useCallback)(e=>{let t=`/${e.name} `;el(t),eC(!1),eR(0),requestAnimationFrame(()=>{let e=eJ.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),tM=(0,i.useCallback)(e=>{let t=eo.trim();if(t||ey.length){if(D?.(),t.startsWith("/")&&B){td(),B(t,"steer"===e?"steer":"followUp",ey.length?ey:void 0);return}td(),"steer"===e&&n?n(t,ey.length?ey:void 0):"followup"===e&&o&&o(t,ey.length?ey:void 0)}},[eo,ey,B,n,o,td,D]),tI=(0,i.useCallback)(e=>{let t=th.length-1;if(t<0)return 0;if("left"===e)return Math.max(0,eT-1);if("right"===e)return Math.min(t,eT+1);let n=e3.current[eT];if(!n)return"down"===e?Math.min(t,eT+1):Math.max(0,eT-1);let r=n.getBoundingClientRect(),i=r.left+r.width/2,o=r.top+r.height/2,l=-1,s=1/0;for(let n=0;n<=t;n+=1){if(n===eT)continue;let t=e3.current[n];if(!t)continue;let r=t.getBoundingClientRect(),a=r.top+r.height/2-o;if("down"===e?a<=4:a>=-4)continue;let d=1e3*Math.abs(a)+Math.abs(r.left+r.width/2-i);d<s&&(l=n,s=d)}return l>=0?l:"down"===e?Math.min(t,eT+1):Math.max(0,eT-1)},[th.length,eT]),tL=(0,i.useCallback)(e=>{let r=e.nativeEvent,i="Enter"===e.key&&!e.shiftKey&&(!ei||e.ctrlKey||e.metaKey),s=Date.now()-e4.current<100,a=e8.current||r.isComposing||229===r.keyCode;if(i&&(a||s)){s&&e.preventDefault();return}if(eF&&!a){if("ArrowDown"===e.key){e.preventDefault(),eD(e=>Math.min(Math.max(0,W.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),eD(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),eN(!1);return}if(("Tab"===e.key||i)&&W[eA]){e.preventDefault(),tT(W[eA]);return}}if(eS&&null!==tu){if("ArrowDown"===e.key){e.preventDefault(),eR(tI("down"));return}if("ArrowUp"===e.key){e.preventDefault(),eR(tI("up"));return}if("ArrowRight"===e.key){e.preventDefault(),eR(tI("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),eR(tI("left"));return}if("Escape"===e.key){e.preventDefault(),eC(!1);return}if(("Tab"===e.key||i)&&th[eT]){e.preventDefault(),tR(th[eT]);return}}if(eE&&null!==eL&&!a){if("ArrowDown"===e.key){e.preventDefault(),eP(e=>Math.min(Math.max(0,tw.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),eP(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),ez(!1);return}if(("Tab"===e.key||i)&&tw[e$]){e.preventDefault(),tC(tw[e$]);return}}if("ArrowUp"===e.key&&!a&&!l&&W.length>0&&0===eo.trim().length){e.preventDefault(),eC(!1),ez(!1),eD(W.length-1),eN(!0);return}if("Escape"===e.key&&!a&&l&&t){e.preventDefault(),t();return}i&&(e.preventDefault(),l&&(n||o)?tM(n?"steer":"followup"):tc())},[ei,l,n,o,t,eS,tu,th,eT,tR,tM,tc,tI,eE,eL,tw,e$,tC,eF,W,eA,tT,eo]),tW=(0,i.useCallback)(()=>{let e=eJ.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tz=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.type.startsWith("image/"));t.length&&(e.preventDefault(),tl(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[tl]);(0,i.useEffect)(()=>{if(null===tu){eC(!1),eR(0),e6.current=!1;return}eC(!0),eR(0),!e6.current&&P&&(e6.current=!0,Promise.resolve(P()).catch(()=>{e6.current=!1}))},[tu,P]),(0,i.useEffect)(()=>{if(!eS||!O)return;let e=!1;return eV({cwd:O,values:{}}),fetch(`/api/skills?cwd=${encodeURIComponent(O)}`).then(e=>{if(!e.ok)throw Error(`skills fetch failed: ${e.status}`);return e.json()}).then(t=>{if(e)return;let n={};for(let e of t.skills??[])n[e.name]=e.disableModelInvocation;eV({cwd:O,values:n})}).catch(()=>{e||eV({cwd:O,values:{}})}),()=>{e=!0}},[eS,O]),(0,i.useEffect)(()=>{eT>=th.length&&eR(Math.max(0,th.length-1))},[th.length,eT]),(0,i.useEffect)(()=>{e3.current.length=th.length},[th.length]),(0,i.useEffect)(()=>{eS&&e3.current[eT]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eT,eS]),(0,i.useLayoutEffect)(()=>{if(!eS||null===tu)return void eI(null);let e=e5.current;if(!e)return;let t=null,n=()=>{t=null;let n=function(e,t,n=8){return Math.max(0,Math.floor(e-t-n))}(e.getBoundingClientRect().bottom,function(e){let t=window.visualViewport?.offsetTop??0;for(let n=e.parentElement;n;n=n.parentElement){let e=window.getComputedStyle(n).overflowY;("auto"===e||"scroll"===e||"hidden"===e||"clip"===e)&&(t=Math.max(t,n.getBoundingClientRect().top+n.clientTop))}return t}(e));eI(e=>e===n?e:n)},r=()=>{null!==t&&cancelAnimationFrame(t),t=requestAnimationFrame(n)};n();let i="u">typeof ResizeObserver&&e.parentElement?new ResizeObserver(r):null;e.parentElement&&i?.observe(e.parentElement);let o=window.visualViewport;return o?.addEventListener("resize",r),o?.addEventListener("scroll",r),window.addEventListener("resize",r),window.addEventListener("scroll",r,!0),()=>{i?.disconnect(),o?.removeEventListener("resize",r),o?.removeEventListener("scroll",r),window.removeEventListener("resize",r),window.removeEventListener("scroll",r,!0),null!==t&&cancelAnimationFrame(t)}},[eS,tu]);let t$=c&&c.length>0?c.map(e=>({provider:e.provider,modelId:e.id,name:e.name})).sort(t0):Object.entries(d??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})).sort(t0),tP=(Y=eu.trim().toLocaleLowerCase())?t$.filter(e=>`${e.name} ${e.modelId}`.toLocaleLowerCase().includes(Y)):t$,tq=t$.length>8,tK=[];for(let e of tP){let t=tK.find(t=>t.provider===e.provider);t?t.options.push(e):tK.push({provider:e.provider,options:[e]})}let tV=s?t$.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:null,tY=b?Math.max(0,b.tokensBefore-b.estimatedTokensAfter):0,tJ=b?`${b.reason&&"manual"!==b.reason?`${b.reason[0].toUpperCase()}${b.reason.slice(1)} `:er("chat.compacted")} ${t8(b.tokensBefore)} -> ${t8(b.estimatedTokensAfter)} tokens (${er("chat.tokensSaved",{saved:t8(tY)})})`:null,nn="auto"!==(J=j??"auto")&&R?R[J]??J:J,nl=Object.entries(tX).find(([,e])=>e===(k??"default"))?.[0]??"default";return(0,i.useEffect)(()=>{let e=e=>{eZ.current&&!eZ.current.contains(e.target)&&eG.current&&!eG.current.contains(e.target)&&(ea(!1),ep("")),eX.current&&!eX.current.contains(e.target)&&eg(!1),eQ.current&&!eQ.current.contains(e.target)&&ef(!1),e0.current&&!e0.current.contains(e.target)&&ev(!1),!e1.current||e1.current.contains(e.target)||eJ.current?.contains(e.target)||eN(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{ei||ev(!1)},[ei]),(0,r.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:ei?16:52},children:[(0,r.jsx)("input",{ref:e2,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{tl(Array.from(e.target.files??[])),e.target.value=""}}),(0,r.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[(0,r.jsx)(ns,{error:u}),(0,r.jsx)(na,{warnings:p}),(L?.steering.length??0)+(L?.followUp.length??0)>0&&(0,r.jsxs)("div",{style:{marginBottom:8,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"5px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 8px 4px 10px"},children:[(0,r.jsx)("span",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:er("chat.queued",{count:(L?.steering.length??0)+(L?.followUp.length??0)})}),E&&(0,r.jsxs)("button",{onClick:E,title:er("chat.recallTitle"),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",fontSize:12,color:"var(--text)",background:"transparent",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",transition:"background 0.12s, border-color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"9 14 4 9 9 4"}),(0,r.jsx)("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]}),er("chat.recall")]})]}),L?.steering.map((e,t)=>(0,r.jsx)(no,{kind:"steer",text:e},`steer-${t}`)),L?.followUp.map((e,t)=>(0,r.jsx)(no,{kind:"follow-up",text:e},`followup-${t}`))]}),I&&(0,r.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"})]}),er("chat.retrying",{attempt:I.attempt,max:I.maxAttempts}),I.errorMessage&&(0,r.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",I.errorMessage]})]}),tJ&&(0,r.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(16,185,129,0.08)",border:"1px solid rgba(16,185,129,0.24)",borderRadius:6,fontSize:12,color:"rgba(5,150,105,0.95)",display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),tJ]}),y&&(0,r.jsx)("div",{role:"alert",style:{marginBottom:8,padding:"7px 10px",background:"rgba(239,68,68,0.07)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:6,color:"#ef4444",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:y}),ey.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap"},children:ey.map((e,t)=>(0,r.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,r.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:"1px solid var(--border)",display:"block"}}),(0,r.jsx)("button",{onClick:()=>ts(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,r.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},t))}),(0,r.jsxs)("div",{style:{position:"relative",minWidth:0},children:[eF&&W.length>0&&(0,r.jsxs)("div",{ref:e1,style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(44vh, 360px)"},children:[(0,r.jsx)("div",{title:"Input history",style:{height:30,padding:"0 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",color:"var(--text-dim)"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),(0,r.jsx)("path",{d:"M3 4v5h5"}),(0,r.jsx)("path",{d:"M12 7v5l3 2"})]})}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(44vh, 360px) - 31px)",overflowY:"auto",padding:4},children:W.map((e,t)=>{let n=t===eA;return(0,r.jsxs)("button",{ref:e=>{e9.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),tT(e)},onMouseEnter:()=>eD(t),style:{width:"100%",display:"flex",alignItems:"flex-start",gap:8,padding:"7px 8px",border:"none",borderRadius:6,background:n?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,lineHeight:1.45},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",paddingTop:1},children:t+1}),(0,r.jsx)("span",{style:{minWidth:0,display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",overflowWrap:"anywhere"},children:e})]},`${t}:${e}`)})})]}),eS&&null!==tu&&(0,r.jsxs)("div",{ref:e5,style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",boxSizing:"border-box",display:"flex",flexDirection:"column",maxHeight:null===eM?"min(72.8vh, 598px)":`min(72.8vh, 598px, ${eM}px)`},children:[(0,r.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("span",{children:$?er("chat.loadingCommands"):er("chat.slashCommands",{label:tx})}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:er("chat.tabEnter")})]}),(0,r.jsx)("div",{style:{flex:"1 1 auto",minHeight:0,overflowY:"auto",padding:10},children:$||0!==tp.length?tg.map(e=>(0,r.jsxs)("section",{style:{marginBottom:12},children:[(0,r.jsxs)("div",{style:{position:"sticky",top:-10,zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"4px 0 6px",background:"var(--bg)",color:"var(--text-dim)",fontSize:10,fontWeight:600,textTransform:"uppercase"},children:[(0,r.jsx)("span",{children:er(t5[e.source])}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:8},children:e.items.map(({command:e,index:t})=>{let n=t===eT,i=ne(e,eY);return(0,r.jsxs)("button",{ref:e=>{e3.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),tR(e)},onMouseEnter:()=>eR(t),style:{width:"100%",minWidth:0,minHeight:58,display:"flex",flexDirection:"column",gap:4,justifyContent:"center",padding:"9px 10px",border:`1px solid ${n?"var(--accent)":"var(--border)"}`,borderRadius:7,background:n?"var(--bg-selected)":"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",boxShadow:n?"0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent)":"none"},children:[(0,r.jsxs)("span",{style:{fontSize:13,fontFamily:"var(--font-mono)",overflowWrap:"anywhere",wordBreak:"break-word",color:i?"var(--text-dim)":void 0},children:["/",e.name,i&&(0,r.jsx)("span",{style:{marginLeft:6,padding:"0 4px",border:"1px solid var(--border)",borderRadius:3,fontSize:9,color:"var(--text-dim)",whiteSpace:"nowrap"},children:er("chat.dormant")})]}),e.description&&(0,r.jsx)("span",{style:{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",fontSize:11,lineHeight:1.35,color:"var(--text-dim)"},children:t9(e,er)})]},`${e.source}:${e.name}`)})})]},e.source)):(0,r.jsx)("div",{style:{padding:"2px 2px 4px",fontSize:12,color:"var(--text-dim)"},children:er("chat.noCommands")})})]}),eE&&null!==eL&&(Z=eO&&(!eB||eB.cwd!==O),G=1===tw.length?er("chat.match"):er("chat.matches",{count:tw.length}),X=eB?.truncated&&!tk?eL.query?er("chat.searchingAll"):er("chat.indexTruncated"):"",(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(48vh, 400px)"},children:[(0,r.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,r.jsx)("span",{children:Z?er("chat.loadingFiles"):er("chat.files",{label:G,hint:X})}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:er("chat.tabEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(48vh, 400px) - 34px)",overflowY:"auto",padding:4},children:Z||0!==tw.length?tw.map((e,t)=>{let n=t===e$,i=e.path.split("/").pop()??e.path,o=e.path.slice(0,e.path.length-i.length);return(0,r.jsxs)("button",{ref:e=>{e7.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),tC(e)},onMouseEnter:()=>eP(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"6px 8px",border:"none",borderRadius:6,background:n?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,r.jsx)(C,{size:14}):M(i,14)}),(0,r.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[o&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:o}),i,e.isDir&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,r.jsx)("div",{style:{padding:"6px 8px",fontSize:12,color:"var(--text-dim)"},children:tb&&!tk?er("chat.searching"):er("chat.noMatchingFiles")})})]})),(0,r.jsxs)("div",{style:{minWidth:0,display:"flex",gap:8,alignItems:"center",background:"var(--glass-bg-input)",backdropFilter:"blur(var(--glass-blur)) saturate(150%)",WebkitBackdropFilter:"blur(var(--glass-blur)) saturate(150%)",border:`1px solid ${ew?"var(--tool-bg)":l&&(n||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:16,padding:"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.12)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,r.jsx)("textarea",{ref:eJ,value:eo,onChange:e=>{tr.current=e.target.value,el(e.target.value),eN(!1),tm(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;tm(t.value,t.selectionStart)},onKeyDown:tL,onCompositionStart:()=>{e8.current=!0},onCompositionEnd:e=>{e8.current=!1,e4.current=Date.now();let t=e.currentTarget;tm(t.value,t.selectionStart)},onInput:tW,onPaste:tz,placeholder:l&&(n||o)?er("chat.steerPlaceholder"):l?er("chat.agentPlaceholder"):er("chat.messagePlaceholder"),rows:1,style:{flex:1,minWidth:0,width:"100%",background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto"}}),l?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[n&&(0,r.jsxs)("button",{onClick:()=>tM("steer"),disabled:!tf,title:"Interrupt the current run and inject this message now",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:tf?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:tf?"rgba(180,130,0,1)":"var(--text-dim)",cursor:tf?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,r.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),er("chat.steer")]}),o&&(0,r.jsxs)("button",{onClick:()=>tM("followup"),disabled:!tf,title:"Queue this message after the agent finishes",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:tf?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:tf?"rgba(99,102,241,1)":"var(--text-dim)",cursor:tf?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,r.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,r.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),er("chat.followUp")]})]}):(0,r.jsxs)("button",{onClick:tc,disabled:!eo.trim()&&!ey.length,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:6,padding:"7px 14px",background:eo.trim()||ey.length?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eo.trim()||ey.length?"#fff":"var(--text-dim)",cursor:eo.trim()||ey.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eo.trim()||ey.length?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,r.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),er("chat.send")]})]})]}),ew&&(0,r.jsxs)("div",{className:"text-xs px-2 py-1",style:{color:ej?"var(--text-muted)":"var(--accent)",marginTop:4},children:[er("chat.shell")," \xb7 ",ej?er("chat.outputLocal"):er("chat.outputModel")]}),(0,r.jsxs)("div",{style:{marginTop:8,display:ei?"grid":"flex",gridTemplateColumns:ei?"minmax(0, 1fr) auto":void 0,alignItems:"center",gap:6,padding:"3px 4px",borderRadius:12,background:"var(--glass-bg)",backdropFilter:"blur(var(--glass-blur)) saturate(140%)",WebkitBackdropFilter:"blur(var(--glass-blur)) saturate(140%)"},children:[(0,r.jsxs)("div",{style:{flex:ei?"1 1 auto":"0 0 auto",minWidth:0,display:"flex",alignItems:"center",gap:2},children:[(0,r.jsx)("button",{onClick:()=>e2.current?.click(),title:er("chat.attachImage"),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:ey.length?"var(--accent)":"var(--text-muted)",cursor:"pointer",opacity:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=ey.length?"var(--accent)":"var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=ey.length?"var(--accent)":"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,r.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),(t$.length>0||tV||u)&&h&&(0,r.jsxs)("div",{ref:eZ,style:{position:"relative",flex:ei?"1 1 auto":void 0,minWidth:0},children:[(0,r.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();ec({top:t.top,left:t.left,width:t.width}),ea(e=>(e&&ep(""),!e))},disabled:l||g,"aria-busy":g||void 0,style:{display:"flex",alignItems:"center",gap:6,justifyContent:ei?"flex-start":void 0,padding:ei?"8px 10px":"8px 12px",height:32,width:ei?"100%":void 0,maxWidth:ei?"100%":220,overflow:"hidden",background:es?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l||g?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||g||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=es?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},title:g?"Switching model":t$.length>0?"Change model":"No available models",children:[g?(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",style:{animation:"spin 0.8s linear infinite",flexShrink:0},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-2.64-6.36"})}):(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,r.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,r.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,r.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,r.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,r.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,r.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,r.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,r.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:tV??(t$.length>0?"Select model":"No models")})]}),es&&ed&&(ee=(Q=window.visualViewport?.height??window.innerHeight)-ed.top+6,et=Math.max(120,Math.min(ed.top-8,.6*Q)),en=ei?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{left:ed.left,width:"max-content",minWidth:ed.width},(0,r.jsxs)("div",{ref:eG,style:{position:"fixed",bottom:ee,...en,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:et,display:"flex",flexDirection:"column"},children:[tq&&(0,r.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,r.jsx)("input",{value:eu,onChange:e=>ep(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(ep(""),ea(!1))},placeholder:er("chat.filterModels"),"aria-label":er("chat.filterModels"),autoFocus:!0,autoComplete:"off",spellCheck:!1,style:{width:"100%",minWidth:220*!ei,fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}})}),(0,r.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:0===tK.length?(0,r.jsx)("div",{style:{padding:"8px 12px",color:"var(--text-dim)",fontSize:12,whiteSpace:"nowrap"},children:eu.trim()?er("chat.noMatchingModels"):"No available models"}):tK.map((e,t)=>(0,r.jsxs)("div",{children:[tK.length>1&&(0,r.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,r.jsxs)("button",{onClick:()=>{ea(!1),ep(""),(!t||a)&&h(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),e.name]},`${e.provider}:${e.modelId}`)})]},e.provider))})]}))]})]}),!ei&&(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsxs)("div",{ref:e0,style:{flex:"0 0 auto",display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:ei?0:"auto"},children:[ei&&(0,r.jsx)("button",{type:"button",title:em?void 0:er("chat.moreControls"),"aria-label":er("chat.moreControls"),"aria-expanded":em,"aria-hidden":em||void 0,tabIndex:em?-1:void 0,onClick:()=>{ea(!1),ep(""),ev(!0)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:32,padding:"8px 10px",background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:em?"default":"pointer",fontSize:12,fontWeight:500,visibility:em?"hidden":"visible",pointerEvents:em?"none":"auto",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{em||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{em||(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)")},children:er("chat.moreControls")}),(0,r.jsxs)("div",{style:{display:ei?em?"flex":"none":"flex",alignItems:"center",gap:ei?1:2,...ei?{position:"absolute",right:0,bottom:0,zIndex:60,padding:1,width:"max-content",maxWidth:"calc(100vw - 32px)",flexWrap:"nowrap",justifyContent:"flex-end",border:"1px solid color-mix(in srgb, var(--border) 72%, transparent)",borderRadius:10,background:"color-mix(in srgb, var(--bg-panel) 92%, var(--bg))",boxShadow:"0 8px 24px rgba(0,0,0,0.14)",backdropFilter:"blur(10px)"}:null},children:[!l&&S&&(0,r.jsxs)("div",{ref:eQ,style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>!l&&ef(e=>!e),disabled:l,title:er("chat.changeReasoning",{level:nn}),"aria-label":er("chat.changeReasoningLabel"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:ei?"0 6px":"8px 12px",width:ei?"auto":void 0,height:32,background:ex?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ex?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,r.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,r.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(!ei||em)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:nn})]}),ex&&(0,r.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",...ei?{left:0}:{right:0},zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:180},children:t1.filter(e=>!T||"auto"===e||T.includes(e)).map(e=>{let t=(j??"auto")===e,n=er(t2[e]),i="auto"!==e&&R?R[e]:void 0,o=null!=i&&i!==e?i:e,l=null!=i&&i!==e;return(0,r.jsxs)("button",{onClick:()=>{ef(!1),t||S(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsxs)("span",{style:{flex:1},children:[o,l&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:n})]},e)})})]}),!l&&w&&(0,r.jsxs)("div",{ref:eX,style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>!l&&eg(e=>!e),disabled:l,title:er("chat.changeToolPreset")+`: ${nl}`,"aria-label":er("chat.changeToolPreset"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:ei?"0 6px":"8px 12px",width:ei?"auto":void 0,height:32,background:eh?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eh?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("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"})}),(!ei||em)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:nl})]}),eh&&(0,r.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:ei?void 0:0,left:ei?0:void 0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:120},children:tG.map(e=>{let t,n=tX[e],i=(k??"default")===n;return t="off"===e?er("chat.noTools"):"read-only"===e?er("chat.readOnlyTools",{count:4}):"default"===e?er("chat.builtInTools",{count:4}):er("chat.allBuiltInTools"),(0,r.jsxs)("button",{onClick:()=>{eg(!1),i||w(n)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:i?"var(--bg-selected)":"none",border:"none",color:i?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:i?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[i?(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)("span",{style:{flex:1},children:e}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:t})]},e)})})]}),!l&&x&&(0,r.jsx)("div",{children:(0,r.jsx)("button",{onClick:v?f:x,disabled:l&&!v,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:ei?"0 6px":"8px 12px",width:ei?"auto":void 0,height:32,background:v?"rgba(239,68,68,0.08)":"none",border:"none",borderRadius:9,color:v?"#ef4444":"var(--text-muted)",cursor:l&&!v?"not-allowed":"pointer",fontSize:12,opacity:l&&!v?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{(!l||v)&&(e.currentTarget.style.background=v?"rgba(239,68,68,0.16)":"var(--bg-hover)",e.currentTarget.style.color=v?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=v?"rgba(239,68,68,0.08)":"none",e.currentTarget.style.color=v?"#ef4444":"var(--text-muted)"},title:v?er("chat.stopCompaction"):er("chat.compactContext"),"aria-label":v?er("chat.stopCompaction"):er("chat.compactContext"),children:v?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,r.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}),(!ei||em)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:er("chat.compacting")})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,r.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,r.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,r.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]}),(!ei||em)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:er("chat.compact")})]})})}),l&&(0,r.jsxs)("button",{onClick:t,title:er("chat.stopAgent"),style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:32,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:9,color:"#ef4444",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,r.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),er("chat.stop")]}),void 0!==A&&(0,r.jsx)("button",{onClick:A,title:N?er("chat.disableSound"):er("chat.enableSound"),"aria-label":N?er("chat.disableSound"):er("chat.enableSound"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:N?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:N?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=N?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=N?"1":"0.55"},children:N?(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,r.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,r.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})}),ei&&em&&(0,r.jsx)("button",{type:"button",title:er("chat.collapseControls"),"aria-label":er("chat.collapseControls"),"aria-expanded":!0,onClick:()=>{eg(!1),ef(!1),ev(!1)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:32,padding:0,marginLeft:0,background:"var(--bg-hover)",border:"none",borderLeft:"1px solid color-mix(in srgb, var(--border) 72%, transparent)",borderRadius:"0 9px 9px 0",color:"var(--text)",cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)"},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),!U&&_&&(0,r.jsx)("button",{type:"button",onClick:()=>_(),title:er("chat.scrollToLatest"),"aria-label":er("chat.scrollToLatest"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,flexShrink:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, opacity 0.12s",animation:"back-to-latest-in 0.18s ease-out both"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("polyline",{points:"7 13 12 18 17 13"}),(0,r.jsx)("polyline",{points:"7 6 12 11 17 6"})]})})]})]})]})]})]})});var nc=n(88576),nu=n.n(nc);function np({level:e,children:t,headingIndex:n,onClick:i}){return(0,r.jsx)("button",{type:"button",className:nu().heading,"data-level":e,"data-preview-heading-index":n??void 0,disabled:null===n||!i,onClick:e=>{e.stopPropagation(),null!==n&&i?.(n)},children:t})}let nh=[...eB??[],function(){return e=>{if(!Array.isArray(e.children))return;let t=e.children.filter(e=>"heading"===e.type&&"number"==typeof e.depth&&e.depth<=3);if(t.length>0){t.forEach((e,t)=>{e.data={...e.data,hProperties:{...e.data?.hProperties,"data-preview-heading-index":t}}}),e.children=t;return}let n=e.children.find(e=>"paragraph"===e.type);e.children=n?[n]:[]}}],ng=[[eR.A,{throwOnError:!1,strict:!1}]];function nx(e){let t=e?.properties,n=t?.dataPreviewHeadingIndex??t?.["data-preview-heading-index"];return"number"==typeof n?n:"string"==typeof n&&/^\d+$/.test(n)?Number(n):null}let nf=(0,i.memo)(function({markdown:e,onHeadingClick:t,onAnswerClick:n}){let o=(0,i.useMemo)(()=>eP(e),[e]);return e?(0,r.jsx)("div",{className:nu().outline,children:(0,r.jsx)(eT.oz,{remarkPlugins:nh,rehypePlugins:ng,components:{h1:({children:e,node:n})=>(0,r.jsx)(np,{level:1,headingIndex:nx(n),onClick:t,children:e}),h2:({children:e,node:n})=>(0,r.jsx)(np,{level:2,headingIndex:nx(n),onClick:t,children:e}),h3:({children:e,node:n})=>(0,r.jsx)(np,{level:3,headingIndex:nx(n),onClick:t,children:e}),h4:()=>null,h5:()=>null,h6:()=>null,p:({children:e})=>(0,r.jsx)("button",{type:"button",className:nu().paragraph,onClick:n,children:e}),blockquote:()=>null,ul:()=>null,ol:()=>null,pre:()=>null,table:()=>null,hr:()=>null,a:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),code:({children:e})=>(0,r.jsx)(r.Fragment,{children:e})},children:o})}):null});function nm({messages:e,streamingMessage:t,scrollContainer:n,messageRefs:o,onRevealHistory:l}){let[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(600),[x,f]=(0,i.useState)(!1),[m,v]=(0,i.useState)(null),y=(0,i.useRef)(!1),b=(0,i.useRef)(null),k=(0,i.useRef)([]),w=(0,i.useRef)({nodes:[],gap:50,fillsHeight:!1}),j=(0,i.useRef)(null),S=(0,i.useRef)(new Map),C=(0,i.useRef)(null),T=(0,i.useRef)(null),R=(0,i.useRef)(null),M=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),I=(0,i.useRef)(M);I.current=M;let L=(0,i.useMemo)(()=>(function(e,t){if(0===e.length)return{nodes:[],gap:50,fillsHeight:!1};let n=Math.max(1,t),r=Math.max(0,n-24);if(1===e.length)return{nodes:[{...e[0],topRatio:12/n}],gap:50,fillsHeight:!1};let i=r/(e.length-1),o=Math.min(50,i);return{nodes:e.map((e,t)=>({...e,topRatio:(12+t*o)/n})),gap:o,fillsHeight:i<=50}})(d,h),[d,h]),{nodes:W,gap:E}=L;w.current=L;let z=(0,i.useCallback)(e=>{T.current={index:e,until:Date.now()+1600},p(e)},[]),$=(0,i.useCallback)((e,t)=>{let n=T.current;if(n&&Date.now()<n.until)return void p(n.index);T.current=null;let r=t.filter(e=>null!==e.targetTurn.scrollTop);if(0===r.length)return void p(null);let i=e.scrollTop+.3*e.clientHeight;p(r.reduce((e,t)=>Math.abs((t.targetTurn.scrollTop??0)-i)<Math.abs((e.targetTurn.scrollTop??0)-i)?t:e,r[0]).index)},[]),P=(0,i.useCallback)(()=>{let e=n.current;if(!e)return;let t=e.scrollHeight-e.clientHeight,r=k.current;a(t>20),$(e,r)},[n,$]),F=(0,i.useRef)(null),N=(0,i.useCallback)(()=>{F.current||(F.current=setTimeout(()=>{F.current=null;let e=n.current,t=b.current;if(!e||!t)return;let r=o.current,i=e.getBoundingClientRect(),l=[],s=0,d=null;for(let t of I.current){if("user"!==t.role&&"assistant"!==t.role)continue;let n=r?.[s];if(s++,"user"===t.role){d=null;let r=n?.getBoundingClientRect();d={userMessage:t,assistantPreviews:[],scrollTop:r?r.top-i.top+e.scrollTop:null},l.push(d);continue}if(!d)continue;let o=function(e){if("assistant"!==e.role)return"";let{answerBlocks:t}=ey(e);return t.filter(e=>"text"===e.type).map(e=>e.text).join("\n\n").trim()}(t);o&&d.assistantPreviews.push({markdown:o,element:n})}let u=l.map((e,t)=>({topRatio:0,targetTurn:e,index:t}));g(t.clientHeight),k.current=u,c(u),a(e.scrollHeight-e.clientHeight>20),$(e,u);let p=R.current,h=p?u[p.nodeIndex]:null;if(p&&h){let t=void 0===p.assistantIndex?null:h.targetTurn.assistantPreviews[p.assistantIndex],n=h.targetTurn.scrollTop;if("assistant"===p.target){let r=t?.element?.getBoundingClientRect();n=r?r.top-i.top+e.scrollTop:null}else if("heading"===p.target){let r=void 0===p.headingIndex?null:t?.element?.querySelectorAll("h1, h2, h3").item(p.headingIndex),o=r?.getBoundingClientRect();n=o?o.top-i.top+e.scrollTop:null}if(null===n)return;R.current=null,z(h.index);let r=.3*e.clientHeight;e.scrollTo({top:Math.max(0,n-r),behavior:"smooth"})}},150))},[z,o,n,$]);(0,i.useEffect)(()=>{let e=n.current;if(e)return e.addEventListener("scroll",P,{passive:!0}),()=>e.removeEventListener("scroll",P)},[n,P]),(0,i.useEffect)(()=>{let e=n.current;if(!e)return;let t=()=>{N(),P()},r=new ResizeObserver(t);return r.observe(e),e.firstElementChild&&r.observe(e.firstElementChild),t(),()=>{r.disconnect(),F.current&&(clearTimeout(F.current),F.current=null)}},[N,n,P]),(0,i.useEffect)(()=>{let e=setTimeout(()=>{N(),P()},50);return()=>clearTimeout(e)},[e.length,N,P]);let A=(0,i.useCallback)((e,t)=>{let r=n.current;if(!r)return;if(z(e.index),null===e.targetTurn.scrollTop){R.current={nodeIndex:e.index,target:"user"},l();return}let i=Math.max(0,e.targetTurn.scrollTop-.3*r.clientHeight);r.scrollTo({top:i,behavior:t})},[z,l,n]),D=(0,i.useCallback)((e,t)=>{let r=n.current;if(!r)return;let i=e.targetTurn.assistantPreviews[t]?.element;if(!i){R.current={nodeIndex:e.index,target:"assistant",assistantIndex:t},l();return}let o=r.getBoundingClientRect(),s=i.getBoundingClientRect().top-o.top+r.scrollTop-.3*r.clientHeight;z(e.index),r.scrollTo({top:Math.max(0,s),behavior:"smooth"})},[z,l,n]),B=(0,i.useCallback)(e=>{let{nodes:t,gap:n,fillsHeight:r}=w.current,i=b.current?.clientHeight??0;if(0===t.length||i<=0)return null;let o=Math.max(0,Math.min(i,e*i)),l=t[0].topRatio*i,s=n>0?Math.round((o-l)/n):0,a=Math.max(0,Math.min(t.length-1,s)),d=t[a];if(!r&&Math.abs(o-d.topRatio*i)>Math.max(10,n/2))return null;return d},[]),H=(0,i.useCallback)((e,t,r)=>{let i=n.current;if(!i)return;let o=e.targetTurn.assistantPreviews[t]?.element;if(!o){R.current={nodeIndex:e.index,target:"heading",assistantIndex:t,headingIndex:r},l();return}let s=o.querySelectorAll("h1, h2, h3").item(r);if(!s)return;let a=i.getBoundingClientRect(),d=s.getBoundingClientRect().top-a.top+i.scrollTop-.3*i.clientHeight;z(e.index),i.scrollTo({top:Math.max(0,d),behavior:"smooth"})},[z,l,n]),O=(0,i.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null)},[]),U=(0,i.useCallback)(()=>{O(),f(!0)},[O]),_=(0,i.useCallback)(()=>{O(),C.current=setTimeout(()=>{C.current=null,f(!1),v(null)},250)},[O]);(0,i.useEffect)(()=>()=>O(),[O]);let q=(0,i.useCallback)(e=>{if(!s)return;y.current=!0,U();let t=e.currentTarget.getBoundingClientRect();v(Math.max(0,Math.min(1,(e.clientY-t.top)/t.height)));let n=(e,n)=>{let r=B(Math.max(0,Math.min(1,(e-t.top)/t.height)));r&&A(r,n)};n(e.clientY,"smooth");let r=e=>{y.current&&n(e.clientY,"auto")},i=()=>{y.current=!1,window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",i)};window.addEventListener("mousemove",r),window.addEventListener("mouseup",i)},[B,A,U,s]),K=null===m?null:B(m),V=K?.index??null;if((0,i.useEffect)(()=>{if(!x||null===V)return;let e=j.current,t=S.current.get(V);if(!e||!t)return;let n=t.offsetTop-(e.clientHeight-t.offsetHeight)/2;e.scrollTop=Math.max(0,n)},[d,x,V]),!s)return null;let Y=Math.max(1,(W.length>0?W[W.length-1].topRatio*h:12)-12);return(0,r.jsxs)("div",{ref:b,onMouseDown:q,onMouseEnter:U,onMouseLeave:_,onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"pointer",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,r.jsx)("div",{style:{position:"absolute",left:"50%",top:12,height:Y,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),W.map(e=>{let t=x&&K?.index===e.index,n=u===e.index;return(0,r.jsx)("div",{"data-minimap-node-index":e.index,"data-minimap-node-active":n?"":void 0,style:{position:"absolute",top:`${100*e.topRatio}%`,transform:"translateY(-50%)",left:0,right:0,height:Math.max(1,E),display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none",zIndex:2},children:(0,r.jsx)("div",{style:{width:8,height:8,borderRadius:2,background:n?"rgba(128,128,128,0.42)":"rgba(128,128,128,0.16)",border:`1.5px solid ${n?"rgba(128,128,128,0.95)":"rgba(128,128,128,0.58)"}`,boxShadow:n?"0 0 0 2px var(--bg-panel)":"none",transition:"transform 0.1s, background 0.1s",transform:t?"scale(1.25)":"scale(1)"}})},e.index)}),x&&d.length>0&&(0,r.jsx)("div",{ref:j,className:nu().preview,"data-minimap-preview-box":"",onMouseEnter:U,onMouseDown:e=>e.stopPropagation(),onMouseMove:e=>e.stopPropagation(),children:d.map(e=>{var t;let n=V===e.index;return(0,r.jsxs)("div",{ref:t=>{t?S.current.set(e.index,t):S.current.delete(e.index)},className:nu().turn,"data-minimap-preview-index":e.index,"data-located":n?"true":void 0,children:[(0,r.jsx)("span",{className:nu().number,"aria-hidden":"true",children:String(e.index+1).padStart(2,"0")}),(0,r.jsxs)("div",{className:nu().content,children:[(0,r.jsx)("button",{type:"button",className:nu().user,"data-minimap-preview-user":e.index,onClick:()=>{A(e,"smooth")},children:(0,r.jsx)("span",{className:nu().userText,children:"string"==typeof(t=e.targetTurn.userMessage).content?t.content.trim():t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n").trim()})}),e.targetTurn.assistantPreviews.map((t,n)=>(0,r.jsxs)("div",{className:nu().assistant,children:[(0,r.jsx)("button",{type:"button",className:nu().assistantJump,"data-minimap-preview-assistant":`${e.index}-${n}`,onClick:()=>D(e,n),"aria-label":"Locate assistant message",title:"Locate assistant message",children:"A"}),(0,r.jsx)(nf,{markdown:t.markdown,onAnswerClick:()=>D(e,n),onHeadingClick:t=>H(e,n,t)})]},n))]})]},e.index)})})]})}function nv({widgets:e}){let t,n,o,{t:l}=(0,m.s)(),s=(0,i.useId)(),a=(0,i.useRef)(null),d=(0,i.useRef)(new Map),[c,u]=(0,i.useState)(()=>e.find(e=>{let t=e.lines.length;return t>1&&t<=3})?.key??null),[p,h]=(0,i.useState)(()=>new Set);if((0,i.useEffect)(()=>{var t;let n=new Map(e.map(e=>[e.key,[...e.lines]])),r=(t=a.current,t?Array.from(n,([e,n])=>{let r=t.get(e);return r&&r.length===n.length?n.some((e,t)=>e!==r[t])?e:null:r?e:null}).filter(e=>null!==e):[]);for(let[e,t]of(a.current=n,d.current))n.has(e)||(clearTimeout(t),d.current.delete(e));for(let e of(h(e=>{let t=new Set(Array.from(e).filter(e=>n.has(e)));for(let e of r)t.add(e);return t.size===e.size&&Array.from(t).every(t=>e.has(t))?e:t}),r)){let t=d.current.get(e);t&&clearTimeout(t),d.current.set(e,setTimeout(()=>{d.current.delete(e),h(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},1100))}},[e]),(0,i.useEffect)(()=>()=>{for(let e of d.current.values())clearTimeout(e);d.current.clear()},[]),0===e.length)return null;let g=e.find(e=>e.key===c&&e.lines.length>1);return(0,r.jsxs)(r.Fragment,{children:[g&&(0,r.jsx)("div",{className:"extension-widget-panels",children:(t=e.indexOf(g),n=`${s}-trigger-${t}`,o=`${s}-panel-${t}`,(0,r.jsxs)("section",{id:o,className:"extension-widget-panel","aria-labelledby":n,children:[(0,r.jsx)("div",{className:"extension-widget-panel-heading",children:g.key}),(0,r.jsx)("pre",{className:"extension-widget-content",children:g.lines.join("\n")})]},g.key))}),(0,r.jsx)("div",{className:"extension-widget-triggers","aria-label":l("chat.extensionWidgets"),children:e.map((e,t)=>{let n=e.lines.length>1,i=n&&e.key===g?.key,o=p.has(e.key),a=l(1===e.lines.length?"chat.extensionWidgetLine":"chat.extensionWidgetLines",{count:e.lines.length}),d=l("belowEditor"===e.placement?"chat.extensionWidgetBelow":"chat.extensionWidgetAbove"),c=`${s}-trigger-${t}`,h=`${s}-panel-${t}`,x=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"extension-widget-update-pulse","aria-hidden":"true"}),(0,r.jsx)("span",{className:"extension-widget-placement","aria-hidden":"true",children:(0,r.jsx)("svg",{className:"extension-widget-placement-icon",viewBox:"0 0 8 6",width:"8",height:"6","data-direction":"belowEditor"===e.placement?"down":"up",focusable:"false",children:(0,r.jsx)("path",{d:"belowEditor"===e.placement?"M0 0h8L4 6z":"M4 0l4 6H0z"})})}),(0,r.jsx)("span",{className:"extension-widget-key",children:e.key})]});return n?(0,r.jsx)("button",{id:c,type:"button",className:`extension-widget-trigger${i?" is-expanded":""}${o?" is-updating":""}`,"aria-controls":h,"aria-expanded":i,"aria-label":`${d}: ${e.key}, ${a}`,title:`${e.key} - ${d} - ${i?l("i18n.collapse"):l("i18n.expand")}`,onClick:()=>{u(t=>{var n;return t===(n=e.key)?null:n})},children:x},e.key):(0,r.jsx)("div",{className:`extension-widget-trigger${o?" is-updating":""}`,"aria-label":`${d}: ${e.key}, ${a}`,title:`${e.key} - ${d}`,children:x},e.key)})})]})}function ny({statuses:e,widgets:t=[]}){if(0===e.length&&0===t.length)return null;let n=[...e].sort((e,t)=>e.key.localeCompare(t.key)).map(({text:e})=>e.replace(/[\r\n\t]/g," ").replace(/ +/g," ").trim()).join(" "),i=ed(n);return(0,r.jsxs)("div",{className:`extension-status-shelf${t.length>0?" has-widgets":""}${e.length>0?" has-status":""}`,children:[t.length>0&&(0,r.jsx)(nv,{widgets:t}),e.length>0&&(0,r.jsx)("div",{role:"status",className:"extension-status-line","aria-label":i,title:i,children:(0,r.jsx)("span",{className:"extension-status-text",children:eh(n).map((e,t)=>(0,r.jsx)("span",{style:e.style,children:e.text},t))})})]})}function nb(e=document){return"visible"!==e.visibilityState||!e.hasFocus()}function nk(e){switch(e.method){case"select":case"confirm":case"input":case"editor":return!0;case"custom":return!0!==e.closed;default:return!1}}async function nw(e,t={createWindowNotification:(e,t)=>new Notification(e,t),getServiceWorkerRegistration:"serviceWorker"in navigator?()=>navigator.serviceWorker.getRegistration():null}){let n={body:e.body,...e.tag?{tag:e.tag}:{}};if(t.getServiceWorkerRegistration)try{let r=await t.getServiceWorkerRegistration();if(r)return await r.showNotification(e.title,{...n,data:{url:e.sessionUrl}}),"service-worker"}catch{}try{let r=t.createWindowNotification(e.title,n);return r.onclick=()=>{r.close(),e.onClick()},"window"}catch{return null}}function nj(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function nS(e,t={}){if("assistant"!==e.role)return e;let n=e.content;if(!Array.isArray(n))return e;let r=n.map(e=>(function(e,t={}){if(!nj(e)||"toolCall"!==e.type)return null;let n={type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input},r=t.includeStreamingRawInput?function(e){if("string"==typeof e.rawInput)return e.rawInput;if("string"==typeof e.partialJson)return e.partialJson;if("string"==typeof e.partialArgs)return e.partialArgs;let t=nj(e.customInput)?e.customInput:null,n=t&&"string"==typeof t.property?t.property:null,r=nj(e.arguments)?e.arguments:null;return n&&r&&"string"==typeof r[n]?r[n]:void 0}(e):void 0;return void 0===r?n:{...n,rawInput:r}})(e,t)??e);return{...e,content:r}}class nC extends Error{constructor(e,t,n,r){super(e),this.status=t,this.code=n,this.accepted=r,this.name="AgentCommandError"}}function nT(e){return e instanceof nC&&"prompt_rejected"===e.code&&!1===e.accepted}async function nR(e,t){let n=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok||r.error)throw new nC(r.error??`HTTP ${n.status}`,n.status,r.code,r.accepted);return r.data}var nM=n(14755);let nI="pi-tool-preset";function nL(){try{return window.localStorage}catch{return null}}function nW(e){if(!e||"object"!=typeof e||"image"!==e.type)return"";let t=e.source;return t&&"object"==typeof t?["url"===t.type?"url":"base64","string"==typeof t.media_type?t.media_type:"","string"==typeof t.data?t.data:"","string"==typeof t.url?t.url:""].join(":"):["base64","string"==typeof e.mimeType?e.mimeType:"","string"==typeof e.data?e.data:"",""].join(":")}function nE(e){let t,n=e.content;return"string"==typeof n?JSON.stringify({text:n,images:[]}):Array.isArray(n)?JSON.stringify({text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.map(e=>e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text?e.text:"").filter(Boolean).join("\n"):"",images:n.map(nW).filter(Boolean)}):JSON.stringify({text:"",images:[]})}class nz extends Error{constructor(e,t){super(t??("ready_timeout"===e?"Timed out starting the agent session. Please try again.":"Failed to connect to the agent event stream. Please try again.")),this.status=e,this.name="AgentEventConnectionError"}}class n${constructor(e){this.options=e,this.current=null,this.retry=null,this.retryGeneration=0}close(){this.stopRetrying(),this.current&&this.discard(this.current,new nz("closed"))}maintain(e){if(!this.options.shouldMaintain(e))return;let t=this.retryGeneration;this.ensureConnected(e).catch(n=>{t===this.retryGeneration&&(n instanceof nz?"startup_error"===n.status?this.stopRetrying():this.scheduleRetry(e):this.options.onUnexpectedError?.(n))})}async ensureConnected(e){for(;;){let t=this.current;if(t&&t.sessionId===e){if(t.attempt.ready&&1===t.source.readyState)return}else t=this.open(e);if(await t.attempt.promise,this.current!==t){if(this.current?.sessionId===e)continue;throw new nz("closed")}if(1===t.source.readyState)return;this.discard(t,new nz("closed"))}}open(e){let t,n,r;this.current&&this.discard(this.current,new nz("closed"));try{t=this.options.createSource(e)}catch(e){throw new nz("closed",e instanceof Error?e.message:String(e))}let i=!1,o=new Promise((e,t)=>{n=e,r=t}),l=setTimeout(()=>{this.fail(a,new nz("ready_timeout"))},this.options.readinessTimeoutMs),s={promise:o,ready:!1,succeed(){i||(i=!0,clearTimeout(l),n())},fail(e){i||(i=!0,clearTimeout(l),r(e))}},a={sessionId:e,source:t,attempt:s};return this.current=a,t.onmessage=e=>{let t;if(this.current===a){try{t=JSON.parse(e.data)}catch{return}if("connected"===t.type)s.ready=!0,s.succeed(),this.stopRetrying();else if("startup_error"===t.type){let e="string"==typeof t.errorMessage?t.errorMessage:void 0;this.fail(a,new nz("startup_error",e));return}this.options.onEvent(t)}},t.onerror=()=>{this.fail(a,new nz("closed"))},a}fail(e,t){this.current===e&&(this.discard(e,t),"startup_error"===t.status?this.stopRetrying():this.scheduleRetry(e.sessionId))}discard(e,t){e.attempt.fail(t),e.source.close(),this.current===e&&(this.current=null)}scheduleRetry(e){if(!this.options.shouldMaintain(e)||this.retry?.sessionId===e)return;this.clearRetry();let t=setTimeout(()=>{this.retry?.timer===t&&(this.retry=null,this.maintain(e))},this.options.reconnectDelayMs);this.retry={sessionId:e,timer:t}}stopRetrying(){this.retryGeneration+=1,this.clearRetry()}clearRetry(){this.retry&&clearTimeout(this.retry.timer),this.retry=null}}function nP(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function nF(e,t,n,r=8){return e+t>=n-r}let nN={isStreaming:!1,streamingMessage:null};function nA(e,t,n){let r=e.streamingMessage;if(!r||!Number.isInteger(t)||t<0)return e;let i=[...r.content],o=n(i[t]);return o?(i[t]=o,{isStreaming:!0,streamingMessage:{...r,content:i}}):e}function nD(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"snapshot":{let n=nS(t.message,{includeStreamingRawInput:!0});return"assistant"===n.role?{isStreaming:!0,streamingMessage:n}:e}case"delta":var n=t.event;switch(n.type){case"text_start":return nA(e,n.contentIndex,e=>e?.type==="text"?e:{type:"text",text:""});case"text_delta":return nA(e,n.contentIndex,e=>e?.type==="text"?{...e,text:e.text+n.delta}:null);case"text_end":return nA(e,n.contentIndex,e=>({...e?.type==="text"?e:{},type:"text",text:n.content}));case"thinking_start":return nA(e,n.contentIndex,e=>e?.type==="thinking"?e:{type:"thinking",thinking:""});case"thinking_delta":return nA(e,n.contentIndex,e=>e?.type==="thinking"?{...e,thinking:e.thinking+n.delta}:null);case"thinking_end":return nA(e,n.contentIndex,e=>({...e?.type==="thinking"?e:{},type:"thinking",thinking:n.content}));case"toolcall_start":return nA(e,n.contentIndex,e=>e?.type==="toolCall"?{...e,toolCallId:n.id??e.toolCallId,toolName:n.toolName??e.toolName,rawInput:e.rawInput??""}:"string"!=typeof n.toolName?null:{type:"toolCall",toolCallId:n.id??"",toolName:n.toolName,input:{},rawInput:""});case"toolcall_delta":return nA(e,n.contentIndex,e=>e?.type==="toolCall"?{...e,toolCallId:n.id||e.toolCallId,toolName:n.toolName||e.toolName,rawInput:(e.rawInput??"")+n.delta}:null);case"toolcall_end":return nA(e,n.contentIndex,()=>({type:"toolCall",toolCallId:n.toolCall.id,toolName:n.toolCall.name,input:n.toolCall.arguments}));default:return e}case"end":return nN;default:return e}}function nB(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}function nH(e){return new Promise(t=>setTimeout(t,e))}function nO(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,n)=>n===t?{...e,exiting:!0}:e)}function nU(e,t){switch(t.type){case"add":if(e.visible.some(e=>e.exiting)||e.visible.length>=5)return{visible:e.visible.some(e=>e.exiting)?e.visible:nO(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:nO(e.visible)};case"remove":return function(e,t){let n=e,r=t;for(;r.length>0&&n.length<5;){let[e,...t]=r;n=[...n,e],r=t}return r.length>0&&!n.some(e=>e.exiting)&&(n=nO(n)),{visible:n,pending:r}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function n_(e,t){return e&&"object"==typeof e?"number"!=typeof e.tokensBefore||"number"!=typeof e.estimatedTokensAfter?null:{reason:t,tokensBefore:e.tokensBefore,estimatedTokensAfter:e.estimatedTokensAfter}:null}function nq({label:e}){let[t,n]=(0,i.useState)(null);if((0,i.useEffect)(()=>{let e=new AbortController;return fetch("/api/app-update",{signal:e.signal}).then(async e=>e.ok?e.json():null).then(e=>{e?.updateAvailable&&e.latestVersion&&e.releaseUrl&&n(e)}).catch(()=>{}),()=>e.abort()},[]),!t)return null;let o=e(t.latestVersion);return(0,r.jsxs)("a",{href:t.releaseUrl,target:"_blank",rel:"noopener noreferrer",title:o,"aria-label":o,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},style:{display:"inline-flex",alignItems:"center",alignSelf:"center",gap:3,minHeight:32,minWidth:0,padding:"0 4px",background:"transparent",borderRadius:5,color:"var(--accent)",fontSize:12,fontWeight:600,lineHeight:1.2,textDecoration:"none",transition:"background 0.12s",whiteSpace:"nowrap"},children:[(0,r.jsxs)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:["v",t.latestVersion]}),(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M7 17 17 7"}),(0,r.jsx)("path",{d:"M7 7h10v10"})]})]})}function nK(e){return"user"===e.role||"custom"===e.role&&"compaction"===e.customType}function nV(e,t,n={}){let r={...e,content:t};return n.omitUsage&&(r.usage=void 0),r}function nY({messageCount:e,toolCallCount:t,defaultExpanded:n=!1,children:o,t:l}){let[s,a]=(0,i.useState)(n),d=[l("chat.processDetails"),`${e} ${l(1===e?"chat.message":"chat.messages")}`];return t>0&&d.push(`${t} ${l(1===t?"chat.toolCall":"chat.toolCalls")}`),(0,r.jsxs)("div",{style:{marginBottom:14},children:[(0,r.jsxs)("button",{type:"button","aria-expanded":s,onClick:()=>a(e=>!e),style:{display:"flex",alignItems:"center",gap:8,width:"auto",minHeight:24,padding:"2px 0",border:"none",background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},title:l(s?"chat.collapseProcess":"chat.expandProcess"),children:[(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:s?"rotate(90deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("polyline",{points:"4 2.5 7.5 6 4 9.5"})}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.join(" \xb7 ")})]}),s&&(0,r.jsx)("div",{style:{marginTop:8},children:o})]})}function nJ({session:e,sessionRunning:t,newSessionCwd:o,newSessionDraftKey:s,onAgentEnd:a,onAttentionNeeded:d,onSessionCreated:c,onSessionForked:u,modelsRefreshKey:p,chatInputRef:h,onBranchDataChange:g,onSystemPromptChange:x,onSystemPromptLoaderChange:f,onSessionStatsChange:v,onSessionStatsPanelOpen:y,onTodosChange:b,onContextUsageChange:k,onOpenFile:w,soundEnabled:j=!0,onSoundToggle:S,playDoneSound:C=()=>{},unlockAudio:T}){var R;let M,{t:I}=(0,m.s)(),L=tZ(),W=(0,i.useRef)(C);W.current=C;let E=(0,i.useRef)(j);E.current=j;let z=(0,i.useRef)(null),$=(0,i.useCallback)(()=>{E.current&&W.current(),a?.()},[a]),P=(0,i.useCallback)(e=>{h?.current?.replaceMessage(e)},[h]),{loading:F,error:N,messages:A,entryIds:D,streamState:B,agentRunning:H,bashRunning:O,pendingBash:U,modelNames:_,modelList:q,modelError:K,modelScopeWarnings:V,modelThinkingLevels:Y,modelThinkingLevelMaps:J,toolPreset:Z,thinkingLevel:G,retryInfo:X,contextUsage:Q,forkingEntryId:ee,isCompacting:et,compactError:en,compactResult:er,displayModel:ei,modelSwitching:eo,sessionStats:el,todos:es,slashCommands:ea,slashCommandsLoading:ed,queuedMessages:ec,notices:eu,extensionDialog:ep,extensionCustomUi:eh,extensionStatuses:eg,extensionWidgets:ex,respondToExtensionUi:ef,sendExtensionCustomInput:ek,isAutoModelSelection:ew,agentPhase:eS,isNew:eT,sessionIdRef:eR,messagesEndRef:eM,scrollContainerRef:eI,lastUserMsgRef:eL,promptAnchorActive:eW,handleSend:eE,handleAbort:ez,handleFork:e$,handleNavigate:eP,handleModelChange:eF,handleCompact:eN,handleSteer:eA,handleFollowUp:eD,handlePromptWithStreamingBehavior:eB,handleAbortCompaction:eH,handleRecallQueue:eO,handleBuiltinSlashCommand:eU,handleToolPresetChange:e_,handleThinkingLevelChange:eq,loadSlashCommands:eK,scrollUserMsgToTop:eV,scrollToBottom:eY}=function(e){let{session:t,sessionRunning:r,newSessionCwd:o,newSessionDraftKey:l,onAgentEnd:s,onAttentionNeeded:a,onSessionCreated:d,onSessionForked:c,modelsRefreshKey:u,onBranchDataChange:p,onSystemPromptChange:h,onSystemPromptLoaderChange:g,onSessionStatsPanelOpen:x}=e,f=null===t&&null!==o,[m,v]=(0,i.useState)(null),[y,b]=(0,i.useState)(!f),[k,w]=(0,i.useState)(null),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)([]),[R,M]=(0,i.useState)([]),[I,L]=(0,i.useState)([]),[W,E]=(0,i.useReducer)(nD,nN),[z,$]=(0,i.useState)(!1),[P,F]=(0,i.useState)(!1),[N,A]=(0,i.useState)(null),[D,B]=(0,i.useState)({}),[H,O]=(0,i.useState)([]),[U,_]=(0,i.useState)(null),[q,K]=(0,i.useState)([]),[V,Y]=(0,i.useState)({}),[J,Z]=(0,i.useState)({}),[G,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)(null),[et,en]=(0,i.useState)("default"),[er,ei]=(0,i.useState)("auto"),[eo,el]=(0,i.useState)(null),[es,ea]=(0,i.useState)(null),[ed,ec]=(0,i.useState)(null),[eu,ep]=(0,i.useState)(null),[eh,eg]=(0,i.useState)(null),[ex,ef]=(0,i.useState)(null),[em,ev]=(0,i.useState)(!1),[ey,eb]=(0,i.useState)(!1),[ek,ew]=(0,i.useState)(null),[ej,eS]=(0,i.useState)(null),[eC,eT]=(0,i.useState)(null),[eR,eM]=(0,i.useState)(!1),[eI,eL]=(0,i.useState)([]),[eW,eE]=(0,i.useState)(!1),[ez,e$]=(0,i.useReducer)(nU,{visible:[],pending:[]}),[eP,eF]=(0,i.useState)(null),[eN,eA]=(0,i.useState)(null),[eD,eB]=(0,i.useState)(null),[eH,eO]=(0,i.useState)([]),[eU,e_]=(0,i.useState)([]),[eq,eK]=(0,i.useState)({steering:[],followUp:[]}),eV=(0,i.useRef)(null),eY=(0,i.useRef)(null),eJ=(0,i.useRef)(0),eZ=(0,i.useRef)(!1),eG=(0,i.useRef)(t?.id??null),eX=(0,i.useRef)(t?.id??null),eQ=(0,i.useRef)(!!r),e0=(0,i.useRef)(!1),e1=(0,i.useRef)(!1),e2=(0,i.useRef)(!1),e8=(0,i.useRef)(-1),e4=(0,i.useRef)(!1),e6=(0,i.useRef)(0),e5=(0,i.useRef)(null),e3=(0,i.useRef)(!1),e7=(0,i.useRef)(null),e9=(0,i.useRef)(!1),te=(0,i.useRef)(!0),tt=(0,i.useRef)(0),tn=(0,i.useRef)(null),tr=(0,i.useRef)(void 0),ti=(0,i.useRef)(null),to=(0,i.useRef)(null),tl=(0,i.useRef)(null),ts=(0,i.useRef)(!1),ta=(0,i.useRef)(null),td=(0,i.useRef)(null),tc=(0,i.useRef)(0),tu=(0,i.useRef)(null),tp=(0,i.useRef)(!1),th=(0,i.useRef)(new Map),tg=(0,i.useRef)(!0);eX.current=t?.id??null,eQ.current=!!r,eV.current||(eV.current=new n$({createSource:e=>new EventSource(`/api/agent/${encodeURIComponent(e)}/events`),onEvent:e=>e5.current?.(e),shouldMaintain:e=>tg.current&&eG.current===e&&(e0.current||eZ.current||eX.current===e&&eQ.current),readinessTimeoutMs:6e4,reconnectDelayMs:1e3,onUnexpectedError:e=>{console.error("Failed to maintain the agent event stream:",e)}}));let tx=e.setToolPreset??en;(0,i.useLayoutEffect)(()=>{f&&!eG.current&&tx(function(e=nL()){if(!e)return"default";try{let t=e.getItem(nI);return(0,nM.sn)(t)?t:"default"}catch{return"default"}}())},[f,tx]);let tf=(0,i.useCallback)((e="smooth")=>{let t=to.current;ti.current?.scrollIntoView({behavior:e}),t&&(tt.current=t.scrollTop)},[]),tm=eh??m?.context.model??ex??null,tv=f?G??Q:tm,ty=t?.id??l??void 0,tb=(0,i.useCallback)(e=>{if(!e)return;let t=e,n=new Set;for(;!n.has(t);){n.add(t);let e=th.current.get(t);if(!e)break;t=e}return t},[]),tk=(0,i.useCallback)((t,n,r)=>{let i=n?.map(({data:e,mimeType:t})=>({data:e,mimeType:t})),o=tb(r);if(!tg.current&&!ts.current&&r===l)return;let s=e.chatInputRef?.current;if(s)s.restoreSubmission(t,i,o);else{let e,n;o&&(n=tB(t,i,(e=tF(o)??{value:"",images:[]}).value,e.images),tN(o,n))}},[l,e.chatInputRef,tb]),tw=(0,i.useMemo)(()=>{if(eP)return{...eP,totalActiveMs:m?.totalActiveMs};let e={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},n=0,r=0,i=0,o=0,l=0;for(let t of C){if("user"===t.role&&(r+=1),"toolResult"===t.role&&(o+=1),"assistant"!==t.role)continue;i+=1;let s=t.usage;l+=t.content.filter(e=>"toolCall"===e.type).length,s&&(e.input+=s.input??0,e.output+=s.output??0,e.cacheRead+=s.cacheRead??0,e.cacheWrite+=s.cacheWrite??0,n+=s.cost?.total??0)}return(e.total=e.input+e.output+e.cacheRead+e.cacheWrite,0===e.total&&0===C.length)?null:{sessionFile:m?.filePath||void 0,sessionId:eG.current??t?.id??"",sessionName:t?.name,userMessages:r,assistantMessages:i,toolCalls:l,toolResults:o,totalMessages:C.length,tokens:e,cost:n,totalActiveMs:m?.totalActiveMs,...es?{contextUsage:es}:{}}},[C,eP,es,m?.filePath,m?.totalActiveMs,t?.id,t?.name]),tj=(0,i.useCallback)(async(e,t=!1,n=!1)=>{let r=!1;try{t&&b(!0);let i=new URLSearchParams({deferThinking:"1",deferMedia:"1"}),o=await fetch(`/api/sessions/${encodeURIComponent(e)}?${i}`);if(404===o.status)return t&&(v(null),S(null),T([]),L([]),w(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let l=await o.json();if(eG.current!==e)return null;let s=l.context.messages;if(v(l),S(l.leafId),T(s),M(l.context.entryIds??[]),L(l.context.todos??[]),eg(e=>tp.current?e:null),w(null),l.context.thinkingLevel&&"off"!==l.context.thinkingLevel&&ei(l.context.thinkingLevel),r=!0,t&&b(!1),!n)return null;try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(eG.current!==e)return null;let r=n.state;return r?(void 0!==r.contextUsage&&ea(r.contextUsage??null),void 0!==r.systemPrompt&&ec(r.systemPrompt??null),void 0!==r.thinkingLevel&&ei(r.thinkingLevel??"auto"),void 0!==r.extensionStatuses&&eO(r.extensionStatuses??[]),void 0!==r.extensionWidgets&&e_(r.extensionWidgets??[]),void 0!==r.queuedMessages&&eK(nB(r.queuedMessages))):n.running||eK({steering:[],followUp:[]}),n}catch(e){return console.error("Failed to load agent state:",e),null}}catch(e){return w(String(e)),null}finally{t&&!r&&b(!1)}},[]),tS=(0,i.useCallback)(async(e,t)=>{try{let n=new URLSearchParams({deferThinking:"1",deferMedia:"1"});t&&n.set("leafId",t);let r=`/api/sessions/${encodeURIComponent(e)}/context?${n}`,i=await fetch(r);if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();T(o.context.messages),M(o.context.entryIds??[]),L(o.context.todos??[])}catch(e){console.error("Failed to load context:",e)}},[]),tC=(0,i.useCallback)(async e=>{try{let t=await nR(e,{type:"get_tools"});if(t){let{getPresetFromTools:e}=await Promise.resolve().then(n.bind(n,14755));tx(e(t))}}catch(e){console.error("Failed to load tools:",e)}},[tx]),tT=(0,i.useCallback)((t=0,n="(no messages)")=>{let r=eG.current;if(f&&o&&r&&!ts.current&&(ts.current=!0,l)){if(l!==r){th.current.set(l,r);let t=e.chatInputRef?.current;t?t.rekeyDraft(l,r):tH(l,r)}d?.({id:r,path:"",cwd:o,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:t,firstMessage:n,transient:!0},l)}},[f,o,l,d,e.chatInputRef]),tR=(0,i.useCallback)(async()=>{if(eG.current||!f||!o)return eG.current;if(tl.current)return tl.current;let e=(async()=>{let e=ta.current,t=td.current;e&&ef(e);let n=(0,nM.xG)(et),r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:o,type:"ensure_session",toolNames:n,...e?{provider:e.provider,modelId:e.modelId}:{},...t?{thinkingLevel:t}:{}})});if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json(),l=i.sessionId;return eG.current=l,i.model&&ta.current===e&&(ef(i.model),e||ee(i.model)),i.thinkingLevel&&td.current===t&&ei(i.thinkingLevel),l})();tl.current=e;try{return await e}finally{tl.current=null}},[f,o,et]),tM=(0,i.useCallback)(async()=>{let e=eG.current??await tR();if(!e)return;let t=await nR(e,{type:"get_state"});tg.current&&eG.current===e&&ec(t.systemPrompt??"")},[tR]),tI=(0,i.useCallback)(async()=>{let e=eG.current??await tR();if(!e)return eL([]),[];eE(!0);try{let t=await nR(e,{type:"get_commands"}),n=t?.commands??[];return eL(n),n}catch(e){return console.error("Failed to load slash commands:",e),eL([]),[]}finally{eE(!1)}},[tR]),tL=(0,i.useCallback)(()=>{eJ.current+=1,eZ.current=!1,eY.current&&(clearTimeout(eY.current),eY.current=null)},[]),tW=(0,i.useCallback)(()=>{eV.current?.close()},[]),tE=(0,i.useCallback)(e=>eV.current.ensureConnected(e),[]),tz=(0,i.useCallback)(e=>{eV.current.maintain(e)},[]);(0,i.useEffect)(()=>{if(t?.id&&r)return tz(t.id),()=>{eG.current!==t.id||e0.current||eZ.current||eX.current===t.id&&eQ.current||eV.current?.close()}},[tz,t?.id,r]);let t$=(0,i.useCallback)(async(e,t)=>{let n=eG.current;if(eA(t=>t?.id===e.id?null:t),n)try{await nR(n,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),tP=(0,i.useCallback)(async(e,t)=>{let n=eG.current;if(n)try{await nR(n,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),tD=(0,i.useCallback)(e=>{let t=e.message.trim();t&&e$({type:"add",notice:{id:e.id??("u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`),message:t,type:e.type??"info"}})},[]),tO=(0,i.useCallback)(t=>{switch(nk(t)&&a?.(t),t.method){case"select":case"confirm":case"input":case"editor":eA(t);break;case"notify":tD({id:t.id,message:t.message,type:t.notifyType??"info"});break;case"setStatus":eO(e=>{let n=e.filter(e=>e.key!==t.statusKey);return void 0!==t.statusText?[...n,{key:t.statusKey,text:t.statusText}]:n});break;case"setWidget":e_(e=>{let n=e.filter(e=>e.key!==t.widgetKey);return t.widgetLines?[...n,{key:t.widgetKey,lines:t.widgetLines,placement:t.widgetPlacement??"aboveEditor"}]:n});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":eB(e=>t.closed?e?.id===t.id?null:e:t)}},[tD,a,e.chatInputRef]),tU=(0,i.useCallback)(()=>{let e=e0.current;return e0.current=!1,$(!1),eT(null),el(null),E({type:"end"}),e},[]),t_=(0,i.useCallback)(e=>e8.current!==e&&(e8.current=e,s?.(),!0),[s]),tq=(0,i.useCallback)(e=>{tL(),eZ.current=!0;let t=eJ.current,n=async()=>{if(t===eJ.current&&eG.current===e&&eZ.current)try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();if(t!==eJ.current||eG.current!==e||!eZ.current)return;let o=i.state;if(i.running&&o&&(o.isStreaming||o.isPromptRunning)){eZ.current=!1,eY.current=null,e1.current=!!o?.isStreaming,e2.current=!!o?.isPromptRunning,e0.current=!0,$(!0),eT(o?.isStreaming?{kind:"waiting_model"}:{kind:"running_command"});return}if(i.running&&o?.isCompacting){eb(!0),eY.current=setTimeout(()=>void n(),600);return}eZ.current=!1,eY.current=null,tW()}catch{if(t!==eJ.current||eG.current!==e||!eZ.current)return;eY.current=setTimeout(()=>void n(),600)}};eY.current=setTimeout(()=>void n(),3e4)},[tL,tW]),tK=(0,i.useCallback)(async(e=eG.current,t=tc.current)=>{if(tc.current===t)try{e&&await tj(e)}finally{if(tc.current!==t)return;let n=e2.current,r=e1.current;e2.current=!1,e1.current=!1,tu.current=null;let i=tU();n?t_(t):r&&i&&s?.(),e&&tq(e)}},[tj,t_,s,tq,tU]),tV=(0,i.useCallback)(async(e,t)=>{await nH(800);let n=Date.now();for(;e0.current&&Date.now()-n<2e4;){if(void 0!==t&&tc.current!==t)return;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(n.ok){let r=await n.json(),i=r.state;if(!r.running||!i||!i.isStreaming&&!i.isPromptRunning)return void await tK(e,t)}}catch{}await nH(600)}},[tK]),tY=(0,i.useCallback)(async e=>{let t=e6.current+1;for(e6.current=t;e4.current&&e6.current===t&&eG.current===e;){await nH(1e3);try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)continue;let r=await n.json();if(r.state?.isBashRunning)continue;if(await tj(e),e6.current!==t||eG.current!==e)return;e4.current=!1,F(!1),A(null);return}catch{}}},[tj]),tJ=(0,i.useCallback)(async e=>{if(!e0.current||eG.current!==e)return;let t=tc.current;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)return;let r=await n.json();if(eG.current!==e||tc.current!==t)return;let i=r.state;if(eb(i?.isCompacting??!1),eK(nB(i?.queuedMessages)),r.running&&i&&(i.isStreaming||i.isPromptRunning||i.isCompacting)){e1.current=!!i.isStreaming,e2.current=!!i.isPromptRunning;return}if(!e0.current)return;i&&(void 0!==i.contextUsage&&ea(i.contextUsage??null),void 0!==i.systemPrompt&&ec(i.systemPrompt??null),void 0!==i.extensionStatuses&&eO(i.extensionStatuses??[]),void 0!==i.extensionWidgets&&e_(i.extensionWidgets??[])),await tK(e,t)}catch{}},[tK]);(0,i.useEffect)(()=>{if(!z)return;let e=()=>{let e=eG.current;e&&tJ(e)},t=()=>{"visible"===document.visibilityState&&e()},n=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(n),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[z,tJ]),(0,i.useEffect)(()=>{e0.current=z},[z]),e5.current=(0,i.useCallback)(e=>{switch(e.type){case"connected":E({type:"end"}),!0===e.isStreaming&&(tL(),e1.current=!0,e0.current=!0,$(!0),eT({kind:"waiting_model"}));break;case"agent_start":tL(),e1.current=!0,e0.current=!0,$(!0),eT({kind:"waiting_model"}),E({type:"start"});break;case"agent_end":if(!e0.current)break;eT(null),el(null),E({type:"end"}),eG.current&&(tj(eG.current),fetch(`/api/agent/${encodeURIComponent(eG.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&ea(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&ec(e.state.systemPrompt??null),e.state?.extensionStatuses!==void 0&&eO(e.state.extensionStatuses??[]),e.state?.extensionWidgets!==void 0&&e_(e.state.extensionWidgets??[]),eK(nB(e.state?.queuedMessages))}).catch(()=>{}));break;case"agent_settled":{let e=e1.current;if(e1.current=!1,!e||e2.current)break;let t=eG.current,n=tU();eb(!1),t&&(tj(t),tq(t)),n&&s?.();break}case"prompt_done":{let e=tc.current,t=e2.current;e2.current=!1,tu.current=null;let n=t_(e);if(!t&&!n)break;let r=eG.current;r&&tj(r),!e1.current&&(tU(),r&&tq(r))}break;case"prompt_error":tD({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":tD({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":if(!e0.current)break;if("message_start"===e.type){let t=e.message;if(t?.role==="user")break;t?.role==="assistant"?(E({type:"snapshot",message:t}),t.content.length>0&&eT(null)):t&&eT(null)}else{let t=e.assistantMessageEvent;t&&(E({type:"delta",event:t}),"toolcall_start"!==t.type&&"toolcall_delta"!==t.type&&eT(null))}!e9.current&&te.current&&null===tn.current&&(tn.current=requestAnimationFrame(()=>{tn.current=null,te.current&&tf("auto")}));break;case"message_end":{if(!e0.current)break;let t=e.message;if(t&&"user"===t.role){let e=nS(t),n=nE(e),r=tu.current;tu.current=null,T(t=>{let i=t[t.length-1];return r&&i?.role==="user"&&nE(i)===r?r===n?t:[...t.slice(0,-1),e]:[...t,e]})}else t&&T(e=>[...e,nS(t)]);E({type:"end"}),eT({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,n=e.toolName;eT(e=>{let r=e?.kind==="running_tools"?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:n}),{kind:"running_tools",tools:r}});break}case"tool_execution_update":{let t=e.toolCallId,n=e.toolName,r=function(e){if(!nP(e))return null;let t=e.content;if(!Array.isArray(t))return null;let n=t.filter(e=>nP(e)&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n").split(/\r?\n/),r="";for(let e=n.length-1;e>=0&&!(r=n[e].trim());e-=1);if(!r)return null;let i=r.replace(/\s+/g," ");return i.length<=500?i:`...${i.slice(-497)}`}(e.partialResult);eT(e=>{let i=e?.kind==="running_tools"?[...e.tools]:[],o=i.find(e=>e.id===t),l={id:t,name:n||o?.name||"tool",progress:r??o?.progress};return{kind:"running_tools",tools:[...i.filter(e=>e.id!==t),l]}});break}case"tool_execution_end":{let t=e.toolCallId;eT(e=>{if(e?.kind!=="running_tools")return e;let n=e.tools.filter(e=>e.id!==t);return 0===n.length?{kind:"waiting_model"}:{kind:"running_tools",tools:n}});break}case"queue_update":eK({steering:[...e.steering??[]],followUp:[...e.followUp??[]]});break;case"auto_retry_start":el({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":el(null);break;case"auto_compaction_start":case"compaction_start":eb(!0),ew(null),eS(null);break;case"auto_compaction_end":case"compaction_end":eb(!1),e.errorMessage?(ew(e.errorMessage),eS(null)):!e.aborted&&(eS(n_(e.result,e.reason??"auto")),eG.current&&tj(eG.current));break;case"extension_ui_request":tO(e)}},[tD,tL,tO,tj,t_,s,tq,tf,tU]);let tZ=(0,i.useCallback)(async(e,n)=>{let r=e.trim();if(!r&&!n?.length)return;if(e0.current||e4.current)return void tk(e,n,ty);let i=!n?.length&&r.startsWith("/");if(!n?.length&&r.startsWith("!")){let t=r.startsWith("!!"),i=(t?r.slice(2):r.slice(1)).trim();return i?void await tr.current?.(i,t):void tk(e,n,ty)}let l=tc.current+1;tL(),e2.current=!0;let s=n?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),a={role:"user",content:s?.length?[...e.trim()?[{type:"text",text:e}]:[],...s]:e,timestamp:Date.now()};T(e=>[...e,a]),tu.current=nE(a),tc.current=l,e0.current=!0,$(!0),eT(i?{kind:"running_command"}:{kind:"waiting_model"}),E({type:"start"}),e9.current=!0,eM(!0);let d=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),c=null,u=!1;try{if(f&&o){let t=eG.current??await tl.current,n=t??await tR();if(!n)throw Error("Unable to create a session for the prompt");c=n,G&&(ef(G),t&&await nR(n,{type:"set_model",provider:G.provider,modelId:G.modelId})),await tE(n),u=!0,await nR(n,{type:"prompt",message:e,...d?.length?{images:d}:{}}),tT(1,e)}else if(t)c=t.id,await tE(t.id),u=!0,await nR(t.id,{type:"prompt",message:e,...d?.length?{images:d}:{}});else throw Error("No active session for the prompt");i&&c&&tV(c,l)}catch(t){if(console.error("Failed to send message:",t),!(!u||nT(t))&&c)return void tV(c,l);if(e2.current=!1,T(e=>{let t=e.lastIndexOf(a);return -1===t?e:[...e.slice(0,t),...e.slice(t+1)]}),tD({type:"error",message:t instanceof Error?t.message:String(t)}),tk(e,n,ty),tu.current=null,c)return void tJ(c);e0.current=!1,tW(),$(!1),eT(null),E({type:"end"})}},[f,o,G,t,tR,tE,tT,tV,tD,tL,tW,ty,tJ,tk]);tr.current=(0,i.useCallback)(async(e,n)=>{if(e0.current||e4.current)return;let r=`${n?"!!":"!"}${e}`;e4.current=!0,A({command:e,excludeFromContext:n}),F(!0);try{let i=eG.current??t?.id??await tR();if(!i)throw Error("Unable to create a session for the shell command");await nR(i,{type:"bash",command:e,excludeFromContext:n}),await tj(i),tT(1,r)}catch(e){console.error("Failed to execute shell command:",e),tD({type:"error",message:e instanceof Error?e.message:String(e)}),tk(r,void 0,ty)}finally{e4.current=!1,A(null),F(!1)}},[tD,ty,tR,tj,tT,tk,t]);let tG=(0,i.useCallback)(async()=>{let e=eG.current;if(e){if(e4.current){try{await nR(e,{type:"abort_bash"})}catch(e){console.error("Failed to abort bash:",e)}return}try{await nR(e,{type:"abort"})}catch(e){console.error("Failed to abort:",e)}}},[]),tX=(0,i.useCallback)(async e=>{if(e4.current)return;let t=eG.current;if(t){ep(e);try{let{cancelled:n,newSessionId:r}=await nR(t,{type:"fork",entryId:e})??{};!n&&r&&c?.(r)}catch(e){console.error("Fork failed:",e)}finally{ep(null)}}},[c]),tQ=(0,i.useCallback)(async e=>{if(e4.current)return;let t=eG.current;t&&(nR(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),S(e),await tS(t,e))},[tS]),t0=(0,i.useCallback)(async e=>{if(e4.current)return;S(e);let t=eG.current;t&&(await tS(t,e),e&&nR(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[tS]),t1=(0,i.useCallback)(async(e,t)=>{if(f){let n={provider:e,modelId:t};ta.current=n,X(n),ef(n);let r=eG.current??await tl.current;if(!r)return;try{await nR(r,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let n=eG.current;if(n&&!tp.current){tp.current=!0,eg({provider:e,modelId:t}),ev(!0);try{await nR(n,{type:"set_model",provider:e,modelId:t}),tp.current=!1,await tj(n)}catch(e){console.error("Failed to set model:",e),tp.current=!1,eg(eh),tD({type:"error",message:`Failed to switch model: ${e instanceof Error?e.message:String(e)}`}),await tj(n)}finally{tp.current=!1,ev(!1)}}},[tD,eh,f,tj,X]),t2=(0,i.useCallback)(async()=>{let e=eG.current;if(e&&!ey){eb(!0),ew(null),eS(null);try{let t=await nR(e,{type:"compact"});eS(n_(t,"manual")),await tj(e,!0)}catch(e){ew(e instanceof Error?e.message:String(e)),eS(null)}finally{eb(!1)}}},[ey,tj]),t8=(0,i.useCallback)(async e=>{let n=o??t?.cwd??"",r=n?`/api/models?cwd=${encodeURIComponent(n)}`:"/api/models",i=await fetch(r,e?{signal:e}:void 0);if(!i.ok)throw Error(`HTTP ${i.status}`);let l=await i.json();B(l.models),_(l.modelError??null),K(l.modelScopeWarnings??[]),Y(l.thinkingLevels??{}),Z(l.thinkingLevelMaps??{});let s=l.modelList??[];if(O(s),f&&!eG.current){let e=(l.defaultModel?s.find(e=>e.id===l.defaultModel?.modelId&&e.provider===l.defaultModel?.provider):void 0)??s[0];ee(e?{provider:e.provider,modelId:e.id}:null);let t=e&&l.thinkingLevelPins?.[`${e.provider}/${e.id}`];null===td.current&&ei(t??"auto")}},[f,o,t?.cwd]),t4=(0,i.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,n,r=""]=t,i=r.trim(),o=eG.current??await tR(),l=e=>(e.handled&&(e.error?tD({type:"error",message:e.error}):"openSessionStats"!==e.action&&tD({type:"success",message:e.message??"Command completed"})),e);try{switch(n){case"compact":{if(!o||ey)return l({handled:!0,error:"No active session to compact"});eb(!0),ew(null),eS(null);let e=await nR(o,{type:"compact",...i?{customInstructions:i}:{}});return eS(n_(e,"manual")),await tj(o,!0)&&tT(),l({handled:!0,message:"Compacted context"})}case"reload":if(!o)return l({handled:!0,error:"No active session to reload"});return await nR(o,{type:"reload"}),await Promise.all([tj(o,!1,!0),tC(o),tI(),t8()]),l({handled:!0,message:"Reloaded session resources"});case"name":if(!o)return l({handled:!0,error:"No active session to name"});if(!i)return l({handled:!0,error:"Usage: /name <name>"});return await nR(o,{type:"set_session_name",name:i}),await tj(o)&&tT(),l({handled:!0,message:`Session renamed to ${i}`});case"session":{if(!o)return l({handled:!0,error:"No active session"});let e=await nR(o,{type:"get_session_stats"});return e&&eF(e),x?.(),l({handled:!0,action:"openSessionStats"})}case"copy":{if(!o)return l({handled:!0,error:"No active session"});let e=await nR(o,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return l({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),l({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return l({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===n&&eb(!1)}},[tD,tR,ey,t8,tj,tI,tC,tT,x]),t6=(0,i.useCallback)(async(e,t,n)=>{let r=eG.current;if(!r){tk(e,n,ty),tD({type:"error",message:"No active session for the queued message"});return}let i=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await nR(r,{type:"prompt",message:e,streamingBehavior:t,...i?.length?{images:i}:{}})}catch(t){console.error("Failed to submit streaming prompt:",t),nT(t)&&tk(e,n,ty),tD({type:"error",message:t instanceof Error?t.message:String(t)})}},[tD,ty,tk]),t5=(0,i.useCallback)(async(e,t)=>{await t6(e,"steer",t)},[t6]),t3=(0,i.useCallback)(async(e,t,n)=>{await t6(e,t,n)},[t6]),t7=(0,i.useCallback)(async(e,t)=>{await t6(e,"followUp",t)},[t6]),t9=(0,i.useCallback)(async()=>{let e=eG.current;if(e)try{await nR(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),ne=(0,i.useCallback)(async()=>{let t=eG.current;if(t)try{let n=await nR(t,{type:"clear_queue"});eK({steering:[],followUp:[]});let r=[...n?.steering??[],...n?.followUp??[]];r.length>0&&e.chatInputRef?.current?.prependText(r.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),tD({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,tD]),nt=(0,i.useCallback)(async e=>{if(ei(e),f&&!eG.current&&(td.current="auto"===e?null:e),"auto"===e)return;let t=eG.current??await tl.current;if(t)try{await nR(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[f]),nn=(0,i.useCallback)(async e=>{let t=(0,nM.xG)(e);!function(e,t=nL()){if(t)try{t.setItem(nI,e)}catch{}}(e),tx(e);let n=eG.current??await tl.current;if(n)try{await nR(n,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[tx]),nr=(0,i.useCallback)(()=>{let e=to.current,t=e7.current;if(!e||!t)return;let n=Math.min(Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop-16),Math.max(0,e.scrollHeight-e.clientHeight));null!==tn.current&&(cancelAnimationFrame(tn.current),tn.current=null),te.current=!0,tt.current=n,e.scrollTo({top:n,behavior:"auto"})},[]),ni=(0,i.useCallback)(()=>{let e=to.current;if(e){let{scrollTop:t,clientHeight:n,scrollHeight:r}=e,i=e0.current,o=te.current,l=function(e,t,n,r,i,o=96){return!!nF(n,r,i)||!(n<t)&&(!!(!e&&n>t&&nF(n,r,i,o))||e)}(o,tt.current,t,n,r,i?96:8);te.current=l,tt.current=t,!o&&l&&i?tf("auto"):l||null===tn.current||(cancelAnimationFrame(tn.current),tn.current=null)}},[tf]);return(0,i.useEffect)(()=>(tg.current=!0,t&&(eG.current=t.id,tj(t.id,!0,!0).then(e=>{e?.running&&(tC(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(e1.current=!!e.state.isStreaming,e2.current=!!e.state.isPromptRunning,e0.current=!0,$(!0),eT(e.state.isStreaming?{kind:"waiting_model"}:{kind:"running_command"}),E({type:"start"}),tz(t.id),!e.state.isStreaming&&e.state.isPromptRunning&&tV(t.id)),e.state?.isBashRunning&&(e4.current=!0,F(!0),tY(t.id))),e?.state&&(void 0!==e.state.isCompacting&&eb(e.state.isCompacting),void 0!==e.state.contextUsage&&ea(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&ec(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&ei(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&eO(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&e_(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&eK(nB(e.state.queuedMessages)))})),()=>{tg.current=!1;let e=f?l:null;e&&queueMicrotask(()=>{tg.current||ts.current||tA(e)}),null!==tn.current&&(cancelAnimationFrame(tn.current),tn.current=null),e6.current+=1,tL(),tW()}),[]),(0,i.useEffect)(()=>{h?.(ed)},[ed,h]),(0,i.useEffect)(()=>(g?.(tM),()=>g?.(null)),[tM,g]),(0,i.useEffect)(()=>{p&&p(m?.tree??[],j,t0)},[m?.tree,j,t0,p]),(0,i.useEffect)(()=>{let e=to.current;if(e)return tt.current=e.scrollTop,e.addEventListener("scroll",ni,{passive:!0}),()=>{e.removeEventListener("scroll",ni)}},[C.length,y,ni]),(0,i.useEffect)(()=>{z||eM(!1)},[z]),(0,i.useLayoutEffect)(()=>{C.length>0&&(e9.current?(e9.current=!1,e3.current=!0,nr()):e3.current?!e0.current&&te.current&&tf("auto"):(e3.current=!0,tf("instant")))},[C.length,z,tf,nr]),(0,i.useEffect)(()=>{let e=new AbortController;return t8(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[t8,u]),(0,i.useEffect)(()=>{if(!ej)return;let e=setTimeout(()=>eS(null),6e3);return()=>clearTimeout(e)},[ej]),(0,i.useEffect)(()=>{if(0===ez.visible.length)return;let e=ez.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{e$({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!ez.visible[0])return;let t=setTimeout(()=>{e$({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[ez.visible]),(0,i.useEffect)(()=>{eF(null)},[C.length,es?.tokens,es?.percent,es?.contextWindow]),{data:m,loading:y,error:k,activeLeafId:j,messages:C,entryIds:R,todos:I,streamState:W,agentRunning:z,modelNames:D,modelList:H,modelError:U,modelScopeWarnings:q,modelThinkingLevels:V,modelThinkingLevelMaps:J,newSessionModel:G,toolPreset:et,thinkingLevel:er,retryInfo:eo,contextUsage:es,systemPrompt:ed,forkingEntryId:eu,isCompacting:ey,compactError:ek,compactResult:ej,currentModel:tm,displayModel:tv,modelSwitching:em,sessionStats:tw,slashCommands:eI,slashCommandsLoading:eW,queuedMessages:eq,notices:ez.visible,extensionDialog:eN,extensionCustomUi:eD,extensionStatuses:eH,extensionWidgets:eU,respondToExtensionUi:t$,sendExtensionCustomInput:tP,isAutoModelSelection:f&&null===G,agentPhase:eC,isNew:f,promptAnchorActive:eR,sessionIdRef:eG,messagesEndRef:ti,scrollContainerRef:to,lastUserMsgRef:e7,pendingScrollToUserRef:e9,initialScrollDoneRef:e3,handleSend:tZ,handleAbort:tG,handleFork:tX,handleNavigate:tQ,handleModelChange:t1,handleCompact:t2,handleSteer:t5,handleFollowUp:t7,handlePromptWithStreamingBehavior:t3,handleAbortCompaction:t9,handleRecallQueue:ne,handleBuiltinSlashCommand:t4,handleToolPresetChange:nn,handleThinkingLevelChange:nt,loadTools:tC,loadSlashCommands:tI,setActiveLeafId:S,setData:v,setMessages:T,scrollToBottom:tf,scrollUserMsgToTop:nr,dispatch:E,setAgentRunning:$,setForkingEntryId:ep,bashRunning:P,pendingBash:N,handleAgentEventRef:e5}}({session:e,sessionRunning:t,newSessionCwd:o,newSessionDraftKey:s,onAgentEnd:$,onAttentionNeeded:d,onSessionCreated:c,onSessionForked:u,modelsRefreshKey:p,chatInputRef:h,onBranchDataChange:g,onSystemPromptChange:x,onSystemPromptLoaderChange:f,onSessionStatsPanelOpen:y}),eJ=H||O;(0,i.useEffect)(()=>{ep&&z.current!==ep.id&&(z.current=ep.id,W.current())},[ep]),(0,i.useEffect)(()=>{l=eJ?ez:null},[eJ,ez]);let[eZ,eG]=(0,i.useState)(50),eX=(0,i.useRef)(null),eQ=(0,i.useRef)(null),[e0,e1]=(0,i.useState)(!0);(0,i.useEffect)(()=>{let e=eX.current,t=eI.current;if(!e||!t)return;let n=new IntersectionObserver(e=>{e[0]?.isIntersecting&&(eQ.current=t.scrollHeight-t.scrollTop,eG(e=>(function(e,t=50){return e+t})(e)))},{root:t,threshold:0});return n.observe(e),()=>n.disconnect()},[eZ,A.length,eI]),(0,i.useEffect)(()=>{if(null==eQ.current)return;let e=eI.current;if(e){var t;t=e.scrollHeight,e.scrollTop=Math.max(0,t-eQ.current),eQ.current=null}},[eZ,eI]);let e2=el?[el.sessionId,el.sessionFile??"",el.sessionName??"",el.userMessages,el.assistantMessages,el.toolCalls,el.toolResults,el.totalMessages,el.tokens.input,el.tokens.output,el.tokens.cacheRead,el.tokens.cacheWrite,el.tokens.total,el.cost??0,el.totalActiveMs??0].join("|"):null,e8=(0,i.useRef)(el);e8.current=el,(0,i.useEffect)(()=>{v?.(e8.current)},[e2,v]),(0,i.useEffect)(()=>()=>{v?.(null)},[v]);let e4=(0,i.useRef)(es);e4.current=es;let e6=es.map(e=>e.id??e.content).join("\0");(0,i.useEffect)(()=>{b?.(e4.current)},[e6,b]),(0,i.useEffect)(()=>()=>{b?.([])},[b]);let e5=Q?`${Q.percent??"null"}|${Q.contextWindow}|${Q.tokens??"null"}`:null,e3=(0,i.useRef)(Q);e3.current=Q,(0,i.useEffect)(()=>{k?.(e3.current)},[e5,k]),(0,i.useEffect)(()=>()=>{k?.(null)},[k]);let{isDragOver:e7,handleDragEnter:e9,handleDragOver:te,handleDragLeave:tt,handleDrop:tn}=function(e){let[t,n]=(0,i.useState)(!1),r=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&(e.preventDefault(),r.current+=1,n(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{r.current-=1,r.current<=0&&(r.current=0,n(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),r.current=0,n(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,i.useCallback)(e=>{h?.current?.addImages(e)},[h])),tr=A.filter(e=>"user"===e.role||"assistant"===e.role),ti=(0,i.useMemo)(()=>{let e=new Map;for(let t of A)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[A]),to=(0,i.useMemo)(()=>{let e=new Set,t=[];for(let n=A.length-1;n>=0;n-=1){let r=function(e){if("user"!==e.role)return null;if("string"==typeof e.content){let t=e.content.trim();return t.length>0?t:null}let t=e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n").trim();return t.length>0?t:null}(A[n]);if(!(!r||e.has(r))&&(e.add(r),t.push(r),t.length>=50))break}return t.reverse()},[A]),tl=(R=tr.length,(M=(0,i.useRef)([])).current=Array(R).fill(null).map((e,t)=>M.current[t]??null),M),ts=(0,i.useCallback)(()=>{eG(e=>Math.max(e,2*A.length))},[A.length]),ta=eT&&0===A.length&&!B.isStreaming&&!eJ,td=!!B.streamingMessage?.content.length,tc=e?.cwd??o??void 0,tu=(0,i.useRef)(null),tp=(0,i.useRef)(null),tg=(0,i.useRef)(0),tx=(0,i.useRef)(null),tf=(0,i.useRef)(!1),tm=(0,i.useRef)(null);(0,i.useLayoutEffect)(()=>{let e=tp.current;if(!H||!eW){tm.current=null,tg.current=0,tf.current=!1,e&&(e.style.height="");return}let t=eI.current,n=tu.current,r=eL.current;if(!t||!n||!r||!e)return;let i=!1,o=()=>{var o;let l;if(i||eI.current!==t||tu.current!==n||eL.current!==r||tp.current!==e)return;let s=t.getBoundingClientRect().top,a=Math.max(0,r.getBoundingClientRect().top-s+t.scrollTop-16),d=e.getBoundingClientRect().top-s+t.scrollTop,c=(o=t.clientHeight,0===(l=Math.max(0,a))?0:Math.max(0,Math.ceil(l+o-Math.max(0,d)))),u=!tf.current;u&&(tf.current=!0),c!==tg.current&&(tg.current=c,e.style.height=c>0?`${c}px`:"",u&&c>0&&eV())};tm.current=o,o();let l="u"<typeof ResizeObserver?null:new ResizeObserver(()=>{i||null!==tx.current||(tx.current=requestAnimationFrame(()=>{tx.current=null,o()}))});return l?.observe(t),l?.observe(n),l?.observe(r),()=>{i=!0,tm.current===o&&(tm.current=null),l?.disconnect(),null!==tx.current&&(cancelAnimationFrame(tx.current),tx.current=null)}},[H,eL,A.length,eW,eI,eV]),(0,i.useLayoutEffect)(()=>{tm.current?.()},[B.streamingMessage]);let tv=ei?Y[`${ei.provider}:${ei.modelId}`]??null:null,ty=ei?J[`${ei.provider}:${ei.modelId}`]??null:null,tb=(0,r.jsx)(nd,{ref:h,onSend:eE,onAbort:ez,onSteer:H?eA:void 0,onFollowUp:H?eD:void 0,onPromptWithStreamingBehavior:H?eB:void 0,isStreaming:eJ,model:ei,isAutoModelSelection:ew,modelNames:_,modelList:q,modelError:K,modelScopeWarnings:V,onModelChange:eF,modelSwitching:eo,onCompact:e||eT?eN:void 0,onAbortCompaction:eH,isCompacting:et,compactError:en,compactResult:er,toolPreset:Z,onToolPresetChange:e||eT?e_:void 0,thinkingLevel:G,onThinkingLevelChange:e||eT?eq:void 0,availableThinkingLevels:tv,thinkingLevelMap:ty,retryInfo:X,queuedMessages:ec,inputHistory:to,onRecallQueue:eO,slashCommands:ea,slashCommandsLoading:ed,onLoadSlashCommands:eK,onBuiltinCommand:eU,soundEnabled:j,onSoundToggle:S,onAudioUnlock:T,draftKey:e?.id??s??void 0,cwd:e?.cwd??o,atBottom:e0,onScrollToBottom:eY});return F?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:I("chat.loadingSession")}):N?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:N}):(0,r.jsxs)("div",{className:"relative flex h-full min-w-0 flex-col overflow-hidden",style:{paddingBottom:"env(safe-area-inset-bottom)"},onDragEnter:e9,onDragOver:te,onDragLeave:tt,onDrop:tn,children:[e7&&(0,r.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,r.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,r.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${e}s`}},e))}),(0,r.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,r.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,r.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,r.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,r.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,r.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,r.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,r.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,r.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,r.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,r.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,r.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),ep&&(0,r.jsx)(nG,{request:ep,onRespond:ef}),eh&&(0,r.jsx)(nX,{request:eh,onInput:ek}),(0,r.jsx)("div",{style:{position:"fixed",right:51,bottom:L?168:118,zIndex:250,display:"flex",flexDirection:"column",alignItems:"flex-end",maxWidth:"min(100vw - 48px, 340px)",maxHeight:"calc(100dvh - 220px)",overflowY:"auto",pointerEvents:"none"},children:(0,r.jsx)(nZ,{notices:eu})}),ta?(0,r.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8",children:(0,r.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,r.jsxs)("div",{className:"mb-3",style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginLeft:16,marginRight:L?16:52,fontFamily:"var(--font-mono)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:L?7:10,minWidth:0,flex:1,lineHeight:1.4,overflow:"hidden"},children:[(0,r.jsx)("span",{style:{fontSize:28,fontWeight:700,letterSpacing:0,color:"var(--text)",flexShrink:0,whiteSpace:"nowrap"},children:"π"}),(0,r.jsx)("span",{style:{fontSize:22,color:"var(--text)",fontWeight:700,letterSpacing:0,flexShrink:0,whiteSpace:"nowrap"},children:"Pi Web"}),(0,r.jsx)(nq,{label:e=>I("appUpdate.releaseNotes",{version:e})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["web ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.1.0"]})]}),(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["pi ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.84.2"]})]})]})]}),tb,(0,r.jsx)(ny,{statuses:eg,widgets:ex})]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"relative flex min-w-0 flex-1 overflow-hidden",children:[(0,r.jsx)("div",{ref:eI,className:"min-w-0 flex-1 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none]",onScroll:e=>{let t=e.currentTarget;e1(nF(t.scrollTop,t.clientHeight,t.scrollHeight))},children:(0,r.jsx)("div",{style:{minWidth:0,padding:"0 16px"},children:(0,r.jsxs)("div",{ref:tu,style:{width:"100%",minWidth:0,maxWidth:820,margin:"0 auto"},children:[(()=>{var t;let n,i,o=-1;for(let e=A.length-1;e>=0;e--)if("user"===A[e].role){o=e;break}let l=-1;for(let e=A.length-1;e>=0;e--)if(nK(A[e])){l=e;break}let s=new Map,a=0;A.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&s.set(t,a++)});let d=(t,n={})=>{let i=n.messageOverride??A[t],l="user"===i.role&&t>0&&"assistant"===A[t-1].role?D[t-1]:void 0,a="user"===i.role||"assistant"===i.role,d=s.get(t),c=n.keyPrefix??"message",u=!1;if("assistant"===i.role){u=!0;for(let e=t+1;e<A.length;e++){let t=A[e].role;if("user"===t)break;if("assistant"===t){u=!1;break}}u&&B.isStreaming&&t===A.length-1&&(u=!1)}void 0!==n.showTimestamp&&(u=n.showTimestamp);let p=(0,r.jsx)(th,{message:i,toolResults:ti,modelNames:_,cwd:tc,onOpenFile:w,entryId:D[t],onFork:eJ||eT||0===t&&"user"===i.role?void 0:e$,forking:ee===D[t],onNavigate:eJ?void 0:eP,prevAssistantEntryId:eJ?void 0:l,onEditContent:P,showTimestamp:u,prevTimestamp:t>0?A[t-1].timestamp:void 0,sessionId:e?.id??eR.current??void 0,writtenFiles:n.writtenFiles},`${c}-view-${t}`);return a&&!1!==n.attachRef&&void 0!==d?(0,r.jsx)("div",{ref:e=>{tl.current[d]=e,t===o&&(eL.current=e)},children:p},`${c}-${t}`):p},c=[];for(let e=0;e<A.length;){if(!nK(A[e])){c.push(d(e)),e+=1;continue}let t=e,n=t+1;for(;n<A.length&&!nK(A[n]);)n+=1;let i=function(e,t,n){for(let i=n-1;i>t;i--){var r;if("assistant"===(r=e[i]).role&&ey(r).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return i}for(let r=n-1;r>t;r--)if(e[r]?.role==="assistant")return r;return -1}(A,t,n);if(-1===i||(eJ||B.isStreaming)&&n===A.length&&t===l){for(let e=t;e<n;e++)c.push(d(e));e=n;continue}c.push(d(t));let o=[];for(let e=t+1;e<i;e++)o.push(e);let a=o.filter(e=>{var t;return"assistant"===(t=A[e]).role?em(t).length>0:"custom"===t.role}),u=A[i],p=ey(u),h=p.processBlocks.length>0?nV(u,p.processBlocks,{omitUsage:!0}):null,g=p.answerBlocks.length>0||ev(u)?nV(u,p.answerBlocks):null,x=a.length+ +!!h;if(x>0){let e=a.map(e=>s.get(e)).find(e=>"number"==typeof e)??(g?void 0:s.get(i)),n=(0,r.jsxs)(nY,{messageCount:x,defaultExpanded:!g,t:I,toolCallCount:function(e,t){let n=0;for(let r of t){let t=e[r];t?.role==="assistant"&&(n+=eb(em(t)))}return n}(A,a)+eb(p.processBlocks),children:[a.map(e=>d(e,{attachRef:!1,keyPrefix:"process"})),h&&d(i,{attachRef:!1,keyPrefix:"process-final",messageOverride:h,showTimestamp:!1})]});c.push((0,r.jsx)("div",{ref:void 0===e?void 0:t=>{tl.current[e]=t},children:n},`process-group-${t}-${i}`))}if(g){let e=[];for(let n=t+1;n<=i;n++){let t=A[n];if(t?.role==="assistant")for(let n of t.content??[])e.push(n)}let n=function(e,t,n){let r=new Set,i=[];for(let o of e){if("toolCall"!==o.type||!function(e){let t;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||eC(e)}(o.toolName))continue;let e=t?.get(o.toolCallId);if(!e||e.isError)continue;let l=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(o.input);if(!l)continue;let s=function(e,t){let n;if(!e)return null;let r=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),i=e=>r?e.replace(/\\/g,"/"):e,o=i(e),l=t?i(t).replace(/\/+$/,""):void 0,s=/^[a-zA-Z]:\//.test(o),a=o.startsWith("//");if(s||a)n=o;else if(o.startsWith("/")){let e=l?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??l?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];n=e?`${e}${o}`:o}else{if(!l)return null;n=`${l}/${o}`}return ej(n)}(l,n);s&&(r.has(s)||(r.add(s),i.push({filePath:s})))}return i}(e,ti,tc);c.push(d(i,{messageOverride:g,writtenFiles:n}))}for(let e=i+1;e<n;e++)c.push(d(e));e=n}let{startIndex:u,hasMore:p}=(n=Math.min(Math.max(eZ,0),Math.max(t=c.length,0)),{startIndex:i=Math.max(0,t-n),hasMore:i>0});return(0,r.jsxs)(r.Fragment,{children:[p&&(0,r.jsx)("div",{ref:eX,className:"py-3 text-center text-xs text-text-muted",children:I("chat.loadEarlier",{count:u})}),c.slice(u)]})})(),B.isStreaming&&td&&B.streamingMessage&&(0,r.jsx)(th,{message:B.streamingMessage,isStreaming:!0,modelNames:_,cwd:tc,onOpenFile:w}),H&&!td&&eS&&(0,r.jsx)("div",{className:"break-words py-2 text-[13px] text-text-muted",children:(0,r.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(e,t){if(e?.kind==="running_tools"){let n=e.tools[e.tools.length-1];if(n?.progress)return`${t("chat.runningNamedTool",{name:n.name})} ${n.progress}`;let r=e.tools.map(e=>e.name);return 0===r.length?t("chat.runningTool"):1===r.length?t("chat.runningNamedTool",{name:r[0]}):r.length<=3?t("chat.runningTools",{names:r.join(", ")}):t("chat.runningToolsMore",{names:r.slice(0,2).join(", "),count:r.length-2})}return e?.kind==="waiting_model"?t("chat.waitingModel"):e?.kind==="running_command"?t("chat.runningCommand"):null}(eS,I)})}),O&&!U&&(0,r.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,r.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:I("chat.runningCommand")})}),U&&(0,r.jsx)(th,{message:{role:"bashExecution",command:U.command,output:"",excludeFromContext:U.excludeFromContext},sessionId:e?.id??eR.current??void 0}),(0,r.jsx)("div",{ref:tp,"aria-hidden":"true"}),(0,r.jsx)("div",{ref:eM})]})})}),L?null:(0,r.jsx)(nm,{messages:A,streamingMessage:B.streamingMessage,scrollContainer:eI,messageRefs:tl,onRevealHistory:ts})]}),(0,r.jsxs)("div",{className:"relative",children:[tb,(0,r.jsx)(ny,{statuses:eg,widgets:ex})]})]})]})}function nZ({notices:e}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:6},children:e.map(e=>{let t="error"===e.type?"#ef4444":"warning"===e.type?"#d97706":"success"===e.type?"#10b981":"var(--accent)";return(0,r.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden",borderRadius:8,border:"1px solid color-mix(in srgb, var(--border) 45%, transparent)",background:"color-mix(in srgb, var(--glass-bg) 55%, var(--bg-panel))",backdropFilter:"blur(10px) saturate(140%)",WebkitBackdropFilter:"blur(10px) saturate(140%)",color:"var(--text)",width:300,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",fontSize:12.5,lineHeight:1.55,transformOrigin:"bottom right",animation:e.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"8px 12px",pointerEvents:"auto"},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:5,height:5,borderRadius:"50%",background:t}}),(0,r.jsx)("span",{className:"notice-shelf-text",style:{minWidth:0,flex:1,wordBreak:"break-word",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:e.message})]},e.id)})})}function nG({request:e,onRespond:t}){let{t:n}=(0,m.s)(),[o,l]=(0,i.useState)("editor"===e.method?e.prefill??"":"");(0,i.useEffect)(()=>{l("editor"===e.method?e.prefill??"":"")},[e]);let s=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:o})};return(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:"min(560px, 100%)",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,r.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:n("chat.extensionRequest")})]}),(0,r.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap"},children:e.message}),"select"===e.method&&(0,r.jsx)("div",{style:{display:"grid",gap:8},children:e.options.map(n=>(0,r.jsx)("button",{onClick:()=>t(e,{value:n}),style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},children:n},n))}),"input"===e.method&&(0,r.jsx)("input",{autoFocus:!0,value:o,placeholder:e.placeholder,onChange:e=>l(e.target.value),onKeyDown:n=>{"Enter"===n.key&&s(),"Escape"===n.key&&t(e,{cancelled:!0})},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,r.jsx)("textarea",{autoFocus:!0,value:o,onChange:e=>l(e.target.value),onKeyDown:n=>{"Escape"===n.key&&t(e,{cancelled:!0}),(n.metaKey||n.ctrlKey)&&"Enter"===n.key&&s()},style:{width:"100%",minHeight:220,padding:10,borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,r.jsx)("button",{onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:n("chat.cancel")}),"confirm"===e.method?(0,r.jsx)("button",{onClick:s,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:n("chat.confirm")}):"select"!==e.method?(0,r.jsx)("button",{onClick:s,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:n("chat.submit")}):null]})]})})}function nX({request:e,onInput:t}){let{t:n}=(0,m.s)(),o=(0,i.useRef)(null),l=(0,i.useRef)(!1),s=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,n=[];for(let r of e){let e=r.replace(el,""),i=ed(e).trimEnd();if(t.test(i))continue;let o=e,l=ep(o);("│"===l||"┃"===l)&&" "===ep(o=eu(o,0))&&(o=eu(o,0));let s=function(e){let t=ec(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(o),a=s>=0?ec(o)[s]?.char:void 0;("│"===a||"┃"===a)&&(o=eu(o,s)),n.push(function(e){let t=e;for(;;){let e=ec(t),n=e[e.length-1];if(!n||""!==n.char.trim())return t;t=t.slice(0,n.start)+t.slice(n.end)}}(o))}for(;n.length>0&&""===ed(n[0]).trim();)n.shift();for(;n.length>0&&""===ed(n[n.length-1]).trim();)n.pop();return n.length?n:e}(e.lines);return(0,i.useEffect)(()=>{o.current?.focus()},[e.id]),(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"true",onClick:e=>{e.target.closest("button")||o.current?.focus()},style:{position:"relative",width:"min(920px, 100%)",maxHeight:"min(760px, calc(100vh - 40px))",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,r.jsx)("textarea",{ref:o,"aria-label":n("chat.extensionInput"),autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,onKeyDown:n=>{if(l.current||n.nativeEvent.isComposing)return;let r=function(e){if(e.metaKey||e.ctrlKey&&!e.altKey&&"v"===e.key.toLowerCase())return null;if(e.ctrlKey&&!e.altKey){let t=function(e){if(1!==e.length)return null;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(31&t):"?"===e?"":null}(e.key);if(t)return t}if(e.altKey&&!e.ctrlKey){if("Backspace"===e.key)return"\x1b\x7f";let t=ex[e.key];if(t)return t;if(1===e.key.length)return`\x1b${e.key}`}return"Enter"===e.key?e.shiftKey?"\n":"\r":"Tab"===e.key?e.shiftKey?"\x1b[Z":" ":eg[e.key]??null}(n);r&&(n.preventDefault(),n.stopPropagation(),t(e,r))},onInput:n=>{if(l.current||n.nativeEvent.isComposing)return;let r=n.currentTarget.value;n.currentTarget.value="",r&&t(e,r)},onCompositionStart:()=>{l.current=!0},onCompositionEnd:n=>{l.current=!1;let r=n.currentTarget;queueMicrotask(()=>{let n=r.value;r.value="",n&&t(e,n)})},onPaste:n=>{n.preventDefault();let r=n.clipboardData.getData("text");r&&t(e,`\x1b[200~${r}\x1b[201~`)},style:{position:"absolute",width:1,height:1,padding:0,border:0,opacity:0,pointerEvents:"none"}}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:n("chat.extensionPanel")}),(0,r.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:n("chat.close")})]}),(0,r.jsx)("pre",{style:{margin:0,padding:14,maxHeight:"calc(min(760px, 100vh - 40px) - 48px)",overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(s.length?s:[""]).map((e,t,n)=>{var o;return(0,r.jsxs)(i.Fragment,{children:[(o=`line-${t}`,eh(e).map((e,t)=>Object.keys(e.style).length>0?(0,r.jsx)("span",{style:e.style,children:e.text},`${o}-${t}`):e.text)),t<n.length-1?"\n":null]},t)})})]})})}var nQ=n(50640);let n0={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",avif:"image/avif"},n1={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",weba:"audio/webm",webm:"audio/webm"};function n2(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}var n8=n(73620);let n4=/^(?:\uFEFF)?---[ \t]*(?:\r\n|\n|\r)/;function n6(e){return function e(t,n){if(null==t)return"";if("string"==typeof t)return t;if("number"==typeof t||"boolean"==typeof t)return String(t);if(Array.isArray(t)){if(n.has(t))return"[Circular]";n.add(t);try{return t.map(t=>e(t,n)).filter(Boolean).join(", ")}finally{n.delete(t)}}if("object"==typeof t)try{return JSON.stringify(t)??Object.prototype.toString.call(t)}catch{return Object.prototype.toString.call(t)}return String(t)}(e,new WeakSet)}let n5=["tags","categories","keywords","tag","category"];function n3({data:e}){var t;if(!e)return null;let n=Object.entries(e);if(0===n.length)return null;let i="string"==typeof(t=e.title)?t.trim()||null:"number"==typeof t||"boolean"==typeof t?String(t):null,o=n5.find(t=>Array.isArray(e[t])),l=o?e[o].map(n6).filter(Boolean):[],s=n.filter(([e])=>e!==o&&("title"!==e||!i));return(0,r.jsxs)("div",{className:"markdown-frontmatter",children:[i&&(0,r.jsx)("div",{className:"markdown-frontmatter-title",children:i}),l.length>0&&(0,r.jsx)("div",{className:"markdown-frontmatter-tags",children:l.map((e,t)=>(0,r.jsx)("span",{className:"markdown-frontmatter-tag",children:e},`${e}-${t}`))}),s.length>0&&(0,r.jsx)("dl",{className:"markdown-frontmatter-rows",children:s.map(([e,t])=>(0,r.jsxs)("div",{className:"markdown-frontmatter-row",children:[(0,r.jsx)("dt",{children:e}),(0,r.jsx)("dd",{children:function(e){let t=n6(e);return t?"string"==typeof e&&/^(https?:\/\/|mailto:)/i.test(e)?(0,r.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:t}):t:null}(t)})]},e))})]})}let n7={source:"Source",preview:"Preview",diff:"Diff"},n9={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},re={width:48,minWidth:48,padding:"0 10px",textAlign:"right",color:"var(--text-dim)",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:11,fontStyle:"normal",fontVariantNumeric:"tabular-nums",lineHeight:"20.8px",userSelect:"none",flexShrink:0,verticalAlign:"top"};function rt(){return(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function rn(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function rr(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let n=t.getRangeAt(0);if(!e.contains(n.startContainer)||!e.contains(n.endContainer))return null;let r=rn(n.startContainer),i=rn(n.endContainer);if(!r||!i||!e.contains(r)||!e.contains(i))return null;let o=Number(r.dataset.lineNumber),l=Number(i.dataset.lineNumber);if(!Number.isInteger(o)||!Number.isInteger(l))return null;if(o<l){let e=r.querySelector(".file-source-line-content");if(e?.contains(n.startContainer)){let t=document.createRange();if(t.selectNodeContents(e),t.setStart(n.startContainer,n.startOffset),0===t.toString().length){let e=r.nextElementSibling;e instanceof HTMLElement&&e.matches(".file-source-line[data-line-number]")&&(o=Number((r=e).dataset.lineNumber))}}let t=i.querySelector(".file-source-line-content");if(t?.contains(n.endContainer)){let e=document.createRange();if(e.selectNodeContents(t),e.setEnd(n.endContainer,n.endOffset),0===e.toString().length){let e=i.previousElementSibling;e instanceof HTMLElement&&e.matches(".file-source-line[data-line-number]")&&(l=Number((i=e).dataset.lineNumber))}}}return o>l?null:{startLine:o,endLine:l}}function ri({rows:e,stylesheet:t,useInlineStyles:n,wrapLines:i}){return e.map((e,o)=>{let l=e.children??[],s=l[0]?.properties?.className,a=Array.isArray(s)&&s.includes("react-syntax-highlighter-line-number"),d=a?l[0]:null,c=a?l.slice(1):l;return(0,r.jsxs)("span",{className:"file-source-line","data-line-number":o+1,style:{display:"flex",minWidth:"100%"},children:[d&&(0,nQ.Ay)({node:d,stylesheet:t,useInlineStyles:n,key:`source-line-number-${o}`}),(0,r.jsx)("span",{className:"file-source-line-content",style:{flex:"1 1 auto",minWidth:0,overflowWrap:i?"anywhere":"normal",whiteSpace:i?"pre-wrap":"pre"},children:c.map((e,r)=>(0,nQ.Ay)({node:e,stylesheet:t,useInlineStyles:n,key:`source-token-${o}-${r}`}))})]},`source-line-${o}`)})}function ro(e,t,n,r={}){let i=L(e),o=new URLSearchParams({type:t});for(let[e,t]of(n&&o.set("sessionId",n),Object.entries(r)))void 0!==t&&o.set(e,String(t));return`/api/files/${i}?${o.toString()}`}function rl({filePath:e,sourceSessionId:t}){let{t:n}=(0,m.s)();return(0,r.jsx)("a",{href:ro(e,"download",t),download:W(e),title:n("i18n.downloadFile"),"aria-label":n("i18n.downloadFile"),className:"file-viewer-icon-button",children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})}function rs(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function ra({patch:e}){let t,{t:n}=(0,m.s)(),i=(t=to(e))?t.flatMap(e=>e.rows.flatMap(e=>{if("hunk"===e.type)return[];if("context"===e.left.type&&"context"===e.right.type)return[{type:"unchanged",text:e.right.text,oldLineNo:e.left.lineNo,newLineNo:e.right.lineNo}];let t=[];return"removed"===e.left.type&&t.push({type:"removed",text:e.left.text,oldLineNo:e.left.lineNo,newLineNo:null}),"added"===e.right.type&&t.push({type:"added",text:e.right.text,oldLineNo:null,newLineNo:e.right.lineNo}),t})):[];if(!i.some(e=>"unchanged"!==e.type))return(0,r.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:n("i18n.noChanges")});let o=new Set(i.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),l=new Set;for(let e of o)for(let t=Math.max(0,e-3);t<=Math.min(i.length-1,e+3);t++)l.add(t);let s=[],a=0;for(;a<i.length;)if(l.has(a)){let e=[];for(;a<i.length&&l.has(a);)e.push(i[a]),a++;s.push({hidden:!1,lines:e})}else{let e=0;for(;a<i.length&&!l.has(a);)e++,a++;s.push({hidden:!0,count:e})}return(0,r.jsx)("div",{className:"file-diff-view",style:{width:"max-content",minWidth:"100%",...n9},children:s.map((e,t)=>{if(e.hidden)return(0,r.jsxs)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:["... ",e.count," unchanged lines ..."]},t);let n=e.lines.map((e,t)=>{let n="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",o="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,r.jsxs)("div",{className:"file-diff-line",style:{display:"flex",minWidth:"100%",background:n,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,r.jsx)("span",{style:re,children:"removed"===e.type?e.oldLineNo:e.newLineNo}),(0,r.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:o,userSelect:"none",flexShrink:0,fontWeight:600},children:i}),(0,r.jsx)("span",{className:"file-diff-line-content",style:{flexShrink:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},t)});return(0,r.jsx)("div",{children:n},t)})})}function rd({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:l}=(0,m.s)(),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),v=(0,i.useRef)(null),y=(0,i.useRef)(0),b=W(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),p(null),g(null),f(null),a(!1)},[e,n]),(0,i.useEffect)(()=>{if(a(!1),v.current&&(v.current.close(),v.current=null),!o)return;let t=!0,r=new EventSource(ro(e,"watch",n));v.current=r,r.addEventListener("connected",()=>{let r;a(!0),r=++y.current,fetch(ro(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===y.current){if(e.error)return void f(e.error);"number"==typeof e.size&&p(e.size),g(null),f(null),c(e=>e+1)}}).catch(e=>{t&&r===y.current&&f(String(e))})}),r.addEventListener("change",e=>{y.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&p(t.size)}catch{}g(null),f(null),c(e=>e+1)});let i=()=>{a(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),v.current===r&&(v.current=null)}},[e,n,o]);let k=ro(e,"read",n,d?{v:d}:void 0),w=null!=u?rs(u):null;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:z(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:b||"image"}),h&&(0,r.jsxs)("span",{children:[h.w," \xd7 ",h.h]}),w&&(0,r.jsx)("span",{children:w}),(0,r.jsxs)("span",{title:l(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]}),(0,r.jsx)(rl,{filePath:e,sourceSessionId:n})]}),(0,r.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",alignItems:"center",justifyContent:"center",padding:16,backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:x?(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13},children:x}):(0,r.jsx)("img",{src:k,alt:e,onLoad:e=>{let t=e.currentTarget;g({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>f("Failed to load image"),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function rc({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:l}=(0,m.s)(),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),v=(0,i.useRef)(null),y=(0,i.useRef)(0),b=W(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),p(null),g(null),f(null),a(!1)},[e,n]),(0,i.useEffect)(()=>{if(a(!1),v.current&&(v.current.close(),v.current=null),!o)return;let t=!0,r=new EventSource(ro(e,"watch",n));v.current=r,r.addEventListener("connected",()=>{let r;a(!0),r=++y.current,fetch(ro(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===y.current){if(e.error)return void f(e.error);"number"==typeof e.size&&p(e.size),g(null),f(null),c(e=>e+1)}}).catch(e=>{t&&r===y.current&&f(String(e))})}),r.addEventListener("change",e=>{y.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&p(t.size)}catch{}g(null),f(null),c(e=>e+1)});let i=()=>{a(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),v.current===r&&(v.current=null)}},[e,n,o]);let k=ro(e,"read",n,d?{v:d}:void 0);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:z(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:b||"audio"}),null!=h&&(0,r.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),n=Math.floor(t/60);return`${n}:${String(t%60).padStart(2,"0")}`}(h)}),null!=u&&(0,r.jsx)("span",{children:rs(u)}),(0,r.jsxs)("span",{title:l(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]}),(0,r.jsx)(rl,{filePath:e,sourceSessionId:n})]}),(0,r.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,r.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[x&&(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:x}),(0,r.jsx)("audio",{controls:!0,preload:"metadata",src:k,onLoadedMetadata:e=>g(e.currentTarget.duration),onError:()=>f("Failed to load audio"),style:{width:"100%"}},k)]})})]})}function ru({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:l}=(0,m.s)(),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),x=(0,i.useRef)(null),f=(0,i.useRef)(0),v=n2(e),y="pdf"===v,b=y?ro(e,"read",n,d?{v:d}:void 0):ro(e,"preview",n,d?{v:d}:void 0);return(0,i.useEffect)(()=>{c(0),p(null),g(null),a(!1);let t=!0,r=++f.current;return fetch(ro(e,"meta",n)).then(e=>e.json()).then(e=>{t&&r===f.current&&(e.error&&g(e.error),"number"==typeof e.size&&(p(e.size),!y&&e.size>0xa00000&&g("DOCX too large for preview (>10MB)")))}).catch(e=>{t&&r===f.current&&g(String(e))}),()=>{t=!1}},[e,y,n]),(0,i.useEffect)(()=>{if(a(!1),x.current&&(x.current.close(),x.current=null),!o)return;let t=!0,r=new EventSource(ro(e,"watch",n));x.current=r,r.addEventListener("connected",()=>{let r;a(!0),r=++f.current,fetch(ro(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===f.current){if(e.error)return void g(e.error);if("number"==typeof e.size&&(p(e.size),!y&&e.size>0xa00000))return void g("DOCX too large for preview (>10MB)");g(null),c(e=>e+1)}}).catch(e=>{t&&r===f.current&&g(String(e))})}),r.addEventListener("change",e=>{f.current+=1;try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(p(t.size),!y&&t.size>0xa00000))return void g("DOCX too large for preview (>10MB)")}catch{}g(null),c(e=>e+1)});let i=()=>{a(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),x.current===r&&(x.current=null)}},[e,y,n,o]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:z(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===v?"docx preview":"pdf"}),null!=u&&(0,r.jsx)("span",{children:rs(u)}),(0,r.jsx)(rl,{filePath:e,sourceSessionId:n}),(0,r.jsxs)("span",{title:l(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]})]}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:h?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:h}):(0,r.jsx)("iframe",{src:b,sandbox:y?void 0:"allow-same-origin",title:l("i18n.previewFile",{file:W(e)}),style:{width:"100%",height:"100%",border:"none",background:y?"var(--bg)":"#eef1f5"}},b)})]})}function rp({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:i,onMentionLines:o,onAtMention:l,gitRefreshKey:s,initialDisplayMode:a,initialState:d,onStateChange:c,watchEnabled:u=!0}){let p;return null!==(n0[n2(e)]??null)?(0,r.jsx)(rd,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==(n1[n2(e)]??null)?(0,r.jsx)(rc,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):null!==("pdf"===(p=n2(e))||"docx"===p?p:null)?(0,r.jsx)(ru,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):(0,r.jsx)(rh,{filePath:e,cwd:t,sourceSessionId:n,onOpenFile:i,onMentionLines:o,onAtMention:l,gitRefreshKey:s,initialDisplayMode:a,initialState:d,onStateChange:c,watchEnabled:u})}function rh({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:o,onMentionLines:l,onAtMention:s,gitRefreshKey:a,initialDisplayMode:d,initialState:c,onStateChange:u,watchEnabled:p=!0}){let{isDark:h}=e5(),{t:g}=(0,m.s)(),[x,f]=(0,i.useState)(null),[v,y]=(0,i.useState)(null),[b,k]=(0,i.useState)(!1),[w,j]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!0),[T,R]=(0,i.useState)(null),M=c?.displayMode??d??"source",I=c?.wrapLines??!1,L=c?.scrollTop??0,W=c?.scrollLeft??0,[$,P]=(0,i.useState)(M),[F,N]=(0,i.useState)(I),[A,D]=(0,i.useState)(!1),B=(0,i.useRef)(null),H=(0,i.useRef)(0),O=(0,i.useRef)(0),U=(0,i.useRef)(null),_=(0,i.useRef)(!1),q=(0,i.useRef)(void 0===c&&void 0===d),K=(0,i.useRef)(!0),V=(0,i.useRef)({displayMode:M,wrapLines:I,scrollTop:L,scrollLeft:W}),Y=(0,i.useRef)(u),[J,Z]=(0,i.useState)(null);Y.current=u;let G=(0,i.useCallback)(e=>{V.current.displayMode=e,P(e)},[]),X=(0,i.useCallback)(()=>{N(e=>{let t=!e;return V.current.wrapLines=t,t})},[]);(0,i.useEffect)(()=>(V.current={displayMode:M,wrapLines:I,scrollTop:L,scrollLeft:W},K.current=!0,_.current=!1,P(M),N(I),()=>{Y.current?.({...V.current})}),[e,n,M,I,L,W]);let Q=(0,i.useCallback)(e=>{let t=++H.current;return fetch(ro(e,"read",n)).then(e=>e.json()).then(e=>t!==H.current?null:e.error?(R(e.error),null):(R(null),f(e),e)).catch(e=>(t!==H.current||R(String(e)),null))},[n]),ee=(0,i.useCallback)(async e=>{let n=++O.current;if(k(!0),!t){y(null),k(!1),j(!0);return}try{let r=new URLSearchParams({cwd:t,path:e}),i=await fetch(`/api/git/diff?${r.toString()}`),o=await i.json();if(n!==O.current)return;y(i.ok&&o.supported&&"string"==typeof o.patch?o:null)}catch{n===O.current&&y(null)}finally{n===O.current&&(k(!1),j(!0))}},[t]);(0,i.useEffect)(()=>{let t=!0;return C(!0),R(null),f(null),y(null),j(!1),D(!1),Q(e).finally(()=>{t&&C(!1)}),()=>{t=!1}},[e,Q,n]),(0,i.useEffect)(()=>{if(D(!1),B.current&&(B.current.close(),B.current=null),!p)return;let t=()=>{Q(e),ee(e)},r=new EventSource(ro(e,"watch",n));B.current=r,r.addEventListener("connected",()=>{D(!0),t()}),r.addEventListener("change",t);let i=()=>{D(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{r.close(),B.current===r&&(B.current=null)}},[e,Q,ee,n,p]),(0,i.useEffect)(()=>{ee(e)},[ee,e,a]),(0,i.useEffect)(()=>{q.current&&(x?.language==="markdown"||x?.language==="html")&&(q.current=!1,G("preview"))},[x?.language,G]);let et=v?.supported===!0&&"string"==typeof v.patch,en=et&&"deleted"===v.status;(0,i.useEffect)(()=>{w&&!et&&"diff"===$&&G("source")},[$,w,et,G]),(0,i.useEffect)(()=>{"diff"===M&&et&&!_.current&&(_.current=!0,G("diff"))},[M,et,G]);let er=(0,i.useMemo)(()=>x?.language==="markdown"?eP(x.content):"",[x]),ei=(0,i.useMemo)(()=>x?.language==="markdown"?function(e){let t=function(e){let t=n4.exec(e);if(!t)return null;let n=/^---[ \t]*(?:(?:\r\n|\n|\r)|$)/gm;n.lastIndex=t[0].length;let r=n.exec(e);return r?{yaml:e.slice(t[0].length,r.index).replace(/(?:\r\n|\n|\r)$/,""),rest:e.slice(r.index+r[0].length)}:null}(e);if(!t)return{data:null,rest:e};try{let e=(0,n8.Hh)(t.yaml);if(e&&"object"==typeof e&&!Array.isArray(e))return{data:e,rest:t.rest}}catch{}return{data:null,rest:t.rest}}(x.content):null,[x]);(0,i.useEffect)(()=>{let e=()=>{let e=U.current;Z(l&&"source"===$&&e?rr(e,window.getSelection()):null)};if(e(),l&&"source"===$)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[x?.content,$,l]);let eo=(0,i.useCallback)(n=>{l&&n&&l(z(e,t),n.startLine,n.endLine)},[t,e,l]);if((0,i.useEffect)(()=>{if(!l||"source"!==$)return;let e=e=>{if(e.repeat||"i"!==e.key.toLowerCase()||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest("input, textarea, [contenteditable='true']"))return;let n=U.current,r=n?rr(n,window.getSelection()):null;r&&(e.preventDefault(),eo(r))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[$,eo,l]),(0,i.useEffect)(()=>{if(!K.current||S||T&&!en||"diff"===M&&!w||"diff"===M&&et&&"diff"!==$)return;let e=U.current;e&&(e.scrollTop=V.current.scrollTop,e.scrollLeft=V.current.scrollLeft,K.current=!1)},[x?.content,$,T,w,et,en,S,M]),S||"diff"===M&&b&&!x)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:g("i18n.loading")});if(T&&!en)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:T});if(!x&&!en)return null;let el=x?.language??"text",es=x?.content??"",ea="html"===el,ed="markdown"===el,ec=E(e),eu=es.split("\n"),ep=en?"diff":$,eh=en?["diff"]:["source",...ea||ed?["preview"]:[],...et?["diff"]:[]],eg=en?g("files.deleted"):`${el} \xb7 ${eu.length} lines \xb7 ${rs(x.size)}`;return(0,r.jsxs)("div",{className:"file-viewer-shell",style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{className:"file-viewer-toolbar",style:{display:"flex",alignItems:"center",gap:8,padding:"5px 12px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{className:"file-viewer-path",style:{fontFamily:"var(--font-mono)"},title:e,children:z(e,t)}),(0,r.jsx)("span",{className:"file-viewer-meta",title:eg,children:eg}),!en&&(0,r.jsx)("span",{title:A?g("i18n.liveSync"):g("i18n.notWatching"),"aria-label":A?g("i18n.liveSync"):g("i18n.notWatching"),className:"file-viewer-live-indicator",style:{background:A?"#4ade80":"var(--border)",boxShadow:A?"0 0 4px #4ade80":"none"}}),(0,r.jsxs)("div",{className:"file-viewer-controls",children:[eh.length>1&&(0,r.jsx)("div",{className:"file-viewer-mode-switch","aria-label":g("i18n.fileViewMode"),children:eh.map(e=>{let t=ep===e;return(0,r.jsx)("button",{type:"button",onClick:()=>G(e),title:"diff"===e?g("i18n.compareHead"):void 0,"aria-pressed":t,className:"file-viewer-mode-button",style:{background:t?"var(--bg-selected)":"transparent",color:t?"var(--text)":"var(--text-muted)"},children:n7[e]},e)})}),(0,r.jsxs)("div",{className:"file-viewer-actions",children:[(s||l)&&(0,r.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{J&&l?eo(J):s?.(z(e,t),!1)},title:J&&l?`${g("i18n.mentionSelectedLines")} (L${J.startLine}${J.startLine!==J.endLine?`-L${J.endLine}`:""})`:g("files.insertPath"),"aria-label":g("files.mention"),disabled:!s&&!l,className:"file-viewer-icon-button",children:(0,r.jsx)(rt,{})}),"source"===ep&&(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("button",{type:"button",onClick:X,title:F?g("i18n.disableWrap"):g("i18n.enableWrap"),"aria-label":F?g("i18n.disableWrap"):g("i18n.enableWrap"),"aria-pressed":F,className:"file-viewer-icon-button",style:{background:F?"var(--bg-selected)":"transparent",color:F?"var(--text)":"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 6h18"}),(0,r.jsx)("path",{d:"M3 12h15a3 3 0 1 1 0 6h-4"}),(0,r.jsx)("path",{d:"m16 16-2 2 2 2"}),(0,r.jsx)("path",{d:"M3 18h7"})]})})})]}),!en&&(0,r.jsx)(rl,{filePath:e,sourceSessionId:n})]})]}),(0,r.jsx)("div",{ref:U,className:"file-viewer-content",onScroll:e=>{V.current.scrollTop=e.currentTarget.scrollTop,V.current.scrollLeft=e.currentTarget.scrollLeft},style:{flex:1,overflow:"auto",background:"var(--bg)"},children:"diff"===ep&&et?(0,r.jsx)(ra,{patch:v.patch}):ea&&"preview"===ep?(0,r.jsx)("iframe",{srcDoc:es,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:g("i18n.htmlPreview")}):ed&&"preview"===ep?(0,r.jsxs)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:[ei?.data&&(0,r.jsx)(n3,{data:ei.data}),(0,r.jsx)(eT.oz,{remarkPlugins:eB,rehypePlugins:eO,components:{code({className:e,children:t,...n}){let i=e?.replace("language-","").toLowerCase()??"",o=String(t);return e?.includes("language-")||o.includes("\n")?"mermaid"===i?(0,r.jsx)(e7,{code:o.replace(/\n$/,""),defaultPreview:!0}):(0,r.jsx)(te,{code:o.replace(/\n$/,""),lang:i}):(0,r.jsx)("code",{className:e,...n,children:t})},pre:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),a({href:e,children:n,...i}){delete i.node;let l=o?eS(e,ec,t??ec):null;return l&&o?(0,r.jsx)("a",{href:e,...i,onClick:e=>{e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),o(l))},children:n}):(0,r.jsx)("a",{href:e,...i,children:n})},img({src:e,alt:i,...o}){delete o.node;let l="string"==typeof e?eS(e,ec,t??ec):null,s=l?ro(l,"read",n):e;return(0,r.jsx)("img",{src:s,alt:i??"",loading:"lazy",...o})}},children:er})]}):(0,r.jsx)(eU.A,{className:F?"file-source-view is-wrapped":"file-source-view",language:"text"===el?"plaintext":el,style:h?e_.xJ:e_.vs,showLineNumbers:!0,lineNumberStyle:{...re},customStyle:{margin:0,padding:0,border:0,background:"var(--bg)",...n9,width:F?"100%":"max-content",minWidth:"100%",minHeight:"100%",overflow:"visible"},codeTagProps:{style:{fontFamily:"var(--font-mono)",overflowWrap:F?"anywhere":"normal"}},renderer:e=>(0,r.jsx)(ri,{...e,wrapLines:F}),wrapLongLines:F,children:es})})]})}function rg({tabs:e,activeTabId:t,onSelectTab:n,onCloseTab:o}){let{t:l}=(0,m.s)(),[s,a]=(0,i.useState)(null);return(0,r.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let i=e.id===t;return(0,r.jsxs)("div",{onClick:()=>n(e.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:t=>{1===t.button&&(t.preventDefault(),t.stopPropagation(),o(e.id))},style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:i?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:i?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,r.jsx)("span",{style:{flexShrink:0,opacity:i?1:.7,display:"flex",alignItems:"center"},children:M(e.label,13)}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:i?500:400},title:e.filePath,children:e.label}),(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),o(e.id)},onMouseEnter:()=>a(e.id),onMouseLeave:()=>a(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,background:s===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:4,color:s===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:l("i18n.close"),"aria-label":`${l("i18n.close")} ${e.label}`,children:(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,r.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id)})})}let rx=["input","output","cacheRead","cacheWrite"];function rf(e){return{input:e?.input===void 0?"":String(e.input),output:e?.output===void 0?"":String(e.output),cacheRead:e?.cacheRead===void 0?"":String(e.cacheRead),cacheWrite:e?.cacheWrite===void 0?"":String(e.cacheWrite)}}function rm(e){if(!rv(e))return;let t=e=>{if(!e.trim())return 0;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0},n=t(e.input),r=t(e.output),i=t(e.cacheRead),o=t(e.cacheWrite);if(void 0!==n&&void 0!==r&&void 0!==i&&void 0!==o)return{input:n,output:r,cacheRead:i,cacheWrite:o}}function rv(e){return rx.some(t=>""!==e[t].trim())}var ry=n(67381),rb=n(64433),rk=n(70350),rw=n(88195),rj=n(9312),rS=n(87275),rC=n(22008),rT=n(95476),rR=n(35029),rM=n(14489),rI=n(78728),rL=n(19872),rW=n(7751),rE=n(92526),rz=n(48238),r$=n(57794),rP=n(41098),rF=n(84604),rN=n(15315),rA=n(74278),rD=n(55457),rB=n(71437),rH=n(29167),rO=n(97283),rU=n(34166),r_=n(33889),rq=n(85486),rK=n(74068),rV=n(83546),rY=n(83709);let rJ={anthropic:{Icon:ry.A,hasColor:!1},openai:{Icon:rb.A,hasColor:!1},"openai-codex":{Icon:rb.A,hasColor:!1},google:{Icon:rk.A,hasColor:!0},"google-vertex":{Icon:rk.A,hasColor:!0},"ant-ling":{Icon:r_.A,hasColor:!0},deepseek:{Icon:rw.A,hasColor:!0},groq:{Icon:rj.A,hasColor:!1},mistral:{Icon:rS.A,hasColor:!0},moonshotai:{Icon:rC.A,hasColor:!1},"moonshotai-cn":{Icon:rC.A,hasColor:!1},moonshot:{Icon:rC.A,hasColor:!1},minimax:{Icon:rT.A,hasColor:!0},"minimax-cn":{Icon:rT.A,hasColor:!0},fireworks:{Icon:rR.A,hasColor:!0},huggingface:{Icon:rM.A,hasColor:!0},cerebras:{Icon:rI.A,hasColor:!0},openrouter:{Icon:rL.A,hasColor:!1},xai:{Icon:rW.A,hasColor:!1},"cloudflare-ai-gateway":{Icon:rE.A,hasColor:!0},"cloudflare-workers-ai":{Icon:rE.A,hasColor:!0},"vercel-ai-gateway":{Icon:rz.A,hasColor:!1},"github-copilot":{Icon:r$.A,hasColor:!1},"amazon-bedrock":{Icon:rP.A,hasColor:!0},"azure-openai-responses":{Icon:rF.A,hasColor:!0},"kimi-coding":{Icon:rN.A,hasColor:!0},nvidia:{Icon:rq.A,hasColor:!0},opencode:{Icon:rK.A,hasColor:!1},"opencode-go":{Icon:rK.A,hasColor:!1},qwen:{Icon:rA.A,hasColor:!0},xiaomi:{Icon:rV.A,hasColor:!1},"xiaomi-token-plan-ams":{Icon:rV.A,hasColor:!1},"xiaomi-token-plan-cn":{Icon:rV.A,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:rV.A,hasColor:!1},zai:{Icon:rY.A,hasColor:!1},"zai-coding-cn":{Icon:rY.A,hasColor:!1},zhipu:{Icon:rD.A,hasColor:!0},cohere:{Icon:rB.A,hasColor:!0},perplexity:{Icon:rH.A,hasColor:!0},together:{Icon:rO.A,hasColor:!0},grok:{Icon:rU.A,hasColor:!1}},rZ=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function rG({label:e,children:t}){return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}let rX={padding:"6px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",width:"100%",boxSizing:"border-box"};function rQ({value:e,onChange:t,placeholder:n,mono:i}){return(0,r.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:n,style:{...rX,fontFamily:i?"var(--font-mono)":"inherit"}})}function r0({value:e,onChange:t,placeholder:n,mono:o,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,u]=(0,i.useState)(!1),{t:p}=(0,m.s)();return(0,i.useEffect)(()=>{e||u(!1)},[e]),(0,r.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,r.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:n,style:{...rX,paddingRight:34,fontFamily:o?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,r.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":p(c?"i18n.hideDetails":"i18n.showDetails"),title:p(c?"i18n.hideDetails":"i18n.showDetails"),style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,r.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,r.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,r.jsx)("path",{d:"M1 1l22 22"})]}):(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function r1({value:e,onChange:t,placeholder:n}){return(0,r.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:n,style:rX})}function r2({value:e,onChange:t,options:n,required:i}){let{t:o}=(0,m.s)();return(0,r.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...rX,color:e?"var(--text)":"var(--text-dim)"},children:[!i&&(0,r.jsxs)("option",{value:"",children:["— ",o("i18n.default")," / none —"]}),n.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]})}function r8({label:e,checked:t,onChange:n}){return(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:e=>n(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function r4({children:e}){return(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:e})}function r6({name:e,provider:t,onChange:n,onRename:o,onDelete:l,onAddModels:s}){let{t:a}=(0,m.s)(),[d,c]=(0,i.useState)(e),[u,p]=(0,i.useState)({phase:"idle"}),[h,g]=(0,i.useState)(""),[x,f]=(0,i.useState)([]),v=(0,i.useRef)(0),y=(0,i.useRef)(null);(0,i.useEffect)(()=>c(e),[e]);let b=(e,r)=>n({...t,[e]:r});(0,i.useEffect)(()=>{t.api||n({...t,api:"openai-completions"})},[t.api]),(0,i.useEffect)(()=>{v.current+=1,p({phase:"idle"}),g(""),f([])},[e,t.baseUrl,t.api,t.apiKey]);let k=(0,i.useCallback)(async()=>{if(!t.baseUrl?.trim()||"loading"===u.phase)return;let n=++v.current;p({phase:"loading"}),f([]);try{let r=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:{...t,models:void 0}})}),i=await r.json();if(n!==v.current)return;if(!r.ok||i.error||!i.models)return void p({phase:"error",message:i.error??`HTTP ${r.status}`});p({phase:"success",models:i.models,endpoint:i.endpoint??t.baseUrl})}catch(e){if(n!==v.current)return;p({phase:"error",message:e instanceof Error?e.message:String(e)})}},[u.phase,e,t]),w=new Set((t.models??[]).map(e=>e.id)),j="success"===u.phase?u.models:[],S=h.trim().toLocaleLowerCase(),C=j.filter(e=>!S||e.id.toLocaleLowerCase().includes(S)||e.name?.toLocaleLowerCase().includes(S)),T=C.slice(0,300),R=T.filter(e=>!w.has(e.id)).map(e=>e.id),M=x.filter(e=>!w.has(e)).length,I=R.length>0&&R.every(e=>x.includes(e)),L=!I&&R.some(e=>x.includes(e));return(0,i.useEffect)(()=>{y.current&&(y.current.indeterminate=L)},[L]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(r4,{children:a("i18n.provider")}),(0,r.jsx)("button",{onClick:l,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:a("i18n.delete")})]}),(0,r.jsxs)(rG,{label:a("i18n.providerName"),children:[(0,r.jsx)(rQ,{value:d,onChange:c,placeholder:"provider-name",mono:!0}),d!==e&&d.trim()&&(0,r.jsx)("button",{onClick:()=>o(d.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:a("i18n.rename")})]}),(0,r.jsx)(rG,{label:"Base URL",children:(0,r.jsx)(rQ,{value:t.baseUrl??"",onChange:e=>b("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,r.jsxs)(rG,{label:"API Key",children:[(0,r.jsx)(r0,{value:t.apiKey??"",onChange:e=>b("apiKey",e||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,r.jsx)(rG,{label:"API",children:(0,r.jsx)(r2,{value:t.api??"openai-completions",onChange:e=>b("api",e),options:rZ,required:!0})}),(0,r.jsxs)(rG,{label:"Headers",children:[(0,r.jsx)(it,{headers:t.headers,onChange:e=>b("headers",e)}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Added to every request from this provider (e.g. User-Agent). Useful for gateways with bot detection."})]}),(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:14,display:"flex",flexDirection:"column",gap:10},children:["success"!==u.phase&&(0,r.jsx)("button",{onClick:k,disabled:!t.baseUrl?.trim()||"loading"===u.phase,style:{alignSelf:"flex-start",height:30,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:t.baseUrl?.trim()&&"loading"!==u.phase?"var(--text-muted)":"var(--text-dim)",cursor:t.baseUrl?.trim()&&"loading"!==u.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===u.phase?a("models.discoveryFetching"):a("models.discoveryFetch")}),"error"===u.phase&&(0,r.jsx)("div",{style:{padding:"7px 9px",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",fontSize:11,lineHeight:1.4},children:u.message}),"success"===u.phase&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{value:h,onChange:e=>g(e.target.value),placeholder:a("models.discoveryFilterPlaceholder",{count:u.models.length}),"aria-label":a("models.discoveryFilter"),style:{...rX,width:"100%",minWidth:0}}),(0,r.jsxs)("div",{style:{maxHeight:220,overflowY:"auto",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)"},children:[(0,r.jsxs)("label",{style:{minHeight:32,padding:"5px 9px",display:"flex",alignItems:"center",gap:8,position:"sticky",top:0,zIndex:1,borderBottom:"1px solid var(--border)",background:"var(--bg)",cursor:R.length?"pointer":"default",color:"var(--text-muted)",fontSize:10,fontWeight:600},children:[(0,r.jsx)("input",{ref:y,type:"checkbox",checked:I,disabled:0===R.length,onChange:()=>{let e=new Set(R);f(t=>I?t.filter(t=>!e.has(t)):Array.from(new Set([...t,...R])))},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),a("models.discoverySelectShown")]}),0===T.length?(0,r.jsx)("div",{style:{padding:12,color:"var(--text-dim)",fontSize:11},children:a("models.discoveryNoMatches")}):T.map((e,t)=>{let n=w.has(e.id),i=x.includes(e.id);return(0,r.jsxs)("label",{style:{minHeight:36,padding:"6px 9px",display:"flex",alignItems:"center",gap:8,borderTop:0===t?"none":"1px solid var(--border)",cursor:n?"default":"pointer",opacity:n?.65:1},children:[(0,r.jsx)("input",{type:"checkbox",checked:i||n,disabled:n,onChange:()=>{var t;return t=e.id,void f(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),(0,r.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11},children:e.name??e.id}),e.name&&(0,r.jsx)("code",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)"},children:e.id})]}),n&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10},children:a("models.discoveryAdded")})]},e.id)})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,r.jsx)("span",{title:u.endpoint,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:C.length>T.length?a("models.discoveryShowing",{shown:T.length,total:C.length}):a("models.discoveryFetched",{count:u.models.length})}),(0,r.jsx)("button",{onClick:()=>{if("success"!==u.phase)return;let e=new Set(x),t=u.models.filter(t=>e.has(t.id)&&!w.has(t.id));0!==t.length&&(s(t),f([]))},disabled:0===M,style:{height:28,padding:"0 11px",border:"none",borderRadius:5,background:M?"var(--accent)":"var(--bg-panel)",color:M?"#fff":"var(--text-dim)",cursor:M?"pointer":"not-allowed",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:M?a("models.discoveryAddSelectedCount",{count:M}):a("models.discoveryAddSelected")})]})]})]})]})}let r5=["off","minimal","low","medium","high","xhigh","max"],r3={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function r7({value:e,onChange:t}){let n=e??{},i=(e,r)=>{let i={...n};"omit"===r?delete i[e]:i[e]=r,t(Object.keys(i).length?i:void 0)};return(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:r5.map(e=>{let t=n[e],o=e in n?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=r3[e],a={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:s,flexShrink:0,opacity:"null"===o?.3:1}}),(0,r.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===o?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===o?"line-through":"none"},children:e})]}),(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,r.jsx)("button",{onClick:()=>i(e,"omit"),style:{...a,..."omit"===o?d:{}},children:"Default"}),(0,r.jsx)("button",{onClick:()=>i(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===o?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===o?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,r.jsx)("button",{onClick:()=>i(e,l||e),style:{...a,..."string"===o?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,r.jsx)("input",{value:l,onChange:t=>i(e,t.target.value),onFocus:()=>{"string"!==o&&i(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===o?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===o?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let r9={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function ie(e){return e.compat?.thinkingFormat==="deepseek"}function it({headers:e,onChange:t}){let[n,o]=(0,i.useState)(()=>Object.entries(e??{}).map(([e,t],n)=>({id:n,name:e,value:t}))),l=(0,i.useRef)(n.length),s=e=>{o(e),t(function(e){let t={};for(let n of e){let e=n.name.trim();e&&(t[e]=n.value)}return Object.keys(t).length?t:void 0}(e))},a=(e,t)=>{s(n.map(n=>n.id===e?{...n,...t}:n))},d={padding:"6px 9px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,lineHeight:1};return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[n.map(e=>(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("input",{value:e.name,onChange:t=>a(e.id,{name:t.target.value}),placeholder:"Header-Name",style:{...rX,fontFamily:"var(--font-mono)",flex:1}}),(0,r.jsx)("input",{value:e.value,onChange:t=>a(e.id,{value:t.target.value}),placeholder:"value",style:{...rX,fontFamily:"var(--font-mono)",flex:1}}),(0,r.jsx)("button",{onClick:()=>{var t;return t=e.id,void s(n.filter(e=>e.id!==t))},style:d,children:"✕"})]},e.id)),(0,r.jsx)("button",{onClick:()=>o(e=>[...e,{id:l.current++,name:"",value:""}]),style:{padding:"5px 9px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:5,alignSelf:"flex-start"},children:"+ Add header"})]})}function ir({providerName:e,provider:t,model:n,onChange:o,onDelete:l}){let[s,a]=(0,i.useState)({phase:"idle"}),{t:d}=(0,m.s)(),[c,u]=(0,i.useState)({phase:"idle"}),[p,h]=(0,i.useState)(!1),[g,x]=(0,i.useState)(()=>rf(n.cost)),f=(0,i.useRef)(g),[v,y]=(0,i.useState)(!1),b=(0,i.useRef)(0),k=(0,i.useRef)(null),w=(0,i.useRef)(n.cost),j=(e,t)=>o({...n,[e]:t}),S=(()=>{if("idle"===s.phase)return null;if("testing"===s.phase)return d("i18n.testingModel");let e=[void 0!==s.latencyMs?`${s.latencyMs}ms`:null,void 0!==s.status?`HTTP ${s.status}`:null].filter(Boolean);return"success"===s.phase?[d("i18n.connected"),...e,s.responseText||null].filter(Boolean).join(" \xb7 "):[d("i18n.failed"),...e,s.message].filter(Boolean).join(" \xb7 ")})();(0,i.useEffect)(()=>{a({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,n.id,n.api]),(0,i.useEffect)(()=>{b.current+=1,u({phase:"idle"}),k.current=null},[e,t.baseUrl,n.id]);let C=(0,i.useCallback)(async()=>{if(n.id.trim()&&"testing"!==s.phase){a({phase:"testing"});try{let r=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:n})}),i=await r.json();if(!r.ok||!i.ok)return void a({phase:"error",message:i.error??`HTTP ${r.status}`,latencyMs:i.latencyMs,status:i.status});a({phase:"success",latencyMs:i.latencyMs,status:i.status,responseText:i.responseText})}catch(e){a({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[n,t,e,s.phase]),T=(0,i.useCallback)(async()=>{let r=n.id.trim();if(!r||"loading"===c.phase)return;let i=++b.current;u({phase:"loading"});try{let l=new URLSearchParams({q:r,provider:e,limit:"50"});t.baseUrl?.trim()&&l.set("baseUrl",t.baseUrl.trim());let s=await fetch(`/api/models-config/catalog?${l}`),a=await s.json();if(i!==b.current)return;if(!s.ok||a.error||!a.recommendation)return void u({phase:"error",message:a.error??`HTTP ${s.status}`});let d=function(e,t){let n={...e},r=0;if(!e.name?.trim()&&t.name&&(n.name=t.name,r+=1),void 0===e.reasoning&&!0===t.reasoning&&(n.reasoning=!0,r+=1),!e.input?.length&&t.input?.length&&(n.input=[...t.input],r+=1),void 0===e.contextWindow&&void 0!==t.contextWindow&&(n.contextWindow=t.contextWindow,r+=1),void 0===e.maxTokens&&void 0!==t.maxTokens&&(n.maxTokens=t.maxTokens,r+=1),t.cost){let i={...e.cost??{}},o=0;for(let e of["input","output","cacheRead","cacheWrite"])void 0===i[e]&&void 0!==t.cost[e]&&(i[e]=t.cost[e],o+=1);let l=rm(rf(i));o>0&&l&&(n.cost={...i,...l},r+=o)}return{model:n,appliedCount:r}}(n,a.recommendation.preset);d.appliedCount>0&&(k.current=n,o(d.model)),h(!1),u({phase:"success",recommendation:a.recommendation,appliedCount:d.appliedCount})}catch(e){if(i!==b.current)return;u({phase:"error",message:e instanceof Error?e.message:String(e)})}},[c.phase,n,o,t.baseUrl,e]),R=(()=>{if("success"!==c.phase)return null;let{recommendation:t,appliedCount:n}=c,r=n>0?d("models.catalogFilled",{count:n}):d("models.catalogNoEmptyFields");if("unreliable"===t.price.status){let e="no-exact-match"===t.price.reason?d("models.catalogNoExactMatch"):d("models.catalogPriceUnreliable");return`${r} \xb7 ${e}`}let i="provider"===t.price.method?d("models.catalogPriceProvider",{provider:t.price.providerName??t.price.providerId??e}):"base-url"===t.price.method?d("models.catalogPriceBaseUrl",{provider:t.price.providerName??t.price.providerId??e}):d("models.catalogPriceConsensus",{support:t.price.support,total:t.price.total});return`${r} \xb7 ${i}`})(),M="error"===c.phase?c.message:R,I="error"===c.phase?"#ef4444":"success"===c.phase&&"unreliable"===c.recommendation.price.status?"#d97706":"var(--text-dim)",L=[{key:"input",label:d("models.costInput")},{key:"output",label:d("models.costOutput")},{key:"cacheRead",label:d("models.costCacheRead")},{key:"cacheWrite",label:d("models.costCacheWrite")}],W=new Set(Object.keys(n.compat??{})),E=0;ie(n)&&(E+=1,W.delete("thinkingFormat"),W.delete("requiresReasoningContentOnAssistantMessages")),Object.prototype.hasOwnProperty.call(n.compat??{},"supportsDeveloperRole")&&(E+=1,W.delete("supportsDeveloperRole")),E+=W.size;let z=[n.api?`API: ${n.api}`:null,Object.keys(n.headers??{}).length?d("models.headersSummary",{count:Object.keys(n.headers??{}).length}):null,E?d("models.compatSummary",{count:E}):null,Object.keys(n.thinkingLevelMap??{}).length?d("models.thinkingSummary",{count:Object.keys(n.thinkingLevelMap??{}).length}):null].filter(e=>!!e),$=z.length?z.join(" \xb7 "):d("models.providerDefaults");return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(r4,{children:d("i18n.model")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[S&&(0,r.jsx)("span",{title:S,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===s.phase?"#fecaca":"success"===s.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===s.phase?"#fee2e2":"success"===s.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:S}),(0,r.jsxs)("button",{onClick:C,disabled:!n.id.trim()||"testing"===s.phase,title:d("i18n.testConnection"),style:{height:24,padding:"0 8px",background:"success"===s.phase?"#16a34a":"none",border:`1px solid ${"success"===s.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===s.phase?"#fff":n.id.trim()&&"testing"!==s.phase?"var(--text-muted)":"var(--text-dim)",cursor:n.id.trim()&&"testing"!==s.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===s.phase&&(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===s.phase?d("i18n.checking"):"success"===s.phase?d("common.ok"):d("i18n.test")]}),(0,r.jsx)("button",{onClick:l,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:d("i18n.remove")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,r.jsx)(rG,{label:"ID *",children:(0,r.jsx)(rQ,{value:n.id,onChange:e=>j("id",e),placeholder:"model-id",mono:!0})}),(0,r.jsx)(rG,{label:"Name",children:(0,r.jsx)(rQ,{value:n.name??"",onChange:e=>j("name",e||void 0),placeholder:"Display name"})})]}),(0,r.jsxs)("div",{style:{padding:"2px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:()=>void T(),disabled:!n.id.trim()||"loading"===c.phase,style:{height:28,padding:"0 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:n.id.trim()&&"loading"!==c.phase?"var(--text-muted)":"var(--text-dim)",cursor:n.id.trim()&&"loading"!==c.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===c.phase?d("models.catalogFilling"):d("models.catalogFill")}),(0,r.jsx)("a",{href:"https://github.com/anomalyco/models.dev",target:"_blank",rel:"noreferrer",style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10,textDecoration:"none"},children:d("models.catalogSource")})]}),M&&(0,r.jsxs)("div",{"aria-live":"polite",style:{marginTop:8,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:I,fontSize:10},children:[(0,r.jsx)("span",{title:M,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:M}),k.current&&(0,r.jsx)("button",{onClick:()=>{let e=k.current;e&&(k.current=null,o(e),u({phase:"idle"}))},style:{flexShrink:0,padding:"0 2px",border:"none",background:"none",color:"var(--accent)",cursor:"pointer",fontSize:10},children:d("models.catalogUndo")})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(r4,{children:d("models.capabilities")}),(0,r.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap",marginTop:8},children:[(0,r.jsx)(r8,{label:d("models.reasoning"),checked:n.reasoning??!1,onChange:e=>j("reasoning",e||void 0)}),(0,r.jsx)(r8,{label:d("models.imageInput"),checked:n.input?.includes("image")??!1,onChange:e=>j("input",e?["text","image"]:void 0)})]})]}),(0,r.jsxs)("section",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,r.jsx)(r4,{children:d("models.modelSpecs")}),(0,r.jsx)("button",{type:"button",onClick:()=>{if(p)return void h(!1);w.current=n.cost;let e=rf(n.cost);f.current=e,x(e),h(!0)},"aria-expanded":p,style:{padding:"2px 4px",border:"none",background:"transparent",color:"var(--accent)",cursor:"pointer",fontSize:10},children:p?d("models.finishEditingCosts"):d("models.editCosts")})]}),(0,r.jsxs)("div",{style:{marginTop:10,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:10},children:[(0,r.jsx)(rG,{label:d("models.contextWindow"),children:(0,r.jsx)(r1,{value:void 0!==n.contextWindow?String(n.contextWindow):"",onChange:e=>j("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,r.jsx)(rG,{label:d("models.maxOutputTokens"),children:(0,r.jsx)(r1,{value:void 0!==n.maxTokens?String(n.maxTokens):"",onChange:e=>j("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,r.jsxs)("div",{style:{marginTop:16},children:[(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontWeight:600,textTransform:"uppercase"},children:d("models.costPerMillion")}),p?(0,r.jsxs)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(110px, 1fr))",gap:8},children:[L.map(({key:e,label:t})=>(0,r.jsx)(rG,{label:t,children:(0,r.jsx)(r1,{value:g[e],onChange:t=>{let r,i,l;return i=rm(r={...f.current,[e]:t}),l={...n},void(f.current=r,x(r),i?(l.cost={...w.current??{},...i},w.current=l.cost):delete l.cost,o(l))},placeholder:"0"})},e)),rv(g)&&!rm(g)&&(0,r.jsx)("div",{"aria-live":"polite",style:{gridColumn:"1 / -1",color:"#d97706",fontSize:10},children:d("models.costAllRequired")})]}):(0,r.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(105px, 1fr))",gap:"8px 16px"},children:L.map(({key:e,label:t})=>{let i,o=n.cost?.[e]===void 0;return(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t}),(0,r.jsx)("div",{style:{marginTop:3,color:o?"var(--text-dim)":"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:void 0===(i=n.cost?.[e])?d("models.notProvided"):`$${String(i)}`})]},e)})})]})]}),(0,r.jsxs)("section",{style:{borderTop:"1px solid var(--border)",paddingTop:4},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>y(e=>!e),"aria-expanded":v,"aria-controls":"model-advanced-settings",style:{width:"100%",minHeight:48,padding:"8px 0",border:"none",background:"transparent",display:"grid",gridTemplateColumns:"minmax(0, 1fr) 18px",alignItems:"center",gap:10,color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsxs)("span",{style:{minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:11,fontWeight:600},children:d("models.advancedSettings")}),(0,r.jsx)("span",{style:{display:"block",marginTop:3,color:"var(--text-dim)",fontSize:10,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:$})]}),(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{color:"var(--text-dim)",transform:v?"rotate(180deg)":"none",transition:"transform 0.15s ease"},children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),v&&(0,r.jsxs)("div",{id:"model-advanced-settings",style:{display:"flex",flexDirection:"column",gap:14,padding:"4px 0 16px"},children:[(0,r.jsx)(rG,{label:d("models.apiOverride"),children:(0,r.jsx)(r2,{value:n.api??"",onChange:e=>j("api",e||void 0),options:rZ})}),(0,r.jsxs)(rG,{label:d("models.headers"),children:[(0,r.jsx)(it,{headers:n.headers,onChange:e=>j("headers",e)}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:d("models.headersHelp")})]}),n.reasoning&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,r.jsx)(r4,{children:d("models.compatibility")}),(0,r.jsx)(r8,{label:d("models.deepSeekThinkingCompat"),checked:ie(n),onChange:e=>o(function(e,t){if(t)return{...e,compat:{...e.compat??{},...r9}};if(!e.compat)return e;let n={...e.compat};return delete n.thinkingFormat,delete n.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(n).length?n:void 0}}(n,e))}),(0,r.jsx)(r8,{label:d("models.developerRole"),checked:!1!==({...t.compat??{},...n.compat??{}}).supportsDeveloperRole,onChange:e=>o({...n,compat:{...n.compat??{},supportsDeveloperRole:e}})}),(0,r.jsxs)("div",{style:{marginTop:4},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,marginBottom:8},children:[(0,r.jsx)(r4,{children:d("models.thinkingLevelMap")}),n.thinkingLevelMap&&(0,r.jsx)("button",{type:"button",onClick:()=>j("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 5px",background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer"},children:d("models.clearAll")})]}),(0,r.jsx)(r7,{value:n.thinkingLevelMap,onChange:e=>j("thinkingLevelMap",e)})]})]})]})]})]})}function ii({provider:e,onRefresh:t}){let[n,o]=(0,i.useState)({phase:"idle"}),{t:l}=(0,m.s)(),[s,a]=(0,i.useState)(""),d=(0,i.useRef)(null),c=(0,i.useRef)(null);(0,i.useEffect)(()=>{("auth"===n.phase||"prompt"===n.phase)&&setTimeout(()=>c.current?.focus(),50)},[n.phase]),(0,i.useEffect)(()=>{o({phase:"idle"}),a(""),d.current?.close(),d.current=null},[e.id]),(0,i.useEffect)(()=>()=>{d.current?.close()},[]);let u=(0,i.useCallback)(()=>{d.current?.close(),o({phase:"connecting"}),a("");let n=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);d.current=n,n.onmessage=e=>{let r=JSON.parse(e.data);"auth"===r.type?(o({phase:"auth",url:r.url,instructions:r.instructions??null,token:r.token}),window.open(r.url,"_blank","noopener,noreferrer")):"device_code"===r.type?(o({phase:"device_code",userCode:r.userCode,verificationUri:r.verificationUri,intervalSeconds:r.intervalSeconds??null,expiresInSeconds:r.expiresInSeconds??null}),window.open(r.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===r.type?o({phase:"prompt",message:r.message,placeholder:r.placeholder??null,token:r.token}):"select_request"===r.type?o({phase:"select",message:r.message,options:r.options??[],token:r.token}):"progress"===r.type?o({phase:"progress",message:r.message}):"success"===r.type?(n.close(),o({phase:"success"}),t()):"error"===r.type?(n.close(),o({phase:"error",message:r.message})):"cancelled"===r.type&&(n.close(),o({phase:"idle"}))},n.onerror=()=>{n.close(),o(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),p=(0,i.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),o({phase:"idle"}),t()},[e.id,t]),h=(0,i.useCallback)(async(t,n)=>{if(n.trim()){o({phase:"progress",message:"Verifying…"});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:n.trim()})});if(!r.ok){let e=await r.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${r.status}`});return}a("")}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),g=(0,i.useCallback)(async(t,n)=>{o({phase:"progress",message:"Continuing…"});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:n})});if(!r.ok){let e=await r.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${r.status}`})}}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),x="connecting"===n.phase||"progress"===n.phase||"auth"===n.phase||"device_code"===n.phase||"prompt"===n.phase||"select"===n.phase;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(r4,{children:l("i18n.subscription")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,r.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:l(e.loggedIn?"i18n.connected":"i18n.notConnected")})]})]}),(0,r.jsxs)("div",{style:{minHeight:48},children:["idle"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:l("i18n.openingBrowser")}),"select"===n.phase&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:n.message}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:n.options.map(e=>(0,r.jsx)("button",{onClick:()=>g(n.token,e.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:e.label},e.id))})]}),("auth"===n.phase||"prompt"===n.phase)&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===n.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":n.message}),"auth"===n.phase&&(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,r.jsx)("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("input",{ref:c,value:s,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"===e.key&&h(n.token,s)},placeholder:"auth"===n.phase?"http://localhost:1455/auth/callback?code=…":n.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,r.jsx)("button",{onClick:()=>h(n.token,s),disabled:!s.trim(),style:{padding:"6px 12px",background:s.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:s.trim()?"#fff":"var(--text-dim)",cursor:s.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:l("i18n.submit")})]})]}),"device_code"===n.phase&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,r.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:n.userCode}),(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,r.jsx)("a",{href:n.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:n.verificationUri}),n.expiresInSeconds?` Expires in ${Math.ceil(n.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:n.message}),"success"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:l("i18n.connectedSuccessfully")}),"error"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:n.message})]}),(0,r.jsx)("div",{style:{display:"flex",gap:8},children:x?(0,r.jsx)("button",{onClick:()=>{d.current?.close(),o({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:l("i18n.cancel")}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:u,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:l(e.loggedIn?"i18n.relogin":"i18n.login")}),e.loggedIn&&(0,r.jsx)("button",{onClick:p,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:l("i18n.disconnect")})]})})]})}function io({provider:e,onRefresh:t}){let[n,o]=(0,i.useState)(""),[l,s]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),{t:g}=(0,m.s)();(0,i.useEffect)(()=>{o(""),u(null),h(!1)},[e.id]);let x=(0,i.useCallback)(async()=>{if(n.trim()){s(!0),u(null),h(!1);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:n.trim()})}),i=await r.json();!r.ok||i.error?u(i.error??`HTTP ${r.status}`):(o(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[n,e.id,t]),f=(0,i.useCallback)(async()=>{d(!0),u(null);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),r=await n.json();!n.ok||r.error?u(r.error??`HTTP ${n.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(r4,{children:"API Key"}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,r.jsx)("span",{style:{fontSize:11,color:e.configured?"#4ade80":"var(--text-dim)"},children:g(e.configured?"i18n.configured":"i18n.notConfigured")})]})]}),(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.configured?"API key is stored. Enter a new key below to replace it, or disconnect to remove it.":`Enter your ${e.displayName} API key to enable ${e.modelCount} model${1!==e.modelCount?"s":""}.`}),(0,r.jsx)(rG,{label:"API Key",children:(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)(r0,{value:n,onChange:o,onKeyDown:e=>{"Enter"===e.key&&n.trim()&&x()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,r.jsxs)("button",{onClick:x,disabled:l||!n.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":n.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:n.trim()||p?"#fff":"var(--text-dim)",cursor:l||!n.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),g(p?"i18n.saved":l?"i18n.saving":"i18n.save")]})]})}),c&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,r.jsx)("button",{onClick:f,disabled:a,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:a?"not-allowed":"pointer",fontSize:12},children:g(a?"i18n.removing":"i18n.disconnect")})]})}function il({id:e,size:t}){let n=rJ[e];if(!n){let n=e.split(/[-_]/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?";return(0,r.jsx)("span",{"aria-hidden":"true",style:{width:t,height:t,border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontSize:Math.max(8,Math.floor(.42*t)),fontWeight:700,lineHeight:1},children:n})}return n.hasColor?(0,r.jsx)(n.Icon,{size:t}):(0,r.jsx)(n.Icon,{size:t,style:{color:"var(--text-muted)"}})}function is({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:n,onSelectApiKey:o,onAddCustom:l,onClose:s}){let[a,d]=(0,i.useState)(""),{t:c}=(0,m.s)(),u=(0,i.useRef)(null);(0,i.useEffect)(()=>{setTimeout(()=>u.current?.focus(),30)},[]);let p=a.trim().toLowerCase(),h=e.filter(e=>!e.loggedIn&&(!p||e.name.toLowerCase().includes(p))),g=t.filter(e=>!e.configured&&(!p||e.displayName.toLowerCase().includes(p)||e.id.toLowerCase().includes(p))),x=!p||"custom".includes(p)||"openai-compatible".includes(p)||"anthropic-compatible".includes(p),f=h.length+g.length+ +!!x,v={display:"flex",flexDirection:"row",alignItems:"center",gap:8,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,boxSizing:"border-box",cursor:"pointer",minWidth:0,textAlign:"left",transition:"border-color 0.12s, background 0.12s",width:"100%"};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&s()},children:(0,r.jsxs)("div",{style:{width:820,maxWidth:"calc(100vw - 32px)",maxHeight:"min(72vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,r.jsx)("input",{ref:u,value:a,onChange:e=>d(e.target.value),onKeyDown:e=>{"Escape"===e.key&&s()},placeholder:c("i18n.searchProviders"),style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===f?(0,r.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:c("i18n.noProviders")}):(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[x&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:c("i18n.custom")}),x&&(0,r.jsxs)("button",{onClick:()=>{l(),s()},style:v,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:c("i18n.customEndpoint")})]}),(0,r.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px dashed var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),h.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!x,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:c("i18n.subscriptions")}),h.map(e=>(0,r.jsxs)("button",{onClick:()=>{n(e.id),s()},style:v,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,r.jsx)(il,{id:e.id,size:28})]},e.id)),g.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(h.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),g.map(e=>(0,r.jsxs)("button",{onClick:()=>{o(e.id),s()},style:v,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,r.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,r.jsx)(il,{id:e.id,size:28})]},e.id))]})})]})})}function ia({onClose:e}){let t=tZ(),{t:n}=(0,m.s)(),[o,l]=(0,i.useState)({providers:{}}),[s,a]=(0,i.useState)(!0),[d,c]=(0,i.useState)(!1),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(!1),[x,f]=(0,i.useState)(null),[v,y]=(0,i.useState)([]),[b,k]=(0,i.useState)([]),[w,j]=(0,i.useState)(!1),S=(0,i.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>{Array.isArray(e.providers)&&y(e.providers)}).catch(()=>{})},[]),C=(0,i.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>{Array.isArray(e.providers)&&k(e.providers)}).catch(()=>{})},[]),T=(0,i.useCallback)(()=>{S(),C()},[S,C]);(0,i.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};l(t);let n=Object.keys(t.providers??{});n.length>0&&f({type:"provider",name:n[0]})}).catch(()=>l({providers:{}})).finally(()=>a(!1)),T()},[T]);let R=(0,i.useCallback)(()=>{let e="new-provider",t=1;for(;o.providers?.[e];)e=`new-provider-${t++}`;l(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),f({type:"provider",name:e})},[o.providers]),M=(0,i.useCallback)((e,t)=>{l(n=>({...n,providers:{...n.providers??{},[e]:t}}))},[]),I=(0,i.useCallback)((e,t)=>{l(n=>{let r=Object.entries(n.providers??{}),i=r.findIndex(([t])=>t===e);return -1===i?n:(r[i]=[t,r[i][1]],{...n,providers:Object.fromEntries(r)})}),f(n=>n?"provider"===n.type&&n.name===e?{type:"provider",name:t}:"model"===n.type&&n.providerName===e?{...n,providerName:t}:n:n)},[]),L=(0,i.useCallback)(e=>{l(t=>{let n={...t.providers??{}};return delete n[e],{...t,providers:n}}),l(e=>{let t=Object.keys(e.providers??{});return f(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),W=(0,i.useCallback)(e=>{l(t=>{let n=t.providers?.[e]??{},r=[...n.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...n,models:r}}}}),l(t=>{let n=(t.providers?.[e]?.models?.length??1)-1;return f({type:"model",providerName:e,index:n}),t})},[]),E=(0,i.useCallback)((e,t)=>{l(n=>{let r=n.providers?.[e]??{},i=[...r.models??[]],o=new Set(i.map(e=>e.id));for(let e of t)o.has(e.id)||(o.add(e.id),i.push({id:e.id,name:e.name}));return{...n,providers:{...n.providers??{},[e]:{...r,models:i}}}})},[]),z=(0,i.useCallback)((e,t,n)=>{l(r=>{let i=r.providers?.[e]??{},o=[...i.models??[]];return o[t]=n,{...r,providers:{...r.providers??{},[e]:{...i,models:o}}}})},[]),$=(0,i.useCallback)((e,t)=>{l(n=>{let r=n.providers?.[e]??{},i=[...r.models??[]];return i.splice(t,1),{...n,providers:{...n.providers??{},[e]:{...r,models:i.length?i:void 0}}}}),f({type:"provider",name:e})},[]),P=(0,i.useCallback)(async()=>{c(!0),p(null),g(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}),t=await e.json();!e.ok||t.error?p(t.error??`HTTP ${e.status}`):(g(!0),setTimeout(()=>g(!1),2e3))}catch(e){p(String(e))}finally{c(!1)}},[o]),F=Object.entries(o.providers??{}),N=v.filter(e=>e.loggedIn),A=b.filter(e=>e.configured),D=(()=>{if(!x)return null;if("oauth"===x.type){let e=v.find(e=>e.id===x.providerId);return e?(0,r.jsx)(ii,{provider:e,onRefresh:T},e.id):null}if("apikey"===x.type){let e=b.find(e=>e.id===x.providerId);return e?(0,r.jsx)(io,{provider:e,onRefresh:T},e.id):null}if("provider"===x.type){let e=o.providers?.[x.name];return e?(0,r.jsx)(r6,{name:x.name,provider:e,onChange:e=>M(x.name,e),onRename:e=>I(x.name,e),onDelete:()=>L(x.name),onAddModels:e=>E(x.name,e)},x.name):null}let e=o.providers?.[x.providerName],t=e?.models?.[x.index];return t?(0,r.jsx)(ir,{providerName:x.providerName,provider:e,model:t,onChange:e=>z(x.providerName,x.index,e),onDelete:()=>$(x.providerName,x.index)},`${x.providerName}-${x.index}`):null})();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:t=>{t.target===t.currentTarget&&e()},children:(0,r.jsxs)("div",{style:{width:t?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:t?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:n("common.models")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,r.jsx)("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:t?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:t?"100%":210,maxHeight:t?"40vh":void 0,borderRight:t?"none":"1px solid var(--border)",borderBottom:t?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[N.map(e=>{let t=x?.type==="oauth"&&x.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>f({type:"oauth",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(il,{id:e.id,size:16}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),A.map(e=>{let t=x?.type==="apikey"&&x.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>f({type:"apikey",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(il,{id:e.id,size:16}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(N.length>0||A.length>0)&&F.length>0&&(0,r.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),s?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:n("i18n.loading")}):F.map(([e,t])=>{let i=x?.type==="provider"&&x.name===e,o=t.models??[];return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)("div",{onClick:()=>f({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:i?"var(--bg-selected)":"none"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,r.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,r.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,r.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,r.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,r.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,r.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,r.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,r.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:i?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),o.map((t,i)=>{let o=x?.type==="model"&&x.providerName===e&&x.index===i;return(0,r.jsxs)("div",{onClick:()=>f({type:"model",providerName:e,index:i}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:t.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.id||n("i18n.newModel")}),t.reasoning&&(0,r.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},i)}),(0,r.jsx)("div",{onClick:t=>{t.stopPropagation(),W(e)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsxs)("span",{style:{fontSize:11},children:["+ ",n("i18n.model")]})})]},e)})]}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,r.jsxs)("button",{onClick:()=>j(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.color="var(--text-muted)"},children:["+ ",n("i18n.addProvider")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:s?null:D??(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:n("i18n.selectProviderModel")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[u&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:u}),(0,r.jsx)("button",{onClick:e,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:n("i18n.cancel")}),(0,r.jsxs)("button",{onClick:P,disabled:d||h,style:{position:"relative",padding:"6px 16px",minWidth:92,background:h?"#16a34a":d?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:h?"#fff":d?"var(--text-muted)":"#fff",cursor:d||h?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:h?"saved-pop 0.45s ease":void 0},children:[h&&(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,r.jsx)("span",{children:h?n("i18n.saved"):d?n("i18n.saving"):n("i18n.save")})]})]})]})}),w&&(0,r.jsx)(is,{oauthProviders:v,apiKeyProviders:b,onSelectOAuth:e=>f({type:"oauth",providerId:e}),onSelectApiKey:e=>f({type:"apikey",providerId:e}),onAddCustom:R,onClose:()=>j(!1)})]})}function id(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ic(e){let t=e.sourceInfo?.source,n=e.sourceInfo?.scope;return"user"===n||"user"===t?"global":"project"===n||"project"===t?"project":"path"}function iu(e){let t=ic(e);return"path"===t?t:e.install?.skillsShUrl?`${t} / skills.sh`:t}function ip(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function ih(e){return e?e.slice(0,8):"unknown"}function ig({enabled:e,loading:t,onToggle:n}){let{t:i}=(0,m.s)();return(0,r.jsx)("button",{onClick:n,disabled:t,title:i(e?"i18n.visibleInPrompt":"i18n.hiddenFromPrompt"),style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none"},children:(0,r.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function ix({skill:e,cwd:t,onToggle:n,toggling:i,saveError:o,updateStatus:l,checkingUpdate:s,updating:a,updateError:d,onCheckUpdate:c,onUpdate:u}){let{t:p}=(0,m.s)(),h=ic(e),g=!e.disableModelInvocation;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===h?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===h?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:h}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if("project"===h&&e.startsWith(t)){let n=e.slice(t.length).replace(/^[/\\]/,"");return`./${n}`}return id(e)}(e.filePath)}),(0,r.jsx)(ig,{enabled:g,loading:i,onToggle:()=>n(e)})]}),(0,r.jsxs)("div",{style:{minHeight:16,display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,flexWrap:"wrap",textAlign:"right"},children:[!g&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:p("i18n.hiddenButInvocable")}),o&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",overflowWrap:"anywhere"},children:o})]})]}),e.install?.skillsShUrl&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Source"}),(0,r.jsx)("a",{href:e.install.skillsShUrl,target:"_blank",rel:"noreferrer",title:e.install.skillsShUrl,style:{display:"flex",alignItems:"center",gap:8,width:"fit-content",maxWidth:"100%",color:"var(--accent)",textDecoration:"none"},children:(0,r.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.install.skillsShUrl.replace(/^https?:\/\//,"")," ↗"]})})]}),e.install&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Version"}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-muted)"},children:ih(l?.currentVersion??e.install.versionHash)}),e.install.canCheckForUpdates&&(0,r.jsx)("button",{onClick:c,disabled:s||a,style:{padding:"4px 9px",border:"1px solid var(--border)",borderRadius:5,background:"none",color:"var(--text-muted)",cursor:s||a?"not-allowed":"pointer",opacity:s||a?.5:1,fontSize:11},children:p("i18n.check")}),l?.state==="update-available"&&(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"#d97706"},children:ih(l.latestVersion)}),(s||l&&"update-available"!==l.state)&&(0,r.jsx)("span",{style:{fontSize:12,color:s?"var(--accent)":l?.state==="up-to-date"?"#16a34a":l?.state==="error"?"#ef4444":"var(--text-dim)"},children:s?p("i18n.checking"):l?.state==="up-to-date"?p("i18n.upToDate"):l?.state==="unsupported"?p("i18n.automaticChecksUnavailable"):l?.message||p("i18n.checkFailed")}),l?.state==="update-available"&&(0,r.jsx)("button",{onClick:u,disabled:a||s,style:{padding:"4px 10px",border:"none",borderRadius:5,background:"var(--accent)",color:"#fff",cursor:a||s?"not-allowed":"pointer",opacity:a||s?.5:1,fontSize:11,fontWeight:600},children:p(a?"i18n.updating":"i18n.update")})]}),d&&(0,r.jsx)("span",{style:{fontSize:12,color:"#ef4444"},children:d})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,r.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function im({cwd:e,installedPackages:t,projectResourcesLoaded:n,onInstalled:o}){let{t:l}=(0,m.s)(),[s,a]=(0,i.useState)(""),[d,c]=(0,i.useState)([]),[u,p]=(0,i.useState)(!1),[h,g]=(0,i.useState)(null),[x,f]=(0,i.useState)(null),[v,y]=(0,i.useState)(null),[b,k]=(0,i.useState)(new Set),[w,j]=(0,i.useState)("global"),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{S.current?.focus()},[]);let C=(0,i.useCallback)(async e=>{if(e.trim()){p(!0),g(null),c([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),n=await t.json();if(n.error)return void g(n.error);c(n.results??[]),0===(n.results??[]).length&&g("No skills found")}catch(e){g(String(e))}finally{p(!1)}}},[]),T=(0,i.useCallback)(async t=>{f(t),y(null);try{let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:w,cwd:e})}),r=await n.json();if(!n.ok||r.error)return void y(r.error??`HTTP ${n.status}`);k(e=>new Set(e).add(`${w}:${t}`)),o()}catch(e){y(String(e))}finally{f(null)}},[o,w,e]),R="global"===w?"~/.pi/agent/skills/":`${id(e)}/.pi/skills/`;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:l("i18n.addSkill")}),(0,r.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,r.jsx)("input",{ref:S,value:s,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"===e.key&&C(s)},placeholder:l("i18n.skillSearchPlaceholder"),style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,r.jsx)("button",{onClick:()=>C(s),disabled:u||!s.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:u||!s.trim()?"not-allowed":"pointer",opacity:u||!s.trim()?.5:1,flexShrink:0},children:u?l("i18n.searching"):l("i18n.search")})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,r.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,r.jsx)("button",{onClick:()=>{("global"===e||n)&&j(e)},disabled:"project"===e&&!n,title:"project"!==e||n?void 0:l("trust.projectScopeUnavailable"),style:{padding:"3px 10px",border:"none",cursor:"project"!==e||n?"pointer":"not-allowed",background:w===e?"var(--bg-selected)":"none",color:w===e?"var(--text)":"var(--text-dim)",fontWeight:w===e?600:400,opacity:"project"!==e||n?1:.45,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",R]})]}),h&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:h}),v&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:v})]}),d.length>0?(0,r.jsx)("div",{style:{flex:1,overflowY:"auto"},children:d.map(e=>{let n=t[w].has(e.package)||b.has(`${w}:${e.package}`),i=x===e.package,o=e.package.indexOf("@"),s=o>-1?e.package.slice(0,o):e.package,a=o>-1?e.package.slice(o+1):null;return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:a??s}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:s}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,r.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,r.jsx)("button",{onClick:()=>!n&&!i&&T(e.package),disabled:n||i||null!==x,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:n||i||null!==x?"not-allowed":"pointer",background:n?"rgba(34,197,94,0.1)":"none",color:n?"#16a34a":i?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:n?`✓ ${l("i18n.installed")}`:i?l("i18n.installing"):l("i18n.install")})]},e.package)})}):!h&&!u&&(0,r.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,r.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function iv({cwd:e,onClose:t}){let n=tZ(),{t:o}=(0,m.s)(),[l,s]=(0,i.useState)([]),[a,d]=(0,i.useState)(!0),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(new Set),[f,v]=(0,i.useState)(null),[y,b]=(0,i.useState)(!1),[k,w]=(0,i.useState)({}),[j,S]=(0,i.useState)(new Set),[C,T]=(0,i.useState)(!1),[R,M]=(0,i.useState)(null),[I,L]=(0,i.useState)(null),[W,E]=(0,i.useState)(!0),[z,$]=(0,i.useState)({}),P=(0,i.useCallback)(async()=>{d(!0),u(null);try{let t=await fetch(`/api/skills?cwd=${encodeURIComponent(e)}`),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);let r=n.skills??[];if(s(r),E(n.projectResourcesLoaded??!0),r.length>0&&!p){let e=r.find(e=>!e.disableModelInvocation)??r[0];h(e.filePath),e.disableModelInvocation&&$(t=>({...t,[iu(e)]:!0}))}return r}catch(e){return u(String(e)),[]}finally{d(!1)}},[e,p]);(0,i.useEffect)(()=>{w({}),L(null),P()},[e]);let F=(0,i.useCallback)(async t=>{let n=(t?[t]:l.filter(e=>!!e.install)).map(ip).filter(e=>!!e);if(0!==n.length){L(null),S(e=>new Set([...e,...n])),t||T(!0);try{let n=await fetch("/api/skills/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:t?.install?.package,scope:t?.install?.scope})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);w(e=>{let t={...e};for(let e of r.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){L(e instanceof Error?e.message:String(e))}finally{S(e=>{let t=new Set(e);for(let e of n)t.delete(e);return t}),t||T(!1)}}},[e,l]),N=(0,i.useCallback)(async t=>{if(!t.install)return;let n=ip(t);M(n),L(null);try{let r=await fetch("/api/skills/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:t.install.package,scope:t.install.scope})}),i=await r.json();if(!r.ok||i.error||!i.success)throw Error(i.error??`HTTP ${r.status}`);await P();let o=i.skill?.install?.versionHash;w(e=>({...e,[n]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:o,latestVersion:o}}))}catch(e){L(e instanceof Error?e.message:String(e))}finally{M(null)}},[e,P]),A=(0,i.useCallback)(async e=>{let t=!e.disableModelInvocation;x(t=>new Set(t).add(e.filePath)),v(null);try{let n=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),r=await n.json();if(!n.ok||r.error)return void v(r.error??`HTTP ${n.status}`);s(n=>n.map(n=>n.filePath===e.filePath?{...n,disableModelInvocation:t}:n)),t&&$(t=>({...t,[iu(e)]:!0}))}catch(e){v(String(e))}finally{x(t=>{let n=new Set(t);return n.delete(e.filePath),n})}},[]),D=l.find(e=>e.filePath===p)??null;return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&t()},children:(0,r.jsxs)("div",{style:{width:n?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:n?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:o("common.skills")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:id(e)})]}),(0,r.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),!W&&(0,r.jsx)("div",{role:"status",style:{padding:"8px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:o("trust.skillsNotLoaded")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:n?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:n?"100%":210,maxHeight:n?"40vh":void 0,borderRight:n?"none":"1px solid var(--border)",borderBottom:n?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:a?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:o("i18n.loading")}):c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:c}):0===l.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:o("i18n.noSkills")}):(()=>{let e=[];for(let{label:t,matches:n}of[{label:"project / skills.sh",matches:e=>"project"===ic(e)&&!!e.install?.skillsShUrl},{label:"project",matches:e=>"project"===ic(e)&&!e.install?.skillsShUrl},{label:"global / skills.sh",matches:e=>"global"===ic(e)&&!!e.install?.skillsShUrl},{label:"global",matches:e=>"global"===ic(e)&&!e.install?.skillsShUrl},{label:"path",matches:e=>"path"===ic(e)}]){let r=l.filter(n);r.length>0&&e.push({label:t,skills:r})}let t=e=>{let t,n,i=!y&&p===e.filePath,l=e.disableModelInvocation;return(0,r.jsxs)("div",{onClick:()=>{h(e.filePath),b(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:i?"var(--bg-selected)":"none"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:l?"var(--border)":"var(--accent)",boxShadow:l?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:i?600:400,color:l?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(n=(t=ip(e))?k[t]:void 0,n?.state!=="update-available"?null:(0,r.jsx)("span",{title:o("i18n.updateAvailable"),style:{color:"#d97706",fontSize:13,lineHeight:1,flexShrink:0},children:"↑"}))]},e.filePath)};return e.map(({label:e,skills:n})=>{let i=n.filter(e=>!e.disableModelInvocation),l=n.filter(e=>e.disableModelInvocation),s=z[e]??!1;return(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:e}),i.map(t),l.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{onClick:()=>$(t=>({...t,[e]:!s})),style:{display:"flex",alignItems:"center",gap:5,padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",cursor:"pointer",userSelect:"none"},children:[(0,r.jsx)("span",{style:{fontSize:8},children:s?"▾":"▸"}),o("i18n.dormant")," (",l.length,")"]}),s&&l.map(t)]})]},e)})})()}),(0,r.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("div",{onClick:()=>b(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:y?"var(--bg-selected)":"none",color:y?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{y||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{y||(e.currentTarget.style.background="none")},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),o("i18n.addSkill")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:y?(0,r.jsx)(im,{cwd:e,projectResourcesLoaded:W,installedPackages:{global:new Set(l.filter(e=>e.install?.scope==="global").map(e=>e.install.package)),project:new Set(l.filter(e=>e.install?.scope==="project").map(e=>e.install.package))},onInstalled:()=>{P()}}):a?null:D?(0,r.jsx)(ix,{skill:D,cwd:e,onToggle:A,toggling:g.has(D.filePath),saveError:f,updateStatus:ip(D)?k[ip(D)]:void 0,checkingUpdate:!!ip(D)&&j.has(ip(D)),updating:R===ip(D),updateError:I,onCheckUpdate:()=>void F(D),onUpdate:()=>void N(D)},D.filePath):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:o("i18n.selectSkill")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[l.some(e=>!!e.install)&&(0,r.jsx)("button",{onClick:()=>void F(),disabled:C||null!==R,style:{padding:"6px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:C||null!==R?"not-allowed":"pointer",opacity:C||null!==R?.5:1,fontSize:12},children:C?o("i18n.checking"):o("i18n.checkUpdates")}),Object.values(k).filter(e=>"update-available"===e.state).length>0&&(0,r.jsxs)("span",{style:{fontSize:12,color:"#d97706"},children:[Object.values(k).filter(e=>"update-available"===e.state).length," ",1===Object.values(k).filter(e=>"update-available"===e.state).length?o("i18n.update"):o("i18n.updates")]})]}),(0,r.jsx)("button",{onClick:t,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:o("i18n.close")})]})]})})}function iy(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ib(e){let t=e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/);return t?.[1]??e}function ik(e){return`${e.scope}\0${e.source}`}function iw(e,t){if(e.disabled)return t("i18n.disabled");let n=[e.counts.extensions?t("i18n.resourceCount",{count:e.counts.extensions,label:t("i18n.extensionShort")}):"",e.counts.skills?t("i18n.resourceCount",{count:e.counts.skills,label:t("i18n.skillShort")}):"",e.counts.prompts?t("i18n.resourceCount",{count:e.counts.prompts,label:t("i18n.promptShort")}):"",e.counts.themes?t("i18n.resourceCount",{count:e.counts.themes,label:t("i18n.themeShort")}):""].filter(Boolean);return n.length?n.join(" \xb7 "):t("i18n.noResources")}function ij(e,t){let n=[];return e.version&&n.push(t("i18n.installedVersion",{version:e.version})),e.configuredVersion&&n.push(t("i18n.configuredVersion",{version:e.configuredVersion})),n.length?n.join(" \xb7 "):t("i18n.unknown")}function iS(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function iC({pkg:e}){let{t}=(0,m.s)(),n=[["extension",t("i18n.extensions")],["skill",t("i18n.skills")],["prompt",t("i18n.prompts")],["theme",t("i18n.themes")]].map(([t,n])=>({kind:t,label:n,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return 0===n.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:t(e.disabled?"i18n.packageDisabled":"i18n.noResolvedResources")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:n.map((e,t)=>(0,r.jsxs)("div",{style:{borderTop:0===t?"none":"1px solid var(--border)",paddingTop:12*(0!==t)},children:[(0,r.jsx)("div",{style:{fontSize:10,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",marginBottom:6},children:e.label}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.resources.map(e=>(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.path,children:e.name}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:1},title:e.path,children:e.relativePath})]},`${e.kind}:${e.path}`))})]},e.kind))})}function iT({scope:e}){return(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===e?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===e?"rgba(99,102,241,0.85)":"var(--text-dim)"},children:e})}function iR(e,t){return{padding:"6px 12px",background:t?"rgba(239,68,68,0.08)":"none",border:"1px solid var(--border)",borderRadius:6,color:t?"#ef4444":"var(--text-muted)",cursor:e?"not-allowed":"pointer",fontSize:12,opacity:e?.5:1}}function iM({enabled:e,loading:t,onToggle:n,label:i}){return(0,r.jsx)("button",{type:"button",onClick:n,disabled:t,title:i,"aria-label":i,"aria-pressed":e,style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none",opacity:t?.65:1},children:(0,r.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function iI({value:e,projectResourcesLoaded:t,onChange:n}){let{t:i}=(0,m.s)();return(0,r.jsx)("div",{style:{display:"inline-flex",border:"1px solid var(--border)",borderRadius:7,overflow:"hidden",height:30},children:["global","project"].map(o=>{let l=e===o,s="project"===o&&!t;return(0,r.jsx)("button",{onClick:()=>{s||n(o)},disabled:s,title:s?i("trust.projectScopeUnavailable"):void 0,style:{width:76,border:"none",borderRight:"global"===o?"1px solid var(--border)":"none",background:l?"var(--bg-selected)":"none",color:l?"var(--text)":"var(--text-muted)",cursor:s?"not-allowed":"pointer",opacity:s?.45:1,fontSize:12},children:o},o)})})}function iL({cwd:e,source:t,scope:n,projectResourcesLoaded:o,busy:l,actionError:s,onSourceChange:a,onScopeChange:d,onInstall:c}){let{t:u}=(0,m.s)(),p=(0,i.useRef)(null);return(0,i.useEffect)(()=>{p.current?.focus()},[]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:u("i18n.addPlugin")}),(0,r.jsxs)("a",{href:"https://pi.dev/packages",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:5,color:"var(--accent)",fontSize:12,textDecoration:"none",whiteSpace:"nowrap"},children:[(0,r.jsxs)("svg",{width:"28",height:"28",viewBox:"0 0 800 800","aria-hidden":"true",focusable:"false",style:{flexShrink:0},children:[(0,r.jsx)("path",{fill:"#000",fillRule:"evenodd",d:"M165.29 165.29H517.36V400H400V517.36H282.65V634.72H165.29ZM282.65 282.65V400H400V282.65Z"}),(0,r.jsx)("path",{fill:"#000",d:"M517.36 400H634.72V634.72H517.36Z"})]}),"pi.dev/packages"]})]}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"project"===n?`${iy(e)}/.pi/agent/{npm,git}`:"~/.pi/agent/{npm,git}"})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{htmlFor:"plugin-source",style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Source"}),(0,r.jsx)("input",{id:"plugin-source",ref:p,value:t,onChange:e=>a(e.target.value),onPaste:e=>{let t=e.clipboardData.getData("text"),n=ib(t);n!==t&&(e.preventDefault(),a(n))},onBlur:e=>a(ib(e.currentTarget.value)),placeholder:"npm:@scope/package",style:{width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,outline:"none"},onKeyDown:e=>{"Enter"===e.key&&t.trim()&&!l&&c()}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)(iI,{value:n,projectResourcesLoaded:o,onChange:d}),(0,r.jsx)("button",{type:"button",onClick:c,disabled:l||!t.trim(),style:{...iR(l||!t.trim()),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:u(l?"i18n.installing":"i18n.install")})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Examples"}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:["npm:@scope/pi-plugin","git:https://github.com/user/repo","/absolute/path/to/plugin"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>a(e),style:{width:"100%",minHeight:30,textAlign:"left",padding:"6px 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"pointer",fontFamily:"var(--font-mono)",fontSize:11},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)",e.currentTarget.style.color="var(--text-dim)"},children:e},e))})]}),s&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:s})]})}function iW({pkg:e,cwd:t,busyKey:n,actionError:i,actionMessage:o,sessionId:l,onAction:s,onReloadSession:a}){let{t:d}=(0,m.s)(),c=ik(e),u=n?.endsWith(c)??!1,p="reload"===n,h=!e.disabled;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20,maxWidth:680},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,minWidth:0,flexWrap:"wrap"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:180,flex:1},children:[(0,r.jsx)(iM,{enabled:h,loading:u||p,onToggle:()=>s(e.disabled?"enable":"disable",e),label:d(e.disabled?"i18n.enablePackage":"i18n.disablePackage")}),(0,r.jsx)(iT,{scope:e.scope}),e.disabled?(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)",color:"var(--text-dim)"},children:d("i18n.disabled")}):e.filtered&&(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(245,158,11,0.12)",color:"#d97706"},children:d("i18n.filtered")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:()=>s("update",e),disabled:u||p,style:iR(u||p),children:d(n===`update:${c}`?"i18n.updating":"i18n.update")}),(0,r.jsx)("button",{onClick:a,disabled:!l||p||u,style:iR(!l||p||u),title:d(l?"i18n.reloadSession":"i18n.openSessionToReload"),children:d(p?"i18n.reloading":"i18n.reloadSession")}),(0,r.jsx)("button",{onClick:()=>s("remove",e),disabled:u||p,style:iR(u||p,!0),children:d(n===`remove:${c}`?"i18n.removing":"i18n.remove")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.status")}),(0,r.jsx)("div",{style:{color:iS(e.status),textTransform:"capitalize"},children:e.status}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.version")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:ij(e,d)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.package")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.packageName??d("i18n.unknown")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.resources")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)"},children:iw(e,d)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.installedPath")}),(0,r.jsx)("div",{style:{color:e.installedPath?"var(--text-muted)":"#ef4444",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.installedPath?iy(e.installedPath):d("i18n.notFound")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.cwd")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:iy(t)})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:d("i18n.resolvedResources")}),(0,r.jsx)(iC,{pkg:e})]}),o&&(0,r.jsx)("div",{style:{fontSize:12,color:"#16a34a"},children:o}),i&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:i})]})}function iE({cwd:e,sessionId:t,onClose:n,onReloaded:o}){let l=tZ(),{t:s}=(0,m.s)(),[a,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(null),[g,x]=(0,i.useState)(null),[f,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(""),[k,w]=(0,i.useState)("global"),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[R,M]=(0,i.useState)(null),I=(0,i.useMemo)(()=>a?.packages??[],[a?.packages]),L=I.find(e=>ik(e)===g)??null,W=a?.projectResourcesLoaded??!0,E=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:I.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[I]),z=(0,i.useCallback)(async()=>{u(!0),h(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);d(n),v(e=>0===n.packages.length||e),x(e=>e&&n.packages.some(t=>ik(t)===e)?e:n.packages[0]?ik(n.packages[0]):null)}catch(e){h(e instanceof Error?e.message:String(e))}finally{u(!1)}},[e]);(0,i.useEffect)(()=>{z()},[z]);let $=(0,i.useCallback)(async(t,n)=>{let r=ik(n);S(`${t}:${r}`),T(null),M(null);try{let r=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:n.source,scope:n.scope,cwd:e})}),i=await r.json();if(!r.ok||i.error)throw Error(i.error??`HTTP ${r.status}`);d(i),"remove"===t?(x(i.packages[0]?ik(i.packages[0]):null),0===i.packages.length&&v(!0),M("Package removed.")):M({install:"Package installed.",update:"Package updated.",disable:"Package disabled.",enable:"Package enabled."}[t])}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}},[e]),P=(0,i.useCallback)(async()=>{let t=ib(y).trim();if(!t)return;b(t);let n=`${k}\0${t}`;S(`install:${n}`),T(null),M(null);try{var r;let i,o,l=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"install",source:t,scope:k,cwd:e})}),s=await l.json();if(!l.ok||s.error)throw Error(s.error??`HTTP ${l.status}`);d(s);let a=(r=s.packages,o=(i=t.trim()).startsWith("npm:")?i.slice(4):i,r.find(e=>e.scope===k&&e.source===i)??r.find(e=>e.scope===k&&e.source===`npm:${o}`)??r.find(e=>e.scope===k&&e.source.endsWith(i)));x(a?ik(a):n),v(!1),b(""),M("Package installed.")}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}},[e,k,y]),F=(0,i.useCallback)(async()=>{if(t){S("reload"),T(null),M(null);try{await nR(t,{type:"reload"}),o?.(),await z(),M("Session reloaded.")}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}}},[z,o,t]),N=j?.startsWith("install:")??!1;return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&n()},children:(0,r.jsxs)("div",{style:{width:l?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:l?"calc(100dvh - 16px)":"76vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:s("common.plugins")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:iy(e)})]}),(0,r.jsx)("button",{onClick:n,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),!W&&(0,r.jsx)("div",{role:"status",style:{padding:"8px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:s("trust.pluginsNotLoaded")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:l?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:l?"100%":245,maxHeight:l?"40vh":void 0,borderRight:l?"none":"1px solid var(--border)",borderBottom:l?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):p?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:p}):0===I.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No plugins configured"}):E.map(e=>(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase"},children:e.scope}),e.packages.map(e=>{let t=ik(e),n=!f&&g===t;return(0,r.jsxs)("div",{onClick:()=>{x(t),v(!1),T(null),M(null)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:n?"var(--bg-selected)":"none"},onMouseEnter:e=>{n||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{n||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:iS(e.status)}}),(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:n?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:iw(e,s)}),(e.version||e.configuredVersion)&&(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:ij(e,s)})]})]},t)})]},e.scope))}),(0,r.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("button",{type:"button",onClick:()=>{v(!0),T(null),M(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:f?"var(--bg-selected)":"none",color:f?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{f||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{f||(e.currentTarget.style.background="none")},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),s("i18n.addPlugin")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:f?(0,r.jsx)(iL,{cwd:e,source:y,scope:k,projectResourcesLoaded:W,busy:N,actionError:C,onSourceChange:b,onScopeChange:w,onInstall:P}):c?null:L?(0,r.jsx)(iW,{pkg:L,cwd:e,busyKey:j,actionError:C,actionMessage:R,sessionId:t,onAction:$,onReloadSession:F},ik(L)):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:s("i18n.selectPackage")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsx)("div",{style:{minWidth:0,flex:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden"},children:a?.diagnostics.length?(0,r.jsxs)("span",{title:a.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:a.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:[a.diagnostics.length," diagnostic",1===a.diagnostics.length?"":"s"]}):(0,r.jsx)("span",{children:a?`${a.totals.extensions} ext \xb7 ${a.totals.skills} skills \xb7 ${a.totals.prompts} prompts \xb7 ${a.totals.themes} themes`:""})}),(0,r.jsx)("button",{onClick:()=>void z(),disabled:c||null!==j,style:iR(c||null!==j),children:s("i18n.refresh")}),(0,r.jsx)("button",{onClick:n,style:iR(!1),children:s("i18n.close")})]})]})})}function iz({cwd:e,busy:t,error:n,onCancel:i,onConfirm:o}){let{t:l}=(0,m.s)();return(0,r.jsx)("div",{role:"presentation",style:{position:"fixed",inset:0,zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center",padding:16,background:"rgba(0,0,0,0.4)"},onClick:e=>{t||e.target!==e.currentTarget||i()},children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"true","aria-labelledby":"project-trust-title",style:{width:440,maxWidth:"100%",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",boxShadow:"0 12px 36px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:12,padding:"18px 18px 14px"},children:[(0,r.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0,marginTop:1},children:[(0,r.jsx)("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"}),(0,r.jsx)("path",{d:"m9 12 2 2 4-4"})]}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{id:"project-trust-title",style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:l("trust.dialogTitle")}),(0,r.jsx)("div",{style:{marginTop:7,fontSize:12,lineHeight:1.6,color:"var(--text-muted)"},children:l("trust.dialogBody")}),(0,r.jsx)("code",{style:{display:"block",marginTop:10,padding:"8px 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:e}),n&&(0,r.jsx)("div",{role:"alert",style:{marginTop:10,color:"#ef4444",fontSize:12,lineHeight:1.5},children:n})]})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,r.jsx)("button",{type:"button",onClick:i,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:t?"not-allowed":"pointer",fontSize:12},children:l("trust.cancel")}),(0,r.jsx)("button",{type:"button",onClick:o,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--accent)",borderRadius:5,background:"var(--accent)",color:"white",cursor:t?"wait":"pointer",opacity:t?.7:1,fontSize:12,fontWeight:600},children:l(t?"trust.trusting":"trust.trustProject")})]})]})})}function i$(e){return"message"===e.type&&"message"in e}function iP(e){let t=e,n=t.branchPreview,r=i$(t.entry)?t.entry:null,i=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],n??=t.branchPreview,!r&&i$(t.entry)&&(r=t.entry),i+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:i,branchPreview:n,labelEntry:r??t.entry}}function iF({node:e,activePathIds:t,depth:n,isLast:i,parentLines:o,onSelect:l}){let{node:s,skipped:a,branchPreview:d,labelEntry:c}=iP(e),u=t.has(s.entry.id),p=t.has(e.entry.id)||t.has(s.entry.id),h=d?.text??function(e){if("message"===e.type&&"message"in e){let t=e.message,n=t.content,r="";if("string"==typeof n?r=n:Array.isArray(n)&&(r=n.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),r.length>40&&(r=r.slice(0,40)+"…"),r)return r;if("assistant"===t.role)return"[assistant]"}return e.type}(c),g=d?d.role??null:i$(c)?c.message.role:null;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>l(s.entry.id),children:[o.map((e,t)=>(0,r.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,r.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,r.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,r.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:i?"50%":0,width:1,background:"var(--border)"}}),(0,r.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,r.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:u?"var(--accent)":p?"var(--text-muted)":"var(--border)",border:u?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),g&&(0,r.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===g?"var(--accent)":"var(--text-dim)",background:"user"===g?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===g?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===g?"U":"A"}),a>0&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",a]}),(0,r.jsx)("span",{style:{fontSize:11,color:u?"var(--text)":p?"var(--text-muted)":"var(--text-dim)",fontWeight:u?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:h})]}),s.children.map((e,a)=>(0,r.jsx)(iF,{node:e,activePathIds:t,depth:n+1,isLast:a===s.children.length-1,parentLines:[...o,!i],onSelect:l},e.entry.id))]})}function iN({tree:e,activeLeafId:t,onLeafChange:n,inline:o,containerRef:l,open:s,onToggle:a,hasSession:d,compact:c,hideInlineButton:u}){let{t:p}=(0,m.s)(),[h,g]=(0,i.useState)(!1),x=void 0!==s?s:h,f=(0,i.useRef)(null),[v,y]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!x||!o)return;let e=l?.current??f.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();y({top:t.bottom,left:t.left,width:t.width})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[x,o,l]);let b=(0,i.useMemo)(()=>t?new Set(function e(n,r){for(let i of n){let n=[...r,i.entry.id];if(i.entry.id===t||i.compressedEntryIds?.includes(t))return n;let o=e(i.children,n);if(o)return o}return null}(e,[])??[]):new Set,[e,t]),k=(0,i.useCallback)(e=>{n(e)},[n]),w=d?!function e(t){if(t.length>1)return!0;for(let n of t)if(n.children.length>1||e(n.children))return!0;return!1}(e)?p("i18n.noBranches"):null:p("i18n.noActiveSession"),j=function(e){if(e.length>1)return e;if(0===e.length)return[];let t=iP(e[0]).node;return t.children.length>1?t.children:[]}(e),S=!w&&j.length>0,C=(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:S?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),T=(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:2,transform:x?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return o?(0,r.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,r.jsxs)("button",{ref:f,onClick:()=>a?a():g(e=>!e),style:{display:u?"none":"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:x?"var(--bg-selected)":"none",border:"none",borderTop:x?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:"pointer",color:x?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=x?"var(--text)":"var(--text-muted)"},title:p("i18n.branches"),"aria-label":p("i18n.branches"),"aria-pressed":x,children:[C,!c&&(0,r.jsx)("span",{children:p("i18n.branches")})]}),x&&v&&(0,r.jsx)("div",{style:{position:"fixed",top:v.top,left:v.left,width:v.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:S?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:j.map((e,t)=>(0,r.jsx)(iF,{node:e,activePathIds:b,depth:0,isLast:t===j.length-1,parentLines:[],onSelect:k},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w})})]}):(0,r.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>g(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:11,textAlign:"left"},children:[C,(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:p("i18n.branches")}),T]}),x&&(0,r.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,background:"var(--bg)",borderBottom:"1px solid var(--border)",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:S?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:j.map((e,t)=>(0,r.jsx)(iF,{node:e,activePathIds:b,depth:0,isLast:t===j.length-1,parentLines:[],onSelect:k},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w??p("i18n.noBranches")})})]})}function iA(e,t,n){let r=Number.isFinite(e)?e:t,i=Math.max(t,n);return Math.round(Math.max(t,Math.min(i,r)))}function iD(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function iB(e){let{ariaLabel:t,cssVariable:n,defaultWidth:r,getDefaultWidth:o,getMaxWidth:l,growthDirection:s,maxWidth:a,minWidth:d,storageKey:c,widthRef:u}=e,p=(0,i.useRef)(null),h=(0,i.useRef)(null),g=(0,i.useRef)(!1),[x,f]=(0,i.useState)(r),[m,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(!1);(0,i.useEffect)(()=>{b(!0)},[]);let k=(0,i.useCallback)(()=>Math.min(a,Math.max(d,l())),[l,a,d]),w=(0,i.useCallback)(e=>iA(e,d,k()),[k,d]),j=(0,i.useCallback)(e=>{u.current=e,p.current?.style.setProperty(n,`${e}px`)},[n,u]),S=(0,i.useCallback)((e,t={})=>{let{forcePersist:n=!1,persist:r=!0}=t,i=w(e),o=i!==u.current;return j(i),f(i),r&&(o||n)&&iD(c,i),i},[j,w,c,u]),C=(0,i.useCallback)(e=>{document.body.style.cursor=e.previousCursor,document.body.style.userSelect=e.previousUserSelect},[]),T=(0,i.useCallback)(e=>{let t=h.current;if(t&&t.pointerId===e){h.current=null,C(t),v(!1),S(u.current,{forcePersist:!0});try{t.target.hasPointerCapture(e)&&t.target.releasePointerCapture(e)}catch{}}},[S,C,u]),R=(0,i.useCallback)(e=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),e.stopPropagation();let t=h.current;t&&T(t.pointerId);let n=e.currentTarget;n.focus({preventScroll:!0}),n.setPointerCapture(e.pointerId),h.current={pointerId:e.pointerId,startX:e.clientX,startWidth:u.current,target:n,previousCursor:document.body.style.cursor,previousUserSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none",v(!0)},[T,u]),M=(0,i.useCallback)(e=>{let t=h.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void T(e.pointerId);e.preventDefault();let n="right"===s?1:-1,r=w(t.startWidth+(e.clientX-t.startX)*n);j(r),e.currentTarget.setAttribute("aria-valuenow",String(r)),e.currentTarget.setAttribute("aria-valuetext",`${r} px`)},[j,w,T,s]),I=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),L=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),W=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),E=(0,i.useCallback)(()=>{S(o?.()??r,{forcePersist:!0})},[S,r,o]),z=(0,i.useCallback)(()=>{S(u.current)},[S,u]),$=(0,i.useCallback)(e=>{let t=e.shiftKey?32:12,n="right"===s?"ArrowRight":"ArrowLeft",r="right"===s?"ArrowLeft":"ArrowRight";e.key===n?(e.preventDefault(),S(u.current+t,{forcePersist:!0})):e.key===r?(e.preventDefault(),S(u.current-t,{forcePersist:!0})):"Home"===e.key?(e.preventDefault(),S(d,{forcePersist:!0})):"End"===e.key?(e.preventDefault(),S(k(),{forcePersist:!0})):"Enter"===e.key&&(e.preventDefault(),E())},[S,k,s,d,E,u]);return(0,i.useEffect)(()=>{if(g.current)return;g.current=!0;let e=function(e){try{let t=window.localStorage.getItem(e);if(null===t)return null;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:null}catch{return null}}(c),t=S(e??o?.()??r,{persist:!1});null!==e&&e!==t&&iD(c,t)},[S,r,o,c]),(0,i.useEffect)(()=>{if(!g.current)return;S(u.current);let e=()=>{S(u.current)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[S,u]),(0,i.useEffect)(()=>{if(!m)return;let e=()=>{let e=h.current;e&&T(e.pointerId)},t=()=>{"visible"!==document.visibilityState&&e()};return window.addEventListener("blur",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("blur",e),document.removeEventListener("visibilitychange",t)}},[T,m]),(0,i.useEffect)(()=>()=>{let e=h.current;e&&(h.current=null,C(e))},[C]),{isResizing:m,panelRef:p,reclampWidth:z,resetWidth:E,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":y?k():a,"aria-valuemin":d,"aria-valuenow":x,"aria-valuetext":`${x} px`,onDoubleClick:E,onKeyDown:$,onLostPointerCapture:W,onPointerCancel:L,onPointerDown:R,onPointerMove:M,onPointerUp:I,role:"separator",tabIndex:0},width:x}}let iH="bg-image",iO="wallpaper";function iU(){return new Promise((e,t)=>{let n=indexedDB.open("pi-web",1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(iH)||n.result.createObjectStore(iH)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}let i_=null;function iq(e){e!==i_&&(i_&&URL.revokeObjectURL(i_),i_=e,document.documentElement.style.setProperty("--app-bg-image",e?`url("${e}")`:"none"))}async function iK(){try{let e=await iU(),t=await new Promise((t,n)=>{let r=e.transaction(iH,"readonly").objectStore(iH).get(iO);r.onsuccess=()=>t(r.result??null),r.onerror=()=>n(r.error)});if(!t)return iq(null),!1;return iq(URL.createObjectURL(t)),!0}catch{return!1}}async function iV(e){let t=await iU();await new Promise((n,r)=>{let i=t.transaction(iH,"readwrite"),o=i.objectStore(iH);e?o.put(e,iO):o.delete(iO),i.oncomplete=()=>n(),i.onerror=()=>r(i.error)})}function iY(){let e,t,n,s,a,d,c,f,v,y=(0,o.useRouter)(),b=(0,o.useSearchParams)(),[k]=(0,i.useState)(()=>{let e;return{requestedCwd:e=b.get("cwd")?.trim()||null,sessionId:e?null:b.get("session")}}),{preference:w,toggleTheme:j}=e5(),{hasBg:S,ready:C,pick:T,remove:R}=function(){let[e,t]=(0,i.useState)(!1),[n,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=!0;return iK().then(n=>{e&&(t(n),r(!0))}),()=>{e=!1}},[]),{hasBg:e,ready:n,pick:(0,i.useCallback)(async e=>{await iV(e),iq(URL.createObjectURL(e)),t(!0)},[]),remove:(0,i.useCallback)(async()=>{await iV(null),iq(null),t(!1)},[])}}(),M="light"===w?"theme.light":"dark"===w?"theme.dark":"theme.auto",{locale:I,setLocale:L,t:E,supportedLocales:z}=(0,m.s)(),$=tZ();(0,i.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=document.documentElement,n=null,r=()=>{let r;n=null,!function({hasFocusedEditable:e,innerHeight:t,viewportHeight:n,viewportScale:r}){let i=.01>Math.abs(r-1);return e&&i&&t-n>1}({hasFocusedEditable:(r=document.activeElement)instanceof HTMLElement&&(r.isContentEditable||"INPUT"===r.tagName||"SELECT"===r.tagName||"TEXTAREA"===r.tagName),innerHeight:window.innerHeight,viewportHeight:e.height,viewportScale:e.scale})?t.style.removeProperty("--app-viewport-height"):t.style.setProperty("--app-viewport-height",`${e.height}px`);let i=0!==window.scrollX||0!==window.scrollY,o=.01>Math.abs(e.scale-1);i&&o&&window.scrollTo(0,0)},i=()=>{null!==n&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(r)};return i(),e.addEventListener("resize",i),e.addEventListener("scroll",i),window.addEventListener("resize",i),window.addEventListener("focusin",i),window.addEventListener("focusout",i),window.addEventListener("pageshow",i),()=>{e.removeEventListener("resize",i),e.removeEventListener("scroll",i),window.removeEventListener("resize",i),window.removeEventListener("focusin",i),window.removeEventListener("focusout",i),window.removeEventListener("pageshow",i),null!==n&&window.cancelAnimationFrame(n),t.style.removeProperty("--app-viewport-height")}},[]);let{soundEnabled:P,onSoundToggle:F,playDoneSound:N,unlockAudio:A,soundEnabledRef:D}=function(){let[e,t]=(0,i.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),n=(0,i.useRef)(e);(0,i.useEffect)(()=>{n.current=e},[e]);let r=(0,i.useRef)(null),o=(0,i.useCallback)(()=>{if(r.current&&"closed"!==r.current.state)return r.current;try{r.current=new AudioContext}catch{return null}return r.current},[]),l=(0,i.useCallback)((e=!1)=>{if(!e&&!n.current)return;let t=o();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[o]);return{soundEnabled:e,onSoundToggle:(0,i.useCallback)(()=>{let e=!n.current;e&&l(!0),n.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[l]),playDoneSound:(0,i.useCallback)(()=>{if(!n.current)return;let e=o();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((n,r)=>{let i=e.createOscillator(),o=e.createGain();i.connect(o),o.connect(e.destination),i.type="sine",i.frequency.value=n;let l=t+.18*r;o.gain.setValueAtTime(0,l),o.gain.linearRampToValueAtTime(.18,l+.02),o.gain.exponentialRampToValueAtTime(.001,l+.45),i.start(l),i.stop(l+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[o]),unlockAudio:l,soundEnabledRef:n}}(),B=(0,i.useRef)(new Set),H=(0,i.useCallback)(()=>{D.current&&N()},[N,D]),[O,U]=(0,i.useState)(null),[_,q]=(0,i.useState)(()=>new Set),K=(0,i.useCallback)(e=>{q(t=>t.size===e.size&&[...e].every(e=>t.has(e))?t:e)},[]),[V,Y]=(0,i.useState)(null),[J,Z]=(0,i.useState)("initial"),G=(0,i.useRef)(null),[Q,ee]=(0,i.useState)(()=>k.requestedCwd?"validating":"idle"),[et,en]=(0,i.useState)(null),[er,ei]=(0,i.useState)(0),[eo,el]=(0,i.useState)(0),[es,ea]=(0,i.useState)(0),[ed,ec]=(0,i.useState)(!1),[eu,ep]=(0,i.useState)(0),[eh,eg]=(0,i.useState)(!1),[ex,ef]=(0,i.useState)(!1),[em,ev]=(0,i.useState)(null),[ey,eb]=(0,i.useState)(!1),[ek,ew]=(0,i.useState)(!1),[ej,eS]=(0,i.useState)(null),[eC,eT]=(0,i.useState)(!0),[eR,eM]=(0,i.useState)(!1),[eI,eL]=(0,i.useState)(!1),[eW,eE]=(0,i.useState)(!1),ez=(0,i.useRef)(null),e$=(0,i.useRef)(null),eP=(0,i.useRef)(null),[eF,eN]=(0,i.useState)(null),[eA,eD]=(0,i.useState)(!1),eB=(0,i.useRef)(260),eH=(0,i.useRef)(560),eO=(0,i.useCallback)(()=>iA(.42*window.innerWidth,360,640),[]),eU=(0,i.useCallback)(()=>(function(e){let{viewportWidth:t,rightPanelOpen:n,rightPanelWidth:r}=e;if(t<=640)return 480;let i=t<960;return Math.min(480,t-(i?320:420)-(!i&&n?r:0))})({viewportWidth:window.innerWidth,rightPanelOpen:eR,rightPanelWidth:eH.current}),[eR]),e_=(0,i.useCallback)(()=>(function(e){let{viewportWidth:t,sidebarOpen:n,sidebarWidth:r}=e;return t<960?1200:Math.min(1200,t-420-(n?r:0))})({viewportWidth:window.innerWidth,sidebarOpen:eC,sidebarWidth:eB.current}),[eC]),eq=iB({ariaLabel:E("layout.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:eU,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:eB}),eK=iB({ariaLabel:E("layout.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:560,getDefaultWidth:eO,getMaxWidth:e_,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:eH}),eV=eq.reclampWidth,eY=eK.reclampWidth;(0,i.useEffect)(()=>{$&&eT(!1)},[$]);let eJ=(0,i.useCallback)(e=>{let t=e.currentTarget.getBoundingClientRect(),n=t.left;n+264>window.innerWidth-8&&(n=Math.max(8,window.innerWidth-264-8)),eN({left:n,top:t.bottom+6}),eE(e=>!e)},[]);(0,i.useEffect)(()=>{if(!eW)return;let e=e=>{ez.current&&!ez.current.contains(e.target)&&eP.current&&!eP.current.contains(e.target)&&eE(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[eW]),(0,i.useEffect)(()=>{eD(!0)},[]),(0,i.useEffect)(()=>{eR&&(eV(),eY())},[eY,eV,eR]);let eZ=(0,i.useRef)(null),eG=(0,i.useRef)(null),eX=(0,i.useRef)(null),eQ=(0,i.useRef)(null),[e0,e1]=(0,i.useState)([]),[e2,e8]=(0,i.useState)(null),e4=(0,i.useRef)(null),e6=(0,i.useCallback)((e,t,n)=>{e1(e),e8(t),e4.current=n},[]),e7=(0,i.useCallback)(e=>{e4.current?.(e)},[]),[e9,te]=(0,i.useState)(null),[tt,tn]=(0,i.useState)(!1),tr=(0,i.useRef)(null),ti=(0,i.useRef)(0),to=(0,i.useRef)(null),tl=(0,i.useCallback)(e=>{te(e),tn(!1)},[]),ts=(0,i.useCallback)(e=>{ti.current+=1,tr.current=e,tn(!1)},[]),[ta,td]=(0,i.useState)(null),[tc,tu]=(0,i.useState)([]),[tp,th]=(0,i.useState)(!1),[tg,tx]=(0,i.useState)(null),tf=(0,i.useRef)(null),tm=(0,i.useRef)(null),[tv,ty]=(0,i.useState)({kind:"idle"}),tb=(0,i.useRef)(null),tk=(0,i.useRef)(O?.id??null);tk.current=O?.id??null;let tw=(0,i.useCallback)(e=>{td(e)},[]),tj=(0,i.useCallback)(e=>{tu(e)},[]),tS=(0,i.useCallback)(async e=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/todos`);if(!t.ok)return;let n=await t.json();Array.isArray(n.todos)&&tu(n.todos)}catch{}},[]),[tC,tT]=(0,i.useState)(null),tR=(0,i.useRef)(null),tM=(0,i.useCallback)((e,t)=>{e3(t).then(()=>{tR.current&&clearTimeout(tR.current),tT(e),tR.current=setTimeout(()=>tT(null),1400)})},[]);(0,i.useEffect)(()=>()=>{tR.current&&clearTimeout(tR.current),tb.current&&clearTimeout(tb.current)},[]);let[tI,tL]=(0,i.useState)(null),tW=(0,i.useCallback)(e=>{tL(e)},[]),[tE,tz]=(0,i.useState)(null),[t$,tP]=(0,i.useState)(null),tF=(0,i.useCallback)((e,t=!1)=>{$&&eT(!1),th(!1),tz(t=>t===e?null:e),$&&t&&eL(!0)},[$]),tN=(0,i.useCallback)((e=!1)=>{let t="system"!==tE;if(tF("system",e),!t||tt)return;let n=tr.current;if(!n)return;let r=++ti.current;tn(!0),n().catch(e=>{console.error("Failed to load system prompt:",e)}).finally(()=>{ti.current===r&&tn(!1)})},[tE,tt,tF]),tA=(0,i.useCallback)(()=>{$&&eT(!1),eL(!1),th(!1),tz("session")},[$]),tD=(0,i.useCallback)(()=>{if($&&eT(!1),eL(!1),tz(null),!tp){if(tf.current){let e=tf.current.getBoundingClientRect();tx({top:e.bottom+2,right:Math.max(8,Math.round(window.innerWidth-e.right))})}O?.id&&tS(O.id)}th(e=>!e)},[$,tp,O?.id,tS]);(0,i.useEffect)(()=>{if(!tp)return;let e=e=>{let t=e.target;tf.current?.contains(t)||tm.current?.contains(t)||th(!1)},t=e=>{"Escape"===e.key&&th(!1)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[tp]);let tB=(0,i.useCallback)(()=>{$&&(tz(null),th(!1),eL(!1)),eT(e=>!e)},[$]),tH=(0,i.useCallback)(()=>{eT(!1),tz(null),th(!1),eL(e=>!e)},[]),tO=(0,i.useCallback)(()=>{$&&(eT(!1),tz(null),eL(!1)),eM(e=>!e)},[$]);(0,i.useEffect)(()=>{if(!eI)return;let e=e=>{let t=eX.current;t&&e.composedPath().includes(t)||eL(!1)},t=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),eL(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[eI]),(0,i.useEffect)(()=>{eL(!1)},[$,O?.id,J]),(0,i.useEffect)(()=>{if(!tE||!eG.current)return;let e=()=>{let e=eG.current.getBoundingClientRect();if("language"===tE&&!$&&eQ.current){let t=eQ.current.getBoundingClientRect(),n=Math.min(176,e.width),r=Math.min(t.left-1,Math.max(e.left,e.right-n));tP({top:e.bottom,left:r,width:n});return}tP({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(eG.current),eQ.current&&t.observe(eQ.current),()=>t.disconnect()},[tE,$]);let[tU,t_]=(0,i.useState)([]),[tK,tV]=(0,i.useState)(null),tY=(0,i.useCallback)((e,t,n)=>{t_(r=>(function(e,t,n,r){let i=e.findIndex(e=>e.id===t);if(-1===i||(e[i].viewerRevision??0)!==n)return e;let o=[...e];return o[i]={...o[i],viewerState:r},o})(r,e,t,n))},[]),tJ=(0,i.useCallback)((e,t)=>{eZ.current?.insertText(tq(e,t)),$&&(eM(!1),eT(!1))},[$]),tG=(0,i.useCallback)(e=>{let t=e.map(e=>tq(e,!1)).join("");t&&eZ.current?.insertText(t),$&&(eM(!1),eT(!1))},[$]),tX=(0,i.useCallback)((e,t,n)=>{let r,i,o,l;eZ.current?.insertText((r=Math.max(1,Math.min(t,n)),i=Math.max(1,Math.max(t,n)),o=e.includes(" ")?`@"${e}"`:`@${e}`,l=r===i?`:${r}`:`:${r}-${i}`,`${o}${l} `)),$&&(eM(!1),eT(!1))},[$]),tQ=k.sessionId,[t0,t1]=(0,i.useState)(null),t2=(0,i.useRef)(null),[t8,t4]=(0,i.useState)(()=>!tQ),t6=(0,i.useRef)(!1),t5=(0,i.useRef)(0),t3=(0,i.useCallback)(()=>{t5.current+=1},[]);(0,i.useEffect)(()=>{O&&function(e,t,n=p()){if(n)try{let r=h(n);r[e]=t,n.setItem(u,JSON.stringify(r))}catch{}}(O.projectKey??t2.current??x(O),O.id)},[O]),(0,i.useEffect)(()=>{let e=k.requestedCwd;if(!e)return;let t=new AbortController;return ee("validating"),en(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async t=>{let n=await t.json().catch(()=>({}));if(!t.ok||!n.cwd)throw Error(n.error??`HTTP ${t.status}`);t6.current=!0;let r=`initial:${e}`;Z(r),G.current=`new:${r}:${n.cwd}`,Y(n.cwd),ee("ready")}).catch(e=>{t.signal.aborted||(en(e instanceof Error?e.message:String(e)),ee("error"))}),()=>t.abort()},[k]);let t7=(0,i.useCallback)(e=>{let t=++t5.current,n=function(e,t=p()){if(!t)return null;try{let n=h(t)[e];return"string"==typeof n&&n.length>0?n:null}catch{return null}}(e);n&&fetch("/api/sessions").then(e=>e.ok?e.json():null).then(r=>{if(t!==t5.current)return;let i=r?.sessions.find(e=>e.id===n);if(!i){r&&g(e);return}x(i)!==e?g(e):(U(i),el(e=>e+1),new URLSearchParams(window.location.search).get("session")!==i.id&&y.replace(`?session=${encodeURIComponent(i.id)}`,{scroll:!1}))}).catch(()=>{})},[y]),t9=(0,i.useCallback)((e,t,n)=>{t3();let r=V??t0;if(t1(e),!e)return;let i=n??t??e,o=t2.current??(O?x(O):null);if(t2.current=i,t6.current){t6.current=!1;return}if(r===e&&o!==i||o===i&&(null!==O||r===e))return;let l="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;Z(l),G.current=`new:${l}:${e}`,U(null),Y(t=>t&&t!==e?null:t),el(e=>e+1),e1([]),e8(null),te(null),tn(!1),tz(null),o!==i&&(t_([]),tV(null),eM(!1),t7(i)),y.replace("/",{scroll:!1})},[t0,t3,V,y,O,t7]),ne=(0,i.useCallback)((e,t=!1)=>{if(t3(),G.current=null,!t&&O){let t=x(O)===x(e);if(O.id===e.id&&t){$&&eT(!1);return}}Y(null),U(e),el(e=>e+1),te(null),tn(!1),t4(!0),$&&!t&&eT(!1),t&&(t6.current=!0),t||y.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[t3,y,$,O]),nt=(0,i.useCallback)((e,t)=>{t3(),G.current=`new:${e}:${t}`,Z(e),U(null),Y(t),el(e=>e+1),e1([]),e8(null),te(null),tn(!1),tz(null),$&&eT(!1),y.replace("/",{scroll:!1})},[t3,y,$]);!function(e){let{onNewSession:t,activeCwd:n}=e;(0,i.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(!l)return;let t=e.target?.tagName;if("TEXTAREA"===t||"INPUT"===t)return;e.preventDefault(),l();return}if("n"===e.key&&e.ctrlKey&&e.altKey){if(!n||!t)return;e.preventDefault(),t(n)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[n,t])}({onNewSession:e=>nt(`kb-${Date.now()}`,e),activeCwd:t0});let nn=(0,i.useCallback)(e=>{fetch("/api/sessions",{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>{let n=t?.sessions.find(t=>t.id===e);n&&U(t=>t?.id===e?{...t,...n,transient:n.transient??!1}:t)}).catch(()=>{})},[]),nr=(0,i.useCallback)((e,t)=>{ei(e=>e+1),G.current===t&&(t3(),G.current=null,Y(null),U(e),nn(e.id),y.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1}))},[t3,y,nn]),ni=(0,i.useCallback)(({targetSession:e,title:t,body:n,tag:r})=>{if(!("Notification"in window))return;let i=()=>{nw({title:t,body:n,sessionUrl:e?`/?session=${encodeURIComponent(e.id)}`:"/",tag:r,onClick:()=>{window.focus(),e&&ne(e)}})};"granted"===Notification.permission?i():"default"===Notification.permission&&Notification.requestPermission().then(e=>{"granted"===e&&i()})},[ne]),no=(0,i.useCallback)(()=>{ei(e=>e+1),ea(e=>e+1),O&&nn(O.id),nb()&&ni({targetSession:O,title:O?.name??E("i18n.sessionComplete"),body:E("i18n.taskFinished")})},[ni,nn,O,E]),nl=(0,i.useCallback)(e=>{var t;nb()&&(t=B.current,!(!nk(e)||t.has(e.id))&&(t.add(e.id),1)&&ni({targetSession:O,title:E("i18n.attentionNeeded"),body:"custom"===e.method?E("i18n.extensionInputNeeded"):e.title,tag:`pi-extension-ui:${e.id}`}))},[ni,O,E]),ns=(0,i.useCallback)(async()=>{let e=O?.id;if(e&&"naming"!==tv.kind){tb.current&&clearTimeout(tb.current),tz(null),ty({kind:"naming"});try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/auto-name`,{method:"POST"}),n=await t.json().catch(()=>({}));if(!t.ok||!n.title)throw Error(n.error||`HTTP ${t.status}`);let r=n.title.trim();if(ei(e=>e+1),tk.current!==e)return;U(t=>t?.id===e?{...t,name:r}:t),td(t=>t?.sessionId===e?{...t,sessionName:r}:t),ty({kind:"success"}),tb.current=setTimeout(()=>ty({kind:"idle"}),1800)}catch(t){if(tk.current!==e)return;ty({kind:"error",message:t instanceof Error?t.message:String(t)}),tb.current=setTimeout(()=>ty({kind:"idle"}),5e3)}}},[tv.kind,O?.id]);(0,i.useEffect)(()=>{tb.current&&clearTimeout(tb.current),ty({kind:"idle"})},[O?.id]),(0,i.useEffect)(()=>{th(!1)},[O?.id]);let na=!!(O?.id&&_.has(O.id));(0,i.useEffect)(()=>{let e,t=O?.id;if(!t||!na)return;let n=!1,r=async()=>{await tS(t),n||(e=setTimeout(r,6e3))};return r(),()=>{n=!0,e&&clearTimeout(e)}},[O?.id,na,tS]);let nd=(0,i.useCallback)(()=>{ea(e=>e+1)},[]),nc=(0,i.useCallback)(e=>{t3(),G.current=null,ei(e=>e+1),el(e=>e+1),Y(null),U(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e,transient:!1})),nn(e),y.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[t3,y,nn]),nu=(0,i.useCallback)(()=>{t4(!0)},[]),np=(0,i.useCallback)(e=>{if(t3(),ei(e=>e+1),O?.id===e){let e=O.cwd,t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;Z(t),G.current=e?`new:${t}:${e}`:null,U(null),Y(e??null),el(e=>e+1),e1([]),e8(null),te(null),tn(!1),tz(null),y.replace("/",{scroll:!1})}},[t3,O,y]),nh=(0,i.useCallback)((e,t,n)=>{let r=n?.sourceSessionId,i=n?.modeHint,o=`file:${e}`;t_(n=>(function(e,t){let n=e.find(e=>e.id===t.tabId);if(!n)return[...e,{id:t.tabId,label:t.fileName,filePath:t.filePath,sourceSessionId:t.sourceSessionId,initialDisplayMode:t.modeHint,viewerState:t.modeHint?{displayMode:t.modeHint,wrapLines:!1,scrollTop:0,scrollLeft:0}:void 0,viewerRevision:0}];let r=!!(t.sourceSessionId&&n.sourceSessionId!==t.sourceSessionId);return r||t.modeHint?e.map(e=>{if(e.id!==t.tabId)return e;let n={...e};return r&&(n.sourceSessionId=t.sourceSessionId),t.modeHint?(n.initialDisplayMode=t.modeHint,n.viewerState={displayMode:t.modeHint,wrapLines:e.viewerState?.wrapLines??!1,scrollTop:0,scrollLeft:0},n.viewerRevision=(e.viewerRevision??0)+1):r&&(n.viewerRevision=(e.viewerRevision??0)+1),n}):e})(n,{fileName:t,filePath:e,modeHint:i,sourceSessionId:r,tabId:o})),tV(o),eM(!0),$&&eT(!1)},[$]),ng=(0,i.useCallback)(e=>{nh(e,W(e),{sourceSessionId:O?.id??null})},[nh,O?.id]),nx=(0,i.useCallback)(e=>{t_(t=>{let n=t.filter(t=>t.id!==e);return 0===n.length&&eM(!1),n}),tV(t=>{if(t!==e)return t;let n=tU.filter(t=>t.id!==e);return n.length>0?n[n.length-1].id:null})},[tU]),nf=(0,i.useCallback)(()=>{O&&window.open(`/api/sessions/${encodeURIComponent(O.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[O]),nm=V??(null===O&&t0?t0:null),nv=null===O&&nm?`new:${J}:${nm}`:null;(0,i.useLayoutEffect)(()=>{G.current=nv},[nv]);let ny=null!==O||null!==nm,nj=O?.cwd??nm,nS=t8&&!ny;(0,i.useEffect)(()=>{if(ev(null),eb(!1),eS(null),!nj)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(nj)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);ev(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[nj]);let nC=(0,i.useCallback)(async()=>{if(nj&&!ek){ew(!0),eS(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:nj})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);ev(t),eb(!1),ep(e=>e+1),el(e=>e+1)}catch(e){eS(e instanceof Error?e.message:String(e))}finally{ew(!1)}}},[ek,nj]),nT=tU.find(e=>e.id===tK)??null,nR=t0?W(t0)||t0:null,nM=nR?`${nR} - Pi Web`:"Pi Web";(0,i.useEffect)(()=>{let e=()=>{document.title!==nM&&(document.title=nM)};e();let t=new MutationObserver(e);return t.observe(document.head,{childList:!0,subtree:!0,characterData:!0}),()=>t.disconnect()},[nM]);let nI=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(X,{selectedSessionId:O?.id??null,onSelectSession:ne,onNewSession:nt,initialSessionId:tQ,skipInitialProjectSelection:null!==k.requestedCwd,onInitialRestoreDone:nu,refreshKey:er,onSessionDeleted:np,selectedCwd:O?.cwd??V??null,onCwdChange:t9,onOpenFile:nh,explorerRefreshKey:es,onExplorerRefresh:nd,onAtMention:tJ,onAtMentions:tG,onBackgroundTaskDone:H,onRunningSessionIdsChange:K}),(0,r.jsx)("div",{style:{padding:"8px",flexShrink:0,display:"flex",justifyContent:"space-between",gap:4},children:[{label:E("common.models"),onClick:()=>ec(!0),disabled:!1,icon:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,r.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,r.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,r.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,r.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,r.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,r.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,r.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,r.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]})},{label:E("common.skills"),onClick:()=>eg(!0),disabled:!t0&&!O?.cwd&&!V,icon:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,r.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,r.jsx)("path",{d:"M2 12l10 5 10-5"})]})},{label:E("common.plugins"),onClick:()=>ef(!0),disabled:!t0&&!O?.cwd&&!V,icon:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M9 7V2"}),(0,r.jsx)("path",{d:"M15 7V2"}),(0,r.jsx)("path",{d:"M6 13V8a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v5a6 6 0 0 1-12 0Z"}),(0,r.jsx)("path",{d:"M12 19v3"})]})}].map(({label:e,onClick:t,disabled:n,icon:i})=>(0,r.jsxs)("button",{onClick:t,disabled:n,title:e,style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:n?"default":"pointer",fontSize:12,opacity:n?.35:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{n||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:[i,e]},e))})]}),nL=e=>(0,r.jsx)("button",{type:"button",onClick:t=>{let n=t.currentTarget.getBoundingClientRect();j({x:n.left+n.width/2,y:n.top+n.height/2}),e&&eL(!0)},title:E(M),"aria-label":E(M),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},"data-mobile-toolbar-action":e?"theme":void 0,children:"light"===w?(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,r.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,r.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,r.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,r.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,r.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,r.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,r.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,r.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):"dark"===w?(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}):(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),(0,r.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,r.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}),nW=e=>(0,r.jsx)("button",{ref:eP,type:"button",onClick:t=>{eJ(t),e&&eL(!0)},title:E("bg.title"),"aria-label":E("bg.title"),"aria-haspopup":"menu","aria-expanded":eW,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:eW?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},"data-mobile-toolbar-action":e?"bg":void 0,children:(0,r.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,r.jsx)("path",{d:"M21 15l-5-5L5 21"})]}),S&&(0,r.jsx)("span",{"aria-label":E("bg.title"),title:E("bg.title"),style:{position:"absolute",top:-2,right:-2,width:7,height:7,borderRadius:"50%",background:"var(--accent)",boxShadow:"0 0 0 2px var(--bg-panel)"}})]})}),nE=e=>(0,r.jsx)("button",{ref:eQ,type:"button",onClick:()=>tF("language",e),title:E("common.language"),"aria-label":E("common.language"),"aria-haspopup":"menu","aria-expanded":"language"===tE,"aria-pressed":"language"===tE,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"language"===tE?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:"language"===tE?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="language"===tE?"var(--text)":"var(--text-muted)"},"data-mobile-toolbar-action":e?"language":void 0,children:(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"m5 8 6 6"}),(0,r.jsx)("path",{d:"m4 14 6-6 2-3"}),(0,r.jsx)("path",{d:"M2 5h12"}),(0,r.jsx)("path",{d:"M7 2h1"}),(0,r.jsx)("path",{d:"m22 22-5-10-5 10"}),(0,r.jsx)("path",{d:"M14 18h6"})]})}),nz=e=>ny&&em?.requiresTrust&&!em.trusted?(0,r.jsxs)("button",{type:"button",onClick:()=>{eS(null),eb(!0)},title:E("trust.resourcesNotLoaded"),"aria-label":E("trust.resourcesNotLoaded"),style:{display:"flex",alignItems:"center",justifyContent:e?"flex-start":"center",gap:6,width:e?"100%":void 0,minHeight:e?32:void 0,height:e?void 0:"100%",padding:e?"6px 12px":"0 12px",background:e?"color-mix(in srgb, #d97706 8%, var(--bg-panel))":"none",border:"none",borderRight:e?"none":"1px solid var(--border)",borderBottom:e?"1px solid var(--border)":"none",color:"#d97706",cursor:"pointer",flexShrink:0,fontSize:11,lineHeight:1.35,textAlign:"left"},"data-mobile-trust-banner":e?"true":void 0,children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"}),(0,r.jsx)("path",{d:"M12 8v4"}),(0,r.jsx)("path",{d:"M12 16h.01"})]}),(0,r.jsx)("span",{children:E("trust.resourcesNotLoaded")})]}):null,n$=e=>{let t,n,i,o,l,s;return e||ny?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{nf(),e&&eL(!0)},disabled:!O,title:O?E("history.full"):E("history.unsaved"),"aria-label":E("history.full"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"none",border:"none",borderTop:"2px solid transparent",borderRight:"1px solid var(--border)",color:O?"var(--text-muted)":"var(--text-dim)",cursor:O?"pointer":"not-allowed",opacity:O?1:.45,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{O&&(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=O?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.background="none"},"data-mobile-toolbar-action":e?"history":void 0,children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:O?"var(--text-muted)":"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"}),(0,r.jsx)("path",{d:"M12 7v5l3 2"})]}),!e&&(0,r.jsx)("span",{children:E("history.label")})]}),(t=!!(O&&((ta?.userMessages??0)>0||O.messageCount>0)),n=!O||O.transient||!t||"naming"===tv.kind,i="success"===tv.kind,o="error"===tv.kind,l="naming"===tv.kind?E("title.generating"):i?E("title.updated"):o?E("title.failed"):E("title.generate"),s=!O||O.transient?E("title.unsaved"):t?o?tv.message:E("title.generateSession"):E("title.noMessages"),(0,r.jsxs)("button",{type:"button",onClick:()=>{ns(),e&&eL(!0)},disabled:n,title:s,"aria-label":l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"none",border:"none",borderTop:"2px solid transparent",borderRight:"1px solid var(--border)",color:o?"#dc2626":i?"var(--accent)":n?"var(--text-dim)":"var(--text-muted)",cursor:n?"not-allowed":"pointer",opacity:n&&"naming"!==tv.kind?.45:1,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{n||(e.currentTarget.style.color=o?"#dc2626":"var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=o?"#dc2626":i?"var(--accent)":n?"var(--text-dim)":"var(--text-muted)",e.currentTarget.style.background="none"},"data-mobile-toolbar-action":e?"name":void 0,children:["naming"===tv.kind?(0,r.jsxs)("svg",{className:"animate-spin",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,r.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):i?(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.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:[(0,r.jsx)("path",{d:"m15 4 5 5L7 22l-5-5Z"}),(0,r.jsx)("path",{d:"m14 5 5 5"}),(0,r.jsx)("path",{d:"M6 4V2M5 3H3M19 19v3M17.5 20.5h3"})]}),!e&&(0,r.jsx)("span",{children:l})]})),e?(0,r.jsx)("button",{type:"button",onClick:()=>tF("branches",!0),title:E("i18n.branches"),"aria-label":E("i18n.branches"),"aria-pressed":"branches"===tE,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:"100%",padding:0,background:"branches"===tE?"var(--bg-selected)":"none",border:"none",borderTop:"branches"===tE?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:"branches"===tE?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0},"data-mobile-toolbar-action":"branches",children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:e0.length>0?"var(--accent)":"var(--text-dim)"},"aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}):(0,r.jsx)(iN,{tree:e0,activeLeafId:e2,onLeafChange:e7,inline:!0,containerRef:eG,open:"branches"===tE,onToggle:()=>tF("branches"),hasSession:!0}),(0,r.jsxs)("button",{ref:to,type:"button",onClick:()=>tN(e),disabled:e&&!ny,title:E("system.prompt"),"aria-label":E("system.prompt"),"aria-pressed":"system"===tE,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"system"===tE?"var(--bg-selected)":"none",border:"none",borderTop:"system"===tE?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:e&&!ny?"not-allowed":"pointer",color:"system"===tE?"var(--text)":"var(--text-muted)",opacity:e&&!ny?.45:1,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:t=>{(!e||ny)&&(t.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="system"===tE?"var(--text)":"var(--text-muted)"},"data-mobile-toolbar-action":e?"system":void 0,children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:e9?"var(--accent)":"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,r.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,r.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,r.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),!e&&(0,r.jsx)("span",{children:E("system.label")})]}),e&&nL(!0),e&&nE(!0),e&&nW(!0)]}):null},nP=e=>{if(!e&&(!ny||!ta&&!tI))return null;let t=ta?.tokens,n=ta?.cost??0,i=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=n>0?n>=.01?`$${n.toFixed(2)}`:"<$0.01":null,l="var(--text-muted)",s=null,a=null;if(tI?.contextWindow){let e=tI.percent;null!==e&&e>90?l="#ef4444":null!==e&&e>70&&(l="rgba(234,179,8,0.95)"),s=null!==e?`${e.toFixed(0)}% / ${i(tI.contextWindow)}`:`? / ${i(tI.contextWindow)}`,a=null!==e?`${e.toFixed(0)}%`:null}let d=[];if(t&&(d.push(`in: ${t.input.toLocaleString(I)}`),d.push(`out: ${t.output.toLocaleString(I)}`),d.push(`cache read: ${t.cacheRead.toLocaleString(I)}`),d.push(`cache write: ${t.cacheWrite.toLocaleString(I)}`),n>0&&d.push(`cost: $${n.toFixed(4)}`)),tI?.contextWindow){let e=tI.percent;d.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${tI.contextWindow.toLocaleString()} tokens`)}let c=d.join(" | "),u=e&&eI,p=!!(t&&(t.input>0||t.output>0)||o||a);return(0,r.jsx)("button",{type:"button",onClick:()=>tF("session"),disabled:!ny||u,tabIndex:u?-1:void 0,title:c||E("session.title"),"aria-label":E("session.title"),"aria-pressed":"session"===tE,"aria-hidden":!!u||void 0,className:e?"mobile-session-stats":void 0,"data-mobile-toolbar-stats":e?"true":void 0,style:{marginLeft:e?0:"auto",display:"flex",alignItems:"center",justifyContent:"flex-end",flex:e?1:void 0,minWidth:0,gap:e?7:10,paddingLeft:e?6:12,paddingRight:e?6:12,height:"100%",overflow:"hidden",visibility:u?"hidden":"visible",pointerEvents:u?"none":"auto",background:"session"===tE?"var(--bg-selected)":"none",border:"none",borderTop:"session"===tE?"2px solid var(--accent)":"2px solid transparent",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:ny?"pointer":"default",fontVariantNumeric:"tabular-nums",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{ny&&!u&&(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="session"===tE?"var(--text)":"var(--text-muted)"},children:e?(0,r.jsxs)(r.Fragment,{children:[t&&t.input>0&&(0,r.jsxs)("span",{className:"mobile-session-stat-io",style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,r.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),i(t.input)]}),t&&t.output>0&&(0,r.jsxs)("span",{className:"mobile-session-stat-io",style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,r.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),i(t.output)]}),o&&(0,r.jsx)("span",{className:"mobile-session-stat-cost",style:{color:"var(--text)",fontWeight:500,flexShrink:0},children:o}),a&&(0,r.jsx)("span",{style:{color:l,flexShrink:0},children:a}),!p&&ny&&(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",color:"var(--text-dim)"},children:E("session.title")})]}):(0,r.jsxs)(r.Fragment,{children:[t&&t.input>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,r.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),i(t.input)]}),t&&t.output>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,r.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),i(t.output)]}),t&&t.cacheRead>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,r.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),i(t.cacheRead)]}),o&&(0,r.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:o}),s&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:l},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,r.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),s]})]})})},nF=e=>{if(0===tc.length)return null;let t=tc.filter(e=>"completed"!==e.status).length,n=tp&&!e;return(0,r.jsxs)("button",{type:"button",ref:tf,onClick:tD,title:E("todo.title"),"aria-label":E("todo.title"),"aria-expanded":tp,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:"100%",padding:e?"0 8px":"0 12px",background:n?"var(--bg-selected)":"none",border:"none",borderTop:n?"2px solid var(--accent)":"2px solid transparent",borderLeft:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=n?"var(--text)":"var(--text-muted)"},children:[(0,r.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:[(0,r.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"3"}),(0,r.jsx)("path",{d:"M8 9h8M8 13h5"})]}),(0,r.jsx)("span",{children:t>0?t:"✓"})]})},nN=e=>{let t=e&&eI;return(0,r.jsx)("button",{type:"button",onClick:tO,disabled:t,tabIndex:t?-1:void 0,"aria-controls":"file-panel","aria-expanded":eR,"aria-hidden":!!t||void 0,title:eR?E("files.hidePanel"):E("files.showPanel"),"aria-label":eR?E("files.hidePanel"):E("files.showPanel"),"data-mobile-toolbar-file":e?"true":void 0,style:{marginLeft:e||ta||tI?0:"auto",display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,visibility:t?"hidden":"visible",pointerEvents:t?"none":"auto",background:eR?"var(--bg-selected)":"none",border:"none",borderLeft:"1px solid var(--border)",color:eR?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{t||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color=eR?"var(--text)":"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("style",{children:`
|
|
5
|
+
@keyframes session-info-pop {
|
|
6
|
+
0% {
|
|
7
|
+
opacity: 0;
|
|
8
|
+
transform: translateY(-24px);
|
|
9
|
+
filter: blur(6px);
|
|
10
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0);
|
|
11
|
+
}
|
|
12
|
+
55% {
|
|
13
|
+
opacity: 1;
|
|
14
|
+
transform: translateY(0);
|
|
15
|
+
filter: blur(0);
|
|
16
|
+
background: color-mix(in srgb, var(--accent) 8%, var(--bg-panel));
|
|
17
|
+
box-shadow: 0 18px 44px rgba(37,99,235,0.16);
|
|
18
|
+
}
|
|
19
|
+
100% {
|
|
20
|
+
opacity: 1;
|
|
21
|
+
transform: translateY(0);
|
|
22
|
+
filter: blur(0);
|
|
23
|
+
background: var(--bg-panel);
|
|
24
|
+
box-shadow: 0 10px 28px rgba(0,0,0,0.10);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
@keyframes session-info-light-wash {
|
|
28
|
+
0% {
|
|
29
|
+
opacity: 0;
|
|
30
|
+
transform: translateX(-110%) skewX(-16deg);
|
|
31
|
+
}
|
|
32
|
+
24% {
|
|
33
|
+
opacity: 0.42;
|
|
34
|
+
}
|
|
35
|
+
100% {
|
|
36
|
+
opacity: 0;
|
|
37
|
+
transform: translateX(115%) skewX(-16deg);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
.session-info-popover {
|
|
41
|
+
position: relative;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
transform-origin: top right;
|
|
44
|
+
animation: session-info-pop 360ms ease-out both;
|
|
45
|
+
will-change: transform, opacity, filter, background, box-shadow;
|
|
46
|
+
}
|
|
47
|
+
.session-info-popover::after {
|
|
48
|
+
content: "";
|
|
49
|
+
position: absolute;
|
|
50
|
+
top: 0;
|
|
51
|
+
bottom: 0;
|
|
52
|
+
left: 0;
|
|
53
|
+
width: 44%;
|
|
54
|
+
pointer-events: none;
|
|
55
|
+
background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 24%, transparent), transparent);
|
|
56
|
+
animation: session-info-light-wash 620ms ease-out both;
|
|
57
|
+
}
|
|
58
|
+
@media (prefers-reduced-motion: reduce) {
|
|
59
|
+
.session-info-popover,
|
|
60
|
+
.session-info-popover::after {
|
|
61
|
+
animation: none;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
.mobile-session-stats {
|
|
65
|
+
container-type: inline-size;
|
|
66
|
+
}
|
|
67
|
+
@container (max-width: 158px) {
|
|
68
|
+
.mobile-session-stat-io {
|
|
69
|
+
display: none !important;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
@container (max-width: 88px) {
|
|
73
|
+
.mobile-session-stat-cost {
|
|
74
|
+
display: none !important;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
@media (max-width: 640px) {
|
|
78
|
+
.sidebar-overlay-backdrop.sidebar-mobile-pending {
|
|
79
|
+
opacity: 0 !important;
|
|
80
|
+
pointer-events: none !important;
|
|
81
|
+
}
|
|
82
|
+
.sidebar-container.sidebar-mobile-pending.sidebar-open {
|
|
83
|
+
transform: translateX(calc(-100% - env(safe-area-inset-left)));
|
|
84
|
+
box-shadow: none;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`}),(0,r.jsxs)("div",{style:{display:"flex",width:"100%",height:"var(--app-viewport-height, 100dvh)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",overflow:"hidden",background:"transparent"},children:[eW&&eF&&(0,r.jsxs)("div",{ref:ez,role:"menu","aria-label":E("bg.title"),style:{position:"fixed",top:eF.top,left:eF.left,zIndex:600,width:264,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 32px -8px rgba(0,0,0,0.28)",padding:12,fontFamily:"inherit"},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",letterSpacing:0,marginBottom:10},children:E("bg.title")}),(0,r.jsx)("input",{ref:e$,type:"file",accept:"image/*",style:{display:"none"},onChange:async e=>{let t=e.target.files?.[0];t&&await T(t),e.target.value=""}}),(0,r.jsxs)("button",{type:"button",onClick:()=>e$.current?.click(),disabled:!C,style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"var(--accent)",color:"#fff",border:"none",borderRadius:8,fontSize:13,fontWeight:600,cursor:"pointer",transition:"opacity 0.12s"},children:[(0,r.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:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,r.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),S?E("bg.replace"):E("bg.choose")]}),S&&(0,r.jsxs)("button",{type:"button",onClick:async()=>{await R(),eE(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",marginTop:6,background:"rgba(239,68,68,0.08)",color:"#dc2626",border:"1px solid rgba(239,68,68,0.25)",borderRadius:8,fontSize:13,cursor:"pointer",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.14)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,r.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:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),E("bg.remove")]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",lineHeight:1.5,marginTop:10},children:E("bg.hint")})]}),(0,r.jsx)("div",{className:`sidebar-overlay-backdrop${eA?"":" sidebar-mobile-pending"}`,onClick:()=>eT(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!eC,pointerEvents:eC?"auto":"none",transition:"opacity 0.25s ease"}}),(0,r.jsx)("div",{ref:eq.panelRef,id:"session-sidebar",className:`sidebar-container${eC?" sidebar-open":" sidebar-closed"}${eA?"":" sidebar-mobile-pending"}${eq.isResizing?" sidebar-resizing":""}`,style:{"--sidebar-width":`${eq.width}px`,background:"var(--glass-bg)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(140%)",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(140%)",borderRight:"1px solid color-mix(in srgb, var(--border) 80%, transparent)",display:"flex",flexDirection:"column",flexShrink:0,paddingTop:"env(safe-area-inset-top)",paddingBottom:"env(safe-area-inset-bottom)",zIndex:200},children:nI}),eC&&(0,r.jsx)("div",{...eq.separatorProps,"aria-controls":"session-sidebar",className:`panel-resize-handle sidebar-resize-handle${eq.isResizing?" is-resizing":""}`,"data-resize-handle":"sidebar",title:`${E("layout.resizeSidebar")}: ${E("layout.resizeHint")}`}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,r.jsxs)("div",{ref:eG,style:{position:"relative",zIndex:300,flexShrink:0,background:"var(--glass-bg-strong)",backdropFilter:"blur(var(--glass-blur))",WebkitBackdropFilter:"blur(var(--glass-blur))"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",position:"relative",borderBottom:"1px solid var(--border)",height:"calc(36px + env(safe-area-inset-top))",paddingTop:"env(safe-area-inset-top)"},children:[(0,r.jsx)("button",{onClick:tB,title:eC?E("sidebar.hide"):E("sidebar.show"),"aria-label":eC?E("sidebar.hide"):E("sidebar.show"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:eC?(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,r.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,r.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,r.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),$&&(0,r.jsxs)("div",{ref:eX,"data-mobile-toolbar":"true",style:{position:"relative",display:"flex",alignItems:"stretch",flex:1,minWidth:0,height:"100%"},children:[(0,r.jsx)("button",{type:"button",onClick:tH,title:eI?E("chat.close"):E("chat.moreControls"),"aria-label":eI?E("chat.close"):E("chat.moreControls"),"aria-controls":"mobile-toolbar-actions","aria-expanded":eI,"data-mobile-toolbar-more":"true",style:{position:"relative",zIndex:eI?21:void 0,display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:eI?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:eI?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},children:eI?(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"5",y1:"5",x2:"19",y2:"19"}),(0,r.jsx)("line",{x1:"19",y1:"5",x2:"5",y2:"19"})]}):(0,r.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,r.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),nP(!0),nF(!0),nN(!0),eI&&(0,r.jsx)("div",{id:"mobile-toolbar-actions",role:"toolbar","aria-label":E("chat.moreControls"),"data-mobile-toolbar-actions":"true",style:{position:"absolute",top:0,right:0,bottom:0,left:36,zIndex:20,display:"flex",alignItems:"stretch",background:"color-mix(in srgb, var(--bg-panel) 94%, var(--bg))",boxShadow:"4px 0 18px rgba(0,0,0,0.12)",backdropFilter:"blur(10px)"},children:n$(!0)})]}),!$&&(0,r.jsxs)(r.Fragment,{children:[nW(!1),nL(!1),nE(!1),nz(!1),n$(!1),nP(!1),nF(!1)]}),!$&&nN(!1),$&&(0,r.jsx)(iN,{tree:e0,activeLeafId:e2,onLeafChange:e7,inline:!0,compact:!0,containerRef:eG,open:"branches"===tE,onToggle:()=>tF("branches"),hasSession:ny,hideInlineButton:!0}),tE&&t$&&(0,r.jsxs)("div",{style:{position:"fixed",top:t$.top,left:t$.left,width:t$.width,maxHeight:`calc(100dvh - ${t$.top}px)`,overflowY:"auto",zIndex:500},children:["language"===tE&&(0,r.jsx)("div",{role:"menu","aria-label":E("common.language"),style:{background:"color-mix(in srgb, var(--glass-bg-strong) 55%, transparent)",backdropFilter:"blur(10px) saturate(140%)",WebkitBackdropFilter:"blur(10px) saturate(140%)",borderLeft:"1px solid var(--border)",borderRight:"1px solid var(--border)",borderBottom:"1px solid var(--border)",overflow:"hidden",padding:4},children:z.map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>{L(e.id),tz(null)},role:"menuitemradio","aria-checked":I===e.id,style:{display:"flex",alignItems:"center",width:"100%",height:34,padding:"0 10px",border:"none",borderRadius:4,background:I===e.id?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12,transition:"background 0.1s"},onMouseEnter:t=>{I!==e.id&&(t.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:t=>{I!==e.id&&(t.currentTarget.style.background="transparent")},children:(0,r.jsx)("span",{children:e.label})},e.id))}),"system"===tE&&(0,r.jsx)("div",{style:{background:"color-mix(in srgb, var(--glass-bg-strong) 55%, transparent)",backdropFilter:"blur(10px) saturate(140%)",WebkitBackdropFilter:"blur(10px) saturate(140%)",borderBottom:"1px solid var(--border)"},children:e9?(0,r.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:e9}):""===e9?(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:E("system.empty")}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:tt?E("system.loading"):E("system.load")})}),"session"===tE&&(0,r.jsx)("div",{className:"session-info-popover",style:{background:"color-mix(in srgb, var(--glass-bg-strong) 55%, transparent)",backdropFilter:"blur(10px) saturate(140%)",WebkitBackdropFilter:"blur(10px) saturate(140%)",borderBottom:"1px solid var(--border)",boxShadow:"0 10px 28px rgba(0,0,0,0.16)",padding:"12px 16px"},children:ta?(e=ta.totalActiveMs??0,t=[...ta.sessionName?[{label:E("session.name"),value:ta.sessionName,copyField:null}]:[],{label:E("session.file"),value:ta.sessionFile??E("session.inMemory"),copyField:"file"},{label:E("session.id"),value:ta.sessionId,copyField:"id"},...e>0?[{label:E("session.totalActive"),value:(e=>{if(e<=0)return"0s";let t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`})(e),copyField:null}]:[]],n=[[E("session.user"),ta.userMessages.toLocaleString(I)],[E("session.assistant"),ta.assistantMessages.toLocaleString(I)],[E("session.toolCalls"),ta.toolCalls.toLocaleString(I)],[E("session.toolResults"),ta.toolResults.toLocaleString(I)],[E("session.total"),ta.totalMessages.toLocaleString(I)]],s=[[E("session.input"),ta.tokens.input.toLocaleString(I)],[E("session.output"),ta.tokens.output.toLocaleString(I)],...ta.tokens.cacheRead>0?[[E("session.cacheRead"),ta.tokens.cacheRead.toLocaleString(I)]]:[],...ta.tokens.cacheWrite>0?[[E("session.cacheWrite"),ta.tokens.cacheWrite.toLocaleString(I)]]:[],[E("session.total"),ta.tokens.total.toLocaleString(I)]],a=tI??ta.contextUsage,c=[...ta.cost>0?[[E("session.cost"),`$${ta.cost.toFixed(4)}`]]:[],...a?.contextWindow?[[E("session.context"),`${null!==a.percent?`${a.percent.toFixed(1)}%`:"?"} / ${(d=a.contextWindow)>=1e6?`${(d/1e6).toFixed(1)}M`:d>=1e3?`${(d/1e3).toFixed(0)}k`:String(d)}`]]:[],...ta.tokens.cacheRead+ta.tokens.cacheWrite>0&&ta.tokens.cacheRead+ta.tokens.cacheWrite+ta.tokens.input>0?[[E("session.cacheHitRate"),`${(ta.tokens.cacheRead/(ta.tokens.cacheRead+ta.tokens.cacheWrite+ta.tokens.input)*100).toFixed(1)}%`]]:[]],f=(e,t,n="left",i=!1)=>(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:e}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:i?"max-content max-content":"auto minmax(0, 1fr)",columnGap:i?14:12,rowGap:4,justifyContent:i?"start":void 0},children:t.map(([t,o])=>(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:t}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:i?"normal":"anywhere",textAlign:n,whiteSpace:"right"===n?"nowrap":"normal"},children:o})]},`${e}:${t}`))})]}),v=(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:E("session.infoSection")}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:t.map(e=>{var t,n;let i;return(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,r.jsx)("div",{children:e.copyField?(t=e.copyField,n=e.value,i=tC===t,(0,r.jsx)("button",{type:"button",title:i?E("session.copied"):E("file"===t?"session.copyFile":"session.copyId"),onClick:()=>tM(t,n),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:i?"var(--accent)":"var(--text-dim)",background:"transparent",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",flex:"0 0 auto",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=i?"var(--accent)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:i?(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})):null})]},`session-info:${e.label}`)})})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:$?"1fr":"minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)",gap:$?16:24,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[v,f(E("session.messages"),n),f(E("session.tokens"),[...s,...c],"right",!0)]})):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:E("session.load")})})]}),tp&&tg&&(0,r.jsxs)("div",{ref:tm,role:"menu","aria-label":E("todo.title"),style:{position:"fixed",top:tg.top,right:tg.right,width:300,maxHeight:"min(440px, calc(100dvh - 44px))",overflowY:"auto",zIndex:500,background:"color-mix(in srgb, var(--glass-bg-strong) 62%, transparent)",backdropFilter:"blur(12px) saturate(140%)",WebkitBackdropFilter:"blur(12px) saturate(140%)",border:"1px solid color-mix(in srgb, var(--border) 80%, transparent)",borderRadius:10,boxShadow:"0 10px 28px rgba(0,0,0,0.18)",fontFamily:"inherit"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"9px 12px",borderBottom:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",fontSize:12,fontWeight:650,color:"var(--text)"},children:[E("todo.title"),(0,r.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-dim)",fontWeight:500},children:[tc.filter(e=>"completed"===e.status).length,"/",tc.length," ",E("todo.completed")]})]}),0===tc.length?(0,r.jsx)("div",{style:{padding:"12px 14px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:E("todo.empty")}):(0,r.jsx)("div",{style:{maxHeight:330,overflowY:"auto"},children:tc.map(e=>{let t="completed"===e.status,n="high"===e.priority?"#ef4444":"medium"===e.priority?"rgba(234,179,8,0.9)":"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,padding:"7px 12px",borderBottom:"1px solid color-mix(in srgb, var(--border) 45%, transparent)"},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,marginTop:2,width:13,height:13,borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:800,lineHeight:1,color:t?"#fff":"transparent",background:t?"#16a34a":"color-mix(in srgb, var(--border) 70%, transparent)",border:t?"none":"1px solid color-mix(in srgb, var(--border) 80%, transparent)"},children:"✓"}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,lineHeight:1.4,color:t?"var(--text-dim)":"var(--text)",textDecoration:t?"line-through":"none",wordBreak:"break-word"},children:e.content}),(0,r.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,marginTop:5,width:7,height:7,borderRadius:"50%",background:n}})]},e.id??e.content)})})]})]}),$&&nz(!0)]}),(0,r.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:ny?(0,r.jsx)(nJ,{session:O,sessionRunning:!!(O&&_.has(O.id)),newSessionCwd:nm,newSessionDraftKey:nv,onAgentEnd:no,onAttentionNeeded:nl,onSessionCreated:nr,onSessionForked:nc,modelsRefreshKey:eu,chatInputRef:eZ,onBranchDataChange:e6,onSystemPromptChange:tl,onSystemPromptLoaderChange:ts,onSessionStatsChange:tw,onSessionStatsPanelOpen:tA,onTodosChange:tj,onContextUsageChange:tW,onOpenFile:ng,soundEnabled:P,onSoundToggle:F,playDoneSound:N,unlockAudio:A},eo):"validating"===Q?(0,r.jsxs)("div",{role:"status",style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,color:"var(--text-muted)",textAlign:"center"},children:[(0,r.jsx)("div",{style:{fontSize:14,color:"var(--text)"},children:E("workspace.opening")}),(0,r.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:k.requestedCwd})]}):"error"===Q?(0,r.jsxs)("div",{role:"alert",style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,color:"var(--text-muted)",textAlign:"center"},children:[(0,r.jsx)("div",{style:{fontSize:14,color:"#dc2626"},children:E("workspace.unable")}),(0,r.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:k.requestedCwd}),(0,r.jsx)("div",{style:{maxWidth:720,fontSize:12},children:et})]}):nS?t0?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:E("workspace.selectSession")}):(0,r.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,r.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,r.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,r.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:E("workspace.getStarted")}),(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),E("workspace.selectProject"),(0,r.jsx)("br",{}),(0,r.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),E("workspace.addModels")]})]})]}):null})]}),(0,r.jsx)("div",{"aria-hidden":"true",className:`right-panel-overlay-backdrop${eR?" is-open":""}`,onClick:()=>eM(!1)}),eR&&(0,r.jsx)("div",{...eK.separatorProps,"aria-controls":"file-panel",className:`panel-resize-handle right-panel-resize-handle${eK.isResizing?" is-resizing":""}`,"data-resize-handle":"right-panel",title:`${E("layout.resizeFilePanel")}: ${E("layout.resizeHint")}`}),(0,r.jsxs)("div",{ref:eK.panelRef,id:"file-panel",className:`right-panel-container${eR?" right-panel-open":" right-panel-closed"}${eK.isResizing?" right-panel-resizing":""}`,style:{"--right-panel-width":`${eK.width}px`,display:"flex",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,height:"calc(36px + env(safe-area-inset-top))",paddingTop:"env(safe-area-inset-top)",background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,r.jsx)(rg,{tabs:tU,activeTabId:tK??"",onSelectTab:tV,onCloseTab:nx})}),(0,r.jsx)("button",{type:"button",onClick:()=>eM(!1),"aria-controls":"file-panel","aria-expanded":eR,title:E("files.hidePanel"),"aria-label":E("files.hidePanel"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"var(--bg-selected)",border:"none",borderLeft:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text)"},children:(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),(0,r.jsx)("div",{style:{flex:1,overflow:"hidden",paddingBottom:"env(safe-area-inset-bottom)"},children:nT?.filePath?(0,r.jsx)(rp,{filePath:nT.filePath,cwd:t0??void 0,sourceSessionId:nT.sourceSessionId,gitRefreshKey:es,initialDisplayMode:nT.initialDisplayMode,initialState:nT.viewerState,watchEnabled:eR,onStateChange:e=>tY(nT.id,nT.viewerRevision??0,e),onMentionLines:eR?tX:void 0,onAtMention:tJ,onOpenFile:e=>nh(e,W(e),{sourceSessionId:nT.sourceSessionId})},`${nT.id}:${nT.viewerRevision??0}`):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:E("files.noneOpen")})})]})]}),ed&&(0,r.jsx)(ia,{onClose:()=>{ec(!1),ep(e=>e+1)}}),ey&&nj&&(0,r.jsx)(iz,{cwd:nj,busy:ek,error:ej,onCancel:()=>{ek||eb(!1)},onConfirm:()=>void nC()}),eh&&nj&&(0,r.jsx)(iv,{cwd:nj,onClose:()=>eg(!1)}),ex&&nj&&(0,r.jsx)(iE,{cwd:nj,sessionId:O?.id??null,onClose:()=>ef(!1),onReloaded:()=>el(e=>e+1)})]})}},39247:(e,t,n)=>{"use strict";n.d(t,{I18nProvider:()=>c,s:()=>u});var r=n(95155),i=n(12115);let o=new Map;function l(e){if(!e.id.trim())throw Error("Locale id must not be empty");if(o.has(e.id))throw Error(`Locale already registered: ${e.id}`);o.set(e.id,e)}function s(){return[...o.keys()]}l({id:"en",label:"English",messages:{"common.ok":"OK","common.language":"Language","common.models":"Models","common.skills":"Skills","common.plugins":"Plugins","appUpdate.releaseNotes":"Pi Web v{version} is available. View release notes","sidebar.hide":"Hide sidebar","sidebar.show":"Show sidebar","theme.light":"Light mode (click for dark)","theme.dark":"Dark mode (click for system)","theme.auto":"System theme (click for light)","history.full":"Full history","history.unsaved":"Full history is available after the session is saved","history.label":"Full history","title.generating":"Generating...","title.updated":"Title updated","title.failed":"Generation failed","title.generate":"Generate title","title.unsaved":"Title generation is available after the session is saved","title.noMessages":"Send a message before naming this session","title.generateSession":"Generate a session title","system.prompt":"System prompt","system.empty":"System prompt is empty (tools are disabled)","system.load":"System prompt has not loaded yet","system.loading":"Loading system prompt…","system.label":"System","session.info":"Session info","session.name":"Name","session.file":"File","session.inMemory":"In-memory","session.id":"ID","session.user":"User","session.assistant":"Assistant","session.toolCalls":"Tool Calls","session.toolResults":"Tool Results","session.total":"Total","session.input":"Input","session.output":"Output","session.cacheRead":"Cache Read","session.cacheWrite":"Cache Write","session.cost":"Cost","session.context":"Context","session.cacheHitRate":"Avg cache hit rate","session.copy":"Copy {value}","session.copied":"Copied","session.title":"Session info","session.load":"Send a message or run /session to load session info","session.infoSection":"Session Info","session.messages":"Messages","session.tokens":"Tokens","session.totalActive":"Active Time","session.copyFile":"Copy file path","session.copyId":"Copy session ID","workspace.opening":"Opening workspace...","workspace.unable":"Unable to open workspace","workspace.selectSession":"Select a session from the sidebar","workspace.getStarted":"Get Started","workspace.selectProject":"Select a project directory from the sidebar","workspace.addModels":"Add models via the Models button at the bottom","workspace.stepProject":"Select a project directory from the sidebar","workspace.stepModels":"Add models via the Models button at the bottom","files.hidePanel":"Hide file panel","files.showPanel":"Show file panel","files.noneOpen":"No file open","layout.resizeSidebar":"Resize sidebar","layout.resizeFilePanel":"Resize file panel","layout.resizeHint":"Drag to resize. Double-click or press Enter to reset.","sidebar.new":"New","sidebar.newSessionTitle":"New session in {path}","sidebar.refresh":"Refresh","sidebar.selectProject":"Select project…","sidebar.filterProjects":"Filter projects…","sidebar.noMatchingProjects":"No matching projects","sidebar.useDefaultDirectory":"Use default directory","sidebar.customPath":"Custom path…","directoryPicker.selectDirectory":"Select directory","directoryPicker.goToParent":"Go to parent directory","directoryPicker.directoryPath":"Directory path","directoryPicker.goToDirectory":"Go to directory","directoryPicker.go":"Go","directoryPicker.loadingDirectories":"Loading directories…","directoryPicker.noSubdirectories":"No subdirectories","directoryPicker.openBeforeSelecting":"Open this path before selecting it","directoryPicker.selectCurrentDirectory":"Select current directory","directoryPicker.selectThisFolder":"Select this folder","directoryPicker.noDrives":"No drives found","sidebar.checking":"Checking…","sidebar.open":"Open","sidebar.cancel":"Cancel","sidebar.openRepoRoot":"Open repo root","sidebar.openRepoRootTitle":"Open the repository root to manage worktrees.","sidebar.gitRepoRootOnly":"Git repo root only","sidebar.gitRepoRootOnlyTitle":"Worktrees are available in Git repository roots.","sidebar.worktrees":"Worktrees...","sidebar.checkingWorktrees":"Checking worktrees for this directory.","sidebar.filterWorktrees":"Filter worktrees…","sidebar.noMatchingWorktrees":"No matching worktrees","sidebar.switchWorktree":"Switch worktree","sidebar.switchWorktreeTitle":"Switch worktree: {path}","sidebar.main":"main","sidebar.forceRemoveCheckout":"Uncommitted changes. Force remove checkout?","sidebar.force":"Force","sidebar.createWorktreeTitle":"Create a worktree checkout for a branch","sidebar.newWorktree":"New worktree…","sidebar.branchName":"branch name","sidebar.creating":"Creating…","sidebar.create":"Create","sidebar.uploadFilesTitle":"Upload files to project root","sidebar.uploadFiles":"Upload files","sidebar.refreshExplorer":"Refresh explorer","sidebar.changedFiles":"{count} changed files","sidebar.loading":"Loading...","sidebar.noSessions":"No sessions found","sidebar.agentRunning":"Agent running…","sidebar.newActivity":"New activity","sidebar.newSessionActivity":"New session activity","sidebar.deleteSession":"Delete {title}?","sidebar.rename":"Rename","sidebar.delete":"Delete","sidebar.deleteWithShiftClick":"Delete (Shift+click to delete without confirmation)","sidebar.expandForks":"Expand forks","sidebar.collapseForks":"Collapse forks","sidebar.messagesCount":"{count} msgs","sidebar.worktreePath":"Worktree: {path}","sidebar.removeWorktreeTitle":"Remove worktree checkout {path}; the branch is kept","files.modified":"Modified","files.added":"Added","files.deleted":"Deleted","files.renamed":"Renamed","files.untracked":"Untracked","files.conflict":"Conflict","files.newlyUploaded":"Newly uploaded","files.containsChangedFiles":"Contains changed files","files.insertPath":"Insert path into chat","files.mention":"mention","files.download":"Download file","files.dismissError":"Dismiss error","files.addUploadedFile":"Add uploaded file to chat","files.addAllUploadedFiles":"Add all uploaded files to chat","files.dismissUploadResults":"Dismiss upload results","files.loading":"Loading files...","files.noFiles":"No files found","files.explorer":"Explorer","files.changedCount":"{count} files","files.changeStats":"{count} changed files, {additions} lines added, {deletions} lines deleted","files.conflictSummary":"{count} file{countSuffix} already exist: {files}","files.cannotReplace":"Cannot replace: {files}","files.replace":"Replace","files.skipExisting":"Skip existing","files.cancel":"Cancel","files.checking":"Checking files","files.uploading":"Uploading, {progress}%","chat.loadingSession":"Loading session...","chat.runningTool":"Running tool...","chat.generatingToolInput":"Generating parameters...","chat.runningNamedTool":"Running {name}...","chat.runningTools":"Running {names}...","chat.runningToolsMore":"Running {names} (+{count})...","chat.waitingModel":"Waiting for model...","chat.runningCommand":"Running command...","chat.thinking":"Thinking...","chat.processDetails":"Process details","chat.message":"message","chat.messages":"messages","chat.toolCall":"tool call","chat.toolCalls":"tool calls","chat.collapseProcess":"Collapse process details","chat.expandProcess":"Expand process details","chat.filesWritten":"Files changed","chat.openWrittenFile":"Open {name}","chat.loadEarlier":"Scroll up to load earlier messages ({count} hidden)","chat.extensionRequest":"extension request","chat.cancel":"Cancel","chat.confirm":"Confirm","chat.submit":"Submit","chat.extensionInput":"Extension terminal input","chat.extensionPanel":"Extension panel","chat.extensionWidgets":"Extension widgets","chat.extensionWidgetAbove":"Above editor widget","chat.extensionWidgetBelow":"Below editor widget","chat.extensionWidgetLine":"{count} line","chat.extensionWidgetLines":"{count} lines","chat.close":"Close","chat.queued":"Queued \xb7 {count}","chat.recall":"Recall to input","chat.recallTitle":"Remove all queued messages and put them back into the input box for editing","chat.retrying":"Retrying ({attempt}/{max})…","chat.loadingCommands":"Loading commands...","chat.slashCommands":"Slash commands \xb7 {label}","chat.tabEnter":"Tab / Enter","chat.noCommands":"No extension, prompt, or skill commands found","chat.match":"1 match","chat.matches":"{count} matches","chat.command":"1 command","chat.commands":"{count} commands","chat.loadingFiles":"Loading files...","chat.files":"Files \xb7 {label}{hint}","chat.searching":"Searching…","chat.noMatchingFiles":"No matching files","chat.searchingAll":" \xb7 searching all files…","chat.indexTruncated":" \xb7 index truncated","chat.steerPlaceholder":"Steer now / queue follow-up...","chat.agentPlaceholder":"Agent is running…","chat.messagePlaceholder":"Message… Type / for commands, @ for files","chat.steer":"Steer","chat.followUp":"Follow-up","chat.send":"Send","chat.attachImage":"Attach image","chat.previewImage":"Preview image","chat.filterModels":"Filter models…","chat.noMatchingModels":"No matching models","chat.moreControls":"More controls","chat.collapseControls":"Collapse controls","chat.shell":"Shell","chat.outputLocal":"output stays local","chat.outputModel":"output sent to model","chat.noTools":"No tools","chat.readOnlyTools":"{count} read-only built-in tools","chat.builtInTools":"{count} built-in tools","chat.allBuiltInTools":"All built-in tools","chat.changeReasoning":"Change reasoning level: {level}","chat.changeReasoningLabel":"Change reasoning level","chat.changeToolPreset":"Change tool preset","chat.stopCompaction":"Stop compaction","chat.compactContext":"Compact context","chat.compacting":"Compacting…","chat.compact":"Compact","chat.scrollToLatest":"Back to latest","bg.title":"Wallpaper","bg.choose":"Choose image…","bg.replace":"Replace image…","bg.remove":"Remove wallpaper","bg.hint":"The original file is stored locally in your browser — never re-encoded or uploaded.","chat.stopAgent":"Stop agent","chat.stop":"Stop","chat.disableSound":"Disable completion sound","chat.enableSound":"Enable completion sound","chat.thinkingUseDefault":"Use pi default","chat.thinkingOff":"Reasoning off","chat.thinkingMinimal":"Minimal reasoning","chat.thinkingLow":"Low reasoning","chat.thinkingMedium":"Medium reasoning","chat.thinkingHigh":"High reasoning","chat.thinkingXhigh":"Extra-high reasoning","chat.thinkingMax":"Max reasoning","chat.builtIn":"Built-in","chat.extensions":"Extensions","chat.prompts":"Prompts","chat.skills":"Skills","chat.dormant":"dormant","chat.commandCompact":"Compress context, optionally with instructions","chat.commandReload":"Reload extensions, skills, prompts, and tools","chat.commandName":"Set the session display name","chat.commandSession":"Show session message, token, and cost stats","chat.commandCopy":"Copy the last assistant message","chat.compacted":"Compacted","chat.tokensSaved":"{saved} saved","i18n.close":"Close","i18n.copy":"Copy","i18n.copied":"Copied","i18n.cancel":"Cancel","i18n.save":"Save","i18n.saving":"Saving…","i18n.saved":"Saved","i18n.remove":"Remove","i18n.removing":"Removing…","i18n.delete":"Delete","i18n.loading":"Loading...","i18n.search":"Search","i18n.refresh":"Refresh","i18n.update":"Update","i18n.updating":"Updating...","i18n.check":"Check","i18n.checking":"Checking...","i18n.install":"Install","i18n.installing":"Installing...","i18n.noResults":"No results","i18n.searchProviders":"Search providers…","i18n.noProviders":"No providers match","i18n.newModel":"new model","i18n.addProvider":"Add provider","i18n.selectProviderModel":"Select a provider or model","i18n.visibleInPrompt":"Visible in model prompt — click to disable","i18n.hiddenFromPrompt":"Hidden from model prompt — click to enable","i18n.dormant":"Dormant","i18n.hiddenButInvocable":"Hidden from model, still manually invocable","i18n.skillSearchPlaceholder":"e.g. react, testing, deploy","i18n.searching":"Searching…","i18n.noSkills":"No skills found","i18n.checkUpdates":"Check updates","i18n.updates":"updates","i18n.noResolvedResources":"No resolved resources","i18n.enablePackage":"Enable package","i18n.disablePackage":"Disable package","i18n.filtered":"filtered","i18n.openSessionToReload":"Open a session to reload","i18n.notFound":"Not found","i18n.noPlugins":"No plugins configured","trust.resourcesNotLoaded":"Restricted mode","trust.trustProject":"Trust project","trust.trusting":"Trusting...","trust.cancel":"Cancel","trust.dialogTitle":"Trust this project?","trust.dialogBody":"Project resources can run local code. Trust only projects whose contents you know.","trust.skillsNotLoaded":"Project skills are not loaded because this project is not trusted.","trust.pluginsNotLoaded":"Project plugins are not loaded because this project is not trusted.","trust.projectScopeUnavailable":"Project installs are unavailable while project resources are not loaded.","i18n.creatingSession":"Creating new session…","i18n.creating":"Creating…","i18n.subscription":"Subscription","i18n.subscriptions":"Subscriptions","i18n.customEndpoint":"Custom endpoint format","i18n.noChanges":"No changes","i18n.branches":"Branches","i18n.noActiveSession":"No active session","i18n.noBranches":"This session has no branches","i18n.source":"Source","i18n.preview":"Preview","i18n.diff":"Diff","i18n.downloadFile":"Download file","i18n.liveSync":"Live sync active","i18n.notWatching":"Not watching","i18n.fileViewMode":"File view mode","i18n.compareHead":"Compare working tree with HEAD","i18n.mentionSelectedLines":"Mention selected lines","i18n.disableWrap":"Disable word wrap","i18n.enableWrap":"Enable word wrap","i18n.htmlPreview":"HTML preview","i18n.previewFile":"Preview {file}","i18n.invalidMermaid":"Invalid Mermaid diagram","i18n.renderingMermaid":"Rendering Mermaid diagram","i18n.previewAfterStreaming":"Preview available after streaming","i18n.showMermaidSource":"Show Mermaid source","i18n.previewMermaid":"Preview Mermaid diagram","i18n.openMermaidViewer":"Open diagram viewer","i18n.mermaidViewer":"Mermaid diagram viewer","i18n.mermaidDiagram":"Mermaid diagram","i18n.zoomOut":"Zoom out","i18n.zoomIn":"Zoom in","i18n.fitToWidth":"Fit to width","models.discoveryFetching":"Importing models…","models.discoveryFetch":"Import models…","models.discoveryFilterPlaceholder":"Filter {count} models…","models.discoveryFilter":"Filter upstream models","models.discoverySelectShown":"Select shown","models.discoveryNoMatches":"No matching models.","models.discoveryAdded":"added","models.discoveryShowing":"Showing first {shown} of {total}","models.discoveryFetched":"{count} models fetched","models.discoveryAddSelected":"Add selected","models.discoveryAddSelectedCount":"Add selected ({count})","models.catalogSource":"source: models.dev ↗","models.catalogFilling":"Filling details…","models.catalogFill":"Fill model details","models.catalogFilled":"{count} fields filled","models.catalogNoEmptyFields":"No empty fields to fill","models.catalogNoExactMatch":"No exact models.dev match","models.catalogPriceProvider":"Price matched Provider {provider}","models.catalogPriceBaseUrl":"Price matched Base URL to {provider}","models.catalogPriceConsensus":"Price agreed by {support}/{total} records","models.catalogPriceUnreliable":"No reliable price found","models.catalogUndo":"Undo","models.capabilities":"Capabilities","models.reasoning":"Reasoning / thinking","models.imageInput":"Image input","models.modelSpecs":"Model specifications","models.contextWindow":"Context window (tokens)","models.maxOutputTokens":"Max output tokens","models.costPerMillion":"Cost per million tokens","models.costInput":"Input","models.costOutput":"Output","models.costCacheRead":"Cache read","models.costCacheWrite":"Cache write","models.notProvided":"Not provided","models.editCosts":"Edit prices","models.finishEditingCosts":"Done","models.costAllRequired":"Enter a valid non-negative price; blank fields are saved as 0.","models.advancedSettings":"Advanced settings","models.providerDefaults":"Using provider defaults","models.headersSummary":"Headers: {count}","models.compatSummary":"Compatibility: {count}","models.thinkingSummary":"Thinking levels: {count}","models.apiOverride":"API override","models.headers":"Headers","models.headersHelp":"Added to this model's requests and overrides provider headers.","models.compatibility":"Compatibility","models.deepSeekThinkingCompat":"DeepSeek thinking compatibility","models.developerRole":"Use the developer role for the system prompt","models.thinkingLevelMap":"Thinking level map","models.clearAll":"Clear all","i18n.testingModel":"Testing model connection...","i18n.connected":"Connected","i18n.failed":"Failed","i18n.test":"Test","i18n.testConnection":"Test model connection","i18n.provider":"Provider","i18n.model":"Model","i18n.providerName":"Provider name","i18n.rename":"Rename","i18n.default":"Default","i18n.disabled":"Disabled","i18n.noResources":"No resources","i18n.unknown":"Unknown","i18n.installedVersion":"installed {version}","i18n.configuredVersion":"configured {version}","i18n.extensions":"Extensions","i18n.prompts":"Prompts","i18n.themes":"Themes","i18n.resourceCount":"{count} {label}","i18n.extensionShort":"ext","i18n.skillShort":"skills","i18n.promptShort":"prompts","i18n.themeShort":"themes","i18n.custom":"Custom","i18n.clearAll":"clear all","i18n.connectedSuccessfully":"Connected successfully.","i18n.notConnected":"not connected","i18n.configured":"configured","i18n.notConfigured":"not configured","i18n.openingBrowser":"Opening browser…","i18n.submit":"Submit","i18n.login":"Login","i18n.relogin":"Re-login","i18n.disconnect":"Disconnect","i18n.networkError":"Network error","i18n.continuing":"Continuing…","i18n.skills":"Skills","i18n.plugins":"Plugins","i18n.addSkill":"Add skill","i18n.addPlugin":"Add plugin","i18n.selectSkill":"Select a skill","i18n.selectPackage":"Select a package","i18n.updateAvailable":"Update available","i18n.upToDate":"Up to date","i18n.automaticChecksUnavailable":"Automatic checks unavailable","i18n.checkFailed":"Check failed","i18n.installed":"Installed","i18n.status":"Status","i18n.version":"Version","i18n.package":"Package","i18n.resources":"Resources","i18n.installedPath":"Installed path","i18n.cwd":"CWD","i18n.resolvedResources":"Resolved Resources","i18n.reloadSession":"Reload session","i18n.reloading":"Reloading...","i18n.packageRemoved":"Package removed.","i18n.packageInstalled":"Package installed.","i18n.packageUpdated":"Package updated.","i18n.packageDisabled":"Package disabled.","i18n.packageEnabled":"Package enabled.","i18n.sessionReloaded":"Session reloaded.","i18n.thinking":"Thinking","i18n.largeMessageReveal":"Message content is very large ({size}). Click to view as plain text — markdown rendering is disabled to keep the page responsive.","i18n.loadingThinking":"Loading thinking...","i18n.copyMessage":"Copy message","i18n.editFromHere":"Edit from here","i18n.editFromHereTitle":"Edit from here — branches within this session","i18n.newSession":"New session","i18n.newSessionTitle":"New session — creates an independent copy from here","i18n.estimatedTokens":"Estimated token count while streaming","i18n.noOutput":"(no output)","i18n.noSummary":"(no summary)","i18n.conversationCompacted":"Conversation compacted","i18n.compactionDescription":"The conversation history before this point was compacted into the following summary:","i18n.fileContext":"File context: {details}","i18n.readFiles":"Read files","i18n.modifiedFiles":"Modified files","i18n.hiddenExtensionMessage":"hidden extension message","i18n.noMessage":"(no message)","i18n.showExtensionMessage":"Show extension message","i18n.collapse":"Collapse","i18n.expand":"Expand","i18n.hideDetails":"Hide details","i18n.showDetails":"Show details","i18n.thinkingUnavailable":"Thinking content unavailable","i18n.before":"Before","i18n.after":"After","i18n.sessionComplete":"Session complete","i18n.taskFinished":"Task finished.","i18n.attentionNeeded":"Pi needs your attention","i18n.extensionInputNeeded":"An extension is waiting for your input.","todo.title":"Tasks","todo.completed":"completed","todo.empty":"No active tasks. Ask the agent to add some!"}}),l({id:"zh-CN",label:"简体中文",messages:{"common.ok":"确定","common.language":"语言","common.models":"模型","common.skills":"技能","common.plugins":"插件","appUpdate.releaseNotes":"Pi Web v{version} 可用,查看更新说明","sidebar.hide":"隐藏侧边栏","sidebar.show":"显示侧边栏","theme.light":"浅色模式(点击切换到深色)","theme.dark":"深色模式(点击切换到跟随系统)","theme.auto":"跟随系统(点击切换到浅色)","history.full":"完整历史","history.unsaved":"会话保存后才能查看完整历史","history.label":"完整历史","title.generating":"正在生成...","title.updated":"标题已更新","title.failed":"生成失败","title.generate":"生成标题","title.unsaved":"会话保存后才能生成标题","title.noMessages":"请先发送消息,再为会话命名","title.generateSession":"生成会话标题","system.prompt":"系统提示词","system.empty":"系统提示词为空(工具已禁用)","system.load":"系统提示词尚未加载","system.loading":"正在加载系统提示词…","system.label":"系统","session.info":"会话信息","session.name":"名称","session.file":"文件","session.inMemory":"内存中","session.id":"ID","session.user":"用户","session.assistant":"助手","session.toolCalls":"工具调用","session.toolResults":"工具结果","session.total":"总计","session.input":"输入","session.output":"输出","session.cacheRead":"缓存读取","session.cacheWrite":"缓存写入","session.cost":"费用","session.context":"上下文","session.cacheHitRate":"平均缓存命中率","session.copy":"复制{value}","session.copied":"已复制","session.title":"会话信息","session.load":"发送消息或运行 /session 以加载会话信息","session.infoSection":"会话信息","session.messages":"消息","session.tokens":"Token","session.totalActive":"活跃时长","session.copyFile":"复制文件路径","session.copyId":"复制会话 ID","workspace.opening":"正在打开工作区...","workspace.unable":"无法打开工作区","workspace.selectSession":"从侧边栏选择一个会话","workspace.getStarted":"开始使用","workspace.selectProject":"从侧边栏选择项目目录","workspace.addModels":"点击底部的“模型”按钮添加模型","workspace.stepProject":"从侧边栏选择项目目录","workspace.stepModels":"点击底部的“模型”按钮添加模型","files.hidePanel":"隐藏文件面板","files.showPanel":"显示文件面板","files.noneOpen":"没有打开的文件","layout.resizeSidebar":"调整侧边栏宽度","layout.resizeFilePanel":"调整文件面板宽度","layout.resizeHint":"拖动调整宽度。双击或按 Enter 恢复默认值。","sidebar.new":"新建","sidebar.newSessionTitle":"在 {path} 中新建会话","sidebar.refresh":"刷新","sidebar.selectProject":"选择项目…","sidebar.filterProjects":"筛选项目…","sidebar.noMatchingProjects":"没有匹配的项目","sidebar.useDefaultDirectory":"使用默认目录","sidebar.customPath":"自定义路径…","directoryPicker.selectDirectory":"选择目录","directoryPicker.goToParent":"转到上级目录","directoryPicker.directoryPath":"目录路径","directoryPicker.goToDirectory":"转到目录","directoryPicker.go":"转到","directoryPicker.loadingDirectories":"正在加载目录…","directoryPicker.noSubdirectories":"没有子目录","directoryPicker.openBeforeSelecting":"选择前请先打开此路径","directoryPicker.selectCurrentDirectory":"选择当前目录","directoryPicker.selectThisFolder":"选择此文件夹","directoryPicker.noDrives":"未找到盘符","sidebar.checking":"检查中…","sidebar.open":"打开","sidebar.cancel":"取消","sidebar.openRepoRoot":"打开仓库根目录","sidebar.openRepoRootTitle":"打开仓库根目录以管理 worktree。","sidebar.gitRepoRootOnly":"仅 Git 仓库根目录","sidebar.gitRepoRootOnlyTitle":"只能在 Git 仓库根目录使用 worktree。","sidebar.worktrees":"Worktrees...","sidebar.checkingWorktrees":"正在检查此目录的 worktree。","sidebar.filterWorktrees":"筛选 worktree…","sidebar.noMatchingWorktrees":"没有匹配的 worktree","sidebar.switchWorktree":"切换 worktree","sidebar.switchWorktreeTitle":"切换 worktree:{path}","sidebar.main":"主分支","sidebar.forceRemoveCheckout":"存在未提交的更改。强制移除 checkout?","sidebar.force":"强制移除","sidebar.createWorktreeTitle":"为分支创建 worktree checkout","sidebar.newWorktree":"新建 worktree…","sidebar.branchName":"分支名称","sidebar.creating":"创建中…","sidebar.create":"创建","sidebar.uploadFilesTitle":"将文件上传到项目根目录","sidebar.uploadFiles":"上传文件","sidebar.refreshExplorer":"刷新文件浏览器","sidebar.changedFiles":"{count} 个变更文件","sidebar.loading":"加载中...","sidebar.noSessions":"未找到会话","sidebar.agentRunning":"Agent 运行中…","sidebar.newActivity":"有新活动","sidebar.newSessionActivity":"会话有新活动","sidebar.deleteSession":"删除 {title}?","sidebar.rename":"重命名","sidebar.delete":"删除","sidebar.deleteWithShiftClick":"删除(按住 Shift 点击可跳过确认)","sidebar.expandForks":"展开分叉","sidebar.collapseForks":"折叠分叉","sidebar.messagesCount":"{count} 条消息","sidebar.worktreePath":"Worktree:{path}","sidebar.removeWorktreeTitle":"移除 worktree checkout {path};保留分支","files.modified":"已修改","files.added":"已添加","files.deleted":"已删除","files.renamed":"已重命名","files.untracked":"未跟踪","files.conflict":"冲突","files.newlyUploaded":"刚上传","files.containsChangedFiles":"包含已更改文件","files.insertPath":"将路径插入聊天","files.mention":"提及","files.download":"下载文件","files.dismissError":"关闭错误","files.addUploadedFile":"将上传的文件添加到聊天","files.addAllUploadedFiles":"将所有上传的文件添加到聊天","files.dismissUploadResults":"关闭上传结果","files.loading":"正在加载文件...","files.noFiles":"未找到文件","files.explorer":"文件浏览器","files.changedCount":"{count} 个文件","files.changeStats":"{count} 个变更文件,新增 {additions} 行,删除 {deletions} 行","files.conflictSummary":"已有 {count} 个文件:{files}","files.cannotReplace":"无法替换:{files}","files.replace":"替换","files.skipExisting":"跳过已有文件","files.cancel":"取消","files.checking":"正在检查文件","files.uploading":"正在上传,{progress}%","chat.loadingSession":"正在加载会话...","chat.runningTool":"正在运行工具...","chat.generatingToolInput":"正在生成参数...","chat.runningNamedTool":"正在运行 {name}...","chat.runningTools":"正在运行 {names}...","chat.runningToolsMore":"正在运行 {names}(另有 {count} 个)...","chat.waitingModel":"正在等待模型...","chat.runningCommand":"正在运行命令...","chat.thinking":"正在思考...","chat.processDetails":"处理详情","chat.message":"条消息","chat.messages":"条消息","chat.toolCall":"次工具调用","chat.toolCalls":"次工具调用","chat.collapseProcess":"收起处理详情","chat.expandProcess":"展开处理详情","chat.filesWritten":"改动的文件","chat.openWrittenFile":"打开 {name}","chat.loadEarlier":"向上滚动以加载更早的消息(隐藏 {count} 条)","chat.extensionRequest":"扩展请求","chat.cancel":"取消","chat.confirm":"确认","chat.submit":"提交","chat.extensionInput":"扩展终端输入","chat.extensionPanel":"扩展面板","chat.extensionWidgets":"扩展组件","chat.extensionWidgetAbove":"输入框上方组件","chat.extensionWidgetBelow":"输入框下方组件","chat.extensionWidgetLine":"{count} 行","chat.extensionWidgetLines":"{count} 行","chat.close":"关闭","chat.queued":"已排队 \xb7 {count}","chat.recall":"移回输入框","chat.recallTitle":"移除所有排队消息并将其放回输入框编辑","chat.retrying":"正在重试({attempt}/{max})…","chat.loadingCommands":"正在加载命令...","chat.slashCommands":"斜杠命令 \xb7 {label}","chat.tabEnter":"Tab / Enter","chat.noCommands":"未找到扩展、提示词或技能命令","chat.match":"1 个匹配项","chat.matches":"{count} 个匹配项","chat.command":"1 个命令","chat.commands":"{count} 个命令","chat.loadingFiles":"正在加载文件...","chat.files":"文件 \xb7 {label}{hint}","chat.searching":"搜索中…","chat.noMatchingFiles":"未找到匹配的文件","chat.searchingAll":" \xb7 正在搜索所有文件…","chat.indexTruncated":" \xb7 索引不完整","chat.steerPlaceholder":"立即引导 / 排队后续消息...","chat.agentPlaceholder":"Agent 运行中…","chat.messagePlaceholder":"消息…输入 / 使用命令,输入 @ 查找文件","chat.steer":"引导","chat.followUp":"后续消息","chat.send":"发送","chat.attachImage":"附加图片","chat.previewImage":"预览图片","chat.filterModels":"筛选模型…","chat.noMatchingModels":"没有匹配的模型","chat.moreControls":"更多控件","chat.collapseControls":"收起控件","chat.shell":"Shell","chat.outputLocal":"输出保留在本地","chat.outputModel":"输出发送给模型","chat.noTools":"不使用工具","chat.readOnlyTools":"{count} 个只读内置工具","chat.builtInTools":"{count} 个内置工具","chat.allBuiltInTools":"全部内置工具","chat.changeReasoning":"更改推理级别:{level}","chat.changeReasoningLabel":"更改推理级别","chat.changeToolPreset":"更改工具预设","chat.stopCompaction":"停止压缩","chat.compactContext":"压缩上下文","chat.compacting":"正在压缩…","chat.compact":"压缩","chat.scrollToLatest":"回到底部","bg.title":"背景图","bg.choose":"选择图片…","bg.replace":"更换图片…","bg.remove":"移除背景图","bg.hint":"原图保存在浏览器本地,不重新编码、不上传。","chat.stopAgent":"停止 Agent","chat.stop":"停止","chat.disableSound":"关闭完成提示音","chat.enableSound":"开启完成提示音","chat.thinkingUseDefault":"使用 pi 默认设置","chat.thinkingOff":"关闭推理","chat.thinkingMinimal":"最低限度推理","chat.thinkingLow":"低强度推理","chat.thinkingMedium":"中等强度推理","chat.thinkingHigh":"高强度推理","chat.thinkingXhigh":"超高强度推理","chat.thinkingMax":"最高强度推理","chat.builtIn":"内置","chat.extensions":"扩展","chat.prompts":"提示词","chat.skills":"技能","chat.dormant":"休眠","chat.commandCompact":"压缩上下文,可选附加说明","chat.commandReload":"重新加载扩展、技能、提示词和工具","chat.commandName":"设置会话显示名称","chat.commandSession":"显示会话消息、Token 和费用统计","chat.commandCopy":"复制最后一条助手消息","chat.compacted":"已压缩","chat.tokensSaved":"节省 {saved}","i18n.close":"关闭","i18n.copy":"复制","i18n.copied":"已复制","i18n.cancel":"取消","i18n.save":"保存","i18n.saving":"保存中…","i18n.saved":"已保存","i18n.remove":"移除","i18n.removing":"移除中…","i18n.delete":"删除","i18n.loading":"加载中...","i18n.search":"搜索","i18n.refresh":"刷新","i18n.update":"更新","i18n.updating":"更新中...","i18n.check":"检查","i18n.checking":"检查中...","i18n.install":"安装","i18n.installing":"安装中...","i18n.noResults":"没有结果","i18n.searchProviders":"搜索 Provider…","i18n.noProviders":"没有匹配的 Provider","i18n.newModel":"新模型","i18n.addProvider":"添加 Provider","i18n.selectProviderModel":"选择 Provider 或模型","i18n.visibleInPrompt":"在模型提示词中可见,点击以禁用","i18n.hiddenFromPrompt":"在模型提示词中隐藏,点击以启用","i18n.dormant":"休眠","i18n.hiddenButInvocable":"对模型隐藏,仍可手动调用","i18n.skillSearchPlaceholder":"例如 react、testing、deploy","i18n.searching":"搜索中…","i18n.noSkills":"未找到技能","i18n.checkUpdates":"检查更新","i18n.updates":"项更新","i18n.noResolvedResources":"没有已解析资源","i18n.enablePackage":"启用包","i18n.disablePackage":"禁用包","i18n.filtered":"已筛选","i18n.openSessionToReload":"打开会话后才能重新加载","i18n.notFound":"未找到","i18n.noPlugins":"未配置插件","trust.resourcesNotLoaded":"受限模式","trust.trustProject":"信任项目","trust.trusting":"正在信任...","trust.cancel":"取消","trust.dialogTitle":"信任此项目?","trust.dialogBody":"项目资源可以运行本地代码。请仅信任你了解其内容的项目。","trust.skillsNotLoaded":"此项目尚未受信任,项目技能未加载。","trust.pluginsNotLoaded":"此项目尚未受信任,项目插件未加载。","trust.projectScopeUnavailable":"项目资源未加载时,无法安装到项目范围。","i18n.creatingSession":"正在创建新会话…","i18n.creating":"创建中…","i18n.subscription":"订阅","i18n.subscriptions":"订阅服务","i18n.customEndpoint":"自定义端点格式","i18n.noChanges":"没有更改","i18n.branches":"分支","i18n.noActiveSession":"没有活动会话","i18n.noBranches":"此会话没有分支","i18n.source":"源代码","i18n.preview":"预览","i18n.diff":"Diff","i18n.downloadFile":"下载文件","i18n.liveSync":"实时同步已启用","i18n.notWatching":"未监视","i18n.fileViewMode":"文件视图模式","i18n.compareHead":"比较工作区与 HEAD","i18n.mentionSelectedLines":"提及所选行","i18n.disableWrap":"禁用自动换行","i18n.enableWrap":"启用自动换行","i18n.htmlPreview":"HTML 预览","i18n.previewFile":"预览 {file}","i18n.invalidMermaid":"Mermaid 图表无效","i18n.renderingMermaid":"正在渲染 Mermaid 图表","i18n.previewAfterStreaming":"流式输出完成后可预览","i18n.showMermaidSource":"显示 Mermaid 源码","i18n.previewMermaid":"预览 Mermaid 图表","i18n.openMermaidViewer":"打开图表查看器","i18n.mermaidViewer":"Mermaid 图表查看器","i18n.mermaidDiagram":"Mermaid 图表","i18n.zoomOut":"缩小","i18n.zoomIn":"放大","i18n.fitToWidth":"适应宽度","models.discoveryFetching":"正在导入模型…","models.discoveryFetch":"导入模型…","models.discoveryFilterPlaceholder":"筛选 {count} 个模型…","models.discoveryFilter":"筛选上游模型","models.discoverySelectShown":"选择当前结果","models.discoveryNoMatches":"没有匹配的模型。","models.discoveryAdded":"已添加","models.discoveryShowing":"显示前 {shown} 个,共 {total} 个","models.discoveryFetched":"已获取 {count} 个模型","models.discoveryAddSelected":"添加所选模型","models.discoveryAddSelectedCount":"添加所选模型({count})","models.catalogSource":"来源:models.dev ↗","models.catalogFilling":"正在填入模型信息…","models.catalogFill":"填入模型信息","models.catalogFilled":"已填入 {count} 个字段","models.catalogNoEmptyFields":"没有需要填入的空字段","models.catalogNoExactMatch":"models.dev 中没有精确匹配","models.catalogPriceProvider":"价格已匹配 Provider {provider}","models.catalogPriceBaseUrl":"价格已按 Base URL 匹配 {provider}","models.catalogPriceConsensus":"价格得到 {support}/{total} 条记录支持","models.catalogPriceUnreliable":"未找到可靠价格","models.catalogUndo":"撤销","models.capabilities":"能力","models.reasoning":"推理 / 思考","models.imageInput":"图片输入","models.modelSpecs":"模型规格","models.contextWindow":"上下文窗口(tokens)","models.maxOutputTokens":"最大输出 tokens","models.costPerMillion":"每百万 tokens 价格","models.costInput":"输入","models.costOutput":"输出","models.costCacheRead":"缓存读取","models.costCacheWrite":"缓存写入","models.notProvided":"未提供","models.editCosts":"编辑价格","models.finishEditingCosts":"完成","models.costAllRequired":"请输入有效的非负价格;留空项将按 0 保存。","models.advancedSettings":"高级设置","models.providerDefaults":"沿用 Provider 默认设置","models.headersSummary":"Headers:{count}","models.compatSummary":"兼容性:{count}","models.thinkingSummary":"思考等级:{count}","models.apiOverride":"API 覆盖","models.headers":"Headers","models.headersHelp":"仅添加到该模型的请求中,并覆盖 Provider 的同名 Header。","models.compatibility":"兼容性","models.deepSeekThinkingCompat":"DeepSeek 思考兼容","models.developerRole":"使用 developer role 传递系统提示词","models.thinkingLevelMap":"思考等级映射","models.clearAll":"全部清除","i18n.testingModel":"正在测试模型连接...","i18n.connected":"已连接","i18n.failed":"失败","i18n.test":"测试","i18n.testConnection":"测试模型连接","i18n.provider":"Provider","i18n.model":"模型","i18n.providerName":"Provider 名称","i18n.rename":"重命名","i18n.default":"默认","i18n.disabled":"已禁用","i18n.noResources":"没有资源","i18n.unknown":"未知","i18n.installedVersion":"已安装 {version}","i18n.configuredVersion":"已配置 {version}","i18n.extensions":"扩展","i18n.prompts":"提示词","i18n.themes":"主题","i18n.resourceCount":"{count}{label}","i18n.extensionShort":"扩展","i18n.skillShort":"技能","i18n.promptShort":"提示词","i18n.themeShort":"主题","i18n.custom":"自定义","i18n.clearAll":"清除全部","i18n.connectedSuccessfully":"连接成功。","i18n.notConnected":"未连接","i18n.configured":"已配置","i18n.notConfigured":"未配置","i18n.openingBrowser":"正在打开浏览器…","i18n.submit":"提交","i18n.login":"登录","i18n.relogin":"重新登录","i18n.disconnect":"断开连接","i18n.networkError":"网络错误","i18n.continuing":"继续中…","i18n.skills":"技能","i18n.plugins":"插件","i18n.addSkill":"添加技能","i18n.addPlugin":"添加插件","i18n.selectSkill":"选择技能","i18n.selectPackage":"选择包","i18n.updateAvailable":"有可用更新","i18n.upToDate":"已是最新","i18n.automaticChecksUnavailable":"自动检查不可用","i18n.checkFailed":"检查失败","i18n.installed":"已安装","i18n.status":"状态","i18n.version":"版本","i18n.package":"包","i18n.resources":"资源","i18n.installedPath":"安装路径","i18n.cwd":"CWD","i18n.resolvedResources":"已解析资源","i18n.reloadSession":"重新加载会话","i18n.reloading":"重新加载中...","i18n.packageRemoved":"包已移除。","i18n.packageInstalled":"包已安装。","i18n.packageUpdated":"包已更新。","i18n.packageDisabled":"包已禁用。","i18n.packageEnabled":"包已启用。","i18n.sessionReloaded":"会话已重新加载。","i18n.thinking":"思考","i18n.largeMessageReveal":"消息内容过大({size})。点击以纯文本查看 — 已禁用 markdown 渲染以避免页面卡顿。","i18n.loadingThinking":"正在加载思考内容...","i18n.copyMessage":"复制消息","i18n.editFromHere":"从此处编辑","i18n.editFromHereTitle":"从此处编辑,此会话内创建分支","i18n.newSession":"新会话","i18n.newSessionTitle":"新会话,从此处创建独立副本","i18n.estimatedTokens":"流式输出期间的估算 Token 数","i18n.noOutput":"(无输出)","i18n.noSummary":"(无摘要)","i18n.conversationCompacted":"会话已压缩","i18n.compactionDescription":"此处之前的会话历史已压缩为以下摘要:","i18n.fileContext":"文件上下文:{details}","i18n.readFiles":"读取的文件","i18n.modifiedFiles":"修改的文件","i18n.hiddenExtensionMessage":"隐藏的扩展消息","i18n.noMessage":"(无消息)","i18n.showExtensionMessage":"显示扩展消息","i18n.collapse":"收起","i18n.expand":"展开","i18n.hideDetails":"隐藏详情","i18n.showDetails":"显示详情","i18n.thinkingUnavailable":"思考内容不可用","i18n.before":"之前","i18n.after":"之后","i18n.sessionComplete":"任务完成","i18n.taskFinished":"任务已完成。","i18n.attentionNeeded":"Pi 需要你的操作","i18n.extensionInputNeeded":"扩展正在等待你的输入。","todo.title":"任务","todo.completed":"已完成","todo.empty":"暂无任务,可以让 agent 添加。"}});let a="pi-locale",d=(0,i.createContext)(null);function c({children:e}){let[t,n]=(0,i.useState)("en"),[l,u]=(0,i.useState)(!1),p=(0,i.useMemo)(()=>s().map(e=>o.get(e)).filter(e=>!!e),[]),h=(0,i.useMemo)(()=>Object.fromEntries(s().flatMap(e=>{let t=o.get(e);return t?[[e,t.messages]]:[]})),[]);(0,i.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(a);if("en"===e||"zh-CN"===e)return e}catch{}for(let e of window.navigator.languages.length?window.navigator.languages:[window.navigator.language]){let t=e.toLowerCase();if("en"===t||t.startsWith("en-"))break;if("zh"===t||t.startsWith("zh-"))return"zh-CN"}return"en"}();n(e),document.documentElement.lang=e,u(!0)},[]);let g=(0,i.useCallback)(e=>{if(o.get(e)){n(e),document.documentElement.lang=e;try{window.localStorage.setItem(a,e)}catch{}}},[]),x=(0,i.useCallback)((e,n)=>(function(e,t,n,r={}){let i=n[e]?.[t]??n.en?.[t];return void 0===i?t:function(e,t={}){return e.replace(/\{([\w.-]+)\}/g,(e,n)=>{let r=t[n];return void 0===r?e:String(r)})}(i,r)})(t,e,h,n),[t,h]),f=(0,i.useMemo)(()=>({locale:l?t:"en",setLocale:g,t:x,supportedLocales:p}),[l,t,g,x,p]);return(0,r.jsx)(d.Provider,{value:f,children:e})}function u(){let e=(0,i.useContext)(d);if(!e)throw Error("useI18n must be used inside I18nProvider");return e}},67061:(e,t,n)=>{Promise.resolve().then(n.bind(n,27150)),Promise.resolve().then(n.bind(n,39247))},88576:e=>{e.exports={preview:"ChatMinimap_preview__laAya",turn:"ChatMinimap_turn__fZuce",number:"ChatMinimap_number__3C_cY",content:"ChatMinimap_content__C7_ju",user:"ChatMinimap_user__WHJHv",userText:"ChatMinimap_userText__Nj9jo",assistant:"ChatMinimap_assistant__s6JLb",assistantJump:"ChatMinimap_assistantJump__3CM2M",outline:"ChatMinimap_outline__aleIF",heading:"ChatMinimap_heading__djZbv",paragraph:"ChatMinimap_paragraph__EqWlO"}}},e=>{e.O(0,[7523,7330,3249,8441,3794,7358],()=>e(e.s=67061)),_N_E=e.O()}]);
|