@pananfly/pi-web 0.8.1
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 +46 -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 +138 -0
- package/.next/react-loadable-manifest.json +2367 -0
- package/.next/required-server-files.js +350 -0
- package/.next/required-server-files.json +350 -0
- package/.next/routes-manifest.json +348 -0
- package/.next/server/app/_global-error/page.js +32 -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 +16 -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 +5 -0
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +5 -0
- package/.next/server/app/_global-error.segments/_head.segment.rsc +5 -0
- package/.next/server/app/_global-error.segments/_index.segment.rsc +5 -0
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -0
- package/.next/server/app/_not-found/page.js +2 -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 +16 -0
- package/.next/server/app/_not-found.rsc +19 -0
- package/.next/server/app/_not-found.segments/_full.segment.rsc +19 -0
- package/.next/server/app/_not-found.segments/_head.segment.rsc +6 -0
- package/.next/server/app/_not-found.segments/_index.segment.rsc +6 -0
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +5 -0
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +5 -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/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/login/route.js +1 -0
- package/.next/server/app/api/auth/login/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/login/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/logout/route.js +1 -0
- package/.next/server/app/api/auth/logout/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/logout/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/auth/refresh/route.js +1 -0
- package/.next/server/app/api/auth/refresh/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/refresh/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/status/route.js +1 -0
- package/.next/server/app/api/auth/status/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/verify/route.js +1 -0
- package/.next/server/app/api/auth/verify/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/verify/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/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/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/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 +14 -0
- package/.next/server/app/index.rsc +18 -0
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +6 -0
- package/.next/server/app/index.segments/_full.segment.rsc +18 -0
- package/.next/server/app/index.segments/_head.segment.rsc +6 -0
- package/.next/server/app/index.segments/_index.segment.rsc +6 -0
- package/.next/server/app/index.segments/_tree.segment.rsc +5 -0
- package/.next/server/app/login/page.js +2 -0
- package/.next/server/app/login/page.js.nft.json +1 -0
- package/.next/server/app/login/page_client-reference-manifest.js +1 -0
- package/.next/server/app/login.html +1 -0
- package/.next/server/app/login.meta +15 -0
- package/.next/server/app/login.rsc +20 -0
- package/.next/server/app/login.segments/_full.segment.rsc +20 -0
- package/.next/server/app/login.segments/_head.segment.rsc +6 -0
- package/.next/server/app/login.segments/_index.segment.rsc +6 -0
- package/.next/server/app/login.segments/_tree.segment.rsc +5 -0
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +6 -0
- package/.next/server/app/login.segments/login.segment.rsc +5 -0
- package/.next/server/app/page.js +73 -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 +46 -0
- package/.next/server/chunks/1069.js +23 -0
- package/.next/server/chunks/1089.js +1 -0
- package/.next/server/chunks/1130.js +79 -0
- package/.next/server/chunks/1207.js +36 -0
- package/.next/server/chunks/1515.js +1 -0
- package/.next/server/chunks/1570.js +24 -0
- package/.next/server/chunks/1605.js +1 -0
- package/.next/server/chunks/1707.js +93 -0
- package/.next/server/chunks/1792.js +38 -0
- package/.next/server/chunks/1813.js +1 -0
- package/.next/server/chunks/2018.js +148 -0
- package/.next/server/chunks/2106.js +1 -0
- package/.next/server/chunks/2155.js +34 -0
- package/.next/server/chunks/2185.js +5 -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/2394.js +1 -0
- package/.next/server/chunks/2434.js +1 -0
- package/.next/server/chunks/2744.js +1 -0
- package/.next/server/chunks/2815.js +1 -0
- package/.next/server/chunks/2871.js +8 -0
- package/.next/server/chunks/2903.js +1 -0
- package/.next/server/chunks/319.js +45 -0
- package/.next/server/chunks/3252.js +115 -0
- package/.next/server/chunks/3379.js +1 -0
- package/.next/server/chunks/3770.js +1 -0
- package/.next/server/chunks/3894.js +1 -0
- package/.next/server/chunks/4030.js +86 -0
- package/.next/server/chunks/4286.js +1 -0
- package/.next/server/chunks/4309.js +1 -0
- package/.next/server/chunks/4338.js +64 -0
- package/.next/server/chunks/4367.js +1 -0
- package/.next/server/chunks/4372.js +1 -0
- package/.next/server/chunks/4424.js +215 -0
- package/.next/server/chunks/4485.js +1 -0
- package/.next/server/chunks/46.js +62 -0
- package/.next/server/chunks/4674.js +1 -0
- package/.next/server/chunks/4741.js +18 -0
- package/.next/server/chunks/4742.js +80 -0
- package/.next/server/chunks/4796.js +104 -0
- package/.next/server/chunks/4980.js +1 -0
- package/.next/server/chunks/5029.js +1 -0
- package/.next/server/chunks/5198.js +90 -0
- package/.next/server/chunks/5318.js +1 -0
- package/.next/server/chunks/5461.js +1 -0
- package/.next/server/chunks/5582.js +3 -0
- package/.next/server/chunks/5598.js +1 -0
- package/.next/server/chunks/5627.js +1 -0
- package/.next/server/chunks/6219.js +41 -0
- package/.next/server/chunks/6337.js +1 -0
- package/.next/server/chunks/6429.js +1 -0
- package/.next/server/chunks/6476.js +27 -0
- package/.next/server/chunks/6509.js +153 -0
- package/.next/server/chunks/6949.js +1 -0
- package/.next/server/chunks/6953.js +1 -0
- package/.next/server/chunks/703.js +1 -0
- package/.next/server/chunks/7152.js +1 -0
- package/.next/server/chunks/7181.js +160 -0
- package/.next/server/chunks/7233.js +1 -0
- package/.next/server/chunks/7307.js +1 -0
- package/.next/server/chunks/7434.js +77 -0
- package/.next/server/chunks/7561.js +1 -0
- package/.next/server/chunks/7872.js +1 -0
- package/.next/server/chunks/7914.js +226 -0
- package/.next/server/chunks/8267.js +24 -0
- package/.next/server/chunks/8294.js +1 -0
- package/.next/server/chunks/835.js +1 -0
- package/.next/server/chunks/8645.js +141 -0
- package/.next/server/chunks/9081.js +1 -0
- package/.next/server/chunks/9169.js +1 -0
- package/.next/server/chunks/9280.js +255 -0
- package/.next/server/chunks/940.js +287 -0
- package/.next/server/chunks/9486.js +1 -0
- package/.next/server/chunks/9509.js +1 -0
- package/.next/server/functions-config-manifest.json +15 -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 +18 -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 +1 -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/050357b0.986bc6597f184c3b.js +62 -0
- package/.next/static/chunks/1212.c32f02f461182c5b.js +226 -0
- package/.next/static/chunks/127.394be8b7a579a747.js +8 -0
- package/.next/static/chunks/1327.09252bb80616cc3a.js +1 -0
- package/.next/static/chunks/1377.e883e13864574c26.js +36 -0
- package/.next/static/chunks/1390.3e7d84d187924556.js +104 -0
- package/.next/static/chunks/1438.d742ea00e0f072ca.js +27 -0
- package/.next/static/chunks/1474.605367a77b6161a0.js +115 -0
- package/.next/static/chunks/1576.93e0666990c12243.js +38 -0
- package/.next/static/chunks/1951.4b73bf47740c2bfb.js +160 -0
- package/.next/static/chunks/2081.47b6e9391094055f.js +1 -0
- package/.next/static/chunks/2178.2adcd2b51553bd50.js +1 -0
- package/.next/static/chunks/2217.4bf1455eb89bdd9b.js +1 -0
- package/.next/static/chunks/2325.23caf22075e51aa5.js +1 -0
- package/.next/static/chunks/2356.52627097a8b56ec1.js +1 -0
- package/.next/static/chunks/2418.b5d9e177e10a686e.js +1 -0
- package/.next/static/chunks/249.973d23a3940a5fc9.js +1 -0
- package/.next/static/chunks/2554.ca4cb2f8bc69f32e.js +86 -0
- package/.next/static/chunks/2566.505384571dedf726.js +79 -0
- package/.next/static/chunks/2619.9aac8983f30c7c8a.js +1 -0
- package/.next/static/chunks/2646.c653cac657d7b035.js +215 -0
- package/.next/static/chunks/2784.3d8e0d20edb71dcd.js +64 -0
- package/.next/static/chunks/2821.934bcf60fbdc28c6.js +1 -0
- package/.next/static/chunks/2847.b66f6d92e4f5e495.js +23 -0
- package/.next/static/chunks/2866.4ecb766127917d99.js +1 -0
- package/.next/static/chunks/28f0fb3b.5f2b0099c24fbe32.js +122 -0
- package/.next/static/chunks/3308.29d4f7078e26a916.js +73 -0
- package/.next/static/chunks/3316.5c51b238308a838b.js +34 -0
- package/.next/static/chunks/3341.6042c7cb7225d88d.js +41 -0
- package/.next/static/chunks/339.1a094bb1c6eaf9dc.js +1 -0
- package/.next/static/chunks/370.57cfa27da8567918.js +1 -0
- package/.next/static/chunks/3708.81252290870c8487.js +1 -0
- package/.next/static/chunks/3794-e569667691edc8f7.js +32 -0
- package/.next/static/chunks/3832.5d713641634c65b5.js +24 -0
- package/.next/static/chunks/4368.e43e952c5535cba6.js +80 -0
- package/.next/static/chunks/4424.fd0c93a807a333e1.js +1 -0
- package/.next/static/chunks/4866.d1060b4faf2ae1e2.js +1 -0
- package/.next/static/chunks/4bd1b696-e356ca5ba0218e27.js +1 -0
- package/.next/static/chunks/5020.9ac8d0dc8390bb6e.js +1 -0
- package/.next/static/chunks/5166.7d3648847337fe52.js +62 -0
- package/.next/static/chunks/5242.7b643c6b3394cac1.js +1 -0
- package/.next/static/chunks/5361.afc00ab2626bacbf.js +1 -0
- package/.next/static/chunks/5460.0337c14f29b9ff9a.js +90 -0
- package/.next/static/chunks/5521.cfdf2cfc6db31407.js +1 -0
- package/.next/static/chunks/5715.048f1bae2c41fa89.js +1 -0
- package/.next/static/chunks/6121.5b8cb3199531d194.js +1 -0
- package/.next/static/chunks/6294.24f510c0c3e3714c.js +1 -0
- package/.next/static/chunks/6467.b354ed428e3bef01.js +5 -0
- package/.next/static/chunks/66d203d7.3e90bc8f1f096a8e.js +153 -0
- package/.next/static/chunks/6787.a15de946178e8ef7.js +1 -0
- package/.next/static/chunks/7176.2979806e91c0df29.js +1 -0
- package/.next/static/chunks/7256.e07cf52d87d40252.js +1 -0
- package/.next/static/chunks/7543.89f7b805ed0f2901.js +1 -0
- package/.next/static/chunks/776.fe8e64ab3669a915.js +287 -0
- package/.next/static/chunks/8118.f905a690db2b859b.js +148 -0
- package/.next/static/chunks/8233.a465d18b04719c6d.js +141 -0
- package/.next/static/chunks/8249.7a48897e80a16391.js +1 -0
- package/.next/static/chunks/8311-95813758da2b283c.js +1 -0
- package/.next/static/chunks/8365.dc22e1ff76d04a3b.js +93 -0
- package/.next/static/chunks/8498.1083c36ddbbedd69.js +1 -0
- package/.next/static/chunks/8511.c7c064a8f58f1355.js +1 -0
- package/.next/static/chunks/869.7152372b662e31af.js +1 -0
- package/.next/static/chunks/8782.9ab86081b5661687.js +77 -0
- package/.next/static/chunks/8863.fa0320ea586efb3b.js +1 -0
- package/.next/static/chunks/8953.e5e7399c7952a1ff.js +1 -0
- package/.next/static/chunks/90542734.b75ad0df50bf68f5.js +1 -0
- package/.next/static/chunks/9165.02dc1f4804b94791.js +24 -0
- package/.next/static/chunks/934.9006461bd0548660.js +1 -0
- package/.next/static/chunks/9522.c7c6e9c330f9ba6b.js +1 -0
- package/.next/static/chunks/9667.c6d6228dd3c4861b.js +1 -0
- package/.next/static/chunks/9705.40a82b97f214e28b.js +1 -0
- package/.next/static/chunks/9793.4567af813117ad25.js +1 -0
- package/.next/static/chunks/app/_global-error/page-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/_not-found/page-3ea40c1a91b0cd39.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/bash-output/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/events/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/agent/new/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/agent/running/events/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/all-providers/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/api-key/[provider]/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/login/[provider]/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/login/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/logout/[provider]/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/logout/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/providers/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/refresh/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/status/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/auth/verify/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/cwd/validate/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/default-cwd/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/file-index/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/files/[...path]/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/git/diff/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/git/status/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/home/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/models/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/models-config/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/models-config/test/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/plugins/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/auto-name/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/context/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/entries/[entryId]/thinking/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/export/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/state/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/sessions/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/skills/check/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/skills/install/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/skills/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/skills/search/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/skills/update/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/api/worktrees/route-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/app/layout-fc0dbec63c654527.js +1 -0
- package/.next/static/chunks/app/login/page-c7d96da038297463.js +1 -0
- package/.next/static/chunks/app/page-883e877df3335b30.js +72 -0
- package/.next/static/chunks/d2c09beb.4f5ff7197b5bbbea.js +1 -0
- package/.next/static/chunks/d3ac728e-7964f816a1ca64e5.js +1 -0
- package/.next/static/chunks/da12927c.00775c0e4542fd3e.js +82 -0
- package/.next/static/chunks/framework-711ef29bc66f648c.js +1 -0
- package/.next/static/chunks/main-app-6d3ca1bd083597b7.js +1 -0
- package/.next/static/chunks/main-b70eb01cb9d3de17.js +5 -0
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/global-error-129b03c25e777d59.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-6270af0206ac74b6.js +1 -0
- package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/.next/static/chunks/webpack-bbd44e4ff13f4c9b.js +1 -0
- package/.next/static/css/88714c00e109ce28.css +1 -0
- package/.next/static/css/afdadd5192f321e7.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/rNxNXXmbOkkvQk0-VdhVR/_buildManifest.js +1 -0
- package/.next/static/rNxNXXmbOkkvQk0-VdhVR/_ssgManifest.js +1 -0
- package/.next/trace +6 -0
- package/.next/trace-build +1 -0
- package/.next/types/app/api/agent/[id]/bash-output/route.ts +351 -0
- package/.next/types/app/api/agent/[id]/events/route.ts +351 -0
- package/.next/types/app/api/agent/[id]/route.ts +351 -0
- package/.next/types/app/api/agent/new/route.ts +351 -0
- package/.next/types/app/api/agent/running/events/route.ts +351 -0
- package/.next/types/app/api/auth/all-providers/route.ts +351 -0
- package/.next/types/app/api/auth/api-key/[provider]/route.ts +351 -0
- package/.next/types/app/api/auth/login/[provider]/route.ts +351 -0
- package/.next/types/app/api/auth/login/route.ts +351 -0
- package/.next/types/app/api/auth/logout/[provider]/route.ts +351 -0
- package/.next/types/app/api/auth/logout/route.ts +351 -0
- package/.next/types/app/api/auth/providers/route.ts +351 -0
- package/.next/types/app/api/auth/refresh/route.ts +351 -0
- package/.next/types/app/api/auth/status/route.ts +351 -0
- package/.next/types/app/api/auth/verify/route.ts +351 -0
- package/.next/types/app/api/cwd/validate/route.ts +351 -0
- package/.next/types/app/api/default-cwd/route.ts +351 -0
- package/.next/types/app/api/file-index/route.ts +351 -0
- package/.next/types/app/api/files/[...path]/route.ts +351 -0
- package/.next/types/app/api/git/diff/route.ts +351 -0
- package/.next/types/app/api/git/status/route.ts +351 -0
- package/.next/types/app/api/home/route.ts +351 -0
- package/.next/types/app/api/models/route.ts +351 -0
- package/.next/types/app/api/models-config/route.ts +351 -0
- package/.next/types/app/api/models-config/test/route.ts +351 -0
- package/.next/types/app/api/plugins/route.ts +351 -0
- package/.next/types/app/api/sessions/[id]/auto-name/route.ts +351 -0
- package/.next/types/app/api/sessions/[id]/context/route.ts +351 -0
- package/.next/types/app/api/sessions/[id]/entries/[entryId]/thinking/route.ts +351 -0
- package/.next/types/app/api/sessions/[id]/export/route.ts +351 -0
- package/.next/types/app/api/sessions/[id]/route.ts +351 -0
- package/.next/types/app/api/sessions/[id]/state/route.ts +351 -0
- package/.next/types/app/api/sessions/route.ts +351 -0
- package/.next/types/app/api/skills/check/route.ts +351 -0
- package/.next/types/app/api/skills/install/route.ts +351 -0
- package/.next/types/app/api/skills/route.ts +351 -0
- package/.next/types/app/api/skills/search/route.ts +351 -0
- package/.next/types/app/api/skills/update/route.ts +351 -0
- package/.next/types/app/api/worktrees/route.ts +351 -0
- package/.next/types/app/layout.ts +87 -0
- package/.next/types/app/login/page.ts +87 -0
- package/.next/types/app/page.ts +87 -0
- package/.next/types/cache-life.d.ts +145 -0
- package/.next/types/package.json +1 -0
- package/.next/types/routes.d.ts +112 -0
- package/.next/types/validator.ts +430 -0
- package/LICENSE +21 -0
- package/README.md +140 -0
- package/README.zh-CN.md +136 -0
- package/bin/pi-web-options.js +45 -0
- package/bin/pi-web.js +343 -0
- package/lib/auth-cli.js +115 -0
- package/next.config.ts +37 -0
- package/package.json +79 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{14755:(e,t,r)=>{"use strict";r.d(t,{getPresetFromTools:()=>s,xG:()=>a});let n=[],o=["read","bash","edit","write"],i=["bash","read","edit","write","grep","find","ls"],l=new Set(i);function s(e){let t=e.filter(e=>e.active);if(0===t.length)return"none";let r=t.map(e=>e.name).filter(e=>l.has(e)).sort().join(",");return r===[...o].sort().join(",")?"default":r===[...i].sort().join(",")?"full":"default"}function a(e){return"none"===e?[...n]:"full"===e?[...i]:[...o]}},18588:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>nA});var n=r(95155),o=r(12115),i=r(73321);let l=null,s="var(--text-dim)";function a({size:e=14,open:t=!1}){return t?(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5h7.5v1H1V4.5Z",fill:s}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:s,strokeWidth:"1",fill:s,fillOpacity:"0.12"})]}):(0,n.jsx)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:s,strokeWidth:"1",fill:s,fillOpacity:"0.1"})})}function d({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:s,strokeWidth:"1",fill:s,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:s,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function c({label:e,size:t=14}){let r=t/14;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:s,strokeWidth:"0.9",fill:s,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:s,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("text",{x:"7",y:"9.5",textAnchor:"middle",fontSize:3.4*r,fontFamily:"var(--font-mono), monospace",fontWeight:"600",fill:s,letterSpacing:"0",children:e})]})}function u({size:e=14}){return(0,n.jsx)(c,{label:"TS",size:e})}function p({size:e=14}){return(0,n.jsx)(c,{label:"TSX",size:e})}function h({size:e=14}){return(0,n.jsx)(c,{label:"JS",size:e})}function x({size:e=14}){return(0,n.jsx)(c,{label:"JSX",size:e})}function g({size:e=14}){return(0,n.jsx)(c,{label:"PY",size:e})}function f({size:e=14}){return(0,n.jsx)(c,{label:"{}",size:e})}function m({size:e=14}){return(0,n.jsx)(c,{label:"CSS",size:e})}function v({size:e=14}){return(0,n.jsx)(c,{label:"SC",size:e})}function y({size:e=14}){return(0,n.jsx)(c,{label:"HTM",size:e})}function b({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:s,strokeWidth:"0.9",fill:s,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:s,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:s,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:s,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function k({size:e=14}){return(0,n.jsx)(c,{label:"YML",size:e})}function j({size:e=14}){return(0,n.jsx)(c,{label:"TOM",size:e})}function w({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:s,strokeWidth:"0.9",fill:s,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:s,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:s,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:s,strokeWidth:"0.95",strokeLinecap:"round"})]})}function S({size:e=14}){return(0,n.jsx)(c,{label:"RS",size:e})}function C({size:e=14}){return(0,n.jsx)(c,{label:"GO",size:e})}function T({size:e=14}){return(0,n.jsx)(c,{label:"SQL",size:e})}function I({size:e=14}){return(0,n.jsx)(c,{label:"GQL",size:e})}function L({size:e=14}){return(0,n.jsx)(c,{label:"TF",size:e})}function R({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:s,strokeWidth:"0.9",fill:s,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:s,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("rect",{x:"3.5",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:s,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:s,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:s,strokeWidth:"0.8"})]})}function z({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:s,strokeWidth:"0.9",fill:s,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:s,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:s,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:s,strokeWidth:"0.9",strokeLinecap:"round"})]})}function M({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:s,strokeWidth:"0.9",fill:s,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:s,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:s,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:s,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:s,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:s,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:s,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function W({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:s,strokeWidth:"0.9",fill:s,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:s,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("rect",{x:"4.5",y:"8.5",width:"5",height:"3",rx:"0.6",stroke:s,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:s,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function E({size:e=14}){return(0,n.jsx)(c,{label:"DOC",size:e})}function $({size:e=14}){return(0,n.jsx)(c,{label:"PDF",size:e})}function B({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:s,strokeWidth:"0.9",fill:s,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:s,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:s,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 6.5v.7M7 10.3v.7M5 8.5h.7M8.3 8.5H9M5.5 6.9l.5.5M8.5 9.6l-.5-.5M5.5 10.1l.5-.5M8.5 7.4l-.5.5",stroke:s,strokeWidth:"0.8",strokeLinecap:"round"})]})}function A(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(R,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(z,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(M,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(W,{size:t});if(r.endsWith(".config.ts")||r.endsWith(".config.js")||r.endsWith(".config.mjs")||r.endsWith(".config.cjs")||[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(r))return(0,n.jsx)(B,{size:t});switch(o){case"ts":return(0,n.jsx)(u,{size:t});case"tsx":return(0,n.jsx)(p,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(h,{size:t});case"jsx":return(0,n.jsx)(x,{size:t});case"py":return(0,n.jsx)(g,{size:t});case"json":case"jsonl":return(0,n.jsx)(f,{size:t});case"css":case"less":return(0,n.jsx)(m,{size:t});case"scss":return(0,n.jsx)(v,{size:t});case"html":case"htm":return(0,n.jsx)(y,{size:t});case"md":case"mdx":return(0,n.jsx)(b,{size:t});case"yaml":case"yml":return(0,n.jsx)(k,{size:t});case"toml":return(0,n.jsx)(j,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(w,{size:t});case"rs":return(0,n.jsx)(S,{size:t});case"go":return(0,n.jsx)(C,{size:t});case"sql":return(0,n.jsx)(T,{size:t});case"graphql":case"gql":return(0,n.jsx)(I,{size:t});case"tf":case"hcl":return(0,n.jsx)(L,{size:t});case"docx":return(0,n.jsx)(E,{size:t});case"pdf":return(0,n.jsx)($,{size:t});case"lock":return(0,n.jsx)(W,{size:t});default:return(0,n.jsx)(d,{size:t})}}function D(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function P(e){return D(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function N(e){let t=D(e).replace(/\/+$/,"");return t.split("/").pop()??t}function F(e){let t=D(e).replace(/\/+$/,""),r=t.lastIndexOf("/");return r<0?"":0===r?"/":2===r&&/^[a-zA-Z]:\//.test(t)?t.slice(0,3):t.slice(0,r)}function O(e,t){if(!t)return e;let r=D(e),n=D(t).replace(/\/$/,"");return r.startsWith(n+"/")?r.slice(n.length+1):e}function H(e,t){return`${D(e).replace(/\/$/,"")}/${t}`}async function U(e){let t=P(e),r=await fetch(`/api/files/${t}?type=list`);if(!r.ok){let e=`Failed to load files (HTTP ${r.status})`;try{let t=await r.json();t.error&&(e=t.error)}catch{}throw Error(e)}return((await r.json()).entries??[]).map(t=>({name:t.name,fullPath:H(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function _(e){let t=new URLSearchParams({cwd:e}),r=await fetch(`/api/git/status?${t.toString()}`);if(!r.ok)throw Error(`Failed to load Git status (HTTP ${r.status})`);return r.json()}let q={modified:"Modified",added:"Added",deleted:"Deleted",renamed:"Renamed",untracked:"Untracked",conflict:"Conflict"},K={modified:"#d6a84b",added:"#4ade80",deleted:"#f87171",renamed:"#60a5fa",untracked:"#4ade80",conflict:"#f87171"};function V({size:e=11}){return(0,n.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,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function J({onClick:e,title:t}){return(0,n.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,n.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,n.jsx)("path",{d:"m6 6 12 12"}),(0,n.jsx)("path",{d:"m18 6-12 12"})]})})}function Y({node:e,depth:t,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:s,onToggleExpanded:d,refreshToken:c,highlightedPaths:u,gitStatusByPath:p,changedDirectoryPaths:h}){let x=s.has(e.fullPath),g=u.has(e.fullPath),f=D(e.fullPath),m=p.get(f),v=e.isDir&&(void 0!==m||h.has(f)),[y,b]=(0,o.useState)(e.children??[]),[k,j]=(0,o.useState)(e.loaded??!1),[w,S]=(0,o.useState)(!1),[C,T]=(0,o.useState)(!1),I=(0,o.useCallback)(async(t=!1)=>{if(!k||t){S(!0);try{let t=await U(e.fullPath);b(t),j(!0)}catch{}finally{S(!1)}}},[k,e.fullPath]);(0,o.useEffect)(()=>{x&&k&&I(!0)},[c]);let L=(0,o.useCallback)(()=>{if(e.isDir){let t=!x;d(e.fullPath,t),t&&!k&&I()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,k,x,I,i,d]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:L,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:C?"var(--bg-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[e.isDir&&(0,n.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:x?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(a,{size:14,open:x}):A(e.name,14)}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),g&&(0,n.jsx)("span",{title:"Newly uploaded","aria-label":"Newly uploaded",style:{width:6,height:6,flexShrink:0,borderRadius:"50%",background:"#3b82f6"}}),!C&&!e.isDir&&m&&(0,n.jsx)("span",{title:q[m.status],"aria-label":q[m.status],style:{width:14,flexShrink:0,color:K[m.status],fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600,textAlign:"center"},children:m.code}),!C&&v&&(0,n.jsx)("span",{title:"Contains changed files","aria-label":"Contains changed files",style:{width:6,height:6,flexShrink:0,borderRadius:"50%",background:"#d6a84b"}}),w&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),l&&C&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l(O(e.fullPath,r),e.isDir)},title:"Insert path into chat",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,n.jsx)(V,{}),"mention"]}),C&&!e.isDir&&(0,n.jsx)("a",{href:`/api/files/${P(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:"Download file",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,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),e.isDir&&x&&(0,n.jsxs)("div",{children:[y.map(e=>(0,n.jsx)(Y,{node:e,depth:t+1,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:s,onToggleExpanded:d,refreshToken:c,highlightedPaths:u,gitStatusByPath:p,changedDirectoryPaths:h},e.fullPath)),0===y.length&&k&&(0,n.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}let Z=(0,o.forwardRef)(function({cwd:e,onOpenFile:t,refreshKey:r,onAtMention:i,onAtMentions:l,onUploadBusyChange:s},a){let[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(!0),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(new Set),[m,v]=(0,o.useState)(0),[y,b]=(0,o.useState)(new Set),[k,j]=(0,o.useState)([]),[w,S]=(0,o.useState)("idle"),[C,T]=(0,o.useState)(0),[I,L]=(0,o.useState)(null),[R,z]=(0,o.useState)(null),[M,W]=(0,o.useState)(null),E=(0,o.useRef)(null),$=(0,o.useRef)(null),B=`${r??0}:${m}`,A="idle"!==w,N=(0,o.useMemo)(()=>new Map(k.map(e=>[D(e.filePath),e])),[k]),q=(0,o.useMemo)(()=>{let t=new Set,r=D(e).replace(/\/$/,"");for(let e of k){let n=F(D(e.filePath));for(;(n===r||n.startsWith(`${r}/`))&&(t.add(n),n!==r);){let e=F(n);if(e===n)break;n=e}}return t},[e,k]),K=(0,o.useCallback)((e,t)=>{f(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]),Z=(0,o.useCallback)(t=>{let r=t.uploaded??[];z({uploaded:r,skipped:t.skipped??[],errors:t.errors??[]}),r.length>0&&(b(new Set(r.map(t=>H(e,t)))),v(e=>e+1))},[e]),G=(0,o.useCallback)(async(t,r)=>{W(null),L(null),T(0),S("uploading");try{let{status:n,data:o}=await new Promise((n,o)=>{let i=new FormData;t.forEach(e=>i.append("files",e,e.name));let l=new XMLHttpRequest;l.open("POST",`/api/files/${P(e)}?type=upload&conflict=${r}`),l.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&T(Math.round(e.loaded/e.total*100))},l.onerror=()=>o(Error("Network error while uploading files")),l.onabort=()=>o(Error("Upload cancelled")),l.onload=()=>{let e={};try{e=JSON.parse(l.responseText)}catch{l.responseText&&(e.error=l.responseText)}n({status:l.status,data:e})},l.send(i)});if(409===n&&o.conflicts?.length)return void W({files:t,conflicts:o.conflicts,nonReplaceable:o.nonReplaceable??[]});if(n<200||n>=300)throw Error(o.error??`Upload failed (HTTP ${n})`);T(100),Z(o)}catch(e){L(e instanceof Error?e.message:String(e))}finally{S("idle")}},[Z,e]),X=(0,o.useCallback)(async t=>{if(0!==t.length&&!A){z(null),b(new Set),W(null),L(null),T(0),S("checking");try{let r=await fetch(`/api/files/${P(e)}?type=upload-check`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileNames:t.map(e=>e.name)})}),n=await r.json().catch(()=>({}));if(!r.ok)throw Error(n.error??`Upload check failed (HTTP ${r.status})`);if(n.conflicts?.length)return void W({files:t,conflicts:n.conflicts,nonReplaceable:n.nonReplaceable??[]});await G(t,"error")}catch(e){L(e instanceof Error?e.message:String(e))}finally{S("idle")}}},[e,G,A]),Q=(0,o.useCallback)(e=>{let t=Array.from(e.target.files??[]);e.target.value="",X(t)},[X]);(0,o.useImperativeHandle)(a,()=>({openUploadPicker(){A||$.current?.click()}}),[A]),(0,o.useEffect)(()=>{s?.(A)},[s,A]),(0,o.useEffect)(()=>()=>s?.(!1),[s]),(0,o.useEffect)(()=>{let t=E.current!==e;E.current=e,t&&(f(new Set),b(new Set),z(null),W(null),L(null)),p(t),x(null);let r=!1;return U(e).then(e=>{r||c(e)}).catch(e=>{r||x(e instanceof Error?e.message:String(e))}).finally(()=>{r||p(!1)}),()=>{r=!0}},[e,r,m]),(0,o.useEffect)(()=>{let t=!1;return _(e).then(e=>{t||j(e.isGitRepository?e.files:[])}).catch(()=>{t||j([])}),()=>{t=!0}},[e,r,m]);let ee=A||null!==M||null!==I||null!==R,et=(0,o.useCallback)(()=>{R&&0!==R.uploaded.length&&l?.(R.uploaded.map(t=>O(H(e,t),e)))},[e,l,R]);return(0,n.jsxs)("div",{style:{minHeight:"100%"},children:[(0,n.jsx)("input",{ref:$,type:"file",multiple:!0,hidden:!0,onChange:Q}),ee&&(0,n.jsxs)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:[A&&(0,n.jsxs)("div",{role:"status","aria-live":"polite","aria-label":"checking"===w?"Checking files":`Uploading, ${C}%`,children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,minHeight:14,color:"var(--text-muted)"},children:["checking"===w?(0,n.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,n.jsx)("path",{d:"M21 12a9 9 0 1 1-5.7-8.4"})}):(0,n.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,n.jsx)("path",{d:"M12 16V4"}),(0,n.jsx)("path",{d:"m7 9 5-5 5 5"}),(0,n.jsx)("path",{d:"M5 20h14"})]}),"uploading"===w&&(0,n.jsxs)("span",{style:{fontSize:10},children:[C,"%"]})]}),"uploading"===w&&(0,n.jsx)("div",{style:{height:3,marginTop:4,overflow:"hidden",borderRadius:2,background:"var(--border)"},children:(0,n.jsx)("div",{style:{width:`${C}%`,height:"100%",background:"var(--text-muted)",transition:"width 120ms ease"}})})]}),M&&(0,n.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,n.jsxs)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:1.35,overflowWrap:"anywhere"},children:[M.conflicts.length," file",1===M.conflicts.length?"":"s"," already exist: ",M.conflicts.join(", ")]}),M.nonReplaceable.length>0&&(0,n.jsxs)("div",{style:{marginTop:3,fontSize:10,color:"#f59e0b",lineHeight:1.35,overflowWrap:"anywhere"},children:["Cannot replace: ",M.nonReplaceable.join(", ")]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,marginTop:7},children:[(0,n.jsx)("button",{type:"button",onClick:()=>void G(M.files,"overwrite"),style:{height:22,padding:"0 7px",border:"1px solid #ef4444",borderRadius:4,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:10},children:"Replace"}),(0,n.jsx)("button",{type:"button",onClick:()=>void G(M.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:"Skip existing"}),(0,n.jsx)("button",{type:"button",onClick:()=>W(null),style:{height:22,padding:"0 7px",border:"none",borderRadius:4,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:10},children:"Cancel"})]})]}),I&&(0,n.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:11,lineHeight:1.35,color:"#f87171"},children:[(0,n.jsx)("span",{style:{minWidth:0,flex:1,overflowWrap:"anywhere"},children:I}),(0,n.jsx)(J,{onClick:()=>L(null),title:"Dismiss error"})]}),R&&(0,n.jsxs)("div",{"aria-live":"polite",children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minHeight:22,fontSize:11},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1,display:"flex",alignItems:"center",gap:8},children:[R.uploaded.length>0&&(0,n.jsxs)("span",{title:`${R.uploaded.length} uploaded`,"aria-label":`${R.uploaded.length} uploaded`,style:{display:"flex",alignItems:"center",gap:3,color:"#22c55e"},children:[(0,n.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,n.jsx)("path",{d:"m5 12 4 4L19 6"})}),(0,n.jsx)("span",{children:R.uploaded.length})]}),R.skipped.length>0&&(0,n.jsxs)("span",{title:`${R.skipped.length} skipped`,"aria-label":`${R.skipped.length} skipped`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--text-dim)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M8 12h8"})]}),(0,n.jsx)("span",{children:R.skipped.length})]}),R.errors.length>0&&(0,n.jsxs)("span",{title:`${R.errors.length} failed`,"aria-label":`${R.errors.length} failed`,style:{display:"flex",alignItems:"center",gap:3,color:"#f87171"},children:[(0,n.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,n.jsx)("path",{d:"M12 3 2.5 20h19L12 3Z"}),(0,n.jsx)("path",{d:"M12 9v4"}),(0,n.jsx)("path",{d:"M12 17h.01"})]}),(0,n.jsx)("span",{children:R.errors.length})]})]}),R.uploaded.length>0&&l&&(0,n.jsxs)("button",{type:"button",onClick:et,title:1===R.uploaded.length?"Add uploaded file to chat":"Add all uploaded files to chat","aria-label":1===R.uploaded.length?"Add uploaded file to chat":"Add all uploaded files to chat",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,n.jsx)(V,{}),"mention"]}),(0,n.jsx)(J,{onClick:()=>z(null),title:"Dismiss upload results"})]}),R.errors.map(e=>(0,n.jsxs)("div",{title:e.error,style:{display:"flex",alignItems:"center",gap:4,marginTop:3,minWidth:0,fontSize:10,color:"#f87171"},children:[(0,n.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,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M12 8v5"}),(0,n.jsx)("path",{d:"M12 17h.01"})]}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.name))]})]}),(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[u?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}):h?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:h}):d.map(r=>(0,n.jsx)(Y,{node:r,depth:0,cwd:e,onOpenFile:t,onAtMention:i,expandedPaths:g,onToggleExpanded:K,refreshToken:B,highlightedPaths:y,gitStatusByPath:N,changedDirectoryPaths:q},r.fullPath)),!u&&!h&&0===d.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"No files found"})]})]})}),G="pi-web:unread-session-ids";function X(e){let t=new Map;for(let r of e){let e=r.projectRoot??r.cwd;if(!e)continue;let n=t.get(e);(!n||r.modified>n)&&t.set(e,r.modified)}return[...t.entries()].sort((e,t)=>t[1].localeCompare(e[1])).map(([e])=>e)}function Q(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function ee({text:e,style:t}){return(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",minWidth:0,lineHeight:1.35,direction:"rtl",textAlign:"left",...t},children:(0,n.jsx)("span",{style:{unicodeBidi:"plaintext"},children:e})})}function et({open:e,children:t,style:r}){let[i,l]=(0,o.useState)(e),[s,a]=(0,o.useState)(e);return((0,o.useEffect)(()=>{let t,r;return e?(l(!0),a(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>a(!0))})):(a(!1),r=setTimeout(()=>l(!1),140)),()=>{void 0!==t&&window.cancelAnimationFrame(t),r&&clearTimeout(r)}},[e]),i)?(0,n.jsx)("div",{style:{...r,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 er="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function en(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:er[Math.floor(Math.random()*er.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"0.8.1p0.81.1":"Pi Web",r),a=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.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 eo({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,skipInitialProjectSelection:l,onInitialRestoreDone:s,refreshKey:a,onSessionDeleted:d,selectedCwd:c,onCwdChange:u,onOpenFile:p,explorerRefreshKey:h,onExplorerRefresh:x,onAtMention:g,onAtMentions:f}){let[m,v]=(0,o.useState)([]),[y,b]=(0,o.useState)(!0),[k,j]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[C,T]=(0,o.useState)(""),[I,L]=(0,o.useState)(!1),[R,z]=(0,o.useState)(""),[M,W]=(0,o.useState)(!1),[E,$]=(0,o.useState)(""),[B,A]=(0,o.useState)(null),[D,P]=(0,o.useState)(!1),N=(0,o.useRef)(null),F=(0,o.useRef)(null),[O,H]=(0,o.useState)(null),[U,_]=(0,o.useState)(!1),[q,K]=(0,o.useState)(!1),[V,J]=(0,o.useState)(""),[Y,er]=(0,o.useState)(null),[el,es]=(0,o.useState)(!1),[ea,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(null),ep=(0,o.useRef)(null),eh=(0,o.useRef)(null),[ex,eg]=(0,o.useState)(!0),[ef,em]=(0,o.useState)(0),[ev,ey]=(0,o.useState)(!1),[eb,ek]=(0,o.useState)(!1),[ej,ew]=(0,o.useState)(!1),[eS,eC]=(0,o.useState)(()=>new Set),[eT,eI]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(G);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}})()),eL=(0,o.useRef)(new Set),eR=(0,o.useRef)(!1),ez=(0,o.useRef)(null),eM=(0,o.useRef)(null),eW=(0,o.useRef)(null),eE=(0,o.useCallback)(async(e=!1)=>{try{e&&b(!0);let t=await fetch("/api/sessions");if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();v(r.sessions),eR.current||eC(new Set(r.runningSessionIds??[]));let n=new Set(r.sessions.map(e=>e.id));eI(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>n.has(e)));return t.size===e.size?e:t}),j(null),e||(ek(!0),ez.current&&clearTimeout(ez.current),ez.current=setTimeout(()=>ek(!1),2e3))}catch(e){j(String(e))}finally{e&&b(!1)}},[]),e$=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!e$.current;e$.current=!0,eE(e)},[eE,a]),(0,o.useEffect)(()=>{try{0===eT.size?window.localStorage.removeItem(G):window.localStorage.setItem(G,JSON.stringify([...eT]))}catch{}},[eT]),(0,o.useEffect)(()=>{let e=new EventSource("/api/agent/running/events");return e.onmessage=e=>{try{let t=JSON.parse(e.data);"running"===t.type&&(eR.current=!0,eC(new Set(t.runningSessionIds??[])))}catch{}},()=>e.close()},[]),(0,o.useEffect)(()=>{let t=[...eL.current].filter(t=>!eS.has(t)&&t!==e),r=[...eS];(t.length>0||r.length>0)&&eI(e=>{let n=new Set(e);return r.forEach(e=>n.delete(e)),t.forEach(e=>n.add(e)),n}),eL.current=eS},[eS,e]),(0,o.useEffect)(()=>{e&&eI(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),r})},[e]),(0,o.useEffect)(()=>{void 0!==h&&em(e=>e+1)},[h]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&T(e.home)}).catch(()=>{})},[]);let eB=(0,o.useRef)(!1),eA=(0,o.useCallback)(e=>{if(!e)return null;if(O&&O.forCwd===e||O?.worktrees.some(t=>t.path===e))return O.projectRoot;let t=m.find(t=>t.cwd===e);return t?.projectRoot??e},[O,m]),eD=(0,o.useRef)(null);(0,o.useEffect)(()=>{eD.current!==w&&(eD.current=w,u?.(w,eA(w)))},[w,u,eA]);let eP=(0,o.useRef)(null);(0,o.useEffect)(()=>{c&&c!==eP.current&&(eP.current=c,S(c))},[c]);let[eN,eF]=(0,o.useState)(0);(0,o.useLayoutEffect)(()=>{if(!w){H(null),eu(null);return}let e=!1;return eu(w),fetch(`/api/worktrees?cwd=${encodeURIComponent(w)}`).then(e=>e.json()).then(t=>{if(!e){if(eu(null),t.error||!t.projectRoot)return void H(null);H({forCwd:w,projectRoot:t.projectRoot,isGit:t.isGit??!1,isTopLevel:t.isTopLevel??!1,worktrees:t.worktrees??[]})}}).catch(()=>{e||(eu(null),H(null))}),()=>{e=!0}},[w,eN,a]),(0,o.useEffect)(()=>{if(0!==m.length&&!l&&null===w){if(i&&!eB.current){eB.current=!0;let e=m.find(e=>e.id===i);if(e){S(e.cwd),t(e,!0);return}s?.()}let e=X(m);e.length>0&&S(e[0])}},[m,w,i,l,t,s]);let eO=(0,o.useCallback)(async e=>{let t=(e??E).trim();if(t&&!D){P(!0),A(null);try{let e=await fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t})}),r=await e.json().catch(()=>({}));if(!e.ok||r.error)return void A(r.error??`HTTP ${e.status}`);S(r.cwd??t),W(!1),$(""),L(!1)}catch(e){A(e instanceof Error?e.message:String(e))}finally{P(!1)}}},[E,D]),eH=(0,o.useCallback)(async()=>{let e=window.piDesktop;if(!e){W(!0),A(null),setTimeout(()=>N.current?.focus(),0);return}try{A(null);let t=await e.selectDirectory();if(null===t)return;$(t),W(!0),await eO(t)}catch(e){W(!0),A(e instanceof Error?e.message:String(e)),setTimeout(()=>N.current?.focus(),0)}},[eO]),eU=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(S(t.cwd),W(!1),$(""),A(null),L(!1))}catch{}},[]),e_=(0,o.useCallback)(async()=>{let e=V.trim();if(e&&!el&&O){es(!0),er(null);try{let t=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:O.projectRoot,branch:e})}),r=await t.json().catch(()=>({}));if(!t.ok||r.error||!r.path)return void er(r.error??`HTTP ${t.status}`);K(!1),J(""),_(!1),H(t=>t?{...t,forCwd:r.path,worktrees:[...t.worktrees,{path:r.path,branch:e,isMain:!1}]}:t),S(r.path),eF(e=>e+1)}catch(e){er(e instanceof Error?e.message:String(e))}finally{es(!1)}}},[V,el,O]),eq=(0,o.useCallback)(async(e,t)=>{if(O&&!el){es(!0),er(null);try{let r=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:O.projectRoot,path:e,force:t})}),n=await r.json().catch(()=>({}));if(!r.ok){if(n.dirty&&!t)return void ed(e);er(n.error??`HTTP ${r.status}`);return}ed(null),w===e&&S(O.projectRoot),eF(e=>e+1)}catch(e){er(e instanceof Error?e.message:String(e))}finally{es(!1)}}},[O,el,w]);(0,o.useEffect)(()=>{let e=e=>{F.current&&!F.current.contains(e.target)&&(L(!1),z(""),W(!1),$(""),A(null)),ep.current&&!ep.current.contains(e.target)&&(_(!1),K(!1),J(""),er(null),ed(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let eK=(0,o.useCallback)(e=>{e.cwd&&S(e.cwd),t(e)},[t]),eV=(0,o.useCallback)(()=>{if(!w)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)}`;r?.(e,w)},[w,r]),eJ=X(m),eY=eJ.length>8,eZ=R.trim()?eJ.filter(e=>e.toLowerCase().includes(R.trim().toLowerCase())):eJ,eG=eA(w),eX=eG?m.filter(e=>(e.projectRoot??e.cwd)===eG):m,eQ=!!(O?.isGit&&O.isTopLevel&&w&&eG===O.projectRoot),e0=w&&O&&eG===O.projectRoot&&!eQ?O.isGit?{label:"Open repo root",title:"Open the repository root to manage worktrees."}:{label:"Git repo root only",title:"Worktrees are available in Git repository roots."}:null,e1=!!(w&&ec===w),e2=e0??(e1&&!eQ?{label:"Worktrees...",title:"Checking worktrees for this directory."}:null),e4=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>o(e.children))};return o(n),n}(eX);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10},children:[(0,n.jsx)(en,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)("button",{onClick:eV,disabled:!w,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:w?"var(--text-muted)":"var(--text-dim)",cursor:w?"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:w?`New session in ${w}`:"Select a project first",onMouseEnter:e=>{w&&(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=w?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New"]}),(0,n.jsx)("button",{onClick:()=>eE(!1),style:{display:"flex",alignItems:"center",justifyContent:"center",background:eb?"rgba(74,222,128,0.18)":"var(--bg-hover)",border:`1px solid ${eb?"rgba(74,222,128,0.4)":"var(--border)"}`,color:eb?"#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=>{eb||(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=>{eb||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)")},title:"Refresh",children:eb?(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]})})]})]}),(0,n.jsxs)("div",{ref:F,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>L(e=>!e),title:eG??w??"",style:{width:"100%",display:"flex",alignItems:"center",padding:"6px 10px",background:w?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:w?"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:w?(0,n.jsx)(ee,{text:Q(eG??w,C),style:{flex:1,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text)"}}):(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:i&&!eB.current?"":"Select project…"})}),(0,n.jsxs)(et,{open:I,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:[eY&&(0,n.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,n.jsx)("input",{value:R,onChange:e=>z(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(z(""),L(!1))},placeholder:"Filter projects…",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,n.jsxs)("div",{style:{maxHeight:"min(50vh, 380px)",overflowY:"auto"},children:[eZ.map(e=>(0,n.jsxs)("button",{onClick:()=>{S(e),z(""),W(!1),$(""),A(null),L(!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===eG?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:[e===eG&&(0,n.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,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}),e!==eG&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)(ee,{text:Q(e,C),style:{flex:1}})]},e)),0===eZ.length&&R.trim()&&(0,n.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:"No matching projects"})]}),!M&&(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),eU()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eZ.length>0?"1px solid var(--border)":"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.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,n.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,n.jsx)("span",{children:"Use default directory"})]}),M?(0,n.jsxs)("div",{style:{padding:"6px 8px",borderTop:eZ.length>0?"none":void 0},children:[(0,n.jsx)("input",{ref:N,value:E,onChange:e=>{$(e.target.value),A(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),eO()),"Escape"===e.key&&(W(!1),$(""),A(null))},placeholder:"/path/to/project",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"}}),B&&(0,n.jsx)("div",{style:{marginTop:5,color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:B}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,n.jsx)("button",{onClick:()=>void eO(),disabled:D||!E.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:D||!E.trim()?"not-allowed":"pointer",opacity:D||!E.trim()?.65:1},children:D?"Checking…":"Open"}),(0,n.jsx)("button",{onClick:()=>{W(!1),$(""),A(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:"Cancel"})]})]}):(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),eH()},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,n.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,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,n.jsx)("span",{children:"Custom path…"})]})]})]}),eQ&&(()=>{if(!O)return null;let e=O.worktrees.find(e=>e.path===w)??O.worktrees.find(e=>e.isMain);return(0,n.jsxs)("div",{ref:ep,style:{position:"relative",marginTop:6},children:[(0,n.jsxs)("button",{onClick:()=>_(e=>!e),title:e?`Switch worktree: ${e.path}`:"Switch worktree",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,n.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:e&&!e.isMain?"var(--accent)":"var(--text-dim)"},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsx)(ee,{text:e?e.branch??Q(e.path,C):"…",style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)"}}),e?.isMain&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:"main"}),O.worktrees.length>1&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:O.worktrees.length}),(0,n.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,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),(0,n.jsxs)(et,{open:U,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:[(0,n.jsx)("div",{style:{maxHeight:"min(40vh, 300px)",overflowY:"auto"},children:O.worktrees.map(e=>{let t=e.path===w||e.isMain&&!O.worktrees.some(e=>e.path===w);return ea===e.path?(0,n.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,n.jsx)("span",{style:{flex:1,fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Uncommitted changes. Force remove checkout?"}),(0,n.jsx)("button",{onClick:()=>void eq(e.path,!0),disabled:el,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:"Force"}),(0,n.jsx)("button",{onClick:()=>ed(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:"Cancel"})]},e.path):(0,n.jsxs)("div",{className:"wt-row",style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{onClick:()=>{S(e.path),_(!1),er(null)},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,n.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,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)(ee,{text:e.branch??Q(e.path,C),style:{flex:1}}),e.isMain&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:"main"})]}),!e.isMain&&(0,n.jsx)("button",{onClick:()=>void eq(e.path,!1),disabled:el,title:`Remove worktree checkout ${e.path}; the branch is kept`,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,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]},e.path)})}),q?(0,n.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,n.jsx)("input",{ref:eh,value:V,onChange:e=>{J(e.target.value),er(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e_()),"Escape"===e.key&&(K(!1),J(""),er(null))},placeholder:"branch name",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,n.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,n.jsx)("button",{onClick:()=>void e_(),disabled:el||!V.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:el||!V.trim()?"not-allowed":"pointer",opacity:el||!V.trim()?.65:1},children:el?"Creating…":"Create"}),(0,n.jsx)("button",{onClick:()=>{K(!1),J(""),er(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:"Cancel"})]})]}):(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),K(!0),er(null),setTimeout(()=>eh.current?.focus(),0)},title:"Create a worktree checkout for a branch",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,n.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,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,n.jsx)("span",{children:"New worktree…"})]}),Y&&(0,n.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:Y})]})]})})(),e2&&(0,n.jsxs)("button",{type:"button","aria-disabled":"true",tabIndex:-1,title:e2.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,n.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,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:e2.label})]})]}),(0,n.jsxs)("div",{style:{flex:ex&&(c||w)?"1 1 0":"1 1 auto",overflowY:"auto",padding:"0",minHeight:80},children:[y&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),k&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:k}),!y&&!k&&0===eX.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"No sessions found"}),e4.map(t=>(0,n.jsx)(ei,{node:t,selectedSessionId:e,runningSessionIds:eS,unreadSessionIds:eT,onSelectSession:eK,onRenamed:eE,onSessionDeleted:e=>{d?.(e),eE()},depth:0},t.session.id))]}),(c||w)&&(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:ex?"1 1 0":"0 0 auto",minHeight:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0},children:[(0,n.jsxs)("button",{onClick:()=>eg(e=>!e),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,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:ex?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"Explorer"]}),ex&&(0,n.jsx)("button",{onClick:()=>eW.current?.openUploadPicker(),disabled:ev,title:"Upload files to project root","aria-label":"Upload files",style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,background:"none",border:"none",color:"var(--text-dim)",cursor:ev?"default":"pointer",borderRadius:5,flexShrink:0,opacity:ev?.6:1,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{ev||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{ev||(e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none")},children:(0,n.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,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("path",{d:"m17 8-5-5-5 5"}),(0,n.jsx)("path",{d:"M12 3v12"})]})}),(0,n.jsx)("button",{onClick:()=>{x?x():em(e=>e+1),ew(!0),eM.current&&clearTimeout(eM.current),eM.current=setTimeout(()=>ew(!1),2e3)},title:"Refresh explorer",style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:6,background:ej?"rgba(74,222,128,0.18)":"none",border:"none",color:ej?"#4ade80":"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{ej||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{ej||(e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none")},children:ej?(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]})})]}),ex&&(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",overflowX:"hidden"},children:(0,n.jsx)(Z,{ref:eW,cwd:w??c,onOpenFile:p??(()=>{}),refreshKey:ef,onAtMention:g,onAtMentions:f,onUploadBusyChange:ey})})]})]})}function ei({node:e,selectedSessionId:t,runningSessionIds:r,unreadSessionIds:i,onSelectSession:l,onRenamed:s,onSessionDeleted:a,depth:d}){let[c,u]=(0,o.useState)(!1),p=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[d>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*d+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(ea,{session:e.session,isSelected:e.session.id===t,isRunning:r.has(e.session.id),isUnread:i.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,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(ei,{node:e,selectedSessionId:t,runningSessionIds:r,unreadSessionIds:i,onSelectSession:l,onRenamed:s,onSessionDeleted:a,depth:d+1},e.session.id))})]})}function el(){return(0,n.jsx)("span",{title:"Agent running…","aria-label":"Agent running",style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})})})}function es(){return(0,n.jsx)("span",{title:"New activity","aria-label":"New session activity",style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#0891b2"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",style:{display:"block"},children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"2.5",fill:"currentColor"}),(0,n.jsxs)("circle",{cx:"7",cy:"7",r:"3",stroke:"currentColor",strokeWidth:"1.4",opacity:"0.32",children:[(0,n.jsx)("animate",{attributeName:"r",values:"3;6;3",dur:"1.6s",repeatCount:"indefinite"}),(0,n.jsx)("animate",{attributeName:"opacity",values:"0.32;0;0.32",dur:"1.6s",repeatCount:"indefinite"})]})]})})}function ea({session:e,isSelected:t,isRunning:r,isUnread:i,onClick:l,onRenamed:s,onDeleted:a,depth:d=0,hasChildren:c=!1,collapsed:u=!1,onToggleCollapse:p}){let h,x,g,f,m,[v,y]=(0,o.useState)(!1),[b,k]=(0,o.useState)(!1),[j,w]=(0,o.useState)(""),[S,C]=(0,o.useState)(!1),[T,I]=(0,o.useState)(!1),L=(0,o.useRef)(null),R=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),z=(0,o.useCallback)(t=>{t.stopPropagation(),w(e.name??""),k(!0),setTimeout(()=>L.current?.select(),0)},[e.name]),M=(0,o.useCallback)(async()=>{let t=j.trim();if(k(!1),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{}},[j,e.id,e.name,s]),W=(0,o.useCallback)(e=>{e.stopPropagation(),C(!0)},[]),E=(0,o.useCallback)(async t=>{t.stopPropagation(),C(!1),I(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),a?.(e.id)}catch{I(!1)}},[e.id,a]),$=(0,o.useCallback)(e=>{e.stopPropagation(),C(!1)},[]);return(0,n.jsx)("div",{onClick:S||b?void 0:l,onMouseEnter:()=>y(!0),onMouseLeave:()=>{y(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:d>0?12*d+14:14,paddingRight:8,cursor:S||b?"default":"pointer",background:S?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":v?"var(--bg-hover)":"transparent",borderLeft:S?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:T?.5:1,gap:6,overflow:"hidden"},children:S?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",R.slice(0,22),R.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:E,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,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:$,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:"Cancel"})]})]}):b?(0,n.jsx)("input",{ref:L,value:j,onChange:e=>w(e.target.value),onBlur:M,onKeyDown:e=>{"Enter"===e.key&&M(),"Escape"===e.key&&k(!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,n.jsxs)(n.Fragment,{children:[d>0&&(0,n.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,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:5,minWidth:0,fontSize:12,fontWeight:t?500:400,lineHeight:1.4,color:"var(--text)"},title:R,children:(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:R})}),(0,n.jsxs)("div",{style:{marginTop:2,display:"flex",alignItems:"center",gap:8,color:"var(--text-dim)",fontSize:11,minWidth:0},children:[r?(0,n.jsx)(el,{}):i?(0,n.jsx)(es,{}):(0,n.jsx)("span",{title:e.modified,children:(h=new Date(e.modified),g=Math.floor((x=new Date().getTime()-h.getTime())/6e4),f=Math.floor(x/36e5),m=Math.floor(x/864e5),g<1?"just now":g<60?`${g}m ago`:f<24?`${f}h ago`:m<7?`${m}d ago`:h.toLocaleDateString())}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),e.worktreeBranch&&(0,n.jsxs)("span",{title:`Worktree: ${e.cwd}`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--accent)",minWidth:0,overflow:"hidden"},children:[(0,n.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,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.worktreeBranch})]})]})]}),c&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),p?.()},title:u?"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:u?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),v&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:z,title:"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,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:W,title:"Delete",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,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}let ed=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,ec=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,eu=/\x1B\[([0-9;]*)m/g,ep=/\x1B_pi:c\x07/g,eh=["#1f2937","#dc2626","#16a34a","#d97706","#2563eb","#9333ea","#0891b2","#6b7280"],ex=["#9ca3af","#ef4444","#22c55e","#f59e0b","#3b82f6","#a855f7","#06b6d4","#e5e7eb"];function eg(e){return e.replace(ep,"").replace(ed,"")}function ef(e){let t=[],r=0;for(;r<e.length;){if(27===e.charCodeAt(r)){let t=e.slice(r).match(ec);if(t){r+=t[0].length;continue}}let n=e.codePointAt(r);if(void 0===n)break;let o=String.fromCodePoint(n);t.push({start:r,end:r+o.length,char:o}),r+=o.length}return t}function em(e,t){let r=ef(e)[t];return r?e.slice(0,r.start)+e.slice(r.end):e}function ev(e){return ef(e)[0]?.char}let ey={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:""},eb={ArrowLeft:"\x1bb",ArrowRight:"\x1bf",ArrowUp:"\x1bp",ArrowDown:"\x1bn"};function ek(e,t={}){return"thinking"===e.type&&!e.deferred&&!t.isStreaming&&""===e.thinking.trim()}function ej(e,t={}){return(e.content??[]).filter(e=>!ek(e,t))}function ew(e,t={}){let r=ej(e,t),n=r.findLastIndex(e=>"text"!==e.type&&"image"!==e.type);return -1===n?{answerBlocks:r,processBlocks:[]}:{answerBlocks:r.slice(n+1),processBlocks:r.slice(0,n+1)}}function eS(e){return e.filter(e=>"toolCall"===e.type).length}var eC=r(32316),eT=r(65063),eI=r(7644);let eL=new Set,eR=new Set;function ez(){try{return localStorage.getItem("pi-theme")??"auto"}catch{return"auto"}}function eM(){eL.forEach(e=>e())}function eW(){eR.forEach(e=>e())}function eE(e){return eL.add(e),()=>{eL.delete(e)}}function e$(){return!("u"<typeof document)&&document.documentElement.classList.contains("dark")}function eB(e){"dark"===e||"light"!==e&&window.matchMedia("(prefers-color-scheme: dark)").matches?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")}function eA(){let e=(0,o.useSyncExternalStore)(eE,e$,()=>!1),[t,r]=(0,o.useState)("auto");(0,o.useEffect)(()=>{var e;return r(ez()),e=()=>r(ez()),eR.add(e),()=>{eR.delete(e)}},[]),(0,o.useEffect)(()=>{let e=window.matchMedia("(prefers-color-scheme: dark)"),t=()=>{"auto"===ez()&&(eB("auto"),eM())};return e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]);let n=(0,o.useCallback)(e=>{try{localStorage.setItem("pi-theme",e)}catch{}eB(e),r(e),eW(),eM()},[]),i=(0,o.useCallback)(e=>{let n="auto"===t?"light":"light"===t?"dark":"auto";try{localStorage.setItem("pi-theme",n)}catch{}eB(n),r(n),eW(),eM()},[t]);return{isDark:e,mode:t,setMode:n,cycleMode:i}}function eD(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 eP(e){try{return decodeURIComponent(e)}catch{return e}}function eN(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function eF(e){let t=eN(e),r=/^[a-zA-Z]:\//.test(t),n=t.startsWith("//"),o=t.startsWith("/")&&!r&&!n,i=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){i.length>0&&".."!==i[i.length-1]?i.pop():o||r||n||i.push(e);continue}i.push(e)}let l=i.join("/");return r?l:n?`//${l}`:o?`/${l}`:l}function eO(e,t,r=t){let n,o,i,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=eP(a),p=u.startsWith("\\\\"),h=eN(u),x=h.toLowerCase();if(x.startsWith("/api/")||x.startsWith("/_next/")||!p&&h.startsWith("//")||/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(h)&&!x.startsWith("file:")&&!/^[a-zA-Z]:\//.test(h))return null;if(x.startsWith("file:")?c=(d=function(e){try{let t=new URL(e);if("file:"!==t.protocol)return null;let r=eP(t.pathname);if(t.hostname)return`//${t.hostname}${r.startsWith("/")?r:`/${r}`}`;if(/^\/[a-zA-Z]:\//.test(r))return r.slice(1);return r}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=`${eN(t).replace(/\/+$/,"")}/${h}`,c="relative"),!d)return null;let g=eF(d).replace(/:\d+(?::\d+)?$/,"");return"relative"===c&&r&&(n=eF(g).replace(/\/+$/,""),o=eF(r).replace(/\/+$/,""),l=(i=/^[a-zA-Z]:\//.test(n)||/^[a-zA-Z]:\//.test(o))?n.toLowerCase():n,!(l===(s=i?o.toLowerCase():o)||l.startsWith(`${s}/`)))?null:g}var eH=r(88374),eU=r(5924),e_=r(94764),eq=r(63835),eK=r(84678),eV=r(98164);let eJ={...e_.j,attributes:{...e_.j.attributes,code:[["className",/^language-./,"math-inline","math-display"]]},strip:[...e_.j.strip||[],"iframe","object","style","form"]},eY=[eK.A,eV.A],eZ=[eK.A],eG=[eU.A,[eq.A,eJ],[eH.A,{throwOnError:!1,strict:!1}]],eX=[eU.A,[eq.A,eJ]];function eQ({children:e,className:t,isStreaming:r,cwd:i,onOpenFile:l}){let s=(0,o.useMemo)(()=>{var t;let r,n,o;return r=(t=e).includes("\r\n")?"\r\n":"\n",n=t.split(/\r?\n/),o=null,n.map(e=>{let t=e.match(/^ {0,3}(`{3,}|~{3,})/);if(t){let r=t[1][0],n=t[1].length;return o?r===o.marker&&n>=o.size&&(o=null):o={marker:r,size:n},e}if(o)return e;let n=e.match(/^([ \t]{0,3})\$\$(.+)\$\$[ \t]*$/);if(!n)return e;let i=n[2].trim();return i?`${n[1]}$$${r}${i}${r}${n[1]}$$`:e}).join(r)},[e]);return(0,n.jsx)("div",{className:["markdown-body",t].filter(Boolean).join(" "),children:(0,n.jsx)(eC.oz,{remarkPlugins:eY,rehypePlugins:eG,components:{code({className:e,children:t,...o}){let i=e?.replace("language-","").toLowerCase()??"",l=String(t);return e?.includes("language-")||l.includes("\n")?"mermaid"===i?(0,n.jsx)(e0,{code:l.replace(/\n$/,""),isStreaming:r}):(0,n.jsx)(e1,{code:l.replace(/\n$/,""),lang:i}):(0,n.jsx)("code",{className:"markdown-inline-code",...o,children:t})},pre:({children:e})=>(0,n.jsx)(n.Fragment,{children:e}),a({href:e,children:t,...r}){delete r.node;let o=l?eO(e,i):null;return o&&l?(0,n.jsx)("a",{href:e,...r,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(o))},children:t}):(0,n.jsx)("a",{href:e,...r,target:"_blank",rel:"noopener noreferrer",children:t})},table:({children:e})=>(0,n.jsx)("div",{className:"markdown-table-wrap",children:(0,n.jsx)("table",{children:e})})},children:s})})}function e0({code:e,isStreaming:t}){let{isDark:i}=eA(),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)(null),x=`${i?"dark":"light"}
|
|
2
|
+
${e}`;(0,o.useEffect)(()=>{if(!l||t)return;let n=!1;return h(null),(async()=>{let{default:t}=await Promise.all([r.e(279),r.e(2280),r.e(3308)]).then(r.bind(r,43328));if(t.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:i?"dark":"default"}),!await t.parse(e,{suppressErrors:!0}))throw Error("Invalid Mermaid diagram");let o="u">typeof crypto&&"randomUUID"in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,l=await t.render(o,e);n||(d(l.svg),u(x))})().catch(()=>{n||h(x)}),()=>{n=!0}},[e,x,i,t,l]);let g=(0,n.jsx)("button",{onClick:()=>s(e=>!e),disabled:t,title:t?"Preview available after streaming":l?"Show Mermaid source":"Preview Mermaid diagram",className:["markdown-code-action",l?"is-active":""].filter(Boolean).join(" "),children:l?"Source":"Preview"});if(!l||t)return(0,n.jsx)(e1,{code:e,lang:"mermaid",headerAction:g});let f=p===x?(0,n.jsx)("div",{className:"mermaid-block mermaid-block-error",children:"Invalid Mermaid diagram"}):a&&c===x?(0,n.jsx)("div",{className:"mermaid-block",dangerouslySetInnerHTML:{__html:a}}):(0,n.jsx)("div",{className:"mermaid-block mermaid-block-loading","aria-label":"Rendering Mermaid diagram"});return(0,n.jsxs)("div",{className:"markdown-code-block",children:[(0,n.jsxs)("div",{className:"markdown-code-header",children:[(0,n.jsx)("span",{className:"markdown-code-lang",children:"mermaid"}),g]}),f]})}function e1({code:e,lang:t,headerAction:r}){let{isDark:i}=eA(),[l,s]=(0,o.useState)(!1);return(0,n.jsxs)("div",{className:"markdown-code-block",children:[(0,n.jsxs)("div",{className:"markdown-code-header",children:[(0,n.jsx)("span",{className:"markdown-code-lang",children:t||"text"}),(0,n.jsxs)("div",{className:"markdown-code-actions",children:[r,(0,n.jsx)("button",{onClick:()=>{eD(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)})},className:"markdown-code-action",children:l?"copied":"copy"})]})]}),(0,n.jsx)(eT.A,{language:t||"text",style:i?eI.xJ:eI.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})]})}let e2=/<(read-files|modified-files)>\s*([\s\S]*?)\s*<\/\1>/g,e4=/(?:\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 e5(e){let t,r=[],n=null,o=0,i=0,l=[],s=[],a=()=>({lineNo:null,text:"",type:"empty"}),d=()=>{if(!n){l=[],s=[];return}let e=Math.max(l.length,s.length);for(let t=0;t<e;t++){let e=l[t]?{lineNo:l[t].lineNo,text:l[t].text,type:"removed"}:a(),r=s[t]?{lineNo:s[t].lineNo,text:s[t].text,type:"added"}:a();n.rows.push({type:"line",left:e,right:r})}l=[],s=[]};for(let a of e.split(/\r?\n/)){if(a.startsWith("--- ")){d(),t=e6(a.slice(4));continue}if(a.startsWith("+++ ")){d(),n={oldPath:t,newPath:e6(a.slice(4)),rows:[]},r.push(n);continue}let e=a.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);if(e){n||(n={rows:[]},r.push(n)),d(),o=Number(e[1]),i=Number(e[2]),n.rows.push({type:"hunk",text:a});continue}if(!n)continue;if(a.startsWith("\\ ")){d(),n.rows.push({type:"hunk",text:a});continue}let c=a[0],u=a.slice(1);" "===c?(d(),n.rows.push({type:"line",left:{lineNo:o++,text:u,type:"context"},right:{lineNo:i++,text:u,type:"context"}})):"-"===c?l.push({lineNo:o++,text:u}):"+"===c?s.push({lineNo:i++,text:u}):""!==a&&(d(),n.rows.push({type:"hunk",text:a}))}d();let c=r.filter(e=>e.rows.some(e=>"line"===e.type));return c.length>0?c:null}function e6(e){return e.split(" ")[0].trim()}let e8=new Map;function e3(e){if(!e)return null;let t=new Date(e),r=new Date,n=t.getFullYear()===r.getFullYear()&&t.getMonth()===r.getMonth()&&t.getDate()===r.getDate(),o=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(n)return o;let i=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==r.getFullYear()?"numeric":void 0});return`${i} ${o}`}let e9=(0,o.memo)(function({message:e,isStreaming:t,toolResults:r,modelNames:o,cwd:i,onOpenFile:l,entryId:s,onFork:a,forking:d,onNavigate:c,prevAssistantEntryId:u,onEditContent:p,showTimestamp:h,prevTimestamp:x,sessionId:g}){return"user"===e.role?(0,n.jsx)(e7,{message:e,cwd:i,onOpenFile:l,entryId:s,onFork:a,forking:d,onNavigate:c,prevAssistantEntryId:u,onEditContent:p}):"assistant"===e.role?(0,n.jsx)(te,{message:e,isStreaming:t,toolResults:r,modelNames:o,cwd:i,onOpenFile:l,showTimestamp:h,prevTimestamp:x,sessionId:g,entryId:s}):"toolResult"===e.role?null:"custom"===e.role?"compaction"===e.customType?(0,n.jsx)(tu,{message:e}):(0,n.jsx)(tx,{message:e,cwd:i,onOpenFile:l}):"bashExecution"===e.role?(0,n.jsx)(tf,{message:e,sessionId:g}):null},(e,t)=>e.message===t.message&&e.isStreaming===t.isStreaming&&function(e,t,r){if(t===r||"assistant"!==e.role)return!0;for(let n of e.content??[])if("toolCall"===n.type&&t?.get(n.toolCallId)!==r?.get(n.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 e7({message:e,cwd:t,onOpenFile:r,entryId:i,onFork:l,forking:s,onNavigate:a,prevAssistantEntryId:d,onEditContent:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),g="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),f="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),m=e3(e.timestamp),v=!!i&&!!l,y=!!d&&!!a;return(0,n.jsxs)("div",{style:{marginBottom:16,display:"flex",flexDirection:"column",alignItems:"flex-end"},onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:6,maxWidth:"85%"},children:(0,n.jsxs)("div",{style:{flex:1,minWidth:0,background:"var(--user-bg)",border:"1px solid rgba(59,130,246,0.2)",borderRadius:12,padding:"8px 12px",fontSize:14,lineHeight:1.6,color:"var(--text)",wordBreak:"break-word"},children:[f.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!g},children:f.map((e,t)=>{let r=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,n.jsx)("img",{src:r,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)"}},t)})}),g&&(0,n.jsx)(eQ,{className:"markdown-user-message",cwd:t,onOpenFile:r,children:g})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3},children:[(0,n.jsx)("div",{style:{display:"flex",gap:3,opacity:+!!u,pointerEvents:u?"auto":"none",transition:"opacity 0.12s"},children:(0,n.jsxs)("button",{onClick:()=>{eD(g).then(()=>{x(!0),setTimeout(()=>x(!1),1500)})},title:"Copy message",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:h?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{h||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{h||(e.currentTarget.style.color="var(--text-dim)")},children:[h?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),h?"Copied":"Copy"]})}),(v||y)&&(0,n.jsxs)("div",{style:{display:"flex",gap:3,opacity:u||s?1:0,pointerEvents:u||s?"auto":"none",transition:"opacity 0.12s"},children:[y&&(0,n.jsxs)("button",{onClick:()=>{a(d),c?.(g)},title:"Edit from here — branches within this session",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,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"15 10 20 15 15 20"}),(0,n.jsx)("path",{d:"M4 4v7a4 4 0 0 0 4 4h12"})]}),"Edit from here"]}),v&&(0,n.jsxs)("button",{onClick:()=>{l(i)},disabled:s,title:s?"Creating new session…":"New session — creates an independent copy from here",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,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),s?"Creating…":"New session"]})]}),m&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:m})]})]})}function te({message:e,isStreaming:t,toolResults:r,modelNames:i,cwd:l,onOpenFile:s,showTimestamp:a,prevTimestamp:d,sessionId:c,entryId:u}){var p;let h,x=a?e3(e.timestamp):null,g=(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!ek(e,{isStreaming:t})),f=g.map(({block:e})=>e),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),k=(0,o.useRef)(null),[j,w]=(0,o.useState)(null),S=(0,o.useRef)(g);S.current=g;let C=(0,o.useRef)(new Map),[T,I]=(0,o.useState)(new Map),L=(0,o.useMemo)(()=>{if(!e.timestamp||!d)return;let t=Math.round((e.timestamp-d)/1e3);return t>0?t:void 0},[e.timestamp,d]),R=(0,o.useMemo)(()=>{let t=new Map;if(!r||!e.timestamp)return t;for(let[n,o]of r)if(o.timestamp&&e.timestamp){let r=Math.round((o.timestamp-e.timestamp)/1e3);r>0&&t.set(n,r)}return t},[r,e.timestamp]),z=f.filter(e=>"text"===e.type).map(e=>e.text).join("\n");return((0,o.useEffect)(()=>{if(!t){let e=new Date().getTime();I(t=>{let r=new Map(t);for(let[t,n]of C.current)r.has(t)||r.set(t,Math.round((e-n)/1e3));return r}),k.current=null,w(null);return}let e=setInterval(()=>{let e=S.current,t=e.map(({block:e})=>e),r=Date.now();e.forEach(({originalIndex:e})=>{C.current.has(e)||C.current.set(e,r)}),I(t=>{let n=!1,o=new Map(t);for(let t=0;t<e.length-1;t++){let i=e[t].originalIndex,l=e[t+1].originalIndex;if(!o.has(i)&&C.current.has(i)){let e=C.current.get(i),t=C.current.get(l)??r;o.set(i,Math.round((t-e)/1e3)),n=!0}}return n?o:t});let n=0;for(let e of t)"text"===e.type?n+=e.text?.length??0:"thinking"===e.type?n+=e.thinking?.length??0:"toolCall"===e.type&&(n+=JSON.stringify(e.input??{}).length);if(0===n)return;null===k.current&&(k.current=r);let o=(r-k.current)/1e3;o>.5&&w(n/4/o)},300);return()=>clearInterval(e)},[t]),0!==f.length||t)?(0,n.jsxs)("div",{style:{marginBottom:16},onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),children:[(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",marginBottom:4,display:"flex",alignItems:"center",gap:6},children:[e.provider&&(0,n.jsx)("span",{children:i?.[`${e.provider}:${e.model}`]??i?.[e.model]??e.model}),t&&(()=>{let e,t=0;for(let e of f)"text"===e.type?t+=e.text?.length??0:"thinking"===e.type?t+=e.thinking?.length??0:"toolCall"===e.type&&(t+=JSON.stringify(e.input??{}).length);let r=Math.round(t/4);return(0,n.jsx)(n.Fragment,{children:r>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--text)"},title:"Estimated token count while streaming",children:[(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2,fontSize:11,fontWeight:400},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),r]}),null!==j&&(e=j>=50?"#53b3cb":j>=30?"#9bc53d":j>=15?"#f9c22e":"#e01a4f",(0,n.jsxs)("span",{style:{marginLeft:6,padding:"1px 6px",borderRadius:4,background:e,color:"#fff",fontSize:11,fontWeight:400},children:[j.toFixed(1)," t/s"]}))]})})})()]}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:g.map(({block:e,originalIndex:o})=>(0,n.jsx)(tt,{block:e,toolResults:r,isStreaming:t,streamingDuration:T.get(o)??("thinking"===e.type?L:void 0),toolCallDurations:R,cwd:l,onOpenFile:s,sessionId:c,entryId:u,blockIndex:o},`${u??"stream"}-${o}`))}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[e.usage&&!t&&(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:(p=e.usage,h=[],p.input&&h.push(`${p.input.toLocaleString()} in`),p.output&&h.push(`${p.output.toLocaleString()} out`),p.cacheRead&&h.push(`${p.cacheRead.toLocaleString()} cache`),p.cost?.total&&h.push(`$${p.cost.total.toFixed(4)}`),h.join(" \xb7 "))}),z&&!t&&(0,n.jsxs)("button",{onClick:()=>{eD(z).then(()=>{b(!0),setTimeout(()=>b(!1),1500)})},title:"Copy message",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:y?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:+!!m,pointerEvents:m?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{y||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{y||(e.currentTarget.style.color="var(--text-dim)")},children:[y?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),y?"Copied":"Copy"]}),x&&!t&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:"auto"},children:x})]})]}):null}function tt({block:e,toolResults:t,isStreaming:r,streamingDuration:o,toolCallDurations:i,cwd:l,onOpenFile:s,sessionId:a,entryId:d,blockIndex:c}){if("text"===e.type)return(0,n.jsx)(tr,{block:e,isStreaming:r,cwd:l,onOpenFile:s});if("thinking"===e.type)return(0,n.jsx)(tn,{block:e,duration:o,sessionId:a,entryId:d,blockIndex:c});if("toolCall"===e.type){let r=t?.get(e.toolCallId),o=i?.get(e.toolCallId);return(0,n.jsx)(to,{block:e,result:r,duration:o})}return null}function tr({block:e,isStreaming:t,cwd:r,onOpenFile:o}){return(0,n.jsx)(eQ,{isStreaming:t,cwd:r,onOpenFile:o,children:e.text})}function tn({block:e,duration:t,sessionId:r,entryId:i,blockIndex:l}){let[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(null),g=async()=>{let t=!s;if(a(t),t&&e.deferred&&null===d){if(!r||!i)return void x("Thinking content unavailable");p(!0),x(null);try{c(await function(e,t,r){let n=`${e}:${t}:${r}`,o=e8.get(n);if(o)return e8.delete(n),e8.set(n,o),o;let i=fetch(`/api/sessions/${encodeURIComponent(e)}/entries/${encodeURIComponent(t)}/thinking?blockIndex=${r}`).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 e8.delete(n),e});if(e8.set(n,i),e8.size>100){let e=e8.keys().next().value;e&&e8.delete(e)}return i}(r,i,l))}catch(e){x(e instanceof Error?e.message:String(e))}finally{p(!1)}}};return(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",fontSize:13},children:[(0,n.jsxs)("button",{onClick:()=>void g(),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"6px 10px",background:"var(--bg-panel)",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,n.jsx)("span",{children:"Thinking"}),void 0!==t&&(0,n.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]})]}),s&&(0,n.jsx)("div",{style:{padding:"8px 10px",color:h?"#f87171":"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",background:"var(--bg-panel)",borderTop:"1px solid var(--border)"},children:u?"Loading thinking...":h??(e.deferred?d:e.thinking)})]})}function to({block:e,result:t,duration:r}){let i,[l,s]=(0,o.useState)(!1),a=JSON.stringify(e.input,null,2),d="edit"===(i=e.toolName.toLowerCase())||i.startsWith("edit_")||i.endsWith(".edit")||i.endsWith("_edit")||i.includes("str_replace")||i.includes("replace_editor"),c=t&&!t.isError?function(e){var t;let r=e.details;if(!("object"==typeof(t=r)&&null!==t&&!Array.isArray(t)))return null;let n="string"==typeof r.patch?r.patch:null;if(n)return{text:n};let o="string"==typeof r.diff?r.diff:null;return o?{text:o}:null}(t):null,u=t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,p=null!==u&&("(no output)"===u.trim()||""===u.trim()),h=t?.isError??!1;return(0,n.jsxs)("div",{style:{borderRadius:7,overflow:"hidden",fontSize:12,border:h?"1px solid rgba(248,113,113,0.45)":"1px solid rgba(34,197,94,0.25)",background:h?"rgba(248,113,113,0.05)":"rgba(34,197,94,0.04)"},children:[(0,n.jsxs)("button",{onClick:()=>s(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,n.jsx)("span",{style:{color:h?"#f87171":"#16a34a",fontFamily:"var(--font-mono)",fontWeight:600,fontSize:11,flexShrink:0},children:e.toolName}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let r=Object.keys(t);return 0===r.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[r[0]]).slice(0,120)}(e)}),void 0!==r&&(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[r,"s"]}),(0,n.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:l?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),l&&!d&&(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",background:"var(--bg-subtle)",borderTop:h?"1px solid rgba(248,113,113,0.25)":"1px solid rgba(34,197,94,0.2)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:a}),l&&t&&(c?(0,n.jsx)(ti,{diff:c}):(0,n.jsx)(tc,{text:u??"",isEmpty:p,isError:h}))]})}function ti({diff:e}){return(0,n.jsx)("div",{style:{borderTop:"1px solid rgba(34,197,94,0.15)",background:"var(--bg)"},children:(0,n.jsx)(tl,{text:e.text})})}function tl({text:e}){let t=(0,o.useMemo)(()=>e5(e),[e]);if(!t)return(0,n.jsx)(td,{text:e});let r=t.length>1;return(0,n.jsx)("div",{style:{maxHeight:560,overflowY:"auto",overflowX:"hidden",background:"var(--bg)"},children:t.map((e,t)=>(0,n.jsxs)("div",{style:{minWidth:0,borderTop:0===t?"none":"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55},children:[r&&(0,n.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,n.jsx)(ts,{title:e.oldPath||"Before",side:"left"}),(0,n.jsx)(ts,{title:e.newPath||"After",side:"right"})]}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)"},children:e.rows.map((e,t)=>"hunk"===e.type?null:(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)(ta,{cell:e.left,side:"left"}),(0,n.jsx)(ta,{cell:e.right,side:"right"})]},t))})]},t))})}function ts({title:e,side:t}){return(0,n.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 ta({cell:e,side:t}){let r="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",o="added"===e.type?"+":"removed"===e.type?"-":" ",i="added"===e.type?"#22c55e":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",minWidth:0,background:r,borderRight:"left"===t?"1px solid var(--border)":"none"},children:[(0,n.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,n.jsx)("span",{style:{width:18,padding:"0 5px",color:i,userSelect:"none",fontWeight:"context"===e.type||"empty"===e.type?400:700,flexShrink:0},children:o}),(0,n.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 td({text:e}){let t=e.split(/\r?\n/);return(0,n.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 r=e.startsWith("@@")?"hunk":e.startsWith("+")&&!e.startsWith("+++")?"added":e.startsWith("-")&&!e.startsWith("---")?"removed":"context";return(0,n.jsxs)("div",{style:{display:"flex",background:"added"===r?"rgba(34,197,94,0.12)":"removed"===r?"rgba(248,113,113,0.13)":"hunk"===r?"rgba(96,165,250,0.12)":"transparent",borderLeft:"added"===r?"3px solid #22c55e":"removed"===r?"3px solid #f87171":"hunk"===r?"3px solid var(--accent)":"3px solid transparent"},children:[(0,n.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,n.jsx)("span",{style:{padding:"0 10px",whiteSpace:"pre-wrap",overflowWrap:"anywhere",color:"added"===r?"#22c55e":"removed"===r?"#f87171":"hunk"===r?"var(--accent)":"var(--text)"},children:e||"\xa0"})]},t)})})}function tc({text:e,isEmpty:t,isError:r}){return(0,n.jsx)("div",{style:{borderTop:`1px solid ${r?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:r?"rgba(248,113,113,0.04)":"var(--bg-subtle)"},children:(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:r?"#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?"(no output)":e})})}function tu({message:e}){let t=tg(e.content),r=(0,o.useMemo)(()=>{let e,r,n,o,i;return e=[],r=[],n=t.match(e4),o=n?.[1]??"",i=n?.index===void 0?t:t.slice(0,n.index),o.replace(e2,(t,n,o)=>{let i=o.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return"read-files"===n?e.push(...i):r.push(...i),""}),{body:i.trim(),readFiles:e,modifiedFiles:r}},[t]),i=e3(e.timestamp);return(0,n.jsx)("div",{style:{marginBottom:16},children:(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg)"},children:[(0,n.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,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:"compaction"}),i&&(0,n.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:i})]}),(0,n.jsxs)("div",{style:{padding:"11px 13px 12px"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700,lineHeight:1.35},children:"Conversation compacted"}),(0,n.jsx)("div",{style:{marginTop:3,marginBottom:10,color:"var(--text)",fontSize:14,lineHeight:1.5},children:"The conversation history before this point was compacted into the following summary:"}),r.body?(0,n.jsx)(eQ,{className:"markdown-compaction-message",children:r.body}):(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:"(no summary)"}),(0,n.jsx)(tp,{readFiles:r.readFiles,modifiedFiles:r.modifiedFiles})]})]})})}function tp({readFiles:e,modifiedFiles:t}){if(0===e.length+t.length)return null;let r=[];return e.length>0&&r.push(`${e.length} read`),t.length>0&&r.push(`${t.length} modified`),(0,n.jsxs)("details",{className:"compaction-file-details",children:[(0,n.jsxs)("summary",{children:["File context: ",r.join(", ")]}),t.length>0&&(0,n.jsx)(th,{title:"Modified files",files:t}),e.length>0&&(0,n.jsx)(th,{title:"Read files",files:e})]})}function th({title:e,files:t}){return(0,n.jsxs)("div",{className:"compaction-file-section",children:[(0,n.jsx)("div",{className:"compaction-file-title",children:e}),(0,n.jsx)("ul",{className:"compaction-file-list",children:t.map(e=>(0,n.jsx)("li",{children:e},e))})]})}function tx({message:e,cwd:t,onOpenFile:r}){var i;let l,s=!1===e.display,[a,d]=(0,o.useState)(!s),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)(!1),x=tg(e.content),g="string"==typeof(i=e.content)?[]:i.filter(e=>"image"===e.type),f=void 0!==e.details,m=f?function(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.details):"",v=e.customType||"extension",y=e3(e.timestamp);return(0,n.jsx)("div",{style:{marginBottom:16},children:(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:s?"var(--bg-subtle)":"var(--bg)",opacity:s&&!a?.82:1},children:[(0,n.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,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:v}),s&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"hidden extension message"}),y&&(0,n.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:y})]}),a?(0,n.jsxs)("div",{style:{padding:"6px 9px"},children:[g.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!x},children:g.map((e,t)=>{var r;let o=(r=e).source?"base64"===r.source.type?`data:${r.source.media_type};base64,${r.source.data}`:r.source.url??"":r.data?`data:${r.mimeType};base64,${r.data}`:"";return o?(0,n.jsx)("img",{src:o,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}},t):null})}),x?(0,n.jsx)(eQ,{className:"markdown-custom-message",cwd:t,onOpenFile:r,children:x}):(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:"(no message)"})]}):(0,n.jsx)("button",{onClick:()=>d(!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"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 9px",borderTop:"1px solid var(--border)",background:"var(--bg-subtle)"},children:[x||m?(0,n.jsx)("button",{onClick:()=>{eD(x||m).then(()=>{h(!0),setTimeout(()=>h(!1),1500)})},style:{padding:"3px 7px",border:"none",background:"none",color:p?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11},children:p?"Copied":"Copy"}):null,(f||s)&&(0,n.jsx)("button",{onClick:()=>{s?d(e=>!e):u(e=>!e)},style:{marginLeft:"auto",padding:"3px 7px",border:"none",background:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11},children:s?a?"Collapse":"Expand":c?"Hide details":"Show details"})]}),f&&(s&&a||!s&&c)&&(0,n.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:m})]})})}function tg(e){return"string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n")}function tf({message:e,sessionId:t}){let[r,i]=(0,o.useState)(null),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.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===r,x=r??e.output;async function g(){if(p){s(!0),d(null);try{let e=await fetch(p),t=await e.json();t.success?i(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:x?[{type:"text",text:x}]:[],isError:u,timestamp:e.timestamp};return(0,n.jsxs)("div",{style:{margin:"6px 0"},children:[(0,n.jsx)(to,{block:m,result:v}),e.truncated&&p&&(0,n.jsxs)("div",{style:{padding:"4px 10px",fontSize:11,marginTop:-1},children:[h&&(0,n.jsx)("button",{onClick:g,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,n.jsx)("a",{href:`${p}&download=1`,style:{marginLeft:10*!!h,color:"var(--accent)",fontSize:11,textDecoration:"underline"},children:"download full output"}),a&&(0,n.jsxs)("span",{style:{marginLeft:6,color:"var(--text-dim)",fontSize:11},children:["(",a,")"]})]})]})}let tm=new Map;function tv(e){return{value:e.value,images:e.images.map(e=>({...e}))}}function ty(e){let t=tm.get(e);return t?tv(t):null}function tb(e,t){t.value||0!==t.images.length?tm.set(e,tv(t)):tm.delete(e)}function tk(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let r=/(?:^|\s)@([^\s"]*)$/.exec(e);return r?{start:e.length-(r[1].length+1),query:r[1],quoted:!1}:null}function tj(e){let t=0;for(let r=0;r<e.length;r++)"/"===e[r]&&t++;return t}function tw(e,t){if(!e)return!0;let r=0;for(let n=0;n<t.length&&r<e.length;n++)t[n]===e[r]&&r++;return r===e.length}function tS(e,t){let r=t?`${e}/`:e;return r.includes(" ")?`@"${r}" `:`@${r} `}let tC="(max-width: 640px)";function tT(e){if(!window.matchMedia)return()=>{};let t=window.matchMedia(tC);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)}function tI(){return!!window.matchMedia&&window.matchMedia(tC).matches}function tL(){return!1}function tR(){return(0,o.useSyncExternalStore)(tT,tI,tL)}let tz=["off","default","full"],tM={off:"none",default:"default",full:"full"},tW=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function tE(e,t){return tW.compare(e.name||e.modelId,t.name||t.modelId)||tW.compare(e.provider,t.provider)||tW.compare(e.modelId,t.modelId)}let t$=["auto","off","minimal","low","medium","high","xhigh","max"],tB={auto:"Use pi default",off:"Reasoning off",minimal:"Minimal reasoning",low:"Low reasoning",medium:"Medium reasoning",high:"High reasoning",xhigh:"Extra-high reasoning",max:"Max reasoning"};function tA(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}let tD=[{name:"compact",description:"Compress context, optionally with instructions",source:"builtin"},{name:"reload",description:"Reload extensions, skills, prompts, and tools",source:"builtin"},{name:"name",description:"Set the session display name",source:"builtin"},{name:"session",description:"Show session message, token, and cost stats",source:"builtin"},{name:"copy",description:"Copy the last assistant message",source:"builtin"}],tP=["builtin","extension","prompt","skill"],tN={builtin:"Built-in",extension:"Extensions",prompt:"Prompts",skill:"Skills"},tF={builtin:0,extension:1,prompt:2,skill:3};function tO(e,t){let r=e.name.toLowerCase(),n=e.description?.toLowerCase()??"";return r===t?0:r.startsWith(t)?1:r.includes(t)?2:n.includes(t)?3:4}function tH(e){return{data:e.data,mimeType:e.mimeType}}function tU(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function t_(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function tq({kind:e,text:t}){return(0,n.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,n.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,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})}let tK=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:s,isAutoModelSelection:d,modelNames:c,modelList:u,onModelChange:p,onCompact:h,onAbortCompaction:x,isCompacting:g,compactError:f,compactResult:m,toolPreset:v,onToolPresetChange:y,thinkingLevel:b,onThinkingLevelChange:k,availableThinkingLevels:j,thinkingLevelMap:w,retryInfo:S,queuedMessages:C,onRecallQueue:T,slashCommands:I,slashCommandsLoading:L,onLoadSlashCommands:R,onBuiltinCommand:z,soundEnabled:M,onSoundToggle:W,onAudioUnlock:E,onPromptWithStreamingBehavior:$,draftKey:B,cwd:D},P){let N,F,O,H,U,_,q,K,V=tR(),[J,Y]=(0,o.useState)(()=>B?ty(B)?.value??"":""),[Z,G]=(0,o.useState)(!1),[X,Q]=(0,o.useState)(null),[ee,et]=(0,o.useState)(!1),[er,en]=(0,o.useState)(!1),[eo,ei]=(0,o.useState)(!1),[el,es]=(0,o.useState)(()=>B?ty(B)?.images.map(tU)??[]:[]),ea=J.trimStart(),ed=0===el.length&&ea.startsWith("!"),ec=ed&&ea.startsWith("!!"),[eu,ep]=(0,o.useState)(!1),[eh,ex]=(0,o.useState)(0),[eg,ef]=(0,o.useState)(null),[em,ev]=(0,o.useState)(!1),[ey,eb]=(0,o.useState)(0),[ek,ej]=(0,o.useState)(null),[ew,eS]=(0,o.useState)(!1),[eC,eT]=(0,o.useState)(null),eI=(0,o.useRef)(null),eL=(0,o.useRef)(null),eR=(0,o.useRef)(null),ez=(0,o.useRef)(null),eM=(0,o.useRef)(null),eW=(0,o.useRef)(null),eE=(0,o.useRef)(null),e$=(0,o.useRef)(!1),eB=(0,o.useRef)(0),eA=(0,o.useRef)(!1),eD=(0,o.useRef)([]),eP=(0,o.useRef)([]),eN=(0,o.useRef)(null),eF=(0,o.useRef)(null),eO=(0,o.useRef)(B),eH=(0,o.useRef)(J),eU=(0,o.useRef)(el);eH.current=J,eU.current=el,(0,o.useImperativeHandle)(P,()=>({insertIfEmpty(e){let t=eI.current;(t?t.value:J).trim()||(Y(e),ef(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},prependText(e){if(!e.trim())return;let t=eI.current,r=[e,t?t.value:J].filter(e=>e.trim()).join("\n\n");Y(r),ef(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(r.length,r.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},insertText(e){let t=eI.current;if(!t)return void Y(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=o.length>0&&!o.endsWith(" ")?" ":"";Y(o+l+e+i),ef(null),requestAnimationFrame(()=>{if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},addImages(e){e_(e)}}));let e_=(0,o.useCallback)(async e=>{if(l)return;let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));es(e=>[...e,...r])},[l]),eq=(0,o.useCallback)(e=>{es(t=>{let r=[...t],[n]=r.splice(e,1);return n&&t_(n),r})},[]),eK=(0,o.useCallback)(()=>{es(e=>(e.forEach(t_),[]))},[]),eV=(0,o.useCallback)(()=>{var e;Y(""),ef(null),B&&tm.delete(B),eO.current&&eO.current!==B&&(e=eO.current,tm.delete(e)),eK(),eI.current&&(eI.current.style.height="auto")},[eK,B]);(0,o.useEffect)(()=>{B&&eO.current===B&&tb(B,{value:J,images:el.map(tH)})},[el,B,J]),(0,o.useEffect)(()=>{let e=eO.current;if(e===B)return;e&&tb(e,{value:eH.current,images:eU.current.map(tH)});let t=B?ty(B):null;eO.current=B,Y(t?.value??""),ef(null),es(e=>(e.forEach(t_),t?.images.map(tU)??[]))},[B]),(0,o.useEffect)(()=>{let e=eI.current;e&&(e.style.height="auto",J&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[J]),(0,o.useEffect)(()=>()=>{eU.current.forEach(t_)},[]);let eJ=(0,o.useCallback)(async()=>{let t=J.trim();if((t||el.length)&&!l){if(E?.(),!el.length&&t.startsWith("/")&&z){let e=await z(t);if(e.handled){e.error||eV();return}}e(t,el.length?el:void 0),eV()}},[J,el,l,z,e,eV,E]),eY=J.startsWith("/")&&!/\s/.test(J.slice(1))?J.slice(1).toLowerCase():null,eZ=null===eY?[]:[...l?[]:tD,...I??[]].filter(e=>{let t=e.name.toLowerCase(),r=e.description?.toLowerCase()??"";return t.includes(eY)||r.includes(eY)}).sort((e,t)=>{let r=tO(e,eY)-tO(t,eY);return 0!==r?r:tF[e.source]-tF[t.source]||tW.compare(e.name,t.name)}),eG=(()=>{let e=new Map;for(let t of tP)e.set(t,{source:t,items:[]});return eZ.forEach((t,r)=>{e.get(t.source)?.items.push({command:t,index:r})}),tP.map(t=>e.get(t)).filter(e=>e.items.length>0)})(),eX=1===eZ.length?eY?"1 match":"1 command":`${eZ.length} ${eY?"matches":"commands"}`,eQ=!!J.trim()&&0===el.length,e0=(0,o.useCallback)((e,t)=>{if(!D)return void ef(null);let r=t??e.length;ef(tk(e.slice(0,r)))},[D]),e1=eg?.query??null,e2=o.useMemo(()=>null!==e1&&ek&&ek.cwd===D?function(e,t,r=20){let n=t.toLowerCase();if(!n)return e.slice(0,r);let o=[];for(let t of e){let e=function(e,t){let r=e.path.toLowerCase(),n=0;if(t.includes("/"))r===t?n=100:r.startsWith(t)?n=80:r.includes(t)?n=50:tw(t,r)&&(n=10);else{let e=r.lastIndexOf("/"),o=-1===e?r:r.slice(e+1);o===t?n=100:o.startsWith(t)?n=80:o.includes(t)?n=50:r.includes(t)?n=30:tw(t,r)&&(n=10)}return e.isDir&&n>0&&(n+=10),n}(t,n);e>0&&o.push({entry:t,score:e})}return o.sort((e,t)=>t.score-e.score||tj(e.entry.path)-tj(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),o.slice(0,r).map(e=>e.entry)}(ek.entries,e1):[],[e1,ek,D]),e4=!!(e1&&ek?.truncated&&ek.cwd===D);(0,o.useEffect)(()=>{if(!e4||!D||!e1)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(D)}&q=${encodeURIComponent(e1)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>eT({cwd:D,query:e1,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[e4,e1,D]);let e5=e4&&null!==eC&&eC.cwd===D&&eC.query===e1,e6=e5?eC.matches:e2,e8=null===eg?null:`${eg.start}:${+!!eg.quoted}:${eg.query}`;(0,o.useEffect)(()=>{if(null===e8){ev(!1),eb(0);return}ev(!0),eb(0)},[e8]);let e3=null!==eg;(0,o.useEffect)(()=>{if(!e3||!D)return;let e=eN.current;e&&e.cwd===D&&Date.now()-e.fetchedAt<1e4||eF.current===D||(eF.current=D,eS(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(D)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{ej({cwd:D,entries:function(e){let t=new Set;for(let r of e){let e=r.indexOf("/");for(;-1!==e;)t.add(r.slice(0,e)),e=r.indexOf("/",e+1)}let r=[];for(let e of t)r.push({path:e,isDir:!0});for(let t of e)t&&r.push({path:t,isDir:!1});return r.sort((e,t)=>tj(e.path)-tj(t.path)||e.path.localeCompare(t.path)),r}(e.files??[]),truncated:!!e.truncated}),eN.current={cwd:D,fetchedAt:Date.now()}}).catch(()=>{eN.current=null}).finally(()=>{eF.current=null,eS(!1)}))},[e3,D]);let e9=(0,o.useCallback)(e=>{if(!eg)return;let t=eI.current,r=t?.selectionStart??J.length,n=J.slice(0,eg.start),o=J.slice(r);eg.quoted&&o.startsWith('"')&&(o=o.slice(1));let i=function(e,t,r=!1){let n=t?`${e}/`:e,o=r||n.includes(" ");if(t){let e=o?`@"${n}"`:`@${n}`;return{text:e,cursorOffset:o?e.length-1:e.length}}let i=o?`@"${n}" `:`@${n} `;return{text:i,cursorOffset:i.length}}(e.path,e.isDir,eg.quoted),l=n+i.text+o,s=n.length+i.cursorOffset;Y(l),ef(tk(l.slice(0,s))),requestAnimationFrame(()=>{let e=eI.current;e&&(e.focus(),e.setSelectionRange(s,s),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[eg,J]);(0,o.useEffect)(()=>{ey>=e6.length&&eb(Math.max(0,e6.length-1))},[e6.length,ey]),(0,o.useEffect)(()=>{eP.current.length=e6.length},[e6.length]),(0,o.useEffect)(()=>{em&&eP.current[ey]?.scrollIntoView({block:"nearest",inline:"nearest"})},[ey,em]);let e7=(0,o.useCallback)(e=>{let t=`/${e.name} `;Y(t),ep(!1),ex(0),requestAnimationFrame(()=>{let e=eI.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),te=(0,o.useCallback)(e=>{let t=J.trim();if((t||el.length)&&!el.length){if(E?.(),t.startsWith("/")&&$){$(t,"steer"===e?"steer":"followUp",el.length?el:void 0),eV();return}"steer"===e&&r?r(t,el.length?el:void 0):"followup"===e&&i&&i(t,el.length?el:void 0),eV()}},[J,el,$,r,i,eV,E]),tt=(0,o.useCallback)(e=>{let t=eZ.length-1;if(t<0)return 0;if("left"===e)return Math.max(0,eh-1);if("right"===e)return Math.min(t,eh+1);let r=eD.current[eh];if(!r)return"down"===e?Math.min(t,eh+1):Math.max(0,eh-1);let n=r.getBoundingClientRect(),o=n.left+n.width/2,i=n.top+n.height/2,l=-1,s=1/0;for(let r=0;r<=t;r+=1){if(r===eh)continue;let t=eD.current[r];if(!t)continue;let n=t.getBoundingClientRect(),a=n.top+n.height/2-i;if("down"===e?a<=4:a>=-4)continue;let d=1e3*Math.abs(a)+Math.abs(n.left+n.width/2-o);d<s&&(l=r,s=d)}return l>=0?l:"down"===e?Math.min(t,eh+1):Math.max(0,eh-1)},[eZ.length,eh]),tr=(0,o.useCallback)(e=>{let n=e.nativeEvent,o=Date.now()-eB.current<100,s=e$.current||n.isComposing||229===n.keyCode;if("Enter"===e.key&&!e.shiftKey&&(s||o)){o&&e.preventDefault();return}if(eu&&null!==eY){if("ArrowDown"===e.key){e.preventDefault(),ex(tt("down"));return}if("ArrowUp"===e.key){e.preventDefault(),ex(tt("up"));return}if("ArrowRight"===e.key){e.preventDefault(),ex(tt("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),ex(tt("left"));return}if("Escape"===e.key){e.preventDefault(),ep(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&eZ[eh]){e.preventDefault(),e7(eZ[eh]);return}}if(em&&null!==eg&&!s){if("ArrowDown"===e.key){e.preventDefault(),eb(e=>Math.min(Math.max(0,e6.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),eb(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),ev(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&e6[ey]){e.preventDefault(),e9(e6[ey]);return}}if("Escape"===e.key&&!s&&l&&t){e.preventDefault(),t();return}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),l&&(r||i)?te(r?"steer":"followup"):eJ())},[l,r,i,t,eu,eY,eZ,eh,e7,te,eJ,tt,em,eg,e6,ey,e9]),tn=(0,o.useCallback)(()=>{let e=eI.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),to=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.type.startsWith("image/"));t.length&&(e.preventDefault(),e_(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[e_]);(0,o.useEffect)(()=>{if(null===eY){ep(!1),ex(0),eA.current=!1;return}ep(!0),ex(0),!eA.current&&R&&(eA.current=!0,Promise.resolve(R()).catch(()=>{eA.current=!1}))},[eY,R]),(0,o.useEffect)(()=>{eh>=eZ.length&&ex(Math.max(0,eZ.length-1))},[eZ.length,eh]),(0,o.useEffect)(()=>{eD.current.length=eZ.length},[eZ.length]),(0,o.useEffect)(()=>{eu&&eD.current[eh]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eh,eu]);let ti=u&&u.length>0?u.map(e=>({provider:e.provider,modelId:e.id,name:e.name})).sort(tE):Object.entries(c??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})).sort(tE),tl=[];for(let e of ti){let t=tl.find(t=>t.provider===e.provider);t?t.options.push(e):tl.push({provider:e.provider,options:[e]})}let ts=s?ti.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:null,ta=m?Math.max(0,m.tokensBefore-m.estimatedTokensAfter):0,td=m?.reason&&"manual"!==m.reason?`${m.reason[0].toUpperCase()}${m.reason.slice(1)} compacted`:"Compacted",tc=m?`${td} ${tA(m.tokensBefore)} -> ${tA(m.estimatedTokensAfter)} tokens (${tA(ta)} saved)`:null,tu="auto"!==(N=b??"auto")&&w?w[N]??N:N,tp=Object.entries(tM).find(([,e])=>e===(v??"default"))?.[0]??"default";return(0,o.useEffect)(()=>{let e=e=>{eL.current&&!eL.current.contains(e.target)&&eR.current&&!eR.current.contains(e.target)&&G(!1),ez.current&&!ez.current.contains(e.target)&&et(!1),eM.current&&!eM.current.contains(e.target)&&en(!1),eW.current&&!eW.current.contains(e.target)&&ei(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,o.useEffect)(()=>{V||ei(!1)},[V]),(0,n.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:V?16:52},children:[(0,n.jsx)("input",{ref:eE,type:"file",accept:"image/*",multiple:!0,disabled:l,style:{display:"none"},onChange:e=>{e_(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[(C?.steering.length??0)+(C?.followUp.length??0)>0&&(0,n.jsxs)("div",{style:{marginBottom:8,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"5px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 8px 4px 10px"},children:[(0,n.jsxs)("span",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:["Queued \xb7 ",(C?.steering.length??0)+(C?.followUp.length??0)]}),T&&(0,n.jsxs)("button",{onClick:T,title:"Remove all queued messages and put them back into the input box for editing",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,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"9 14 4 9 9 4"}),(0,n.jsx)("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]}),"Recall to input"]})]}),C?.steering.map((e,t)=>(0,n.jsx)(tq,{kind:"steer",text:e},`steer-${t}`)),C?.followUp.map((e,t)=>(0,n.jsx)(tq,{kind:"follow-up",text:e},`followup-${t}`))]}),S&&(0,n.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,n.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,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",S.attempt,"/",S.maxAttempts,")…",S.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",S.errorMessage]})]}),tc&&(0,n.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,n.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,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),tc]}),el.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap"},children:el.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:"1px solid var(--border)",display:"block"}}),(0,n.jsx)("button",{onClick:()=>eq(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,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},t))}),(0,n.jsxs)("div",{style:{position:"relative"},children:[eu&&null!==eY&&(0,n.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(56vh, 460px)"},children:[(0,n.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,n.jsx)("span",{children:L?"Loading commands...":`Slash commands \xb7 ${eX}`}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:"Tab / Enter"})]}),(0,n.jsx)("div",{style:{maxHeight:"calc(min(56vh, 460px) - 34px)",overflowY:"auto",padding:10},children:L||0!==eZ.length?eG.map(e=>(0,n.jsxs)("section",{style:{marginBottom:12},children:[(0,n.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,n.jsx)("span",{children:tN[e.source]}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:8},children:e.items.map(({command:e,index:t})=>{let r=t===eh;return(0,n.jsxs)("button",{ref:e=>{eD.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),e7(e)},onMouseEnter:()=>ex(t),style:{width:"100%",minWidth:0,minHeight:58,display:"flex",flexDirection:"column",gap:4,justifyContent:"center",padding:"9px 10px",border:`1px solid ${r?"var(--accent)":"var(--border)"}`,borderRadius:7,background:r?"var(--bg-selected)":"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",boxShadow:r?"0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent)":"none"},children:[(0,n.jsxs)("span",{style:{fontSize:13,fontFamily:"var(--font-mono)",overflowWrap:"anywhere",wordBreak:"break-word"},children:["/",e.name]}),e.description&&(0,n.jsx)("span",{style:{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",fontSize:11,lineHeight:1.35,color:"var(--text-dim)"},children:e.description})]},`${e.source}:${e.name}`)})})]},e.source)):(0,n.jsx)("div",{style:{padding:"2px 2px 4px",fontSize:12,color:"var(--text-dim)"},children:"No extension, prompt, or skill commands found"})})]}),em&&null!==eg&&(F=ew&&(!ek||ek.cwd!==D),O=1===e6.length?"1 match":`${e6.length} matches`,H=ek?.truncated&&!e5?eg.query?" \xb7 searching all files…":" \xb7 index truncated":"",(0,n.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,n.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,n.jsx)("span",{children:F?"Loading files...":`Files \xb7 ${O}${H}`}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:"Tab / Enter"})]}),(0,n.jsx)("div",{style:{maxHeight:"calc(min(48vh, 400px) - 34px)",overflowY:"auto",padding:4},children:F||0!==e6.length?e6.map((e,t)=>{let r=t===ey,o=e.path.split("/").pop()??e.path,i=e.path.slice(0,e.path.length-o.length);return(0,n.jsxs)("button",{ref:e=>{eP.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),e9(e)},onMouseEnter:()=>eb(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"6px 8px",border:"none",borderRadius:6,background:r?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,fontFamily:"var(--font-mono)"},children:[(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(a,{size:14}):A(o,14)}),(0,n.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[i&&(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:i}),o,e.isDir&&(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,n.jsx)("div",{style:{padding:"6px 8px",fontSize:12,color:"var(--text-dim)"},children:e4&&!e5?"Searching…":"No matching files"})})]})),(0,n.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",background:"var(--bg)",border:`1px solid ${ed?"var(--tool-bg)":l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:14,padding:"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:eI,value:J,onChange:e=>{Y(e.target.value),e0(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;e0(t.value,t.selectionStart)},onKeyDown:tr,onCompositionStart:()=>{e$.current=!0},onCompositionEnd:e=>{e$.current=!1,eB.current=Date.now();let t=e.currentTarget;e0(t.value,t.selectionStart)},onInput:tn,onPaste:to,placeholder:l&&(r||i)?"Steer now / queue follow-up...":l?"Agent is running…":"Message… Type / for commands, @ for files",rows:1,style:{flex:1,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,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>te("steer"),disabled:!eQ,title:el.length?"Image attachments cannot be queued while the agent is running":"Interrupt the current run and inject this message now",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:eQ?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eQ?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eQ?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>te("followup"),disabled:!eQ,title:el.length?"Image attachments cannot be queued while the agent is running":"Queue this message after the agent finishes",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:eQ?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eQ?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eQ?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:eJ,disabled:!J.trim()&&!el.length,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:6,padding:"7px 14px",background:J.trim()||el.length?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:J.trim()||el.length?"#fff":"var(--text-dim)",cursor:J.trim()||el.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:J.trim()||el.length?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]})]}),ed&&(0,n.jsxs)("div",{className:"text-xs px-2 py-1",style:{color:ec?"var(--text-muted)":"var(--accent)",marginTop:4},children:["Shell \xb7 ",ec?"output stays local":"output sent to model"]}),(0,n.jsxs)("div",{style:{marginTop:8,display:V?"grid":"flex",gridTemplateColumns:V?"minmax(0, 1fr) auto":void 0,alignItems:"center",gap:6},children:[(0,n.jsxs)("div",{style:{flex:V?"1 1 auto":"0 0 auto",minWidth:0,display:"flex",alignItems:"center",gap:2},children:[(0,n.jsx)("button",{onClick:()=>eE.current?.click(),disabled:l,title:"Attach image",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:el.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",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=el.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=el.length?"var(--accent)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,n.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),ti.length>0&&ts&&p&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative",flex:V?"1 1 auto":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();Q({top:t.top,left:t.left,width:t.width}),G(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,justifyContent:V?"flex-start":void 0,padding:V?"8px 10px":"8px 12px",height:32,width:V?"100%":void 0,maxWidth:V?"100%":220,overflow:"hidden",background:Z?"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=Z?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:ts})]}),Z&&X&&(_=(U=window.visualViewport?.height??window.innerHeight)-X.top+6,q=Math.max(120,Math.min(X.top-8,.6*U)),K=V?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{left:X.left,width:"max-content",minWidth:X.width},(0,n.jsx)("div",{ref:eR,style:{position:"fixed",bottom:_,...K,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:q,overflowY:"auto"},children:tl.map((e,t)=>(0,n.jsxs)("div",{children:[tl.length>1&&(0,n.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,n.jsxs)("button",{onClick:()=>{G(!1),(!t||d)&&p(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,n.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,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),e.name]},`${e.provider}:${e.modelId}`)})]},e.provider))}))]})]}),!V&&(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsxs)("div",{ref:eW,style:{flex:"0 0 auto",display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:V?0:"auto"},children:[V&&(0,n.jsx)("button",{type:"button",title:eo?void 0:"More controls","aria-label":"More controls","aria-expanded":eo,"aria-hidden":eo||void 0,tabIndex:eo?-1:void 0,onClick:()=>{G(!1),ei(!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:eo?"default":"pointer",fontSize:12,fontWeight:500,visibility:eo?"hidden":"visible",pointerEvents:eo?"none":"auto",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{eo||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{eo||(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)")},children:"More"}),(0,n.jsxs)("div",{style:{display:V?eo?"flex":"none":"flex",alignItems:"center",gap:V?1:2,...V?{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&&k&&(0,n.jsxs)("div",{ref:eM,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&en(e=>!e),disabled:l,title:`Change reasoning level: ${tu}`,"aria-label":"Change reasoning level",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:V?"0 6px":"8px 12px",width:V?"auto":void 0,height:32,background:er?"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=er?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.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,n.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(!V||eo)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:tu})]}),er&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",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:t$.filter(e=>!j||"auto"===e||j.includes(e)).map(e=>{let t=(b??"auto")===e,r=tB[e],o="auto"!==e&&w?w[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{en(!1),t||k(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,n.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,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[i,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),!l&&y&&(0,n.jsxs)("div",{ref:ez,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&et(e=>!e),disabled:l,title:`Change tool preset: ${tp}`,"aria-label":"Change tool preset",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:V?"0 6px":"8px 12px",width:V?"auto":void 0,height:32,background:ee?"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=ee?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.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"})}),(!V||eo)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:tp})]}),ee&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",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:120},children:tz.map(e=>{let t=tM[e],r=(v??"default")===t,o="off"===e?"No tools, read-only":"default"===e?"4 built-in tools":"All built-in tools";return(0,n.jsxs)("button",{onClick:()=>{et(!1),r||y(t)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:r?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.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,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),!l&&h&&(0,n.jsxs)("div",{style:{position:"relative"},children:[f&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,background:"#1f2937",color:"#f87171",fontSize:11,padding:"4px 8px",borderRadius:5,whiteSpace:"nowrap",pointerEvents:"none",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",zIndex:50},children:f}),(0,n.jsx)("button",{onClick:g?x:h,disabled:l&&!g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:V?"0 6px":"8px 12px",width:V?"auto":void 0,height:32,background:g?"rgba(239,68,68,0.08)":"none",border:"none",borderRadius:9,color:g?"#ef4444":"var(--text-muted)",cursor:l&&!g?"not-allowed":"pointer",fontSize:12,opacity:l&&!g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{(!l||g)&&(e.currentTarget.style.background=g?"rgba(239,68,68,0.16)":"var(--bg-hover)",e.currentTarget.style.color=g?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=g?"rgba(239,68,68,0.08)":"none",e.currentTarget.style.color=g?"#ef4444":"var(--text-muted)"},title:g?"Stop compaction":"Compact context","aria-label":g?"Stop compaction":"Compact context",children:g?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}),(!V||eo)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:"Compacting…"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]}),(!V||eo)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:"Compact"})]})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"Stop agent",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,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),void 0!==W&&(0,n.jsx)("button",{onClick:W,title:M?"Disable completion sound":"Enable completion sound","aria-label":M?"Disable completion sound":"Enable completion sound",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:M?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:M?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=M?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=M?"1":"0.55"},children:M?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})}),V&&eo&&(0,n.jsx)("button",{type:"button",title:"Collapse controls","aria-label":"Collapse controls","aria-expanded":!0,onClick:()=>{et(!1),en(!1),ei(!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,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]})]})]})]})});function tV(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function tJ({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(null),v=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),k=(0,o.useRef)(b);k.current=b;let j=(0,o.useCallback)(()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t))},[r]),w=(0,o.useRef)(null),S=(0,o.useCallback)(()=>{w.current||(w.current=setTimeout(()=>{w.current=null;let e=r.current;if(!e)return;let t=e.scrollHeight;if(t<=0)return;let n=i.current,o=[],l=0,s=k.current;for(let r=0;r<s.length;r++){let i=s[r];if("user"!==i.role&&"assistant"!==i.role)continue;let a=n?.[l];if(l++,("user"===i.role||"assistant"===i.role&&(i.content??[]).some(e=>"text"===e.type))&&a){let r=a.getBoundingClientRect(),n=e.getBoundingClientRect(),l=r.top-n.top+e.scrollTop,s=r.height;o.push({topRatio:l/t,heightRatio:s/t,msg:i,index:o.length})}}h(o)},150))},[r,i]);(0,o.useEffect)(()=>{let e=r.current;if(e)return e.addEventListener("scroll",j,{passive:!0}),()=>e.removeEventListener("scroll",j)},[r,j]),(0,o.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{j(),S()},n=new ResizeObserver(t);return n.observe(e),e.firstElementChild&&n.observe(e.firstElementChild),t(),()=>{n.disconnect(),w.current&&(clearTimeout(w.current),w.current=null)}},[r,S,j]),(0,o.useEffect)(()=>{let e=setTimeout(()=>{j(),S()},50);return()=>clearTimeout(e)},[e.length,S,j]);let C=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),T=(0,o.useCallback)(e=>{if(!c)return;v.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;C(r-o);let i=e=>{v.current&&C((e.clientY-t.top)/t.height-o)},s=()=>{v.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,C]),I=y.current?.clientHeight??600,L=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*I-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(I-22,e[t]));return e},[x,p,I]);if(!c)return null;let R=l*(1-a)*100,z=100*a,M=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:T,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),m(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();m((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${R}%`,height:`${z}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=tV(e.msg),r=x&&M===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:o?8:6,height:o?8:6,borderRadius:o?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),o=tV(e.msg),i=M===e.index;return r&&0!==L.length?(0,n.jsx)("div",{style:{position:"absolute",top:L[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function tY(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let r=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{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})??e);return{...e,content:r}}async function tZ(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.data}var tG=r(14755);function tX(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function tQ(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}let t0=new Set(["ArrowUp","ArrowDown","PageUp","PageDown","Home","End"," ","Space","Spacebar"]);class t1 extends Error{constructor(e){super("timeout"===e?"Timed out connecting to the agent event stream. Please try again.":"Failed to connect to the agent event stream. Please try again."),this.status=e,this.name="EventStreamConnectionError"}}function t2(e){return new Promise(t=>setTimeout(t,e))}function t4(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,r)=>r===t?{...e,exiting:!0}:e)}function t5(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:t4(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:t4(e.visible)};case"remove":return function(e,t){let r=e,n=t;for(;n.length>0&&r.length<5;){let[e,...t]=n;r=[...r,e],n=t}return n.length>0&&!r.some(e=>e.exiting)&&(r=t4(r)),{visible:r,pending:n}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function t6(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 t8(e){let t,r=e.content;return"string"==typeof r?JSON.stringify({text:r,images:[]}):Array.isArray(r)?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:r.map(t6).filter(Boolean)}):JSON.stringify({text:"",images:[]})}function t3(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 t9(e,t,r={}){let n={...e,content:t};return r.omitUsage&&(n.usage=void 0),n}function t7({messageCount:e,toolCallCount:t,children:r}){let[i,l]=(0,o.useState)(!1),s=["Process details",`${e} ${1===e?"message":"messages"}`];return t>0&&s.push(`${t} ${1===t?"tool call":"tool calls"}`),(0,n.jsxs)("div",{style:{marginBottom:14},children:[(0,n.jsxs)("button",{type:"button","aria-expanded":i,onClick:()=>l(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:i?"Collapse process details":"Expand process details",children:[(0,n.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:i?"rotate(90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"4 2.5 7.5 6 4 9.5"})}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.join(" \xb7 ")})]}),i&&(0,n.jsx)("div",{style:{marginTop:8},children:r})]})}function re({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:s,onSessionForked:a,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:u,onSystemPromptChange:p,onSessionStatsChange:h,onSessionStatsPanelOpen:x,onContextUsageChange:g,onOpenFile:f}){var m;let v,{soundEnabled:y,onSoundToggle:b,playDoneSound:k,unlockAudio:j}=function(){let[e,t]=(0,o.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),r=(0,o.useRef)(e);(0,o.useEffect)(()=>{r.current=e},[e]);let n=(0,o.useRef)(null),i=(0,o.useCallback)(()=>{if(n.current&&"closed"!==n.current.state)return n.current;try{n.current=new AudioContext}catch{return null}return n.current},[]),l=(0,o.useCallback)((e=!1)=>{if(!e&&!r.current)return;let t=i();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[i]);return{soundEnabled:e,onSoundToggle:(0,o.useCallback)(()=>{let e=!r.current;e&&l(!0),r.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[l]),playDoneSound:(0,o.useCallback)(()=>{if(!r.current)return;let e=i();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((r,n)=>{let o=e.createOscillator(),i=e.createGain();o.connect(i),i.connect(e.destination),o.type="sine",o.frequency.value=r;let l=t+.18*n;i.gain.setValueAtTime(0,l),i.gain.linearRampToValueAtTime(.18,l+.02),i.gain.exponentialRampToValueAtTime(.001,l+.45),o.start(l),o.stop(l+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[i]),unlockAudio:l,soundEnabledRef:r}}(),w=tR(),S=(0,o.useRef)(k);S.current=k;let C=(0,o.useRef)(y);C.current=y;let T=(0,o.useCallback)(()=>{C.current&&S.current(),i?.()},[i]),I=(0,o.useCallback)(e=>{c?.current?.insertIfEmpty(e)},[c]),{loading:L,error:R,messages:z,entryIds:M,streamState:W,agentRunning:E,bashRunning:$,pendingBash:B,modelNames:A,modelList:D,modelThinkingLevels:P,modelThinkingLevelMaps:N,toolPreset:F,thinkingLevel:O,retryInfo:H,contextUsage:U,forkingEntryId:_,isCompacting:q,compactError:K,compactResult:V,displayModel:J,sessionStats:Y,slashCommands:Z,slashCommandsLoading:G,queuedMessages:X,notices:Q,extensionDialog:ee,extensionCustomUi:et,extensionStatuses:er,extensionWidgets:en,respondToExtensionUi:eo,sendExtensionCustomInput:ei,isAutoModelSelection:el,agentPhase:es,isNew:ea,sessionIdRef:ed,messagesEndRef:ec,scrollContainerRef:eu,lastUserMsgRef:ep,handleSend:eh,handleAbort:ex,handleFork:eg,handleNavigate:ef,handleModelChange:em,handleCompact:ev,handleSteer:ey,handleFollowUp:eb,handlePromptWithStreamingBehavior:ek,handleAbortCompaction:eC,handleRecallQueue:eT,handleBuiltinSlashCommand:eI,handleToolPresetChange:eL,handleThinkingLevelChange:eR,loadSlashCommands:ez}=function(e){let{session:t,newSessionCwd:n,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onBranchDataChange:d,onSystemPromptChange:c,onSessionStatsPanelOpen:u}=e,p=null===t&&null!==n,[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(!p),[m,v]=(0,o.useState)(null),[y,b]=(0,o.useState)(null),[k,j]=(0,o.useState)([]),[w,S]=(0,o.useState)([]),[C,T]=(0,o.useReducer)(tX,{isStreaming:!1,streamingMessage:null}),[I,L]=(0,o.useState)(!1),[R,z]=(0,o.useState)(!1),[M,W]=(0,o.useState)(null),[E,$]=(0,o.useState)({}),[B,A]=(0,o.useState)([]),[D,P]=(0,o.useState)({}),[N,F]=(0,o.useState)({}),[O,H]=(0,o.useState)(null),[U,_]=(0,o.useState)(null),[q,K]=(0,o.useState)("default"),[V,J]=(0,o.useState)("auto"),[Y,Z]=(0,o.useState)(null),[G,X]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(null),[et,er]=(0,o.useState)(null),[en,eo]=(0,o.useState)(null),[ei,el]=(0,o.useState)(null),[es,ea]=(0,o.useState)(!1),[ed,ec]=(0,o.useState)(null),[eu,ep]=(0,o.useState)(null),[eh,ex]=(0,o.useState)(null),[eg,ef]=(0,o.useState)([]),[em,ev]=(0,o.useState)(!1),[ey,eb]=(0,o.useReducer)(t5,{visible:[],pending:[]}),[ek,ej]=(0,o.useState)(null),[ew,eS]=(0,o.useState)(null),[eC,eT]=(0,o.useState)(null),[eI,eL]=(0,o.useState)([]),[eR,ez]=(0,o.useState)([]),[eM,eW]=(0,o.useState)({steering:[],followUp:[]}),eE=(0,o.useRef)(null),e$=(0,o.useRef)(t?.id??null),eB=(0,o.useRef)(!1),eA=(0,o.useRef)(!1),eD=(0,o.useRef)(0),eP=(0,o.useRef)(null),eN=(0,o.useRef)(!1),eF=(0,o.useRef)(null),eO=(0,o.useRef)(!1),eH=(0,o.useRef)(!0),eU=(0,o.useRef)(void 0),e_=(0,o.useRef)(0),eq=(0,o.useRef)(0),eK=(0,o.useRef)(null),eV=(0,o.useRef)(null),eJ=(0,o.useRef)(null),eY=(0,o.useRef)(!1),eZ=(0,o.useRef)(0),eG=(0,o.useRef)(null),eX=e.setToolPreset??K,eQ=en??h?.context.model??ei??null,e0=p?O??U:eQ,e1=(0,o.useMemo)(()=>{if(ek)return ek;let e={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},r=0,n=0,o=0,i=0,l=0;for(let t of k){if("user"===t.role&&(n+=1),"toolResult"===t.role&&(i+=1),"assistant"!==t.role)continue;o+=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,r+=s.cost?.total??0)}return(e.total=e.input+e.output+e.cacheRead+e.cacheWrite,0===e.total&&0===k.length)?null:{sessionFile:h?.filePath||void 0,sessionId:e$.current??t?.id??"",sessionName:t?.name,userMessages:n,assistantMessages:o,toolCalls:l,toolResults:i,totalMessages:k.length,tokens:e,cost:r,...G?{contextUsage:G}:{}}},[k,ek,G,h?.filePath,t?.id,t?.name]),e2=(0,o.useCallback)(async(e,t=!1,r=!1)=>{let n=!1;try{t&&f(!0);let o=new URLSearchParams({deferThinking:"1",deferMedia:"1"}),i=await fetch(`/api/sessions/${encodeURIComponent(e)}?${o}`);if(404===i.status)return t&&(x(null),b(null),j([]),v(null)),null;if(!i.ok)throw Error(`HTTP ${i.status}`);let l=await i.json();if(e$.current!==e||(x(l),b(l.leafId),j(l.context.messages),S(l.context.entryIds??[]),eo(null),v(null),l.context.thinkingLevel&&"off"!==l.context.thinkingLevel&&J(l.context.thinkingLevel),n=!0,t&&f(!1),!r))return null;try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(e$.current!==e)return null;let n=r.state;return n?(void 0!==n.contextUsage&&X(n.contextUsage??null),void 0!==n.systemPrompt&&ee(n.systemPrompt??null),void 0!==n.thinkingLevel&&J(n.thinkingLevel??"auto"),void 0!==n.extensionStatuses&&eL(n.extensionStatuses??[]),void 0!==n.extensionWidgets&&ez(n.extensionWidgets??[]),void 0!==n.queuedMessages&&eW(tQ(n.queuedMessages))):r.running||eW({steering:[],followUp:[]}),r}catch(e){return console.error("Failed to load agent state:",e),null}}catch(e){return v(String(e)),null}finally{t&&!n&&f(!1)}},[]),e4=(0,o.useCallback)(async(e,t)=>{try{let r=new URLSearchParams({deferThinking:"1",deferMedia:"1"});t&&r.set("leafId",t);let n=`/api/sessions/${encodeURIComponent(e)}/context?${r}`,o=await fetch(n);if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();j(i.context.messages),S(i.context.entryIds??[])}catch(e){console.error("Failed to load context:",e)}},[]),e5=(0,o.useCallback)(async e=>{try{let t=await tZ(e,{type:"get_tools"});if(t){let{getPresetFromTools:e}=await Promise.resolve().then(r.bind(r,14755));eX(e(t))}}catch(e){console.error("Failed to load tools:",e)}},[eX]),e6=(0,o.useCallback)((e=0,t="(no messages)")=>{let r=e$.current;p&&n&&r&&!eY.current&&(eY.current=!0,l?.({id:r,path:"",cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:e,firstMessage:t}))},[p,n,l]),e8=(0,o.useCallback)(async()=>{if(e$.current||!p||!n)return e$.current;if(eJ.current)return eJ.current;let e=(async()=>{let e=O??U;e&&el(e);let t=(0,tG.xG)(q),r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,type:"ensure_session",toolNames:t,...e?{provider:e.provider,modelId:e.modelId}:{},..."auto"!==V?{thinkingLevel:V}:{}})});if(!r.ok)throw Error(`HTTP ${r.status}`);let o=(await r.json()).sessionId;return e$.current=o,o})();eJ.current=e;try{return await e}finally{eJ.current=null}},[p,n,O,U,q,V]),e3=(0,o.useCallback)(async()=>{let e=e$.current??await e8();if(!e)return ef([]),[];ev(!0);try{let t=await tZ(e,{type:"get_commands"}),r=t?.commands??[];return ef(r),r}catch(e){return console.error("Failed to load slash commands:",e),ef([]),[]}finally{ev(!1)}},[e8]),e9=(0,o.useCallback)(e=>{eE.current&&(eE.current.close(),eE.current=null);let t=new EventSource(`/api/agent/${encodeURIComponent(e)}/events`);return eE.current=t,new Promise(r=>{let n=!1,o=e=>{n||(n=!0,clearTimeout(i),r({status:e,source:t}))},i=setTimeout(()=>o("timeout"),5e3);t.onmessage=e=>{try{let t=JSON.parse(e.data);"connected"===t.type&&o("connected"),eP.current?.(t)}catch{}},t.onerror=()=>{t.readyState===EventSource.CLOSED&&(o("closed"),eE.current===t&&eB.current&&(eE.current=null,setTimeout(()=>{eB.current&&e9(e)},1e3)))}})},[]),e7=(0,o.useCallback)(async e=>{let t=await e9(e);if("connected"!==t.status&&t.source.readyState!==EventSource.OPEN)throw eE.current===t.source&&(eE.current=null),t.source.close(),new t1(t.status)},[e9]),te=(0,o.useCallback)(async(e,t)=>{let r=e$.current;if(eS(t=>t?.id===e.id?null:t),r)try{await tZ(r,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),tt=(0,o.useCallback)(async(e,t)=>{let r=e$.current;if(r)try{await tZ(r,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),tr=(0,o.useCallback)(e=>{let t=e.message.trim();t&&eb({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"}})},[]),tn=(0,o.useCallback)(t=>{switch(t.method){case"select":case"confirm":case"input":case"editor":eS(t);break;case"notify":tr({id:t.id,message:t.message,type:t.notifyType??"info"});break;case"setStatus":eL(e=>{let r=e.filter(e=>e.key!==t.statusKey);return t.statusText?[...r,{key:t.statusKey,text:t.statusText}]:r});break;case"setWidget":ez(e=>{let r=e.filter(e=>e.key!==t.widgetKey);return t.widgetLines?[...r,{key:t.widgetKey,lines:t.widgetLines,placement:t.widgetPlacement??"aboveEditor"}]:r});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":eT(e=>t.closed?e?.id===t.id?null:e:t)}},[tr,e.chatInputRef]),to=(0,o.useCallback)(async(e=e$.current,t)=>{if(void 0===t||eZ.current===t)try{e&&await e2(e)}finally{if(void 0!==t&&eZ.current!==t||(eG.current=null,!eB.current))return;eB.current=!1,L(!1),ex(null),Z(null),T({type:"end"}),i?.()}},[e2,i]),ti=(0,o.useCallback)(async(e,t)=>{await t2(800);let r=Date.now();for(;eB.current&&Date.now()-r<2e4;){if(void 0!==t&&eZ.current!==t)return;try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(r.ok){let n=await r.json(),o=n.state;if(!n.running||!o||!o.isStreaming&&!o.isPromptRunning)return void await to(e,t)}}catch{}await t2(600)}},[to]),tl=(0,o.useCallback)(async e=>{let t=eD.current+1;for(eD.current=t;eA.current&&eD.current===t&&e$.current===e;){await t2(1e3);try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)continue;let n=await r.json();if(n.state?.isBashRunning)continue;if(await e2(e),eD.current!==t||e$.current!==e)return;eA.current=!1,z(!1),W(null);return}catch{}}},[e2]),ts=(0,o.useCallback)(async e=>{if(!eB.current)return;let t=eZ.current;try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)return;let n=await r.json();if(eZ.current!==t)return;let o=n.state;if(ea(o?.isCompacting??!1),eW(tQ(o?.queuedMessages)),n.running&&o&&(o.isStreaming||o.isPromptRunning||o.isCompacting)||!eB.current)return;o&&(void 0!==o.contextUsage&&X(o.contextUsage??null),void 0!==o.systemPrompt&&ee(o.systemPrompt??null),void 0!==o.extensionStatuses&&eL(o.extensionStatuses??[]),void 0!==o.extensionWidgets&&ez(o.extensionWidgets??[])),await to(e,t)}catch{}},[to]);(0,o.useEffect)(()=>{if(!I)return;let e=()=>{let e=e$.current;e&&ts(e)},t=()=>{"visible"===document.visibilityState&&e()},r=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(r),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[I,ts]),(0,o.useEffect)(()=>{eB.current=I},[I]),eP.current=(0,o.useCallback)(e=>{switch(e.type){case"agent_start":eB.current=!0,L(!0),ex({kind:"waiting_model"}),T({type:"start"});break;case"agent_end":if(!eB.current)break;eB.current=!1,L(!1),ex(null),Z(null),T({type:"end"}),e$.current&&(e2(e$.current),fetch(`/api/agent/${encodeURIComponent(e$.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&X(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&ee(e.state.systemPrompt??null),e.state?.extensionStatuses!==void 0&&eL(e.state.extensionStatuses??[]),e.state?.extensionWidgets!==void 0&&ez(e.state.extensionWidgets??[]),eW(tQ(e.state?.queuedMessages))}).catch(()=>{})),i?.();break;case"prompt_done":if(!eB.current)break;to(e$.current);break;case"prompt_error":tr({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":tr({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":{if(!eB.current)break;let t=e.message;if(t?.role==="user")break;t&&T({type:"update",message:tY(t)}),ex(null);break}case"message_end":{if(!eB.current)break;let t=e.message;if(t&&"user"===t.role){let e=tY(t),r=t8(e),n=eG.current;eG.current=null,j(t=>{let o=t[t.length-1];return n&&o?.role==="user"&&t8(o)===n?n===r?t:[...t.slice(0,-1),e]:[...t,e]})}else t&&j(e=>[...e,tY(t)]);T({type:"reset"}),ex({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,r=e.toolName;ex(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r}),{kind:"running_tools",tools:n}});break}case"tool_execution_end":{let t=e.toolCallId;ex(e=>{if(e?.kind!=="running_tools")return e;let r=e.tools.filter(e=>e.id!==t);return 0===r.length?{kind:"waiting_model"}:{kind:"running_tools",tools:r}});break}case"queue_update":eW({steering:[...e.steering??[]],followUp:[...e.followUp??[]]});break;case"auto_retry_start":Z({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":Z(null);break;case"auto_compaction_start":case"compaction_start":ea(!0),ec(null),ep(null);break;case"auto_compaction_end":case"compaction_end":ea(!1),e.errorMessage?(ec(e.errorMessage),ep(null)):!e.aborted&&(ep(t3(e.result,e.reason??"auto")),e$.current&&e2(e$.current));break;case"extension_ui_request":tn(e)}},[tr,to,tn,e2,i]);let ta=(0,o.useCallback)(async(e,r)=>{let o=e.trim();if(!o&&!r?.length||eB.current||eA.current)return;let i=!r?.length&&o.startsWith("/");if(!r?.length&&o.startsWith("!")){let e=o.startsWith("!!"),t=(e?o.slice(2):o.slice(1)).trim();if(!t)return;await eU.current?.(t,e);return}let l=eZ.current+1,s=r?.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()};j(e=>[...e,a]),eG.current=t8(a),eZ.current=l,eB.current=!0,L(!0),ex(i?{kind:"running_command"}:{kind:"waiting_model"}),T({type:"start"}),eO.current=!0,eH.current=!0;let d=r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{let r=null;if(p&&n){let t=e$.current??await eJ.current,n=t??await e8();n&&(r=n,O&&(el(O),t&&await tZ(n,{type:"set_model",provider:O.provider,modelId:O.modelId})),await e7(n),await tZ(n,{type:"prompt",message:e,...d?.length?{images:d}:{}}),e6(1,e))}else t&&(r=t.id,await e7(t.id),await tZ(t.id,{type:"prompt",message:e,...d?.length?{images:d}:{}}));i&&r&&ti(r,l)}catch(e){if(console.error("Failed to send message:",e),e instanceof t1){let t=eG.current;t&&j(e=>{let r=e[e.length-1];return r?.role==="user"&&t8(r)===t?e.slice(0,-1):e}),tr({type:"error",message:e.message})}eG.current=null,eB.current=!1,L(!1),ex(null),T({type:"end"})}},[p,n,O,t,e8,e7,e6,ti,tr]);eU.current=(0,o.useCallback)(async(r,n)=>{if(eB.current||eA.current)return;let o=`${n?"!!":"!"}${r}`;eA.current=!0,W({command:r,excludeFromContext:n}),z(!0);try{let e=e$.current??t?.id??await e8();if(!e)throw Error("Unable to create a session for the shell command");await tZ(e,{type:"bash",command:r,excludeFromContext:n}),await e2(e),e6(1,o)}catch(t){console.error("Failed to execute shell command:",t),tr({type:"error",message:t instanceof Error?t.message:String(t)}),e.chatInputRef?.current?.insertIfEmpty(o)}finally{eA.current=!1,W(null),z(!1)}},[tr,e8,e2,e.chatInputRef,e6,t]);let td=(0,o.useCallback)(async()=>{let e=e$.current;if(e){if(eA.current){try{await tZ(e,{type:"abort_bash"})}catch(e){console.error("Failed to abort bash:",e)}return}try{await tZ(e,{type:"abort"})}catch(e){console.error("Failed to abort:",e)}}},[]),tc=(0,o.useCallback)(async e=>{if(eA.current)return;let t=e$.current;if(t){er(e);try{let{cancelled:r,newSessionId:n}=await tZ(t,{type:"fork",entryId:e})??{};!r&&n&&s?.(n)}catch(e){console.error("Fork failed:",e)}finally{er(null)}}},[s]),tu=(0,o.useCallback)(async e=>{if(eA.current)return;let t=e$.current;t&&(tZ(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),b(e),await e4(t,e))},[e4]),tp=(0,o.useCallback)(async e=>{if(eA.current)return;b(e);let t=e$.current;t&&(await e4(t,e),e&&tZ(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[e4]),th=(0,o.useCallback)(async(e,t)=>{if(p){H({provider:e,modelId:t}),el({provider:e,modelId:t});let r=e$.current??await eJ.current;if(!r)return;try{await tZ(r,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let r=e$.current;if(r)try{await tZ(r,{type:"set_model",provider:e,modelId:t}),eo({provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}},[p,H]),tx=(0,o.useCallback)(async()=>{let e=e$.current;if(e&&!es){ea(!0),ec(null),ep(null);try{let t=await tZ(e,{type:"compact"});ep(t3(t,"manual")),await e2(e,!0)}catch(e){ec(e instanceof Error?e.message:String(e)),ep(null)}finally{ea(!1)}}},[es,e2]),tg=(0,o.useCallback)(async e=>{let r=n??t?.cwd??"",o=r?`/api/models?cwd=${encodeURIComponent(r)}`:"/api/models",i=await fetch(o,e?{signal:e}:void 0);if(!i.ok)throw Error(`HTTP ${i.status}`);let l=await i.json();$(l.models),P(l.thinkingLevels??{}),F(l.thinkingLevelMaps??{});let s=l.modelList??[];if(A(s),p){let e=(l.defaultModel?s.find(e=>e.id===l.defaultModel?.modelId&&e.provider===l.defaultModel?.provider):void 0)??s[0];_(e?{provider:e.provider,modelId:e.id}:null)}},[p,n,t?.cwd]),tf=(0,o.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,r,n=""]=t,o=n.trim(),i=e$.current??await e8(),l=e=>(e.handled&&(e.error?tr({type:"error",message:e.error}):"openSessionStats"!==e.action&&tr({type:"success",message:e.message??"Command completed"})),e);try{switch(r){case"compact":{if(!i||es)return l({handled:!0,error:"No active session to compact"});ea(!0),ec(null),ep(null);let e=await tZ(i,{type:"compact",...o?{customInstructions:o}:{}});return ep(t3(e,"manual")),await e2(i,!0)&&e6(),l({handled:!0,message:"Compacted context"})}case"reload":if(!i)return l({handled:!0,error:"No active session to reload"});return await tZ(i,{type:"reload"}),await Promise.all([e2(i,!1,!0),e5(i),e3(),tg()]),l({handled:!0,message:"Reloaded session resources"});case"name":if(!i)return l({handled:!0,error:"No active session to name"});if(!o)return l({handled:!0,error:"Usage: /name <name>"});return await tZ(i,{type:"set_session_name",name:o}),await e2(i)&&e6(),l({handled:!0,message:`Session renamed to ${o}`});case"session":{if(!i)return l({handled:!0,error:"No active session"});let e=await tZ(i,{type:"get_session_stats"});return e&&ej(e),u?.(),l({handled:!0,action:"openSessionStats"})}case"copy":{if(!i)return l({handled:!0,error:"No active session"});let e=await tZ(i,{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"===r&&ea(!1)}},[tr,e8,es,tg,e2,e3,e5,e6,u]),tm=(0,o.useCallback)(async(e,t)=>{let r=e$.current;if(!r)return;let n=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await tZ(r,{type:"steer",message:e,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to steer:",e)}},[]),tv=(0,o.useCallback)(async(e,t,r)=>{let n=e$.current;if(!n)return;let o=r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await tZ(n,{type:"prompt",message:e,streamingBehavior:t,...o?.length?{images:o}:{}})}catch(e){console.error("Failed to queue prompt:",e)}},[]),ty=(0,o.useCallback)(async(e,t)=>{let r=e$.current;if(!r)return;let n=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await tZ(r,{type:"follow_up",message:e,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to follow up:",e)}},[]),tb=(0,o.useCallback)(async()=>{let e=e$.current;if(e)try{await tZ(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),tk=(0,o.useCallback)(async()=>{let t=e$.current;if(t)try{let r=await tZ(t,{type:"clear_queue"});eW({steering:[],followUp:[]});let n=[...r?.steering??[],...r?.followUp??[]];n.length>0&&e.chatInputRef?.current?.prependText(n.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),tr({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,tr]),tj=(0,o.useCallback)(async e=>{if(J(e),"auto"===e)return;let t=e$.current??await eJ.current;if(t)try{await tZ(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),tw=(0,o.useCallback)(async e=>{let t=(0,tG.xG)(e);eX(e);let r=e$.current??await eJ.current;if(r)try{await tZ(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[eX]),tS=(0,o.useCallback)((e="smooth")=>{eq.current=Date.now()+700,eK.current?.scrollIntoView({behavior:e})},[]),tC=(0,o.useCallback)(()=>{let e=eV.current,t=eF.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;eq.current=Date.now()+700,e.scrollTo({top:r-16,behavior:"smooth"})},[]),tT=(0,o.useCallback)(e=>{e instanceof KeyboardEvent&&(!t0.has(e.key)||e.target instanceof Element&&e.target.closest("input, textarea, [contenteditable='true']"))||(e_.current=Date.now()+1200)},[]),tI=(0,o.useCallback)(()=>{!eB.current||Date.now()<eq.current||Date.now()>e_.current||(eH.current=!1)},[]);return(0,o.useEffect)(()=>(t&&(e$.current=t.id,e2(t.id,!0,!0).then(e=>{e?.running&&(e5(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(eB.current=!0,L(!0),ex(e.state.isStreaming?{kind:"waiting_model"}:{kind:"running_command"}),T({type:"start"}),e9(t.id),!e.state.isStreaming&&e.state.isPromptRunning&&ti(t.id)),e.state?.isBashRunning&&(eA.current=!0,z(!0),tl(t.id))),e?.state&&(void 0!==e.state.isCompacting&&ea(e.state.isCompacting),void 0!==e.state.contextUsage&&X(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&ee(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&J(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&eL(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&ez(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&eW(tQ(e.state.queuedMessages)))})),()=>{eD.current+=1,eE.current?.close(),eE.current=null}),[]),(0,o.useEffect)(()=>{c?.(Q)},[Q,c]),(0,o.useEffect)(()=>{d&&d(h?.tree??[],y,tp)},[h?.tree,y,tp,d]),(0,o.useEffect)(()=>(window.addEventListener("keydown",tT),window.addEventListener("pointerdown",tT,{passive:!0}),()=>{window.removeEventListener("keydown",tT),window.removeEventListener("pointerdown",tT)}),[tT]),(0,o.useEffect)(()=>{let e=eV.current;if(e)return e.addEventListener("wheel",tT,{passive:!0}),e.addEventListener("touchstart",tT,{passive:!0}),e.addEventListener("scroll",tI,{passive:!0}),()=>{e.removeEventListener("wheel",tT),e.removeEventListener("touchstart",tT),e.removeEventListener("scroll",tI)}},[k.length,g,tI,tT]),(0,o.useEffect)(()=>{k.length>0&&(eO.current?(eO.current=!1,eN.current=!0,tC()):eN.current?!eB.current&&eH.current&&tS("smooth"):(eN.current=!0,tS("instant")))},[k.length,I,tS,tC]),(0,o.useEffect)(()=>{let e=new AbortController;return tg(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[tg,a]),(0,o.useEffect)(()=>{if(!ed)return;let e=setTimeout(()=>ec(null),3e3);return()=>clearTimeout(e)},[ed]),(0,o.useEffect)(()=>{if(!eu)return;let e=setTimeout(()=>ep(null),6e3);return()=>clearTimeout(e)},[eu]),(0,o.useEffect)(()=>{if(0===ey.visible.length)return;let e=ey.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{eb({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!ey.visible[0])return;let t=setTimeout(()=>{eb({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[ey.visible]),(0,o.useEffect)(()=>{ej(null)},[k.length,G?.tokens,G?.percent,G?.contextWindow]),{data:h,loading:g,error:m,activeLeafId:y,messages:k,entryIds:w,streamState:C,agentRunning:I,modelNames:E,modelList:B,modelThinkingLevels:D,modelThinkingLevelMaps:N,newSessionModel:O,toolPreset:q,thinkingLevel:V,retryInfo:Y,contextUsage:G,systemPrompt:Q,forkingEntryId:et,isCompacting:es,compactError:ed,compactResult:eu,currentModel:eQ,displayModel:e0,sessionStats:e1,slashCommands:eg,slashCommandsLoading:em,queuedMessages:eM,notices:ey.visible,extensionDialog:ew,extensionCustomUi:eC,extensionStatuses:eI,extensionWidgets:eR,respondToExtensionUi:te,sendExtensionCustomInput:tt,isAutoModelSelection:p&&null===O,agentPhase:eh,isNew:p,sessionIdRef:e$,eventSourceRef:eE,messagesEndRef:eK,scrollContainerRef:eV,lastUserMsgRef:eF,pendingScrollToUserRef:eO,initialScrollDoneRef:eN,handleSend:ta,handleAbort:td,handleFork:tc,handleNavigate:tu,handleModelChange:th,handleCompact:tx,handleSteer:tm,handleFollowUp:ty,handlePromptWithStreamingBehavior:tv,handleAbortCompaction:tb,handleRecallQueue:tk,handleBuiltinSlashCommand:tf,handleToolPresetChange:tw,handleThinkingLevelChange:tj,loadTools:e5,loadSlashCommands:e3,setActiveLeafId:b,setData:x,setMessages:j,dispatch:T,setAgentRunning:L,setForkingEntryId:er,bashRunning:R,pendingBash:M,handleAgentEventRef:eP}}({session:e,newSessionCwd:t,onAgentEnd:T,onSessionCreated:s,onSessionForked:a,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:u,onSystemPromptChange:p,onSessionStatsPanelOpen:x}),eM=E||$;(0,o.useEffect)(()=>{l=eM?ex:null},[eM,ex]);let[eW,eE]=(0,o.useState)(50),e$=(0,o.useRef)(null),eB=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=e$.current,t=eu.current;if(!e||!t)return;let r=new IntersectionObserver(e=>{e[0]?.isIntersecting&&(eB.current=t.scrollHeight-t.scrollTop,eE(e=>(function(e,t=50){return e+t})(e)))},{root:t,threshold:0});return r.observe(e),()=>r.disconnect()},[eW,z.length,eu]),(0,o.useEffect)(()=>{if(null==eB.current)return;let e=eu.current;if(e){var t;t=e.scrollHeight,e.scrollTop=Math.max(0,t-eB.current),eB.current=null}},[eW,eu]);let eA=Y?[Y.sessionId,Y.sessionFile??"",Y.sessionName??"",Y.userMessages,Y.assistantMessages,Y.toolCalls,Y.toolResults,Y.totalMessages,Y.tokens.input,Y.tokens.output,Y.tokens.cacheRead,Y.tokens.cacheWrite,Y.tokens.total,Y.cost??0].join("|"):null,eD=(0,o.useRef)(Y);eD.current=Y,(0,o.useEffect)(()=>{h?.(eD.current)},[eA,h]),(0,o.useEffect)(()=>()=>{h?.(null)},[h]);let eP=U?`${U.percent??"null"}|${U.contextWindow}|${U.tokens??"null"}`:null,eN=(0,o.useRef)(U);eN.current=U,(0,o.useEffect)(()=>{g?.(eN.current)},[eP,g]),(0,o.useEffect)(()=>()=>{g?.(null)},[g]);let{isDragOver:eF,handleDragEnter:eO,handleDragOver:eH,handleDragLeave:eU,handleDrop:e_}=function(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:l,handleDragLeave:(0,o.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,o.useCallback)(e=>{eM||c?.current?.addImages(e)},[eM,c])),eq=(m=z.filter(e=>"user"===e.role||"assistant"===e.role).length,(v=(0,o.useRef)([])).current=Array(m).fill(null).map((e,t)=>v.current[t]??null),v),eK=ea&&0===z.length&&!W.isStreaming&&!eM,eV=e?.cwd??t??void 0,eJ=J?P[`${J.provider}:${J.modelId}`]??null:null,eY=J?N[`${J.provider}:${J.modelId}`]??null:null,eZ=(0,n.jsx)(tK,{ref:c,onSend:eh,onAbort:ex,onSteer:E?ey:void 0,onFollowUp:E?eb:void 0,onPromptWithStreamingBehavior:E?ek:void 0,isStreaming:eM,model:J,isAutoModelSelection:el,modelNames:A,modelList:D,onModelChange:em,onCompact:e||ea?ev:void 0,onAbortCompaction:eC,isCompacting:q,compactError:K,compactResult:V,toolPreset:F,onToolPresetChange:e||ea?eL:void 0,thinkingLevel:O,onThinkingLevelChange:e||ea?eR:void 0,availableThinkingLevels:eJ,thinkingLevelMap:eY,retryInfo:H,queuedMessages:X,onRecallQueue:eT,slashCommands:Z,slashCommandsLoading:G,onLoadSlashCommands:ez,onBuiltinCommand:eI,soundEnabled:y,onSoundToggle:b,onAudioUnlock:j,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t}),eG=en.filter(e=>"belowEditor"!==e.placement),eX=en.filter(e=>"belowEditor"===e.placement);return L?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):R?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:R}):(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:eO,onDragOver:eH,onDragLeave:eU,onDrop:e_,children:[eF&&!eM&&(0,n.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,n.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,n.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,n.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,n.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,n.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,n.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,n.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,n.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,n.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,n.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,n.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,n.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,n.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,n.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),ee&&(0,n.jsx)(ro,{request:ee,onRespond:eo}),et&&(0,n.jsx)(ri,{request:et,onInput:ei}),eK?(0,n.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8",children:(0,n.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,n.jsxs)("div",{className:"mb-3",style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginLeft:16,marginRight:52,fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4,overflow:"hidden"},children:[(0,n.jsx)("span",{style:{fontSize:28,fontWeight:700,letterSpacing:0,color:"var(--text)",flexShrink:0,whiteSpace:"nowrap"},children:"π"}),(0,n.jsx)("span",{style:{fontSize:22,color:"var(--text)",fontWeight:700,letterSpacing:0,flexShrink:0,whiteSpace:"nowrap"},children:"Pi Web"})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["web ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.8.1"]})]}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["pi ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.81.1"]})]})]})]}),(0,n.jsx)(rn,{notices:Q,align:"right"}),eZ]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{style:{position:"absolute",top:12,left:0,right:36*!w,zIndex:40,padding:"0 16px",pointerEvents:"none"},children:(0,n.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,n.jsx)(rn,{notices:Q,floating:!0,align:"right"})})}),(0,n.jsx)("div",{ref:eu,className:"flex-1 overflow-y-auto pt-4 [scrollbar-width:none]",children:(0,n.jsx)("div",{style:{padding:"0 16px"},children:(0,n.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[(0,n.jsx)(rt,{statuses:er}),(0,n.jsx)(rr,{widgets:eG}),(()=>{var t;let r,o,i=new Map;for(let e of z)"toolResult"===e.role&&i.set(e.toolCallId,e);let l=-1;for(let e=z.length-1;e>=0;e--)if("user"===z[e].role){l=e;break}let s=new Map,a=0;z.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&s.set(t,a++)});let d=(t,r={})=>{let o=r.messageOverride??z[t],a="user"===o.role&&t>0&&"assistant"===z[t-1].role?M[t-1]:void 0,d="user"===o.role||"assistant"===o.role,c=s.get(t),u=r.keyPrefix??"message",p=!1;if("assistant"===o.role){p=!0;for(let e=t+1;e<z.length;e++){let t=z[e].role;if("user"===t)break;if("assistant"===t){p=!1;break}}p&&W.isStreaming&&t===z.length-1&&(p=!1)}void 0!==r.showTimestamp&&(p=r.showTimestamp);let h=(0,n.jsx)(e9,{message:o,toolResults:i,modelNames:A,cwd:eV,onOpenFile:f,entryId:M[t],onFork:eM||ea||0===t&&"user"===o.role?void 0:eg,forking:_===M[t],onNavigate:eM?void 0:ef,prevAssistantEntryId:eM?void 0:a,onEditContent:I,showTimestamp:p,prevTimestamp:t>0?z[t-1].timestamp:void 0,sessionId:e?.id??ed.current??void 0},`${u}-view-${t}`);return d&&!1!==r.attachRef&&void 0!==c?(0,n.jsx)("div",{ref:e=>{eq.current[c]=e,t===l&&(ep.current=e)},children:h},`${u}-${t}`):h},c=[];for(let e=0;e<z.length;){if("user"!==z[e].role){c.push(d(e)),e+=1;continue}let t=e,r=t+1;for(;r<z.length&&"user"!==z[r].role;)r+=1;let o=function(e,t,r){for(let o=r-1;o>t;o--){var n;if("assistant"===(n=e[o]).role&&ew(n).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return o}for(let n=r-1;n>t;n--)if(e[n]?.role==="assistant")return n;return -1}(z,t,r);if(-1===o||(eM||W.isStreaming)&&r===z.length&&t===l){for(let e=t;e<r;e++)c.push(d(e));e=r;continue}c.push(d(t));let i=[];for(let e=t+1;e<o;e++)i.push(e);let a=i.filter(e=>{var t;return"assistant"===(t=z[e]).role?ej(t).length>0:"custom"===t.role}),u=z[o],p=ew(u),h=p.processBlocks.length>0?t9(u,p.processBlocks,{omitUsage:!0}):null,x=p.answerBlocks.length>0?t9(u,p.answerBlocks):null,g=a.length+ +!!h;if(g>0){let e=a.map(e=>s.get(e)).find(e=>"number"==typeof e)??(x?void 0:s.get(o)),r=(0,n.jsxs)(t7,{messageCount:g,toolCallCount:function(e,t){let r=0;for(let n of t){let t=e[n];t?.role==="assistant"&&(r+=eS(ej(t)))}return r}(z,a)+eS(p.processBlocks),children:[a.map(e=>d(e,{attachRef:!1,keyPrefix:"process"})),h&&d(o,{attachRef:!1,keyPrefix:"process-final",messageOverride:h,showTimestamp:!1})]});c.push((0,n.jsx)("div",{ref:void 0===e?void 0:t=>{eq.current[e]=t},children:r},`process-group-${t}-${o}`))}x&&c.push(d(o,{messageOverride:x}));for(let e=o+1;e<r;e++)c.push(d(e));e=r}let{startIndex:u,hasMore:p}=(r=Math.min(Math.max(eW,0),Math.max(t=c.length,0)),{startIndex:o=Math.max(0,t-r),hasMore:o>0});return(0,n.jsxs)(n.Fragment,{children:[p&&(0,n.jsxs)("div",{ref:e$,className:"py-3 text-center text-xs text-text-muted",children:["Scroll up to load earlier messages (",u," hidden)"]}),c.slice(u)]})})(),W.isStreaming&&W.streamingMessage&&(0,n.jsx)(e9,{message:W.streamingMessage,isStreaming:!0,modelNames:A,cwd:eV,onOpenFile:f}),E&&!W.streamingMessage&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.name);return 0===t.length?"Running tool...":1===t.length?`Running ${t[0]}...`:t.length<=3?`Running ${t.join(", ")}...`:`Running ${t.slice(0,2).join(", ")} (+${t.length-2})...`}return e?.kind==="waiting_model"?"Waiting for model...":e?.kind==="running_command"?"Running command...":"Thinking..."}(es)})}),$&&!B&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:"Running command..."})}),B&&(0,n.jsx)(e9,{message:{role:"bashExecution",command:B.command,output:"",excludeFromContext:B.excludeFromContext},sessionId:e?.id??ed.current??void 0}),E&&(0,n.jsx)("div",{style:{height:eu.current?eu.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:ec})]})})}),w?null:(0,n.jsx)(tJ,{messages:z,streamingMessage:W.streamingMessage,scrollContainer:eu,messageRefs:eq})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{style:{padding:"0 16px",paddingRight:w?16:52},children:(0,n.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,n.jsx)(rr,{widgets:eX})})}),eZ]})]})]})}function rt({statuses:e}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,maxWidth:"100%",padding:"4px 8px",border:"1px solid color-mix(in srgb, var(--accent) 24%, var(--border))",borderRadius:6,background:"color-mix(in srgb, var(--accent) 7%, var(--bg))",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:e.key}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.text})]},e.key))})}function rr({widgets:e}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:e.map(e=>(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"5px 9px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:e.key}),(0,n.jsx)("pre",{style:{margin:0,padding:"8px 9px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:e.lines.join("\n")})]},e.key))})}function rn({notices:e,floating:t=!1,align:r="left"}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:"right"===r?"flex-end":"stretch",marginBottom:10*!t},children:e.map((r,o)=>{let i="error"===r.type?"#ef4444":"warning"===r.type?"#d97706":"success"===r.type?"#10b981":"var(--accent)";return(0,n.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:10,minHeight:60,height:60,maxHeight:60,marginBottom:6*(o!==e.length-1),overflow:"hidden",borderRadius:14,border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",background:"var(--bg)",color:"var(--text-muted)",width:"fit-content",maxWidth:"min(100%, 620px)",boxShadow:t?"0 1px 2px rgba(15,23,42,0.05), 0 10px 28px -14px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",fontSize:18,lineHeight:1.45,transformOrigin:"top center",animation:r.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"0 12px"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i,flexShrink:0}}),(0,n.jsx)("span",{style:{padding:"14px 0",minWidth:0,maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.message})]},r.id)})})}function ro({request:e,onRespond:t}){let[r,i]=(0,o.useState)("editor"===e.method?e.prefill??"":"");(0,o.useEffect)(()=>{i("editor"===e.method?e.prefill??"":"")},[e]);let l=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:r})};return(0,n.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,n.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,n.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:"extension request"})]}),(0,n.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap"},children:e.message}),"select"===e.method&&(0,n.jsx)("div",{style:{display:"grid",gap:8},children:e.options.map(r=>(0,n.jsx)("button",{onClick:()=>t(e,{value:r}),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:r},r))}),"input"===e.method&&(0,n.jsx)("input",{autoFocus:!0,value:r,placeholder:e.placeholder,onChange:e=>i(e.target.value),onKeyDown:r=>{"Enter"===r.key&&l(),"Escape"===r.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,n.jsx)("textarea",{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:r=>{"Escape"===r.key&&t(e,{cancelled:!0}),(r.metaKey||r.ctrlKey)&&"Enter"===r.key&&l()},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,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.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:"Cancel"}),"confirm"===e.method?(0,n.jsx)("button",{onClick:l,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:"Confirm"}):"select"!==e.method?(0,n.jsx)("button",{onClick:l,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:"Submit"}):null]})]})})}function ri({request:e,onInput:t}){let r=(0,o.useRef)(null),i=(0,o.useRef)(!1),l=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,r=[];for(let n of e){let e=n.replace(ep,""),o=eg(e).trimEnd();if(t.test(o))continue;let i=e,l=ev(i);("│"===l||"┃"===l)&&" "===ev(i=em(i,0))&&(i=em(i,0));let s=function(e){let t=ef(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(i),a=s>=0?ef(i)[s]?.char:void 0;("│"===a||"┃"===a)&&(i=em(i,s)),r.push(function(e){let t=e;for(;;){let e=ef(t),r=e[e.length-1];if(!r||""!==r.char.trim())return t;t=t.slice(0,r.start)+t.slice(r.end)}}(i))}for(;r.length>0&&""===eg(r[0]).trim();)r.shift();for(;r.length>0&&""===eg(r[r.length-1]).trim();)r.pop();return r.length?r:e}(e.lines);return(0,o.useEffect)(()=>{r.current?.focus()},[e.id]),(0,n.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,n.jsxs)("div",{role:"dialog","aria-modal":"true",onClick:e=>{e.target.closest("button")||r.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,n.jsx)("textarea",{ref:r,"aria-label":"Extension terminal input",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,onKeyDown:r=>{if(i.current||r.nativeEvent.isComposing)return;let n=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=eb[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":" ":ey[e.key]??null}(r);n&&(r.preventDefault(),r.stopPropagation(),t(e,n))},onInput:r=>{if(i.current||r.nativeEvent.isComposing)return;let n=r.currentTarget.value;r.currentTarget.value="",n&&t(e,n)},onCompositionStart:()=>{i.current=!0},onCompositionEnd:r=>{i.current=!1;let n=r.currentTarget;queueMicrotask(()=>{let r=n.value;n.value="",r&&t(e,r)})},onPaste:r=>{r.preventDefault();let n=r.clipboardData.getData("text");n&&t(e,`\x1b[200~${n}\x1b[201~`)},style:{position:"absolute",width:1,height:1,padding:0,border:0,opacity:0,pointerEvents:"none"}}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:"Extension panel"}),(0,n.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:"Close"})]}),(0,n.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:(l.length?l:[""]).map((e,t,r)=>{var i;return(0,n.jsxs)(o.Fragment,{children:[(i=`line-${t}`,(function(e){let t,r=[],n={},o=0;for(eu.lastIndex=0;null!==(t=eu.exec(e));)t.index>o&&r.push({text:e.slice(o,t.index),style:n}),n=function(e,t){let r={...e};for(let e=0;e<t.length;e++){let n=t[e];if(0===n)for(let e of Object.keys(r))delete r[e];else if(1===n)r.fontWeight=700;else if(2===n)r.opacity=.65;else if(3===n)r.fontStyle="italic";else if(4===n)r.textDecoration="underline";else if(22===n)delete r.fontWeight,delete r.opacity;else if(23===n)delete r.fontStyle;else if(24===n)delete r.textDecoration;else if(39===n)delete r.color;else if(49===n)delete r.backgroundColor;else if(n>=30&&n<=37)r.color=eh[n-30];else if(n>=90&&n<=97)r.color=ex[n-90];else if(n>=40&&n<=47)r.backgroundColor=eh[n-40];else if(n>=100&&n<=107)r.backgroundColor=ex[n-100];else if((38===n||48===n)&&2===t[e+1]){let[o,i,l]=[t[e+2],t[e+3],t[e+4]];[o,i,l].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===n?r.color=`rgb(${o}, ${i}, ${l})`:r.backgroundColor=`rgb(${o}, ${i}, ${l})`),e+=4}else if((38===n||48===n)&&5===t[e+1]){let o=function(e){if(e>=0&&e<8)return eh[e];if(e>=8&&e<16)return ex[e-8];if(e>=16&&e<=231){let t=e-16,r=Math.floor(t/36),n=Math.floor(t%36/6),o=e=>0===e?0:55+40*e;return`rgb(${o(r)}, ${o(n)}, ${o(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);o&&(38===n?r.color=o:r.backgroundColor=o),e+=2}}return r}(n,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),o=t.index+t[0].length;return o<e.length&&r.push({text:e.slice(o),style:n}),r})(e).map((e,t)=>Object.keys(e.style).length>0?(0,n.jsx)("span",{style:e.style,children:e.text},`${i}-${t}`):e.text)),t<r.length-1?"\n":null]},t)})})]})})}var rl=r(50640);let rs={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"},ra={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 rd(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}let rc={source:"Source",preview:"Preview",diff:"Diff"},ru={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},rp={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 rh({rows:e,stylesheet:t,useInlineStyles:r,wrapLines:o}){return e.map((e,i)=>{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,n.jsxs)("span",{className:"file-source-line",style:{display:"flex",minWidth:"100%"},children:[d&&(0,rl.Ay)({node:d,stylesheet:t,useInlineStyles:r,key:`source-line-number-${i}`}),(0,n.jsx)("span",{className:"file-source-line-content",style:{flex:"1 1 auto",minWidth:0,overflowWrap:o?"anywhere":"normal",whiteSpace:o?"pre-wrap":"pre"},children:c.map((e,n)=>(0,rl.Ay)({node:e,stylesheet:t,useInlineStyles:r,key:`source-token-${i}-${n}`}))})]},`source-line-${i}`)})}function rx(e,t,r,n={}){let o=P(e),i=new URLSearchParams({type:t});for(let[e,t]of(r&&i.set("sessionId",r),Object.entries(n)))void 0!==t&&i.set(e,String(t));return`/api/files/${o}?${i.toString()}`}function rg({filePath:e,sourceSessionId:t}){return(0,n.jsx)("a",{href:rx(e,"download",t),download:N(e),title:"Download file","aria-label":"Download file",className:"file-viewer-icon-button",children:(0,n.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,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})}function rf(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function rm({patch:e}){let t,r=(t=e5(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(!r.some(e=>"unchanged"!==e.type))return(0,n.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"No changes"});let o=new Set(r.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),i=new Set;for(let e of o)for(let t=Math.max(0,e-3);t<=Math.min(r.length-1,e+3);t++)i.add(t);let l=[],s=0;for(;s<r.length;)if(i.has(s)){let e=[];for(;s<r.length&&i.has(s);)e.push(r[s]),s++;l.push({hidden:!1,lines:e})}else{let e=0;for(;s<r.length&&!i.has(s);)e++,s++;l.push({hidden:!0,count:e})}return(0,n.jsx)("div",{className:"file-diff-view",style:{width:"max-content",minWidth:"100%",...ru},children:l.map((e,t)=>{if(e.hidden)return(0,n.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 r=e.lines.map((e,t)=>{let r="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",o="added"===e.type?"+":"removed"===e.type?"-":" ",i="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{className:"file-diff-line",style:{display:"flex",minWidth:"100%",background:r,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,n.jsx)("span",{style:rp,children:"removed"===e.type?e.oldLineNo:e.newLineNo}),(0,n.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:i,userSelect:"none",flexShrink:0,fontWeight:600},children:o}),(0,n.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,n.jsx)("div",{children:r},t)})})}function rv({filePath:e,cwd:t,sourceSessionId:r}){let[i,l]=(0,o.useState)(!1),[s,a]=(0,o.useState)(0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),g=(0,o.useRef)(null),f=N(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{a(0),c(null),p(null),x(null),l(!1),g.current&&(g.current.close(),g.current=null);let t=new EventSource(rx(e,"watch",r));return g.current=t,t.addEventListener("connected",()=>l(!0)),t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&c(t.size)}catch{}a(e=>e+1)}),t.addEventListener("error",()=>l(!1)),t.onerror=()=>l(!1),()=>{t.close(),g.current=null}},[e,r]);let m=rx(e,"read",r,s?{v:s}:void 0),v=null!=d?rf(d):null;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.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,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:O(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:f||"image"}),u&&(0,n.jsxs)("span",{children:[u.w," \xd7 ",u.h]}),v&&(0,n.jsx)("span",{children:v}),(0,n.jsxs)("span",{title:i?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:i?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i?"#4ade80":"var(--border)",display:"inline-block",boxShadow:i?"0 0 4px #4ade80":"none"}}),i?"live":"static"]}),(0,n.jsx)(rg,{filePath:e,sourceSessionId:r})]}),(0,n.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:h?(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13},children:h}):(0,n.jsx)("img",{src:m,alt:e,onLoad:e=>{let t=e.currentTarget;p({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>x("Failed to load image"),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function ry({filePath:e,cwd:t,sourceSessionId:r}){let[i,l]=(0,o.useState)(!1),[s,a]=(0,o.useState)(0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),g=(0,o.useRef)(null),f=N(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{a(0),c(null),p(null),x(null),l(!1),g.current&&(g.current.close(),g.current=null);let t=new EventSource(rx(e,"watch",r));return g.current=t,t.addEventListener("connected",()=>l(!0)),t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&c(t.size)}catch{}p(null),x(null),a(e=>e+1)}),t.addEventListener("error",()=>l(!1)),t.onerror=()=>l(!1),()=>{t.close(),g.current=null}},[e,r]);let m=rx(e,"read",r,s?{v:s}:void 0);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.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,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:O(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:f||"audio"}),null!=u&&(0,n.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),r=Math.floor(t/60);return`${r}:${String(t%60).padStart(2,"0")}`}(u)}),null!=d&&(0,n.jsx)("span",{children:rf(d)}),(0,n.jsxs)("span",{title:i?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:i?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i?"#4ade80":"var(--border)",display:"inline-block",boxShadow:i?"0 0 4px #4ade80":"none"}}),i?"live":"static"]}),(0,n.jsx)(rg,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,n.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[h&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:h}),(0,n.jsx)("audio",{controls:!0,preload:"metadata",src:m,onLoadedMetadata:e=>p(e.currentTarget.duration),onError:()=>x("Failed to load audio"),style:{width:"100%"}},m)]})})]})}function rb({filePath:e,cwd:t,sourceSessionId:r}){let[i,l]=(0,o.useState)(!1),[s,a]=(0,o.useState)(0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),h=(0,o.useRef)(null),x=rd(e),g="pdf"===x,f=g?rx(e,"read",r,s?{v:s}:void 0):rx(e,"preview",r,s?{v:s}:void 0);return(0,o.useEffect)(()=>{a(0),c(null),p(null),l(!1),h.current&&(h.current.close(),h.current=null),fetch(rx(e,"meta",r)).then(e=>e.json()).then(e=>{e.error&&p(e.error),"number"==typeof e.size&&(c(e.size),!g&&e.size>0xa00000&&p("DOCX too large for preview (>10MB)"))}).catch(e=>p(String(e)));let t=new EventSource(rx(e,"watch",r));return h.current=t,t.addEventListener("connected",()=>l(!0)),t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(c(t.size),!g&&t.size>0xa00000))return void p("DOCX too large for preview (>10MB)")}catch{}p(null),a(e=>e+1)}),t.addEventListener("error",()=>l(!1)),t.onerror=()=>l(!1),()=>{t.close(),h.current=null}},[e,g,r]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.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,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:O(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===x?"docx preview":"pdf"}),null!=d&&(0,n.jsx)("span",{children:rf(d)}),(0,n.jsx)(rg,{filePath:e,sourceSessionId:r}),(0,n.jsxs)("span",{title:i?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:i?"#4ade80":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i?"#4ade80":"var(--border)",display:"inline-block",boxShadow:i?"0 0 4px #4ade80":"none"}}),i?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:u?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:u}):(0,n.jsx)("iframe",{src:f,sandbox:g?void 0:"",title:`Preview ${N(e)}`,style:{width:"100%",height:"100%",border:"none",background:g?"var(--bg)":"#eef1f5"}},f)})]})}function rk({filePath:e,cwd:t,sourceSessionId:r,onOpenFile:o,gitRefreshKey:i}){let l;return null!==(rs[rd(e)]??null)?(0,n.jsx)(rv,{filePath:e,cwd:t,sourceSessionId:r}):null!==(ra[rd(e)]??null)?(0,n.jsx)(ry,{filePath:e,cwd:t,sourceSessionId:r}):null!==("pdf"===(l=rd(e))||"docx"===l?l:null)?(0,n.jsx)(rb,{filePath:e,cwd:t,sourceSessionId:r}):(0,n.jsx)(rj,{filePath:e,cwd:t,sourceSessionId:r,onOpenFile:o,gitRefreshKey:i})}function rj({filePath:e,cwd:t,sourceSessionId:r,onOpenFile:i,gitRefreshKey:l}){let{isDark:s}=eA(),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!0),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)("source"),[v,y]=(0,o.useState)(!1),[b,k]=(0,o.useState)(!1),j=(0,o.useRef)(null),w=(0,o.useRef)(0),S=(0,o.useCallback)(e=>fetch(rx(e,"read",r)).then(e=>e.json()).then(e=>e.error?(g(e.error),null):(g(null),d(e),e)).catch(e=>(g(String(e)),null)),[r]),C=(0,o.useCallback)(async e=>{let r=++w.current;if(!t)return void u(null);try{let n=new URLSearchParams({cwd:t,path:e}),o=await fetch(`/api/git/diff?${n.toString()}`),i=await o.json();if(r!==w.current)return;u(o.ok&&i.supported&&"string"==typeof i.patch?i:null)}catch{r===w.current&&u(null)}},[t]);(0,o.useEffect)(()=>{h(!0),g(null),d(null),u(null),m("source"),y(!1),k(!1),j.current&&(j.current.close(),j.current=null),S(e).then(e=>{e?.language==="markdown"&&m("preview")}).finally(()=>h(!1));let t=new EventSource(rx(e,"watch",r));return j.current=t,t.addEventListener("connected",()=>{k(!0)}),t.addEventListener("change",()=>{S(e),C(e)}),t.addEventListener("error",()=>{k(!1)}),t.onerror=()=>{k(!1)},()=>{t.close(),j.current=null}},[e,S,C,r]),(0,o.useEffect)(()=>{C(e)},[C,e,l]);let T=c?.supported===!0&&"string"==typeof c.patch;if((0,o.useEffect)(()=>{T||"diff"!==f||m("source")},[f,T]),p)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading..."});if(x)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:x});if(!a)return null;let I="html"===a.language,L="markdown"===a.language,R=F(e),z=a.content.split("\n"),M=["source",...I||L?["preview"]:[],...T?["diff"]:[]],W=`${a.language} \xb7 ${z.length} lines \xb7 ${rf(a.size)}`;return(0,n.jsxs)("div",{className:"file-viewer-shell",style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.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,n.jsx)("span",{className:"file-viewer-path",style:{fontFamily:"var(--font-mono)"},title:e,children:O(e,t)}),(0,n.jsx)("span",{className:"file-viewer-meta",title:W,children:W}),(0,n.jsx)("span",{title:b?"Live sync active":"Not watching","aria-label":b?"Live sync active":"Not watching",className:"file-viewer-live-indicator",style:{background:b?"#4ade80":"var(--border)",boxShadow:b?"0 0 4px #4ade80":"none"}}),(0,n.jsxs)("div",{className:"file-viewer-controls",children:[M.length>1&&(0,n.jsx)("div",{className:"file-viewer-mode-switch","aria-label":"File view mode",children:M.map(e=>{let t=f===e;return(0,n.jsx)("button",{type:"button",onClick:()=>m(e),title:"diff"===e?"Compare working tree with HEAD":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:rc[e]},e)})}),(0,n.jsx)("div",{className:"file-viewer-action-slot",children:"source"===f&&(0,n.jsx)("button",{type:"button",onClick:()=>y(e=>!e),title:v?"Disable word wrap":"Enable word wrap","aria-label":v?"Disable word wrap":"Enable word wrap","aria-pressed":v,className:"file-viewer-icon-button",style:{background:v?"var(--bg-selected)":"transparent",color:v?"var(--text)":"var(--text-muted)"},children:(0,n.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,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M3 12h15a3 3 0 1 1 0 6h-4"}),(0,n.jsx)("path",{d:"m16 16-2 2 2 2"}),(0,n.jsx)("path",{d:"M3 18h7"})]})})}),(0,n.jsx)(rg,{filePath:e,sourceSessionId:r})]})]}),(0,n.jsx)("div",{className:"file-viewer-content",style:{flex:1,overflow:"auto",background:"var(--bg)"},children:"diff"===f&&T?(0,n.jsx)(rm,{patch:c.patch}):I&&"preview"===f?(0,n.jsx)("iframe",{srcDoc:a.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:"HTML preview"}):L&&"preview"===f?(0,n.jsx)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:(0,n.jsx)(eC.oz,{remarkPlugins:eZ,rehypePlugins:eX,components:{a({href:e,children:r,...o}){delete o.node;let l=i?eO(e,R,t??R):null;return l&&i?(0,n.jsx)("a",{href:e,...o,onClick:e=>{e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),i(l))},children:r}):(0,n.jsx)("a",{href:e,...o,children:r})}},children:a.content})}):(0,n.jsx)(eT.A,{className:v?"file-source-view is-wrapped":"file-source-view",language:"text"===a.language?"plaintext":a.language,style:s?eI.xJ:eI.vs,showLineNumbers:!0,lineNumberStyle:{...rp},customStyle:{margin:0,padding:0,border:0,background:"var(--bg)",...ru,width:v?"100%":"max-content",minWidth:"100%",minHeight:"100%",overflow:"visible"},codeTagProps:{style:{fontFamily:"var(--font-mono)",overflowWrap:v?"anywhere":"normal"}},renderer:e=>(0,n.jsx)(rh,{...e,wrapLines:v}),wrapLongLines:v,children:a.content})})]})}function rw({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i}){let[l,s]=(0,o.useState)(null);return(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let o=e.id===t;return(0,n.jsxs)("div",{onClick:()=>r(e.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:t=>{1===t.button&&(t.preventDefault(),t.stopPropagation(),i(e.id))},style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:o?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:o?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,n.jsx)("span",{style:{flexShrink:0,opacity:o?1:.7,display:"flex",alignItems:"center"},children:A(e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:o?500:400},title:e.filePath,children:e.label}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},onMouseEnter:()=>s(e.id),onMouseLeave:()=>s(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,background:l===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:4,color:l===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:"Close","aria-label":`Close ${e.label}`,children:(0,n.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,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id)})})}var rS=r(67381),rC=r(64433),rT=r(70350),rI=r(88195),rL=r(9312),rR=r(87275),rz=r(22008),rM=r(95476),rW=r(35029),rE=r(14489),r$=r(78728),rB=r(19872),rA=r(7751),rD=r(92526),rP=r(48238),rN=r(57794),rF=r(41098),rO=r(84604),rH=r(15315),rU=r(74278),r_=r(55457),rq=r(71437),rK=r(29167),rV=r(97283),rJ=r(34166),rY=r(33889),rZ=r(85486),rG=r(74068),rX=r(83546),rQ=r(83709);let r0={anthropic:{Icon:rS.A,hasColor:!1},openai:{Icon:rC.A,hasColor:!1},"openai-codex":{Icon:rC.A,hasColor:!1},google:{Icon:rT.A,hasColor:!0},"google-vertex":{Icon:rT.A,hasColor:!0},"ant-ling":{Icon:rY.A,hasColor:!0},deepseek:{Icon:rI.A,hasColor:!0},groq:{Icon:rL.A,hasColor:!1},mistral:{Icon:rR.A,hasColor:!0},moonshotai:{Icon:rz.A,hasColor:!1},"moonshotai-cn":{Icon:rz.A,hasColor:!1},moonshot:{Icon:rz.A,hasColor:!1},minimax:{Icon:rM.A,hasColor:!0},"minimax-cn":{Icon:rM.A,hasColor:!0},fireworks:{Icon:rW.A,hasColor:!0},huggingface:{Icon:rE.A,hasColor:!0},cerebras:{Icon:r$.A,hasColor:!0},openrouter:{Icon:rB.A,hasColor:!1},xai:{Icon:rA.A,hasColor:!1},"cloudflare-ai-gateway":{Icon:rD.A,hasColor:!0},"cloudflare-workers-ai":{Icon:rD.A,hasColor:!0},"vercel-ai-gateway":{Icon:rP.A,hasColor:!1},"github-copilot":{Icon:rN.A,hasColor:!1},"amazon-bedrock":{Icon:rF.A,hasColor:!0},"azure-openai-responses":{Icon:rO.A,hasColor:!0},"kimi-coding":{Icon:rH.A,hasColor:!0},nvidia:{Icon:rZ.A,hasColor:!0},opencode:{Icon:rG.A,hasColor:!1},"opencode-go":{Icon:rG.A,hasColor:!1},qwen:{Icon:rU.A,hasColor:!0},xiaomi:{Icon:rX.A,hasColor:!1},"xiaomi-token-plan-ams":{Icon:rX.A,hasColor:!1},"xiaomi-token-plan-cn":{Icon:rX.A,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:rX.A,hasColor:!1},zai:{Icon:rQ.A,hasColor:!1},"zai-coding-cn":{Icon:rQ.A,hasColor:!1},zhipu:{Icon:r_.A,hasColor:!0},cohere:{Icon:rq.A,hasColor:!0},perplexity:{Icon:rK.A,hasColor:!0},together:{Icon:rV.A,hasColor:!0},grok:{Icon:rJ.A,hasColor:!1}},r1=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function r2({label:e,children:t}){return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}let r4={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 r5({value:e,onChange:t,placeholder:r,mono:o}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:r,style:{...r4,fontFamily:o?"var(--font-mono)":"inherit"}})}function r6({value:e,onChange:t,placeholder:r,mono:i,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{e||u(!1)},[e]),(0,n.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,n.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:r,style:{...r4,paddingRight:34,fontFamily:i?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,n.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":c?"Hide API key":"Show API key",title:c?"Hide API key":"Show API key",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,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.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,n.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,n.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,n.jsx)("path",{d:"M1 1l22 22"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function r8({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:r4})}function r3({value:e,onChange:t,options:r,required:o}){return(0,n.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...r4,color:e?"var(--text)":"var(--text-dim)"},children:[!o&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),r.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function r9({label:e,checked:t,onChange:r}){return(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:t,onChange:e=>r(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function r7({children:e}){return(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:e})}function ne({name:e,provider:t,onChange:r,onRename:i,onDelete:l}){let[s,a]=(0,o.useState)(e);(0,o.useEffect)(()=>a(e),[e]);let d=(e,n)=>r({...t,[e]:n});return(0,o.useEffect)(()=>{t.api||r({...t,api:"openai-completions"})},[t.api]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(r7,{children:"Provider"}),(0,n.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:"Delete"})]}),(0,n.jsxs)(r2,{label:"Provider name",children:[(0,n.jsx)(r5,{value:s,onChange:a,placeholder:"provider-name",mono:!0}),s!==e&&s.trim()&&(0,n.jsx)("button",{onClick:()=>i(s.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:"Rename"})]}),(0,n.jsx)(r2,{label:"Base URL",children:(0,n.jsx)(r5,{value:t.baseUrl??"",onChange:e=>d("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(r2,{label:"API Key",children:[(0,n.jsx)(r6,{value:t.apiKey??"",onChange:e=>d("apiKey",e||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,n.jsx)(r2,{label:"API",children:(0,n.jsx)(r3,{value:t.api??"openai-completions",onChange:e=>d("api",e),options:r1,required:!0})})]})}let nt=["off","minimal","low","medium","high","xhigh","max"],nr={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function nn({value:e,onChange:t}){let r=e??{},o=(e,n)=>{let o={...r};"omit"===n?delete o[e]:o[e]=n,t(Object.keys(o).length?o:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:nt.map(e=>{let t=r[e],i=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=nr[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,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:s,flexShrink:0,opacity:"null"===i?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===i?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===i?"line-through":"none"},children:e})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>o(e,"omit"),style:{...a,..."omit"===i?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>o(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===i?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===i?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>o(e,l||e),style:{...a,..."string"===i?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>o(e,t.target.value),onFocus:()=>{"string"!==i&&o(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===i?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===i?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let no={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function ni({providerName:e,provider:t,model:r,onChange:i,onDelete:l}){let[s,a]=(0,o.useState)({phase:"idle"}),d=(e,t)=>i({...r,[e]:t}),c=(()=>{if("idle"===s.phase)return null;if("testing"===s.phase)return"Testing model connection...";let e=[void 0!==s.latencyMs?`${s.latencyMs}ms`:null,void 0!==s.status?`HTTP ${s.status}`:null].filter(Boolean);return"success"===s.phase?["Connected",...e,s.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...e,s.message].filter(Boolean).join(" \xb7 ")})();(0,o.useEffect)(()=>{a({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]);let u=(0,o.useCallback)(async()=>{if(r.id.trim()&&"testing"!==s.phase){a({phase:"testing"});try{let n=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:r})}),o=await n.json();if(!n.ok||!o.ok)return void a({phase:"error",message:o.error??`HTTP ${n.status}`,latencyMs:o.latencyMs,status:o.status});a({phase:"success",latencyMs:o.latencyMs,status:o.status,responseText:o.responseText})}catch(e){a({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[r,t,e,s.phase]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(r7,{children:"Model"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[c&&(0,n.jsx)("span",{title:c,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:c}),(0,n.jsxs)("button",{onClick:u,disabled:!r.id.trim()||"testing"===s.phase,title:"Test model connection",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":r.id.trim()&&"testing"!==s.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.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,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===s.phase?"Testing…":"success"===s.phase?"OK":"Test"]}),(0,n.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:"Remove"})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(r2,{label:"ID *",children:(0,n.jsx)(r5,{value:r.id,onChange:e=>d("id",e),placeholder:"model-id",mono:!0})}),(0,n.jsx)(r2,{label:"Name",children:(0,n.jsx)(r5,{value:r.name??"",onChange:e=>d("name",e||void 0),placeholder:"Display name"})})]}),(0,n.jsx)(r2,{label:"API override",children:(0,n.jsx)(r3,{value:r.api??"",onChange:e=>d("api",e||void 0),options:r1})}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(r9,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(r9,{label:"Image input",checked:r.input?.includes("image")??!1,onChange:e=>d("input",e?["text","image"]:void 0)})]}),r.reasoning&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r9,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>i(function(e,t){if(t)return{...e,compat:{...e.compat??{},...no}};if(!e.compat)return e;let r={...e.compat};return delete r.thinkingFormat,delete r.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(r).length?r:void 0}}(r,e))}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,n.jsx)(r7,{children:"Thinking level map"}),r.thinkingLevelMap&&(0,n.jsx)("button",{onClick:()=>d("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 7px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",cursor:"pointer"},children:"clear all"})]}),(0,n.jsx)(nn,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(r2,{label:"Context window (tokens)",children:(0,n.jsx)(r8,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(r2,{label:"Max output tokens",children:(0,n.jsx)(r8,{value:void 0!==r.maxTokens?String(r.maxTokens):"",onChange:e=>d("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(r7,{children:"Cost (per million tokens)"}),(0,n.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:8},children:["input","output","cacheRead","cacheWrite"].map(e=>(0,n.jsx)(r2,{label:e,children:(0,n.jsx)(r8,{value:r.cost?.[e]!==void 0?String(r.cost[e]):"",onChange:t=>{let n;return n=parseFloat(t),void i({...r,cost:{...r.cost??{},[e]:isNaN(n)?void 0:n}})},placeholder:"0"})},e))})]})]})}function nl({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)({phase:"idle"}),[l,s]=(0,o.useState)(""),a=(0,o.useRef)(null),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>d.current?.focus(),50)},[r.phase]),(0,o.useEffect)(()=>{i({phase:"idle"}),s(""),a.current?.close(),a.current=null},[e.id]),(0,o.useEffect)(()=>()=>{a.current?.close()},[]);let c=(0,o.useCallback)(()=>{a.current?.close(),i({phase:"connecting"}),s("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);a.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(i({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(i({phase:"device_code",userCode:n.userCode,verificationUri:n.verificationUri,intervalSeconds:n.intervalSeconds??null,expiresInSeconds:n.expiresInSeconds??null}),window.open(n.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===n.type?i({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?i({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?i({phase:"progress",message:n.message}):"success"===n.type?(r.close(),i({phase:"success"}),t()):"error"===n.type?(r.close(),i({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),i({phase:"idle"}))},r.onerror=()=>{r.close(),i(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),u=(0,o.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),i({phase:"idle"}),t()},[e.id,t]),p=(0,o.useCallback)(async(t,r)=>{if(r.trim()){i({phase:"progress",message:"Verifying…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r.trim()})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`});return}s("")}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),h=(0,o.useCallback)(async(t,r)=>{i({phase:"progress",message:"Continuing…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r})});if(!n.ok){let e=await n.json().catch(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),x="connecting"===r.phase||"progress"===r.phase||"auth"===r.phase||"device_code"===r.phase||"prompt"===r.phase||"select"===r.phase;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(r7,{children:"Subscription"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:e.loggedIn?"connected":"not connected"})]})]}),(0,n.jsxs)("div",{style:{minHeight:48},children:["idle"===r.phase&&(0,n.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"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:r.message}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.options.map(e=>(0,n.jsx)("button",{onClick:()=>h(r.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"===r.phase||"prompt"===r.phase)&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===r.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":r.message}),"auth"===r.phase&&(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,n.jsx)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{ref:d,value:l,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p(r.token,l)},placeholder:"auth"===r.phase?"http://localhost:1455/auth/callback?code=…":r.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,n.jsx)("button",{onClick:()=>p(r.token,l),disabled:!l.trim(),style:{padding:"6px 12px",background:l.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:l.trim()?"#fff":"var(--text-dim)",cursor:l.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,n.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:r.userCode}),(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsx)("a",{href:r.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:r.verificationUri}),r.expiresInSeconds?` Expires in ${Math.ceil(r.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:r.message}),"success"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."}),"error"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:r.message})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:x?(0,n.jsx)("button",{onClick:()=>{a.current?.close(),i({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:c,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:e.loggedIn?"Re-login":"Login"}),e.loggedIn&&(0,n.jsx)("button",{onClick:u,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:"Disconnect"})]})})]})}function ns({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{i(""),u(null),h(!1)},[e.id]);let x=(0,o.useCallback)(async()=>{if(r.trim()){s(!0),u(null),h(!1);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r.trim()})}),o=await n.json();!n.ok||o.error?u(o.error??`HTTP ${n.status}`):(i(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[r,e.id,t]),g=(0,o.useCallback)(async()=>{d(!0),u(null);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),n=await r.json();!r.ok||n.error?u(n.error??`HTTP ${r.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(r7,{children:"API Key"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.configured?"#4ade80":"var(--text-dim)"},children:e.configured?"configured":"not configured"})]})]}),(0,n.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,n.jsx)(r2,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(r6,{value:r,onChange:i,onKeyDown:e=>{"Enter"===e.key&&r.trim()&&x()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,n.jsxs)("button",{onClick:x,disabled:l||!r.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":r.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:r.trim()||p?"#fff":"var(--text-dim)",cursor:l||!r.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),p?"Saved":l?"Saving…":"Save"]})]})}),c&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,n.jsx)("button",{onClick:g,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:a?"Removing…":"Disconnect"})]})}function na({id:e,size:t}){let r=r0[e];if(!r){let r=e.split(/[-_]/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?";return(0,n.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:r})}return r.hasColor?(0,n.jsx)(r.Icon,{size:t}):(0,n.jsx)(r.Icon,{size:t,style:{color:"var(--text-muted)"}})}function nd({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:i,onAddCustom:l,onClose:s}){let[a,d]=(0,o.useState)(""),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{setTimeout(()=>c.current?.focus(),30)},[]);let u=a.trim().toLowerCase(),p=e.filter(e=>!e.loggedIn&&(!u||e.name.toLowerCase().includes(u))),h=t.filter(e=>!e.configured&&(!u||e.displayName.toLowerCase().includes(u)||e.id.toLowerCase().includes(u))),x=!u||"custom".includes(u)||"openai-compatible".includes(u)||"anthropic-compatible".includes(u),g=p.length+h.length+ +!!x,f={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,n.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,n.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,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,n.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,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,n.jsx)("input",{ref:c,value:a,onChange:e=>d(e.target.value),onKeyDown:e=>{"Escape"===e.key&&s()},placeholder:"Search providers…",style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===g?(0,n.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:"No providers match"}):(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[x&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),x&&(0,n.jsxs)("button",{onClick:()=>{l(),s()},style:f,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,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Custom endpoint format"})]}),(0,n.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,n.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,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),p.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!x,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),p.map(e=>(0,n.jsxs)("button",{onClick:()=>{r(e.id),s()},style:f,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,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,n.jsx)(na,{id:e.id,size:28})]},e.id)),h.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(p.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),h.map(e=>(0,n.jsxs)("button",{onClick:()=>{i(e.id),s()},style:f,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,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,n.jsx)(na,{id:e.id,size:28})]},e.id))]})})]})})}function nc({onClose:e}){let t=tR(),[r,i]=(0,o.useState)({providers:{}}),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)([]),[v,y]=(0,o.useState)([]),[b,k]=(0,o.useState)(!1),j=(0,o.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>m(e.providers)).catch(()=>{})},[]),w=(0,o.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>y(e.providers)).catch(()=>{})},[]);(0,o.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};i(t);let r=Object.keys(t.providers??{});r.length>0&&g({type:"provider",name:r[0]})}).catch(()=>i({providers:{}})).finally(()=>s(!1)),j(),w()},[j,w]);let S=(0,o.useCallback)(()=>{let e="new-provider",t=1;for(;r.providers?.[e];)e=`new-provider-${t++}`;i(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),g({type:"provider",name:e})},[r.providers]),C=(0,o.useCallback)((e,t)=>{i(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),T=(0,o.useCallback)((e,t)=>{i(r=>{let n=Object.entries(r.providers??{}),o=n.findIndex(([t])=>t===e);return -1===o?r:(n[o]=[t,n[o][1]],{...r,providers:Object.fromEntries(n)})}),g(r=>r?"provider"===r.type&&r.name===e?{type:"provider",name:t}:"model"===r.type&&r.providerName===e?{...r,providerName:t}:r:r)},[]),I=(0,o.useCallback)(e=>{i(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),i(e=>{let t=Object.keys(e.providers??{});return g(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),L=(0,o.useCallback)(e=>{i(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),i(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return g({type:"model",providerName:e,index:r}),t})},[]),R=(0,o.useCallback)((e,t,r)=>{i(n=>{let o=n.providers?.[e]??{},i=[...o.models??[]];return i[t]=r,{...n,providers:{...n.providers??{},[e]:{...o,models:i}}}})},[]),z=(0,o.useCallback)((e,t)=>{i(r=>{let n=r.providers?.[e]??{},o=[...n.models??[]];return o.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:o.length?o:void 0}}}}),g({type:"provider",name:e})},[]),M=(0,o.useCallback)(async()=>{d(!0),u(null),h(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),t=await e.json();!e.ok||t.error?u(t.error??`HTTP ${e.status}`):(h(!0),setTimeout(()=>h(!1),2e3))}catch(e){u(String(e))}finally{d(!1)}},[r]),W=Object.entries(r.providers??{}),E=f.filter(e=>e.loggedIn),$=v.filter(e=>e.configured),B=(()=>{if(!x)return null;if("oauth"===x.type){let e=f.find(e=>e.id===x.providerId);return e?(0,n.jsx)(nl,{provider:e,onRefresh:j},e.id):null}if("apikey"===x.type){let e=v.find(e=>e.id===x.providerId);return e?(0,n.jsx)(ns,{provider:e,onRefresh:w},e.id):null}if("provider"===x.type){let e=r.providers?.[x.name];return e?(0,n.jsx)(ne,{name:x.name,provider:e,onChange:e=>C(x.name,e),onRename:e=>T(x.name,e),onDelete:()=>I(x.name)},x.name):null}let e=r.providers?.[x.providerName],t=e?.models?.[x.index];return t?(0,n.jsx)(ni,{providerName:x.providerName,provider:e,model:t,onChange:e=>R(x.providerName,x.index,e),onDelete:()=>z(x.providerName,x.index)},`${x.providerName}-${x.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.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,n.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,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Models"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,n.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,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:t?"column":"row",overflow:"hidden"},children:[(0,n.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,n.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[E.map(e=>{let t=x?.type==="oauth"&&x.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>g({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,n.jsx)(na,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),$.map(e=>{let t=x?.type==="apikey"&&x.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>g({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,n.jsx)(na,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(E.length>0||$.length>0)&&W.length>0&&(0,n.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),l?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):W.map(([e,t])=>{let r=x?.type==="provider"&&x.name===e,o=t.models??[];return(0,n.jsxs)("div",{style:{marginBottom:2},children:[(0,n.jsxs)("div",{onClick:()=>g({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[(0,n.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,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),o.map((t,r)=>{let o=x?.type==="model"&&x.providerName===e&&x.index===r;return(0,n.jsxs)("div",{onClick:()=>g({type:"model",providerName:e,index:r}),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,n.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||"new model"}),t.reasoning&&(0,n.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"})]},r)}),(0,n.jsx)("div",{onClick:t=>{t.stopPropagation(),L(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,n.jsx)("span",{style:{fontSize:11},children:"+ model"})})]},e)})]}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,n.jsx)("button",{onClick:()=>k(!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:"+ Add provider"})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:l?null:B??(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[c&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:c}),(0,n.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:"Cancel"}),(0,n.jsxs)("button",{onClick:M,disabled:a||p,style:{position:"relative",padding:"6px 16px",minWidth:92,background:p?"#16a34a":a?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:p?"#fff":a?"var(--text-muted)":"#fff",cursor:a||p?"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:p?"saved-pop 0.45s ease":void 0},children:[p&&(0,n.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,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,n.jsx)("span",{children:p?"Saved":a?"Saving…":"Save"})]})]})]})}),b&&(0,n.jsx)(nd,{oauthProviders:f,apiKeyProviders:v,onSelectOAuth:e=>g({type:"oauth",providerId:e}),onSelectApiKey:e=>g({type:"apikey",providerId:e}),onAddCustom:S,onClose:()=>k(!1)})]})}function nu(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function np(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function nh(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function nx(e){return e?e.slice(0,8):"unknown"}function ng({enabled:e,loading:t,onToggle:r}){return(0,n.jsx)("button",{onClick:r,disabled:t,title:e?"Visible in model prompt — click to disable":"Hidden from model prompt — click to enable",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,n.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 nf({skill:e,cwd:t,onToggle:r,toggling:o,saveError:i,updateStatus:l,checkingUpdate:s,updating:a,updateError:d,onCheckUpdate:c,onUpdate:u}){let p=np(e),h=!e.disableModelInvocation;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===p?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===p?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:p}),(0,n.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"===p&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return nu(e)}(e.filePath)}),(0,n.jsx)(ng,{enabled:h,loading:o,onToggle:()=>r(e)}),i&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:i})]}),e.install?.skillsShUrl&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Source"}),(0,n.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,n.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.install.skillsShUrl.replace(/^https?:\/\//,"")," ↗"]})})]}),e.install&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Version"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-muted)"},children:nx(l?.currentVersion??e.install.versionHash)}),e.install.canCheckForUpdates&&(0,n.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:"Check"}),l?.state==="update-available"&&(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"#d97706"},children:nx(l.latestVersion)}),(s||l&&"update-available"!==l.state)&&(0,n.jsx)("span",{style:{fontSize:12,color:s?"var(--accent)":l?.state==="up-to-date"?"#16a34a":l?.state==="error"?"#ef4444":"var(--text-dim)"},children:s?"Checking...":l?.state==="up-to-date"?"Up to date":l?.state==="unsupported"?"Automatic checks unavailable":l?.message||"Check failed"}),l?.state==="update-available"&&(0,n.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:a?"Updating...":"Update"})]}),d&&(0,n.jsx)("span",{style:{fontSize:12,color:"#ef4444"},children:d})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,n.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function nm({cwd:e,installedPackages:t,onInstalled:r}){let[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)([]),[d,c]=(0,o.useState)(!1),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(new Set),[y,b]=(0,o.useState)("global"),k=(0,o.useRef)(null);(0,o.useEffect)(()=>{k.current?.focus()},[]);let j=(0,o.useCallback)(async e=>{if(e.trim()){c(!0),p(null),a([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),r=await t.json();if(r.error)return void p(r.error);a(r.results??[]),0===(r.results??[]).length&&p("No skills found")}catch(e){p(String(e))}finally{c(!1)}}},[]),w=(0,o.useCallback)(async t=>{x(t),f(null);try{let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:y,cwd:e})}),o=await n.json();if(!n.ok||o.error)return void f(o.error??`HTTP ${n.status}`);v(e=>new Set(e).add(`${y}:${t}`)),r()}catch(e){f(String(e))}finally{x(null)}},[r,y,e]),S="global"===y?"~/.pi/agent/skills/":`${nu(e)}/.pi/skills/`;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:"Add Skill"}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{ref:k,value:i,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&j(i)},placeholder:"e.g. react, testing, deploy",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,n.jsx)("button",{onClick:()=>j(i),disabled:d||!i.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:d||!i.trim()?"not-allowed":"pointer",opacity:d||!i.trim()?.5:1,flexShrink:0},children:d?"Searching…":"Search"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,n.jsx)("button",{onClick:()=>b(e),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:y===e?"var(--bg-selected)":"none",color:y===e?"var(--text)":"var(--text-dim)",fontWeight:y===e?600:400,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,n.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",S]})]}),u&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:u}),g&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:g})]}),s.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:s.map(e=>{let r=t[y].has(e.package)||m.has(`${y}:${e.package}`),o=h===e.package,i=e.package.indexOf("@"),l=i>-1?e.package.slice(0,i):e.package,s=i>-1?e.package.slice(i+1):null;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:s??l}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:l}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,n.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,n.jsx)("button",{onClick:()=>!r&&!o&&w(e.package),disabled:r||o||null!==h,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:r||o||null!==h?"not-allowed":"pointer",background:r?"rgba(34,197,94,0.1)":"none",color:r?"#16a34a":o?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:r?"✓ Installed":o?"Installing…":"Install"})]},e.package)})}):!u&&!d&&(0,n.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,n.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 nv({cwd:e,onClose:t}){let r=tR(),[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(new Set),[g,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)({}),[k,j]=(0,o.useState)(new Set),[w,S]=(0,o.useState)(!1),[C,T]=(0,o.useState)(null),[I,L]=(0,o.useState)(null),R=(0,o.useCallback)(async()=>{a(!0),c(null);try{let t=await fetch(`/api/skills?cwd=${encodeURIComponent(e)}`),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);let n=r.skills??[];return l(n),n.length>0&&!u&&p(n[0].filePath),n}catch(e){return c(String(e)),[]}finally{a(!1)}},[e,u]);(0,o.useEffect)(()=>{b({}),L(null),R()},[e]);let z=(0,o.useCallback)(async t=>{let r=(t?[t]:i.filter(e=>!!e.install)).map(nh).filter(e=>!!e);if(0!==r.length){L(null),j(e=>new Set([...e,...r])),t||S(!0);try{let r=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})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);b(e=>{let t={...e};for(let e of n.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){L(e instanceof Error?e.message:String(e))}finally{j(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t||S(!1)}}},[e,i]),M=(0,o.useCallback)(async t=>{if(!t.install)return;let r=nh(t);T(r),L(null);try{let n=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})}),o=await n.json();if(!n.ok||o.error||!o.success)throw Error(o.error??`HTTP ${n.status}`);await R();let i=o.skill?.install?.versionHash;b(e=>({...e,[r]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:i,latestVersion:i}}))}catch(e){L(e instanceof Error?e.message:String(e))}finally{T(null)}},[e,R]),W=(0,o.useCallback)(async e=>{let t=!e.disableModelInvocation;x(t=>new Set(t).add(e.filePath)),f(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),n=await r.json();if(!r.ok||n.error)return void f(n.error??`HTTP ${r.status}`);l(r=>r.map(r=>r.filePath===e.filePath?{...r,disableModelInvocation:t}:r))}catch(e){f(String(e))}finally{x(t=>{let r=new Set(t);return r.delete(e.filePath),r})}},[]),E=i.find(e=>e.filePath===u)??null;return(0,n.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,n.jsxs)("div",{style:{width:r?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:r?"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,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Skills"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:nu(e)})]}),(0,n.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:r?"column":"row",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:r?"100%":210,maxHeight:r?"40vh":void 0,borderRight:r?"none":"1px solid var(--border)",borderBottom:r?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:s?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):d?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:d}):0===i.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No skills found"}):(()=>{let e=[];for(let{label:t,matches:r}of[{label:"project / skills.sh",matches:e=>"project"===np(e)&&!!e.install?.skillsShUrl},{label:"project",matches:e=>"project"===np(e)&&!e.install?.skillsShUrl},{label:"global / skills.sh",matches:e=>"global"===np(e)&&!!e.install?.skillsShUrl},{label:"global",matches:e=>"global"===np(e)&&!e.install?.skillsShUrl},{label:"path",matches:e=>"path"===np(e)}]){let n=i.filter(r);n.length>0&&e.push({label:t,skills:n})}return e.map(({label:e,skills:t})=>(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:e}),t.map(e=>{let t,r,o=!m&&u===e.filePath,i=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{p(e.filePath),v(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",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,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:i?"var(--border)":"var(--accent)",boxShadow:i?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:o?600:400,color:i?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(r=(t=nh(e))?y[t]:void 0,r?.state!=="update-available"?null:(0,n.jsx)("span",{title:"Update available",style:{color:"#d97706",fontSize:13,lineHeight:1,flexShrink:0},children:"↑"}))]},e.filePath)})]},e))})()}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{onClick:()=>v(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:m?"var(--bg-selected)":"none",color:m?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{m||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{m||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add skill"]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:m?(0,n.jsx)(nm,{cwd:e,installedPackages:{global:new Set(i.filter(e=>e.install?.scope==="global").map(e=>e.install.package)),project:new Set(i.filter(e=>e.install?.scope==="project").map(e=>e.install.package))},onInstalled:()=>{R()}}):s?null:E?(0,n.jsx)(nf,{skill:E,cwd:e,onToggle:W,toggling:h.has(E.filePath),saveError:g,updateStatus:nh(E)?y[nh(E)]:void 0,checkingUpdate:!!nh(E)&&k.has(nh(E)),updating:C===nh(E),updateError:I,onCheckUpdate:()=>void z(E),onUpdate:()=>void M(E)},E.filePath):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a skill"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[i.some(e=>!!e.install)&&(0,n.jsx)("button",{onClick:()=>void z(),disabled:w||null!==C,style:{padding:"6px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:w||null!==C?"not-allowed":"pointer",opacity:w||null!==C?.5:1,fontSize:12},children:w?"Checking...":"Check updates"}),Object.values(y).filter(e=>"update-available"===e.state).length>0&&(0,n.jsxs)("span",{style:{fontSize:12,color:"#d97706"},children:[Object.values(y).filter(e=>"update-available"===e.state).length," ",1===Object.values(y).filter(e=>"update-available"===e.state).length?"update":"updates"]})]}),(0,n.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:"Close"})]})]})})}function ny(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function nb(e){return`${e.scope}\0${e.source}`}function nk(e){if(e.disabled)return"Disabled";let t=[e.counts.extensions?`${e.counts.extensions} ext`:"",e.counts.skills?`${e.counts.skills} skills`:"",e.counts.prompts?`${e.counts.prompts} prompts`:"",e.counts.themes?`${e.counts.themes} themes`:""].filter(Boolean);return t.length?t.join(" \xb7 "):"No resources"}function nj(e){let t=[];return e.version&&t.push(`installed ${e.version}`),e.configuredVersion&&t.push(`configured ${e.configuredVersion}`),t.length?t.join(" \xb7 "):"Unknown"}function nw(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function nS({pkg:e}){let t=[["extension","Extensions"],["skill","Skills"],["prompt","Prompts"],["theme","Themes"]].map(([t,r])=>({kind:t,label:r,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return 0===t.length?(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:e.disabled?"Package disabled":"No resolved resources"}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:t.map((e,t)=>(0,n.jsxs)("div",{style:{borderTop:0===t?"none":"1px solid var(--border)",paddingTop:12*(0!==t)},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",marginBottom:6},children:e.label}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.resources.map(e=>(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.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,n.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 nC({scope:e}){return(0,n.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 nT(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 nI({enabled:e,loading:t,onToggle:r,label:o}){return(0,n.jsx)("button",{type:"button",onClick:r,disabled:t,title:o,"aria-label":o,"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,n.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 nL({value:e,onChange:t}){return(0,n.jsx)("div",{style:{display:"inline-flex",border:"1px solid var(--border)",borderRadius:7,overflow:"hidden",height:30},children:["global","project"].map(r=>{let o=e===r;return(0,n.jsx)("button",{onClick:()=>t(r),style:{width:76,border:"none",borderRight:"global"===r?"1px solid var(--border)":"none",background:o?"var(--bg-selected)":"none",color:o?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12},children:r},r)})})}function nR({cwd:e,source:t,scope:r,busy:i,actionError:l,onSourceChange:s,onScopeChange:a,onInstall:d}){let c=(0,o.useRef)(null);return(0,o.useEffect)(()=>{c.current?.focus()},[]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Add Plugin"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"project"===r?`${ny(e)}/.pi/agent/{npm,git}`:"~/.pi/agent/{npm,git}"})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("label",{htmlFor:"plugin-source",style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Source"}),(0,n.jsx)("input",{id:"plugin-source",ref:c,value:t,onChange:e=>s(e.target.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()&&!i&&d()}})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)(nL,{value:r,onChange:a}),(0,n.jsx)("button",{type:"button",onClick:d,disabled:i||!t.trim(),style:{...nT(i||!t.trim()),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:i?"Installing...":"Install"})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Examples"}),(0,n.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,n.jsx)("button",{type:"button",onClick:()=>s(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))})]}),l&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:l})]})}function nz({pkg:e,cwd:t,busyKey:r,actionError:o,actionMessage:i,sessionId:l,onAction:s,onReloadSession:a}){let d=nb(e),c=r?.endsWith(d)??!1,u="reload"===r,p=!e.disabled;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20,maxWidth:680},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,minWidth:0,flexWrap:"wrap"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:180,flex:1},children:[(0,n.jsx)(nI,{enabled:p,loading:c||u,onToggle:()=>s(e.disabled?"enable":"disable",e),label:e.disabled?"Enable package":"Disable package"}),(0,n.jsx)(nC,{scope:e.scope}),e.disabled?(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)",color:"var(--text-dim)"},children:"disabled"}):e.filtered&&(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(245,158,11,0.12)",color:"#d97706"},children:"filtered"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("button",{onClick:()=>s("update",e),disabled:c||u,style:nT(c||u),children:r===`update:${d}`?"Updating...":"Update"}),(0,n.jsx)("button",{onClick:a,disabled:!l||u||c,style:nT(!l||u||c),title:l?"Reload current session":"Open a session to reload",children:u?"Reloading...":"Reload session"}),(0,n.jsx)("button",{onClick:()=>s("remove",e),disabled:c||u,style:nT(c||u,!0),children:r===`remove:${d}`?"Removing...":"Remove"})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Status"}),(0,n.jsx)("div",{style:{color:nw(e.status),textTransform:"capitalize"},children:e.status}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Version"}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:nj(e)}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Package"}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.packageName??"Unknown"}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Resources"}),(0,n.jsx)("div",{style:{color:"var(--text-muted)"},children:nk(e)}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Installed path"}),(0,n.jsx)("div",{style:{color:e.installedPath?"var(--text-muted)":"#ef4444",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.installedPath?ny(e.installedPath):"Not found"}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Cwd"}),(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:ny(t)})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Resolved Resources"}),(0,n.jsx)(nS,{pkg:e})]}),i&&(0,n.jsx)("div",{style:{fontSize:12,color:"#16a34a"},children:i}),o&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:o})]})}function nM({cwd:e,sessionId:t,onClose:r,onReloaded:i}){let l=tR(),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)(!0),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(!1),[m,v]=(0,o.useState)(""),[y,b]=(0,o.useState)("global"),[k,j]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[C,T]=(0,o.useState)(null),I=(0,o.useMemo)(()=>s?.packages??[],[s?.packages]),L=I.find(e=>nb(e)===h)??null,R=(0,o.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:I.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[I]),z=(0,o.useCallback)(async()=>{c(!0),p(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);a(r),f(e=>0===r.packages.length||e),x(e=>e&&r.packages.some(t=>nb(t)===e)?e:r.packages[0]?nb(r.packages[0]):null)}catch(e){p(e instanceof Error?e.message:String(e))}finally{c(!1)}},[e]);(0,o.useEffect)(()=>{z()},[z]);let M=(0,o.useCallback)(async(t,r)=>{let n=nb(r);j(`${t}:${n}`),S(null),T(null);try{let n=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:r.source,scope:r.scope,cwd:e})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);a(o),"remove"===t?(x(o.packages[0]?nb(o.packages[0]):null),0===o.packages.length&&f(!0),T("Package removed.")):T({install:"Package installed.",update:"Package updated.",disable:"Package disabled.",enable:"Package enabled."}[t])}catch(e){S(e instanceof Error?e.message:String(e))}finally{j(null)}},[e]),W=(0,o.useCallback)(async()=>{let t=m.trim();if(!t)return;let r=`${y}\0${t}`;j(`install:${r}`),S(null),T(null);try{var n;let o,i,l=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"install",source:t,scope:y,cwd:e})}),s=await l.json();if(!l.ok||s.error)throw Error(s.error??`HTTP ${l.status}`);a(s);let d=(n=s.packages,i=(o=t.trim()).startsWith("npm:")?o.slice(4):o,n.find(e=>e.scope===y&&e.source===o)??n.find(e=>e.scope===y&&e.source===`npm:${i}`)??n.find(e=>e.scope===y&&e.source.endsWith(o)));x(d?nb(d):r),f(!1),v(""),T("Package installed.")}catch(e){S(e instanceof Error?e.message:String(e))}finally{j(null)}},[e,y,m]),E=(0,o.useCallback)(async()=>{if(t){j("reload"),S(null),T(null);try{await tZ(t,{type:"reload"}),i?.(),await z(),T("Session reloaded.")}catch(e){S(e instanceof Error?e.message:String(e))}finally{j(null)}}},[z,i,t]),$=k?.startsWith("install:")??!1;return(0,n.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&&r()},children:(0,n.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,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Plugins"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ny(e)})]}),(0,n.jsx)("button",{onClick:r,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:l?"column":"row",overflow:"hidden"},children:[(0,n.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,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:d?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):u?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:u}):0===I.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No plugins configured"}):R.map(e=>(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.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=nb(e),r=!g&&h===t;return(0,n.jsxs)("div",{onClick:()=>{x(t),f(!1),S(null),T(null)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:nw(e.status)}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:nk(e)}),(e.version||e.configuredVersion)&&(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:nj(e)})]})]},t)})]},e.scope))}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("button",{type:"button",onClick:()=>{f(!0),S(null),T(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:g?"var(--bg-selected)":"none",color:g?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{g||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{g||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add plugin"]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:g?(0,n.jsx)(nR,{cwd:e,source:m,scope:y,busy:$,actionError:w,onSourceChange:v,onScopeChange:b,onInstall:W}):d?null:L?(0,n.jsx)(nz,{pkg:L,cwd:e,busyKey:k,actionError:w,actionMessage:C,sessionId:t,onAction:M,onReloadSession:E},nb(L)):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a package"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsx)("div",{style:{minWidth:0,flex:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden"},children:s?.diagnostics.length?(0,n.jsxs)("span",{title:s.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:s.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:[s.diagnostics.length," diagnostic",1===s.diagnostics.length?"":"s"]}):(0,n.jsx)("span",{children:s?`${s.totals.extensions} ext \xb7 ${s.totals.skills} skills \xb7 ${s.totals.prompts} prompts \xb7 ${s.totals.themes} themes`:""})}),(0,n.jsx)("button",{onClick:()=>void z(),disabled:d||null!==k,style:nT(d||null!==k),children:"Refresh"}),(0,n.jsx)("button",{onClick:r,style:nT(!1),children:"Close"})]})]})})}function nW(e){let t=e,r=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],r+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:r}}function nE({node:e,activePathIds:t,depth:r,isLast:o,parentLines:i,onSelect:l}){let{node:s,skipped:a}=nW(e),d=t.has(s.entry.id),c=t.has(e.entry.id)||t.has(s.entry.id),u=function(e){if("message"===e.type&&"message"in e){let t=e.message,r=t.content,n="";if("string"==typeof r?n=r:Array.isArray(r)&&(n=r.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),n.length>40&&(n=n.slice(0,40)+"…"),n)return n;if("assistant"===t.role)return"[assistant]"}return e.type}(s.entry),p="message"===s.entry.type&&"message"in s.entry?s.entry.message.role:null;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>l(s.entry.id),children:[i.map((e,t)=>(0,n.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,n.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:o?"50%":0,width:1,background:"var(--border)"}}),(0,n.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,n.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:d?"var(--accent)":c?"var(--text-muted)":"var(--border)",border:d?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),p&&(0,n.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===p?"var(--accent)":"var(--text-dim)",background:"user"===p?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===p?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===p?"U":"A"}),a>0&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",a]}),(0,n.jsx)("span",{style:{fontSize:11,color:d?"var(--text)":c?"var(--text-muted)":"var(--text-dim)",fontWeight:d?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:u})]}),s.children.map((e,a)=>(0,n.jsx)(nE,{node:e,activePathIds:t,depth:r+1,isLast:a===s.children.length-1,parentLines:[...i,!o],onSelect:l},e.entry.id))]})}function n$({tree:e,activeLeafId:t,onLeafChange:r,inline:i,containerRef:l,open:s,onToggle:a,hasSession:d,compact:c}){let[u,p]=(0,o.useState)(!1),h=void 0!==s?s:u,x=(0,o.useRef)(null),[g,f]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(!h||!i)return;let e=l?.current??x.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();f({top:t.bottom,left:t.left,width:t.width})};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[h,i,l]);let m=(0,o.useMemo)(()=>t?new Set(function e(r,n){for(let o of r){let r=[...n,o.entry.id];if(o.entry.id===t||o.compressedEntryIds?.includes(t))return r;let i=e(o.children,r);if(i)return i}return null}(e,[])??[]):new Set,[e,t]),v=(0,o.useCallback)(e=>{r(e)},[r]),y=d?!function e(t){for(let r of t)if(r.children.length>1||e(r.children))return!0;return!1}(e)?"This session has no branches":null:"No active session",b=e.length>0?nW(e[0]):null,k=b?.node??null,j=!y&&k&&k.children.length>1,w=(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:j?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),S=(0,n.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:h?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return i?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,n.jsxs)("button",{ref:x,onClick:()=>a?a():p(e=>!e),style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:h?"var(--bg-selected)":"none",border:"none",borderTop:h?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:"pointer",color:h?"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=h?"var(--text)":"var(--text-muted)"},title:"Branches","aria-label":"Branches","aria-pressed":h,children:[w,!c&&(0,n.jsx)("span",{children:"Branches"})]}),h&&g&&(0,n.jsx)("div",{style:{position:"fixed",top:g.top,left:g.left,width:g.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:j&&k?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:k.children.map((e,t)=>(0,n.jsx)(nE,{node:e,activePathIds:m,depth:0,isLast:t===k.children.length-1,parentLines:[],onSelect:v},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:y})})]}):(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>p(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:[w,(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),S]}),h&&(0,n.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:j&&k?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:k.children.map((e,t)=>(0,n.jsx)(nE,{node:e,activePathIds:m,depth:0,isLast:t===k.children.length-1,parentLines:[],onSelect:v},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:y??"This session has no branches"})})]})}var nB=r(41463);function nA(){let e,t,r,s,a,d,c,u,p,h,x,g,f,m,v,y,b,k,j=(0,i.useRouter)(),w=(0,i.useSearchParams)(),[S]=(0,o.useState)(()=>{let e;return{requestedCwd:e=w.get("cwd")?.trim()||null,sessionId:e?null:w.get("session")}}),{isDark:C,mode:T,cycleMode:I}=eA(),L=tR();e=(0,i.useRouter)(),t="true"===nB.env.NEXT_PUBLIC_AUTH_ENABLED,r=(0,o.useCallback)(async()=>{try{return(await fetch("/api/auth/refresh",{method:"POST"})).ok}catch{return!1}},[]),s=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/auth/status");return(await e.json()).authenticated}catch{return!1}},[]),(0,o.useEffect)(()=>{if(!t)return;let n=async()=>{!await s()&&(await r()||e.push("/login"))},o=setInterval(n,3e5);return n(),()=>clearInterval(o)},[e,s,r,t]);let[R,z]=(0,o.useState)(null),[M,W]=(0,o.useState)(null),[E,$]=(0,o.useState)(()=>S.requestedCwd?"validating":"idle"),[B,A]=(0,o.useState)(null),[D,P]=(0,o.useState)(0),[F,O]=(0,o.useState)(0),[H,U]=(0,o.useState)(0),[_,q]=(0,o.useState)(!1),[K,V]=(0,o.useState)(0),[J,Y]=(0,o.useState)(!1),[Z,G]=(0,o.useState)(!1),[X,Q]=(0,o.useState)(!0),[ee,et]=(0,o.useState)(!1);(0,o.useEffect)(()=>{L&&Q(!1)},[L]),(0,o.useEffect)(()=>{et(!0)},[]);let er=(0,o.useRef)(null),en=(0,o.useRef)(null),[ei,el]=(0,o.useState)([]),[es,ea]=(0,o.useState)(null),ed=(0,o.useRef)(null),ec=(0,o.useCallback)((e,t,r)=>{el(e),ea(t),ed.current=r},[]),eu=(0,o.useCallback)(e=>{ed.current?.(e)},[]),[ep,eh]=(0,o.useState)(null),ex=(0,o.useRef)(null),eg=(0,o.useCallback)(e=>{eh(e)},[]),[ef,em]=(0,o.useState)(null),[ev,ey]=(0,o.useState)({kind:"idle"}),eb=(0,o.useRef)(null),ek=(0,o.useRef)(R?.id??null);ek.current=R?.id??null;let ej=(0,o.useCallback)(e=>{em(e)},[]),[ew,eS]=(0,o.useState)(null),eC=(0,o.useRef)(null),eT=(0,o.useCallback)((e,t)=>{eD(t).then(()=>{eC.current&&clearTimeout(eC.current),eS(e),eC.current=setTimeout(()=>eS(null),1400)})},[]);(0,o.useEffect)(()=>()=>{eC.current&&clearTimeout(eC.current),eb.current&&clearTimeout(eb.current)},[]);let[eI,eL]=(0,o.useState)(null),eR=(0,o.useCallback)(e=>{eL(e)},[]),[ez,eM]=(0,o.useState)(null),[eW,eE]=(0,o.useState)(null),e$=(0,o.useCallback)(e=>{L&&Q(!1),eM(t=>t===e?null:e)},[L]),eB=(0,o.useCallback)(()=>{L&&Q(!1),eM("session")},[L]),eP=(0,o.useCallback)(()=>{L&&eM(null),Q(e=>!e)},[L]);(0,o.useEffect)(()=>{if(!ez||!en.current)return;let e=()=>{let e=en.current.getBoundingClientRect();eE({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(en.current),()=>t.disconnect()},[ez]);let[eN,eF]=(0,o.useState)([]),[eO,eH]=(0,o.useState)(null),[eU,e_]=(0,o.useState)(!1),eq=(0,o.useCallback)((e,t)=>{er.current?.insertText(tS(e,t))},[]),eK=(0,o.useCallback)(e=>{let t=e.map(e=>tS(e,!1)).join("");t&&er.current?.insertText(t)},[]),eV=S.sessionId,[eJ,eY]=(0,o.useState)(null),[eZ,eG]=(0,o.useState)(()=>!eV),eX=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=S.requestedCwd;if(!e)return;let t=new AbortController;return $("validating"),A(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok||!t.cwd)throw Error(t.error??`HTTP ${e.status}`);eX.current=!0,W(t.cwd),$("ready")}).catch(e=>{t.signal.aborted||(A(e instanceof Error?e.message:String(e)),$("error"))}),()=>t.abort()},[S]);let eQ=(0,o.useCallback)((e,t)=>{if(eY(e),!e)return;if(eX.current){eX.current=!1;return}let r=t??e;R&&(R.projectRoot??R.cwd)===r||(z(null),W(t=>t&&t!==e?null:t),O(e=>e+1),el([]),ea(null),eh(null),eM(null),j.replace("/",{scroll:!1}))},[j,R]),e0=(0,o.useCallback)((e,t=!1)=>{W(null),z(e),O(e=>e+1),eh(null),eG(!0),L&&!t&&Q(!1),t&&(eX.current=!0),t||j.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[j,L]),e1=(0,o.useCallback)((e,t)=>{z(null),W(t),O(e=>e+1),el([]),ea(null),eh(null),eM(null),L&&Q(!1),j.replace("/",{scroll:!1})},[j,L]);!function(e){let{onNewSession:t,activeCwd:r}=e;(0,o.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(!r||!t)return;e.preventDefault(),t(r)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[r,t])}({onNewSession:e=>e1(`kb-${Date.now()}`,e),activeCwd:eJ});let e2=(0,o.useCallback)(e=>{fetch("/api/sessions").then(e=>e.ok?e.json():null).then(t=>{let r=t?.sessions.find(t=>t.id===e);r&&z(t=>t&&t.id===e&&!t.projectRoot?r:t)}).catch(()=>{})},[]),e4=(0,o.useCallback)(e=>{W(null),z(e),P(e=>e+1),e2(e.id),j.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[j,e2]),e5=(0,o.useCallback)(()=>{P(e=>e+1),U(e=>e+1)},[]),e6=(0,o.useCallback)(async()=>{let e=R?.id;if(e&&"naming"!==ev.kind){eb.current&&clearTimeout(eb.current),eM(null),ey({kind:"naming"});try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/auto-name`,{method:"POST"}),r=await t.json().catch(()=>({}));if(!t.ok||!r.title)throw Error(r.error||`HTTP ${t.status}`);let n=r.title.trim();if(P(e=>e+1),ek.current!==e)return;z(t=>t?.id===e?{...t,name:n}:t),em(t=>t?.sessionId===e?{...t,sessionName:n}:t),ey({kind:"success"}),eb.current=setTimeout(()=>ey({kind:"idle"}),1800)}catch(t){if(ek.current!==e)return;ey({kind:"error",message:t instanceof Error?t.message:String(t)}),eb.current=setTimeout(()=>ey({kind:"idle"}),5e3)}}},[ev.kind,R?.id]);(0,o.useEffect)(()=>{eb.current&&clearTimeout(eb.current),ey({kind:"idle"})},[R?.id]);let e8=(0,o.useCallback)(()=>{U(e=>e+1)},[]),e3=(0,o.useCallback)(e=>{P(e=>e+1),O(e=>e+1),W(null),z(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e})),e2(e),j.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[j,e2]),e9=(0,o.useCallback)(()=>{eG(!0)},[]),e7=(0,o.useCallback)(e=>{if(P(e=>e+1),R?.id===e){let e=R.cwd;z(null),W(e??null),O(e=>e+1),el([]),ea(null),eh(null),eM(null),j.replace("/",{scroll:!1})}},[R,j]),te=(0,o.useCallback)((e,t,r)=>{let n=`file:${e}`;eF(o=>{let i=o.find(e=>e.id===n);return i?r&&i.sourceSessionId!==r?o.map(e=>e.id===n?{...e,sourceSessionId:r}:e):o:[...o,{id:n,label:t,filePath:e,sourceSessionId:r}]}),eH(n),e_(!0),L&&Q(!1)},[L]),tt=(0,o.useCallback)(e=>{te(e,N(e),R?.id??null)},[te,R?.id]),tr=(0,o.useCallback)(e=>{eF(t=>{let r=t.filter(t=>t.id!==e);return 0===r.length&&e_(!1),r}),eH(t=>{if(t!==e)return t;let r=eN.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:null})},[eN]),tn=(0,o.useCallback)(()=>{R&&window.open(`/api/sessions/${encodeURIComponent(R.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[R]),to=M??(null===R&&eJ?eJ:null),ti=null!==R||null!==to,tl=eZ&&!ti,ts=eN.find(e=>e.id===eO)??null,ta=eJ?N(eJ)||eJ:null,td=ta?`${ta} - Pi Web`:"Pi Web";(0,o.useEffect)(()=>{let e=()=>{document.title!==td&&(document.title=td)};e();let t=new MutationObserver(e);return t.observe(document.head,{childList:!0,subtree:!0,characterData:!0}),()=>t.disconnect()},[td]);let tc=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eo,{selectedSessionId:R?.id??null,onSelectSession:e0,onNewSession:e1,initialSessionId:eV,skipInitialProjectSelection:null!==S.requestedCwd,onInitialRestoreDone:e9,refreshKey:D,onSessionDeleted:e7,selectedCwd:R?.cwd??M??null,onCwdChange:eQ,onOpenFile:te,explorerRefreshKey:H,onExplorerRefresh:e8,onAtMention:eq,onAtMentions:eK}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0,display:"flex",justifyContent:"space-between",gap:4},children:[{label:"Models",onClick:()=>q(!0),disabled:!1,icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]})},{label:"Skills",onClick:()=>Y(!0),disabled:!eJ&&!R?.cwd&&!M,icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,n.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,n.jsx)("path",{d:"M2 12l10 5 10-5"})]})},{label:"Plugins",onClick:()=>G(!0),disabled:!eJ&&!R?.cwd&&!M,icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 7V2"}),(0,n.jsx)("path",{d:"M15 7V2"}),(0,n.jsx)("path",{d:"M6 13V8a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v5a6 6 0 0 1-12 0Z"}),(0,n.jsx)("path",{d:"M12 19v3"})]})}].map(({label:e,onClick:t,disabled:r,icon:o})=>(0,n.jsxs)("button",{onClick:t,disabled:r,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:r?"default":"pointer",fontSize:12,opacity:r?.35:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(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:[o,e]},e))})]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("style",{children:`
|
|
3
|
+
@keyframes session-info-pop {
|
|
4
|
+
0% {
|
|
5
|
+
opacity: 0;
|
|
6
|
+
transform: translateY(-24px);
|
|
7
|
+
filter: blur(6px);
|
|
8
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0);
|
|
9
|
+
}
|
|
10
|
+
55% {
|
|
11
|
+
opacity: 1;
|
|
12
|
+
transform: translateY(0);
|
|
13
|
+
filter: blur(0);
|
|
14
|
+
background: color-mix(in srgb, var(--accent) 8%, var(--bg-panel));
|
|
15
|
+
box-shadow: 0 18px 44px rgba(37,99,235,0.16);
|
|
16
|
+
}
|
|
17
|
+
100% {
|
|
18
|
+
opacity: 1;
|
|
19
|
+
transform: translateY(0);
|
|
20
|
+
filter: blur(0);
|
|
21
|
+
background: var(--bg-panel);
|
|
22
|
+
box-shadow: 0 10px 28px rgba(0,0,0,0.10);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
@keyframes session-info-light-wash {
|
|
26
|
+
0% {
|
|
27
|
+
opacity: 0;
|
|
28
|
+
transform: translateX(-110%) skewX(-16deg);
|
|
29
|
+
}
|
|
30
|
+
24% {
|
|
31
|
+
opacity: 0.42;
|
|
32
|
+
}
|
|
33
|
+
100% {
|
|
34
|
+
opacity: 0;
|
|
35
|
+
transform: translateX(115%) skewX(-16deg);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
.session-info-popover {
|
|
39
|
+
position: relative;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
transform-origin: top right;
|
|
42
|
+
animation: session-info-pop 360ms ease-out both;
|
|
43
|
+
will-change: transform, opacity, filter, background, box-shadow;
|
|
44
|
+
}
|
|
45
|
+
.session-info-popover::after {
|
|
46
|
+
content: "";
|
|
47
|
+
position: absolute;
|
|
48
|
+
top: 0;
|
|
49
|
+
bottom: 0;
|
|
50
|
+
left: 0;
|
|
51
|
+
width: 44%;
|
|
52
|
+
pointer-events: none;
|
|
53
|
+
background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 24%, transparent), transparent);
|
|
54
|
+
animation: session-info-light-wash 620ms ease-out both;
|
|
55
|
+
}
|
|
56
|
+
@media (prefers-reduced-motion: reduce) {
|
|
57
|
+
.session-info-popover,
|
|
58
|
+
.session-info-popover::after {
|
|
59
|
+
animation: none;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
@media (max-width: 640px) {
|
|
63
|
+
.sidebar-overlay-backdrop.sidebar-mobile-pending {
|
|
64
|
+
opacity: 0 !important;
|
|
65
|
+
pointer-events: none !important;
|
|
66
|
+
}
|
|
67
|
+
.sidebar-container.sidebar-mobile-pending.sidebar-open {
|
|
68
|
+
transform: translateX(-100%);
|
|
69
|
+
box-shadow: none;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`}),(0,n.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("div",{className:`sidebar-overlay-backdrop${ee?"":" sidebar-mobile-pending"}`,onClick:()=>Q(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!X,pointerEvents:X?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${X?" sidebar-open":" sidebar-closed"}${ee?"":" sidebar-mobile-pending"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200},children:tc}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:en,style:{display:"flex",alignItems:"center",flexShrink:0,borderBottom:"1px solid var(--border)",height:36,background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{onClick:eP,title:X?"Hide sidebar":"Show sidebar","aria-label":X?"Hide sidebar":"Show sidebar",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:X?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,n.jsxs)("button",{"data-mode":T,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();I({x:t.left+t.width/2,y:t.top+t.height/2})},title:"auto"===T?"跟随系统":"light"===T?"浅色":"深色","aria-label":"切换主题模式",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:[(0,n.jsx)("span",{style:{display:"auto"===T?"flex":"none",alignItems:"center"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"14",rx:"2"}),(0,n.jsx)("line",{x1:"8",y1:"22",x2:"16",y2:"22"}),(0,n.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"22"})]})}),(0,n.jsx)("span",{style:{display:"auto"!==T&&C?"flex":"none",alignItems:"center"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),(0,n.jsx)("span",{style:{display:"auto"===T||C?"none":"flex",alignItems:"center"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,n.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,n.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,n.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,n.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,n.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,n.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,n.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,n.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]})})]}),ti&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,n.jsxs)("button",{onClick:tn,disabled:!R,title:R?"View full history":"Full history is available after the session is saved","aria-label":"View full history",style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:"none",border:"none",borderTop:"2px solid transparent",borderRight:"1px solid var(--border)",color:R?"var(--text-muted)":"var(--text-dim)",cursor:R?"pointer":"not-allowed",opacity:R?1:.45,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{R&&(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=R?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.background="none"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:R?"var(--text-muted)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"}),(0,n.jsx)("path",{d:"M12 7v5l3 2"})]}),!L&&(0,n.jsx)("span",{children:"Full history"})]}),(a=!!(R&&(ef?.userMessages??R.messageCount)>0),d=!R||!a||"naming"===ev.kind,c="success"===ev.kind,u="error"===ev.kind,p="naming"===ev.kind?"Generating...":c?"Title updated":u?"Generation failed":"Generate title",h=R?a?u?ev.message:"Generate a session title":"Send a message before naming this session":"Title generation is available after the session is saved",(0,n.jsxs)("button",{type:"button",onClick:()=>void e6(),disabled:d,title:h,"aria-label":p,style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:"none",border:"none",borderTop:"2px solid transparent",borderRight:"1px solid var(--border)",color:u?"#dc2626":c?"var(--accent)":d?"var(--text-dim)":"var(--text-muted)",cursor:d?"not-allowed":"pointer",opacity:d&&"naming"!==ev.kind?.45:1,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{d||(e.currentTarget.style.color=u?"#dc2626":"var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=u?"#dc2626":c?"var(--accent)":d?"var(--text-dim)":"var(--text-muted)",e.currentTarget.style.background="none"},children:["naming"===ev.kind?(0,n.jsxs)("svg",{className:"animate-spin",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,n.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):c?(0,n.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,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.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,n.jsx)("path",{d:"m15 4 5 5L7 22l-5-5Z"}),(0,n.jsx)("path",{d:"m14 5 5 5"}),(0,n.jsx)("path",{d:"M6 4V2M5 3H3M19 19v3M17.5 20.5h3"})]}),!L&&(0,n.jsx)("span",{children:p})]})),(0,n.jsx)(n$,{tree:ei,activeLeafId:es,onLeafChange:eu,inline:!0,compact:L,containerRef:en,open:"branches"===ez,onToggle:()=>e$("branches"),hasSession:!0}),(0,n.jsxs)("button",{ref:ex,onClick:()=>e$("system"),title:"System prompt","aria-label":"System prompt","aria-pressed":"system"===ez,style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:"system"===ez?"var(--bg-selected)":"none",border:"none",borderTop:"system"===ez?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:"pointer",color:"system"===ez?"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="system"===ez?"var(--text)":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:ep?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,n.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,n.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),!L&&(0,n.jsx)("span",{children:"System"})]})]}),ti&&(ef||eI)&&(()=>{let e=ef?.tokens,t=ef?.cost??0,r=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=t>0?t>=.01?`$${t.toFixed(2)}`:"<$0.01":null,i="var(--text-muted)",l=null;if(eI?.contextWindow){let e=eI.percent;null!==e&&e>90?i="#ef4444":null!==e&&e>70&&(i="rgba(234,179,8,0.95)"),l=null!==e?`${e.toFixed(0)}% / ${r(eI.contextWindow)}`:`? / ${r(eI.contextWindow)}`}let s=[];if(e&&(s.push(`in: ${e.input.toLocaleString()}`),s.push(`out: ${e.output.toLocaleString()}`),s.push(`cache read: ${e.cacheRead.toLocaleString()}`),s.push(`cache write: ${e.cacheWrite.toLocaleString()}`),t>0&&s.push(`cost: $${t.toFixed(4)}`)),eI?.contextWindow){let e=eI.percent;s.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${eI.contextWindow.toLocaleString()} tokens`)}let a=s.join(" | ");return(0,n.jsxs)("button",{type:"button",onClick:()=>e$("session"),title:a||"Session info","aria-label":"Session info","aria-pressed":"session"===ez,style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:10,paddingLeft:12,paddingRight:eU?12:48,height:"100%",background:"session"===ez?"var(--bg-selected)":"none",border:"none",borderTop:"session"===ez?"2px solid var(--accent)":"2px solid transparent",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"pointer",fontVariantNumeric:"tabular-nums",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="session"===ez?"var(--text)":"var(--text-muted)"},children:[L&&(0,n.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,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),!L&&e&&e.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),r(e.input)]}),!L&&e&&e.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),r(e.output)]}),!L&&e&&e.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),r(e.cacheRead)]}),!L&&o&&(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:o}),l&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:i},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),l]})]})})(),ez&&eW&&(0,n.jsxs)("div",{style:{position:"fixed",top:eW.top,left:eW.left,width:eW.width,maxHeight:`calc(100dvh - ${eW.top}px)`,overflowY:"auto",zIndex:500},children:["system"===ez&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:ep?(0,n.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:ep}):""===ep?(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})}),"session"===ez&&(0,n.jsx)("div",{className:"session-info-popover",style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",padding:"12px 16px"},children:ef?(x=[...ef.sessionName?[{label:"Name",value:ef.sessionName,copyField:null}]:[],{label:"File",value:ef.sessionFile??"In-memory",copyField:"file"},{label:"ID",value:ef.sessionId,copyField:"id"}],g=[["User",ef.userMessages.toLocaleString()],["Assistant",ef.assistantMessages.toLocaleString()],["Tool Calls",ef.toolCalls.toLocaleString()],["Tool Results",ef.toolResults.toLocaleString()],["Total",ef.totalMessages.toLocaleString()]],f=[["Input",ef.tokens.input.toLocaleString()],["Output",ef.tokens.output.toLocaleString()],...ef.tokens.cacheRead>0?[["Cache Read",ef.tokens.cacheRead.toLocaleString()]]:[],...ef.tokens.cacheWrite>0?[["Cache Write",ef.tokens.cacheWrite.toLocaleString()]]:[],["Total",ef.tokens.total.toLocaleString()]],m=eI??ef.contextUsage,y=[...ef.cost>0?[["Cost",`$${ef.cost.toFixed(4)}`]]:[],...m?.contextWindow?[["Context",`${null!==m.percent?`${m.percent.toFixed(1)}%`:"?"} / ${(v=m.contextWindow)>=1e6?`${(v/1e6).toFixed(1)}M`:v>=1e3?`${(v/1e3).toFixed(0)}k`:String(v)}`]]:[]],b=(e,t,r="left",o=!1)=>(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:e}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:o?"max-content max-content":"auto minmax(0, 1fr)",columnGap:o?14:12,rowGap:4,justifyContent:o?"start":void 0},children:t.map(([t,i])=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:t}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:o?"normal":"anywhere",textAlign:r,whiteSpace:"right"===r?"nowrap":"normal"},children:i})]},`${e}:${t}`))})]}),k=(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:"Session Info"}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:x.map(e=>{var t,r;let o;return(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,n.jsx)("div",{children:e.copyField?(t=e.copyField,r=e.value,o=ew===t,(0,n.jsx)("button",{type:"button",title:o?"Copied":`Copy ${"file"===t?"file path":"session ID"}`,onClick:()=>eT(t,r),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:o?"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=o?"var(--accent)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:o?(0,n.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,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.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,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.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,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:L?"1fr":"minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)",gap:L?16:24,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[k,b("Messages",g),b("Tokens",[...f,...y],"right",!0)]})):(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message or run /session to load session info"})})]})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:ti?(0,n.jsx)(re,{session:R,newSessionCwd:to,onAgentEnd:e5,onSessionCreated:e4,onSessionForked:e3,modelsRefreshKey:K,chatInputRef:er,onBranchDataChange:ec,onSystemPromptChange:eg,onSessionStatsChange:ej,onSessionStatsPanelOpen:eB,onContextUsageChange:eR,onOpenFile:tt},F):"validating"===E?(0,n.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,n.jsx)("div",{style:{fontSize:14,color:"var(--text)"},children:"Opening workspace..."}),(0,n.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:S.requestedCwd})]}):"error"===E?(0,n.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,n.jsx)("div",{style:{fontSize:14,color:"#dc2626"},children:"Unable to open workspace"}),(0,n.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:S.requestedCwd}),(0,n.jsx)("div",{style:{maxWidth:720,fontSize:12},children:B})]}):tl?eJ?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,n.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,n.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,n.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,n.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),(0,n.jsxs)("div",{className:`right-panel-container${eU?" right-panel-open":" right-panel-closed"}`,style:{display:"flex",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)"},children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(rw,{tabs:eN,activeTabId:eO??"",onSelectTab:eH,onCloseTab:tr})})}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:ts?.filePath?(0,n.jsx)(rk,{filePath:ts.filePath,cwd:eJ??void 0,sourceSessionId:ts.sourceSessionId,gitRefreshKey:H,onOpenFile:e=>te(e,N(e),ts.sourceSessionId)}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),(0,n.jsx)("button",{onClick:()=>e_(e=>!e),title:eU?"Hide file panel":"Show file panel","aria-label":eU?"Hide file panel":"Show file panel",style:{position:"fixed",top:0,right:0,zIndex:300,display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"var(--bg-panel)",border:"none",borderLeft:"1px solid var(--border)",borderBottom:"1px solid var(--border)",color:eU?"var(--text)":"var(--text-muted)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=eU?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})}),_&&(0,n.jsx)(nc,{onClose:()=>{q(!1),V(e=>e+1)}}),J&&(eJ??R?.cwd??M)&&(0,n.jsx)(nv,{cwd:eJ??R?.cwd??M,onClose:()=>Y(!1)}),Z&&(eJ??R?.cwd??M)&&(0,n.jsx)(nM,{cwd:eJ??R?.cwd??M,sessionId:R?.id??null,onClose:()=>G(!1),onReloaded:()=>O(e=>e+1)})]})}},78722:(e,t,r)=>{Promise.resolve().then(r.bind(r,18588))}},e=>{e.O(0,[7330,8311,8441,3794,7358],()=>e(e.s=78722)),_N_E=e.O()}]);
|