@calmabacus/pi-web 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -0
- package/.next/app-path-routes-manifest.json +66 -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 +189 -0
- package/.next/react-loadable-manifest.json +2367 -0
- package/.next/required-server-files.js +387 -0
- package/.next/required-server-files.json +387 -0
- package/.next/routes-manifest.json +505 -0
- package/.next/server/app/_global-error/page.js +31 -0
- package/.next/server/app/_global-error/page.js.nft.json +1 -0
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -0
- package/.next/server/app/_global-error.html +1 -0
- package/.next/server/app/_global-error.meta +27 -0
- package/.next/server/app/_global-error.rsc +14 -0
- package/.next/server/app/_global-error.segments/_full.segment.rsc +14 -0
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +20 -0
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -0
- package/.next/server/app/_not-found/page.js +1 -0
- package/.next/server/app/_not-found/page.js.nft.json +1 -0
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
- package/.next/server/app/_not-found.html +1 -0
- package/.next/server/app/_not-found.meta +27 -0
- package/.next/server/app/_not-found.rsc +23 -0
- package/.next/server/app/_not-found.segments/_full.segment.rsc +23 -0
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +29 -0
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +8 -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]/lease/route.js +1 -0
- package/.next/server/app/api/agent/[id]/lease/route.js.nft.json +1 -0
- package/.next/server/app/api/agent/[id]/lease/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/route.js +1 -0
- package/.next/server/app/api/agent/running/route.js.nft.json +1 -0
- package/.next/server/app/api/agent/running/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/app-update/route.js +1 -0
- package/.next/server/app/api/app-update/route.js.nft.json +1 -0
- package/.next/server/app/api/app-update/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -0
- package/.next/server/app/api/auth/api-key/[provider]/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/api-key/[provider]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/login/[provider]/route.js +3 -0
- package/.next/server/app/api/auth/login/[provider]/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/login/[provider]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/logout/[provider]/route.js +1 -0
- package/.next/server/app/api/auth/logout/[provider]/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/logout/[provider]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/auth/providers/route.js +1 -0
- package/.next/server/app/api/auth/providers/route.js.nft.json +1 -0
- package/.next/server/app/api/auth/providers/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/cwd/browse/route.js +1 -0
- package/.next/server/app/api/cwd/browse/route.js.nft.json +1 -0
- package/.next/server/app/api/cwd/browse/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/cwd/validate/route.js +1 -0
- package/.next/server/app/api/cwd/validate/route.js.nft.json +1 -0
- package/.next/server/app/api/cwd/validate/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/default-cwd/route.js +1 -0
- package/.next/server/app/api/default-cwd/route.js.nft.json +1 -0
- package/.next/server/app/api/default-cwd/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/file-index/route.js +1 -0
- package/.next/server/app/api/file-index/route.js.nft.json +1 -0
- package/.next/server/app/api/file-index/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/files/[...path]/route.js +49 -0
- package/.next/server/app/api/files/[...path]/route.js.nft.json +1 -0
- package/.next/server/app/api/files/[...path]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/git/diff/route.js +6 -0
- package/.next/server/app/api/git/diff/route.js.nft.json +1 -0
- package/.next/server/app/api/git/diff/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/git/status/route.js +6 -0
- package/.next/server/app/api/git/status/route.js.nft.json +1 -0
- package/.next/server/app/api/git/status/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/home/route.js +1 -0
- package/.next/server/app/api/home/route.js.nft.json +1 -0
- package/.next/server/app/api/home/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/image-generation/route.js +1 -0
- package/.next/server/app/api/image-generation/route.js.nft.json +1 -0
- package/.next/server/app/api/image-generation/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/image-generation/settings/connections/route.js +1 -0
- package/.next/server/app/api/image-generation/settings/connections/route.js.nft.json +1 -0
- package/.next/server/app/api/image-generation/settings/connections/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/image-generation/settings/route.js +1 -0
- package/.next/server/app/api/image-generation/settings/route.js.nft.json +1 -0
- package/.next/server/app/api/image-generation/settings/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models/route.js +1 -0
- package/.next/server/app/api/models/route.js.nft.json +1 -0
- package/.next/server/app/api/models/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models-config/catalog/route.js +1 -0
- package/.next/server/app/api/models-config/catalog/route.js.nft.json +1 -0
- package/.next/server/app/api/models-config/catalog/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models-config/discover/route.js +1 -0
- package/.next/server/app/api/models-config/discover/route.js.nft.json +1 -0
- package/.next/server/app/api/models-config/discover/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/models-config/picker/route.js +1 -0
- package/.next/server/app/api/models-config/picker/route.js.nft.json +1 -0
- package/.next/server/app/api/models-config/picker/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/runtime/route.js +1 -0
- package/.next/server/app/api/models-config/runtime/route.js.nft.json +1 -0
- package/.next/server/app/api/models-config/runtime/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/check/route.js +1 -0
- package/.next/server/app/api/plugins/check/route.js.nft.json +1 -0
- package/.next/server/app/api/plugins/check/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/plugins/route.js +1 -0
- package/.next/server/app/api/plugins/route.js.nft.json +1 -0
- package/.next/server/app/api/plugins/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/project-trust/route.js +1 -0
- package/.next/server/app/api/project-trust/route.js.nft.json +1 -0
- package/.next/server/app/api/project-trust/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/push/config/route.js +1 -0
- package/.next/server/app/api/push/config/route.js.nft.json +1 -0
- package/.next/server/app/api/push/config/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/push/subscribe/route.js +1 -0
- package/.next/server/app/api/push/subscribe/route.js.nft.json +1 -0
- package/.next/server/app/api/push/subscribe/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]/entries/[entryId]/tool-result-image/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/entries/[entryId]/tool-result-image/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/entries/[entryId]/tool-result-image/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/export/route.js +56 -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]/outline/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/outline/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/outline/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/sessions/search/route.js +1 -0
- package/.next/server/app/api/sessions/search/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/search/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 +4 -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/subagents/[id]/route.js +1 -0
- package/.next/server/app/api/subagents/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/subagents/[id]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/subagents/profiles/route.js +1 -0
- package/.next/server/app/api/subagents/profiles/route.js.nft.json +1 -0
- package/.next/server/app/api/subagents/profiles/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/subagents/settings/route.js +1 -0
- package/.next/server/app/api/subagents/settings/route.js.nft.json +1 -0
- package/.next/server/app/api/subagents/settings/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/terminal/[id]/events/route.js +4 -0
- package/.next/server/app/api/terminal/[id]/events/route.js.nft.json +1 -0
- package/.next/server/app/api/terminal/[id]/events/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/terminal/[id]/route.js +1 -0
- package/.next/server/app/api/terminal/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/terminal/[id]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/terminal/route.js +1 -0
- package/.next/server/app/api/terminal/route.js.nft.json +1 -0
- package/.next/server/app/api/terminal/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/tools/settings/route.js +1 -0
- package/.next/server/app/api/tools/settings/route.js.nft.json +1 -0
- package/.next/server/app/api/tools/settings/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/web-auth/route.js +1 -0
- package/.next/server/app/api/web-auth/route.js.nft.json +1 -0
- package/.next/server/app/api/web-auth/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/worktrees/route.js +1 -0
- package/.next/server/app/api/worktrees/route.js.nft.json +1 -0
- package/.next/server/app/api/worktrees/route_client-reference-manifest.js +1 -0
- package/.next/server/app/favicon.ico/route.js +1 -0
- package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
- package/.next/server/app/favicon.ico.body +0 -0
- package/.next/server/app/favicon.ico.meta +1 -0
- package/.next/server/app/index.html +1 -0
- package/.next/server/app/index.meta +21 -0
- package/.next/server/app/index.rsc +24 -0
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +29 -0
- package/.next/server/app/index.segments/_full.segment.rsc +24 -0
- package/.next/server/app/index.segments/_tree.segment.rsc +9 -0
- package/.next/server/app/login/page.js +3 -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 +26 -0
- package/.next/server/app/login.rsc +27 -0
- package/.next/server/app/login.segments/_full.segment.rsc +27 -0
- package/.next/server/app/login.segments/_tree.segment.rsc +8 -0
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +33 -0
- package/.next/server/app/manifest.webmanifest/route.js +17 -0
- package/.next/server/app/manifest.webmanifest/route.js.nft.json +1 -0
- package/.next/server/app/manifest.webmanifest/route_client-reference-manifest.js +1 -0
- package/.next/server/app/manifest.webmanifest.body +1 -0
- package/.next/server/app/manifest.webmanifest.meta +1 -0
- package/.next/server/app/page.js +254 -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 +66 -0
- package/.next/server/chunks/1094.js +160 -0
- package/.next/server/chunks/1515.js +1 -0
- package/.next/server/chunks/1555.js +1 -0
- package/.next/server/chunks/1601.js +24 -0
- package/.next/server/chunks/1625.js +1 -0
- package/.next/server/chunks/1800.js +1 -0
- package/.next/server/chunks/1813.js +1 -0
- package/.next/server/chunks/1860.js +1 -0
- package/.next/server/chunks/2075.js +23 -0
- package/.next/server/chunks/2106.js +1 -0
- package/.next/server/chunks/2169.js +36 -0
- package/.next/server/chunks/2190.js +1 -0
- package/.next/server/chunks/2243.js +1 -0
- package/.next/server/chunks/2325.js +82 -0
- package/.next/server/chunks/2349.js +1 -0
- package/.next/server/chunks/2408.js +1 -0
- package/.next/server/chunks/2430.js +193 -0
- package/.next/server/chunks/2452.js +93 -0
- package/.next/server/chunks/2744.js +1 -0
- package/.next/server/chunks/2903.js +1 -0
- package/.next/server/chunks/295.js +1 -0
- package/.next/server/chunks/3012.js +1 -0
- package/.next/server/chunks/3186.js +86 -0
- package/.next/server/chunks/3379.js +1 -0
- package/.next/server/chunks/3383.js +27 -0
- package/.next/server/chunks/3569.js +1 -0
- package/.next/server/chunks/3618.js +1 -0
- package/.next/server/chunks/3869.js +8 -0
- package/.next/server/chunks/3894.js +1 -0
- package/.next/server/chunks/426.js +14 -0
- package/.next/server/chunks/4267.js +1 -0
- package/.next/server/chunks/4315.js +1 -0
- package/.next/server/chunks/4367.js +1 -0
- package/.next/server/chunks/4372.js +1 -0
- package/.next/server/chunks/4538.js +24 -0
- package/.next/server/chunks/4548.js +1 -0
- package/.next/server/chunks/4563.js +38 -0
- package/.next/server/chunks/4674.js +1 -0
- package/.next/server/chunks/4741.js +165 -0
- package/.next/server/chunks/4980.js +1 -0
- package/.next/server/chunks/5029.js +1 -0
- package/.next/server/chunks/5318.js +1 -0
- package/.next/server/chunks/5582.js +8 -0
- package/.next/server/chunks/5974.js +77 -0
- package/.next/server/chunks/6052.js +141 -0
- package/.next/server/chunks/611.js +1 -0
- package/.next/server/chunks/6253.js +104 -0
- package/.next/server/chunks/6337.js +1 -0
- package/.next/server/chunks/6366.js +80 -0
- package/.next/server/chunks/6429.js +29 -0
- package/.next/server/chunks/673.js +287 -0
- package/.next/server/chunks/6759.js +1 -0
- package/.next/server/chunks/6916.js +226 -0
- package/.next/server/chunks/703.js +1 -0
- package/.next/server/chunks/7233.js +1 -0
- package/.next/server/chunks/7265.js +215 -0
- package/.next/server/chunks/7307.js +1 -0
- package/.next/server/chunks/7561.js +1 -0
- package/.next/server/chunks/7710.js +1 -0
- package/.next/server/chunks/7744.js +64 -0
- package/.next/server/chunks/7790.js +1 -0
- package/.next/server/chunks/7799.js +34 -0
- package/.next/server/chunks/7872.js +1 -0
- package/.next/server/chunks/8106.js +1 -0
- package/.next/server/chunks/8294.js +1 -0
- package/.next/server/chunks/8333.js +79 -0
- package/.next/server/chunks/835.js +1 -0
- package/.next/server/chunks/8397.js +41 -0
- package/.next/server/chunks/8604.js +115 -0
- package/.next/server/chunks/8679.js +1 -0
- package/.next/server/chunks/8713.js +148 -0
- package/.next/server/chunks/8782.js +153 -0
- package/.next/server/chunks/8920.js +62 -0
- package/.next/server/chunks/922.js +5 -0
- package/.next/server/chunks/9280.js +255 -0
- package/.next/server/chunks/9486.js +1 -0
- package/.next/server/chunks/9509.js +1 -0
- package/.next/server/chunks/9510.js +90 -0
- package/.next/server/chunks/974.js +1 -0
- package/.next/server/functions-config-manifest.json +26 -0
- package/.next/server/instrumentation.js +1 -0
- package/.next/server/instrumentation.js.nft.json +1 -0
- package/.next/server/interception-route-rewrite-manifest.js +1 -0
- package/.next/server/middleware-build-manifest.js +1 -0
- package/.next/server/middleware-manifest.json +6 -0
- package/.next/server/middleware-react-loadable-manifest.js +1 -0
- package/.next/server/middleware.js +163 -0
- package/.next/server/middleware.js.nft.json +1 -0
- package/.next/server/next-font-manifest.js +1 -0
- package/.next/server/next-font-manifest.json +1 -0
- package/.next/server/pages/404.html +1 -0
- package/.next/server/pages/500.html +1 -0
- package/.next/server/pages-manifest.json +4 -0
- package/.next/server/prefetch-hints.json +53 -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/LkMtlo9B5W74YX7J-8ccI/_buildManifest.js +1 -0
- package/.next/static/LkMtlo9B5W74YX7J-8ccI/_ssgManifest.js +1 -0
- package/.next/static/chunks/103.23142a67b02246a8.js +215 -0
- package/.next/static/chunks/1032.12b382a9096ab2a4.js +1 -0
- package/.next/static/chunks/1063.775c442bdbeef08b.js +1 -0
- package/.next/static/chunks/1278-b81177f3a674e4e0.js +1 -0
- package/.next/static/chunks/1327.09252bb80616cc3a.js +1 -0
- package/.next/static/chunks/1708.d029f8776e4578de.js +1 -0
- package/.next/static/chunks/1781.866132cea8e77cd0.js +1 -0
- package/.next/static/chunks/1ba63609.b2ae90f43319a29e.js +153 -0
- package/.next/static/chunks/2081.47b6e9391094055f.js +1 -0
- package/.next/static/chunks/2181.ba21239d3ac39f81.js +1 -0
- package/.next/static/chunks/2258.4defa30121ef44a5.js +1 -0
- package/.next/static/chunks/2325.23caf22075e51aa5.js +1 -0
- package/.next/static/chunks/2356.523277bb8c6bf72a.js +23 -0
- package/.next/static/chunks/2418.b5d9e177e10a686e.js +1 -0
- package/.next/static/chunks/2480.cf27ca02e5b19761.js +24 -0
- package/.next/static/chunks/2539.c5a4f2fd8e421c70.js +41 -0
- package/.next/static/chunks/2619.9431a3f48da8eef4.js +1 -0
- package/.next/static/chunks/268.72794ee2773c2060.js +80 -0
- package/.next/static/chunks/2695.6f49435bae1e6f33.js +90 -0
- package/.next/static/chunks/2703.495a65ed14b2f094.js +36 -0
- package/.next/static/chunks/2821.934bcf60fbdc28c6.js +1 -0
- package/.next/static/chunks/3251.0dce7a0a0ff67235.js +1 -0
- package/.next/static/chunks/3308.be8762955e7155d1.js +73 -0
- package/.next/static/chunks/3336.a76f9485fe7cb762.js +1 -0
- package/.next/static/chunks/370.8e8f3cf8eb0e29dd.js +1 -0
- package/.next/static/chunks/3716.72bf4c9d7325debd.js +1 -0
- package/.next/static/chunks/3794-d29203733ca4633c.js +52 -0
- package/.next/static/chunks/398.ffa02af9062a3950.js +77 -0
- package/.next/static/chunks/3995.eca0f5bef1fc3ae5.js +38 -0
- package/.next/static/chunks/4004.74b9bcf5478b1663.js +160 -0
- package/.next/static/chunks/4202.8440832386f023c7.js +226 -0
- package/.next/static/chunks/4238.6f102dcbcf2ae339.js +141 -0
- package/.next/static/chunks/4405.7a19458960a1058e.js +287 -0
- package/.next/static/chunks/4424.fd0c93a807a333e1.js +1 -0
- package/.next/static/chunks/4866.d1060b4faf2ae1e2.js +1 -0
- package/.next/static/chunks/4970.8a63b4953b0e4946.js +1 -0
- package/.next/static/chunks/4bd1b696-8a4ab4fdf0ae305a.js +1 -0
- package/.next/static/chunks/5020.9ac8d0dc8390bb6e.js +1 -0
- package/.next/static/chunks/5137.f163e94c74a94d01.js +1 -0
- package/.next/static/chunks/5242.7b643c6b3394cac1.js +1 -0
- package/.next/static/chunks/5361.afc00ab2626bacbf.js +1 -0
- package/.next/static/chunks/5521.cfdf2cfc6db31407.js +1 -0
- package/.next/static/chunks/5526.ff46471041fdcb79.js +86 -0
- package/.next/static/chunks/5681.dd0e66b0de16e54b.js +27 -0
- package/.next/static/chunks/5772-ddd18c0d4b7715e5.js +3 -0
- package/.next/static/chunks/6121.eb9023b1cbc78ee2.js +1 -0
- package/.next/static/chunks/6161.4836cd7d031026bf.js +1 -0
- package/.next/static/chunks/6195.1153369f5f8b13a2.js +24 -0
- package/.next/static/chunks/6294.24f510c0c3e3714c.js +1 -0
- package/.next/static/chunks/6654.16f727522ec47f5a.js +1 -0
- package/.next/static/chunks/6794.f746d8fbbf248ecf.js +93 -0
- package/.next/static/chunks/7256.e07cf52d87d40252.js +1 -0
- package/.next/static/chunks/7268.236544be8e242c16.js +1 -0
- package/.next/static/chunks/7331.2add3c4e125a2dba.js +104 -0
- package/.next/static/chunks/7543.89f7b805ed0f2901.js +1 -0
- package/.next/static/chunks/8200.a36b9f8c983c6b9e.js +5 -0
- package/.next/static/chunks/869.7152372b662e31af.js +1 -0
- package/.next/static/chunks/8863.fa0320ea586efb3b.js +1 -0
- package/.next/static/chunks/8885.cf60cac98bf8b70c.js +79 -0
- package/.next/static/chunks/8901.e117d206a917bda0.js +1 -0
- package/.next/static/chunks/90542734.ae439f2382f58c51.js +1 -0
- package/.next/static/chunks/918.6a9bbe564e4a2d0f.js +115 -0
- package/.next/static/chunks/934.9006461bd0548660.js +1 -0
- package/.next/static/chunks/9445-fde6feabcb39142c.js +7 -0
- package/.next/static/chunks/9522.c7c6e9c330f9ba6b.js +1 -0
- package/.next/static/chunks/9614.3221013d7f0af27f.js +64 -0
- package/.next/static/chunks/9698.4d09a99b9d99f3e5.js +148 -0
- package/.next/static/chunks/9705.40a82b97f214e28b.js +1 -0
- package/.next/static/chunks/973.88e865b52eff479a.js +8 -0
- package/.next/static/chunks/9764.2669775c6e107a01.js +62 -0
- package/.next/static/chunks/9793.4567af813117ad25.js +1 -0
- package/.next/static/chunks/993e5495.8797001fcfcf2889.js +62 -0
- package/.next/static/chunks/9974.9a0f79beca65e8c4.js +34 -0
- package/.next/static/chunks/app/_global-error/page-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/_not-found/page-d1e0360401438077.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/bash-output/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/events/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/lease/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/agent/new/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/agent/running/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/app-update/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/auth/api-key/[provider]/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/auth/login/[provider]/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/auth/logout/[provider]/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/auth/providers/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/cwd/browse/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/cwd/validate/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/default-cwd/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/file-index/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/files/[...path]/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/git/diff/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/git/status/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/home/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/image-generation/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/image-generation/settings/connections/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/image-generation/settings/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/models/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/models-config/catalog/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/models-config/discover/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/models-config/picker/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/models-config/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/models-config/runtime/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/models-config/test/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/plugins/check/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/plugins/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/project-trust/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/push/config/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/push/subscribe/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/auto-name/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/context/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/entries/[entryId]/thinking/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/entries/[entryId]/tool-result-image/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/export/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/outline/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/state/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/sessions/search/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/skills/check/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/skills/install/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/skills/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/skills/search/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/skills/update/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/subagents/[id]/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/subagents/profiles/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/subagents/settings/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/terminal/[id]/events/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/terminal/[id]/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/terminal/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/tools/settings/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/web-auth/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/api/worktrees/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/layout-f900e4d3794672ad.js +1 -0
- package/.next/static/chunks/app/login/page-4d08a41789f24789.js +1 -0
- package/.next/static/chunks/app/manifest.webmanifest/route-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/app/page-3c64134d63e2eff9.js +232 -0
- package/.next/static/chunks/bf2ff291.3a109dffc1fe84af.js +122 -0
- package/.next/static/chunks/d3ac728e-7964f816a1ca64e5.js +1 -0
- package/.next/static/chunks/da12927c.476aa688a637649c.js +82 -0
- package/.next/static/chunks/db9d41be.e72ce090a86a3691.js +1 -0
- package/.next/static/chunks/e868780c-1584512c612787d7.js +18 -0
- package/.next/static/chunks/framework-b33a8f5d57cd8d87.js +1 -0
- package/.next/static/chunks/main-app-5f091d229b1e5a0e.js +1 -0
- package/.next/static/chunks/main-dac5ab3797407fcb.js +5 -0
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/global-error-ae6c57598b75d8bb.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-24ad8f9c794ebb73.js +1 -0
- package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/.next/static/chunks/webpack-25464d90fe89e601.js +1 -0
- package/.next/static/css/2ac0338d70747eca.css +1 -0
- package/.next/static/css/2f46e0db0d4a3aed.css +1 -0
- package/.next/static/css/444123c292add02f.css +1 -0
- package/.next/static/css/58d019c61385df31.css +1 -0
- package/.next/static/css/89aae141d5b3edde.css +1 -0
- package/.next/static/css/fddca953485158e4.css +1 -0
- package/.next/static/media/01bdb1c2bb2f530a-s.woff2 +0 -0
- package/.next/static/media/060fd7a2ba6f57dc-s.woff2 +0 -0
- package/.next/static/media/06d755a5cd3e2b96-s.woff2 +0 -0
- package/.next/static/media/09341845bc7215c3-s.woff2 +0 -0
- package/.next/static/media/09d8b46d011a8a55-s.woff2 +0 -0
- package/.next/static/media/0ac3ab6b6a54cd96-s.woff2 +0 -0
- package/.next/static/media/0cb7a0edc360425e-s.woff2 +0 -0
- package/.next/static/media/0de82041d2acf4c3-s.woff2 +0 -0
- package/.next/static/media/1249fbbadbb69451-s.woff2 +0 -0
- package/.next/static/media/15605e25b523335c-s.woff2 +0 -0
- package/.next/static/media/182682366c265526-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/246116fa49278f72-s.woff2 +0 -0
- package/.next/static/media/2ad4a039dd2c0f35-s.woff2 +0 -0
- package/.next/static/media/2cd94acf7f6a8cd1-s.woff2 +0 -0
- package/.next/static/media/30af2a5bc088caeb-s.woff2 +0 -0
- package/.next/static/media/3117748ae3be552d-s.woff2 +0 -0
- package/.next/static/media/373befd5a68230ff-s.woff2 +0 -0
- package/.next/static/media/37ae20ae1d329cc2-s.woff2 +0 -0
- package/.next/static/media/3832bef2caf4f297-s.woff2 +0 -0
- package/.next/static/media/3b6ebd4dd223d8c1-s.woff2 +0 -0
- package/.next/static/media/3da25081fc21e3b2-s.woff2 +0 -0
- package/.next/static/media/3eb545844a1630b6-s.woff2 +0 -0
- package/.next/static/media/41870aeb5505be99-s.woff2 +0 -0
- package/.next/static/media/45c8f5377f81d417-s.woff2 +0 -0
- package/.next/static/media/48d86e2f8821c61e-s.woff2 +0 -0
- package/.next/static/media/4957022da3161c6e-s.woff2 +0 -0
- package/.next/static/media/4be71ddc6c749643-s.woff2 +0 -0
- package/.next/static/media/4c4b3b30b6bcb2be-s.woff2 +0 -0
- package/.next/static/media/4dc4381bbf526d04-s.woff2 +0 -0
- package/.next/static/media/4eb0814ea9e22f45-s.woff2 +0 -0
- package/.next/static/media/4f86cf50532e0e9b-s.woff2 +0 -0
- package/.next/static/media/5022b11bb4a81e48-s.woff2 +0 -0
- package/.next/static/media/5080c55e2dccd63d-s.woff2 +0 -0
- package/.next/static/media/5348b1e69a651725-s.woff2 +0 -0
- package/.next/static/media/54c50561be23e605-s.woff2 +0 -0
- package/.next/static/media/567d6f765096ee76-s.woff2 +0 -0
- package/.next/static/media/58045d1f8695a418-s.woff2 +0 -0
- package/.next/static/media/5a274ddc03d9a5ab-s.woff2 +0 -0
- package/.next/static/media/5feee92221bb8605-s.woff2 +0 -0
- package/.next/static/media/6067d3f78ecc4535-s.woff2 +0 -0
- package/.next/static/media/61a11ca45429493a-s.woff2 +0 -0
- package/.next/static/media/63d030730737efae-s.woff2 +0 -0
- package/.next/static/media/641a7b8a5800ee0e-s.woff2 +0 -0
- package/.next/static/media/6bd056ddce336924-s.woff2 +0 -0
- package/.next/static/media/6dc0bae4a5666821-s.woff2 +0 -0
- package/.next/static/media/7513cc52807669ca-s.woff2 +0 -0
- package/.next/static/media/75ae81fea4aec8c5-s.woff2 +0 -0
- package/.next/static/media/77f6534b6a3eb37a-s.woff2 +0 -0
- package/.next/static/media/782d4006a26041e7-s.woff2 +0 -0
- package/.next/static/media/7d509f4f988023eb-s.woff2 +0 -0
- package/.next/static/media/7d58f39a50828c68-s.woff2 +0 -0
- package/.next/static/media/7db71cc013812f1c-s.woff2 +0 -0
- package/.next/static/media/7deddc85b7ffd1dc-s.p.woff2 +0 -0
- package/.next/static/media/7eb3f914ae6dd7a0-s.woff2 +0 -0
- package/.next/static/media/8051eb8307aa13c8-s.woff2 +0 -0
- package/.next/static/media/829dca987e1e010e-s.woff2 +0 -0
- package/.next/static/media/842f675c7a332a48-s.woff2 +0 -0
- package/.next/static/media/866e2e7b0cbc2cb4-s.woff2 +0 -0
- package/.next/static/media/86b38dc7f713ddda-s.woff2 +0 -0
- package/.next/static/media/8a3a66ae6bb27151-s.woff2 +0 -0
- package/.next/static/media/8b56b70f6d577d9f-s.woff2 +0 -0
- package/.next/static/media/8d93dbb77672da11-s.woff2 +0 -0
- package/.next/static/media/8f5c2d0a25b8f50c-s.woff2 +0 -0
- package/.next/static/media/966e6d14b6c229fc-s.woff2 +0 -0
- package/.next/static/media/9877fefe733dd250-s.woff2 +0 -0
- package/.next/static/media/9c57f4420502d43a-s.woff2 +0 -0
- package/.next/static/media/9cedd2ad7b0bcf3d-s.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/a00fb5ef1ca68e5d-s.woff2 +0 -0
- package/.next/static/media/a171b1d72388367c-s.woff2 +0 -0
- package/.next/static/media/a310fb84e6868735-s.woff2 +0 -0
- package/.next/static/media/a53504b22c396db6-s.woff2 +0 -0
- package/.next/static/media/aabb87babcdda375-s.woff2 +0 -0
- package/.next/static/media/afe75c8050c8fd4e-s.woff2 +0 -0
- package/.next/static/media/b201193f76404e13-s.woff2 +0 -0
- package/.next/static/media/b20daecae68a588f-s.woff2 +0 -0
- package/.next/static/media/b2574bc564dca98d-s.woff2 +0 -0
- package/.next/static/media/b6a1339c290590d0-s.woff2 +0 -0
- package/.next/static/media/b6fe4b2295863fe4-s.woff2 +0 -0
- package/.next/static/media/bb8ff9c700288292-s.woff2 +0 -0
- package/.next/static/media/bc1ccfae4ae17995-s.woff2 +0 -0
- package/.next/static/media/be15c189f996aeb2-s.woff2 +0 -0
- package/.next/static/media/c0d1f6928a1dbc31-s.woff2 +0 -0
- package/.next/static/media/c36d8bb68a53eb60-s.woff2 +0 -0
- package/.next/static/media/c5db947ee2561e06-s.woff2 +0 -0
- package/.next/static/media/c77ac7f613b44045-s.woff2 +0 -0
- package/.next/static/media/ca73d0c74010e612-s.woff2 +0 -0
- package/.next/static/media/cfbad6ceeeca5c58-s.woff2 +0 -0
- package/.next/static/media/d24aebb82f01e48d-s.woff2 +0 -0
- package/.next/static/media/d2c6107607eb7d44-s.woff2 +0 -0
- package/.next/static/media/d2c7d5e8db7ce20a-s.woff2 +0 -0
- package/.next/static/media/d51f7558abc55aa6-s.woff2 +0 -0
- package/.next/static/media/da718921282f76d0-s.woff2 +0 -0
- package/.next/static/media/dae37106d788c7c9-s.woff2 +0 -0
- package/.next/static/media/e0d4cd45847004a4-s.woff2 +0 -0
- package/.next/static/media/e100c7a7874aebd9-s.woff2 +0 -0
- package/.next/static/media/e26dff18031f4a7e-s.woff2 +0 -0
- package/.next/static/media/e5b759c1d5c42d99-s.woff2 +0 -0
- package/.next/static/media/ea21a07081db26d0-s.woff2 +0 -0
- package/.next/static/media/eaee7682c49bd1c2-s.woff2 +0 -0
- package/.next/static/media/ec14413c594b3356-s.p.woff2 +0 -0
- package/.next/static/media/ec408158b9e08aea-s.woff2 +0 -0
- package/.next/static/media/ee5d9aad76ea4c0a-s.woff2 +0 -0
- package/.next/static/media/efdbc7cff3271ee9-s.woff2 +0 -0
- package/.next/static/media/f128be4e72405705-s.woff2 +0 -0
- package/.next/static/media/fb6cfff6119f26e8-s.woff2 +0 -0
- package/.next/static/media/fd516adbc3328c82-s.woff2 +0 -0
- package/.next/trace +7 -0
- package/.next/trace-build +1 -0
- package/.next/types/app/api/agent/[id]/bash-output/route.ts +353 -0
- package/.next/types/app/api/agent/[id]/events/route.ts +353 -0
- package/.next/types/app/api/agent/[id]/lease/route.ts +353 -0
- package/.next/types/app/api/agent/[id]/route.ts +353 -0
- package/.next/types/app/api/agent/new/route.ts +353 -0
- package/.next/types/app/api/agent/running/route.ts +353 -0
- package/.next/types/app/api/app-update/route.ts +353 -0
- package/.next/types/app/api/auth/api-key/[provider]/route.ts +353 -0
- package/.next/types/app/api/auth/login/[provider]/route.ts +353 -0
- package/.next/types/app/api/auth/logout/[provider]/route.ts +353 -0
- package/.next/types/app/api/auth/providers/route.ts +353 -0
- package/.next/types/app/api/cwd/browse/route.ts +353 -0
- package/.next/types/app/api/cwd/validate/route.ts +353 -0
- package/.next/types/app/api/default-cwd/route.ts +353 -0
- package/.next/types/app/api/file-index/route.ts +353 -0
- package/.next/types/app/api/files/[...path]/route.ts +353 -0
- package/.next/types/app/api/git/diff/route.ts +353 -0
- package/.next/types/app/api/git/status/route.ts +353 -0
- package/.next/types/app/api/home/route.ts +353 -0
- package/.next/types/app/api/image-generation/route.ts +353 -0
- package/.next/types/app/api/image-generation/settings/connections/route.ts +353 -0
- package/.next/types/app/api/image-generation/settings/route.ts +353 -0
- package/.next/types/app/api/models/route.ts +353 -0
- package/.next/types/app/api/models-config/catalog/route.ts +353 -0
- package/.next/types/app/api/models-config/discover/route.ts +353 -0
- package/.next/types/app/api/models-config/picker/route.ts +353 -0
- package/.next/types/app/api/models-config/route.ts +353 -0
- package/.next/types/app/api/models-config/runtime/route.ts +353 -0
- package/.next/types/app/api/models-config/test/route.ts +353 -0
- package/.next/types/app/api/plugins/check/route.ts +353 -0
- package/.next/types/app/api/plugins/route.ts +353 -0
- package/.next/types/app/api/project-trust/route.ts +353 -0
- package/.next/types/app/api/push/config/route.ts +353 -0
- package/.next/types/app/api/push/subscribe/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/auto-name/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/context/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/entries/[entryId]/thinking/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/entries/[entryId]/tool-result-image/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/export/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/outline/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/route.ts +353 -0
- package/.next/types/app/api/sessions/[id]/state/route.ts +353 -0
- package/.next/types/app/api/sessions/route.ts +353 -0
- package/.next/types/app/api/sessions/search/route.ts +353 -0
- package/.next/types/app/api/skills/check/route.ts +353 -0
- package/.next/types/app/api/skills/install/route.ts +353 -0
- package/.next/types/app/api/skills/route.ts +353 -0
- package/.next/types/app/api/skills/search/route.ts +353 -0
- package/.next/types/app/api/skills/update/route.ts +353 -0
- package/.next/types/app/api/subagents/[id]/route.ts +353 -0
- package/.next/types/app/api/subagents/profiles/route.ts +353 -0
- package/.next/types/app/api/subagents/settings/route.ts +353 -0
- package/.next/types/app/api/terminal/[id]/events/route.ts +353 -0
- package/.next/types/app/api/terminal/[id]/route.ts +353 -0
- package/.next/types/app/api/terminal/route.ts +353 -0
- package/.next/types/app/api/tools/settings/route.ts +353 -0
- package/.next/types/app/api/web-auth/route.ts +353 -0
- package/.next/types/app/api/worktrees/route.ts +353 -0
- package/.next/types/app/layout.ts +89 -0
- package/.next/types/app/login/page.ts +89 -0
- package/.next/types/app/page.ts +89 -0
- package/.next/types/cache-life.d.ts +146 -0
- package/.next/types/package.json +1 -0
- package/.next/types/root-params.d.ts +3 -0
- package/.next/types/routes.d.ts +131 -0
- package/.next/types/validator.ts +601 -0
- package/LICENSE +22 -0
- package/README.md +64 -0
- package/bin/node-version.js +24 -0
- package/bin/pi-web-options.js +87 -0
- package/bin/pi-web.js +132 -0
- package/bin/prepare-terminal.js +14 -0
- package/bin/process-lifecycle.js +81 -0
- package/next.config.ts +73 -0
- package/package.json +95 -0
- package/public/icons/apple-touch-icon.png +0 -0
- package/public/icons/catppuccin/LICENSE +22 -0
- package/public/icons/catppuccin/README.md +9 -0
- package/public/icons/catppuccin/latte/_file.svg +3 -0
- package/public/icons/catppuccin/latte/_folder.svg +3 -0
- package/public/icons/catppuccin/latte/_folder_open.svg +3 -0
- package/public/icons/catppuccin/latte/bash.svg +7 -0
- package/public/icons/catppuccin/latte/bun-lock.svg +8 -0
- package/public/icons/catppuccin/latte/config.svg +3 -0
- package/public/icons/catppuccin/latte/css.svg +6 -0
- package/public/icons/catppuccin/latte/database.svg +3 -0
- package/public/icons/catppuccin/latte/docker.svg +3 -0
- package/public/icons/catppuccin/latte/env.svg +3 -0
- package/public/icons/catppuccin/latte/eslint.svg +6 -0
- package/public/icons/catppuccin/latte/git.svg +6 -0
- package/public/icons/catppuccin/latte/go.svg +3 -0
- package/public/icons/catppuccin/latte/graphql.svg +3 -0
- package/public/icons/catppuccin/latte/html.svg +6 -0
- package/public/icons/catppuccin/latte/javascript-react.svg +8 -0
- package/public/icons/catppuccin/latte/javascript.svg +6 -0
- package/public/icons/catppuccin/latte/json.svg +3 -0
- package/public/icons/catppuccin/latte/lock.svg +3 -0
- package/public/icons/catppuccin/latte/markdown.svg +3 -0
- package/public/icons/catppuccin/latte/ms-word.svg +6 -0
- package/public/icons/catppuccin/latte/next.svg +6 -0
- package/public/icons/catppuccin/latte/npm-lock.svg +7 -0
- package/public/icons/catppuccin/latte/pdf.svg +3 -0
- package/public/icons/catppuccin/latte/python.svg +8 -0
- package/public/icons/catppuccin/latte/rust.svg +6 -0
- package/public/icons/catppuccin/latte/sass.svg +3 -0
- package/public/icons/catppuccin/latte/terraform.svg +3 -0
- package/public/icons/catppuccin/latte/toml.svg +3 -0
- package/public/icons/catppuccin/latte/typescript-react.svg +8 -0
- package/public/icons/catppuccin/latte/typescript.svg +6 -0
- package/public/icons/catppuccin/latte/yaml.svg +3 -0
- package/public/icons/icon-192.png +0 -0
- package/public/icons/icon-512.png +0 -0
- package/public/offline.html +83 -0
- package/public/provider-icons.svg +54 -0
- package/public/sw.js +145 -0
- package/public/sw.test.mjs +141 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{14755:(e,t,n)=>{"use strict";n.d(t,{YO:()=>u,getPresetFromTools:()=>c,sn:()=>d,xG:()=>h});let r=["none","read-only","default","full"],i=[],o=["read","grep","find","ls"],l=["read","bash","edit","write"],s=["bash","read","edit","write","grep","find","ls"],a=new Set([...s,"powershell"]);function d(e){return"string"==typeof e&&r.includes(e)}function c(e){return u(e.filter(e=>e.active).map(e=>e.name))}function u(e){if(0===e.length)return"none";let t=e.map(e=>"powershell"===e?"bash":e).filter(e=>a.has(e)).sort().join(",");return t===[...o].sort().join(",")?"read-only":t===[...l].sort().join(",")?"default":t===[...s].sort().join(",")?"full":"default"}function h(e){return"none"===e?[...i]:"read-only"===e?[...o]:"full"===e?[...s]:[...l]}},50954:(e,t,n)=>{"use strict";n.d(t,{AppShell:()=>sv});var r=n(95155),i=n(12115),o=n(73321);function l(e){let t=function(e){let t=new Map(e.map(e=>[e.id,e])),n=new Map;for(let r of e){if(n.has(r.id))continue;let e=[],i=new Set,o=r.id,l=null;for(;;){if(n.has(o)){l=n.get(o)??null;break}if(i.has(o))break;i.add(o),e.push(o);let r=t.get(o);if(!r)break;if(r.relation?.kind!=="subagent"){l=r.id;break}o=r.relation.parentSessionId}for(let t of e)n.set(t,l)}return n}(e),n=new Map;for(let t of e)t.relation?.kind!=="subagent"&&n.set(t.id,{root:t,subagents:[],latestModified:t.modified});for(let r of e){if(r.relation?.kind!=="subagent")continue;let e=t.get(r.id),i=e?n.get(e):void 0;i&&(i.subagents.push(r),r.modified>i.latestModified&&(i.latestModified=r.modified))}return[...n.values()].sort((e,t)=>t.latestModified.localeCompare(e.latestModified))}let s="pi-web:file-explorer:open";function a(){try{return window.localStorage}catch{return null}}let d=/^<skill name="([^"\n]+)" location="([^"\n]+)">\nReferences are relative to [^\n]+\.\n\n([\s\S]*)\n<\/skill>(?:\n\n([\s\S]+))?$/;function c(e){let t=e.match(d);if(!t)return null;let[,n,,,r]=t;return r?`/skill:${n} ${r}`:`/skill:${n}`}function u(e,t){let n=e.slice(0,t),r=n.charCodeAt(n.length-1);return r>=55296&&r<=56319?n.slice(0,-1):n}function h(e){var t;return e.name?e.name:u((t=e.firstMessage)?u(c(t)??t,500):"",50)||e.id.slice(0,12)}function p(e){return e.projectKey??e.projectRoot??e.cwd}function f(e){let t=new Map;for(let n of e){let e=n.projectRoot??n.cwd;if(!e)continue;let r=p(n),i=t.get(r);(!i||n.modified>i.modified)&&t.set(r,{root:e,modified:n.modified})}return[...t.entries()].sort((e,t)=>t[1].modified.localeCompare(e[1].modified)).map(([e,{root:t}])=>({key:e,root:t}))}var g=n(2730),x=n(21278),m=n(47650);async function y(e){let t=e?`?path=${encodeURIComponent(e)}`:"",n=await fetch(`/api/cwd/browse${t}`),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);return r}function v(){return(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M1.5 3h4l1.5 2h7.5v7.5h-13z"})})}function b(){return(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.5"}),(0,r.jsx)("path",{d:"M2 9h12"}),(0,r.jsx)("circle",{cx:"11.5",cy:"11",r:"0.6",fill:"currentColor",stroke:"none"})]})}function w({onCancel:e,onSelect:t,initialPath:n,busy:o=!1,error:l}){let{t:s}=(0,x.s)(),[a,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(""),[h,p]=(0,i.useState)(null),[f,g]=(0,i.useState)(n??""),[k,j]=(0,i.useState)([]),[S,C]=(0,i.useState)(null),[I,M]=(0,i.useState)(null),[T,E]=(0,i.useState)(!0),L=(0,i.useCallback)(async e=>{E(!0),M(null);try{let t=await y(e),n=t.path??e??"/";u(n),p(t.parentPath??null),g(n),j(t.directories??[]),C(t.drives??null)}catch(e){M(e instanceof Error?e.message:String(e))}finally{E(!1)}},[]);(0,i.useEffect)(()=>{d(document.body),L(n||void 0)},[n,L]);let R=f.trim()!==c,N=!!c&&!R&&!o,$=!!h||/^[a-zA-Z]:[\\/]?$/.test(c);return a?(0,m.createPortal)((0,r.jsx)("div",{className:"directory-picker-backdrop",role:"dialog","aria-modal":"true","aria-label":s("directoryPicker.selectDirectory"),onClick:t=>{t.target!==t.currentTarget||o||e()},onKeyDown:t=>{"Escape"!==t.key||o||e()},style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.35)"},children:(0,r.jsxs)("div",{className:"directory-picker-panel",style:{width:520,maxWidth:"calc(100vw - 16px)",height:"min(620px, calc(100dvh - 16px))",maxHeight:"calc(100dvh - 16px)",display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 8px 32px rgba(0,0,0,0.18)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0,padding:"12px 18px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{minWidth:0,flex:1},children:(0,r.jsx)("div",{style:{color:"var(--text)",fontWeight:700,fontSize:15},children:s("directoryPicker.selectDirectory")})}),(0,r.jsx)("button",{type:"button",onClick:e,disabled:o,title:s("i18n.close"),"aria-label":s("i18n.close"),style:{padding:"2px 6px",border:0,background:"none",color:"var(--text-muted)",fontSize:20,lineHeight:1,cursor:o?"default":"pointer",opacity:o?.5:1},children:"\xd7"})]}),(0,r.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=f.trim();t&&L(t)},style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,padding:"10px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("button",{className:"directory-picker-back",type:"button",onClick:()=>void L(h??void 0),disabled:T||!$,title:s("directoryPicker.goToParent"),"aria-label":s("directoryPicker.goToParent"),style:{width:36,height:36,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:$?"pointer":"default",opacity:$?1:.45},children:(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m18 15-6-6-6 6"})})}),(0,r.jsx)("label",{htmlFor:"directory-path",style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:s("directoryPicker.directoryPath")}),(0,r.jsx)("input",{className:"directory-picker-path",id:"directory-path",type:"text",value:f,placeholder:"/path/to/project or ~/project",autoFocus:!0,autoComplete:"off",spellCheck:!1,onChange:e=>{g(e.target.value),M(null)},style:{minWidth:0,flex:1,height:36,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,outline:"none",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12}}),(0,r.jsx)("button",{className:"directory-picker-action",type:"submit",disabled:T||!f.trim(),title:s("directoryPicker.goToDirectory"),style:{minWidth:58,height:36,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:T||!f.trim()?"default":"pointer",opacity:T||!f.trim()?.6:1},children:s("directoryPicker.go")})]}),(0,r.jsxs)("div",{className:"directory-picker-list",style:{flex:1,minHeight:0,overflow:"auto",padding:"8px 10px"},children:[T?(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:s("directoryPicker.loadingDirectories")}):null!==S?(0,r.jsx)(r.Fragment,{children:S.length>0?S.map(e=>(0,r.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void L(e.path),title:e.path,style:{width:"100%",minHeight:34,display:"flex",alignItems:"center",gap:7,padding:"6px 8px",border:0,borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)",fontSize:11},children:[(0,r.jsx)(b,{}),(0,r.jsx)("span",{children:e.name})]},e.path)):(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:s("directoryPicker.noDrives")})}):k.length>0?k.map(e=>(0,r.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void L(e.path),title:e.path,style:{width:"100%",minHeight:30,display:"flex",alignItems:"center",gap:7,padding:"5px 8px",border:0,borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)",fontSize:11},children:[(0,r.jsx)(v,{}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.path)):(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:s("directoryPicker.noSubdirectories")}),(I||l)&&(0,r.jsx)("div",{style:{padding:"8px",color:"#dc2626",fontSize:11},children:I??l})]}),(0,r.jsxs)("div",{className:"directory-picker-footer",style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:10,flexShrink:0,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,r.jsx)("button",{className:"directory-picker-action",type:"button",onClick:e,disabled:o,style:{padding:"6px 14px",border:"1px solid var(--border)",borderRadius:6,background:"none",color:"var(--text-muted)",cursor:o?"default":"pointer",fontSize:13},children:s("i18n.cancel")}),(0,r.jsx)("button",{className:"directory-picker-action",type:"button",onClick:()=>t(c),disabled:!N,title:s(R?"directoryPicker.openBeforeSelecting":"directoryPicker.selectCurrentDirectory"),style:{padding:"6px 16px",border:0,borderRadius:6,background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,opacity:N?1:.6,cursor:N?"pointer":"default"},children:s(o?"i18n.checking":"directoryPicker.selectThisFolder")})]})]})}),a):null}function k({name:e,size:t=14}){let n={width:t,height:t,"--catppuccin-icon":`url(/icons/catppuccin/latte/${e}.svg)`};return(0,r.jsx)("span",{"aria-hidden":"true",className:"catppuccin-file-icon",style:n})}function j({size:e=14,open:t=!1}){return(0,r.jsx)(k,{name:t?"_folder_open":"_folder",size:e})}function S({size:e=14}){return(0,r.jsx)(k,{name:"_file",size:e})}let C={ts:"typescript",tsx:"typescript-react",js:"javascript",mjs:"javascript",cjs:"javascript",jsx:"javascript-react",py:"python",json:"json",jsonl:"json",css:"css",less:"css",scss:"sass",html:"html",htm:"html",md:"markdown",mdx:"markdown",yaml:"yaml",yml:"yaml",toml:"toml",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",rs:"rust",go:"go",sql:"database",graphql:"graphql",gql:"graphql",tf:"terraform",hcl:"terraform",docx:"ms-word",pdf:"pdf",lock:"lock"};function I(e,t=14){let n=e.toLowerCase(),i="dockerfile"===n||n.startsWith("dockerfile.")?"docker":".env"===n||n.startsWith(".env.")?"env":[".gitignore",".gitattributes",".gitmodules"].includes(n)?"git":"package-lock.json"===n?"npm-lock":"bun.lock"===n?"bun-lock":["next.config.js","next.config.mjs","next.config.cjs","next.config.ts"].includes(n)?"next":[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(n)?"eslint":["yarn.lock","pnpm-lock.yaml","cargo.lock"].includes(n)?"lock":n.endsWith(".config.ts")||n.endsWith(".config.js")||n.endsWith(".config.mjs")||n.endsWith(".config.cjs")?"config":void 0;if(i)return(0,r.jsx)(k,{name:i,size:t});let o=C[n.split(".").pop()??""];return o?(0,r.jsx)(k,{name:o,size:t}):(0,r.jsx)(S,{size:t})}function M(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function T(e){return M(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function E(e){let t=M(e).replace(/\/+$/,"");return t.split("/").pop()??t}function L(e){let t=M(e).replace(/\/+$/,""),n=t.lastIndexOf("/");return n<0?"":0===n?"/":2===n&&/^[a-zA-Z]:\//.test(t)?t.slice(0,3):t.slice(0,n)}function R(e,t){if(!t)return e;let n=M(e),r=M(t).replace(/\/$/,"");return n.startsWith(r+"/")?n.slice(r.length+1):e}function N(e,t){return`${M(e).replace(/\/$/,"")}/${t}`}async function $(e){let t=T(e),n=await fetch(`/api/files/${t}?type=list`);if(!n.ok){let e=`Failed to load files (HTTP ${n.status})`;try{let t=await n.json();t.error&&(e=t.error)}catch{}throw Error(e)}return((await n.json()).entries??[]).map(t=>({name:t.name,fullPath:N(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function W(e){let t=new URLSearchParams({cwd:e}),n=await fetch(`/api/git/status?${t.toString()}`);if(!n.ok)throw Error(`Failed to load Git status (HTTP ${n.status})`);return n.json()}let z={modified:"files.modified",added:"files.added",deleted:"files.deleted",renamed:"files.renamed",untracked:"files.untracked",conflict:"files.conflict"},P={modified:"#d6a84b",added:"#4ade80",deleted:"#f87171",renamed:"#60a5fa",untracked:"#4ade80",conflict:"#f87171"};function A({status:e,t}){return(0,r.jsx)("span",{title:t(z[e.status]),"aria-label":t(z[e.status]),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",color:P[e.status],fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600},children:e.code})}function D({size:e=11}){return(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function F({onClick:e,title:t}){return(0,r.jsx)("button",{type:"button",onClick:e,title:t,"aria-label":t,style:{width:24,height:24,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"none",borderRadius:4,background:"none",color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"m6 6 12 12"}),(0,r.jsx)("path",{d:"m18 6-12 12"})]})})}function B({node:e,depth:t,cwd:n,onOpenFile:o,onAtMention:l,expandedPaths:s,onToggleExpanded:a,refreshToken:d,highlightedPaths:c,gitStatusByPath:u,changedDirectoryPaths:h,t:p}){let f=s.has(e.fullPath),g=c.has(e.fullPath),x=M(e.fullPath),m=u.get(x),y=e.isDir&&(void 0!==m||h.has(x)),[v,b]=(0,i.useState)(e.children??[]),[w,k]=(0,i.useState)(e.loaded??!1),[S,C]=(0,i.useState)(!1),[E,L]=(0,i.useState)(null),[N,W]=(0,i.useState)(!1),z=(0,i.useCallback)(async(t=!1)=>{if(!w||t){C(!0),L(null);try{let t=await $(e.fullPath);b(t),k(!0)}catch(e){L(e instanceof Error?e.message:String(e))}finally{C(!1)}}},[w,e.fullPath]);(0,i.useEffect)(()=>{void 0!==d&&f&&w&&z(!0)},[d]);let P=(0,i.useCallback)(()=>{if(e.isDir){let t=!f;a(e.fullPath,t)}else o(e.fullPath,e.name,{cwd:n})},[n,e.isDir,e.fullPath,e.name,f,o,a]);return(0,i.useEffect)(()=>{f&&!w&&z()},[z,w,f]),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{onClick:P,onMouseEnter:()=>W(!0),onMouseLeave:()=>W(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:N?"var(--bg-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[e.isDir&&(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:f?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,r.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)("span",{style:{flexShrink:0,display:"inline-flex",alignItems:"center",transform:"translateY(0.5px)"},children:e.isDir?(0,r.jsx)(j,{size:14,open:f}):I(e.name,14)}),(0,r.jsx)("span",{style:{fontSize:12,lineHeight:1,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),g&&(0,r.jsx)("span",{title:p("files.newlyUploaded"),"aria-label":p("files.newlyUploaded"),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"#3b82f6"}})}),!N&&!e.isDir&&m&&(0,r.jsx)(A,{status:m,t:p}),!N&&y&&(0,r.jsx)("span",{title:p("files.containsChangedFiles"),"aria-label":p("files.containsChangedFiles"),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"#d6a84b"}})}),S&&(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,r.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),l&&N&&(0,r.jsxs)("button",{onClick:t=>{t.stopPropagation(),l(R(e.fullPath,n),e.isDir,n)},title:p("files.insertPath"),style:{position:"absolute",right:e.isDir?4:28,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)(D,{}),p("files.mention")]}),N&&!e.isDir&&(0,r.jsx)("a",{href:`/api/files/${T(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:p("files.download"),style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 5px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap",textDecoration:"none"},children:(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),e.isDir&&f&&(0,r.jsxs)("div",{children:[v.map(e=>(0,r.jsx)(B,{node:e,depth:t+1,cwd:n,onOpenFile:o,onAtMention:l,expandedPaths:s,onToggleExpanded:a,refreshToken:d,highlightedPaths:c,gitStatusByPath:u,changedDirectoryPaths:h,t:p},e.fullPath)),0===v.length&&w&&(0,r.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"}),E&&(0,r.jsx)("button",{type:"button",onClick:()=>void z(!0),title:E,style:{marginLeft:8+(t+1)*14,height:22,padding:0,border:0,background:"none",color:"#f87171",cursor:"pointer",fontSize:11},children:p("files.loadFailedRetry")})]})]})}function H({status:e,cwd:t,onOpenFile:n,t:o}){let[l,s]=(0,i.useState)(!1),a=E(e.filePath),d=R(e.filePath,t);return(0,r.jsxs)("div",{onClick:()=>n(e.filePath,a,{modeHint:"diff",cwd:t}),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),title:e.filePath,style:{display:"flex",alignItems:"center",gap:6,paddingLeft:10,paddingRight:8,height:24,cursor:"pointer",background:l?"var(--bg-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[(0,r.jsx)(A,{status:e,t:o}),(0,r.jsx)("span",{style:{flexShrink:0,display:"inline-flex",alignItems:"center",opacity:.85,transform:"translateY(0.5px)"},children:I(a,13)}),(0,r.jsx)("span",{style:{fontSize:12,lineHeight:1,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:d})]})}let O=(0,i.forwardRef)(function({cwd:e,onOpenFile:t,refreshKey:n,onAtMention:o,onAtMentions:l,onUploadBusyChange:s,changesCollapsed:a,onChangesCountChange:d,fileSearchOpen:c=!1,onFileSearchOpenChange:u},h){let{t:p}=(0,x.s)(),[f,g]=(0,i.useState)([]),[m,y]=(0,i.useState)(!0),[v,b]=(0,i.useState)(null),[w,k]=(0,i.useState)(new Set),[j,S]=(0,i.useState)(0),[C,I]=(0,i.useState)(new Set),[E,z]=(0,i.useState)([]),[A,O]=(0,i.useState)({additions:0,deletions:0}),[U,_]=(0,i.useState)(null),[q,K]=(0,i.useState)(null),[V,J]=(0,i.useState)("idle"),[Y,Z]=(0,i.useState)(0),[G,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)(null),[et,en]=(0,i.useState)(null),[er,ei]=(0,i.useState)(""),[eo,el]=(0,i.useState)([]),[es,ea]=(0,i.useState)(!1),[ed,ec]=(0,i.useState)(!1),[eu,eh]=(0,i.useState)(new Set),ep=(0,i.useRef)(null),ef=(0,i.useRef)(null),eg=(0,i.useRef)(null),ex=(0,i.useRef)(null),em=`${n??0}:${j}`,ey="idle"!==V,ev=er.trim().length>0;(0,i.useEffect)(()=>{if(!c)return;let t=er.trim();if(!t){el([]),ea(!1),ec(!1);return}let n=new AbortController;ea(!0),ec(!1);let r=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(e)}&q=${encodeURIComponent(t)}&kind=file&version=${encodeURIComponent(em)}`,{signal:n.signal}).then(e=>e.ok?e.json():Promise.reject(Error("Search failed"))).then(e=>el((e.matches??[]).filter(e=>!e.isDir).map(e=>e.path))).catch(()=>{n.signal.aborted||(el([]),ec(!0))}).finally(()=>{n.signal.aborted||ea(!1)})},150);return()=>{clearTimeout(r),n.abort()}},[e,c,em,er]),(0,i.useEffect)(()=>{c&&ep.current?.focus()},[c]),(0,i.useEffect)(()=>{if(0===eo.length)return;let t=new Set;for(let n of eo){let r=n.split("/"),i="";for(let n=0;n<r.length-1;n++)i=i?`${i}/${r[n]}`:r[n],t.add(N(e,i))}eh(e=>{let n=!1,r=new Set(e);for(let e of t)r.has(e)||(r.add(e),n=!0);return n?r:e})},[e,eo]);let eb=(0,i.useMemo)(()=>{let t=n=>({name:n.name,fullPath:N(e,n.path),isDir:n.isDir,size:0,children:n.children.map(t),loaded:!0});return(function(e){let t=[],n=new Map;for(let r of e){let e=r.split("/"),i=t,o="";for(let t=0;t<e.length;t++){o=o?`${o}/${e[t]}`:e[t];let r=n.get(o);r||(r={name:e[t],path:o,isDir:t<e.length-1,children:[]},n.set(o,r),i.push(r)),i=r.children}}let r=e=>{e.sort((e,t)=>e.isDir!==t.isDir?e.isDir?-1:1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t})(eo).map(t)},[e,eo]),ew=(0,i.useMemo)(()=>new Map(E.map(e=>[M(e.filePath),e])),[E]),ek=(0,i.useMemo)(()=>{let t=new Set,n=M(e).replace(/\/$/,"");for(let e of E){let r=L(M(e.filePath));for(;(r===n||r.startsWith(`${n}/`))&&(t.add(r),r!==n);){let e=L(r);if(e===r)break;r=e}}return t},[e,E]),ej=(0,i.useCallback)((e,t)=>{k(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),eS=(0,i.useCallback)(t=>{let n=t.uploaded??[];ee({uploaded:n,skipped:t.skipped??[],errors:t.errors??[]}),n.length>0&&(I(new Set(n.map(t=>N(e,t)))),S(e=>e+1))},[e]),eC=(0,i.useCallback)(async(t,n)=>{en(null),X(null),Z(0),J("uploading");try{let{status:r,data:i}=await new Promise((r,i)=>{let o=new FormData;t.forEach(e=>o.append("files",e,e.name));let l=new XMLHttpRequest;l.open("POST",`/api/files/${T(e)}?type=upload&conflict=${n}`),l.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&Z(Math.round(e.loaded/e.total*100))},l.onerror=()=>i(Error("Network error while uploading files")),l.onabort=()=>i(Error("Upload cancelled")),l.onload=()=>{let e={};try{e=JSON.parse(l.responseText)}catch{l.responseText&&(e.error=l.responseText)}r({status:l.status,data:e})},l.send(o)});if(409===r&&i.conflicts?.length)return void en({files:t,conflicts:i.conflicts,nonReplaceable:i.nonReplaceable??[]});if(r<200||r>=300)throw Error(i.error??`Upload failed (HTTP ${r})`);Z(100),eS(i)}catch(e){X(e instanceof Error?e.message:String(e))}finally{J("idle")}},[eS,e]),eI=(0,i.useCallback)(async t=>{if(0!==t.length&&!ey){ee(null),I(new Set),en(null),X(null),Z(0),J("checking");try{let n=await fetch(`/api/files/${T(e)}?type=upload-check`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileNames:t.map(e=>e.name)})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r.error??`Upload check failed (HTTP ${n.status})`);if(r.conflicts?.length)return void en({files:t,conflicts:r.conflicts,nonReplaceable:r.nonReplaceable??[]});await eC(t,"error")}catch(e){X(e instanceof Error?e.message:String(e))}finally{J("idle")}}},[e,eC,ey]),eM=(0,i.useCallback)(e=>{let t=Array.from(e.target.files??[]);e.target.value="",eI(t)},[eI]);(0,i.useImperativeHandle)(h,()=>({openUploadPicker(){ey||ex.current?.click()}}),[ey]),(0,i.useEffect)(()=>{s?.(ey)},[s,ey]),(0,i.useEffect)(()=>()=>s?.(!1),[s]),(0,i.useEffect)(()=>{let t=ef.current!==e;ef.current=e,t&&(k(new Set),I(new Set),ee(null),en(null),X(null)),y(t),b(null);let n=!1;return $(e).then(e=>{n||g(e)}).catch(e=>{n||b(e instanceof Error?e.message:String(e))}).finally(()=>{n||y(!1)}),()=>{n=!0}},[e,n,j]),(0,i.useEffect)(()=>{let t=!1;return eg.current!==e&&(_(null),z([]),O({additions:0,deletions:0})),K(null),W(e).then(n=>{t||(z(n.isGitRepository?n.files:[]),O(n.isGitRepository?{additions:n.additions,deletions:n.deletions}:{additions:0,deletions:0}),eg.current=e,_(e))}).catch(e=>{t||K(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e,n,j]),(0,i.useEffect)(()=>{d?.(U===e?E.length:0)},[e,E,U,d]);let eT=ey||null!==et||null!==G||null!==Q,eE=(0,i.useCallback)(()=>{Q&&0!==Q.uploaded.length&&l?.(Q.uploaded.map(t=>R(N(e,t),e)),e)},[e,l,Q]);return(0,r.jsxs)("div",{style:{minHeight:"100%"},children:[(0,r.jsx)("input",{ref:ex,type:"file",multiple:!0,hidden:!0,onChange:eM}),eT&&(0,r.jsxs)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:[ey&&(0,r.jsxs)("div",{role:"status","aria-live":"polite","aria-label":"checking"===V?p("files.checking"):p("files.uploading",{progress:Y}),children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,minHeight:14,color:"var(--text-muted)"},children:["checking"===V?(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-5.7-8.4"})}):(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M12 16V4"}),(0,r.jsx)("path",{d:"m7 9 5-5 5 5"}),(0,r.jsx)("path",{d:"M5 20h14"})]}),"uploading"===V&&(0,r.jsxs)("span",{style:{fontSize:10},children:[Y,"%"]})]}),"uploading"===V&&(0,r.jsx)("div",{style:{height:3,marginTop:4,overflow:"hidden",borderRadius:2,background:"var(--border)"},children:(0,r.jsx)("div",{style:{width:`${Y}%`,height:"100%",background:"var(--text-muted)",transition:"width 120ms ease"}})})]}),et&&(0,r.jsxs)("div",{role:"alert",style:{padding:7,border:"1px solid color-mix(in srgb, #f59e0b 55%, var(--border))",borderRadius:4,background:"color-mix(in srgb, #f59e0b 9%, var(--bg-panel))"},children:[(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:1.35,overflowWrap:"anywhere"},children:p("files.conflictSummary",{count:et.conflicts.length,countSuffix:1===et.conflicts.length?"":"s",files:et.conflicts.join(", ")})}),et.nonReplaceable.length>0&&(0,r.jsx)("div",{style:{marginTop:3,fontSize:10,color:"#f59e0b",lineHeight:1.35,overflowWrap:"anywhere"},children:p("files.cannotReplace",{files:et.nonReplaceable.join(", ")})}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:7},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void eC(et.files,"overwrite"),style:{height:22,padding:"0 7px",border:"1px solid #ef4444",borderRadius:4,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:10},children:p("files.replace")}),(0,r.jsx)("button",{type:"button",onClick:()=>void eC(et.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:p("files.skipExisting")}),(0,r.jsx)("button",{type:"button",onClick:()=>en(null),style:{height:22,padding:"0 7px",border:"none",borderRadius:4,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:10},children:p("files.cancel")})]})]}),G&&(0,r.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:11,lineHeight:1.35,color:"#f87171"},children:[(0,r.jsx)("span",{style:{minWidth:0,flex:1,overflowWrap:"anywhere"},children:G}),(0,r.jsx)(F,{onClick:()=>X(null),title:p("files.dismissError")})]}),Q&&(0,r.jsxs)("div",{"aria-live":"polite",children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minHeight:22,fontSize:11},children:[(0,r.jsxs)("div",{style:{minWidth:0,flex:1,display:"flex",alignItems:"center",gap:8},children:[Q.uploaded.length>0&&(0,r.jsxs)("span",{title:`${Q.uploaded.length} uploaded`,"aria-label":`${Q.uploaded.length} uploaded`,style:{display:"flex",alignItems:"center",gap:3,color:"#22c55e"},children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m5 12 4 4L19 6"})}),(0,r.jsx)("span",{children:Q.uploaded.length})]}),Q.skipped.length>0&&(0,r.jsxs)("span",{title:`${Q.skipped.length} skipped`,"aria-label":`${Q.skipped.length} skipped`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--text-dim)"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"M8 12h8"})]}),(0,r.jsx)("span",{children:Q.skipped.length})]}),Q.errors.length>0&&(0,r.jsxs)("span",{title:`${Q.errors.length} failed`,"aria-label":`${Q.errors.length} failed`,style:{display:"flex",alignItems:"center",gap:3,color:"#f87171"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M12 3 2.5 20h19L12 3Z"}),(0,r.jsx)("path",{d:"M12 9v4"}),(0,r.jsx)("path",{d:"M12 17h.01"})]}),(0,r.jsx)("span",{children:Q.errors.length})]})]}),Q.uploaded.length>0&&l&&(0,r.jsxs)("button",{type:"button",onClick:eE,title:1===Q.uploaded.length?p("files.addUploadedFile"):p("files.addAllUploadedFiles"),"aria-label":1===Q.uploaded.length?p("files.addUploadedFile"):p("files.addAllUploadedFiles"),style:{height:22,padding:"0 7px",display:"flex",alignItems:"center",justifyContent:"center",gap:4,flexShrink:0,border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)(D,{}),p("files.mention")]}),(0,r.jsx)(F,{onClick:()=>ee(null),title:p("files.dismissUploadResults")})]}),Q.errors.map(e=>(0,r.jsxs)("div",{title:e.error,style:{display:"flex",alignItems:"center",gap:4,marginTop:3,minWidth:0,fontSize:10,color:"#f87171"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"M12 8v5"}),(0,r.jsx)("path",{d:"M12 17h.01"})]}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.name))]})]}),c&&(0,r.jsxs)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("div",{style:{position:"relative"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{position:"absolute",left:8,top:"50%",transform:"translateY(-50%)",color:"var(--text-dim)",pointerEvents:"none"},children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,r.jsx)("path",{d:"m20 20-4-4"})]}),(0,r.jsx)("input",{ref:ep,value:er,onChange:e=>ei(e.target.value),onKeyDown:e=>{"Escape"===e.key&&u?.(!1)},placeholder:p("sidebar.searchFilesPlaceholder"),"aria-label":p("sidebar.searchFiles"),style:{width:"100%",boxSizing:"border-box",padding:"6px 24px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11}}),er&&(0,r.jsx)("button",{type:"button",onClick:()=>ei(""),title:p("sidebar.clearSearch"),"aria-label":p("sidebar.clearSearch"),style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",width:18,height:18,padding:0,border:"none",borderRadius:4,background:"none",color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M18 6 6 18"}),(0,r.jsx)("path",{d:"m6 6 12 12"})]})})]}),ev&&(0,r.jsxs)("div",{style:{paddingTop:3},children:[es&&(0,r.jsx)("div",{role:"status",style:{padding:"6px 2px",fontSize:10,color:"var(--text-dim)"},children:p("sidebar.searchingFiles")}),!es&&ed&&(0,r.jsx)("div",{role:"alert",style:{padding:"6px 2px",fontSize:10,color:"#f87171"},children:p("i18n.networkError")}),!es&&!ed&&0===eo.length&&(0,r.jsx)("div",{style:{padding:"6px 2px",fontSize:10,color:"var(--text-dim)"},children:p("sidebar.noMatchingFiles")}),!es&&!ed&&eo.length>0&&(0,r.jsx)("div",{children:eb.map(n=>(0,r.jsx)(B,{node:n,depth:0,cwd:e,onOpenFile:t,onAtMention:o,expandedPaths:eu,onToggleExpanded:(e,t)=>{eh(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},highlightedPaths:C,gitStatusByPath:ew,changedDirectoryPaths:ek,t:p},`${er}:${n.fullPath}`))})]})]}),q&&(0,r.jsx)("div",{role:"alert",title:q,style:{padding:"6px 12px",fontSize:11,color:"#f87171"},children:p("files.gitStatusFailed")}),!a&&U===e&&E.length>0&&(0,r.jsxs)("div",{style:{padding:"0 4px 2px"},children:[(0,r.jsxs)("div",{"aria-label":p("files.changeStats",{count:E.length,additions:A.additions,deletions:A.deletions}),style:{display:"flex",alignItems:"center",gap:6,height:24,padding:"0 10px",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:p("files.changedCount",{count:E.length})}),(0,r.jsxs)("span",{style:{color:P.added,fontFamily:"var(--font-mono)"},children:["+",A.additions]}),(0,r.jsxs)("span",{style:{color:P.deleted,fontFamily:"var(--font-mono)"},children:["-",A.deletions]})]}),E.map(n=>(0,r.jsx)(H,{status:n,cwd:e,onOpenFile:t,t:p},n.filePath))]}),(a||U!==e||0===E.length)&&(!c||!ev)&&(0,r.jsxs)("div",{style:{padding:"2px 4px"},children:[m?(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}):v?(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:v}):f.map(n=>(0,r.jsx)(B,{node:n,depth:0,cwd:e,onOpenFile:t,onAtMention:o,expandedPaths:w,onToggleExpanded:ej,refreshToken:em,highlightedPaths:C,gitStatusByPath:ew,changedDirectoryPaths:ek,t:p},n.fullPath)),!m&&!v&&0===f.length&&(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:p("files.noFiles")})]})]})});function U({open:e,query:t,refreshKey:n,children:o,selectedSessionId:l,onSelectSession:s}){let{t:a,locale:d}=(0,x.s)(),[c,u]=(0,i.useState)({query:""}),h=t.trim(),p=c.query===h?c.response:void 0,f=c.query===h&&c.failed;return(0,i.useEffect)(()=>{if(!e||!h)return;let t=new AbortController;u({query:h});let n=setTimeout(async()=>{try{let e=await fetch(`/api/sessions/search?${new URLSearchParams({q:h})}`,{signal:t.signal});if(!e.ok)throw Error(`HTTP ${e.status}`);let n=await e.json();t.signal.aborted||u({query:h,response:n})}catch{t.signal.aborted||u({query:h,failed:!0})}},300);return()=>{clearTimeout(n),t.abort()}},[e,h,n]),e&&h?(0,r.jsxs)("div",{className:"min-h-20 flex-1 overflow-y-auto","aria-busy":!p&&!f,children:[(0,r.jsx)("div",{role:"status",className:"px-3 py-2 text-xs text-text-muted",children:f?a("sidebar.sessionSearchFailed"):p?0===p.results.length?a("sidebar.sessionSearchEmpty"):a("sidebar.sessionSearchCount",{count:p.results.length}):a("sidebar.sessionSearching")}),p?.truncated&&(0,r.jsx)("div",{role:"status",className:"px-3 pb-2 text-xs text-text-muted",children:a("sidebar.sessionSearchPartial")}),p?.results.map(({session:e,entryId:t,blockIndex:n,before:i,match:o,after:a})=>(0,r.jsxs)("button",{type:"button",onClick:()=>s(e,t,n),"aria-current":e.id===l?"true":void 0,className:`block w-full cursor-pointer border-b border-border px-3 py-2 text-left hover:bg-bg-hover focus-visible:outline-2 focus-visible:outline-accent ${e.id===l?"bg-bg-selected":""}`,children:[(0,r.jsx)("span",{className:"block truncate text-xs font-medium text-text",children:e.name||e.firstMessage}),(0,r.jsxs)("span",{className:"mt-1 flex min-w-0 gap-2 text-[10px] text-text-dim",children:[(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate",title:e.cwd,children:e.cwd}),(0,r.jsx)("span",{className:"shrink-0",children:(0,g.fw)(e.modified,d)})]}),(0,r.jsxs)("span",{className:"mt-1 block text-xs leading-relaxed wrap-anywhere text-text-muted",children:[i,(0,r.jsx)("mark",{className:"rounded-sm bg-accent/20 text-text",children:o}),a]})]},e.id))]}):o}function _({size:e=14,title:t,ariaLabel:n,className:i,style:o}){let l=e<=10?4:5;return(0,r.jsxs)("span",{className:`live-pulse-beacon${i?` ${i}`:""}`,title:t,"aria-label":n,style:{width:e,height:e,...o},children:[(0,r.jsx)("span",{className:"live-pulse-beacon-halo",style:{width:l,height:l},"aria-hidden":"true"}),(0,r.jsx)("span",{className:"live-pulse-beacon-core",style:{width:l,height:l},"aria-hidden":"true"})]})}function q({size:e=14,strokeWidth:t=2,className:n,style:i}){return(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:n,style:{flexShrink:0,...i},children:[(0,r.jsx)("rect",{x:"3",y:"7",width:"13",height:"13",rx:"2"}),(0,r.jsx)("path",{d:"M8 3h10a2 2 0 0 1 2 2v10"})]})}function K({onClick:e,title:t,disabled:n,skipHover:i,color:o,background:l="none",marginRight:s,ariaPressed:a,children:d}){return(0,r.jsx)("button",{onClick:e,disabled:n,title:t,"aria-label":t,"aria-pressed":a,style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:s,background:l,border:"none",color:o,cursor:n?"default":"pointer",borderRadius:4,flexShrink:0,opacity:n?.6:1,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{n||i||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{n||i||(e.currentTarget.style.color=o,e.currentTarget.style.background=l)},children:d})}let V="pi-web:unread-session-ids",J="pi-web:last-custom-cwd";function Y(){try{return window.localStorage.getItem(J)??""}catch{return""}}function Z(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function G({text:e,style:t}){return(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",minWidth:0,lineHeight:1.35,direction:"rtl",textAlign:"left",...t},children:(0,r.jsx)("span",{style:{unicodeBidi:"plaintext"},children:e})})}function X({open:e,children:t,style:n}){let[o,l]=(0,i.useState)(e),[s,a]=(0,i.useState)(e);return((0,i.useEffect)(()=>{let t,n;return e?(l(!0),a(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>a(!0))})):(a(!1),n=setTimeout(()=>l(!1),140)),()=>{void 0!==t&&window.cancelAnimationFrame(t),n&&clearTimeout(n)}},[e]),o)?(0,r.jsx)("div",{style:{...n,opacity:+!!s,transform:s?"translateY(0) scale(1)":"translateY(-8px) scale(0.96)",transformOrigin:"top center",transition:"opacity 140ms ease, transform 140ms ease",pointerEvents:e?"auto":"none"},children:t}):null}function Q({selectedSessionId:e,onSelectSession:t,onOpenSessionInNewTab:n,onPinSession:o,onNewSession:d,initialSessionId:c,skipInitialProjectSelection:u,refreshKey:h,onSessionDeleted:g,selectedCwd:m,onCwdChange:y,onOpenFile:v,onOpenTerminal:b,explorerRefreshKey:k,onExplorerRefresh:j,onAtMention:S,onAtMentions:C,onBackgroundTaskDone:I,onRunningSessionIdsChange:M,onSessionsChange:T}){var E;let{t:L}=(0,x.s)(),[R,N]=(0,i.useState)([]),[$,W]=(0,i.useState)(null),z=(0,i.useRef)(null),P=(0,i.useRef)(0),[A,D]=(0,i.useState)(!0),[F,B]=(0,i.useState)(null),[H,q]=(0,i.useState)(null),[ee,et]=(0,i.useState)(""),[er,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(""),[es,ea]=(0,i.useState)(""),[ed,ec]=(0,i.useState)(!1),[eu,eh]=(0,i.useState)(Y),[ep,ef]=(0,i.useState)(null),[eg,ex]=(0,i.useState)(!1),[em,ey]=(0,i.useState)(null),ev=(0,i.useRef)(null),[eb,ew]=(0,i.useState)(null),[ek,ej]=(0,i.useState)(!1),[eS,eC]=(0,i.useState)(!1),[eI,eM]=(0,i.useState)(""),[eT,eE]=(0,i.useState)(null),[eL,eR]=(0,i.useState)(!1),[eN,e$]=(0,i.useState)(null),[eW,ez]=(0,i.useState)(null),eP=(0,i.useRef)(null),eA=(0,i.useRef)(null),[eD,eF]=(0,i.useState)(!0),[eB,eH]=(0,i.useState)(0),[eO,eU]=(0,i.useState)(!1),[e_,eq]=(0,i.useState)(!1),[eK,eV]=(0,i.useState)(!1),[eJ,eY]=(0,i.useState)(""),eZ=eK&&!!eJ.trim(),[eG,eX]=(0,i.useState)(0),[eQ,e0]=(0,i.useState)(!0),[e1,e2]=(0,i.useState)(()=>new Set),[e4,e8]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(V);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}})()),e5=(0,i.useRef)(new Set),e6=(0,i.useRef)(new Set),e3=(0,i.useRef)(new Set),e7=(0,i.useRef)(!1),e9=(0,i.useRef)(null),te=(0,i.useRef)(null),[tt,tn]=(0,i.useState)(0),[tr,ti]=(0,i.useState)(0),[to,tl]=(0,i.useState)(null),[ts,ta]=(0,i.useState)(null),td=(0,i.useRef)(null),tc=(0,i.useCallback)(e=>{ta(null);let t=e.currentTarget.scrollTop;null==td.current&&(td.current=requestAnimationFrame(()=>{td.current=null,ti(t)}))},[]);(0,i.useEffect)(()=>{if(!ts)return;let e=e=>{let t=e.target;t?.closest(".session-row-actions")||ta(null)};return window.addEventListener("pointerdown",e,!0),()=>window.removeEventListener("pointerdown",e,!0)},[ts]),(0,i.useLayoutEffect)(()=>{let e=te.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e)tn(t.contentRect.height)});return t.observe(e),tn(e.clientHeight),ti(e.scrollTop),()=>t.disconnect()},[eZ]);let tu=(0,i.useCallback)(async(e=!1,t=!1)=>{let n=++P.current;try{e&&D(!0);let r=await fetch(t?"/api/sessions?force=1":"/api/sessions",{cache:"no-store"});if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();if(n!==P.current)return;z.current=i.sessionListVersion,W(i.sessionListVersion),N(i.sessions),e7.current||(e6.current=new Set(i.completionNotificationSuppressedSessionIds??[]),e2(new Set(i.runningSessionIds??[])));let o=new Set(i.sessions.filter(e=>e.relation?.kind!=="subagent").map(e=>e.id));e8(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>o.has(e)));return t.size===e.size?e:t}),B(null)}catch(e){n===P.current&&B(String(e))}finally{n===P.current&&D(!1)}},[]),th=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!th.current;th.current=!0,tu(e,!e)},[tu,h]),(0,i.useEffect)(()=>{eF(function(e=a()){if(!e)return!0;try{return"false"!==e.getItem(s)}catch{return!0}}())},[]),(0,i.useEffect)(()=>{try{0===e4.size?window.localStorage.removeItem(V):window.localStorage.setItem(V,JSON.stringify([...e4]))}catch{}},[e4]),(0,i.useEffect)(()=>{let e=!1,t=null,n=null,r=()=>{t&&clearTimeout(t),t=null},i=async()=>{if(e||"visible"!==document.visibilityState)return;let o=new AbortController;n?.abort(),n=o;try{let t=await fetch("/api/agent/running",{cache:"no-store",signal:o.signal});if(!t.ok)return;let r=await t.json();if(e||n!==o)return;e7.current=!0,e6.current=new Set(r.completionNotificationSuppressedSessionIds??[]),e2(new Set(r.runningSessionIds??[])),r.sessionListVersion!==z.current&&await tu()}catch{}finally{n===o&&(n=null),r(),e||"visible"!==document.visibilityState||(t=setTimeout(()=>void i(),2500))}},o=()=>{"visible"===document.visibilityState?i():(r(),n?.abort(),n=null)};return i(),document.addEventListener("visibilitychange",o),()=>{e=!0,r(),n?.abort(),document.removeEventListener("visibilitychange",o)}},[tu]),(0,i.useEffect)(()=>{M?.(e1)},[M,e1]),(0,i.useEffect)(()=>{T?.(R)},[R,T]),(0,i.useEffect)(()=>{let t=e5.current,n=[...t].filter(t=>!e1.has(t)&&t!==e),r=new Set(R.filter(e=>e.relation?.kind==="subagent").map(e=>e.id)),i=n.filter(e=>!e3.current.has(e)&&!r.has(e)),o=[...e1].filter(e=>!t.has(e));(i.length>0||o.length>0)&&e8(e=>{let t=new Set(e);return e1.forEach(e=>t.delete(e)),i.forEach(e=>t.add(e)),t});let l=o.some(e=>!R.some(t=>t.id===e));(n.length>0||l)&&tu(!1,!0),i.length>0&&I?.(i),e5.current=e1,e3.current=new Set([...e1].filter(e=>e6.current.has(e)||r.has(e)))},[e1,e,R,tu,I]),(0,i.useEffect)(()=>{e&&e8(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[e]),(0,i.useEffect)(()=>{void 0!==k&&eH(e=>e+1)},[k]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&et(e.home)}).catch(()=>{})},[]);let tp=(0,i.useRef)(!1),tf=(0,i.useCallback)((e,t)=>({root:e,key:t}),[]),tg=(0,i.useCallback)(e=>{if(!e)return null;if(em?.cwd===e)return tf(em.root,em.key);if(eb&&eb.forCwd===e||eb?.worktrees.some(t=>t.path===e))return tf(eb.projectRoot,eb.projectKey);let t=R.find(t=>t.cwd===e||(t.projectRoot??t.cwd)===e);return t?tf(t.projectRoot??t.cwd,p(t)):tf(e,e)},[em,eb,R,tf]),tx=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=tg(H),t=tx.current;(t?.cwd!==H||t.key!==(e?.key??null))&&(tx.current={cwd:H,key:e?.key??null},y?.(H,e?.root??null,e?.key??null))},[H,y,tg]);let tm=(0,i.useRef)(null);(0,i.useEffect)(()=>{m&&m!==tm.current&&(tm.current=m,q(m))},[m]);let[ty,tv]=(0,i.useState)(0);(0,i.useLayoutEffect)(()=>{if(!H){ew(null),ez(null);return}let e=!1;return ez(H),fetch(`/api/worktrees?cwd=${encodeURIComponent(H)}`).then(e=>e.json()).then(t=>{if(!e){if(ez(null),t.error||!t.projectRoot)return void ew(null);ew({forCwd:H,projectRoot:t.projectRoot,projectKey:t.projectKey??t.projectRoot,isGit:t.isGit??!1,isTopLevel:t.isTopLevel??!1,currentWorktreePath:t.currentWorktreePath??null,worktrees:t.worktrees??[]})}}).catch(()=>{e||(ez(null),ew(null))}),()=>{e=!0}},[H,ty,h]),(0,i.useEffect)(()=>{if(0!==R.length&&!u&&null===H){if(c&&!tp.current){tp.current=!0;let e=R.find(e=>e.id===c);if(e){q(e.cwd),t(e,!0);return}}let e=f(R);e.length>0&&q(e[0].root)}},[R,H,c,u,t]);let tb=eb?eb.worktrees.find(e=>e.path===H)??(eb.forCwd===H&&eb.currentWorktreePath?eb.worktrees.find(e=>e.path===eb.currentWorktreePath):void 0)??eb.worktrees.find(e=>e.isMain):void 0,tw=tb?.path??null,tk=(0,i.useCallback)(async e=>{let t=(e??eu).trim();if(t&&!eg){ex(!0),ef(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||!r.cwd||!r.projectRoot||!r.projectKey)return void ef(r.error??`HTTP ${e.status}`);ey({cwd:r.cwd,root:r.projectRoot,key:r.projectKey});var n=r.cwd;try{window.localStorage.setItem(J,n)}catch{}eh(r.cwd),q(r.cwd),ec(!1),ei(!1)}catch(e){ef(e instanceof Error?e.message:String(e))}finally{ex(!1)}}},[eu,eg]),tj=(0,i.useCallback)(()=>{ec(!0),ef(null),ei(!1)},[]),tS=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(q(t.cwd),ec(!1),ef(null),ei(!1))}catch{}},[]),tC=(0,i.useCallback)(async()=>{let e=eI.trim();if(e&&!eL&&eb){eR(!0),eE(null);try{let t=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:eb.projectRoot,branch:e})}),n=await t.json().catch(()=>({}));if(!t.ok||n.error||!n.path)return void eE(n.error??`HTTP ${t.status}`);eC(!1),eM(""),ej(!1),ew(t=>t?{...t,forCwd:n.path,currentWorktreePath:n.path,worktrees:[...t.worktrees,{path:n.path,branch:e,isMain:!1}]}:t),q(n.path),tv(e=>e+1)}catch(e){eE(e instanceof Error?e.message:String(e))}finally{eR(!1)}}},[eI,eL,eb]),tI=(0,i.useCallback)(async(e,t)=>{if(eb&&!eL){eR(!0),eE(null);try{let n=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:eb.projectRoot,path:e,force:t})}),r=await n.json().catch(()=>({}));if(!n.ok){if(r.dirty&&!t)return void e$(e);eE(r.error??`HTTP ${n.status}`);return}e$(null),tw===e&&q(eb.projectRoot),tv(e=>e+1)}catch(e){eE(e instanceof Error?e.message:String(e))}finally{eR(!1)}}},[eb,eL,tw]);(0,i.useEffect)(()=>{let e=e=>{ev.current&&!ev.current.contains(e.target)&&(ei(!1),el("")),eP.current&&!eP.current.contains(e.target)&&(ej(!1),eC(!1),eM(""),eE(null),e$(null),ea(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let tM=(0,i.useCallback)((e,n,r)=>{N(t=>t.some(t=>t.id===e.id)?t:[e,...t]),function(e){let t=e.sessionCwd;if(!t)return!1;let n=e.selectedCwd;if(!n)return!0;if(t===n)return!1;let r=e.worktrees;if(!r?.length)return!0;let i=e=>r.find(t=>t.path===e)?.path??null,o=i(t);return!!o&&o!==(i(n)??n)}({sessionCwd:e.cwd,selectedCwd:H,worktrees:eb?.worktrees})&&q(e.cwd),t(e,!1,n,r)},[t,H,eb]),tT=(0,i.useCallback)(()=>{if(!H)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)}`;d?.(e,H)},[H,d]),tE=f(R),tL=!H&&!A&&!F&&0===tE.length,tR=tE.length>8,tN=eo.trim()?tE.filter(e=>e.root.toLowerCase().includes(eo.trim().toLowerCase())):tE,t$=tg(H),tW=(0,i.useMemo)(()=>(function(e,t,n){let r=new Map;for(let i of e){let e=p(i);if(!e)continue;let o=r.get(e);o||(o={running:0,unread:0},r.set(e,o)),t.has(i.id)&&o.running++,n.has(i.id)&&o.unread++}return r})(R,e1,e4),[R,e1,e4]),tz=(0,i.useMemo)(()=>{let e=0,t=0;for(let[n,r]of tW.entries())n!==t$?.key&&(e+=r.running,t+=r.unread);return{running:e,unread:t}},[tW,t$]),tP=t$?(E=t$.key,R.filter(e=>p(e)===E)):R,tA=!!(eb?.isGit&&eb.isTopLevel&&H&&t$?.key===eb.projectKey),tD=H&&eb&&t$?.key===eb.projectKey&&!tA?eb.isGit?{label:L("sidebar.openRepoRoot"),title:L("sidebar.openRepoRootTitle")}:{label:L("sidebar.gitRepoRootOnly"),title:L("sidebar.gitRepoRootOnlyTitle")}:null,tF=!!(H&&eW===H),tB=tD??(tF&&!tA?{label:L("sidebar.worktrees"),title:L("sidebar.checkingWorktrees")}:null),tH=l(tP),tO=function(e,t,n,r=-1){let i=Math.ceil((n||600)/28)+16,o=Math.max(0,Math.min(Math.floor(t/28)-8,e-i)),l=Math.min(e,o+i),s=Array.from({length:l-o},(e,t)=>o+t);return r>=0&&r<o&&s.unshift(r),r>=l&&r<e&&s.push(r),s}(tH.length,tr,tt,tH.findIndex(e=>e.root.id===to));return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[ed&&(0,r.jsx)(w,{initialPath:eu,busy:eg,error:ep,onCancel:()=>{ec(!1),ef(null)},onSelect:e=>void tk(e)}),(0,r.jsxs)("div",{style:{height:"var(--workspace-header-height, 30px)",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 0 0 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontWeight:700,fontSize:13,letterSpacing:"-0.01em",color:"var(--text)",height:"100%",display:"inline-flex",alignItems:"center"},children:"Pi Web"}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,r.jsx)("button",{type:"button",className:"workspace-header-action",onClick:tT,disabled:!H,style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"none",border:"none",color:H?"var(--text-muted)":"var(--text-dim)",cursor:H?"pointer":"not-allowed",flexShrink:0,transition:"color 0.12s, background 0.12s"},title:H?L("sidebar.newSessionTitle",{path:H}):L("sidebar.selectProject"),"aria-label":H?L("sidebar.newSessionTitle",{path:H}):L("sidebar.selectProject"),onMouseEnter:e=>{H&&(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=H?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),(0,r.jsx)("button",{type:"button",onClick:()=>{eV(e=>!e),ej(!1)},title:L("sidebar.toggleSessionSearch"),"aria-label":L("sidebar.toggleSessionSearch"),"aria-expanded":eK,"aria-controls":"session-search-input",style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:eK?"var(--bg-selected)":"none",border:"none",color:eK?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},className:"workspace-header-action",onMouseEnter:e=>{eK||(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{eK||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="none")},children:(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,r.jsx)("path",{d:"m20 20-4-4"})]})})]})]}),(H||tL)&&(0,r.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{ref:ev,style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>ei(e=>!e),title:t$?.root??H??L("sidebar.selectProject"),style:{width:"100%",display:"flex",alignItems:"center",padding:"6px 10px",background:H?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:H?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:4,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left",transition:"border-color 0.15s, background 0.15s"},children:[H?(0,r.jsx)(G,{text:Z(t$?.root??H,ee),style:{flex:1,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text)"}}):(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:L("sidebar.selectProject")}),tz.running>0?(0,r.jsx)("span",{style:{marginLeft:6,display:"inline-flex",alignItems:"center",flexShrink:0},children:(0,r.jsx)(_,{size:12,title:`${L("sidebar.agentRunning")} (${tz.running})`,ariaLabel:`${L("sidebar.agentRunning")} (${tz.running})`})}):tz.unread>0?(0,r.jsx)("span",{title:`${L("sidebar.newSessionActivity")} (${tz.unread})`,"aria-label":`${L("sidebar.newSessionActivity")} (${tz.unread})`,style:{marginLeft:6,display:"inline-flex",alignItems:"center",justifyContent:"center",width:12,height:12,flexShrink:0},children:(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",style:{display:"block"},children:[(0,r.jsx)("circle",{cx:"6",cy:"6",r:"5",fill:"#10b981"}),(0,r.jsx)("path",{d:"M3.6 6.2l1.6 1.6 3.2-3.4",stroke:"#ffffff",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]})}):null]}),(0,r.jsxs)(X,{open:er,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[tR&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px",borderBottom:"1px solid var(--border)",background:"var(--bg-subtle)"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,r.jsx)("input",{className:"sidebar-dropdown-filter-input",value:eo,onChange:e=>el(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(el(""),ei(!1))},placeholder:L("sidebar.filterProjects"),autoFocus:!0,style:{flex:1,minWidth:0,fontSize:12,fontFamily:"inherit",padding:"2px 0",border:"none",outline:"none",background:"transparent",color:"var(--text)"}}),eo&&(0,r.jsx)("button",{type:"button",onClick:()=>el(""),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,padding:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer"},title:L("chat.clear"),children:(0,r.jsxs)("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,r.jsxs)("div",{style:{maxHeight:"min(50vh, 380px)",overflowY:"auto"},children:[tN.map(e=>{var t,n;return(0,r.jsxs)("button",{onClick:()=>{q(e.root),el(""),ec(!1),ef(null),ei(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"var(--bg)",border:"none",borderBottom:"1px solid var(--border)",color:e.key===t$?.key?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.root,children:[e.key===t$?.key&&(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}),e.key!==t$?.key&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(G,{text:Z(e.root,ee),style:{flex:1}}),(t=tW.get(e.key),n=L,t&&(0!==t.running||0!==t.unread)?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5,flexShrink:0,marginLeft:6},children:[t.running>0&&(0,r.jsxs)("span",{title:n("sidebar.agentRunning"),"aria-label":`${n("sidebar.agentRunning")} (${t.running})`,style:{display:"inline-flex",alignItems:"center",gap:3.5,color:"var(--accent)",fontSize:10,fontFamily:"var(--font-mono)",lineHeight:1},children:[(0,r.jsx)(_,{size:12}),(0,r.jsx)("span",{style:{lineHeight:1},children:t.running})]}),t.unread>0&&(0,r.jsxs)("span",{title:n("sidebar.newSessionActivity"),"aria-label":`${n("sidebar.newSessionActivity")} (${t.unread})`,style:{display:"inline-flex",alignItems:"center",gap:3.5,color:"#10b981",fontSize:10,fontFamily:"var(--font-mono)",lineHeight:1},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",style:{display:"block",flexShrink:0},children:[(0,r.jsx)("circle",{cx:"6",cy:"6",r:"5",fill:"#10b981"}),(0,r.jsx)("path",{d:"M3.6 6.2l1.6 1.6 3.2-3.4",stroke:"#ffffff",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),(0,r.jsx)("span",{style:{lineHeight:1},children:t.unread})]})]}):null)]},e.key)}),0===tN.length&&eo.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:L("sidebar.noMatchingProjects")})]}),!ed&&(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tS()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:tN.length>0?"1px solid var(--border)":"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2H4L5 3.5H8.5a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-7A.5.5 0 0 1 1 8V3Z"})}),(0,r.jsx)("span",{children:L("sidebar.useDefaultDirectory")})]}),(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tj()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,r.jsx)("span",{children:L("sidebar.customPath")})]})]})]}),eK&&(0,r.jsx)("input",{id:"session-search-input",type:"search",autoFocus:!0,value:eJ,maxLength:200,"aria-label":L("sidebar.searchSessions"),placeholder:L("sidebar.searchSessions"),onChange:e=>eY(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),eY(""))},className:"mt-[6px] block h-[29px] w-full min-w-0 rounded-[4px] border border-border bg-bg px-[10px] text-xs text-text focus:outline-2 focus:outline-accent"}),!eK&&tA&&(()=>{if(!eb)return null;let e=eb.worktrees.length>=8,t=e&&es.trim()?eb.worktrees.filter(e=>(e.branch??Z(e.path,ee)).toLowerCase().includes(es.trim().toLowerCase())):eb.worktrees;return(0,r.jsxs)("div",{ref:eP,style:{position:"relative",marginTop:6},children:[(0,r.jsxs)("button",{onClick:()=>ej(e=>!e),title:tb?L("sidebar.switchWorktreeTitle",{path:tb.path}):L("sidebar.switchWorktree"),style:{width:"100%",height:29,boxSizing:"border-box",display:"flex",alignItems:"center",gap:6,padding:"0 10px",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",fontSize:11,lineHeight:1.35,color:"var(--text-muted)",textAlign:"left"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:tb&&!tb.isMain?"var(--accent)":"var(--text-dim)"},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,r.jsx)(G,{text:tb?tb.branch??Z(tb.path,ee):"…",style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)"}}),tb?.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:L("sidebar.main")}),eb.worktrees.length>1&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:eb.worktrees.length}),(0,r.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),(0,r.jsxs)(X,{open:ek,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[e&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px",borderBottom:"1px solid var(--border)",background:"var(--bg-subtle)"},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,r.jsx)("input",{className:"sidebar-dropdown-filter-input",value:es,onChange:e=>ea(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(ea(""),ej(!1))},placeholder:L("sidebar.filterWorktrees"),autoFocus:!0,style:{flex:1,minWidth:0,fontSize:12,fontFamily:"inherit",padding:"2px 0",border:"none",outline:"none",background:"transparent",color:"var(--text)"}}),es&&(0,r.jsx)("button",{type:"button",onClick:()=>ea(""),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,padding:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer"},title:L("chat.clear"),children:(0,r.jsxs)("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,r.jsxs)("div",{style:{maxHeight:"min(40vh, 300px)",overflowY:"auto"},children:[t.map(e=>{let t=e.path===tw;return eN===e.path?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"rgba(239,68,68,0.06)"},children:[(0,r.jsx)("span",{style:{flex:1,fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:L("sidebar.forceRemoveCheckout")}),(0,r.jsx)("button",{onClick:()=>void tI(e.path,!0),disabled:eL,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:4,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:L("sidebar.force")}),(0,r.jsx)("button",{onClick:()=>e$(null),style:{padding:"3px 9px",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",fontSize:11,cursor:"pointer",flexShrink:0},children:L("sidebar.cancel")})]},e.path):(0,r.jsxs)("div",{className:"wt-row",style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{onClick:()=>{q(e.path),ej(!1),eE(null),ea("")},title:e.path,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px",background:"var(--bg)",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[t?(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(G,{text:e.branch??Z(e.path,ee),style:{flex:1}}),e.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:L("sidebar.main")})]}),!e.isMain&&(0,r.jsx)("button",{onClick:()=>void tI(e.path,!1),disabled:eL,title:L("sidebar.removeWorktreeTitle",{path:e.path}),style:{display:"flex",alignItems:"center",justifyContent:"center",width:34,height:28,padding:0,marginRight:4,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",borderRadius:4,flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="#ef4444",e.currentTarget.style.background="rgba(239,68,68,0.08)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]},e.path)}),e&&0===t.length&&es.trim()&&(0,r.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:L("sidebar.noMatchingWorktrees")})]}),eS?(0,r.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,r.jsx)("input",{ref:eA,value:eI,onChange:e=>{eM(e.target.value),eE(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),tC()),"Escape"===e.key&&(eC(!1),eM(""),eE(null))},placeholder:L("sidebar.branchName"),style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:4,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,r.jsx)("button",{onClick:()=>void tC(),disabled:eL||!eI.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",fontSize:11,fontWeight:600,cursor:eL||!eI.trim()?"not-allowed":"pointer",opacity:eL||!eI.trim()?.65:1},children:eL?L("sidebar.creating"):L("sidebar.create")}),(0,r.jsx)("button",{onClick:()=>{eC(!1),eM(""),eE(null)},style:{flex:1,padding:"4px 0",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:L("sidebar.cancel")})]})]}):(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),eC(!0),eE(null),setTimeout(()=>eA.current?.focus(),0)},title:L("sidebar.createWorktreeTitle"),style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,r.jsx)("span",{children:L("sidebar.newWorktree")})]}),eT&&(0,r.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:eT})]})]})})(),!eK&&tB&&(0,r.jsxs)("button",{type:"button","aria-disabled":"true",tabIndex:-1,title:tB.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:4,background:"var(--bg-hover)",color:"var(--text-dim)",fontSize:11,lineHeight:1.35,whiteSpace:"nowrap",textAlign:"left",cursor:"default",opacity:.82},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:tB.label})]})]}),(0,r.jsx)(U,{open:eK,query:eJ,refreshKey:$,selectedSessionId:e,onSelectSession:tM,children:(0,r.jsxs)("div",{ref:te,onScroll:tc,style:{flex:eD&&(m||H)?"1 1 0":"1 1 auto",overflowY:"auto",padding:"0",minHeight:80},children:[F&&(0,r.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:F}),!A&&!F&&!tL&&0===tH.length&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:L("sidebar.noSessions")}),tH.length>0&&(0,r.jsx)("div",{style:{position:"relative",height:28*tH.length},children:tO.map(t=>{let i=tH[t],l=[i.root,...i.subagents],s=i.latestModified===i.root.modified?i.root:{...i.root,modified:i.latestModified};return(0,r.jsx)("div",{onFocus:()=>tl(i.root.id),onBlur:()=>tl(null),style:{position:"absolute",top:28*t,left:0,right:0},children:(0,r.jsx)(en,{session:s,isSelected:l.some(t=>t.id===e),isRunning:l.some(e=>e1.has(e.id)),isUnread:l.some(e=>e4.has(e.id)),isActionsRevealed:ts===i.root.id,onRevealActions:()=>ta(i.root.id),onDismissActions:()=>ta(e=>e===i.root.id?null:e),onClick:()=>{ta(null),tM(i.root)},onRenamed:tu,onOpenInNewTab:n?()=>{ta(null),n(i.root)}:void 0,onPin:o?()=>{ta(null),o(i.root)}:void 0,onDeleted:e=>{ta(null),g?.(e),tu()}})},i.root.id)})})]})}),(m||H)&&(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:eD?"1 1 0":"0 0 auto",minHeight:0,overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0},children:[(0,r.jsxs)("button",{onClick:()=>eF(e=>{let t=!e;return!function(e,t=a()){if(t)try{t.setItem(s,String(e))}catch{}}(t),t}),style:{display:"flex",alignItems:"center",gap:6,flex:1,padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,r.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:eD?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,r.jsx)("polyline",{points:"3 2 7 5 3 8"})}),L("files.explorer")]}),b&&(0,r.jsx)(K,{onClick:()=>b(H??m),title:L("terminal.open"),color:"var(--text-dim)",children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,r.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}),eD&&eG>0&&(0,r.jsx)(K,{onClick:()=>e0(e=>!e),title:L("sidebar.changedFiles",{count:eG}),ariaPressed:!eQ,color:eQ?"var(--text-dim)":"var(--accent)",background:eQ?"none":"var(--bg-selected)",children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,r.jsx)("path",{d:"M3 12h6"}),(0,r.jsx)("path",{d:"M15 12h6"})]})}),eD&&(0,r.jsx)(K,{onClick:()=>{eq(e=>!e)},title:L("sidebar.searchFiles"),ariaPressed:e_,color:e_?"var(--accent)":"var(--text-dim)",background:e_?"var(--bg-selected)":"none",children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,r.jsx)("path",{d:"m20 20-4-4"})]})}),eD&&(0,r.jsx)(K,{onClick:()=>e9.current?.openUploadPicker(),disabled:eO,title:L("sidebar.uploadFilesTitle"),color:"var(--text-dim)",children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("path",{d:"m17 8-5-5-5 5"}),(0,r.jsx)("path",{d:"M12 3v12"})]})}),(0,r.jsx)(K,{onClick:()=>{j?j():eH(e=>e+1)},title:L("sidebar.refreshExplorer"),color:"var(--text-dim)",marginRight:6,children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"})]})})]}),eD&&(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",overflowX:"hidden"},children:(0,r.jsx)(O,{ref:e9,cwd:H??m,onOpenFile:v??(()=>{}),refreshKey:eB,onAtMention:S,onAtMentions:C,onUploadBusyChange:eU,changesCollapsed:eQ,onChangesCountChange:eX,fileSearchOpen:e_,onFileSearchOpenChange:eq})})]})]})}function ee(){let{t:e}=(0,x.s)();return(0,r.jsx)(_,{size:14,title:e("sidebar.agentRunning"),ariaLabel:e("sidebar.agentRunning")})}function et(){let{t:e}=(0,x.s)();return(0,r.jsx)("span",{title:e("sidebar.newSessionActivity"),"aria-label":e("sidebar.newSessionActivity"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",style:{display:"block"},children:[(0,r.jsx)("circle",{cx:"6",cy:"6",r:"5",fill:"#10b981"}),(0,r.jsx)("path",{d:"M3.6 6.2l1.6 1.6 3.2-3.4",stroke:"#ffffff",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]})})}function en({session:e,isSelected:t,isRunning:n,isUnread:o,isActionsRevealed:l=!1,onRevealActions:s,onDismissActions:a,onClick:d,onRenamed:u,onOpenInNewTab:p,onPin:f,onDeleted:m,depth:y=0,hasChildren:v=!1,collapsed:b=!1,onToggleCollapse:w}){let{locale:k,t:j}=(0,x.s)(),[S,C]=(0,i.useState)(!1),[I,M]=(0,i.useState)(!1),[T,E]=(0,i.useState)(""),[L,R]=(0,i.useState)(!1),[N,$]=(0,i.useState)(!1),W=(0,i.useRef)(null),z=(0,i.useRef)(null),P=(0,i.useRef)(null),A=(0,i.useRef)(!1),D=(0,i.useCallback)(t=>{if(L||I||e.transient)return;let n=t.touches[0];P.current={x:n.clientX,y:n.clientY},A.current=!1,z.current=setTimeout(()=>{A.current=!0,window.getSelection()?.removeAllRanges();try{navigator.vibrate?.(15)}catch{}s?.()},400)},[L,s,I,e.transient]),F=(0,i.useCallback)(e=>{if(!P.current||!z.current)return;let t=e.touches[0],n=Math.abs(t.clientX-P.current.x),r=Math.abs(t.clientY-P.current.y);(n>10||r>10)&&(clearTimeout(z.current),z.current=null)},[]),B=(0,i.useCallback)(()=>{z.current&&(clearTimeout(z.current),z.current=null)},[]);(0,i.useEffect)(()=>{if(I){let e=requestAnimationFrame(()=>W.current?.select());return()=>cancelAnimationFrame(e)}},[I]);let H=c(e.firstMessage)??e.firstMessage,O=h(e),U=(0,i.useCallback)(t=>{t?.stopPropagation(),e.transient||(E(h(e)),M(!0))},[e]),_=(0,i.useCallback)(async()=>{let t=T.trim();if(M(!1),T!==O&&t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),u?.()}catch{}},[T,e.id,e.name,u,O]),K=(0,i.useCallback)(async()=>{if(!e.transient){R(!1),$(!0);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"});if(!t.ok)throw Error(`HTTP ${t.status}`);m?.(e.id)}catch{$(!1)}}},[e.id,e.transient,m]),V=(0,i.useCallback)(e=>{e.stopPropagation(),e.shiftKey?K():R(!0)},[K]),J=(0,i.useCallback)(e=>{e.stopPropagation(),K()},[K]),Y=(0,i.useCallback)(e=>{e.stopPropagation(),R(!1)},[]),Z=(0,i.useCallback)(t=>{if(A.current||l){t.preventDefault(),t.stopPropagation();return}(function(e,t=window){let n=new CustomEvent("pi-web:session-row-contextmenu",{cancelable:!0,detail:e});return!t.dispatchEvent(n)})({id:e.id,path:e.path,cwd:e.cwd,name:e.name,clientX:t.clientX,clientY:t.clientY,refresh:()=>{u?.()}})&&(t.preventDefault(),t.stopPropagation())},[l,u,e.cwd,e.id,e.name,e.path]);return(0,r.jsx)("div",{className:`session-list-row${l?" is-actions-revealed":""}`,onClick:e=>{if(A.current){A.current=!1,e.preventDefault(),e.stopPropagation();return}l?a?.():L||I||d()},onDoubleClick:()=>{L||I||l||e.transient||f?.()},onTouchStart:D,onTouchMove:F,onTouchEnd:B,onTouchCancel:B,onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:e=>{1!==e.button||!p||L||I||(e.preventDefault(),e.stopPropagation(),p())},onContextMenu:L||I?void 0:Z,onMouseEnter:()=>C(!0),onMouseLeave:()=>{C(!1)},style:{height:28,position:"relative",display:"flex",alignItems:"center",paddingLeft:y>0?12*y+10:10,paddingRight:8,cursor:L||I?"default":"pointer",background:L?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":S?"var(--bg-hover)":"transparent",borderLeft:L?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:N?.5:1,gap:6,overflow:"hidden",userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none"},children:L?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j("sidebar.deleteSession",{title:O.slice(0,22)+(O.length>22?"…":"")})}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,r.jsxs)("button",{onClick:J,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:24,padding:"0 8px",background:"#ef4444",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),j("sidebar.delete")]}),(0,r.jsx)("button",{onClick:Y,style:{display:"flex",alignItems:"center",justifyContent:"center",height:24,padding:"0 8px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:j("sidebar.cancel")})]})]}):I?(0,r.jsx)("input",{ref:W,value:T,onChange:e=>E(e.target.value),onBlur:_,onKeyDown:e=>{"Enter"===e.key&&_(),"Escape"===e.key&&M(!1)},autoFocus:!0,className:"session-rename-input",style:{flex:1,minWidth:0,fontSize:13,fontWeight:t?500:400,fontFamily:"inherit",lineHeight:1.4,padding:"1px 6px",border:"1px solid var(--accent)",borderRadius:4,outline:"none",background:"var(--bg)",color:"var(--text)",height:24,boxSizing:"border-box"}}):(0,r.jsxs)(r.Fragment,{children:[y>0&&(0,r.jsx)(q,{size:11,strokeWidth:2,style:{color:"var(--accent)"}}),(0,r.jsx)("button",{type:"button","aria-current":t?"page":void 0,style:{flex:1,minWidth:0,padding:0,border:"none",background:"none",color:"inherit",font:"inherit",textAlign:"left",cursor:"pointer"},children:(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",gap:5,minWidth:0,fontSize:13,fontWeight:t?500:400,lineHeight:1.4,color:"var(--text)"},title:e.name||H||e.id,children:(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:O})})}),e.isWorktree&&e.branch&&(0,r.jsx)("span",{title:`Worktree: ${e.branch}
|
|
2
|
+
${e.cwd}`,style:{display:"flex",color:"var(--text-dim)",flexShrink:0},children:(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}),v&&(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),w?.()},title:j(b?"sidebar.expandSubagents":"sidebar.collapseSubagents"),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:b?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),(0,r.jsx)("div",{className:"session-row-meta",style:{display:"flex",alignItems:"center",justifyContent:"flex-end",flexShrink:0,color:"var(--text-dim)",fontSize:11,whiteSpace:"nowrap"},children:n?(0,r.jsx)(ee,{}):o?(0,r.jsx)(et,{}):(0,r.jsx)("span",{title:e.modified,children:(0,g.wA)(e.modified,k)})}),!e.transient&&(0,r.jsxs)("div",{className:"session-row-actions",style:{display:"flex",alignItems:"center",gap:2,position:"absolute",right:6,top:0,height:"100%",background:t?"var(--bg-selected)":S?"var(--bg-hover)":"var(--bg-panel)",paddingLeft:4,borderRadius:4},children:[p&&(0,r.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),a?.(),p()},title:j("chatTabs.openInNewTab",{defaultValue:"在新标签页打开"}),"aria-label":j("chatTabs.openInNewTab",{defaultValue:"在新标签页打开"}),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"transparent",border:"none",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background=t?"var(--bg-hover)":"var(--bg-selected)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,r.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,r.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),f&&(0,r.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),a?.(),f()},onDoubleClick:e=>e.stopPropagation(),title:j("chatTabs.pinTab",{defaultValue:"固定标签"}),"aria-label":j("chatTabs.pinTab",{defaultValue:"固定标签"}),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"transparent",border:"none",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background=t?"var(--bg-hover)":"var(--bg-selected)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"22"}),(0,r.jsx)("path",{d:"M5 17h14v-1.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1v4.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24Z"})]})}),(0,r.jsx)("button",{onClick:e=>{a?.(),U(e)},title:j("sidebar.rename"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"transparent",border:"none",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background=t?"var(--bg-hover)":"var(--bg-selected)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,r.jsx)("button",{onClick:e=>{a?.(),V(e)},title:j("sidebar.deleteWithShiftClick"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"transparent",border:"none",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.12)",e.currentTarget.style.color="#ef4444"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,r.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,r.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}function er({src:e,alt:t="",children:n,className:o,style:l}){let{t:s}=(0,x.s)(),[a,d]=(0,i.useState)(!1),c=(0,i.useRef)(null),u=(0,i.useRef)(null),h=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!a)return;let e=u.current;if(!e)return;let t=c.current,n=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),h.current?.focus({preventScroll:!0}),()=>{document.body.style.overflow=n,e.open&&e.close(),t?.isConnected&&t.focus({preventScroll:!0})}},[a]);let p=()=>{u.current?.open&&u.current.close(),d(!1)};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:c,type:"button",className:o,style:{display:"block",padding:0,border:"none",background:"none",color:"inherit",cursor:"zoom-in",...l},onClick:()=>d(!0),"aria-label":s("chat.previewImage"),"aria-haspopup":"dialog","aria-expanded":a,title:s("chat.previewImage"),children:n}),a&&(0,r.jsxs)("dialog",{ref:u,className:"image-preview-dialog","aria-label":s("chat.previewImage"),onCancel:e=>{e.preventDefault(),e.stopPropagation(),p()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),p())},onClick:e=>{e.target===e.currentTarget&&p()},children:[(0,r.jsx)("img",{className:"image-preview-image",src:e,alt:t}),(0,r.jsx)("button",{ref:h,type:"button",className:"image-preview-close",onClick:p,"aria-label":s("chat.close"),title:s("chat.close"),children:(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})]})]})}let ei="pi-image-result",eo=[{model:"gpt-image-2.5-flare",label:"Flare"},{model:"gpt-image-2.5-sunburst",label:"Sunburst"},{model:"grok-imagine-image-2.0",label:"Grok"}],el=["1:1","16:9","9:16","4:3","3:4","3:2","2:3"];function es(e,t){let n=Math.abs(e),r=Math.abs(t);for(;r;){let e=n%r;n=r,r=e}return`${e/n}:${t/n}`}let ea=/@"([^"]+)"|@([^\s"]+)/g,ed=/\.(?:png|jpe?g|webp)$/i;function ec(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function eu(e){if(!ec(e)||![ei,"pi-web:image"].includes(e.type)||1!==e.version)return null;let t=e.type===ei;return!("string"!=typeof e.path||!e.path||t&&(!e.path.startsWith(".pi/generated-images/")||e.path.split(/[\\/]/).includes("..")))&&"string"==typeof e.mimeType&&e.mimeType.startsWith("image/")&&"string"==typeof e.prompt&&e.prompt&&"string"==typeof e.connection&&e.connection&&(void 0===e.label||"string"==typeof e.label&&e.label)&&"string"==typeof e.model&&e.model&&"number"==typeof e.width&&Number.isSafeInteger(e.width)&&!(e.width<=0)&&"number"==typeof e.height&&Number.isSafeInteger(e.height)&&!(e.height<=0)&&(void 0===e.size||"string"==typeof e.size)&&(void 0===e.resolution||"string"==typeof e.resolution)&&(void 0===e.quality||"string"==typeof e.quality)&&(void 0===e.source||"string"==typeof e.source)?{...e,type:ei}:null}function eh(e,t,n){if("generate_image"!==e)return null;let r=eu(n);return r?r.source?"edit":"generate":ec(t)&&!0===t.new_image?"generate":ec(t)&&("string"==typeof t.target&&t.target||!0===t.use_last_attachment)?"edit":null}function ep(e,t){return`/api/files/${T(e)}?type=${t}`}function ef(e,t){return e.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(e)?e:t?N(t,e):e}function eg({path:e,cwd:t,onRemove:n}){let{t:i}=(0,x.s)(),o=ep(ef(e,t),"read");return(0,r.jsxs)("span",{className:"relative inline-block shrink-0 overflow-hidden rounded-md border border-border align-middle",style:{width:56,height:56},children:[(0,r.jsx)("img",{src:o,alt:"",className:"block h-full w-full object-cover"}),n?(0,r.jsx)("button",{type:"button",onClick:n,className:"absolute right-0.5 top-0.5 flex h-4 w-4 items-center justify-center rounded-full border-0 bg-black/55 text-white","aria-label":i("i18n.close"),children:(0,r.jsx)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M18 6 6 18M6 6l12 12"})})}):null]})}function ex(e,t){return{aspectRatio:`${e} / ${t}`,width:`min(100%, calc(28rem * ${e/t}))`}}function em({value:e,cwd:t,onEdit:n,onMention:o,showPrompt:l=!1,createdAt:s}){let a,d,c,u,{t:h,locale:p}=(0,x.s)(),f=eu(e),[g,m]=(0,i.useState)(!1);if(!f)return null;let y=ef(f.path,t),v=ep(y,"read"),b=(c=[(a=function(e,t){if(e<=0||t<=0)return es(e,t);let n=e/t,r=el[0],i=1/0;for(let e of el){let[t,o]=e.split(":").map(Number),l=Math.abs(n-t/o)/(t/o);l<i&&(r=e,i=l)}return i<=.03?r:es(e,t)}(f.width,f.height),d=`${f.width}\u00d7${f.height}`,a===`${f.width}:${f.height}`?d:`${a}(${d})`)],f.resolution&&c.push(f.resolution.toUpperCase()),(u="low"===f.quality?h("image.qualityLow"):"medium"===f.quality?h("image.qualityMedium"):"high"===f.quality?h("image.qualityHigh"):"auto"===f.quality?h("image.qualityAuto"):f.quality)&&c.push(u),c.join(" \xb7 ")),w=[f.label?f.label:f.model.includes("sunburst")?"Sunburst":f.model.includes("flare")?"Flare":f.model.includes("grok-imagine")?"Grok":f.model.includes("flash-image")?"Banana 2":f.model,s?function(e,t){let n=new Date(e),r=new Date,i=n.toLocaleTimeString(t,{hour:"2-digit",minute:"2-digit",hour12:!1});if(n.getFullYear()===r.getFullYear()&&n.getMonth()===r.getMonth()&&n.getDate()===r.getDate())return i;let o=n.toLocaleDateString(t,{month:"short",day:"numeric",year:n.getFullYear()!==r.getFullYear()?"numeric":void 0});return`${o} ${i}`}(s,p):void 0].filter(Boolean).join(" \xb7 ");return(0,r.jsxs)("article",{className:"mb-3 mt-2 w-fit max-w-full",children:[(0,r.jsxs)("div",{className:"relative max-w-full overflow-hidden rounded-[10px] border border-border/80 bg-bg-panel",style:ex(f.width,f.height),children:[g?(0,r.jsx)("div",{className:"flex h-full min-h-28 items-center justify-center px-4 text-xs text-text-muted",children:h("chat.imagePreviewUnavailable")}):(0,r.jsx)(er,{src:v,alt:f.prompt,className:"block h-full w-full",children:(0,r.jsx)("img",{src:v,alt:f.prompt,loading:"lazy",onError:()=>m(!0),className:"block h-full w-full object-cover"})}),(0,r.jsx)("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-end p-2",children:(0,r.jsxs)("div",{className:"pointer-events-auto flex items-center rounded-full bg-black/50 p-0.5 text-white backdrop-blur-sm",children:[n?(0,r.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),n(f)},title:h("image.edit"),className:"h-7 rounded-full px-2.5 text-[11px] font-medium tracking-wide text-white/95 hover:bg-white/15",children:h("image.edit")}):null,n?(0,r.jsx)("span",{className:"mx-0.5 h-3 w-px bg-white/25","aria-hidden":"true"}):null,o?(0,r.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),o(f.path)},title:h("image.quote"),"aria-label":h("image.quote"),className:"inline-flex h-7 w-7 items-center justify-center rounded-full text-white/95 hover:bg-white/15",children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M9 17 4 12l5-5"}),(0,r.jsx)("path",{d:"M20 18v-2a4 4 0 0 0-4-4H4"})]})}):null,(0,r.jsx)("a",{href:ep(y,"download"),download:!0,title:h("i18n.downloadFile"),"aria-label":h("i18n.downloadFile"),onClick:e=>e.stopPropagation(),className:"inline-flex h-7 w-7 items-center justify-center rounded-full text-white/95 hover:bg-white/15",children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("path",{d:"m7 10 5 5 5-5M12 15V3"})]})})]})})]}),l&&f.prompt?(0,r.jsx)("p",{className:"mt-1.5 line-clamp-3 text-[12px] leading-snug text-text-muted",title:f.prompt,children:f.prompt}):null,b||w?(0,r.jsxs)("div",{className:`${l&&f.prompt?"mt-1":"mt-1.5"} max-w-full text-[11px] leading-snug tracking-wide text-text-muted`,title:f.model,children:[b,b&&w?" \xb7 ":null,w]}):null]})}function ey({prompt:e,size:t,width:n,height:i,previewUrl:o}){let{t:l}=(0,x.s)(),{w:s,h:a}=function(e,t){if(e&&"auto"!==e){let t=/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?)$/.exec(e.trim());if(t)return{w:Number(t[1]),h:Number(t[2])};let n=/^(\d+)x(\d+)$/.exec(e.trim());if(n)return{w:Number(n[1]),h:Number(n[2])}}return t?.width&&t.height?{w:t.width,h:t.height}:{w:1,h:1}}(t,{width:n,height:i});return(0,r.jsxs)("article",{className:"mb-3 mt-2 w-fit max-w-full",children:[(0,r.jsxs)("div",{role:"status","aria-label":l("image.generating"),className:"relative max-w-full overflow-hidden rounded-[10px] border border-border/80 bg-bg-panel",style:ex(s,a),children:[o?(0,r.jsx)("img",{src:o,alt:"",className:"absolute inset-0 h-full w-full object-cover opacity-35"}):null,(0,r.jsx)("div",{className:"image-pending-sheen","aria-hidden":"true"})]}),e?(0,r.jsx)("p",{className:"mt-1.5 line-clamp-3 text-[12px] leading-snug text-text-muted",children:e}):null]})}function ev(e,t,n,r){let i=e?.capabilities[t];if(r&&i?.includes(r))return r;let o=e?.defaults?.[n];return o&&i?.includes(o)?o:i?.includes("auto")?"auto":i?.[0]??""}function eb({value:e,label:t,onChange:n,children:i}){return(0,r.jsxs)("label",{className:"relative inline-flex flex-none items-center",children:[(0,r.jsx)("select",{"aria-label":t,value:e,onChange:e=>n(e.target.value),className:"image-generation-select appearance-none bg-transparent py-1 pl-1.5 pr-5 text-[12px] text-text-muted outline-none hover:text-text focus:text-text",children:i}),(0,r.jsx)("svg",{className:"pointer-events-none absolute right-0.5 top-1/2 -translate-y-1/2 text-text-dim",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}function ew({config:e,edit:t,editPreviewUrl:n,onClose:o,onSubmit:l}){let{t:s}=(0,x.s)(),a=(0,i.useRef)(null),d=(0,i.useRef)(null),[c,u]=(0,i.useState)(""),[h,p]=(0,i.useState)(()=>t?.connection&&e.connections.some(e=>e.id===t.connection)?t.connection:e.defaultConnection);(0,i.useEffect)(()=>{e.connections.some(e=>e.id===h)||p(e.defaultConnection||e.connections[0]?.id||"")},[e,h]);let f=e.connections.find(e=>e.id===h)??e.connections[0],[g,m]=(0,i.useState)(()=>ev(f,"sizes","size",t?.size)),[y,v]=(0,i.useState)(()=>ev(f,"resolutions","resolution",t?.resolution)),[b,w]=(0,i.useState)(()=>ev(f,"qualities","quality",t?.quality)),k=f?.capabilities.sizes??[],j=f?.capabilities.resolutions??[],S=f?.capabilities.qualities??[],C=!!t,I=e.connections.length>1;(0,i.useLayoutEffect)(()=>{let e=d.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,160)}px`)},[c]),(0,i.useEffect)(()=>{let e=document.activeElement;return window.matchMedia("(max-width: 640px)").matches||d.current?.focus(),()=>{e?.isConnected&&e.focus()}},[]),(0,i.useEffect)(()=>{let e=t&&f?.id===t.connection?t:void 0;m(ev(f,"sizes","size",e?.size)),v(ev(f,"resolutions","resolution",e?.resolution)),w(ev(f,"qualities","quality",e?.quality))},[f,t]);let M=()=>{if(!c.trim()||!f)return;let e={prompt:c.trim(),connection:f.id,...g?{size:g}:{},...y?{resolution:y}:{},...b?{quality:b}:{},...t?{target:t.path}:{new_image:!0}};o(),l(e)};return(0,r.jsx)("div",{role:"presentation",className:"fixed inset-0 z-[1100] flex items-end justify-center bg-black/40 p-0 sm:items-center sm:p-4",onClick:e=>{e.target===e.currentTarget&&o()},children:(0,r.jsxs)("div",{ref:a,role:"dialog","aria-modal":"true","aria-labelledby":"image-generation-title",tabIndex:-1,className:"flex max-h-[min(92dvh,100%)] w-full max-w-full flex-col overflow-hidden rounded-t-[16px] border border-border/80 bg-bg-panel shadow-2xl sm:max-h-[calc(100dvh-2rem)] sm:w-[480px] sm:rounded-[12px]",onKeyDown:e=>{if("Escape"===e.key){e.preventDefault(),o();return}if((e.metaKey||e.ctrlKey)&&"Enter"===e.key){e.preventDefault(),M();return}if("Tab"!==e.key)return;let t=Array.from(a.current?.querySelectorAll("button:not(:disabled), textarea:not(:disabled), select:not(:disabled), input:not(:disabled)")??[]).filter(e=>null!==e.offsetParent);if(!t.length)return;let n=t[0],r=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):e.shiftKey||document.activeElement!==r||(e.preventDefault(),n.focus())},children:[(0,r.jsx)("div",{className:"flex justify-center pt-2 sm:hidden","aria-hidden":"true",children:(0,r.jsx)("div",{className:"h-1 w-10 rounded-full bg-border"})}),(0,r.jsxs)("header",{className:"flex h-10 shrink-0 items-center px-4 sm:h-11",children:[(0,r.jsx)("h2",{id:"image-generation-title",className:"text-[14px] font-medium text-text",children:C?s("image.editTitle"):s("image.title")}),(0,r.jsx)("button",{type:"button",onClick:o,className:"ml-auto inline-flex h-7 w-7 items-center justify-center rounded-md border-0 bg-transparent text-text-muted hover:bg-bg-hover hover:text-text",title:s("trust.cancel"),"aria-label":s("trust.cancel"),children:(0,r.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),(0,r.jsx)("div",{className:"min-h-0 overflow-y-auto px-4",children:(0,r.jsxs)("div",{className:C&&n?"flex flex-col gap-3 sm:flex-row sm:items-start":void 0,children:[C&&n?(0,r.jsx)("div",{className:"overflow-hidden rounded-[10px] sm:shrink-0",children:(0,r.jsx)("img",{src:n,alt:t?.prompt??s("image.editSource"),className:"block h-auto w-full sm:h-28 sm:w-auto sm:max-w-[7.5rem]"})}):null,(0,r.jsx)("textarea",{ref:d,id:"image-prompt",rows:2,value:c,maxLength:32e3,"aria-label":s("image.prompt"),onChange:e=>u(e.target.value),placeholder:C?s("image.editPromptPlaceholder"):s("image.promptPlaceholder"),className:`image-generation-prompt w-full resize-none rounded-[10px] border-0 bg-bg px-3 py-2.5 leading-[1.5] text-text outline-none ring-1 ring-inset ring-transparent placeholder:text-text-dim focus:ring-accent/50 ${C&&n?"sm:min-h-28 sm:flex-1":""}`,style:{fontFamily:"var(--font-chat)",fontSize:"var(--chat-content-font-size, 14px)"}})]})}),(0,r.jsxs)("footer",{className:"flex shrink-0 items-center gap-2 px-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-3",children:[(0,r.jsxs)("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-x-1 gap-y-0.5",children:[I?(0,r.jsx)(eb,{value:h,label:s("image.connection"),onChange:p,children:e.connections.map(e=>(0,r.jsx)("option",{value:e.id,children:e.label},e.id))}):null,k.length?(0,r.jsx)(eb,{value:g,label:s("image.aspect"),onChange:m,children:k.map(e=>{let t,n,i;return(0,r.jsx)("option",{value:e,children:"auto"===(t="auto"===(i=e.trim())?"auto":(n=function(e){let t=/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?)$/.exec(e.trim())??/^(\d+)x(\d+)$/.exec(e.trim());if(!t)return null;let n=Number(t[1]),r=Number(t[2]);return!Number.isFinite(n)||!Number.isFinite(r)||n<=0||r<=0?null:{width:n,height:r}}(i))?n.width===n.height?"square":n.width>n.height?"landscape":"portrait":null)?s("image.aspectAuto"):"square"===t?`${s("image.aspectSquare")} ${e}`:"portrait"===t?`${s("image.aspectPortrait")} ${e}`:"landscape"===t?`${s("image.aspectLandscape")} ${e}`:e},e)})}):null,j.length?(0,r.jsx)(eb,{value:y,label:s("image.resolution"),onChange:v,children:j.map(e=>(0,r.jsx)("option",{value:e,children:e.toUpperCase()},e))}):null,S.length?(0,r.jsx)(eb,{value:b,label:s("image.quality"),onChange:w,children:S.map(e=>(0,r.jsx)("option",{value:e,children:"auto"===e?s("image.qualityAuto"):"low"===e?s("image.qualityLow"):"medium"===e?s("image.qualityMedium"):"high"===e?s("image.qualityHigh"):e},e))}):null]}),(0,r.jsx)("button",{type:"button",disabled:!c.trim(),onClick:M,className:"h-8 shrink-0 rounded-md border-0 bg-accent px-3 text-[12.5px] font-medium text-white disabled:cursor-not-allowed disabled:opacity-50",children:C?s("image.edit"):s("image.generate")})]})]})})}let ek=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,ej=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,eS=/\x1B_pi:c\x07/g;function eC(e){return e.replace(eS,"").replace(ek,"")}function eI(e){let t=[],n=0;for(;n<e.length;){if(27===e.charCodeAt(n)){let t=e.slice(n).match(ej);if(t){n+=t[0].length;continue}}let r=e.codePointAt(n);if(void 0===r)break;let i=String.fromCodePoint(r);t.push({start:n,end:n+i.length,char:i}),n+=i.length}return t}function eM(e,t){let n=eI(e)[t];return n?e.slice(0,n.start)+e.slice(n.end):e}function eT(e){return eI(e)[0]?.char}let eE={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:""},eL={ArrowLeft:"\x1bb",ArrowRight:"\x1bf",ArrowUp:"\x1bp",ArrowDown:"\x1bn"};function eR(e){return"user"===e.role||"custom"===e.role&&"compaction"===e.customType}function eN(e){return"custom"===e.role&&"pi-web:subagent-notification"===e.customType}function e$(e){return eR(e)||eN(e)}function eW(e,t={}){return"thinking"===e.type&&!e.deferred&&!t.isStreaming&&""===e.thinking.trim()}function ez(e,t={}){return(e.content??[]).filter(e=>!eW(e,t)&&!function(e,t={}){return"text"===e.type&&!t.isStreaming&&""===e.text.trim()}(e,t))}function eP(e,t={}){return t.isStreaming||"error"!==e.stopReason?null:e.errorMessage?.trim()||"Unknown provider error"}function eA(e,t={}){let n=ez(e,t),r=n.findLastIndex(e=>!function(e,t={}){return"image"===e.type||"text"===e.type&&(t.isStreaming?e.text.length>0:e.text.trim().length>0)}(e,t));return -1===r?{answerBlocks:n,processBlocks:[]}:{answerBlocks:n.slice(r+1),processBlocks:n.slice(0,r+1)}}function eD(e){return e.filter(e=>"toolCall"===e.type).length}function eF(e){return!e.defaultPrevented&&0===e.button&&!e.shiftKey&&!e.altKey}function eB(e){try{return decodeURIComponent(e)}catch{return e}}function eH(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function eO(e){let t=eH(e),n=/^[a-zA-Z]:\//.test(t),r=t.startsWith("//"),i=t.startsWith("/")&&!n&&!r,o=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){o.length>0&&".."!==o[o.length-1]?o.pop():i||n||r||o.push(e);continue}o.push(e)}let l=o.join("/");return n?l:r?`//${l}`:i?`/${l}`:l}function eU(e,t,n=t){let r,i,o,l,s;if(!e)return null;let a=e.split("#",1)[0].split("?",1)[0].trim();if(!a)return null;let d=null,c=null,u=eB(a),h=u.startsWith("\\\\"),p=eH(u),f=p.toLowerCase();if(f.startsWith("/api/")||f.startsWith("/_next/")||!h&&p.startsWith("//")||/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(p)&&!f.startsWith("file:")&&!/^[a-zA-Z]:\//.test(p))return null;if(f.startsWith("file:")?c=(d=function(e){try{let t=new URL(e);if("file:"!==t.protocol)return null;let n=eB(t.pathname);if(t.hostname)return`//${t.hostname}${n.startsWith("/")?n:`/${n}`}`;if(/^\/[a-zA-Z]:\//.test(n))return n.slice(1);return n}catch{return null}}(a))?"absolute":null:/^[a-zA-Z]:\//.test(p)||p.startsWith("/")?(d=p,c="absolute"):t&&!(p.startsWith("#")||p.startsWith("?"))&&(p.startsWith("./")||p.startsWith("../")||p.includes("/")||/(^|\/)\.?[^/]+\.[^/.]+$/.test(p))&&(d=`${eH(t).replace(/\/+$/,"")}/${p}`,c="relative"),!d)return null;let g=eO(d).replace(/:\d+(?::\d+)?$/,"");return"relative"===c&&n&&(r=eO(g).replace(/\/+$/,""),i=eO(n).replace(/\/+$/,""),l=(o=/^[a-zA-Z]:\//.test(r)||/^[a-zA-Z]:\//.test(i))?r.toLowerCase():r,!(l===(s=o?i.toLowerCase():i)||l.startsWith(`${s}/`)))?null:g}function e_(e){let t=e.toLowerCase();return"edit"===t||t.startsWith("edit_")||t.endsWith(".edit")||t.endsWith("_edit")||t.includes("str_replace")||t.includes("replace_editor")}function eq(e,t,n){let r=e.trim().split("\n").map(e=>`> ${e}`).join("\n");return`${t}
|
|
3
|
+
|
|
4
|
+
${r}
|
|
5
|
+
|
|
6
|
+
${n}`}function eK(e,t,n=50){let r=Math.max(0,e),i=Math.min(Math.max(0,t),Math.max(0,r-Math.min(n,r))),o=r-i;return{startIndex:Math.max(0,o-n),endIndex:o}}function eV(e,t,n,r=8){return e+t>=n-r}class eJ extends Error{constructor(e,t){super(t),this.name="OutlineLocateError",this.reason=e}}function eY(e,t){return e.entry.id===t||!!e.compressedEntryIds?.includes(t)}function eZ(e,t){if(!e)return null;let n=new Map,r=[];for(let t=e.length-1;t>=0;t--)n.set(e[t],null),r.push(e[t]);for(;r.length>0;){let e=r.pop();if(eY(e,t)){let t=[],r=e;for(;r;)t.push(r),r=n.get(r)??null;return t.reverse(),t}let i=e.children;if(i&&0!==i.length)for(let t=i.length-1;t>=0;t--)n.set(i[t],e),r.push(i[t])}return null}async function eG(e,t,n,r){let i=t,o=new Set;for(;;){if(r.throwIfAborted(),i.entryIds.includes(e))return;let t=i.oldestEntryId;if(!i.hasMore||!t)throw new eJ("exhausted","Question is no longer in this branch. Refresh the outline and try again.");if(o.has(t))throw new eJ("stalled","History did not advance. Please try again.");o.add(t);let l=await n(t);if(r.throwIfAborted(),!l)throw new eJ("load_failed","Could not load this question. Please try again.");if(l.entryIds.includes(e))return;if(l.oldestEntryId===t||null!==l.oldestEntryId&&o.has(l.oldestEntryId))throw new eJ("stalled","History did not advance. Please try again.");i=l}}function eX(e,t){return t.aborted||e instanceof DOMException&&"AbortError"===e.name||e instanceof Error&&"AbortError"===e.name}var eQ=n(32316),e0=n(88374),e1=n(5924),e2=n(94764),e4=n(63835),e8=n(54152),e5=n(84678),e6=n(98164);let e3={...e2.j,attributes:{...e2.j.attributes,code:[["className",/^language-./,"math-inline","math-display"]]},protocols:{...e2.j.protocols,href:[...e2.j.protocols?.href??[],"file"]},strip:[...e2.j.strip||[],"iframe","object","style","form"]};function e7(e){return/^file:/i.test(e)?e:(0,eQ.Lv)(e)}let e9=/(?<![\\`])`((?:[^`\n]|\\`)+?)(?<![\\`])`(?!`)/g;function te(e){let t=e.includes("\r\n")?"\r\n":"\n",n=e.split(/\r?\n/),r=[],i=null,o=0,l=null,s=new Map;for(let e=0;e<n.length;e++){var a,d;let t=n[e];if(l){r.push(t),RegExp(`</${l}\\s*>`,"i").test(t)&&(l=null);continue}let c=t.match(/^ {0,3}(`{3,}|~{3,})/);if(c){let e=c[1][0],n=c[1].length;i?e===i.marker&&n>=i.size&&(i=null):i={marker:e,size:n},o=0,r.push(t);continue}if(i){r.push(t);continue}let u=t.match(/<(code|pre|script|style)\b/i);if(u){let e=u[1].toLowerCase(),n=t.slice((u.index??0)+u[0].length);RegExp(`</${e}\\s*>`,"i").test(n)||(l=e),o=0,r.push(t);continue}if(/^(?: {4}|\t)/.test(t)||""===t.trim()){o=0,r.push(t);continue}if(o||(t=t.replace(e9,(e,t)=>{let n=t.replace(/\\`/g,"`");if(n===t)return e;let r="`".repeat(Math.max(...n.match(/`+/g)?.map(e=>e.length)??[0])+1);return`${r}${n}${r}`})),o||t.includes("`")){o=function(e,t){let n=t;for(let t=0;t<e.length;){if("`"!==e[t]){t++;continue}let r=t+1;for(;"`"===e[r];)r++;let i=r-t;0===n?n=i:i===n&&(n=0),t=r}return n}(t,o),r.push(t);continue}let h=t.match(/^([ ]{0,3})\\\[[ \t]*(.+?)[ \t]*\\\][ \t]*$/);if(h){let e=h[2].trim();if(e){r.push(`${h[1]}$$`,`${h[1]}${e}`,`${h[1]}$$`);continue}}let p=t.match(/^([ ]{0,3})\[[ \t]*(.+?)[ \t]*\][ \t]*$/);if(p){let e=p[2].trim();if(a=e,/\\[A-Za-z]+/.test(a)&&!/\b(?:https?|file|mailto):|\b[A-Za-z]:\\|^\\\\/i.test(a)){r.push(`${p[1]}$$`,`${p[1]}${e}`,`${p[1]}$$`);continue}}let f=t.match(/^([ ]{0,3})\\\[[ \t]*$/);if(f){let t=function(e,t){for(let n=t;n<e.length;n++){let t=e[n];if(/^ {0,3}\\\][ \t]*$/.test(t))return n;if(/^ {0,3}(`{3,}|~{3,})/.test(t)||/^ {0,3}\\\[[ \t]*$/.test(t)||/<(code|pre|script|style)\b/i.test(t))break}return -1}(n,e+1);if(-1!==t){r.push(`${f[1]}$$`,...n.slice(e+1,t).map(e=>tn(e,f[1])),`${f[1]}$$`),e=t;continue}}let g=t.match(/^([ \t]{0,3})\$\$(.+)\$\$[ \t]*$/);if(g){let e=g[2].trim();if(e){r.push(`${g[1]}$$`,`${g[1]}${e}`,`${g[1]}$$`);continue}}let x=t.match(/^([ \t]{0,3})\$\$(.+)$/);if(x){let t=x[1],i=x[2].trimEnd();if(i&&!i.includes("$$")){let o=tt(n,e+1,t,s);if(o){r.push(`${t}$$`,`${t}${i}`);for(let i=e+1;i<o.index;i++)r.push(tn(n[i],t));o.content&&r.push(`${t}${o.content}`),r.push(`${t}$$`),e=o.index;continue}}}let m=t.match(/^([ \t]{0,3})\$\$\s*$/);if(m){let t=m[1],i=tt(n,e+1,t,s);if(i&&(i.glued||""!==t)){r.push(`${t}$$`);for(let o=e+1;o<i.index;o++)r.push(tn(n[o],t));i.content&&r.push(`${t}${i.content}`),r.push(`${t}$$`),e=i.index;continue}}r.push((d=t,/^\s{0,3}\[[^\]]+\]:/.test(d)||/]\s*\(/.test(d)||/<(?:!--|\/?[A-Za-z][^>]*>)/.test(d)||/\b(?:https?|file|mailto):/i.test(d)||/\b[A-Za-z]:\\/.test(d)?d:d.replace(/(?<!\\)\\\(([^`\r\n$]+?)(?<!\\)\\\)/g,(e,t)=>t.trim()?`$${t}$`:e)))}return r.join(t)}function tt(e,t,n,r){let i=r.get(n);if(void 0!==i&&t<i)return null;for(let i=t;i<e.length;i++){var o,l,s,a;let t=e[i];if(o=t,""===(l=n)?/^ {0,3}\$\$\s*$/.test(o):o.startsWith(l)&&/^\$\$\s*$/.test(o.slice(l.length)))return{index:i,content:"",glued:!1};if(s=t,/^ {0,3}(`{3,}|~{3,})/.test(s)||/^[ \t]*(?:[-+*]|\d{1,9}[.)])(?:[ \t]+|$)/.test(s)||/^ {0,3}#{1,6}(?:[ \t]+|$)/.test(s)||/^ {0,3}>/.test(s)||/<(code|pre|script|style)\b/i.test(s)||(a=t,/^ {0,3}\$\$(?:\S|[ \t]+\S)/.test(a)))return r.set(n,i),null;let d=function(e,t){if(!e.startsWith(t))return null;let n=e.slice(t.length).match(/^(.+?)\$\$\s*$/);if(!n)return null;let r=n[1].trimEnd();return r&&!r.includes("$$")?r:null}(t,n);if(null!==d)return{index:i,content:d,glued:!0}}return r.set(n,e.length),null}function tn(e,t){if(!t||!e||e.startsWith(" "))return e;let n=e.match(/^ */)?.[0].length??0;return n>=t.length?e:`${t.slice(n)}${e}`}let tr={singleTilde:!1},ti=[[e8.A,["yaml"]],[e5.A,tr],e6.A],to=[[e8.A,["yaml"]],[e5.A,tr],e6.A],tl=[e1.A,[e4.A,e3],[e0.A,{throwOnError:!1,strict:!1}]],ts=[e1.A,[e4.A,e3],[e0.A,{throwOnError:!1,strict:!1}]];var ta=n(7644);let td="pi-theme",tc=["light","dark","auto"],tu={preference:"auto",theme:"light"},th=new Set,tp=null,tf=!1;function tg(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function tx(e){return"auto"===e?tg():e}let tm={light:"#f5f5f5",dark:"#242424"};function ty(e){"u">typeof document&&(document.documentElement.classList.toggle("dark","dark"===e),function(e){if("u"<typeof document)return;let t=tm[e],n=document.querySelectorAll('meta[name="theme-color"]');if(0===n.length){let e=document.createElement("meta");e.name="theme-color",e.content=t,document.head.appendChild(e);return}for(let e of n)e.removeAttribute("media"),e.content=t}(e))}function tv(){if(tp)return tp;let e=function(){try{let e=localStorage.getItem(td);if("light"===e||"dark"===e||"auto"===e)return e}catch{}return"auto"}(),t=tx(e);return ty(t),tp={preference:e,theme:t}}function tb(e,t,n){if(ty(t),n)try{localStorage.setItem(td,e)}catch{}tp={preference:e,theme:t},th.forEach(e=>e())}function tw(){let e=tv();if("auto"!==e.preference)return;let t=tg();t!==e.theme&&tb("auto",t,!1)}function tk(e){return th.add(e),tv(),tf||!window.matchMedia||(window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",tw),window.addEventListener("focus",tw),document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&tw()}),tf=!0),tw(),()=>{th.delete(e)}}function tj(){return tv()}function tS(){return tu}function tC(){let e=(0,i.useSyncExternalStore)(tk,tj,tS),t=(0,i.useCallback)((e,t)=>{if(tv().preference===e)return;let n=tx(e),r=()=>{tb(e,n,!0)},i=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||i)return void r();let o=t?.x??window.innerWidth/2,l=t?.y??window.innerHeight/2,s=Math.hypot(Math.max(o,window.innerWidth-o),Math.max(l,window.innerHeight-l));document.startViewTransition(r).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${o}px ${l}px)`,`circle(${s}px at ${o}px ${l}px)`]},{duration:450,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})}).catch(()=>{})},[]),n=(0,i.useCallback)(e=>{var n;let r;t((n=tv().preference,r=tc.indexOf(n),tc[(r+1)%tc.length]),e)},[t]);return{theme:e.theme,preference:e.preference,setThemePreference:t,toggleTheme:n,isDark:"dark"===e.theme}}function tI(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()}}var tM=n(65063);function tT({code:e,isStreaming:t,defaultPreview:o=!1}){let{isDark:l}=tC(),{t:s}=(0,x.s)(),[a,d]=(0,i.useState)(o),[c,u]=(0,i.useState)(null),[h,p]=(0,i.useState)(!1),f=(0,i.useRef)(null),g=`${l?"dark":"light"}
|
|
7
|
+
${e}`,m=a&&!t;(0,i.useEffect)(()=>{if(!m)return;let t=!1;return u({key:g,status:"loading"}),(async()=>{let{default:r}=await Promise.all([n.e(988),n.e(9425),n.e(3308)]).then(n.bind(n,43328));if(r.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:l?"dark":"default"}),!await r.parse(e,{suppressErrors:!0}))throw Error("Invalid Mermaid diagram");let i="u">typeof crypto&&"randomUUID"in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,o=await r.render(i,e);t||u({key:g,status:"ready",svg:o.svg})})().catch(()=>{t||u({key:g,status:"error"})}),()=>{t=!0}},[e,g,l,m]);let y=(0,i.useMemo)(()=>(0,r.jsx)("button",{type:"button",onClick:()=>d(e=>!e),disabled:t,title:t?s("i18n.previewAfterStreaming"):m?s("i18n.showMermaidSource"):s("i18n.previewMermaid"),className:["markdown-code-action",m?"is-active":""].filter(Boolean).join(" "),children:m?s("i18n.source"):s("i18n.preview")}),[t,m,s]);if(!m)return(0,r.jsx)(tL,{code:e,lang:"mermaid",headerAction:y,isStreaming:t});let v=c?.key===g&&"error"===c.status?(0,r.jsx)("div",{className:"mermaid-block mermaid-block-error",children:s("i18n.invalidMermaid")}):c?.key!==g||"ready"!==c.status?(0,r.jsx)("div",{className:"mermaid-block mermaid-block-loading","aria-label":s("i18n.renderingMermaid")}):(0,r.jsxs)(r.Fragment,{children:[!h&&(0,r.jsx)("button",{ref:f,type:"button",className:"mermaid-block mermaid-preview-button",title:s("i18n.openMermaidViewer"),"aria-label":s("i18n.openMermaidViewer"),onClick:()=>p(!0),dangerouslySetInnerHTML:{__html:c.svg}}),h&&(0,r.jsx)(tE,{svg:c.svg,onClose:()=>p(!1)})]});return(0,r.jsxs)("div",{className:"markdown-code-block",children:[(0,r.jsxs)("div",{className:"markdown-code-header",children:[(0,r.jsx)("span",{className:"markdown-code-lang",children:"mermaid"}),(0,r.jsxs)("div",{className:"markdown-code-actions",children:[c?.key===g&&"ready"===c.status&&(0,r.jsx)("button",{type:"button",className:"markdown-code-action",title:`${s("i18n.downloadFile")} (SVG)`,"aria-label":`${s("i18n.downloadFile")} (SVG)`,onClick:()=>{let e,t,n,r=f.current?.querySelector("svg");r&&(e=new XMLSerializer().serializeToString(r),t=URL.createObjectURL(new Blob([e],{type:"image/svg+xml;charset=utf-8"})),(n=document.createElement("a")).href=t,n.download="mermaid-diagram.svg",n.click(),setTimeout(()=>URL.revokeObjectURL(t),0))},children:"SVG"}),y]})]}),v]})}function tE({svg:e,onClose:t}){let{t:n}=(0,x.s)(),o=(0,i.useRef)(null),[l,s]=(0,i.useState)(1);return(0,i.useEffect)(()=>{let e=o.current;if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),()=>{document.body.style.overflow=t,e.open&&e.close()}},[]),(0,r.jsx)("dialog",{ref:o,className:"mermaid-zoom-dialog","aria-label":n("i18n.mermaidViewer"),onCancel:e=>{e.preventDefault(),e.stopPropagation(),t()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t())},children:(0,r.jsxs)("div",{className:"mermaid-zoom-layout",children:[(0,r.jsxs)("div",{className:"mermaid-zoom-toolbar",children:[(0,r.jsx)("span",{className:"mermaid-zoom-title",children:n("i18n.mermaidDiagram")}),(0,r.jsxs)("div",{className:"mermaid-zoom-actions",children:[(0,r.jsxs)("div",{className:"mermaid-zoom-stepper",children:[(0,r.jsx)("button",{type:"button",onClick:()=>s(e=>Math.max(.5,e-.25)),disabled:l<=.5,title:n("i18n.zoomOut"),"aria-label":n("i18n.zoomOut"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M5 12h14"})})}),(0,r.jsxs)("span",{className:"mermaid-zoom-value",children:[Math.round(100*l),"%"]}),(0,r.jsx)("button",{type:"button",onClick:()=>s(e=>Math.min(3,e+.25)),disabled:l>=3,title:n("i18n.zoomIn"),"aria-label":n("i18n.zoomIn"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M12 5v14M5 12h14"})})})]}),(0,r.jsx)("button",{type:"button",className:"mermaid-zoom-icon-button",onClick:()=>s(1),title:n("i18n.fitToWidth"),"aria-label":n("i18n.fitToWidth"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M8 3H3v5M16 3h5v5M8 21H3v-5M16 21h5v-5"})})}),(0,r.jsx)("button",{type:"button",className:"mermaid-zoom-icon-button",onClick:t,title:n("i18n.close"),"aria-label":n("i18n.close"),children:(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})]})]}),(0,r.jsx)("div",{className:"mermaid-zoom-viewport",onClick:e=>{e.target===e.currentTarget&&t()},children:(0,r.jsx)("div",{className:"mermaid-zoom-canvas",style:{width:`${100*l}%`},dangerouslySetInnerHTML:{__html:e}})})]})})}let tL=(0,i.memo)(function({code:e,lang:t,headerAction:n,isStreaming:o}){let{isDark:l}=tC(),{t:s}=(0,x.s)(),[a,d]=(0,i.useState)(!1);return(0,r.jsxs)("div",{className:"markdown-code-block",children:[(0,r.jsxs)("div",{className:"markdown-code-header",children:[(0,r.jsx)("span",{className:"markdown-code-lang",children:t||"text"}),(0,r.jsxs)("div",{className:"markdown-code-actions",children:[n,(0,r.jsxs)("button",{type:"button",onClick:()=>{tI(e).then(()=>{d(!0),setTimeout(()=>d(!1),1500)})},className:"markdown-code-action",title:s(a?"i18n.copied":"i18n.copy"),"aria-label":s(a?"i18n.copied":"i18n.copy"),children:[a?(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,r.jsx)("span",{children:s(a?"i18n.copied":"i18n.copy")})]})]})]}),o?(0,r.jsx)("pre",{style:{margin:0,padding:"6px 10px",fontSize:"calc(13px + var(--chat-font-size-offset, 0px))",lineHeight:1.54,overflowX:"auto",scrollbarWidth:"thin",border:"none",borderRadius:0,background:"transparent",backgroundColor:"transparent"},children:(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:e})}):(0,r.jsx)(tM.A,{language:t||"text",style:l?ta.xJ:ta.vs,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal",opacity:.45,paddingRight:"0.8em",userSelect:"none"},customStyle:{margin:0,padding:"6px 10px",fontSize:"calc(13px + var(--chat-font-size-offset, 0px))",lineHeight:1.54,borderRadius:0,border:"none",boxShadow:"none",background:"transparent",backgroundColor:"transparent",overflowX:"auto",scrollbarWidth:"thin"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})});function tR({children:e,className:t,isStreaming:n,cwd:o,onOpenFile:l}){let s=(0,i.useMemo)(()=>te(e),[e]),a=(0,i.useMemo)(()=>({code({className:e,children:t,...i}){let o=e?.replace("language-","").toLowerCase()??"",l=String(t);return e?.includes("language-")||l.includes("\n")?"mermaid"===o?(0,r.jsx)(tT,{code:l.replace(/\n$/,""),isStreaming:n,defaultPreview:!0}):(0,r.jsx)(tL,{code:l.replace(/\n$/,""),lang:o,isStreaming:n}):(0,r.jsx)("code",{className:"markdown-inline-code",...i,children:t})},pre:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),a({href:e,children:t,...n}){delete n.node;let i=l?eU(e,o):null;return i&&l?(0,r.jsx)("a",{href:e,...n,onClick:e=>{if(!eF(e))return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),l(i))},children:t}):(0,r.jsx)("a",{href:e,...n,target:"_blank",rel:"noopener noreferrer",children:t})},img({src:e,alt:t,...n}){delete n.node;let i="string"==typeof e?eU(e,o):null,l=i?`/api/files/${T(i)}?type=read`:e;return(0,r.jsx)("img",{src:l,alt:t??"",loading:"lazy",...n})},table:({children:e})=>(0,r.jsx)("div",{className:"markdown-table-wrap",children:(0,r.jsx)("table",{children:e})})}),[o,n,l]);return(0,r.jsx)("div",{className:["markdown-body",t].filter(Boolean).join(" "),children:(0,r.jsx)(eQ.oz,{remarkPlugins:ti,rehypePlugins:tl,urlTransform:l?e7:void 0,components:a,children:s})})}function tN({active:e,size:t=14,className:n,style:i}){return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:n,style:{flexShrink:0,color:e?"var(--accent)":"currentColor",display:"block",...i},children:[(0,r.jsx)("path",{d:"M9.5 4a3.5 3.5 0 0 0-3.5 3.5c0 .34.05.67.14.98A4 4 0 0 0 4 12c0 1.9 1.3 3.5 3.1 3.9A3.5 3.5 0 0 0 10.5 19h1"}),(0,r.jsx)("path",{d:"M14.5 4a3.5 3.5 0 0 1 3.5 3.5c0 .34-.05.67-.14.98A4 4 0 0 1 20 12c0 1.9-1.3 3.5-3.1 3.9A3.5 3.5 0 0 1 13.5 19h-1"}),(0,r.jsx)("path",{d:"M12 4v16"})]})}function t$({toolName:e,isError:t,size:n=12}){if(t)return(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"#ef4444",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",style:{display:"block"},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]});let i=e.toLowerCase();return i.includes("bash")||i.includes("sh")||i.includes("terminal")||i.includes("powershell")||i.includes("command")?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-text-muted",style:{display:"block"},"aria-hidden":"true",children:[(0,r.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,r.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}):"read"===i||i.includes("read_file")||i.includes("view")?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-text-muted",style:{display:"block"},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,r.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,r.jsx)("line",{x1:"9",y1:"13",x2:"15",y2:"13"}),(0,r.jsx)("line",{x1:"9",y1:"17",x2:"13",y2:"17"})]}):i.includes("write")||i.includes("edit")||i.includes("patch")||i.includes("apply")?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-text-muted",style:{display:"block"},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,r.jsx)("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}):i.includes("todo")||i.includes("task")?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-text-muted",style:{display:"block"},"aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"5",width:"6",height:"6",rx:"1"}),(0,r.jsx)("path",{d:"m3 17 2 2 4-4"}),(0,r.jsx)("path",{d:"M13 6h8"}),(0,r.jsx)("path",{d:"M13 12h8"}),(0,r.jsx)("path",{d:"M13 18h8"})]}):i.includes("agent")||i.includes("subagent")?(0,r.jsx)(q,{size:n,strokeWidth:2.2,className:"shrink-0 text-text-muted",style:{display:"block"}}):i.includes("search")||i.includes("fetch")||i.includes("web")||i.includes("browser")?(0,r.jsxs)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-text-muted",style:{display:"block"},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}):(0,r.jsx)("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-text-muted",style:{display:"block"},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})})}let tW=/<(read-files|modified-files)>\s*([\s\S]*?)\s*<\/\1>/g,tz=/(?:\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 tP(e){let t,n=[],r=null,i=0,o=0,l=0,s=0,a=[],d=[],c=()=>({lineNo:null,text:"",type:"empty"}),u=()=>{if(!r){a=[],d=[];return}let e=Math.max(a.length,d.length);for(let t=0;t<e;t++){let e=a[t]?{lineNo:a[t].lineNo,text:a[t].text,type:"removed"}:c(),n=d[t]?{lineNo:d[t].lineNo,text:d[t].text,type:"added"}:c();r.rows.push({type:"line",left:e,right:n})}a=[],d=[]};for(let c of e.split(/\r?\n/)){if(!(l>0||s>0)){if(c.startsWith("--- ")){u(),t=tA(c.slice(4));continue}if(c.startsWith("+++ ")){u(),r={oldPath:t,newPath:tA(c.slice(4)),rows:[]},n.push(r);continue}}let e=c.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(e){r||(r={rows:[]},n.push(r)),u(),i=Number(e[1]),o=Number(e[3]),l=void 0===e[2]?1:Number(e[2]),s=void 0===e[4]?1:Number(e[4]),r.rows.push({type:"hunk",text:c});continue}if(!r)continue;if(c.startsWith("\\ ")){u(),r.rows.push({type:"hunk",text:c});continue}let h=c[0],p=c.slice(1);" "===h?(u(),r.rows.push({type:"line",left:{lineNo:i++,text:p,type:"context"},right:{lineNo:o++,text:p,type:"context"}}),l>0&&l--,s>0&&s--):"-"===h?(a.push({lineNo:i++,text:p}),l>0&&l--):"+"===h?(d.push({lineNo:o++,text:p}),s>0&&s--):""!==c&&(u(),r.rows.push({type:"hunk",text:c}))}u();let h=n.filter(e=>e.rows.some(e=>"line"===e.type));return h.length>0?h:null}function tA(e){return e.split(" ")[0].trim()}let tD="pi-thinking-expanded",tF="pi-thinking-expanded-changed";function tB(){return"true"===window.localStorage.getItem(tD)}function tH({files:e,onOpenFile:t}){let{t:n}=(0,x.s)();return 0===e.length?null:(0,r.jsx)("div",{"aria-label":n("chat.filesWritten"),style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,marginTop:6},children:e.map(({filePath:e})=>{let i=E(e);return(0,r.jsxs)("button",{type:"button",title:e,"aria-label":n("chat.openWrittenFile",{name:i}),onClick:()=>t?.(e),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"2.5px 7px",minHeight:22,fontSize:"calc(11.5px + var(--chat-font-size-offset, 0px))",fontFamily:"var(--font-mono)",lineHeight:1,color:"var(--text-muted)",background:"color-mix(in srgb, var(--bg-subtle) 65%, var(--bg))",border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",borderRadius:5,cursor:"pointer",transition:"background 0.12s ease, color 0.12s ease"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="color-mix(in srgb, var(--bg-subtle) 65%, var(--bg))",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,transform:"translateY(0.5px)"},children:I(i,12)}),(0,r.jsx)("span",{style:{lineHeight:1},children:i})]},e)})})}function tO(e){return{requestStartAt:e,firstTokenAt:null}}function tU(e,t){return null!==e.firstTokenAt?e:{...e,firstTokenAt:t}}function t_(e){return"number"==typeof e.timestamp&&Number.isFinite(e.timestamp)?`${e.timestamp}:${e.model??""}`:null}function tq(e,t){if(0===t.size)return e;let n=!1,r=e.map(e=>{if("assistant"!==e.role)return e;let r=t_(e);if(!r)return e;let i=t.get(r);return i&&e.decode!==i?(n=!0,{...e,decode:i}):e});return n?r:e}let tK=new Map;function tV({children:e,className:t,...n}){let{t:o}=(0,x.s)(),[l,s]=(0,i.useState)(!1);if(e.length<=1e5)return(0,r.jsx)(tR,{className:t,...n,children:e});if(!l){var a;return(0,r.jsxs)("button",{onClick:()=>s(!0),style:{display:"block",width:"100%",margin:"4px 0",padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:["⚠ ",o("i18n.largeMessageReveal",{size:(a=e.length)>=1e6?`${(a/1e6).toFixed(1)} MB`:a>=1e3?`${Math.round(a/1e3)} KB`:`${a} B`})]})}return(0,r.jsx)("div",{className:t,style:{maxHeight:420,overflow:"auto",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.5},children:(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)",color:"var(--text-muted)"},children:e})})}function tJ(e,t){if("number"!=typeof e||"number"!=typeof t)return;let n=Math.round((t-e)/1e3);return n>0?n:void 0}function tY(e){if(!e)return null;let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate(),i=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(r)return i;let o=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==n.getFullYear()?"numeric":void 0});return`${o} ${i}`}let tZ=(0,i.memo)(function({message:e,modelName:t,isStreaming:n,toolResults:i,cwd:o,onOpenFile:l,onOpenSession:s,entryId:a,searchBlock:d,onFork:c,forking:u,onNavigate:h,prevAssistantEntryId:p,onEditContent:f,isTurnEnd:g,sessionId:x,writtenFiles:m,isProcess:y}){return"user"===e.role?(0,r.jsx)(tX,{message:e,cwd:o,onOpenFile:l,entryId:a,onFork:c,forking:u,onNavigate:h,prevAssistantEntryId:p,onEditContent:f}):"assistant"===e.role?(0,r.jsx)(t0,{message:e,modelName:t,isStreaming:n,toolResults:i,cwd:o,onOpenFile:l,onOpenSession:s,isTurnEnd:g,sessionId:x,entryId:a,searchBlock:d,writtenFiles:m,isProcess:y}):"toolResult"===e.role?null:"custom"===e.role?"compaction"===e.customType?(0,r.jsx)(nr,{message:e}):eN(e)?(0,r.jsx)(nl,{message:e,cwd:o,onOpenFile:l}):(0,r.jsx)(ns,{message:e,cwd:o,onOpenFile:l}):"bashExecution"===e.role?(0,r.jsx)(nu,{message:e,sessionId:x}):null},(e,t)=>e.message===t.message&&e.isStreaming===t.isStreaming&&function(e,t,n){if(t===n||"assistant"!==e.role)return!0;for(let r of e.content??[])if("toolCall"===r.type&&t?.get(r.toolCallId)!==n?.get(r.toolCallId))return!1;return!0}(e.message,e.toolResults,t.toolResults)&&e.cwd===t.cwd&&e.onOpenFile===t.onOpenFile&&e.onOpenSession===t.onOpenSession&&e.entryId===t.entryId&&e.searchBlock===t.searchBlock&&e.onFork===t.onFork&&e.forking===t.forking&&e.onNavigate===t.onNavigate&&e.prevAssistantEntryId===t.prevAssistantEntryId&&e.onEditContent===t.onEditContent&&e.isTurnEnd===t.isTurnEnd&&e.modelName===t.modelName&&e.writtenFiles===t.writtenFiles&&e.sessionId===t.sessionId&&e.isProcess===t.isProcess);function tG({text:e,cwd:t,onOpenFile:n}){let i=function(e){let t=[],n=0;for(let r of e.matchAll(ea)){let i=function(e){let t=(e[1]??e[2]??"").replace(/[),.;]+$/,"");if(!(!ed.test(t)||t.split(/[\\/]/).includes("..")))return t}(r),o=r.index??0;i&&(o>n&&t.push({type:"text",value:e.slice(n,o)}),t.push({type:"mention",path:i}),n=o+r[0].length)}return n<e.length&&t.push({type:"text",value:e.slice(n)}),t.length?t:[{type:"text",value:e}]}(e),o=i.filter(e=>"mention"===e.type),l=i.filter(e=>"text"===e.type).map(e=>e.value).join("").trim();return o.length?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!l},children:o.map(e=>(0,r.jsx)(eg,{path:e.path,cwd:t},e.path))}),l?(0,r.jsx)(tV,{className:"markdown-user-message",cwd:t,onOpenFile:n,children:l}):null]}):(0,r.jsx)(tV,{className:"markdown-user-message",cwd:t,onOpenFile:n,children:e})}function tX({message:e,cwd:t,onOpenFile:n,entryId:o,onFork:l,forking:s,onNavigate:a,prevAssistantEntryId:d,onEditContent:u}){let{t:h}=(0,x.s)(),[p,f]=(0,i.useState)(!1),[g,m]=(0,i.useState)(!1),[y,v]=(0,i.useState)(!1),b="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),w="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),k=c(b),j=k?.search(/\s/)??-1,S=k?-1===j?k:k.slice(0,j):"",C=k&&-1!==j?k.slice(j+1):"",I=tY(e.timestamp),M=!!o&&!!l,T=k??b,E=k?function(e,t){if("string"==typeof e.content)return{...e,content:t};let n=[],r=!1;for(let i of e.content){if("text"!==i.type){n.push(i);continue}r||(n.push({...i,text:t}),r=!0)}return r||n.unshift({type:"text",text:t}),{...e,content:n}}(e,k):e,L=w.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!b},children:w.map((e,t)=>{let n=e.source?"base64"===e.source.type?`data:${e.source.media_type};base64,${e.source.data}`:e.source.url??"":e.data?`data:${e.mimeType};base64,${e.data}`:"";return(0,r.jsx)(er,{src:n,children:(0,r.jsx)("img",{src:n,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:8,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})},t)})}),R=!!d&&!!a;return(0,r.jsxs)("div",{style:{marginBottom:10,display:"flex",flexDirection:"column",alignItems:"flex-end"},onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:6,maxWidth:"min(85%, 680px)"},children:(0,r.jsx)("div",{style:{flex:1,minWidth:0,background:"var(--user-bg)",border:"1px solid var(--user-border, var(--border))",borderRadius:6,padding:"6px 11px",fontSize:"calc(14px + var(--chat-font-size-offset, 0px))",lineHeight:1.58,color:"var(--text)",wordBreak:"break-word",maxHeight:480,overflowY:"auto"},children:k?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,minWidth:0},children:[L,(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,flexWrap:"wrap"},children:[(0,r.jsxs)("button",{onClick:()=>v(e=>!e),title:h(y?"i18n.collapse":"i18n.expand"),"aria-expanded":y,style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,padding:0,background:"none",border:"none",cursor:"pointer",color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:"calc(13px + var(--chat-font-size-offset, 0px))",textAlign:"left"},children:[(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S}),(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.75,transform:y?"rotate(180deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),C&&(0,r.jsx)("span",{style:{color:"var(--text)",fontSize:"calc(14px + var(--chat-font-size-offset, 0px))",lineHeight:1.58,whiteSpace:"pre-wrap",wordBreak:"break-word",minWidth:0,flex:1},children:C})]}),y&&(0,r.jsx)(tR,{className:"markdown-user-message",cwd:t,onOpenFile:n,children:b})]}):(0,r.jsxs)(r.Fragment,{children:[L,b&&(0,r.jsx)(tG,{text:b,cwd:t,onOpenFile:n})]})})}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:2},children:[(0,r.jsx)("div",{className:"message-action-group",style:{opacity:+!!p,pointerEvents:p?"auto":"none"},children:(0,r.jsx)("button",{type:"button",className:"message-action-button","data-copied":g?"true":void 0,onClick:()=>{tI(T).then(()=>{m(!0),setTimeout(()=>m(!1),1500)})},title:h(g?"i18n.copied":"i18n.copyMessage"),"aria-label":h(g?"i18n.copied":"i18n.copy"),children:g?(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}),(M||R)&&(0,r.jsxs)("div",{className:"message-action-group",style:{opacity:p||s?1:0,pointerEvents:p||s?"auto":"none"},children:[R&&(0,r.jsx)("button",{type:"button",className:"message-action-button",onClick:()=>{a(d),u?.(E)},title:h("i18n.editFromHereTitle"),"aria-label":h("i18n.editFromHere"),children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("polyline",{points:"15 10 20 15 15 20"}),(0,r.jsx)("path",{d:"M4 4v7a4 4 0 0 0 4 4h12"})]})}),M&&(0,r.jsx)("button",{type:"button",className:"message-action-button",onClick:()=>{l(o)},disabled:s,title:h(s?"i18n.creatingSession":"i18n.newSessionTitle"),"aria-label":h(s?"i18n.creating":"i18n.newSession"),children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})})]}),I&&(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",userSelect:"none"},children:I})]})]})}function tQ({decode:e}){let t,{t:n}=(0,x.s)(),i=[];if(e.ttftMs>=100){let t=function(e){let t=e/1e3;if(t<60)return{seconds:Math.round(10*t)/10};let n=Math.round(t);return{minutes:Math.floor(n/60),seconds:n%60}}(e.ttftMs),r=n("minutes"in t?"chat.decodeMinutes":"chat.decodeSeconds",t);i.push(n("chat.ttft",{duration:r}))}return(void 0!==e.tokensPerSecond&&i.push(n("chat.tokensPerSecond",{throughput:(t=Math.max(0,e.tokensPerSecond))>=10?String(Math.round(t)):String(Math.round(10*t)/10)})),0===i.length)?null:(0,r.jsx)("div",{"data-decode-stats":!0,style:{marginTop:4,color:"var(--text-muted)",fontSize:11,fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums",userSelect:"none"},children:i.join(" \xb7 ")})}function t0({message:e,modelName:t,isStreaming:n,toolResults:o,cwd:l,onOpenFile:s,onOpenSession:a,isTurnEnd:d,sessionId:c,entryId:u,searchBlock:h,writtenFiles:p,isProcess:f}){let{t:g}=(0,x.s)(),[m,y]=(0,i.useState)(!1),v=(0,i.useMemo)(()=>(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!eW(e,{isStreaming:n})),[e.content,n]),b=(0,i.useMemo)(()=>v.map(({block:e})=>e),[v]),w=e.completedAt??e.timestamp,k=(0,i.useMemo)(()=>{let t=new Map;if(!o||void 0===w)return t;for(let n of e.content){if("toolCall"!==n.type)continue;let e=o.get(n.toolCallId),r=tJ(w,e?.timestamp);void 0!==r&&t.set(n.toolCallId,r)}return t},[e.content,o,w]),j=eP(e,{isStreaming:n}),S=b.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),C=d&&!n?tY(e.timestamp):null,I=d&&!n&&!!(S||C);return 0!==b.length||n||j?(0,r.jsxs)("div",{"data-message-role":"assistant","data-entry-id":u,style:{marginBottom:d?16:8},children:[d&&!n&&(t||e.model)&&(0,r.jsx)("div",{"data-answer-model":!0,style:{marginBottom:4,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-ui)"},children:t||e.model}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:v.map(({block:t,originalIndex:i},d)=>{let p="thinking"===t.type?t:null,f=p?p.startedAt??e.timestamp:void 0,g=p?tJ(f,p.endedAt??e.completedAt):void 0,x=!!(n&&p&&d===v.length-1&&void 0===g&&"number"==typeof f);return(0,r.jsx)(t4,{block:t,searchTarget:t===h,toolResults:o,isStreaming:n,streamingDuration:g,startTime:x?f:void 0,toolCallDurations:k,cwd:l,onOpenFile:s,onOpenSession:a,sessionId:c,entryId:u,blockIndex:i},`${u??"stream"}-${i}`)})}),!n&&d&&e.decode&&(0,r.jsx)(tQ,{decode:e.decode}),j&&(f?(0,r.jsx)("div",{style:{marginTop:4*(b.length>0)},children:(0,r.jsx)(t1,{error:j})}):(0,r.jsxs)("div",{role:"alert",style:{marginTop:8*(b.length>0),padding:"7px 10px",border:"1px solid rgba(239,68,68,0.3)",borderRadius:6,background:"rgba(239,68,68,0.07)",color:"#ef4444",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:["Error: ",j]})),p&&p.length>0&&(0,r.jsx)(tH,{files:p,onOpenFile:s}),I&&(0,r.jsxs)("div",{"data-answer-footer":!0,style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:2},children:[S&&(0,r.jsx)("button",{type:"button",className:"answer-copy-button message-action-button","data-copied":m?"true":void 0,onClick:()=>{tI(S).then(()=>{y(!0),setTimeout(()=>y(!1),1500)})},title:g(m?"i18n.copied":"i18n.copyMessage"),"aria-label":g(m?"i18n.copied":"i18n.copy"),children:m?(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),C&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",userSelect:"none"},children:C})]})]}):null}function t1({error:e}){let{t}=(0,x.s)(),[n,o]=(0,i.useState)(!1),l=(0,i.useId)(),s=(0,i.useMemo)(()=>{let t=e.replace(/^(Error:\s*)+/i,"").trim();return t.split("\n")[0]||t},[e]);return(0,r.jsxs)("div",{"data-step-card":"",style:{borderRadius:6,overflow:"hidden",fontSize:"calc(11.5px + var(--chat-font-size-offset, 0px))",border:"1px solid rgba(248,113,113,0.35)",background:"rgba(248,113,113,0.05)"},children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"stretch",minWidth:0},children:(0,r.jsxs)("button",{type:"button","aria-expanded":n,"data-step-trigger":"","aria-controls":l,title:t(n?"chat.collapseProcess":"chat.expandProcess"),onClick:()=>o(e=>!e),style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,padding:"3px 8px",minHeight:24,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:"inherit",textAlign:"left"},children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:14,height:14,flexShrink:0,opacity:.85,transform:"translateY(0.5px)"},children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#f87171",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,r.jsx)("span",{style:{color:"#f87171",fontFamily:"var(--font-mono)",fontWeight:500,fontSize:11,lineHeight:1.35,flexShrink:0},children:t("chat.modelError")}),(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0,opacity:.85,lineHeight:1.35},children:s}),(0,r.jsx)("svg",{"data-step-chevron":"",width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.4,display:"block",transform:n?"rotate(180deg)":"none",transition:"transform 0.15s, opacity 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]})}),n&&(0,r.jsxs)("div",{id:l,style:{padding:"8px 10px",background:"var(--bg)",borderTop:"1px solid rgba(248,113,113,0.2)",fontFamily:"var(--font-mono)",fontSize:"calc(11px + var(--chat-font-size-offset, 0px))",lineHeight:1.55,color:"#f87171",whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:["Error: ",e]})]})}function t2({startTime:e}){let[t,n]=(0,i.useState)(()=>Math.max(0,Math.round((Date.now()-e)/1e3)));return(0,i.useEffect)(()=>{let t=setInterval(()=>{n(Math.max(0,Math.round((Date.now()-e)/1e3)))},500);return()=>clearInterval(t)},[e]),(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[t,"s"]})}function t4({block:e,searchTarget:t,toolResults:n,isStreaming:i,streamingDuration:o,startTime:l,toolCallDurations:s,cwd:a,onOpenFile:d,onOpenSession:c,sessionId:u,entryId:h,blockIndex:p}){if("text"===e.type){let n=e.text;return i||n&&""!==n.trim()?(0,r.jsx)("div",{"data-message-text":!0,"data-search-target":t||void 0,children:(0,r.jsx)(t8,{block:e,isStreaming:i,cwd:a,onOpenFile:d})}):null}if("image"===e.type){let n=nc(e);return n?(0,r.jsx)("div",{"data-search-target":t||void 0,style:{margin:"8px 0"},children:(0,r.jsx)(er,{src:n,children:(0,r.jsx)("img",{src:n,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})})}):null}if("thinking"===e.type)return(0,r.jsx)(t5,{block:e,duration:o,startTime:l,isStreaming:i,sessionId:u,entryId:h,blockIndex:p});if("toolCall"===e.type){let t=n?.get(e.toolCallId),i=s?.get(e.toolCallId);return(0,r.jsx)(t6,{block:e,result:t,duration:i,onOpenSession:c})}return null}function t8({block:e,isStreaming:t,cwd:n,onOpenFile:i}){return(0,r.jsx)(tV,{className:"markdown-assistant-message",isStreaming:t,cwd:n,onOpenFile:i,children:e.text})}function t5({block:e,duration:t,startTime:n,isStreaming:o,sessionId:l,entryId:s,blockIndex:a}){var d;let{t:c}=(0,x.s)(),[u,h]=(0,i.useState)(tB),[p,f]=(0,i.useState)(null),[g,m]=(0,i.useState)(!1),[y,v]=(0,i.useState)(null),b=(0,i.useRef)(c);b.current=c;let w=(d=e.thinking,d.trimStart().match(/^[^\r\n]{0,240}/u)?.[0].trimEnd()??"");return(0,i.useEffect)(()=>{let e=()=>h(tB());return window.addEventListener(tF,e),()=>window.removeEventListener(tF,e)},[]),(0,i.useEffect)(()=>{if(!u||!e.deferred||null!==p)return;if(!l||!s)return void v(b.current("i18n.thinkingUnavailable"));let t=!1;return m(!0),v(null),(function(e,t,n){let r=`${e}:${t}:${n}`,i=tK.get(r);if(i)return tK.delete(r),tK.set(r,i),i;let o=fetch(`/api/sessions/${encodeURIComponent(e)}/entries/${encodeURIComponent(t)}/thinking?blockIndex=${n}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if("string"!=typeof t.thinking)throw Error("Invalid thinking response");return t.thinking}).catch(e=>{throw tK.delete(r),e});if(tK.set(r,o),tK.size>100){let e=tK.keys().next().value;e&&tK.delete(e)}return o})(l,s,a).then(e=>{t||(f(e),m(!1))}).catch(e=>{t||(v(e instanceof Error?e.message:String(e)),m(!1))}),()=>{t=!0}},[u,e.deferred,p,l,s,a]),(0,r.jsxs)("div",{"data-step-card":"",style:{borderRadius:6,overflow:"hidden",border:"1px solid var(--border)",background:"var(--bg-subtle)",transition:"border-color 0.15s ease"},children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"stretch",minWidth:0},children:(0,r.jsxs)("button",{type:"button","aria-expanded":u,"data-step-trigger":"","aria-label":`${c("i18n.thinking")}${w?`: ${w}`:""}`,title:c("i18n.thinking"),onClick:()=>h(e=>!e),style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,padding:"3px 8px",minHeight:24,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:14,height:14,flexShrink:0,opacity:.85,transform:"translateY(0.5px)"},children:(0,r.jsx)(tN,{active:u,size:12})}),(0,r.jsx)("span",{style:{color:"var(--text)",fontFamily:"var(--font-ui)",fontWeight:500,fontSize:11.5,lineHeight:1.35,flexShrink:0},children:c("i18n.thinking")}),!u&&(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-ui)",fontSize:11.5,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0,opacity:.85,lineHeight:1.35},children:w?(0,r.jsx)(eQ.oz,{allowedElements:[],unwrapDisallowed:!0,skipHtml:!0,children:w}):"..."}),u&&(0,r.jsx)("div",{style:{flex:1}}),void 0!==t?(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums",lineHeight:1.35},children:[t,"s"]}):o&&n?(0,r.jsx)(t2,{startTime:n}):null,(0,r.jsx)("svg",{"data-step-chevron":"",width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.4,display:"block",transform:u?"rotate(180deg)":"none",transition:"transform 0.15s, opacity 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]})}),u&&(0,r.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",borderTop:"1px solid color-mix(in srgb, var(--border) 80%, transparent)",fontFamily:"var(--font-mono)",fontSize:"calc(11px + var(--chat-font-size-offset, 0px))",lineHeight:1.55,color:y?"#f87171":"var(--text-muted)",whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:g?c("i18n.loadingThinking"):y??(e.deferred?p:e.thinking)})]})}function t6({block:e,result:t,duration:n,onOpenSession:o}){var l,s;let{t:a}=(0,x.s)(),[d,c]=(0,i.useState)(!1),u=(s=e).rawInput??JSON.stringify(s.input,null,2),h=void 0!==e.rawInput,p=e_(e.toolName),f=eh(e.toolName,e.input,t?.details),g="edit"===f?a("image.edit"):"generate"===f?a("image.generate"):e.toolName,m=t&&!t.isError?function(e){var t;let n=e.details;if(!("object"==typeof(t=n)&&null!==t&&!Array.isArray(t)))return null;let r="string"==typeof n.patch?n.patch:null;if(r)return{text:r};let i="string"==typeof n.diff?n.diff:null;return i?{text:i}:null}(t):null,y=t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,v=nd(t?.content??[]),b=null!==y&&("(no output)"===y.trim()||""===y.trim()),w=t?.isError??!1,k=(l=t?.details)&&"object"==typeof l&&"pi-web-subagent"===l.kind&&"string"==typeof l.sessionId?t.details:null;return(0,r.jsxs)("div",{"data-step-card":"",style:{borderRadius:6,overflow:"hidden",fontSize:"calc(11.5px + var(--chat-font-size-offset, 0px))",border:w?"1px solid rgba(248,113,113,0.45)":"1px solid var(--border)",background:w?"rgba(248,113,113,0.05)":"var(--bg-subtle)",transition:"border-color 0.15s ease"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",minWidth:0},children:[(0,r.jsxs)("button",{type:"button","aria-expanded":d,"data-step-trigger":"",onClick:()=>c(e=>!e),style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,padding:"3px 8px",minHeight:24,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:"inherit",textAlign:"left"},children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:14,height:14,flexShrink:0,opacity:.85,transform:"translateY(0.5px)"},children:(0,r.jsx)(t$,{toolName:e.toolName,isError:w,size:12})}),(0,r.jsx)("span",{style:{color:w?"#f87171":"var(--text)",fontFamily:"var(--font-mono)",fontWeight:500,fontSize:11,lineHeight:1.35,flexShrink:0},children:g}),(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0,opacity:.85,lineHeight:1.35},children:h?a("chat.generatingToolInput"):function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let n=Object.keys(t);return 0===n.length?"":"command"in t?String(t.command).slice(0,120):"path"in t?String(t.path).slice(0,120):"file_path"in t?String(t.file_path).slice(0,120):"pattern"in t?String(t.pattern).slice(0,120):"query"in t?String(t.query).slice(0,120):String(t[n[0]]).slice(0,120)}(e)}),void 0!==n&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums",lineHeight:1.35},children:[n,"s"]}),(0,r.jsx)("svg",{"data-step-chevron":"",width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.4,display:"block",transform:d?"rotate(180deg)":"none",transition:"transform 0.15s, opacity 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),k&&o&&(0,r.jsx)("button",{type:"button",onClick:()=>o(k.sessionId),title:a("subagent.open"),"aria-label":a("subagent.open"),style:{width:30,display:"grid",placeItems:"center",border:"none",borderLeft:"1px solid var(--border)",background:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M15 3h6v6"}),(0,r.jsx)("path",{d:"M10 14 21 3"}),(0,r.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})})]}),d&&(h||!p)&&(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:"var(--text-muted)",fontSize:"calc(11.5px + var(--chat-font-size-offset, 0px))",lineHeight:1.5,overflow:"auto",background:"var(--bg)",borderTop:w?"1px solid rgba(239,68,68,0.25)":"1px solid color-mix(in srgb, var(--border) 80%, transparent)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:u}),d&&t&&(m?(0,r.jsx)(t3,{diff:m}):(0,r.jsx)(nn,{text:y??"",images:v,isEmpty:b,isError:w}))]})}function t3({diff:e}){return(0,r.jsx)("div",{style:{borderTop:"1px solid rgba(34,197,94,0.15)",background:"var(--bg)"},children:(0,r.jsx)(t7,{text:e.text})})}function t7({text:e}){let{t}=(0,x.s)(),n=(0,i.useMemo)(()=>tP(e),[e]);if(!n)return(0,r.jsx)(nt,{text:e});let o=n.length>1;return(0,r.jsx)("div",{style:{maxHeight:560,overflowY:"auto",overflowX:"hidden",background:"var(--bg)"},children:n.map((e,n)=>(0,r.jsxs)("div",{style:{minWidth:0,borderTop:0===n?"none":"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.55},children:[o&&(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",position:"sticky",top:0,zIndex:1,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)(t9,{title:e.oldPath||t("i18n.before"),side:"left"}),(0,r.jsx)(t9,{title:e.newPath||t("i18n.after"),side:"right"})]}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)"},children:e.rows.map((e,t)=>"hunk"===e.type?null:(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)(ne,{cell:e.left,side:"left"}),(0,r.jsx)(ne,{cell:e.right,side:"right"})]},t))})]},n))})}function t9({title:e,side:t}){return(0,r.jsx)("div",{title:e,style:{padding:"5px 10px",color:"var(--text-dim)",borderRight:"left"===t?"1px solid var(--border)":"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})}function ne({cell:e,side:t}){let n="added"===e.type?"rgba(34,197,94,0.12)":"removed"===e.type?"rgba(248,113,113,0.13)":"empty"===e.type?"var(--bg-subtle)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",o="added"===e.type?"#22c55e":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",minWidth:0,background:n,borderRight:"left"===t?"1px solid var(--border)":"none"},children:[(0,r.jsx)("span",{style:{width:42,padding:"0 6px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",flexShrink:0},children:e.lineNo??""}),(0,r.jsx)("span",{style:{width:18,padding:"0 5px",color:o,userSelect:"none",fontWeight:"context"===e.type||"empty"===e.type?400:700,flexShrink:0},children:i}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 10px 0 0",color:"empty"===e.type?"var(--text-dim)":"var(--text)",whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:e.text||"\xa0"})]})}function nt({text:e}){let t=e.split(/\r?\n/);return(0,r.jsx)("div",{style:{maxHeight:520,overflowY:"auto",overflowX:"hidden",fontFamily:"var(--font-mono)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.55,minWidth:0},children:t.map((e,t)=>{let n=e.startsWith("@@")?"hunk":e.startsWith("+")&&!e.startsWith("+++")?"added":e.startsWith("-")&&!e.startsWith("---")?"removed":"context";return(0,r.jsxs)("div",{style:{display:"flex",background:"added"===n?"rgba(34,197,94,0.12)":"removed"===n?"rgba(248,113,113,0.13)":"hunk"===n?"rgba(96,165,250,0.12)":"transparent",borderLeft:"added"===n?"3px solid #22c55e":"removed"===n?"3px solid #f87171":"hunk"===n?"3px solid var(--accent)":"3px solid transparent"},children:[(0,r.jsx)("span",{style:{width:48,padding:"0 8px",color:"var(--text-dim)",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",textAlign:"right",userSelect:"none",flexShrink:0},children:t+1}),(0,r.jsx)("span",{style:{padding:"0 10px",whiteSpace:"pre-wrap",overflowWrap:"anywhere",color:"added"===n?"#22c55e":"removed"===n?"#f87171":"hunk"===n?"var(--accent)":"var(--text)"},children:e||"\xa0"})]},t)})})}function nn({text:e,images:t,isEmpty:n,isError:i}){let{t:o}=(0,x.s)(),l=!n||0===t.length;return(0,r.jsxs)("div",{style:{borderTop:`1px solid ${i?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:i?"rgba(248,113,113,0.04)":"var(--bg-subtle)"},children:[t.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",padding:"10px",background:"var(--bg)"},children:t.map((e,t)=>{let n=nc(e);return n?(0,r.jsx)(er,{src:n,style:{maxWidth:"100%"},children:(0,r.jsx)("img",{src:n,alt:"",loading:"lazy",style:{display:"block",maxWidth:"min(100%, 720px)",maxHeight:520,borderRadius:6,objectFit:"contain",border:"1px solid var(--border)"}})},`${n}-${t}`):null})}),l&&(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:i?"#f87171":n?"var(--text-dim)":"var(--text-muted)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.5,overflow:"auto",maxHeight:400,background:"var(--bg)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontStyle:n?"italic":"normal",opacity:n?.6:1},children:n?o("i18n.noOutput"):e})]})}function nr({message:e}){let{t}=(0,x.s)(),n=na(e.content),o=(0,i.useMemo)(()=>{let e,t,r,i,o;return e=[],t=[],r=n.match(tz),i=r?.[1]??"",o=r?.index===void 0?n:n.slice(0,r.index),i.replace(tW,(n,r,i)=>{let o=i.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return"read-files"===r?e.push(...o):t.push(...o),""}),{body:o.trim(),readFiles:e,modifiedFiles:t}},[n]),l=tY(e.timestamp);return(0,r.jsx)("div",{style:{marginBottom:16},children:(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:"compaction"}),l&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:l})]}),(0,r.jsxs)("div",{style:{padding:"11px 13px 12px"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:"calc(15px + var(--chat-font-size-offset, 0px))",fontWeight:700,lineHeight:1.35},children:t("i18n.conversationCompacted")}),(0,r.jsx)("div",{style:{marginTop:3,marginBottom:10,color:"var(--text)",fontSize:"calc(14px + var(--chat-font-size-offset, 0px))",lineHeight:1.5},children:t("i18n.compactionDescription")}),o.body?(0,r.jsx)(tR,{className:"markdown-compaction-message",children:o.body}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:t("i18n.noSummary")}),(0,r.jsx)(ni,{readFiles:o.readFiles,modifiedFiles:o.modifiedFiles})]})]})})}function ni({readFiles:e,modifiedFiles:t}){let{t:n}=(0,x.s)();if(0===e.length+t.length)return null;let i=[];return e.length>0&&i.push(`${e.length} read`),t.length>0&&i.push(`${t.length} modified`),(0,r.jsxs)("details",{className:"compaction-file-details",children:[(0,r.jsx)("summary",{children:n("i18n.fileContext",{details:i.join(", ")})}),t.length>0&&(0,r.jsx)(no,{title:n("i18n.modifiedFiles"),files:t}),e.length>0&&(0,r.jsx)(no,{title:n("i18n.readFiles"),files:e})]})}function no({title:e,files:t}){return(0,r.jsxs)("div",{className:"compaction-file-section",children:[(0,r.jsx)("div",{className:"compaction-file-title",children:e}),(0,r.jsx)("ul",{className:"compaction-file-list",children:t.map(e=>(0,r.jsx)("li",{children:e},e))})]})}function nl({message:e,cwd:t,onOpenFile:n}){let{t:o}=(0,x.s)(),[l,s]=(0,i.useState)(!1),a=(e.details?.sessionIds??[]).length||1,d=1===a?o("subagent.notificationSingle"):o("subagent.notificationMany",{count:a}),c=na(e.content);return(0,r.jsxs)("div",{"data-step-card":"",style:{overflow:"hidden",borderRadius:4},children:[(0,r.jsxs)("button",{type:"button","aria-expanded":l,"data-step-trigger":"",title:d,onClick:()=>s(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",minHeight:24,padding:"3px 8px",border:"none",background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)("span",{style:{width:14,height:14,display:"grid",placeItems:"center",flexShrink:0},children:(0,r.jsx)(q,{size:12,strokeWidth:2})}),(0,r.jsx)("span",{style:{minWidth:0,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:500},children:d}),(0,r.jsx)("svg",{"data-step-chevron":"",width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.4,transform:l?"rotate(180deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),l&&c&&(0,r.jsx)("div",{style:{padding:"7px 10px 8px 28px",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)",color:"var(--text-muted)",fontSize:"calc(11px + var(--chat-font-size-offset, 0px))",lineHeight:1.48},children:(0,r.jsx)(tV,{className:"markdown-subagent-notification",cwd:t,onOpenFile:n,children:c})})]})}function ns({message:e,cwd:t,onOpenFile:n}){let o,{t:l}=(0,x.s)(),s=!1===e.display,[a,d]=(0,i.useState)(!s),[c,u]=(0,i.useState)(!1),[h,p]=(0,i.useState)(!1),f=na(e.content),g=nd(e.content),m=void 0!==e.details,y=m?function(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.details):"",v=e.customType||"extension",b=tY(e.timestamp);return(0,r.jsx)("div",{style:{marginBottom:16},children:(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:s?"var(--bg-subtle)":"var(--bg)",opacity:s&&!a?.82:1},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:v}),s&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:l("i18n.hiddenExtensionMessage")}),b&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:b})]}),a?(0,r.jsxs)("div",{style:{padding:"6px 9px"},children:[g.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!f},children:g.map((e,t)=>{let n=nc(e);return n?(0,r.jsx)(er,{src:n,children:(0,r.jsx)("img",{src:n,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})},t):null})}),f?(0,r.jsx)(tR,{className:"markdown-custom-message",cwd:t,onOpenFile:n,children:f}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:l("i18n.noMessage")})]}):(0,r.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:f?(o=f.replace(/\s+/g," ").trim())?o.length>140?`${o.slice(0,140)}...`:o:"Show extension message":l("i18n.showExtensionMessage")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 9px",borderTop:"1px solid var(--border)",background:"var(--bg-subtle)"},children:[f||y?(0,r.jsx)("button",{onClick:()=>{tI(f||y).then(()=>{p(!0),setTimeout(()=>p(!1),1500)})},style:{padding:"3px 7px",border:"none",background:"none",color:h?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11},children:l(h?"i18n.copied":"i18n.copy")}):null,(m||s)&&(0,r.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:l(s?a?"i18n.collapse":"i18n.expand":c?"i18n.hideDetails":"i18n.showDetails")})]}),m&&(s&&a||!s&&c)&&(0,r.jsx)("pre",{style:{margin:0,padding:"9px 10px",borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:"calc(12px + var(--chat-font-size-offset, 0px))",lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:360,overflow:"auto",fontFamily:"var(--font-mono)"},children:y})]})})}function na(e){return"string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n")}function nd(e){return"string"==typeof e?[]:e.filter(e=>"image"===e.type)}function nc(e){return 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}`:""}function nu({message:e,sessionId:t}){let[n,o]=(0,i.useState)(null),[l,s]=(0,i.useState)(!1),[a,d]=(0,i.useState)(null),c=!e.output&&void 0===e.exitCode&&!e.cancelled,u=e.cancelled||void 0!==e.exitCode&&0!==e.exitCode,h=t&&e.fullOutputPath?`/api/agent/${encodeURIComponent(t)}/bash-output?path=${encodeURIComponent(e.fullOutputPath)}`:null,p=e.truncated&&h&&null===n,f=n??e.output;async function g(){if(h){s(!0),d(null);try{let e=await fetch(h),t=await e.json();t.success?o(t.data?.output??""):d(t.error??"failed")}catch(e){d(String(e))}finally{s(!1)}}}let x=e.excludeFromContext?"bash (local)":"bash",m={type:"toolCall",toolCallId:`bash-${e.timestamp??""}`,toolName:x,input:{command:e.command}},y=c?void 0:{role:"toolResult",toolCallId:m.toolCallId,toolName:x,content:f?[{type:"text",text:f}]:[],isError:u,timestamp:e.timestamp};return(0,r.jsxs)("div",{style:{margin:"6px 0"},children:[(0,r.jsx)(t6,{block:m,result:y}),e.truncated&&h&&(0,r.jsxs)("div",{style:{padding:"4px 10px",fontSize:11,marginTop:-1},children:[p&&(0,r.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,r.jsx)("a",{href:`${h}&download=1`,style:{marginLeft:10*!!p,color:"var(--accent)",fontSize:11,textDecoration:"underline"},children:"download full output"}),a&&(0,r.jsxs)("span",{style:{marginLeft:6,color:"var(--text-dim)",fontSize:11},children:["(",a,")"]})]})]})}let nh=new Map;function np(e){return`pi-chat-draft:${encodeURIComponent(e)}`}function nf(){try{return window.sessionStorage}catch{return null}}function ng(e){return{value:e.value,images:e.images.map(e=>({...e}))}}function nx(e){return!e.value&&0===e.images.length}function nm(e){let t=nh.get(e)??function(e){try{let t=nf()?.getItem(np(e));if(!t)return null;let n=JSON.parse(t);if("string"!=typeof n.value||!Array.isArray(n.images)||!n.images.every(e=>"string"==typeof e?.data&&"string"==typeof e?.mimeType))return null;return ng(n)}catch{return null}}(e);return t&&!nh.has(e)&&nh.set(e,t),t?ng(t):null}function ny(e,t){if(nx(t))return nv(e),!0;let n=ng(t);nh.set(e,n);let r=nf();if(!r)return!1;try{return r.setItem(np(e),JSON.stringify(n)),!0}catch{return r.removeItem(np(e)),!1}}function nv(e){nh.delete(e);try{nf()?.removeItem(np(e))}catch{}}function nb(e,t){return e.trim()?t.trim()?`${e}
|
|
8
|
+
|
|
9
|
+
${t}`:e:t}function nw(e){return{data:e.data,mimeType:e.mimeType}}function nk(e,t,n,r){return{value:nb(e,n),images:[...t??[],...r].map(nw)}}function nj(e,t,n){if(e===t)return n?ng(n):nm(t);let r=nm(e),i=n&&!nx(n)?ng(n):r??(n?ng(n):null),o=nm(t);if(nv(e),!i)return o;let l=o?nk(o.value,o.images,i.value,i.images):i;return ny(t,l),ng(l)}function nS(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let n=/(?:^|\s)@([^\s"]*)$/.exec(e);return n?{start:e.length-(n[1].length+1),query:n[1],quoted:!1}:null}function nC(e){let t=0;for(let n=0;n<e.length;n++)"/"===e[n]&&t++;return t}function nI(e,t){if(!e)return!0;let n=0;for(let r=0;r<t.length&&n<e.length;r++)t[r]===e[n]&&n++;return n===e.length}function nM(e,t){let n=t?`${e}/`:e;return n.includes(" ")?`@"${n}" `:`@${n} `}let nT="(max-width: 640px)",nE=e=>(function(e,t){if(!window.matchMedia)return()=>{};let n=window.matchMedia(e);return n.addEventListener("change",t),()=>n.removeEventListener("change",t)})(nT,e),nL=()=>!!window.matchMedia&&window.matchMedia(nT).matches;function nR(){return!1}function nN(){return(0,i.useSyncExternalStore)(nE,nL,nR)}let n$="pi-chat-content-width",nW="pi-chat-content-font-size",nz={width:820,fontSize:14},nP=null,nA=new Set;function nD(e){let t=Number(e);return Number.isFinite(t)?Math.max(820,Math.min(2e3,Math.round(t))):820}function nF(e){let t=Number(e??14);return Number.isFinite(t)?Math.max(12,Math.min(24,Math.round(t))):14}function nB(e){try{return window.localStorage.getItem(e)}catch{return null}}function nH({width:e,fontSize:t}){"u">typeof document&&(document.documentElement.style.setProperty("--chat-content-max-width",`${e}px`),document.documentElement.style.setProperty("--chat-content-font-size",`${t}px`))}function nO(){return nP||nH(nP={width:nD(nB(n$)),fontSize:nF(nB(nW))}),nP}function nU(e){return nA.add(e),()=>{nA.delete(e)}}function n_(e,t){let n="width"===e?nD(t):nF(t);nH(nP={...nO(),[e]:n});try{window.localStorage.setItem("width"===e?n$:nW,String(n))}catch{}nA.forEach(e=>e())}let nq=e=>n_("width",e),nK=e=>n_("fontSize",e);function nV(){return{...(0,i.useSyncExternalStore)(nU,nO,()=>nz),setWidth:nq,setFontSize:nK}}function nJ(e,t){if(null==e||Number.isNaN(e))return"?";if(e<=0)return"0";if(e<1e3)return String(e);if(e>=1e6){let t=Math.round(e/1e6*100)/100;return`${t}M`}let n=e/1e3;if(n<10){let e=Math.round(10*n)/10;return`${e}k`}return`${Math.round(n).toLocaleString(t)}k`}let nY="pi-shift-enter-to-send";function nZ(){try{return"true"===window.localStorage.getItem(nY)}catch{return!1}}let nG=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function nX(e,t){return nG.compare(e.name||e.modelId,t.name||t.modelId)||nG.compare(e.provider,t.provider)||nG.compare(e.modelId,t.modelId)}function nQ({options:e,value:t,onChange:n,onClear:o,emptyLabel:l,selectedLabel:s,disabled:a=!1,busy:d=!1,isAutoSelection:c=!1,ariaLabel:u,variant:h="toolbar",placement:p="up"}){let f,g,x,m,y,v,b,w,k=nN(),j=(0,i.useRef)(null),S=(0,i.useRef)(null),[C,I]=(0,i.useState)(!1),[M,T]=(0,i.useState)(null),E=a||d,L=(0,i.useMemo)(()=>[...e].sort(nX),[e]),R=[];for(let e of L){let t=R.find(t=>t.provider===e.provider);t?t.options.push(e):R.push({provider:e.provider,options:[e]})}let N=s??(t?L.find(e=>e.modelId===t.modelId&&e.provider===t.provider)?.name??t.modelId:l??(L.length>0?"Select model":"No models"));(0,i.useEffect)(()=>{let e=e=>{j.current&&!j.current.contains(e.target)&&S.current&&!S.current.contains(e.target)&&I(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{E&&I(!1)},[E]);let $="field"===h?{display:"flex",alignItems:"center",gap:7,width:"100%",minWidth:0,height:34,padding:"0 9px",overflow:"hidden",border:"1px solid var(--border)",borderRadius:4,background:E?"var(--bg-panel)":"var(--bg)",color:E?"var(--text-dim)":"var(--text)",cursor:E?"default":"pointer",fontSize:12,textAlign:"left"}:{display:"flex",alignItems:"center",justifyContent:"flex-start",textAlign:"left",gap:6,width:k?"100%":void 0,maxWidth:k?"100%":220,height:k?32:28,padding:"0 4px",overflow:"visible",border:"none",borderRadius:4,background:C?"var(--bg-hover)":"none",color:"var(--text-muted)",cursor:E?"not-allowed":"pointer",fontSize:12,lineHeight:1.25,opacity:E?.5:1,transition:"background 0.12s, color 0.12s"};return(0,r.jsxs)("div",{ref:j,className:`model-selector is-${h}${E?" is-disabled":""}`,style:{position:"relative",width:"field"===h||k?"100%":void 0,minWidth:0,flex:"toolbar"===h&&k?"1 1 auto":void 0,display:"toolbar"===h?"flex":void 0,alignItems:"toolbar"===h?"center":void 0},onKeyDown:e=>{"Escape"===e.key&&C&&(e.preventDefault(),e.stopPropagation(),I(!1))},children:[(0,r.jsxs)("button",{type:"button","aria-label":u,"aria-haspopup":"listbox","aria-expanded":C,"aria-busy":d||void 0,disabled:E,title:d?"Switching model":E?N:L.length>0||o?"Change model":"No available models",style:$,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();T({top:t.top,right:t.right,bottom:t.bottom,left:t.left,width:t.width}),I(e=>!e)},onMouseEnter:e=>{E||k&&"toolbar"===h||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{if(E){e.currentTarget.style.background="field"===h?"var(--bg-panel)":"none",e.currentTarget.style.color="field"===h?"var(--text-dim)":"var(--text-muted)";return}k&&"toolbar"===h||(e.currentTarget.style.background=C?"var(--bg-hover)":"field"===h?"var(--bg)":"none",e.currentTarget.style.color="field"===h?"var(--text)":"var(--text-muted)")},children:[d?(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",style:{animation:"spin 0.8s linear infinite",display:"block",flexShrink:0,transform:"translateY(-1px)"},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-2.64-6.36"})}):"field"===h?(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block",flexShrink:0},children:[(0,r.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,r.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,r.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,r.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,r.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,r.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,r.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,r.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,r.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}):null,(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.25},children:N}),"field"===h&&(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0,color:"var(--text-dim)"},children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),C&&M&&(f=window.visualViewport?.height??window.innerHeight,g=window.visualViewport?.width??window.innerWidth,x=M.top-8,m=f-M.bottom-8,v=Math.max(120,Math.min((y="up"===p||x>m)?x:m,.6*f)),b=y?{bottom:f-M.top+6}:{top:M.bottom+6},w=k?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{left:M.left,width:"max-content",minWidth:M.width,maxWidth:Math.max(M.width,g-M.left-8)},(0,r.jsx)("div",{ref:S,role:"listbox","aria-label":u,style:{position:"fixed",...b,...w,zIndex:500,display:"flex",flexDirection:"column",maxHeight:v,overflow:"hidden",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg)",boxShadow:y?"0 -4px 16px rgba(0,0,0,0.10)":"0 4px 16px rgba(0,0,0,0.10)"},children:(0,r.jsxs)("div",{style:{minHeight:0,overflowY:"auto"},children:[o&&(0,r.jsx)(n0,{active:!t,label:l??"Default",onClick:()=>{I(!1),o()}}),0===R.length?(0,r.jsx)("div",{style:{padding:"8px 12px",color:"var(--text-dim)",fontSize:12,whiteSpace:"nowrap"},children:"No available models"}):R.map((e,i)=>(0,r.jsxs)("div",{children:[R.length>1&&(0,r.jsx)("div",{style:{padding:"6px 12px 4px",borderTop:i>0||o?"1px solid var(--border)":"none",color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:0,textTransform:"uppercase"},children:e.provider}),e.options.map(e=>(0,r.jsx)(n0,{active:e.modelId===t?.modelId&&e.provider===t?.provider,label:e.name,onClick:()=>{let r;return r=e.modelId===t?.modelId&&e.provider===t?.provider,void(I(!1),(!r||c)&&n(e.provider,e.modelId))}},`${e.provider}:${e.modelId}`))]},e.provider))]})}))]})}function n0({active:e,label:t,onClick:n}){return(0,r.jsxs)("button",{type:"button",role:"option","aria-selected":e,onClick:n,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",border:"none",background:e?"var(--bg-selected)":"none",color:e?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:e?600:400,textAlign:"left",whiteSpace:"nowrap"},onMouseEnter:t=>{e||(t.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:t=>{e||(t.currentTarget.style.background="none")},children:[e?(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)("span",{title:t,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:t})]})}let n1=["chat-only","read-only","default","full"],n2={"chat-only":"none","read-only":"read-only",default:"default",full:"full"},n4=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function n8(e,t){let n=null,r=()=>{n=null,t(function(e,t,n=8){return Math.max(0,Math.floor(e-t-n))}(e.getBoundingClientRect().bottom,function(e){let t=window.visualViewport?.offsetTop??0;for(let n=e.parentElement;n;n=n.parentElement){let e=window.getComputedStyle(n).overflowY;("auto"===e||"scroll"===e||"hidden"===e||"clip"===e)&&(t=Math.max(t,n.getBoundingClientRect().top+n.clientTop))}return t}(e)))},i=()=>{null!==n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};r();let o=e.parentElement,l=o?.parentElement,s="u">typeof ResizeObserver&&o?new ResizeObserver(i):null;o&&s?.observe(o),l&&s?.observe(l);let a=window.visualViewport;return a?.addEventListener("resize",i),a?.addEventListener("scroll",i),window.addEventListener("resize",i),window.addEventListener("scroll",i,!0),()=>{s?.disconnect(),a?.removeEventListener("resize",i),a?.removeEventListener("scroll",i),window.removeEventListener("resize",i),window.removeEventListener("scroll",i,!0),null!==n&&cancelAnimationFrame(n)}}let n5=["auto","off","minimal","low","medium","high","xhigh","max"],n6={auto:"chat.thinkingUseDefault",off:"chat.thinkingOff",minimal:"chat.thinkingMinimal",low:"chat.thinkingLow",medium:"chat.thinkingMedium",high:"chat.thinkingHigh",xhigh:"chat.thinkingXhigh",max:"chat.thinkingMax"},n3=[{name:"compact",description:"chat.commandCompact",source:"builtin"},{name:"reload",description:"chat.commandReload",source:"builtin"},{name:"name",description:"chat.commandName",source:"builtin"},{name:"session",description:"chat.commandSession",source:"builtin",availableWhileStreaming:!0},{name:"copy",description:"chat.commandCopy",source:"builtin",availableWhileStreaming:!0},{name:"clone",description:"chat.commandClone",source:"builtin"}];function n7(e){return function(e){let t=e.trim().match(/^\/([^\s]+)(?:\s|$)/);if(t)return n3.find(e=>e.name===t[1])}(e)?.availableWhileStreaming===!0}function n9(e,t){return`${t.map(e=>nM(e,!1)).join("")}${e.trim()}`.trim()}let re=["builtin","extension","prompt","skill"],rt={builtin:"chat.builtIn",extension:"chat.extensions",prompt:"chat.prompts",skill:"chat.skills"},rn={builtin:0,extension:1,prompt:2,skill:3};function rr(e,t,n){let r=e.name.toLowerCase(),i=ri(e,n).toLowerCase();return r===t?0:r.startsWith(t)?1:r.includes(t)?2:i.includes(t)?3:4}function ri(e,t){return"builtin"===e.source?t(e.description):e.description??""}function ro(e,t){return"skill"===e.source&&!!e.name.startsWith("skill:")&&!0===t[e.name.slice(6)]}async function rl(e){let t=()=>{var t;return t=e.type,new Promise((n,r)=>{let i=new FileReader;i.onload=()=>{let e="string"==typeof i.result?i.result.split(",")[1]:void 0;e?n({data:e,mimeType:t}):r(Error("Failed to read image"))},i.onerror=r,i.readAsDataURL(e)})};if(!(e.size>1048576&&"image/gif"!==e.type)||"function"!=typeof createImageBitmap)return t();let n=await createImageBitmap(e).catch(()=>null);if(!n)return t();try{let r=Math.min(1,1024/Math.max(n.width,n.height)),i=document.createElement("canvas");i.width=Math.max(1,Math.round(n.width*r)),i.height=Math.max(1,Math.round(n.height*r));let o=i.getContext("2d");if(!o)return t();o.fillStyle="#fff",o.fillRect(0,0,i.width,i.height),o.drawImage(n,0,0,i.width,i.height);let l=i.toDataURL("image/jpeg",.85).split(",")[1];return l&&l.length<4*Math.ceil(e.size/3)?{data:l,mimeType:"image/jpeg"}:t()}catch{return t()}finally{n.close()}}function rs(e){return{data:e.data,mimeType:e.mimeType}}function ra(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function rd(e){return(e??[]).map(ra)}function rc(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function ru({kind:e,text:t}){return(0,r.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",padding:"1px 7px",borderRadius:4,border:`1px solid ${"steer"===e?"color-mix(in srgb, var(--accent) 45%, transparent)":"var(--border)"}`,color:"steer"===e?"var(--accent)":"var(--text-dim)"},children:e}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})}function rh({tone:e,title:t,body:n,onClose:i}){let o="error"===e?"239,68,68":"234,179,8";return(0,r.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"flex-start",gap:8,maxHeight:120,marginBottom:8,padding:"7px 10px",overflowY:"auto",border:`1px solid rgba(${o},0.3)`,borderRadius:4,background:`rgba(${o},0.07)`,color:`rgb(${o})`,fontSize:11,lineHeight:1.45},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:1},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M10.3 2.9 1.8 17a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 2.9a2 2 0 0 0-3.4 0Z"}),(0,r.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,r.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("div",{style:{fontWeight:600},children:t}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:n})]}),i&&(0,r.jsx)("button",{type:"button",onClick:i,"aria-label":"Dismiss",style:{flexShrink:0,background:"none",border:"none",padding:"0 2px",cursor:"pointer",color:"inherit",opacity:.7,fontSize:13,lineHeight:1},children:"\xd7"})]})}function rp({error:e}){let{t}=(0,x.s)();return e?(0,r.jsx)(rh,{tone:"error",title:t("chat.modelError"),body:e}):null}function rf({warnings:e}){let{t}=(0,x.s)();return e&&0!==e.length?(0,r.jsx)(rh,{tone:"warning",title:t(e.length>1?"chat.modelScopeWarnings":"chat.modelScopeWarning"),body:e.join("\n")}):null}let rg=(0,i.forwardRef)(function({onSend:e,onOpenImageGeneration:t,onAbort:n,onSteer:o,onFollowUp:l,isStreaming:s,disabled:a=!1,model:d,isAutoModelSelection:c,modelNames:u,modelList:h,modelError:p,modelScopeWarnings:f,onModelChange:g,modelSwitching:m,onCompact:y,onAbortCompaction:v,isCompacting:b,compactError:w,compactResult:k,toolPreset:S,onToolPresetChange:C,contextUsage:M,cacheHitRate:T,onOpenSessionStats:E,thinkingLevel:L,onThinkingLevelChange:R,availableThinkingLevels:N,thinkingLevelMap:$,retryInfo:W,queuedMessages:z,inputHistory:P=[],onRecallQueue:A,slashCommands:D,slashCommandsLoading:F,onLoadSlashCommands:B,onBuiltinCommand:H,soundEnabled:O,onSoundToggle:U,onAudioUnlock:_,onPromptWithStreamingBehavior:q,draftKey:K,onDraftChange:V,draftPersistenceWarning:J=!1,cwd:Y,compact:Z=!1},G){let X,Q,ee,et,en,er,ei,eo,el,es,ea,ed,ec,eu,eh,ep,ef,ex,{t:em}=(0,x.s)(),{fontSize:ey}=nV(),ev=nN(),eb=(0,i.useId)(),[ew,ek]=(0,i.useState)(()=>K?nm(K)?.value??"":""),[ej,eS]=(0,i.useState)(!1),[eC,eI]=(0,i.useState)(!1),[eM,eT]=(0,i.useState)(!1),[eE,eL]=(0,i.useState)(!1),[eR,eN]=(0,i.useState)([]),e$=(0,i.useRef)([]);e$.current=eR;let[eW,ez]=(0,i.useState)(()=>K?rd(nm(K)?.images):[]),eP=ew.trimStart(),eA=0===eW.length&&eP.startsWith("!"),eD=eA&&eP.startsWith("!!"),[eF,eB]=(0,i.useState)(!1),[eH,eO]=(0,i.useState)(0),[eU,e_]=(0,i.useState)(null),[eq,eK]=(0,i.useState)(null),[eV,eJ]=(0,i.useState)(!1),[eY,eZ]=(0,i.useState)(null),[eG,eX]=(0,i.useState)(0),[eQ,e0]=(0,i.useState)(!1),[e1,e2]=(0,i.useState)(!1),[e4,e8]=(0,i.useState)(!1),[e5,e6]=(0,i.useState)(0),[e3,e7]=(0,i.useState)(!1),[e9,te]=(0,i.useState)(null),[tt,tn]=(0,i.useState)(!1),[tr,ti]=(0,i.useState)(null),[to,tl]=(0,i.useState)(null),ts=Y&&to?.cwd===Y?to.values:{},ta=(0,i.useRef)(null),td=(0,i.useRef)(null),tc=(0,i.useRef)(null),tu=(0,i.useRef)(null),th=(0,i.useRef)(null),tp=(0,i.useRef)(null),tf=(0,i.useRef)(null),tg=(0,i.useRef)(!1),tx=(0,i.useRef)(0),tm=(0,i.useRef)(!1),ty=(0,i.useRef)(null),tv=(0,i.useRef)([]),tb=(0,i.useRef)(null),tw=(0,i.useRef)([]),tk=(0,i.useRef)(!1),tj=(0,i.useRef)([]),tS=(0,i.useRef)(null),tC=(0,i.useRef)(null),tI=(0,i.useRef)(K),tM=(0,i.useRef)(ew),tT=(0,i.useRef)(eW),tE=(0,i.useRef)(0);tM.current=ew,tT.current=eW,(0,i.useImperativeHandle)(G,()=>({insertIfEmpty(e){let t=ta.current;(t?t.value:ew).trim()||(tM.current=e,ek(e),eK(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},replaceMessage(e){var t,n,r;let i=ta.current;if(t=i?i.value:ew,n=tT.current.length,r=tE.current,t.trim()||0!==n||0!==r)return;let o="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),l=rd("string"==typeof e.content?[]:e.content.flatMap(e=>{if("image"!==e.type)return[];let t=e.source?.type==="base64"?e.source.data:e.data,n=e.source?.type==="base64"?e.source.media_type:e.mimeType;if("string"!=typeof t||"string"!=typeof n)return[];let r={data:t,mimeType:n};return!function(e){if(!e||"object"!=typeof e||"string"!=typeof e.data||"string"!=typeof e.mimeType||!e.mimeType.startsWith("image/"))return!1;let t=function(e){if(!e||e.length%4!=0)return null;let t=e.endsWith("==")?2:+!!e.endsWith("="),n=e.length-t;for(let t=0;t<n;t+=1){var r;if(!((r=e.charCodeAt(t))>=65&&r<=90||r>=97&&r<=122||r>=48&&r<=57||43===r||47===r))return null}for(let t=n;t<e.length;t+=1)if("="!==e[t])return null;return e.length/4*3-t}(e.data);return null!==t&&t<=0xa00000}(r)?[]:[r]}));tM.current=o,tT.current=l,ek(o),eK(null),e8(!1),ez(e=>(e.forEach(rc),l)),requestAnimationFrame(()=>{i&&(i.focus(),i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight,200)}px`)})},prependText(e){if(!e.trim())return;let t=ta.current,n=[e,t?t.value:ew].filter(e=>e.trim()).join("\n\n");tM.current=n,ek(n),eK(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(n.length,n.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},rekeyDraft(e,t){if(e===t)return;if(tI.current!==e)return void nj(e,t);let n={value:tM.current,images:tT.current.map(rs)},r=nj(e,t,n)??{value:"",images:[]},i=r.value===n.value&&r.images.length===n.images.length&&r.images.every((e,t)=>e.data===n.images[t]?.data&&e.mimeType===n.images[t]?.mimeType);if(tI.current=t,i)return;let o=rd(r.images);tM.current=r.value,tT.current=o,ek(r.value),ez(e=>(e.forEach(rc),o)),eK(null),e8(!1)},restoreSubmission(e,t,n){if(!e.trim()&&!t?.length)return;let r=tI.current,i=n??r,o=i===r,l=!o&&i?nm(i):null,s=nk(e,t,o?tM.current:l?.value??"",o?tT.current.map(rs):l?.images??[]);if(i&&ny(i,s),!o)return;let a=rd(s.images);tM.current=s.value,tT.current=a,ek(t=>{let n=nb(e,t);return tM.current=n,n}),eK(null),e8(!1),ez(e=>(e.forEach(rc),tT.current=a,a)),requestAnimationFrame(()=>{let e=ta.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},insertText(e){let t=ta.current;if(!t)return void ek(t=>t+(t?" ":"")+e);let n=t.selectionStart??t.value.length,r=t.selectionEnd??t.value.length,i=t.value.slice(0,n),o=t.value.slice(r),l=i.length>0&&!i.endsWith(" ")?" ":"",s=i+l+e+o;tM.current=s,ek(s),eK(null),requestAnimationFrame(()=>{if(!t)return;let r=n+l.length+e.length;t.setSelectionRange(r,r),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},addImages(e){tL(e)},mentionImage(e){eN(t=>t.includes(e)?t:[...t,e]),requestAnimationFrame(()=>ta.current?.focus())}}));let tL=(0,i.useCallback)(async e=>{if(Z)return;let t=Math.max(0,10-tT.current.length-tE.current),n=e.filter(e=>e.type.startsWith("image/")&&e.size<=0xa00000).slice(0,t);if(n.length){tE.current+=n.length;try{let e=await Promise.all(n.map(async e=>({...await rl(e),previewUrl:URL.createObjectURL(e)})));ez(t=>{let n=e.slice(0,Math.max(0,10-t.length));e.slice(n.length).forEach(rc);let r=[...t,...n];return tT.current=r,r})}finally{tE.current-=n.length}}},[Z]),tR=(0,i.useCallback)(e=>{ez(t=>{let n=[...t],[r]=n.splice(e,1);return r&&rc(r),tT.current=n,n})},[]),t$=(0,i.useCallback)(()=>{tT.current=[],ez(e=>(e.forEach(rc),[]))},[]),tW=(0,i.useCallback)(()=>{tM.current="",ek(""),eK(null),e8(!1),K&&nv(K),tI.current&&tI.current!==K&&nv(tI.current),t$(),e$.current=[],eN([]),ta.current&&(ta.current.style.height="auto")},[t$,K]);(0,i.useEffect)(()=>{K&&tI.current===K&&(e7(!ny(K,{value:ew,images:eW.map(rs)})),V?.(K,ew,eW.length))},[eW,K,V,ew]),(0,i.useEffect)(()=>{let e=tI.current;if(e===K)return;e&&ny(e,{value:tM.current,images:tT.current.map(rs)});let t=K?nm(K):null;tI.current=K;let n=t?.value??"",r=rd(t?.images);tM.current=n,tT.current=r,ek(n),eK(null),e8(!1),ez(e=>(e.forEach(rc),r)),K&&V?.(K,n,r.length)},[K,V]);let tz=(0,i.useCallback)(()=>{let e=ta.current;e&&(e.style.height="auto",e.value&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[]);(0,i.useLayoutEffect)(tz,[ew,ey,tz]),(0,i.useEffect)(()=>{let e=ta.current;if(!e)return;let t=-1,n=new ResizeObserver(([e])=>{e.contentRect.width!==t&&(t=e.contentRect.width,tz())});return n.observe(e),()=>n.disconnect()},[tz]),(0,i.useEffect)(()=>()=>{tT.current.forEach(rc)},[]);let tP=(0,i.useCallback)(async e=>{if(eW.length||!e.startsWith("/")||!H)return!1;if(tk.current)return!0;tk.current=!0,e0(!0);try{var t,n;let r=await H(e);if(!r.handled)return!1;return r.error||(t=tM.current,n=tT.current.length,0!==n||t.trim()!==e)||tW(),!0}finally{tk.current=!1,e0(!1)}},[eW.length,tW,H]),tA=(0,i.useCallback)(async()=>{if(a)return;let t=ew.trim();if(eW.length>10)return;let n=n9(t,eR);if(!n&&!eW.length||(_?.(),(!s||n7(t))&&await tP(t)||s))return;let r=eW.length?eW:void 0;tW(),e(n,r)},[a,ew,eW,eR,s,tP,e,tW,_]),tD=!Z&&ew.startsWith("/")&&!/\s/.test(ew.slice(1))?ew.slice(1).toLowerCase():null,tF=null===tD?[]:[...s?n3.filter(e=>e.availableWhileStreaming):n3,...D??[]].filter(e=>{let t=e.name.toLowerCase(),n=ri(e,em).toLowerCase();return t.includes(tD)||n.includes(tD)}).sort((e,t)=>{let n=rr(e,tD,em)-rr(t,tD,em);return 0!==n?n:rn[e.source]-rn[t.source]||n4.compare(e.name,t.name)}),{commands:tB,groups:tH}=(X=0,{commands:(Q=re.map(e=>{let t=tF.filter(t=>t.source===e),n="skill"===e?[...t.filter(e=>!ro(e,ts)),...t.filter(e=>ro(e,ts))]:t;return{source:e,items:n.map(e=>({command:e,index:X++}))}}).filter(e=>e.items.length>0)).flatMap(e=>e.items.map(({command:e})=>e)),groups:Q}),tO=1===tF.length?em(tD?"chat.match":"chat.command"):em(tD?"chat.matches":"chat.commands",{count:tF.length}),tU=!!ew.trim(),t_=eW.length>10,tq=!t_&&(tU||eW.length>0||eR.length>0),tK=!a&&!t_&&(tU||eW.length>0||eR.length>0),tV=eW.length>0&&!function(e,t){if(!e)return!0;let n=t?.find(t=>t.provider===e.provider&&t.id===e.modelId);return!n||!n.input||n.input.includes("image")}(d,h)&&!e1;(0,i.useEffect)(()=>{0===eW.length&&e2(!1)},[eW.length]);let tJ=(0,i.useCallback)((e,t)=>{if(!Y)return void eK(null);let n=t??e.length;eK(nS(e.slice(0,n)))},[Y]),tY=eq?.query??null,tZ=i.useMemo(()=>null!==tY&&e9&&e9.cwd===Y?function(e,t,n=20){let r=t.toLowerCase();if(!r)return e.slice(0,n);let i=[];for(let t of e){let e=function(e,t){let n=e.path.toLowerCase(),r=0;if(t.includes("/"))n===t?r=100:n.startsWith(t)?r=80:n.includes(t)?r=50:nI(t,n)&&(r=10);else{let e=n.lastIndexOf("/"),i=-1===e?n:n.slice(e+1);i===t?r=100:i.startsWith(t)?r=80:i.includes(t)?r=50:n.includes(t)?r=30:nI(t,n)&&(r=10)}return e.isDir&&r>0&&(r+=10),r}(t,r);e>0&&i.push({entry:t,score:e})}return i.sort((e,t)=>t.score-e.score||nC(e.entry.path)-nC(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),i.slice(0,n).map(e=>e.entry)}(e9.entries,tY):[],[tY,e9,Y]),tG=!!(tY&&e9?.truncated&&e9.cwd===Y);(0,i.useEffect)(()=>{if(!tG||!Y||!tY)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(Y)}&q=${encodeURIComponent(tY)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>ti({cwd:Y,query:tY,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[tG,tY,Y]);let tX=tG&&null!==tr&&tr.cwd===Y&&tr.query===tY,tQ=tX?tr.matches:tZ,t0=null===eq?null:`${eq.start}:${+!!eq.quoted}:${eq.query}`;(0,i.useEffect)(()=>{if(null===t0){eJ(!1),eX(0);return}eJ(!0),eX(0)},[t0]);let t1=null!==eq;(0,i.useEffect)(()=>{if(!t1||!Y)return;let e=tS.current;e&&e.cwd===Y&&Date.now()-e.fetchedAt<1e4||tC.current===Y||(tC.current=Y,tn(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(Y)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{te({cwd:Y,entries:function(e){let t=new Set;for(let n of e){let e=n.indexOf("/");for(;-1!==e;)t.add(n.slice(0,e)),e=n.indexOf("/",e+1)}let n=[];for(let e of t)n.push({path:e,isDir:!0});for(let t of e)t&&n.push({path:t,isDir:!1});return n.sort((e,t)=>nC(e.path)-nC(t.path)||e.path.localeCompare(t.path)),n}(e.files??[]),truncated:!!e.truncated}),tS.current={cwd:Y,fetchedAt:Date.now()}}).catch(()=>{tS.current=null}).finally(()=>{tC.current=null,tn(!1)}))},[t1,Y]);let t2=(0,i.useCallback)(e=>{if(!eq)return;let t=ta.current,n=t?.selectionStart??ew.length,r=ew.slice(0,eq.start),i=ew.slice(n);eq.quoted&&i.startsWith('"')&&(i=i.slice(1));let o=function(e,t,n=!1){let r=t?`${e}/`:e,i=n||r.includes(" ");if(t){let e=i?`@"${r}"`:`@${r}`;return{text:e,cursorOffset:i?e.length-1:e.length}}let o=i?`@"${r}" `:`@${r} `;return{text:o,cursorOffset:o.length}}(e.path,e.isDir,eq.quoted),l=r+o.text+i,s=r.length+o.cursorOffset;ek(l),eK(nS(l.slice(0,s))),requestAnimationFrame(()=>{let e=ta.current;e&&(e.focus(),e.setSelectionRange(s,s),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[eq,ew]);(0,i.useEffect)(()=>{eG>=tQ.length&&eX(Math.max(0,tQ.length-1))},[tQ.length,eG]),(0,i.useEffect)(()=>{tw.current.length=tQ.length},[tQ.length]),(0,i.useEffect)(()=>{eV&&tw.current[eG]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eG,eV]),(0,i.useEffect)(()=>{e5>=P.length&&e6(Math.max(0,P.length-1))},[P.length,e5]),(0,i.useEffect)(()=>{tj.current.length=P.length},[P.length]),(0,i.useEffect)(()=>{e4&&tj.current[e5]?.scrollIntoView({block:"nearest",inline:"nearest"})},[e5,e4]);let t4=(0,i.useCallback)(e=>{ek(e),e8(!1),e6(0),eK(null),requestAnimationFrame(()=>{let t=ta.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},[]),t8=(0,i.useCallback)(e=>{let t=`/${e.name} `;ek(t),eB(!1),eO(0),requestAnimationFrame(()=>{let e=ta.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),t5=(0,i.useCallback)(e=>{let t=ew.trim();if(eW.length>10)return;let n=n9(t,eR);if(!n&&!eW.length)return;if(_?.(),!eW.length&&H&&n7(t))return void tP(t);let r=eW.length?eW:void 0;if(t.startsWith("/")&&q){tW(),q(t,"steer"===e?"steer":"followUp",r);return}tW(),"steer"===e&&o?o(n,r):"followup"===e&&l&&l(n,r)},[ew,eW,eR,H,q,o,l,tW,_,tP]),t6=(0,i.useCallback)(e=>{let t=tB.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 n=tv.current[eH];if(!n)return"down"===e?Math.min(t,eH+1):Math.max(0,eH-1);let r=n.getBoundingClientRect(),i=r.left+r.width/2,o=r.top+r.height/2,l=-1,s=1/0;for(let n=0;n<=t;n+=1){if(n===eH)continue;let t=tv.current[n];if(!t)continue;let r=t.getBoundingClientRect(),a=r.top+r.height/2-o;if("down"===e?a<=4:a>=-4)continue;let d=1e3*Math.abs(a)+Math.abs(r.left+r.width/2-i);d<s&&(l=n,s=d)}return l>=0?l:"down"===e?Math.min(t,eH+1):Math.max(0,eH-1)},[tB.length,eH]),t3=(0,i.useCallback)(e=>{let t=e.nativeEvent,r=!ev&&nZ(),i="Enter"===e.key&&e.shiftKey===r&&(!ev||e.ctrlKey||e.metaKey),a=Date.now()-tx.current<100,d=tg.current||t.isComposing||229===t.keyCode;if(i&&(d||a)){a&&e.preventDefault();return}if(e4&&!d){if("ArrowDown"===e.key){e.preventDefault(),e6(e=>Math.min(Math.max(0,P.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),e6(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),e8(!1);return}if(("Tab"===e.key||i)&&P[e5]){e.preventDefault(),t4(P[e5]);return}}if(eF&&null!==tD){if("ArrowDown"===e.key){e.preventDefault(),eO(t6("down"));return}if("ArrowUp"===e.key){e.preventDefault(),eO(t6("up"));return}if("ArrowRight"===e.key){e.preventDefault(),eO(t6("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),eO(t6("left"));return}if("Escape"===e.key){e.preventDefault(),eB(!1);return}let t=tB[eH];if("Tab"===e.key&&t){e.preventDefault(),t8(t);return}if(i&&t)return void((e.preventDefault(),s&&("builtin"!==t.source||!0!==t.availableWhileStreaming)||"builtin"!==t.source||ew.trim()!==`/${t.name}`)?t8(t):(eB(!1),tA()))}if(eV&&null!==eq&&!d){if("ArrowDown"===e.key){e.preventDefault(),eX(e=>0===tQ.length?0:(e+1)%tQ.length);return}if("ArrowUp"===e.key){e.preventDefault(),eX(e=>0===tQ.length?0:(e-1+tQ.length)%tQ.length);return}if("Escape"===e.key){e.preventDefault(),eJ(!1);return}if(("Tab"===e.key||i)&&tQ[eG]){e.preventDefault(),t2(tQ[eG]);return}}if("ArrowUp"===e.key&&!d&&!s&&P.length>0&&0===ew.trim().length){e.preventDefault(),eB(!1),eJ(!1),e6(P.length-1),e8(!0);return}if("Escape"===e.key&&eM){e.preventDefault(),eT(!1);return}if("Escape"===e.key&&!d&&s&&n){e.preventDefault(),n();return}i&&(e.preventDefault(),s&&(o||l)?t5(e.altKey&&l||!o?"followup":"steer"):tA())},[ev,s,o,l,n,eM,eF,tD,tB,eH,t8,t5,tA,t6,eV,eq,tQ,eG,t2,e4,P,e5,t4,ew]),t7=(0,i.useCallback)(()=>{let e=ta.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),t9=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.type.startsWith("image/"));if(!Z&&t.length){e.preventDefault(),tL(t.map(e=>e.getAsFile()).filter(e=>null!==e));return}let n=e.clipboardData.getData("text/html"),r=e.clipboardData.getData("text/plain");if(!n||!r)return;let i=new DOMParser().parseFromString(n,"text/html"),o=function(e,t){let n="",r=0,i=!1;for(let{label:o,href:l,occurrence:s}of t){if(!o||!l)continue;let t=0;for(let n=0;n<=s&&!((t=e.indexOf(o,n?t+o.length:0))<0);n++);if(t<r)continue;let a=o.replace(/([\\[\]])/g,"\\$1"),d=l.replace(/([\\()])/g,"\\$1");n+=`${e.slice(r,t)}[${a}](${d})`,r=t+o.length,i=!0}return i?n+e.slice(r):null}(r,Array.from(i.querySelectorAll("a[href]"),e=>{let t=e.textContent??"",n=i.createRange();return n.setStart(i.body,0),n.setEndBefore(e),{label:t,href:e.getAttribute("href")?.trim()??"",occurrence:t?n.toString().split(t).length-1:0}}));if(null===o)return;let l=e.currentTarget,s=l.selectionStart,a=l.value.slice(0,s)+o+l.value.slice(l.selectionEnd);e.preventDefault(),tM.current=a,ek(a),e8(!1),tJ(a,s+o.length),requestAnimationFrame(()=>{l.focus(),l.setSelectionRange(s+o.length,s+o.length)})},[Z,tL,tJ]);(0,i.useEffect)(()=>{if(null===tD){eB(!1),eO(0),tm.current=!1;return}eB(!0),eO(0),!tm.current&&B&&(tm.current=!0,Promise.resolve(B()).catch(()=>{tm.current=!1}))},[tD,B]),(0,i.useEffect)(()=>{if(!eF||!Y)return;let e=!1;return tl({cwd:Y,values:{}}),fetch(`/api/skills?cwd=${encodeURIComponent(Y)}`).then(e=>{if(!e.ok)throw Error(`skills fetch failed: ${e.status}`);return e.json()}).then(t=>{if(e)return;let n={};for(let e of t.skills??[])n[e.name]=e.disableModelInvocation;tl({cwd:Y,values:n})}).catch(()=>{e||tl({cwd:Y,values:{}})}),()=>{e=!0}},[eF,Y]),(0,i.useEffect)(()=>{eH>=tB.length&&eO(Math.max(0,tB.length-1))},[tB.length,eH]),(0,i.useEffect)(()=>{tv.current.length=tB.length},[tB.length]),(0,i.useEffect)(()=>{eF&&tv.current[eH]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eH,eF]),(0,i.useLayoutEffect)(()=>{if(!eF||null===tD)return void e_(null);let e=ty.current;if(e)return n8(e,e=>{e_(t=>t===e?t:e)})},[eF,tD]),(0,i.useLayoutEffect)(()=>{if(!eV||null===eq)return void eZ(null);let e=tb.current;if(e)return n8(e,e=>{eZ(t=>t===e?t:e)})},[eV,eq]);let ne=h&&h.length>0?h.map(e=>({provider:e.provider,modelId:e.id,name:e.name})):Object.entries(u??{}).map(([e,t])=>({provider:d?.provider??"unknown",modelId:e,name:t})),nt=k?Math.max(0,k.tokensBefore-k.estimatedTokensAfter):0,nn=k?`${k.reason&&"manual"!==k.reason?`${k.reason[0].toUpperCase()}${k.reason.slice(1)} `:em("chat.compacted")} ${nJ(k.tokensBefore)} -> ${nJ(k.estimatedTokensAfter)} tokens (${em("chat.tokensSaved",{saved:nJ(nt)})})`:null,nr="auto"!==(ee=L??"auto")&&$?$[ee]??ee:ee,ni=Object.entries(n2).find(([,e])=>e===(S??"default"))?.[0]??"default",no="chat-only"===ni?em("chat.chatOnly"):ni,nl=M?.percent??null,ns=[nr,null!=nl&&nl>=70?`${Math.round(nl)}%`:null].filter(Boolean).join(" \xb7 ");(0,i.useEffect)(()=>{let e=e=>{let t=e.target;td.current&&!td.current.contains(t)&&eS(!1),tc.current&&!tc.current.contains(t)&&eI(!1),tu.current&&!tu.current.contains(t)&&eT(!1),th.current&&!th.current.contains(t)&&eL(!1),!tp.current||tp.current.contains(t)||ta.current?.contains(t)||e8(!1)};return document.addEventListener("pointerdown",e),document.addEventListener("mousedown",e),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("mousedown",e)}},[]),(0,i.useEffect)(()=>{ev||eL(!1)},[ev]),(0,i.useEffect)(()=>{s&&(eI(!1),eS(!1),eT(!1))},[s]);let na=`${eb}-history`,nd=`${eb}-slash`,nc=`${eb}-files`,nu=e4&&P.length>0?na:eF&&null!==tD?nd:eV&&null!==eq?nc:void 0,nh=nu===na&&void 0!==P[e5]?`${na}-${e5}`:nu===nd&&tB[eH]?`${nd}-${eH}`:nu===nc&&tQ[eG]?`${nc}-${eG}`:void 0;return(0,r.jsxs)("fieldset",{disabled:eQ,"aria-busy":eQ,className:Z?"chat-input is-compact":"chat-input",style:{flexShrink:0,minWidth:0,margin:0,border:0,background:"transparent",padding:Z?0:"0 16px 8px",paddingRight:16*!Z,opacity:eQ?.5:1,transition:"opacity 0.15s"},children:[!Z&&(0,r.jsx)("input",{ref:tf,type:"file",accept:"image/*",multiple:!0,disabled:a,style:{display:"none"},onChange:e=>{tL(Array.from(e.target.files??[])),e.target.value=""}}),(0,r.jsxs)("div",{style:{maxWidth:"var(--chat-content-max-width, 820px)",margin:"0 auto"},children:[(0,r.jsx)(rp,{error:p}),(0,r.jsx)(rf,{warnings:f}),t_&&(0,r.jsx)(rh,{tone:"error",title:em("chat.tooManyImagesTitle"),body:em("chat.tooManyImagesBody",{count:eW.length,max:10})}),tV&&(et=h?.find(e=>e.provider===d?.provider&&e.id===d?.modelId),(0,r.jsx)(rh,{tone:"warning",title:em("chat.imageNotSupportedTitle"),body:em("chat.imageNotSupportedBody",{model:et?.name||d?.modelId||""}),onClose:()=>e2(!0)})),(z?.steering.length??0)+(z?.followUp.length??0)>0&&(0,r.jsxs)("div",{style:{marginBottom:8,border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",padding:"5px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 8px 4px 10px"},children:[(0,r.jsx)("span",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:em("chat.queued",{count:(z?.steering.length??0)+(z?.followUp.length??0)})}),A&&(0,r.jsxs)("button",{onClick:A,title:em("chat.recallTitle"),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",fontSize:12,color:"var(--text)",background:"transparent",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",transition:"background 0.12s, border-color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"9 14 4 9 9 4"}),(0,r.jsx)("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]}),em("chat.recall")]})]}),z?.steering.map((e,t)=>(0,r.jsx)(ru,{kind:"steer",text:e},`steer-${t}`)),z?.followUp.map((e,t)=>(0,r.jsx)(ru,{kind:"follow-up",text:e},`followup-${t}`))]}),W&&(0,r.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:4,fontSize:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"})]}),em("chat.retrying",{attempt:W.attempt,max:W.maxAttempts}),W.errorMessage&&(0,r.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",W.errorMessage]})]}),nn&&(0,r.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(16,185,129,0.08)",border:"1px solid rgba(16,185,129,0.24)",borderRadius:4,fontSize:12,color:"rgba(5,150,105,0.95)",display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),nn]}),w&&(0,r.jsx)("div",{role:"alert",style:{marginBottom:8,padding:"7px 10px",background:"rgba(239,68,68,0.07)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:w}),(e3||J)&&(0,r.jsx)("div",{role:"status",style:{marginBottom:8,color:"#d97706",fontSize:11.5},children:em("chat.draftPageOnly")}),(eW.length>0||eR.length>0)&&(0,r.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:8,flexWrap:"wrap",padding:"0 2px"},children:[eR.map(e=>(0,r.jsx)(eg,{path:e,cwd:Y??void 0,onRemove:()=>eN(t=>t.filter(t=>t!==e))},e)),eW.map((e,t)=>(0,r.jsxs)("div",{style:{position:"relative",flexShrink:0,borderRadius:6,overflow:"hidden",border:"1px solid var(--border)",boxShadow:"0 1px 3px rgba(0,0,0,0.05)"},children:[(0,r.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",display:"block"}}),(0,r.jsx)("button",{onClick:()=>tR(t),title:em("i18n.close"),"aria-label":em("i18n.close"),style:{position:"absolute",top:3,right:3,width:18,height:18,borderRadius:"50%",background:"rgba(0, 0, 0, 0.55)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"#ffffff",backdropFilter:"blur(4px)",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(0, 0, 0, 0.85)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(0, 0, 0, 0.55)"},children:(0,r.jsxs)("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},t))]}),(0,r.jsxs)("div",{style:{position:"relative",minWidth:0},children:[e4&&P.length>0&&(0,r.jsxs)("div",{ref:tp,style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(44vh, 360px)"},children:[(0,r.jsx)("div",{title:em("chat.inputHistory"),style:{height:30,padding:"0 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",color:"var(--text-dim)"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),(0,r.jsx)("path",{d:"M3 4v5h5"}),(0,r.jsx)("path",{d:"M12 7v5l3 2"})]})}),(0,r.jsx)("div",{id:na,role:"listbox",style:{maxHeight:"calc(min(44vh, 360px) - 31px)",overflowY:"auto",padding:4},children:P.map((e,t)=>{let n=t===e5;return(0,r.jsxs)("button",{ref:e=>{tj.current[t]=e},type:"button",id:`${na}-${t}`,role:"option","aria-selected":n,tabIndex:-1,onMouseDown:t=>{t.preventDefault(),t4(e)},onMouseEnter:()=>e6(t),style:{width:"100%",display:"flex",alignItems:"flex-start",gap:8,padding:"7px 8px",border:"none",borderRadius:4,background:n?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,lineHeight:1.45},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",paddingTop:1},children:t+1}),(0,r.jsx)("span",{style:{minWidth:0,display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",overflowWrap:"anywhere"},children:e})]},`${t}:${e}`)})})]}),eF&&null!==tD&&(0,r.jsxs)("div",{ref:ty,style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",boxSizing:"border-box",display:"flex",flexDirection:"column",maxHeight:null===eU?"min(72.8vh, 598px)":`min(72.8vh, 598px, ${eU}px)`},children:[(0,r.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("span",{children:F?em("chat.loadingCommands"):em("chat.slashCommands",{label:tO})}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:em("chat.tabEnter")})]}),(0,r.jsx)("div",{id:nd,role:"listbox",style:{flex:"1 1 auto",minHeight:0,overflowY:"auto",padding:10},children:F||0!==tF.length?tH.map(e=>(0,r.jsxs)("section",{style:{marginBottom:12},children:[(0,r.jsxs)("div",{style:{position:"sticky",top:-10,zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"4px 0 6px",background:"var(--bg)",color:"var(--text-dim)",fontSize:10,fontWeight:600,textTransform:"uppercase"},children:[(0,r.jsx)("span",{children:em(rt[e.source])}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:8},children:e.items.map(({command:e,index:t})=>{let n=t===eH,i=ro(e,ts);return(0,r.jsxs)("button",{ref:e=>{tv.current[t]=e},type:"button",id:`${nd}-${t}`,role:"option","aria-selected":n,tabIndex:-1,onMouseDown:t=>{t.preventDefault(),t8(e)},onMouseEnter:()=>eO(t),style:{width:"100%",minWidth:0,minHeight:58,display:"flex",flexDirection:"column",gap:4,justifyContent:"center",padding:"9px 10px",border:`1px solid ${n?"var(--accent)":"var(--border)"}`,borderRadius:4,background:n?"var(--bg-selected)":"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",boxShadow:n?"0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent)":"none"},children:[(0,r.jsxs)("span",{style:{fontSize:13,fontFamily:"var(--font-mono)",overflowWrap:"anywhere",wordBreak:"break-word",color:i?"var(--text-dim)":void 0},children:["/",e.name,i&&(0,r.jsx)("span",{style:{marginLeft:6,padding:"0 4px",border:"1px solid var(--border)",borderRadius:3,fontSize:9,color:"var(--text-dim)",whiteSpace:"nowrap"},children:em("chat.dormant")})]}),e.description&&(0,r.jsx)("span",{style:{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",fontSize:11,lineHeight:1.35,color:"var(--text-dim)"},children:ri(e,em)})]},`${e.source}:${e.name}`)})})]},e.source)):(0,r.jsx)("div",{style:{padding:"2px 2px 4px",fontSize:12,color:"var(--text-dim)"},children:em("chat.noCommands")})})]}),eV&&null!==eq&&(en=tt&&(!e9||e9.cwd!==Y),er=1===tQ.length?em("chat.match"):em("chat.matches",{count:tQ.length}),ei=e9?.truncated&&!tX?eq.query?em("chat.searchingAll"):em("chat.indexTruncated"):"",(0,r.jsxs)("div",{ref:tb,style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",boxSizing:"border-box",display:"flex",flexDirection:"column",maxHeight:null===eY?"min(48vh, 400px)":`min(48vh, 400px, ${eY}px)`},children:[(0,r.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("span",{children:en?em("chat.loadingFiles"):em("chat.files",{label:er,hint:ei})}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:em("chat.tabEnter")})]}),(0,r.jsx)("div",{id:nc,role:"listbox",style:{flex:"1 1 auto",minHeight:0,overflowY:"auto",padding:4},children:en||0!==tQ.length?tQ.map((e,t)=>{let n=t===eG,i=e.path.split("/").pop()??e.path,o=e.path.slice(0,e.path.length-i.length);return(0,r.jsxs)("button",{ref:e=>{tw.current[t]=e},type:"button",id:`${nc}-${t}`,role:"option","aria-selected":n,tabIndex:-1,onMouseDown:t=>{t.preventDefault(),t2(e)},onMouseEnter:()=>eX(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"6px 8px",border:"none",borderRadius:4,background:n?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"inline-flex",alignItems:"center",transform:"translateY(0.5px)"},children:e.isDir?(0,r.jsx)(j,{size:14}):I(i,14)}),(0,r.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1},children:[o&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:o}),i,e.isDir&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,r.jsx)("div",{style:{padding:"6px 8px",fontSize:12,color:"var(--text-dim)"},children:tG&&!tX?em("chat.searching"):em("chat.noMatchingFiles")})})]})),(0,r.jsxs)("div",{className:`chat-input-composer${eA?" is-bash-mode":""}`,style:{minWidth:0,display:"flex",flexDirection:Z?"column":"row",gap:8,alignItems:Z?"stretch":"center",background:eA?"color-mix(in srgb, var(--bg-panel) 75%, var(--bg))":"var(--bg)",border:Z?"none":`1px solid ${eA?eD?"rgba(100,116,139,0.45)":"color-mix(in srgb, var(--accent) 45%, var(--border))":s&&(o||l)?"color-mix(in srgb, var(--border) 80%, transparent)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:6*!Z,padding:Z?0:"4px 6px 4px 10px",boxShadow:Z?"none":eA?"0 0 0 1px rgba(37,99,235,0.12)":"0 1px 2px rgba(15,23,42,0.04)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[eA&&(0,r.jsxs)("div",{style:{display:"inline-flex",alignItems:"center",gap:5,padding:"2px 6px",borderRadius:4,background:eD?"rgba(100,116,139,0.12)":"rgba(37,99,235,0.12)",color:eD?"var(--text-muted)":"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600,flexShrink:0,userSelect:"none"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block",transform:"translateY(0.5px)"},"aria-hidden":"true",children:[(0,r.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,r.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),(0,r.jsx)("span",{style:{lineHeight:1},children:eD?"Local":"Shell"})]}),(0,r.jsx)("textarea",{ref:ta,className:"chat-input-textarea",role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-expanded":!!nu,"aria-controls":nu,"aria-activedescendant":nh,"aria-label":Z?em("chat.quoteQuestion"):em("chat.message"),disabled:a,placeholder:a?em("agentSwitcher.status.queued"):void 0,value:ew,onChange:e=>{tM.current=e.target.value,ek(e.target.value),e8(!1),tJ(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;tJ(t.value,t.selectionStart)},onKeyDown:t3,onCompositionStart:()=>{tg.current=!0},onCompositionEnd:e=>{tg.current=!1,tx.current=Date.now();let t=e.currentTarget;tJ(t.value,t.selectionStart)},onInput:t7,onPaste:t9,rows:1,style:{flex:Z?"none":1,minWidth:0,width:"100%",background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:"var(--chat-content-font-size, 14px)",lineHeight:1.5,padding:0,fontFamily:eA?"var(--font-mono)":"var(--font-chat)",minHeight:Z?96:24,maxHeight:200,overflow:"auto"}}),s?tq?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[(0,r.jsx)("button",{type:"button",className:"chat-input-action","aria-label":em("chat.stop"),title:em("chat.stopAgent"),onClick:n,style:{display:"flex",alignItems:"center",justifyContent:"center",width:ev?32:28,height:ev?32:28,padding:0,background:"color-mix(in srgb, #ef4444 10%, transparent)",border:"1px solid color-mix(in srgb, #ef4444 24%, transparent)",borderRadius:5,color:"#ef4444",cursor:"pointer",transition:"background 0.15s, border-color 0.15s"},onMouseEnter:e=>{e.currentTarget.style.background="color-mix(in srgb, #ef4444 18%, transparent)",e.currentTarget.style.borderColor="color-mix(in srgb, #ef4444 40%, transparent)"},onMouseLeave:e=>{e.currentTarget.style.background="color-mix(in srgb, #ef4444 10%, transparent)",e.currentTarget.style.borderColor="color-mix(in srgb, #ef4444 24%, transparent)"},children:(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block",flexShrink:0},children:(0,r.jsx)("rect",{x:"5.5",y:"5.5",width:"13",height:"13",rx:"2",fill:"currentColor"})})}),l&&(0,r.jsxs)("button",{className:"chat-input-action","aria-label":em("chat.followUp"),onClick:()=>t5("followup"),title:`${em("chat.followUpHint")} (${ev?"Ctrl/Cmd+":""}Alt/Option+Enter)`,"aria-keyshortcuts":ev?"Control+Alt+Enter Meta+Alt+Enter":"Alt+Enter",style:{display:"flex",alignItems:"center",gap:5,height:ev?32:28,padding:"0 10px",background:"color-mix(in srgb, var(--accent) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 26%, transparent)",borderRadius:5,color:"var(--accent)",cursor:"pointer",fontSize:12.5,fontWeight:600,letterSpacing:"-0.01em",lineHeight:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="color-mix(in srgb, var(--accent) 16%, transparent)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 40%, transparent)"},onMouseLeave:e=>{e.currentTarget.style.background="color-mix(in srgb, var(--accent) 10%, transparent)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 26%, transparent)"},children:[(0,r.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block",flexShrink:0},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M12 17V5m-6 6 6-6 6 6M5 21h14"})}),(0,r.jsx)("span",{className:"chat-input-action-label",children:em("chat.followUp")})]}),o&&(0,r.jsxs)("button",{className:"chat-input-action","aria-label":em("chat.steer"),onClick:()=>t5("steer"),title:em("chat.steerHint"),style:{display:"flex",alignItems:"center",gap:5,height:ev?32:28,padding:"0 10px",background:"var(--accent)",border:"none",borderRadius:5,color:"#ffffff",cursor:"pointer",fontSize:12.5,fontWeight:600,letterSpacing:"-0.01em",lineHeight:1,transition:"background 0.12s, filter 0.12s"},onMouseEnter:e=>{e.currentTarget.style.filter="brightness(1.08)"},onMouseLeave:e=>{e.currentTarget.style.filter="none"},children:[(0,r.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block",flexShrink:0},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M5 12h14m-6-6 6 6-6 6"})}),(0,r.jsx)("span",{className:"chat-input-action-label",children:em("chat.steer")})]})]}):(0,r.jsxs)("button",{className:"chat-input-action","aria-label":em("chat.stop"),title:em("chat.stopAgent"),onClick:n,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:5,height:ev?32:28,padding:"0 10px",background:"color-mix(in srgb, #ef4444 12%, transparent)",border:"1px solid color-mix(in srgb, #ef4444 26%, transparent)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12.5,fontWeight:600,letterSpacing:"-0.01em",lineHeight:1,transition:"background 0.15s, border-color 0.15s"},onMouseEnter:e=>{e.currentTarget.style.background="color-mix(in srgb, #ef4444 18%, transparent)",e.currentTarget.style.borderColor="color-mix(in srgb, #ef4444 40%, transparent)"},onMouseLeave:e=>{e.currentTarget.style.background="color-mix(in srgb, #ef4444 12%, transparent)",e.currentTarget.style.borderColor="color-mix(in srgb, #ef4444 26%, transparent)"},children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block",flexShrink:0},children:(0,r.jsx)("rect",{x:"5.5",y:"5.5",width:"13",height:"13",rx:"2",fill:"currentColor"})}),(0,r.jsx)("span",{className:"chat-input-action-label",children:em("chat.stop")})]}):(0,r.jsxs)("button",{className:"chat-input-action","aria-label":em("chat.send"),title:t_?em("chat.tooManyImagesTitle"):em("chat.send"),onClick:tA,disabled:!tK,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:5,height:ev?32:28,padding:"0 10px",background:tK?"var(--accent)":"none",border:"none",borderRadius:5,color:tK?"#fff":"var(--text-dim)",opacity:tK?1:.45,cursor:tK?"pointer":"not-allowed",fontSize:12.5,fontWeight:600,letterSpacing:"-0.01em",lineHeight:1,transition:"background 0.15s, color 0.15s, opacity 0.15s, filter 0.15s"},onMouseEnter:e=>{tK&&(e.currentTarget.style.filter="brightness(1.08)")},onMouseLeave:e=>{tK&&(e.currentTarget.style.filter="none")},children:[(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block",flexShrink:0},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M12 19V5m-7 7 7-7 7 7"})}),(0,r.jsx)("span",{className:"chat-input-action-label",children:em("chat.send")})]})]})]}),eA&&(0,r.jsxs)("div",{className:"text-xs px-2 py-1",style:{color:eD?"var(--text-muted)":"var(--accent)",marginTop:4},children:[em("chat.shell")," \xb7 ",eD?em("chat.outputLocal"):em("chat.outputModel")]}),!Z&&(0,r.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:4,padding:ev?0:"0 2px",display:ev?"grid":"flex",gridTemplateColumns:ev?"minmax(0, 1fr) auto":void 0,alignItems:"center",gap:4},children:[(0,r.jsxs)("div",{style:{flex:ev?"1 1 auto":"0 0 auto",minWidth:0,display:"flex",alignItems:"center",gap:1},children:[(0,r.jsxs)("div",{ref:tu,style:{position:"relative",display:"flex",alignItems:"center"},children:[(0,r.jsx)("button",{type:"button",disabled:a,onClick:()=>{t?eT(e=>!e):tf.current?.click()},title:t?`${em("chat.attachImage")} / ${em("image.title")}`:em("chat.attachImage"),"aria-label":t?`${em("chat.attachImage")} / ${em("image.title")}`:em("chat.attachImage"),"aria-expanded":t?eM:void 0,"aria-haspopup":t?"menu":void 0,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",height:ev?32:28,padding:"0 4px",background:eM?"var(--bg-hover)":"none",border:"none",borderRadius:4,color:eW.length?"var(--accent)":eM?"var(--text)":"var(--text-muted)",cursor:a?"not-allowed":"pointer",opacity:a?.45:1,lineHeight:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{ev||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eW.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{ev||(e.currentTarget.style.background=eM?"var(--bg-hover)":"none",e.currentTarget.style.color=eW.length?"var(--accent)":eM?"var(--text)":"var(--text-muted)")},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block",flexShrink:0},children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,r.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),eM&&t&&(0,r.jsxs)("div",{role:"menu",onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),eT(!1))},style:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:120},children:[(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{eT(!1),tf.current?.click()},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:"none",border:"none",color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,r.jsx)("polyline",{points:"21 15 16 10 5 21"})]}),(0,r.jsx)("span",{children:em("chat.attachImage")})]}),(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{eT(!1),t()},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:"none",border:"none",color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"m15 4 5 5L8 21l-5-5L15 4Z"}),(0,r.jsx)("path",{d:"m14 5 5 5M6 4v3M4.5 5.5h3M19 16v4M17 18h4"})]}),(0,r.jsx)("span",{children:em("image.title")})]})]})]}),(ne.length>0||d||p)&&g&&(0,r.jsx)(nQ,{options:ne,value:d,onChange:g,disabled:s,busy:m,isAutoSelection:c})]}),!ev&&(0,r.jsx)("div",{style:{flex:1}}),ev&&eE&&(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:55,background:"transparent"},onClick:()=>{eS(!1),eI(!1),eL(!1)}}),(0,r.jsxs)("div",{ref:th,style:{flex:"0 0 auto",display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:ev?0:"auto",zIndex:ev&&eE?60:void 0},children:[ev&&(eo=!!(null!=nl&&nl>=85),(0,r.jsxs)("button",{type:"button",title:eE?em("chat.collapseControls"):em("chat.moreControls"),"aria-label":em("chat.moreControls"),"aria-expanded":eE,onClick:()=>{eE?(eS(!1),eI(!1),eL(!1)):eL(!0)},style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,maxWidth:"min(48vw, 200px)",height:32,padding:"0 6px",background:eE?eo?"rgba(239,68,68,0.12)":"var(--bg-hover)":eo?"rgba(239,68,68,0.06)":"none",border:eo?"1px solid rgba(239,68,68,0.25)":"none",borderRadius:4,color:eo?"#ef4444":null!=nl&&nl>=70&&nl<85?"rgba(234,179,8,0.95)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:400,lineHeight:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},children:[(0,r.jsx)(tN,{size:14,style:{display:"block"}}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ns})]})),(0,r.jsxs)("div",{className:"chat-input-toolbar-controls",style:{display:ev?eE?"flex":"none":"flex",alignItems:"center",gap:1,...ev?{position:"absolute",right:0,bottom:"calc(100% + 6px)",zIndex:60,padding:"1px 2px",width:"max-content",maxWidth:"calc(100vw - 32px)",flexWrap:"wrap",justifyContent:"flex-end",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg)",boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"}:null},children:[R&&(0,r.jsxs)("div",{ref:tc,style:{position:"relative",display:"flex",alignItems:"center"},children:[(0,r.jsxs)("button",{onClick:()=>!s&&eI(e=>!e),disabled:s,title:em("chat.changeReasoning",{level:nr}),"aria-label":em("chat.changeReasoningLabel"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 4px",width:ev?"auto":void 0,height:ev?32:28,background:eC?"var(--bg-hover)":"none",border:"none",borderRadius:4,color:"var(--text-muted)",cursor:s?"not-allowed":"pointer",fontSize:12,lineHeight:1,opacity:s?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{s||ev||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{ev||(e.currentTarget.style.background=eC?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)")},children:[(0,r.jsx)(tN,{size:14,style:{display:"block"}}),(!ev||eE)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap",lineHeight:1},children:nr})]}),eC&&(0,r.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",...ev?{left:0}:{right:0},zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:180},children:n5.filter(e=>!N||"auto"===e||N.includes(e)).map(e=>{let t=(L??"auto")===e,n=em(n6[e]),i="auto"!==e&&$?$[e]:void 0,o=null!=i&&i!==e?i:e,l=null!=i&&i!==e;return(0,r.jsxs)("button",{onClick:()=>{eI(!1),ev&&eL(!1),t||R(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsxs)("span",{style:{flex:1},children:[o,l&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:n})]},e)})})]}),!ev&&M&&M.contextWindow>0&&(el=M.contextWindow,es=M.tokens,ed=null!==(ea=M.percent??(null!==es?es/el*100:null))?Math.min(100,Math.max(0,ea)):0,ec=null!==ea&&ea>=85,eu=null!==ea&&ea>=70&&ea<85,eh=null!==es?`${nJ(es)}/${nJ(el)}`:`?/${nJ(el)}`,ep=null!==es?Math.max(0,el-es):null,ef=[`${em("chat.contextUsage")}: ${null!==es?nJ(es):"?"} / ${nJ(el)} (${null!==ea?ea.toFixed(1):"?"}%)`,null!==ep?`${em("chat.contextRemaining")}: ${nJ(ep)}`:null,null!=T?`${em("session.cacheHitRate")}: ${T.toFixed(1)}%`:null,ec?`⚠️ ${em("chat.contextHighWarning")}`:null].filter(Boolean).join("\n"),(0,r.jsxs)("button",{type:"button",onClick:E,title:ef,"aria-label":ef,"data-top-panel-trigger":E?"session":void 0,"aria-controls":E?"workspace-top-panel":void 0,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 4px",height:28,background:ec?"rgba(239,68,68,0.06)":"none",border:ec?"1px solid rgba(239,68,68,0.25)":"none",borderRadius:4,color:ec?"#ef4444":eu?"rgba(234,179,8,0.95)":"var(--text-muted)",cursor:E?"pointer":"default",fontSize:12,lineHeight:1,fontVariantNumeric:"tabular-nums",whiteSpace:"nowrap",transition:"background 0.12s, border-color 0.12s, color 0.12s"},onMouseEnter:e=>{E&&(e.currentTarget.style.background=ec?"rgba(239,68,68,0.12)":"var(--bg-hover)")},onMouseLeave:e=>{E&&(e.currentTarget.style.background=ec?"rgba(239,68,68,0.06)":"none")},children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",style:{display:"block",flexShrink:0,transform:"rotate(-90deg)"},children:[(0,r.jsx)("circle",{cx:"8",cy:"8",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.22"}),(0,r.jsx)("circle",{cx:"8",cy:"8",r:"5.5",pathLength:"100",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:`${ed} 100`,style:{transition:"stroke-dasharray 0.3s ease"}})]}),(0,r.jsx)("span",{style:{fontWeight:ec?600:400,letterSpacing:"-0.01em",lineHeight:1},children:eh}),null!=T&&(0,r.jsxs)("span",{style:{lineHeight:1},children:[T.toFixed(0),"%"]})]})),!s&&C&&(0,r.jsxs)("div",{ref:td,style:{position:"relative",display:"flex",alignItems:"center"},children:[(0,r.jsxs)("button",{onClick:()=>!s&&eS(e=>!e),disabled:s,title:em("chat.changeToolPreset")+`: ${no}`,"aria-label":em("chat.changeToolPreset"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 4px",width:ev?"auto":void 0,height:ev?32:28,background:ej?"var(--bg-hover)":"none",border:"none",borderRadius:4,color:"var(--text-muted)",cursor:s?"not-allowed":"pointer",fontSize:12,lineHeight:1,opacity:s?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{s||ev||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{ev||(e.currentTarget.style.background=ej?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)")},children:[(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block",flexShrink:0},children:(0,r.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(!ev||eE)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap",lineHeight:1},children:no})]}),ej&&(0,r.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:ev?void 0:0,left:ev?0:void 0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:120},children:n1.map(e=>{let t,n=n2[e],i=(S??"default")===n;return t="chat-only"===e?em("chat.chatOnly"):"read-only"===e?em("chat.readOnlyTools",{count:4}):"default"===e?em("chat.builtInTools",{count:4}):em("chat.allBuiltInTools"),(0,r.jsxs)("button",{onClick:()=>{eS(!1),ev&&eL(!1),i||C(n)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:i?"var(--bg-selected)":"none",border:"none",color:i?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:i?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[i?(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,r.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)("span",{style:{flex:1},children:e}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:t})]},e)})})]}),!s&&y&&(ex=!!(M?.percent&&M.percent>=85),(0,r.jsx)("div",{style:{display:"flex",alignItems:"center"},children:(0,r.jsx)("button",{onClick:()=>{ev&&eL(!1),b?v?.():y?.()},disabled:s&&!b,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 4px",width:ev?"auto":void 0,height:ev?32:28,background:b?"rgba(239,68,68,0.08)":ex?"rgba(239,68,68,0.06)":"none",border:ex&&!b?"1px solid rgba(239,68,68,0.25)":"none",borderRadius:4,color:b||ex?"#ef4444":"var(--text-muted)",cursor:s&&!b?"not-allowed":"pointer",fontSize:12,lineHeight:1,opacity:s&&!b?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{ev||s&&!b||(e.currentTarget.style.background=b?"rgba(239,68,68,0.16)":ex?"rgba(239,68,68,0.12)":"var(--bg-hover)",e.currentTarget.style.color=b||ex?"#ef4444":"var(--text)")},onMouseLeave:e=>{ev||(e.currentTarget.style.background=b?"rgba(239,68,68,0.08)":ex?"rgba(239,68,68,0.06)":"none",e.currentTarget.style.color=b||ex?"#ef4444":"var(--text-muted)")},title:b?em("chat.stopCompaction"):ex?`${em("chat.compactContext")} (${em("chat.contextHighWarning")})`:em("chat.compactContext"),"aria-label":b?em("chat.stopCompaction"):em("chat.compactContext"),children:b?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block",flexShrink:0},children:(0,r.jsx)("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2",fill:"currentColor"})}),(!ev||eE)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap",lineHeight:1},children:em("chat.compacting")})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block",flexShrink:0},children:[(0,r.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,r.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,r.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,r.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]}),(!ev||eE)&&(0,r.jsx)("span",{style:{whiteSpace:"nowrap",lineHeight:1},children:em("chat.compact")})]})})})),void 0!==U&&(0,r.jsx)("button",{onClick:()=>{ev&&eL(!1),U?.()},title:O?em("chat.disableSound"):em("chat.enableSound"),"aria-label":O?em("chat.disableSound"):em("chat.enableSound"),style:{display:"flex",alignItems:"center",justifyContent:"center",height:ev?32:28,padding:"0 4px",background:"none",border:"none",borderRadius:4,color:O?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:O?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{ev||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1")},onMouseLeave:e=>{ev||(e.currentTarget.style.background="none",e.currentTarget.style.color=O?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=O?"1":"0.55")},children:O?(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block",flexShrink:0},children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,r.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block",flexShrink:0},children:[(0,r.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,r.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,r.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})]})});var rx=n(88576),rm=n.n(rx);function ry({items:e,activeEntryId:t,onJumpToEntry:n,label:o,left:l,top:s,maxHeight:a=360,width:d=310}){var c,u;let h,p,f,{t:g}=(0,x.s)(),m=(0,i.useRef)(null),y=(0,i.useRef)(null),[v,b]=(0,i.useState)(!1),[w,k]=(0,i.useState)(0),[j,S]=(0,i.useState)(0),[C,I]=(0,i.useState)(null),M=(0,i.useRef)(0),T=(0,i.useRef)(null),E=(0,i.useRef)(!1),L=(0,i.useRef)(null),R=(0,i.useRef)(null),N=(0,i.useRef)(null),$=(0,i.useId)(),W=e.findIndex(e=>e.entryId===t),z={start:h=Math.max(0,Math.min(W-Math.floor(7.5),(c=e.length)-15)),end:Math.min(c,h+15)},P=Math.min(28*e.length,a-28*(C?.state==="error")),{start:A,end:D}=(u=e.length,p=Math.min(P,28*u),{start:Math.max(0,Math.floor((f=Math.max(0,Math.min(w,28*u-p)))/28)-1),end:Math.min(u,Math.ceil((f+p)/28)+1)});(0,i.useEffect)(()=>()=>{M.current++,L.current&&clearTimeout(L.current),R.current&&clearTimeout(R.current),N.current&&clearTimeout(N.current)},[]);let F=(0,i.useCallback)(()=>{L.current&&clearTimeout(L.current),R.current&&clearTimeout(R.current),N.current&&clearTimeout(N.current),T.current=null,b(!1)},[]),B=(0,i.useCallback)(()=>{R.current&&(clearTimeout(R.current),R.current=null),v||(L.current=setTimeout(()=>{b(!0)},100))},[v]),H=(0,i.useCallback)(e=>{L.current&&(clearTimeout(L.current),L.current=null);let t=document.activeElement;t instanceof HTMLElement&&e.currentTarget.contains(t)&&t.matches(":focus-visible")||(R.current=setTimeout(()=>{F()},150))},[F]);async function O(e){let t=++M.current;I({entryId:e,state:"loading"});try{await n(e),M.current===t&&(I(null),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{F()},160))}catch(n){if(M.current!==t)return;if(n&&"object"==typeof n&&"name"in n&&"AbortError"===n.name)return void I(null);I({entryId:e,state:"error",message:n instanceof Error?n.message:String(n)})}}function U(t){let n=Math.max(0,Math.min(e.length-1,t));T.current=n,S(n);let r=y.current;if(r){var i;let e;i=r.scrollTop,r.scrollTop=(e=28*n)<i?e:e+28>i+P?e+28-P:i,k(r.scrollTop);let t=r.querySelector(`[data-outline-index="${n}"]`);t&&(T.current=null,t.focus({preventScroll:!0}))}b(!0)}return((0,i.useLayoutEffect)(()=>{if(!v){E.current=!1;return}let e=y.current;if(e){if(!E.current){let t=Math.max(0,W);e.scrollTop=Math.max(0,(t+.5)*28-P/2),S(t),E.current=!0}k(e.scrollTop)}},[v,W,P]),(0,i.useLayoutEffect)(()=>{if(!v||null===T.current)return;let e=y.current?.querySelector(`[data-outline-index="${T.current}"]`);e&&(T.current=null,e.focus({preventScroll:!0}))}),e.length)?(0,r.jsxs)("div",{className:rm().minimap,style:{left:l,top:s},onMouseEnter:B,onMouseLeave:H,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||F()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),F(),m.current?.focus({preventScroll:!0}))},children:[(0,r.jsx)("button",{ref:m,type:"button",className:rm().trigger,style:{height:Math.min(a,Math.max(20,(z.end-z.start)*8+6))},"aria-label":o,"aria-expanded":v,"aria-controls":v?$:void 0,"aria-busy":C?.state==="loading"||void 0,onClick:e=>{0===e.detail?U(Math.max(0,W)):(L.current&&clearTimeout(L.current),R.current&&clearTimeout(R.current),b(e=>!e))},onKeyDown:e=>{("ArrowDown"===e.key||"ArrowUp"===e.key)&&(e.preventDefault(),U(Math.max(0,W)))},children:e.slice(z.start,z.end).map((e,n)=>(0,r.jsx)("span",{className:rm().marker,"data-marker-index":z.start+n,"data-active":t===e.entryId?"true":void 0,"aria-hidden":"true"},e.entryId))}),v&&(0,r.jsx)("div",{className:rm().panel,style:{width:d},children:(0,r.jsxs)("nav",{id:$,className:rm().menu,"aria-label":o,children:[(0,r.jsx)("div",{ref:y,className:rm().list,style:{height:P},onScroll:e=>k(e.currentTarget.scrollTop),children:(0,r.jsx)("div",{className:rm().track,style:{height:28*e.length},children:e.slice(A,D).map((n,i)=>{let o=A+i;return(0,r.jsx)("button",{type:"button",className:rm().row,style:{top:28*o},"data-outline-index":o,"aria-current":t===n.entryId?"location":void 0,"aria-label":n.preview,tabIndex:o===(j>=A&&j<D?j:A)?0:-1,onFocus:()=>S(o),onKeyDown:t=>{let n={ArrowDown:o+1,ArrowUp:o-1,Home:0,End:e.length-1,PageDown:o+Math.max(1,Math.floor(P/28)),PageUp:o-Math.max(1,Math.floor(P/28))};t.key in n&&(t.preventDefault(),U(n[t.key]))},onClick:()=>{O(n.entryId)},children:(0,r.jsx)("span",{className:rm().rowText,children:n.preview})},n.entryId)})})}),C?.state==="error"&&(0,r.jsxs)("div",{className:rm().status,role:"status","aria-live":"polite",children:[(0,r.jsx)("span",{children:`${g("chatMinimap.jumpFailed")||"跳转失败:"}${C.message||"请重试"}`}),(0,r.jsx)("button",{type:"button",onClick:()=>{O(C.entryId)},children:g("chatMinimap.retry")||"重试"})]})]})})]}):null}function rv({items:e,scrollContainer:t,contentContainer:n,loadedEntryIds:o,onJumpToEntry:l,label:s}){let[a,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(null),h=(0,i.useMemo)(()=>(function(e,t){let n=new Set(e),r=new Map,i=t.find(e=>n.has(e)),o=void 0===i?e.length:e.indexOf(i),l=e[o-1]??null;for(let e of t)n.has(e)&&(l=e),null!==l&&r.set(e,l);for(let t of e)r.set(t,t);return r})(e.map(e=>e.entryId),o),[e,o]);return((0,i.useEffect)(()=>{let r=t.current,i=n.current;if(!r||!i)return;let o=0,l=!0,s=[],a=[],c=new ResizeObserver(()=>f()),p=()=>{o||(o=requestAnimationFrame(g))},f=()=>{l=!0,p()};function g(){var t,n,p;if(o=0,l){l=!1;let t=r.getBoundingClientRect(),n=Math.max(0,t.top),o=Math.min(window.innerHeight,t.bottom),d=Math.min(window.innerWidth,t.right),p=Math.max(0,Math.min(360,o-n-16)),f={left:d-26,top:(n+o-Math.min(p,Math.max(20,8*Math.min(15,e.length)+6)))/2,maxHeight:p,width:Math.max(0,Math.min(310,d-Math.max(0,t.left)-36))};u(e=>e&&e.left===f.left&&e.top===f.top&&e.maxHeight===p&&e.width===f.width?e:f);let g=Array.from(i.children).filter(e=>e instanceof HTMLElement&&e.hasAttribute("data-entry-id"));s=g.flatMap(e=>{let n=h.get(e.dataset.entryId);return n?[{userId:n,top:e.getBoundingClientRect().top-t.top-r.clientTop+r.scrollTop}]:[]}).sort((e,t)=>e.top-t.top);let x=new Set(g),m=new Set(a);for(let e of a)x.has(e)||c.unobserve(e);for(let e of g)m.has(e)||c.observe(e);a=g}d(function(e,t){if(!e.length)return null;let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i].top<=t?n=i+1:r=i}return e[Math.max(0,n-1)].userId}(s,(t=r.scrollTop,n=r.clientHeight,(p=r.scrollHeight)-n>0&&t+n>=p-8?1/0:t+48)))}c.observe(r),c.observe(i);let x=new MutationObserver(f);x.observe(i,{subtree:!0,childList:!0,characterData:!0,attributes:!0}),r.addEventListener("scroll",p,{passive:!0}),window.addEventListener("resize",f);let m=e=>{e.target!==r&&e.target instanceof Node&&e.target.contains(r)&&f()};return window.addEventListener("scroll",m,!0),p(),()=>{cancelAnimationFrame(o),c.disconnect(),x.disconnect(),r.removeEventListener("scroll",p),window.removeEventListener("resize",f),window.removeEventListener("scroll",m,!0)}},[e.length,h,t,n]),!c||c.maxHeight<52||c.width<80)?null:(0,m.createPortal)((0,r.jsx)(ry,{items:e,activeEntryId:a,onJumpToEntry:l,label:s,...c}),document.body)}function rb({sessionId:e,leafId:t,outlineRevision:n,...o}){let{t:l}=(0,x.s)(),s=JSON.stringify([e,t]),[a,d]=(0,i.useState)(null);return((0,i.useEffect)(()=>{if(!e)return;let n=new AbortController,r=new URLSearchParams;t&&r.set("leafId",t);let i=r.toString();return fetch(`/api/sessions/${encodeURIComponent(e)}/outline${i?`?${i}`:""}`,{signal:n.signal}).then(async e=>e.ok?e.json():{items:[]}).then(e=>{n.signal.aborted||d({key:s,items:e.items??[]})}).catch(()=>{n.signal.aborted||d({key:s,items:[]})}),()=>n.abort()},[e,t,n,s]),e&&a?.key===s&&a.items.length)?(0,r.jsx)(rv,{...o,items:a.items,label:l("chatMinimap.userOutline")},s):null}var rw=n(42790);function rk({text:e}){let t=(0,i.useMemo)(()=>new rw.v().ansi_to_html(e),[e]);return(0,r.jsx)("span",{dangerouslySetInnerHTML:{__html:t}})}let rj="/icons/icon-192.png";function rS(e=document){return"visible"!==e.visibilityState||!e.hasFocus()}function rC(e){let t;if("u"<typeof Notification)return()=>{};e(Notification.permission);let n="u"<typeof navigator?void 0:navigator.permissions;if(!n?.query)return()=>{};let r=!1;return n.query({name:"notifications"}).then(n=>{r||(t=n,n.onchange=()=>e(Notification.permission))}).catch(()=>{}),()=>{r=!0,t&&(t.onchange=null)}}function rI(e){switch(e.method){case"select":case"confirm":case"input":case"editor":return!0;case"custom":return!0!==e.closed;default:return!1}}async function rM(e,t={createWindowNotification:(e,t)=>new Notification(e,t),getServiceWorkerRegistration:"serviceWorker"in navigator?()=>navigator.serviceWorker.getRegistration():null}){let n={body:e.body,icon:rj,badge:rj,...e.tag?{tag:e.tag,renotify:!0}:{}};if(t.getServiceWorkerRegistration)try{let r=await t.getServiceWorkerRegistration();if(r)return await r.showNotification(e.title,{...n,data:{url:e.sessionUrl}}),"service-worker"}catch{}try{let r=t.createWindowNotification(e.title,n);return r.onclick=()=>{r.close(),e.onClick()},"window"}catch{return null}}function rT(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function rE(e,t={}){if("assistant"!==e.role)return e;let n=e.content;if(!Array.isArray(n))return e;let r=n.map(e=>(function(e,t={}){if(!rT(e)||"toolCall"!==e.type)return null;let n={type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input},r=t.includeStreamingRawInput?function(e){if("string"==typeof e.rawInput)return e.rawInput;if("string"==typeof e.partialJson)return e.partialJson;if("string"==typeof e.partialArgs)return e.partialArgs;let t=rT(e.customInput)?e.customInput:null,n=t&&"string"==typeof t.property?t.property:null,r=rT(e.arguments)?e.arguments:null;return n&&r&&"string"==typeof r[n]?r[n]:void 0}(e):void 0;return void 0===r?n:{...n,rawInput:r}})(e,t)??e);return{...e,content:r}}class rL extends Error{constructor(e,t,n,r){super(e),this.status=t,this.code=n,this.accepted=r,this.name="AgentCommandError"}}function rR(e){return e instanceof rL&&"prompt_rejected"===e.code&&!1===e.accepted}async function rN(e,t){let n=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok||r.error)throw new rL(r.error??`HTTP ${n.status}`,n.status,r.code,r.accepted);return r.data}var r$=n(14755);let rW="pi-tool-preset";function rz(){try{return window.localStorage}catch{return null}}function rP(e,t){t&&(e.tokens.input+=t.input??0,e.tokens.output+=t.output??0,e.tokens.cacheRead+=t.cacheRead??0,e.tokens.cacheWrite+=t.cacheWrite??0,e.cost+=t.cost?.total??0)}function rA(e){let t={userMessages:0,assistantMessages:0,toolCalls:0,toolResults:0,totalMessages:0,tokens:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0},cost:0};for(let n of e)"custom"!==n.role&&(t.totalMessages+=1,"user"===n.role?t.userMessages+=1:"toolResult"===n.role?(t.toolResults+=1,rP(t,n.usage)):"assistant"===n.role&&(t.assistantMessages+=1,Array.isArray(n.content)&&(t.toolCalls+=n.content.filter(e=>"toolCall"===e.type).length),rP(t,n.usage)));return t.tokens.total=t.tokens.input+t.tokens.output+t.tokens.cacheRead+t.tokens.cacheWrite,t}function rD(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 rF(e){let t,n=e.content;return"string"==typeof n?JSON.stringify({text:n,images:[]}):Array.isArray(n)?JSON.stringify({text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.map(e=>e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text?e.text:"").filter(Boolean).join("\n"):"",images:n.map(rD).filter(Boolean)}):JSON.stringify({text:"",images:[]})}class rB extends Error{constructor(e,t){super(t??("ready_timeout"===e?"Timed out starting the agent session. Please try again.":"Failed to connect to the agent event stream. Please try again.")),this.status=e,this.name="AgentEventConnectionError"}}class rH{constructor(e){this.options=e,this.current=null,this.retry=null,this.retryGeneration=0}close(){this.stopRetrying(),this.current&&this.discard(this.current,new rB("closed"))}maintain(e){if(!this.options.shouldMaintain(e))return;let t=this.retryGeneration;this.ensureConnected(e).catch(n=>{t===this.retryGeneration&&(n instanceof rB?"startup_error"===n.status?this.stopRetrying():this.scheduleRetry(e):this.options.onUnexpectedError?.(n))})}async ensureConnected(e){for(;;){let t=this.current;if(t&&t.sessionId===e){if(t.attempt.ready&&1===t.source.readyState)return}else t=this.open(e);if(await t.attempt.promise,this.current!==t){if(this.current?.sessionId===e)continue;throw new rB("closed")}if(1===t.source.readyState)return;this.discard(t,new rB("closed"))}}open(e){let t,n,r;this.current&&this.discard(this.current,new rB("closed"));try{t=this.options.createSource(e)}catch(e){throw new rB("closed",e instanceof Error?e.message:String(e))}let i=!1,o=new Promise((e,t)=>{n=e,r=t}),l=setTimeout(()=>{this.fail(a,new rB("ready_timeout"))},this.options.readinessTimeoutMs),s={promise:o,ready:!1,succeed(){i||(i=!0,clearTimeout(l),n())},fail(e){i||(i=!0,clearTimeout(l),r(e))}},a={sessionId:e,source:t,attempt:s};return this.current=a,t.onmessage=e=>{let t;if(this.current===a){try{t=JSON.parse(e.data)}catch{return}if("connected"===t.type)s.ready=!0,s.succeed(),this.stopRetrying();else if("startup_error"===t.type){let e="string"==typeof t.errorMessage?t.errorMessage:void 0;this.fail(a,new rB("startup_error",e));return}this.options.onEvent(t)}},t.onerror=()=>{this.fail(a,new rB("closed"))},a}fail(e,t){this.current===e&&(this.discard(e,t),"startup_error"===t.status?this.stopRetrying():this.scheduleRetry(e.sessionId))}discard(e,t){e.attempt.fail(t),e.source.close(),this.current===e&&(this.current=null)}scheduleRetry(e){if(!this.options.shouldMaintain(e)||this.retry?.sessionId===e)return;this.clearRetry();let t=setTimeout(()=>{this.retry?.timer===t&&(this.retry=null,this.maintain(e))},this.options.reconnectDelayMs);this.retry={sessionId:e,timer:t}}stopRetrying(){this.retryGeneration+=1,this.clearRetry()}clearRetry(){this.retry&&clearTimeout(this.retry.timer),this.retry=null}}let rO={isStreaming:!1,streamingMessage:null};function rU(e,t,n){let r=e.streamingMessage;if(!r||!Number.isInteger(t)||t<0)return e;let i=[...r.content],o=n(i[t]);return o?(i[t]=o,{isStreaming:!0,streamingMessage:{...r,content:i}}):e}function r_(e,t){switch(t.type){case"text_start":return rU(e,t.contentIndex,e=>e?.type==="text"?e:{type:"text",text:""});case"text_delta":return rU(e,t.contentIndex,e=>e?.type==="text"?{...e,text:e.text+t.delta}:null);case"text_end":return rU(e,t.contentIndex,e=>({...e?.type==="text"?e:{},type:"text",text:t.content}));case"thinking_start":{let n=Date.now(),r=e.streamingMessage;if(!r)return e;let i=[...r.content];for(let e=0;e<i.length;e++){let r=i[e];e!==t.contentIndex&&r?.type==="thinking"&&"number"!=typeof r.endedAt&&(i[e]={...r,endedAt:n})}let o=i[t.contentIndex];return i[t.contentIndex]=o?.type==="thinking"?{...o,startedAt:o.startedAt??n}:{type:"thinking",thinking:"",startedAt:n},{isStreaming:!0,streamingMessage:{...r,content:i}}}case"thinking_delta":return rU(e,t.contentIndex,e=>e?.type==="thinking"?{...e,thinking:e.thinking+t.delta,startedAt:e.startedAt??Date.now()}:null);case"thinking_end":return rU(e,t.contentIndex,e=>({...e?.type==="thinking"?e:{startedAt:Date.now()},type:"thinking",thinking:t.content,endedAt:Date.now()}));case"toolcall_start":return rU(e,t.contentIndex,e=>e?.type==="toolCall"?{...e,toolCallId:t.id??e.toolCallId,toolName:t.toolName??e.toolName,rawInput:e.rawInput??""}:"string"!=typeof t.toolName?null:{type:"toolCall",toolCallId:t.id??"",toolName:t.toolName,input:{},rawInput:""});case"toolcall_delta":return rU(e,t.contentIndex,e=>e?.type==="toolCall"?{...e,toolCallId:t.id||e.toolCallId,toolName:t.toolName||e.toolName,rawInput:(e.rawInput??"")+t.delta}:null);case"toolcall_end":return rU(e,t.contentIndex,()=>({type:"toolCall",toolCallId:t.toolCall.id,toolName:t.toolCall.name,input:t.toolCall.arguments}));default:return e}}function rq(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"resume":return{...e,isStreaming:!0};case"snapshot":{let n=rE(t.message,{includeStreamingRawInput:!0});if("assistant"!==n.role)return e;let r="number"==typeof n.timestamp?n.timestamp:Date.now(),i=e.streamingMessage,o=n.content.map((e,t)=>{if("thinking"!==e.type)return e;let n=i?.content[t],o=e.startedAt??(n?.type==="thinking"?n.startedAt:void 0)??r,l=e.endedAt??(n?.type==="thinking"?n.endedAt:void 0);return e.startedAt===o&&e.endedAt===l?e:{...e,startedAt:o,..."number"==typeof l?{endedAt:l}:{}}});return{isStreaming:!0,streamingMessage:{...n,timestamp:r,content:o}}}case"delta":return r_(e,t.event);case"deltas":return t.events.reduce(r_,e);case"end":return rO;default:return e}}class rK{begin(e){this.inFlight.add(e)}cancel(e){this.cancelled.add(e)}markDispatched(e){this.dispatched.add(e)}isCancelled(e){return this.cancelled.has(e)}wasDispatched(e){return this.dispatched.has(e)}isInFlight(e){return this.inFlight.has(e)}shouldAbandonUnsent(e){return this.isCancelled(e)&&!this.wasDispatched(e)}forget(e){this.cancelled.delete(e),this.dispatched.delete(e),this.inFlight.delete(e)}constructor(){this.cancelled=new Set,this.dispatched=new Set,this.inFlight=new Set}}function rV(e,t,n,r){return e===t&&"string"==typeof n&&n.length>0&&n===r}async function rJ(e){let{gate:t,runId:n}=e;t.begin(n);let r=()=>!(!t.isCancelled(n)||t.wasDispatched(n))&&(e.abandonUnsent(),!0),i=null,o=!1;try{if(r()||(i=await e.prepare(),r()))return{status:"abandoned"};if(!i)throw Error("No active session for the prompt");if(o=!0,t.markDispatched(n),e.onDispatched?.(),await e.send(i),!t.isCancelled(n))return{status:"sent",sessionId:i};if(e.promptPending()&&rV(n,e.currentRunId(),i,e.currentSessionId()))return await e.abort(i),{status:"aborted",sessionId:i};return{status:"stale"}}catch(r){if(!t.isCancelled(n))return{status:"failed",sessionId:i,error:r,requestStarted:o};if(!o)return e.abandonUnsent(),{status:"abandoned"};if(e.promptPending()&&rV(n,e.currentRunId(),i,e.currentSessionId()))return{status:"cancelled_after_dispatch",sessionId:i};return{status:"stale"}}finally{t.forget(n)}}async function rY(e){let t=null,n=!1;try{if(t=await e.prepare(),e.abortRequested())return e.restoreUnsent(),{status:"restored_unsent"};if(!t)throw Error("Unable to create a session for the shell command");return n=!0,await e.send(t),await e.loadResults(t),e.abortRequested()?{status:"cancelled_after_dispatch",sessionId:t}:{status:"completed",sessionId:t}}catch(r){if(!e.abortRequested())throw r;if(!n)return e.restoreUnsent(),{status:"restored_unsent"};if(t)try{await e.loadResults(t)}catch{}return{status:"cancelled_after_dispatch",sessionId:t}}}function rZ(e){return(e??[]).map(e=>"string"==typeof e?{text:e,images:[]}:{text:"string"==typeof e.text?e.text:"",images:Array.isArray(e.images)?e.images.flatMap(e=>{let t=e&&"object"==typeof e&&"string"==typeof e.data&&0!==e.data.length&&"string"==typeof e.mimeType&&e.mimeType.startsWith("image/")?{data:e.data,mimeType:e.mimeType}:null;return t?[t]:[]}):[]})}let rG=new Map,rX=new Map;function rQ(e){return"string"==typeof e?e:e?.text??""}function r0(e){return{steering:(e?.steering??[]).map(rQ),followUp:(e?.followUp??[]).map(rQ)}}function r1(e,t){return e===t||null!==e&&null!==t&&e.tokens===t.tokens&&e.percent===t.percent&&e.contextWindow===t.contextWindow?e:t}let r2=[2e3,5e3,1e4];function r4(e){return new Promise(t=>setTimeout(t,e))}function r8(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,n)=>n===t?{...e,exiting:!0}:e)}function r5(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:r8(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:r8(e.visible)};case"remove":return function(e,t){let n=e,r=t;for(;r.length>0&&n.length<5;){let[e,...t]=r;n=[...n,e],r=t}return r.length>0&&!n.some(e=>e.exiting)&&(n=r8(n)),{visible:n,pending:r}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function r6(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 r3(e){if(!e?.defaultModel)return null;let t=e.modelList?.find(t=>t.id===e.defaultModel?.modelId&&t.provider===e.defaultModel?.provider);return t?{provider:t.provider,modelId:t.id}:null}function r7(e,t){let n=e[0];for(let r of e){if(r.top>t)break;n=r}return n?{anchorEntryId:n.entryId,anchorOffset:n.top-t}:null}function r9({label:e}){return(0,r.jsx)("div",{role:"status","aria-label":e,className:"flex h-[30px] items-center px-2",style:{marginBottom:10},children:(0,r.jsx)(_,{size:14})})}function ie({cwd:e,onChange:t}){let{t:n}=(0,x.s)(),[o,l]=(0,i.useState)(!1),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(null);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",title:n("chat.changeWorkingDirectory"),"aria-label":`${n("chat.changeWorkingDirectory")}: ${e}`,onClick:()=>l(!0),onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},style:{marginTop:10,maxWidth:"100%",border:"none",background:"none",color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.4,padding:0,cursor:"pointer"},children:(0,r.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"center"},children:(0,r.jsx)("span",{style:{unicodeBidi:"plaintext"},children:e})})}),o&&(0,r.jsx)(w,{initialPath:e,busy:s,error:d,onCancel:()=>{l(!1),c(null)},onSelect:e=>{a(!0),c(null),t(e).then(()=>l(!1),e=>c(e instanceof Error?e.message:String(e))).finally(()=>a(!1))}})]})}function it({label:e}){let[t,n]=(0,i.useState)(null);if((0,i.useEffect)(()=>{let e=new AbortController;return fetch("/api/app-update",{signal:e.signal}).then(async e=>e.ok?e.json():null).then(e=>{e?.updateAvailable&&e.latestVersion&&e.releaseUrl&&n(e)}).catch(()=>{}),()=>e.abort()},[]),!t)return null;let o=e(t.latestVersion);return(0,r.jsxs)("a",{href:t.releaseUrl,target:"_blank",rel:"noopener noreferrer",title:o,"aria-label":o,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},style:{display:"inline-flex",alignItems:"center",alignSelf:"center",gap:3,minHeight:32,minWidth:0,padding:"0 4px",background:"transparent",borderRadius:4,color:"var(--accent)",fontSize:12,fontWeight:600,lineHeight:1.2,textDecoration:"none",transition:"background 0.12s",whiteSpace:"nowrap"},children:[(0,r.jsxs)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:["v",t.latestVersion]}),(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M7 17 17 7"}),(0,r.jsx)("path",{d:"M7 7h10v10"})]})]})}function ir(e,t,n){for(let i=n-1;i>t;i--){var r;if("assistant"===(r=e[i]).role&&eA(r).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return i}for(let r=n-1;r>t;r--)if(e[r]?.role==="assistant")return r;return -1}function ii(e,t,n={}){let r={...e,content:t};return n.omitUsage&&(r.usage=void 0),n.omitError&&("error"===r.stopReason&&(r.stopReason="stop"),r.errorMessage=void 0),r}function io(e,t={}){let n=eA(e,t),r=e.content.indexOf(n.answerBlocks[0]),i=e.content.slice(0,r<0?void 0:r),o=n.answerBlocks.length>0||eP(e,t)?ii(e,n.answerBlocks):null;return{processMessage:ez({...e,content:i},t).length>0?ii(e,i,{omitUsage:!!o&&!t.isStreaming,omitError:!!o}):null,answerMessage:o}}function il(e){return e?.content.at(-1)}function is(e,t,n,r,i=!1){if(!e)return!1;if(r?.kind==="running_tools")return!0;let o=il(n);return!!t&&(o?.type==="thinking"||o?.type==="toolCall")||!i}function ia(e,t,n){if(!e)return null;let r=eh(e,t);return"edit"===r?n("image.edit"):"generate"===r?n("image.generate"):null}function id(e,t,n){if(t?.kind==="running_tools"){let e=t.tools[t.tools.length-1]?.name??null;return ia(e,void 0,n)??e}let r=il(e);return r?.type==="thinking"?n("chat.thinking"):r?.type==="toolCall"?ia(r.toolName,r.input,n)??r.toolName??null:null}function ic(e,t,n,r){return t?(e&&(n.current=e),n.current??r):(n.current=null,null)}function iu(e,t){if("number"==typeof e&&"number"==typeof t&&Number.isFinite(e)&&Number.isFinite(t)&&!(t<=e))return Math.max(1,Math.round((t-e)/1e3))}function ih(e,t){return e<60?t("chat.decodeSeconds",{seconds:e}):t("chat.decodeMinutes",{minutes:Math.floor(e/60),seconds:e%60})}function ip({startTime:e,t}){let[n,o]=(0,i.useState)(()=>Math.max(0,Math.round((Date.now()-e)/1e3)));return(0,i.useEffect)(()=>{let t=setInterval(()=>{o(Math.max(0,Math.round((Date.now()-e)/1e3)))},500);return()=>clearInterval(t)},[e]),(0,r.jsx)("span",{style:{fontSize:11.5,color:"var(--accent)",fontVariantNumeric:"tabular-nums",flexShrink:0},children:ih(n,t)})}function ig({messageCount:e,toolCallCount:t,durationSeconds:n,startTime:o,defaultExpanded:l=!1,reveal:s=!1,isMobile:a=!1,activeStepSummary:d=null,isStreaming:c=!1,children:u,t:h}){let p,[f,g]=(0,i.useState)(l),x=(0,i.useRef)(null),m=(0,i.useRef)(!1),y=(0,i.useRef)(!1);(0,i.useLayoutEffect)(()=>{y.current||g(l)},[l]);let v=f||s,b=t>0?t:e,w=h(1===b?"chat.step":"chat.steps");if(void 0!==n&&n>0){let e=ih(n,h);p=t>0?h("chat.workedForSteps",{duration:e,count:b,steps:w}):h("chat.workedFor",{duration:e})}else p=`${b} ${w}`;return(0,i.useLayoutEffect)(()=>{if(!v){m.current=!1;return}let e=x.current;!e||m.current||e.scrollHeight<=e.clientHeight+1||(e.scrollTop=e.scrollHeight)},[v,e,t]),(0,r.jsxs)("div",{style:{marginBottom:8},children:[(0,r.jsxs)("button",{type:"button","aria-expanded":v,onClick:()=>{y.current=!0,g(e=>!e)},className:"process-details-summary",style:{display:"inline-flex",alignItems:"center",gap:5,maxWidth:"100%",minHeight:24,padding:"2px 0",border:"none",background:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11.5,fontFamily:"var(--font-ui)",fontWeight:400,textAlign:"left",transition:"color 0.12s ease"},title:h(v?"chat.collapseProcess":"chat.expandProcess"),children:[c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(_,{size:12}),o&&(0,r.jsx)(ip,{startTime:o,t:h}),(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5,minWidth:0,fontSize:11.5,color:"var(--accent)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[o&&(0,r.jsx)("span",{style:{opacity:.5,color:"var(--text-dim)"},children:"\xb7"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d||h("chat.thinking")})]})]}):(0,r.jsx)("span",{"data-summary-label":"",style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:400,color:"inherit",lineHeight:1.35,transition:"color 0.12s ease"},children:p}),(0,r.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.45,display:"block",transform:v?"rotate(90deg)":"none",transition:"transform 0.15s ease"},"aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]}),v&&(0,r.jsx)("div",{ref:x,onScroll:()=>{let e=x.current;e&&(m.current=!(e.scrollTop+e.clientHeight>=e.scrollHeight-20))},className:"process-details-list",style:{display:"flex",flexDirection:"column",gap:1,padding:"2px 0 4px 0",maxHeight:a?220:280,overflowY:"auto",overflowX:"hidden",overscrollBehavior:"contain"},children:u})]})}function ix({session:e,searchTarget:t,onSearchTargetHandled:o,initialScrollPosition:l,onScrollPositionChange:s,sessionRunning:a,newSessionCwd:d,newSessionDraftKey:c,onDraftChange:u,onKeepTabOpen:h,onNewSessionCwdChange:p,draftPersistenceWarning:f=!1,onAgentEnd:g,onAttentionNeeded:y,onSessionCreated:v,onSessionForked:b,modelsRefreshKey:w,chatInputRef:k,isFocusedPane:j=!1,isVisiblePane:S=j,onBranchDataChange:C,onSystemPromptChange:I,onSystemToolsChange:M,onSystemInfoLoaderChange:E,onSessionStatsChange:L,onSessionStatsPanelOpen:R,onContextUsageChange:$,onOpenFile:W,onOpenSession:z,onAskInNewChat:P,quoteSelectionEnabled:A=!1,initialPrompt:D,onInitialPromptConsumed:F,soundEnabled:B=!0,onSoundToggle:H,playDoneSound:O=()=>{},unlockAudio:U}){var _;let q,{t:K}=(0,x.s)(),V=nN(),J=e?.relation?.kind!=="subagent",Y=(0,i.useRef)(O);Y.current=O;let Z=(0,i.useRef)(B);Z.current=B;let G=(0,i.useRef)(e);G.current=e;let X=(0,i.useRef)(null),Q=(0,i.useCallback)(e=>{let t=X.current;X.current=e,k&&(e?k.current=e:k.current===t&&(k.current=null))},[k]),ee=(0,i.useRef)(null),et=(0,i.useCallback)(()=>{J&&Z.current&&Y.current(),g?.(G.current)},[J,g]),en=(0,i.useCallback)(e=>{y?.(e,G.current)},[y]),er=(0,i.useCallback)(e=>{b?.(e,G.current?.id??null)},[b]),eo=(0,i.useCallback)(e=>{W?.(e,G.current?.id??null)},[W]),el=(0,i.useCallback)(()=>{let e=G.current?.id;e&&h?.(e)},[h]),es=(0,i.useCallback)(e=>{X.current?.replaceMessage(e)},[]),ea=(0,i.useRef)(t?null:l??null),[ed,ec]=(0,i.useState)(()=>{let e=ea.current;return e&&!e.atBottom?e:null}),[eh,ep]=(0,i.useState)(!1),{data:ef,loading:eg,error:ex,messages:ev,activeToolResults:eb,entryIds:ek,historyCursor:ej,hasEarlierMessages:eS,streamState:eC,agentRunning:eI,directImageRunning:eM,bashRunning:eT,pendingBash:eE,modelNames:eL,modelList:eW,modelError:eA,modelScopeWarnings:eF,modelThinkingLevels:eB,modelThinkingLevelMaps:eH,toolPreset:eU,thinkingLevel:eQ,retryInfo:e0,contextUsage:e1,forkingEntryId:e2,isCompacting:e4,compactError:e8,compactResult:e5,displayModel:e6,modelSwitching:e3,sessionStats:e7,slashCommands:e9,slashCommandsLoading:te,queuedMessages:tt,notices:tn,extensionDialog:tr,extensionCustomUi:ti,respondToExtensionUi:to,sendExtensionCustomInput:tl,addNotice:ts,setNoticePaused:ta,isAutoModelSelection:td,agentPhase:tc,isNew:tu,sessionIdRef:th,scrollContainerRef:tp,handleSend:tf,handleDirectImageGeneration:tg,abortDirectImageGeneration:tx,handleAbort:tm,handleFork:ty,handleNavigate:tv,handleModelChange:tb,handleCompact:tw,handleSteer:tk,handleFollowUp:tj,handlePromptWithStreamingBehavior:tS,handleAbortCompaction:tC,handleRecallQueue:tI,handleBuiltinSlashCommand:tM,handleToolPresetChange:tT,handleThinkingLevelChange:tE,loadSlashCommands:tL,loadContext:tR,activeLeafId:tN,scrollToBottom:t$,scrollToMessage:tW}=function(e){let{session:t,sessionRunning:r,newSessionCwd:o,newSessionDraftKey:l,onAgentEnd:s,onAttentionNeeded:a,onSessionCreated:d,onSessionForked:c,modelsRefreshKey:u,onBranchDataChange:h,onSystemPromptChange:p,onSystemToolsChange:f,onSystemInfoLoaderChange:g,onSessionStatsPanelOpen:x}=e,m=null===t&&null!==o,y=o??t?.cwd??"",v=y?`/api/models?cwd=${encodeURIComponent(y)}`:"/api/models",b=rG.get(v)?.data,w=m?r3(b):null,k=w?b?.thinkingLevelPins?.[`${w.provider}/${w.modelId}`]:void 0,[j,S]=(0,i.useState)(null),[C,I]=(0,i.useState)(!m),[M,T]=(0,i.useState)(null),[E,L]=(0,i.useState)(null),[R,N]=(0,i.useState)([]),[$,W]=(0,i.useState)(new Map),[z,P]=(0,i.useState)([]),[A,D]=(0,i.useState)(null),[F,B]=(0,i.useState)(!1),H=(0,i.useRef)({messages:R,entryIds:z,oldestEntryId:A,hasMore:F});H.current={messages:R,entryIds:z,oldestEntryId:A,hasMore:F};let[O,U]=(0,i.useReducer)(rq,rO),_=(0,i.useRef)(O);_.current=O;let[q,K]=(0,i.useState)(!1),[V,J]=(0,i.useState)(!1),[Y,Z]=(0,i.useState)(null),[G,X]=(0,i.useState)(!1),Q=(0,i.useRef)(!1),ee=(0,i.useRef)(null),et=(0,i.useRef)(!1),[en,er]=(0,i.useState)(()=>b?.models??{}),[ei,eo]=(0,i.useState)(()=>b?.modelList??[]),[el,es]=(0,i.useState)(()=>b?.modelError??null),[ea,ed]=(0,i.useState)(()=>b?.modelScopeWarnings??[]),[ec,eu]=(0,i.useState)(()=>b?.thinkingLevels??{}),[eh,ep]=(0,i.useState)(()=>b?.thinkingLevelMaps??{}),[ef,eg]=(0,i.useState)(null),[ex,em]=(0,i.useState)(w),[ey,ev]=(0,i.useState)("default"),[eb,ew]=(0,i.useState)(k??"auto"),[ek,ej]=(0,i.useState)(null),[eS,eC]=(0,i.useState)(null),[eI,eM]=(0,i.useState)(null),[eT,eE]=(0,i.useState)(null),[eL,eR]=(0,i.useState)(null),[eN,e$]=(0,i.useState)(null),[eW,ez]=(0,i.useState)(!1),[eP,eA]=(0,i.useState)(!1),[eD,eF]=(0,i.useState)(null),[eB,eH]=(0,i.useState)(null),[eO,eU]=(0,i.useState)(null),[e_,eq]=(0,i.useState)([]),[eK,eJ]=(0,i.useState)(!1),[eY,eZ]=(0,i.useReducer)(r5,{visible:[],pending:[]}),[eG,eX]=(0,i.useState)(null),[eQ,e0]=(0,i.useState)(null),[e1,e2]=(0,i.useState)(null),[e4,e8]=(0,i.useState)({steering:[],followUp:[]}),e5=(0,i.useRef)(null),e6=(0,i.useRef)(null),e3=(0,i.useRef)(0),e7=(0,i.useRef)(!1),e9=(0,i.useRef)(t?.id??null),te=(0,i.useRef)(t?.id??null),tt=(0,i.useRef)(!!r),tn=(0,i.useRef)(!1),tr=(0,i.useRef)(!1),ti=(0,i.useRef)(!1),to=(0,i.useRef)(-1),tl=(0,i.useRef)(!1),ts=(0,i.useRef)(!1),ta=(0,i.useRef)(0),td=(0,i.useRef)(null),tc=(0,i.useRef)(!!e.deferInitialScroll),tu=(0,i.useRef)(!1),th=(0,i.useRef)(!0),tp=(0,i.useRef)(0),tf=(0,i.useRef)(null),tg=(0,i.useRef)(null),tx=(0,i.useRef)([]),tm=(0,i.useRef)(void 0),ty=(0,i.useRef)(null),tv=(0,i.useRef)(null),tb=(0,i.useRef)(!1),tw=(0,i.useRef)(null),tk=(0,i.useRef)(null),tj=(0,i.useRef)(0),tS=(0,i.useRef)(new rK),tC=(0,i.useRef)(null),tI=(0,i.useRef)(!1),tM=(0,i.useRef)(null),tT=(0,i.useRef)(!1),tE=(0,i.useRef)(u),tL=(0,i.useRef)(new Map),tR=(0,i.useRef)(!0),tN=(0,i.useRef)(!1),t$=(0,i.useRef)(null),tW=(0,i.useRef)(new Map),tz=(0,i.useRef)(t?.id??null);te.current=t?.id??null,tt.current=!!r,e5.current||(e5.current=new rH({createSource:e=>new EventSource(`/api/agent/${encodeURIComponent(e)}/events`),onEvent:e=>td.current?.(e),shouldMaintain:e=>tR.current&&e9.current===e&&(tn.current||e7.current||te.current===e&&tt.current),readinessTimeoutMs:6e4,reconnectDelayMs:1e3,onUnexpectedError:e=>{console.error("Failed to maintain the agent event stream:",e)}}));let tP=e.setToolPreset??ev,tA=t?.id;(0,i.useLayoutEffect)(()=>{(tA||m&&!e9.current)&&tP(function(e=rz()){if(!e)return"default";try{let t=e.getItem(rW);return(0,r$.sn)(t)?t:"default"}catch{return"default"}}())},[tA,m,tP]),(0,i.useEffect)(()=>{let e=t?.id??null;if(tz.current!==e){if(null===tz.current&&e&&t$.current){tz.current=e;return}tz.current=e,tW.current=new Map,t$.current=null,tN.current=!1}},[t?.id]);let tD=(0,i.useCallback)((e="smooth")=>{let t=ty.current;t&&(th.current=!0,t.scrollTo({top:t.scrollHeight,behavior:e}),tp.current=t.scrollTop)},[]),tF=eL??j?.context.model??eN??null,tB=m?ef??ex:tF,tH=t?.id??l??void 0,tK=(0,i.useCallback)(e=>{if(!e)return;let t=e,n=new Set;for(;!n.has(t);){n.add(t);let e=tL.current.get(t);if(!e)break;t=e}return t},[]),tV=(0,i.useCallback)((t,n,r)=>{let i=n?.map(({data:e,mimeType:t})=>({data:e,mimeType:t})),o=tK(r);if(!tR.current&&!tb.current&&r===l)return;let s=e.chatInputRef?.current;if(s)s.restoreSubmission(t,i,o);else{let e,n;o&&(n=nk(t,i,(e=nm(o)??{value:"",images:[]}).value,e.images),ny(o,n))}},[l,e.chatInputRef,tK]),tJ=(0,i.useMemo)(()=>{if(eG)return{...eG,totalActiveMs:j?.totalActiveMs,...eS?{contextUsage:eS}:{}};let e=j?.stats,n=function(e,t,n){let r=rA(n);if(!e)return r;let i=rA(t),o=(e,t)=>Math.max(0,e-t),l={input:e.tokens.input+o(r.tokens.input,i.tokens.input),output:e.tokens.output+o(r.tokens.output,i.tokens.output),cacheRead:e.tokens.cacheRead+o(r.tokens.cacheRead,i.tokens.cacheRead),cacheWrite:e.tokens.cacheWrite+o(r.tokens.cacheWrite,i.tokens.cacheWrite),total:0};return l.total=l.input+l.output+l.cacheRead+l.cacheWrite,{userMessages:e.userMessages+o(r.userMessages,i.userMessages),assistantMessages:e.assistantMessages+o(r.assistantMessages,i.assistantMessages),toolCalls:e.toolCalls+o(r.toolCalls,i.toolCalls),toolResults:e.toolResults+o(r.toolResults,i.toolResults),totalMessages:e.totalMessages+o(r.totalMessages,i.totalMessages),tokens:l,cost:e.cost+o(r.cost,i.cost)}}(e,j?.context.messages??[],R);return 0!==n.tokens.total||0!==R.length||e?{sessionFile:j?.filePath||void 0,sessionId:e9.current??t?.id??"",sessionName:t?.name,...n,totalActiveMs:j?.totalActiveMs,...eS?{contextUsage:eS}:{}}:null},[R,eG,eS,j?.context.messages,j?.filePath,j?.totalActiveMs,j?.stats,t?.id,t?.name]),tY=(0,i.useCallback)(async(e,t=!1,n=!1)=>{let r=!1;try{t&&I(!0);let i=new URLSearchParams({deferThinking:"1",deferMedia:"1"}),o=await fetch(`/api/sessions/${encodeURIComponent(e)}?${i}`);if(404===o.status)return t&&(S(null),L(null),N([]),P([]),D(null),B(!1),eC(null),T(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let l=await o.json();if(e9.current!==e)return null;let s={messages:l.context.messages,entryIds:l.context.entryIds??[],oldestEntryId:l.context.oldestEntryId,hasMore:l.context.hasMore},a=t?s:function(e,t){if(0===e.entryIds.length||0===t.entryIds.length)return t;let n=new Set(t.entryIds),r=e.entryIds.findIndex(e=>n.has(e));return r<=0?t:{messages:[...e.messages.slice(0,r),...t.messages],entryIds:[...e.entryIds.slice(0,r),...t.entryIds],oldestEntryId:e.oldestEntryId??e.entryIds[0]??t.oldestEntryId,hasMore:e.hasMore}}(H.current,s);if(S({...l,context:{...l.context,...a}}),L(l.leafId),N(tq(a.messages,tW.current)),P(a.entryIds),D(a.oldestEntryId),B(a.hasMore),tP(void 0!==l.toolNames?(0,r$.YO)(l.toolNames):"default"),eR(e=>tT.current?e:null),T(null),l.context.thinkingLevel&&"off"!==l.context.thinkingLevel&&ew(l.context.thinkingLevel),void 0!==l.contextUsage&&eC(l.contextUsage??null),r=!0,t&&I(!1),!n)return null;try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();if(e9.current!==e)return null;let r=n.state;return r?(void 0!==r.contextUsage&&eC(r.contextUsage??null),void 0!==r.systemPrompt&&eM(r.systemPrompt??null),void 0!==r.thinkingLevel&&ew(r.thinkingLevel??"auto"),void 0!==r.queuedMessages&&e8(r0(r.queuedMessages))):n.running||e8({steering:[],followUp:[]}),n}catch(e){return console.error("Failed to load agent state:",e),null}}catch(e){return T(String(e)),null}finally{t&&!r&&I(!1)}},[tP]),tZ=(0,i.useCallback)(async(e,t,n,r)=>{try{let i=new URLSearchParams({deferThinking:"1",deferMedia:"1"});t&&i.set("leafId",t),n&&i.set("before",n),r?.tail&&i.set("tail",String(r.tail));let o=`/api/sessions/${encodeURIComponent(e)}/context?${i}`,l=await fetch(o,{signal:r?.signal});if(!l.ok)throw Error(`HTTP ${l.status}`);let s=await l.json();if(e9.current!==e||r?.signal?.aborted||!tR.current)return;return D(s.context.oldestEntryId),B(s.context.hasMore),S(t=>{if(!t||t.sessionId!==e)return t;let r=n?{...t.context,messages:[...s.context.messages,...t.context.messages],entryIds:[...s.context.entryIds,...t.context.entryIds],oldestEntryId:s.context.oldestEntryId,hasMore:s.context.hasMore}:s.context;return{...t,context:r}}),n?(N(e=>[...tq(s.context.messages,tW.current),...e]),P(e=>[...s.context.entryIds,...e])):(N(tq(s.context.messages,tW.current)),P(s.context.entryIds??[])),s.context}catch(e){r?.signal?.aborted||console.error("Failed to load context:",e)}},[]),tG=(0,i.useCallback)(async e=>{try{let t=await rN(e,{type:"get_tools"});if(!t||!tR.current||e9.current!==e)return null;let{getPresetFromTools:r}=await Promise.resolve().then(n.bind(n,14755));return tP(r(t)),f?.(t),t}catch(e){return console.error("Failed to load tools:",e),null}},[f,tP]),tX=(0,i.useCallback)((t=0,n="(no messages)")=>{let r=e9.current;if(m&&o&&r&&!tb.current&&(tb.current=!0,l)){if(l!==r){tL.current.set(l,r);let t=e.chatInputRef?.current;t?t.rekeyDraft(l,r):nj(l,r)}d?.({id:r,path:"",cwd:o,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:t,firstMessage:n,transient:!0},l)}},[m,o,l,d,e.chatInputRef]),tQ=(0,i.useCallback)(async()=>{if(e9.current||!m||!o)return e9.current;if(tv.current)return tv.current;let e=(async()=>{let e=tw.current,t=tk.current;e&&e$(e);let n=(0,r$.xG)(ey),r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:o,type:"ensure_session",toolNames:n,...e?{provider:e.provider,modelId:e.modelId}:{},...t?{thinkingLevel:t}:{}})});if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json(),l=i.sessionId;return e9.current=l,void 0!==i.contextUsage&&eC(i.contextUsage??null),i.model&&tw.current===e&&(e$(i.model),e||em(i.model)),i.thinkingLevel&&tk.current===t&&ew(i.thinkingLevel),l})();tv.current=e;try{return await e}finally{tv.current=null}},[m,o,ey]),t0=(0,i.useCallback)(async()=>{let e=e9.current??await tQ();if(!e)return;let[t]=await Promise.all([rN(e,{type:"get_state"}),tG(e)]);tR.current&&e9.current===e&&eM(t.systemPrompt??"")},[tQ,tG]),t1=(0,i.useCallback)(async()=>{let e=e9.current??await tQ();if(!e)return eq([]),[];eJ(!0);try{let t=await rN(e,{type:"get_commands"}),n=t?.commands??[];return eq(n),n}catch(e){return console.error("Failed to load slash commands:",e),eq([]),[]}finally{eJ(!1)}},[tQ]),t2=(0,i.useCallback)(()=>{e3.current+=1,e7.current=!1,e6.current&&(clearTimeout(e6.current),e6.current=null)},[]),t4=(0,i.useCallback)(()=>{e5.current?.close()},[]),t8=(0,i.useCallback)(e=>e5.current.ensureConnected(e),[]),t5=(0,i.useCallback)(e=>{e5.current.maintain(e)},[]);(0,i.useEffect)(()=>{if(t?.id&&r)return t5(t.id),()=>{e9.current!==t.id||tn.current||e7.current||te.current===t.id&&tt.current||e5.current?.close()}},[t5,t?.id,r]);let t6=(0,i.useCallback)(async(e,t)=>{let n=e9.current;if(e0(t=>t?.id===e.id?null:t),n)try{await rN(n,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),t3=(0,i.useCallback)(async(e,t)=>{let n=e9.current;if(n)try{await rN(n,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),t7=(0,i.useCallback)(e=>{let t=e.message.trim();t&&eZ({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"}})},[]),t9=(0,i.useCallback)(t=>{switch(rI(t)&&a?.(t),t.method){case"select":case"confirm":case"input":case"editor":e0(t);break;case"notify":t7({id:t.id,message:t.message,type:t.notifyType??"info"});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":e2(e=>t.closed?e?.id===t.id?null:e:t)}},[t7,a,e.chatInputRef]),ne=(0,i.useCallback)(()=>{!tu.current&&th.current&&null===tf.current&&(tf.current=requestAnimationFrame(()=>{tf.current=null,th.current&&tD("auto")}))},[tD]),nt=(0,i.useCallback)(()=>{null!==tg.current&&(cancelAnimationFrame(tg.current),tg.current=null);let e=tx.current;0!==e.length&&(tx.current=[],U({type:"deltas",events:e}),ne())},[ne]),nn=(0,i.useCallback)(e=>{tx.current.push(e),null===tg.current&&(tg.current=requestAnimationFrame(()=>{tg.current=null,nt()}))},[nt]),nr=(0,i.useCallback)(()=>{nt();let e=tn.current;return tn.current=!1,K(!1),eU(null),ej(null),W(new Map),U({type:"end"}),e},[nt]),ni=(0,i.useCallback)(e=>to.current!==e&&(to.current=e,s?.(),!0),[s]),no=(0,i.useCallback)(e=>{t2(),e7.current=!0;let t=e3.current,n=async()=>{if(t===e3.current&&e9.current===e&&e7.current)try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();if(t!==e3.current||e9.current!==e||!e7.current)return;let o=i.state;if(i.running&&o&&(o.isStreaming||o.isPromptRunning)){e7.current=!1,e6.current=null,tr.current=!!o?.isStreaming,ti.current=!!o?.isPromptRunning,tn.current=!0,K(!0),eU(o?.isStreaming?{kind:"waiting_model"}:{kind:"running_command"});return}if(i.running&&o?.isCompacting){eA(!0),e6.current=setTimeout(()=>void n(),600);return}e7.current=!1,e6.current=null,t4()}catch{if(t!==e3.current||e9.current!==e||!e7.current)return;e6.current=setTimeout(()=>void n(),600)}};e6.current=setTimeout(()=>void n(),3e4)},[t2,t4]),nl=(0,i.useCallback)(async(e=e9.current,t=tj.current)=>{if(tj.current===t)try{e&&await tY(e)}finally{if(tj.current!==t)return;let n=ti.current,r=tr.current;ti.current=!1,tr.current=!1,tM.current=null;let i=nr();n?ni(t):r&&i&&s?.(),e&&no(e)}},[tY,ni,s,no,nr]),ns=(0,i.useCallback)(async(e,t)=>{await r4(800);let n=Date.now();for(;tn.current&&Date.now()-n<2e4;){if(void 0!==t&&tj.current!==t)return;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(n.ok){let r=await n.json(),i=r.state;if(!r.running||!i||!i.isStreaming&&!i.isPromptRunning)return void await nl(e,t)}}catch{}await r4(600)}},[nl]),na=(0,i.useCallback)(async e=>{let t=ta.current+1;for(ta.current=t;tl.current&&ta.current===t&&e9.current===e;){await r4(1e3);try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)continue;let r=await n.json();if(r.state?.isBashRunning)continue;if(await tY(e),ta.current!==t||e9.current!==e)return;tl.current=!1,J(!1),Z(null);return}catch{}}},[tY]),nd=(0,i.useCallback)(async e=>{if(!tn.current||e9.current!==e)return;let t=tj.current;try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)return;let r=await n.json();if(e9.current!==e||tj.current!==t)return;let i=r.state;if(eA(i?.isCompacting??!1),e8(r0(i?.queuedMessages)),i?.contextUsage!==void 0&&eC(e=>r1(e,i.contextUsage??null)),r.running&&i&&(i.isStreaming||i.isPromptRunning||i.isCompacting)){tr.current=!!i.isStreaming,ti.current=!!i.isPromptRunning;return}if(!tn.current)return;i&&void 0!==i.systemPrompt&&eM(i.systemPrompt??null),await nl(e,t)}catch{}},[nl]);(0,i.useEffect)(()=>{if(!q)return;let e=()=>{let e=e9.current;e&&nd(e)},t=()=>{"visible"===document.visibilityState&&e()},n=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(n),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[q,nd]),(0,i.useEffect)(()=>{tn.current=q},[q]),td.current=(0,i.useCallback)(e=>{switch("message_update"!==e.type&&nt(),e.type){case"connected":U({type:!0===e.isStreaming?"resume":"end"}),!0===e.isStreaming&&(t2(),tr.current=!0,tn.current=!0,K(!0),eU({kind:"waiting_model"}));break;case"agent_start":t2(),tr.current=!0,tn.current=!0,K(!0),eU({kind:"waiting_model"}),tN.current=!0,t$.current||(t$.current=tO(Date.now())),U({type:"start"});break;case"agent_end":if(!tn.current)break;eU(null),ej(null),U({type:"end"}),e9.current&&(tY(e9.current),fetch(`/api/agent/${encodeURIComponent(e9.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&eC(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&eM(e.state.systemPrompt??null),e8(r0(e.state?.queuedMessages))}).catch(()=>{}));break;case"agent_settled":{let e=tr.current;if(tr.current=!1,!e||ti.current)break;let t=e9.current,n=nr();eA(!1),t&&(tY(t),no(t)),n&&s?.();break}case"prompt_done":{let e=tj.current,t=ti.current;ti.current=!1,tM.current=null;let n=ni(e);if(!t&&!n)break;let r=e9.current;r&&tY(r),!tr.current&&(nr(),r&&no(r))}break;case"prompt_error":t7({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":t7({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":if(!tn.current)break;if("message_start"===e.type){let t=e.message;if(t?.role==="user")break;t?.role==="assistant"?(U({type:"snapshot",message:t}),t.content.length>0&&eU(null),tN.current&&(t$.current||(t$.current=tO(Date.now())),function(e){if(!e?.content||!Array.isArray(e.content))return!1;for(let t of e.content)if(t&&"object"==typeof t&&("text"===t.type&&"string"==typeof t.text&&t.text.length>0||"thinking"===t.type&&"string"==typeof t.thinking&&t.thinking.length>0||"toolCall"===t.type&&("string"==typeof t.toolName&&t.toolName.length>0||"string"==typeof t.rawInput&&t.rawInput.length>0||t.input&&"object"==typeof t.input&&!Array.isArray(t.input)&&Object.keys(t.input).length>0)))return!0;return!1}(t)&&(t$.current=tU(t$.current,Date.now())))):t&&eU(null)}else{let t=e.assistantMessageEvent;t&&(nn(t),"toolcall_start"!==t.type&&"toolcall_delta"!==t.type&&eU(null),tN.current&&t$.current&&function(e){switch(e.type){case"thinking_delta":case"text_delta":case"toolcall_delta":return"string"==typeof e.delta&&e.delta.length>0;case"thinking_end":case"text_end":return"string"==typeof e.content&&e.content.length>0;case"toolcall_start":return"string"==typeof e.toolName&&e.toolName.length>0;case"toolcall_end":return!0;default:return!1}}(t)&&(t$.current=tU(t$.current,Date.now())))}"message_start"===e.type&&ne();break;case"message_end":{if(!tn.current)break;let o=e.message;if(o&&"user"===o.role){let e=rE(o),t=rF(e),n=tM.current;tM.current=null,N(r=>{let i=r[r.length-1];return n&&i?.role==="user"&&rF(i)===n?n===t?r:[...r.slice(0,-1),e]:[...r,e]})}else if(o){let e=rE(o);if("assistant"===e.role){var t,n,r,i;let o,l=function(e){if("assistant"!==e.role||"aborted"===e.stopReason||"error"===e.stopReason)return null;let t=e.usage;if(!t)return null;let n=t.totalTokens,r=n&&n>0?n:t.input+t.output+t.cacheRead+t.cacheWrite;return r>0?r:null}(e);null!==l&&eC(e=>{let t=e?.contextWindow??0;return t<=0?e:r1(e,{tokens:l,contextWindow:t,percent:l/t*100})});let s=Date.now(),a=function(e,t,n){if(!t)return e;let r=!1,i=e.content.map((e,i)=>{if("thinking"!==e.type)return e;let o=t.content[i],l=(o?.type==="thinking"?o.startedAt:void 0)??e.startedAt??t.timestamp,s=(o?.type==="thinking"?o.endedAt:void 0)??e.endedAt??n;return e.startedAt===l&&e.endedAt===s?e:(r=!0,{...e,..."number"==typeof l?{startedAt:l}:{},..."number"==typeof s?{endedAt:s}:{}})});return r?{...e,content:i}:e}({...e,completedAt:s},_.current.streamingMessage,s),d=(t=t$.current,n=a,r=s,t?function(e){if(null===e.firstTokenAt)return null;let t=Math.max(0,e.firstTokenAt-e.requestStartAt),n=Math.max(0,e.completedAt-e.firstTokenAt),r="number"==typeof e.outputTokens&&Number.isFinite(e.outputTokens)&&e.outputTokens>=0?e.outputTokens:null,i=null!==r&&r>0&&n>0?r/(n/1e3):void 0;return void 0===i&&t<100?null:{ttftMs:t,...void 0!==i?{tokensPerSecond:i}:{}}}({requestStartAt:t.requestStartAt,firstTokenAt:t.firstTokenAt,completedAt:r,outputTokens:(i=n.usage,"number"==typeof(o=i?.output)&&Number.isFinite(o)&&o>=0?o:null)}):null);if(t$.current=null,d){let e=t_(a);e&&tW.current.set(e,d),N(e=>[...e,{...a,decode:d}])}else N(e=>[...e,a])}else t$.current=null,N(t=>[...t,e])}U({type:"end"}),eU({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,n=e.toolName;eU(e=>{let r=e?.kind==="running_tools"?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:n}),{kind:"running_tools",tools:r}});break}case"tool_execution_update":{let t=e.toolCallId,n=e.toolName,r=e.partialResult,i=r?.content;("bash"===n||"powershell"===n)&&Array.isArray(i)&&W(e=>{let o=new Map(e);return o.set(t,{role:"toolResult",toolCallId:t,toolName:n,content:i,isError:r?.isError,details:r?.details}),o}),eU(e=>{let r=e?.kind==="running_tools"?e.tools:[],i=r.find(e=>e.id===t),o=n||i?.name||"tool";return i?.name===o?e:{kind:"running_tools",tools:[...r.filter(e=>e.id!==t),{id:t,name:o}]}});break}case"tool_execution_end":{let t=e.toolCallId;W(e=>{if(!e.has(t))return e;let n=new Map(e);return n.delete(t),n}),eU(e=>{if(e?.kind!=="running_tools")return e;let n=e.tools.filter(e=>e.id!==t);return 0===n.length?{kind:"waiting_model"}:{kind:"running_tools",tools:n}});break}case"queue_update":e8({steering:[...e.steering??[]],followUp:[...e.followUp??[]]});break;case"auto_retry_start":ej({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":ej(null);break;case"auto_compaction_start":case"compaction_start":eA(!0),eF(null),eH(null);break;case"auto_compaction_end":case"compaction_end":eA(!1),e.errorMessage?(eF(e.errorMessage),eH(null)):!e.aborted&&(eH(r6(e.result,e.reason??"auto")),e9.current&&tY(e9.current));break;case"extension_ui_request":t9(e);break;case"extension_ui_closed":e0(t=>t?.id===e.id?null:t)}},[t7,t2,nt,t9,tY,ni,s,nn,no,ne,nr]);let nc=(0,i.useCallback)(async(e,n)=>{let r=e.trim();if(!r&&!n?.length)return;if(tn.current||tl.current)return void tV(e,n,tH);let i=!n?.length&&r.startsWith("/");if(!n?.length&&r.startsWith("!")){let t=r.startsWith("!!"),i=(t?r.slice(2):r.slice(1)).trim();return i?void await tm.current?.(i,t):void tV(e,n,tH)}let l=tj.current+1;t2(),ti.current=!0;let s=n?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),a={role:"user",content:s?.length?[...e.trim()?[{type:"text",text:e}]:[],...s]:e,timestamp:Date.now()};N(e=>[...e,a]),tM.current=rF(a),tj.current=l,tn.current=!0,K(!0),eU(i?{kind:"running_command"}:{kind:"waiting_model"}),tN.current=!0,t$.current=tO(Date.now()),U({type:"start"}),tu.current=!0,tC.current={runId:l,message:e,images:n,userMsg:a};let d=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),c=!1;tS.current.begin(l);let u=async e=>{try{await rN(e,{type:"abort"})}catch(e){t7({type:"error",message:e instanceof Error?e.message:String(e)})}},h=await rJ({gate:tS.current,runId:l,currentRunId:()=>tj.current,currentSessionId:()=>e9.current,promptPending:()=>ti.current,abandonUnsent:()=>{tC.current?.runId===l&&(tC.current=null,ti.current=!1,N(e=>{let t=e.lastIndexOf(a);return -1===t?e:[...e.slice(0,t),...e.slice(t+1)]}),tV(e,n,tH),tM.current=null,tj.current===l&&(tn.current=!1,K(!1),eU(null),U({type:"end"})))},onDispatched:()=>{tC.current?.runId===l&&(tC.current=null)},abort:u,prepare:async()=>{if(m&&o){let e=e9.current??await tv.current;if(tS.current.isCancelled(l))return null;let t=e??await tQ();if(tS.current.isCancelled(l))return null;if(!t)throw Error("Unable to create a session for the prompt");return ef&&(e$(ef),e)&&(await rN(t,{type:"set_model",provider:ef.provider,modelId:ef.modelId}),tS.current.isCancelled(l))?null:(await t8(t),tS.current.isCancelled(l))?null:t}if(t)return(await t8(t.id),tS.current.isCancelled(l))?null:t.id;throw Error("No active session for the prompt")},send:async t=>{let n=await rN(t,{type:"prompt",message:e,...d?.length?{images:d}:{}});c=n?.subagentAction==="steered"||n?.subagentAction==="resumed"}});if("abandoned"!==h.status&&"aborted"!==h.status&&"stale"!==h.status){if("cancelled_after_dispatch"===h.status)return void ns(h.sessionId,l);if("failed"===h.status){let t=h.error,r=h.sessionId,i=h.requestStarted;return(console.error("Failed to send message:",t),!(!i||rR(t))&&r)?void ns(r,l):(ti.current=!1,tC.current?.runId===l&&(tC.current=null),N(e=>{let t=e.lastIndexOf(a);return -1===t?e:[...e.slice(0,t),...e.slice(t+1)]}),t7({type:"error",message:t instanceof Error?t.message:String(t)}),tV(e,n,tH),tM.current=null,r)?void nd(r):(tn.current=!1,t4(),K(!1),eU(null),void U({type:"end"}))}if(m&&o&&tX(1,e),c&&h.sessionId){ti.current=!1,ns(h.sessionId,l);return}i&&h.sessionId&&ns(h.sessionId,l)}},[m,o,ef,t,tQ,t8,tX,ns,t7,t2,t4,tH,nd,tV]),nu=(0,i.useCallback)(async e=>{if(tn.current||tl.current||Q.current)throw Error("Cannot generate an image while the session is busy");let n=crypto.randomUUID();Q.current=!0,ee.current=n,et.current=!1,X(!0);try{let r=t?.id??(m&&o?await tQ():null);if(!r)throw Error("No active session for image generation");if(et.current)throw new DOMException("Image generation cancelled","AbortError");let i=await rN(r,{type:"generate_image_direct",requestId:n,arguments:e});return await tY(r),m&&o&&tX(1,e.prompt),i}finally{ee.current===n&&(Q.current=!1,ee.current=null,et.current=!1,X(!1))}},[tQ,m,tY,o,tX,t?.id]),nh=(0,i.useCallback)(async()=>{et.current=!0;let e=e9.current,t=ee.current;e&&t&&await rN(e,{type:"abort_image_generation",requestId:t})},[]);tm.current=(0,i.useCallback)(async(e,n)=>{if(tn.current||tl.current)return;let r=`${n?"!!":"!"}${e}`;tI.current=!1,tl.current=!0,Z({command:e,excludeFromContext:n}),J(!0);try{let i=await rY({abortRequested:()=>tI.current,prepare:async()=>e9.current??t?.id??await tQ(),send:async t=>{await rN(t,{type:"bash",command:e,excludeFromContext:n})},loadResults:async e=>{e9.current===e&&await tY(e)},restoreUnsent:()=>tV(r,void 0,tH)});("completed"===i.status||"cancelled_after_dispatch"===i.status)&&tX(1,r)}catch(e){console.error("Failed to execute shell command:",e),t7({type:"error",message:e instanceof Error?e.message:String(e)}),tV(r,void 0,tH)}finally{tl.current=!1,Z(null),J(!1)}},[t7,tH,tQ,tY,tX,tV,t]);let np=(0,i.useCallback)(async()=>{var e;let n=tj.current,r=e9.current,i=async e=>{if(r&&!ts.current){ts.current=!0;try{await rN(r,{type:e})}catch(e){console.error("Failed to abort:",e),t7({type:"error",message:e instanceof Error?e.message:String(e)})}finally{ts.current=!1}}};if(tl.current){tI.current=!0,await i("abort_bash");return}let o=tC.current;(tS.current.isInFlight(n)||o?.runId===n)&&tS.current.cancel(n);let l=!!(o&&o.runId===n&&tS.current.shouldAbandonUnsent(n));if(l&&o){tC.current=null,ti.current=!1,N(e=>{let t=e.lastIndexOf(o.userMsg);return -1===t?e:[...e.slice(0,t),...e.slice(t+1)]}),tV(o.message,o.images,tH),tM.current=null,tn.current=!1,K(!1),eU(null),U({type:"end"});return}let s=(e={bashRunning:!1,hasSessionId:!!r,localUnsent:l,agentRunning:tn.current||ti.current}).bashRunning?e.hasSessionId?"abort_bash":"none":!e.agentRunning||e.localUnsent?"none":e.hasSessionId?"abort":"none";t?.relation?.kind==="subagent"&&"queued"===t.relation.status&&r?await i("abort"):"none"!==s&&r&&await i("abort_bash"===s?"abort_bash":"abort")},[t7,tH,tV,t]),nf=(0,i.useCallback)(async e=>{if(tl.current)return;let t=e9.current;if(t){eE(e);try{let{cancelled:n,newSessionId:r}=await rN(t,{type:"fork",entryId:e})??{};!n&&r&&c?.(r)}catch(e){console.error("Fork failed:",e)}finally{eE(null)}}},[c]),ng=(0,i.useCallback)(async e=>{if(tl.current)return;let t=e9.current;t&&(rN(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),L(e),await tZ(t,e))},[tZ]),nx=(0,i.useCallback)(async e=>{if(tl.current)return;L(e);let t=e9.current;t&&(await tZ(t,e),e&&rN(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[tZ]),nv=(0,i.useCallback)(async(e,t)=>{if(m){let n={provider:e,modelId:t};tw.current=n,eg(n),e$(n);let r=e9.current??await tv.current;if(!r)return;try{await rN(r,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let n=e9.current;if(n&&!tT.current){tT.current=!0,eR({provider:e,modelId:t}),ez(!0);try{await rN(n,{type:"set_model",provider:e,modelId:t}),tT.current=!1,await tY(n)}catch(e){console.error("Failed to set model:",e),tT.current=!1,eR(eL),t7({type:"error",message:`Failed to switch model: ${e instanceof Error?e.message:String(e)}`}),await tY(n)}finally{tT.current=!1,ez(!1)}}},[t7,eL,m,tY,eg]),nb=(0,i.useCallback)(async()=>{let e=e9.current;if(e&&!eP){eA(!0),eF(null),eH(null);try{let t=await rN(e,{type:"compact"});eH(r6(t,"manual")),await tY(e,!0)}catch(e){eF(e instanceof Error?e.message:String(e)),eH(null)}finally{eA(!1)}}},[eP,tY]),nw=(0,i.useCallback)(async(e,t=!1,n)=>{let r;try{r=await function(e,t,n={}){let r=rG.get(e);if(!n.force&&r&&r.loadedAt+6e4>Date.now())return Promise.resolve(r.data);let i=rX.get(e);if(i&&(!n.force||i.forced&&i.refreshToken===n.refreshToken))return i.promise;let o=(i?i.promise.catch(()=>void 0):Promise.resolve()).then(t).then(t=>{if(t.modelError&&(t.modelList?.length??0)===0)throw Error(t.modelError);for(rG.delete(e),rG.set(e,{data:t,loadedAt:Date.now()});rG.size>32;){let e=rG.keys().next().value;if(void 0===e)break;rG.delete(e)}return t}).finally(()=>{rX.get(e)?.promise===o&&rX.delete(e)});return rX.set(e,{promise:o,forced:!0===n.force,...void 0!==n.refreshToken?{refreshToken:n.refreshToken}:{}}),o}(v,async()=>{let e=await fetch(v);if(!e.ok){let t="";try{let n=await e.json();n&&"object"==typeof n&&"error"in n&&"string"==typeof n.error&&(t=n.error)}catch{}throw Error(t||`Failed to load models (HTTP ${e.status})`)}return e.json()},{force:t,refreshToken:n}),e?.throwIfAborted()}catch(t){throw e?.aborted||t instanceof DOMException&&"AbortError"===t.name||es(t instanceof Error?t.message:String(t)),t}if(er(r.models),es(r.modelError??null),ed(r.modelScopeWarnings??[]),eu(r.thinkingLevels??{}),ep(r.thinkingLevelMaps??{}),eo(r.modelList??[]),m&&!e9.current){let e=r3(r);em(e);let t=e&&r.thinkingLevelPins?.[`${e.provider}/${e.modelId}`];null===tk.current&&ew(t??"auto")}},[m,v]),nS=(0,i.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,n,r=""]=t,i=r.trim(),o=e9.current??await tQ(),l=e=>(e.handled&&(e.error?t7({type:"error",message:e.error}):"openSessionStats"!==e.action&&t7({type:"success",message:e.message??"Command completed"})),e);try{switch(n){case"compact":{if(!o||eP)return l({handled:!0,error:"No active session to compact"});eA(!0),eF(null),eH(null);let e=await rN(o,{type:"compact",...i?{customInstructions:i}:{}});return eH(r6(e,"manual")),await tY(o,!0)&&tX(),l({handled:!0,message:"Compacted context"})}case"reload":if(!o)return l({handled:!0,error:"No active session to reload"});return await rN(o,{type:"reload"}),await Promise.all([tY(o,!1,!0),tG(o),t1(),nw(void 0,!0)]),l({handled:!0,message:"Reloaded session resources"});case"name":if(!o)return l({handled:!0,error:"No active session to name"});if(!i)return l({handled:!0,error:"Usage: /name <name>"});return await rN(o,{type:"set_session_name",name:i}),await tY(o)&&tX(),l({handled:!0,message:`Session renamed to ${i}`});case"session":{if(!o)return l({handled:!0,error:"No active session"});let e=await rN(o,{type:"get_session_stats"});return e&&eX(e),x?.(),l({handled:!0,action:"openSessionStats"})}case"copy":{if(!o)return l({handled:!0,error:"No active session"});let e=await rN(o,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return l({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),l({handled:!0,message:"Copied last assistant message"})}case"clone":{if(!o)return l({handled:!0,error:"No active session to clone"});if(tn.current||tl.current)return l({handled:!0,error:"Cannot clone while the session is running"});let e=await rN(o,{type:"clone",leafId:E});if(e?.cancelled||!e?.newSessionId)return l({handled:!0,error:"Cannot clone an empty or unsaved session"});let t=l({handled:!0,message:"Cloned current session branch"});return c?.(e.newSessionId),t}default:return{handled:!1}}}catch(e){return l({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===n&&eA(!1)}},[E,t7,tQ,eP,nw,tY,t1,tG,tX,c,x]),nC=(0,i.useCallback)(async(e,t,n)=>{let r=e9.current;if(!r){tV(e,n,tH),t7({type:"error",message:"No active session for the queued message"});return}let i=n?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await rN(r,{type:"prompt",message:e,streamingBehavior:t,...i?.length?{images:i}:{}})}catch(t){console.error("Failed to submit streaming prompt:",t),rR(t)&&tV(e,n,tH),t7({type:"error",message:t instanceof Error?t.message:String(t)})}},[t7,tH,tV]),nI=(0,i.useCallback)(async(e,t)=>{await nC(e,"steer",t)},[nC]),nM=(0,i.useCallback)(async(e,t,n)=>{await nC(e,t,n)},[nC]),nT=(0,i.useCallback)(async(e,t)=>{await nC(e,"followUp",t)},[nC]),nE=(0,i.useCallback)(async()=>{let e=e9.current;if(e)try{await rN(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),nL=(0,i.useCallback)(async()=>{let e=e9.current;if(e)try{let t=await rN(e,{type:"clear_queue"});e8({steering:[],followUp:[]});let n=[...rZ(t?.steering),...rZ(t?.followUp)];if(0===n.length)return;tV(n.map(e=>e.text).filter(Boolean).join("\n\n"),n.flatMap(e=>e.images).map(e=>({...e,previewUrl:""})),tH)}catch(e){console.error("Failed to recall queued messages:",e),t7({type:"error",message:e instanceof Error?e.message:"Failed to recall queued messages"})}},[t7,tH,tV]),nR=(0,i.useCallback)(async e=>{if(ew(e),m&&!e9.current&&(tk.current="auto"===e?null:e),"auto"===e)return;let t=e9.current??await tv.current;if(t)try{await rN(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[m]),nN=(0,i.useCallback)(async e=>{let t=(0,r$.xG)(e);!function(e,t=rz()){if(t)try{t.setItem(rW,e)}catch{}}(e),tP(e);let n=e9.current??await tv.current;if(n)try{let e=await rN(n,{type:"set_tools",toolNames:t}),r=e?.sessionId??n;r!==n&&(t2(),t4(),e9.current=r),eq([]);let[i]=await Promise.all([rN(r,{type:"get_state"}),tG(r)]);tR.current&&e9.current===r&&eM(i.systemPrompt??"")}catch(e){console.error("Failed to set tools:",e)}},[t2,t4,tG,tP]),n$=(0,i.useCallback)((e,t=16)=>{let n=ty.current;n&&(null!==tf.current&&(cancelAnimationFrame(tf.current),tf.current=null),tc.current=!0,tu.current=!1,th.current=!1,n.scrollTo({top:e.getBoundingClientRect().top-n.getBoundingClientRect().top+n.scrollTop-t,behavior:"instant"}),tp.current=n.scrollTop)},[]),nW=(0,i.useCallback)(()=>{let e=ty.current;if(e){let{scrollTop:t,clientHeight:n,scrollHeight:r}=e,i=tn.current,o=th.current,l=function(e,t,n,r,i,o=96){return!!eV(n,r,i)||!(n<t)&&(!!(!e&&n>t&&eV(n,r,i,o))||e)}(o,tp.current,t,n,r,i?96:8);th.current=l,tp.current=t,!o&&l&&i?tD("auto"):l||null===tf.current||(cancelAnimationFrame(tf.current),tf.current=null)}},[tD]);(0,i.useEffect)(()=>(tR.current=!0,t&&(e9.current=t.id,tY(t.id,!0,!0).then(e=>{e?.running&&(tG(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(tr.current=!!e.state.isStreaming,ti.current=!!e.state.isPromptRunning,tn.current=!0,K(!0),eU(e.state.isStreaming?{kind:"waiting_model"}:{kind:"running_command"}),tN.current=!1,t$.current=null,U({type:"resume"}),t5(t.id),!e.state.isStreaming&&e.state.isPromptRunning&&ns(t.id)),e.state?.isBashRunning&&(tl.current=!0,J(!0),na(t.id))),e?.state&&(void 0!==e.state.isCompacting&&eA(e.state.isCompacting),void 0!==e.state.contextUsage&&eC(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&eM(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&ew(e.state.thinkingLevel??"auto"),void 0!==e.state.queuedMessages&&e8(r0(e.state.queuedMessages)))})),()=>{tR.current=!1,null!==tf.current&&(cancelAnimationFrame(tf.current),tf.current=null),null!==tg.current&&cancelAnimationFrame(tg.current),tg.current=null,tx.current=[],ta.current+=1,t2(),t4()}),[]),(0,i.useEffect)(()=>{p?.(eI)},[eI,p]),(0,i.useEffect)(()=>(g?.(t0),()=>g?.(null)),[t0,g]),(0,i.useEffect)(()=>{h&&h(j?.tree??[],E,nx)},[j?.tree,E,nx,h]),(0,i.useEffect)(()=>{let e=ty.current;if(e)return tp.current=e.scrollTop,e.addEventListener("scroll",nW,{passive:!0}),()=>{e.removeEventListener("scroll",nW)}},[R.length,C,nW]),(0,i.useLayoutEffect)(()=>{R.length>0&&(tu.current?(tu.current=!1,tc.current=!0,tD("instant")):tc.current?!tn.current&&th.current&&tD("auto"):(tc.current=!0,tD("instant")))},[R.length,q,tD]),(0,i.useEffect)(()=>{let e=new AbortController,t=tE.current!==u;return tE.current=u,(async()=>{for(let n=0;;n++)try{await nw(e.signal,t,u);return}catch(t){if(e.signal.aborted||t instanceof DOMException&&"AbortError"===t.name||n>=r2.length||(await r4(r2[n]),e.signal.aborted))return}})(),()=>e.abort()},[nw,u]),(0,i.useEffect)(()=>{if(!eB)return;let e=setTimeout(()=>eH(null),6e3);return()=>clearTimeout(e)},[eB]);let[nz,nP]=(0,i.useState)(null),nA=(0,i.useRef)(5e3),nD=(0,i.useRef)(null),nF=(0,i.useRef)(null);return(0,i.useEffect)(()=>{if(0===eY.visible.length){nF.current=null;return}let e=eY.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{eZ({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}let t=eY.visible[0];if(!t||(nF.current!==t.id&&(nF.current=t.id,nA.current=5e3),eY.visible.some(e=>e.id===nz)))return;nD.current=Date.now();let n=setTimeout(()=>{eZ({type:"mark_oldest_exiting"})},nA.current);return()=>{clearTimeout(n),null!==nD.current&&(nA.current=Math.max(0,nA.current-(Date.now()-nD.current)),nD.current=null)}},[eY.visible,nz]),(0,i.useEffect)(()=>{eX(null)},[R.length,eS?.tokens,eS?.percent,eS?.contextWindow]),{data:j,loading:C,error:M,activeLeafId:E,messages:R,activeToolResults:$,entryIds:z,historyCursor:A,hasEarlierMessages:F,streamState:O,agentRunning:q,directImageRunning:G,modelNames:en,modelList:ei,modelError:el,modelScopeWarnings:ea,modelThinkingLevels:ec,modelThinkingLevelMaps:eh,newSessionModel:ef,toolPreset:ey,thinkingLevel:eb,retryInfo:ek,contextUsage:eS,systemPrompt:eI,forkingEntryId:eT,isCompacting:eP,compactError:eD,compactResult:eB,currentModel:tF,displayModel:tB,modelSwitching:eW,sessionStats:tJ,slashCommands:e_,slashCommandsLoading:eK,queuedMessages:e4,notices:eY.visible,extensionDialog:eQ,extensionCustomUi:e1,respondToExtensionUi:t6,sendExtensionCustomInput:t3,isAutoModelSelection:m&&null===ef,agentPhase:eO,isNew:m,sessionIdRef:e9,scrollContainerRef:ty,initialScrollDoneRef:tc,handleSend:nc,handleDirectImageGeneration:nu,abortDirectImageGeneration:nh,handleAbort:np,handleFork:nf,handleNavigate:ng,handleModelChange:nv,handleCompact:nb,handleSteer:nI,handleFollowUp:nT,handlePromptWithStreamingBehavior:nM,handleAbortCompaction:nE,handleRecallQueue:nL,handleBuiltinSlashCommand:nS,addNotice:t7,setNoticePaused:nP,handleToolPresetChange:nN,handleThinkingLevelChange:nR,loadTools:tG,loadSlashCommands:t1,setActiveLeafId:L,setData:S,setMessages:N,loadContext:tZ,scrollToBottom:tD,scrollToMessage:n$,dispatch:U,setAgentRunning:K,setForkingEntryId:eE,bashRunning:V,pendingBash:Y,handleAgentEventRef:td}}({session:e,sessionRunning:a,newSessionCwd:d,newSessionDraftKey:c,onAgentEnd:et,onAttentionNeeded:en,onSessionCreated:v,onSessionForked:er,modelsRefreshKey:w,chatInputRef:X,onBranchDataChange:C,onSystemPromptChange:I,onSystemToolsChange:M,onSystemInfoLoaderChange:E,onSessionStatsPanelOpen:R,deferInitialScroll:!!ed}),tz=eI||eM||eT,tP=(0,i.useCallback)(()=>eM?tx():tm(),[tx,eM,tm]),tA=(0,i.useRef)(null),tD=e7?e7.tokens.input+e7.tokens.cacheRead+e7.tokens.cacheWrite:0,tF=e7&&tD>0?e7.tokens.cacheRead/tD*100:null,[tB,tH]=(0,i.useState)(null),tK=tu&&0===ev.length&&!eC.isStreaming&&!tz&&null===tB,[tV,tJ]=(0,i.useState)(!1),[tY,tG]=(0,i.useState)(null),[tX,tQ]=(0,i.useState)(!1),[t0,t1]=(0,i.useState)(null),[t2,t4]=(0,i.useState)(0),[t8,t5]=(0,i.useState)(null),[t6,t3]=(0,i.useState)(!1),[t7,t9]=(0,i.useState)(!1),[ne,nt]=(0,i.useState)(null),nn=(0,i.useRef)(null),nr=(0,i.useRef)(null),ni=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=new AbortController;return fetch("/api/image-generation",{signal:e.signal}).then(async e=>{let t=await e.json();e.ok&&t.available&&t.config?.connections.length?tG(t.config):(tG(null),tQ(!1),t1(null))}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load image generation config:",e)}),()=>e.abort()},[t2,w]);let no=(0,i.useCallback)(async t=>{el();let n=null;for(let e=ev.length-1;e>=0;e--){let t=eu(ev[e].details);if(t){n=t;break}}let r=e?.cwd??d,i=t.target,o=i&&(i.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(i)?i:r?N(r,i):i);tH({prompt:t.prompt,size:t.size,width:n?.width,height:n?.height,previewUrl:o?`/api/files/${T(o)}?type=read`:void 0});try{await tg(t)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;ts({type:"error",message:e instanceof Error?e.message:String(e)})}finally{tH(null)}},[ts,tg,el,ev,d,e?.cwd]),nl=(0,i.useCallback)(async e=>{let t=await tM(e);return!("error"in t)&&/^\/reload(?:\s|$)/.test(e.trim())&&t4(e=>e+1),t},[tM]),ns=(0,i.useCallback)(()=>{t5(null),t3(!1),nt(null)},[]);(0,i.useEffect)(()=>{A||ns()},[A,ns]);let na=(0,i.useCallback)(e=>{let t=ni.current;if(t&&!(null!=e&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)||!A||t6)return;let n=window.getSelection(),r=n?.rangeCount?n.getRangeAt(0):null,i=nS.current;if(!n||n.isCollapsed||!r||!i||!i.contains(r.commonAncestorContainer))return void t5(null);let o=n.toString().trim();if(!o)return void t5(null);let l=r.getBoundingClientRect(),s=[r.commonAncestorContainer.nodeType===Node.ELEMENT_NODE?r.commonAncestorContainer:r.commonAncestorContainer.parentElement,r.startContainer.nodeType===Node.ELEMENT_NODE?r.startContainer:r.startContainer.parentElement,r.endContainer.nodeType===Node.ELEMENT_NODE?r.endContainer:r.endContainer.parentElement].map(e=>e?.closest('[data-message-role="assistant"]')?.dataset.entryId).find(e=>!!e);t5({text:o,top:Math.min(window.innerHeight-44,l.bottom+8),left:Math.max(64,Math.min(window.innerWidth-64,l.left+l.width/2)),sourceEntryId:s})},[A,t6]);(0,i.useEffect)(()=>{t6&&t8&&nr.current?.insertIfEmpty(eq(t8.text,K("chat.quoteIntro"),K("chat.quoteQuestion")))},[t6,t8,K]),(0,i.useLayoutEffect)(()=>{let e=nn.current;if(!e||!t8)return;let t=window.visualViewport,n=()=>{let n=e.getBoundingClientRect(),r=t?.offsetTop??0,i=t?.offsetLeft??0;e.style.top=`${Math.max(r+8,Math.min(t8.top,r+(t?.height??window.innerHeight)-n.height-8))}px`,e.style.left=`${Math.max(i+8,Math.min(t8.left-n.width/2,i+(t?.width??window.innerWidth)-n.width-8))}px`};n();let r=new ResizeObserver(n);return r.observe(e),window.addEventListener("resize",n),t?.addEventListener("resize",n),t?.addEventListener("scroll",n),()=>{r.disconnect(),window.removeEventListener("resize",n),t?.removeEventListener("resize",n),t?.removeEventListener("scroll",n)}},[t8,t6,ne]),(0,i.useEffect)(()=>{if(!t8)return;let e=e=>{if(t6||nn.current?.contains(e.target))return;ni.current={x:e.clientX,y:e.clientY};let t=()=>{document.removeEventListener("pointerup",t),document.removeEventListener("pointercancel",t),queueMicrotask(()=>{ni.current=null})};document.addEventListener("pointerup",t),document.addEventListener("pointercancel",t),ns()},t=e=>{"Escape"===e.key&&!e.isComposing&&(e.preventDefault(),e.stopPropagation(),t7||ns())};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",t)}},[t8,t6,t7,ns]);let nd=(0,i.useCallback)(()=>{t8&&(X.current?.insertText(eq(t8.text,K("chat.quoteIntro"),K("chat.quoteQuestion"))),window.getSelection()?.removeAllRanges(),ns())},[t8,ns,K]),nc=(0,i.useCallback)(async t=>{let n=th.current??e?.id;if(!t7&&t.trim()&&t8?.sourceEntryId&&n&&P){t9(!0),nt(null),U?.();try{await P(t,n,t8.sourceEntryId),ns()}catch(e){nr.current?.restoreSubmission(t),nt(e instanceof Error?e.message:String(e))}finally{t9(!1)}}},[P,t8,t7,e?.id,th,ns,U]),nu=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(eg||ex||!D||nu.current)return;let t=th.current??e?.id;t&&(nu.current=!0,F?.(t),el(),tf(D))},[D,eg,ex,tf,F,el,e?.id,th]),(0,i.useEffect)(()=>{J&&tr&&ee.current!==tr.id&&(ee.current=tr.id,Y.current())},[J,tr]);let[nh,np]=(0,i.useState)(0),[nf,ng]=(0,i.useState)(50),nx=(0,i.useRef)(null),nv=(0,i.useRef)(null),nb=(0,i.useRef)({startIndex:0,endIndex:0,totalCount:0}),nw=(0,i.useRef)(null),nS=(0,i.useRef)(null),nC=(0,i.useRef)(null),nI=(0,i.useRef)(!1),nM=(0,i.useRef)(null),[nT,nE]=(0,i.useState)(null),nL=(0,i.useRef)(!1),nR=(0,i.useRef)(tN),n$=(0,i.useRef)(ed);n$.current=ed;let[nW,nz]=(0,i.useState)(null),nP=ev[ek.indexOf(nW?.entryId??"")],nA=nP?.role==="assistant"?nW?.blockIndex===void 0?nP.content.find(e=>"text"===e.type):nP.content[nW.blockIndex]:void 0,nD=(0,i.useRef)({entryIds:ek,historyCursor:ej,hasEarlierMessages:eS});nD.current={entryIds:ek,historyCursor:ej,hasEarlierMessages:eS},(0,i.useLayoutEffect)(()=>{let t=e?.id,n=tp.current,r=nS.current;if(t&&s&&n&&r)return()=>{if(n$.current)return;if(eV(n.scrollTop,n.clientHeight,n.scrollHeight))return void s(t,{atBottom:!0});let e=n.getBoundingClientRect().top,i=r7(Array.from(r.children).flatMap(e=>{if(!(e instanceof HTMLElement)||!e.dataset.entryId)return[];let t=e.getBoundingClientRect();return[{entryId:e.dataset.entryId,top:t.top,bottom:t.bottom}]}),e);i&&s(t,{atBottom:!1,...i,oldestEntryId:nD.current.historyCursor})}},[eg,s,tp,e?.id]),(0,i.useEffect)(()=>{t&&ec(null)},[t]);let nF=(0,i.useCallback)(async(e,t,n)=>{do await new Promise(e=>requestAnimationFrame(()=>e())),n.throwIfAborted();while(nI.current);nI.current=!0;try{let r=nD.current;await eG(e,{entryIds:r.entryIds,oldestEntryId:r.historyCursor,hasMore:r.hasEarlierMessages},e=>tR(t,tN,e,{signal:n}),n)}finally{nI.current=!1}},[tN,tR]),nB=(0,i.useRef)(nF);nB.current=nF;let nH=(0,i.useCallback)(()=>{let e=nb.current;np(e.totalCount-e.endIndex),ng(50)},[]);(0,i.useEffect)(()=>{let n=e?.id;if(!ed||!n||eg||t||nL.current)return;nL.current=!0,nM.current?.abort();let r=new AbortController;nM.current=r,nE(null),nz(null);let i=()=>{ep(!1),ec(null)};return(async()=>{try{if(await nB.current(ed.anchorEntryId,n,r.signal),r.signal.aborted)return void i();ep(!0)}catch(e){if(eX(e,r.signal))return void i();t$("instant"),ec(null)}})(),()=>{r.abort(),nM.current===r&&(nM.current=null),ec(null),ep(!1)}},[eg,ed,t$,t,e?.id]),(0,i.useLayoutEffect)(()=>{let e=nS.current;if(!ed||!e||t)return;let n=e.querySelector(`[data-entry-id="${CSS.escape(ed.anchorEntryId)}"]`);if(n){nH(),tW(n,ed.anchorOffset),ec(null);return}eh&&(t$("instant"),ec(null))},[ek,nH,ed,eh,t$,tW,t,nf,nh]),(0,i.useEffect)(()=>{if(!t||eg)return;nM.current?.abort();let e=new AbortController;nM.current=e,nE(null),nz(null);let n=t.sessionId;return(async()=>{try{if(await nB.current(t.entryId,n,e.signal),e.signal.aborted)return;nC.current=null,nz(t)}catch(n){if(eX(n,e.signal))return;ts({type:"warning",message:"other_branch"===(n instanceof eJ&&"exhausted"===n.reason?function(e,t,n){if(!t||!n)return"not_found";let r=eZ(t,n);return!r||r.some(t=>eY(t,e))?"not_found":eZ(t,e)?"other_branch":"not_found"}(t.entryId,ef?.tree,tN):"not_found")?K("chat.locateOtherBranch"):n instanceof eJ&&"stalled"===n.reason?K("chat.locateHistoryStalled"):n instanceof eJ&&"load_failed"===n.reason?K("chat.locateLoadFailed"):K("chat.locateNotFound")}),o?.(t)}})(),()=>{e.abort(),nM.current===e&&(nM.current=null)}},[tN,ts,ef?.tree,eg,o,t,K]),(0,i.useLayoutEffect)(()=>{var e;let n=nW?`[data-entry-id="${CSS.escape(nW.entryId)}"]`:null,r=n?tp.current?.querySelector(nP?.role==="user"?n:`${n} [data-search-target]`)??tp.current?.querySelector(n):null,i=(e={pending:nW??null,searchTarget:t??null,elementFound:!!r}).pending?e.pending!==e.searchTarget?"clear-stale":e.elementFound?"commit":"retry":"ignore";"ignore"===i||"retry"===i||("clear-stale"===i?nz(null):r&&nW&&(nH(),tW(r),r.animate([{backgroundColor:"var(--bg-selected)"},{backgroundColor:"transparent"}],{duration:2500}),nz(null),o?.(nW)))},[ek,nH,ev.length,nf,nW,t,nP,tp,tW,o,nh]),(0,i.useEffect)(()=>{np(0),ng(50)},[e?.id]),(0,i.useEffect)(()=>{let e=tp.current;e&&(tz||eC.isStreaming)&&eV(e.scrollTop,e.clientHeight,e.scrollHeight)&&np(0)},[tz,eC.isStreaming,tp]),(0,i.useEffect)(()=>{let e=tp.current;if(!e)return void tJ(!1);let t=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight;tJ(nh>0||t>160)},n=()=>{t(),nM.current||nh>0||eV(e.scrollTop,e.clientHeight,e.scrollHeight)&&(np(0),ng(50))};t();let r=new ResizeObserver(t);return r.observe(e),nS.current&&r.observe(nS.current),e.addEventListener("scroll",n,{passive:!0}),()=>{r.disconnect(),e.removeEventListener("scroll",n)}},[tK,eg,tp,e?.id,nh]);let nO=(0,i.useCallback)(()=>{if(nI.current||nM.current)return;let t=tp.current;if(nb.current.startIndex>0){let e=nS.current;if(e&&t){let n=t.getBoundingClientRect().top;nw.current=r7(Array.from(e.children).flatMap((e,t)=>{if(!(e instanceof HTMLElement))return[];let n=e.dataset.entryId||e.dataset.slotIndex||`slot-${t}`,r=e.getBoundingClientRect();return[{entryId:n,top:r.top,bottom:r.bottom}]}),n)}np(e=>e+25),ng(50);return}if(!eS||!ej)return;let n=e?.id??th.current;n&&(nI.current=!0,t&&(nC.current=t.scrollHeight-t.scrollTop),tR(n,tN,ej).finally(()=>{nI.current=!1}))},[ej,eS,e,tN,tR,th,tp]);(0,i.useEffect)(()=>{let e=nx.current,t=tp.current;if(!e||!t)return;let n=new IntersectionObserver(e=>{e[0]?.isIntersecting&&nO()},{root:t,threshold:0});return n.observe(e),()=>n.disconnect()},[nO,tp]),(0,i.useEffect)(()=>{let e=nv.current,t=tp.current;if(!e||!t)return;let n=new IntersectionObserver(e=>{e[0]?.isIntersecting&&!nM.current&&np(e=>Math.max(0,e-25))},{root:t,threshold:0});return n.observe(e),()=>n.disconnect()},[nh,tp]),(0,i.useLayoutEffect)(()=>{let e=nw.current,t=nS.current;if(!e||!t)return;let n=Array.from(t.children).find((t,n)=>t instanceof HTMLElement&&(t.dataset.entryId||t.dataset.slotIndex||`slot-${n}`)===e.anchorEntryId);n instanceof HTMLElement&&tW(n,e.anchorOffset),nw.current=null},[nh,tW]),(0,i.useEffect)(()=>{if(null==nC.current)return;let e=tp.current;if(e){var t;t=e.scrollHeight,e.scrollTop=Math.max(0,t-nC.current),nC.current=null}},[ev.length,tp]);let nU=e7?[e7.sessionId,e7.sessionFile??"",e7.sessionName??"",e7.userMessages,e7.assistantMessages,e7.toolCalls,e7.toolResults,e7.totalMessages,e7.tokens.input,e7.tokens.output,e7.tokens.cacheRead,e7.tokens.cacheWrite,e7.tokens.total,e7.cost??0,e7.totalActiveMs??0,e7.contextUsage?.percent??"null",e7.contextUsage?.contextWindow??"",e7.contextUsage?.tokens??"null"].join("|"):null,n_=(0,i.useRef)(e7);n_.current=e7,(0,i.useEffect)(()=>{eg||L?.(n_.current)},[eg,nU,L]),(0,i.useEffect)(()=>()=>{L?.(null)},[L]);let nq=e1?`${e1.percent??"null"}|${e1.contextWindow}|${e1.tokens??"null"}`:null,nK=(0,i.useRef)(e1);nK.current=e1,(0,i.useEffect)(()=>{eg||$?.(nK.current)},[nq,eg,$]),(0,i.useEffect)(()=>()=>{$?.(null)},[$]);let{isDragOver:nV,handleDragEnter:nJ,handleDragOver:nY,handleDragLeave:nZ,handleDrop:nG}=function(e){let[t,n]=(0,i.useState)(!1),r=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&(e.preventDefault(),r.current+=1,n(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{r.current-=1,r.current<=0&&(r.current=0,n(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),r.current=0,n(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,i.useCallback)(e=>{X.current?.addImages(e)},[])),nX=e?.cwd??d??void 0,nQ=(0,i.useMemo)(()=>ev.filter(e=>e$(e)||"assistant"===e.role||"toolResult"===e.role&&!e.isError&&eu(e.details)),[ev]),n0=(0,i.useMemo)(()=>{let e=new Map(eb);for(let t of ev)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[eb,ev]),n1=(0,i.useMemo)(()=>ev.map(e=>"assistant"===e.role?io(e):null),[ev]),n2=(0,i.useMemo)(()=>{let e=new Map;for(let t=0;t<ev.length;){let n=e$(ev[t])?t:-1,r=n>=0?t+1:t;for(;r<ev.length&&!e$(ev[r]);)r+=1;let i=ir(ev,n,r);if(i>=0&&n1[i]?.answerMessage){let t=[];for(let e=n+1;e<=i;e+=1){let n=ev[e];n?.role==="assistant"&&t.push(...n.content)}e.set(i,function(e,t,n){let r=new Set,i=[];for(let o of e){if("toolCall"!==o.type||!function(e){let t;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||e_(e)}(o.toolName))continue;let e=t?.get(o.toolCallId);if(!e||e.isError)continue;let l=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(o.input);if(!l)continue;let s=function(e,t){let n;if(!e)return null;let r=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),i=e=>r?e.replace(/\\/g,"/"):e,o=i(e),l=t?i(t).replace(/\/+$/,""):void 0,s=/^[a-zA-Z]:\//.test(o),a=o.startsWith("//");if(s||a)n=o;else if(o.startsWith("/")){let e=l?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??l?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];n=e?`${e}${o}`:o}else{if(!l)return null;n=`${l}/${o}`}return eO(n)}(l,n);s&&(r.has(s)||(r.add(s),i.push({filePath:s})))}return i}(t,n0,nX))}t=r}return e},[n1,nX,ev,n0]),n4=(0,i.useMemo)(()=>{let e=new Set,t=[];for(let n=ev.length-1;n>=0;n-=1){let r=function(e){if("user"!==e.role)return null;if("string"==typeof e.content){let t=e.content.trim();return t.length>0?t:null}let t=e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n").trim();return t.length>0?t:null}(ev[n]);if(!(!r||e.has(r))&&(e.add(r),t.push(r),t.length>=50))break}return t.reverse()},[ev]),n8=(_=nQ.length,(q=(0,i.useRef)([])).current=Array(_).fill(null).map((e,t)=>q.current[t]??null),q),n5=(0,i.useMemo)(()=>{for(let e=ev.length-1;e>=0;e--)if(ev[e]?.role==="user")return ek[e]??"";return""},[ek,ev]);(0,i.useEffect)(()=>{let e=nR.current;nR.current=tN,null!==e&&e!==tN&&(nM.current?.abort(),n$.current&&(ec(null),ep(!1)))},[tN]),(0,i.useEffect)(()=>()=>{nM.current?.abort()},[e?.id]);let n6=(0,i.useCallback)(async t=>{let n=e?.id??th.current;if(!n)return;nM.current?.abort();let r=new AbortController;nM.current=r,nE(null),nz(null);try{nC.current=null,nw.current=null,await nF(t,n,r.signal),r.signal.throwIfAborted(),await new Promise((e,n)=>{r.signal.addEventListener("abort",()=>n(r.signal.reason),{once:!0}),nE({entryId:t,signal:r.signal,resolve:e})})}catch(e){if(eX(e,r.signal))return;ts({type:"warning",message:e instanceof eJ&&"stalled"===e.reason?K("chat.locateHistoryStalled"):e instanceof eJ&&"load_failed"===e.reason?K("chat.locateLoadFailed"):K("chat.locateNotFound")})}finally{nE(e=>e?.signal===r.signal?null:e),nM.current===r&&(nM.current=null)}},[ts,nF,e?.id,th,K]);(0,i.useLayoutEffect)(()=>{if(!nT||nT.signal.aborted)return;let e=nS.current?.querySelector(`[data-entry-id="${CSS.escape(nT.entryId)}"]`);e&&(nH(),tW(e),nT.resolve())},[nT,ek,nH,ev.length,nf,nh,tW]);let n3=!!eC.streamingMessage?.content.length,n7=(0,i.useMemo)(()=>{let e=-1;for(let t=ev.length-1;t>=0;t--)if(e$(ev[t])){e=t;break}let t=e>=0&&eN(ev[e])?e:e+1;for(let e=t;e<ev.length;e++){let t=ev[e];if("custom"===t.role||"assistant"===t.role&&(ez(t).length>0||eP(t)))return!0}return!1},[ev]),n9=eC.streamingMessage?.role==="assistant"?eC.streamingMessage:null,re=n9?io(n9,{isStreaming:!0}):{processMessage:null,answerMessage:null},rt=(0,i.useRef)(j);(0,i.useLayoutEffect)(()=>{let e=rt.current;rt.current=j,!e&&j&&tz&&!tV&&t$("instant")},[j,tz,tV,t$]);let rn=e6?eB[`${e6.provider}:${e6.modelId}`]??null:null,rr=e6?eH[`${e6.provider}:${e6.modelId}`]??null:null,ri=(0,i.useCallback)(async(e,t)=>{el(),nM.current?.abort(),nE(null),nz(null),np(0),ng(50),await tf(e,t)},[tf,el]),ro=(0,i.useCallback)(e=>(el(),ty(e)),[ty,el]),rl=(0,i.useCallback)((e,t)=>(el(),tk(e,t)),[tk,el]),rs=(0,i.useCallback)((e,t)=>(el(),tj(e,t)),[tj,el]),ra=(0,i.useCallback)((e,t,n)=>(el(),tS(e,t,n)),[tS,el]),rd=!tu&&eg,rc=e?.relation?.kind==="subagent"&&"queued"===e.relation.status,ru=(0,r.jsx)(rg,{ref:Q,onSend:ri,onOpenImageGeneration:!tY||rd||tz||rc?void 0:()=>{t1(null),t4(e=>e+1),tQ(!0)},onAbort:tP,onSteer:eI?rl:void 0,onFollowUp:eI?rs:void 0,onPromptWithStreamingBehavior:eI?ra:void 0,isStreaming:tz||rc,disabled:rc,model:rd?null:e6,isAutoModelSelection:!rd&&td,modelNames:eL,modelList:eW,modelError:rd?null:eA,modelScopeWarnings:rd?[]:eF,onModelChange:rd||rc?void 0:tb,modelSwitching:e3,onCompact:!rc&&(e||tu)?tw:void 0,onAbortCompaction:tC,isCompacting:e4,compactError:e8,compactResult:e5,contextUsage:rd?null:e1,cacheHitRate:tF,onOpenSessionStats:R,toolPreset:eU,onToolPresetChange:!rc&&(e||tu)?tT:void 0,thinkingLevel:rd?void 0:eQ,onThinkingLevelChange:rd||rc?void 0:e||tu?tE:void 0,availableThinkingLevels:rn,thinkingLevelMap:rr,retryInfo:e0,queuedMessages:tt,inputHistory:n4,onRecallQueue:tI,slashCommands:e9,slashCommandsLoading:te,onLoadSlashCommands:tL,onBuiltinCommand:nl,soundEnabled:B,onSoundToggle:H,onAudioUnlock:U,draftKey:e?.id??c??void 0,onDraftChange:u,draftPersistenceWarning:f,cwd:e?.cwd??d});return eg?(0,r.jsxs)("div",{className:"chat-content relative flex h-full min-w-0 flex-col overflow-hidden",style:{paddingBottom:"env(safe-area-inset-bottom)"},children:[(0,r.jsx)("div",{className:"relative flex min-h-0 min-w-0 flex-1 items-center justify-center",children:(0,r.jsx)("div",{className:"text-sm text-text-muted",children:K("chat.loadingSession")})}),(0,r.jsx)("div",{className:"relative shrink-0",children:ru})]}):ex?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:ex}):(0,r.jsxs)("div",{className:"chat-content relative flex h-full min-w-0 flex-col overflow-hidden",style:{paddingBottom:"env(safe-area-inset-bottom)"},onDragEnter:nJ,onDragOver:nY,onDragLeave:nZ,onDrop:nG,children:[nV&&(0,r.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,r.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,r.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${e}s`}},e))}),(0,r.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,r.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,r.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,r.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,r.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,r.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,r.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,r.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,r.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,r.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,r.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,r.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,r.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),(0,r.jsx)("div",{className:"notice-shelf-wrapper",style:{position:"absolute",top:12,left:0,right:0,zIndex:40,display:"flex",justifyContent:"flex-end",padding:"0 16px",pointerEvents:"none"},children:(0,r.jsx)(iy,{notices:tn,floating:!0,onPauseChange:ta})}),(0,r.jsxs)("div",{className:"relative flex min-h-0 min-w-0 flex-1 overflow-hidden",children:[tX&&tY&&(0,r.jsx)(ew,{config:tY,edit:t0,editPreviewUrl:t0?`/api/files/${T(t0.path.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(t0.path)?t0.path:nX?N(nX,t0.path):t0.path)}?type=read`:void 0,onClose:()=>{tQ(!1),t1(null)},onSubmit:no}),tr&&(0,r.jsx)(iv,{request:tr,onRespond:to},tr.id),ti&&(0,r.jsx)(ib,{request:ti,onInput:tl},ti.id),!tK&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{ref:tp,className:"min-w-0 flex-1 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none]",style:{visibility:ed?"hidden":void 0},children:(0,r.jsx)("div",{style:{minWidth:0,padding:"0 16px"},children:(0,r.jsxs)("div",{ref:nS,onPointerUp:na,style:{width:"100%",minWidth:0,maxWidth:"var(--chat-content-max-width, 820px)",margin:"0 auto"},children:[(()=>{var n,i;let o=-1;for(let e=ev.length-1;e>=0;e--)if(e$(ev[e])){o=e;break}let l=new Map,s=0;ev.forEach((e,t)=>{let n=("toolResult"!==e.role||e.isError)&&("custom"!==e.role||e.customType!==ei)?null:eu(e.details);(e$(e)||"assistant"===e.role||n)&&l.set(t,s++)});let a=(t,n={})=>{var i,o;let s,a,d,c=n.messageOverride??ev[t],u="user"===c.role&&t>0&&"assistant"===ev[t-1].role?ek[t-1]:void 0,h=("toolResult"!==c.role||c.isError)&&("custom"!==c.role||c.customType!==ei)?null:eu(c.details),p=e$(c)||"assistant"===c.role||!!h,f=l.get(t),g=n.keyPrefix??"message",x=ek[t]??t,m=h?(0,r.jsx)(em,{value:h,cwd:nX,onEdit:tY&&!tz&&tY.connections.some(e=>e.id===h.connection&&!0===e.capabilities.editing)?e=>{t1(e),t4(e=>e+1),tQ(!0)}:void 0,onMention:tY?e=>{X.current?.mentionImage(e)}:void 0,showPrompt:"custom"===c.role,createdAt:c.timestamp},`${g}-image-${x}`):(0,r.jsx)(tZ,{message:c,modelName:n.isTurnEnd&&"assistant"===c.role?(i=c.provider??"",o=c.model??"",s=i.toLowerCase(),a=o.toLowerCase(),d=Object.entries(eL??{}).flatMap(([e,t])=>{let n=e.indexOf(":");return n>0&&e.slice(0,n).toLowerCase()===s?[{id:e.slice(n+1).toLowerCase(),name:t}]:[]}),d.find(e=>e.id===a)?.name??d.find(e=>a.endsWith(`/${e.id}`))?.name??Object.entries(eL??{}).find(([e])=>e.toLowerCase()===a)?.[1]??(i&&o?`${i}/${o}`:o)):void 0,toolResults:n0,cwd:nX,onOpenFile:eo,onOpenSession:z,entryId:ek[t],searchBlock:ek[t]===nW?.entryId?nA:void 0,onFork:tz||tu?void 0:ro,forking:e2===ek[t],onNavigate:tz?void 0:tv,prevAssistantEntryId:tz?void 0:u,onEditContent:es,isTurnEnd:n.isTurnEnd,sessionId:e?.id??th.current??void 0,writtenFiles:n.writtenFiles,isProcess:n.isProcess},`${g}-view-${x}`);return p?(0,r.jsx)("div",{"data-entry-id":ek[t],"data-slot-index":`msg-${t}`,ref:!1===n.attachRef||void 0===f?void 0:e=>{n8.current[f]=e},children:m},`${g}-${x}`):m},d=(n={outline:nT?{entryId:nT.entryId,aborted:nT.signal.aborted}:null,search:nW?{entryId:nW.entryId,matchesTarget:nW===t}:null,restore:ed?{entryId:ed.anchorEntryId}:null}).outline&&!n.outline.aborted?n.outline.entryId:n.search&&n.search.matchesTarget?n.search.entryId:n.restore?n.restore.entryId:null,c=[],u=-1,h=e=>{var t,n;t=u,n=c.length,u=d&&e.includes(d)?n:t},p=0;for(let e=0;e<ev.length;){let t,n,i,s=e$(ev[e]),u=eR(ev[e]),f=s?e:-1,g=f>=0&&eN(ev[f]),x=s?e+1:e;for(;x<ev.length&&!e$(ev[x]);)x+=1;let m=s?f:e,y=g?f:f+1,v=ir(ev,f,x),b=(tz||eC.isStreaming)&&x===ev.length&&f===o;if(b&&(p=x-m),-1===v&&!g){for(let e=m;e<x;e++)h([ek[e]]),c.push(a(e));if(b&&re.processMessage){h([]);let e=is(!0,eC.isStreaming,n9,tc,!!re.answerMessage),t=f>=0&&"number"==typeof ev[f]?.timestamp&&Number.isFinite(ev[f].timestamp)?ev[f].timestamp:re.processMessage.timestamp,n=iu(t,re.processMessage.completedAt);c.push((0,r.jsx)("div",{children:(0,r.jsx)(ig,{messageCount:1,toolCallCount:eD(re.processMessage.content??[]),durationSeconds:n,startTime:t,defaultExpanded:!0,isMobile:V,activeStepSummary:ic(id(re.processMessage,tc,K),e,tA,K("chat.thinking")),isStreaming:e,t:K,children:(0,r.jsx)(tZ,{message:re.processMessage,isStreaming:!0,isProcess:!0,toolResults:n0,cwd:nX,onOpenFile:eo,onOpenSession:z},"streaming-process-view")})},`process-group-${ek[m]??m}`))}e=x;continue}u&&(h([ek[f]]),c.push(a(f)));let w=n1[v],k=w?.answerMessage??null,j=v>=0?v:x-1,S=[],C=[],I=0,M=!1;for(let e=y;e<=j;e++){let r=ev[e];if("number"==typeof r.timestamp&&Number.isFinite(r.timestamp)&&(n=void 0===n?r.timestamp:Math.min(n,r.timestamp),i=void 0===i?r.timestamp:Math.max(i,r.timestamp)),"assistant"===r.role&&"number"==typeof r.completedAt&&Number.isFinite(r.completedAt)&&(i=void 0===i?r.completedAt:Math.max(i,r.completedAt)),"custom"===r.role){t??=l.get(e),M||=!!(d&&d===ek[e]),ek[e]&&C.push(ek[e]),S.push(a(e,{attachRef:!1,keyPrefix:"process",isProcess:!0}));continue}if("assistant"!==r.role)continue;let o=e===v?w?.processMessage:r;if(!o)continue;let s=ez(o),c=!!eP(o);(0!==s.length||c)&&(t??=l.get(e),I+=eD(s),M||=!!(d&&ek[e]===d&&(!nA||nW?.entryId!==d||s.includes(nA))),ek[e]&&C.push(ek[e]),S.push(a(e,{attachRef:!1,keyPrefix:"process",messageOverride:o,isTurnEnd:!1,isProcess:!0})))}b&&re.processMessage&&S.push((0,r.jsx)(tZ,{message:re.processMessage,isStreaming:!0,isProcess:!0,toolResults:n0,cwd:nX,onOpenFile:eo,onOpenSession:z},"streaming-process-view"));let T=!!(k||re.answerMessage),E=is(b,eC.isStreaming,n9,tc,T),L=ic(id(n9,tc,K),E,tA,K("chat.thinking")),R=f>=0&&"number"==typeof ev[f]?.timestamp&&Number.isFinite(ev[f].timestamp)?ev[f].timestamp:n,N=iu(R??n,i);S.length>0&&(h(C),c.push((0,r.jsx)("div",{"data-entry-id":ek[y],ref:void 0===t?void 0:e=>{n8.current[t]=e},children:(0,r.jsx)(ig,{messageCount:S.length,toolCallCount:I,durationSeconds:N,startTime:R??n,defaultExpanded:!k&&x===ev.length,reveal:M,isMobile:V,activeStepSummary:L,isStreaming:E,t:K,children:S})},`process-group-${ek[m]??m}`)));for(let e=m;e<=j;e++){let t=ev[e];"toolResult"===t.role&&!t.isError&&eu(t.details)&&(h([ek[e]]),c.push(a(e)))}if(k&&(h([ek[v]]),c.push(a(v,{isTurnEnd:!0,messageOverride:k,writtenFiles:n2.get(v)}))),v>=0)for(let e=v+1;e<x;e++)h([ek[e]]),c.push(a(e));e=x}let f=Math.max(nf,50+p),{startIndex:g,endIndex:x}=u>=0?eK(i=c.length,i-Math.max(0,u-5)-50):eK(c.length,nh,f);nb.current={startIndex:g,endIndex:x,totalCount:c.length};let m=g>0||eS;return(0,r.jsxs)(r.Fragment,{children:[m&&(0,r.jsx)("button",{type:"button",ref:nx,onClick:nO,className:"w-full cursor-pointer py-3 text-center text-xs text-text-muted transition-colors hover:text-text focus-visible:outline-2 focus-visible:outline-accent",children:K("chat.loadEarlier")}),c.slice(g,x),x<c.length&&(0,r.jsx)("div",{ref:nv,className:"py-3 text-center text-xs text-text-muted"})]})})(),eC.isStreaming&&re.answerMessage&&(0,r.jsx)(tZ,{message:re.answerMessage,isStreaming:!0,cwd:nX,onOpenFile:eo,onOpenSession:z}),eI&&!n3&&!n7&&(0,r.jsx)(r9,{label:K("chat.agentWorking")}),eT&&!eE&&(0,r.jsx)(r9,{label:K("chat.agentWorking")}),eE&&(0,r.jsx)(tZ,{message:{role:"bashExecution",command:eE.command,output:"",excludeFromContext:eE.excludeFromContext},sessionId:e?.id??th.current??void 0,onOpenSession:z}),tB&&(0,r.jsx)(ey,{prompt:tB.prompt,size:tB.size,width:tB.width,height:tB.height,previewUrl:tB.previewUrl})]})})}),tV&&!ed&&(0,r.jsx)("button",{type:"button",onClick:()=>{nM.current?.abort(),nE(null),nz(null),np(0),ng(50),requestAnimationFrame(()=>t$("smooth"))},className:"absolute bottom-3 right-5 z-30 inline-flex h-7 w-7 items-center justify-center rounded-[4px] border border-[var(--border)] bg-[var(--bg)] text-[var(--text-muted)] transition-colors hover:bg-[var(--bg-hover)] hover:text-[var(--text)] focus-visible:outline-2 focus-visible:outline-[var(--accent)]",title:K("chat.scrollToBottom"),"aria-label":K("chat.scrollToBottom"),children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m7 10 5 5 5-5"})})}),!S||V||ed?null:(0,r.jsx)(rb,{sessionId:e?.id??th.current,leafId:tN,outlineRevision:n5,scrollContainer:tp,contentContainer:nS,loadedEntryIds:ek,onJumpToEntry:n6})]})]}),A&&t8&&(0,m.createPortal)((0,r.jsx)("div",{ref:nn,role:t6?"dialog":"toolbar","aria-label":K(t6?"chat.newQuoteChat":"chat.askSelection"),style:{position:"fixed",top:t8.top,left:t8.left,zIndex:130,display:"flex",flexWrap:"wrap",gap:2,width:t6?"min(420px, calc(100vw - 16px))":void 0,maxWidth:"calc(100vw - 16px)",maxHeight:"calc(var(--app-viewport-height, 100dvh) - 16px)",overflowY:"auto",padding:t6?12:2,border:"1px solid var(--border)",borderRadius:4,background:"var(--bg)"},children:t6?(0,r.jsxs)("fieldset",{disabled:t7,"aria-busy":t7,style:{width:"100%",minWidth:0,margin:0,padding:0,border:"none",display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,fontWeight:600},children:K("chat.askInNewChat")}),(0,r.jsx)("button",{type:"button",className:"file-viewer-icon-button",title:K("i18n.close"),"aria-label":K("i18n.close"),disabled:t7,onClick:ns,style:{border:"none"},children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m6 6 12 12M18 6 6 18"})})})]}),(0,r.jsx)(rg,{ref:nr,compact:!0,onSend:nc,onAbort:ns,isStreaming:!1}),ne&&(0,r.jsx)("div",{role:"alert",style:{color:"#dc2626",fontSize:12,overflowWrap:"anywhere"},children:ne})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",className:"inline-flex h-6 shrink-0 cursor-pointer items-center gap-1 rounded-[4px] border-0 bg-transparent px-2 text-[11px] font-medium text-[var(--text-muted)] hover:bg-[var(--bg-hover)] hover:text-[var(--text)] focus-visible:outline-2 focus-visible:outline-[var(--accent)]",title:K("chat.askInCurrent"),"aria-label":K("chat.askInCurrent"),onPointerDown:e=>e.preventDefault(),onClick:nd,children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"@"}),(0,r.jsx)("span",{children:K("chat.askInCurrent")})]}),P&&t8.sourceEntryId&&!tz&&(0,r.jsxs)("button",{type:"button",className:"inline-flex h-6 shrink-0 cursor-pointer items-center gap-1 rounded-[4px] border-0 bg-transparent px-2 text-[11px] font-medium text-[var(--text-muted)] hover:bg-[var(--bg-hover)] hover:text-[var(--text)] focus-visible:outline-2 focus-visible:outline-[var(--accent)]",title:K("chat.askInNewChat"),"aria-label":K("chat.askInNewChat"),onPointerDown:e=>e.preventDefault(),onClick:()=>{t3(!0),window.getSelection()?.removeAllRanges()},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M6 3v12M18 9a9 9 0 0 1-9 9"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"})]}),(0,r.jsx)("span",{children:K("chat.askInNewChat")})]})]})}),document.body),(0,r.jsxs)("div",{className:"relative shrink-0",children:[tK&&(0,r.jsxs)("div",{className:"mx-auto mb-6 flex select-none flex-col items-center justify-center text-center",style:{maxWidth:"var(--chat-content-max-width, 820px)",padding:"0 16px"},children:[(0,r.jsxs)("div",{style:{display:"inline-flex",alignItems:"baseline",gap:V?7:10,fontFamily:"var(--font-mono)",lineHeight:1.4},children:[(0,r.jsx)("span",{style:{fontSize:28,fontWeight:700,color:"var(--text)",flexShrink:0,whiteSpace:"nowrap"},children:"π"}),(0,r.jsx)("span",{style:{fontSize:22,fontWeight:700,color:"var(--text)",flexShrink:0,whiteSpace:"nowrap"},children:"Pi Web"}),(0,r.jsx)(it,{label:e=>K("appUpdate.releaseNotes",{version:e})})]}),d&&p&&(0,r.jsx)(ie,{cwd:d,onChange:p})]}),ru]}),tK&&(0,r.jsx)("div",{className:"min-h-0 flex-1"})]})}function im({type:e}){return"success"===e?(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#10b981",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:2},children:(0,r.jsx)("path",{d:"M20 6 9 17l-5-5"})}):"error"===e?(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#ef4444",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:2},children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,r.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}):"warning"===e?(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#d97706",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:2},children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}):(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,marginTop:2},children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,r.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function iy({notices:e,floating:t=!1,onPauseChange:n}){return 0===e.length?null:(0,r.jsx)("div",{className:"notice-shelf-root",style:{display:"flex",flexDirection:"column",alignItems:"flex-end",marginBottom:10*!t},children:e.map((i,o)=>(0,r.jsxs)("div",{className:"notice-shelf-item",onMouseEnter:()=>n?.(i.id),onMouseLeave:e=>{e.currentTarget.contains(document.activeElement)||n?.(null)},onFocus:()=>n?.(i.id),onBlur:e=>{e.currentTarget.matches(":hover")||n?.(null)},style:{display:"flex",alignItems:"flex-start",gap:8,minHeight:34,height:"auto",maxHeight:500,pointerEvents:"auto",marginBottom:6*(o!==e.length-1),overflow:"hidden",borderRadius:8,border:"1px solid var(--border)",background:"color-mix(in srgb, var(--bg) 95%, var(--bg-panel))",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"var(--text)",width:"fit-content",maxWidth:"min(100%, 540px)",boxShadow:t?"0 4px 16px -2px rgba(0, 0, 0, 0.12), 0 2px 6px -1px rgba(0, 0, 0, 0.06)":"0 2px 8px -2px rgba(0, 0, 0, 0.08)",fontSize:13,lineHeight:1.45,transformOrigin:"top right",animation:i.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out backwards",padding:"8px 12px"},children:[(0,r.jsx)(im,{type:i.type}),(0,r.jsx)("span",{tabIndex:0,style:{minWidth:0,maxWidth:"100%",maxHeight:480,overflowY:"auto",scrollbarWidth:"thin",whiteSpace:"pre-line",wordBreak:"break-word"},children:i.message})]},i.id))})}function iv({request:e,onRespond:t}){let{t:n}=(0,x.s)(),[o,l]=(0,i.useState)("editor"===e.method?e.prefill??"":""),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(()=>Date.now()),u=(0,i.useCallback)(e=>e?.focus(),[]),h=function(e){if("select"===e.method&&e.options.length>0)return e.options[0];if("confirm"===e.method){let t=e.message.split("\n").find(e=>e.trim());return t?.trim()}}(e),p=void 0===e.expiresAt?null:Math.max(0,Math.ceil((e.expiresAt-d)/1e3));(0,i.useEffect)(()=>{if(void 0===e.expiresAt)return;let t=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(t)},[e.expiresAt]);let f=null!==p&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap",flexShrink:0},children:n("chat.extensionExpiresIn",{seconds:p})}),g=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:o})};return(0,r.jsx)("div",{onKeyDown:n=>{"Escape"!==n.key||n.nativeEvent.isComposing||(n.preventDefault(),n.stopPropagation(),t(e,{cancelled:!0}))},style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:s?"flex-start":"center",justifyContent:"center",padding:20,pointerEvents:"none"},children:s?(0,r.jsxs)("button",{type:"button",onClick:()=>a(!1),"aria-expanded":!1,style:{pointerEvents:"auto",display:"flex",alignItems:"center",gap:10,maxWidth:"min(560px, 100%)",width:"100%",padding:"10px 12px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg)",boxShadow:"0 12px 32px rgba(0,0,0,0.18)",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:650,color:"var(--accent)",flexShrink:0},children:n("chat.extensionPending")}),(0,r.jsx)("span",{style:{fontSize:13,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:e.title}),h&&(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"34%",flexShrink:1},children:h}),f,(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",flexShrink:0},children:n("chat.extensionExpand")})]}):(0,r.jsxs)("div",{role:"dialog","aria-label":e.title,style:{pointerEvents:"auto",width:"min(560px, 100%)",maxHeight:"min(760px, 100%)",display:"flex",flexDirection:"column",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{flexShrink:0,display:"flex",alignItems:"flex-start",gap:8,padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{children:n("chat.extensionRequest")}),f]})]}),(0,r.jsx)("button",{type:"button",onClick:()=>a(!0),"aria-expanded":!0,title:n("chat.extensionCollapse"),"aria-label":n("chat.extensionCollapse"),style:{display:"grid",placeItems:"center",width:28,height:28,borderRadius:4,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})})]}),(0,r.jsxs)("div",{style:{padding:14,flex:"1 1 auto",minHeight:0,overflowY:"auto"},children:["confirm"===e.method&&(0,r.jsx)(tR,{children:e.message}),"select"===e.method&&(0,r.jsx)("div",{onKeyDown:e=>{if(!["ArrowDown","ArrowRight","ArrowUp","ArrowLeft","Home","End"].includes(e.key))return;let t=Array.from(e.currentTarget.querySelectorAll("[data-extension-option]")),n=t.indexOf(e.target);if(n<0)return;e.preventDefault();let r="Home"===e.key?0:"End"===e.key?t.length-1:(n+("ArrowDown"===e.key||"ArrowRight"===e.key?1:-1)+t.length)%t.length;t[r].focus({preventScroll:!0}),t[r].scrollIntoView({block:"nearest"})},style:{display:"grid",gap:8},children:e.options.map((n,i)=>(0,r.jsx)("div",{role:"button",tabIndex:0,"data-extension-option":!0,"aria-label":n,ref:0===i?u:void 0,onClick:()=>t(e,{value:n}),onKeyDown:r=>{("Enter"===r.key||" "===r.key)&&(r.preventDefault(),t(e,{value:n}))},style:{width:"100%",padding:"9px 10px",borderRadius:4,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13,overflowWrap:"anywhere"},children:(0,r.jsx)("div",{inert:!0,children:(0,r.jsx)(tR,{children:n})})},n))}),"input"===e.method&&(0,r.jsx)("input",{autoFocus:!0,value:o,placeholder:e.placeholder,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||g()},style:{width:"100%",padding:"9px 10px",borderRadius:4,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,r.jsx)("textarea",{autoFocus:!0,value:o,onChange:e=>l(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&!e.nativeEvent.isComposing&&g()},style:{width:"100%",minHeight:220,padding:10,borderRadius:4,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,r.jsxs)("div",{style:{flexShrink:0,display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,r.jsx)("button",{autoFocus:"confirm"===e.method||"select"===e.method&&0===e.options.length,onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:4,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:n("chat.cancel")}),"confirm"===e.method?(0,r.jsx)("button",{onClick:g,style:{padding:"6px 10px",borderRadius:4,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:n("chat.confirm")}):"select"!==e.method?(0,r.jsx)("button",{onClick:g,style:{padding:"6px 10px",borderRadius:4,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:n("chat.submit")}):null]})]})})}function ib({request:e,onInput:t}){let{t:n}=(0,x.s)(),o=(0,i.useRef)(null),l=(0,i.useRef)(!1),[s,a]=(0,i.useState)(!1),d=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,n=[];for(let r of e){let e=r.replace(eS,""),i=eC(e).trimEnd();if(t.test(i))continue;let o=e,l=eT(o);("│"===l||"┃"===l)&&" "===eT(o=eM(o,0))&&(o=eM(o,0));let s=function(e){let t=eI(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(o),a=s>=0?eI(o)[s]?.char:void 0;("│"===a||"┃"===a)&&(o=eM(o,s)),n.push(function(e){let t=e;for(;;){let e=eI(t),n=e[e.length-1];if(!n||""!==n.char.trim())return t;t=t.slice(0,n.start)+t.slice(n.end)}}(o))}for(;n.length>0&&""===eC(n[0]).trim();)n.shift();for(;n.length>0&&""===eC(n[n.length-1]).trim();)n.pop();return n.length?n:e}(e.lines),c=d.find(e=>e.trim())?.trim();return(0,i.useEffect)(()=>{s||o.current?.focus()},[s]),(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:s?"flex-start":"center",justifyContent:"center",padding:20,pointerEvents:"none"},children:s?(0,r.jsxs)("button",{type:"button",onClick:()=>a(!1),"aria-expanded":!1,style:{pointerEvents:"auto",display:"flex",alignItems:"center",gap:10,maxWidth:"min(920px, 100%)",width:"100%",padding:"10px 12px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg)",boxShadow:"0 12px 32px rgba(0,0,0,0.18)",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:650,color:"var(--accent)",flexShrink:0},children:n("chat.extensionPending")}),(0,r.jsx)("span",{style:{fontSize:13,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:n("chat.extensionPanel")}),c&&(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"34%",flexShrink:1},children:c}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",flexShrink:0},children:n("chat.extensionExpand")})]}):(0,r.jsxs)("div",{role:"dialog",onClick:e=>{e.target.closest("button")||o.current?.focus()},style:{pointerEvents:"auto",position:"relative",width:"min(920px, 100%)",maxHeight:"min(760px, 100%)",display:"flex",flexDirection:"column",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,r.jsx)("textarea",{ref:o,"aria-label":n("chat.extensionInput"),autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,onKeyDown:n=>{if(l.current||n.nativeEvent.isComposing)return;let r=function(e){if(e.metaKey||e.ctrlKey&&!e.altKey&&"v"===e.key.toLowerCase())return null;if(e.ctrlKey&&!e.altKey){let t=function(e){if(1!==e.length)return null;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(31&t):"?"===e?"":null}(e.key);if(t)return t}if(e.altKey&&!e.ctrlKey){if("Backspace"===e.key)return"\x1b\x7f";let t=eL[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":" ":eE[e.key]??null}(n);r&&(n.preventDefault(),n.stopPropagation(),t(e,r))},onInput:n=>{if(l.current||n.nativeEvent.isComposing)return;let r=n.currentTarget.value;n.currentTarget.value="",r&&t(e,r)},onCompositionStart:()=>{l.current=!0},onCompositionEnd:n=>{l.current=!1;let r=n.currentTarget;queueMicrotask(()=>{let n=r.value;r.value="",n&&t(e,n)})},onPaste:n=>{n.preventDefault();let r=n.clipboardData.getData("text");r&&t(e,`\x1b[200~${r}\x1b[201~`)},style:{position:"absolute",width:1,height:1,padding:0,border:0,opacity:0,pointerEvents:"none"}}),(0,r.jsxs)("div",{style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:n("chat.extensionPanel")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("button",{type:"button",onClick:()=>a(!0),"aria-expanded":!0,title:n("chat.extensionCollapse"),"aria-label":n("chat.extensionCollapse"),style:{display:"grid",placeItems:"center",width:28,height:28,borderRadius:4,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),(0,r.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:4,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:n("chat.close")})]})]}),(0,r.jsx)("pre",{style:{margin:0,padding:14,minHeight:0,overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(0,r.jsx)(rk,{text:d.join("\n")})})]})})}function iw({tabs:e,activeTabId:t,splitTabId:n=null,activePane:o="primary",runningSessionIds:l,onSelectTab:s,onCloseTab:a,onPinTab:d,onNewTab:c,onToggleSplit:u,onClosePane:h,canSplit:p=!0,isSecondaryPane:f=!1,unifiedHeader:g=!1,isMobile:y=!1}){let{t:v}=(0,x.s)(),[b,w]=(0,i.useState)(null),[k,j]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),[I,M]=(0,i.useState)({top:0,left:0,width:320}),T=(0,i.useRef)(null),E=(0,i.useRef)(null),L=(0,i.useRef)(null),R=(0,i.useRef)(null);(0,i.useEffect)(()=>{T.current&&T.current.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})},[t]),(0,i.useEffect)(()=>{let e=E.current;if(!e)return;let t=()=>j(e.scrollWidth>e.clientWidth+1);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[e]),(0,i.useEffect)(()=>{if(!S)return;let e=e=>{let t=e.composedPath();R.current&&t.includes(R.current)||L.current&&t.includes(L.current)||C(!1)},t=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),C(!1),L.current?.focus())},n=()=>C(!1);return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),window.addEventListener("resize",n),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0),window.removeEventListener("resize",n)}},[S]),(0,i.useEffect)(()=>{k||C(!1)},[k]);let N=p&&!y,$=!!(n&&!y),W=e=>{let t=e?Array.from(document.querySelectorAll("[data-chat-tab-id]")).find(t=>t.dataset.chatTabId===e):null,n=T.current??document.querySelector('[data-chat-tab="true"][tabindex="0"]'),r=Array.from(document.querySelectorAll(".chat-input-textarea")).find(e=>e.getClientRects().length>0);(t??n??r)?.focus()};return(0,r.jsxs)("div",{role:"tablist","aria-label":v("chatTabs.label",{defaultValue:"对话标签"}),style:{display:"flex",alignItems:"stretch",background:g?"transparent":"var(--bg-panel)",borderBottom:g?"none":"1px solid var(--border)",height:"var(--workspace-header-height, 30px)",minHeight:"var(--workspace-header-height, 30px)",maxHeight:"var(--workspace-header-height, 30px)",width:g?"auto":"100%",maxWidth:"100%",minWidth:0,flex:g?"0 1 auto":"0 0 auto",flexShrink:0,overflow:"hidden",position:"relative"},children:[(0,r.jsx)("div",{ref:E,onWheel:e=>{e.deltaY&&!e.deltaX&&(e.currentTarget.scrollLeft+=e.deltaY)},style:{display:"flex",alignItems:"stretch",flex:"0 1 auto",minWidth:0,overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",WebkitOverflowScrolling:"touch",touchAction:"pan-x",overscrollBehaviorX:"contain"},children:e.map((i,c)=>{let u=i.id===t,h=i.id===n,p=u||h,f=u&&"primary"===o||h&&"secondary"===o,g="session"===i.kind&&!!(i.session&&l?.has(i.session.id));return(0,r.jsxs)("div",{"data-chat-tab":"true","data-chat-tab-id":i.id,ref:u?T:void 0,role:"tab","aria-label":i.dirty?`${i.title}, ${v("chatTabs.unsentDraft")}`:i.title,"aria-selected":p,tabIndex:f||!t&&0===c?0:-1,onClick:()=>s(i.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:e=>{1===e.button&&(e.preventDefault(),e.stopPropagation(),a(i.id))},onDoubleClick:()=>d?.(i.id),onKeyDown:t=>{if(t.target===t.currentTarget){if("Enter"===t.key||" "===t.key)t.preventDefault(),s(i.id);else if(["ArrowLeft","ArrowRight"].includes(t.key)){t.preventDefault();let n=(c+("ArrowRight"===t.key?1:-1)+e.length)%e.length;s(e[n].id),t.currentTarget.parentElement?.children[n]?.focus()}else if("Delete"===t.key){if(t.preventDefault(),!1===a(i.id))return;requestAnimationFrame(()=>{W()})}}},style:{display:"flex",alignItems:"center",gap:y?4:6,height:"100%",paddingLeft:y?8:10,paddingRight:y?p?4:8:4,borderRight:"1px solid var(--border)",background:p?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:p?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:y?130:200,minWidth:y?70:84,flexShrink:0,userSelect:"none",WebkitUserSelect:"none",touchAction:"pan-x",position:"relative",transition:"background 0.12s, color 0.12s",boxShadow:f?"inset 0 -2px 0 var(--accent)":void 0},title:i.preview?`${i.title} \xb7 ${v("chatTabs.previewTabHint",{defaultValue:"预览标签,双击固定"})}`:i.title,children:[(g||"draft"===i.kind)&&(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",color:g?"var(--accent)":p?"var(--text)":"var(--text-dim)"},children:g?(0,r.jsx)(_,{size:12,ariaLabel:"Running"}):(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:p?500:400,fontStyle:i.preview?"italic":"normal"},children:i.title}),"draft"===i.kind&&i.dirty&&(0,r.jsx)("span",{title:v("chatTabs.unsentDraft"),"aria-hidden":"true",style:{width:5,height:5,borderRadius:"50%",background:"var(--accent)",flexShrink:0}}),(!y||p)&&(0,r.jsx)("button",{type:"button",tabIndex:-1,onClick:e=>{e.stopPropagation(),a(i.id)},onDoubleClick:e=>e.stopPropagation(),onMouseEnter:()=>w(i.id),onMouseLeave:()=>w(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:y?22:20,height:y?22:20,background:b===i.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:b===i.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:v("chatTabs.closeTab",{defaultValue:"关闭标签"}),"aria-label":`${v("chatTabs.closeTab",{defaultValue:"关闭标签"})}: ${i.title}`,children:(0,r.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,r.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},i.id)})}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:g?"transparent":"var(--bg-panel)",boxShadow:y?"-4px 0 10px -2px rgba(0,0,0,0.18)":void 0,zIndex:2,position:"relative"},children:[k&&!y&&(0,r.jsx)("button",{ref:L,type:"button",onClick:()=>{if(S)return void C(!1);let e=L.current.getBoundingClientRect(),t=Math.min(320,window.innerWidth-16);M({top:e.bottom+4,left:Math.max(8,Math.min(e.right-t,window.innerWidth-t-8)),width:t}),C(!0)},"aria-expanded":S,title:v("chatTabs.allTabs"),"aria-label":v("chatTabs.allTabs"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:"100%",padding:0,border:"none",borderRight:"1px solid var(--border)",background:S?"var(--bg-selected)":"transparent",color:"var(--text-muted)",cursor:"pointer"},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M8 6h13M8 12h13M8 18h13"}),(0,r.jsx)("path",{d:"M3 6h.01M3 12h.01M3 18h.01"})]})}),(0,r.jsx)("button",{type:"button",onClick:c,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:"100%",background:"transparent",border:"none",borderRight:N?"1px solid var(--border)":"none",color:"var(--text-muted)",cursor:"pointer",padding:0,transition:"color 0.12s, background 0.12s"},title:v("chatTabs.newTab",{defaultValue:"新建对话标签"}),"aria-label":v("chatTabs.newTab",{defaultValue:"新建对话标签"}),onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="transparent"},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),!f&&N&&u&&(0,r.jsx)("button",{type:"button",onClick:u,"aria-pressed":$,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:"100%",background:$?"var(--bg-selected)":"transparent",border:"none",color:$?"var(--accent)":"var(--text-muted)",cursor:"pointer",padding:0,transition:"color 0.12s, background 0.12s"},title:$?v("chatTabs.closeSplit",{defaultValue:"关闭分屏"}):v("chatTabs.splitView",{defaultValue:"向右分屏"}),"aria-label":$?v("chatTabs.closeSplit",{defaultValue:"关闭分屏"}):v("chatTabs.splitView",{defaultValue:"向右分屏"}),onMouseEnter:e=>{$||(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{$||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="transparent")},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]})}),f&&h&&(0,r.jsx)("button",{type:"button",onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:"100%",background:"transparent",border:"none",color:"var(--text-muted)",cursor:"pointer",padding:0,transition:"color 0.12s, background 0.12s"},title:v("chatTabs.closeSplit",{defaultValue:"关闭分屏"}),"aria-label":v("chatTabs.closeSplit",{defaultValue:"关闭分屏"}),onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="transparent"},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),S&&(0,m.createPortal)((0,r.jsx)("div",{ref:R,role:"dialog","aria-label":v("chatTabs.allTabs"),style:{position:"fixed",top:I.top,left:I.left,width:I.width,zIndex:700,padding:6,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:(0,r.jsx)("div",{style:{maxHeight:"min(50vh, 360px)",overflowY:"auto"},children:e.map((e,i)=>{let o=e.id===t||e.id===n,d="session"===e.kind&&!!(e.session&&l?.has(e.session.id));return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",minWidth:0,background:o?"var(--bg-selected)":"transparent",borderRadius:4},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{C(!1),s(e.id),requestAnimationFrame(()=>W(e.id))},style:{display:"flex",alignItems:"center",gap:7,flex:1,minWidth:0,height:30,padding:"0 8px",border:"none",background:"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12},children:[d?(0,r.jsx)("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:12,height:12,flexShrink:0},children:(0,r.jsx)(_,{size:10})}):(0,r.jsx)("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",flexShrink:0,background:e.dirty?"var(--accent)":"transparent"}}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.title})]}),(0,r.jsx)("button",{type:"button","data-tab-menu-close":e.id,onClick:()=>{!1!==a(e.id)&&requestAnimationFrame(()=>{let e=E.current;if(e&&e.scrollWidth>e.clientWidth+1){let e=R.current?.querySelectorAll("[data-tab-menu-close]"),t=e?.[Math.min(i,e.length-1)];if(t)return void t.focus()}C(!1),W()})},title:`${v("chatTabs.closeTab")}: ${e.title}`,"aria-label":`${v("chatTabs.closeTab")}: ${e.title}`,style:{width:28,height:28,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M2 2l6 6M8 2 2 8"})})})]},e.id)})})}),document.body)]})}function ik(e,t){let n=e.split(/\r?\n/).find(e=>e.trim())?.trim();if(!n)return t;let r=Array.from(n);return r.length<=48?n:`${r.slice(0,47).join("")}…`}function ij(e){return e.pane??"primary"}function iS(e,t){return e.filter(e=>ij(e)===t)}function iC(e,t,n="primary"){let r=e.findIndex(e=>e.id===t.id),i=h(t);if(r>=0){let n=[...e];return n[r]={...n[r],session:t,title:i,projectKey:t.projectKey??t.cwd},{tabs:n,tabId:t.id}}let o=e.findIndex(e=>!0===e.preview&&ij(e)===n);if(o>=0){let r=[...e];return r[o]={id:t.id,kind:"session",title:i,session:t,newSessionCwd:null,newSessionDraftKey:null,projectKey:t.projectKey??t.cwd,preview:!0,pane:n},{tabs:r,tabId:t.id}}return{tabs:[...e,{id:t.id,kind:"session",title:i,session:t,newSessionCwd:null,newSessionDraftKey:null,projectKey:t.projectKey??t.cwd,preview:!0,pane:n}],tabId:t.id}}function iI(e,t){let n=e.findIndex(e=>e.id===t);if(-1===n||!0!==e[n].preview)return e;let r=[...e];return r[n]={...r[n],preview:!1},r}function iM(e,t){let n=[...iS(e,"primary"),...iS(e,"secondary")],r=n.find(e=>e.id===t&&e.preview)??n.find(e=>e.preview);return n.map(e=>({...e,pane:"primary",preview:!0===e.preview?e.id===r?.id:e.preview}))}function iT(e,t,n="primary"){let r=e.findIndex(e=>e.id===t.id),i=h(t);if(r>=0){let n=[...e];return n[r]={...n[r],session:t,title:i,projectKey:t.projectKey??t.cwd,preview:!1},{tabs:n,tabId:t.id}}return{tabs:[...e,{id:t.id,kind:"session",title:i,session:t,newSessionCwd:null,newSessionDraftKey:null,projectKey:t.projectKey??t.cwd,pane:n}],tabId:t.id}}function iE(e,t,n,r="新会话",i="primary"){let o=`draft:${n}`;return e.find(e=>e.id===o)?{tabs:e,tabId:o}:{tabs:[...e,{id:o,kind:"draft",title:r,session:null,newSessionCwd:t,newSessionDraftKey:n,projectKey:t,dirty:!1,pane:i}],tabId:o}}function iL(e,t,n,r=null){let i=e.findIndex(e=>e.id===t);if(-1===i)return{tabs:e,nextActiveTabId:n,nextSplitTabId:r};let o=e.filter(e=>e.id!==t),l=ij(e[i]),s=iS(e,l),a=iS(o,l),d=a[Math.min(s.findIndex(e=>e.id===t),a.length-1)]?.id??null,c=t===n?d:n,u=t===r?d:r;if(r&&0===a.length){let e="primary"===l?u:c;return{tabs:iM(o,e),nextActiveTabId:e,nextSplitTabId:null}}return{tabs:o,nextActiveTabId:c,nextSplitTabId:u}}var iR=n(50640);let iN={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"},i$={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"},iW={mp4:"video/mp4",m4v:"video/mp4",webm:"video/webm",mov:"video/quicktime",ogv:"video/ogg"};function iz(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}function iP(e){return null!==(iN[iz(e)]??null)}function iA(e){return null!==(i$[iz(e)]??null)}function iD(e){return null!==(iW[iz(e)]??null)}function iF(e){let t;return null!==("pdf"===(t=iz(e))||"docx"===t?t:null)}let iB=new Set(["md","mdx","html","htm"]);var iH=n(73620);let iO=/^(?:\uFEFF)?---[ \t]*(?:\r\n|\n|\r)/;function iU(e){return function e(t,n){if(null==t)return"";if("string"==typeof t)return t;if("number"==typeof t||"boolean"==typeof t)return String(t);if(Array.isArray(t)){if(n.has(t))return"[Circular]";n.add(t);try{return t.map(t=>e(t,n)).filter(Boolean).join(", ")}finally{n.delete(t)}}if("object"==typeof t)try{return JSON.stringify(t)??Object.prototype.toString.call(t)}catch{return Object.prototype.toString.call(t)}return String(t)}(e,new WeakSet)}function i_(e,t){if(e[t]?.level!==3)return -1;for(let n=t-1;n>=0;n--)if(e[n].level<3)return n;return -1}let iq=/^ {0,3}(`{3,}|~{3,})/,iK=/^ {0,3}(#{1,3})[ \t]+(.+?)[ \t]*#*[ \t]*$/,iV=["tags","categories","keywords","tag","category"];function iJ({data:e}){var t;if(!e)return null;let n=Object.entries(e);if(0===n.length)return null;let i="string"==typeof(t=e.title)?t.trim()||null:"number"==typeof t||"boolean"==typeof t?String(t):null,o=iV.find(t=>Array.isArray(e[t])),l=o?e[o].map(iU).filter(Boolean):[],s=n.filter(([e])=>e!==o&&("title"!==e||!i));return(0,r.jsxs)("div",{className:"markdown-frontmatter",children:[i&&(0,r.jsx)("div",{className:"markdown-frontmatter-title",children:i}),l.length>0&&(0,r.jsx)("div",{className:"markdown-frontmatter-tags",children:l.map((e,t)=>(0,r.jsx)("span",{className:"markdown-frontmatter-tag",children:e},`${e}-${t}`))}),s.length>0&&(0,r.jsx)("dl",{className:"markdown-frontmatter-rows",children:s.map(([e,t])=>(0,r.jsxs)("div",{className:"markdown-frontmatter-row",children:[(0,r.jsx)("dt",{children:e}),(0,r.jsx)("dd",{children:function(e){let t=iU(e);return t?"string"==typeof e&&/^(https?:\/\/|mailto:)/i.test(e)?(0,r.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:t}):t:null}(t)})]},e))})]})}function iY({items:e,scrollRoot:t}){let{t:n}=(0,x.s)(),o=(0,i.useId)(),l=(0,i.useRef)(null),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(()=>new Set),u=e.length>20;if((0,i.useEffect)(()=>{a(!1),c(new Set)},[e]),(0,i.useEffect)(()=>{if(!s)return;let e=e=>{l.current?.contains(e.target)||a(!1)},t=e=>{"Escape"===e.key&&a(!1)};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",t)}},[s]),0===e.length)return null;let h=e.map(()=>!1);if(u)for(let t=0;t<e.length;t++){let n=i_(e,t);n>=0&&(h[n]=!0)}return(0,r.jsxs)("div",{ref:l,className:"file-outline",children:[(0,r.jsx)("button",{type:"button",className:"file-viewer-icon-button","aria-expanded":s,"aria-haspopup":"menu","aria-controls":o,"aria-label":n("i18n.outline"),title:n("i18n.outline"),onClick:()=>a(e=>!e),style:{background:s?"var(--bg-selected)":"transparent",color:s?"var(--text)":"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M8 6h13"}),(0,r.jsx)("path",{d:"M8 12h13"}),(0,r.jsx)("path",{d:"M8 18h13"}),(0,r.jsx)("path",{d:"M3 6h.01"}),(0,r.jsx)("path",{d:"M3 12h.01"}),(0,r.jsx)("path",{d:"M3 18h.01"})]})}),s&&(0,r.jsx)("div",{className:"file-outline-menu",id:o,role:"menu",children:e.map((n,i)=>{if(u&&3===n.level){let t=i_(e,i);if(t>=0&&!d.has(t))return null}return(0,r.jsxs)("div",{className:"file-outline-item","data-level":n.level,children:[h[i]?(0,r.jsx)("button",{type:"button",className:"file-outline-fold","aria-expanded":d.has(i),"aria-label":n.text,onClick:()=>{c(e=>{let t=new Set(e);return t.has(i)?t.delete(i):t.add(i),t})},children:(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"m9 6 6 6-6 6"})})}):null,(0,r.jsx)("button",{type:"button",role:"menuitem",className:"file-outline-jump",title:n.text,onClick:()=>{!function(e,t,n){let r=t[n];if(!e||!r)return;let i=t.slice(0,n).filter(e=>e.text===r.text).length,o=0;for(let t of e.querySelectorAll(".markdown-file-preview :is(h1, h2, h3)"))if(t.textContent?.replace(/\s+/g," ").trim()===r.text){if(o===i)return void t.scrollIntoView({block:"start",inline:"nearest"});o++}}(t.current,e,i),a(!1)},children:n.text})]},`${n.level}-${i}-${n.text}`)})})]})}function iZ(e,t,n){var r;return r=n??(iB.has(iz(e))?"preview":void 0),t?.displayMode??r??"source"}let iG={fontFamily:"var(--font-mono)",fontSize:"calc(13px + var(--chat-font-size-offset, 0px))",lineHeight:1.6},iX={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:"calc(11px + var(--chat-font-size-offset, 0px))",fontStyle:"normal",fontVariantNumeric:"tabular-nums",lineHeight:1.6,userSelect:"none",flexShrink:0,verticalAlign:"top"};function iQ(){return(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function i0(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function i1(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let n=t.getRangeAt(0);if(!e.contains(n.startContainer)||!e.contains(n.endContainer))return null;let r=i0(n.startContainer),i=i0(n.endContainer);if(!r||!i||!e.contains(r)||!e.contains(i))return null;let o=Number(r.dataset.lineNumber),l=Number(i.dataset.lineNumber);if(!Number.isInteger(o)||!Number.isInteger(l))return null;if(o<l){let e=r.querySelector(".file-source-line-content");if(e?.contains(n.startContainer)){let t=document.createRange();if(t.selectNodeContents(e),t.setStart(n.startContainer,n.startOffset),0===t.toString().length){let e=r.nextElementSibling;e instanceof HTMLElement&&e.matches(".file-source-line[data-line-number]")&&(o=Number((r=e).dataset.lineNumber))}}let t=i.querySelector(".file-source-line-content");if(t?.contains(n.endContainer)){let e=document.createRange();if(e.selectNodeContents(t),e.setEnd(n.endContainer,n.endOffset),0===e.toString().length){let e=i.previousElementSibling;e instanceof HTMLElement&&e.matches(".file-source-line[data-line-number]")&&(l=Number((i=e).dataset.lineNumber))}}}return o>l?null:{startLine:o,endLine:l}}function i2({rows:e,stylesheet:t,useInlineStyles:n,wrapLines:i}){return e.map((e,o)=>{let l=e.children??[],s=l[0]?.properties?.className,a=Array.isArray(s)&&s.includes("react-syntax-highlighter-line-number"),d=a?l[0]:null,c=a?l.slice(1):l;return(0,r.jsxs)("span",{className:"file-source-line","data-line-number":o+1,style:{display:"flex",minWidth:"100%"},children:[d&&(0,iR.Ay)({node:d,stylesheet:t,useInlineStyles:n,key:`source-line-number-${o}`}),(0,r.jsx)("span",{className:"file-source-line-content",style:{flex:"1 1 auto",minWidth:0,overflowWrap:i?"anywhere":"normal",whiteSpace:i?"pre-wrap":"pre"},children:c.map((e,r)=>(0,iR.Ay)({node:e,stylesheet:t,useInlineStyles:n,key:`source-token-${o}-${r}`}))})]},`source-line-${o}`)})}function i4(e,t,n,r={}){let i=T(e),o=new URLSearchParams({type:t});for(let[e,t]of(n&&o.set("sessionId",n),Object.entries(r)))void 0!==t&&o.set(e,String(t));return`/api/files/${i}?${o.toString()}`}function i8({filePath:e,sourceSessionId:t}){let{t:n}=(0,x.s)();return(0,r.jsx)("a",{href:i4(e,"download",t),download:E(e),title:n("i18n.downloadFile"),"aria-label":n("i18n.downloadFile"),className:"file-viewer-icon-button",children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})}function i5(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function i6({patch:e}){let{t}=(0,x.s)(),n=(0,i.useMemo)(()=>{let t;return(t=tP(e))?t.flatMap(e=>e.rows.flatMap(e=>{if("hunk"===e.type)return[{type:"hunk",text:e.text}];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})):[]},[e]),o=e.split(/\r?\n/).filter(e=>/^(?:similarity index|dissimilarity index|rename from|rename to|copy from|copy to|old mode|new mode|new file mode|deleted file mode|Binary files|Submodule )/.test(e));return o.length>0||n.some(e=>"added"===e.type||"removed"===e.type)?(0,r.jsxs)("div",{className:"file-diff-view",style:{width:"max-content",minWidth:"100%",...iG},children:[o.map((e,t)=>(0,r.jsx)("div",{style:{padding:"2px 12px",color:"var(--text-muted)",background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:e},`${t}:${e}`)),n.map((e,t)=>{if("hunk"===e.type)return(0,r.jsx)("div",{style:{padding:"2px 12px",color:"var(--accent)",background:"var(--bg-panel)",borderBlock:"1px solid var(--border)"},children:e.text},`hunk-${t}`);let n="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",o="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,r.jsxs)("div",{className:"file-diff-line",style:{display:"flex",minWidth:"100%",background:n,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,r.jsx)("span",{style:{...iX,width:40,minWidth:40,paddingInline:6},children:e.oldLineNo}),(0,r.jsx)("span",{style:{...iX,width:40,minWidth:40,paddingInline:6},children:e.newLineNo}),(0,r.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:o,userSelect:"none",flexShrink:0,fontWeight:600},children:i}),(0,r.jsx)("span",{className:"file-diff-line-content",style:{flexShrink:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},t)})]}):(0,r.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:t("i18n.noChanges")})}function i3({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:l}=(0,x.s)(),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,h]=(0,i.useState)(null),[p,f]=(0,i.useState)(null),[g,m]=(0,i.useState)(null),y=(0,i.useRef)(null),v=(0,i.useRef)(0),b=E(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),h(null),f(null),m(null),a(!1)},[e,n]),(0,i.useEffect)(()=>{if(a(!1),y.current&&(y.current.close(),y.current=null),!o)return;let t=!0,r=new EventSource(i4(e,"watch",n));y.current=r,r.addEventListener("connected",()=>{let r;a(!0),r=++v.current,fetch(i4(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===v.current){if(e.error)return void m(e.error);"number"==typeof e.size&&h(e.size),f(null),m(null),c(e=>e+1)}}).catch(e=>{t&&r===v.current&&m(String(e))})}),r.addEventListener("change",e=>{v.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&h(t.size)}catch{}f(null),m(null),c(e=>e+1)});let i=()=>{a(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),y.current===r&&(y.current=null)}},[e,n,o]);let w=i4(e,"read",n,d?{v:d}:void 0),k=null!=u?i5(u):null;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:R(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:b||"image"}),p&&(0,r.jsxs)("span",{children:[p.w," \xd7 ",p.h]}),k&&(0,r.jsx)("span",{children:k}),(0,r.jsxs)("span",{title:l(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]}),(0,r.jsx)(i8,{filePath:e,sourceSessionId:n})]}),(0,r.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",alignItems:"center",justifyContent:"center",padding:16,backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:g?(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13},children:g}):(0,r.jsx)("img",{src:w,alt:e,onLoad:e=>{let t=e.currentTarget;f({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>m("Failed to load image"),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function i7(e){if(!Number.isFinite(e))return"";let t=Math.round(e),n=Math.floor(t/60);return`${n}:${String(t%60).padStart(2,"0")}`}function i9({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:l}=(0,x.s)(),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,h]=(0,i.useState)(null),[p,f]=(0,i.useState)(null),[g,m]=(0,i.useState)(null),y=(0,i.useRef)(null),v=(0,i.useRef)(0),b=E(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),h(null),f(null),m(null),a(!1)},[e,n]),(0,i.useEffect)(()=>{if(a(!1),y.current&&(y.current.close(),y.current=null),!o)return;let t=!0,r=new EventSource(i4(e,"watch",n));y.current=r,r.addEventListener("connected",()=>{let r;a(!0),r=++v.current,fetch(i4(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===v.current){if(e.error)return void m(e.error);"number"==typeof e.size&&h(e.size),f(null),m(null),c(e=>e+1)}}).catch(e=>{t&&r===v.current&&m(String(e))})}),r.addEventListener("change",e=>{v.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&h(t.size)}catch{}f(null),m(null),c(e=>e+1)});let i=()=>{a(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),y.current===r&&(y.current=null)}},[e,n,o]);let w=i4(e,"read",n,d?{v:d}:void 0);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:R(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:b||"audio"}),null!=p&&(0,r.jsx)("span",{children:i7(p)}),null!=u&&(0,r.jsx)("span",{children:i5(u)}),(0,r.jsxs)("span",{title:l(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]}),(0,r.jsx)(i8,{filePath:e,sourceSessionId:n})]}),(0,r.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,r.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[g&&(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:g}),(0,r.jsx)("audio",{controls:!0,preload:"metadata",src:w,onLoadedMetadata:e=>f(e.currentTarget.duration),onError:()=>m("Failed to load audio"),style:{width:"100%"}},w)]})})]})}function oe({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:l}=(0,x.s)(),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,h]=(0,i.useState)(null),[p,f]=(0,i.useState)(null),[g,m]=(0,i.useState)(null),y=(0,i.useRef)(null),v=(0,i.useRef)(0),b=E(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),h(null),f(null),m(null),a(!1)},[e,n]),(0,i.useEffect)(()=>{if(a(!1),y.current&&(y.current.close(),y.current=null),!o)return;let t=!0,r=new EventSource(i4(e,"watch",n));y.current=r,r.addEventListener("connected",()=>{let r;a(!0),r=++v.current,fetch(i4(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===v.current){if(e.error)return void m(e.error);"number"==typeof e.size&&h(e.size),f(null),m(null),c(e=>e+1)}}).catch(e=>{t&&r===v.current&&m(String(e))})}),r.addEventListener("change",e=>{v.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&h(t.size)}catch{}f(null),m(null),c(e=>e+1)});let i=()=>{a(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),y.current===r&&(y.current=null)}},[e,n,o]);let w=i4(e,"read",n,d?{v:d}:void 0);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:R(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:b||"video"}),null!=p&&(0,r.jsx)("span",{children:i7(p)}),null!=u&&(0,r.jsx)("span",{children:i5(u)}),(0,r.jsxs)("span",{title:l(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]}),(0,r.jsx)(i8,{filePath:e,sourceSessionId:n})]}),(0,r.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)",minHeight:0},children:(0,r.jsxs)("div",{style:{width:"min(960px, 100%)",height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:0},children:[g&&(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:g}),(0,r.jsx)("video",{controls:!0,playsInline:!0,preload:"metadata",src:w,onLoadedMetadata:e=>f(e.currentTarget.duration),onError:()=>m("Failed to load video"),style:{maxWidth:"100%",maxHeight:"100%"}},w)]})})]})}function ot({filePath:e,cwd:t,sourceSessionId:n,watchEnabled:o=!0}){let{t:l}=(0,x.s)(),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,h]=(0,i.useState)(null),[p,f]=(0,i.useState)(null),g=(0,i.useRef)(null),m=(0,i.useRef)(0),y=iz(e),v="pdf"===y,b=v?i4(e,"read",n,d?{v:d}:void 0):i4(e,"preview",n,d?{v:d}:void 0);return(0,i.useEffect)(()=>{c(0),h(null),f(null),a(!1);let t=!0,r=++m.current;return fetch(i4(e,"meta",n)).then(e=>e.json()).then(e=>{t&&r===m.current&&(e.error&&f(e.error),"number"==typeof e.size&&(h(e.size),!v&&e.size>0xa00000&&f("DOCX too large for preview (>10MB)")))}).catch(e=>{t&&r===m.current&&f(String(e))}),()=>{t=!1}},[e,v,n]),(0,i.useEffect)(()=>{if(a(!1),g.current&&(g.current.close(),g.current=null),!o)return;let t=!0,r=new EventSource(i4(e,"watch",n));g.current=r,r.addEventListener("connected",()=>{let r;a(!0),r=++m.current,fetch(i4(e,"meta",n)).then(e=>e.json()).then(e=>{if(t&&r===m.current){if(e.error)return void f(e.error);if("number"==typeof e.size&&(h(e.size),!v&&e.size>0xa00000))return void f("DOCX too large for preview (>10MB)");f(null),c(e=>e+1)}}).catch(e=>{t&&r===m.current&&f(String(e))})}),r.addEventListener("change",e=>{m.current+=1;try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(h(t.size),!v&&t.size>0xa00000))return void f("DOCX too large for preview (>10MB)")}catch{}f(null),c(e=>e+1)});let i=()=>{a(!1)};return r.addEventListener("error",i),r.onerror=i,()=>{t=!1,r.close(),g.current===r&&(g.current=null)}},[e,v,n,o]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:R(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===y?"docx preview":"pdf"}),null!=u&&(0,r.jsx)("span",{children:i5(u)}),(0,r.jsx)(i8,{filePath:e,sourceSessionId:n}),(0,r.jsxs)("span",{title:l(s?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:s?"#4ade80":"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s?"#4ade80":"var(--border)",display:"inline-block",boxShadow:s?"0 0 4px #4ade80":"none"}}),s?"live":"static"]})]}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:p?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:p}):(0,r.jsx)("iframe",{src:b,sandbox:v?void 0:"allow-same-origin",title:l("i18n.previewFile",{file:E(e)}),style:{width:"100%",height:"100%",border:"none",background:v?"var(--bg)":"#eef1f5"}},b)})]})}function on({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:i,onMentionLines:o,onAtMention:l,gitRefreshKey:s,initialDisplayMode:a,initialState:d,onStateChange:c,watchEnabled:u=!0}){let h="diff"===iZ(e,d,a);return!h&&iP(e)?(0,r.jsx)(i3,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):!h&&iA(e)?(0,r.jsx)(i9,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):!h&&iD(e)?(0,r.jsx)(oe,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):!h&&iF(e)?(0,r.jsx)(ot,{filePath:e,cwd:t,sourceSessionId:n,watchEnabled:u}):(0,r.jsx)(or,{filePath:e,cwd:t,sourceSessionId:n,onOpenFile:i,onMentionLines:o,onAtMention:l,gitRefreshKey:s,initialDisplayMode:a,initialState:d,onStateChange:c,watchEnabled:u})}function or({filePath:e,cwd:t,sourceSessionId:n,onOpenFile:o,onMentionLines:l,onAtMention:s,gitRefreshKey:a,initialDisplayMode:d,initialState:c,onStateChange:u,watchEnabled:h=!0}){let{isDark:p}=tC(),{t:f}=(0,x.s)(),[g,m]=(0,i.useState)(null),[y,v]=(0,i.useState)(null),[b,w]=(0,i.useState)(!1),[k,j]=(0,i.useState)(!1),[S,C]=(0,i.useState)(null),[I,M]=(0,i.useState)(!0),[T,E]=(0,i.useState)(!1),[N,$]=(0,i.useState)(null),W=iZ(e,c,d),z="diff"===W&&(iP(e)||iA(e)||iD(e)||iF(e)),P=c?.wrapLines??!1,A=c?.scrollByMode?.[W],D=A?.scrollTop??c?.scrollTop??0,F=A?.scrollLeft??c?.scrollLeft??0,B=c?.loadedBytes??0,[H,O]=(0,i.useState)(W),[U,_]=(0,i.useState)(P),[q,K]=(0,i.useState)(!1),V=(0,i.useRef)(null),J=(0,i.useRef)(0),Y=(0,i.useRef)(null),Z=(0,i.useRef)(0),G=(0,i.useRef)(null),X=(0,i.useRef)(!1),Q=(0,i.useRef)(0),ee=(0,i.useRef)(null),et=(0,i.useRef)(!1),en=(0,i.useRef)(!0),er=(0,i.useRef)({displayMode:W,wrapLines:P,scrollTop:D,scrollLeft:F,loadedBytes:B,scrollByMode:{...c?.scrollByMode}}),ei=(0,i.useRef)(u),[eo,el]=(0,i.useState)(null);ei.current=u;let es=(0,i.useCallback)(e=>{er.current.displayMode=e,O(e)},[]),ea=(0,i.useCallback)(()=>{_(e=>{let t=!e;return er.current.wrapLines=t,t})},[]);(0,i.useEffect)(()=>(er.current={displayMode:W,wrapLines:P,scrollTop:D,scrollLeft:F,loadedBytes:B,scrollByMode:{...c?.scrollByMode}},en.current=!0,et.current=!1,O(W),_(P),()=>{ei.current?.({...er.current})}),[e,n,W,P,D,F,B,c?.scrollByMode]);let ed=(0,i.useCallback)(async(e,t=0)=>{let r=++J.current,i=async t=>(await fetch(i4(e,"read",n,{offset:t||void 0}))).json();try{let e=t,n=await i(e);if(r!==J.current||e&&"Invalid text preview offset"===n.error&&(e=0,n=await i(0),r!==J.current))return null;if(n.error)return $(n.error),null;if(e&&(Y.current!==n.version||Z.current!==e)){if(e=0,n=await i(0),r!==J.current)return null;if(n.error)return $(n.error),null}return $(null),Y.current=n.version,Z.current=n.nextOffset,er.current.loadedBytes=n.nextOffset,m(t=>e&&t?{...n,content:t.content+n.content}:n),n}catch(e){if(r!==J.current)return null;return $(String(e)),null}},[n]),ec=(0,i.useCallback)(async e=>{let n=++Q.current;if(w(!0),C(null),!t){v(null),w(!1),j(!0);return}try{let r=new URLSearchParams({cwd:t,path:e}),i=await fetch(`/api/git/diff?${r.toString()}`),o=await i.json();if(n!==Q.current)return;i.ok||C(o.error??`Failed to load diff (HTTP ${i.status})`),v(i.ok&&o.supported&&"string"==typeof o.patch?o:null)}catch(e){n===Q.current&&(v(null),C(e instanceof Error?e.message:String(e)))}finally{n===Q.current&&(w(!1),j(!0))}},[t]);(0,i.useEffect)(()=>{let t=!0;if(M(!0),$(null),m(null),v(null),j(!1),C(null),K(!1),Y.current=null,Z.current=0,X.current=!1,z)return M(!1),G.current=null,()=>{t=!1,J.current+=1};let n=(async()=>{let n=await ed(e);for(;t&&n?.truncated&&n.nextOffset<B;)n=await ed(e,n.nextOffset);return n})();return G.current=n,n.finally(()=>{G.current===n&&(G.current=null),t&&M(!1)}),()=>{t=!1,J.current+=1}},[e,ed,B,z,n]),(0,i.useEffect)(()=>{if(K(!1),V.current&&(V.current.close(),V.current=null),!h)return;let t=new EventSource(i4(e,"watch",n));V.current=t,t.addEventListener("connected",n=>{K(!0);let r=X.current;if(X.current=!0,r&&ec(e),z)return;let i=(()=>{try{return JSON.parse(n.data).version??null}catch{return null}})();(G.current??Promise.resolve()).then(()=>{V.current===t&&i!==Y.current&&(ed(e,0),ec(e))})}),t.addEventListener("change",()=>{z||ed(e,0),ec(e)});let r=()=>{K(!1)};return t.addEventListener("error",r),t.onerror=r,()=>{t.close(),V.current===t&&(V.current=null)}},[e,ed,ec,z,n,h]),(0,i.useEffect)(()=>{ec(e)},[ec,e,a]);let eu=y?.supported===!0&&"string"==typeof y.patch,eh=eu&&"deleted"===y.status;(0,i.useEffect)(()=>{k&&!eu&&"diff"===H&&es("source")},[H,k,eu,es]),(0,i.useEffect)(()=>{"diff"===W&&eu&&!et.current&&(et.current=!0,es("diff"))},[W,eu,es]);let ep=(0,i.useMemo)(()=>g?.language==="markdown"?te(g.content):"",[g]),ef=(0,i.useMemo)(()=>g?.language==="markdown"?function(e){let t=function(e){let t=iO.exec(e);if(!t)return null;let n=/^---[ \t]*(?:(?:\r\n|\n|\r)|$)/gm;n.lastIndex=t[0].length;let r=n.exec(e);return r?{yaml:e.slice(t[0].length,r.index).replace(/(?:\r\n|\n|\r)$/,""),rest:e.slice(r.index+r[0].length)}:null}(e);if(!t)return{data:null,rest:e};try{let e=(0,iH.Hh)(t.yaml);if(e&&"object"==typeof e&&!Array.isArray(e))return{data:e,rest:t.rest}}catch{}return{data:null,rest:t.rest}}(g.content):null,[g]),eg=(0,i.useMemo)(()=>(function(e){let t=[],n=null;for(let r of e.split(/\r?\n/)){let e=iq.exec(r);if(e){let t=e[1][0],r=e[1].length;n?n.ch===t&&r>=n.n&&(n=null):n={ch:t,n:r};continue}if(n)continue;let i=iK.exec(r);if(!i)continue;let o=i[2].replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/[*_`]/g,"").trim();o&&t.push({level:i[1].length,text:o})}return t})(ef?.rest??""),[ef]),ex=g?.content??"",em=(0,i.useMemo)(()=>ex.split("\n"),[ex]),ey=g?.language??"text",ev="html"===ey,eb="markdown"===ey,ew=!g?.truncated&&(ev||eb),ek=eh?"diff":"preview"!==H||ew?H:"source",ej=(em.length>1e3||(g?.size??0)>131072)&&!("diff"===ek&&eu)&&!("preview"===ek&&ew),eS=!ej&&!("diff"===ek&&eu)&&!("preview"===ek&&ew),eC=(0,i.useMemo)(()=>eS?(0,r.jsx)(tM.A,{className:U?"file-source-view is-wrapped":"file-source-view",language:"text"===ey?"plaintext":ey,style:p?ta.xJ:ta.vs,showLineNumbers:!0,lineNumberStyle:{...iX},customStyle:{margin:0,padding:0,border:0,background:"var(--bg)",...iG,width:U?"100%":"max-content",minWidth:"100%",minHeight:"100%",overflow:"visible"},codeTagProps:{style:{fontFamily:"var(--font-mono)",overflowWrap:U?"anywhere":"normal"}},renderer:e=>(0,r.jsx)(i2,{...e,wrapLines:U}),wrapLongLines:U,children:ex}):null,[p,ey,eS,ex,U]),eI=(0,i.useMemo)(()=>ej?em.map((e,t)=>(0,r.jsxs)("span",{className:"file-source-line","data-line-number":t+1,style:{display:"flex",minWidth:"100%"},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:iX,children:t+1}),(0,r.jsx)("span",{className:"file-source-line-content",style:{flex:"1 1 auto",minWidth:0,overflowWrap:U?"anywhere":"normal",whiteSpace:U?"pre-wrap":"pre"},children:e})]},`source-line-${t}`)):null,[em,ej,U]);(0,i.useEffect)(()=>{let e=()=>{let e=ee.current;el(t=>{let n=l&&"source"===H&&e?i1(e,window.getSelection()):null;return null===t&&null===n||t&&n&&t.startLine===n.startLine&&t.endLine===n.endLine?t:n})};if(e(),l&&"source"===H)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[g?.content,H,l]);let eM=(0,i.useCallback)(n=>{l&&n&&l(R(e,t),n.startLine,n.endLine,t)},[t,e,l]);if((0,i.useEffect)(()=>{if(!l||"source"!==H)return;let e=e=>{if(e.repeat||"i"!==e.key.toLowerCase()||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest("input, textarea, [contenteditable='true']"))return;let n=ee.current,r=n?i1(n,window.getSelection()):null;r&&(e.preventDefault(),eM(r))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[H,eM,l]),(0,i.useEffect)(()=>{if(!en.current||I||N&&!eh||"diff"===W&&!k||"diff"===W&&eu&&"diff"!==H)return;let e=ee.current;e&&(e.scrollTop=er.current.scrollTop,e.scrollLeft=er.current.scrollLeft,en.current=!1)},[g?.content,H,N,k,eu,eh,I,W]),(0,i.useLayoutEffect)(()=>{if(en.current)return;let e=ee.current;if(!e)return;let t=er.current.scrollByMode?.[ek];e.scrollTop=t?.scrollTop??0,e.scrollLeft=t?.scrollLeft??0},[ek]),I||"diff"===W&&b&&!k)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:f("i18n.loading")});if("diff"===W&&k&&S)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:S});if(N&&!("diff"===ek&&eu))return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:N});if(!g&&!("diff"===ek&&eu))return null;let eT=L(e),eE=!g||eh?["diff"]:["source",...ew?["preview"]:[],...eu?["diff"]:[]],eL=eh?f("files.deleted"):g?`${ey} \xb7 ${em.length} lines \xb7 ${i5(g.size)}`:f("i18n.diff");return(0,r.jsxs)("div",{className:"file-viewer-shell",style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",position:"relative"},children:[(0,r.jsxs)("div",{className:"file-viewer-toolbar",style:{display:"flex",alignItems:"center",gap:8,padding:"5px 12px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,r.jsx)("span",{className:"file-viewer-path",style:{fontFamily:"var(--font-mono)"},title:e,children:R(e,t)}),(0,r.jsx)("span",{className:"file-viewer-meta",title:eL,children:eL}),g&&!eh&&(0,r.jsx)("span",{title:q?f("i18n.liveSync"):f("i18n.notWatching"),"aria-label":q?f("i18n.liveSync"):f("i18n.notWatching"),className:"file-viewer-live-indicator",style:{background:q?"#4ade80":"var(--border)",boxShadow:q?"0 0 4px #4ade80":"none"}}),(0,r.jsxs)("div",{className:"file-viewer-controls",children:[eE.length>1&&(0,r.jsx)("div",{className:"file-viewer-mode-switch","aria-label":f("i18n.fileViewMode"),children:eE.map(e=>{let t=ek===e;return(0,r.jsx)("button",{type:"button",onClick:()=>es(e),title:"diff"===e?f("i18n.compareHead"):void 0,"aria-pressed":t,className:"file-viewer-mode-button",style:{background:t?"var(--bg-selected)":"transparent",color:t?"var(--text)":"var(--text-muted)"},children:"source"===e?f("i18n.source"):"preview"===e?f("i18n.preview"):f("i18n.diff")},e)})}),(0,r.jsxs)("div",{className:"file-viewer-actions",children:[eb&&"preview"===ek&&(0,r.jsx)(iY,{items:eg,scrollRoot:ee}),(s||l)&&(0,r.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{eo&&l?eM(eo):s?.(R(e,t),!1,t)},title:eo&&l?`${f("i18n.mentionSelectedLines")} (L${eo.startLine}${eo.startLine!==eo.endLine?`-L${eo.endLine}`:""})`:f("files.insertPath"),"aria-label":f("files.mention"),disabled:!s&&!l,className:"file-viewer-icon-button",children:(0,r.jsx)(iQ,{})}),"source"===ek&&(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("button",{type:"button",onClick:ea,title:U?f("i18n.disableWrap"):f("i18n.enableWrap"),"aria-label":U?f("i18n.disableWrap"):f("i18n.enableWrap"),"aria-pressed":U,className:"file-viewer-icon-button",style:{background:U?"var(--bg-selected)":"transparent",color:U?"var(--text)":"var(--text-muted)"},children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 6h18"}),(0,r.jsx)("path",{d:"M3 12h15a3 3 0 1 1 0 6h-4"}),(0,r.jsx)("path",{d:"m16 16-2 2 2 2"}),(0,r.jsx)("path",{d:"M3 18h7"})]})})})]}),!eh&&(0,r.jsx)(i8,{filePath:e,sourceSessionId:n})]})]}),g?.truncated&&(0,r.jsxs)("div",{className:"file-viewer-load-more",children:[(0,r.jsxs)("span",{children:[i5(g.nextOffset)," / ",i5(g.size)]}),(0,r.jsx)("button",{type:"button",className:"file-viewer-mode-button",disabled:T,onClick:()=>{E(!0),ed(e,g.nextOffset).finally(()=>E(!1))},children:T?f("i18n.loading"):f("i18n.loadMore")})]}),(0,r.jsx)("div",{ref:ee,className:"file-viewer-content",onScroll:e=>{let t={scrollTop:e.currentTarget.scrollTop,scrollLeft:e.currentTarget.scrollLeft};er.current.scrollTop=t.scrollTop,er.current.scrollLeft=t.scrollLeft,er.current.scrollByMode={...er.current.scrollByMode,[ek]:t}},style:{flex:1,overflow:"auto",background:"var(--bg)",paddingBottom:g?.truncated?48:void 0},children:"diff"===ek&&eu?(0,r.jsx)(i6,{patch:y.patch}):ev&&"preview"===ek?(0,r.jsx)("iframe",{srcDoc:ex,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:f("i18n.htmlPreview")}):eb&&"preview"===ek?(0,r.jsxs)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:[ef?.data&&(0,r.jsx)(iJ,{data:ef.data}),(0,r.jsx)(eQ.oz,{remarkPlugins:to,rehypePlugins:ts,urlTransform:o?e7:void 0,components:{code({className:e,children:t,...n}){let i=e?.replace("language-","").toLowerCase()??"",o=String(t);return e?.includes("language-")||o.includes("\n")?"mermaid"===i?(0,r.jsx)(tT,{code:o.replace(/\n$/,""),defaultPreview:!0}):(0,r.jsx)(tL,{code:o.replace(/\n$/,""),lang:i}):(0,r.jsx)("code",{className:["markdown-inline-code",e].filter(Boolean).join(" "),...n,children:t})},table:({children:e})=>(0,r.jsx)("div",{className:"markdown-table-wrap",children:(0,r.jsx)("table",{children:e})}),pre:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),a({href:e,children:n,...i}){delete i.node;let l=o?eU(e,eT,t??eT):null;return l&&o?(0,r.jsx)("a",{href:e,...i,onClick:e=>{eF(e)&&(e.preventDefault(),o(l))},children:n}):(0,r.jsx)("a",{href:e,...i,target:"_blank",rel:"noopener noreferrer",children:n})},img({src:e,alt:i,...o}){delete o.node;let l="string"==typeof e?eU(e,eT,t??eT):null,s=l?i4(l,"read",n):e;return(0,r.jsx)("img",{src:s,alt:i??"",loading:"lazy",...o})}},children:ep})]}):ej?(0,r.jsx)("div",{className:"file-source-view is-lightweight",style:{width:U?"100%":"max-content",minWidth:"100%",minHeight:"100%",background:"var(--bg)",...iG},children:eI}):eC})]})}function oi(e,t){if(t<=0)return"";let n=Math.max(0,e.length-1-t);return e.slice(n,-1).join("/")||e[0]||""}function oo(e,t){return t?`${e} \xb7 ${t}`:e}function ol(e){let t=new Map;for(let n of e)t.set(n,(t.get(n)??0)+1);return t}function os({tabs:e,activeTabId:t,onSelectTab:n,onCloseTab:o}){let{t:l}=(0,x.s)(),[s,a]=(0,i.useState)(null),d=(0,i.useRef)(null),c=(0,i.useRef)(!1),u=(0,i.useMemo)(()=>(function(e){let t=new Map,n=new Map;for(let t of e){let e=function(e){let t=e.label?.trim();return t||E(e.path)||e.path}(t),r=n.get(e);r?r.push(t):n.set(e,[t])}for(let[e,r]of n){if(1===r.length){t.set(r[0].id,e);continue}let n=r.map(e=>(function(e){let t=M(e).replace(/\/+$/,"");return t?/^[a-zA-Z]:$/.test(t)?[t]:t.split("/").filter((e,t)=>e.length>0||0===t):[]})(e.path)),i=n.map(e=>Math.max(0,e.length-1)),o=r.map(()=>0),l=!0;for(;l;){l=!1;let t=r.map((t,r)=>oo(e,oi(n[r],o[r]))),s=ol(t);for(let e=0;e<r.length;e+=1)!((s.get(t[e])??0)<=1)&&(o[e]>=i[e]||(o[e]+=1,l=!0))}let s=r.map((t,r)=>oo(e,oi(n[r],o[r]))),a=ol(s);r.forEach((n,r)=>{t.set(n.id,(a.get(s[r])??0)>1?e:s[r])})}return t})(e.map(e=>({id:e.id,path:e.filePath,label:e.label}))),[e]);return(0,i.useEffect)(()=>{d.current?.scrollIntoView({block:"nearest",inline:"nearest"}),c.current&&(c.current=!1,d.current?.focus())},[t,e]),(0,r.jsx)("div",{role:"tablist",style:{display:"flex",alignItems:"stretch",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:"100%"},children:e.map(i=>{let h=i.id===t,p=u.get(i.id)??i.label;return(0,r.jsxs)("div",{ref:h?d:null,role:"tab","aria-label":"terminal"===i.kind?l("terminal.tabLabel",{name:p}):p,"aria-selected":h,tabIndex:h||!t&&e[0].id===i.id?0:-1,onKeyDown:t=>{if(t.target===t.currentTarget){if("Enter"===t.key||" "===t.key)t.preventDefault(),n(i.id);else if(["ArrowLeft","ArrowRight","Home","End"].includes(t.key)){t.preventDefault();let r=e.findIndex(e=>e.id===i.id),o="Home"===t.key?0:"End"===t.key?e.length-1:(r+("ArrowRight"===t.key?1:-1)+e.length)%e.length;n(e[o].id),t.currentTarget.parentElement?.children[o]?.focus()}}},onClick:()=>n(i.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:e=>{1===e.button&&(e.preventDefault(),e.stopPropagation(),i.closing||o(i.id))},style:{display:"flex",alignItems:"center",gap:6,height:"100%",paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:h?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:h?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,r.jsx)("span",{style:{flexShrink:0,opacity:h?1:.7,display:"inline-flex",alignItems:"center",transform:"translateY(0.5px)"},children:"terminal"===i.kind?(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},"aria-hidden":"true",children:[(0,r.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,r.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}):I(i.label,13)}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,lineHeight:1,fontWeight:h?500:400},title:i.filePath,children:p}),(0,r.jsx)("button",{type:"button",className:"file-tab-close",disabled:i.closing,onClick:e=>{e.stopPropagation(),a(null),c.current=!0,o(i.id)},onMouseEnter:()=>a(i.id),onMouseLeave:()=>a(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,background:s===i.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:4,color:s===i.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:l("terminal"===i.kind?"terminal.close":"i18n.close"),"aria-label":`${l("terminal"===i.kind?"terminal.close":"i18n.close")} ${p}`,children:(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,r.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},i.id)})})}function oa(e,t){let n=e.findIndex(e=>e.id===t);if(-1===n)return null;let r=e.filter(e=>e.id!==t);return r[Math.min(n,r.length-1)]?.id??null}let od=["general","models","agents","images","skills","plugins"],oc="pi-web:settings-navigation",ou=new Set(["skills","agents","plugins"]);function oh(){try{return window.localStorage}catch{return null}}function op(e){let t=e.getItem(oc);if(!t)return{};try{let e=JSON.parse(t);if(null===e||"object"!=typeof e||Array.isArray(e))return{};return{section:"string"==typeof e.section?e.section:void 0,selections:null===e.selections||"object"!=typeof e.selections||Array.isArray(e.selections)?void 0:e.selections}}catch{return{}}}function of(e,t){return"models"===e?e:t?JSON.stringify([e,t]):null}function og(e,t=oh()){if(t)try{let n=op(t);n.section=e,t.setItem(oc,JSON.stringify(n))}catch{}}function ox(e,t,n=oh()){if(!n)return null;let r=of(e,t);if(!r)return null;try{let e=op(n).selections?.[r];return"string"==typeof e&&e.length>0?e:null}catch{return null}}function om(e,t,n,r=oh()){if(!r||!t)return;let i=of(e,n);if(i)try{let e=op(r);e.selections={...e.selections,[i]:t},r.setItem(oc,JSON.stringify(e))}catch{}}let oy="pi-auto-session-title";function ov(){try{return"false"!==window.localStorage.getItem(oy)}catch{return!0}}let ob=["input","output","cacheRead","cacheWrite"];function ow(e){return{input:e?.input===void 0?"":String(e.input),output:e?.output===void 0?"":String(e.output),cacheRead:e?.cacheRead===void 0?"":String(e.cacheRead),cacheWrite:e?.cacheWrite===void 0?"":String(e.cacheWrite)}}function ok(e){if(!oj(e))return;let t=e=>{if(!e.trim())return 0;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0},n=t(e.input),r=t(e.output),i=t(e.cacheRead),o=t(e.cacheWrite);if(void 0!==n&&void 0!==r&&void 0!==i&&void 0!==o)return{input:n,output:r,cacheRead:i,cacheWrite:o}}function oj(e){return ob.some(t=>""!==e[t].trim())}let oS=["name","api","reasoning","thinkingLevelMap","input","contextWindow","maxTokens","cost","headers","compat"];function oC({embedded:e,title:t,subtitle:n,closeLabel:i="Close",onClose:o,children:l,width:s=900,height:a="78vh"}){let d=e?void 0:{"--config-panel-width":`${s}px`,"--config-panel-height":a};return(0,r.jsx)("div",{role:e?void 0:"dialog","aria-modal":e?void 0:"true","aria-label":t,className:`config-panel-root ${e?"is-embedded":"is-modal"}`,onClick:t=>{e||t.target!==t.currentTarget||o()},children:(0,r.jsxs)("div",{className:"config-panel-surface",style:d,children:[!e&&(0,r.jsxs)("div",{className:"config-panel-header",children:[(0,r.jsx)("strong",{className:"config-panel-title",children:t}),n&&(0,r.jsx)("code",{className:"config-panel-subtitle",title:n,children:n}),(0,r.jsx)("button",{type:"button",className:"config-close-button",onClick:o,title:i,"aria-label":i,children:"\xd7"})]}),l]})})}function oI({children:e}){return(0,r.jsx)("div",{className:"config-split-view",children:e})}function oM({children:e}){return(0,r.jsx)("aside",{className:"config-sidebar",children:e})}function oT({children:e}){return(0,r.jsx)("div",{className:"config-sidebar-list",children:e})}function oE({children:e}){return(0,r.jsx)("div",{className:"config-sidebar-group-label",children:e})}function oL({active:e=!1,className:t,children:n,...i}){return(0,r.jsx)("button",{type:"button",...i,"aria-current":e?"page":void 0,className:["config-sidebar-item",t].filter(Boolean).join(" "),children:n})}function oR({className:e,...t}){return(0,r.jsx)("span",{...t,className:["config-sidebar-text",e].filter(Boolean).join(" ")})}function oN({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-stack",e].filter(Boolean).join(" ")})}function o$({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-header",e].filter(Boolean).join(" ")})}function oW({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-header-info",e].filter(Boolean).join(" ")})}function oz({className:e,...t}){return(0,r.jsx)("div",{...t,className:["config-detail-actions",e].filter(Boolean).join(" ")})}function oP({children:e}){return(0,r.jsx)("div",{className:"config-detail-title",children:e})}function oA({children:e}){return(0,r.jsx)("div",{className:"config-section-title",children:e})}function oD({label:e,children:t,style:n}){return(0,r.jsxs)("div",{className:"config-field",style:n,children:[(0,r.jsx)("span",{className:"config-field-label",children:e}),t]})}function oF({children:e}){return(0,r.jsx)("div",{className:"config-empty-state",children:e})}function oB({children:e,style:t}){return(0,r.jsx)("div",{className:"config-detail",style:t,children:e})}function oH({status:e,children:t}){return(0,r.jsxs)("footer",{className:"config-footer",children:[(0,r.jsx)("div",{className:"config-footer-status",children:e}),(0,r.jsx)("div",{className:"config-footer-actions",children:t})]})}function oO({variant:e="secondary",size:t="default",className:n,children:i,...o}){return(0,r.jsx)("button",{type:"button",...o,className:["config-button",`config-button-${e}`,`config-button-${t}`,n].filter(Boolean).join(" "),children:i})}function oU({checked:e,disabled:t=!1,loading:n=!1,label:i,onChange:o}){let l=t||n;return(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":e,"aria-busy":n||void 0,"aria-label":i,title:i,disabled:l,className:`config-switch${n?" is-loading":""}`,onClick:()=>o(!e),children:(0,r.jsx)("span",{className:"config-switch-knob","aria-hidden":"true"})})}function o_({active:e=!1,children:t,className:n,...i}){return(0,r.jsx)("div",{className:"config-list-action",children:(0,r.jsxs)("button",{type:"button",...i,"aria-current":e?"page":void 0,className:["config-list-action-button",n].filter(Boolean).join(" "),children:[(0,r.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M12 5v14M5 12h14"})}),t]})})}function oq({active:e,color:t}){return(0,r.jsx)("span",{"aria-hidden":"true",className:`config-status-dot${e?" is-active":!1===e?" is-inactive":""}`,style:t?{backgroundColor:t}:void 0})}let oK={anthropic:{symbol:"anthropic",color:!1},openai:{symbol:"openai",color:!1},"openai-codex":{symbol:"openai",color:!1},google:{symbol:"google",color:!0},"google-vertex":{symbol:"google",color:!0},"ant-ling":{symbol:"antgroup",color:!0},deepseek:{symbol:"deepseek",color:!0},groq:{symbol:"groq",color:!1},mistral:{symbol:"mistral",color:!0},moonshotai:{symbol:"moonshot",color:!1},"moonshotai-cn":{symbol:"moonshot",color:!1},moonshot:{symbol:"moonshot",color:!1},minimax:{symbol:"minimax",color:!0},"minimax-cn":{symbol:"minimax",color:!0},fireworks:{symbol:"fireworks",color:!0},huggingface:{symbol:"huggingface",color:!0},cerebras:{symbol:"cerebras",color:!0},openrouter:{symbol:"openrouter",color:!1},xai:{symbol:"xai",color:!1},"cloudflare-ai-gateway":{symbol:"cloudflare",color:!0},"cloudflare-workers-ai":{symbol:"cloudflare",color:!0},"vercel-ai-gateway":{symbol:"vercel",color:!1},"github-copilot":{symbol:"githubcopilot",color:!1},"amazon-bedrock":{symbol:"aws",color:!0},"azure-openai-responses":{symbol:"azure",color:!0},"kimi-coding":{symbol:"kimi",color:!0},nvidia:{symbol:"nvidia",color:!0},opencode:{symbol:"opencode",color:!1},"opencode-go":{symbol:"opencode",color:!1},qwen:{symbol:"qwen",color:!0},xiaomi:{symbol:"xiaomimimo",color:!1},"xiaomi-token-plan-ams":{symbol:"xiaomimimo",color:!1},"xiaomi-token-plan-cn":{symbol:"xiaomimimo",color:!1},"xiaomi-token-plan-sgp":{symbol:"xiaomimimo",color:!1},zai:{symbol:"zai",color:!1},"zai-coding-cn":{symbol:"zai",color:!1},zhipu:{symbol:"zhipu",color:!0},cohere:{symbol:"cohere",color:!0},perplexity:{symbol:"perplexity",color:!0},together:{symbol:"together",color:!0},grok:{symbol:"grok",color:!1}};function oV({id:e,size:t}){let n=oK[e];if(n)return(0,r.jsx)("svg",{"aria-hidden":"true",width:t,height:t,viewBox:"0 0 24 24",fill:n.color?void 0:"currentColor",style:{color:"var(--text-muted)",flexShrink:0},children:(0,r.jsx)("use",{href:`/provider-icons.svg#${n.symbol}`})});let i=e.split(/[-_]/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?";return(0,r.jsx)("span",{"aria-hidden":"true",style:{width:t,height:t,border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontSize:Math.max(8,Math.floor(.42*t)),fontWeight:700,lineHeight:1},children:i})}function oJ(){let e=ox("models");if(!e)return null;try{let t=JSON.parse(e);if(null===t||"object"!=typeof t)return null;if("provider"===t.type&&"string"==typeof t.name)return{type:"provider",name:t.name};if("model"===t.type&&"string"==typeof t.providerName&&"number"==typeof t.index&&Number.isInteger(t.index)&&t.index>=0)return{type:"model",providerName:t.providerName,index:t.index};if("runtime-model"===t.type&&"string"==typeof t.providerName&&"string"==typeof t.id)return{type:"runtime-model",providerName:t.providerName,id:t.id};if(("oauth"===t.type||"apikey"===t.type)&&"string"==typeof t.providerId)return{type:t.type,providerId:t.providerId}}catch{}return null}function oY(e){return{id:e.id,name:e.name,api:e.api,reasoning:e.reasoning,thinkingLevelMap:e.thinkingLevelMap,input:e.input,contextWindow:e.contextWindow,maxTokens:e.maxTokens,cost:e.cost,headers:e.headers,compat:e.compat}}let oZ=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function oG({label:e,children:t}){return(0,r.jsx)(oD,{label:e,children:t})}let oX={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 oQ({value:e,onChange:t,placeholder:n,mono:i,disabled:o}){return(0,r.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:n,disabled:o,style:{...oX,fontFamily:i?"var(--font-mono)":"inherit",opacity:o?.7:1}})}function o0({value:e,onChange:t,placeholder:n,mono:o,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,u]=(0,i.useState)(!1),{t:h}=(0,x.s)();return(0,i.useEffect)(()=>{e||u(!1)},[e]),(0,r.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,r.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:n,style:{...oX,paddingRight:34,fontFamily:o?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,r.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":h(c?"i18n.hideDetails":"i18n.showDetails"),title:h(c?"i18n.hideDetails":"i18n.showDetails"),style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,r.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,r.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,r.jsx)("path",{d:"M1 1l22 22"})]}):(0,r.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function o1({value:e,onChange:t,placeholder:n}){return(0,r.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:n,style:oX})}function o2({value:e,onChange:t,options:n,required:i}){let{t:o}=(0,x.s)();return(0,r.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...oX,color:e?"var(--text)":"var(--text-dim)"},children:[!i&&(0,r.jsxs)("option",{value:"",children:["— ",o("i18n.default")," / none —"]}),n.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]})}function o4({label:e,checked:t,onChange:n}){return(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:e=>n(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function o8({children:e}){return(0,r.jsx)(oA,{children:e})}function o5({name:e,provider:t,onChange:n,onRename:o,onDelete:l,onAddModels:s}){let{t:a}=(0,x.s)(),[d,c]=(0,i.useState)(e),[u,h]=(0,i.useState)({phase:"idle"}),[p,f]=(0,i.useState)(""),[g,m]=(0,i.useState)([]),y=(0,i.useRef)(0),v=(0,i.useRef)(null);(0,i.useEffect)(()=>c(e),[e]);let b=(e,r)=>n({...t,[e]:r});(0,i.useEffect)(()=>{t.api||n({...t,api:"openai-completions"})},[t.api]),(0,i.useEffect)(()=>{y.current+=1,h({phase:"idle"}),f(""),m([])},[e,t.baseUrl,t.api,t.apiKey]);let w=(0,i.useCallback)(async()=>{if(!t.baseUrl?.trim()||"loading"===u.phase)return;let n=++y.current;h({phase:"loading"}),m([]);try{let r=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:{...t,models:void 0}})}),i=await r.json();if(n!==y.current)return;if(!r.ok||i.error||!i.models)return void h({phase:"error",message:i.error??`HTTP ${r.status}`});h({phase:"success",models:i.models,endpoint:i.endpoint??t.baseUrl})}catch(e){if(n!==y.current)return;h({phase:"error",message:e instanceof Error?e.message:String(e)})}},[u.phase,e,t]),k=new Set((t.models??[]).map(e=>e.id)),j="success"===u.phase?u.models:[],S=p.trim().toLocaleLowerCase(),C=j.filter(e=>!S||e.id.toLocaleLowerCase().includes(S)||e.name?.toLocaleLowerCase().includes(S)),I=C.slice(0,300),M=I.filter(e=>!k.has(e.id)).map(e=>e.id),T=g.filter(e=>!k.has(e)).length,E=M.length>0&&M.every(e=>g.includes(e)),L=!E&&M.some(e=>g.includes(e));return(0,i.useEffect)(()=>{v.current&&(v.current.indeterminate=L)},[L]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(o8,{children:a("i18n.provider")}),(0,r.jsx)("button",{onClick:l,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:a("i18n.delete")})]}),(0,r.jsxs)(oG,{label:a("i18n.providerName"),children:[(0,r.jsx)(oQ,{value:d,onChange:c,placeholder:"provider-name",mono:!0}),d!==e&&d.trim()&&(0,r.jsx)("button",{onClick:()=>o(d.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:a("i18n.rename")})]}),(0,r.jsx)(oG,{label:"Base URL",children:(0,r.jsx)(oQ,{value:t.baseUrl??"",onChange:e=>b("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,r.jsxs)(oG,{label:"API Key",children:[(0,r.jsx)(o0,{value:t.apiKey??"",onChange:e=>b("apiKey",e||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,r.jsx)(oG,{label:"API",children:(0,r.jsx)(o2,{value:t.api??"openai-completions",onChange:e=>b("api",e),options:oZ,required:!0})}),(0,r.jsxs)(oG,{label:"Headers",children:[(0,r.jsx)(lt,{headers:t.headers,onChange:e=>b("headers",e)}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Added to every request from this provider (e.g. User-Agent). Useful for gateways with bot detection."})]}),(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:14,display:"flex",flexDirection:"column",gap:10},children:["success"!==u.phase&&(0,r.jsx)("button",{onClick:w,disabled:!t.baseUrl?.trim()||"loading"===u.phase,style:{alignSelf:"flex-start",height:30,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:t.baseUrl?.trim()&&"loading"!==u.phase?"var(--text-muted)":"var(--text-dim)",cursor:t.baseUrl?.trim()&&"loading"!==u.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===u.phase?a("models.discoveryFetching"):a("models.discoveryFetch")}),"error"===u.phase&&(0,r.jsx)("div",{style:{padding:"7px 9px",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",fontSize:11,lineHeight:1.4},children:u.message}),"success"===u.phase&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{value:p,onChange:e=>f(e.target.value),placeholder:a("models.discoveryFilterPlaceholder",{count:u.models.length}),"aria-label":a("models.discoveryFilter"),style:{...oX,width:"100%",minWidth:0}}),(0,r.jsxs)("div",{style:{maxHeight:220,overflowY:"auto",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)"},children:[(0,r.jsxs)("label",{style:{minHeight:32,padding:"5px 9px",display:"flex",alignItems:"center",gap:8,position:"sticky",top:0,zIndex:1,borderBottom:"1px solid var(--border)",background:"var(--bg)",cursor:M.length?"pointer":"default",color:"var(--text-muted)",fontSize:10,fontWeight:600},children:[(0,r.jsx)("input",{ref:v,type:"checkbox",checked:E,disabled:0===M.length,onChange:()=>{let e=new Set(M);m(t=>E?t.filter(t=>!e.has(t)):Array.from(new Set([...t,...M])))},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),a("models.discoverySelectShown")]}),0===I.length?(0,r.jsx)("div",{style:{padding:12,color:"var(--text-dim)",fontSize:11},children:a("models.discoveryNoMatches")}):I.map((e,t)=>{let n=k.has(e.id),i=g.includes(e.id);return(0,r.jsxs)("label",{style:{minHeight:36,padding:"6px 9px",display:"flex",alignItems:"center",gap:8,borderTop:0===t?"none":"1px solid var(--border)",cursor:n?"default":"pointer",opacity:n?.65:1},children:[(0,r.jsx)("input",{type:"checkbox",checked:i||n,disabled:n,onChange:()=>{var t;return t=e.id,void m(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),(0,r.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11},children:e.name??e.id}),e.name&&(0,r.jsx)("code",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)"},children:e.id})]}),n&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10},children:a("models.discoveryAdded")})]},e.id)})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,r.jsx)("span",{title:u.endpoint,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:C.length>I.length?a("models.discoveryShowing",{shown:I.length,total:C.length}):a("models.discoveryFetched",{count:u.models.length})}),(0,r.jsx)("button",{onClick:()=>{if("success"!==u.phase)return;let e=new Set(g),t=u.models.filter(t=>e.has(t.id)&&!k.has(t.id));0!==t.length&&(s(t),m([]))},disabled:0===T,style:{height:28,padding:"0 11px",border:"none",borderRadius:5,background:T?"var(--accent)":"var(--bg-panel)",color:T?"#fff":"var(--text-dim)",cursor:T?"pointer":"not-allowed",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:T?a("models.discoveryAddSelectedCount",{count:T}):a("models.discoveryAddSelected")})]})]})]})]})}let o6=["off","minimal","low","medium","high","xhigh","max"],o3={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function o7({value:e,onChange:t}){let n=e??{},i=(e,r)=>{let i={...n};"omit"===r?delete i[e]:i[e]=r,t(Object.keys(i).length?i:void 0)};return(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:o6.map(e=>{let t=n[e],o=e in n?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=o3[e],a={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,r.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:s,flexShrink:0,opacity:"null"===o?.3:1}}),(0,r.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===o?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===o?"line-through":"none"},children:e})]}),(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,r.jsx)("button",{onClick:()=>i(e,"omit"),style:{...a,..."omit"===o?d:{}},children:"Default"}),(0,r.jsx)("button",{onClick:()=>i(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===o?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===o?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,r.jsx)("button",{onClick:()=>i(e,l||e),style:{...a,..."string"===o?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,r.jsx)("input",{value:l,onChange:t=>i(e,t.target.value),onFocus:()=>{"string"!==o&&i(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===o?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===o?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let o9={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function le(e){return e.compat?.thinkingFormat==="deepseek"}function lt({headers:e,onChange:t}){let[n,o]=(0,i.useState)(()=>Object.entries(e??{}).map(([e,t],n)=>({id:n,name:e,value:t}))),l=(0,i.useRef)(n.length),s=e=>{o(e),t(function(e){let t={};for(let n of e){let e=n.name.trim();e&&(t[e]=n.value)}return Object.keys(t).length?t:void 0}(e))},a=(e,t)=>{s(n.map(n=>n.id===e?{...n,...t}:n))},d={padding:"6px 9px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,lineHeight:1};return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[n.map(e=>(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("input",{value:e.name,onChange:t=>a(e.id,{name:t.target.value}),placeholder:"Header-Name",style:{...oX,fontFamily:"var(--font-mono)",flex:1}}),(0,r.jsx)("input",{value:e.value,onChange:t=>a(e.id,{value:t.target.value}),placeholder:"value",style:{...oX,fontFamily:"var(--font-mono)",flex:1}}),(0,r.jsx)("button",{onClick:()=>{var t;return t=e.id,void s(n.filter(e=>e.id!==t))},style:d,children:"✕"})]},e.id)),(0,r.jsx)("button",{onClick:()=>o(e=>[...e,{id:l.current++,name:"",value:""}]),style:{padding:"5px 9px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:5,alignSelf:"flex-start"},children:"+ Add header"})]})}function ln({providerName:e,provider:t,model:n,onChange:o,onDelete:l,lockId:s=!1}){let[a,d]=(0,i.useState)({phase:"idle"}),{t:c}=(0,x.s)(),[u,h]=(0,i.useState)({phase:"idle"}),[p,f]=(0,i.useState)(!1),[g,m]=(0,i.useState)(()=>ow(n.cost)),y=(0,i.useRef)(g),[v,b]=(0,i.useState)(!1),w=(0,i.useRef)(0),k=(0,i.useRef)(null),j=(0,i.useRef)(n.cost),S=(e,t)=>o({...n,[e]:t}),C=(()=>{if("idle"===a.phase)return null;if("testing"===a.phase)return c("i18n.testingModel");let e=[void 0!==a.latencyMs?`${a.latencyMs}ms`:null,void 0!==a.status?`HTTP ${a.status}`:null].filter(Boolean);return"success"===a.phase?[c("i18n.connected"),...e,a.responseText||null].filter(Boolean).join(" \xb7 "):[c("i18n.failed"),...e,a.message].filter(Boolean).join(" \xb7 ")})();(0,i.useEffect)(()=>{d({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,n.id,n.api]),(0,i.useEffect)(()=>{w.current+=1,h({phase:"idle"}),k.current=null},[e,t.baseUrl,n.id]);let I=(0,i.useCallback)(async()=>{if(n.id.trim()&&"testing"!==a.phase){d({phase:"testing"});try{let r=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:n})}),i=await r.json();if(!r.ok||!i.ok)return void d({phase:"error",message:i.error??`HTTP ${r.status}`,latencyMs:i.latencyMs,status:i.status});d({phase:"success",latencyMs:i.latencyMs,status:i.status,responseText:i.responseText})}catch(e){d({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[n,t,e,a.phase]),M=(0,i.useCallback)(async()=>{let r=n.id.trim();if(!r||"loading"===u.phase)return;let i=++w.current;h({phase:"loading"});try{let l=new URLSearchParams({q:r,provider:e,limit:"50"});t.baseUrl?.trim()&&l.set("baseUrl",t.baseUrl.trim());let s=await fetch(`/api/models-config/catalog?${l}`),a=await s.json();if(i!==w.current)return;if(!s.ok||a.error||!a.recommendation)return void h({phase:"error",message:a.error??`HTTP ${s.status}`});let d=function(e,t){let n={...e},r=0;if(!e.name?.trim()&&t.name&&(n.name=t.name,r+=1),void 0===e.reasoning&&!0===t.reasoning&&(n.reasoning=!0,r+=1),!e.input?.length&&t.input?.length&&(n.input=[...t.input],r+=1),void 0===e.contextWindow&&void 0!==t.contextWindow&&(n.contextWindow=t.contextWindow,r+=1),void 0===e.maxTokens&&void 0!==t.maxTokens&&(n.maxTokens=t.maxTokens,r+=1),t.cost){let i={...e.cost??{}},o=0;for(let e of["input","output","cacheRead","cacheWrite"])void 0===i[e]&&void 0!==t.cost[e]&&(i[e]=t.cost[e],o+=1);let l=ok(ow(i));o>0&&l&&(n.cost={...i,...l},r+=o)}return{model:n,appliedCount:r}}(n,a.recommendation.preset);d.appliedCount>0&&(k.current=n,o(d.model)),f(!1),h({phase:"success",recommendation:a.recommendation,appliedCount:d.appliedCount})}catch(e){if(i!==w.current)return;h({phase:"error",message:e instanceof Error?e.message:String(e)})}},[u.phase,n,o,t.baseUrl,e]),T=(()=>{if("success"!==u.phase)return null;let{recommendation:t,appliedCount:n}=u,r=n>0?c("models.catalogFilled",{count:n}):c("models.catalogNoEmptyFields");if("unreliable"===t.price.status){let e="no-exact-match"===t.price.reason?c("models.catalogNoExactMatch"):c("models.catalogPriceUnreliable");return`${r} \xb7 ${e}`}let i="provider"===t.price.method?c("models.catalogPriceProvider",{provider:t.price.providerName??t.price.providerId??e}):"base-url"===t.price.method?c("models.catalogPriceBaseUrl",{provider:t.price.providerName??t.price.providerId??e}):c("models.catalogPriceConsensus",{support:t.price.support,total:t.price.total});return`${r} \xb7 ${i}`})(),E="error"===u.phase?u.message:T,L="error"===u.phase?"#ef4444":"success"===u.phase&&"unreliable"===u.recommendation.price.status?"#d97706":"var(--text-dim)",R=[{key:"input",label:c("models.costInput")},{key:"output",label:c("models.costOutput")},{key:"cacheRead",label:c("models.costCacheRead")},{key:"cacheWrite",label:c("models.costCacheWrite")}],N=new Set(Object.keys(n.compat??{})),$=0;le(n)&&($+=1,N.delete("thinkingFormat"),N.delete("requiresReasoningContentOnAssistantMessages")),Object.prototype.hasOwnProperty.call(n.compat??{},"supportsDeveloperRole")&&($+=1,N.delete("supportsDeveloperRole")),$+=N.size;let W=[n.api?`API: ${n.api}`:null,Object.keys(n.headers??{}).length?c("models.headersSummary",{count:Object.keys(n.headers??{}).length}):null,$?c("models.compatSummary",{count:$}):null,Object.keys(n.thinkingLevelMap??{}).length?c("models.thinkingSummary",{count:Object.keys(n.thinkingLevelMap??{}).length}):null].filter(e=>!!e),z=W.length?W.join(" \xb7 "):c("models.providerDefaults");return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(o8,{children:c("i18n.model")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C&&(0,r.jsx)("span",{title:C,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===a.phase?"#fecaca":"success"===a.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===a.phase?"#fee2e2":"success"===a.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:C}),(0,r.jsxs)("button",{onClick:I,disabled:!n.id.trim()||"testing"===a.phase,title:c("i18n.testConnection"),style:{height:24,padding:"0 8px",background:"success"===a.phase?"#16a34a":"none",border:`1px solid ${"success"===a.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===a.phase?"#fff":n.id.trim()&&"testing"!==a.phase?"var(--text-muted)":"var(--text-dim)",cursor:n.id.trim()&&"testing"!==a.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===a.phase&&(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===a.phase?c("i18n.checking"):"success"===a.phase?c("common.ok"):c("i18n.test")]}),l&&(0,r.jsx)("button",{onClick:l,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:c("i18n.remove")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,r.jsx)(oG,{label:"ID *",children:(0,r.jsx)(oQ,{value:n.id,onChange:e=>S("id",e),placeholder:"model-id",mono:!0,disabled:s})}),(0,r.jsx)(oG,{label:"Name",children:(0,r.jsx)(oQ,{value:n.name??"",onChange:e=>S("name",e||void 0),placeholder:"Display name"})})]}),(0,r.jsxs)("div",{style:{padding:"2px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:()=>void M(),disabled:!n.id.trim()||"loading"===u.phase,style:{height:28,padding:"0 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:n.id.trim()&&"loading"!==u.phase?"var(--text-muted)":"var(--text-dim)",cursor:n.id.trim()&&"loading"!==u.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===u.phase?c("models.catalogFilling"):c("models.catalogFill")}),(0,r.jsx)("a",{href:"https://github.com/anomalyco/models.dev",target:"_blank",rel:"noreferrer",style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10,textDecoration:"none"},children:c("models.catalogSource")})]}),E&&(0,r.jsxs)("div",{"aria-live":"polite",style:{marginTop:8,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:L,fontSize:10},children:[(0,r.jsx)("span",{title:E,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:E}),k.current&&(0,r.jsx)("button",{onClick:()=>{let e=k.current;e&&(k.current=null,o(e),h({phase:"idle"}))},style:{flexShrink:0,padding:"0 2px",border:"none",background:"none",color:"var(--accent)",cursor:"pointer",fontSize:10},children:c("models.catalogUndo")})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(o8,{children:c("models.capabilities")}),(0,r.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap",marginTop:8},children:[(0,r.jsx)(o4,{label:c("models.reasoning"),checked:n.reasoning??!1,onChange:e=>S("reasoning",e||void 0)}),(0,r.jsx)(o4,{label:c("models.imageInput"),checked:n.input?.includes("image")??!1,onChange:e=>S("input",e?["text","image"]:void 0)})]})]}),(0,r.jsxs)("section",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,r.jsx)(o8,{children:c("models.modelSpecs")}),(0,r.jsx)("button",{type:"button",onClick:()=>{if(p)return void f(!1);j.current=n.cost;let e=ow(n.cost);y.current=e,m(e),f(!0)},"aria-expanded":p,style:{padding:"2px 4px",border:"none",background:"transparent",color:"var(--accent)",cursor:"pointer",fontSize:10},children:p?c("models.finishEditingCosts"):c("models.editCosts")})]}),(0,r.jsxs)("div",{style:{marginTop:10,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:10},children:[(0,r.jsx)(oG,{label:c("models.contextWindow"),children:(0,r.jsx)(o1,{value:void 0!==n.contextWindow?String(n.contextWindow):"",onChange:e=>S("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,r.jsx)(oG,{label:c("models.maxOutputTokens"),children:(0,r.jsx)(o1,{value:void 0!==n.maxTokens?String(n.maxTokens):"",onChange:e=>S("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,r.jsxs)("div",{style:{marginTop:16},children:[(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontWeight:600,textTransform:"uppercase"},children:c("models.costPerMillion")}),p?(0,r.jsxs)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(110px, 1fr))",gap:8},children:[R.map(({key:e,label:t})=>(0,r.jsx)(oG,{label:t,children:(0,r.jsx)(o1,{value:g[e],onChange:t=>{let r,i,l;return i=ok(r={...y.current,[e]:t}),l={...n},void(y.current=r,m(r),i?(l.cost={...j.current??{},...i},j.current=l.cost):delete l.cost,o(l))},placeholder:"0"})},e)),oj(g)&&!ok(g)&&(0,r.jsx)("div",{"aria-live":"polite",style:{gridColumn:"1 / -1",color:"#d97706",fontSize:10},children:c("models.costAllRequired")})]}):(0,r.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(105px, 1fr))",gap:"8px 16px"},children:R.map(({key:e,label:t})=>{let i,o=n.cost?.[e]===void 0;return(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t}),(0,r.jsx)("div",{style:{marginTop:3,color:o?"var(--text-dim)":"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:void 0===(i=n.cost?.[e])?c("models.notProvided"):`$${String(i)}`})]},e)})})]})]}),(0,r.jsxs)("section",{style:{borderTop:"1px solid var(--border)",paddingTop:4},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>b(e=>!e),"aria-expanded":v,"aria-controls":"model-advanced-settings",style:{width:"100%",minHeight:48,padding:"8px 0",border:"none",background:"transparent",display:"grid",gridTemplateColumns:"minmax(0, 1fr) 18px",alignItems:"center",gap:10,color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsxs)("span",{style:{minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:11,fontWeight:600},children:c("models.advancedSettings")}),(0,r.jsx)("span",{style:{display:"block",marginTop:3,color:"var(--text-dim)",fontSize:10,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z})]}),(0,r.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{color:"var(--text-dim)",transform:v?"rotate(180deg)":"none",transition:"transform 0.15s ease"},children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),v&&(0,r.jsxs)("div",{id:"model-advanced-settings",style:{display:"flex",flexDirection:"column",gap:14,padding:"4px 0 16px"},children:[(0,r.jsx)(oG,{label:c("models.apiOverride"),children:(0,r.jsx)(o2,{value:n.api??"",onChange:e=>S("api",e||void 0),options:oZ})}),(0,r.jsxs)(oG,{label:c("models.headers"),children:[(0,r.jsx)(lt,{headers:n.headers,onChange:e=>S("headers",e)}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:c("models.headersHelp")})]}),n.reasoning&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,r.jsx)(o8,{children:c("models.compatibility")}),(0,r.jsx)(o4,{label:c("models.deepSeekThinkingCompat"),checked:le(n),onChange:e=>o(function(e,t){if(t)return{...e,compat:{...e.compat??{},...o9}};if(!e.compat)return e;let n={...e.compat};return delete n.thinkingFormat,delete n.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(n).length?n:void 0}}(n,e))}),(0,r.jsx)(o4,{label:c("models.developerRole"),checked:!1!==({...t.compat??{},...n.compat??{}}).supportsDeveloperRole,onChange:e=>o({...n,compat:{...n.compat??{},supportsDeveloperRole:e}})}),(0,r.jsxs)("div",{style:{marginTop:4},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,marginBottom:8},children:[(0,r.jsx)(o8,{children:c("models.thinkingLevelMap")}),n.thinkingLevelMap&&(0,r.jsx)("button",{type:"button",onClick:()=>S("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 5px",background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer"},children:c("models.clearAll")})]}),(0,r.jsx)(o7,{value:n.thinkingLevelMap,onChange:e=>S("thinkingLevelMap",e)})]})]})]})]})]})}function lr({provider:e,onRefresh:t}){let[n,o]=(0,i.useState)({phase:"idle"}),{t:l}=(0,x.s)(),[s,a]=(0,i.useState)(""),d=(0,i.useRef)(null),c=(0,i.useRef)(null);(0,i.useEffect)(()=>{("auth"===n.phase||"prompt"===n.phase)&&setTimeout(()=>c.current?.focus(),50)},[n.phase]),(0,i.useEffect)(()=>{o({phase:"idle"}),a(""),d.current?.close(),d.current=null},[e.id]),(0,i.useEffect)(()=>()=>{d.current?.close()},[]);let u=(0,i.useCallback)(()=>{d.current?.close(),o({phase:"connecting"}),a("");let n=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);d.current=n,n.onmessage=e=>{let r=JSON.parse(e.data);"auth"===r.type?(o({phase:"auth",url:r.url,instructions:r.instructions??null,token:r.token}),window.open(r.url,"_blank","noopener,noreferrer")):"device_code"===r.type?(o({phase:"device_code",userCode:r.userCode,verificationUri:r.verificationUri,intervalSeconds:r.intervalSeconds??null,expiresInSeconds:r.expiresInSeconds??null}),window.open(r.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===r.type?o({phase:"prompt",message:r.message,placeholder:r.placeholder??null,token:r.token}):"select_request"===r.type?o({phase:"select",message:r.message,options:r.options??[],token:r.token}):"progress"===r.type?o({phase:"progress",message:r.message}):"success"===r.type?(n.close(),o({phase:"success"}),t()):"error"===r.type?(n.close(),o({phase:"error",message:r.message})):"cancelled"===r.type&&(n.close(),o({phase:"idle"}))},n.onerror=()=>{n.close(),o(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),h=(0,i.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),o({phase:"idle"}),t()},[e.id,t]),p=(0,i.useCallback)(async(t,n)=>{if(n.trim()){o({phase:"progress",message:"Verifying…"});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:n.trim()})});if(!r.ok){let e=await r.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${r.status}`});return}a("")}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),f=(0,i.useCallback)(async(t,n)=>{o({phase:"progress",message:"Continuing…"});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:n})});if(!r.ok){let e=await r.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${r.status}`})}}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),g="connecting"===n.phase||"progress"===n.phase||"auth"===n.phase||"device_code"===n.phase||"prompt"===n.phase||"select"===n.phase;return e.loggedIn&&"idle"===n.phase?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:12,color:"#4ade80"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:"#4ade80",display:"inline-block"}}),l("i18n.connected")]}),(0,r.jsxs)("span",{style:{display:"inline-flex",gap:8},children:[(0,r.jsx)("button",{onClick:u,style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:l("i18n.relogin")}),(0,r.jsx)("button",{onClick:h,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:l("i18n.disconnect")})]})]}):(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(o8,{children:l("i18n.subscription")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,r.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:l(e.loggedIn?"i18n.connected":"i18n.notConnected")})]})]}),(0,r.jsxs)("div",{style:{minHeight:48},children:["idle"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:l("i18n.openingBrowser")}),"select"===n.phase&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:n.message}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:n.options.map(e=>(0,r.jsx)("button",{onClick:()=>f(n.token,e.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:e.label},e.id))})]}),("auth"===n.phase||"prompt"===n.phase)&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===n.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":n.message}),"auth"===n.phase&&(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,r.jsx)("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("input",{ref:c,value:s,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p(n.token,s)},placeholder:"auth"===n.phase?"http://localhost:1455/auth/callback?code=…":n.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,r.jsx)("button",{onClick:()=>p(n.token,s),disabled:!s.trim(),style:{padding:"6px 12px",background:s.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:s.trim()?"#fff":"var(--text-dim)",cursor:s.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:l("i18n.submit")})]})]}),"device_code"===n.phase&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,r.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:n.userCode}),(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,r.jsx)("a",{href:n.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:n.verificationUri}),n.expiresInSeconds?` Expires in ${Math.ceil(n.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:n.message}),"success"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:l("i18n.connectedSuccessfully")}),"error"===n.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:n.message})]}),(0,r.jsx)("div",{style:{display:"flex",gap:8},children:g?(0,r.jsx)("button",{onClick:()=>{d.current?.close(),o({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:l("i18n.cancel")}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:u,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:l(e.loggedIn?"i18n.relogin":"i18n.login")}),e.loggedIn&&(0,r.jsx)("button",{onClick:h,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:l("i18n.disconnect")})]})})]})}function li({provider:e,onRefresh:t}){let[n,o]=(0,i.useState)(""),[l,s]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[h,p]=(0,i.useState)(!1),{t:f}=(0,x.s)();(0,i.useEffect)(()=>{o(""),u(null),p(!1)},[e.id]);let g=(0,i.useCallback)(async()=>{if(n.trim()){s(!0),u(null),p(!1);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:n.trim()})}),i=await r.json();!r.ok||i.error?u(i.error??`HTTP ${r.status}`):(o(""),p(!0),setTimeout(()=>p(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[n,e.id,t]),m=(0,i.useCallback)(async()=>{d(!0),u(null);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),r=await n.json();!n.ok||r.error?u(r.error??`HTTP ${n.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:12,color:e.configured?"#4ade80":"var(--text-dim)"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),f(e.configured?"i18n.configured":"i18n.notConfigured")]}),e.configured&&(0,r.jsx)("button",{onClick:m,disabled:a,style:{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:f(a?"i18n.removing":"i18n.disconnect")})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)(o0,{value:n,onChange:o,onKeyDown:e=>{"Enter"===e.key&&n.trim()&&g()},placeholder:e.configured?f("models.replaceKeyPlaceholder"):"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,r.jsxs)("button",{onClick:g,disabled:l||!n.trim()||h,style:{padding:"6px 12px",background:h?"#16a34a":n.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:n.trim()||h?"#fff":"var(--text-dim)",cursor:l||!n.trim()||h?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[h&&(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),f(h?"i18n.saved":l?"i18n.saving":"models.updateKey")]})]}),c&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c})]})}function lo({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:n,onSelectApiKey:o,onAddCustom:l,onClose:s}){let[a,d]=(0,i.useState)(""),{t:c}=(0,x.s)(),u=(0,i.useRef)(null);(0,i.useEffect)(()=>{setTimeout(()=>u.current?.focus(),30)},[]);let h=a.trim().toLowerCase(),p=e.filter(e=>!e.loggedIn&&(!h||e.name.toLowerCase().includes(h))),f=t.filter(e=>!e.configured&&(!h||e.displayName.toLowerCase().includes(h)||e.id.toLowerCase().includes(h))),g=!h||"custom".includes(h)||"openai-compatible".includes(h)||"anthropic-compatible".includes(h),m=p.length+f.length+ +!!g,y={display:"flex",flexDirection:"row",alignItems:"center",gap:8,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,boxSizing:"border-box",cursor:"pointer",minWidth:0,textAlign:"left",transition:"border-color 0.12s, background 0.12s",width:"100%"};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&s()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),s())},children:(0,r.jsxs)("div",{style:{width:820,maxWidth:"calc(100vw - 32px)",maxHeight:"min(72vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,r.jsx)("input",{ref:u,value:a,onChange:e=>d(e.target.value),placeholder:c("i18n.searchProviders"),style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===m?(0,r.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:c("i18n.noProviders")}):(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[g&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:c("i18n.custom")}),g&&(0,r.jsxs)("button",{onClick:()=>{l(),s()},style:y,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:c("i18n.customEndpoint")})]}),(0,r.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px dashed var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),p.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!g,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:c("i18n.subscriptions")}),p.map(e=>(0,r.jsxs)("button",{onClick:()=>{n(e.id),s()},style:y,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,r.jsx)(oV,{id:e.id,size:28})]},e.id)),f.length>0&&(0,r.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"}),f.map(e=>(0,r.jsxs)("button",{onClick:()=>{o(e.id),s()},style:y,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,r.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,r.jsx)(oV,{id:e.id,size:28})]},e.id))]})})]})})}function ll({onClose:e,embedded:t=!1,cwd:n=null}){let{t:o}=(0,x.s)(),[l,s]=(0,i.useState)({providers:{}}),[a,d]=(0,i.useState)({providers:{}}),[c,u]=(0,i.useState)(!0),[h,p]=(0,i.useState)(!1),[f,g]=(0,i.useState)(null),[m,y]=(0,i.useState)(!1),[v,b]=(0,i.useState)(oJ),[w,k]=(0,i.useState)([]),[j,S]=(0,i.useState)([]),[C,I]=(0,i.useState)(!1),[M,T]=(0,i.useState)([]),[E,L]=(0,i.useState)(!0),[R,N]=(0,i.useState)(null),[$,W]=(0,i.useState)(null),z=(0,i.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>{Array.isArray(e.oauthProviders)&&k(e.oauthProviders),Array.isArray(e.apiKeyProviders)&&S(e.apiKeyProviders)}).catch(()=>{})},[]),P=(0,i.useCallback)(()=>{if(!n)return void T([]);let e=new URLSearchParams({cwd:n});fetch(`/api/models-config/runtime?${e}`).then(e=>e.json()).then(e=>{Array.isArray(e.catalog)&&T(e.catalog),L(!!e.unscoped)}).catch(()=>{})},[n]);(0,i.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};s(t),d(t);let n=Object.keys(t.providers??{});b(e=>e&&("provider"===e.type?t.providers?.[e.name]:"model"!==e.type||t.providers?.[e.providerName]?.models?.[e.index])?e:n[0]?{type:"provider",name:n[0]}:null)}).catch(()=>s({providers:{}})).finally(()=>u(!1)),z()},[z]),(0,i.useEffect)(()=>{P()},[P]),(0,i.useEffect)(()=>{v&&om("models",JSON.stringify(v))},[v]);let A=(0,i.useCallback)(()=>{let e="new-provider",t=1;for(;l.providers?.[e];)e=`new-provider-${t++}`;s(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),b({type:"provider",name:e})},[l.providers]),D=(0,i.useCallback)((e,t)=>{s(n=>({...n,providers:{...n.providers??{},[e]:t}}))},[]),F=(0,i.useCallback)((e,t)=>{s(n=>{let r=Object.entries(n.providers??{}),i=r.findIndex(([t])=>t===e);return -1===i?n:(r[i]=[t,r[i][1]],{...n,providers:Object.fromEntries(r)})}),b(n=>n?"provider"===n.type&&n.name===e?{type:"provider",name:t}:"model"===n.type&&n.providerName===e||"runtime-model"===n.type&&n.providerName===e?{...n,providerName:t}:n:n)},[]),B=(0,i.useCallback)(e=>{s(t=>{let n={...t.providers??{}};return delete n[e],{...t,providers:n}}),s(e=>{let t=Object.keys(e.providers??{});return b(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),H=(0,i.useCallback)(e=>{s(t=>{let n=t.providers?.[e]??{},r=[...n.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...n,models:r}}}}),s(t=>{let n=(t.providers?.[e]?.models?.length??1)-1;return b({type:"model",providerName:e,index:n}),t})},[]),O=(0,i.useCallback)((e,t)=>{s(n=>{let r=n.providers?.[e]??{},i=[...r.models??[]],o=new Set(i.map(e=>e.id));for(let e of t)o.has(e.id)||(o.add(e.id),i.push({id:e.id,name:e.name}));return{...n,providers:{...n.providers??{},[e]:{...r,models:i}}}})},[]),U=(0,i.useCallback)((e,t,n)=>{s(r=>{let i=r.providers?.[e]??{},o=[...i.models??[]];return o[t]=n,{...r,providers:{...r.providers??{},[e]:{...i,models:o}}}})},[]),_=(0,i.useCallback)((e,t,n)=>{let r=function(e,t){let n={};for(let i of oS){let o=t[i];if(void 0!==o){var r;r=e[i],JSON.stringify(o)!==JSON.stringify(r)&&(n[i]=o)}}return Object.keys(n).length>0?n:void 0}(oY(t),{...n,id:t.id});s(n=>{var i,o;let l,s=n.providers?.[e]??{},a={...s},d=(i=s.modelOverrides,o=t.id,l={...i??{}},delete l[o],r&&(l[o]=r),Object.keys(l).length>0?l:void 0);return d?a.modelOverrides=d:delete a.modelOverrides,{...n,providers:{...n.providers??{},[e]:a}}})},[]),q=(0,i.useCallback)(async(e,t,r)=>{if(n&&(r||!E||window.confirm(o("models.pickerMaterializeConfirm")))){W(`${e}/${t}`),N(null);try{let i=await fetch("/api/models-config/picker",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,provider:e,id:t,inPicker:r})}),l=await i.json();if(!i.ok){let e="project-override"===l.code?o("models.pickerProjectOverride"):"glob-managed"===l.code?o("models.pickerGlobManaged"):"last-model"===l.code?o("models.pickerLastModel"):l.error??o("models.pickerError");N(e);return}P()}catch{N(o("models.pickerError"))}finally{W(null)}}},[n,E,P,o]),K=(0,i.useCallback)((e,t)=>{s(n=>{let r=n.providers?.[e]??{},i=[...r.models??[]];return i.splice(t,1),{...n,providers:{...n.providers??{},[e]:{...r,models:i.length?i:void 0}}}}),b({type:"provider",name:e})},[]),V=(0,i.useCallback)(async()=>{p(!0),g(null),y(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),t=await e.json();!e.ok||t.error?g(t.error??`HTTP ${e.status}`):(d(l),y(!0),setTimeout(()=>y(!1),2e3),P())}catch(e){g(String(e))}finally{p(!1)}},[l,P]),J=Object.entries(l.providers??{}),Y=w.filter(e=>e.loggedIn),Z=j.filter(e=>e.configured),G=JSON.stringify(l)!==JSON.stringify(a),X=new Set([...Y.map(e=>e.id),...Z.map(e=>e.id)]),Q=e=>!!(e?.baseUrl?.trim()||e?.models&&e.models.length>0),ee=(e,t)=>{let n=(l.providers?.[e]?.models??[]).findIndex(e=>e.id===t);n>=0?b({type:"model",providerName:e,index:n}):b({type:"runtime-model",providerName:e,id:t})},et=e=>{let t=l.providers?.[e]?.models??[],n=M.filter(t=>t.provider===e&&t.inPicker),i=t.map((e,t)=>({model:e,index:t})).filter(({model:e})=>!e.id);return(0,r.jsxs)(r.Fragment,{children:[n.map(n=>{let i=t.findIndex(e=>e.id===n.id),o=i>=0?v?.type==="model"&&v.providerName===e&&v.index===i:v?.type==="runtime-model"&&v.providerName===e&&v.id===n.id;return(0,r.jsx)(oL,{active:o,className:"models-sidebar-indented-item",onClick:()=>ee(e,n.id),children:(0,r.jsx)(oR,{className:"is-grow",style:{color:"var(--text-muted)"},children:n.id})},n.id)}),i.map(({model:t,index:n})=>{let i=v?.type==="model"&&v.providerName===e&&v.index===n;return(0,r.jsx)(oL,{active:i,className:"models-sidebar-indented-item",onClick:()=>b({type:"model",providerName:e,index:n}),children:(0,r.jsx)(oR,{className:"is-grow",style:{color:"var(--text-dim)"},children:t.id||o("i18n.newModel")})},`local-${n}`)}),!X.has(e)&&!!l.providers?.[e]&&(0,r.jsx)(oL,{className:"models-sidebar-indented-item models-sidebar-add-item",onClick:t=>{t.stopPropagation(),H(e)},children:(0,r.jsxs)(oR,{children:["+ ",o("i18n.model")]})})]})},en=(e,t)=>{let n=(0,r.jsx)(o5,{name:e,provider:t,onChange:t=>D(e,t),onRename:t=>F(e,t),onDelete:()=>B(e),onAddModels:t=>O(e,t)},`${e}-json`);return M.some(t=>t.provider===e)?(0,r.jsxs)("details",{children:[(0,r.jsx)("summary",{style:{cursor:"pointer",fontSize:11,fontWeight:600,color:"var(--text-dim)",letterSpacing:"0.04em",textTransform:"uppercase"},children:o("models.endpoint")}),(0,r.jsx)("div",{style:{marginTop:12},children:n})]}):n},er=e=>{let t=M.filter(t=>t.provider===e);return 0===t.length?null:(0,r.jsxs)("div",{className:"catalog-shelf-list",children:[(0,r.jsx)(o8,{children:o("models.catalogShelf")}),t.map(t=>{let n=$===`${t.provider}/${t.id}`,i=(l.providers?.[e]?.models??[]).findIndex(e=>e.id===t.id),s=i>=0?v?.type==="model"&&v.providerName===e&&v.index===i:v?.type==="runtime-model"&&v.providerName===e&&v.id===t.id;return(0,r.jsxs)("div",{className:s?"catalog-shelf-row is-active":"catalog-shelf-row",children:[(0,r.jsx)("input",{type:"checkbox",checked:t.inPicker,disabled:n,title:o("models.inPicker"),"aria-label":o("models.inPicker"),onChange:e=>void q(t.provider,t.id,e.target.checked)}),(0,r.jsx)("button",{type:"button",className:"catalog-shelf-name",onClick:()=>ee(e,t.id),children:t.id})]},t.id)})]})},ei=(()=>{if(!v)return null;if("oauth"===v.type){let e=w.find(e=>e.id===v.providerId);if(!e)return null;let t=l.providers?.[e.id],n=j.find(t=>t.id===e.id&&t.configured);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lr,{provider:e,onRefresh:z},e.id),n&&(0,r.jsx)(li,{provider:n,onRefresh:z},`${e.id}-key`),er(e.id),Q(t)&&t&&en(e.id,t)]})}if("apikey"===v.type){let e=j.find(e=>e.id===v.providerId);if(!e)return null;let t=l.providers?.[e.id];return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(li,{provider:e,onRefresh:z},e.id),er(e.id),Q(t)&&t&&en(e.id,t)]})}if("provider"===v.type){let e=l.providers?.[v.name];return e?(0,r.jsxs)(r.Fragment,{children:[er(v.name),en(v.name,e)]}):null}if("runtime-model"===v.type){var e;let t=M.find(e=>e.provider===v.providerName&&e.id===v.id);if(!t)return null;let n=l.providers?.[v.providerName]??{},i=n.modelOverrides?.[t.id],o=(e=oY(t),i?{...e,...i,id:e.id,cost:i.cost?{...e.cost,...i.cost}:e.cost}:{...e,id:e.id});return(0,r.jsx)(ln,{providerName:v.providerName,provider:n,model:o,lockId:!0,onChange:e=>_(v.providerName,t,e)},`${v.providerName}-${v.id}`)}let t=l.providers?.[v.providerName],n=t?.models?.[v.index];return n?(0,r.jsx)(ln,{providerName:v.providerName,provider:t,model:n,onChange:e=>U(v.providerName,v.index,e),onDelete:()=>K(v.providerName,v.index)},`${v.providerName}-${v.index}`):null})();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(oC,{embedded:t,title:o("common.models"),subtitle:"~/.pi/agent/models.json",closeLabel:o("i18n.close"),onClose:e,children:[(0,r.jsxs)(oI,{children:[(0,r.jsxs)(oM,{children:[(0,r.jsxs)(oT,{children:[Y.map(e=>{let t=v?.type==="oauth"&&v.providerId===e.id;return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)(oL,{active:t,onClick:()=>b({type:"oauth",providerId:e.id}),children:[(0,r.jsx)(oV,{id:e.id,size:16}),(0,r.jsx)(oR,{className:"is-grow",children:e.name})]}),et(e.id)]},e.id)}),Z.filter(e=>!Y.some(t=>t.id===e.id)).map(e=>{let t=v?.type==="apikey"&&v.providerId===e.id;return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)(oL,{active:t,onClick:()=>b({type:"apikey",providerId:e.id}),children:[(0,r.jsx)(oV,{id:e.id,size:16}),(0,r.jsx)(oR,{className:"is-grow",children:e.displayName})]}),et(e.id)]},e.id)}),(Y.length>0||Z.length>0)&&J.some(([e])=>!X.has(e))&&(0,r.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:o("i18n.loading")}):J.filter(([e])=>!X.has(e)).map(([e])=>{let t=v?.type==="provider"&&v.name===e;return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)(oL,{onClick:()=>b({type:"provider",name:e}),active:t,children:[(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,r.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,r.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,r.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,r.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,r.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,r.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,r.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,r.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,r.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,r.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,r.jsx)(oR,{className:"is-grow",children:e})]}),et(e)]},e)})]}),(0,r.jsx)(o_,{onClick:()=>I(!0),children:o("i18n.addProvider")})]}),(0,r.jsx)(oB,{children:(0,r.jsx)(oN,{className:"is-fill",children:c?null:ei??(0,r.jsx)(oF,{children:o("i18n.selectProviderModel")})})})]}),(0,r.jsxs)(oH,{status:(f||R)&&(0,r.jsx)("span",{style:{color:"#f87171"},children:f||R}),children:[!t&&(0,r.jsx)(oO,{onClick:e,children:o("i18n.cancel")}),(G||h||m)&&(0,r.jsxs)(oO,{variant:"primary",onClick:V,disabled:h||m,className:m?"is-success":void 0,children:[m&&(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"config-button-success-icon",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,r.jsx)("span",{children:m?o("i18n.saved"):h?o("i18n.saving"):o("models.saveModelsJson")})]})]})]}),C&&(0,r.jsx)(lo,{oauthProviders:w,apiKeyProviders:j,onSelectOAuth:e=>b({type:"oauth",providerId:e}),onSelectApiKey:e=>b({type:"apikey",providerId:e}),onAddCustom:A,onClose:()=>I(!1)})]})}function ls(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function la(e){let t=e.sourceInfo?.source,n=e.sourceInfo?.scope;return"user"===n||"user"===t?"global":"project"===n||"project"===t?"project":"path"}function ld(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function lc(e){return e?e.slice(0,8):"unknown"}function lu({skill:e,cwd:t,onToggle:n,toggling:i,saveError:o,updateStatus:l,checkingUpdate:s,updating:a,updateError:d,onCheckUpdate:c,onUpdate:u}){let{t:h}=(0,x.s)(),p=la(e),f=!e.disableModelInvocation;return(0,r.jsxs)(oN,{children:[(0,r.jsxs)("div",{className:"skill-detail-heading",children:[(0,r.jsxs)(o$,{children:[(0,r.jsxs)(oW,{children:[(0,r.jsx)("span",{className:`config-scope-tag${"project"===p?" is-project":""}`,children:p}),(0,r.jsx)("span",{className:"config-detail-path",children:function(e){if("project"===p&&e.startsWith(t)){let n=e.slice(t.length).replace(/^[/\\]/,"");return`./${n}`}return ls(e)}(e.filePath)})]}),(0,r.jsx)(oz,{children:(0,r.jsx)(oU,{checked:f,loading:i,label:h(f?"i18n.visibleInPrompt":"i18n.hiddenFromPrompt"),onChange:()=>n(e)})})]}),(0,r.jsxs)("div",{className:"skill-detail-status-row",children:[!f&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:h("i18n.hiddenButInvocable")}),o&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",overflowWrap:"anywhere"},children:o})]})]}),e.install?.skillsShUrl&&(0,r.jsx)(oD,{label:"Source",children:(0,r.jsx)("a",{href:e.install.skillsShUrl,target:"_blank",rel:"noreferrer",title:e.install.skillsShUrl,className:"skill-source-link",children:(0,r.jsxs)("span",{className:"skill-source-link-text",children:[e.install.skillsShUrl.replace(/^https?:\/\//,"")," ↗"]})})}),e.install&&(0,r.jsxs)(oD,{label:"Version",children:[(0,r.jsxs)("div",{className:"skill-version-row",children:[(0,r.jsx)("span",{className:"skill-version-value",children:lc(l?.currentVersion??e.install.versionHash)}),e.install.canCheckForUpdates&&(0,r.jsx)(oO,{size:"small",onClick:c,disabled:s||a,children:h("i18n.check")}),l?.state==="update-available"&&(0,r.jsx)("span",{className:"skill-version-value is-update",children:lc(l.latestVersion)}),(s||l&&"update-available"!==l.state)&&(0,r.jsx)("span",{className:`skill-update-status ${s?"is-checking":l?.state==="up-to-date"?"is-success":l?.state==="error"?"is-error":"is-muted"}`,children:s?h("i18n.checking"):l?.state==="up-to-date"?h("i18n.upToDate"):l?.state==="unsupported"?h("i18n.automaticChecksUnavailable"):l?.message||h("i18n.checkFailed")}),l?.state==="update-available"&&(0,r.jsx)(oO,{variant:"primary",size:"small",onClick:u,disabled:a||s,children:h(a?"i18n.updating":"i18n.update")})]}),d&&(0,r.jsx)("span",{style:{fontSize:12,color:"#ef4444"},children:d})]}),(0,r.jsx)(oD,{label:"Name",children:(0,r.jsx)("span",{className:"skill-name-value",children:e.name})}),(0,r.jsx)(oD,{label:"Description",children:(0,r.jsx)("span",{className:"skill-description",children:e.description})})]})}function lh({cwd:e,installedPackages:t,projectResourcesLoaded:n,onInstalled:o}){let{t:l}=(0,x.s)(),[s,a]=(0,i.useState)(""),[d,c]=(0,i.useState)([]),[u,h]=(0,i.useState)(!1),[p,f]=(0,i.useState)(null),[g,m]=(0,i.useState)(null),[y,v]=(0,i.useState)(null),[b,w]=(0,i.useState)(new Set),[k,j]=(0,i.useState)("global"),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{S.current?.focus()},[]);let C=(0,i.useCallback)(async e=>{if(e.trim()){h(!0),f(null),c([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),n=await t.json();if(n.error)return void f(n.error);c(n.results??[]),0===(n.results??[]).length&&f("No skills found")}catch(e){f(String(e))}finally{h(!1)}}},[]),I=(0,i.useCallback)(async t=>{m(t),v(null);try{let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:k,cwd:e})}),r=await n.json();if(!n.ok||r.error)return void v(r.error??`HTTP ${n.status}`);w(e=>new Set(e).add(`${k}:${t}`)),o()}catch(e){v(String(e))}finally{m(null)}},[o,k,e]),M="global"===k?"~/.pi/agent/skills/":`${ls(e)}/.pi/skills/`;return(0,r.jsxs)(oN,{className:"is-full-height",children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,r.jsx)(oP,{children:l("i18n.addSkill")}),(0,r.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,r.jsx)("input",{ref:S,value:s,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"===e.key&&C(s)},placeholder:l("i18n.skillSearchPlaceholder"),style:{flex:1,padding:"7px 10px",fontSize:12,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,r.jsx)(oO,{variant:"primary",onClick:()=>C(s),disabled:u||!s.trim(),children:u?l("i18n.searching"):l("i18n.search")})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,r.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,r.jsx)("button",{onClick:()=>{("global"===e||n)&&j(e)},disabled:"project"===e&&!n,title:"project"!==e||n?void 0:l("trust.projectScopeUnavailable"),style:{padding:"3px 10px",border:"none",cursor:"project"!==e||n?"pointer":"not-allowed",background:k===e?"var(--bg-selected)":"none",color:k===e?"var(--text)":"var(--text-dim)",fontWeight:k===e?600:400,opacity:"project"!==e||n?1:.45,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",M]})]}),p&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:p}),y&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:y})]}),d.length>0?(0,r.jsx)("div",{style:{flex:1,overflowY:"auto"},children:d.map(e=>{let n=t[k].has(e.package)||b.has(`${k}:${e.package}`),i=g===e.package,o=e.package.indexOf("@"),s=o>-1?e.package.slice(0,o):e.package,a=o>-1?e.package.slice(o+1):null;return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:a??s}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:s}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,r.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,r.jsx)(oO,{size:"small",onClick:()=>!n&&!i&&I(e.package),disabled:n||i||null!==g,style:{flexShrink:0,background:n?"rgba(34,197,94,0.1)":"none",color:n?"#16a34a":i?"var(--accent)":"var(--text-muted)"},children:n?`✓ ${l("i18n.installed")}`:i?l("i18n.installing"):l("i18n.install")})]},e.package)})}):!p&&!u&&(0,r.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,r.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function lp({cwd:e,onClose:t,embedded:n=!1}){let{t:o}=(0,x.s)(),[l,s]=(0,i.useState)([]),[a,d]=(0,i.useState)(!0),[c,u]=(0,i.useState)(null),[h,p]=(0,i.useState)(()=>ox("skills",e)),[f,g]=(0,i.useState)(new Set),[m,y]=(0,i.useState)(null),[v,b]=(0,i.useState)(!1),[w,k]=(0,i.useState)({}),[j,S]=(0,i.useState)(new Set),[C,I]=(0,i.useState)(!1),[M,T]=(0,i.useState)(null),[E,L]=(0,i.useState)(null),[R,N]=(0,i.useState)(!0),$=(0,i.useCallback)(async()=>{d(!0),u(null);try{let t=await fetch(`/api/skills?cwd=${encodeURIComponent(e)}`),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);let r=n.skills??[];return s(r),N(n.projectResourcesLoaded??!0),p(e=>{if(e&&r.some(t=>t.filePath===e))return e;let t=r.find(e=>!e.disableModelInvocation)??r[0];return t?.filePath??null}),r}catch(e){return u(String(e)),[]}finally{d(!1)}},[e]);(0,i.useEffect)(()=>{k({}),L(null),$()},[e]),(0,i.useEffect)(()=>{h&&om("skills",h,e)},[e,h]);let W=(0,i.useCallback)(async t=>{let n=(t?[t]:l.filter(e=>!!e.install)).map(ld).filter(e=>!!e);if(0!==n.length){L(null),S(e=>new Set([...e,...n])),t||I(!0);try{let n=await fetch("/api/skills/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:t?.install?.package,scope:t?.install?.scope})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);k(e=>{let t={...e};for(let e of r.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){L(e instanceof Error?e.message:String(e))}finally{S(e=>{let t=new Set(e);for(let e of n)t.delete(e);return t}),t||I(!1)}}},[e,l]),z=(0,i.useCallback)(async t=>{if(!t.install)return;let n=ld(t);T(n),L(null);try{let r=await fetch("/api/skills/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:t.install.package,scope:t.install.scope})}),i=await r.json();if(!r.ok||i.error||!i.success)throw Error(i.error??`HTTP ${r.status}`);await $();let o=i.skill?.install?.versionHash;k(e=>({...e,[n]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:o,latestVersion:o}}))}catch(e){L(e instanceof Error?e.message:String(e))}finally{T(null)}},[e,$]),P=(0,i.useCallback)(async t=>{let n=!t.disableModelInvocation;g(e=>new Set(e).add(t.filePath)),y(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t.filePath,disableModelInvocation:n})}),i=await r.json();if(!r.ok||i.error)return void y(i.error??`HTTP ${r.status}`);s(e=>e.map(e=>e.filePath===t.filePath?{...e,disableModelInvocation:n}:e))}catch(e){y(String(e))}finally{g(e=>{let n=new Set(e);return n.delete(t.filePath),n})}},[e]),A=l.find(e=>e.filePath===h)??null;return(0,r.jsxs)(oC,{embedded:n,title:o("common.skills"),subtitle:ls(e),closeLabel:o("i18n.close"),onClose:t,children:[!R&&(0,r.jsx)("div",{role:"status",className:"config-trust-notice",children:o("trust.skillsNotLoaded")}),(0,r.jsxs)(oI,{children:[(0,r.jsxs)(oM,{children:[(0,r.jsx)(oT,{children:a?(0,r.jsx)("div",{className:"config-sidebar-message",children:o("i18n.loading")}):c?(0,r.jsx)("div",{className:"config-sidebar-message is-error",children:c}):0===l.length?(0,r.jsx)("div",{className:"config-sidebar-message is-empty",children:o("i18n.noSkills")}):(()=>{let e=[],t={project:o("skills.scope.project"),global:o("skills.scope.global"),path:o("skills.scope.path")};for(let{label:n,matches:r}of[{label:`${t.project} / skills.sh`,matches:e=>"project"===la(e)&&!!e.install?.skillsShUrl},{label:t.project,matches:e=>"project"===la(e)&&!e.install?.skillsShUrl},{label:`${t.global} / skills.sh`,matches:e=>"global"===la(e)&&!!e.install?.skillsShUrl},{label:t.global,matches:e=>"global"===la(e)&&!e.install?.skillsShUrl},{label:t.path,matches:e=>"path"===la(e)}]){let t=l.filter(r);t.length>0&&e.push({label:n,skills:t})}let n=e=>{let t,n,i=!v&&h===e.filePath,l=e.disableModelInvocation;return(0,r.jsxs)(oL,{active:i,onClick:()=>{p(e.filePath),b(!1)},children:[(0,r.jsx)(oq,{active:!l}),(0,r.jsx)(oR,{className:`is-grow${l?" is-muted":""}`,children:e.name}),(n=(t=ld(e))?w[t]:void 0,n?.state!=="update-available"?null:(0,r.jsx)("span",{title:o("i18n.updateAvailable"),className:"skill-update-indicator",children:"↑"}))]},e.filePath)};return e.map(({label:e,skills:t})=>(0,r.jsxs)("div",{className:"config-sidebar-group",children:[(0,r.jsx)(oE,{children:e}),[...t.filter(e=>!e.disableModelInvocation),...t.filter(e=>e.disableModelInvocation)].map(n)]},e))})()}),(0,r.jsx)(o_,{onClick:()=>b(!0),active:v,children:o("i18n.addSkill")})]}),(0,r.jsx)(oB,{children:(0,r.jsx)(oN,{className:"is-fill",children:v?(0,r.jsx)(lh,{cwd:e,projectResourcesLoaded:R,installedPackages:{global:new Set(l.filter(e=>e.install?.scope==="global").map(e=>e.install.package)),project:new Set(l.filter(e=>e.install?.scope==="project").map(e=>e.install.package))},onInstalled:()=>{$()}}):a?null:A?(0,r.jsx)(lu,{skill:A,cwd:e,onToggle:P,toggling:f.has(A.filePath),saveError:m,updateStatus:ld(A)?w[ld(A)]:void 0,checkingUpdate:!!ld(A)&&j.has(ld(A)),updating:M===ld(A),updateError:E,onCheckUpdate:()=>void W(A),onUpdate:()=>void z(A)},A.filePath):(0,r.jsx)(oF,{children:o("i18n.selectSkill")})})})]}),(0,r.jsxs)(oH,{status:Object.values(w).filter(e=>"update-available"===e.state).length>0&&(0,r.jsxs)("span",{style:{fontSize:12,color:"#d97706"},children:[Object.values(w).filter(e=>"update-available"===e.state).length," ",1===Object.values(w).filter(e=>"update-available"===e.state).length?o("i18n.update"):o("i18n.updates")]}),children:[!n&&(0,r.jsx)(oO,{onClick:t,children:o("i18n.close")}),l.some(e=>!!e.install)&&(0,r.jsx)(oO,{variant:"secondary",onClick:()=>void W(),disabled:C||null!==M,children:C?o("i18n.checking"):o("i18n.checkUpdates")})]})]})}let lf={builtin:0,global:1,workspace:2,project:3},lg=["read","bash","edit","write","grep","find","ls"],lx=["","off","minimal","low","medium","high","xhigh","max"],lm={name:"custom-agent",displayName:"Custom agent",description:"",systemPrompt:"",tools:["read","bash","edit","write","grep","find","ls"],loadSkills:!1,loadExtensions:!1,inheritContext:!1,runInBackground:!0,enabled:!0},ly={width:"100%",minWidth:0,height:34,padding:"0 9px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none"},lv={background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"default"};function lb(e){return{name:e.name,displayName:e.displayName,description:e.description,systemPrompt:e.systemPrompt,tools:[...e.tools],loadSkills:e.loadSkills,loadExtensions:e.loadExtensions,...e.model?{model:e.model}:{},...e.thinking?{thinking:e.thinking}:{},...e.maxTurns?{maxTurns:e.maxTurns}:{},inheritContext:e.inheritContext,runInBackground:e.runInBackground,enabled:e.enabled}}function lw(e){return`${e.scope}:${e.name}`}function lk(e){return"global"===e||"project"===e}function lj(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function lS({label:e,children:t}){return(0,r.jsx)(oD,{label:e,children:t})}function lC({checked:e,disabled:t,label:n,onChange:i}){return(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:7,color:t?"var(--text-dim)":"var(--text-muted)",fontSize:12,cursor:t?"default":"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:e,disabled:t,onChange:e=>i(e.target.checked)}),n]})}function lI({cwd:e,sessionId:t=null,onClose:n,onReloaded:o,embedded:l=!1}){let s=nN(),{t:a}=(0,x.s)(),[d,c]=(0,i.useState)([]),[u,h]=(0,i.useState)([]),[p,f]=(0,i.useState)(!0),[g,m]=(0,i.useState)(null),[y,v]=(0,i.useState)(()=>ox("agents",e)),[b,w]=(0,i.useState)(lm),[k,j]=(0,i.useState)("view"),[S,C]=(0,i.useState)("global"),[I,M]=(0,i.useState)(!0),[T,E]=(0,i.useState)(!1),[L,R]=(0,i.useState)(!1),[N,$]=(0,i.useState)(!1),[W,z]=(0,i.useState)(null),[P,A]=(0,i.useState)(!0),[D,F]=(0,i.useState)(10),[B,H]=(0,i.useState)(!0),[O,U]=(0,i.useState)(!1),[_,q]=(0,i.useState)(null),[K,V]=(0,i.useState)(!1),[J,Y]=(0,i.useState)(!1),Z=(0,i.useMemo)(()=>d.find(e=>lw(e)===y)??null,[d,y]),G=(0,i.useMemo)(()=>u.map(e=>({provider:e.provider,modelId:e.id,name:e.name})),[u]),X=(0,i.useCallback)(async t=>{M(!0),z(null);try{let n=await fetch(`/api/subagents/profiles?cwd=${encodeURIComponent(e)}`,{cache:"no-store"}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);let i=r.profiles??[];c(i);let o=t??ox("agents",e),l=i.find(e=>lw(e)===o)??i.find(e=>"project"===e.scope)??i.find(e=>"global"===e.scope)??i[0]??null;v(l?lw(l):null),l&&(w(lb(l)),j(lk(l.scope)?"edit":"view"),lk(l.scope)&&C(l.scope))}catch(e){z(e instanceof Error?e.message:String(e))}finally{M(!1)}},[e]);(0,i.useEffect)(()=>{X()},[X]),(0,i.useEffect)(()=>{let e=new AbortController;return H(!0),q(null),(async()=>{try{let t=await fetch("/api/subagents/settings",{cache:"no-store",signal:e.signal}),n=await t.json();if(!t.ok||n.error||"boolean"!=typeof n.enabled)throw Error(n.error??`HTTP ${t.status}`);A(n.enabled),"number"==typeof n.maxConcurrent&&F(n.maxConcurrent)}catch(t){if(e.signal.aborted)return;q(t instanceof Error?t.message:String(t))}finally{e.signal.aborted||H(!1)}})(),()=>e.abort()},[]),(0,i.useEffect)(()=>{y&&om("agents",y,e)},[e,y]),(0,i.useEffect)(()=>{let t=new AbortController;return f(!0),m(null),(async()=>{try{let n=await fetch(`/api/models?cwd=${encodeURIComponent(e)}`,{signal:t.signal}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);h(r.modelList??[]),m(r.modelError??null)}catch(e){if(t.signal.aborted)return;m(e instanceof Error?e.message:String(e))}finally{t.signal.aborted||f(!1)}})(),()=>t.abort()},[e]);let Q=async()=>{E(!0),z(null),R(!1);try{let t=await fetch("/api/subagents/profiles",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:S,profile:b})}),n=await t.json();if(!t.ok||n.error||!n.profile)throw Error(n.error??`HTTP ${t.status}`);await X(lw(n.profile)),R(!0),setTimeout(()=>R(!1),2e3)}catch(e){z(e instanceof Error?e.message:String(e))}finally{E(!1)}},ee=async()=>{if(Z&&lk(Z.scope)&&window.confirm(a("agents.deleteConfirm",{name:Z.displayName}))){E(!0),z(null);try{let t=await fetch("/api/subagents/profiles",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:Z.scope,name:Z.name})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);await X()}catch(e){z(e instanceof Error?e.message:String(e))}finally{E(!1)}}},et="view"!==k,en="create"===k,er=!et||T||N,ei=en?S:Z?.scope,eo=en?"global"===S?`~/.pi/agent/agents/${b.name||"..."}.md`:`./.pi/agents/${b.name||"..."}.md`:Z?function(e,t){if(!e.filePath)return null;if(("project"===e.scope||"workspace"===e.scope)&&e.filePath.startsWith(t)){let n=e.filePath.slice(t.length).replace(/^[/\\]/,"");return`./${n}`}return lj(e.filePath)}(Z,e)??a("agents.builtinPath"):"",el=en?eo:Z?.filePath??eo,es=!b.model||u.some(e=>`${e.provider}/${e.id}`===b.model),ea=(()=>{if(!b.model)return null;let e=b.model.indexOf("/");return e<0?{provider:"",modelId:b.model}:{provider:b.model.slice(0,e),modelId:b.model.slice(e+1)}})(),ed=er?{...ly,...lv}:ly,ec=(e,t)=>{w(n=>({...n,[e]:t}))},eu=async t=>{if(en)return void ec("enabled",t);if(Z&&lk(Z.scope)){$(!0),z(null);try{let n=await fetch("/api/subagents/profiles",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,scope:Z.scope,name:Z.name,enabled:t})}),r=await n.json();if(!n.ok||r.error||!r.profile)throw Error(r.error??`HTTP ${n.status}`);let i=r.profile;c(e=>e.map(e=>lw(e)===lw(i)?i:e)),w(e=>({...e,enabled:i.enabled}))}catch(e){z(e instanceof Error?e.message:String(e))}finally{$(!1)}}},eh=async e=>{U(!0),q(null);try{let n=await fetch("/api/subagents/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})}),r=await n.json();if(!n.ok||r.error||"boolean"!=typeof r.enabled)throw Error(r.error??`HTTP ${n.status}`);A(r.enabled),V(!!t)}catch(e){q(e instanceof Error?e.message:String(e))}finally{U(!1)}},ep=async e=>{F(e),q(null);try{let t=await fetch("/api/subagents/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({maxConcurrent:e})}),n=await t.json();if(!t.ok||n.error||"number"!=typeof n.maxConcurrent)throw Error(n.error??`HTTP ${t.status}`);F(n.maxConcurrent)}catch(e){q(e instanceof Error?e.message:String(e))}},ef=async()=>{if(t){Y(!0),q(null);try{await rN(t,{type:"reload"}),V(!1),o?.()}catch(e){q(e instanceof Error?e.message:String(e))}finally{Y(!1)}}};return(0,r.jsxs)(oC,{embedded:l,title:a("common.agents"),subtitle:lj(e),closeLabel:a("agents.close"),onClose:n,children:[(0,r.jsxs)("div",{className:"agents-feature-setting",children:[(0,r.jsxs)("div",{className:"agents-feature-copy",children:[(0,r.jsx)("strong",{children:a("agents.builtInTitle")}),(0,r.jsx)("span",{children:a("agents.builtInDescription")}),K&&(0,r.jsx)("span",{role:"status",className:"agents-feature-reload-notice",children:a("agents.reloadRequired")})]}),(0,r.jsxs)("div",{className:"agents-feature-actions",children:[K&&t&&(0,r.jsx)(oO,{size:"small",onClick:()=>void ef(),disabled:J||O,children:J?a("agents.reloading"):a("agents.reloadSession")}),(0,r.jsx)(oU,{checked:P,disabled:B||J,loading:O,label:a("agents.builtInTitle"),onChange:e=>void eh(e)})]})]}),(0,r.jsxs)("div",{className:"agents-feature-setting",children:[(0,r.jsxs)("div",{className:"agents-feature-copy",children:[(0,r.jsx)("strong",{children:a("agents.maxConcurrent")}),(0,r.jsx)("span",{children:a("agents.maxConcurrentDescription")})]}),(0,r.jsx)("input",{"aria-label":a("agents.maxConcurrent"),type:"number",min:1,max:32,value:D,disabled:B||O,onChange:e=>F(Number(e.target.value)),onBlur:()=>void ep(D),style:{...ly,width:76}})]}),(0,r.jsxs)(oI,{children:[(0,r.jsxs)(oM,{children:[(0,r.jsx)(oT,{children:I?(0,r.jsx)("div",{style:{padding:10,color:"var(--text-dim)",fontSize:12},children:a("agents.loading")}):["project","global","workspace","builtin"].map(e=>{let t=d.filter(t=>t.scope===e);return 0===t.length?null:(0,r.jsxs)("div",{className:"config-sidebar-group",children:[(0,r.jsx)(oE,{children:a(`agents.scope.${e}`)}),t.map(e=>{let t,n,i=(t=e.name.toLowerCase(),n=lf[e.scope],d.some(e=>e.name.toLowerCase()===t&&lf[e.scope]>n));return(0,r.jsxs)(oL,{active:y===lw(e)&&!en,onClick:()=>{v(lw(e)),w(lb(e)),j(lk(e.scope)?"edit":"view"),lk(e.scope)&&C(e.scope),z(null)},children:[(0,r.jsx)(oq,{active:e.enabled}),(0,r.jsx)(oR,{className:`is-grow${e.enabled?"":" is-muted"}`,children:e.displayName}),i&&(0,r.jsx)("span",{className:"agents-overridden-label",children:a("agents.overridden")})]},lw(e))})]},e)})}),(0,r.jsx)(o_,{active:en,onClick:()=>{let e="custom-agent",t=2;for(;d.some(t=>t.name===e);)e=`custom-agent-${t++}`;v(null),w({...lm,name:e,displayName:e}),j("create"),C("global"),z(null)},children:a("agents.new")})]}),(0,r.jsx)(oB,{children:(0,r.jsx)(oN,{className:"is-fill",children:Z||en?(0,r.jsxs)(oN,{children:[(0,r.jsxs)(o$,{children:[(0,r.jsxs)(oW,{children:[ei&&(0,r.jsx)("span",{className:`config-scope-tag${"project"===ei?" is-project":""}`,children:a(`agents.scope.${ei}`)}),(0,r.jsx)("span",{title:el,className:"config-detail-path",children:eo})]}),(0,r.jsxs)(oz,{children:[Z&&("view"===k||"edit"===k)&&(0,r.jsx)(oO,{size:"small",onClick:()=>{if(!Z)return;let e=function(e,t){let n=new Set(t.map(e=>e.name.toLowerCase())),r=`${e}-copy`,i=r,o=2;for(;n.has(i.toLowerCase());)i=`${r}-${o++}`;return i}(Z.name,d);v(null),w({...lb(Z),name:e,displayName:a("agents.copyName",{name:Z.displayName})}),j("create"),C(lk(Z.scope)?Z.scope:"global"),z(null)},disabled:T||N,children:a("agents.duplicate")}),Z&&lk(Z.scope)&&"edit"===k&&(0,r.jsx)(oO,{variant:"danger",size:"small",onClick:()=>void ee(),disabled:T||N,children:a("agents.delete")}),(0,r.jsx)(oU,{checked:b.enabled,disabled:er,label:b.enabled?a("agents.disable"):a("agents.enable"),onChange:e=>void eu(e)})]})]}),en&&(0,r.jsx)(lS,{label:a("agents.saveScope"),children:(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:3,padding:3,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)"},children:["global","project"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>C(e),disabled:T,style:{height:28,border:"none",borderRadius:4,background:S===e?"var(--bg-selected)":"transparent",color:S===e?"var(--text)":"var(--text-muted)",cursor:T?"default":"pointer",fontSize:11,fontWeight:S===e?600:400},children:a(`agents.scope.${e}`)},e))})}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:s?"1fr":"minmax(0, 1fr) minmax(0, 1fr)",gap:12},children:[(0,r.jsx)(lS,{label:a("agents.name"),children:en?(0,r.jsx)("input",{"aria-label":a("agents.name"),value:b.name,disabled:er,onChange:e=>ec("name",e.target.value),style:ly}):(0,r.jsx)("code",{style:{minHeight:34,display:"flex",alignItems:"center",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:12},children:b.name})}),(0,r.jsx)(lS,{label:a("agents.displayName"),children:(0,r.jsx)("input",{"aria-label":a("agents.displayName"),value:b.displayName,disabled:er,onChange:e=>ec("displayName",e.target.value),style:ed})})]}),(0,r.jsx)(lS,{label:a("agents.description"),children:(0,r.jsx)("input",{"aria-label":a("agents.description"),value:b.description,disabled:er,onChange:e=>ec("description",e.target.value),style:ed})}),(0,r.jsx)(lS,{label:a("agents.prompt"),children:(0,r.jsx)("textarea",{className:"agents-system-prompt","aria-label":a("agents.prompt"),value:b.systemPrompt,disabled:er,onChange:e=>ec("systemPrompt",e.target.value),style:{...ed,height:195,minHeight:195,maxHeight:"60vh",padding:9,overflow:"auto",resize:er?"none":"vertical",lineHeight:1.5}})}),(0,r.jsx)(lS,{label:a("agents.tools"),children:(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px"},children:lg.map(e=>(0,r.jsx)(lC,{label:e,disabled:er,checked:b.tools.includes(e),onChange:t=>ec("tools",t?[...b.tools,e]:b.tools.filter(t=>t!==e))},e))})}),(0,r.jsx)(lS,{label:a("agents.resources"),children:(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 20px"},children:[(0,r.jsx)(lC,{label:a("agents.loadSkills"),disabled:er,checked:b.loadSkills,onChange:e=>ec("loadSkills",e)}),(0,r.jsx)(lC,{label:a("agents.loadExtensions"),disabled:er,checked:b.loadExtensions,onChange:e=>ec("loadExtensions",e)})]})}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:s?"1fr":"minmax(0, 1.5fr) minmax(120px, 0.75fr) minmax(100px, 0.5fr)",gap:12},children:[(0,r.jsx)(lS,{label:a("agents.model"),children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)(nQ,{options:G,value:ea,onChange:(e,t)=>ec("model",`${e}/${t}`),onClear:()=>ec("model",void 0),emptyLabel:p?a("agents.modelsLoading"):a("agents.inherit"),selectedLabel:b.model&&!es?a("agents.modelUnavailable",{model:b.model}):void 0,disabled:er||p||0===u.length&&!b.model,ariaLabel:a("agents.model"),variant:"field",placement:"auto"}),g&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:10},children:g})]})}),(0,r.jsx)(lS,{label:a("agents.thinking"),children:(0,r.jsx)("select",{"aria-label":a("agents.thinking"),value:b.thinking??"",disabled:er,onChange:e=>ec("thinking",e.target.value||void 0),style:ed,children:lx.map(e=>(0,r.jsx)("option",{value:e,children:e||a("agents.inherit")},e||"default"))})}),(0,r.jsx)(lS,{label:a("agents.maxTurns"),children:(0,r.jsx)("input",{"aria-label":a("agents.maxTurns"),type:"number",min:1,value:b.maxTurns??"",disabled:er,onChange:e=>ec("maxTurns",e.target.value?Number(e.target.value):void 0),style:ed})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"10px 20px"},children:[(0,r.jsx)(lC,{label:a("agents.inheritContext"),disabled:er,checked:b.inheritContext,onChange:e=>ec("inheritContext",e)}),(0,r.jsx)(lC,{label:a("agents.background"),disabled:er,checked:b.runInBackground,onChange:e=>ec("runInBackground",e)})]})]}):(0,r.jsx)(oF,{children:a("agents.empty")})})})]}),(0,r.jsx)(oH,{status:(_||W)&&(0,r.jsx)("span",{role:"alert",style:{color:"#ef4444"},children:_||W}),children:et&&(0,r.jsxs)(oO,{variant:"primary",onClick:()=>void Q(),disabled:T||L||N||!b.name.trim(),className:L?"is-success":void 0,children:[L&&(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"config-button-success-icon",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,r.jsx)("span",{children:L?a("i18n.saved"):T?a("agents.saving"):a("agents.save")})]})})]})}function lM(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function lT(e){let t=e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/);return t?.[1]??e}function lE(e){return`${e.scope}\0${e.source}`}function lL(e){return`extension\0${e.path}`}function lR(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function lN({pkg:e}){let{t}=(0,x.s)(),n=[["extension",t("i18n.extensions")],["skill",t("i18n.skills")],["prompt",t("i18n.prompts")],["theme",t("i18n.themes")]].map(([t,n])=>({kind:t,label:n,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return 0===n.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:t(e.disabled?"i18n.packageDisabled":"i18n.noResolvedResources")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:n.map((e,t)=>(0,r.jsxs)("div",{style:{borderTop:0===t?"none":"1px solid var(--border)",paddingTop:12*(0!==t)},children:[(0,r.jsx)("div",{style:{fontSize:10,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",marginBottom:6},children:e.label}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.resources.map(e=>(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.path,children:e.name}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:1},title:e.path,children:e.relativePath})]},`${e.kind}:${e.path}`))})]},e.kind))})}function l$({scope:e}){return(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===e?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===e?"rgba(99,102,241,0.85)":"var(--text-dim)"},children:e})}function lW({value:e,projectResourcesLoaded:t,onChange:n}){let{t:i}=(0,x.s)();return(0,r.jsx)("div",{style:{display:"inline-flex",border:"1px solid var(--border)",borderRadius:7,overflow:"hidden",height:30},children:["global","project"].map(o=>{let l=e===o,s="project"===o&&!t;return(0,r.jsx)("button",{onClick:()=>{s||n(o)},disabled:s,title:s?i("trust.projectScopeUnavailable"):void 0,style:{width:76,border:"none",borderRight:"global"===o?"1px solid var(--border)":"none",background:l?"var(--bg-selected)":"none",color:l?"var(--text)":"var(--text-muted)",cursor:s?"not-allowed":"pointer",opacity:s?.45:1,fontSize:12},children:o},o)})})}function lz({cwd:e,source:t,scope:n,projectResourcesLoaded:o,busy:l,actionError:s,onSourceChange:a,onScopeChange:d,onInstall:c}){let{t:u}=(0,x.s)(),h=(0,i.useRef)(null);return(0,i.useEffect)(()=>{h.current?.focus()},[]),(0,r.jsxs)(oN,{className:"is-fill",children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[(0,r.jsx)(oP,{children:u("i18n.addPlugin")}),(0,r.jsxs)("a",{href:"https://pi.dev/packages",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:5,color:"var(--accent)",fontSize:12,textDecoration:"none",whiteSpace:"nowrap"},children:[(0,r.jsxs)("svg",{width:"28",height:"28",viewBox:"0 0 800 800","aria-hidden":"true",focusable:"false",style:{flexShrink:0},children:[(0,r.jsx)("path",{fill:"#000",fillRule:"evenodd",d:"M165.29 165.29H517.36V400H400V517.36H282.65V634.72H165.29ZM282.65 282.65V400H400V282.65Z"}),(0,r.jsx)("path",{fill:"#000",d:"M517.36 400H634.72V634.72H517.36Z"})]}),"pi.dev/packages"]})]}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"project"===n?`${lM(e)}/.pi/agent/{npm,git}`:"~/.pi/agent/{npm,git}"})]}),(0,r.jsx)(oD,{label:"Source",children:(0,r.jsx)("input",{id:"plugin-source",ref:h,value:t,onChange:e=>a(e.target.value),onPaste:e=>{let t=e.clipboardData.getData("text"),n=lT(t);n!==t&&(e.preventDefault(),a(n))},onBlur:e=>a(lT(e.currentTarget.value)),placeholder:"npm:@scope/package",style:{width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"},onKeyDown:e=>{"Enter"===e.key&&t.trim()&&!l&&c()}})}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)(lW,{value:n,projectResourcesLoaded:o,onChange:d}),(0,r.jsx)(oO,{variant:"primary",onClick:c,disabled:l||!t.trim(),className:"is-pushed-right",children:u(l?"i18n.installing":"i18n.install")})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Examples"}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:["npm:@scope/pi-plugin","git:https://github.com/user/repo","/absolute/path/to/plugin"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>a(e),style:{width:"100%",minHeight:30,textAlign:"left",padding:"6px 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"pointer",fontFamily:"var(--font-mono)",fontSize:11},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)",e.currentTarget.style.color="var(--text-dim)"},children:e},e))})]}),s&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:s})]})}function lP({pkg:e,cwd:t,busyKey:n,actionError:i,actionMessage:o,sessionId:l,updateStatus:s,checkingUpdate:a,updateError:d,onAction:c,onCheckUpdate:u,onReloadSession:h}){let p,{t:f}=(0,x.s)(),g=lE(e),m=n?.endsWith(g)??!1,y="reload"===n,v=!e.disabled,b=e.canCheckForUpdates,w=s?.state==="update-available";return(0,r.jsxs)(oN,{children:[(0,r.jsxs)(o$,{className:"is-top-aligned",children:[(0,r.jsxs)(oW,{children:[(0,r.jsx)(l$,{scope:e.scope}),e.disabled?(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)",color:"var(--text-dim)"},children:f("i18n.disabled")}):e.filtered&&(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(245,158,11,0.12)",color:"#d97706"},children:f("i18n.filtered")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source})]}),(0,r.jsxs)(oz,{children:[(0,r.jsx)(oO,{size:"small",variant:w?"primary":void 0,onClick:w||!b?()=>c("update",e):u,disabled:m||y||a,title:w?f("i18n.updateAvailable"):void 0,children:f(n===`update:${g}`?"i18n.updating":a?"i18n.checking":w||!b?"i18n.update":"i18n.check")}),(0,r.jsx)(oO,{size:"small",onClick:h,disabled:!l||y||m,title:f(l?"i18n.reloadSession":"i18n.openSessionToReload"),children:f(y?"i18n.reloading":"i18n.reloadSession")}),(0,r.jsx)(oO,{variant:"danger",size:"small",onClick:()=>c("remove",e),disabled:m||y,children:f(n===`remove:${g}`?"i18n.removing":"i18n.remove")}),(0,r.jsx)(oU,{checked:v,loading:m||y,onChange:()=>c(e.disabled?"enable":"disable",e),label:f(e.disabled?"i18n.enablePackage":"i18n.disablePackage")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:f("i18n.status")}),(0,r.jsx)("div",{style:{color:lR(e.status),textTransform:"capitalize"},children:e.status}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:f("i18n.version")}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0},children:[(0,r.jsxs)("div",{className:"skill-version-row",children:[(0,r.jsx)("span",{className:"skill-version-value",children:(p=[],e.version&&p.push(f("i18n.installedVersion",{version:e.version})),e.configuredVersion&&p.push(f("i18n.configuredVersion",{version:e.configuredVersion})),p.length?p.join(" \xb7 "):f("i18n.unknown"))}),w&&(0,r.jsx)("span",{className:"skill-version-value is-update",title:s.displayName,children:f("i18n.updateAvailable")}),b&&(a||s&&!w)&&(0,r.jsx)("span",{className:`skill-update-status ${a?"is-checking":s?.state==="up-to-date"?"is-success":s?.state==="error"?"is-error":"is-muted"}`,children:a?f("i18n.checking"):s?.state==="up-to-date"?f("i18n.upToDate"):s?.state==="unsupported"?f("i18n.automaticChecksUnavailable"):s?.message||f("i18n.checkFailed")})]}),d&&(0,r.jsx)("span",{style:{fontSize:12,color:"#ef4444"},children:d})]}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:f("i18n.package")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.packageName??f("i18n.unknown")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:f("i18n.resources")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)"},children:function(e,t){if(e.disabled)return t("i18n.disabled");let n=[e.counts.extensions?t("i18n.resourceCount",{count:e.counts.extensions,label:t("i18n.extensionShort")}):"",e.counts.skills?t("i18n.resourceCount",{count:e.counts.skills,label:t("i18n.skillShort")}):"",e.counts.prompts?t("i18n.resourceCount",{count:e.counts.prompts,label:t("i18n.promptShort")}):"",e.counts.themes?t("i18n.resourceCount",{count:e.counts.themes,label:t("i18n.themeShort")}):""].filter(Boolean);return n.length?n.join(" \xb7 "):t("i18n.noResources")}(e,f)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:f("i18n.installedPath")}),(0,r.jsx)("div",{style:{color:e.installedPath?"var(--text-muted)":"#ef4444",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.installedPath?lM(e.installedPath):f("i18n.notFound")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:f("i18n.cwd")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:lM(t)})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)(oA,{children:f("i18n.resolvedResources")}),(0,r.jsx)(lN,{pkg:e})]}),o&&(0,r.jsx)("div",{style:{fontSize:12,color:"#16a34a"},children:o}),i&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:i})]})}function lA({extension:e}){let{t}=(0,x.s)(),n=e.enabled?"loaded":"disabled";return(0,r.jsxs)(oN,{children:[(0,r.jsx)(o$,{children:(0,r.jsxs)(oW,{children:[(0,r.jsx)(l$,{scope:e.scope}),(0,r.jsx)(oP,{children:e.name})]})}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:t("i18n.status")}),(0,r.jsx)("div",{style:{color:e.enabled?"var(--accent)":"var(--text-dim)"},children:n}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:t("i18n.installedPath")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:lM(e.path)})]})]})}function lD({cwd:e,sessionId:t,onClose:n,onReloaded:o,embedded:l=!1}){let{t:s}=(0,x.s)(),[a,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(!0),[h,p]=(0,i.useState)(null),[f,g]=(0,i.useState)(()=>ox("plugins",e)),[m,y]=(0,i.useState)(!1),[v,b]=(0,i.useState)(""),[w,k]=(0,i.useState)("global"),[j,S]=(0,i.useState)(null),[C,I]=(0,i.useState)(null),[M,T]=(0,i.useState)(null),[E,L]=(0,i.useState)({}),[R,N]=(0,i.useState)(new Set),[$,W]=(0,i.useState)(!1),[z,P]=(0,i.useState)(null),[A,D]=(0,i.useState)(!1),F=(0,i.useMemo)(()=>a?.packages??[],[a?.packages]),B=(0,i.useMemo)(()=>a?.standaloneExtensions??[],[a?.standaloneExtensions]),H=F.find(e=>lE(e)===f)??null,O=B.find(e=>lL(e)===f)??null,U=a?.projectResourcesLoaded??!0,_=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:F.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[F]),q=(0,i.useCallback)(async()=>{u(!0),p(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);d(n),y(e=>0===n.packages.length&&0===n.standaloneExtensions.length||e),g(e=>e&&(n.packages.some(t=>lE(t)===e)||n.standaloneExtensions.some(t=>lL(t)===e))?e:n.packages[0]?lE(n.packages[0]):n.standaloneExtensions[0]?lL(n.standaloneExtensions[0]):null)}catch(e){p(e instanceof Error?e.message:String(e))}finally{u(!1)}},[e]);(0,i.useEffect)(()=>{L({}),P(null),q()},[e]),(0,i.useEffect)(()=>{f&&om("plugins",f,e)},[e,f]);let K=(0,i.useCallback)(async t=>{let n=(t?[t]:F.filter(e=>e.canCheckForUpdates)).map(lE);if(0!==n.length){P(null),N(e=>new Set([...e,...n])),t||W(!0);try{let n=await fetch("/api/plugins/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,source:t?.source,scope:t?.scope})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);L(e=>{let t={...e};for(let e of r.updates??[])t[lE(e)]=e;return t})}catch(e){P(e instanceof Error?e.message:String(e))}finally{N(e=>{let t=new Set(e);for(let e of n)t.delete(e);return t}),t||W(!1)}}},[e,F]),V=(0,i.useCallback)(async()=>{D(!0),I(null),T(null),P(null);try{let n=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"update",cwd:e})}),r=await n.json();if(!n.ok||r.error)throw Error(r.error??`HTTP ${n.status}`);d(r),L({}),T(s("i18n.packagesUpdated")),t&&T(`${s("i18n.packagesUpdated")} ${s("agents.reloadRequired")}`)}catch(e){I(e instanceof Error?e.message:String(e))}finally{D(!1)}},[e,t,s]),J=(0,i.useCallback)(async(t,n)=>{let r=lE(n);S(`${t}:${r}`),I(null),T(null);try{let i=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:n.source,scope:n.scope,cwd:e})}),o=await i.json();if(!i.ok||o.error)throw Error(o.error??`HTTP ${i.status}`);d(o),"remove"===t?(g(o.packages[0]?lE(o.packages[0]):o.standaloneExtensions[0]?lL(o.standaloneExtensions[0]):null),0===o.packages.length&&0===o.standaloneExtensions.length&&y(!0),T("Package removed."),L(e=>{let t={...e};return delete t[r],t})):(T({install:"Package installed.",update:"Package updated.",disable:"Package disabled.",enable:"Package enabled."}[t]),"update"===t&&L(e=>{let t={...e};return delete t[r],t}))}catch(e){I(e instanceof Error?e.message:String(e))}finally{S(null)}},[e]),Y=(0,i.useCallback)(async()=>{let t=lT(v).trim();if(!t)return;b(t);let n=`${w}\0${t}`;S(`install:${n}`),I(null),T(null);try{var r;let i,o,l=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"install",source:t,scope:w,cwd:e})}),s=await l.json();if(!l.ok||s.error)throw Error(s.error??`HTTP ${l.status}`);d(s);let a=(r=s.packages,o=(i=t.trim()).startsWith("npm:")?i.slice(4):i,r.find(e=>e.scope===w&&e.source===i)??r.find(e=>e.scope===w&&e.source===`npm:${o}`)??r.find(e=>e.scope===w&&e.source.endsWith(i)));g(a?lE(a):n),y(!1),b(""),T("Package installed.")}catch(e){I(e instanceof Error?e.message:String(e))}finally{S(null)}},[e,w,v]),Z=(0,i.useCallback)(async()=>{if(t){S("reload"),I(null),T(null);try{await rN(t,{type:"reload"}),o?.(),await q(),T("Session reloaded.")}catch(e){I(e instanceof Error?e.message:String(e))}finally{S(null)}}},[q,o,t]),G=j?.startsWith("install:")??!1,X=Object.values(E).filter(e=>"update-available"===e.state).length,Q=F.some(e=>e.canCheckForUpdates),ee=c||null!==j||R.size>0||A;return(0,r.jsxs)(oC,{embedded:l,title:s("common.plugins"),subtitle:lM(e),closeLabel:s("i18n.close"),onClose:n,children:[!U&&(0,r.jsx)("div",{role:"status",className:"config-trust-notice",children:s("trust.pluginsNotLoaded")}),(0,r.jsxs)(oI,{children:[(0,r.jsxs)(oM,{children:[(0,r.jsx)(oT,{children:c?(0,r.jsx)("div",{className:"config-sidebar-message",children:"Loading..."}):h?(0,r.jsx)("div",{className:"config-sidebar-message is-error",children:h}):0===F.length&&0===B.length?(0,r.jsx)("div",{className:"config-sidebar-message is-empty",children:"No plugins configured"}):(0,r.jsxs)(r.Fragment,{children:[B.length>0&&(0,r.jsxs)("div",{className:"config-sidebar-group",children:[(0,r.jsx)(oE,{children:s("i18n.extensions")}),B.map(e=>{let t=lL(e);return(0,r.jsxs)(oL,{active:!m&&f===t,title:e.path,onClick:()=>{g(t),y(!1),I(null),T(null)},children:[(0,r.jsx)(oq,{active:e.enabled}),(0,r.jsx)(oR,{className:`is-grow${e.enabled?"":" is-muted"}`,children:e.name})]},t)})]}),_.map(e=>(0,r.jsxs)("div",{className:"config-sidebar-group",children:[(0,r.jsx)(oE,{children:e.scope}),e.packages.map(e=>{let t=lE(e),n=!m&&f===t;return(0,r.jsxs)(oL,{active:n,onClick:()=>{g(t),y(!1),I(null),T(null)},children:[(0,r.jsx)(oq,{active:!e.disabled,color:lR(e.status)}),(0,r.jsx)(oR,{className:`is-grow${e.disabled?" is-muted":""}`,children:e.source}),E[lE(e)]?.state==="update-available"&&(0,r.jsx)("span",{title:s("i18n.updateAvailable"),className:"skill-update-indicator",children:"↑"})]},t)})]},e.scope))]})}),(0,r.jsx)(o_,{active:m,onClick:()=>{y(!0),I(null),T(null)},children:s("i18n.addPlugin")})]}),(0,r.jsx)(oB,{children:(0,r.jsx)(oN,{className:"is-fill",children:m?(0,r.jsx)(lz,{cwd:e,source:v,scope:w,projectResourcesLoaded:U,busy:G,actionError:C,onSourceChange:b,onScopeChange:k,onInstall:Y}):c?null:O?(0,r.jsx)(lA,{extension:O}):H?(0,r.jsx)(lP,{pkg:H,cwd:e,busyKey:j,actionError:C,actionMessage:M,sessionId:t,updateStatus:E[lE(H)],checkingUpdate:R.has(lE(H)),updateError:z,onAction:J,onCheckUpdate:()=>void K(H),onReloadSession:Z},lE(H)):(0,r.jsx)(oF,{children:s("i18n.selectPackage")})})})]}),(0,r.jsxs)(oH,{status:X>0?(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--accent)"},children:[X," ",1===X?s("i18n.update"):s("i18n.updates")]}):a?.diagnostics.length?(0,r.jsxs)("span",{title:a.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:a.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:[a.diagnostics.length," diagnostic",1===a.diagnostics.length?"":"s"]}):(0,r.jsx)("span",{children:a?`${a.totals.extensions} ext \xb7 ${a.totals.skills} skills \xb7 ${a.totals.prompts} prompts \xb7 ${a.totals.themes} themes`:""}),children:[!l&&(0,r.jsx)(oO,{onClick:n,children:s("i18n.close")}),Q&&(0,r.jsx)(oO,{variant:X>0?"primary":"secondary",onClick:()=>void(X>0?V():K()),disabled:ee,title:X>0?s("i18n.updateAllPluginsHint"):void 0,children:A?s("i18n.updating"):$?s("i18n.checking"):X>0?`${s("i18n.updateAllPlugins")} (${X})`:s("i18n.checkUpdates")}),(0,r.jsx)(oO,{variant:"secondary",onClick:()=>void q(),disabled:ee,children:s("i18n.refresh")})]})]})}let lF=new Set(["openai-codex","antigravity","xai"]);function lB({sessionId:e=null,onReloaded:t}){let{t:n}=(0,x.s)(),[o,l]=(0,i.useState)(null),[s,a]=(0,i.useState)(!0),[d,c]=(0,i.useState)(!1),[u,h]=(0,i.useState)(!1),[p,f]=(0,i.useState)(!1),[g,m]=(0,i.useState)(null),[y,v]=(0,i.useState)(null),[b,w]=(0,i.useState)(null),[k,j]=(0,i.useState)("");(0,i.useEffect)(()=>{let e=new AbortController;return a(!0),m(null),(async()=>{try{let t=await fetch("/api/image-generation/settings",{cache:"no-store",signal:e.signal}),n=await t.json();if(!t.ok||n.error||"boolean"!=typeof n.enabled||!Array.isArray(n.connections))throw Error(n.error??`HTTP ${t.status}`);let r=lH(n);l(r),j(e=>{var t;return r.providers.some(t=>t.id===e)?e:(t=r.providers,t.find(e=>!lF.has(e.id))?.id??t[0]?.id??"")})}catch(e){e instanceof DOMException&&"AbortError"===e.name||m(e instanceof Error?e.message:String(e))}finally{e.signal.aborted||a(!1)}})(),()=>e.abort()},[]);let S=async t=>{let n=await t.json();if(!t.ok||n.error||"boolean"!=typeof n.enabled||!Array.isArray(n.connections))throw Error(n.error??`HTTP ${t.status}`);l(lH(n)),f(!!e)},C=async e=>{c(!0),m(null);try{let t=await fetch("/api/image-generation/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});await S(t)}catch(e){m(e instanceof Error?e.message:String(e))}finally{c(!1)}},I=async e=>{if(k){c(!0),m(null);try{let t=await fetch("/api/image-generation/settings/connections",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:e.label,provider:k,model:e.model})});await S(t)}catch(e){m(e instanceof Error?e.message:String(e))}finally{c(!1)}}},M=async()=>{if(!b||!b.label.trim())return void w(null);c(!0),m(null);try{let e=await fetch("/api/image-generation/settings/connections",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:b.id,label:b.label.trim()})});await S(e),w(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{c(!1)}},T=async()=>{if(y){c(!0),m(null);try{let e=await fetch("/api/image-generation/settings/connections",{method:"edit"===y.mode?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify("edit"===y.mode?{id:y.id,label:y.label,provider:y.provider,model:y.model}:{label:y.label,provider:y.provider,model:y.model})});await S(e),v(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{c(!1)}}},E=async e=>{if(window.confirm(n("agents.deleteConfirm",{name:e.label}))){c(!0),m(null);try{let t=await fetch("/api/image-generation/settings/connections",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})});await S(t),y?.mode==="edit"&&y.id===e.id&&v(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{c(!1)}}},L=async()=>{if(e){h(!0),m(null);try{await rN(e,{type:"reload"}),f(!1),t?.()}catch(e){m(e instanceof Error?e.message:String(e))}finally{h(!1)}}},R=o?.connections.filter(e=>"custom"!==e.kind)??[],N=o?.connections.filter(e=>"custom"===e.kind)??[],$=o?.providers??[],W=eo.filter(e=>!N.some(t=>t.provider===k&&t.model===e.model));return(0,r.jsxs)("div",{className:"settings-general",children:[(0,r.jsx)("h2",{className:"settings-general-title",children:n("settings.images")}),(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("p",{className:"settings-general-description",children:n("settings.imagesDescription")}),(0,r.jsxs)("div",{className:"settings-image-options",children:[(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-switch-option",children:[(0,r.jsx)("span",{children:n("settings.imagesEnabled")}),(0,r.jsxs)("div",{className:"settings-image-actions",children:[p&&e&&(0,r.jsx)(oO,{size:"small",onClick:()=>void L(),disabled:u||d,children:u?n("agents.reloading"):n("agents.reloadSession")}),(0,r.jsx)(oU,{checked:o?.enabled===!0,disabled:s||u||!o,loading:d&&!y&&!b,label:n("settings.imagesEnabled"),onChange:e=>void C({enabled:e})})]})]}),o?.enabled&&(0,r.jsxs)("div",{className:"settings-general-columns",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"settings-image-group",children:n("settings.imagesBuiltin")}),R.map(e=>(0,r.jsx)(lO,{connection:e,disabled:s||u||d,unsignedLabel:n("settings.imagesSignedOut"),onChange:t=>void C({connections:{[e.id]:{enabled:t}}}),renaming:b?.id===e.id,renameValue:b?.id===e.id?b.label:e.label,onRenameChange:t=>w({id:e.id,label:t}),onRenameSubmit:()=>void M(),onRenameCancel:()=>w(null),onEdit:()=>{v(null),w({id:e.id,label:e.label})},editLabel:n("i18n.rename")},e.id))]}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"settings-image-group-row",children:[(0,r.jsx)("h3",{className:"settings-image-group",children:n("settings.imagesCustom")}),$.length>0&&!y&&(0,r.jsx)(oO,{size:"small",disabled:s||u||d,onClick:()=>{w(null),v({mode:"create",label:"",provider:k||$[0]?.id||"",model:""})},children:n("settings.imagesOtherModel")})]}),0===$.length&&(0,r.jsx)("p",{className:"settings-general-description",children:n("settings.imagesNoProviders")}),N.map(e=>(0,r.jsx)(lO,{connection:e,disabled:s||u||d,unsignedLabel:n("settings.imagesNotConfigured"),onChange:t=>void C({connections:{[e.id]:{enabled:t}}}),onEdit:()=>{w(null),v({mode:"edit",id:e.id,label:e.label,provider:e.provider,model:e.model})},onDelete:()=>void E(e),editLabel:n("image.edit"),deleteLabel:n("agents.delete")},e.id)),W.length>0&&$.length>0&&(0,r.jsxs)("div",{className:"settings-image-presets",children:[$.length>1&&(0,r.jsx)("select",{"aria-label":n("settings.imagesProvider"),className:"settings-image-provider",value:k,onChange:e=>j(e.target.value),children:$.map(e=>(0,r.jsx)("option",{value:e.id,children:e.name===e.id?e.id:`${e.name} (${e.id})`},e.id))}),(0,r.jsx)("div",{className:"settings-image-preset-actions",children:W.map(e=>(0,r.jsx)(oO,{size:"small",disabled:s||u||d||!k,onClick:()=>void I(e),children:e.label},e.model))})]}),y&&(0,r.jsxs)("form",{className:"settings-image-form",onSubmit:e=>{e.preventDefault(),T()},children:[(0,r.jsxs)("label",{className:"settings-image-field",children:[(0,r.jsx)("span",{children:n("settings.imagesLabel")}),(0,r.jsx)("input",{value:y.label,onChange:e=>v({...y,label:e.target.value}),required:!0})]}),(0,r.jsxs)("label",{className:"settings-image-field",children:[(0,r.jsx)("span",{children:n("settings.imagesProvider")}),(0,r.jsx)("select",{value:y.provider,onChange:e=>v({...y,provider:e.target.value}),required:!0,children:$.map(e=>(0,r.jsx)("option",{value:e.id,children:e.name===e.id?e.id:`${e.name} (${e.id})`},e.id))})]}),(0,r.jsxs)("label",{className:"settings-image-field",children:[(0,r.jsx)("span",{children:n("settings.imagesModel")}),(0,r.jsx)(l_,{value:y.model,t:n,onChange:e=>{let t=eo.find(t=>t.model===e);v({...y,model:e,..."create"===y.mode&&!y.label.trim()&&t?{label:t.label}:{}})}},"edit"===y.mode?y.id:"create")]}),(0,r.jsxs)("div",{className:"settings-image-form-actions",children:[(0,r.jsx)(oO,{type:"submit",variant:"primary",size:"small",disabled:d||!y.label.trim()||!y.provider||!y.model.trim(),children:d?n("agents.saving"):n("agents.save")}),(0,r.jsx)(oO,{type:"button",size:"small",disabled:d,onClick:()=>v(null),children:n("trust.cancel")})]})]})]})]}),p&&(0,r.jsx)("p",{role:"status",className:"settings-image-reload-notice",children:n("agents.reloadRequired")}),g&&(0,r.jsx)("p",{role:"alert",className:"settings-general-error",children:g})]})]})]})}function lH(e){return{enabled:!0===e.enabled,defaultConnection:e.defaultConnection??"",connections:(e.connections??[]).map(e=>({...e,model:e.model??"",kind:"custom"===e.kind?"custom":"builtin"})),providers:(e.providers??[]).filter(e=>!!(e&&"string"==typeof e.id&&e.id))}}function lO({connection:e,disabled:t,unsignedLabel:n,onChange:o,onEdit:l,onDelete:s,editLabel:a,deleteLabel:d,renaming:c=!1,renameValue:u,onRenameChange:h,onRenameSubmit:p,onRenameCancel:f}){let g=(0,i.useRef)(!1),x=!e.signedIn&&!e.enabled;return(0,r.jsxs)("div",{className:`settings-image-connection${e.signedIn?"":" is-unsigned"}`,children:[(0,r.jsxs)("div",{className:"settings-image-connection-copy",children:[c?(0,r.jsx)("input",{className:"settings-image-rename",value:u,autoFocus:!0,"aria-label":a,onChange:e=>h?.(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),g.current=!0,p?.()),"Escape"===e.key&&(e.preventDefault(),g.current=!0,f?.())},onBlur:()=>{if(g.current){g.current=!1;return}p?.()}}):(0,r.jsx)("strong",{children:e.label}),e.signedIn?null:(0,r.jsx)("span",{children:n})]}),(0,r.jsxs)("div",{className:"settings-image-actions",children:[l&&!c?(0,r.jsx)(oO,{size:"small",disabled:t,onClick:l,children:a}):null,s?(0,r.jsx)(oO,{size:"small",disabled:t,onClick:s,children:d}):null,(0,r.jsx)(oU,{checked:e.enabled,disabled:t||x,label:e.label,onChange:o})]})]})}let lU="__other__";function l_({value:e,onChange:t,t:n}){let o=eo.some(t=>t.model===e),[l,s]=(0,i.useState)(!o),a=l||!o?lU:e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("select",{value:a,onChange:e=>{let n=e.target.value;n===lU?s(!0):(s(!1),t(n))},children:[eo.map(e=>(0,r.jsxs)("option",{value:e.model,children:[e.label," \xb7 ",e.model]},e.model)),(0,r.jsx)("option",{value:lU,children:n("settings.imagesOtherModel")})]}),a===lU?(0,r.jsx)("input",{value:e,onChange:e=>t(e.target.value),required:!0}):null]})}let lq=null;async function lK(e){if(!("serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window)||"granted"!==Notification.permission)return!1;if(lq)return lq;let t=(async()=>{try{let t=await fetch("/api/push/config");if(!t.ok)return!1;let{publicKey:n}=await t.json();if(!n)return!1;let r=await navigator.serviceWorker.ready,i=await r.pushManager.getSubscription();return i||(i=await r.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:function(e){let t="=".repeat((4-e.length%4)%4),n=atob((e+t).replace(/-/g,"+").replace(/_/g,"/")),r=new Uint8Array(n.length);for(let e=0;e<n.length;e+=1)r[e]=n.charCodeAt(e);return r}(n)})),(await fetch("/api/push/subscribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({subscription:i.toJSON(),locale:e})})).ok}catch{return lq=null,!1}})();return lq=t,t.then(e=>{e||lq!==t||(lq=null)}),t}function lV({section:e,size:t=16,strokeWidth:n=1.8}){let i={width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,className:"settings-section-icon"};return"general"===e?(0,r.jsxs)("svg",{...i,children:[(0,r.jsx)("path",{d:"M20 7h-9M14 17H5"}),(0,r.jsx)("circle",{cx:"7",cy:"7",r:"3"}),(0,r.jsx)("circle",{cx:"17",cy:"17",r:"3"})]}):"models"===e?(0,r.jsxs)("svg",{...i,children:[(0,r.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,r.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,r.jsx)("path",{d:"M9 1v3M15 1v3M9 20v3M15 20v3M20 9h3M20 15h3M1 9h3M1 15h3"})]}):"images"===e?(0,r.jsxs)("svg",{...i,children:[(0,r.jsx)("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),(0,r.jsx)("circle",{cx:"8.5",cy:"10.5",r:"1.5"}),(0,r.jsx)("path",{d:"m21 16-5-4-4 3-3-2-5 4"})]}):"skills"===e?(0,r.jsx)("svg",{...i,children:(0,r.jsx)("path",{d:"m12 3-1.9 5.8a2 2 0 0 1-1.3 1.3L3 12l5.8 1.9a2 2 0 0 1 1.3 1.3L12 21l1.9-5.8a2 2 0 0 1 1.3-1.3L21 12l-5.8-1.9a2 2 0 0 1-1.3-1.3L12 3Z"})}):"agents"===e?(0,r.jsx)(q,{size:t,strokeWidth:n,className:"settings-section-icon is-agent"}):(0,r.jsxs)("svg",{...i,children:[(0,r.jsx)("path",{d:"m16.5 9.4-9-5.19M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),(0,r.jsx)("polyline",{points:"3.27 6.96 12 12.01 20.73 6.96"}),(0,r.jsx)("line",{x1:"12",y1:"22.08",x2:"12",y2:"12"})]})}function lJ({preference:e}){return"light"===e?(0,r.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,r.jsx)("path",{d:"M12 2v2M12 20v2M4.93 4.93l1.42 1.42M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.42-1.41M17.66 6.34l1.41-1.41"})]}):"dark"===e?(0,r.jsx)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79Z"})}):(0,r.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"4",width:"18",height:"13",rx:"2"}),(0,r.jsx)("path",{d:"M8 21h8M12 17v4"})]})}function lY({sessionId:e,onSessionReloaded:t,quoteSelectionEnabled:n,onQuoteSelectionChange:o}){let{locale:l,setLocale:s,supportedLocales:a,t:d}=(0,x.s)(),{preference:c,setThemePreference:u}=tC(),{width:h,setWidth:p,fontSize:f,setFontSize:g}=nV(),[m,y]=(0,i.useState)(null),[v,b]=(0,i.useState)(!1),[w,k]=(0,i.useState)(null),[j,S]=(0,i.useState)(!1),[C,I]=(0,i.useState)(!0),[M,T]=(0,i.useState)(!1),[E,L]=(0,i.useState)(null),[R,N]=(0,i.useState)(!1),[$,W]=(0,i.useState)(null),[z,P]=(0,i.useState)(!1),[A,D]=(0,i.useState)(!1),[F,B]=(0,i.useState)("");(0,i.useEffect)(()=>{S(tB()),I(ov()),T(nZ())},[]),(0,i.useEffect)(()=>{fetch("/api/web-auth").then(e=>e.ok?e.json():null).then(e=>P(e?.enabled===!0)).catch(()=>{})},[]),(0,i.useEffect)(()=>rC(L),[]);let H=[{id:"light",label:d("settings.themeLight")},{id:"dark",label:d("settings.themeDark")},{id:"auto",label:d("settings.themeSystem")}];(0,i.useEffect)(()=>{let e=!1;return fetch("/api/tools/settings").then(async t=>{let n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);e||y(n)}).catch(t=>{e||k(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let O=async n=>{b(!0),k(null);try{let r=await fetch("/api/tools/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:n})}),i=await r.json();if(!r.ok||i.error)throw Error(i.error??`HTTP ${r.status}`);y(i),e&&(await rN(e,{type:"reload"}),t())}catch(e){k(e instanceof Error?e.message:String(e))}finally{b(!1)}},U=async()=>{if(!R){N(!0),W(null);try{if(!("Notification"in window))throw Error("unsupported or not permitted");let e="default"===Notification.permission?await Notification.requestPermission():Notification.permission;if("granted"!==e||!await lK(l))throw Error("unsupported or not permitted");W({kind:"ok",message:d("settings.pushRegistered")})}catch(e){W({kind:"error",message:`${d("settings.pushRegisterFailed")} ${e instanceof Error?e.message:String(e)}`})}finally{N(!1)}}},_=async()=>{D(!0),B("");try{let e=await fetch("/api/web-auth",{method:"DELETE"});if(!e.ok)throw Error(`HTTP ${e.status}`);window.location.replace("/login")}catch{B(d("auth.logoutFailed"))}finally{D(!1)}};return(0,r.jsxs)("div",{className:"settings-general",children:[(0,r.jsx)("h2",{className:"settings-general-title",children:d("settings.general")}),(0,r.jsxs)("div",{className:"settings-general-columns",children:[(0,r.jsxs)("div",{children:[(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:d("settings.appearance")}),(0,r.jsx)("div",{role:"radiogroup","aria-label":d("settings.appearance"),className:"settings-theme-options",children:H.map(e=>{let t=c===e.id;return(0,r.jsxs)("button",{type:"button",role:"radio","aria-checked":t,onClick:()=>u(e.id),className:"settings-theme-option",children:[(0,r.jsx)(lJ,{preference:e.id}),(0,r.jsx)("span",{className:"settings-theme-option-label",children:e.label})]},e.id)})})]}),(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:d("settings.chat")}),(0,r.jsxs)("div",{className:"settings-chat-options",children:[(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-switch-option",children:[(0,r.jsx)("span",{children:d("settings.thinkingExpandedDefault")}),(0,r.jsx)(oU,{checked:j,label:d("settings.thinkingExpandedDefault"),onChange:e=>{window.localStorage.setItem(tD,String(e)),window.dispatchEvent(new Event(tF)),S(e)}})]}),(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-switch-option",children:[(0,r.jsx)("span",{children:d("settings.autoSessionTitle")}),(0,r.jsx)(oU,{checked:C,label:d("settings.autoSessionTitle"),onChange:e=>{window.localStorage.setItem(oy,String(e)),I(e)}})]}),(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-range-option",children:[(0,r.jsxs)("div",{className:"settings-chat-range-header",children:[(0,r.jsx)("label",{htmlFor:"settings-chat-content-width",children:d("settings.chatContentWidth")}),(0,r.jsxs)("output",{htmlFor:"settings-chat-content-width",children:[h,"px"]}),(0,r.jsx)(oO,{variant:"ghost",size:"small",className:"settings-chat-reset",title:d("settings.resetChatContentWidth"),"aria-label":d("settings.resetChatContentWidth"),disabled:820===h,onClick:()=>p(820),children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5"})})})]}),(0,r.jsx)("input",{id:"settings-chat-content-width",type:"range",min:820,max:2e3,step:10,value:h,onChange:e=>p(Number(e.target.value))})]}),(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-range-option",children:[(0,r.jsxs)("div",{className:"settings-chat-range-header",children:[(0,r.jsx)("label",{htmlFor:"settings-chat-content-font-size",children:d("settings.chatContentFontSize")}),(0,r.jsxs)("output",{htmlFor:"settings-chat-content-font-size",children:[f,"px"]}),(0,r.jsx)(oO,{variant:"ghost",size:"small",className:"settings-chat-reset",title:d("settings.resetChatContentFontSize"),"aria-label":d("settings.resetChatContentFontSize"),disabled:14===f,onClick:()=>g(14),children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5"})})})]}),(0,r.jsx)("input",{id:"settings-chat-content-font-size",type:"range",min:12,max:24,step:1,value:f,onChange:e=>g(Number(e.target.value))})]}),(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-switch-option",children:[(0,r.jsx)("span",{children:d("settings.shiftEnterToSend")}),(0,r.jsx)(oU,{checked:M,label:d("settings.shiftEnterToSend"),onChange:e=>{window.localStorage.setItem(nY,String(e)),T(e)}})]}),(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-switch-option",children:[(0,r.jsx)("span",{children:d("settings.quoteSelection")}),(0,r.jsx)(oU,{checked:n,label:d("settings.quoteSelection"),onChange:o})]}),E&&(0,r.jsxs)("div",{className:"settings-chat-option settings-chat-switch-option",children:[(0,r.jsx)("span",{children:d("settings.browserNotifications")}),"granted"===E?(0,r.jsx)("span",{className:"settings-chat-status",children:d("settings.browserNotificationsOn")}):"denied"===E?(0,r.jsx)("span",{className:"settings-chat-status",children:d("settings.browserNotificationsBlocked")}):(0,r.jsx)(oO,{size:"small",onClick:()=>{Notification.requestPermission().then(L)},children:d("settings.browserNotificationsEnable")})]})]})]}),m?.isWindows&&(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:d("settings.shellTool")}),(0,r.jsx)("p",{className:"settings-general-description",children:d("settings.shellToolDescription")}),(0,r.jsxs)("div",{className:"settings-shell-option",children:[(0,r.jsx)("span",{children:d("settings.usePowerShell")}),(0,r.jsx)(oU,{checked:m.powerShellEnabled,loading:v,label:d("settings.usePowerShell"),onChange:e=>void O(e)})]}),w&&(0,r.jsx)("p",{role:"alert",className:"settings-general-error",children:w})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:d("common.language")}),(0,r.jsx)("div",{role:"radiogroup","aria-label":d("common.language"),className:"settings-language-options",children:a.map(e=>{let t=l===e.id;return(0,r.jsxs)("button",{type:"button",role:"radio","aria-checked":t,onClick:()=>s(e.id),className:"settings-language-option",children:[(0,r.jsx)("span",{className:"settings-language-radio",children:t&&(0,r.jsx)("span",{className:"settings-language-radio-dot"})}),(0,r.jsx)("span",{className:"settings-language-label",children:e.label}),(0,r.jsx)("span",{className:"settings-language-code",children:e.id})]},e.id)})})]}),z&&(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsxs)(oO,{variant:"secondary",disabled:A,onClick:()=>void _(),children:[(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M10 17l5-5-5-5M15 12H3M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"})}),A?d("auth.loggingOut"):d("auth.logOut")]}),F&&(0,r.jsx)("p",{role:"alert",className:"settings-general-error",children:F})]}),(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:d("settings.typography")}),(0,r.jsx)("p",{className:"settings-general-description",children:d("settings.typographyDescription")}),(0,r.jsx)("div",{className:"settings-font-link-row",children:(0,r.jsxs)("a",{href:"https://github.com/be5invis/Sarasa-Gothic/releases",target:"_blank",rel:"noreferrer",title:"Sarasa Term SC is a cut of Sarasa Gothic",className:"settings-font-link",children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,r.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,r.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),(0,r.jsx)("span",{children:d("settings.fontMonoDownload")})]})})]}),(0,r.jsxs)("section",{className:"settings-general-section",children:[(0,r.jsx)("h3",{className:"settings-general-heading",children:d("settings.pushPermission")}),(0,r.jsx)("p",{className:"settings-general-description",children:d("settings.pushPermissionDescription")}),(0,r.jsx)("div",{className:"settings-font-link-row",children:(0,r.jsx)(oO,{size:"small",variant:"secondary",disabled:R,onClick:()=>void U(),children:R?d("settings.pushRegisterLoading"):d("settings.pushRegister")})}),$&&(0,r.jsx)("p",{role:"status",className:"settings-general-error",style:"ok"===$.kind?{color:"var(--accent)"}:void 0,children:$.message})]})]})]})]})}function lZ({cwd:e,sessionId:t,initialSection:n,onClose:o,onSessionReloaded:l,quoteSelectionEnabled:s,onQuoteSelectionChange:a}){let{t:d}=(0,x.s)(),[c,u]=(0,i.useState)(n),[h,p]=(0,i.useState)(()=>new Set([c])),f=[{id:"general",label:d("settings.general"),requiresProject:!1},{id:"models",label:d("common.models"),requiresProject:!1},{id:"agents",label:d("common.agents"),requiresProject:!0},{id:"images",label:d("settings.images"),requiresProject:!1},{id:"skills",label:d("common.skills"),requiresProject:!0},{id:"plugins",label:d("common.plugins"),requiresProject:!0}];(0,i.useEffect)(()=>og(n),[n]),(0,i.useEffect)(()=>{let e=e=>{"Escape"!==e.key||e.defaultPrevented||(e.preventDefault(),e.stopPropagation(),o())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[o]),(0,i.useEffect)(()=>{e||"skills"!==c&&"agents"!==c&&"plugins"!==c||(u("general"),p(e=>new Set(e).add("general")),og("general"))},[e,c]);let g=e=>{p(t=>new Set(t).add(e)),u(e),og(e)},m=(e,t)=>h.has(e)?(0,r.jsx)("div",{hidden:c!==e,className:"settings-section-host",children:t},e):null;return(0,r.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":d("settings.title"),onClick:e=>{e.target===e.currentTarget&&o()},className:"settings-dialog-backdrop",children:(0,r.jsxs)("div",{className:"settings-dialog-surface",children:[(0,r.jsxs)("div",{className:"settings-dialog-header",children:[(0,r.jsx)("strong",{className:"settings-dialog-title",children:d("settings.title")}),(0,r.jsx)("select",{"aria-label":d("settings.title"),value:c,onChange:e=>g(e.target.value),className:"settings-mobile-section-picker",children:f.map(t=>(0,r.jsx)("option",{value:t.id,disabled:t.requiresProject&&!e,children:t.label},t.id))}),(0,r.jsx)("nav",{"aria-label":d("settings.title"),className:"settings-section-tabs",children:f.map(t=>{let n=c===t.id,i=t.requiresProject&&!e;return(0,r.jsxs)("button",{type:"button",className:"settings-section-tab",disabled:i,title:i?d("settings.projectRequired"):t.label,"aria-current":n?"page":void 0,onClick:()=>g(t.id),children:[(0,r.jsx)(lV,{section:t.id}),(0,r.jsx)("span",{children:t.label})]},t.id)})}),(0,r.jsx)("button",{type:"button",onClick:o,title:d("i18n.close"),"aria-label":d("i18n.close"),className:"config-close-button settings-dialog-close",children:"\xd7"})]}),(0,r.jsxs)("main",{className:"settings-dialog-main",children:[m("general",(0,r.jsx)(lY,{sessionId:t,onSessionReloaded:l,quoteSelectionEnabled:s,onQuoteSelectionChange:a})),m("models",(0,r.jsx)(ll,{embedded:!0,onClose:o,cwd:e})),e&&m("agents",(0,r.jsx)(lI,{embedded:!0,cwd:e,sessionId:t,onClose:o,onReloaded:l},e)),m("images",(0,r.jsx)(lB,{sessionId:t,onReloaded:l})),e&&m("skills",(0,r.jsx)(lp,{embedded:!0,cwd:e,onClose:o},e)),e&&m("plugins",(0,r.jsx)(lD,{embedded:!0,cwd:e,sessionId:t,onClose:o,onReloaded:l},e))]})]})})}function lG({cwd:e,busy:t,error:n,onCancel:o,onConfirm:l}){let{t:s}=(0,x.s)(),a=(0,i.useRef)(null),d=(0,i.useRef)(null);return(0,i.useEffect)(()=>{let e=document.activeElement;return d.current?.focus(),()=>{e?.isConnected?e.focus():document.querySelector('[data-dialog-focus-fallback="true"]')?.focus()}},[]),(0,i.useEffect)(()=>{t&&a.current?.focus()},[t]),(0,r.jsx)("div",{role:"presentation",style:{position:"fixed",inset:0,zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center",padding:16,background:"rgba(0,0,0,0.4)"},onClick:e=>{t||e.target!==e.currentTarget||o()},children:(0,r.jsxs)("div",{ref:a,role:"dialog","aria-modal":"true","aria-labelledby":"project-trust-title",tabIndex:-1,onKeyDown:e=>{if("Escape"===e.key&&!t){e.preventDefault(),o();return}if("Tab"!==e.key)return;let n=Array.from(a.current?.querySelectorAll("button:not(:disabled)")??[]);if(0===n.length){e.preventDefault(),a.current?.focus();return}let r=n[0],i=n[n.length-1];e.shiftKey&&(document.activeElement===r||document.activeElement===a.current)?(e.preventDefault(),i.focus()):e.shiftKey||document.activeElement!==i||(e.preventDefault(),r.focus())},style:{width:440,maxWidth:"100%",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",boxShadow:"0 12px 36px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:12,padding:"18px 18px 14px"},children:[(0,r.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0,marginTop:1},children:[(0,r.jsx)("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"}),(0,r.jsx)("path",{d:"m9 12 2 2 4-4"})]}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{id:"project-trust-title",style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:s("trust.dialogTitle")}),(0,r.jsx)("div",{style:{marginTop:7,fontSize:12,lineHeight:1.6,color:"var(--text-muted)"},children:s("trust.dialogBody")}),(0,r.jsx)("code",{style:{display:"block",marginTop:10,padding:"8px 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:e}),n&&(0,r.jsx)("div",{role:"alert",style:{marginTop:10,color:"#ef4444",fontSize:12,lineHeight:1.5},children:n})]})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,r.jsx)("button",{ref:d,type:"button",onClick:o,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:t?"not-allowed":"pointer",fontSize:12},children:s("trust.cancel")}),(0,r.jsx)("button",{type:"button",onClick:l,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--accent)",borderRadius:5,background:"var(--accent)",color:"white",cursor:t?"wait":"pointer",opacity:t?.7:1,fontSize:12,fontWeight:600},children:s(t?"trust.trusting":"trust.trustProject")})]})]})})}function lX(e){return"message"===e.type&&"message"in e}function lQ(e){let t=e,n=t.branchPreview,r=lX(t.entry)?t.entry:null,i=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],n??=t.branchPreview,!r&&lX(t.entry)&&(r=t.entry),i+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:i,branchPreview:n,labelEntry:r??t.entry}}function l0(e){if(e.length>1)return!0;let t=[...e];for(;t.length>0;){let e=t.pop();if(e.children.length>1)return!0;for(let n of e.children)t.push(n)}return!1}function l1({node:e,activePathIds:t,depth:n,isLast:i,parentLines:o,onSelect:l}){let{node:s,skipped:a,branchPreview:d,labelEntry:c}=lQ(e),u=t.has(s.entry.id),h=t.has(e.entry.id)||t.has(s.entry.id),p=d?.text??function(e){if("message"===e.type&&"message"in e){let t=e.message,n=t.content,r="";if("string"==typeof n?r=n:Array.isArray(n)&&(r=n.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),r.length>40&&(r=r.slice(0,40)+"…"),r)return r;if("assistant"===t.role)return"[assistant]"}return e.type}(c),f=d?d.role??null:lX(c)?c.message.role:null;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>l(s.entry.id),children:[o.map((e,t)=>(0,r.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,r.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,r.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,r.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:i?"50%":0,width:1,background:"var(--border)"}}),(0,r.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,r.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:u?"var(--accent)":h?"var(--text-muted)":"var(--border)",border:u?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),f&&(0,r.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===f?"var(--accent)":"var(--text-dim)",background:"user"===f?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===f?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===f?"U":"A"}),a>0&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",a]}),(0,r.jsx)("span",{style:{fontSize:11,color:u?"var(--text)":h?"var(--text-muted)":"var(--text-dim)",fontWeight:u?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:p})]}),s.children.map((e,a)=>(0,r.jsx)(l1,{node:e,activePathIds:t,depth:n+1,isLast:a===s.children.length-1,parentLines:[...o,!i],onSelect:l},e.entry.id))]})}function l2({tree:e,activeLeafId:t,onLeafChange:n,inline:o,containerRef:l,open:s,onToggle:a,hasSession:d,compact:c,hideInlineButton:u,disabled:h=!1}){let{t:p}=(0,x.s)(),[f,g]=(0,i.useState)(!1),m=void 0!==s?s:f,y=(0,i.useRef)(null),[v,b]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!m||!o)return;let e=l?.current??y.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();b({top:t.bottom,left:t.left,width:t.width})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[m,o,l]);let w=(0,i.useMemo)(()=>(function(e,t){if(!t)return new Set;let n=e.map(e=>({node:e,path:[e.entry.id]}));for(;n.length>0;){let{node:e,path:r}=n.pop();if(e.entry.id===t||e.compressedEntryIds?.includes(t))return new Set(r);for(let t of e.children)n.push({node:t,path:[...r,t.entry.id]})}return new Set})(e,t),[e,t]),k=(0,i.useCallback)(e=>{n(e)},[n]),j=d?l0(e)?null:p("i18n.noBranches"):p("i18n.noActiveSession"),S=function(e){if(e.length>1)return e;if(0===e.length)return[];let t=lQ(e[0]).node;return t.children.length>1?t.children:[]}(e),C=!j&&S.length>0,I=h||!C,M=(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:I?"var(--text-dim)":"var(--accent)",flexShrink:0,display:"block",transform:"translateY(0.5px)"},children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),T=(0,r.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:2,transform:m?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return o?(0,r.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,r.jsxs)("button",{className:"workspace-header-action",ref:y,disabled:I,onClick:()=>{I||(a?a():g(e=>!e))},style:{display:u?"none":"flex",alignItems:"center",justifyContent:c?"center":void 0,gap:6*!c,height:"100%",width:c?30:void 0,padding:c?0:"0 12px",background:m?"var(--bg-selected)":"none",border:"none",cursor:I?"not-allowed":"pointer",color:I?"var(--text-dim)":m?"var(--text)":"var(--text-muted)",opacity:I?.45:1,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{I||(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{I||(e.currentTarget.style.color=m?"var(--text)":"var(--text-muted)",e.currentTarget.style.background=m?"var(--bg-selected)":"none")},title:I?p("i18n.noBranches",{defaultValue:"没有分支"}):p("i18n.branches"),"aria-label":p("i18n.branches"),"aria-pressed":m,children:[M,!c&&(0,r.jsx)("span",{style:{lineHeight:1},children:p("i18n.branches")})]}),m&&v&&(0,r.jsx)("div",{style:{position:"fixed",top:v.top,left:v.left,width:v.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:C?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:S.map((e,t)=>(0,r.jsx)(l1,{node:e,activePathIds:w,depth:0,isLast:t===S.length-1,parentLines:[],onSelect:k},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:j})})]}):(0,r.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,r.jsxs)("button",{onClick:()=>g(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:11,textAlign:"left"},children:[M,(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:p("i18n.branches")}),T]}),m&&(0,r.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,background:"var(--bg)",borderBottom:"1px solid var(--border)",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:C?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:S.map((e,t)=>(0,r.jsx)(l1,{node:e,activePathIds:w,depth:0,isLast:t===S.length-1,parentLines:[],onSelect:k},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:j??p("i18n.noBranches")})})]})}function l4({mobile:e,disabled:t,menuOpen:n,exporting:o=!1,error:l,labels:s,onViewFullHistory:a,onExportMarkdown:d,onMenuOpenChange:c}){let u=(0,i.useRef)(null),[h,p]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!n)return void p(null);let e=()=>{let e=u.current?.getBoundingClientRect();e&&p({top:e.bottom,left:e.left})};e();let t=e=>{u.current?.contains(e.target)||c(!1)},r=e=>{"Escape"===e.key&&c(!1)};return window.addEventListener("resize",e),document.addEventListener("pointerdown",t,!0),document.addEventListener("keydown",r,!0),()=>{window.removeEventListener("resize",e),document.removeEventListener("pointerdown",t,!0),document.removeEventListener("keydown",r,!0)}},[n,c]);let f=t?"var(--text-dim)":"var(--text-muted)",g=(e,n)=>{t||(e.currentTarget.style.color=n?"var(--text)":"var(--text-muted)",e.currentTarget.style.background=n?"var(--bg-hover)":"none")};return(0,r.jsxs)("div",{ref:u,style:{display:"flex",alignItems:"stretch",height:"100%",position:"relative"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>{t||c(!n)},disabled:t,title:t?s.unsaved:s.menu,"aria-label":s.menu,"aria-haspopup":"menu","aria-expanded":n,style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:n?"var(--bg-selected)":"none",border:"none",color:n?"var(--text)":f,cursor:t?"not-allowed":"pointer",opacity:t?.45:1,flexShrink:0,transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>g(e,!0),onMouseLeave:e=>g(e,!1),className:"workspace-header-action","data-mobile-toolbar-action":e?"history":void 0,children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:n?"var(--text)":f,flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"}),(0,r.jsx)("path",{d:"M12 7v5l3 2"})]})}),n&&!t&&h&&(0,r.jsxs)("div",{role:"menu","aria-label":s.menu,style:{position:"fixed",top:h.top+2,left:Math.max(8,Math.min(h.left,window.innerWidth-210)),minWidth:195,zIndex:520,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,boxShadow:"0 6px 20px rgba(0,0,0,0.12)",padding:4,display:"flex",flexDirection:"column",gap:2},children:[(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{c(!1),a()},style:l8,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-muted)",flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7L3 8"}),(0,r.jsx)("path",{d:"M3 3v5h5"}),(0,r.jsx)("path",{d:"M12 7v5l3 2"})]}),(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.full})]}),(0,r.jsxs)("button",{type:"button",role:"menuitem",title:s.exportMarkdownTitle,disabled:o,onClick:()=>{d()},style:{...l8,opacity:o?.6:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-muted)",flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,r.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,r.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.exportMarkdown}),o&&(0,r.jsxs)("svg",{className:"animate-spin",width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{marginLeft:6,flexShrink:0},"aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,r.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})]}),l&&(0,r.jsx)("div",{style:{padding:"6px 8px",fontSize:11,color:"#dc2626",lineHeight:1.35},children:l})]})]})}let l8={display:"flex",alignItems:"center",gap:8,width:"100%",height:28,padding:"0 8px",border:"none",borderRadius:4,background:"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12,fontFamily:"var(--font-ui)",transition:"background 0.12s ease",boxSizing:"border-box"};function l5({loading:e,prompt:t,translate:n}){return(0,r.jsxs)("section",{className:"system-prompt-panel","aria-label":n("system.prompt"),children:[(0,r.jsx)("div",{className:"system-prompt-scroll",children:t?(0,r.jsx)("div",{className:"system-prompt-text",children:t}):(0,r.jsx)("div",{className:"system-prompt-empty",children:n(""===t?"system.empty":e?"system.loading":"system.load")})}),(0,r.jsx)("style",{children:`
|
|
10
|
+
.system-prompt-panel {
|
|
11
|
+
display: flex;
|
|
12
|
+
height: min(600px, 75dvh);
|
|
13
|
+
min-height: 220px;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
background: var(--bg-panel);
|
|
16
|
+
border-bottom: 1px solid var(--border);
|
|
17
|
+
}
|
|
18
|
+
.system-prompt-scroll {
|
|
19
|
+
min-height: 0;
|
|
20
|
+
flex: 1;
|
|
21
|
+
overflow: auto;
|
|
22
|
+
padding: 12px 16px;
|
|
23
|
+
}
|
|
24
|
+
.system-prompt-text {
|
|
25
|
+
color: var(--text-muted);
|
|
26
|
+
font-family: var(--font-mono);
|
|
27
|
+
font-size: 12px;
|
|
28
|
+
line-height: 1.6;
|
|
29
|
+
overflow-wrap: anywhere;
|
|
30
|
+
white-space: pre-wrap;
|
|
31
|
+
}
|
|
32
|
+
.system-prompt-empty {
|
|
33
|
+
padding: 10px 0;
|
|
34
|
+
color: var(--text-muted);
|
|
35
|
+
font-size: 12px;
|
|
36
|
+
font-style: italic;
|
|
37
|
+
}
|
|
38
|
+
`})]})}function l6(e){if("string"==typeof e)return e;if(void 0===e)return"";try{return JSON.stringify(e)}catch{return String(e)}}function l3({children:e}){return(0,r.jsx)("div",{className:"tool-definitions-empty",children:e})}function l7({loading:e,tools:t,translate:n}){let o=(0,i.useMemo)(()=>t?.filter(e=>e.active)??null,[t]),[l,s]=(0,i.useState)(null);(0,i.useEffect)(()=>{s(e=>o?.some(t=>t.name===e)?e:o?.[0]?.name??null)},[o]);let a=o?.find(e=>e.name===l)??o?.[0]??null,d=a?function(e){if(!e||!e.properties||"object"!=typeof e.properties)return[];let t=e.properties,n=new Set(Array.isArray(e.required)?e.required.filter(e=>"string"==typeof e):[]);return Object.entries(t).map(([e,t])=>{let r=t&&"object"==typeof t?t:{};return{name:e,type:function e(t){let n=Array.isArray(t.anyOf)?t.anyOf:Array.isArray(t.oneOf)?t.oneOf:null;if(n)return n.map(t=>t&&"object"==typeof t?e(t):"unknown").filter((e,t,n)=>n.indexOf(e)===t).join(" | ");if(void 0!==t.const)return l6(t.const);if(Array.isArray(t.enum)&&t.enum.length>0&&void 0===t.type)return[...new Set(t.enum.map(e=>null===e?"null":typeof e))].join(" | ");let r=t.type,i=Array.isArray(r)?r.filter(e=>"string"==typeof e).join(" | "):"string"==typeof r?r:"string"==typeof t.$ref?t.$ref.split("/").pop()??"object":"unknown";if("array"===i){let n=t.items,r=n&&"object"==typeof n?e(n):"unknown";return`${r}[]`}return i}(r),description:"string"==typeof r.description?r.description:void 0,required:n.has(e),allowedValues:Array.isArray(r.enum)?r.enum.map(l6).join(", "):void 0,defaultValue:void 0===r.default?void 0:l6(r.default)}})}(a.parameters):[];return(0,r.jsxs)("div",{className:"tool-definitions-panel",children:[(0,r.jsx)("nav",{className:"tool-definitions-sidebar","aria-label":n("tools.title"),children:(0,r.jsx)("div",{className:"tool-definitions-list",children:o&&o.length>0?o.map(e=>{let t=e.name===a?.name;return(0,r.jsx)("button",{type:"button",className:`tool-definitions-item${t?" selected":""}`,"aria-pressed":t,onClick:()=>s(e.name),children:(0,r.jsx)("code",{children:e.name})},e.name)}):o?(0,r.jsx)(l3,{children:n("tools.noTools")}):(0,r.jsx)(l3,{children:e?n("tools.loading"):n("tools.load")})})}),(0,r.jsx)("section",{className:"tool-definition-detail","aria-label":n("tools.details"),children:a?(0,r.jsxs)("div",{className:"tool-definition-scroll",children:[a.description&&(0,r.jsxs)("section",{className:"tool-definition-section",children:[(0,r.jsx)("div",{className:"tool-definition-section-label",children:n("tools.description")}),(0,r.jsx)("div",{className:"tool-definition-description",children:a.description})]}),(0,r.jsxs)("section",{className:"tool-definition-section",children:[(0,r.jsxs)("div",{className:"tool-definition-section-label",children:[(0,r.jsx)("span",{children:n("tools.parameters")}),(0,r.jsx)("span",{children:n("tools.parameterCount",{count:d.length})})]}),d.length>0?(0,r.jsx)("div",{className:"tool-definition-fields",children:d.map(e=>(0,r.jsxs)("div",{className:"tool-definition-field",children:[(0,r.jsxs)("div",{className:"tool-definition-field-name",children:[(0,r.jsx)("code",{children:e.name}),(0,r.jsx)("span",{className:e.required?"required":void 0,children:n(e.required?"tools.required":"tools.optional")})]}),(0,r.jsxs)("div",{className:"tool-definition-field-value",children:[(0,r.jsx)("code",{className:"tool-definition-type",children:e.type}),e.description&&(0,r.jsx)("div",{children:e.description}),e.allowedValues&&(0,r.jsxs)("div",{className:"tool-definition-meta",children:[n("tools.allowedValues"),": ",(0,r.jsx)("code",{children:e.allowedValues})]}),void 0!==e.defaultValue&&(0,r.jsxs)("div",{className:"tool-definition-meta",children:[n("tools.defaultValue"),": ",(0,r.jsx)("code",{children:e.defaultValue})]})]})]},e.name))}):(0,r.jsx)("div",{className:"tool-definition-no-parameters",children:n("tools.noParameters")})]}),a.promptGuidelines&&a.promptGuidelines.length>0&&(0,r.jsxs)("section",{className:"tool-definition-section",children:[(0,r.jsx)("div",{className:"tool-definition-section-label",children:n("tools.guidelines")}),(0,r.jsx)("ul",{className:"tool-definition-guidelines",children:a.promptGuidelines.map((e,t)=>(0,r.jsx)("li",{children:e},`${a.name}:${t}`))})]})]}):(0,r.jsx)(l3,{children:o?n("tools.noTools"):e?n("tools.loading"):n("tools.load")})}),(0,r.jsx)("style",{children:`
|
|
39
|
+
.tool-definitions-panel {
|
|
40
|
+
display: grid;
|
|
41
|
+
grid-template-columns: clamp(112px, 26%, 220px) minmax(0, 1fr);
|
|
42
|
+
height: min(600px, 75dvh);
|
|
43
|
+
min-height: 240px;
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
background: var(--bg-panel);
|
|
46
|
+
border-bottom: 1px solid var(--border);
|
|
47
|
+
}
|
|
48
|
+
.tool-definitions-sidebar,
|
|
49
|
+
.tool-definition-detail {
|
|
50
|
+
display: flex;
|
|
51
|
+
min-width: 0;
|
|
52
|
+
min-height: 0;
|
|
53
|
+
flex-direction: column;
|
|
54
|
+
}
|
|
55
|
+
.tool-definitions-sidebar {
|
|
56
|
+
border-right: 1px solid var(--border);
|
|
57
|
+
background: color-mix(in srgb, var(--bg-panel) 94%, var(--bg));
|
|
58
|
+
}
|
|
59
|
+
.tool-definitions-list,
|
|
60
|
+
.tool-definition-scroll {
|
|
61
|
+
min-height: 0;
|
|
62
|
+
flex: 1;
|
|
63
|
+
overflow: auto;
|
|
64
|
+
}
|
|
65
|
+
.tool-definitions-item {
|
|
66
|
+
display: flex;
|
|
67
|
+
width: 100%;
|
|
68
|
+
min-height: 38px;
|
|
69
|
+
align-items: center;
|
|
70
|
+
padding: 8px 12px;
|
|
71
|
+
border: none;
|
|
72
|
+
border-bottom: 1px solid var(--border);
|
|
73
|
+
background: transparent;
|
|
74
|
+
color: var(--text-muted);
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
text-align: left;
|
|
77
|
+
}
|
|
78
|
+
.tool-definitions-item:hover {
|
|
79
|
+
background: var(--bg-hover);
|
|
80
|
+
color: var(--text);
|
|
81
|
+
}
|
|
82
|
+
.tool-definitions-item.selected {
|
|
83
|
+
background: var(--bg-selected);
|
|
84
|
+
box-shadow: inset 2px 0 0 var(--accent);
|
|
85
|
+
color: var(--text);
|
|
86
|
+
}
|
|
87
|
+
.tool-definitions-item code {
|
|
88
|
+
max-width: 100%;
|
|
89
|
+
color: inherit;
|
|
90
|
+
font-size: 11px;
|
|
91
|
+
font-weight: 600;
|
|
92
|
+
overflow-wrap: anywhere;
|
|
93
|
+
}
|
|
94
|
+
.tool-definition-scroll {
|
|
95
|
+
padding: 14px 16px 20px;
|
|
96
|
+
}
|
|
97
|
+
.tool-definition-section + .tool-definition-section {
|
|
98
|
+
margin-top: 18px;
|
|
99
|
+
}
|
|
100
|
+
.tool-definition-section-label {
|
|
101
|
+
display: flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: space-between;
|
|
104
|
+
gap: 8px;
|
|
105
|
+
margin-bottom: 7px;
|
|
106
|
+
color: var(--text-dim);
|
|
107
|
+
font-size: 11px;
|
|
108
|
+
font-weight: 600;
|
|
109
|
+
}
|
|
110
|
+
.tool-definition-section-label > span:last-child {
|
|
111
|
+
font-weight: 400;
|
|
112
|
+
white-space: nowrap;
|
|
113
|
+
}
|
|
114
|
+
.tool-definition-description {
|
|
115
|
+
color: var(--text-muted);
|
|
116
|
+
font-size: 12px;
|
|
117
|
+
line-height: 1.55;
|
|
118
|
+
overflow-wrap: anywhere;
|
|
119
|
+
white-space: pre-wrap;
|
|
120
|
+
}
|
|
121
|
+
.tool-definition-fields {
|
|
122
|
+
border-top: 1px solid var(--border);
|
|
123
|
+
}
|
|
124
|
+
.tool-definition-field {
|
|
125
|
+
display: grid;
|
|
126
|
+
grid-template-columns: minmax(88px, 0.75fr) minmax(0, 1.5fr);
|
|
127
|
+
gap: 12px;
|
|
128
|
+
padding: 9px 0;
|
|
129
|
+
border-bottom: 1px solid var(--border);
|
|
130
|
+
font-size: 11px;
|
|
131
|
+
line-height: 1.45;
|
|
132
|
+
}
|
|
133
|
+
.tool-definition-field-name {
|
|
134
|
+
display: flex;
|
|
135
|
+
min-width: 0;
|
|
136
|
+
flex-direction: column;
|
|
137
|
+
gap: 3px;
|
|
138
|
+
color: var(--text);
|
|
139
|
+
}
|
|
140
|
+
.tool-definition-field-name code {
|
|
141
|
+
overflow-wrap: anywhere;
|
|
142
|
+
}
|
|
143
|
+
.tool-definition-field-name span {
|
|
144
|
+
color: var(--text-dim);
|
|
145
|
+
font-size: 10px;
|
|
146
|
+
}
|
|
147
|
+
.tool-definition-field-name span.required {
|
|
148
|
+
color: var(--accent);
|
|
149
|
+
}
|
|
150
|
+
.tool-definition-field-value {
|
|
151
|
+
min-width: 0;
|
|
152
|
+
color: var(--text-muted);
|
|
153
|
+
overflow-wrap: anywhere;
|
|
154
|
+
}
|
|
155
|
+
.tool-definition-type {
|
|
156
|
+
display: block;
|
|
157
|
+
margin-bottom: 3px;
|
|
158
|
+
color: var(--text);
|
|
159
|
+
}
|
|
160
|
+
.tool-definition-meta {
|
|
161
|
+
margin-top: 4px;
|
|
162
|
+
color: var(--text-dim);
|
|
163
|
+
}
|
|
164
|
+
.tool-definition-meta code {
|
|
165
|
+
color: var(--text-muted);
|
|
166
|
+
}
|
|
167
|
+
.tool-definition-no-parameters {
|
|
168
|
+
padding: 2px 0 10px;
|
|
169
|
+
color: var(--text-dim);
|
|
170
|
+
font-size: 11px;
|
|
171
|
+
}
|
|
172
|
+
.tool-definition-guidelines {
|
|
173
|
+
margin: 0;
|
|
174
|
+
padding-left: 18px;
|
|
175
|
+
color: var(--text-muted);
|
|
176
|
+
font-size: 11px;
|
|
177
|
+
line-height: 1.5;
|
|
178
|
+
}
|
|
179
|
+
.tool-definitions-empty {
|
|
180
|
+
padding: 14px 12px;
|
|
181
|
+
color: var(--text-muted);
|
|
182
|
+
font-size: 12px;
|
|
183
|
+
font-style: italic;
|
|
184
|
+
overflow-wrap: anywhere;
|
|
185
|
+
}
|
|
186
|
+
@media (max-width: 640px) {
|
|
187
|
+
.tool-definitions-panel {
|
|
188
|
+
grid-template-columns: 112px minmax(0, 1fr);
|
|
189
|
+
}
|
|
190
|
+
.tool-definitions-item {
|
|
191
|
+
padding: 8px 10px;
|
|
192
|
+
}
|
|
193
|
+
.tool-definition-scroll {
|
|
194
|
+
padding: 12px;
|
|
195
|
+
}
|
|
196
|
+
.tool-definition-field {
|
|
197
|
+
grid-template-columns: minmax(74px, 0.7fr) minmax(0, 1.3fr);
|
|
198
|
+
gap: 9px;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
`})]})}function l9(e){return e.name||e.firstMessage||e.id.slice(0,12)}function se(e,t){return t?"running":e.relation?.kind==="subagent"?e.relation.status:"completed"}function st(e){return"running"===e||"starting"===e?0:"queued"===e?1:2}function sn({status:e}){return"running"===e||"starting"===e?(0,r.jsx)(_,{size:13}):"failed"===e?(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"m9 9 6 6M15 9l-6 6"})]}):"queued"===e?(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"M12 7v5l3 2"})]}):"aborted"===e||"interrupted"===e?(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"M9 9h6v6H9z"})]}):(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{d:"m8 12 3 3 5-6"})]})}function sr({session:e,main:t,selected:n,running:i,onSelect:o,onOpenInNewTab:l}){let{locale:s,t:a}=(0,x.s)(),d=e.relation?.kind==="subagent"?e.relation:null,c=se(e,i),u=t?a("agentSwitcher.main"):d?.description||l9(e),h=t?l9(e):`${d?.profile??a("agentSwitcher.subagent")} \xb7 ${function(e,t){let n=new Date(e).getTime();if(!Number.isFinite(n))return"";let r=Math.round((n-Date.now())/1e3),i=new Intl.RelativeTimeFormat(t,{numeric:"auto"});if(60>Math.abs(r))return i.format(r,"second");let o=Math.round(r/60);if(60>Math.abs(o))return i.format(o,"minute");let l=Math.round(o/60);return 24>Math.abs(l)?i.format(l,"hour"):i.format(Math.round(l/24),"day")}(e.modified,s)}`;return(0,r.jsxs)("button",{type:"button",role:"option","aria-selected":n,onClick:o,onAuxClick:e=>{1===e.button&&l&&(e.preventDefault(),l())},style:{width:"100%",minHeight:56,display:"grid",gridTemplateColumns:"28px minmax(0, 1fr) auto",alignItems:"center",gap:9,padding:"7px 12px",border:"none",borderBottom:"1px solid var(--border)",borderLeft:n?"2px solid var(--accent)":"2px solid transparent",background:n?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{n||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{n||(e.currentTarget.style.background="transparent")},children:[(0,r.jsx)("span",{style:{width:28,height:28,display:"grid",placeItems:"center",color:t?"var(--text-muted)":"var(--accent)"},children:t?(0,r.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),(0,r.jsx)("path",{d:"M3 9h18"})]}):(0,r.jsx)(q,{size:17,strokeWidth:1.8})}),(0,r.jsxs)("span",{style:{minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:n?600:500},title:u,children:u}),(0,r.jsx)("span",{style:{display:"block",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:11},title:h,children:h})]}),(0,r.jsx)("span",{style:{display:"flex",alignItems:"center",gap:6,color:t&&!i?"var(--text-dim)":"running"===c||"starting"===c?"var(--accent)":"completed"===c?"#16a34a":"failed"===c?"#dc2626":"aborted"===c?"#d97706":"var(--text-dim)",fontSize:11,whiteSpace:"nowrap"},children:t&&!i?n?a("agentSwitcher.current"):null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(sn,{status:c}),(0,r.jsx)("span",{children:a(`agentSwitcher.status.${c}`)})]})})]})}function si({rootSession:e,subagents:t,selectedSessionId:n,runningSessionIds:o,onSelectSession:l,onOpenInNewTab:s}){let{t:a}=(0,x.s)(),[d,c]=(0,i.useState)(""),u=(0,i.useMemo)(()=>[...t].sort((e,t)=>{let n=st(se(e,o.has(e.id)))-st(se(t,o.has(t.id)));return 0!==n?n:t.modified.localeCompare(e.modified)}),[o,t]),h=d.trim().toLowerCase(),p=h?u.filter(e=>{let t=e.relation?.kind==="subagent"?e.relation:null;return[t?.description,t?.profile,e.name,e.firstMessage].some(e=>e?.toLowerCase().includes(h))}):u,f=t.filter(e=>o.has(e.id)).length;return(0,r.jsx)("div",{role:"listbox","aria-label":a("agentSwitcher.title"),style:{background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 10px 30px rgba(0, 0, 0, 0.14)",overflow:"hidden"},children:(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{minHeight:44,display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("strong",{style:{fontSize:12,fontWeight:600},children:a("agentSwitcher.title")}),(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:a("agentSwitcher.count",{count:t.length})}),f>0&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--accent)",fontSize:11},children:a("agentSwitcher.runningCount",{count:f})})]}),t.length>8&&(0,r.jsx)("div",{style:{padding:8,borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("input",{type:"search",value:d,onChange:e=>c(e.target.value),placeholder:a("agentSwitcher.search"),"aria-label":a("agentSwitcher.search"),style:{width:"100%",height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none"}})}),(0,r.jsxs)("div",{style:{maxHeight:"min(58dvh, 480px)",overflowY:"auto"},children:[(0,r.jsx)(sr,{session:e,main:!0,selected:e.id===n,running:o.has(e.id),onSelect:()=>l(e),onOpenInNewTab:s?()=>s(e):void 0}),p.map(e=>(0,r.jsx)(sr,{session:e,selected:e.id===n,running:o.has(e.id),onSelect:()=>l(e),onOpenInNewTab:s?()=>s(e):void 0},e.id)),0===p.length&&(0,r.jsx)("div",{style:{padding:"22px 12px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:a("agentSwitcher.noMatches")})]})]})})}var so=n(63606),sl=n(8422);async function ss(e,t){let n=await fetch(e,{...t,signal:AbortSignal.timeout(15e3)}),r=await n.json().catch(()=>{throw Error(`Terminal request failed (HTTP ${n.status}): server returned an empty or invalid JSON response. Check the pi-web server log.`)});if(!r||"object"!=typeof r)throw Error(`Terminal request failed (HTTP ${n.status}): invalid JSON response. Check the pi-web server log.`);if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);return r}function sa({tab:e,active:t,onRestart:n,onClosed:o,onCloseError:l}){let{t:s}=(0,x.s)(),{id:a,cwd:d,restored:c}=e,u=(0,i.useRef)(null),h=(0,i.useRef)(null),p=(0,i.useRef)(Promise.resolve()),f=(0,i.useRef)(null),g=(0,i.useRef)({onClosed:o,onCloseError:l});g.current={onClosed:o,onCloseError:l};let[m,y]=(0,i.useState)("connecting"),[v,b]=(0,i.useState)(null),[w,k]=(0,i.useState)(null),[j,S]=(0,i.useState)(0);return(0,i.useEffect)(()=>{var e;let t,n,r,i,o,l=u.current;if(!l)return;let s=!1,g=null,x=!1,m=!1,v=!1;y("connecting"),b(null),k(null);let w=new sl.B({cursorBlink:!0,fontFamily:getComputedStyle(l).getPropertyValue("--font-mono").trim()||"monospace",fontSize:13,lineHeight:1.25,scrollback:8e3,screenReaderMode:!0,disableStdin:!0,theme:{background:"#111318",foreground:"#d7dce5",cursor:"#60a5fa",selectionBackground:"#365b8a",black:"#1d222b",red:"#f87171",green:"#4ade80",yellow:"#facc15",blue:"#60a5fa",magenta:"#c084fc",cyan:"#22d3ee",white:"#e5e7eb",brightBlack:"#6b7280",brightRed:"#fca5a5",brightGreen:"#86efac",brightYellow:"#fde047",brightBlue:"#93c5fd",brightMagenta:"#d8b4fe",brightCyan:"#67e8f9",brightWhite:"#ffffff"}});h.current=w;let S=new so.Y;w.loadAddon(S),w.open(l),w.attachCustomKeyEventHandler(e=>{if("keydown"!==e.type)return!0;let t=e.key.toLowerCase();return!((e.ctrlKey||e.metaKey)&&"v"===t||(e.ctrlKey||e.metaKey)&&"c"===t&&w.hasSelection())});let C=(e=e=>{s||(v=!0,w.options.disableStdin=!0,b(e.message),y("error"))},n=Promise.resolve(),r=!1,i=null,o=t=>{r||(n=n.then(async()=>{r||(t===i&&(i=null),await ss(`/api/terminal/${encodeURIComponent(a)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}))}).catch(t=>{r=!0,e(t)}))},{write(e){if(!r)for(let t of e.match(/[\s\S]{1,32768}/gu)??[])i&&i.data.length+t.length<=65536?i.data+=t:o(i={type:"input",data:t})},resize(e,t){i=null,o({type:"resize",cols:e,rows:t})},stop:()=>(r=!0,i=null,n)});f.current=C;let I=w.onData(e=>{!x||m||v||C.write(e)}),M=()=>{l.offsetWidth&&l.offsetHeight&&S.fit()},T=w.onResize(({cols:e,rows:t})=>{!x||m||v||C.resize(e,t)}),E=new ResizeObserver(M);E.observe(l);let L=()=>{s||m||!navigator.onLine||(g?.close(),(g=new EventSource(`/api/terminal/${encodeURIComponent(a)}/events${void 0===t?"":`?after=${t}`}`)).onmessage=e=>{let n=JSON.parse(e.data);if("output"===n.type){if(n.reset)w.reset();else if(void 0!==t&&n.offset<=t)return;w.write(n.data),t=n.offset}else m=!0,x=!1,w.options.disableStdin=!0,g?.close(),k("exit"===n.type?n.exitCode:null),y("exited")},g.onopen=()=>{x=!0,!v&&(w.options.disableStdin=!1,y("ready"),M(),C.resize(w.cols,w.rows),l.offsetWidth&&l.offsetHeight&&w.focus())},g.onerror=()=>{s||m||(x=!1,w.options.disableStdin=!0,y(g?.readyState===EventSource.CLOSED?"error":"connecting"))})};p.current=(async()=>{M(),c||j>0?await ss(`/api/terminal/${encodeURIComponent(a)}`):await ss("/api/terminal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:a,cwd:d,cols:w.cols,rows:w.rows})}),L()})().catch(e=>{s||(b(e.message),y("error"))});let R=()=>{x=!1,w.options.disableStdin=!0,g?.close(),m||v||y("connecting")},N=e=>{e.persisted&&L()};return window.addEventListener("pagehide",R),window.addEventListener("pageshow",N),window.addEventListener("offline",R),window.addEventListener("online",L),()=>{s=!0,g?.close(),C.stop(),E.disconnect(),I.dispose(),T.dispose(),window.removeEventListener("pagehide",R),window.removeEventListener("pageshow",N),window.removeEventListener("offline",R),window.removeEventListener("online",L),w.dispose(),h.current=null}},[a,d,c,j]),(0,i.useEffect)(()=>{t&&h.current?.focus()},[t]),(0,i.useEffect)(()=>{if(!e.closing)return;let t=!1;return h.current&&(h.current.options.disableStdin=!0),(async()=>{await p.current,await f.current?.stop(),await ss(`/api/terminal/${encodeURIComponent(a)}`,{method:"DELETE",keepalive:!0}),t||g.current.onClosed()})().catch(e=>{t||(b(e.message),y("error"),g.current.onCloseError())}),()=>{t=!0}},[a,e.closing]),(0,r.jsxs)("section",{className:"terminal-panel","aria-label":s("terminal.title"),children:[(0,r.jsxs)("header",{className:"terminal-panel-header",children:[(0,r.jsxs)("div",{className:"terminal-panel-path",children:[(0,r.jsx)("span",{className:`terminal-status-dot is-${m}`,title:s(`terminal.${m}`)}),(0,r.jsx)("span",{title:d,children:d})]}),"error"===m&&(0,r.jsx)("button",{type:"button",onClick:()=>S(e=>e+1),disabled:!!e.closing,title:s("terminal.reconnect"),"aria-label":s("terminal.reconnect"),children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("path",{d:"M10 13a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-2 2M14 11a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l2-2"})})}),(0,r.jsx)("button",{type:"button",onClick:n,disabled:!!e.closing,title:s("terminal.restart"),"aria-label":s("terminal.restart"),children:(0,r.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M20 11a8 8 0 1 0-2.34 5.66"}),(0,r.jsx)("polyline",{points:"20 4 20 11 13 11"})]})})]}),(0,r.jsxs)("div",{children:[v&&(0,r.jsx)("div",{className:"terminal-panel-error",role:"alert",children:v}),"exited"===m&&(0,r.jsx)("div",{className:"terminal-panel-exit",role:"status",children:null===w?s("terminal.exited"):s("terminal.exitCode",{code:w})})]}),(0,r.jsx)("div",{className:"terminal-xterm",children:(0,r.jsx)("div",{ref:u,className:"terminal-xterm-host"})})]})}let sd="pi-web:terminal-tabs";function sc(e){return{id:Array.from(crypto.getRandomValues(new Uint8Array(16)),e=>e.toString(16).padStart(2,"0")).join(""),cwd:e}}function su(e,t,n){let r=Number.isFinite(e)?e:t,i=Math.max(t,n);return Math.round(Math.max(t,Math.min(i,r)))}function sh(e){return{min:Math.max(.2,280/e),max:Math.min(.8,(e-12-280)/e)}}function sp(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function sf(e){let{ariaLabel:t,cssVariable:n,defaultWidth:r,getDefaultWidth:o,getMaxWidth:l,growthDirection:s,maxWidth:a,minWidth:d,storageKey:c,widthRef:u}=e,h=(0,i.useRef)(null),p=(0,i.useRef)(null),f=(0,i.useRef)(!1),[g,x]=(0,i.useState)(r),[m,y]=(0,i.useState)(!1),[v,b]=(0,i.useState)(!1);(0,i.useEffect)(()=>{b(!0)},[]);let w=(0,i.useCallback)(()=>Math.min(a,Math.max(d,l())),[l,a,d]),k=(0,i.useCallback)(e=>su(e,d,w()),[w,d]),j=(0,i.useCallback)(e=>{u.current=e,h.current?.style.setProperty(n,`${e}px`)},[n,u]),S=(0,i.useCallback)((e,t={})=>{let{forcePersist:n=!1,persist:r=!0}=t,i=k(e),o=i!==u.current;return j(i),x(i),r&&(o||n)&&sp(c,i),i},[j,k,c,u]),C=(0,i.useCallback)(e=>{document.body.style.cursor=e.previousCursor,document.body.style.userSelect=e.previousUserSelect},[]),I=(0,i.useCallback)(e=>{let t=p.current;if(t&&t.pointerId===e){p.current=null,C(t),y(!1),S(u.current,{forcePersist:!0});try{t.target.hasPointerCapture(e)&&t.target.releasePointerCapture(e)}catch{}}},[S,C,u]),M=(0,i.useCallback)(e=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),e.stopPropagation();let t=p.current;t&&I(t.pointerId);let n=e.currentTarget;n.focus({preventScroll:!0}),n.setPointerCapture(e.pointerId),p.current={pointerId:e.pointerId,startX:e.clientX,startWidth:u.current,target:n,previousCursor:document.body.style.cursor,previousUserSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none",y(!0)},[I,u]),T=(0,i.useCallback)(e=>{let t=p.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void I(e.pointerId);e.preventDefault();let n="right"===s?1:-1,r=k(t.startWidth+(e.clientX-t.startX)*n);j(r),e.currentTarget.setAttribute("aria-valuenow",String(r)),e.currentTarget.setAttribute("aria-valuetext",`${r} px`)},[j,k,I,s]),E=(0,i.useCallback)(e=>{I(e.pointerId)},[I]),L=(0,i.useCallback)(e=>{I(e.pointerId)},[I]),R=(0,i.useCallback)(e=>{I(e.pointerId)},[I]),N=(0,i.useCallback)(()=>{S(o?.()??r,{forcePersist:!0})},[S,r,o]),$=(0,i.useCallback)(()=>{S(u.current)},[S,u]),W=(0,i.useCallback)(e=>{let t=e.shiftKey?32:12,n="right"===s?"ArrowRight":"ArrowLeft",r="right"===s?"ArrowLeft":"ArrowRight";e.key===n?(e.preventDefault(),S(u.current+t,{forcePersist:!0})):e.key===r?(e.preventDefault(),S(u.current-t,{forcePersist:!0})):"Home"===e.key?(e.preventDefault(),S(d,{forcePersist:!0})):"End"===e.key?(e.preventDefault(),S(w(),{forcePersist:!0})):"Enter"===e.key&&(e.preventDefault(),N())},[S,w,s,d,N,u]);return(0,i.useLayoutEffect)(()=>{if(f.current)return;f.current=!0;let e=h.current,t=e?.style.transition??"";e&&(e.style.transition="none");let n=function(e){try{let t=window.localStorage.getItem(e);if(null===t)return null;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:null}catch{return null}}(c),i=S(n??o?.()??r,{persist:!1});null!==n&&n!==i&&sp(c,i),e&&(e.offsetWidth,e.style.transition=t)},[S,r,o,c]),(0,i.useEffect)(()=>{if(!f.current)return;S(u.current);let e=()=>{S(u.current)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[S,u]),(0,i.useEffect)(()=>{if(!m)return;let e=()=>{let e=p.current;e&&I(e.pointerId)},t=()=>{"visible"!==document.visibilityState&&e()};return window.addEventListener("blur",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("blur",e),document.removeEventListener("visibilitychange",t)}},[I,m]),(0,i.useEffect)(()=>()=>{let e=p.current;e&&(p.current=null,C(e))},[C]),{isResizing:m,panelRef:h,reclampWidth:$,resetWidth:N,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":v?w():a,"aria-valuemin":d,"aria-valuenow":g,"aria-valuetext":`${g} px`,onDoubleClick:N,onKeyDown:W,onLostPointerCapture:R,onPointerCancel:L,onPointerDown:M,onPointerMove:T,onPointerUp:E,role:"separator",tabIndex:0},width:g}}function sg(e,t,n){return t&&n?M(t).replace(/\/$/,"")===M(n).replace(/\/$/,"")||e.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(e)?e:N(t,e):e}let sx="pi-chat-draft-tabs";function sm(e){return`parked-new:${e}`}function sy({size:e=14}){return(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function sv(){let e,t,n,s,a,d,c,u,f,g,m,y,v,b,w,k=(0,o.useRouter)(),j=(0,o.useSearchParams)(),[S]=(0,i.useState)(()=>{let e;return{requestedCwd:e=j.get("cwd")?.trim()||null,sessionId:e?null:j.get("session")}}),{locale:C,t:I}=(0,x.s)(),M=nN();(0,i.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=document.documentElement,n=null,r=()=>{let r;n=null,!function({hasFocusedEditable:e,innerHeight:t,viewportHeight:n,viewportScale:r}){let i=.01>Math.abs(r-1);return e&&i&&t-n>1}({hasFocusedEditable:(r=document.activeElement)instanceof HTMLElement&&(r.isContentEditable||"INPUT"===r.tagName||"SELECT"===r.tagName||"TEXTAREA"===r.tagName),innerHeight:window.innerHeight,viewportHeight:e.height,viewportScale:e.scale})?t.style.removeProperty("--app-viewport-height"):t.style.setProperty("--app-viewport-height",`${e.height}px`);let i=0!==window.scrollX||0!==window.scrollY,o=.01>Math.abs(e.scale-1);i&&o&&window.scrollTo(0,0)},i=()=>{null!==n&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(r)};return i(),e.addEventListener("resize",i),e.addEventListener("scroll",i),window.addEventListener("resize",i),window.addEventListener("focusin",i),window.addEventListener("focusout",i),window.addEventListener("pageshow",i),()=>{e.removeEventListener("resize",i),e.removeEventListener("scroll",i),window.removeEventListener("resize",i),window.removeEventListener("focusin",i),window.removeEventListener("focusout",i),window.removeEventListener("pageshow",i),null!==n&&window.cancelAnimationFrame(n),t.style.removeProperty("--app-viewport-height")}},[]),tC(),(0,i.useEffect)(()=>rC(e=>{"granted"===e&&lK(C)}),[C]);let{soundEnabled:T,onSoundToggle:L,playDoneSound:R,unlockAudio:N,soundEnabledRef:$}=function(){let[e,t]=(0,i.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),n=(0,i.useRef)(e);(0,i.useEffect)(()=>{n.current=e},[e]);let r=(0,i.useRef)(null),o=(0,i.useCallback)(()=>{if(r.current&&"closed"!==r.current.state)return r.current;try{r.current=new AudioContext}catch{return null}return r.current},[]),l=(0,i.useCallback)((e=!1)=>{if(!e&&!n.current)return;let t=o();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[o]);return{soundEnabled:e,onSoundToggle:(0,i.useCallback)(()=>{let e=!n.current;e&&l(!0),n.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[l]),playDoneSound:(0,i.useCallback)(()=>{if(!n.current)return;let e=o();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((n,r)=>{let i=e.createOscillator(),o=e.createGain();i.connect(o),o.connect(e.destination),i.type="sine",i.frequency.value=n;let l=t+.18*r;o.gain.setValueAtTime(0,l),o.gain.linearRampToValueAtTime(.18,l+.02),o.gain.exponentialRampToValueAtTime(.001,l+.45),i.start(l),i.stop(l+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[o]),unlockAudio:l,soundEnabledRef:n}}(),[W,z]=(0,i.useState)(!1);(0,i.useEffect)(()=>{try{z("true"===localStorage.getItem("pi-quote-selection-enabled"))}catch{}},[]);let P=(0,i.useCallback)(e=>{z(e);try{localStorage.setItem("pi-quote-selection-enabled",String(e))}catch{}},[]),A=(0,i.useRef)(new Set),D=(0,i.useCallback)(e=>{if(!$.current)return;let t=new Set(ev.current.filter(e=>"session"===e.kind&&e.session).map(e=>e.session.id));(!e||!(e.length>0)||e.some(e=>!t.has(e)))&&R()},[R,$]),[F,B]=(0,i.useState)(null),[H,O]=(0,i.useState)([]),U=(0,i.useCallback)(e=>{O(e)},[]),_=(0,i.useMemo)(()=>F?[...H.filter(e=>e.id!==F.id),F]:H,[F,H]),K=(0,i.useMemo)(()=>{var e;return(e=F?.id)?l(_).find(t=>t.root.id===e||t.subagents.some(t=>t.id===e))??null:null},[F?.id,_]),V=!!K?.subagents.length,[J,Y]=(0,i.useState)(()=>new Set),Z=(0,i.useCallback)(e=>{Y(t=>t.size===e.size&&[...e].every(e=>t.has(e))?t:e)},[]),[G,X]=(0,i.useState)(null),[ee,et]=(0,i.useState)("initial"),en=(0,i.useRef)(null),[er,ei]=(0,i.useState)(()=>S.requestedCwd?"validating":"idle"),[eo,el]=(0,i.useState)(null),[es,ea]=(0,i.useState)(0),[ed,ec]=(0,i.useState)(0),eu=(0,i.useRef)(new Map),eh=(0,i.useCallback)((e,t)=>{eu.current.set(e,t)},[]),[ep,ef]=(0,i.useState)([]),[eg,ex]=(0,i.useState)(!1),[em,ey]=(0,i.useState)(!1),ev=(0,i.useRef)([]);ev.current=ep;let[eb,ew]=(0,i.useState)(null),ek=(0,i.useRef)(null);ek.current=eb;let[ej,eS]=(0,i.useState)(null),eC=(0,i.useRef)(null);eC.current=ej;let[eI,eM]=(0,i.useState)("primary"),eT=(0,i.useRef)("primary");eT.current=eI;let eE=(0,i.useRef)(!1),[eL,eR]=(0,i.useState)(.5),eN=(0,i.useRef)(null),e$=(0,i.useRef)(!1),[eW,ez]=(0,i.useState)(600);e=(0,i.useMemo)(()=>0===ep.length?F?.id?[F.id]:[]:ep.flatMap(e=>"session"===e.kind&&e.session?[e.session.id]:[]),[ep,F?.id]).join(","),(0,i.useEffect)(()=>{if(!e)return;let t=e.split(","),n=!1,r=()=>{if(!n)for(let e of t)fetch(`/api/agent/${encodeURIComponent(e)}/lease`,{method:"POST",cache:"no-store"}).catch(()=>{})};r();let i=setInterval(r,3e4),o=()=>{"visible"===document.visibilityState&&r()};return document.addEventListener("visibilitychange",o),()=>{n=!0,clearInterval(i),document.removeEventListener("visibilitychange",o)}},[e]);let eP=(0,i.useCallback)((e,t,n)=>{let r=!!(t.trim()||n>0),i=ik(t,I("i18n.newSession"));ef(t=>{let n=!1,o=t.map(t=>"draft"!==t.kind||t.newSessionDraftKey!==e||t.dirty===r&&t.title===i?t:(n=!0,{...t,dirty:r,title:i}));return n?o:t})},[I]);(0,i.useEffect)(()=>{try{let e=window.sessionStorage.getItem(sx),t=(e?JSON.parse(e):[]).flatMap(e=>{if("string"!=typeof e?.draftKey||"string"!=typeof e?.title)return[];let t=nm(e.draftKey);return t?[{id:`draft:${e.draftKey}`,kind:"draft",title:ik(t.value,e.title),session:null,newSessionCwd:"string"==typeof e.cwd?e.cwd:null,newSessionDraftKey:e.draftKey,projectKey:"string"==typeof e.cwd?e.cwd:null,dirty:!0}]:[]});if(t.length>0&&(ef(e=>[...e,...t.filter(t=>!e.some(e=>e.id===t.id))]),!S.sessionId&&!S.requestedCwd)){let e=t[0];ew(t=>t??e.id),B(null),X(e.newSessionCwd),en.current=e.newSessionDraftKey}}catch{}ex(!0)},[S.requestedCwd,S.sessionId]),(0,i.useEffect)(()=>{if(!eg)return;let e=ep.flatMap(e=>"draft"===e.kind&&e.dirty&&e.newSessionDraftKey?[{draftKey:e.newSessionDraftKey,cwd:e.newSessionCwd,title:e.title}]:[]);if(0===e.length){try{window.sessionStorage.removeItem(sx)}catch{}ey(!1);return}try{window.sessionStorage.setItem(sx,JSON.stringify(e)),ey(!1)}catch{ey(!0)}},[ep,eg]);let[eA,eD]=(0,i.useState)(null),eF=(0,i.useCallback)(e=>{eD(t=>t===e?null:t)},[]),[eB,eH]=(0,i.useState)(0),[eO,eU]=(0,i.useState)(null),[e_,eq]=(0,i.useState)(0),[eK,eV]=(0,i.useState)(null),[eJ,eY]=(0,i.useState)(!1),[eZ,eG]=(0,i.useState)(!1),[eX,eQ]=(0,i.useState)(null),[e0,e1]=(0,i.useState)(!0),[e2,e4]=(0,i.useState)(!1),[e8,e5]=(0,i.useState)(!1),[e6,e3]=(0,i.useState)(!1),e7=(0,i.useRef)(260),e9=(0,i.useRef)(560),te=(0,i.useCallback)(()=>su(.42*window.innerWidth,360,640),[]),tt=(0,i.useCallback)(()=>(function(e){let{viewportWidth:t,rightPanelOpen:n,rightPanelWidth:r}=e;if(t<=640)return 480;let i=t<960;return Math.min(480,t-(i?320:420)-(!i&&n?r:0))})({viewportWidth:window.innerWidth,rightPanelOpen:e2,rightPanelWidth:e9.current}),[e2]),tn=(0,i.useCallback)(()=>(function(e){let{viewportWidth:t,sidebarOpen:n,sidebarWidth:r}=e;return t<960?1200:Math.min(1200,t-420-(n?r:0))})({viewportWidth:window.innerWidth,sidebarOpen:e0,sidebarWidth:e7.current}),[e0]),tr=sf({ariaLabel:I("layout.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:tt,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:e7}),ti=sf({ariaLabel:I("layout.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:560,getDefaultWidth:te,getMaxWidth:tn,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:e9}),to=tr.reclampWidth,tl=ti.reclampWidth;(0,i.useEffect)(()=>{M&&e1(!1)},[M]),(0,i.useEffect)(()=>{e3(!0)},[]),(0,i.useEffect)(()=>{e2&&(to(),tl())},[tl,to,e2]),(0,i.useEffect)(()=>{if(!e2)return void e5(!1);let e=ti.panelRef.current,t=!1,n=()=>{t||(t=!0,e5(!0))};if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return void n();let r=t=>{t.target===e&&("width"===t.propertyName||"min-width"===t.propertyName||"transform"===t.propertyName)&&n()};e?.addEventListener("transitionend",r);let i=window.setTimeout(n,280);return()=>{e?.removeEventListener("transitionend",r),window.clearTimeout(i)}},[e2,ti.panelRef]);let ts=(0,i.useRef)(null),[ta,td]=(0,i.useState)(null),tc=(0,i.useCallback)(e=>{td(t=>t?.sessionId===e?null:t)},[]),tu=(0,i.useRef)(null),[th,tp]=(0,i.useState)([]),[tf,tg]=(0,i.useState)(null),[tx,tm]=(0,i.useState)(!1),[ty,tv]=(0,i.useState)(!1),[tb,tw]=(0,i.useState)(null),tk=(0,i.useRef)(null),tj=l0(th),tS=(0,i.useRef)(new Map),tM=(0,i.useRef)(new Map),tT=(0,i.useRef)(new Map),tE=(0,i.useCallback)((e,t,n)=>{tZ.current&&tT.current.set(tZ.current,{tree:e,activeLeafId:t}),tp(e),tg(t),tk.current=n},[]),tL=(0,i.useCallback)(e=>{tk.current?.(e)},[]),[tR,tN]=(0,i.useState)(null),[t$,tW]=(0,i.useState)(null),[tz,tP]=(0,i.useState)(!1),tA=(0,i.useRef)(null),tD=(0,i.useRef)(0),tF=(0,i.useRef)(null),tB=(0,i.useRef)(null),tH=(0,i.useRef)(null),tO=(0,i.useRef)(null),tU=(0,i.useRef)(null),t_=(0,i.useRef)(null),tq=(0,i.useCallback)(e=>{tN(e),tP(!1)},[]),tK=(0,i.useCallback)(e=>{tW(e)},[]),tV=(0,i.useCallback)(e=>{tD.current+=1,tA.current=e,tP(!1)},[]),[tJ,tY]=(0,i.useState)(null),tZ=(0,i.useRef)(F?.id??null);tZ.current=F?.id??null;let tG=(0,i.useCallback)(e=>{null!==e&&(e.sessionId&&tS.current.set(e.sessionId,e),tY(e))},[]),[tX,tQ]=(0,i.useState)(null),t0=(0,i.useRef)(null),t1=(0,i.useCallback)((e,t)=>{tI(t).then(()=>{t0.current&&clearTimeout(t0.current),tQ(e),t0.current=setTimeout(()=>tQ(null),1400)})},[]);(0,i.useEffect)(()=>()=>{t0.current&&clearTimeout(t0.current)},[]);let[t2,t4]=(0,i.useState)(null),t8=(0,i.useCallback)(e=>{null!==e&&(tZ.current&&tM.current.set(tZ.current,e),t4(e))},[]),t5=(0,i.useCallback)(e=>{tY(tS.current.get(e)??null),t4(tM.current.get(e)??null);let t=tT.current.get(e);tp(t?.tree??[]),tg(t?.activeLeafId??null)},[]);(0,i.useEffect)(()=>{if(!F){tY(null),t4(null);return}t5(F.id)},[F,t5]);let[t6,t3]=(0,i.useState)(null),[t7,t9]=(0,i.useState)(null),ne=(0,i.useCallback)((e=!1)=>{t3(null),e&&t6&&requestAnimationFrame(()=>{let e=document.querySelector(`[data-top-panel-trigger="${t6}"]`)??tB.current;e?.focus()})},[t6]);(0,i.useEffect)(()=>{tj||t3(e=>"branches"===e?null:e)},[tj]),(0,i.useEffect)(()=>{V||t3(e=>"agents"===e?null:e)},[V]);let nt=(0,i.useCallback)(e=>{M&&e1(!1),t3(t=>t===e?null:e)},[M]),nn=(0,i.useCallback)(e=>{let t=t6!==e;if(nt(e),!t||tz)return;let n=tA.current;if(!n)return;let r=++tD.current;tP(!0),n().catch(e=>{console.error("Failed to load system information:",e)}).finally(()=>{tD.current===r&&tP(!1)})},[t6,tz,nt]),nr=(0,i.useCallback)(()=>{M&&e1(!1),t3(e=>"session"===e?null:"session")},[M]),ni=(0,i.useCallback)(()=>{M&&t3(null),e1(e=>!e)},[M]),no=(0,i.useCallback)(()=>{e1(!1),requestAnimationFrame(()=>tB.current?.focus())},[]);(0,i.useEffect)(()=>{if(!M||!e0||!e6)return;let e=requestAnimationFrame(()=>{let e=tr.panelRef.current;e?.querySelector('[aria-current="page"], button:not(:disabled)')?.focus()}),t=e=>{"Escape"===e.key&&(e.preventDefault(),no())};return document.addEventListener("keydown",t),()=>{cancelAnimationFrame(e),document.removeEventListener("keydown",t)}},[no,M,e6,e0,tr.panelRef]);let nl=(0,i.useCallback)(()=>{M&&(e1(!1),t3(null)),e4(e=>!e)},[M]),ns=(0,i.useCallback)((e=!1)=>{e4(!1),e&&requestAnimationFrame(()=>tH.current?.focus())},[]);(0,i.useEffect)(()=>{if(!e2)return;let e=requestAnimationFrame(()=>{(M||!(window.innerWidth>=960))&&ti.panelRef.current?.querySelector('[role="tab"][aria-selected="true"]')?.focus()}),t=e=>{"Escape"===e.key&&(M||!(window.innerWidth>=960))&&(e.preventDefault(),e.stopPropagation(),ns(!0))};return document.addEventListener("keydown",t,!0),()=>{cancelAnimationFrame(e),document.removeEventListener("keydown",t,!0)}},[ns,M,e2,ti.panelRef]),(0,i.useEffect)(()=>{tm(!1),tw(null)},[M,F?.id,ee]),(0,i.useEffect)(()=>{t6&&tm(!1)},[t6]),(0,i.useEffect)(()=>{if(!t6||!tu.current)return;let e=()=>{let e=tu.current.getBoundingClientRect();if("agents"===t6){let t=tU.current??tO.current,n=Math.min(420,window.innerWidth-16);if(t){let e=t.getBoundingClientRect(),r=Math.max(8,Math.min(e.right-n,window.innerWidth-n-8));t9({top:e.bottom+4,left:r,width:n});return}let r=Math.max(8,Math.min(e.right-n-8,window.innerWidth-n-8));t9({top:e.bottom+4,left:r,width:n});return}t9({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(tu.current),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("resize",e)}},[t6,M]),(0,i.useEffect)(()=>{if(!t6||"branches"===t6||"language"===t6)return;let e=e=>{let t=e.target;!t||t_.current?.contains(t)||t instanceof Element&&t.closest(`[data-top-panel-trigger="${t6}"]`)||ne()},t=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),ne(!0))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[t6,ne]);let[na,nd]=(0,i.useState)([]),[nc,nu]=(0,i.useState)(null),[nh,np]=(0,i.useState)([]),[nf,ng]=(0,i.useState)(!1),nx=(0,i.useMemo)(()=>[...na,...nh.map(e=>({id:e.id,label:E(e.cwd)||e.cwd,filePath:e.cwd,kind:"terminal",closing:!!e.closing}))],[na,nh]);(0,i.useEffect)(()=>{try{let e=function(e){try{let t=JSON.parse(e??"null"),n=[];for(let e of Array.isArray(t?.tabs)?t.tabs:[])e&&"string"==typeof e.id&&/^[a-f0-9]{32}$/.test(e.id)&&"string"==typeof e.cwd&&e.cwd.trim()&&!n.some(t=>t.id===e.id||t.cwd===e.cwd)&&n.push({id:e.id,cwd:e.cwd,restored:!0});return{tabs:n,activeId:n.some(e=>e.id===t.activeId)?t.activeId:null,open:t?.open===!0}}catch{return{tabs:[],activeId:null,open:!1}}}(window.sessionStorage.getItem(sd));np(e.tabs),e.activeId&&(nu(e.activeId),e4(e.open))}catch{}ng(!0)},[]),(0,i.useEffect)(()=>{if(nf)try{window.sessionStorage.setItem(sd,JSON.stringify({tabs:nh.map(({id:e,cwd:t})=>({id:e,cwd:t})),activeId:nc,open:e2}))}catch{}},[nh,nc,e2,nf]);let ny=(0,i.useCallback)((e,t,n)=>{nd(r=>(function(e,t,n,r){let i=e.findIndex(e=>e.id===t);if(-1===i||(e[i].viewerRevision??0)!==n)return e;let o=[...e];return o[i]={...o[i],viewerState:r},o})(r,e,t,n))},[]),[nb,nw]=(0,i.useState)(null),nk=(0,i.useCallback)(()=>{let e=eE.current&&"secondary"===eT.current?eC.current:ek.current,t=ev.current.find(t=>t.id===e);return t?.kind==="session"?t.session?.cwd??null:t?.kind==="draft"?t.newSessionCwd:F?.cwd??G??nb},[nb,G,F?.cwd]),nS=(0,i.useCallback)((e,t,n)=>{let r=sg(e,n,nk());ts.current?.insertText(nM(r,t)),M&&(e4(!1),e1(!1))},[nk,M]),nC=(0,i.useCallback)((e,t)=>{let n=nk(),r=e.map(e=>sg(e,t,n)).map(e=>nM(e,!1)).join("");r&&ts.current?.insertText(r),M&&(e4(!1),e1(!1))},[nk,M]),nI=(0,i.useCallback)((e,t,n,r)=>{let i,o,l,s,a=sg(e,r,nk());ts.current?.insertText((i=Math.max(1,Math.min(t,n)),o=Math.max(1,Math.max(t,n)),l=a.includes(" ")?`@"${a}"`:`@${a}`,s=i===o?`:${i}`:`:${i}-${o}`,`${l}${s} `)),M&&(e4(!1),e1(!1))},[nk,M]),nT=S.sessionId,nE=(0,i.useRef)(null),nL=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=S.requestedCwd;if(!e)return;let t=new AbortController;return ei("validating"),el(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async t=>{let n=await t.json().catch(()=>({}));if(!t.ok||!n.cwd)throw Error(n.error??`HTTP ${t.status}`);nL.current=!0;let r=`initial:${e}`;et(r),en.current=`new:${r}:${n.cwd}`,X(n.cwd),ei("ready")}).catch(e=>{t.signal.aborted||(el(e instanceof Error?e.message:String(e)),ei("error"))}),()=>t.abort()},[S]);let nR=(0,i.useCallback)((e,t,n)=>{let r=G??nb;if(nw(e),!e)return;let i=n??t??e,o=nE.current??(F?p(F):null);if(nE.current=i,nL.current){nL.current=!1;return}if(r===e&&o!==i||void 0!==ev&&ev.current?.length>0||o===i&&(null!==F||r===e))return;let l=en.current;l&&r&&nj(l,sm(r));let s="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,a=`new:${s}:${e}`;nj(sm(e),a),et(s),en.current=a,B(null),X(t=>t&&t!==e?null:t),ec(e=>e+1),tp([]),tg(null),tN(null),tW(null),tP(!1),t3(null),o!==i&&(nd([]),(!nc||nc.startsWith("file:"))&&(nu(null),e4(!1))),k.replace(window.location.pathname,{scroll:!1})},[nb,nc,G,k,F]),n$=(0,i.useCallback)((e,t=!1,n,r,i=!1,o=!1)=>{var l,s;let a,d;eD(n?{sessionId:e.id,entryId:n,blockIndex:r}:null);let c=en.current,u=G??(null===F?nb:null);c&&u&&!ev.current.some(e=>e.id===`draft:${c}`)&&nj(c,sm(u)),en.current=null;let f=F?.projectKey??(F?null:nE.current);if(f&&e.projectKey&&f!==e.projectKey&&(nd([]),(!nc||nc.startsWith("file:"))&&(nu(null),e4(!1)),t3(null)),e.projectKey&&(nE.current=e.projectKey),!t&&F){let t=p(F)===p(e);if(F.id===e.id&&t){i&&ef(t=>iI(t,e.id)),M&&e1(!1);return}}X(null),"function"==typeof t5&&t5(e.id),B(e);let g=eE.current?eT.current:"primary",x=(l=ev.current,s=e.id,"secondary"===(d=(a=l.find(e=>e.id===s))?ij(a):g)?{splitChatTabId:s,pane:d}:{activeChatTabId:s,pane:d});ef(n=>!o||t||i?(t||i?iT(n,e,g):iC(n,e,g)).tabs:function(e,t,n,r="primary"){let i=e.findIndex(e=>e.id===n.id),o=h(n);if(i>=0){let t=[...e];return t[i]={...t[i],session:n,title:o,projectKey:n.projectKey??n.cwd},{tabs:t,tabId:n.id}}let l=t?e.findIndex(e=>e.id===t):-1,s=l>=0?e[l]:void 0;if(!s||"session"!==s.kind)return iC(e,n,r);let a=[...e];return a[l]={...s,id:n.id,title:o,session:n,newSessionCwd:null,newSessionDraftKey:null,projectKey:n.projectKey??n.cwd,mountKey:void 0},{tabs:a,tabId:n.id}}(n,"secondary"===g?eC.current:ek.current,e,g).tabs),void 0!==x.activeChatTabId&&ew(x.activeChatTabId),void 0!==x.splitChatTabId&&eS(x.splitChatTabId),eM(x.pane),ec(e=>e+1),tp([]),tg(null),tk.current=null,tN(null),tW(null),tP(!1),M&&!t&&e1(!1),t&&(nL.current=!0),t||k.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[nb,nc,k,M,G,F,t5]),nW=(0,i.useCallback)((e,t)=>{let n=`new:${e}:${t}`;nj(sm(t),n),en.current=n,et(e),B(null),X(t);{let e=eE.current&&"secondary"===eT.current,r=`draft:${n}`;ef(r=>iE(r,t,n,I("i18n.newSession"),e?"secondary":"primary").tabs),e?eS(r):ew(r)}ec(e=>e+1),tp([]),tg(null),tN(null),tW(null),tP(!1),t3(null),M&&e1(!1),k.replace(window.location.pathname,{scroll:!1})},[k,M,I]),nz=(0,i.useCallback)(e=>{fetch("/api/sessions",{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>{let n=t?.sessions.find(t=>t.id===e);n&&(B(t=>t?.id===e?{...t,...n,transient:n.transient??!1}:t),ef(t=>t.map(t=>t.id===e&&"session"===t.kind?{...t,title:h(n),session:{...t.session,...n}}:t)))}).catch(()=>{})},[]),nP=(0,i.useCallback)(e=>{n$(e,!1,void 0,void 0,!0)},[n$]),nA=(0,i.useCallback)(e=>{n$(e,!1,void 0,void 0,!1,!0)},[n$]),nD=(0,i.useCallback)(async e=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}`,{cache:"no-store"}),n=await t.json();if(!t.ok||!n.info)throw Error(n.error??`HTTP ${t.status}`);nP(n.info)}catch(e){console.error("[pi-web] failed to open session:",e instanceof Error?e.message:e)}},[nP]),nF=(0,i.useCallback)((e,t)=>{ea(e=>e+1),ef(n=>{var r;let i,{tabs:o,newTabId:l}=(r=`draft:${t}`,i=h(e),{tabs:n.map(t=>t.id===r?{...t,id:e.id,kind:"session",title:i,session:e,newSessionCwd:null,newSessionDraftKey:null,projectKey:e.projectKey??e.cwd,mountKey:t.mountKey??t.id}:t),newTabId:e.id});return ew(e=>e===`draft:${t}`?l:e),eS(e=>e===`draft:${t}`?l:e),o}),en.current===t&&(en.current=null,X(null),B(e),nz(e.id),k.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1}))},[k,nz]),nB=(0,i.useCallback)(({targetSession:e,title:t,body:n,tag:r})=>{"Notification"in window&&"granted"===Notification.permission&&rM({title:t,body:n,sessionUrl:e?`/?session=${encodeURIComponent(e.id)}`:"/",tag:r,onClick:()=>{window.focus(),e&&nP(e)}})},[nP]),nH=(0,i.useCallback)((e,t)=>{ea(e=>e+1),B(n=>n?.id===e?{...n,name:t}:n),ef(n=>n.map(n=>n.id===e&&"session"===n.kind?{...n,title:t,session:n.session?{...n.session,name:t}:n.session}:n)),tY(n=>n?.sessionId===e?{...n,sessionName:t}:n)},[]),nO=(0,i.useRef)(void 0),nU=(0,i.useRef)(new Set),n_=(0,i.useCallback)(e=>{ea(e=>e+1),eH(e=>e+1),F&&nz(F.id);let t=e??F;if(ov()&&t&&t.id&&!t.name&&t.relation?.kind!=="subagent"&&!nU.current.has(t.id)){let e=t.id;setTimeout(()=>{nO.current?.({sessionId:e})},350)}t?.relation?.kind==="subagent"||rS()&&nB({targetSession:t,title:t?.name??I("i18n.sessionComplete"),body:I("i18n.taskFinished"),tag:t?`pi-session-complete:${t.id}`:"pi-session-complete"})},[nB,nz,F,I]),nq=(0,i.useCallback)((e,t)=>{var n;t?.relation?.kind!=="subagent"&&rS()&&(n=A.current,!(!rI(e)||n.has(e.id))&&(n.add(e.id),1)&&nB({targetSession:t,title:I("i18n.attentionNeeded"),body:"custom"===e.method?I("i18n.extensionInputNeeded"):e.title,tag:`pi-extension-ui:${e.id}`}))},[nB,I]);nO.current=(0,i.useCallback)(async e=>{let t=e?.sessionId;if(t&&!nU.current.has(t)){nU.current.add(t);try{let e=await fetch(`/api/sessions/${encodeURIComponent(t)}/auto-name`,{method:"POST"}),n=await e.json().catch(()=>({}));if(!e.ok||!n.title)throw Error(n.error||`HTTP ${e.status}`);nH(t,n.title.trim())}catch(e){console.warn("[pi-web] silent auto-name failed:",e instanceof Error?e.message:e)}finally{nU.current.delete(t)}}},[nH]);let nK=(0,i.useCallback)(()=>{eH(e=>e+1)},[]),nV=(0,i.useCallback)((e,t)=>{let n=ev.current.find(e=>e.id===(t??F?.id)),r=t?n?.session:F,i=eE.current&&n?ij(n):"primary",o={...r??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e,transient:!1},l=!t||tZ.current===t;ea(e=>e+1),ef(e=>iT(e,o,i).tabs),nz(e),l&&(en.current=null,ec(e=>e+1),X(null),B(o),"secondary"===i?eS(e):ew(e),eM(i),k.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1}))},[nz,k,F]),nY=(0,i.useCallback)(async(e,t,n)=>{ef(e=>iI(e,t));let r=await rN(t,{type:"fork_branch",entryId:n});if(!r?.newSessionId)throw Error(I("chat.quoteForkFailed"));td({sessionId:r.newSessionId,text:e}),nV(r.newSessionId,t)},[nV,I]),nZ=(0,i.useCallback)(e=>{ea(e=>e+1),ef(t=>{if(!t.some(t=>t.id===e))return t;let{tabs:n,nextActiveTabId:r,nextSplitTabId:i}=iL(t,e,ek.current??"",eC.current);if(0===n.length){let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,t=nb?`new:${e}:${nb}`:`draft:${e}`,n=iE([],nb??null,t,I("i18n.newSession"));return ew(n.tabId),eS(null),eM("primary"),B(null),X(nb??null),k.replace(window.location.pathname,{scroll:!1}),n.tabs}ew(r),eS(i),i||"secondary"!==eT.current||eM("primary");let o="secondary"===eT.current&&i?i:r,l=n.find(e=>e.id===o);return l?.kind==="session"&&l.session?(B(l.session),X(null),k.replace(`?session=${encodeURIComponent(l.session.id)}`,{scroll:!1})):l?.kind==="draft"&&(B(null),X(l.newSessionCwd),k.replace(window.location.pathname,{scroll:!1})),n}),tZ.current===e&&(tp([]),tg(null),tN(null),tW(null),tP(!1),t3(null))},[nb,k,I]),nG=(0,i.useCallback)(e=>{let t=eN.current;if(!t)return;let n=t.getBoundingClientRect();if(n.width<=0)return;let r=sh(n.width);eR(Math.max(r.min,Math.min(r.max,(e-n.left)/n.width)))},[]),nX=(0,i.useCallback)(e=>{e.preventDefault(),e$.current=!0,e.currentTarget.setPointerCapture(e.pointerId),nG(e.clientX)},[nG]),nQ=(0,i.useCallback)(e=>{e$.current&&nG(e.clientX)},[nG]),n0=(0,i.useCallback)(()=>{e$.current=!1},[]),n1=(0,i.useCallback)(e=>{let t=sh(eW);if("ArrowLeft"===e.key||"ArrowRight"===e.key){e.preventDefault();let n="ArrowLeft"===e.key?-1:1;eR(e=>Math.max(t.min,Math.min(t.max,e+.05*n)))}else("Home"===e.key||"End"===e.key)&&(e.preventDefault(),eR("Home"===e.key?t.min:t.max))},[eW]),n2=(0,i.useMemo)(()=>iS(ep,"primary"),[ep]),n4=(0,i.useMemo)(()=>iS(ep,"secondary"),[ep]),n8=(0,i.useMemo)(()=>n2.find(e=>e.id===eb)??n2[0]??null,[n2,eb]),n5=(0,i.useMemo)(()=>ej?ep.find(e=>e.id===ej)??null:null,[ep,ej]),n6=!M&&eW>=600,n3=!!(n6&&ej&&n5&&eb!==ej);eE.current=n3;let n7=!n3||"primary"===eI,n9=(0,i.useCallback)((e,t)=>{if(eM(t),"session"===e.kind&&e.session){en.current=null,tZ.current!==e.session.id&&(tk.current=null,t5(e.session.id),tN(null),tW(null),tP(!1),t3(null)),B(e.session),X(null),k.replace(`?session=${encodeURIComponent(e.session.id)}`,{scroll:!1});return}en.current=e.newSessionDraftKey,B(null),X(e.newSessionCwd),tY(null),t4(null),tp([]),tg(null),tk.current=null,tN(null),tW(null),tP(!1),t3(null),k.replace(window.location.pathname,{scroll:!1})},[k,t5]),re=(0,i.useCallback)(e=>{let t="secondary"===e?n5:n8;t&&n9(t,e)},[n9,n8,n5]);(0,i.useLayoutEffect)(()=>{let e=eN.current;if(!e)return;let t=e=>{if(ez(e),e<600)return;let t=sh(e);eR(e=>Math.max(t.min,Math.min(t.max,e)))};t(e.getBoundingClientRect().width);let n=new ResizeObserver(([e])=>t(e.contentRect.width));return n.observe(e),()=>n.disconnect()},[]),(0,i.useEffect)(()=>{if(!ej||n6)return;let e="secondary"===eI?n5:n8;(ef(t=>iM(t,e?.id??null)),eS(null),e)?(ew(e.id),n9(e,"primary")):eM("primary")},[eI,n6,n9,n8,n5,ej]);let rt=(0,i.useCallback)(e=>{let t=ep.find(t=>t.id===e);t&&(ew(e),n9(t,"primary"))},[ep,n9]),rn=(0,i.useCallback)(e=>{let t=ep.find(t=>t.id===e);t&&(eS(e),n9(t,"secondary"))},[ep,n9]),rr=(0,i.useCallback)(e=>{let t=ep.find(t=>t.id===e);if(!t)return;let n=n3?ij(t):"primary";"secondary"===n?eS(e):ew(e),n9(t,n)},[ep,n9,n3]),ri=(0,i.useCallback)(e=>{let t=ev.current.find(t=>t.id===e);if(t?.kind==="draft"&&t.newSessionDraftKey){let e=nm(t.newSessionDraftKey);if((t.dirty||e&&(e.value.trim()||e.images.length>0))&&!window.confirm(I("chatTabs.discardDraft")))return!1;nv(t.newSessionDraftKey)}return ef(t=>{let{tabs:n,nextActiveTabId:r,nextSplitTabId:i}=iL(t,e,eb??"",ej);if(0===n.length){let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,t=`new:${e}:${nb??""}`;nj(sm(nb??""),t),en.current=t,et(e);let n=iE([],nb,t,I("i18n.newSession"));return ew(n.tabId),eS(null),eM("primary"),B(null),X(nb),k.replace(window.location.pathname,{scroll:!1}),n.tabs}ew(r),eS(i),i||"secondary"!==eI||eM("primary");let o="secondary"===eI&&i?i:r,l=n.find(e=>e.id===o)??n.find(e=>e.id===r);return l?.kind==="session"&&l.session?(B(l.session),X(null),k.replace(`?session=${encodeURIComponent(l.session.id)}`,{scroll:!1})):l?.kind==="draft"&&(B(null),X(l.newSessionCwd),k.replace(window.location.pathname,{scroll:!1})),n}),!0},[eI,eb,nb,k,ej,I]),ro=(0,i.useCallback)(e=>{var t;let n=n3&&("secondary"===e||"primary"!==e&&"secondary"===eI),r=((t=n?n5:n8)?"session"===t.kind?t.session?.cwd??null:t.newSessionCwd:null)??nb,i="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,o=`new:${i}:${r??""}`;nj(sm(r??""),o),en.current=o,et(i);let{tabs:l,tabId:s}=iE(ep,r,o,I("i18n.newSession"),n?"secondary":"primary");ef(l),n?(eS(s),eM("secondary")):(ew(s),eM("primary")),B(null),X(r),k.replace(window.location.pathname,{scroll:!1})},[eI,nb,ep,n3,n8,k,n5,I]),rl=(0,i.useCallback)(async(e,t)=>{let n=await fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t})}),r=await n.json();if(!n.ok||!r.cwd)throw Error(r.error??`HTTP ${n.status}`);let i=r.cwd;e&&ef(t=>t.map(t=>"draft"===t.kind&&t.newSessionDraftKey===e?{...t,newSessionCwd:i,projectKey:i}:t)),e&&en.current!==e||X(i)},[]),rs=(0,i.useCallback)(()=>{if(ej){let e="secondary"===eI?n5:n8;ef(t=>iM(t,e?.id??null)),eS(null),eM("primary"),e&&(ew(e.id),n9(e,"primary"))}else if(n6){let e=ep.findIndex(e=>e.id===eb),t=ep[e+1]??ep[e-1];if(t)ef(e=>e.map(e=>e.id===t.id?{...e,pane:"secondary"}:e)),eS(t.id),eM("secondary"),"session"===t.kind&&t.session?(B(t.session),X(null),k.replace(`?session=${encodeURIComponent(t.session.id)}`,{scroll:!1})):"draft"===t.kind&&(B(null),X(t.newSessionCwd),k.replace(window.location.pathname,{scroll:!1}));else{let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,t=`new:${e}:${nb??""}`;nj(sm(nb??""),t),en.current=t,et(e);let{tabs:n,tabId:r}=iE(ep,nb,t,I("i18n.newSession"),"secondary");ef(n),eS(r),eM("secondary"),B(null),X(nb),k.replace(window.location.pathname,{scroll:!1})}}},[eI,eb,nb,n6,ep,n9,n8,k,n5,ej,I]),ra=(0,i.useCallback)((e,t,n)=>{let r=n?.sourceSessionId,i=n?.modeHint,o=`file:${e}`;nd(l=>(function(e,t){let n=e.find(e=>e.id===t.tabId);if(!n)return[...e,{id:t.tabId,label:t.fileName,filePath:t.filePath,cwd:t.cwd,sourceSessionId:t.sourceSessionId,initialDisplayMode:t.modeHint,viewerState:t.modeHint?{displayMode:t.modeHint,wrapLines:!1,scrollTop:0,scrollLeft:0}:void 0,viewerRevision:0}];let r=!!(t.sourceSessionId&&n.sourceSessionId!==t.sourceSessionId),i=!!(t.cwd&&n.cwd!==t.cwd);return r||i||t.modeHint?e.map(e=>{if(e.id!==t.tabId)return e;let n={...e};return r&&(n.sourceSessionId=t.sourceSessionId),i&&(n.cwd=t.cwd),t.modeHint?(n.initialDisplayMode=t.modeHint,n.viewerState={displayMode:t.modeHint,wrapLines:e.viewerState?.wrapLines??!1,scrollTop:0,scrollLeft:0,loadedBytes:e.viewerState?.loadedBytes,scrollByMode:{...e.viewerState?.scrollByMode,diff:{scrollTop:0,scrollLeft:0}}},n.viewerRevision=(e.viewerRevision??0)+1):(r||i)&&(n.viewerRevision=(e.viewerRevision??0)+1),n}):e})(l,{fileName:t,filePath:e,cwd:n?.cwd??nb??void 0,modeHint:i,sourceSessionId:r,tabId:o})),nu(o),e4(!0),M&&e1(!1)},[nb,M]),rd=(0,i.useCallback)((e,t)=>{let n=t?ev.current.find(e=>e.id===t)?.session?.cwd:void 0;ra(e,E(e),{sourceSessionId:t,cwd:n})},[ra]),rc=(0,i.useCallback)(e=>{let t=nh.find(t=>t.cwd===e),n=t??sc(e);t||np(e=>[...e,n]),nu(n.id),e4(!0),M&&e1(!1)},[nh,M]),ru=(0,i.useCallback)(e=>{if(nh.some(t=>t.id===e))return void np(t=>t.map(t=>t.id!==e||t.closing?t:{...t,closing:"close"}));let t=oa(nx,e);nd(t=>{let n=t.filter(t=>t.id!==e);return 0===n.length&&0===nh.length&&e4(!1),n}),nu(n=>n!==e?n:t)},[nx,nh]),rh=(0,i.useCallback)(()=>{F&&window.open(`/api/sessions/${encodeURIComponent(F.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[F]);(0,i.useEffect)(()=>{if(F)ef(e=>e.some(e=>e.id===F.id)?e:iT(e,F).tabs),ew(e=>e??F.id);else if(G){let e=en.current??ee;ef(t=>{let n=`draft:${e}`;return t.some(e=>e.id===n)?t:iE(t,G,e,I("i18n.newSession")).tabs}),ew(e=>e??`draft:${en.current??ee}`)}},[G,ee,F,I]);let rp=(0,i.useCallback)(e=>{ef(t=>iI(t,e))},[]),rf=(e,t,n,i,o,l)=>{let s=e?J.has(e.id):!!(F&&J.has(F.id));return(0,r.jsx)(ix,{session:e,searchTarget:i&&eA?.sessionId===e?.id?eA:null,onSearchTargetHandled:eF,initialScrollPosition:e?eu.current.get(e.id)??null:null,onScrollPositionChange:eh,sessionRunning:s,newSessionCwd:t,newSessionDraftKey:n,onDraftChange:eP,onKeepTabOpen:rp,onNewSessionCwdChange:!e&&t?e=>rl(n,e):void 0,draftPersistenceWarning:em,onAgentEnd:n_,onAttentionNeeded:nq,onSessionCreated:nF,onSessionForked:nV,modelsRefreshKey:e_,chatInputRef:i?ts:void 0,isFocusedPane:i,isVisiblePane:l,onBranchDataChange:i?tE:void 0,onSystemPromptChange:i?tq:void 0,onSystemToolsChange:i?tK:void 0,onSystemInfoLoaderChange:i?tV:void 0,onSessionStatsChange:i?tG:void 0,onSessionStatsPanelOpen:nr,onContextUsageChange:i?t8:void 0,onOpenFile:rd,onOpenSession:nD,onAskInNewChat:nY,quoteSelectionEnabled:W,initialPrompt:ta?.sessionId===e?.id?ta?.text:void 0,onInitialPromptConsumed:tc,soundEnabled:T,onSoundToggle:L,playDoneSound:R,unlockAudio:N},o??ed)},rg=(0,i.useCallback)(e=>{e&&t3(null),tm(e),e||tw(null)},[]),rx=(0,i.useCallback)(async()=>{if(F){tw(null),tv(!0);try{let e=new URLSearchParams({format:"md"});tf&&e.set("leafId",tf),e.set("tz",String(-new Date().getTimezoneOffset()));let t=await fetch(`/api/sessions/${encodeURIComponent(F.id)}/export?${e}`);if(!t.ok){let e=await t.json().catch(()=>null);tw(e?.error==="empty"?I("history.exportEmpty"):I("history.exportFailed"));return}let n=await t.blob(),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=function(e){if(!e)return null;let t=/filename\*=UTF-8''([^;]+)/i.exec(e);if(t?.[1])try{return decodeURIComponent(t[1])}catch{return t[1]}return/filename="([^"]+)"/i.exec(e)?.[1]??null}(t.headers.get("Content-Disposition"))??"session.md",document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),tm(!1)}catch{tw(I("history.exportFailed"))}finally{tv(!1)}}},[tf,F,I]),rm=G??(null===F&&nb?nb:null),ry=null===F&&rm?`new:${ee}:${rm}`:null,rv=n3&&"secondary"===eI?n5:n8,rb=rv?.kind==="draft"?rv.newSessionDraftKey:0===ep.length?ry:null;(0,i.useLayoutEffect)(()=>{en.current=rb},[rb]);let rw=null!==F||null!==rm,rk=!!(F&&tJ?.sessionId===F.id),rj=F?.cwd??rm;(0,i.useEffect)(()=>{if(eV(null),eY(!1),eQ(null),!rj)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(rj)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eV(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[rj]);let rT=(0,i.useCallback)(async()=>{if(rj&&!eZ){eG(!0),eQ(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:rj})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eV(t),eY(!1),eq(e=>e+1),ec(e=>e+1)}catch(e){eQ(e instanceof Error?e.message:String(e))}finally{eG(!1)}}},[eZ,rj]),rE=na.find(e=>e.id===nc)??null,rL=nb?E(nb)||nb:null,rR=rL?`${rL} - Pi Web`:"Pi Web";(0,i.useEffect)(()=>{let e=()=>{document.title!==rR&&(document.title=rR)};e();let t=new MutationObserver(e);return t.observe(document.head,{childList:!0,subtree:!0,characterData:!0}),()=>t.disconnect()},[rR]);let r$=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q,{selectedSessionId:F?.id??null,onPinSession:nP,onSelectSession:n$,onOpenSessionInNewTab:nP,onNewSession:nW,initialSessionId:nT,skipInitialProjectSelection:null!==S.requestedCwd,refreshKey:es,onSessionDeleted:nZ,selectedCwd:nb??F?.cwd??G??null,onCwdChange:nR,onOpenFile:ra,onOpenTerminal:rc,explorerRefreshKey:eB,onExplorerRefresh:nK,onAtMention:nS,onAtMentions:nC,onBackgroundTaskDone:D,onRunningSessionIdsChange:Z,onSessionsChange:U}),(0,r.jsx)("div",{style:{flexShrink:0,padding:"4px 8px",borderTop:"1px solid var(--border)"},children:(0,r.jsxs)("button",{type:"button",onClick:()=>eU(function(e,t=oh()){if(!t)return"general";try{let n=op(t).section;if(!("string"==typeof n&&od.includes(n)))return"general";return ou.has(n)&&!e?"general":n}catch{return"general"}}(rj)),title:I("common.settings"),"aria-label":I("common.settings"),style:{display:"flex",alignItems:"center",gap:8,boxSizing:"border-box",width:"100%",height:30,margin:0,padding:"0 8px",background:"none",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontFamily:"inherit",fontSize:12,fontWeight:500,textAlign:"left",transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="none"},children:[(0,r.jsx)(sy,{size:14}),(0,r.jsx)("span",{children:I("common.settings")})]})})]}),rW=e=>rw&&eK?.requiresTrust&&!eK.trusted?(0,r.jsxs)("button",{type:"button",onClick:()=>{eQ(null),eY(!0)},title:I("trust.resourcesNotLoaded"),"aria-label":I("trust.resourcesNotLoaded"),style:{display:"flex",alignItems:"center",justifyContent:e?"flex-start":"center",gap:6,width:e?"100%":void 0,minHeight:e?32:void 0,height:e?void 0:"100%",padding:e?"6px 12px":"0 12px",background:e?"color-mix(in srgb, #d97706 8%, var(--bg-panel))":"none",border:"none",borderRight:e?"none":"1px solid var(--border)",borderBottom:e?"1px solid var(--border)":"none",color:"#d97706",cursor:"pointer",flexShrink:0,fontSize:11,lineHeight:e?1.35:void 0,textAlign:"left"},className:e?void 0:"workspace-header-action","data-mobile-trust-banner":e?"true":void 0,children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,r.jsx)("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"}),(0,r.jsx)("path",{d:"M12 8v4"}),(0,r.jsx)("path",{d:"M12 16h.01"})]}),(0,r.jsx)("span",{children:I("trust.resourcesNotLoaded")})]}):null,rz=(e,t)=>{let n=t?.sessionTools??!0;return(e||rw)&&(e||n||V)?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[V&&F?.relation?.kind==="subagent"&&(0,r.jsx)("button",{type:"button",onClick:()=>nA(K.root),title:I("agentSwitcher.backToMain"),"aria-label":I("agentSwitcher.backToMain"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},className:"workspace-header-action",children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M19 12H5"}),(0,r.jsx)("path",{d:"m12 19-7-7 7-7"})]})}),V&&(0,r.jsxs)("button",{ref:e?void 0:tO,type:"button",onClick:e=>{tU.current=e.currentTarget,nt("agents")},title:I("agentSwitcher.title"),"aria-label":I("agentSwitcher.title"),"aria-pressed":"agents"===t6,"aria-expanded":"agents"===t6,"aria-controls":"workspace-top-panel","data-top-panel-trigger":"agents",style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"agents"===t6?"var(--bg-selected)":"none",border:"none",color:"agents"===t6?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.1s, background 0.1s"},className:"workspace-header-action","data-mobile-toolbar-action":e?"agents":void 0,children:[(0,r.jsx)(q,{size:13,strokeWidth:1.9}),(0,r.jsx)("span",{"aria-hidden":"true",style:{position:"absolute",top:2,right:2,minWidth:13,height:13,padding:"0 3px",display:"grid",placeItems:"center",borderRadius:4,background:"var(--bg-selected)",color:"var(--accent)",fontSize:9,lineHeight:1,fontVariantNumeric:"tabular-nums"},children:K.subagents.length})]}),n&&(e?tj&&(0,r.jsx)("button",{type:"button",onClick:()=>nt("branches"),title:I("i18n.branches"),"aria-label":I("i18n.branches"),"aria-pressed":"branches"===t6,style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"branches"===t6?"var(--bg-selected)":"none",border:"none",color:"branches"===t6?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0},className:"workspace-header-action","data-mobile-toolbar-action":"branches",children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:th.length>0?"var(--accent)":"var(--text-dim)"},"aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,r.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}):(0,r.jsx)(l2,{tree:th,activeLeafId:tf,onLeafChange:tL,inline:!0,compact:!0,containerRef:tu,open:"branches"===t6,onToggle:()=>nt("branches"),disabled:!tj,hasSession:!0})),n&&(0,r.jsx)(l4,{mobile:e,disabled:!F,menuOpen:tx,exporting:ty,error:tb,labels:{full:I("history.full"),unsaved:I("history.unsaved"),menu:I("history.menu"),exportMarkdown:I("history.exportMarkdown"),exportMarkdownTitle:I("history.exportMarkdownTitle")},onMenuOpenChange:e=>{rg(e)},onViewFullHistory:()=>{rh()},onExportMarkdown:()=>{rx()}}),n&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{ref:tF,type:"button",onClick:()=>nn("system"),disabled:e&&!rw,title:I("system.prompt"),"aria-label":I("system.prompt"),"aria-pressed":"system"===t6,"aria-expanded":"system"===t6,"aria-controls":"workspace-top-panel","data-top-panel-trigger":"system",style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"system"===t6?"var(--bg-selected)":"none",border:"none",cursor:e&&!rw?"not-allowed":"pointer",color:"system"===t6?"var(--text)":"var(--text-muted)",opacity:e&&!rw?.45:1,transition:"color 0.1s, background 0.1s"},onMouseEnter:t=>{(!e||rw)&&(t.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="system"===t6?"var(--text)":"var(--text-muted)"},className:"workspace-header-action","data-mobile-toolbar-action":e?"system":void 0,children:(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,display:"block"},"aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,r.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,r.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,r.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]})}),(0,r.jsx)("button",{type:"button",onClick:()=>nn("tools"),disabled:e&&!rw,title:I("tools.title"),"aria-label":I("tools.title"),"aria-pressed":"tools"===t6,"aria-expanded":"tools"===t6,"aria-controls":"workspace-top-panel","data-top-panel-trigger":"tools",style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"tools"===t6?"var(--bg-selected)":"none",border:"none",cursor:e&&!rw?"not-allowed":"pointer",color:"tools"===t6?"var(--text)":"var(--text-muted)",opacity:e&&!rw?.45:1,transition:"color 0.1s, background 0.1s"},onMouseEnter:t=>{(!e||rw)&&(t.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="tools"===t6?"var(--text)":"var(--text-muted)"},className:"workspace-header-action","data-mobile-toolbar-action":e?"tools":void 0,children:(0,r.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,display:"block"},"aria-hidden":"true",children:(0,r.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.8-3.8a6 6 0 0 1-7.9 7.9l-6.9 6.9a2.1 2.1 0 0 1-3-3l6.9-6.9a6 6 0 0 1 7.9-7.9z"})})})]})]}):null},rP=F?h(F):I("i18n.newSession"),rA=e=>{if(!e&&(!rw||!rk))return null;let t=t2??tJ?.contextUsage;if(!tJ&&(!e||!t))return null;let n=tJ?.tokens,i=tJ?.cost??0,o=i>=.01?`$${i.toFixed(2)}`:i>0?"<$0.01":"$0.00",l=(n?.cacheRead??0)+(n?.cacheWrite??0)+(n?.input??0),s=l>0?(n?.cacheRead??0)/l*100:null,a=t?.contextWindow??0,d=t?.tokens??null,c=t?.percent??(null!==d&&a>0?d/a*100:null),u=null!==c?Math.min(100,Math.max(0,c)):0,h=null!==c&&c>=85,p=a>0?null!==d?`${nJ(d,C)}/${nJ(a,C)}`:`?/${nJ(a,C)}`:null,f=[];if(n&&(f.push(`in: ${n.input.toLocaleString(C)}`),f.push(`out: ${n.output.toLocaleString(C)}`),f.push(`cache read: ${n.cacheRead.toLocaleString(C)}`),f.push(`cache write: ${n.cacheWrite.toLocaleString(C)}`),null!==s&&f.push(`${I("session.cacheHitRate")}: ${s.toFixed(1)}%`),i>0&&f.push(`cost: $${i.toFixed(4)}`)),t?.contextWindow){let e=t.percent;f.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${t.contextWindow.toLocaleString()} tokens`)}let g=f.join(" | ");return(0,r.jsxs)("button",{type:"button",onClick:()=>nt("session"),disabled:!rw,title:g||I("session.title"),"aria-label":g||I("session.title"),"aria-pressed":"session"===t6,"aria-expanded":"session"===t6,"aria-controls":"workspace-top-panel","data-top-panel-trigger":"session",className:"workspace-header-action","data-mobile-toolbar-stats":e?"true":void 0,style:{marginLeft:e?0:"auto",display:"flex",alignItems:"center",justifyContent:"flex-end",flex:e?1:void 0,minWidth:0,gap:e?8:10,paddingLeft:e?6:8,paddingRight:e?6:8,height:"100%",overflow:"hidden",background:"session"===t6?"var(--bg-selected)":"none",border:"none",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:rw?"pointer":"default",fontVariantNumeric:"tabular-nums",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{rw&&(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="session"===t6?"var(--text)":"var(--text-muted)"},children:[e&&p&&(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5,flexShrink:0,lineHeight:1,color:h?"#ef4444":null!==c&&c>=70&&c<85?"rgba(234,179,8,0.95)":"var(--text-muted)"},children:[(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",style:{display:"block",flexShrink:0,transform:"rotate(-90deg)"},children:[(0,r.jsx)("circle",{cx:"8",cy:"8",r:"5.5",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.22"}),(0,r.jsx)("circle",{cx:"8",cy:"8",r:"5.5",pathLength:"100",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeDasharray:`${u} 100`,style:{transition:"stroke-dasharray 0.3s ease"}})]}),(0,r.jsx)("span",{style:{fontWeight:h?600:400,letterSpacing:"-0.01em",lineHeight:1},children:p}),null!==s&&(0,r.jsxs)("span",{style:{lineHeight:1},children:[s.toFixed(0),"%"]})]}),o&&(0,r.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text-muted)",fontWeight:400,flexShrink:0,lineHeight:1},children:o})]})},rD=e=>(0,r.jsx)("button",{ref:tH,type:"button",onClick:nl,"aria-controls":"file-panel","aria-expanded":e2,title:e2?I("files.hidePanel"):I("files.showPanel"),"aria-label":e2?I("files.hidePanel"):I("files.showPanel"),className:"workspace-header-action","data-mobile-toolbar-file":e?"true":void 0,style:{marginLeft:tJ||t2?0:"auto",display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"none",border:"none",borderLeft:"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,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})});return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("style",{children:`
|
|
202
|
+
@keyframes session-info-pop {
|
|
203
|
+
0% {
|
|
204
|
+
opacity: 0;
|
|
205
|
+
transform: translateY(-8px);
|
|
206
|
+
}
|
|
207
|
+
100% {
|
|
208
|
+
opacity: 1;
|
|
209
|
+
transform: translateY(0);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
.session-info-popover {
|
|
213
|
+
position: relative;
|
|
214
|
+
overflow: hidden;
|
|
215
|
+
animation: session-info-pop 180ms cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
216
|
+
}
|
|
217
|
+
@media (prefers-reduced-motion: reduce) {
|
|
218
|
+
.session-info-popover {
|
|
219
|
+
animation: none;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
@media (max-width: 640px) {
|
|
223
|
+
.sidebar-overlay-backdrop.sidebar-mobile-pending {
|
|
224
|
+
opacity: 0 !important;
|
|
225
|
+
pointer-events: none !important;
|
|
226
|
+
}
|
|
227
|
+
.sidebar-container.sidebar-mobile-pending.sidebar-open {
|
|
228
|
+
transform: translateX(calc(-100% - env(safe-area-inset-left)));
|
|
229
|
+
box-shadow: none;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
`}),(0,r.jsxs)("div",{style:{display:"flex",width:"100%",height:"var(--app-viewport-height, 100dvh)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",overflow:"hidden",background:"var(--bg)"},children:[(0,r.jsx)("div",{className:`sidebar-overlay-backdrop${e6?"":" sidebar-mobile-pending"}`,"aria-hidden":"true",onClick:no,style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!e0,pointerEvents:e0?"auto":"none",transition:"opacity 0.25s ease"}}),(0,r.jsx)("div",{ref:tr.panelRef,id:"session-sidebar",role:"navigation","aria-label":"Pi Web","aria-hidden":!!M&&!e0||void 0,inert:!!M&&!e0||void 0,className:`sidebar-container${e0?" sidebar-open":" sidebar-closed"}${e6?"":" sidebar-mobile-pending"}${tr.isResizing?" sidebar-resizing":""}`,style:{"--sidebar-width":`${tr.width}px`,background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,paddingTop:"env(safe-area-inset-top)",paddingBottom:"env(safe-area-inset-bottom)",zIndex:200},children:r$}),e0&&(0,r.jsx)("div",{...tr.separatorProps,"aria-controls":"session-sidebar",className:`panel-resize-handle sidebar-resize-handle${tr.isResizing?" is-resizing":""}`,"data-resize-handle":"sidebar",title:`${I("layout.resizeSidebar")}: ${I("layout.resizeHint")}`}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,r.jsxs)("div",{ref:tu,style:{flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsxs)("div",{className:"workspace-header",style:{position:"relative"},children:[(0,r.jsx)("button",{ref:tB,"data-dialog-focus-fallback":"true",className:"workspace-header-action",onClick:ni,title:e0?I("sidebar.hide"):I("sidebar.show"),"aria-label":e0?I("sidebar.hide"):I("sidebar.show"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"none",border:"none",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:e0?(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,r.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,r.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,r.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),M&&(0,r.jsxs)("div",{"data-mobile-toolbar":"true",style:{display:"flex",alignItems:"stretch",flex:1,minWidth:0,height:"100%"},children:[rz(!0),rA(!0),rD(!0)]}),!M&&(0,r.jsxs)(r.Fragment,{children:[!n3&&rw&&ep.length>0&&(0,r.jsx)("div",{style:{flex:"0 1 auto",minWidth:0,height:"100%",overflow:"hidden",display:"flex",alignItems:"stretch"},children:(0,r.jsx)(iw,{tabs:ep,activeTabId:eb??"",activePane:"primary",runningSessionIds:J,onSelectTab:rr,onCloseTab:ri,onPinTab:rp,onNewTab:ro,onToggleSplit:rs,canSplit:n6,unifiedHeader:!0})}),e0||!rw||ep.length>0?null:(0,r.jsx)("button",{type:"button",onClick:()=>nt("session"),title:rP,"aria-label":rP,"aria-pressed":"session"===t6,"aria-expanded":"session"===t6,"aria-controls":"workspace-top-panel","data-top-panel-trigger":"session",className:"workspace-header-action","data-collapsed-session-title":"true",style:{display:"flex",alignItems:"center",minWidth:0,flex:1,height:"100%",padding:"0 12px",border:"none",borderRight:"1px solid var(--border)",background:"session"===t6?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",fontSize:12,fontWeight:500,textAlign:"left"},children:(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:rP})}),(0,r.jsxs)("div",{"data-desktop-header-actions":"true",style:{marginLeft:"auto",display:"flex",alignItems:"stretch",height:"100%",flexShrink:0},children:[rW(!1),rA(!1),rz(!1,{sessionTools:rk})]})]}),!M&&rD(!1),M&&tj&&(0,r.jsx)(l2,{tree:th,activeLeafId:tf,onLeafChange:tL,inline:!0,compact:!0,containerRef:tu,open:"branches"===t6,onToggle:()=>nt("branches"),hasSession:rw,hideInlineButton:!0}),t6&&t7&&(0,r.jsxs)("div",{ref:t_,id:"workspace-top-panel",role:"region","aria-label":"agents"===t6?I("agentSwitcher.title"):"system"===t6?I("system.prompt"):"tools"===t6?I("tools.title"):I("session.title"),style:{position:"fixed",top:t7.top,left:t7.left,width:t7.width,maxHeight:`calc(100dvh - ${t7.top}px - 16px)`,overflowY:"agents"===t6?"visible":"auto",zIndex:520},children:["agents"===t6&&K&&F&&(0,r.jsx)(si,{rootSession:K.root,subagents:K.subagents,selectedSessionId:F.id,runningSessionIds:J,onSelectSession:nA,onOpenInNewTab:nP}),"system"===t6&&(0,r.jsx)(l5,{loading:tz,prompt:tR,translate:I}),"tools"===t6&&(0,r.jsx)(l7,{loading:tz,tools:t$,translate:I}),"session"===t6&&(0,r.jsxs)("div",{className:"session-info-popover",style:{position:"relative",background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",boxShadow:"0 8px 24px rgba(0,0,0,0.08)",padding:M?"12px 14px":"14px 20px"},children:[(0,r.jsx)("div",{style:{position:"absolute",top:10,right:12,zIndex:2},children:(0,r.jsx)("button",{type:"button",onClick:()=>ne(!0),title:I("i18n.close"),"aria-label":I("i18n.close"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:24,height:24,background:"transparent",border:"none",borderRadius:4,color:"var(--text-dim)",cursor:"pointer",transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="transparent"},children:(0,r.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})}),tJ?(t=tJ.totalActiveMs??0,n={file:"session.copyFile",id:"session.copyId",projectDir:"session.copyProjectDir",gitBranch:"session.copyGitBranch",gitWorktree:"session.copyGitWorktree"},s=(e,t)=>{let i=tX===e;return(0,r.jsx)("button",{type:"button",title:i?I("session.copied"):I(n[e]),onClick:()=>t1(e,t),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,color:i?"var(--accent)":"var(--text-dim)",background:"transparent",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",flex:"0 0 auto",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=i?"var(--accent)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:i?(0,r.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,r.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})},a=t2??tJ.contextUsage,c=null!==(d=a?.percent??(a?.tokens!==null&&a?.contextWindow?a.tokens/a.contextWindow*100:null))?Math.min(100,Math.max(0,d)):0,u=null!==d&&d>=85,f=null!==d&&d>=70&&d<85,g=a?.tokens!==null&&a?.contextWindow?Math.max(0,a.contextWindow-a.tokens):null,m=a?.contextWindow?(0,r.jsxs)("div",{style:{minWidth:0,display:"flex",flexDirection:"column"},children:[(0,r.jsxs)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)("span",{children:I("session.activeContext")}),null!==d&&(0,r.jsxs)("span",{style:{fontSize:11,fontWeight:650,color:u?"#ef4444":f?"rgba(234,179,8,0.95)":"var(--accent)"},children:[d.toFixed(1),"%"]})]}),(0,r.jsx)("div",{style:{width:"100%",height:5,borderRadius:3,background:"var(--border)",overflow:"hidden",marginBottom:8},children:(0,r.jsx)("div",{style:{width:`${c}%`,height:"100%",background:u?"#ef4444":f?"#eab308":"var(--accent)",borderRadius:3,transition:"width 0.3s ease"}})}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"max-content max-content",columnGap:14,rowGap:4,justifyContent:"start",fontSize:11.5},children:[null!==a.tokens&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:I("session.contextUsed")}),(0,r.jsx)("div",{style:{color:"var(--text)",textAlign:"right",whiteSpace:"nowrap"},children:nJ(a.tokens,C)})]}),(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:I("session.contextWindow")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",textAlign:"right",whiteSpace:"nowrap"},children:nJ(a.contextWindow,C)}),null!==g&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:I("session.contextRemaining")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",textAlign:"right",whiteSpace:"nowrap"},children:nJ(g,C)})]})]}),u&&(0,r.jsxs)("div",{style:{marginTop:6,fontSize:11,color:"#ef4444",display:"flex",alignItems:"center",gap:4},children:[(0,r.jsx)("span",{children:"⚠️"}),(0,r.jsx)("span",{children:I("chat.contextHighWarning")})]})]}):null,v=(y=tJ.tokens.cacheRead+tJ.tokens.cacheWrite)+tJ.tokens.input>0?`${(tJ.tokens.cacheRead/(y+tJ.tokens.input)*100).toFixed(1)}%`:null,b=(0,r.jsxs)("div",{style:{minWidth:0,display:"flex",flexDirection:"column"},children:[(0,r.jsxs)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)("span",{children:I("session.cumulativeTokens")}),tJ.cost>0&&(0,r.jsxs)("span",{style:{fontSize:11,fontWeight:650,color:"var(--text)"},children:["$",tJ.cost.toFixed(4)]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"max-content max-content",columnGap:14,rowGap:4,justifyContent:"start",fontSize:11.5},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:I("session.total")}),(0,r.jsx)("div",{style:{color:"var(--text)",textAlign:"right",whiteSpace:"nowrap"},children:nJ(tJ.tokens.total,C)}),(0,r.jsxs)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:[I("session.input")," / ",I("session.output")]}),(0,r.jsxs)("div",{style:{color:"var(--text-muted)",textAlign:"right",whiteSpace:"nowrap"},children:[nJ(tJ.tokens.input,C)," / ",nJ(tJ.tokens.output,C)]}),tJ.tokens.cacheRead>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:I("session.cacheRead")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",textAlign:"right",whiteSpace:"nowrap"},children:nJ(tJ.tokens.cacheRead,C)})]}),v&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:I("session.cacheHitRate")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",textAlign:"right",whiteSpace:"nowrap"},children:v})]})]})]}),w=(0,r.jsxs)("div",{style:{minWidth:0,display:"flex",flexDirection:"column"},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:I("session.infoSection")}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5,fontSize:11.5},children:[tJ.sessionName&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:8},children:[(0,r.jsxs)("span",{style:{color:"var(--text-dim)",whiteSpace:"nowrap",flexShrink:0},children:[I("session.name"),":"]}),(0,r.jsx)("span",{style:{color:"var(--text)",fontWeight:550,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:tJ.sessionName})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsxs)("span",{style:{color:"var(--text-dim)",whiteSpace:"nowrap",flexShrink:0},children:[I("session.messages"),":"]}),(0,r.jsxs)("span",{style:{color:"var(--text-muted)",whiteSpace:"nowrap"},children:[tJ.userMessages," ",I("session.user").toLowerCase()," \xb7 ",tJ.assistantMessages," ",I("session.assistant").toLowerCase()," \xb7 ",tJ.toolCalls," ",I("session.toolCalls").toLowerCase(),t>0?` (${(e=>{if(e<=0)return"0s";let t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`})(t)})`:""]})]}),tJ.sessionFile&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[(0,r.jsxs)("span",{style:{color:"var(--text-dim)",whiteSpace:"nowrap",flexShrink:0},children:[I("session.file"),":"]}),(0,r.jsx)("span",{title:tJ.sessionFile,style:{color:"var(--text-muted)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",textAlign:"left"},children:tJ.sessionFile}),s("file",tJ.sessionFile)]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsxs)("span",{style:{color:"var(--text-dim)",whiteSpace:"nowrap",flexShrink:0},children:[I("session.id"),":"]}),(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11},children:tJ.sessionId?`${tJ.sessionId.slice(0,8)}...${tJ.sessionId.slice(-6)}`:"?"}),tJ.sessionId&&s("id",tJ.sessionId)]})]})]}),(0,r.jsxs)("div",{className:"session-stats-grid",style:{fontFamily:"var(--font-mono)",lineHeight:1.45},children:[m,b,w]})):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:I("session.load")})]})]})]}),M&&rw&&ep.length>1&&(0,r.jsx)("div",{"data-mobile-chat-tabs":"true",style:{borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",height:"var(--workspace-header-height, 30px)",minHeight:"var(--workspace-header-height, 30px)",width:"100%",maxWidth:"100%",minWidth:0,overflow:"hidden",display:"flex",alignItems:"stretch"},children:(0,r.jsx)(iw,{tabs:ep,activeTabId:eb??"",activePane:"primary",runningSessionIds:J,onSelectTab:rr,onCloseTab:ri,onPinTab:rp,onNewTab:ro,canSplit:!1,isMobile:!0})}),M&&rW(!0)]}),(0,r.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative",display:"flex",flexDirection:"column"},children:(0,r.jsx)("div",{ref:eN,style:{flex:1,overflow:"hidden",position:"relative",display:"grid",minHeight:0,gridTemplateColumns:n3?`${100*eL}% 0 minmax(0, 1fr)`:"minmax(0, 1fr)",gridTemplateRows:n3?"auto minmax(0, 1fr)":"minmax(0, 1fr)"},children:rw?(0,r.jsxs)(r.Fragment,{children:[n3&&(0,r.jsx)("div",{style:{gridColumn:1,gridRow:1,minWidth:0,overflow:"hidden"},onPointerDownCapture:()=>re("primary"),children:(0,r.jsx)(iw,{tabs:n2,activeTabId:eb??"",activePane:"primary"===eI?"primary":"secondary",runningSessionIds:J,onSelectTab:rt,onCloseTab:ri,onPinTab:rp,onNewTab:()=>ro("primary"),onToggleSplit:rs,canSplit:!1})}),ep.length>0?ep.map(e=>{let t=n3?ij(e):"primary",n=e.id===("secondary"===t?ej:eb),i="secondary"===t?"secondary"===eI:n7,o=e.mountKey??e.id;return(0,r.jsx)("div",{"data-chat-pane":t,onPointerDownCapture:()=>{n&&n3&&re(t)},style:{gridColumn:"secondary"===t?3:1,gridRow:n3?2:1,display:n?"flex":"none",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden",position:"relative",borderLeft:"secondary"===t?"1px solid var(--border)":void 0},children:rf("session"===e.kind?e.session:null,"draft"===e.kind?e.newSessionCwd:null,"draft"===e.kind?e.newSessionDraftKey:null,n&&i,o,n)},o)}):(0,r.jsx)("div",{style:{gridColumn:1,gridRow:n3?2:1,minHeight:0,display:"flex",flexDirection:"column"},children:rf(F,rm,ry,n7)}),n3&&(0,r.jsx)("div",{className:"split-chat-resize-handle",style:{gridColumn:2,gridRow:"1 / 3"},role:"separator","aria-orientation":"vertical","aria-valuemin":Math.round(100*sh(eW).min),"aria-valuemax":Math.round(100*sh(eW).max),"aria-valuenow":Math.round(100*eL),tabIndex:0,title:I("chatTabs.splitView",{defaultValue:"调整分屏大小"}),onPointerDown:nX,onPointerMove:nQ,onPointerUp:n0,onPointerCancel:n0,onKeyDown:n1,onDoubleClick:()=>eR(.5)}),n3&&n5&&(0,r.jsx)("div",{style:{gridColumn:3,gridRow:1,minWidth:0,overflow:"hidden",borderLeft:"1px solid var(--border)"},onPointerDownCapture:()=>re("secondary"),children:(0,r.jsx)(iw,{tabs:n4,activeTabId:ej??"",activePane:"secondary"===eI?"primary":"secondary",runningSessionIds:J,onSelectTab:rn,onCloseTab:ri,onPinTab:rp,onNewTab:()=>ro("secondary"),onClosePane:rs,isSecondaryPane:!0})})]}):"validating"===er?(0,r.jsxs)("div",{role:"status",style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,color:"var(--text-muted)",textAlign:"center"},children:[(0,r.jsx)("div",{style:{fontSize:14,color:"var(--text)"},children:I("workspace.opening")}),(0,r.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:S.requestedCwd})]}):"error"===er?(0,r.jsxs)("div",{role:"alert",style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,color:"var(--text-muted)",textAlign:"center"},children:[(0,r.jsx)("div",{style:{fontSize:14,color:"#dc2626"},children:I("workspace.unable")}),(0,r.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:S.requestedCwd}),(0,r.jsx)("div",{style:{maxWidth:720,fontSize:12},children:eo})]}):null})})]}),(0,r.jsx)("div",{"aria-hidden":"true",className:`right-panel-overlay-backdrop${e2?" is-open":""}`,onClick:()=>ns(!0)}),e2&&(0,r.jsx)("div",{...ti.separatorProps,"aria-controls":"file-panel",className:`panel-resize-handle right-panel-resize-handle${ti.isResizing?" is-resizing":""}`,"data-resize-handle":"right-panel",title:`${I("layout.resizeFilePanel")}: ${I("layout.resizeHint")}`}),(0,r.jsxs)("div",{ref:ti.panelRef,id:"file-panel","aria-hidden":!e2,inert:!e2||void 0,className:`right-panel-container${e2?" right-panel-open":" right-panel-closed"}${ti.isResizing?" right-panel-resizing":""}`,style:{"--right-panel-width":`${ti.width}px`,display:"flex",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)"},children:[(0,r.jsxs)("div",{className:"workspace-header",style:{background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{flex:1,height:"100%",overflow:"hidden"},children:(0,r.jsx)(os,{tabs:nx,activeTabId:nc??"",onSelectTab:nu,onCloseTab:ru})}),(0,r.jsx)("button",{type:"button",onClick:()=>ns(!0),className:"workspace-header-action right-panel-header-close","aria-controls":"file-panel",title:I("files.hidePanel"),"aria-label":I("files.hidePanel"),style:{alignItems:"center",justifyContent:"center",width:30,height:"100%",padding:0,background:"none",border:"none",borderLeft:"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,r.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"})]})})]}),(0,r.jsxs)("div",{style:{flex:1,minHeight:0,overflow:"hidden",paddingBottom:"env(safe-area-inset-bottom)"},children:[rE?.filePath?(0,r.jsx)(on,{filePath:rE.filePath,cwd:rE.cwd??nb??void 0,sourceSessionId:rE.sourceSessionId,gitRefreshKey:eB,initialDisplayMode:rE.initialDisplayMode,initialState:rE.viewerState,watchEnabled:e8,onStateChange:e=>ny(rE.id,rE.viewerRevision??0,e),onMentionLines:e2?nI:void 0,onAtMention:nS,onOpenFile:e=>ra(e,E(e),{sourceSessionId:rE.sourceSessionId,cwd:rE.cwd})},`${rE.id}:${rE.viewerRevision??0}`):nh.some(e=>e.id===nc)?null:(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:I("files.noneOpen")}),nh.map(e=>(0,r.jsx)("div",{hidden:e.id!==nc,style:{width:"100%",height:"100%"},children:(0,r.jsx)(sa,{tab:e,active:e2&&e.id===nc,onRestart:()=>np(t=>t.map(t=>t.id===e.id?{...t,closing:"restart"}:t)),onClosed:()=>{let t,n,r;return t="restart"===e.closing?sc(e.cwd):null,n=nh.filter(t=>t.id!==e.id),r=oa(nx,e.id),void(np(n=>n.flatMap(n=>n.id!==e.id?[n]:t?[t]:[])),nu(n=>n!==e.id?n:t?.id??r),!t&&!n.length&&!na.length&&e4(!1))},onCloseError:()=>np(t=>t.map(t=>t.id===e.id?{...t,closing:void 0}:t))})},e.id))]})]})]}),eO&&(0,r.jsx)(lZ,{cwd:rj,sessionId:F?.id??null,initialSection:eO,quoteSelectionEnabled:W,onQuoteSelectionChange:P,onClose:()=>{eU(null),eq(e=>e+1)},onSessionReloaded:()=>ec(e=>e+1)}),eJ&&rj&&(0,r.jsx)(lG,{cwd:rj,busy:eZ,error:eX,onCancel:()=>{eZ||eY(!1)},onConfirm:()=>void rT()})]})}},88576:e=>{e.exports={minimap:"ChatMinimap_minimap__gDaeY",trigger:"ChatMinimap_trigger__Wb5KU",marker:"ChatMinimap_marker__NEjJc",panel:"ChatMinimap_panel__bAkor",menu:"ChatMinimap_menu__7Cur1",minimapFadeIn:"ChatMinimap_minimapFadeIn__XXu75",list:"ChatMinimap_list__g9HUb",track:"ChatMinimap_track__ZlbIX",row:"ChatMinimap_row__LGVWw",rowText:"ChatMinimap_rowText__bagDa",status:"ChatMinimap_status__U2inN"}},94423:(e,t,n)=>{Promise.resolve().then(n.bind(n,50954)),Promise.resolve().then(n.bind(n,21278))}},e=>{e.O(0,[7523,7330,3888,9445,1278,8441,3794,7358],()=>e(e.s=94423)),_N_E=e.O()}]);
|