@qt4798/pi-web 0.9.21 → 0.9.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +20 -17
- package/.next/build-manifest.json +2 -2
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/routes-manifest.json +18 -0
- package/.next/server/app/_global-error/page.js +3 -3
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page.js +2 -2
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +2 -2
- package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/api/agent/[id]/bash-output/route.js +1 -1
- package/.next/server/app/api/agent/[id]/events/route.js +2 -2
- package/.next/server/app/api/agent/[id]/route.js +1 -1
- package/.next/server/app/api/agent/new/route.js +1 -1
- package/.next/server/app/api/agent/running/events/route.js +1 -1
- package/.next/server/app/api/agent/running/route.js +1 -1
- package/.next/server/app/api/auth/all-providers/route.js +1 -1
- package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -1
- package/.next/server/app/api/auth/combined/route.js +1 -1
- package/.next/server/app/api/auth/login/[provider]/route.js +2 -2
- package/.next/server/app/api/auth/logout/[provider]/route.js +1 -1
- package/.next/server/app/api/auth/providers/route.js +1 -1
- package/.next/server/app/api/backup/export/route.js +1 -1
- package/.next/server/app/api/backup/import/route.js +1 -1
- package/.next/server/app/api/cwd/browse/route.js +1 -1
- package/.next/server/app/api/cwd/validate/route.js +1 -1
- package/.next/server/app/api/deepseek/balance/route.js +1 -1
- package/.next/server/app/api/default-cwd/route.js +1 -1
- package/.next/server/app/api/events/route.js +2 -2
- package/.next/server/app/api/features/route.js +1 -1
- package/.next/server/app/api/file-index/route.js +1 -1
- package/.next/server/app/api/files/[...path]/route.js +1 -1
- package/.next/server/app/api/git/diff/route.js +2 -2
- package/.next/server/app/api/git/push/route.js +1 -1
- package/.next/server/app/api/git/stash/route.js +1 -1
- package/.next/server/app/api/git/status/route.js +1 -1
- package/.next/server/app/api/home/route.js +1 -1
- package/.next/server/app/api/import/discover/route.js +1 -1
- package/.next/server/app/api/import/execute/route.js +1 -1
- package/.next/server/app/api/import/status/route.js +1 -1
- package/.next/server/app/api/logs/route.js +1 -1
- package/.next/server/app/api/mcp/restart/route.js +1 -0
- package/.next/server/app/api/mcp/restart/route.js.nft.json +1 -0
- package/.next/server/app/api/mcp/restart/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/mcp/route.js +1 -1
- package/.next/server/app/api/models/route.js +1 -1
- package/.next/server/app/api/models-config/builtin/route.js +1 -1
- package/.next/server/app/api/models-config/catalog/route.js +1 -1
- package/.next/server/app/api/models-config/discover/route.js +1 -1
- package/.next/server/app/api/models-config/route.js +1 -1
- package/.next/server/app/api/models-config/test/route.js +1 -1
- package/.next/server/app/api/modes/route.js +1 -1
- package/.next/server/app/api/opencode-zen/external/key/route.js +1 -1
- package/.next/server/app/api/opencode-zen/external/test/route.js +1 -1
- package/.next/server/app/api/opencode-zen/import/route.js +1 -1
- package/.next/server/app/api/opencode-zen/key/route.js +1 -1
- package/.next/server/app/api/opencode-zen/route.js +1 -1
- package/.next/server/app/api/opencode-zen/test/route.js +1 -1
- package/.next/server/app/api/plugins/route.js +1 -1
- package/.next/server/app/api/project-aliases/route.js +1 -0
- package/.next/server/app/api/project-aliases/route.js.nft.json +1 -0
- package/.next/server/app/api/project-aliases/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/project-trust/route.js +1 -1
- package/.next/server/app/api/proxy/route.js +1 -1
- package/.next/server/app/api/proxy/test/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/auto-name/route.js +3 -3
- package/.next/server/app/api/sessions/[id]/context/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/entries/[entryId]/thinking/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/export/route.js +2 -2
- package/.next/server/app/api/sessions/[id]/queue-recovery/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/state/route.js +1 -1
- package/.next/server/app/api/sessions/route.js +1 -1
- package/.next/server/app/api/settings/title-model/route.js +1 -1
- package/.next/server/app/api/skills/check/route.js +1 -1
- package/.next/server/app/api/skills/install/route.js +1 -1
- package/.next/server/app/api/skills/route.js +2 -2
- package/.next/server/app/api/skills/search/route.js +1 -1
- package/.next/server/app/api/skills/update/route.js +1 -1
- package/.next/server/app/api/snippets/[id]/route.js +1 -1
- package/.next/server/app/api/snippets/route.js +1 -1
- package/.next/server/app/api/subagents/agents/[name]/route.js +2 -2
- package/.next/server/app/api/subagents/route.js +2 -2
- package/.next/server/app/api/subagents/transcript/route.js +1 -0
- package/.next/server/app/api/subagents/transcript/route.js.nft.json +1 -0
- package/.next/server/app/api/subagents/transcript/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/tasks/[id]/[action]/route.js +1 -1
- package/.next/server/app/api/tasks/[id]/changed-files/route.js +2 -2
- package/.next/server/app/api/tasks/[id]/diff/route.js +1 -1
- package/.next/server/app/api/tasks/[id]/events/route.js +1 -1
- package/.next/server/app/api/tasks/[id]/route.js +1 -1
- package/.next/server/app/api/tasks/batch/route.js +1 -1
- package/.next/server/app/api/tasks/events/route.js +2 -2
- package/.next/server/app/api/tasks/route.js +1 -1
- package/.next/server/app/api/tasks/settings/route.js +1 -1
- package/.next/server/app/api/tasks/templates/route.js +1 -1
- package/.next/server/app/api/themes/[name]/route.js +1 -1
- package/.next/server/app/api/themes/route.js +1 -1
- package/.next/server/app/api/usage/route.js +1 -1
- package/.next/server/app/api/vision-config/route.js +2 -2
- package/.next/server/app/api/worktrees/route.js +1 -1
- package/.next/server/app/icon.ico/route.js +1 -1
- package/.next/server/app/icon.png/route.js +1 -1
- package/.next/server/app/icon.svg/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +4 -4
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
- package/.next/server/app/index.segments/_full.segment.rsc +4 -4
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +2 -2
- package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/page.js +15 -15
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +20 -17
- package/.next/server/chunks/4253.js +1 -1
- package/.next/server/chunks/5582.js +2 -2
- package/.next/server/chunks/6429.js +1 -1
- package/.next/server/chunks/7915.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/static/Zj8YLnblAjsL5HR_ER_d_/_buildManifest.js +1 -0
- package/.next/static/chunks/711-462ef5daacae3d6c.js +1 -0
- package/.next/static/chunks/app/_global-error/page-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/bash-output/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/events/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/agent/new/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/agent/running/events/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/agent/running/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/auth/all-providers/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/auth/api-key/[provider]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/auth/combined/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/auth/login/[provider]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/auth/logout/[provider]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/auth/providers/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/backup/export/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/backup/import/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/cwd/browse/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/cwd/validate/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/deepseek/balance/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/default-cwd/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/events/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/features/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/file-index/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/files/[...path]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/git/diff/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/git/push/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/git/stash/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/git/status/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/home/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/import/discover/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/import/execute/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/import/status/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/logs/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/mcp/restart/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/mcp/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/models/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/models-config/builtin/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/models-config/catalog/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/models-config/discover/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/models-config/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/models-config/test/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/modes/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/opencode-zen/external/key/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/opencode-zen/external/test/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/opencode-zen/import/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/opencode-zen/key/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/opencode-zen/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/opencode-zen/test/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/plugins/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/project-aliases/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/project-trust/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/proxy/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/proxy/test/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/auto-name/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/context/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/entries/[entryId]/thinking/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/export/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/queue-recovery/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/state/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/sessions/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/settings/title-model/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/skills/check/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/skills/install/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/skills/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/skills/search/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/skills/update/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/snippets/[id]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/snippets/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/subagents/agents/[name]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/subagents/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/subagents/transcript/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/[id]/[action]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/[id]/changed-files/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/[id]/diff/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/[id]/events/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/[id]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/batch/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/events/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/settings/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/tasks/templates/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/themes/[name]/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/themes/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/usage/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/vision-config/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/api/worktrees/route-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/app/page-4e2e6b9b44c2727c.js +53 -0
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-e106132a25a7dc95.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-e106132a25a7dc95.js +1 -0
- package/.next/static/css/437ace30775068cf.css +1 -0
- package/.next/trace +9 -9
- package/.next/trace-build +1 -1
- package/.next/types/app/api/mcp/restart/route.ts +351 -0
- package/.next/types/app/api/project-aliases/route.ts +351 -0
- package/.next/types/app/api/subagents/transcript/route.ts +351 -0
- package/.next/types/routes.d.ts +4 -1
- package/.next/types/validator.ts +27 -0
- package/package.json +1 -1
- package/.next/static/GxM26wqNKTWNiNc1-YXns/_buildManifest.js +0 -1
- package/.next/static/chunks/3555-b9de79b68c0278d5.js +0 -1
- package/.next/static/chunks/app/_global-error/page-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/bash-output/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/events/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/agent/new/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/agent/running/events/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/agent/running/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/auth/all-providers/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/auth/api-key/[provider]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/auth/combined/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/auth/login/[provider]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/auth/logout/[provider]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/auth/providers/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/backup/export/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/backup/import/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/cwd/browse/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/cwd/validate/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/deepseek/balance/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/default-cwd/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/events/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/features/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/file-index/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/files/[...path]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/git/diff/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/git/push/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/git/stash/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/git/status/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/home/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/import/discover/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/import/execute/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/import/status/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/logs/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/mcp/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/models/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/models-config/builtin/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/models-config/catalog/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/models-config/discover/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/models-config/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/models-config/test/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/modes/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/opencode-zen/external/key/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/opencode-zen/external/test/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/opencode-zen/import/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/opencode-zen/key/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/opencode-zen/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/opencode-zen/test/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/plugins/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/project-trust/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/proxy/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/proxy/test/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/auto-name/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/context/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/entries/[entryId]/thinking/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/export/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/queue-recovery/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/state/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/sessions/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/settings/title-model/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/skills/check/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/skills/install/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/skills/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/skills/search/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/skills/update/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/snippets/[id]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/snippets/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/subagents/agents/[name]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/subagents/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/[id]/[action]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/[id]/changed-files/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/[id]/diff/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/[id]/events/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/[id]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/batch/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/events/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/settings/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/tasks/templates/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/themes/[name]/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/themes/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/usage/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/vision-config/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/api/worktrees/route-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/app/page-3de6991e0964e474.js +0 -53
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-3581deaae88a2371.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-3581deaae88a2371.js +0 -1
- package/.next/static/css/096d7027f97f110c.css +0 -1
- /package/.next/static/{GxM26wqNKTWNiNc1-YXns → Zj8YLnblAjsL5HR_ER_d_}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{14755:(e,t,o)=>{"use strict";o.d(t,{SC:()=>i,getPresetFromTools:()=>l,xG:()=>d});let r=[],n=["read","bash","edit","write"],s=["bash","read","edit","write","grep","find","ls"],i=["read","grep","find","ls"],a=new Set(s);function l(e){let t=e.filter(e=>e.active);if(0===t.length)return"none";let o=t.map(e=>e.name).filter(e=>a.has(e)).sort().join(",");return o===[...i].sort().join(",")?"plan":o===[...n].sort().join(",")?"default":o===[...s].sort().join(",")?"full":"default"}function d(e){return"none"===e?[...r]:"full"===e?[...s]:"plan"===e?[...i]:[...n]}},23084:(e,t,o)=>{"use strict";async function r(e,t){let o=await fetch(e,{...t,headers:t?.body?{"Content-Type":"application/json"}:void 0}),r=await o.json().catch(()=>({}));if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);return r}async function n(e){return(await r(`/api/tasks?projectRoot=${encodeURIComponent(e)}`)).tasks}async function s(){return(await r("/api/tasks/projects")).projects}async function i(e){return(await r("/api/tasks",{method:"POST",body:JSON.stringify(e)})).task}async function a(e,t,o){return(await r(`/api/tasks/${e}?projectRoot=${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({projectRoot:t,...o})})).task}async function l(e,t,o=!1){await r(`/api/tasks/${e}?projectRoot=${encodeURIComponent(t)}&deleteWorktree=${+!!o}`,{method:"DELETE"})}async function d(e,t,o,n){await r(`/api/tasks/${e}/${o}?projectRoot=${encodeURIComponent(t)}`,{method:"POST",body:JSON.stringify({...n})})}async function c(e,t,o){await r(`/api/tasks/${e}/return?projectRoot=${encodeURIComponent(t)}`,{method:"POST",body:JSON.stringify({feedback:o})})}async function p(e,t,o,n){await r(`/api/tasks/${e}/merge?projectRoot=${encodeURIComponent(t)}`,{method:"POST",body:JSON.stringify({message:o,deleteWorktree:n})})}async function u(e,t,o){await r(`/api/tasks/${e}/complete?projectRoot=${encodeURIComponent(t)}`,{method:"POST",body:JSON.stringify({deleteWorktree:o})})}async function g(e,t,o){await r(`/api/tasks/${e}/archive?projectRoot=${encodeURIComponent(t)}`,{method:"POST",body:JSON.stringify({archived:o})})}async function h(e,t){await r("/api/tasks/batch?mode=reorder",{method:"POST",body:JSON.stringify({projectRoot:e,orderedIds:t})})}async function x(e){return(await r("/api/tasks/batch?mode=start-all",{method:"POST",body:JSON.stringify({projectRoot:e})})).claimed}async function f(e,t,o=500){return(await r(`/api/tasks/${t}/events?projectRoot=${encodeURIComponent(e)}&limit=${o}`)).events}async function m(e,t){return r(`/api/tasks/${t}/changed-files?projectRoot=${encodeURIComponent(e)}`)}async function k(e,t,o){return r(`/api/tasks/${t}/diff?projectRoot=${encodeURIComponent(e)}&file=${encodeURIComponent(o)}`)}async function v(e){return(await r(`/api/tasks/settings?projectRoot=${encodeURIComponent(e)}`)).settings}async function y(e){return(await r(`/api/tasks/settings?projectRoot=${encodeURIComponent(e)}&own=1`)).settings}async function b(e,t){await r("/api/tasks/settings",{method:"PUT",body:JSON.stringify({projectRoot:e,settings:t})})}async function w(e){await r(`/api/tasks/settings?projectRoot=${encodeURIComponent(e)}`,{method:"DELETE"})}async function j(){return(await r("/api/tasks/templates")).templates}async function S(e){return(await r("/api/tasks/templates",{method:"POST",body:JSON.stringify(e)})).template}async function C(e){await r(`/api/tasks/templates?id=${e}`,{method:"DELETE"})}o.d(t,{B_:()=>C,CG:()=>v,E:()=>w,HB:()=>f,JH:()=>m,Lu:()=>h,Pf:()=>y,VB:()=>j,Vk:()=>n,Wt:()=>s,ZX:()=>u,a5:()=>x,bH:()=>l,createTaskApi:()=>i,eA:()=>b,et:()=>g,h:()=>k,in:()=>c,nY:()=>S,oB:()=>p,oQ:()=>d,updateTaskApi:()=>a})},39247:(e,t,o)=>{"use strict";o.d(t,{I18nProvider:()=>c,s:()=>p});var r=o(95155),n=o(12115);let s=new Map;function i(e){if(!e.id.trim())throw Error("Locale id must not be empty");if(s.has(e.id))throw Error(`Locale already registered: ${e.id}`);s.set(e.id,e)}function a(e){return s.get(e)}i({id:"en",label:"English",messages:{"i18n.close":"Close","i18n.cancel":"Cancel","i18n.checking":"Checking…","desktop.settings":"Settings","desktop.settingsSections":"Settings sections","desktop.closeSettings":"Close settings","desktop.display":"Display","desktop.chat":"Chat","desktop.models":"Models","desktop.skills":"Skills","desktop.plugins":"Plugins","desktop.opencodeZen":"OpenCode Zen","desktop.proxy":"Proxy","desktop.proxyEnable":"Enable Proxy","desktop.proxyProtocol":"Protocol","desktop.proxyHost":"Host","desktop.proxyPort":"Port","desktop.proxyUsername":"Username (optional)","desktop.proxyPassword":"Password (optional)","desktop.proxyNoProxy":"No-Proxy (comma-separated, optional)","desktop.proxySave":"Save","desktop.proxySaving":"Saving…","desktop.proxyTest":"Test Connection","desktop.proxyTesting":"Testing…","desktop.proxySaved":"Proxy configuration saved","desktop.proxySaveFailed":"Failed to save","desktop.proxyTestSuccess":"Connected","desktop.proxyTestFailed":"Connection failed","desktop.proxyUnsaved":"Unsaved changes","desktop.features":"Features","desktop.logs":"Logs","desktop.snippets":"Snippets","desktop.snippetsDesc":"Reusable text/code snippets — type # in the composer to autocomplete","desktop.snippetNew":"New snippet","desktop.snippetName":"Name","desktop.snippetContent":"Content","desktop.snippetSave":"Save","desktop.snippetEdit":"Edit","desktop.snippetDelete":"Delete","desktop.snippetEmpty":"No snippets yet — create one to get started.","desktop.snippetNameRequired":"Snippet name is required","desktop.snippetHint":"Type #name in the composer to autocomplete; Enter expands it to the snippet content.","desktop.logsAllCodes":"All error codes","desktop.logsAllSources":"All sources","desktop.logsSearch":"Search error logs","desktop.logsClear":"Clear logs","desktop.logsCopy":"Copy log","desktop.logsEmpty":"No error logs","desktop.mcpVisionTitle":"DeepSeek Vision module","desktop.mcpVisionDesc":"Dedicated configuration for the deepseek-vision module (image analysis / OCR). Both the MCP registration and the model settings can be edited here.","desktop.mcpVisionRegistered":"Registered","desktop.mcpVisionNotRegistered":"Not registered","desktop.mcpVisionRegistration":"MCP registration","desktop.mcpVisionCommand":"Command","desktop.mcpVisionCommandRequired":"Command is required","desktop.mcpVisionLifecycle":"Lifecycle","desktop.mcpVisionTransport":"Transport","desktop.mcpVisionTransportFixed":"stdio (fixed)","desktop.mcpVisionSaveReg":"Save registration","desktop.mcpVisionSavedReg":"Registration saved — takes effect in a new session or after restarting pi.","desktop.mcpVisionRemove":"Remove from MCP config","desktop.mcpVisionRemoved":"Registration removed","desktop.mcpVisionModelConfig":"Model configuration","desktop.mcpVisionModelNote":'Model settings are written to .env immediately. Use "Restart server" below to apply them right away.',"desktop.mcpVisionProvider":"Provider","desktop.mcpVisionBaseUrl":"Base URL","desktop.mcpVisionApiKey":"API key","desktop.mcpVisionModel":"Vision model","desktop.mcpVisionMaxTokens":"Max output tokens","desktop.mcpVisionSaveModel":"Save model configuration","desktop.mcpVisionSavedModel":"Model configuration saved","desktop.mcpVisionNameReserved":"This name is reserved for the built-in DeepSeek Vision configuration — pick another name.","desktop.mcpVisionRestart":"Restart server (apply now)","desktop.mcpVisionRestarting":"Restarting…","desktop.mcpVisionRestarted":"Restart command sent — takes effect shortly","desktop.mcpVisionRestartTitle":"Restart the deepseek-vision server so .env changes take effect immediately","desktop.mcpVisionRestartNoSession":"Open a session first to restart the server","desktop.applyNow":"Apply now","desktop.applyNowApplying":"Reloading…","desktop.applyNowDone":"Reloaded — changes applied","desktop.applyNowTitle":"Reload the current session so changes take effect immediately (no pi restart needed)","desktop.applyNowNoSession":"Open a session first to apply changes now","desktop.featuresDesc":"Manage optional Pi Web features. Disabling one hides its entry points.","desktop.featuresTasksBoard":"Task Board","desktop.featuresTasksBoardDesc":"Show the Task Board entry in the top toolbar to manage cross-project tasks.","desktop.featuresLoading":"Loading…","desktop.featuresSaving":"Saving…","desktop.featuresCollabDefault":"Default task mode","desktop.featuresCollabDefaultDesc":"Default collaboration mode for new chats (Normal / Plan / Goal)","desktop.featuresTokenDefault":"Default token profile","desktop.featuresTokenDefaultDesc":"Default token profile for new chats (Lite / Balanced / Delivery)","desktop.featuresApprovalDefault":"Default tool approval","desktop.featuresApprovalDefaultDesc":"Default tool approval for new chats (Ask / Auto / Yolo)","desktop.usage":"Usage","desktop.usageSession":"Current session","desktop.usageGlobal":"Global","desktop.usageContext":"Context {used} / {window} tokens","desktop.usageContextHint":"Live context usage of the current session","desktop.usageNoSessionData":"No usage data for the current session","desktop.usageNoSession":"No session open","desktop.usageTotal":"Estimated total","desktop.usageMessages":"Messages","desktop.usageMessagesHint":"across all sessions","desktop.usageSessions":"sessions","desktop.usageDaily":"Daily usage trend","desktop.usageTopSessions":"Top sessions by usage","desktop.usageNoData":"No data yet","desktop.mcp":"MCP","desktop.mcpServers":"MCP servers","desktop.mcpAddServer":"Add server","desktop.mcpNewServer":"New MCP server","desktop.mcpEditServer":'Edit MCP server "{name}"',"desktop.mcpRestartNote":"MCP servers are loaded when pi starts. Changes made here take effect after restarting pi.","desktop.mcpEmpty":"No MCP servers configured yet — add one to expose tools to the agent.","desktop.mcpEmptyOther":"No other MCP servers configured — DeepSeek Vision is managed in the card above.","desktop.mcpServerName":"Name","desktop.mcpCommand":"Command","desktop.mcpArgs":"Arguments (one per line)","desktop.mcpTransport":"Transport","desktop.mcpLifecycle":"Lifecycle","desktop.mcpRequestTimeoutMs":"Request timeout (ms)","desktop.mcpEnv":"Environment (JSON)","desktop.mcpEdit":"Edit","desktop.mcpDelete":"Delete","desktop.mcpSave":"Save","desktop.saving":"Saving…","desktop.mcpCancel":"Cancel","desktop.mcpSavedRestart":"Saved — restart pi to apply changes.","desktop.subagents":"Subagents","desktop.subagentsDesc":"Subagent fleet configuration. Applies to pi-subagents managed runs; restart pi to apply changes.","desktop.subagentsMaxConcurrent":"Max concurrent","desktop.subagentsDefaultMaxTurns":"Default max turns (0 = unlimited)","desktop.subagentsGraceTurns":"Grace turns","desktop.subagentsJoinMode":"Default join mode","desktop.subagentsWidgetMode":"Widget mode","desktop.subagentsToolDescMode":"Tool description mode","desktop.subagentsScheduling":"Scheduling enabled","desktop.subagentsSchedulingDesc":"Let pi schedule subagent runs instead of running them immediately.","desktop.subagentsScopeModels":"Scope models","desktop.subagentsScopeModelsDesc":"Restrict subagent model choices to the current model scope.","desktop.subagentsDisableDefault":"Disable default agents","desktop.subagentsDisableDefaultDesc":"Hide built-in default agent definitions (only custom agents are offered).","desktop.subagentsFleetView":"Fleet view","desktop.subagentsFleetViewDesc":"Show a fleet overview of running subagents in the UI.","desktop.subagentsOutputTranscript":"Output transcript","desktop.subagentsOutputTranscriptDesc":"Keep a transcript of subagent output for later review.","desktop.subagentsSaved":"Saved","desktop.subagentsModel":"Model","desktop.subagentsModelDefault":"Default (unspecified)","desktop.subagentsDiscovered":"Discovered agents","desktop.subagentsPanelTitle":"Subagents","desktop.subagentsStatusRunning":"running","desktop.subagentsStatusCompleted":"done","desktop.subagentsStatusFailed":"failed","desktop.subagentsStatusStopped":"stopped","desktop.subagentsNoDesc":"(no description)","desktop.subagentsViewTitle":"Subagents","desktop.subagentsRunningBubble":"subagent(s) running","desktop.subagentsBackToFiles":"Files","desktop.subagentsEmpty":"No subagents running","desktop.subagentsBack":"Back","desktop.subagentsNotFound":"Subagent already ended","desktop.subagentsNoTranscript":"No transcript yet (subagent not writing one or already cleaned up)","desktop.subagentsWaitingFirstMessage":"Waiting for the subagent's first message…","desktop.backup":"Backup","desktop.backupExportTitle":"Export backup","desktop.backupExportDescription":"Package all global configuration: providers, models, credentials, settings, MCP servers, skills and local plugins.","desktop.backupIncludeSecrets":"Include API keys and credentials","desktop.backupSecretsWarning":"Warning: the backup will contain plaintext API keys (models.json) and OAuth credentials (auth.json). Keep it safe.","desktop.backupIncludeSessions":"Include session history","desktop.backupSessionsHint":"Sessions can be large and may contain sensitive conversation content.","desktop.backupExportButton":"Export backup","desktop.backupExporting":"Exporting…","desktop.backupExportFailed":"Backup export failed","desktop.backupImportTitle":"Import backup","desktop.backupImportButton":"Choose backup file","desktop.backupImportDescription":"Restore from a pi-backup zip. Paths are remapped to this machine and MCP commands are adapted per platform.","desktop.backupImportFailed":"Failed to read the backup file","desktop.backupRestoreFailed":"Restore failed","desktop.backupManifest":"Backup created","desktop.backupNoSecrets":"no credentials included","desktop.backupCategories":"Restore categories","desktop.backupCategorycore":"Core config","desktop.backupCategoryskills":"Skills","desktop.backupCategorypackages":"Plugins","desktop.backupCategorymcp":"MCP servers","desktop.backupCategorysessions":"Sessions","desktop.backupMcpServers":"MCP servers","desktop.backupNpmPackages":"npm packages","desktop.backupReinstallNpm":"Reinstall these npm packages after restore","desktop.backupReinstallNpmHint":"Install scripts run code shipped with the backup; only enable this if you trust its source","desktop.backupInstallModel":"Model for the install session","desktop.backupInstallSession":"Create install session","desktop.backupOpenSession":"Open session","desktop.backupInstallSessionFailed":"Failed to create the install session","desktop.backupRestoreButton":"Restore","desktop.backupRestoring":"Restoring…","desktop.backupRestoreReport":"Restore report","desktop.backupReportRestored":"Restored","desktop.backupReportRestart":"Needs restart to take effect","desktop.backupReportManual":"Needs manual attention","desktop.backupRestartHint":"Settings, models, credentials and MCP config take effect after restarting pi-web / pi.","desktop.importSessions":"Import Sessions","desktop.importSessionsDesc":"Import conversation history from other AI coding tools into pi-web. Currently supports Reasonix, with more tools coming soon.","desktop.comingSoon":"Coming soon","desktop.projects":"projects","desktop.importSelectProjects":"Select projects to import","desktop.importSelectAll":"Select all","desktop.importDeselectAll":"Deselect all","desktop.importMerged":"Merge into existing project","desktop.importNewProject":"New project","desktop.importExistingCount":"{count} existing","desktop.importStart":"Start import","desktop.importing":"Importing…","desktop.importDone":"Import complete","desktop.importedSummary":"Successfully imported {imported} sessions","desktop.importSkippedCount":"{skipped} skipped","desktop.importErrorsCount":"{errors} errors","desktop.importGeneratingTitles":"Generating titles…","desktop.importGenerateTitles":"Generate titles for imported sessions","desktop.importAgain":"Import again","desktop.importNoData":"No Reasonix data found. Make sure ~/.reasonix/projects/ exists with session files.","desktop.importFromReasonix":"from Reasonix","desktop.importFromCodex":"from Codex","desktop.builtinModelsTitle":"Model configuration","desktop.builtinModelsLoadFailed":"Failed to load models","desktop.builtinModelsEmpty":"No models available for this provider.","desktop.builtinModelsContext":"Context","desktop.builtinModelsMaxTokens":"Max output","desktop.builtinModelsReasoning":"Reasoning model","desktop.builtinModelsThinking":"Thinking levels (thinkingLevelMap)","desktop.builtinModelsDirty":"{count} unsaved change(s)","desktop.builtinModelsHide":"Hide this model","desktop.inputShortcut":"Input shortcut","desktop.inputShortcutDescription":"Choose how to send messages with the Enter key.","desktop.useCtrlEnter":"Ctrl+Enter to send","desktop.useCtrlEnterDescription":"Enter inserts a newline, Ctrl+Enter sends the message.","desktop.useEnter":"Enter to send","desktop.useEnterDescription":"Enter sends the message, Shift+Enter inserts a newline.","desktop.theme":"Theme","desktop.themes":"Themes","desktop.language":"Language","desktop.light":"Light","desktop.dark":"Dark","desktop.system":"System","desktop.english":"English","desktop.chinese":"简体中文","desktop.themeDescription":"Choose the appearance of Pi Web.","desktop.languageDescription":"Choose the display language for the interface.","desktop.colorScheme":"Color Scheme","desktop.openThemeFolder":"Open Pi theme folder","desktop.learnPiThemes":"Learn about Pi themes","desktop.defaultTheme":"Default","desktop.appearanceMode":"Appearance Mode","desktop.loadingThemes":"Loading themes…","desktop.borderVisibility":"Border Visibility","desktop.borderSubtle":"Subtle","desktop.borderBold":"Bold","desktop.noCustomThemes":"No custom themes installed.","desktop.noCustomThemesHint":"Add JSON files to","desktop.noCustomThemesHint2":"to see them here.","desktop.darkVariant":"Dark variant available","desktop.lightVariant":"Light variant available","desktop.switchToLight":"Switch to light mode","desktop.switchToDark":"Switch to dark mode","desktop.showSidebar":"Show sidebar","desktop.hideSidebar":"Hide sidebar","desktop.resizeSidebar":"Resize sidebar","desktop.resizeFilePanel":"Resize file panel","desktop.trustProject":"Trust project","desktop.trustingProject":"Trusting…","desktop.projectResourcesRestricted":"Project resources are restricted","desktop.projectSkillsRestricted":"Project skills are unavailable until you trust this project.","desktop.projectSkillInstallUnavailable":"Trust this project before installing project skills.","desktop.shellCommand":"Shell command","desktop.shellOutputLocal":"output stays local","desktop.shellOutputModel":"output is available to the model","desktop.runningShellCommand":"Running shell command…","desktop.loadFullOutput":"Load full output","desktop.download":"Download","desktop.trustProjectTitle":"Trust this project?","desktop.trustProjectBody":"Project extensions, skills, prompts, and package resources can execute code. Trust this project only if you recognize its contents.","desktop.minimize":"Minimize","desktop.maximize":"Maximize","desktop.restore":"Restore","desktop.close":"Close","desktop.viewFullHistory":"View full history","desktop.fullHistoryAvailableAfterSave":"Full history is available after the session is saved","desktop.systemPrompt":"System prompt","desktop.sessionInfo":"Session info","desktop.hideFilePanel":"Hide file panel","desktop.showFilePanel":"Show file panel","desktop.sessionInfoTitle":"Session Info","desktop.sessionInfoFile":"File","desktop.sessionInfoId":"ID","desktop.sessionInfoInMemory":"In-memory","desktop.sessionInfoMessages":"Messages","desktop.sessionInfoTokens":"Tokens","desktop.sessionInfoActiveTime":"Estimated Active Time","desktop.sessionInfoUser":"User","desktop.sessionInfoAssistant":"Assistant","desktop.sessionInfoToolCalls":"Tool Calls","desktop.sessionInfoToolResults":"Tool Results","desktop.sessionInfoTotal":"Total","desktop.sessionInfoInput":"Input","desktop.sessionInfoOutput":"Output","desktop.sessionInfoCacheRead":"Cache Read","desktop.sessionInfoCacheWrite":"Cache Write","desktop.sessionInfoCost":"Cost","desktop.sessionInfoCostOfficial":"Cost (official)","desktop.sessionInfoContext":"Context","desktop.balance":"Balance","desktop.balanceGranted":"Granted","desktop.balanceToppedUp":"Topped up","desktop.balanceUnavailable":"Balance unavailable","desktop.turnUsageTitle":"This turn","desktop.turnUsageByOfficialPrice":"priced at official rates","desktop.copyFilePath":"Copy file path","desktop.copySessionId":"Copy session ID","desktop.sendMessageForSessionInfo":"Send a message or run /session to load session info","desktop.selectSessionFromSidebar":"Select a session from the sidebar","desktop.getStarted":"Get Started","desktop.selectProjectDirectory":"Select a project directory from the sidebar","desktop.addModelsFromBottom":"Add models via the Models button at the bottom","desktop.loadingSession":"Loading session...","desktop.scrollToLoadEarlierMessages":"Scroll up to load earlier messages ({count} hidden)","desktop.scrollToBottom":"Scroll to latest","desktop.filesWritten":"Files changed","desktop.openWrittenFile":"Open {name}","desktop.taskRunning":"running","desktop.taskTodo":"todo","desktop.taskStatusHint":"Task progress for the current project — click to open the board","desktop.runningTool":"Running tool...","desktop.runningTools":"Running {tools}...","desktop.waitingForModel":"Waiting for model...","desktop.runningCommand":"Running command...","desktop.thinking":"Thinking...","desktop.extensionRequest":"extension request","desktop.extensionPanel":"Extension panel","desktop.cancel":"Cancel","desktop.confirm":"Confirm","desktop.submit":"Submit","desktop.queued":"Queued","desktop.queueMoveUp":"Move up","desktop.queueMoveDown":"Move down","desktop.queueRecallOne":"Recall to input","desktop.queueRemove":"Remove queued message","desktop.recalledEditing":"Editing a queued message. Sending puts it back at its original position.","desktop.steer":"Steer","desktop.followUp":"Follow-up","desktop.recallToInput":"Recall to input","desktop.recallQueuedMessages":"Remove all queued messages and put them back into the input box for editing","desktop.retrying":"Retrying","desktop.compacted":"Compacted","desktop.tokens":"tokens","desktop.saved":"saved","desktop.removeImage":"Remove image","desktop.loadingCommands":"Loading commands...","desktop.slashCommands":"Slash commands","desktop.tabOrEnter":"Tab / Enter","desktop.noSlashCommands":"No extension, prompt, or skill commands found","desktop.builtIn":"Built-in","desktop.extensions":"Extensions","desktop.prompts":"Prompts","desktop.commandSkills":"Skills","desktop.match":"match","desktop.matches":"matches","desktop.snippetMatches":"snippet matches","desktop.command":"command","desktop.commands":"commands","desktop.loadingFiles":"Loading files...","desktop.files":"Files","desktop.searchingAllFiles":"searching all files...","desktop.indexTruncated":"index truncated","desktop.searching":"Searching...","desktop.search":"Search","desktop.noMatchingFiles":"No matching files","desktop.steerOrQueueFollowUp":"Steer now / queue follow-up...","desktop.agentRunning":"Agent is running...","desktop.messageWithCommands":"Message... Type / for commands, @ for files","desktop.inputHistory":"Input history","desktop.quickChanges":"Quick Changes","desktop.changedFiles":"{count} changed files","desktop.imageAttachmentsCannotQueue":"Image attachments cannot be queued while the agent is running","desktop.injectMessageNow":"Interrupt the current run and inject this message now","desktop.queueMessageAfterFinish":"Queue this message after the agent finishes","desktop.attachImage":"Attach image","desktop.push":"Push current branch","desktop.pushOk":"Push succeeded","desktop.pushFailed":"Push failed","desktop.stash":"Stash","desktop.stashTitle":"Stash manager","desktop.stashPush":"Stash changes","desktop.stashList":"Stash list","desktop.stashEmpty":"No stashes","desktop.stashPop":"Pop","desktop.stashDrop":"Drop","desktop.stashMessagePlaceholder":"Stash message (optional)…","desktop.stashDone":"Done","desktop.attachMenu":"Choose input mode","desktop.attachUpload":"Upload file","desktop.attachUploadDesc":"Attach images and other files","desktop.attachReference":"Reference files","desktop.attachReferenceDesc":"Reference workspace files with @","desktop.attachSessions":"Reference sessions","desktop.attachSessionsDesc":"Reference past conversations with #","desktop.attachCommands":"Use commands","desktop.attachCommandsDesc":"Use commands and skills with /","desktop.planModeBadge":"Plan mode","desktop.planModeLabel":"Plan mode","desktop.planModeHint":"Plan mode: read-only analysis, no file modifications. Confirm execution or exit when done.","desktop.disableCompletionSound":"Disable completion sound","desktop.enableCompletionSound":"Enable completion sound","desktop.soundLabelOn":"Sound: On","desktop.soundLabelOff":"Sound: Off","desktop.changeReasoningLevel":"Change reasoning level: {level}","desktop.reasoningLevel":"Change reasoning level","desktop.moreControls":"More controls","desktop.more":"More","modes.collabNormal":"Normal","modes.collabPlan":"Plan","modes.collabGoal":"Goal","modes.tokenEconomy":"Lite","modes.tokenFull":"Balanced","modes.tokenDelivery":"Delivery","modes.approvalAsk":"Ask","modes.approvalAuto":"Auto","modes.approvalYolo":"Yolo","modes.collabNormalTitle":"Normal \xb7 act as you go","modes.collabNormalDesc":"Execute directly, advancing as you go","modes.collabPlanTitle":"Plan \xb7 confirm before executing","modes.collabPlanDesc":"Produce a plan first; tool execution still follows permissions","modes.collabGoalTitle":"Goal \xb7 keep pushing","modes.collabGoalDesc":"Work continuously until done or blocked","modes.tokenEconomyTitle":"Lite \xb7 fast, token-saving","modes.tokenEconomyDesc":"Less context, tools enabled on demand","modes.tokenFullTitle":"Balanced \xb7 daily general use","modes.tokenFullDesc":"Full tools, autonomous execution","modes.tokenDeliveryTitle":"Delivery \xb7 full verification","modes.tokenDeliveryDesc":"Mandatory acceptance, recheck and verify","modes.approvalAskTitle":"Require approval","modes.approvalAskDesc":"Writes and commands needing approval ask first","modes.approvalAutoTitle":"Auto-approve","modes.approvalAutoDesc":"Auto-execute what the policy allows","modes.approvalYoloTitle":"Yolo approve","modes.approvalYoloDesc":"Skip normal tool prompts (this session only)","desktop.goalRunning":"Goal","desktop.goalComplete":"Goal complete","desktop.goalBlocked":"Goal blocked","desktop.goalPaused":"Goal paused","desktop.goalNoProgress":"{n} no-progress turns","desktop.goalPause":"Pause goal","desktop.goalPauseShort":"Ⅱ","desktop.goalResume":"Resume goal","desktop.goalResumeShort":"▶","desktop.goalStop":"Stop goal","approval.title":"Tool approval required","approval.subtitle":"The agent wants to run this tool. Choose Allow to run it, or Deny to send a blocked result back.","approval.queued":"more waiting","approval.allow":"Allow","approval.deny":"Deny","approval.denyWithReason":"Deny with reason","approval.hideReason":"Hide reason","approval.reasonPlaceholder":"Reason shown to the agent (optional)","desktop.stopCompaction":"Stop compaction","desktop.compactContext":"Compact context","desktop.compacting":"Compacting...","desktop.compact":"Compact","desktop.changeToolPreset":"Change tool preset: {preset}","desktop.toolPreset":"Change tool preset","desktop.sendMessage":"Send message","desktop.stopAgent":"Stop agent","desktop.stop":"Stop","desktop.collapseControls":"Collapse controls","desktop.usePiDefault":"Use pi default","desktop.reasoningOff":"Reasoning off","desktop.minimalReasoning":"Minimal reasoning","desktop.lowReasoning":"Low reasoning","desktop.mediumReasoning":"Medium reasoning","desktop.highReasoning":"High reasoning","desktop.extraHighReasoning":"Extra-high reasoning","desktop.maxReasoning":"Max reasoning","desktop.noToolsReadOnly":"No tools, read-only","desktop.fourBuiltInTools":"4 built-in tools","desktop.allBuiltInTools":"All built-in tools","desktop.toolOff":"off","desktop.toolDefault":"default","desktop.toolFull":"full","desktop.thinkingAuto":"auto","desktop.thinkingOff":"off","desktop.thinkingMinimal":"minimal","desktop.thinkingLow":"low","desktop.thinkingMedium":"medium","desktop.thinkingHigh":"high","desktop.thinkingExtraHigh":"xhigh","desktop.thinkingMax":"max","desktop.compactCommandDescription":"Compress context, optionally with instructions","desktop.reloadCommandDescription":"Reload extensions, skills, prompts, and tools","desktop.nameCommandDescription":"Set the session display name","desktop.sessionCommandDescription":"Show session message, token, and cost stats","desktop.copyCommandDescription":"Copy the last assistant message","desktop.selectModel":"Select model","desktop.selectProject":"Select project","desktop.selectProjectFirst":"Select a project first","desktop.noMatchingProjects":"No matching projects","desktop.noProjectsYet":"No projects yet","desktop.useDefaultDirectory":"Use default directory","desktop.customPath":"Custom path…","desktop.projectPathPlaceholder":"/path/to/project","desktop.filterProjects":"Filter projects…","desktop.searchProjects":"Search projects…","desktop.recentProjects":"Recent Projects","desktop.editProjectAlias":"Rename project","desktop.projectAliasPlaceholder":"Add a remark for this project…","desktop.quickWorkspace":"Quick workspace","desktop.selectFolder":"Select folder","desktop.checking":"Checking…","desktop.open":"Open","directoryPicker.selectDirectory":"Select directory","directoryPicker.goToParent":"Go to parent directory","directoryPicker.loadingDirectories":"Loading directories…","directoryPicker.noSubdirectories":"No subdirectories","directoryPicker.noMatchingDirectories":"No matching subdirectories","directoryPicker.filterPlaceholder":"Filter subdirectories…","directoryPicker.selectCurrentDirectory":"Select current directory","directoryPicker.selectThisFolder":"Select this folder","directoryPicker.noDrives":"No drives found","desktop.switchWorktree":"Switch worktree","desktop.switchWorktreeWithPath":"Switch worktree: {path}","desktop.openRepoRoot":"Open repo root","desktop.openRepoRootDescription":"Open the repository root to manage worktrees.","desktop.gitRepoRootOnly":"Git repo root only","desktop.gitRepoRootOnlyDescription":"Worktrees are available in Git repository roots.","desktop.checkingWorktrees":"Checking worktrees for this directory.","desktop.worktreesLoading":"Worktrees...","desktop.createWorktree":"Create a worktree checkout for a branch","desktop.newWorktree":"New worktree…","desktop.branchName":"branch name","desktop.creating":"Creating…","desktop.create":"Create","desktop.main":"main","desktop.removeWorktree":"Remove worktree checkout {path}; the branch is kept","desktop.uncommittedChanges":"Uncommitted changes. Force remove checkout?","desktop.force":"Force","desktop.sessions":"Sessions","desktop.newSession":"New","desktop.newSessionIn":"New session in {cwd}","desktop.refresh":"Refresh","desktop.loading":"Loading...","desktop.noModels":"No models available","desktop.noSessionsFound":"No sessions found","desktop.explorer":"Explorer","desktop.uploadFiles":"Upload files","desktop.uploadFilesToProjectRoot":"Upload files to project root","desktop.refreshExplorer":"Refresh explorer","desktop.agentRunningLabel":"Agent running","desktop.newActivity":"New activity","desktop.newSessionActivity":"New session activity","desktop.deleteSession":"Delete {title}?","desktop.delete":"Delete","desktop.deleteWithShift":"Delete (Shift-click to skip confirmation)","desktop.openingWorkspace":"Opening workspace…","desktop.unableToOpenWorkspace":"Unable to open this workspace","desktop.rename":"Rename","desktop.titleGenerationFailed":"Title generation failed","desktop.retryTitleGeneration":"Retry title generation","desktop.retry":"Retry","desktop.changeTitleModel":"Change model","desktop.pastedLabel":"[Pasted text #{id} \xb7 {lines} lines]","desktop.pastedShowPreview":"Preview pasted text","desktop.pastedHidePreview":"Collapse pasted text preview","desktop.pastedRemove":"Remove pasted text","desktop.generateTitle":"Generate title","desktop.generateAllTitles":"Generate titles for all sessions in this project","desktop.generatingTitlesProgress":"Generating titles… {done}/{total}","desktop.generatingTitle":"Generating title...","desktop.titleNeedsMessages":"No messages to generate a title from","desktop.expandForks":"Expand forks","desktop.collapseForks":"Collapse forks","desktop.sessionViewList":"List","desktop.sessionViewGroups":"Groups","desktop.searchSessions":"Search sessions, branches...","desktop.noSearchResults":"No matching sessions","desktop.pinned":"Pinned","desktop.today":"Today","desktop.yesterday":"Yesterday","desktop.older":"Older","desktop.collapseGroup":"Collapse","desktop.expandGroup":"Expand","desktop.pin":"Pin to top","desktop.unpin":"Unpin","desktop.forkedFrom":"Forked from {title}","desktop.messagesCount":"{count} msgs","desktop.worktree":"Worktree: {cwd}","desktop.justNow":"just now","desktop.minutesAgo":"{count}m ago","desktop.hoursAgo":"{count}h ago","desktop.daysAgo":"{count}d ago","desktop.closeTab":"Close","desktop.closeTabWithLabel":"Close {label}","desktop.modelsHideApiKey":"Hide API key","desktop.modelsShowApiKey":"Show API key","desktop.modelsInheritNone":"— inherit / none —","desktop.modelsProvider":"Provider","desktop.modelsProviderName":"Provider name","desktop.modelsBaseUrl":"Base URL","desktop.modelsApiKey":"API Key","desktop.modelsApiKeyHelp":"Prefix with ! to run a shell command, or use an env var name","desktop.modelsApiKeyPlaceholder":"ENV_VAR_NAME, !shell-command, or literal key","desktop.modelsApi":"API","desktop.modelsDefault":"Default","desktop.modelsDisabled":"Disabled","desktop.modelsCustom":"Custom","desktop.modelsModelSection":"Model","desktop.modelsTestingConnection":"Testing model connection...","desktop.modelsConnected":"Connected","desktop.modelsFailed":"Failed","desktop.modelsTestConnection":"Test model connection","desktop.modelsTesting":"Testing…","desktop.modelsTest":"Test","desktop.modelsOk":"OK","desktop.modelsRemove":"Remove","desktop.modelsIdRequired":"ID *","desktop.modelsName":"Name","desktop.modelsDisplayName":"Display name","desktop.modelsApiOverride":"API override","desktop.modelsReasoningThinking":"Reasoning / thinking","desktop.modelsImageInput":"Image input","desktop.modelsDeepSeekCompat":"DeepSeek thinking compat","desktop.modelsThinkingLevelMap":"Thinking level map","desktop.modelsClearAll":"clear all","desktop.modelsDiscoveryFetching":"Importing models…","desktop.modelsDiscoveryFetch":"Import models…","desktop.modelsDiscoveryFilterPlaceholder":"Filter {count} models…","desktop.modelsDiscoveryFilter":"Filter upstream models","desktop.modelsDiscoverySelectShown":"Select shown","desktop.modelsDiscoveryNoMatches":"No matching models.","desktop.modelsDiscoveryAdded":"added","desktop.modelsDiscoveryShowing":"Showing first {shown} of {total}","desktop.modelsDiscoveryFetched":"{count} models fetched","desktop.modelsDiscoveryAddSelected":"Add selected","desktop.modelsDiscoveryAddSelectedCount":"Add selected ({count})","desktop.modelsCatalogSource":"source: models.dev ↗","desktop.modelsCatalogFilling":"Filling details…","desktop.modelsCatalogFill":"Fill model details","desktop.modelsCatalogFilled":"{count} fields filled","desktop.modelsCatalogNoEmptyFields":"No empty fields to fill","desktop.modelsCatalogNoExactMatch":"No exact models.dev match","desktop.modelsCatalogPriceProvider":"Price matched Provider {provider}","desktop.modelsCatalogPriceBaseUrl":"Price matched Base URL to {provider}","desktop.modelsCatalogPriceConsensus":"Price agreed by {support}/{total} records","desktop.modelsCatalogPriceUnreliable":"No reliable price found","desktop.modelsCatalogUndo":"Undo","desktop.modelsContextWindow":"Context window (tokens)","desktop.modelsMaxOutputTokens":"Max output tokens","desktop.modelsCostPerMillionTokens":"Cost (per million tokens)","desktop.modelsSubscription":"Subscription","desktop.titleModel":"Title generation model","desktop.titleModelDescription":'Model used to auto-generate session titles. Keep "Follow session model" to use each session\'s own model.',"desktop.titleModelFollowSession":"Follow session model (default)","desktop.titleModelInvalid":"no longer imported — title generation falls back to the session model","desktop.titleModelSaved":"Saved","desktop.titleModelSaveError":"Failed to save title model setting","desktop.modelsNotConnected":"not connected","desktop.modelsAlreadyConnected":"Already connected. You can re-login or disconnect.","desktop.modelsConnectAccount":"Connect your {provider} account.","desktop.modelsOpeningBrowser":"Opening browser…","desktop.modelsCompleteSignIn":"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.","desktop.modelsBrowserDidNotOpen":"If the browser window did not open,","desktop.modelsOpenLoginPage":"click here to open the login page","desktop.modelsEnterValue":"Enter value…","desktop.modelsOpenVerificationPage":"Open the verification page and enter this code:","desktop.modelsExpiresInMinutes":"Expires in {count} minutes.","desktop.modelsConnectedSuccessfully":"Connected successfully.","desktop.modelsReLogin":"Re-login","desktop.modelsLogin":"Login","desktop.modelsDisconnect":"Disconnect","desktop.modelsConnectionLost":"Connection lost","desktop.modelsAuthenticationStateChanged":"Authentication state changed. Please refresh and try again.","desktop.modelsVerifying":"Verifying…","desktop.modelsContinuing":"Continuing…","desktop.modelsServerError":"Server error {status}","desktop.modelsNetworkError":"Network error","desktop.modelsConfigured":"configured","desktop.modelsNotConfigured":"not configured","desktop.modelsApiKeyStored":"API key is stored. Enter a new key below to replace it, or disconnect to remove it.","desktop.modelsEnableModels":"Enter your {provider} API key to enable {count} {models}.","desktop.modelsSingular":"model","desktop.modelsPlural":"models","desktop.modelsEnterNewKey":"Enter new key to replace…","desktop.modelsSaving":"Saving…","desktop.modelsSaved":"Saved","desktop.modelsRemoving":"Removing…","desktop.modelsSearchProviders":"Search providers…","desktop.modelsNoProvidersMatch":"No providers match","desktop.modelsCompatibleProvider":"OpenAI / Anthropic compatible","desktop.modelsCustomEndpointFormat":"Custom endpoint format","desktop.modelsSubscriptions":"Subscriptions","desktop.modelsCount":"{count} models","desktop.modelsLoading":"Loading…","desktop.modelsNewModel":"new model","desktop.modelsAddModel":"+ model","desktop.modelsAddProvider":"+ Add provider","desktop.modelsSelectProviderOrModel":"Select a provider or model","desktop.modelsClose":"Close models","desktop.modelsSave":"Save","desktop.searchModels":"Search models…","desktop.noModelsMatch":"No matching models","desktop.global":"global","desktop.project":"project","desktop.path":"path","desktop.addPlugin":"Add plugin","desktop.addPluginTitle":"Add Plugin","desktop.pluginSource":"Source","desktop.install":"Install","desktop.installing":"Installing...","desktop.examples":"Examples","desktop.disabled":"Disabled","desktop.filtered":"filtered","desktop.noResources":"No resources","desktop.packageDisabled":"Package disabled","desktop.noResolvedResources":"No resolved resources","desktop.unknown":"Unknown","desktop.installedVersion":"installed {version}","desktop.configuredVersion":"configured {version}","desktop.enablePackage":"Enable package","desktop.disablePackage":"Disable package","desktop.update":"Update","desktop.updating":"Updating...","desktop.reloadSession":"Reload session","desktop.reloading":"Reloading...","desktop.reloadCurrentSession":"Reload current session","desktop.openSessionToReload":"Open a session to reload","desktop.remove":"Remove","desktop.removing":"Removing...","desktop.status":"Status","desktop.version":"Version","desktop.package":"Package","desktop.resources":"Resources","desktop.installedPath":"Installed path","desktop.notFound":"Not found","desktop.cwd":"Cwd","desktop.resolvedResources":"Resolved Resources","desktop.packageRemoved":"Package removed.","desktop.packageInstalled":"Package installed.","desktop.packageUpdated":"Package updated.","desktop.packageDisabledMessage":"Package disabled.","desktop.packageEnabled":"Package enabled.","desktop.sessionReloaded":"Session reloaded.","desktop.noPluginsConfigured":"No plugins configured","desktop.selectPackage":"Select a package","desktop.diagnosticsCount":"{count} diagnostic{suffix}","desktop.pluginResourceTotals":"{extensions} ext \xb7 {skills} skills \xb7 {prompts} prompts \xb7 {themes} themes","desktop.extensionsCount":"{count} ext","desktop.skillsCount":"{count} skills","desktop.promptsCount":"{count} prompts","desktop.themesCount":"{count} themes","desktop.addSkill":"Add skill","desktop.addSkillTitle":"Add Skill","desktop.skillSearchPlaceholder":"e.g. react, testing, deploy","desktop.noSkillsFound":"No skills found","desktop.skillSearchHint":"Search skills.sh to discover and install skills for your agent.","desktop.visibleInModelPrompt":"Visible in model prompt — click to disable","desktop.hiddenFromModelPrompt":"Hidden from model prompt — click to enable","desktop.dormant":"Dormant","desktop.hiddenButInvocable":"Hidden from the model, still manually invocable","desktop.check":"Check","desktop.upToDate":"Up to date","desktop.automaticChecksUnavailable":"Automatic checks unavailable","desktop.checkFailed":"Check failed","desktop.name":"Name","desktop.description":"Description","desktop.selectSkill":"Select a skill","desktop.checkUpdates":"Check updates","desktop.updateAvailable":"Update available","desktop.installed":"Installed","desktop.updatesCount":"{count} update{suffix}","desktop.downloadFile":"Download file","desktop.loadingFile":"Loading...","desktop.noChanges":"No changes","desktop.unchangedLines":"... {count} unchanged lines ...","desktop.lines":"{count} lines","desktop.mentionFile":"Mention file","desktop.mentionSelectedLines":"Mention selected lines {start}-{end}","desktop.source":"Source","desktop.diff":"Diff","desktop.enableWordWrap":"Enable word wrap","desktop.disableWordWrap":"Disable word wrap","desktop.wrap":"wrap","desktop.code":"Code","desktop.preview":"Preview","desktop.raw":"Raw","desktop.htmlPreview":"HTML preview","desktop.image":"image","desktop.audio":"audio","desktop.docxPreview":"docx preview","desktop.failedToLoadImage":"Failed to load image","desktop.failedToLoadAudio":"Failed to load audio","desktop.docxTooLargeForPreview":"DOCX too large for preview (>10MB)","desktop.previewFile":"Preview {file}","desktop.branches":"Branches","desktop.noActiveSession":"No active session","desktop.sessionHasNoBranches":"No branches yet — use Edit from here or Fork on a message to create one","desktop.copyMessage":"Copy message","desktop.copyPlainText":"Copy as plain text","desktop.createTaskFromMessage":"Create task from message","desktop.editFromHere":"Edit from here — branches within this session","desktop.creatingNewSession":"Creating new session…","desktop.newSessionFromHere":"New session — creates an independent copy from here","desktop.estimatedStreamingTokenCount":"Estimated token count while streaming","desktop.tokensPerSecond":"{count} t/s","desktop.thinkingContentUnavailable":"Thinking content unavailable","desktop.loadingThinking":"Loading thinking...","desktop.conversationCompacted":"Conversation compacted","desktop.compactionSummaryDescription":"The conversation history before this point was compacted into the following summary:","desktop.noSummary":"(no summary)","desktop.fileContext":"File context: {context}","desktop.readFilesCount":"{count} read","desktop.modifiedFilesCount":"{count} modified","desktop.modifiedFiles":"Modified files","desktop.readFiles":"Read files","desktop.hiddenExtensionMessage":"hidden extension message","desktop.noMessage":"(no message)","desktop.showExtensionMessage":"Show extension message","desktop.copied":"Copied","desktop.copy":"Copy","desktop.collapse":"Collapse","desktop.expand":"Expand","desktop.hideDetails":"Hide details","desktop.showDetails":"Show details","desktop.before":"Before","desktop.after":"After","desktop.noOutput":"(no output)","desktop.extension":"extension","desktop.assistant":"assistant","desktop.favorites":"Favorites","desktop.favorite":"Favorite","desktop.unfavorite":"Unfavorite","desktop.processStepThinking":"Thinking","desktop.processStepFileRead":"Read","desktop.processStepFileCreate":"Create","desktop.processStepFileEdit":"Edit","desktop.processStepFileDelete":"Delete","desktop.processStepSearch":"Search","desktop.processStepFind":"Find","desktop.processStepList":"List","desktop.processStepRead":"Read","desktop.processStepFetch":"Fetch","desktop.processStepDelete":"Delete","desktop.processStepCopy":"Copy","desktop.processStepCommand":"Run","desktop.processStepTool":"Tool","desktop.processStepTodo":"Todo","desktop.processStepArtifact":"Artifact","desktop.processStepCompaction":"Compaction","desktop.processStepError":"Error","desktop.processWorking":"Working...","desktop.processUsed":"Used {summary}","desktop.processToolCount":"{count} tool","desktop.processToolsCount":"{count} tools","desktop.processFailedCount":" ({failed} failed)","desktop.processThoughtCount":"{count} thought","desktop.processThoughtsCount":"{count} thoughts","desktop.processThoughtDone":"Thought {duration}s","desktop.processThoughtDoneNoDuration":"Thought","desktop.processCustomCount":"{count} event","desktop.processCustomsCount":"{count} events","desktop.processCompleted":"Process complete","desktop.processOutput":"Process output","desktop.processTabMode":"Tab mode","desktop.processTimelineMode":"Timeline mode","desktop.processFailedStep":"failed","desktop.markdownPreviewAvailableAfterStreaming":"Preview available after streaming","desktop.markdownPreviewMermaidDiagram":"Preview Mermaid diagram","desktop.markdownInvalidMermaidDiagram":"Invalid Mermaid diagram","desktop.markdownRenderingMermaidDiagram":"Rendering Mermaid diagram","desktop.openMermaidViewer":"Open Mermaid viewer","desktop.mermaidDiagram":"Mermaid diagram","desktop.mermaidViewer":"Mermaid diagram viewer","desktop.zoomPanHint":"Drag to pan \xb7 Scroll to zoom","desktop.selectText":"Select text","desktop.zoomOut":"Zoom out","desktop.resetZoom":"Reset to 100% (fit)","desktop.zoomIn":"Zoom in","desktop.fitToViewport":"Fit to viewport","desktop.quoteReply":"Quote reply","desktop.quoteReplyHint":"Click to quote reply","desktop.openFile":"Open","desktop.queueRecoveryTitle":"Recover queued messages","desktop.queueImportTitle":"Imported queued messages","desktop.queueRecoveryDescription":"These messages were saved before the previous server session ended. Choose what to re-queue; nothing is sent automatically.","desktop.queueImportDescription":"Choose which imported messages to re-queue. Nothing is sent automatically.","desktop.selectAll":"Select all","desktop.selectNone":"Select none","desktop.import":"Import","desktop.queueImages":"Image attachment","desktop.queueNoText":"(image-only message)","desktop.queueExported":"Exported {count} message(s)","desktop.queueImportEmpty":"No valid queued messages found","desktop.queueImported":"Imported {count} message(s) for review","desktop.dismiss":"Dismiss","desktop.discard":"Discard","desktop.requeue":"Re-queue","desktop.requeueAndContinue":"Re-queue & continue","desktop.markdownPlainText":"text","desktop.hideTaskBoard":"Hide task board","desktop.showTaskBoard":"Show task board","tasks.actionArchive":"Archive","tasks.actionCancel":"Cancel","tasks.actionEdit":"Edit","tasks.actionMerge":"Merge","tasks.stashDone":"Changes stashed successfully","tasks.actionRequeue":"Re-queue","tasks.actionRetry":"Retry","tasks.actionReturn":"Return with feedback","tasks.actionStart":"Start","tasks.actionComplete":"Complete","tasks.actionUnarchive":"Unarchive","tasks.actionViewSession":"View session","tasks.allFolders":"All projects","tasks.archiveAllDone":"Archive all","tasks.badgeCleanupFailed":"cleanup failed","tasks.badgeWorktreeKept":"worktree kept","tasks.beta":"Beta","tasks.cancelDescription":"The task will stop. You can leave a reason for whoever requeues it later (optional).","tasks.cancelKeep":"Keep task","tasks.cancelReasonLabel":"Cancel reason (optional)","tasks.cancelReasonPlaceholder":"e.g. wrong approach, requirements changed…","tasks.cancelSubmit":"Cancel task","tasks.cancelTitle":"Cancel task","tasks.changedFiles":"Changed files","tasks.colAttention":"Attention","tasks.colDone":"Done","tasks.colInProgress":"In progress","tasks.colTodo":"Todo","tasks.delete":"Delete","tasks.deleteConfirm":"Delete","tasks.deleteTemplate":"Delete template","tasks.deleteWorktree":"Also delete the worktree","tasks.diff":"Diff","tasks.dropToStart":"Drop to start","tasks.editTitle":"Edit task","tasks.empty":"No tasks yet","tasks.emptyColAttention":"Nothing needs you","tasks.emptyColDone":"Nothing completed yet","tasks.emptyColInProgress":"Nothing running","tasks.emptyColTodo":"No pending tasks","tasks.emptyHint":"Create a task and the board walks it through execution — start it and a worktree branch runs the agent to completion.","tasks.errorView":"View","tasks.event_archived":"archived","tasks.event_canceled":"canceled","tasks.event_created":"created","tasks.event_failed":"failed","tasks.event_interrupted":"interrupted","tasks.event_merge_failed":"merge failed","tasks.event_merge_requested":"merge requested","tasks.event_merged":"merged","tasks.event_merging":"merging","tasks.event_preflight_failed":"preflight failed","tasks.event_preflight_passed":"preflight passed","tasks.event_preflight_start":"preflight running","tasks.event_preparing":"preparing","tasks.event_queued":"queued","tasks.event_recovered":"recovered","tasks.event_requeued":"re-queued","tasks.event_return_feedback":"feedback","tasks.event_returned":"returned","tasks.event_review":"review","tasks.event_started":"started","tasks.event_unarchived":"unarchived","tasks.event_updated":"updated","tasks.fieldProject":"Project","tasks.fieldPrompt":"Prompt","tasks.fieldPromptPlaceholder":"Describe the work the agent should complete…","tasks.fieldTitle":"Title","tasks.fieldTitlePlaceholder":"Short title for the task","tasks.filter":"Filter","tasks.loading":"Loading…","tasks.mergeAutoMessage":"Let the agent write the commit message","tasks.mergeConfirm":"Merge","tasks.mergeDeleteWorktree":"Delete the worktree after merging","tasks.mergeManualMessage":"Provide a commit message","tasks.mergeMessagePlaceholder":"Commit message…","tasks.mergeStrategyMerge":"Merge commit","tasks.mergeStrategySquash":"Squash","tasks.mergeTitle":"Merge task","tasks.completeDeleteWorktree":"Delete worktree on completion","tasks.completeDescription":"This task produced no file changes, so there is nothing to merge. Confirm to mark it done.","tasks.completeSubmit":"Complete","tasks.completeTitle":"Complete task","tasks.followUpPlaceholderRequeue":"Note for the agent (optional)…","tasks.followUpPlaceholderRetry":"Note for the agent (optional)…","tasks.actionAddNote":"Note (optional)","tasks.restartDescription":"The note is injected into the next run's prompt (optional).","tasks.restartTitleRequeue":"Requeue","tasks.restartTitleRetry":"Retry","tasks.planReviewTitle":"Plan complete","tasks.planReviewDescription":"The plan-mode analysis has finished. Confirm to execute the plan, send suggestions for another pass, or exit plan mode.","tasks.planReviewShowPlan":"View plan","tasks.planReviewHidePlan":"Collapse plan","tasks.planReviewExecute":"Execute","tasks.planReviewExecutePrompt":"Please execute the following plan:\n\n{plan}","tasks.planReviewSuggest":"Suggest","tasks.planReviewSendFeedback":"Send suggestions","tasks.planReviewFeedbackLabel":"Suggestions (sent back to the agent to refine the plan)","tasks.planReviewFeedbackPlaceholder":"e.g. add risk analysis first, split into smaller steps…","tasks.planReviewExit":"Exit plan mode","tasks.metaCommit":"Commit","tasks.metaCreated":"Created","tasks.metaProject":"Project","tasks.new":"New task","tasks.newTitle":"New task","tasks.noDiff":"No diff available","tasks.noEvents":"No events yet","tasks.notifyFailed":"{title} failed","tasks.notifyReview":"{title} is ready for review","tasks.returnPlaceholder":"Feedback for the agent…","tasks.returnSubmit":"Send back","tasks.save":"Save","tasks.saveAsTemplate":"Save as template","tasks.sessionFile":"Session file","tasks.sessionHint":"The task's agent conversation is stored like any other session. Open it from the sessions list to read or continue it.","tasks.sessionId":"Session id","tasks.sessionTitle":"Task session","tasks.settingsAutoProcess":"Auto-process queued tasks","tasks.settingsDeleteWorktree":"Delete worktree after merge (default)","tasks.settingsInitCommand":"Init command (run in the worktree before the agent)","tasks.settingsInitPlaceholder":"e.g. pnpm install","tasks.settingsMaxConcurrent":"Max concurrent tasks (0 = unlimited)","tasks.settingsMergeStrategy":"Merge strategy","tasks.settingsNoProject":"Create a task first to pick a project.","tasks.settingsPreflightCommand":"Preflight command (acceptance check)","tasks.settingsPreflightPlaceholder":"e.g. npm test","tasks.settingsProject":"Project","tasks.settingsReset":"Reset to defaults","tasks.settingsStagePrompts":"Stage prompts (extra instructions)","tasks.settingsTitle":"Task settings","tasks.showArchived":"Show archived","tasks.showCanceled":"Show canceled","tasks.stage_merge":"Merge","tasks.stage_retry":"Retry","tasks.stage_return":"Return","tasks.stage_work":"Work","tasks.startAll":"Start all","tasks.statusAwaitingInput":"Awaiting input","tasks.statusCanceled":"Canceled","tasks.statusDone":"Done","tasks.statusFailed":"Failed","tasks.statusInterrupted":"Interrupted","tasks.statusMerging":"Merging","tasks.statusPreparing":"Preparing","tasks.statusQueued":"Queued","tasks.statusReview":"Review","tasks.statusRunning":"Running","tasks.statusTodo":"Todo","tasks.templateNamePlaceholder":"Template name…","tasks.templates":"Templates","tasks.timeline":"Timeline","tasks.title":"Tasks","tasks.attentionBadge":"needs you"}}),i({id:"zh-CN",label:"简体中文",messages:{"i18n.close":"关闭","i18n.cancel":"取消","i18n.checking":"正在检查…","desktop.settings":"设置","desktop.settingsSections":"设置分类","desktop.closeSettings":"关闭设置","desktop.display":"显示","desktop.chat":"聊天","desktop.models":"模型","desktop.skills":"技能","desktop.plugins":"插件","desktop.opencodeZen":"OpenCode Zen","desktop.proxy":"代理","desktop.proxyEnable":"启用代理","desktop.proxyProtocol":"协议","desktop.proxyHost":"主机","desktop.proxyPort":"端口","desktop.proxyUsername":"用户名(可选)","desktop.proxyPassword":"密码(可选)","desktop.proxyNoProxy":"绕过代理(逗号分隔,可选)","desktop.proxySave":"保存","desktop.proxySaving":"保存中…","desktop.proxyTest":"测试连接","desktop.proxyTesting":"测试中…","desktop.proxySaved":"代理配置已保存","desktop.proxySaveFailed":"保存失败","desktop.proxyTestSuccess":"连接成功","desktop.proxyTestFailed":"连接失败","desktop.proxyUnsaved":"有未保存的更改","desktop.features":"功能","desktop.logs":"日志","desktop.snippets":"片段","desktop.snippetsDesc":"常用代码/文本片段,输入 # 号即可补全插入","desktop.snippetNew":"新增片段","desktop.snippetName":"名称","desktop.snippetContent":"内容","desktop.snippetSave":"保存","desktop.snippetEdit":"编辑","desktop.snippetDelete":"删除","desktop.snippetEmpty":"还没有片段,先新增一个吧。","desktop.snippetNameRequired":"请输入片段名称","desktop.snippetHint":"在输入框输入 #名称 即可弹出补全,Enter 展开为片段内容。","desktop.logsAllCodes":"全部错误码","desktop.logsAllSources":"全部来源","desktop.logsSearch":"搜索错误日志","desktop.logsClear":"清空日志","desktop.logsCopy":"复制日志","desktop.logsEmpty":"暂无错误日志","desktop.mcpVisionTitle":"DeepSeek Vision 视觉模块","desktop.mcpVisionDesc":"deepseek-vision 视觉模块(图像分析 / OCR)的独立配置,MCP 注册与模型配置均可在此修改。","desktop.mcpVisionRegistered":"已注册","desktop.mcpVisionNotRegistered":"未注册","desktop.mcpVisionRegistration":"MCP 注册","desktop.mcpVisionCommand":"命令","desktop.mcpVisionCommandRequired":"命令不能为空","desktop.mcpVisionLifecycle":"生命周期","desktop.mcpVisionTransport":"传输方式","desktop.mcpVisionTransportFixed":"stdio(固定)","desktop.mcpVisionSaveReg":"保存注册","desktop.mcpVisionSavedReg":"注册已保存 — 新开会话或重启 pi 后生效","desktop.mcpVisionRemove":"从 MCP 配置移除","desktop.mcpVisionRemoved":"已移除注册","desktop.mcpVisionModelConfig":"模型配置","desktop.mcpVisionModelNote":"模型配置保存后立即写入 .env,点击“重启服务器”即可立即生效。","desktop.mcpVisionProvider":"Provider","desktop.mcpVisionBaseUrl":"Base URL","desktop.mcpVisionApiKey":"API Key","desktop.mcpVisionModel":"视觉模型","desktop.mcpVisionMaxTokens":"最大输出 tokens","desktop.mcpVisionSaveModel":"保存模型配置","desktop.mcpVisionSavedModel":"模型配置已保存","desktop.mcpVisionNameReserved":"该名称由内置的 DeepSeek Vision 配置使用,请换一个名称。","desktop.mcpVisionRestart":"重启服务器(立即生效)","desktop.mcpVisionRestarting":"重启中…","desktop.mcpVisionRestarted":"已发送重启指令,稍候生效","desktop.mcpVisionRestartTitle":"重启 deepseek-vision 服务器,使 .env 配置立即生效","desktop.mcpVisionRestartNoSession":"请先打开一个会话,才能重启服务器","desktop.applyNow":"立即生效","desktop.applyNowApplying":"重载中…","desktop.applyNowDone":"已重载,改动已生效","desktop.applyNowTitle":"重载当前会话,使改动立即生效(无需重启 pi)","desktop.applyNowNoSession":"请先打开一个会话,才能立即生效","desktop.featuresDesc":"管理 Pi Web 的可选功能。关闭后相关入口将不再显示。","desktop.featuresTasksBoard":"任务看板","desktop.featuresTasksBoardDesc":"在顶部工具栏显示任务看板入口,用于管理多项目任务。","desktop.featuresLoading":"加载中…","desktop.featuresSaving":"保存中…","desktop.featuresCollabDefault":"默认任务模式","desktop.featuresCollabDefaultDesc":"新建对话默认的协作模式(常规 / 计划 / 目标)","desktop.featuresTokenDefault":"默认运行档位","desktop.featuresTokenDefaultDesc":"新建对话默认的档位(轻量 / 均衡 / 交付)","desktop.featuresApprovalDefault":"默认工具权限","desktop.featuresApprovalDefaultDesc":"新建对话默认的工具权限(批准 / 自动 / Yolo)","desktop.usage":"用量","desktop.usageSession":"当前会话","desktop.usageGlobal":"全局","desktop.usageContext":"上下文占用 {used} / {window} tokens","desktop.usageContextHint":"当前会话实时上下文占用","desktop.usageNoSessionData":"当前会话暂无用量数据","desktop.usageNoSession":"未打开会话","desktop.usageTotal":"预估总用量","desktop.usageMessages":"消息数","desktop.usageMessagesHint":"全部会话","desktop.usageSessions":"个会话","desktop.usageDaily":"每日用量趋势","desktop.usageTopSessions":"用量最高的会话","desktop.usageNoData":"暂无数据","desktop.mcp":"MCP","desktop.mcpServers":"MCP 服务器","desktop.mcpAddServer":"添加服务器","desktop.mcpNewServer":"新增 MCP 服务器","desktop.mcpEditServer":'编辑 MCP 服务器 "{name}"',"desktop.mcpRestartNote":"MCP 服务器在 pi 启动时加载,此处修改需重启 pi 后生效。","desktop.mcpEmpty":"尚未配置 MCP 服务器 — 添加一个即可向 Agent 暴露工具。","desktop.mcpEmptyOther":"未配置其他 MCP 服务器 — DeepSeek Vision 的配置见上方卡片。","desktop.mcpServerName":"名称","desktop.mcpCommand":"命令","desktop.mcpArgs":"参数(每行一个)","desktop.mcpTransport":"传输方式","desktop.mcpLifecycle":"生命周期","desktop.mcpRequestTimeoutMs":"请求超时(毫秒)","desktop.mcpEnv":"环境变量(JSON)","desktop.mcpEdit":"编辑","desktop.mcpDelete":"删除","desktop.mcpSave":"保存","desktop.saving":"保存中…","desktop.mcpCancel":"取消","desktop.mcpSavedRestart":"已保存 — 重启 pi 后生效。","desktop.subagents":"子代理","desktop.subagentsDesc":"子代理配置。适用于 pi-subagents 管理的运行;重启 pi 后生效。","desktop.subagentsMaxConcurrent":"最大并发数","desktop.subagentsDefaultMaxTurns":"默认最大轮数(0 = 不限)","desktop.subagentsGraceTurns":"宽限轮数","desktop.subagentsJoinMode":"默认加入模式","desktop.subagentsWidgetMode":"Widget 模式","desktop.subagentsToolDescMode":"工具描述模式","desktop.subagentsScheduling":"启用调度","desktop.subagentsSchedulingDesc":"让 pi 调度子代理运行,而非立即执行。","desktop.subagentsScopeModels":"限定模型范围","desktop.subagentsScopeModelsDesc":"将子代理的模型选择限制在当前模型范围内。","desktop.subagentsDisableDefault":"禁用默认代理","desktop.subagentsDisableDefaultDesc":"隐藏内置默认代理定义(只提供自定义代理)。","desktop.subagentsFleetView":"舰队视图","desktop.subagentsFleetViewDesc":"在界面中显示运行中子代理的舰队总览。","desktop.subagentsOutputTranscript":"输出转录","desktop.subagentsOutputTranscriptDesc":"保留子代理输出转录,便于之后回顾。","desktop.subagentsSaved":"已保存","desktop.subagentsModel":"模型","desktop.subagentsModelDefault":"默认(不指定)","desktop.subagentsDiscovered":"已发现的代理","desktop.subagentsPanelTitle":"子代理运行","desktop.subagentsStatusRunning":"运行中","desktop.subagentsStatusCompleted":"完成","desktop.subagentsStatusFailed":"失败","desktop.subagentsStatusStopped":"已停止","desktop.subagentsNoDesc":"(无描述)","desktop.subagentsViewTitle":"子代理","desktop.subagentsRunningBubble":"子代理运行中","desktop.subagentsBackToFiles":"文件","desktop.subagentsEmpty":"暂无子代理运行","desktop.subagentsBack":"返回","desktop.subagentsNotFound":"子代理已结束","desktop.subagentsNoTranscript":"暂无运行记录(子代理未写转录或已完成清理)","desktop.subagentsWaitingFirstMessage":"等待子代理首条消息…","desktop.backup":"备份","desktop.backupExportTitle":"导出备份","desktop.backupExportDescription":"打包全部全局配置:供应商、模型、凭证、设置、MCP 服务器、技能与本地插件。","desktop.backupIncludeSecrets":"包含 API 密钥与登录凭证","desktop.backupSecretsWarning":"警告:备份将包含明文 API 密钥(models.json)与 OAuth 凭证(auth.json),请妥善保管。","desktop.backupIncludeSessions":"包含会话历史","desktop.backupSessionsHint":"会话历史可能较大,且含敏感对话内容。","desktop.backupExportButton":"导出备份","desktop.backupExporting":"导出中…","desktop.backupExportFailed":"备份导出失败","desktop.backupImportTitle":"导入备份","desktop.backupImportButton":"选择备份文件","desktop.backupImportDescription":"从 pi-backup zip 恢复。路径会自动重映射到本机,MCP 命令按平台适配。","desktop.backupImportFailed":"读取备份文件失败","desktop.backupRestoreFailed":"恢复失败","desktop.backupManifest":"备份创建于","desktop.backupNoSecrets":"不含凭证","desktop.backupCategories":"恢复类别","desktop.backupCategorycore":"核心配置","desktop.backupCategoryskills":"技能","desktop.backupCategorypackages":"插件","desktop.backupCategorymcp":"MCP 服务器","desktop.backupCategorysessions":"会话","desktop.backupMcpServers":"MCP 服务器","desktop.backupNpmPackages":"npm 插件包","desktop.backupReinstallNpm":"恢复后重新安装这些 npm 包","desktop.backupReinstallNpmHint":"安装脚本将执行备份包自带的代码,仅在你信任该备份来源时勾选","desktop.backupInstallModel":"安装会话使用的模型","desktop.backupInstallSession":"创建安装会话","desktop.backupOpenSession":"打开会话","desktop.backupInstallSessionFailed":"创建安装会话失败","desktop.backupRestoreButton":"开始恢复","desktop.backupRestoring":"恢复中…","desktop.backupRestoreReport":"恢复报告","desktop.backupReportRestored":"已恢复","desktop.backupReportRestart":"需重启生效","desktop.backupReportManual":"需人工确认","desktop.backupRestartHint":"设置、模型、凭证与 MCP 配置需重启 pi-web / pi 后生效。","desktop.importSessions":"导入会话","desktop.importSessionsDesc":"从其他 AI 编码工具导入历史对话记录到 pi-web。目前支持 Reasonix,更多工具陆续支持中。","desktop.comingSoon":"即将支持","desktop.projects":"个项目","desktop.importSelectProjects":"选择要导入的项目","desktop.importSelectAll":"全选","desktop.importDeselectAll":"取消全选","desktop.importMerged":"合并到现有项目","desktop.importNewProject":"新建项目","desktop.importExistingCount":"{count} 个已有","desktop.importStart":"开始导入","desktop.importing":"导入中…","desktop.importDone":"导入完成","desktop.importedSummary":"成功导入 {imported} 个会话","desktop.importSkippedCount":"{skipped} 个跳过","desktop.importErrorsCount":"{errors} 个失败","desktop.importGeneratingTitles":"正在生成标题…","desktop.importGenerateTitles":"为导入的会话生成标题","desktop.importAgain":"再次导入","desktop.importNoData":"未找到 Reasonix 数据。请确认 ~/.reasonix/projects/ 目录存在且包含会话文件。","desktop.importFromReasonix":"来自 Reasonix","desktop.importFromCodex":"来自 Codex","desktop.builtinModelsTitle":"模型配置","desktop.builtinModelsLoadFailed":"加载模型失败","desktop.builtinModelsEmpty":"该供应商暂无可用模型。","desktop.builtinModelsContext":"上下文","desktop.builtinModelsMaxTokens":"最大返回","desktop.builtinModelsReasoning":"思考模型","desktop.builtinModelsThinking":"思考强度(thinkingLevelMap)","desktop.builtinModelsDirty":"{count} 处未保存修改","desktop.builtinModelsHide":"隐藏此模型","desktop.inputShortcut":"输入快捷键","desktop.inputShortcutDescription":"选择使用 Enter 键发送消息的方式。","desktop.useCtrlEnter":"使用 Ctrl+Enter 发送","desktop.useCtrlEnterDescription":"Enter 用于换行,Ctrl+Enter 发送消息。","desktop.useEnter":"使用 Enter 发送","desktop.useEnterDescription":"Enter 发送消息,Shift+Enter 用于换行。","desktop.theme":"主题","desktop.themes":"主题","desktop.language":"语言","desktop.light":"浅色","desktop.dark":"深色","desktop.system":"跟随系统","desktop.english":"English","desktop.chinese":"简体中文","desktop.themeDescription":"选择 Pi Web 的外观。","desktop.languageDescription":"选择界面的显示语言。","desktop.colorScheme":"配色方案","desktop.openThemeFolder":"打开本地 Pi theme 文件夹","desktop.learnPiThemes":"了解 Pi theme","desktop.defaultTheme":"默认","desktop.appearanceMode":"外观模式","desktop.loadingThemes":"加载主题中…","desktop.borderVisibility":"边框可见度","desktop.borderSubtle":"浅淡","desktop.borderBold":"浓重","desktop.noCustomThemes":"未安装自定义主题。","desktop.noCustomThemesHint":"将 JSON 文件放入","desktop.noCustomThemesHint2":"即可在此处看到。","desktop.darkVariant":"深色变体可用","desktop.lightVariant":"浅色变体可用","desktop.switchToLight":"切换至浅色模式","desktop.switchToDark":"切换至深色模式","desktop.showSidebar":"显示侧边栏","desktop.hideSidebar":"隐藏侧边栏","desktop.resizeSidebar":"调整侧边栏宽度","desktop.resizeFilePanel":"调整文件面板宽度","desktop.trustProject":"信任项目","desktop.trustingProject":"正在信任…","desktop.projectResourcesRestricted":"项目资源已受限","desktop.projectSkillsRestricted":"信任此项目后才能使用项目技能。","desktop.projectSkillInstallUnavailable":"请先信任此项目,再安装项目技能。","desktop.shellCommand":"Shell 命令","desktop.shellOutputLocal":"输出仅保留在本地","desktop.shellOutputModel":"输出将提供给模型","desktop.runningShellCommand":"正在运行 Shell 命令…","desktop.loadFullOutput":"加载完整输出","desktop.download":"下载","desktop.trustProjectTitle":"信任此项目?","desktop.trustProjectBody":"项目扩展、技能、提示词和软件包资源可能执行代码。仅在确认项目内容可信时授予信任。","desktop.minimize":"最小化","desktop.maximize":"最大化","desktop.restore":"还原","desktop.close":"关闭","desktop.viewFullHistory":"查看完整历史","desktop.fullHistoryAvailableAfterSave":"保存会话后可查看完整历史","desktop.systemPrompt":"系统提示词","desktop.sessionInfo":"会话信息","desktop.hideFilePanel":"隐藏文件面板","desktop.showFilePanel":"显示文件面板","desktop.sessionInfoTitle":"会话信息","desktop.sessionInfoFile":"文件","desktop.sessionInfoId":"ID","desktop.sessionInfoInMemory":"内存中","desktop.sessionInfoMessages":"消息","desktop.sessionInfoTokens":"令牌","desktop.sessionInfoActiveTime":"估算活跃耗时","desktop.sessionInfoUser":"用户","desktop.sessionInfoAssistant":"助手","desktop.sessionInfoToolCalls":"工具调用","desktop.sessionInfoToolResults":"工具结果","desktop.sessionInfoTotal":"总计","desktop.sessionInfoInput":"输入","desktop.sessionInfoOutput":"输出","desktop.sessionInfoCacheRead":"缓存读取","desktop.sessionInfoCacheWrite":"缓存写入","desktop.sessionInfoCost":"费用","desktop.sessionInfoCostOfficial":"费用(官网价)","desktop.sessionInfoContext":"上下文","desktop.balance":"余额","desktop.balanceGranted":"赠送额度","desktop.balanceToppedUp":"充值额度","desktop.balanceUnavailable":"余额不可用","desktop.turnUsageTitle":"本次回复","desktop.turnUsageByOfficialPrice":"按官网价折算","desktop.copyFilePath":"复制文件路径","desktop.copySessionId":"复制会话 ID","desktop.sendMessageForSessionInfo":"发送消息或运行 /session 以加载会话信息","desktop.selectSessionFromSidebar":"请从侧边栏选择会话","desktop.getStarted":"开始使用","desktop.selectProjectDirectory":"从侧边栏选择项目目录","desktop.addModelsFromBottom":"通过底部的“模型”按钮添加模型","desktop.loadingSession":"正在加载会话...","desktop.scrollToLoadEarlierMessages":"向上滚动以加载更早的消息(隐藏了 {count} 条)","desktop.scrollToBottom":"滚动到底部","desktop.filesWritten":"改动的文件","desktop.openWrittenFile":"打开 {name}","desktop.taskRunning":"进行中","desktop.taskTodo":"待办","desktop.taskStatusHint":"当前项目的任务进度,点击打开任务看板","desktop.runningTool":"正在运行工具...","desktop.runningTools":"正在运行 {tools}...","desktop.waitingForModel":"正在等待模型...","desktop.runningCommand":"正在运行命令...","desktop.thinking":"思考中...","desktop.extensionRequest":"扩展请求","desktop.extensionPanel":"扩展面板","desktop.cancel":"取消","desktop.confirm":"确认","desktop.submit":"提交","desktop.queued":"已排队","desktop.queueMoveUp":"上移","desktop.queueMoveDown":"下移","desktop.queueRecallOne":"取回到输入框","desktop.queueRemove":"移除排队消息","desktop.recalledEditing":"正在编辑一条已取回的排队消息;发送后会回到原来的队列位置。","desktop.steer":"引导","desktop.followUp":"后续消息","desktop.recallToInput":"恢复到输入框","desktop.recallQueuedMessages":"移除所有排队消息,并将其放回输入框以便编辑","desktop.retrying":"正在重试","desktop.compacted":"已压缩","desktop.tokens":"令牌","desktop.saved":"已节省","desktop.removeImage":"移除图片","desktop.loadingCommands":"正在加载命令...","desktop.slashCommands":"斜杠命令","desktop.tabOrEnter":"Tab / Enter","desktop.noSlashCommands":"未找到扩展、提示词或技能命令","desktop.builtIn":"内置","desktop.extensions":"扩展","desktop.prompts":"提示词","desktop.commandSkills":"技能","desktop.match":"个匹配项","desktop.matches":"个匹配项","desktop.snippetMatches":"个片段匹配","desktop.command":"个命令","desktop.commands":"个命令","desktop.loadingFiles":"正在加载文件...","desktop.files":"文件","desktop.searchingAllFiles":"正在搜索所有文件...","desktop.indexTruncated":"索引已截断","desktop.searching":"正在搜索...","desktop.search":"搜索","desktop.noMatchingFiles":"没有匹配的文件","desktop.steerOrQueueFollowUp":"立即引导 / 排队后续消息...","desktop.agentRunning":"Agent 正在运行...","desktop.messageWithCommands":"输入消息... 输入 / 查看命令,@ 查看文件","desktop.inputHistory":"输入历史","desktop.quickChanges":"快速变更","desktop.changedFiles":"{count} 个变更文件","desktop.imageAttachmentsCannotQueue":"Agent 运行时无法将图片附件加入队列","desktop.injectMessageNow":"中断当前运行并立即注入此消息","desktop.queueMessageAfterFinish":"在 Agent 完成后将此消息加入队列","desktop.attachImage":"添加图片","desktop.push":"推送当前分支","desktop.pushOk":"推送成功","desktop.pushFailed":"推送失败","desktop.stash":"Stash 管理","desktop.stashTitle":"Stash 管理","desktop.stashPush":"保存到 Stash","desktop.stashList":"Stash 列表","desktop.stashEmpty":"暂无 stash","desktop.stashPop":"恢复","desktop.stashDrop":"删除","desktop.stashMessagePlaceholder":"stash 说明(可选)…","desktop.stashDone":"操作成功","desktop.attachMenu":"选择输入模式","desktop.attachUpload":"上传文件","desktop.attachUploadDesc":"附加图片等文件","desktop.attachReference":"引用文件","desktop.attachReferenceDesc":"通过 @ 引用工作区文件","desktop.attachSessions":"引用会话","desktop.attachSessionsDesc":"通过 # 引用过去的对话","desktop.attachCommands":"使用命令","desktop.attachCommandsDesc":"通过 / 使用命令和技能","desktop.planModeBadge":"计划模式","desktop.planModeLabel":"计划模式","desktop.planModeHint":"当前为计划模式:只读分析,不修改文件。结束后可确认执行或退出。","desktop.disableCompletionSound":"关闭完成提示音","desktop.enableCompletionSound":"开启完成提示音","desktop.soundLabelOn":"提示音:开启","desktop.soundLabelOff":"提示音:关闭","desktop.changeReasoningLevel":"更改推理级别:{level}","desktop.reasoningLevel":"更改推理级别","desktop.moreControls":"更多控件","desktop.more":"更多","modes.collabNormal":"常规","modes.collabPlan":"计划","modes.collabGoal":"目标","modes.tokenEconomy":"轻量","modes.tokenFull":"均衡","modes.tokenDelivery":"交付","modes.approvalAsk":"批准","modes.approvalAuto":"自动","modes.approvalYolo":"Yolo","modes.collabNormalTitle":"常规 \xb7 边做边推进","modes.collabNormalDesc":"直接执行,边做边推进","modes.collabPlanTitle":"计划 \xb7 确认后执行","modes.collabPlanDesc":"先产出计划;工具执行仍由权限与沙箱决定","modes.collabGoalTitle":"目标 \xb7 持续推进","modes.collabGoalDesc":"输入目标后持续工作,直到完成或阻塞","modes.tokenEconomyTitle":"轻量 \xb7 快速省用量","modes.tokenEconomyDesc":"少上下文,工具按需启用","modes.tokenFullTitle":"均衡 \xb7 日常通用","modes.tokenFullDesc":"完整工具,模型自主执行","modes.tokenDeliveryTitle":"交付 \xb7 完整验证","modes.tokenDeliveryDesc":"强制验收,复查验证","modes.approvalAskTitle":"需要批准","modes.approvalAskDesc":"需审批的写入与命令会先询问","modes.approvalAutoTitle":"自动批准","modes.approvalAutoDesc":"自动执行权限策略允许的操作","modes.approvalYoloTitle":"Yolo 批准","modes.approvalYoloDesc":"跳过普通工具权限提示(仅本会话)","desktop.goalRunning":"目标","desktop.goalComplete":"目标完成","desktop.goalBlocked":"目标阻塞","desktop.goalPaused":"目标暂停","desktop.goalNoProgress":"{n} 轮无进展","desktop.goalPause":"暂停目标","desktop.goalPauseShort":"Ⅱ","desktop.goalResume":"恢复目标","desktop.goalResumeShort":"▶","desktop.goalStop":"结束目标","approval.title":"需要工具审批","approval.subtitle":"Agent 想执行此工具。选择「允许」执行,或「拒绝」向 Agent 返回被阻止的结果。","approval.queued":"个待处理","approval.allow":"允许","approval.deny":"拒绝","approval.denyWithReason":"附理由拒绝","approval.hideReason":"隐藏理由","approval.reasonPlaceholder":"展示给 Agent 的理由(可选)","desktop.stopCompaction":"停止压缩","desktop.compactContext":"压缩上下文","desktop.compacting":"正在压缩...","desktop.compact":"压缩","desktop.changeToolPreset":"更改工具预设:{preset}","desktop.toolPreset":"更改工具预设","desktop.sendMessage":"发送消息","desktop.stopAgent":"停止 Agent","desktop.stop":"停止","desktop.collapseControls":"收起控件","desktop.usePiDefault":"使用 pi 默认设置","desktop.reasoningOff":"关闭推理","desktop.minimalReasoning":"最小推理","desktop.lowReasoning":"低推理","desktop.mediumReasoning":"中等推理","desktop.highReasoning":"高推理","desktop.extraHighReasoning":"超高推理","desktop.maxReasoning":"最高推理","desktop.noToolsReadOnly":"不使用工具,只读","desktop.fourBuiltInTools":"4 个内置工具","desktop.allBuiltInTools":"所有内置工具","desktop.toolOff":"关闭","desktop.toolDefault":"默认","desktop.toolFull":"完整","desktop.thinkingAuto":"自动","desktop.thinkingOff":"关闭","desktop.thinkingMinimal":"最小","desktop.thinkingLow":"低","desktop.thinkingMedium":"中等","desktop.thinkingHigh":"高","desktop.thinkingExtraHigh":"超高","desktop.thinkingMax":"最高","desktop.compactCommandDescription":"压缩上下文,可选择附加指令","desktop.reloadCommandDescription":"重新加载扩展、技能、提示词和工具","desktop.nameCommandDescription":"设置会话显示名称","desktop.sessionCommandDescription":"显示会话消息、令牌和费用统计","desktop.copyCommandDescription":"复制最后一条助手消息","desktop.selectModel":"选择模型","desktop.selectProject":"选择项目","desktop.selectProjectFirst":"请先选择项目","desktop.noMatchingProjects":"没有匹配的项目","desktop.noProjectsYet":"尚无项目","desktop.useDefaultDirectory":"使用默认目录","desktop.customPath":"自定义路径…","desktop.projectPathPlaceholder":"/path/to/project","desktop.filterProjects":"筛选项目…","desktop.searchProjects":"搜索项目…","desktop.recentProjects":"最近项目","desktop.editProjectAlias":"修改项目备注","desktop.projectAliasPlaceholder":"给项目加个备注…","desktop.quickWorkspace":"快速工作区","desktop.selectFolder":"选择文件夹","desktop.checking":"正在检查…","desktop.open":"打开","directoryPicker.selectDirectory":"选择目录","directoryPicker.goToParent":"转到上级目录","directoryPicker.loadingDirectories":"正在加载目录…","directoryPicker.noSubdirectories":"没有子目录","directoryPicker.noMatchingDirectories":"没有匹配的子目录","directoryPicker.filterPlaceholder":"筛选子目录…","directoryPicker.selectCurrentDirectory":"选择当前目录","directoryPicker.selectThisFolder":"选择此文件夹","directoryPicker.noDrives":"未找到盘符","desktop.switchWorktree":"切换工作树","desktop.switchWorktreeWithPath":"切换工作树:{path}","desktop.openRepoRoot":"打开仓库根目录","desktop.openRepoRootDescription":"打开仓库根目录以管理工作树。","desktop.gitRepoRootOnly":"仅 Git 仓库根目录","desktop.gitRepoRootOnlyDescription":"工作树仅在 Git 仓库根目录可用。","desktop.checkingWorktrees":"正在检查此目录的工作树。","desktop.worktreesLoading":"工作树…","desktop.createWorktree":"为分支创建工作树检出","desktop.newWorktree":"新建工作树…","desktop.branchName":"分支名称","desktop.creating":"正在创建…","desktop.create":"创建","desktop.main":"主工作树","desktop.removeWorktree":"移除工作树检出 {path};分支将保留","desktop.uncommittedChanges":"存在未提交的更改。要强制移除检出吗?","desktop.force":"强制移除","desktop.sessions":"会话","desktop.newSession":"新建","desktop.newSessionIn":"在 {cwd} 中新建会话","desktop.refresh":"刷新","desktop.loading":"正在加载…","desktop.noModels":"没有可用模型","desktop.noSessionsFound":"未找到会话","desktop.explorer":"资源管理器","desktop.uploadFiles":"上传文件","desktop.uploadFilesToProjectRoot":"上传文件到项目根目录","desktop.refreshExplorer":"刷新资源管理器","desktop.agentRunningLabel":"Agent 正在运行","desktop.newActivity":"有新动态","desktop.newSessionActivity":"会话有新动态","desktop.deleteSession":"删除“{title}”?","desktop.delete":"删除","desktop.deleteWithShift":"删除(按住 Shift 点击跳过确认)","desktop.openingWorkspace":"正在打开工作区…","desktop.unableToOpenWorkspace":"无法打开此工作区","desktop.rename":"重命名","desktop.titleGenerationFailed":"标题生成失败","desktop.retryTitleGeneration":"重新生成标题","desktop.retry":"重试","desktop.changeTitleModel":"换模型","desktop.pastedLabel":"[已粘贴文本 #{id} \xb7 {lines} 行]","desktop.pastedShowPreview":"预览粘贴文本","desktop.pastedHidePreview":"收起粘贴文本预览","desktop.pastedRemove":"删除粘贴文本","desktop.generateTitle":"生成标题","desktop.generateAllTitles":"批量生成当前项目所有会话的标题","desktop.generatingTitlesProgress":"正在批量生成标题… {done}/{total}","desktop.generatingTitle":"正在生成标题…","desktop.titleNeedsMessages":"会话暂无消息,无法生成标题","desktop.expandForks":"展开分支","desktop.collapseForks":"折叠分支","desktop.sessionViewList":"列表","desktop.sessionViewGroups":"分组","desktop.searchSessions":"搜索会话、分支...","desktop.noSearchResults":"未找到匹配会话","desktop.pinned":"置顶","desktop.today":"今天","desktop.yesterday":"昨天","desktop.older":"更早","desktop.collapseGroup":"收起","desktop.expandGroup":"展开","desktop.pin":"置顶","desktop.unpin":"取消置顶","desktop.forkedFrom":"从「{title}」分叉","desktop.messagesCount":"{count} 条消息","desktop.worktree":"工作树:{cwd}","desktop.justNow":"刚刚","desktop.minutesAgo":"{count} 分钟前","desktop.hoursAgo":"{count} 小时前","desktop.daysAgo":"{count} 天前","desktop.closeTab":"关闭","desktop.closeTabWithLabel":"关闭 {label}","desktop.modelsHideApiKey":"隐藏 API 密钥","desktop.modelsShowApiKey":"显示 API 密钥","desktop.modelsInheritNone":"— 继承 / 无 —","desktop.modelsProvider":"提供商","desktop.modelsProviderName":"提供商名称","desktop.modelsBaseUrl":"基础 URL","desktop.modelsApiKey":"API 密钥","desktop.modelsApiKeyHelp":"使用 ! 前缀运行 shell 命令,或使用环境变量名称","desktop.modelsApiKeyPlaceholder":"环境变量名称、!shell 命令或原始密钥","desktop.modelsApi":"API","desktop.modelsDefault":"默认","desktop.modelsDisabled":"已禁用","desktop.modelsCustom":"自定义","desktop.modelsModelSection":"模型","desktop.modelsTestingConnection":"正在测试模型连接...","desktop.modelsConnected":"已连接","desktop.modelsFailed":"失败","desktop.modelsTestConnection":"测试模型连接","desktop.modelsTesting":"测试中…","desktop.modelsTest":"测试","desktop.modelsOk":"正常","desktop.modelsRemove":"移除","desktop.modelsIdRequired":"ID *","desktop.modelsName":"名称","desktop.modelsDisplayName":"显示名称","desktop.modelsApiOverride":"覆盖 API","desktop.modelsReasoningThinking":"推理 / 思考","desktop.modelsImageInput":"图片输入","desktop.modelsDeepSeekCompat":"DeepSeek 思考兼容模式","desktop.modelsThinkingLevelMap":"思考级别映射","desktop.modelsClearAll":"清除全部","desktop.modelsDiscoveryFetching":"正在导入模型…","desktop.modelsDiscoveryFetch":"导入模型…","desktop.modelsDiscoveryFilterPlaceholder":"筛选 {count} 个模型…","desktop.modelsDiscoveryFilter":"筛选上游模型","desktop.modelsDiscoverySelectShown":"选择当前结果","desktop.modelsDiscoveryNoMatches":"没有匹配的模型。","desktop.modelsDiscoveryAdded":"已添加","desktop.modelsDiscoveryShowing":"显示前 {shown} 个,共 {total} 个","desktop.modelsDiscoveryFetched":"已获取 {count} 个模型","desktop.modelsDiscoveryAddSelected":"添加所选模型","desktop.modelsDiscoveryAddSelectedCount":"添加所选模型({count})","desktop.modelsCatalogSource":"来源:models.dev ↗","desktop.modelsCatalogFilling":"正在填入模型信息…","desktop.modelsCatalogFill":"填入模型信息","desktop.modelsCatalogFilled":"已填入 {count} 个字段","desktop.modelsCatalogNoEmptyFields":"没有需要填入的空字段","desktop.modelsCatalogNoExactMatch":"models.dev 中没有精确匹配","desktop.modelsCatalogPriceProvider":"价格已匹配 Provider {provider}","desktop.modelsCatalogPriceBaseUrl":"价格已按 Base URL 匹配 {provider}","desktop.modelsCatalogPriceConsensus":"价格得到 {support}/{total} 条记录支持","desktop.modelsCatalogPriceUnreliable":"未找到可靠价格","desktop.modelsCatalogUndo":"撤销","desktop.modelsContextWindow":"上下文窗口(令牌)","desktop.modelsMaxOutputTokens":"最大输出令牌数","desktop.modelsCostPerMillionTokens":"费用(每百万令牌)","desktop.modelsSubscription":"订阅","desktop.titleModel":"标题生成模型","desktop.titleModelDescription":'用于自动生成会话标题的模型。保持"跟随会话模型"则使用每个会话自身的模型。',"desktop.titleModelFollowSession":"跟随会话模型(默认)","desktop.titleModelInvalid":"已不再导入——标题生成将回退到会话模型","desktop.titleModelSaved":"已保存","desktop.titleModelSaveError":"保存标题生成模型设置失败","desktop.modelsNotConnected":"未连接","desktop.modelsAlreadyConnected":"已连接。你可以重新登录或断开连接。","desktop.modelsConnectAccount":"连接你的 {provider} 账户。","desktop.modelsOpeningBrowser":"正在打开浏览器…","desktop.modelsCompleteSignIn":"请在浏览器中完成登录,然后复制地址栏中的重定向 URL 并粘贴到下方。","desktop.modelsBrowserDidNotOpen":"如果浏览器窗口未打开,","desktop.modelsOpenLoginPage":"点击此处打开登录页面","desktop.modelsEnterValue":"输入值…","desktop.modelsOpenVerificationPage":"打开验证页面并输入此代码:","desktop.modelsExpiresInMinutes":"将在 {count} 分钟后过期。","desktop.modelsConnectedSuccessfully":"连接成功。","desktop.modelsReLogin":"重新登录","desktop.modelsLogin":"登录","desktop.modelsDisconnect":"断开连接","desktop.modelsConnectionLost":"连接已断开","desktop.modelsAuthenticationStateChanged":"认证状态已变化,请刷新后重试。","desktop.modelsVerifying":"验证中…","desktop.modelsContinuing":"正在继续…","desktop.modelsServerError":"服务器错误 {status}","desktop.modelsNetworkError":"网络错误","desktop.modelsConfigured":"已配置","desktop.modelsNotConfigured":"未配置","desktop.modelsApiKeyStored":"API 密钥已保存。请在下方输入新密钥以替换它,或断开连接以移除它。","desktop.modelsEnableModels":"输入你的 {provider} API 密钥以启用 {count} 个{models}。","desktop.modelsSingular":"模型","desktop.modelsPlural":"模型","desktop.modelsEnterNewKey":"输入新密钥以替换…","desktop.modelsSaving":"保存中…","desktop.modelsSaved":"已保存","desktop.modelsRemoving":"移除中…","desktop.modelsSearchProviders":"搜索提供商…","desktop.modelsNoProvidersMatch":"没有匹配的提供商","desktop.modelsCompatibleProvider":"兼容 OpenAI / Anthropic","desktop.modelsCustomEndpointFormat":"自定义端点格式","desktop.modelsSubscriptions":"订阅","desktop.modelsCount":"{count} 个模型","desktop.modelsLoading":"加载中…","desktop.modelsNewModel":"新模型","desktop.modelsAddModel":"+ 添加模型","desktop.modelsAddProvider":"+ 添加提供商","desktop.modelsSelectProviderOrModel":"选择提供商或模型","desktop.modelsClose":"关闭模型设置","desktop.modelsSave":"保存","desktop.searchModels":"搜索模型…","desktop.noModelsMatch":"没有匹配的模型","desktop.global":"全局","desktop.project":"项目","desktop.path":"路径","desktop.addPlugin":"添加插件","desktop.addPluginTitle":"添加插件","desktop.pluginSource":"来源","desktop.install":"安装","desktop.installing":"正在安装...","desktop.examples":"示例","desktop.disabled":"已禁用","desktop.filtered":"已筛选","desktop.noResources":"没有资源","desktop.packageDisabled":"软件包已禁用","desktop.noResolvedResources":"没有已解析的资源","desktop.unknown":"未知","desktop.installedVersion":"已安装 {version}","desktop.configuredVersion":"已配置 {version}","desktop.enablePackage":"启用软件包","desktop.disablePackage":"禁用软件包","desktop.update":"更新","desktop.updating":"正在更新...","desktop.reloadSession":"重新加载会话","desktop.reloading":"正在重新加载...","desktop.reloadCurrentSession":"重新加载当前会话","desktop.openSessionToReload":"打开一个会话以重新加载","desktop.remove":"移除","desktop.removing":"正在移除...","desktop.status":"状态","desktop.version":"版本","desktop.package":"软件包","desktop.resources":"资源","desktop.installedPath":"安装路径","desktop.notFound":"未找到","desktop.cwd":"当前目录","desktop.resolvedResources":"已解析资源","desktop.packageRemoved":"软件包已移除。","desktop.packageInstalled":"软件包已安装。","desktop.packageUpdated":"软件包已更新。","desktop.packageDisabledMessage":"软件包已禁用。","desktop.packageEnabled":"软件包已启用。","desktop.sessionReloaded":"会话已重新加载。","desktop.noPluginsConfigured":"未配置插件","desktop.selectPackage":"选择一个软件包","desktop.diagnosticsCount":"{count} 条诊断信息","desktop.pluginResourceTotals":"{extensions} 个扩展 \xb7 {skills} 个技能 \xb7 {prompts} 个提示词 \xb7 {themes} 个主题","desktop.extensionsCount":"{count} 个扩展","desktop.skillsCount":"{count} 个技能","desktop.promptsCount":"{count} 个提示词","desktop.themesCount":"{count} 个主题","desktop.addSkill":"添加技能","desktop.addSkillTitle":"添加技能","desktop.skillSearchPlaceholder":"例如:react、testing、deploy","desktop.noSkillsFound":"未找到技能","desktop.skillSearchHint":"搜索 skills.sh,发现并为你的 Agent 安装技能。","desktop.visibleInModelPrompt":"在模型提示词中可见 — 点击以禁用","desktop.hiddenFromModelPrompt":"在模型提示词中隐藏 — 点击以启用","desktop.dormant":"休眠","desktop.hiddenButInvocable":"已从模型中隐藏,仍可手动调用","desktop.check":"检查","desktop.upToDate":"已是最新","desktop.automaticChecksUnavailable":"无法自动检查更新","desktop.checkFailed":"检查失败","desktop.name":"名称","desktop.description":"描述","desktop.selectSkill":"选择一个技能","desktop.checkUpdates":"检查更新","desktop.updateAvailable":"有可用更新","desktop.installed":"已安装","desktop.updatesCount":"{count} 个更新","desktop.downloadFile":"下载文件","desktop.loadingFile":"正在加载...","desktop.noChanges":"没有更改","desktop.unchangedLines":"... {count} 行未更改 ...","desktop.lines":"{count} 行","desktop.mentionFile":"提及文件","desktop.mentionSelectedLines":"提及所选行 {start}-{end}","desktop.source":"源文件","desktop.diff":"差异","desktop.enableWordWrap":"启用自动换行","desktop.disableWordWrap":"禁用自动换行","desktop.wrap":"换行","desktop.code":"代码","desktop.preview":"预览","desktop.raw":"原始内容","desktop.htmlPreview":"HTML 预览","desktop.image":"图片","desktop.audio":"音频","desktop.docxPreview":"DOCX 预览","desktop.failedToLoadImage":"加载图片失败","desktop.failedToLoadAudio":"加载音频失败","desktop.docxTooLargeForPreview":"DOCX 文件过大,无法预览(超过 10MB)","desktop.previewFile":"预览 {file}","desktop.branches":"分支","desktop.noActiveSession":"没有活动会话","desktop.sessionHasNoBranches":"此会话暂无分支 —— 对任意消息点「从这里继续」或「分叉」后会出现分支树","desktop.copyMessage":"复制消息","desktop.copyPlainText":"复制纯文本","desktop.createTaskFromMessage":"创建任务","desktop.editFromHere":"从此处编辑 — 在此会话内创建分支","desktop.creatingNewSession":"正在创建新会话…","desktop.newSessionFromHere":"新建会话 — 从此处创建独立副本","desktop.estimatedStreamingTokenCount":"流式输出期间的预估令牌数","desktop.tokensPerSecond":"{count} 令牌/秒","desktop.thinkingContentUnavailable":"思考内容不可用","desktop.loadingThinking":"正在加载思考内容...","desktop.conversationCompacted":"对话已压缩","desktop.compactionSummaryDescription":"此处之前的对话历史已压缩为以下摘要:","desktop.noSummary":"(无摘要)","desktop.fileContext":"文件上下文:{context}","desktop.readFilesCount":"已读取 {count} 个","desktop.modifiedFilesCount":"已修改 {count} 个","desktop.modifiedFiles":"已修改的文件","desktop.readFiles":"已读取的文件","desktop.hiddenExtensionMessage":"隐藏的扩展消息","desktop.noMessage":"(无消息)","desktop.showExtensionMessage":"显示扩展消息","desktop.copied":"已复制","desktop.copy":"复制","desktop.collapse":"收起","desktop.expand":"展开","desktop.hideDetails":"隐藏详情","desktop.showDetails":"显示详情","desktop.before":"之前","desktop.after":"之后","desktop.noOutput":"(无输出)","desktop.extension":"扩展","desktop.assistant":"助手","desktop.favorites":"收藏","desktop.favorite":"收藏","desktop.unfavorite":"取消收藏","desktop.processStepThinking":"思考","desktop.processStepFileRead":"读取","desktop.processStepFileCreate":"创建","desktop.processStepFileEdit":"编辑","desktop.processStepFileDelete":"删除","desktop.processStepSearch":"搜索","desktop.processStepFind":"查找","desktop.processStepList":"列出","desktop.processStepRead":"读取","desktop.processStepFetch":"抓取","desktop.processStepDelete":"删除","desktop.processStepCopy":"复制","desktop.processStepCommand":"运行","desktop.processStepTool":"工具","desktop.processStepTodo":"待办","desktop.processStepArtifact":"产物","desktop.processStepCompaction":"压缩","desktop.processStepError":"错误","desktop.processWorking":"工作中...","desktop.processUsed":"使用了 {summary}","desktop.processToolCount":"{count} 个工具","desktop.processToolsCount":"{count} 个工具","desktop.processFailedCount":"({failed} 个失败)","desktop.processThoughtCount":"{count} 条思考","desktop.processThoughtsCount":"{count} 条思考","desktop.processThoughtDone":"已思考 {duration}s","desktop.processThoughtDoneNoDuration":"已思考","desktop.processCustomCount":"{count} 个事件","desktop.processCustomsCount":"{count} 个事件","desktop.processCompleted":"处理完成","desktop.processOutput":"处理输出","desktop.processTabMode":"标签页模式","desktop.processTimelineMode":"时间线模式","desktop.processFailedStep":"失败","desktop.markdownPreviewAvailableAfterStreaming":"流式输出结束后可预览","desktop.markdownPreviewMermaidDiagram":"预览 Mermaid 图表","desktop.markdownInvalidMermaidDiagram":"无效的 Mermaid 图表","desktop.markdownRenderingMermaidDiagram":"正在渲染 Mermaid 图表","desktop.openMermaidViewer":"打开 Mermaid 查看器","desktop.mermaidDiagram":"Mermaid 图表","desktop.mermaidViewer":"Mermaid 图表查看器","desktop.zoomPanHint":"拖动平移 \xb7 滚轮缩放","desktop.selectText":"选择文本","desktop.zoomOut":"缩小","desktop.resetZoom":"重置为 100%(适应窗口)","desktop.zoomIn":"放大","desktop.fitToViewport":"适应窗口","desktop.quoteReply":"引用回复","desktop.quoteReplyHint":"点击引用回复","desktop.openFile":"打开","desktop.queueRecoveryTitle":"恢复排队消息","desktop.queueImportTitle":"导入的排队消息","desktop.queueRecoveryDescription":"这些消息在上一个服务会话结束前已保存。请选择要重新入队的消息;系统不会自动发送。","desktop.queueImportDescription":"请选择要重新入队的导入消息;系统不会自动发送。","desktop.selectAll":"全选","desktop.selectNone":"取消全选","desktop.import":"导入","desktop.queueImages":"图片附件","desktop.queueNoText":"(仅图片消息)","desktop.queueExported":"已导出 {count} 条消息","desktop.queueImportEmpty":"未找到有效的排队消息","desktop.queueImported":"已导入 {count} 条消息,等待确认","desktop.dismiss":"暂不处理","desktop.discard":"丢弃","desktop.requeue":"重新入队","desktop.requeueAndContinue":"重新入队并继续","desktop.markdownPlainText":"文本","desktop.hideTaskBoard":"隐藏任务看板","desktop.showTaskBoard":"显示任务看板","tasks.actionArchive":"归档","tasks.stashDone":"变更已成功暂存","tasks.actionCancel":"取消","tasks.actionEdit":"编辑","tasks.actionMerge":"合并","tasks.actionRequeue":"重新排队","tasks.actionRetry":"重试","tasks.actionReturn":"退回反馈","tasks.actionStart":"开始","tasks.actionComplete":"直接完成","tasks.actionUnarchive":"取消归档","tasks.actionViewSession":"查看会话","tasks.allFolders":"全部项目","tasks.archiveAllDone":"全部归档","tasks.badgeCleanupFailed":"清理失败","tasks.badgeWorktreeKept":"保留 worktree","tasks.beta":"Beta","tasks.cancelDescription":"任务将停止。可以留下取消原因,方便之后重新排队时了解背景(可选)。","tasks.cancelKeep":"保留任务","tasks.cancelReasonLabel":"取消原因(可选)","tasks.cancelReasonPlaceholder":"例如:方案不对、需求变了…","tasks.cancelSubmit":"取消任务","tasks.cancelTitle":"取消任务","tasks.changedFiles":"变更文件","tasks.colAttention":"待处理","tasks.colDone":"已完成","tasks.colInProgress":"进行中","tasks.colTodo":"待办","tasks.delete":"删除","tasks.deleteConfirm":"确认删除","tasks.deleteTemplate":"删除模板","tasks.deleteWorktree":"同时删除 worktree","tasks.diff":"差异","tasks.dropToStart":"松手启动","tasks.editTitle":"编辑任务","tasks.empty":"还没有任务","tasks.emptyColAttention":"没有需要你处理的任务","tasks.emptyColDone":"还没有完成的任务","tasks.emptyColInProgress":"没有正在执行的任务","tasks.emptyColTodo":"暂无待办任务","tasks.emptyHint":"创建一个任务,看板会驱动它完成整个流程——启动后会在 worktree 分支里运行 agent 直到结束。","tasks.errorView":"查看","tasks.event_archived":"已归档","tasks.event_canceled":"已取消","tasks.event_created":"已创建","tasks.event_failed":"失败","tasks.event_interrupted":"已中断","tasks.event_merge_failed":"合并失败","tasks.event_merge_requested":"合并请求","tasks.event_merged":"已合并","tasks.event_merging":"合并中","tasks.event_preflight_failed":"预检失败","tasks.event_preflight_passed":"预检通过","tasks.event_preflight_start":"预检运行中","tasks.event_preparing":"准备中","tasks.event_queued":"已排队","tasks.event_recovered":"已恢复","tasks.event_requeued":"已重新排队","tasks.event_return_feedback":"反馈","tasks.event_returned":"已退回","tasks.event_review":"待验收","tasks.event_started":"已启动","tasks.event_unarchived":"已取消归档","tasks.event_updated":"已更新","tasks.fieldProject":"项目","tasks.fieldPrompt":"任务说明","tasks.fieldPromptPlaceholder":"描述 agent 需要完成的工作…","tasks.fieldTitle":"标题","tasks.fieldTitlePlaceholder":"任务的简短标题","tasks.filter":"筛选","tasks.loading":"加载中…","tasks.mergeAutoMessage":"让 agent 自动写提交信息","tasks.mergeConfirm":"合并","tasks.mergeDeleteWorktree":"合并后删除 worktree","tasks.mergeManualMessage":"手动填写提交信息","tasks.mergeMessagePlaceholder":"提交信息…","tasks.mergeStrategyMerge":"合并提交","tasks.mergeStrategySquash":"压缩提交","tasks.mergeTitle":"合并任务","tasks.completeDeleteWorktree":"完成后删除 worktree","tasks.completeDescription":"该任务没有产生任何文件变更,无需合并。确认后直接标记为完成。","tasks.completeSubmit":"确认完成","tasks.completeTitle":"完成任务","tasks.followUpPlaceholderRequeue":"给 agent 的备注(可选)…","tasks.followUpPlaceholderRetry":"给 agent 的备注(可选)…","tasks.actionAddNote":"备注(可选)","tasks.restartDescription":"备注会注入下一次运行的提示词中(可选)。","tasks.restartTitleRequeue":"重新排队","tasks.restartTitleRetry":"重试","tasks.planReviewTitle":"计划已完成","tasks.planReviewDescription":"计划模式的分析已结束。你可以确认执行这份计划、提出建议继续完善,或退出计划模式。","tasks.planReviewShowPlan":"查看计划","tasks.planReviewHidePlan":"收起计划","tasks.planReviewExecute":"确认执行","tasks.planReviewExecutePrompt":"请按以下计划执行:\n\n{plan}","tasks.planReviewSuggest":"提出建议","tasks.planReviewSendFeedback":"发送建议","tasks.planReviewFeedbackLabel":"建议(将返回给 agent 继续完善计划)","tasks.planReviewFeedbackPlaceholder":"例如:先补充风险分析,拆分更细的步骤…","tasks.planReviewExit":"退出计划","tasks.metaCommit":"提交","tasks.metaCreated":"创建于","tasks.metaProject":"项目","tasks.new":"新建任务","tasks.newTitle":"新建任务","tasks.noDiff":"暂无差异","tasks.noEvents":"暂无事件","tasks.notifyFailed":"{title} 执行失败","tasks.notifyReview":"{title} 等待验收","tasks.returnPlaceholder":"给 agent 的反馈…","tasks.returnSubmit":"退回","tasks.save":"保存","tasks.saveAsTemplate":"存为模板","tasks.sessionFile":"会话文件","tasks.sessionHint":"任务的 agent 会话与其他会话一样存储。在会话列表中打开即可查看或继续。","tasks.sessionId":"会话 ID","tasks.sessionTitle":"任务会话","tasks.settingsAutoProcess":"自动处理排队任务","tasks.settingsDeleteWorktree":"合并后默认删除 worktree","tasks.settingsInitCommand":"初始化命令(agent 启动前在 worktree 中执行)","tasks.settingsInitPlaceholder":"例如 pnpm install","tasks.settingsMaxConcurrent":"最大并发任务数(0 = 不限)","tasks.settingsMergeStrategy":"合并策略","tasks.settingsNoProject":"先创建一个任务以选择项目。","tasks.settingsPreflightCommand":"预检命令(验收检查)","tasks.settingsPreflightPlaceholder":"例如 npm test","tasks.settingsProject":"项目","tasks.settingsReset":"恢复默认设置","tasks.settingsStagePrompts":"阶段提示词(附加指令)","tasks.settingsTitle":"任务设置","tasks.showArchived":"显示已归档","tasks.showCanceled":"显示已取消","tasks.stage_merge":"合并","tasks.stage_retry":"重试","tasks.stage_return":"退回","tasks.stage_work":"执行","tasks.startAll":"全部启动","tasks.statusAwaitingInput":"等待输入","tasks.statusCanceled":"已取消","tasks.statusDone":"已完成","tasks.statusFailed":"失败","tasks.statusInterrupted":"已中断","tasks.statusMerging":"合并中","tasks.statusPreparing":"准备中","tasks.statusQueued":"排队中","tasks.statusReview":"待验收","tasks.statusRunning":"运行中","tasks.statusTodo":"待办","tasks.templateNamePlaceholder":"模板名称…","tasks.templates":"模板","tasks.timeline":"时间线","tasks.title":"任务","tasks.attentionBadge":"条待处理"}});let l="pi-locale",d=(0,n.createContext)(null);function c({children:e}){let[t,o]=(0,n.useState)("en"),[i,p]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(l);if("en"===e||"zh-CN"===e)return e}catch{}for(let e of window.navigator.languages.length?window.navigator.languages:[window.navigator.language]){let t=e.toLowerCase();if("en"===t||t.startsWith("en-"))break;if("zh"===t||t.startsWith("zh-"))return"zh-CN"}return"en"}();o(e),document.documentElement.lang=e,p(!0)},[]);let u=(0,n.useMemo)(()=>(function(){let e=a("en"),t=a("zh-CN");if(!e||!t)throw Error("Built-in locales must be registered before rendering I18nProvider");return{en:e.messages,"zh-CN":t.messages}})(),[]),g=(0,n.useMemo)(()=>[...s.keys()].map(e=>a(e)).filter(e=>!!e),[]),h=(0,n.useCallback)(e=>{if(a(e)){o(e);document.documentElement.lang=e,document.documentElement.dataset.language=e;try{window.localStorage.setItem(l,e)}catch{}}},[]),x=(0,n.useCallback)((e,o)=>(function(e,t,o,r={}){let n=o[e]?.[t]??o.en?.[t];return void 0===n?t:function(e,t={}){return e.replace(/\{([\w.-]+)\}/g,(e,o)=>{let r=t[o];return void 0===r?e:String(r)})}(n,r)})(t,e,u,o),[t,u]),f=(0,n.useMemo)(()=>({locale:t,setLocale:h,t:x,supportedLocales:g}),[t,h,x,g]);return(0,r.jsx)(d.Provider,{value:f,children:i?e:null})}function p(){let e=(0,n.useContext)(d);if(!e)throw Error("useI18n must be used inside I18nProvider");return e}},79023:(e,t,o)=>{Promise.resolve().then(o.bind(o,98270)),Promise.resolve().then(o.bind(o,39247))},98270:(e,t,o)=>{"use strict";o.d(t,{AppShell:()=>l5});var r=o(95155),n=o(12115),s=o(53516),i=o(73321);let a=null;var l=o(47650),d=o(25349),c=o(64178),p=o(9720),u=o(98664),g=o(20077),h=o(49467),x=o(56123),f=o(85265),m=o(94125),k=o(25388),v=o(3083),y=o(6033),b=o(73988),w=o(41780),j=o(11693),S=o(77862),C=o(19157),T=o(72422),z=o(5085),R=o(36824),I=o(42515),M=o(44368),E=o(39247);async function P(e){let t=e?`?path=${encodeURIComponent(e)}`:"",o=await fetch(`/api/cwd/browse${t}`),r=await o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);return r}function D(){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 $(){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 F({onCancel:e,onSelect:t,busy:o=!1,error:s}){let i,{t:a}=(0,E.s)(),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(""),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)([]),[m,k]=(0,n.useState)(null),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(!0),[j,S]=(0,n.useState)(""),C=(0,n.useCallback)(async e=>{w(!0),y(null),S("");try{let t=await P(e),o=t.path??e??"/";u(o),h(t.parentPath??null),f(t.directories??[]),k(t.drives??null)}catch(e){y(e instanceof Error?e.message:String(e))}finally{w(!1)}},[]);(0,n.useEffect)(()=>{c(document.body),C()},[C]);let T=!!p&&!o,z=!!g||/^[a-zA-Z]:[\\/]?$/.test(p);return d?(0,l.createPortal)((0,r.jsx)("div",{className:"directory-picker-backdrop",role:"dialog","aria-modal":"true","aria-label":a("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:a("directoryPicker.selectDirectory")})}),(0,r.jsx)("button",{type:"button",onClick:e,disabled:o,title:a("i18n.close"),"aria-label":a("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)("div",{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 C(g??void 0),disabled:b||!z,title:a("directoryPicker.goToParent"),"aria-label":a("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:z?"pointer":"default",opacity:z?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)("div",{title:p,style:{minWidth:0,flex:1,height:36,display:"flex",alignItems:"center",padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p||a("directoryPicker.loadingDirectories")})]}),(0,r.jsxs)("div",{className:"directory-picker-list",style:{flex:1,minHeight:0,overflow:"auto",padding:"8px 10px"},children:[b?(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:a("directoryPicker.loadingDirectories")}):null!==m?(0,r.jsx)(r.Fragment,{children:m.length>0?m.map(e=>(0,r.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void C(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)($,{}),(0,r.jsx)("span",{children:e.name})]},e.path)):(0,r.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:a("directoryPicker.noDrives")})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{type:"text",value:j,onChange:e=>S(e.target.value),placeholder:a("directoryPicker.filterPlaceholder"),"aria-label":a("directoryPicker.filterPlaceholder"),style:{width:"100%",boxSizing:"border-box",marginBottom:6,padding:"5px 9px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11,outline:"none"}}),(i=function(e,t){if(null===t||""===t)return[...e];let o=t.trim().toLowerCase();return o?e.filter(e=>e.name.toLowerCase().includes(o)):[...e]}(x,j)).length>0?i.map(e=>(0,r.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void C(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)(D,{}),(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:a(j.trim()?"directoryPicker.noMatchingDirectories":"directoryPicker.noSubdirectories")})]}),(v||s)&&(0,r.jsx)("div",{style:{padding:"8px",color:"#dc2626",fontSize:11},children:v??s})]}),(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:a("i18n.cancel")}),(0,r.jsx)("button",{className:"directory-picker-action",type:"button",onClick:()=>t(p),disabled:!T,title:a("directoryPicker.selectCurrentDirectory"),style:{padding:"6px 16px",border:0,borderRadius:6,background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,opacity:T?1:.6,cursor:T?"pointer":"default"},children:a(o?"i18n.checking":"directoryPicker.selectThisFolder")})]})]})}),d):null}var W=o(63256),N=o(19413),A=o(69248),L=o(95516),O=o(6513);function H(e,t){return`url(/catppuccin-icons/${e}/${t}.svg)`}function B({icon:e,size:t=14}){let o={"--catppuccin-icon-light":H("latte",e),"--catppuccin-icon-dark":H("mocha",e),width:t,height:t};return(0,r.jsx)("span",{className:"catppuccin-file-icon",style:o,"aria-hidden":"true"})}let U={".github":"github",".git":"git",".vscode":"vscode",".next":"next",".nuxt":"nuxt",".storybook":"storybook",".turbo":"turbo",".yarn":"yarn",".husky":"husky",".cursor":"cursor",api:"api",app:"app",assets:"assets",components:"components",config:"config",docs:"docs",examples:"examples",hooks:"hooks",lib:"lib",node_modules:"node",pages:"routes",public:"public",scripts:"scripts",src:"src",styles:"styles",test:"tests",tests:"tests",__tests__:"tests",types:"types",utils:"utils"};function _({size:e=14,open:t=!1,name:o}){let n=o?U[o.toLowerCase()]:void 0,s=n?`folder_${n}${t?"_open":""}`:`_${t?"folder_open":"folder"}`;return(0,r.jsx)(B,{icon:s,size:e})}function q({size:e=14}){return(0,r.jsx)(B,{icon:"_file",size:e})}function V({icon:e,size:t=14}){return(0,r.jsx)(B,{icon:e,size:t})}let K={".babelrc":"babel",".dockerignore":"docker-ignore",".env":"env",".eslintignore":"eslint-ignore",".eslintrc":"eslint",".gitattributes":"git",".gitignore":"git",".gitmodules":"git",".npmignore":"npm-ignore",".prettierignore":"prettier-ignore",".prettierrc":"prettier",".yarnrc":"yarn","bun.lock":"bun-lock","bun.lockb":"bun-lock","cargo.lock":"cargo-lock","cargo.toml":"cargo",codeowners:"codeowners","docker-compose.yaml":"docker-compose","docker-compose.yml":"docker-compose",dockerfile:"docker","eslint.config.js":"eslint","eslint.config.mjs":"eslint","eslint.config.ts":"eslint","next.config.js":"next","next.config.mjs":"next","next.config.ts":"next","package-lock.json":"npm-lock","package.json":"package-json","pnpm-lock.yaml":"pnpm-lock","pnpm-workspace.yaml":"pnpm","prettier.config.js":"prettier","prettier.config.mjs":"prettier","prettier.config.ts":"prettier","tailwind.config.js":"tailwind","tailwind.config.ts":"tailwind","tsconfig.json":"typescript-config","vite.config.js":"vite","vite.config.mjs":"vite","vite.config.ts":"vite","vitest.config.ts":"vitest","yarn.lock":"yarn-lock"},J={astro:"astro",bash:"bash",c:"c",cpp:"cpp",css:"css",csv:"csv",cjs:"javascript",cts:"typescript",dockerfile:"docker",env:"env",go:"go",gql:"graphql",graphql:"graphql",hcl:"terraform",htm:"html",html:"html",ini:"config",java:"java",js:"javascript",json:"json",jsonc:"json",jsonl:"json",jsx:"javascript-react",less:"less",lua:"lua",md:"markdown",mdx:"markdown-mdx",mjs:"javascript",mts:"typescript",pdf:"pdf",php:"php",py:"python",rs:"rust",sass:"sass",scss:"sass",sh:"bash",sql:"database",svg:"svg",svelte:"svelte",tf:"terraform",toml:"toml",ts:"typescript",tsx:"typescript-react",txt:"text",vue:"vue",xml:"xml",yaml:"yaml",yml:"yaml",zsh:"bash"};function G(e,t=14){let o=e.toLowerCase(),n=K[o];if(n)return(0,r.jsx)(V,{icon:n,size:t});if(".env"===o||o.startsWith(".env."))return(0,r.jsx)(V,{icon:"env",size:t});if("dockerfile"===o||o.startsWith("dockerfile."))return(0,r.jsx)(V,{icon:"docker",size:t});if(o.endsWith(".config.ts")||o.endsWith(".config.js")||o.endsWith(".config.mjs")||o.endsWith(".config.cjs"))return(0,r.jsx)(V,{icon:o.startsWith("vite.")?"vite":"config",size:t});let s=J[o.split(".").pop()??""];return s?(0,r.jsx)(V,{icon:s,size:t}):(0,r.jsx)(q,{size:t})}function Y(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function Z(e){return Y(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function X(e){let t=Y(e).replace(/\/+$/,"");return t.split("/").pop()??t}function Q(e,t){if(!t)return e;let o=Y(e),r=Y(t).replace(/\/$/,"");return o.startsWith(r+"/")?o.slice(r.length+1):e}function ee(e,t){return`${Y(e).replace(/\/$/,"")}/${t}`}function et(e){let t=e.replace(/\\/g,"/").replace(/\/+$/,"");return/^[a-zA-Z]:\//.test(t)?t.toLowerCase():t}function eo(e){return"added"===e?"var(--git-status-added)":"deleted"===e?"var(--git-status-deleted)":"modified"===e?"var(--git-status-modified)":"var(--text)"}function er(e){return"deleted"===e?3:"added"===e?2:1}async function en(e){let t=await fetch(`/api/git/status?${new URLSearchParams({cwd:e}).toString()}`,{cache:"no-store"});if(!t.ok)throw Error(`Failed to load Git status (HTTP ${t.status})`);return t.json()}async function es(e){let t=Z(e),o=await fetch(`/api/files/${t}?type=list`);if(!o.ok){let e=`Failed to load files (HTTP ${o.status})`;try{let t=await o.json();t.error&&(e=t.error)}catch{}throw Error(e)}return((await o.json()).entries??[]).map(t=>({name:t.name,fullPath:ee(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}function ei({size:e=11}){return(0,r.jsx)(W.At,{size:e,weight:"regular","aria-hidden":"true"})}function ea({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.jsx)(c.X,{size:13,weight:"regular","aria-hidden":"true"})})}function el({node:e,depth:t,cwd:o,onOpenFile:s,onAtMention:i,expandedPaths:a,onToggleExpanded:l,refreshToken:d,highlightedPaths:c,ignoredPaths:p,changedFiles:u}){let g=a.has(e.fullPath),h=c.has(e.fullPath),x=et(e.fullPath),f=function(e,t){if(t.has(e))return!0;for(let o of t)if(e.startsWith(`${o}/`))return!0;return!1}(x,p),k=function(e,t,o){let r,n=o.get(e);if(n||!t)return n;for(let[t,n]of o)t.startsWith(`${e}/`)&&(!r||er(n)>er(r))&&(r=n);return r}(x,e.isDir,u),[v,y]=(0,n.useState)(e.children??[]),[b,w]=(0,n.useState)(e.loaded??!1),[j,S]=(0,n.useState)(!1),[C,T]=(0,n.useState)(!1),z=(0,n.useCallback)(async(t=!1)=>{if(!b||t){S(!0);try{let t=await es(e.fullPath);y(t),w(!0)}catch{}finally{S(!1)}}},[b,e.fullPath]);(0,n.useEffect)(()=>{g&&b&&z(!0)},[d]);let I=(0,n.useCallback)(()=>{if(e.isDir){let t=!g;l(e.fullPath,t),t&&!b&&z()}else s(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,b,g,z,s,l]);return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{onClick:I,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:C?"var(--bg-hover)":"transparent",borderRadius:4,userSelect:"none",opacity:f?C?.72:.5:1},children:[e.isDir&&(0,r.jsx)(m.K,{size:10,color:"var(--text-dim)",weight:"regular",style:{flexShrink:0,transform:g?"rotate(90deg)":"none",transition:"transform 0.1s"},"aria-hidden":"true"}),!e.isDir&&(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsxs)("span",{style:{position:"relative",width:14,height:14,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:[e.isDir?(0,r.jsx)(_,{size:14,open:g,name:e.name}):G(e.name,14),k&&(0,r.jsx)("span",{"aria-hidden":"true",style:{position:"absolute",left:-1,top:"50%",transform:"translateY(-50%)",zIndex:1,width:7,height:7,border:"1px solid var(--bg-panel)",borderRadius:"50%",background:eo(k)}})]}),(0,r.jsx)("span",{style:{fontSize:12,color:eo(k),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),h&&(0,r.jsx)("span",{title:"Newly uploaded","aria-label":"Newly uploaded",style:{width:6,height:6,flexShrink:0,borderRadius:"50%",background:"#3b82f6"}}),j&&(0,r.jsx)(N.y,{size:10,color:"var(--text-dim)",weight:"regular","aria-hidden":"true"}),i&&C&&(0,r.jsxs)("button",{onClick:t=>{t.stopPropagation(),i(Q(e.fullPath,o),e.isDir)},title:"Insert path into chat",style:{position:"absolute",right:e.isDir?4:28,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)(ei,{}),"mention"]}),C&&!e.isDir&&(0,r.jsx)("a",{href:`/api/files/${Z(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:"Download file",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 5px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap",textDecoration:"none"},children:(0,r.jsx)(R.z,{size:11,weight:"regular","aria-hidden":"true"})})]}),e.isDir&&g&&(0,r.jsxs)("div",{children:[v.map(e=>(0,r.jsx)(el,{node:e,depth:t+1,cwd:o,onOpenFile:s,onAtMention:i,expandedPaths:a,onToggleExpanded:l,refreshToken:d,highlightedPaths:c,ignoredPaths:p,changedFiles:u},e.fullPath)),0===v.length&&b&&(0,r.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}let ed=(0,n.forwardRef)(function({cwd:e,onOpenFile:t,refreshKey:o,onAtMention:s,onAtMentions:i,onUploadBusyChange:a},l){let[d,c]=(0,n.useState)([]),[p,g]=(0,n.useState)(null),[h,x]=(0,n.useState)(!0),[f,m]=(0,n.useState)(null),[k,v]=(0,n.useState)(new Set),[y,b]=(0,n.useState)(0),[w,j]=(0,n.useState)(new Set),[C,T]=(0,n.useState)("idle"),[z,R]=(0,n.useState)(0),[I,M]=(0,n.useState)(null),[E,P]=(0,n.useState)(null),[D,$]=(0,n.useState)(null),F=(0,n.useRef)(null),W=(0,n.useRef)(null),H=`${o??0}:${y}`,B="idle"!==C,U=(0,n.useMemo)(()=>new Set((p?.ignoredPaths??[]).map(et)),[p]),_=(0,n.useMemo)(()=>new Map((p?.files??[]).map(e=>{var t;return[et(e.filePath),"added"===(t=e.status)||"untracked"===t?"added":"deleted"===t||"conflict"===t?"deleted":"modified"]})),[p]),q=(0,n.useCallback)((e,t)=>{v(o=>{let r=new Set(o);return t?r.add(e):r.delete(e),r})},[]),V=(0,n.useCallback)(t=>{let o=t.uploaded??[];P({uploaded:o,skipped:t.skipped??[],errors:t.errors??[]}),o.length>0&&(j(new Set(o.map(t=>ee(e,t)))),b(e=>e+1))},[e]),K=(0,n.useCallback)(async(t,o)=>{$(null),M(null),R(0),T("uploading");try{let{status:r,data:n}=await new Promise((r,n)=>{let s=new FormData;t.forEach(e=>s.append("files",e,e.name));let i=new XMLHttpRequest;i.open("POST",`/api/files/${Z(e)}?type=upload&conflict=${o}`),i.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&R(Math.round(e.loaded/e.total*100))},i.onerror=()=>n(Error("Network error while uploading files")),i.onabort=()=>n(Error("Upload cancelled")),i.onload=()=>{let e={};try{e=JSON.parse(i.responseText)}catch{i.responseText&&(e.error=i.responseText)}r({status:i.status,data:e})},i.send(s)});if(409===r&&n.conflicts?.length)return void $({files:t,conflicts:n.conflicts,nonReplaceable:n.nonReplaceable??[]});if(r<200||r>=300)throw Error(n.error??`Upload failed (HTTP ${r})`);R(100),V(n)}catch(e){M(e instanceof Error?e.message:String(e))}finally{T("idle")}},[V,e]),J=(0,n.useCallback)(async t=>{if(0!==t.length&&!B){P(null),j(new Set),$(null),M(null),R(0),T("checking");try{let o=await fetch(`/api/files/${Z(e)}?type=upload-check`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileNames:t.map(e=>e.name)})}),r=await o.json().catch(()=>({}));if(!o.ok)throw Error(r.error??`Upload check failed (HTTP ${o.status})`);if(r.conflicts?.length)return void $({files:t,conflicts:r.conflicts,nonReplaceable:r.nonReplaceable??[]});await K(t,"error")}catch(e){M(e instanceof Error?e.message:String(e))}finally{T("idle")}}},[e,K,B]),G=(0,n.useCallback)(e=>{let t=Array.from(e.target.files??[]);e.target.value="",J(t)},[J]);(0,n.useImperativeHandle)(l,()=>({openUploadPicker(){B||W.current?.click()}}),[B]),(0,n.useEffect)(()=>{a?.(B)},[a,B]),(0,n.useEffect)(()=>()=>a?.(!1),[a]),(0,n.useEffect)(()=>{let t=F.current!==e;F.current=e,t&&(v(new Set),j(new Set),P(null),$(null),M(null)),x(t),m(null);let o=!1;return Promise.all([es(e),en(e).catch(()=>null)]).then(([e,t])=>{o||(c(e),g(t))}).catch(e=>{o||m(e instanceof Error?e.message:String(e))}).finally(()=>{o||x(!1)}),()=>{o=!0}},[e,o,y]);let Y=B||null!==D||null!==I||null!==E,X=(0,n.useCallback)(()=>{E&&0!==E.uploaded.length&&i?.(E.uploaded.map(t=>Q(ee(e,t),e)))},[e,i,E]);return(0,r.jsxs)("div",{style:{minHeight:"100%"},children:[(0,r.jsx)("input",{ref:W,type:"file",multiple:!0,hidden:!0,onChange:G}),Y&&(0,r.jsxs)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:[B&&(0,r.jsxs)("div",{role:"status","aria-live":"polite","aria-label":"checking"===C?"Checking files":`Uploading, ${z}%`,children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,minHeight:14,color:"var(--text-muted)"},children:["checking"===C?(0,r.jsx)(N.y,{size:13,weight:"regular",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}):(0,r.jsx)(S.C,{size:13,weight:"regular","aria-hidden":"true"}),"uploading"===C&&(0,r.jsxs)("span",{style:{fontSize:10},children:[z,"%"]})]}),"uploading"===C&&(0,r.jsx)("div",{style:{height:3,marginTop:4,overflow:"hidden",borderRadius:2,background:"var(--border)"},children:(0,r.jsx)("div",{style:{width:`${z}%`,height:"100%",background:"var(--text-muted)",transition:"width 120ms ease"}})})]}),D&&(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.jsxs)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:1.35,overflowWrap:"anywhere"},children:[D.conflicts.length," file",1===D.conflicts.length?"":"s"," already exist: ",D.conflicts.join(", ")]}),D.nonReplaceable.length>0&&(0,r.jsxs)("div",{style:{marginTop:3,fontSize:10,color:"#f59e0b",lineHeight:1.35,overflowWrap:"anywhere"},children:["Cannot replace: ",D.nonReplaceable.join(", ")]}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:7},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void K(D.files,"overwrite"),style:{height:22,padding:"0 7px",border:"1px solid #ef4444",borderRadius:4,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:10},children:"Replace"}),(0,r.jsx)("button",{type:"button",onClick:()=>void K(D.files,"skip"),style:{height:22,padding:"0 7px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",fontSize:10},children:"Skip existing"}),(0,r.jsx)("button",{type:"button",onClick:()=>$(null),style:{height:22,padding:"0 7px",border:"none",borderRadius:4,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:10},children:"Cancel"})]})]}),I&&(0,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:I}),(0,r.jsx)(ea,{onClick:()=>M(null),title:"Dismiss error"})]}),E&&(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:[E.uploaded.length>0&&(0,r.jsxs)("span",{title:`${E.uploaded.length} uploaded`,"aria-label":`${E.uploaded.length} uploaded`,style:{display:"flex",alignItems:"center",gap:3,color:"#22c55e"},children:[(0,r.jsx)(u.J,{size:13,weight:"regular","aria-hidden":"true"}),(0,r.jsx)("span",{children:E.uploaded.length})]}),E.skipped.length>0&&(0,r.jsxs)("span",{title:`${E.skipped.length} skipped`,"aria-label":`${E.skipped.length} skipped`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--text-dim)"},children:[(0,r.jsx)(A.F,{size:13,weight:"regular","aria-hidden":"true"}),(0,r.jsx)("span",{children:E.skipped.length})]}),E.errors.length>0&&(0,r.jsxs)("span",{title:`${E.errors.length} failed`,"aria-label":`${E.errors.length} failed`,style:{display:"flex",alignItems:"center",gap:3,color:"#f87171"},children:[(0,r.jsx)(L.N,{size:13,weight:"regular","aria-hidden":"true"}),(0,r.jsx)("span",{children:E.errors.length})]})]}),E.uploaded.length>0&&i&&(0,r.jsxs)("button",{type:"button",onClick:X,title:1===E.uploaded.length?"Add uploaded file to chat":"Add all uploaded files to chat","aria-label":1===E.uploaded.length?"Add uploaded file to chat":"Add all uploaded files to chat",style:{height:22,padding:"0 7px",display:"flex",alignItems:"center",justifyContent:"center",gap:4,flexShrink:0,border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)(ei,{}),"mention"]}),(0,r.jsx)(ea,{onClick:()=>P(null),title:"Dismiss upload results"})]}),E.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.jsx)(O.R,{size:11,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.name))]})]}),(0,r.jsxs)("div",{style:{padding:"2px 4px"},children:[h?(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}):f?(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:f}):d.map(o=>(0,r.jsx)(el,{node:o,depth:0,cwd:e,onOpenFile:t,onAtMention:s,expandedPaths:k,onToggleExpanded:q,refreshToken:H,highlightedPaths:w,ignoredPaths:U,changedFiles:_},o.fullPath)),!h&&!f&&0===d.length&&(0,r.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"No files found"})]})]})}),ec={modified:"var(--git-status-modified)",added:"var(--git-status-added)",deleted:"var(--git-status-deleted)",renamed:"var(--git-status-modified)",untracked:"var(--git-status-added)",conflict:"var(--git-status-deleted)"};async function ep(e){let t=await fetch(`/api/git/status?${new URLSearchParams({cwd:e}).toString()}`);if(!t.ok)throw Error(`Failed to load Git status (HTTP ${t.status})`);return t.json()}function eu({status:e,cwd:t,onOpenFile:o}){let[s,i]=(0,n.useState)(!1),a=Q(e.filePath,t);return(0,r.jsxs)("button",{type:"button",onClick:()=>o(e.filePath,X(e.filePath),{initialDisplayMode:"diff"}),onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),title:e.filePath,style:{width:"100%",display:"flex",alignItems:"center",gap:4,padding:"0 5px",height:24,border:"none",borderRadius:4,background:s?"var(--bg-hover)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)("span",{style:{width:14,flexShrink:0,color:ec[e.status],fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600,textAlign:"center"},children:e.code}),(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center",opacity:.85},children:G(X(e.filePath),13)}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,fontSize:12},children:a})]})}function eg({cwd:e,refreshKey:t,onOpenFile:o}){let{t:s}=(0,E.s)(),[i,a]=(0,n.useState)(!1),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(!1),u=(0,n.useCallback)(async()=>{p(!0);try{d(await ep(e))}catch{d(null)}finally{p(!1)}},[e]);if((0,n.useEffect)(()=>{u()},[u,t]),!l?.isGitRepository||0===l.files.length)return null;let g=l.files.reduce((e,t)=>("added"===t.status||"untracked"===t.status?e.added+=1:"deleted"===t.status||"conflict"===t.status?e.deleted+=1:e.modified+=1,e),{modified:0,added:0,deleted:0});return(0,r.jsxs)("section",{style:{flex:"0 0 auto",minHeight:0,borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>a(e=>!e),"aria-expanded":i,style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,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)(m.K,{size:9,weight:"regular",style:{transform:i?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s("desktop.quickChanges")})]}),(0,r.jsxs)("div",{className:"git-changes-indicator","aria-label":`Changed files: ${g.modified} modified, ${g.added} added, ${g.deleted} deleted`,children:[g.modified>0&&(0,r.jsx)("span",{className:"git-changes-indicator-part git-changes-indicator-modified",children:g.modified}),g.added>0&&(0,r.jsx)("span",{className:"git-changes-indicator-part git-changes-indicator-added",children:g.added}),g.deleted>0&&(0,r.jsx)("span",{className:"git-changes-indicator-part git-changes-indicator-deleted",children:g.deleted})]}),(0,r.jsxs)("span",{style:{marginLeft:6,color:"var(--git-status-added)",fontFamily:"var(--font-mono)",fontSize:11},children:["+",l.additions]}),(0,r.jsxs)("span",{style:{marginLeft:5,color:"var(--git-status-deleted)",fontFamily:"var(--font-mono)",fontSize:11},children:["-",l.deletions]}),(0,r.jsx)("button",{type:"button",onClick:()=>void u(),disabled:c,title:s("desktop.refresh"),"aria-label":s("desktop.refresh"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginLeft:4,marginRight:6,border:"none",borderRadius:5,background:"none",color:"var(--text-dim)",cursor:c?"wait":"pointer",opacity:c?.55:1},children:c?(0,r.jsx)(N.y,{size:12,style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true"}):(0,r.jsx)(w.S,{size:13,weight:"regular","aria-hidden":"true"})})]}),i&&(0,r.jsx)("div",{style:{minHeight:0,maxHeight:"min(35vh, 280px)",overflowY:"auto",overflowX:"hidden",padding:"2px 4px 4px"},children:l.files.map(t=>(0,r.jsx)(eu,{status:t,cwd:e,onOpenFile:o},t.filePath))})]})}let eh="pi-web:file-explorer:open";function ex(){try{return window.localStorage}catch{return null}}var ef=o(79617),em=o(87358);function ek(e){return e&&"win32"===em.platform?(0,ef.normalize)(e):e}function ev(e,t){return e===t||!!e&&!!t&&"win32"===em.platform&&ek(e).toLowerCase()===ek(t).toLowerCase()}let ey="normal",eb="full",ew="auto";function ej(e){return"normal"===e||"plan"===e||"goal"===e?e:ey}function eS(e){return"economy"===e||"delivery"===e||"full"===e?e:eb}function eC(e){return"ask"===e||"auto"===e||"yolo"===e?e:ew}let eT=["bash","edit","edit_file","grep","find","kill_shell","ls","read","update_goal","wait","write","write_file"],ez=`You are in PLAN MODE. Work as a read-only planning assistant.
|
|
2
|
+
- Analyze, read, search and reason about the codebase; do NOT modify any files.
|
|
3
|
+
- Do NOT run shell commands that mutate state, install packages, or start servers.
|
|
4
|
+
- When you have enough understanding, produce a concrete, step-by-step implementation plan.
|
|
5
|
+
- Structure the plan with clear phases, the files involved, and any risks or open questions.
|
|
6
|
+
- Do not write code yet — the plan itself is the deliverable.`,eR=`<economy-profile>
|
|
7
|
+
Economy mode is on. Keep work direct and use the core file and shell tools only.
|
|
8
|
+
Minimize context: skip exploratory reads you do not need, avoid re-reading files you already have,
|
|
9
|
+
and do not pad responses with extra explanation or tool round-trips.
|
|
10
|
+
</economy-profile>`,eI=`<delivery-profile>
|
|
11
|
+
Prioritize a verified, complete result over minimizing model calls or tokens.
|
|
12
|
+
For action requests: establish acceptance criteria; reproduce bugs when practical;
|
|
13
|
+
inspect the relevant code and project rules; fix the root cause; run focused
|
|
14
|
+
verification; review the resulting diff and adjacent behavior; and continue until
|
|
15
|
+
the request is complete or a genuine blocker remains. Do not claim success without
|
|
16
|
+
evidence. State any unverified result or assumption explicitly.
|
|
17
|
+
</delivery-profile>`,eM=`<goal-profile>
|
|
18
|
+
You are working toward a stated goal. Do the next useful work each turn.
|
|
19
|
+
At the end of each turn report your disposition explicitly:
|
|
20
|
+
- "continue" with the next concrete step, when more work remains;
|
|
21
|
+
- "complete" only when the goal is fully done and verified;
|
|
22
|
+
- "blocked" when only the user can unblock you.
|
|
23
|
+
</goal-profile>`;function eE(e){if(!e)return"";let t=e.replace(/^\uFEFF/,""),o=t;if((t=t.replace(/<(?:economy|delivery|goal)-profile>\n?[\s\S]*?<\/(?:economy|delivery|goal)-profile>\n*(?:Goal:\s*[^\n]*\n?)?/g,""))===o){let e=/^\s*<(?:economy|delivery|goal)-profile>\s*/.exec(t);if(e){let o=t.slice(e[0].length).match(/^[^.]*?\.\s+([\s\S]*)$/);t=o?o[1]:""}}return(t=t.replace(/^You are in PLAN MODE\.[\s\S]*?\n(?=\n|$)/,"")).replace(/^\s*\n/,"").trimStart()}let eP="pi-web:unread-session-ids";function eD(e,t){let o=new Date(e),r=new Date().getTime()-o.getTime(),n=Math.floor(r/6e4),s=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?t("desktop.justNow"):n<60?t("desktop.minutesAgo",{count:n}):s<24?t("desktop.hoursAgo",{count:s}):i<7?t("desktop.daysAgo",{count:i}):o.toLocaleDateString()}function e$(e,t,o=[]){let r=new Map;for(let t of e){let e=t.projectRoot??t.cwd;if(!e)continue;let o=r.get(e);(!o||t.modified>o)&&r.set(e,t.modified)}let n=new Set;for(let e of(t&&n.add(t),o))n.add(e);for(let e of n)r.has(e)||r.set(e,"");return[...r.entries()].sort((e,t)=>t[1].localeCompare(e[1])).map(([e])=>e)}function eF(e,t){if(!t)return e;let o=e.replace(/\\/g,"/").toLowerCase(),r=t.replace(/\\/g,"/").toLowerCase();if(!o.startsWith(r))return e;let n=e.slice(t.length);return"~"+(n.startsWith("/")||n.startsWith("\\"),n)}function eW(e){return e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()??e}function eN({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 eA({open:e,children:t,style:o}){let[s,i]=(0,n.useState)(e),[a,l]=(0,n.useState)(e);return((0,n.useEffect)(()=>{let t,o;return e?(i(!0),l(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>l(!0))})):(l(!1),o=setTimeout(()=>i(!1),140)),()=>{void 0!==t&&window.cancelAnimationFrame(t),o&&clearTimeout(o)}},[e]),s)?(0,r.jsx)("div",{style:{...o,opacity:+!!a,transform:a?"translateY(0) scale(1)":"translateY(-8px) scale(0.96)",transformOrigin:"top center",transition:"opacity 140ms ease, transform 140ms ease",pointerEvents:e?"auto":"none"},children:t}):null}let eL="pi-web:session-view-style",eO={pinned:"desktop.pinned",today:"desktop.today",yesterday:"desktop.yesterday",older:"desktop.older"};function eH(e){let t=e.getFullYear(),o=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return`${t}-${o}-${r}`}function eB({selectedSessionId:e,onSelectSession:t,onNewSession:o,initialSessionId:s,onInitialRestoreDone:i,refreshKey:a,onSessionDeleted:R,selectedCwd:I,onCwdChange:M,onOpenFile:P,explorerRefreshKey:D,onAtMention:$,onAtMentions:W,onOpenSettings:N,selectedSessionStats:A,workspaceControlsHosts:L,showWorkspaceControls:O=!0}){let{t:H}=(0,E.s)(),[B,U]=(0,n.useState)([]),[_,q]=(0,n.useState)(!0),[V,K]=(0,n.useState)(null),[J,G]=(0,n.useState)(null),[Y,Z]=(0,n.useState)([]),X=(0,n.useCallback)(e=>{e&&Z(t=>t.includes(e)?t:[...t,e])},[]),[Q,ee]=(0,n.useState)(""),[et,eo]=(0,n.useState)(!1),[er,en]=(0,n.useState)(null),[es,ei]=(0,n.useState)(null),[ea,el]=(0,n.useState)(""),[ec,ep]=(0,n.useState)(!1),[eu,ef]=(0,n.useState)(null),[em,ek]=(0,n.useState)(!1),ey=(0,n.useRef)(null),eb=(0,n.useRef)({title:null,welcome:null}),[ew,ej]=(0,n.useState)(null),[eS,eC]=(0,n.useState)(!1),[eT,ez]=(0,n.useState)(!1),[eR,eI]=(0,n.useState)(""),[eM,eE]=(0,n.useState)(null),[eD,e_]=(0,n.useState)(!1),[eq,eV]=(0,n.useState)(null),[eJ,eG]=(0,n.useState)(null),eY=(0,n.useRef)(null),eZ=(0,n.useRef)(null),[eX,eQ]=(0,n.useState)(!0),[e0,e1]=(0,n.useState)(()=>{try{return"groups"===window.localStorage.getItem(eL)?"groups":"list"}catch{return"list"}}),[e2,e4]=(0,n.useState)(""),[e6,e5]=(0,n.useState)({pinned:!0,today:!0,yesterday:!0,older:!1}),e3=(0,n.useCallback)(e=>{e1(e);try{window.localStorage.setItem(eL,e)}catch{}},[]),[e8,e7]=(0,n.useState)(!0),[e9,te]=(0,n.useState)(0),[tt,to]=(0,n.useState)(!1),[tr,tn]=(0,n.useState)(!1),[ts,ti]=(0,n.useState)(!1),[ta,tl]=(0,n.useState)(()=>new Set),[td,tc]=(0,n.useState)(()=>(function(){try{let e=window.localStorage.getItem(eP);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}})()),tp=(0,n.useRef)(new Set),tu=(0,n.useRef)(!1),tg=(0,n.useRef)(null),th=(0,n.useRef)(null),tx=(0,n.useRef)(null),tf=(0,n.useCallback)(async(e=!1)=>{try{e&&q(!0);let t=await fetch("/api/sessions");if(!t.ok)throw Error(`HTTP ${t.status}`);let o=await t.json();U(o.sessions),tu.current||tl(new Set(o.runningSessionIds??[]));let r=new Set(o.sessions.map(e=>e.id));tc(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>r.has(e)));return t.size===e.size?e:t}),K(null),e||(tn(!0),tg.current&&clearTimeout(tg.current),tg.current=setTimeout(()=>tn(!1),2e3))}catch(e){K(String(e))}finally{e&&q(!1)}},[]),[tm,tk]=(0,n.useState)({}),tv=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/project-aliases");if(!e.ok)return;let t=await e.json();tk(t.aliases??{})}catch{}},[]);(0,n.useEffect)(()=>{tv()},[tv,a]);let ty=(0,n.useRef)(!1);(0,n.useEffect)(()=>{e7(function(e=ex()){if(!e)return!0;try{return"false"!==e.getItem(eh)}catch{return!0}}())},[]),(0,n.useEffect)(()=>{let e=!ty.current;ty.current=!0,tf(e)},[tf,a]),(0,n.useEffect)(()=>{try{0===td.size?window.localStorage.removeItem(eP):window.localStorage.setItem(eP,JSON.stringify([...td]))}catch{}},[td]),(0,n.useEffect)(()=>{let e=!0,t=null,o=null,r=async()=>{if(!e||"visible"!==document.visibilityState)return;t?.abort();let n=new AbortController;t=n;try{let o=await fetch("/api/agent/running",{cache:"no-store",signal:n.signal});if(!o.ok||!e||t!==n)return;let r=await o.json();if(!e||t!==n)return;tu.current=!0,tl(new Set((r.sessions??[]).filter(e=>e.running).map(e=>e.id)))}catch(e){"AbortError"!==e.name&&console.warn("Failed to poll running sessions",e)}finally{e&&t===n&&"visible"===document.visibilityState&&(o=setTimeout(r,2500))}},n=()=>{"visible"===document.visibilityState?r():(t?.abort(),o&&clearTimeout(o),o=null)};return r(),document.addEventListener("visibilitychange",n),()=>{e=!1,t?.abort(),o&&clearTimeout(o),document.removeEventListener("visibilitychange",n)}},[]),(0,n.useEffect)(()=>{let e=new EventSource("/api/agent/running/events");return e.onmessage=e=>{try{let t=JSON.parse(e.data),o=t.sessions?t.sessions.filter(e=>e.running).map(e=>e.id):t.runningSessionIds??[];tu.current=!0,tl(new Set(o))}catch{}},()=>e.close()},[]),(0,n.useEffect)(()=>{let e=new EventSource("/api/events"),t=new Set(["message_end","agent_end","entry_appended","session_info_changed","agent_settled","auto_compaction_end","session_pin_changed"]),o=null,r=!1;return e.onmessage=e=>{try{let n=JSON.parse(e.data);n&&n.type&&t.has(n.type)?r||(r=!0,o=setTimeout(()=>{r=!1,tf(!1)},2e3)):n&&"project_alias_changed"===n.type&&tv()}catch{}},()=>{e.close(),o&&clearTimeout(o)}},[tf,tv]),(0,n.useEffect)(()=>{let t=[...tp.current].filter(t=>!ta.has(t)&&t!==e),o=[...ta];(t.length>0||o.length>0)&&tc(e=>{let r=new Set(e);return o.forEach(e=>r.delete(e)),t.forEach(e=>r.add(e)),r}),tp.current=ta},[ta,e]),(0,n.useEffect)(()=>{e&&tc(t=>{if(!t.has(e))return t;let o=new Set(t);return o.delete(e),o})},[e]),(0,n.useEffect)(()=>{void 0!==D&&te(e=>e+1)},[D]),(0,n.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&ee(e.home)}).catch(()=>{})},[]);let tb=(0,n.useRef)(!1),tw=(0,n.useCallback)(e=>{if(!e)return null;if(ew&&ew.forCwd===e||ew?.worktrees.some(t=>ev(t.path,e)))return ew.projectRoot;let t=B.find(t=>ev(t.cwd,e));return t?.projectRoot??e},[ew,B]);(0,n.useEffect)(()=>{J&&X(J)},[J,X]);let tj=(0,n.useRef)(null);(0,n.useEffect)(()=>{tj.current!==J&&(tj.current=J,M?.(J,tw(J)))},[J,M,tw]);let tS=(0,n.useRef)(null);(0,n.useEffect)(()=>{I&&I!==tS.current&&(tS.current=I,G(I))},[I]);let[tC,tT]=(0,n.useState)(0);(0,n.useLayoutEffect)(()=>{if(!J){ej(null),eG(null);return}let e=!1;return eG(J),fetch(`/api/worktrees?cwd=${encodeURIComponent(J)}`).then(e=>e.json()).then(t=>{if(!e){if(eG(null),t.error||!t.projectRoot)return void ej(null);ej({forCwd:J,projectRoot:t.projectRoot,isGit:t.isGit??!1,isTopLevel:t.isTopLevel??!1,worktrees:t.worktrees??[]})}}).catch(()=>{e||(eG(null),ej(null))}),()=>{e=!0}},[J,tC,a]),(0,n.useEffect)(()=>{if(0!==B.length&&null===J){if(s&&!tb.current){tb.current=!0;let e=B.find(e=>e.id===s);if(e){G(e.cwd),t(e,!0);return}i?.()}if(I)return void G(I);let e=e$(B,null);e.length>0&&G(e[0])}},[B,J,s,I,t,i]),(0,n.useEffect)(()=>{s&&(tb.current=!1)},[s]);let tz=(0,n.useCallback)(async e=>{let t=e.trim();if(t&&!em){ek(!0),ef(null);try{let e=await fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t})}),o=await e.json().catch(()=>({}));if(!e.ok||o.error)return void ef(o.error??`HTTP ${e.status}`);G(o.cwd??t),ep(!1),eo(!1),en(null)}catch(e){ef(e instanceof Error?e.message:String(e))}finally{ek(!1)}}},[em]),tR=(0,n.useCallback)(()=>{ef(null),ep(!0)},[]),tI=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(G(t.cwd),ep(!1),ef(null),eo(!1),en(null))}catch{}},[]),tM=(0,n.useCallback)(async()=>{let e=eR.trim();if(e&&!eD&&ew){e_(!0),eE(null);try{let t=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ew.projectRoot,branch:e})}),o=await t.json().catch(()=>({}));if(!t.ok||o.error||!o.path)return void eE(o.error??`HTTP ${t.status}`);ez(!1),eI(""),eC(!1),ei(null),ej(t=>t?{...t,forCwd:o.path,worktrees:[...t.worktrees,{path:o.path,branch:e,isMain:!1}]}:t),G(o.path),tT(e=>e+1)}catch(e){eE(e instanceof Error?e.message:String(e))}finally{e_(!1)}}},[eR,eD,ew]),tE=(0,n.useCallback)(async(e,t)=>{if(ew&&!eD){e_(!0),eE(null);try{let o=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ew.projectRoot,path:e,force:t})}),r=await o.json().catch(()=>({}));if(!o.ok){if(r.dirty&&!t)return void eV(e);eE(r.error??`HTTP ${o.status}`);return}eV(null),J===e&&G(ew.projectRoot),tT(e=>e+1)}catch(e){eE(e instanceof Error?e.message:String(e))}finally{e_(!1)}}},[ew,eD,J]);(0,n.useEffect)(()=>{let e=e=>{let t=e.target;ey.current?.contains(t)||eY.current?.contains(t)||Object.values(eb.current).some(e=>e?.contains(t))||(eo(!1),en(null),eC(!1),ei(null),el(""),ef(null),ez(!1),eI(""),eE(null),eV(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let tP=(0,n.useCallback)(e=>{e.cwd&&G(e.cwd),t(e)},[t]),tD=(0,n.useCallback)((e,t)=>{U(o=>o.map(o=>o.id===e.id?{...o,pinned:t}:o)),fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({pinned:t})}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`)}).catch(()=>{U(o=>o.map(o=>o.id===e.id?{...o,pinned:!t}:o)),tf(!1)})},[tf]),t$=(0,n.useCallback)(()=>{if(!J)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)}`;o?.(e,J)},[J,o]),tF=tw(J),tW=e$(B,J?tw(J)??J:null,Y),tN=ea.trim()?tW.filter(e=>e.toLowerCase().includes(ea.trim().toLowerCase())):tW,tA=tF?B.filter(e=>(e.projectRoot??e.cwd)===tF):B,[tL,tO]=(0,n.useState)(!1),[tH,tB]=(0,n.useState)({done:0,total:0}),tU=(0,n.useCallback)(async()=>{if(tL)return;let e=tA.filter(e=>e.messageCount>0).map(e=>e.id);if(0===e.length)return;tO(!0),tB({done:0,total:e.length});let t=0,o=async()=>{for(;t<e.length;){let o=t++,r=e[o];if(r){try{await fetch(`/api/sessions/${encodeURIComponent(r)}/auto-name`,{method:"POST"})}catch{}tB({done:o+1,total:e.length})}}},r=Array.from({length:Math.min(2,e.length)},o);await Promise.all(r),tO(!1),tf(!1)},[tL,tA,tf]),t_=!!(ew?.isGit&&ew.isTopLevel&&J&&tF===ew.projectRoot),tq=J&&ew&&tF===ew.projectRoot&&!t_?ew.isGit?{label:H("desktop.openRepoRoot"),title:H("desktop.openRepoRootDescription")}:{label:H("desktop.gitRepoRootOnly"),title:H("desktop.gitRepoRootOnlyDescription")}:null,tV=!!(J&&eJ===J),tK=tq??(tV&&!t_?{label:H("desktop.worktreesLoading"),title:H("desktop.checkingWorktrees")}:null),tJ=(0,n.useMemo)(()=>{let e=e2.trim().toLowerCase();return e?tA.filter(t=>{let o=(t.name||t.firstMessage||"").toLowerCase(),r=(t.worktreeBranch||"").toLowerCase();return o.includes(e)||r.includes(e)}):tA},[e2,tA]),tG=(0,n.useMemo)(()=>(function(e){let t=new Map;for(let o of e)t.set(o.id,{session:o,children:[]});let o=new Map;for(let t of e)t.parentSessionId&&o.set(t.id,t.parentSessionId);let r=[];for(let e of t.values()){let n=function(e){let r=o.get(e),n=new Set;for(;r&&!n.has(r);){if(n.add(r),t.has(r))return r;r=o.get(r)}return null}(e.session.id);n?t.get(n).children.push(e):r.push(e)}let n=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>n(e.children))};return n(r),r})(tJ),[tJ]),[tY,tZ]=(0,n.useState)(0);(0,n.useEffect)(()=>{let e=setInterval(()=>tZ(e=>e+1),6e4);return()=>clearInterval(e)},[]);let tX=(0,n.useMemo)(()=>(function(e,t){let o=new Date,r=eH(o),n=eH(new Date(o.getTime()-864e5)),s={pinned:[],today:[],yesterday:[],older:[]};for(let t of e){let e=eH(new Date(t.modified));t.pinned&&s.pinned.push(t),e===r?s.today.push(t):e===n?s.yesterday.push(t):s.older.push(t)}return["pinned","today","yesterday","older"].map(e=>({key:e,rows:function(e,t,o){if(0===e.length)return[];let r=new Map(t.map(e=>[e.id,e])),n=new Set(e.map(e=>e.id)),s=new Map;for(let t of e)if(t.parentSessionId&&n.has(t.parentSessionId)){let e=s.get(t.parentSessionId)??[];e.push(t),s.set(t.parentSessionId,e)}let i=(e,t)=>t.modified.localeCompare(e.modified),a=e.filter(e=>!(e.parentSessionId&&n.has(e.parentSessionId))).sort(i);for(let e of s.values())e.sort(i);let l=[],d=new Set,c=e=>{if(!d.has(e.id))for(let t of(d.add(e.id),l.push({session:e,forkDepth:o?0:(e=>{let t=0,o=e,n=new Set;for(;o?.parentSessionId&&!n.has(o.id);){n.add(o.id);let e=r.get(o.parentSessionId);if(!e)break;o=e,t++}return t})(e)}),s.get(e.id)??[]))c(t)};for(let e of a)c(e);for(let t of e)c(t);return l}(s[e],t,"pinned"===e)})).filter(e=>e.rows.length>0)})(tJ,B),[tJ,B,tY]),tQ=ew?.worktrees.find(e=>ev(e.path,J??""))??ew?.worktrees.find(e=>e.isMain)??null,t0=(0,n.useCallback)(e=>{for(let t of Object.keys(tm))if(ev(t,e))return tm[t]},[tm]),[t1,t2]=(0,n.useState)(null),[t4,t6]=(0,n.useState)(""),t5=(0,n.useRef)(null),t3=(0,n.useCallback)(e=>{t2(e),t6(t0(e)??""),setTimeout(()=>t5.current?.focus(),0)},[t0]),t8=(0,n.useCallback)(async e=>{t2(null);let t=t4.trim();tk(o=>{let r=Object.keys(o).find(t=>ev(t,e))??e,n={...o};return t?n[r]=t:delete n[r],n});try{let o=await fetch("/api/project-aliases",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,alias:t})}),r=await o.json().catch(()=>null);if(!o.ok||!r?.aliases)throw Error(`HTTP ${o.status}`);tk(r.aliases)}catch{tv()}},[t4,tv]),t7=J?t0(tF??J)??eW(tF??J):s&&!tb.current?"":`${H("desktop.selectProject")}…`,t9=(0,r.jsx)("div",{style:{borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center"},children:[(0,r.jsx)(d.e,{size:13,color:"var(--text-dim)",style:{position:"absolute",left:12,pointerEvents:"none"},"aria-hidden":"true"}),(0,r.jsx)("input",{value:ea,onChange:e=>el(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(ea?el(""):(eo(!1),en(null)))},placeholder:H("desktop.searchProjects"),"aria-label":H("desktop.searchProjects"),autoFocus:!0,style:{width:"100%",padding:"8px 12px 8px 34px",background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",boxSizing:"border-box"}})]})}),oe=(0,r.jsxs)("div",{className:"scroll-overlay",style:{maxHeight:"min(32vh, 240px)",flex:1,minHeight:0,padding:"4px"},children:[tN.length>0&&(0,r.jsx)("div",{style:{padding:"5px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:H("desktop.recentProjects")}),tN.map(e=>{let t=e===tF,o=function(e,t){if(!t)return!1;let o=e.replace(/\\/g,"/").toLowerCase(),r=t.replace(/\\/g,"/").toLowerCase();if(!o.startsWith(r))return!1;let n=o.slice(r.length).replace(/^\/+/,"").split("/")[0]??"";return/^pi-cwd-\d{8}$/.test(n)}(e,Q),n=t0(e);return t1===e?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"2px 8px"},children:[(0,r.jsx)("input",{ref:t5,value:t4,onChange:e=>t6(e.target.value),onKeyDown:t=>{"Enter"===t.key&&(t.preventDefault(),t8(e)),"Escape"===t.key&&(t2(null),t6(n??""))},onBlur:()=>void t8(e),placeholder:H("desktop.projectAliasPlaceholder"),"aria-label":H("desktop.projectAliasPlaceholder"),maxLength:80,style:{flex:1,minWidth:0,fontSize:12,fontFamily:"var(--font-mono)",padding:"4px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}}),(0,r.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{t2(null),t6(n??"")},title:H("i18n.close"),"aria-label":H("i18n.close"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-selected)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsx)(c.X,{size:11,"aria-hidden":"true"})})]},e):(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",width:"100%",background:t?"var(--bg-selected)":"transparent",borderRadius:5,minWidth:0},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:[(0,r.jsxs)("button",{onClick:()=>{G(e),el(""),ep(!1),ef(null),eo(!1),en(null)},title:e,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"3px 8px",background:"transparent",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12,fontFamily:"var(--font-mono)"},children:[o?(0,r.jsx)(p.l,{size:12,color:t?"var(--accent)":"var(--text-dim)",weight:t?"fill":"regular",style:{flexShrink:0},"aria-hidden":"true"}):t?(0,r.jsx)(u.J,{size:12,color:"var(--accent)",weight:"bold",style:{flexShrink:0},"aria-hidden":"true"}):(0,r.jsx)("span",{style:{width:12,flexShrink:0}}),(0,r.jsxs)("span",{style:{display:"flex",alignItems:"baseline",gap:6,flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,flex:n?"0 1 auto":"1 1 0"},children:n??eW(e)}),n&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:eW(e)})]})]}),(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),t3(e)},title:H("desktop.editProjectAlias"),"aria-label":H("desktop.editProjectAlias"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,marginRight:4,background:"none",border:"none",color:t?"var(--accent)":"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,opacity:.7},onMouseEnter:e=>{e.currentTarget.style.opacity="1",e.currentTarget.style.color=t?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background="var(--bg-selected)"},onMouseLeave:e=>{e.currentTarget.style.opacity="0.7",e.currentTarget.style.color=t?"var(--accent)":"var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsx)(g.I,{size:12,weight:"regular","aria-hidden":"true"})})]},e)}),0===tN.length&&(0,r.jsx)("div",{style:{padding:"8px",fontSize:12,color:"var(--text-dim)"},children:ea.trim()?H("desktop.noMatchingProjects"):H("desktop.noProjectsYet")})]}),ot=(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",padding:"4px",flexShrink:0},children:[(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tI()},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 8px",background:"transparent",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(p.l,{size:14,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{children:H("desktop.quickWorkspace")})]}),(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),tR()},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 8px",background:"transparent",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(h.Bm,{size:14,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{children:H("desktop.selectFolder")})]})]}),oo=tQ?tQ.branch??eW(tQ.path):tK?.label,or=!!(L?.title||L?.welcome);return(0,r.jsxs)(r.Fragment,{children:[ec&&(0,r.jsx)(F,{busy:em,error:eu,onCancel:()=>{em||(ep(!1),ef(null))},onSelect:e=>void tz(e)}),Object.entries(L??{}).map(([e,t])=>{let o,n,s;return t&&(0,l.createPortal)((0,r.jsx)("div",{ref:t=>{eb.current[e]=t},children:(o="welcome"===e,n=er===e,s=es===e,O?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-start",gap:o?6:2,height:o?"auto":"100%",minWidth:0,width:o?"100%":void 0},children:[(0,r.jsxs)("div",{style:{position:"relative",minWidth:0,width:o?"fit-content":void 0,maxWidth:o?"min(100%, 560px)":void 0},children:[(0,r.jsxs)("button",{className:`app-no-drag app-titlebar-context-control workspace-project-control${o?" workspace-project-control-large":""}`,onClick:()=>en(t=>t===e?null:e),title:tF??J??H("desktop.selectProject"),"aria-label":H("desktop.selectProject"),"aria-expanded":n,style:{height:o?48:36,width:o?"100%":void 0,maxWidth:o?"100%":260,minWidth:0,display:"flex",alignItems:"center",gap:o?10:6,padding:o?"0 12px":"0 8px",background:n?"var(--bg-selected)":"none",border:"none",borderRadius:8*!!o,color:n?"var(--text)":J?o?"var(--text)":"var(--text-muted)":"var(--text-dim)",cursor:"pointer",fontSize:o?24:12,fontWeight:500,fontFamily:"var(--font-mono)",lineHeight:1,letterSpacing:0,textAlign:"left",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=J?"var(--text)":"var(--text-muted)"},onMouseLeave:e=>{e.currentTarget.style.background=n?"var(--bg-selected)":"none",e.currentTarget.style.color=n?"var(--text)":J?"var(--text-muted)":"var(--text-dim)"},children:[(0,r.jsx)(eN,{text:t7,style:{flex:1,minWidth:0,color:"inherit",direction:"ltr",fontFamily:"inherit"}}),(0,r.jsx)(x.a,{size:12,weight:"regular",style:{flexShrink:0,transition:"transform 0.12s",transform:n?"rotate(180deg)":"none"},"aria-hidden":"true"})]}),(0,r.jsxs)(eA,{open:n,style:{position:"absolute",top:"calc(100% + 4px)",left:0,width:320,zIndex:1e3,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.16)",overflow:"hidden",display:"flex",flexDirection:"column",maxHeight:"min(38vh, 300px)"},children:[t9,oe,ot]})]}),(t_||tK)&&(0,r.jsxs)("div",{style:{position:"relative",minWidth:0},children:[(0,r.jsxs)("button",{className:"app-no-drag app-titlebar-context-control workspace-worktree-control",onClick:()=>{t_&&ei(t=>t===e?null:e)},"aria-label":H("desktop.switchWorktree"),"aria-expanded":t_?s:void 0,"aria-disabled":!t_,tabIndex:t_?0:-1,title:t_&&tQ?H("desktop.switchWorktreeWithPath",{path:tQ.path}):tK?.title,style:{height:36,maxWidth:220,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"0 8px",background:s?"var(--bg-selected)":"none",border:"none",color:s?"var(--text)":t_?"var(--text-muted)":"var(--text-dim)",cursor:t_?"pointer":"default",fontSize:12,fontWeight:500,fontFamily:"var(--font-mono)",lineHeight:1,letterSpacing:0,opacity:t_?1:.82,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{t_&&(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=s?"var(--bg-selected)":"none",e.currentTarget.style.color=s?"var(--text)":t_?"var(--text-muted)":"var(--text-dim)"},children:[(0,r.jsx)(f.Z,{size:16,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{className:"worktree-title-label",children:(0,r.jsx)(eN,{text:oo??"",style:{flex:1,minWidth:0,color:"inherit",direction:"ltr",fontFamily:"inherit"}})}),t_&&(0,r.jsx)(x.a,{size:12,weight:"regular",style:{flexShrink:0,transition:"transform 0.12s",transform:s?"rotate(180deg)":"none"},"aria-hidden":"true"})]}),(0,r.jsxs)(eA,{open:t_&&s,style:{position:"absolute",top:"calc(100% + 4px)",left:0,width:320,zIndex:1e3,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.16)",overflow:"hidden"},children:[(0,r.jsx)("div",{className:"scroll-overlay",style:{maxHeight:"min(40vh, 300px)"},children:ew?.worktrees.map(e=>{let t=ev(e.path,J??"")||e.isMain&&!ew.worktrees.some(e=>ev(e.path,J??""));return(0,r.jsxs)("button",{onClick:()=>{G(e.path),eC(!1),ei(null),eE(null)},title:e.path,style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"var(--bg)",border:"none",borderBottom:"1px solid var(--border)",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[t?(0,r.jsx)(u.J,{size:10,color:"var(--accent)",weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(eN,{text:e.branch??eF(e.path,Q),style:{flex:1}}),e.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:H("desktop.main")})]},e.path)})}),eT?(0,r.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,r.jsx)("input",{ref:eZ,value:eR,onChange:e=>{eI(e.target.value),eE(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),tM()),"Escape"===e.key&&(ez(!1),eI(""),eE(null))},placeholder:H("desktop.branchName"),style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,r.jsx)("button",{onClick:()=>void tM(),disabled:eD||!eR.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:eD||!eR.trim()?"not-allowed":"pointer",opacity:eD||!eR.trim()?.65:1},children:eD?H("desktop.creating"):H("desktop.create")}),(0,r.jsx)("button",{onClick:()=>{ez(!1),eI(""),eE(null)},style:{flex:1,padding:"4px 0",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:H("desktop.cancel")})]}),eM&&(0,r.jsx)("div",{style:{marginTop:5,color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:eM})]}):(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),ez(!0),eE(null),setTimeout(()=>eZ.current?.focus(),0)},title:H("desktop.createWorktree"),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.jsx)("span",{children:H("desktop.newWorktree")})})]})]})]}):null)}),t,e)}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[(0,r.jsxs)("button",{onClick:()=>eQ(e=>!e),style:{display:"flex",alignItems:"center",gap:6,flex:1,padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,r.jsx)(m.K,{size:9,weight:"regular",style:{transform:eX?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},"aria-hidden":"true"}),H("desktop.sessions")]}),(0,r.jsxs)("div",{style:{display:"flex",gap:2,flexShrink:0,marginRight:2},role:"group","aria-label":"Session view",children:[(0,r.jsx)("button",{onClick:()=>e3("list"),title:H("desktop.sessionViewList"),"aria-label":H("desktop.sessionViewList"),"aria-pressed":"list"===e0,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"list"===e0?"var(--bg-selected)":"none",border:"none",borderRadius:5,flexShrink:0,color:"list"===e0?"var(--accent)":"var(--text-dim)",cursor:"pointer",transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{"list"!==e0&&(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)")},onMouseLeave:e=>{"list"!==e0&&(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)")},children:(0,r.jsx)(k.B,{size:12,weight:"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:()=>e3("groups"),title:H("desktop.sessionViewGroups"),"aria-label":H("desktop.sessionViewGroups"),"aria-pressed":"groups"===e0,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"groups"===e0?"var(--bg-selected)":"none",border:"none",borderRadius:5,flexShrink:0,color:"groups"===e0?"var(--accent)":"var(--text-dim)",cursor:"pointer",transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{"groups"!==e0&&(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)")},onMouseLeave:e=>{"groups"!==e0&&(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)")},children:(0,r.jsx)(v.d,{size:12,weight:"regular","aria-hidden":"true"})})]}),(0,r.jsx)("button",{onClick:t$,disabled:!J,title:J?H("desktop.newSessionIn",{cwd:J}):H("desktop.selectProjectFirst"),"aria-label":H("desktop.newSession"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,background:"none",border:"none",color:"var(--text-dim)",cursor:J?"pointer":"default",borderRadius:5,flexShrink:0,opacity:J?1:.6,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{J&&(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.jsx)(y.F,{size:13,weight:"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:()=>void tU(),disabled:tL||!J||0===tA.filter(e=>e.messageCount>0).length,title:tL?`${H("desktop.generatingTitlesProgress",{done:tH.done,total:tH.total})}`:H("desktop.generateAllTitles"),"aria-label":H("desktop.generateAllTitles"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,background:"none",border:"none",color:"var(--text-dim)",cursor:tL?"default":"pointer",borderRadius:5,flexShrink:0,opacity:J&&0!==tA.filter(e=>e.messageCount>0).length?1:.5,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{tL||(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:tL?(0,r.jsxs)("svg",{style:{animation:"spin 1s linear infinite"},width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,r.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):(0,r.jsx)(b.R,{size:13,weight:"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:()=>tf(!1),title:H("desktop.refresh"),"aria-label":H("desktop.refresh"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:6,background:tr?"rgba(74,222,128,0.18)":"none",border:"none",color:tr?"#4ade80":"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{tr||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{tr||(e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none")},children:tr?(0,r.jsx)(u.J,{size:13,color:"#4ade80",weight:"regular","aria-hidden":"true"}):(0,r.jsx)(w.S,{size:13,weight:"regular","aria-hidden":"true"})})]}),!or&&(0,r.jsxs)("div",{ref:ey,style:{position:"relative"},children:[(0,r.jsx)("button",{onClick:()=>eo(e=>!e),title:tF??J??"",style:{width:"100%",display:"flex",alignItems:"center",padding:"6px 10px",background:J?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:J?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left",transition:"border-color 0.15s, background 0.15s"},children:J?(0,r.jsx)(eN,{text:t0(tF??J??"")??eF(tF??J,Q),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:s&&!tb.current?"":`${H("desktop.selectProject")}…`})}),(0,r.jsxs)(eA,{open:et,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",display:"flex",flexDirection:"column",maxHeight:"min(38vh, 300px)"},children:[t9,oe,ot]})]}),!or&&t_&&(()=>{if(!ew)return null;let e=ew.worktrees.find(e=>ev(e.path,J??""))??ew.worktrees.find(e=>e.isMain);return(0,r.jsxs)("div",{ref:eY,style:{position:"relative",marginTop:6},children:[(0,r.jsxs)("button",{onClick:()=>eC(e=>!e),title:e?H("desktop.switchWorktreeWithPath",{path:e.path}):H("desktop.switchWorktree"),style:{width:"100%",height:29,boxSizing:"border-box",display:"flex",alignItems:"center",gap:6,padding:"0 10px",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",fontSize:11,lineHeight:1.35,color:"var(--text-muted)",textAlign:"left"},children:[(0,r.jsx)(f.Z,{size:11,weight:"regular",style:{flexShrink:0,color:e&&!e.isMain?"var(--accent)":"var(--text-dim)"},"aria-hidden":"true"}),(0,r.jsx)(eN,{text:e?e.branch??eF(e.path,Q):"…",style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)"}}),e?.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:H("desktop.main")}),ew.worktrees.length>1&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:ew.worktrees.length}),(0,r.jsx)(x.a,{size:9,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"})]}),(0,r.jsxs)(eA,{open:eS,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[(0,r.jsx)("div",{className:"scroll-overlay",style:{maxHeight:"min(40vh, 300px)"},children:ew.worktrees.map(e=>{let t=ev(e.path,J??"")||e.isMain&&!ew.worktrees.some(e=>ev(e.path,J??""));return eq===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:H("desktop.uncommittedChanges")}),(0,r.jsx)("button",{onClick:()=>void tE(e.path,!0),disabled:eD,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:H("desktop.force")}),(0,r.jsx)("button",{onClick:()=>eV(null),style:{padding:"3px 9px",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer",flexShrink:0},children:H("desktop.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:()=>{G(e.path),eC(!1),eE(null)},title:e.path,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px",background:"var(--bg)",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[t?(0,r.jsx)(u.J,{size:10,color:"var(--accent)",weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}):(0,r.jsx)("span",{style:{width:10,flexShrink:0}}),(0,r.jsx)(eN,{text:e.branch??eF(e.path,Q),style:{flex:1}}),e.isMain&&(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:H("desktop.main")})]}),!e.isMain&&(0,r.jsx)("button",{onClick:()=>void tE(e.path,!1),disabled:eD,title:H("desktop.removeWorktree",{path:e.path}),style:{display:"flex",alignItems:"center",justifyContent:"center",width:34,height:28,padding:0,marginRight:4,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="#ef4444",e.currentTarget.style.background="rgba(239,68,68,0.08)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsx)(j.l,{size:12,weight:"regular","aria-hidden":"true"})})]},e.path)})}),eT?(0,r.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,r.jsx)("input",{ref:eZ,value:eR,onChange:e=>{eI(e.target.value),eE(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),tM()),"Escape"===e.key&&(ez(!1),eI(""),eE(null))},placeholder:H("desktop.branchName"),style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,r.jsx)("button",{onClick:()=>void tM(),disabled:eD||!eR.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:eD||!eR.trim()?"not-allowed":"pointer",opacity:eD||!eR.trim()?.65:1},children:eD?H("desktop.creating"):H("desktop.create")}),(0,r.jsx)("button",{onClick:()=>{ez(!1),eI(""),eE(null)},style:{flex:1,padding:"4px 0",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:H("desktop.cancel")})]})]}):(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),ez(!0),eE(null),setTimeout(()=>eZ.current?.focus(),0)},title:H("desktop.createWorktree"),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.jsx)(y.F,{size:10,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{children:H("desktop.newWorktree")})]}),eM&&(0,r.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:eM})]})]})})(),!or&&tK&&(0,r.jsxs)("button",{type:"button","aria-disabled":"true",tabIndex:-1,title:tK.title,style:{width:"100%",height:29,boxSizing:"border-box",marginTop:6,display:"flex",alignItems:"center",gap:6,padding:"0 10px",border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-hover)",color:"var(--text-dim)",fontSize:11,lineHeight:1.35,whiteSpace:"nowrap",textAlign:"left",cursor:"default",opacity:.82},children:[(0,r.jsx)(f.Z,{size:11,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:tK.label})]})]}),eX&&(0,r.jsxs)("div",{className:"scroll-overlay",style:{flex:e8?"0 1 auto":"1 1 0",padding:"0",minHeight:0,maxHeight:e8?"min(40%, 360px)":"none"},children:[(0,r.jsx)("div",{style:{position:"sticky",top:0,zIndex:1,padding:"4px 10px 6px",background:"var(--bg)"},children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,background:"var(--bg-hover)",borderRadius:8,padding:"0 9px",height:30},children:[(0,r.jsx)(d.e,{size:13,color:"var(--text-dim)",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("input",{value:e2,onChange:e=>e4(e.target.value),placeholder:H("desktop.searchSessions"),"aria-label":H("desktop.searchSessions"),style:{flex:1,minWidth:0,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"}}),e2&&(0,r.jsx)("button",{onClick:()=>e4(""),"aria-label":H("i18n.close"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:18,height:18,padding:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",borderRadius:4,flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-selected)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsx)(c.X,{size:11,"aria-hidden":"true"})})]})}),_&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:H("desktop.loading")}),V&&(0,r.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:V}),!_&&!V&&"list"===e0&&(0,r.jsxs)(r.Fragment,{children:[0===tJ.length&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:H(e2.trim()?"desktop.noSearchResults":"desktop.noSessionsFound")}),tG.map(t=>(0,r.jsx)(eU,{node:t,selectedSessionId:e,runningSessionIds:ta,unreadSessionIds:td,onSelectSession:tP,onRenamed:tf,selectedSessionStats:A,onSessionDeleted:e=>{R?.(e),tf()},depth:0},t.session.id))]}),!_&&!V&&"groups"===e0&&(0,r.jsxs)(r.Fragment,{children:[0===tJ.length&&(0,r.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:H(e2.trim()?"desktop.noSearchResults":"desktop.noSessionsFound")}),tX.map(t=>{let o=e2.trim().length>0||e6[t.key];return(0,r.jsx)(eK,{groupKey:t.key,label:H(eO[t.key]),rows:t.rows,isOpen:o,onToggle:()=>e5(e=>({...e,[t.key]:!e[t.key]})),onSelectSession:tP,selectedSessionId:e,runningSessionIds:ta,unreadSessionIds:td,allSessions:B,onPinChange:tD,onRenamed:tf,onSessionDeleted:e=>{R?.(e),tf()}},t.key)})]})]}),(I||J)&&(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:e8?"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:()=>e7(e=>{let t=!e;return!function(e,t=ex()){if(t)try{t.setItem(eh,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)(m.K,{size:9,weight:"regular",style:{transform:e8?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},"aria-hidden":"true"}),H("desktop.explorer")]}),e8&&(0,r.jsx)("button",{onClick:()=>tx.current?.openUploadPicker(),disabled:tt,title:H("desktop.uploadFilesToProjectRoot"),"aria-label":H("desktop.uploadFiles"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,background:"none",border:"none",color:"var(--text-dim)",cursor:tt?"default":"pointer",borderRadius:5,flexShrink:0,opacity:tt?.6:1,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{tt||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{tt||(e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none")},children:(0,r.jsx)(S.C,{size:13,weight:"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:()=>{te(e=>e+1),ti(!0),th.current&&clearTimeout(th.current),th.current=setTimeout(()=>ti(!1),2e3)},title:H("desktop.refreshExplorer"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:6,background:ts?"rgba(74,222,128,0.18)":"none",border:"none",color:ts?"#4ade80":"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{ts||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{ts||(e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none")},children:ts?(0,r.jsx)(u.J,{size:13,color:"#4ade80",weight:"regular","aria-hidden":"true"}):(0,r.jsx)(w.S,{size:13,weight:"regular","aria-hidden":"true"})})]}),e8&&(0,r.jsx)("div",{className:"scroll-overlay",style:{flex:1,overflowX:"hidden"},children:(0,r.jsx)(ed,{ref:tx,cwd:J??I,onOpenFile:P??(()=>{}),refreshKey:e9,onAtMention:$,onAtMentions:W,onUploadBusyChange:to})})]}),(I||J)&&(0,r.jsx)(eg,{cwd:J??I,refreshKey:e9,onOpenFile:P??(()=>{})}),N&&(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:5,padding:"7px 8px",borderTop:"1px solid var(--border)",flexShrink:0,marginTop:"auto"},children:[{tab:"models",label:H("desktop.models"),Icon:C.f},{tab:"skills",label:H("desktop.skills"),Icon:T.B},{tab:"plugins",label:H("desktop.plugins"),Icon:z.F}].map(({tab:e,label:t,Icon:o})=>(0,r.jsxs)("button",{type:"button",onClick:()=>N(e),title:t,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:4,minWidth:0,padding:"6px 4px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:10.5},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(o,{size:13,"aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]},e))})]})]})}function eU({node:e,selectedSessionId:t,runningSessionIds:o,unreadSessionIds:s,onSelectSession:i,onRenamed:a,onSessionDeleted:l,selectedSessionStats:d,depth:c}){let[p,u]=(0,n.useState)(!1),g=e.children.length>0;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{position:"relative"},children:[c>0&&(0,r.jsx)("div",{style:{position:"absolute",left:12*c+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,r.jsx)(eV,{session:e.session,isSelected:e.session.id===t,isRunning:o.has(e.session.id),isUnread:s.has(e.session.id),onClick:()=>i(e.session),onRenamed:a,onDeleted:e=>l?.(e),selectedSessionId:t,selectedSessionStats:d,depth:c,hasChildren:g,collapsed:p,onToggleCollapse:()=>u(e=>!e)})]}),g&&!p&&(0,r.jsx)("div",{children:e.children.map(e=>(0,r.jsx)(eU,{node:e,selectedSessionId:t,runningSessionIds:o,unreadSessionIds:s,onSelectSession:i,onRenamed:a,onSessionDeleted:l,selectedSessionStats:d,depth:c+1},e.session.id))})]})}function e_(){let{t:e}=(0,E.s)();return(0,r.jsx)("span",{title:e("desktop.agentRunning"),"aria-label":e("desktop.agentRunningLabel"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"var(--accent)"},children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,r.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})})})}function eq(){let{t:e}=(0,E.s)();return(0,r.jsx)("span",{title:e("desktop.newActivity"),"aria-label":e("desktop.newSessionActivity"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"var(--accent)"},children:(0,r.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,r.jsx)("circle",{cx:"7",cy:"7",r:"3",fill:"currentColor",children:(0,r.jsx)("animate",{attributeName:"opacity",values:"1;0.25;1",dur:"1.6s",repeatCount:"indefinite"})})})})}function eV({session:e,isSelected:t,isRunning:o,isUnread:s,onClick:i,onRenamed:a,onDeleted:l,selectedSessionId:d,selectedSessionStats:p,depth:u=0,hasChildren:h=!1,collapsed:m=!1,onToggleCollapse:k}){let v,{t:y}=(0,E.s)(),[S,T]=(0,n.useState)(!1),[z,I]=(0,n.useState)(!1),[M,P]=(0,n.useState)(""),[D,$]=(0,n.useState)(0),[F,W]=(0,n.useState)(0),[N,A]=(0,n.useState)(!1),[L,O]=(0,n.useState)(!1),[H,B]=(0,n.useState)(!1),[U,_]=(0,n.useState)(null),q=(0,n.useRef)(null),V=(0,n.useRef)(null),K=(0,n.useRef)(null),[J,G]=(0,n.useState)(!1),[Y,Z]=(0,n.useState)([]),[X,Q]=(0,n.useState)(!1),[ee,et]=(0,n.useState)(!1),eo=(0,n.useMemo)(()=>{let e=new Map;for(let t of Y){let o=t.provider||"other",r=e.get(o);r?r.push(t):e.set(o,[t])}return Array.from(e.entries()).sort((e,t)=>e[0].localeCompare(t[0]))},[Y]),er=eE(e.name)||e.firstMessage.slice(0,50)||e.id.slice(0,12),en=e.messageCount>0||e.id===d&&(p?.userMessages??0)>0;(0,n.useLayoutEffect)(()=>{z&&W(V.current?.getBoundingClientRect().width??0)},[z,M,D]);let es=(0,n.useCallback)(e=>{e.stopPropagation(),P(er),$(er.length),I(!0),setTimeout(()=>q.current?.select(),0)},[er]),ei=(0,n.useCallback)(async()=>{let t=M.trim();if(I(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),a?.()}catch{}},[M,e.id,e.name,a]),ea=(0,n.useCallback)(async t=>{if(t.stopPropagation(),!H&&en){B(!0),_(null);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e.id)}/auto-name`,{method:"POST"}),o=await t.json().catch(()=>({}));if(!t.ok||!o.title)throw Error(o.error||`HTTP ${t.status}`);a?.()}catch(e){_(e instanceof Error?e.message:String(e))}finally{B(!1)}}},[H,en,e.id,a]),el=(0,n.useCallback)(async()=>{G(!0),Q(!0);try{let t=await fetch(`/api/models?cwd=${encodeURIComponent(e.cwd||"")}`),o=await t.json().catch(()=>({}));Z(o.modelList??[])}catch{Z([])}finally{Q(!1)}},[e.cwd]),ed=(0,n.useCallback)(async t=>{et(!0);try{await fetch("/api/settings/title-model",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({modelId:t})}),G(!1),_(null),B(!0);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e.id)}/auto-name`,{method:"POST"}),o=await t.json().catch(()=>({}));if(!t.ok||!o.title)throw Error(o.error||`HTTP ${t.status}`);a?.()}catch(e){_(e instanceof Error?e.message:String(e))}finally{B(!1)}}catch{}finally{et(!1)}},[e.id,a]),ec=(0,n.useCallback)(async()=>{O(!0);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"});if(!t.ok)throw Error(`HTTP ${t.status}`);l?.(e.id)}catch{O(!1)}},[e.id,l]),ep=(0,n.useCallback)(e=>{e.stopPropagation(),e.shiftKey?ec():A(!0)},[ec]),eu=(0,n.useCallback)(e=>{e.stopPropagation(),A(!1),ec()},[ec]),eg=(0,n.useCallback)(e=>{e.stopPropagation(),A(!1)},[]);return(0,r.jsx)("div",{ref:K,onClick:N||z?void 0:i,onMouseEnter:()=>T(!0),onMouseLeave:()=>{T(!1)},style:{height:50,display:"flex",alignItems:"center",paddingLeft:u>0?12*u+14:14,paddingRight:8,cursor:N||z?"default":"pointer",background:N?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":S?"var(--bg-hover)":"transparent",borderLeft:N?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:L?.5:1,gap:6,overflow:"hidden"},children:N?(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:y("desktop.deleteSession",{title:`“${er.slice(0,22)}${er.length>22?"…":""}”`})}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,r.jsxs)("button",{onClick:eu,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)(j.l,{size:12,weight:"regular","aria-hidden":"true"}),y("desktop.delete")]}),(0,r.jsx)("button",{onClick:eg,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:y("desktop.cancel")})]})]}):(0,r.jsxs)(r.Fragment,{children:[u>0&&(0,r.jsx)(f.Z,{size:10,color:"var(--text-dim)",weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,minWidth:0,height:20,fontSize:12,fontWeight:t?500:400,lineHeight:"20px",color:"var(--text)"},title:o?`${er} \xb7 ${y("desktop.agentRunning")}`:s?`${er} \xb7 ${y("desktop.newActivity")}`:er,children:[o?(0,r.jsx)(e_,{}):s?(0,r.jsx)(eq,{}):null,z?(0,r.jsxs)("div",{style:{position:"relative",flex:"1 1 0",alignSelf:"stretch",width:"100%",minWidth:0,height:20,background:"color-mix(in srgb, var(--accent) 18%, var(--bg))",borderRadius:3},children:[(0,r.jsx)("span",{ref:V,"aria-hidden":"true",style:{position:"absolute",visibility:"hidden",whiteSpace:"pre",font:"inherit",lineHeight:"inherit"},children:M.slice(0,D)}),(0,r.jsx)("span",{"aria-hidden":"true",style:{position:"absolute",top:2,bottom:2,left:F,width:2,background:"var(--accent)",borderRadius:1,animation:"blink 1s step-end infinite",pointerEvents:"none"}}),(0,r.jsx)("input",{ref:q,value:M,onChange:e=>{P(e.target.value),$(e.target.selectionStart??e.target.value.length)},onSelect:e=>$(e.currentTarget.selectionEnd??0),onBlur:ei,onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),ei()),"Escape"===e.key&&(e.preventDefault(),I(!1))},"aria-label":y("desktop.rename"),autoFocus:!0,style:{width:"100%",minWidth:0,height:20,margin:0,padding:0,border:"none",outline:"none",background:"transparent",borderRadius:"inherit",color:"inherit",font:"inherit",lineHeight:"inherit",caretColor:"transparent"}})]}):(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,flex:1},children:er}),h&&(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),k?.()},title:y(m?"desktop.expandForks":"desktop.collapseForks"),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:m?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,r.jsx)(x.a,{size:10,weight:"regular","aria-hidden":"true"})}),S&&!z&&(0,r.jsxs)("div",{style:{display:"flex",gap:2,flexShrink:0},children:[(0,r.jsx)("button",{onClick:ea,disabled:H||!en,title:U??y(en?H?"desktop.generatingTitle":"desktop.generateTitle":"desktop.titleNeedsMessages"),"aria-label":y("desktop.generateTitle"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"none",border:"none",borderRadius:4,color:U?"#ef4444":"var(--text-dim)",cursor:H||!en?"default":"pointer",flexShrink:0,opacity:H?.7:en?1:.35,transition:"color 0.12s"},onMouseEnter:e=>{!H&&en&&(e.currentTarget.style.color=U?"#ef4444":"var(--accent)")},onMouseLeave:e=>{e.currentTarget.style.color=U?"#ef4444":"var(--text-dim)"},children:H?(0,r.jsxs)("svg",{style:{animation:"spin 1s linear infinite"},width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,r.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):(0,r.jsx)(b.R,{size:13,weight:"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:es,title:y("desktop.rename"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"none",border:"none",borderRadius:4,color:"var(--text-dim)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)(g.I,{size:13,weight:"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:ep,title:y("desktop.deleteWithShift"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"none",border:"none",borderRadius:4,color:"var(--text-dim)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="#ef4444"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)(j.l,{size:13,weight:"regular","aria-hidden":"true"})})]})]}),(0,r.jsxs)("div",{style:{marginTop:2,display:"flex",gap:8,color:"var(--text-dim)",fontSize:11,minWidth:0,flexWrap:"nowrap",whiteSpace:"nowrap"},children:[(0,r.jsx)("span",{title:e.modified,style:{flexShrink:0},children:eD(e.modified,y)}),(0,r.jsx)("span",{style:{flexShrink:0},children:y("desktop.messagesCount",{count:e.messageCount})}),e.worktreeBranch&&(0,r.jsxs)("span",{title:y("desktop.worktree",{cwd:e.cwd}),style:{display:"flex",alignItems:"center",gap:3,color:"var(--accent)",minWidth:0,overflow:"hidden",flex:"1 1 auto"},children:[(0,r.jsx)(f.Z,{size:9,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.worktreeBranch})]}),e.importedFrom&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:3,color:"var(--text-dim)",minWidth:0,overflow:"hidden",flexShrink:1},children:[(0,r.jsx)(R.z,{size:9,weight:"regular",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"reasonix"===e.importedFrom?y("desktop.importFromReasonix")??"来自 Reasonix":e.importedFrom})]})]}),U&&K.current&&(v=K.current.getBoundingClientRect(),(0,r.jsxs)("div",{style:{position:"fixed",top:Math.max(8,v.top+v.height/2-34),left:v.right+10,zIndex:3e3,width:300,padding:"10px 12px",borderRadius:10,background:"var(--bg-panel)",border:"1px solid color-mix(in srgb, #ef4444 40%, var(--border))",boxShadow:"0 10px 30px rgba(0,0,0,0.25)",animation:"plan-card-in 0.15s ease-out"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:650,color:"#ef4444",flex:1,minWidth:0},children:y("desktop.titleGenerationFailed")}),(0,r.jsx)("button",{type:"button",onClick:()=>_(null),"aria-label":y("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(c.X,{size:12,"aria-hidden":"true"})})]}),(0,r.jsx)("div",{style:{fontSize:11,lineHeight:1.45,color:"var(--text-muted)",wordBreak:"break-word",marginBottom:8},children:U}),(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsxs)("button",{type:"button",onClick:ea,disabled:H,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"5px 10px",borderRadius:6,background:"#ef4444",border:"none",color:"#fff",fontSize:11.5,fontWeight:600,cursor:H?"default":"pointer"},children:[(0,r.jsx)(w.S,{size:11,"aria-hidden":"true"}),y("desktop.retry")]}),(0,r.jsxs)("button",{type:"button",onClick:el,disabled:ee,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"5px 10px",borderRadius:6,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:11.5,cursor:ee?"default":"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,r.jsx)(C.f,{size:11,"aria-hidden":"true"}),y("desktop.changeTitleModel")]})]})]})),J&&(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:3100,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.4)",padding:16},onMouseDown:e=>{e.target===e.currentTarget&&G(!1)},children:(0,r.jsxs)("div",{role:"dialog","aria-label":y("desktop.changeTitleModel"),style:{width:"min(420px, calc(100vw - 32px))",maxHeight:"min(70vh, 480px)",display:"flex",flexDirection:"column",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 16px 40px rgba(0,0,0,0.3)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)(C.f,{size:15,"aria-hidden":"true"}),(0,r.jsx)("span",{style:{fontSize:13,fontWeight:650,color:"var(--text)",flex:1},children:y("desktop.changeTitleModel")}),(0,r.jsx)("button",{type:"button",onClick:()=>G(!1),"aria-label":y("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:3,display:"flex"},children:(0,r.jsx)(c.X,{size:14,"aria-hidden":"true"})})]}),(0,r.jsx)("div",{className:"scroll-overlay",style:{padding:"8px 6px",flex:1},children:X?(0,r.jsx)("div",{style:{padding:"12px 8px",fontSize:12,color:"var(--text-muted)"},children:y("desktop.loading")}):0===Y.length?(0,r.jsx)("div",{style:{padding:"12px 8px",fontSize:12,color:"var(--text-muted)"},children:y("desktop.noModels")}):eo.map(([e,t])=>(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"capitalize"},children:e}),t.map(e=>{let t=`${e.provider||"other"}\u0000${e.id}`;return(0,r.jsx)("button",{type:"button",onClick:()=>{ed(e.id)},disabled:ee,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:"none",border:"none",borderRadius:7,color:"var(--text)",fontSize:12.5,cursor:ee?"default":"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name||e.id})},t)})]},e))})]})})]})]})})}function eK({groupKey:e,label:t,rows:o,isOpen:n,onToggle:s,onSelectSession:i,selectedSessionId:a,runningSessionIds:l,unreadSessionIds:d,allSessions:c,onPinChange:p,onRenamed:u,onSessionDeleted:g}){let{t:h}=(0,E.s)();return(0,r.jsxs)("div",{style:{margin:"0 8px 6px",borderRadius:10,background:"var(--bg-panel)",border:"1px solid var(--border)",overflow:"hidden"},children:[(0,r.jsxs)("button",{type:"button",onClick:s,"aria-expanded":n,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"7px 10px",background:"none",border:"none",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)(x.a,{size:11,weight:"regular","aria-hidden":"true",style:{flexShrink:0,transform:n?"rotate(0deg)":"rotate(-90deg)",transition:"transform 0.15s"}}),(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--text-muted)"},children:t}),(0,r.jsx)("span",{style:{background:"var(--bg-hover)",borderRadius:999,padding:"0 6px",fontSize:10,fontWeight:600,color:"var(--text-muted)",lineHeight:"16px",flexShrink:0},children:o.length}),(0,r.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)",flexShrink:0},children:h(n?"desktop.collapseGroup":"desktop.expandGroup")})]}),n&&(0,r.jsx)("div",{style:{padding:"2px 4px 6px"},children:o.map((t,o)=>(0,r.jsx)("div",{style:{animation:"accordion-row-in 0.14s ease-out both",animationDelay:`${20*Math.min(o,10)}ms`},children:(0,r.jsx)(eJ,{session:t.session,forkDepth:t.forkDepth,isSelected:t.session.id===a,isRunning:l.has(t.session.id),isUnread:d.has(t.session.id),onClick:()=>i(t.session),allSessions:c,onPinChange:p,onRenamed:u,onDeleted:g,inPinnedGroup:"pinned"===e})},t.session.id))})]})}function eJ({session:e,forkDepth:t=0,isSelected:o,isRunning:s,isUnread:i,onClick:a,allSessions:l,onPinChange:d,onRenamed:c,onDeleted:p,inPinnedGroup:u=!1}){let h,{t:x}=(0,E.s)(),[m,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(!1),[w,S]=(0,n.useState)(""),[C,T]=(0,n.useState)(!1),[z,R]=(0,n.useState)(!1),[P,D]=(0,n.useState)(!1),[$,F]=(0,n.useState)(!1),[W,N]=(0,n.useState)(null),A=(0,n.useRef)(null),L=eE(e.name)||e.firstMessage.slice(0,50)||e.id.slice(0,12),O=e.parentSessionId?l.find(t=>t.id===e.parentSessionId):void 0,H=async()=>{let t=w.trim();if(y(!1),t&&t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),c?.()}catch{}},B=async t=>{if(t.stopPropagation(),!P&&0!==e.messageCount){D(!0);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e.id)}/auto-name`,{method:"POST"}),o=await t.json().catch(()=>({}));if(!t.ok||!o.title)throw Error(o.error||`HTTP ${t.status}`);c?.()}catch{}finally{D(!1)}}},U=async()=>{R(!0);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"});if(!t.ok)throw Error(`HTTP ${t.status}`);p?.(e.id)}catch{R(!1)}};return(0,r.jsxs)("div",{ref:A,onClick:C||v?void 0:a,onMouseEnter:()=>k(!0),onMouseLeave:()=>{k(!1),F(!1)},style:{display:"flex",flexDirection:"column",justifyContent:"center",padding:"5px 8px 5px 10px",paddingLeft:10+14*t,position:"relative",cursor:C||v?"default":"pointer",background:C?"rgba(239,68,68,0.06)":o?"var(--bg-selected)":m?"var(--bg-hover)":"transparent",borderLeft:C?"2px solid #ef4444":o?"2px solid var(--accent)":"2px solid transparent",borderRadius:6,transition:"background 0.1s",opacity:z?.5:1},children:[t>0&&(0,r.jsx)("span",{"aria-hidden":"true",style:{position:"absolute",left:12+(t-1)*14,top:2,bottom:2,width:2,borderRadius:1,background:"var(--border)",pointerEvents:"none"}}),C?(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:x("desktop.deleteSession",{title:`"${L.slice(0,22)}${L.length>22?"…":""}"`})}),(0,r.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,r.jsxs)("button",{onClick:e=>{e.stopPropagation(),U()},style:{display:"flex",alignItems:"center",gap:4,height:28,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,r.jsx)(j.l,{size:12,weight:"regular","aria-hidden":"true"}),x("desktop.delete")]}),(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),T(!1)},style:{height:28,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,whiteSpace:"nowrap"},children:x("desktop.cancel")})]})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,minWidth:0,height:20},children:[s?(0,r.jsx)(e_,{}):i?(0,r.jsx)(eq,{}):null,v?(0,r.jsx)("input",{autoFocus:!0,value:w,onChange:e=>S(e.target.value),onBlur:H,onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),H()),"Escape"===e.key&&(e.preventDefault(),y(!1))},"aria-label":x("desktop.rename"),style:{flex:1,minWidth:0,height:18,margin:0,padding:"0 4px",border:"1px solid var(--accent)",borderRadius:3,outline:"none",background:"color-mix(in srgb, var(--accent) 18%, var(--bg))",color:"var(--text)",fontSize:12}}):(0,r.jsx)("span",{title:e.modified,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0,flex:1,fontSize:12,fontWeight:o?500:400,color:"var(--text)"},children:L}),m&&!v&&(0,r.jsxs)("div",{style:{display:"flex",gap:1,flexShrink:0},children:[(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),d?.(e,!e.pinned)},title:x(e.pinned?"desktop.unpin":"desktop.pin"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"none",border:"none",borderRadius:4,color:e.pinned?"var(--accent)":"var(--text-dim)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:t=>{t.currentTarget.style.color=e.pinned?"var(--accent)":"var(--text-muted)"},onMouseLeave:t=>{t.currentTarget.style.color=e.pinned?"var(--accent)":"var(--text-dim)"},children:(0,r.jsx)(I.U,{size:12,weight:e.pinned?"fill":"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:B,disabled:P||0===e.messageCount,title:x(0===e.messageCount?"desktop.titleNeedsMessages":P?"desktop.generatingTitle":"desktop.generateTitle"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"none",border:"none",borderRadius:4,color:"var(--text-dim)",cursor:P||0===e.messageCount?"default":"pointer",flexShrink:0,opacity:P?.7:0===e.messageCount?.35:1,transition:"color 0.12s"},onMouseEnter:t=>{P||0===e.messageCount||(t.currentTarget.style.color="var(--accent)")},onMouseLeave:t=>{P||0===e.messageCount||(t.currentTarget.style.color="var(--text-dim)")},children:P?(0,r.jsxs)("svg",{style:{animation:"spin 1s linear infinite"},width:"12",height:"12",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,r.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):(0,r.jsx)(b.R,{size:12,weight:"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),S(L),y(!0)},title:x("desktop.rename"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"none",border:"none",borderRadius:4,color:"var(--text-dim)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)(g.I,{size:12,weight:"regular","aria-hidden":"true"})}),(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),e.shiftKey?U():T(!0)},title:x("desktop.deleteWithShift"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"none",border:"none",borderRadius:4,color:"var(--text-dim)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="#ef4444"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)(j.l,{size:12,weight:"regular","aria-hidden":"true"})})]}),e.pinned&&!u&&!m&&(0,r.jsx)("span",{title:x("desktop.pinned"),style:{flexShrink:0,display:"inline-flex",alignItems:"center",opacity:.85},children:(0,r.jsx)(I.U,{size:11,weight:"fill",color:"var(--accent)","aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:1,minWidth:0,height:16,flexWrap:"nowrap",whiteSpace:"nowrap"},children:[(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",flexShrink:0},children:eD(e.modified,x)}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",flexShrink:0},children:x("desktop.messagesCount",{count:e.messageCount})}),e.worktreeBranch&&(0,r.jsxs)("span",{title:e.worktreeBranch,style:{display:"inline-flex",alignItems:"center",gap:3,maxWidth:"60%",background:"var(--bg-hover)",borderRadius:4,padding:"0 5px",height:15,minWidth:0,overflow:"hidden"},children:[(0,r.jsx)(f.Z,{size:8,weight:"regular",color:"var(--text-dim)",style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-muted)",lineHeight:"15px"},children:e.worktreeBranch})]}),e.parentSessionId&&(0,r.jsx)("span",{style:{marginLeft:"auto",flexShrink:0,display:"inline-flex",alignItems:"center"},onMouseEnter:e=>{let t=A.current?.getBoundingClientRect();t&&(N({top:t.top+t.height/2-15,left:t.right+8}),F(!0))},onMouseLeave:()=>F(!1),children:(0,r.jsx)(M.d,{size:10,weight:"regular",color:"var(--text-dim)",style:{cursor:"help"},"aria-hidden":"true"})})]}),$&&W&&(h=O?eE(O.name)||O.firstMessage.slice(0,30)||O.id.slice(0,8):"",(0,r.jsx)("div",{style:{position:"fixed",top:W.top,left:W.left,zIndex:3e3,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,padding:"4px 8px",boxShadow:"0 6px 20px rgba(0,0,0,0.2)",fontSize:10.5,color:"var(--text-muted)",whiteSpace:"nowrap",pointerEvents:"none",animation:"plan-card-in 0.12s ease-out"},children:x("desktop.forkedFrom",{title:h||"—"})}))]})]})}let eG=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,eY=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,eZ=/\x1B\[([0-9;]*)m/g,eX=["#1f2937","#dc2626","#16a34a","#d97706","#2563eb","#9333ea","#0891b2","#6b7280"],eQ=["#9ca3af","#ef4444","#22c55e","#f59e0b","#3b82f6","#a855f7","#06b6d4","#e5e7eb"];function e0(e){return e.replace(eG,"")}function e1(e){let t=[],o=0;for(;o<e.length;){if(27===e.charCodeAt(o)){let t=e.slice(o).match(eY);if(t){o+=t[0].length;continue}}let r=e.codePointAt(o);if(void 0===r)break;let n=String.fromCodePoint(r);t.push({start:o,end:o+n.length,char:n}),o+=n.length}return t}function e2(e,t){let o=e1(e)[t];return o?e.slice(0,o.start)+e.slice(o.end):e}function e4(e){return e1(e)[0]?.char}function e6(e,t={}){return"thinking"===e.type&&!e.deferred&&!t.isStreaming&&""===e.thinking.trim()}function e5(e,t={}){return(e.content??[]).filter(e=>!e6(e,t))}function e3(e,t={}){let o=e5(e,t),r=o.findLastIndex(e=>"text"!==e.type&&"image"!==e.type);return -1===r?{answerBlocks:o,processBlocks:[]}:{answerBlocks:o.slice(r+1),processBlocks:o.slice(0,r+1)}}function e8(e){try{return decodeURIComponent(e)}catch{return e}}function e7(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function e9(e){let t=e7(e),o=/^[a-zA-Z]:\//.test(t),r=t.startsWith("//"),n=t.startsWith("/")&&!o&&!r,s=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){s.length>0&&".."!==s[s.length-1]?s.pop():n||o||r||s.push(e);continue}s.push(e)}let i=s.join("/");return o?i:r?`//${i}`:n?`/${i}`:i}function te(e,t,o=t){let r,n,s,i,a;if(!e)return null;let l=e.split("#",1)[0].split("?",1)[0].trim();if(!l)return null;let d=null,c=null,p=e8(l),u=p.startsWith("\\\\"),g=e7(p),h=g.toLowerCase();if(h.startsWith("/api/")||h.startsWith("/_next/")||!u&&g.startsWith("//")||/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(g)&&!h.startsWith("file:")&&!/^[a-zA-Z]:\//.test(g))return null;if(h.startsWith("file:")?c=(d=function(e){try{let t=new URL(e);if("file:"!==t.protocol)return null;let o=e8(t.pathname);if(t.hostname)return`//${t.hostname}${o.startsWith("/")?o:`/${o}`}`;if(/^\/[a-zA-Z]:\//.test(o))return o.slice(1);return o}catch{return null}}(g))?"absolute":null:/^[a-zA-Z]:\//.test(g)||g.startsWith("/")?(d=g,c="absolute"):t&&!(g.startsWith("#")||g.startsWith("?"))&&(g.startsWith("./")||g.startsWith("../")||g.includes("/")||/(^|\/)\.?[^/]+\.[^/.]+$/.test(g))&&(d=`${e7(t).replace(/\/+$/,"")}/${g}`,c="relative"),!d)return null;let x=e9(d).replace(/:\d+(?::\d+)?$/,"");return"relative"===c&&o&&(r=e9(x).replace(/\/+$/,""),n=e9(o).replace(/\/+$/,""),i=(s=/^[a-zA-Z]:\//.test(r)||/^[a-zA-Z]:\//.test(n))?r.toLowerCase():r,!(i===(a=s?n.toLowerCase():n)||i.startsWith(`${a}/`)))?null:x}function tt(e,t){return(e.content??[]).filter(e=>"thinking"!==e.type||e.deferred||t||e.thinking.trim().length>0)}function to(e,t,o){return`${e??`message-${t}`}:${o}`}function tr(e,t){let{messageIndex:o,entryId:r,phase:n,toolResults:s,isStreaming:i=!1}=t;return"custom"===e.role?e.display?[{id:to(r,o,0),type:"custom",customType:e.customType,message:e,origin:{phase:n,placement:"standalone",sourceMessageIndex:o,sourceEntryId:r}}]:[]:"assistant"!==e.role?[]:(t.blocks??tt(e,i)).map((t,i)=>{let a=e.content.indexOf(t),l=a>=0?a:i,d={phase:n,placement:"standalone",sourceMessageIndex:o,sourceEntryId:r,sourceBlockIndex:l},c=to(r,o,l);if("text"===t.type)return{id:c,type:"text",text:t.text,origin:d};if("image"===t.type)return{id:c,type:"image",source:t.source,origin:d};if("thinking"===t.type)return{id:c,type:"thinking",thinking:t.thinking,deferred:t.deferred,origin:d};let p=s?.get(t.toolCallId);return{id:c,type:"toolCall",toolCallId:t.toolCallId,toolName:t.toolName,input:t.input,result:p,duration:function(e,t){if(!e.timestamp||!t?.timestamp)return;let o=Math.round((t.timestamp-e.timestamp)/1e3);return o>0?o:void 0}(e,p),status:p?.isError?"error":p?"success":"running",origin:{...d,groupId:t.toolCallId}}})}function tn(e,t){let o=tt(e,t.isStreaming??!1),r=o.findLastIndex(e=>"text"!==e.type&&"image"!==e.type),n=-1===r?[]:o.slice(0,r+1),s=-1===r?o:o.slice(r+1);return{processBlocks:tr(e,{...t,phase:"process",blocks:n}),resultBlocks:tr(e,{...t,phase:"result",blocks:s})}}function ts(e,t,o,r){return o.flatMap(o=>tr(e[o],{messageIndex:o,entryId:t[o],phase:"process",toolResults:r}))}var ti=o(19447),ta=o(32316),tl=o(16764);let td=new Set;function tc(e){return td.add(e),()=>{td.delete(e)}}function tp(){td.forEach(e=>e())}let tu="pi-theme-mode",tg="pi-theme",th="pi-theme-light",tx="pi-theme-dark",tf="pi-border-depth";function tm(e){try{let t="dark"===e?tx:th,o=localStorage.getItem(t);if(o)return o;let r=function(e){try{let t=localStorage.getItem(tg);if(!t||"dark"===t||"light"===t)return null;let o="dark"===e?tx:th;return localStorage.getItem(o)||localStorage.setItem(o,t),localStorage.removeItem(tg),t}catch{}return null}(e);if(r)return r}catch{}return""}function tk(e,t){try{localStorage.setItem("dark"===e?tx:th,t),localStorage.removeItem(tg)}catch{}}function tv(){try{let e=localStorage.getItem(tf);if(null!==e){let t=parseInt(e,10);if(!isNaN(t)&&t>=0&&t<=100)return t}}catch{}return 50}function ty(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function tb(e){return"system"===e?ty()?"dark":"light":e}function tw(){if("u"<typeof document)return"dark";let e=document.documentElement.dataset.themeMode;if("dark"===e||"light"===e||"system"===e)return e;try{let e=localStorage.getItem(tu);if("dark"===e||"light"===e||"system"===e)return e}catch{}return"dark"}function tj(){if("u"<typeof document)return"";let e=document.documentElement.dataset.theme;return e||tm(tb(tw()))}function tS(){return"dark"}let tC=["--bg","--bg-panel","--bg-secondary","--bg-card","--bg-hover","--bg-selected","--bg-card-hover","--bg-subtle","--border","--border-hover","--text","--text-muted","--text-dim","--accent","--accent-hover","--accent-blue","--accent-red","--accent-green","--accent-orange","--git-status-added","--git-status-modified","--git-status-deleted","--git-status-added-bg","--git-status-modified-bg","--git-status-deleted-bg","--user-bg","--assistant-bg","--tool-bg","--hatch-color","--status-error","--status-warning","--status-success","--status-info","--status-error-bg","--status-warning-bg","--status-success-bg","--status-info-bg","--status-error-border","--status-warning-border","--status-success-border","--status-info-border","--syntax-keyword","--syntax-string","--syntax-number","--syntax-function","--syntax-comment"],tT=["--border-orig","--border-hover-orig"];function tz(){let e=document.documentElement;for(let t of tC)e.style.removeProperty(t);for(let t of tT)e.style.removeProperty(t)}function tR(e){let t=document.documentElement,o=document.documentElement,r=o.style.getPropertyValue("--border-orig").trim(),n=o.style.getPropertyValue("--border-hover-orig").trim();if(!r||!n){let e=getComputedStyle(o);!r&&(r=e.getPropertyValue("--border").trim())&&o.style.setProperty("--border-orig",r),!n&&(n=e.getPropertyValue("--border-hover").trim())&&o.style.setProperty("--border-hover-orig",n)}if(50===e){let e=t.style.getPropertyValue("--border-orig").trim(),o=t.style.getPropertyValue("--border-hover-orig").trim();e?t.style.setProperty("--border",e):t.style.removeProperty("--border"),o?t.style.setProperty("--border-hover",o):t.style.removeProperty("--border-hover");return}let s=e/100,i=e=>{if(s<=.5){let t=Math.round(2*s*100);return`color-mix(in srgb, var(${e}) ${t}%, var(--bg) ${100-t}%)`}{let t=Math.round((s-.5)*200);return`color-mix(in srgb, var(${e}) ${100-t}%, var(--text) ${t}%)`}};t.style.setProperty("--border",i("--border-orig")),t.style.setProperty("--border-hover",i("--border-hover-orig"))}let tI=new Map;async function tM(e,t){let o=`${e}::${t}`;if(tI.has(o))return tI.get(o);try{let r=await fetch(`/api/themes/${encodeURIComponent(e)}?mode=${t}`);if(!r.ok)return null;let n=await r.json();return tI.set(o,n),n}catch{return null}}async function tE(e,t){let o=document.documentElement;if("dark"===e?o.classList.add("dark"):o.classList.remove("dark"),!t){delete o.dataset.theme,tz();return}o.dataset.theme=t;let r=await tM(t,e);if(r){var n=r.cssVars;let e=document.documentElement;for(let t of tC)n[t]?e.style.setProperty(t,n[t]):e.style.removeProperty(t);n["--border"]?e.style.setProperty("--border-orig",n["--border"]):e.style.removeProperty("--border-orig"),n["--border-hover"]?e.style.setProperty("--border-hover-orig",n["--border-hover"]):e.style.removeProperty("--border-hover-orig")}else console.warn(`Theme "${t}" variant "${e}" not found, using defaults`),tz()}function tP(){let e=(0,n.useSyncExternalStore)(tc,tw,tS),t=(0,n.useSyncExternalStore)(tc,tj,()=>""),[o,r]=(0,n.useState)(()=>{if("u">typeof document){let e=document.documentElement.dataset.themeResolvedMode;if("dark"===e||"light"===e)return e}return tb(tw())}),[s,i]=(0,n.useState)(()=>tv()),a=(0,n.useCallback)(e=>{let t=Math.max(0,Math.min(100,Math.round(e)));i(t);try{localStorage.setItem(tf,String(t))}catch{}tR(t)},[]),l="dark"===o,d=(0,n.useRef)(!1),c=(0,n.useCallback)((e,t,o)=>{let n=document.documentElement;n.dataset.themeMode=t,n.dataset.themeResolvedMode=e,"dark"===e?n.classList.add("dark"):n.classList.remove("dark"),o?n.dataset.theme=o:delete n.dataset.theme,r(e)},[]);(0,n.useEffect)(()=>{let o=document.documentElement,r=o.dataset.themeMode,n=o.dataset.theme,s="dark"===r||"light"===r||"system"===r?r:e,i=n||t;if(d.current)return;d.current=!0;let a=tb(s);c(a,s,i),tE(a,i).finally(()=>{d.current=!1;try{localStorage.setItem(tu,s)}catch{}tk(a,i),tR(tv()),tp()})},[]),(0,n.useEffect)(()=>{var e;let t;return e=()=>{if("system"===tw()){let e=ty()?"dark":"light",t=tm(e);c(e,"system",t),tE(e,t),tR(tv()),tp()}},(t=window.matchMedia("(prefers-color-scheme: dark)")).addEventListener("change",e),()=>t.removeEventListener("change",e)},[c]);let p=(0,n.useCallback)(async e=>{if(!d.current){d.current=!0;try{await tE(o,e),tk(o,e);let t=tw();c(o,t,e),tR(tv()),tp()}finally{d.current=!1}}},[o,c]),u=(0,n.useCallback)(async e=>{if(d.current)return;d.current=!0;let t=tb(e),o=tm(t);try{await tE(t,o);try{localStorage.setItem(tu,e)}catch{}c(t,e,o),tR(tv()),tp()}finally{d.current=!1}},[c]),g=(0,n.useCallback)(e=>{let t=tw(),r="system"===t?"dark"===o?"light":"dark":"dark"===t?"light":"dark",n=()=>{u(r)},s=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||s)return void n();let i=e?.x??window.innerWidth/2,a=e?.y??window.innerHeight/2,l=Math.hypot(Math.max(i,window.innerWidth-i),Math.max(a,window.innerHeight-a));document.startViewTransition(()=>{n()}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${i}px ${a}px)`,`circle(${l}px at ${i}px ${a}px)`]},{duration:450,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})}).catch(()=>{})},[o,u]);return{mode:e,resolvedMode:o,themeName:t,setMode:u,setTheme:p,toggleTheme:g,isDark:l,borderDepth:s,setBorderDepth:a}}function tD(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);try{let t=document.createElement("textarea");return t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch{return Promise.reject()}}function t$(e,t,o){let r=function(e){let t=0xdeadbeef,o=0x41c6ce57;for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);t=Math.imul(t^n,0x9e3779b1),o=Math.imul(o^n,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(o^o>>>13,0xc2b2ae35),(0x100000000*(2097151&(o=Math.imul(o^o>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)).toString(36)}(e);if(o){let n=o.get(r);if(void 0!==n)return{id:r,text:n,tail:t};o.set(r,e)}return{id:r,text:e,tail:t}}let tF=/^ {0,3}(`{3,}|~{3,})/;var tW=o(73342),tN=o(94764),tA=o(63835),tL=o(84678),tO=o(98164);let tH={...tN.j,attributes:{...tN.j.attributes,code:[["className",/^language-./,"math-inline","math-display"]]},strip:[...tN.j.strip||[],"iframe","object","style","form"]};function tB(e){return String(e).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g,"-").replace(/^-+|-+$/g,"")}function tU(e){let t=e.includes("\r\n")?"\r\n":"\n",o=e.split(/\r?\n/),r=[],n=null,s=0,i=null,a=new Map;for(let e=0;e<o.length;e++){var l;let t=o[e];if(i){r.push(t),RegExp(`</${i}\\s*>`,"i").test(t)&&(i=null);continue}let d=t.match(/^ {0,3}(`{3,}|~{3,})/);if(d){let e=d[1][0],o=d[1].length;n?e===n.marker&&o>=n.size&&(n=null):n={marker:e,size:o},s=0,r.push(t);continue}if(n){r.push(t);continue}let c=t.match(/<(code|pre|script|style)\b/i);if(c){let e=c[1].toLowerCase(),o=t.slice((c.index??0)+c[0].length);RegExp(`</${e}\\s*>`,"i").test(o)||(i=e),s=0,r.push(t);continue}if(/^(?: {4}|\t)/.test(t)||""===t.trim()){s=0,r.push(t);continue}if(s||t.includes("`")){s=function(e,t){let o=t;for(let t=0;t<e.length;){if("`"!==e[t]){t++;continue}let r=t+1;for(;"`"===e[r];)r++;let n=r-t;0===o?o=n:n===o&&(o=0),t=r}return o}(t,s),r.push(t);continue}let p=t.match(/^([ ]{0,3})\\\[[ \t]*(.+?)[ \t]*\\\][ \t]*$/);if(p){let e=p[2].trim();if(e){r.push(`${p[1]}$$`,`${p[1]}${e}`,`${p[1]}$$`);continue}}let u=t.match(/^([ ]{0,3})\\\[[ \t]*$/);if(u){let t=function(e,t){for(let o=t;o<e.length;o++){let t=e[o];if(/^ {0,3}\\\][ \t]*$/.test(t))return o;if(/^ {0,3}(`{3,}|~{3,})/.test(t)||/^ {0,3}\\\[[ \t]*$/.test(t)||/<(code|pre|script|style)\b/i.test(t))break}return -1}(o,e+1);if(-1!==t){r.push(`${u[1]}$$`,...o.slice(e+1,t).map(e=>tq(e,u[1])),`${u[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 h=t.match(/^([ \t]{0,3})\$\$(.+)$/);if(h){let t=h[1],n=h[2].trimEnd();if(n&&!n.includes("$$")){let s=t_(o,e+1,t,a);if(s){r.push(`${t}$$`,`${t}${n}`);for(let n=e+1;n<s.index;n++)r.push(tq(o[n],t));s.content&&r.push(`${t}${s.content}`),r.push(`${t}$$`),e=s.index;continue}}}let x=t.match(/^([ \t]{0,3})\$\$\s*$/);if(x){let t=x[1],n=t_(o,e+1,t,a);if(n&&(n.glued||""!==t)){r.push(`${t}$$`);for(let s=e+1;s<n.index;s++)r.push(tq(o[s],t));n.content&&r.push(`${t}${n.content}`),r.push(`${t}$$`),e=n.index;continue}}r.push((l=t,/^\s{0,3}\[[^\]]+\]:/.test(l)||/]\s*\(/.test(l)||/<(?:!--|\/?[A-Za-z][^>]*>)/.test(l)||/\b(?:https?|file|mailto):/i.test(l)||/\b[A-Za-z]:\\/.test(l)?l:l.replace(/(?<!\\)\\\(([^`\r\n$]+?)(?<!\\)\\\)/g,(e,t)=>t.trim()?`$${t}$`:e)))}return r.join(t)}function t_(e,t,o,r){let n=r.get(o);if(void 0!==n&&t<n)return null;for(let n=t;n<e.length;n++){var s,i,a,l;let t=e[n];if(s=t,""===(i=o)?/^ {0,3}\$\$\s*$/.test(s):s.startsWith(i)&&/^\$\$\s*$/.test(s.slice(i.length)))return{index:n,content:"",glued:!1};if(a=t,/^ {0,3}(`{3,}|~{3,})/.test(a)||/^[ \t]*(?:[-+*]|\d{1,9}[.)])(?:[ \t]+|$)/.test(a)||/^ {0,3}#{1,6}(?:[ \t]+|$)/.test(a)||/^ {0,3}>/.test(a)||/<(code|pre|script|style)\b/i.test(a)||(l=t,/^ {0,3}\$\$(?:\S|[ \t]+\S)/.test(l)))return r.set(o,n),null;let d=function(e,t){if(!e.startsWith(t))return null;let o=e.slice(t.length).match(/^(.+?)\$\$\s*$/);if(!o)return null;let r=o[1].trimEnd();return r&&!r.includes("$$")?r:null}(t,o);if(null!==d)return{index:n,content:d,glued:!0}}return r.set(o,e.length),null}function tq(e,t){if(!t||!e||e.startsWith(" "))return e;let o=e.match(/^ */)?.[0].length??0;return o>=t.length?e:`${t.slice(o)}${e}`}let tV=[[tL.A,{singleTilde:!1}],tO.A];tL.A,tO.A;let tK=[[tA.A,tH],[tW.A,{throwOnError:!1,strict:!1}]];tA.A,tW.A;let tJ={'pre[class*="language-"]':{color:"var(--text)",background:"transparent"},'code[class*="language-"]':{color:"var(--text)",background:"transparent"},comment:{color:"var(--syntax-comment, var(--text-dim))",fontStyle:"italic"},prolog:{color:"var(--syntax-comment, var(--text-dim))",fontStyle:"italic"},doctype:{color:"var(--syntax-comment, var(--text-dim))",fontStyle:"italic"},cdata:{color:"var(--syntax-comment, var(--text-dim))"},punctuation:{color:"var(--text-muted)"},operator:{color:"var(--text-muted)"},string:{color:"var(--syntax-string, var(--accent-orange))"},char:{color:"var(--syntax-string, var(--accent-orange))"},builtin:{color:"var(--syntax-string, var(--accent-orange))"},"attr-value":{color:"var(--syntax-string, var(--accent-orange))"},keyword:{color:"var(--syntax-keyword, var(--accent))"},atrule:{color:"var(--syntax-keyword, var(--accent))"},property:{color:"var(--accent-blue)"},"attr-name":{color:"var(--accent-blue)"},variable:{color:"var(--accent-blue)"},parameter:{color:"var(--accent-blue)"},constant:{color:"var(--accent-blue)"},number:{color:"var(--syntax-number, var(--accent-blue))"},boolean:{color:"var(--syntax-number, var(--accent-blue))"},symbol:{color:"var(--syntax-number, var(--accent-blue))"},function:{color:"var(--syntax-function, var(--accent-green))"},"class-name":{color:"var(--syntax-function, var(--accent-green))"},"maybe-class-name":{color:"var(--syntax-function, var(--accent-green))"},tag:{color:"var(--accent-red)"},selector:{color:"var(--accent-red)"},regex:{color:"var(--accent-red)"},entity:{color:"var(--accent-red)"},deleted:{color:"var(--accent-red)"},inserted:{color:"var(--accent-green)"},important:{color:"var(--accent-orange)",fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}};function tG(e){return e.replace(/[*_`~]/g,"").trim()}function tY(e,t){return e.length>t?e.slice(0,t).trimEnd()+"…":e}function tZ(e){return e.replace(/^(我要|我想我?|你想要?|你想我?|你想要?|想要?|需要|你来|你来?|用|使用|选|选择|我|你)\s*/u,"").replace(/[吗吧呢]?$/u,"").replace(/[??,,。.!!、]$/gu,"").trim()}function tX({segments:e,onPick:t,onOpenFile:o,cwd:s,innerRef:i}){let{t:a}=(0,E.s)(),[l,d]=(0,n.useState)([]);return((0,n.useEffect)(()=>{let t=!1;return Promise.all(Array.from(new Set(e.flatMap(e=>(function(e){let t=new Set,o=[];for(let r of e.matchAll(/(?:\.[\w-]+\/|[\w-]+\/)+[\w.@-]+\.\w+|\b[A-Za-z0-9_.-]+\.(?:ts|tsx|js|jsx|mjs|cjs|md|mdx|json|py|go|rs|css|scss|html|sh|yml|yaml|toml|lock|txt|sql|env)\b/gu)){let e=r[0];(e=e.replace(/[),。、;:!!??)>"'`]$/u,"")).length>=3&&!t.has(e)&&(t.add(e),o.push(e))}return o})(e.text)))).map(e=>e.startsWith("/")?e:s?ee(s,e):e).map(async e=>{try{return(await fetch(`/api/files/${Z(e)}?type=meta`)).ok?e:null}catch{return null}})).then(e=>{t||d(e.filter(e=>!!e))}),()=>{t=!0}},[e,s]),0===e.length)?null:(0,r.jsxs)("span",{ref:i,style:{display:"flex",flexDirection:"column",gap:3,marginTop:4,width:"fit-content",maxWidth:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:4,boxShadow:"0 4px 14px rgba(0,0,0,0.14)"},onMouseDown:e=>e.preventDefault(),onClick:e=>e.stopPropagation(),children:[o&&l.length>0&&(0,r.jsx)("span",{style:{display:"flex",flexWrap:"wrap",gap:4},children:l.map(e=>(0,r.jsxs)("button",{type:"button",onClick:t=>{t.stopPropagation(),o(e)},title:a("desktop.openFile"),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 9px",fontSize:12,color:"var(--accent)",background:"color-mix(in srgb, var(--accent) 10%, transparent)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer",whiteSpace:"nowrap",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis"},children:[(0,r.jsx)(t0,{}),a("desktop.openFile"),": ",e.split("/").pop()]},e))}),e.map((e,o)=>(0,r.jsx)(tQ,{segment:e,onPick:t,t:a},o))]})}function tQ({segment:e,onPick:t,t:o}){let n=e.options??[{label:o("desktop.quoteReply"),value:""}];return(0,r.jsx)("span",{style:{display:"flex",flexWrap:"wrap",gap:4},children:n.map((o,n)=>(0,r.jsx)("button",{onClick:r=>{var n,s;let i;r.stopPropagation(),t((n=e.text,s=o.value||void 0,i=tG(n).split("\n").map(e=>`> ${e}`).join("\n"),s?`${i}
|
|
24
|
+
${s}`:`${i}
|
|
25
|
+
`))},title:e.text.slice(0,60),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 9px",fontSize:12,color:o.value?"var(--accent)":"var(--text-muted)",background:o.value?"color-mix(in srgb, var(--accent) 10%, transparent)":"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer",whiteSpace:"nowrap",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",transition:"background 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)"},children:o.label},n))})}function t0(){return(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)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function t1(e,t,o){return Math.min(o,Math.max(t,e))}function t2(e,t,o,r){return o<=0||r<=0||e<=0||t<=0?1:Math.min(.9*e/o,.9*t/r)}function t4({children:e,contentWidth:t,contentHeight:o,title:s,ariaLabel:i,onClose:a}){let{t:l}=(0,E.s)(),d=(0,n.useRef)(null),c=(0,n.useRef)(null),p=t+26,u=o+26,[g,h]=(0,n.useState)(1),[x,f]=(0,n.useState)({scale:1,tx:0,ty:0}),[m,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(!1),b=(0,n.useRef)(0),w=(0,n.useRef)(g),j=(0,n.useRef)(x);w.current=g,j.current=x;let S=(0,n.useRef)(null),C=(0,n.useCallback)((e,t,o)=>{let{scale:r,tx:n,ty:s}=j.current,i=w.current,a=t1(e,.25*i,3*i);a!==r&&f({scale:a,tx:t-(t-n)*a/r,ty:o-(o-s)*a/r})},[]),T=(0,n.useCallback)(e=>{let t=c.current;if(!t)return;let o=t.getBoundingClientRect(),r=o.width/2,n=o.height/2,s=w.current;C((j.current.scale/s+.25*e)*s,r,n)},[C]),z=(0,n.useCallback)(()=>{let e=c.current;if(!e)return;let{clientWidth:t,clientHeight:o}=e,r=t2(t,o,p,u);h(r),f({scale:r,tx:(t-p*r)/2,ty:(o-u*r)/2})},[p,u]);(0,n.useEffect)(()=>{let e=d.current;if(!e)return;let t=document.body.style.overflow;document.body.style.overflow="hidden",e.showModal();let o=requestAnimationFrame(()=>{z()});return()=>{cancelAnimationFrame(o),document.body.style.overflow=t,e.open&&e.close()}},[z]),(0,n.useEffect)(()=>{let e=c.current;if(!e||"u"<typeof ResizeObserver)return;let t=!1,o=new ResizeObserver(()=>{if(!t){t=!0;return}let{clientWidth:o,clientHeight:r}=e;if(o<=0||r<=0)return;let n=w.current,s=j.current,i=s.scale/n,a=t2(o,r,p,u),l=t1(i*a,.25*a,3*a),d=o/2,c=r/2,g=(d-s.tx)/s.scale,x=(c-s.ty)/s.scale;h(a),f({scale:l,tx:d-g*l,ty:c-x*l})});return o.observe(e),()=>o.disconnect()},[p,u]);let R=e=>{let t=S.current;if(!t||t.pointerId!==e.pointerId)return;t.capturing&&e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId);let o=t.moved;S.current=null,k(!1),o&&(b.current=Date.now())},I=Math.round(x.scale/g*100),M=.25*g,P=3*g;return(0,r.jsx)("dialog",{ref:d,className:"mermaid-zoom-dialog","aria-label":i,onCancel:e=>{e.preventDefault(),a()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),a())},children:(0,r.jsxs)("div",{className:"mermaid-zoom-layout",children:[(0,r.jsxs)("div",{className:"mermaid-zoom-toolbar",children:[s?(0,r.jsx)("span",{className:"mermaid-zoom-title",children:s}):null,!v&&(0,r.jsx)("span",{className:"mermaid-zoom-hint",children:l("desktop.zoomPanHint")}),(0,r.jsxs)("div",{className:"mermaid-zoom-actions",children:[(0,r.jsx)("button",{type:"button",className:["mermaid-zoom-icon-button","mermaid-zoom-select-button",v?"is-active":""].filter(Boolean).join(" "),onClick:()=>y(e=>!e),title:l("desktop.selectText"),"aria-label":l("desktop.selectText"),"aria-pressed":v,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:"M4 6V4h16v2M4 18v2h16v-2M12 4v16"})})}),(0,r.jsxs)("div",{className:"mermaid-zoom-stepper",children:[(0,r.jsx)("button",{type:"button",onClick:()=>T(-1),disabled:x.scale<=M+1e-9,title:l("desktop.zoomOut"),"aria-label":l("desktop.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)("button",{type:"button",className:"mermaid-zoom-value",onClick:()=>{z()},title:l("desktop.resetZoom"),"aria-label":`${I}%`,children:[I,"%"]}),(0,r.jsx)("button",{type:"button",onClick:()=>T(1),disabled:x.scale>=P-1e-9,title:l("desktop.zoomIn"),"aria-label":l("desktop.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:z,title:l("desktop.fitToViewport"),"aria-label":l("desktop.fitToViewport"),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:a,title:l("desktop.close"),"aria-label":l("desktop.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",{ref:c,className:["mermaid-zoom-viewport",v?"is-selecting":"",m?"is-dragging":""].filter(Boolean).join(" "),onWheel:e=>{e.preventDefault();let t=c.current;if(!t)return;let o=t.getBoundingClientRect(),r=e.clientX-o.left,n=e.clientY-o.top,s=Math.exp(-(.0015*e.deltaY));C(j.current.scale*s,r,n)},onPointerDown:e=>{0!==e.button||v||(S.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,originTx:j.current.tx,originTy:j.current.ty,moved:!1,capturing:!1})},onPointerMove:e=>{let t=S.current;if(!t||t.pointerId!==e.pointerId)return;let o=e.clientX-t.startX,r=e.clientY-t.startY;if(!t.moved){if(4>Math.hypot(o,r))return;t.moved=!0,t.capturing=!0,k(!0),e.currentTarget.setPointerCapture(e.pointerId)}f(e=>({...e,tx:t.originTx+o,ty:t.originTy+r}))},onPointerUp:R,onPointerCancel:R,onClick:e=>{if(Date.now()-b.current<500||e.target!==e.currentTarget)return;let t=window.getSelection();(!t||t.isCollapsed)&&a()},onDoubleClick:e=>{if(v)return;e.preventDefault();let t=c.current;if(!t)return;let o=t.getBoundingClientRect(),r=e.clientX-o.left,n=e.clientY-o.top,s=w.current,i=.05>Math.abs(j.current.scale/s-1)?2:1;1===i?z():C(i*s,r,n)},children:(0,r.jsx)("div",{className:"mermaid-zoom-world",style:{width:t*x.scale+26,height:o*x.scale+26,left:x.tx,top:x.ty},children:(0,r.jsx)("div",{className:"mermaid-zoom-canvas",children:e})})})]})})}let t6=(0,n.createContext)({openId:null,setOpenId:()=>{}});function t5({isStreaming:e,cwd:t,onOpenFile:o,onQuoteReply:s,quoteScope:i="markdown"}){return{h1:({children:e})=>(0,r.jsx)("h1",{id:tB(e),className:"scroll-mt-24 text-xl font-semibold mt-4 mb-2 text-(--text)",children:e}),h2:({children:e})=>(0,r.jsx)("h2",{id:tB(e),className:"scroll-mt-24 text-lg font-semibold mt-3 mb-2 text-(--text)",children:e}),h3:({children:e})=>(0,r.jsx)("h3",{id:tB(e),className:"scroll-mt-24 text-base font-semibold mt-3 mb-1 text-(--text)",children:e}),code({className:t,children:o,...n}){let s=t?.replace("language-","").toLowerCase()??"",i=String(o);return t?.includes("language-")?"mermaid"===s?(0,r.jsx)(t9,{code:i.replace(/\n$/,""),isStreaming:e}):(0,r.jsx)(oo,{code:i.replace(/\n$/,""),lang:s,isStreaming:e}):(0,r.jsx)("code",{className:"inline max-w-full whitespace-normal break-words [overflow-wrap:anywhere] align-baseline bg-(--bg-secondary) border border-(--border) px-1.5 py-0.5 text-xs font-mono text-(--accent-blue)",...n,children:o})},pre:({children:e})=>(0,r.jsx)("div",{className:"markdown-block-code",children:e}),p({children:e,node:a,...l}){let d=`${i}-p-${a?.position?.start?.offset??0}`;return n.Children.toArray(e).some(e=>(0,n.isValidElement)(e)&&("div"===e.type||"pre"===e.type||"table"===e.type||"ul"===e.type||"ol"===e.type))?(0,r.jsx)("div",{className:"markdown-block-wrap",...l,children:e}):s?(0,r.jsx)(ot,{pid:d,onQuoteReply:s,onOpenFile:o,cwd:t,children:e}):(0,r.jsx)("p",{...l,children:e})},li({children:e,node:n,...a}){let l=`${i}-li-${n?.position?.start?.offset??0}`;return s?(0,r.jsx)(ot,{as:"li",pid:l,onQuoteReply:s,onOpenFile:o,cwd:t,children:e}):(0,r.jsx)("li",{...a,children:e})},a({href:e,children:n,...s}){delete s.node;let i="text-(--accent-blue) underline underline-offset-2 hover:text-(--accent-blue)/80",a=o?te(e,t):null;return a&&o?(0,r.jsx)("a",{href:e,...s,className:i,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),o(a))},children:n}):(0,r.jsx)("a",{href:e,...s,className:i,target:"_blank",rel:"noopener noreferrer",children:n})},img({src:e,alt:o,...n}){delete n.node;let s="string"==typeof e?te(e,t):null,i=s?`/api/files/${Z(s)}?type=read`:e;return(0,r.jsx)("img",{src:i,alt:o??"",loading:"lazy",...n})},table:({children:e})=>(0,r.jsx)("div",{className:"my-3 rounded-lg overflow-hidden border border-(--border)",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsx)("table",{className:"w-full text-sm border-collapse [&_tr:last-child>td]:border-b-0",children:e})})}),tr({children:e,node:n,...a}){let l=`${i}-tr-${n?.position?.start?.offset??0}`;return s?(0,r.jsx)(ot,{as:"tr",pid:l,onQuoteReply:s,onOpenFile:o,cwd:t,children:e}):(0,r.jsx)("tr",{...a,children:e})}}}let t3=(0,n.memo)(function({text:e,isStreaming:t,cwd:o,onOpenFile:s,onQuoteReply:i,quoteScope:a}){let l=(0,n.useMemo)(()=>tU(e),[e]),d=(0,n.useMemo)(()=>t5({isStreaming:t,cwd:o,onOpenFile:s,onQuoteReply:i,quoteScope:a}),[t,o,s,i,a]);return(0,r.jsx)(ta.oz,{remarkPlugins:tV,rehypePlugins:tK,components:d,children:l})});function t8({children:e,className:t,isStreaming:o,cwd:s,onOpenFile:i,onQuoteReply:a}){let l=(0,n.useMemo)(()=>tU(e),[e]),d=(0,n.useRef)(new Map),c=(0,n.useMemo)(()=>(function(e,t){let o;if(0===e.length)return[];let r=e.split(/\r?\n/),n="",s=0,i=!1,a=-1;for(let e=0;e<r.length;e++){let t=tF.exec(r[e]);i?t&&t[1][0]===n&&t[1].length>=s&&(i=!1,n="",s=0,a=-1):t&&(n=t[1][0],s=t[1].length,i=!0,a=e)}if(a>=0)o=a;else{let e=-1;for(let t=0;t<r.length;t++)""===r[t]&&(e=t);o=e+1}let l=r.slice(0,o),d=r.slice(o),c=[],p=[],u=()=>{for(;p.length>0&&""===p[p.length-1];)p.pop();for(;p.length>0&&""===p[0];)p.shift();p.length>0&&(c.push(t$(p.join("\n"),!1,t)),p=[])};for(let e of l)""===e&&p.length>0?u():p.push(e);for(p.length>0&&u();d.length>0&&""===d[0];)d.shift();return d.length>0&&c.push(t$(d.join("\n"),!0,t)),c})(l,d.current),[l]),p=o&&c.length>1,u=(0,n.useMemo)(()=>t5({isStreaming:o,cwd:s,onOpenFile:i,onQuoteReply:a,quoteScope:"full"}),[o,s,i,a]);return(0,r.jsx)(t7,{children:(0,r.jsx)("div",{className:["markdown-body",t].filter(Boolean).join(" "),children:p?c.map((e,t)=>(0,r.jsx)(t3,{text:e.text,isStreaming:!!e.tail&&o,cwd:s,onOpenFile:i,onQuoteReply:a,quoteScope:e.id},`${t}-${e.id}`)):(0,r.jsx)(ta.oz,{remarkPlugins:tV,rehypePlugins:tK,components:u,children:l})})})}function t7({children:e}){let[t,o]=(0,n.useState)(null),s=(0,n.useMemo)(()=>({openId:t,setOpenId:o}),[t]);return(0,r.jsx)(t6.Provider,{value:s,children:e})}function t9({code:e,isStreaming:t}){let{t:s}=(0,E.s)(),{isDark:i}=tP(),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(""),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(!1),m=`${i?"dark":"light"}
|
|
26
|
+
${e}`;(0,n.useEffect)(()=>{if(!a||t)return;let r=!1;return h(null),(async()=>{let{default:t}=await Promise.all([o.e(988),o.e(9425),o.e(3308)]).then(o.bind(o,43328));if(t.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:i?"dark":"default"}),!await t.parse(e,{suppressErrors:!0}))throw Error("Invalid Mermaid diagram");let n="u">typeof crypto&&"randomUUID"in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,s=await t.render(n,e);r||(c(s.svg),u(m))})().catch(()=>{r||h(m)}),()=>{r=!0}},[e,m,i,t,a]);let k=(0,r.jsx)("button",{onClick:()=>l(e=>!e),disabled:t,title:s(t?"desktop.markdownPreviewAvailableAfterStreaming":a?"desktop.source":"desktop.markdownPreviewMermaidDiagram"),className:["markdown-code-action",a?"is-active":""].filter(Boolean).join(" "),children:s(a?"desktop.source":"desktop.preview")});if(!a||t)return(0,r.jsx)(oo,{code:e,lang:"mermaid",headerAction:k,isStreaming:t});let v=g===m?(0,r.jsx)("div",{className:"mermaid-block mermaid-block-error",children:s("desktop.markdownInvalidMermaidDiagram")}):d&&p===m?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"mermaid-block mermaid-preview-button",title:s("desktop.openMermaidViewer"),"aria-label":s("desktop.openMermaidViewer"),onClick:()=>f(!0),dangerouslySetInnerHTML:{__html:d}}),x&&(0,r.jsx)(oe,{svg:d,onClose:()=>f(!1)})]}):(0,r.jsx)("div",{className:"mermaid-block mermaid-block-loading","aria-label":s("desktop.markdownRenderingMermaidDiagram")});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.jsx)("div",{className:"markdown-code-actions",children:k})]}),v]})}function oe({svg:e,onClose:t}){let{t:o}=(0,E.s)(),s=(0,n.useMemo)(()=>(function(e){if("u"<typeof DOMParser)return{html:e,width:800,height:600};let t=new DOMParser().parseFromString(e,"image/svg+xml").documentElement;if(!t||"svg"!==t.tagName.toLowerCase())return{html:e,width:800,height:600};let o=0,r=0,n=t.getAttribute("viewBox");if(n){let e=n.trim().split(/[\s,]+/).map(Number);4===e.length&&e.every(e=>Number.isFinite(e))&&(o=e[2],r=e[3])}return o>0&&r>0||(o=parseFloat(t.getAttribute("width")||""),r=parseFloat(t.getAttribute("height")||"")),o>0&&r>0||(o=800,r=600),t.removeAttribute("width"),t.removeAttribute("height"),t.style.maxWidth="none",t.getAttribute("viewBox")||t.setAttribute("viewBox",`0 0 ${o} ${r}`),{html:t.outerHTML,width:o,height:r}})(e),[e]);return(0,r.jsx)(t4,{contentWidth:s.width,contentHeight:s.height,title:o("desktop.mermaidDiagram"),ariaLabel:o("desktop.mermaidViewer"),onClose:t,children:(0,r.jsx)("div",{dangerouslySetInnerHTML:{__html:s.html}})})}function ot({children:e,onQuoteReply:t,onOpenFile:o,cwd:s,as:i="p",pid:a}){let{openId:l,setOpenId:d}=(0,n.useContext)(t6),{t:c}=(0,E.s)(),p=l===a,u=(0,n.useRef)(null),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(!1),[m,k]=(0,n.useState)(1),v=(0,n.useRef)(null),[y]=(0,n.useState)(()=>window.matchMedia?.("(pointer: coarse)").matches);(0,n.useEffect)(()=>{!p&&g&&h(null)},[p,g]);let b=(0,n.useRef)(null);(0,n.useEffect)(()=>{g&&b.current&&b.current.scrollIntoView({block:"nearest"})},[g]);let w=()=>{h(null),d(null)},j=()=>{g?w():(()=>{let e;if(g||p)return;let t=u.current,o=(!(e=tG("tr"===i&&t?Array.from(t.querySelectorAll("td, th")).map(e=>(e.textContent??"").trim()).join(" | "):t?.textContent??""))?[]:e.split(/(?<=[??])|[;;]/u).map(e=>e.trim()).filter(e=>e.length>0)).map(e=>({text:e,options:function(e){let t=tG(e);if(!t)return null;let o=t.match(/^(.+?)\s*(?:还是|或者|或者还是|\bor\b)\s*(.+?)[??]?\s*$/iu);if(o){let e=tZ(o[1]),t=tZ(o[2]);if(e&&t&&e!==t)return[{label:tY(e,12),value:e},{label:tY(t,12),value:t}]}if(!/怎么|如何|怎样|哪个|哪些|什么|为什么|为何|谁|多少|几(个|点|时)?|what|how|why|who|where/u.test(t)&&(/[??]\s*$/u.test(t)||/(?:吗|吧|呢)[??]?\s*$/u.test(t)||/是否|要不要|能不能|可不可以|要不要我|需要我/u.test(t))){let e=t.replace(/^(要我|需要我|要不要我?|是否|能不能|可不可以|要不要|或者|还是|你能|你可以|请|麻烦)\s*/u,"").replace(/[吗吧呢啊呀]?[??]+$/u,"").replace(/[吗吧呢啊呀]$/u,"").trim();return e&&e.length<=16?[{label:`好,${tY(e,10)}`,value:"是的"},{label:"不用",value:"不用了"}]:[{label:"是",value:"是的"},{label:"否",value:"不用了"}]}return null}(e)}));o.length>0&&("tr"===i&&t&&k(Math.max(1,t.querySelectorAll("td, th").length)),h(o),d(a))})()},S=(e,t)=>{v.current&&(v.current.style.left=`${e+12}px`,v.current.style.top=`${t+14}px`)},C=g&&(0,r.jsx)(tX,{innerRef:b,segments:g,onPick:e=>{t(e),w()},onOpenFile:o,cwd:s});return"tr"===i?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("tr",{ref:e=>{u.current=e},onClick:j,title:y||g?void 0:c("desktop.quoteReplyHint"),style:{cursor:"pointer"},children:e}),C&&(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:m,children:C})})]}):(0,r.jsxs)(i,{ref:u,onMouseEnter:e=>{if(y)return;f(!0);let{clientX:t,clientY:o}=e;requestAnimationFrame(()=>S(t,o))},onMouseMove:y?void 0:e=>S(e.clientX,e.clientY),onMouseLeave:()=>f(!1),onClick:j,style:{position:"relative",cursor:"pointer"},children:[e,x&&!g&&(0,r.jsx)("span",{ref:v,style:{position:"fixed",left:-9999,top:-9999,fontSize:11,color:"var(--text-dim)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,padding:"2px 6px",pointerEvents:"none",zIndex:50,whiteSpace:"nowrap"},children:c("desktop.quoteReplyHint")}),C]})}function oo({code:e,lang:t,headerAction:o,isStreaming:s}){let{t:i}=(0,E.s)(),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(!1);return(0,r.jsxs)("div",{className:"markdown-code-block",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[(0,r.jsxs)("div",{style:{position:"absolute",top:6,right:8,zIndex:1,display:"flex",alignItems:"center",gap:6,opacity:+!!d,pointerEvents:d?"auto":"none",transition:"opacity 0.12s"},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:10,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",userSelect:"none"},children:t||i("desktop.markdownPlainText")}),o,(0,r.jsx)("button",{onClick:()=>{tD(e).then(()=>{l(!0),setTimeout(()=>l(!1),1500)})},title:i(a?"desktop.copied":"desktop.copy"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,border:"none",borderRadius:5,background:"transparent",color:a?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:10,transition:"color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{a||(e.currentTarget.style.color="var(--text-dim)")},children:a?(0,r.jsx)(u.J,{size:11,"aria-hidden":"true"}):(0,r.jsx)(ti.Q,{size:11,"aria-hidden":"true"})})]}),s?(0,r.jsx)("pre",{className:"markdown-code-streaming",children:(0,r.jsx)("code",{children:e})}):(0,r.jsx)(tl.A,{language:t||"text",style:tJ,showLineNumbers:!1,customStyle:{margin:0,padding:"10px 16px",fontSize:13,lineHeight:1.65,borderRadius:0,border:"none",background:"var(--bg-secondary)"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})}let or=/^<skill name="([^"]+)" location="([^"]+)">/,on="\n</skill>",os=/<(read-files|modified-files)>\s*([\s\S]*?)\s*<\/\1>/g,oi=/(?:\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 oa({content:e}){var t,o,s;let i,{t:a}=(0,E.s)(),[l,d]=(0,n.useState)(!1),c="string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),p=(0,n.useMemo)(()=>{let e,t,o,r,n;return e=[],t=[],o=c.match(oi),r=o?.[1]??"",n=o?.index===void 0?c:c.slice(0,o.index),r.replace(os,(o,r,n)=>{let s=n.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return"read-files"===r?e.push(...s):t.push(...s),""}),{body:n.trim(),readFiles:e,modifiedFiles:t}},[c]),u=(t=p.readFiles.length,o=p.modifiedFiles.length,s=a,i=[],t>0&&i.push(s("desktop.readFilesCount",{count:t})),o>0&&i.push(s("desktop.modifiedFilesCount",{count:o})),i.length>0?i.join(", "):null),[g,h]=(0,n.useState)(!1),[x,f]=(0,n.useState)(!1),k=(0,n.useRef)(null),v=(0,n.useCallback)(()=>{let e=k.current;e&&(h(e.scrollTop>0),f(e.scrollHeight-e.scrollTop-e.clientHeight>1))},[]);return(0,n.useEffect)(()=>{let e=k.current;if(!e||!l)return;let t=new ResizeObserver(v);return e.addEventListener("scroll",v,{passive:!0}),t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),v(),()=>{e.removeEventListener("scroll",v),t.disconnect()}},[l,v]),(0,r.jsxs)("div",{className:"group/process relative mb-3 min-w-0",children:[(0,r.jsx)("div",{className:"group/summary-row flex items-center justify-between",children:(0,r.jsxs)("button",{type:"button",onClick:()=>d(e=>!e),className:"group/summary flex min-w-0 items-center gap-1.5 text-left text-sm leading-relaxed text-text-muted transition-colors hover:text-text","aria-expanded":l,children:[(0,r.jsx)("span",{className:"truncate",children:a("desktop.conversationCompacted")}),(0,r.jsx)("span",{className:`opacity-0 transition-opacity group-hover/summary:opacity-60 ${l?"rotate-90":""}`,children:(0,r.jsx)(m.J,{size:12,className:"shrink-0 transition-all duration-150"})})]})}),l&&(0,r.jsxs)("div",{className:"relative mt-2",children:[(0,r.jsxs)("div",{ref:k,className:"max-h-[280px] overflow-y-auto pr-2 text-text-dim",children:[(0,r.jsx)("p",{className:"mb-2 text-xs leading-relaxed",children:a("desktop.compactionSummaryDescription")}),p.body?(0,r.jsx)(t8,{className:"!text-text-dim",children:p.body}):(0,r.jsx)("span",{className:"text-xs",children:a("desktop.noSummary")}),u&&(0,r.jsxs)("div",{className:"mt-3 border-t border-border pt-2 text-xs",children:[(0,r.jsx)("div",{className:"font-medium",children:a("desktop.fileContext",{context:u})}),p.modifiedFiles.length>0&&(0,r.jsx)(ol,{title:a("desktop.modifiedFiles"),files:p.modifiedFiles}),p.readFiles.length>0&&(0,r.jsx)(ol,{title:a("desktop.readFiles"),files:p.readFiles})]})]}),g&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),x&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"})]})]})}function ol({title:e,files:t}){return(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("div",{className:"mb-1 font-mono text-[11px] font-medium text-text",children:e}),(0,r.jsx)("ul",{className:"max-h-45 overflow-auto rounded-sm border border-border bg-bg-subtle px-2 py-1.5 font-mono text-[11px] leading-relaxed",children:t.map(e=>(0,r.jsx)("li",{className:"break-all",children:e},e))})]})}function od(e){let t,o=[],r=null,n=0,s=0,i=0,a=0,l=[],d=[],c=()=>({lineNo:null,text:"",type:"empty"}),p=()=>{if(!r){l=[],d=[];return}let e=Math.max(l.length,d.length);for(let t=0;t<e;t++){let e=l[t]?{lineNo:l[t].lineNo,text:l[t].text,type:"removed"}:c(),o=d[t]?{lineNo:d[t].lineNo,text:d[t].text,type:"added"}:c();r.rows.push({type:"line",left:e,right:o})}l=[],d=[]};for(let c of e.split(/\r?\n/)){let e=i>0||a>0;if(!e&&c.startsWith("--- ")){p(),t=oc(c.slice(4));continue}if(!e&&c.startsWith("+++ ")){p(),r={oldPath:t,newPath:oc(c.slice(4)),rows:[]},o.push(r);continue}let u=c.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(u){r||(r={rows:[]},o.push(r)),p(),n=Number(u[1]),s=Number(u[3]),i=void 0===u[2]?1:Number(u[2]),a=void 0===u[4]?1:Number(u[4]),r.rows.push({type:"hunk",text:c});continue}if(!r)continue;if(c.startsWith("\\ ")){p(),r.rows.push({type:"hunk",text:c});continue}if(0===i&&0===a){""!==c&&r.rows.push({type:"hunk",text:c});continue}let g=c[0],h=c.slice(1);" "===g?(p(),r.rows.push({type:"line",left:{lineNo:n++,text:h,type:"context"},right:{lineNo:s++,text:h,type:"context"}}),i>0&&(i-=1),a>0&&(a-=1)):"-"===g?(l.push({lineNo:n++,text:h}),i>0&&(i-=1)):"+"===g?(d.push({lineNo:s++,text:h}),a>0&&(a-=1)):""!==c&&(p(),r.rows.push({type:"hunk",text:c}))}p();let u=o.filter(e=>e.rows.some(e=>"line"===e.type));return u.length>0?u:null}function oc(e){return e.split(" ")[0].trim()}function op({files:e,onOpenFile:t}){let{t:o}=(0,E.s)();return 0===e.length?null:(0,r.jsx)("div",{"aria-label":o("desktop.filesWritten"),style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,marginTop:6},children:e.map(({filePath:e})=>{let n=X(e);return(0,r.jsxs)("button",{type:"button",title:e,"aria-label":o("desktop.openWrittenFile",{name:n}),onClick:()=>t?.(e),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",fontSize:12,fontFamily:"var(--font-mono)",color:"var(--text)",background:"var(--bg-subtle)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer"},children:[(0,r.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,r.jsx)("path",{d:"M9 1.5H4A1.5 1.5 0 0 0 2.5 3v10A1.5 1.5 0 0 0 4 14.5h8A1.5 1.5 0 0 0 13.5 13V6z"}),(0,r.jsx)("path",{d:"M9 1.5V6h4.5"})]}),(0,r.jsx)("span",{children:n})]},e)})})}var ou=o(35831),og=o(63522),oh=o(22540),ox=o(36462),of=o(42405),om=o(26131),ok=o(47142);let ov={flash:{cacheRead:.02,input:1,output:2,cacheWrite:0},pro:{cacheRead:.025,input:3,output:6,cacheWrite:0}};function oy(e){let t=(e??"").toLowerCase();return t.includes("deepseek-v4-flash")?"flash":t.includes("deepseek-v4-pro")?"pro":null}function ob(e){return null!==oy(e)}function ow(e,t){let o=oy(e);if(!o||!t)return 0;let r=ov[o],n=oS(t.input),s=oS(t.output),i=oS(t.cacheRead),a=oS(t.cacheWrite);return(i*r.cacheRead+n*r.input+s*r.output+a*r.cacheWrite)/1e6}function oj(e){var t;let o="number"==typeof(t=e)&&Number.isFinite(t)?t:0;return!Number.isFinite(o)||o<=0?"\xa50.00":o<.01?"<\xa50.01":o<1?`\xa5${o.toFixed(4)}`:`\xa5${o.toFixed(2)}`}function oS(e){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:0}let oC=new Map;function oT(e,t,o){let r=`${e}:${t}:${o}`,n=oC.get(r);if(n)return oC.delete(r),oC.set(r,n),n;let s=fetch(`/api/sessions/${encodeURIComponent(e)}/entries/${encodeURIComponent(t)}/thinking?blockIndex=${o}`).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 oC.delete(r),e});if(oC.set(r,s),oC.size>100){let e=oC.keys().next().value;e&&oC.delete(e)}return s}function oz(e){if(!e)return null;let t=new Date(e),o=new Date,r=t.getFullYear()===o.getFullYear()&&t.getMonth()===o.getMonth()&&t.getDate()===o.getDate(),n=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(r)return n;let s=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==o.getFullYear()?"numeric":void 0});return`${s} ${n}`}let oR=(0,n.memo)(function({message:e,isStreaming:t,toolResults:o,modelNames:n,cwd:s,onOpenFile:i,onQuoteReply:a,entryId:l,onFork:d,forking:c,onNavigate:p,prevAssistantEntryId:u,onEditContent:g,showTimestamp:h,prevTimestamp:x,sessionId:f,onCreateTask:m,writtenFiles:k}){return"user"===e.role?(0,r.jsx)(oI,{message:e,cwd:s,onOpenFile:i,entryId:l,onFork:d,forking:c,onNavigate:p,prevAssistantEntryId:u,onEditContent:g,onCreateTask:m}):"assistant"===e.role?(0,r.jsx)(oM,{message:e,isStreaming:t,toolResults:o,modelNames:n,cwd:s,onOpenFile:i,onQuoteReply:a,showTimestamp:h,prevTimestamp:x,sessionId:f,entryId:l,onFork:d,forking:c,writtenFiles:k}):"toolResult"===e.role?null:"custom"===e.role?"compaction"===e.customType?(0,r.jsx)(oa,{content:e.content}):(0,r.jsx)(oU,{message:e,isStreaming:t,cwd:s,onOpenFile:i}):"bashExecution"===e.role?(0,r.jsx)(o_,{message:e,sessionId:f}):null},(e,t)=>e.message===t.message&&e.isStreaming===t.isStreaming&&function(e,t,o){if(t===o||"assistant"!==e.role)return!0;for(let r of e.content??[])if("toolCall"===r.type&&t?.get(r.toolCallId)!==o?.get(r.toolCallId))return!1;return!0}(e.message,e.toolResults,t.toolResults)&&e.modelNames===t.modelNames&&e.cwd===t.cwd&&e.onOpenFile===t.onOpenFile&&e.onQuoteReply===t.onQuoteReply&&e.entryId===t.entryId&&e.onFork===t.onFork&&e.forking===t.forking&&e.onNavigate===t.onNavigate&&e.prevAssistantEntryId===t.prevAssistantEntryId&&e.onEditContent===t.onEditContent&&e.onCreateTask===t.onCreateTask&&e.showTimestamp===t.showTimestamp&&e.prevTimestamp===t.prevTimestamp&&e.sessionId===t.sessionId&&e.writtenFiles===t.writtenFiles);function oI({message:e,cwd:t,onOpenFile:o,entryId:s,onFork:i,forking:a,onNavigate:l,prevAssistantEntryId:d,onEditContent:c,onCreateTask:p}){let{t:g}=(0,E.s)(),[h,x]=(0,n.useState)(!1),[f,m]=(0,n.useState)(!1),k="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),v="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),y=(k&&k.trim()?k.trim().startsWith("/")?k:function(e){let t=e.match(or);if(!t)return null;let o=t[1],r=e.indexOf(on),n="";if(-1!==r){let t=e.slice(r+on.length);t.startsWith("\n\n")&&(n=t.slice(2).trim())}return n?`/skill:${o} ${n}`:`/skill:${o}`}(k):null)??k,b=oz(e.timestamp),w=!!s&&!!i,j=!!d&&!!l;return(0,r.jsxs)("div",{className:"chat-user-message chat-msg-in",onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),children:[(0,r.jsx)("div",{className:"chat-user-bubble-wrap",children:(0,r.jsxs)("div",{className:"chat-user-bubble",children:[v.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!k},children:v.map((e,t)=>{let o=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)("img",{src:o,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)"}},t)})}),y&&(0,r.jsx)(t8,{className:"markdown-user-message",cwd:t,onOpenFile:o,children:y})]})}),(0,r.jsxs)("div",{className:"msg-actions",style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:3,opacity:+!!h,pointerEvents:h?"auto":"none",transition:"opacity 0.12s"},children:[(0,r.jsx)("button",{onClick:()=>{tD(k).then(()=>{m(!0),setTimeout(()=>m(!1),1500)})},title:g("desktop.copyMessage"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:f?"var(--accent)":"var(--text-dim)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{f||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{f||(e.currentTarget.style.color="var(--text-dim)")},children:f?(0,r.jsx)(u.S,{size:11}):(0,r.jsx)(ti.T,{size:11})}),p&&k.trim()&&(0,r.jsx)("button",{onClick:()=>p(k,t),title:g("desktop.createTaskFromMessage"),"aria-label":g("desktop.createTaskFromMessage"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)(of.X,{size:11})})]}),(w||j)&&(0,r.jsxs)("div",{className:"msg-actions",style:{display:"flex",gap:3,opacity:h||a?1:0,pointerEvents:h||a?"auto":"none",transition:"opacity 0.12s"},children:[j&&(0,r.jsx)("button",{onClick:()=>{l(d),c?.(e)},title:g("desktop.editFromHere"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,r.jsx)(ou.S,{size:11})}),w&&(0,r.jsx)("button",{onClick:()=>{i(s)},disabled:a,title:g(a?"desktop.creatingNewSession":"desktop.newSessionFromHere"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:a?"var(--accent)":"var(--text-dim)",cursor:a?"not-allowed":"pointer",transition:"color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{a||(e.currentTarget.style.color="var(--text-dim)")},children:(0,r.jsx)(M.C,{size:11})})]}),b&&(0,r.jsx)("span",{style:{fontSize:11,color:h?"var(--text-muted)":"var(--text-dim)",opacity:h?1:.5,transition:"color 0.15s, opacity 0.15s"},children:b})]})]})}function oM({message:e,isStreaming:t,toolResults:o,modelNames:s,cwd:i,onOpenFile:a,onQuoteReply:l,showTimestamp:d,prevTimestamp:c,sessionId:p,entryId:g,onFork:h,forking:x,writtenFiles:f}){let{t:m}=(0,E.s)(),k=d?oz(e.timestamp):null,v=(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!e6(e,{isStreaming:t})),y=v.map(({block:e})=>e),[b,w]=(0,n.useState)(!1),[j,S]=(0,n.useState)(!1),[C,T]=(0,n.useState)(!1),z=(0,n.useRef)(null),[R,I]=(0,n.useState)(null),P=(0,n.useRef)(v);P.current=v;let D=(0,n.useRef)(new Map),[$,F]=(0,n.useState)(new Map),W=(0,n.useMemo)(()=>{if(!e.timestamp||!c)return;let t=Math.round((e.timestamp-c)/1e3);return t>0?t:void 0},[e.timestamp,c]),N=(0,n.useMemo)(()=>{let t=new Map;if(!o||!e.timestamp)return t;for(let[r,n]of o)if(n.timestamp&&e.timestamp){let o=Math.round((n.timestamp-e.timestamp)/1e3);o>0&&t.set(r,o)}return t},[o,e.timestamp]),A=y.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),L=function(e){let t=new Set;for(let o of e){if("toolCall"!==o.type)continue;let e=(o.toolName??"").toLowerCase();if("apply_patch"===e||e.includes("patch")||!(oH(o.toolName??"")||"write"===e||"create"===e||e.includes("file_write")||e.includes("create_file")||e.includes("multiedit")))continue;let r=o.input??{},n=r.filePath??r.file_path??r.path??r.file??r.destination??r.newFilePath??r.oldPath;"string"==typeof n&&n.trim()&&t.add(n)}return[...t]}(y),[O,H]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(!t){let e=new Date().getTime();F(t=>{let o=new Map(t);for(let[t,r]of D.current)o.has(t)||o.set(t,Math.round((e-r)/1e3));return o}),z.current=null,I(null);return}let e=setInterval(()=>{let e=P.current,t=e.map(({block:e})=>e),o=Date.now();e.forEach(({originalIndex:e})=>{D.current.has(e)||D.current.set(e,o)}),F(t=>{let r=!1,n=new Map(t);for(let t=0;t<e.length-1;t++){let s=e[t].originalIndex,i=e[t+1].originalIndex;if(!n.has(s)&&D.current.has(s)){let e=D.current.get(s),t=D.current.get(i)??o;n.set(s,Math.round((t-e)/1e3)),r=!0}}return r?n:t});let r=0;for(let e of t)"text"===e.type?r+=e.text?.length??0:"thinking"===e.type?r+=e.thinking?.length??0:"toolCall"===e.type&&(r+=JSON.stringify(e.input??{}).length);if(0===r)return;null===z.current&&(z.current=o);let n=(o-z.current)/1e3;n>.5&&I(r/4/n)},300);return()=>clearInterval(e)},[t]);let B=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toLocaleString(),U="error"===e.stopReason&&e.errorMessage?e.errorMessage:null;return 0!==y.length||t||U?(0,r.jsxs)("div",{className:["chat-assistant-message chat-msg-in",t?"is-streaming":""].filter(Boolean).join(" "),onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),children:[t&&(0,r.jsx)("div",{className:"chat-assistant-meta",children:(()=>{let e,t=0;for(let e of y)"text"===e.type?t+=e.text?.length??0:"thinking"===e.type?t+=e.thinking?.length??0:"toolCall"===e.type&&(t+=JSON.stringify(e.input??{}).length);let o=Math.round(t/4);return(0,r.jsx)(r.Fragment,{children:o>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--text)"},title:m("desktop.estimatedStreamingTokenCount"),children:[(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2,fontSize:11,fontWeight:400},children:[(0,r.jsx)(ox.g,{size:13}),o]}),null!==R&&(e=R>=50?"--accent-green":R>=30?"--accent-blue":R>=15?"--accent-orange":"--accent-red",(0,r.jsx)("span",{style:{marginLeft:6,padding:"1px 6px",borderRadius:4,background:`var(${e})`,color:"var(--bg)",fontSize:11,fontWeight:400},children:m("desktop.tokensPerSecond",{count:R.toFixed(1)})}))]})})})()}),(0,r.jsxs)("div",{className:"chat-assistant-content",children:[U&&(0,r.jsxs)("div",{className:"chat-assistant-error",role:"alert",children:[(0,r.jsx)(ok.M,{size:13,weight:"bold"}),(0,r.jsx)("span",{children:U})]}),v.map(({block:e,originalIndex:n})=>(0,r.jsx)(oE,{block:e,toolResults:o,isStreaming:t,streamingDuration:$.get(n)??("thinking"===e.type?W:void 0),toolCallDurations:N,cwd:i,onOpenFile:a,onQuoteReply:l,sessionId:p,entryId:g,blockIndex:n},`${g??"stream"}-${n}`))]}),f&&f.length>0&&(0,r.jsx)(op,{files:f,onOpenFile:a}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[!t&&(e.provider||e.usage)&&(0,r.jsxs)("div",{style:{fontSize:11,color:b?"var(--text-muted)":"var(--text-dim)",opacity:b?1:.5,display:"flex",alignItems:"center",gap:5,flexWrap:"wrap",transition:"color 0.15s, opacity 0.15s"},children:[e.provider&&(0,r.jsx)("span",{children:s?.[`${e.provider}:${e.model}`]??s?.[e.model]??e.model}),e.usage&&e.usage.input>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2},children:[(0,r.jsx)(oh.K,{size:10}),B(e.usage.input)]}),e.usage&&e.usage.output>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2},children:[(0,r.jsx)(og.Z,{size:10}),B(e.usage.output)]}),e.usage&&e.usage.cacheRead>0&&(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2},children:[(0,r.jsx)(om.b,{size:10}),B(e.usage.cacheRead)]}),e.usage&&e.usage.cost?.total>0&&(()=>{if(ob(e.model)){let t=ow(e.model,e.usage);return t<=0?null:(0,r.jsx)("span",{title:m("desktop.turnUsageByOfficialPrice"),children:oj(t)})}return(0,r.jsxs)("span",{children:["$",e.usage.cost.total.toFixed(4)]})})()]}),A&&!t&&(0,r.jsx)("button",{className:"msg-actions",onClick:()=>{tD(A).then(()=>{S(!0),setTimeout(()=>S(!1),1500)})},title:m("desktop.copyMessage"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:j?"var(--accent)":"var(--text-dim)",cursor:"pointer",opacity:+!!b,pointerEvents:b?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{j||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{j||(e.currentTarget.style.color="var(--text-dim)")},children:j?(0,r.jsx)(u.S,{size:11}):(0,r.jsx)(ti.T,{size:11})}),A&&!t&&(0,r.jsx)("button",{className:"msg-actions",onClick:()=>{tD(A.replace(/`([^`]+)`/g,"$1").replace(/```[^\n]*\n?/g,"\n").replace(/```/g,"\n").replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/(\*\*|__)(.*?)\1/g,"$2").replace(/(\*|_)([^*_]+)\1/g,"$2").replace(/~~(.*?)~~/g,"$1").replace(/^#{1,6}\s+/gm,"").replace(/^>\s?/gm,"").replace(/^(\s*)([-*+]|\d+\.)\s+/gm,"$1").replace(/^\s*\|?[\s:|-]+\|?\s*$/gm,"").replace(/\|/g," ").replace(/\n{3,}/g,"\n\n").trim()).then(()=>{T(!0),setTimeout(()=>T(!1),1500)})},title:m("desktop.copyPlainText"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:C?"var(--accent)":"var(--text-dim)",cursor:"pointer",opacity:+!!b,pointerEvents:b?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{C||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{C||(e.currentTarget.style.color="var(--text-dim)")},children:C?(0,r.jsx)(u.S,{size:11}):(0,r.jsx)(of.X,{size:11})}),g&&h&&!t&&(0,r.jsx)("button",{className:"msg-actions",onClick:()=>h(g),disabled:x,title:x?m("desktop.creatingNewSession"):m("desktop.newSessionFromHere"),"aria-label":m("desktop.newSessionFromHere"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,background:"none",border:"none",borderRadius:5,color:x?"var(--accent)":"var(--text-dim)",cursor:x?"not-allowed":"pointer",opacity:+!!b,pointerEvents:b?"auto":"none",transition:"opacity 0.12s, color 0.12s"},children:(0,r.jsx)(M.C,{size:11})}),k&&!t&&(0,r.jsx)("span",{style:{fontSize:11,color:b?"var(--text-muted)":"var(--text-dim)",opacity:b?1:.5,marginLeft:"auto",transition:"color 0.15s, opacity 0.15s"},children:k}),L.length>0&&!t&&(0,r.jsxs)("span",{style:{position:"relative",display:"inline-flex",alignItems:"center"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>H(e=>!e),title:m("desktop.changedFiles",{count:L.length}),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 7px",border:"1px solid var(--border)",borderRadius:999,background:O?"var(--bg-hover)":"none",color:"var(--text-muted)",fontSize:10,cursor:"pointer",opacity:b||O?1:.5,transition:"opacity 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{O||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)")},children:[(0,r.jsx)(M.C,{size:10,"aria-hidden":"true"}),L.length]}),O&&(0,r.jsx)("span",{style:{position:"absolute",right:0,top:"calc(100% + 6px)",zIndex:30,minWidth:200,maxWidth:320,padding:"6px 0",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.18)"},children:L.map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>{H(!1),a?.(e)},style:{display:"block",width:"100%",padding:"5px 12px",background:"none",border:"none",color:"var(--text-muted)",fontSize:11,textAlign:"left",fontFamily:"var(--font-mono)",cursor:"pointer",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:e},e))})]})]})]}):null}function oE({block:e,toolResults:t,isStreaming:o,streamingDuration:n,toolCallDurations:s,cwd:i,onOpenFile:a,onQuoteReply:l,sessionId:d,entryId:c,blockIndex:p}){if("text"===e.type)return(0,r.jsx)(oP,{block:e,isStreaming:o,cwd:i,onOpenFile:a,onQuoteReply:l});if("thinking"===e.type)return(0,r.jsx)(oD,{block:e,duration:n,sessionId:d,entryId:c,blockIndex:p});if("toolCall"===e.type){let o=t?.get(e.toolCallId),n=s?.get(e.toolCallId);return(0,r.jsx)(oF,{block:e,result:o,duration:n})}return null}function oP({block:e,isStreaming:t,cwd:o,onOpenFile:n,onQuoteReply:s}){return(0,r.jsx)(t8,{isStreaming:t,cwd:o,onOpenFile:n,onQuoteReply:s,children:e.text})}function oD({block:e,duration:t,sessionId:o,entryId:s,blockIndex:i,contentOnly:a=!1,isStreaming:l,cwd:d,onOpenFile:c,className:p}){let{t:u}=(0,E.s)(),[g,h]=(0,n.useState)(!1),[x,f]=(0,n.useState)(null),[m,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(null),b=async()=>{let t=!g;if(h(t),!t||!e.deferred||null!==x)return;if(!o||!s)return void y(u("desktop.thinkingContentUnavailable"));let r=5,n=()=>{k(!0),y(null),oT(o,s,i).then(e=>{f(e),k(!1)}).catch(e=>{r>1?(r--,setTimeout(n,2e3)):(k(!1),y(e instanceof Error?e.message:String(e)))})};n()};return a?(0,r.jsx)(o$,{block:e,sessionId:o,entryId:s,blockIndex:i,isStreaming:l,cwd:d,onOpenFile:c,className:p}):(0,r.jsxs)("div",{className:"thinking-block",children:[(0,r.jsxs)("button",{onClick:()=>void b(),className:"thinking-block-trigger","aria-expanded":g,children:[(0,r.jsx)("span",{className:`thinking-block-caret ${g?"is-expanded":""}`,"aria-hidden":"true",children:"›"}),(0,r.jsx)("span",{className:"thinking-block-icon","aria-hidden":"true",children:"✦"}),(0,r.jsx)("span",{children:u("desktop.thinking")}),void 0!==t&&(0,r.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]})]}),g&&(0,r.jsx)("div",{className:`thinking-block-content ${v?"is-error":""}`,children:m?u("desktop.loadingThinking"):v??(e.deferred?x:e.thinking)})]})}function o$({block:e,sessionId:t,entryId:o,blockIndex:s,isStreaming:i,cwd:a,onOpenFile:l,className:d}){let{t:c}=(0,E.s)(),[p,u]=(0,n.useState)(null),[g,h]=(0,n.useState)(!0===e.deferred),[x,f]=(0,n.useState)(null);return((0,n.useEffect)(()=>{let r=!1,n=5;if(!e.deferred)return void h(!1);if(!t||!o){h(!1),f(c("desktop.thinkingContentUnavailable"));return}let i=()=>{r||(h(!0),f(null),oT(t,o,s).then(e=>{r||(u(e),h(!1))}).catch(e=>{r||(n>1?(n--,setTimeout(i,2e3)):(h(!1),f(e instanceof Error?e.message:String(e))))}))};return i(),()=>{r=!0}},[e.deferred,s,o,t,c]),g)?(0,r.jsx)("div",{className:"text-xs text-text-dim",children:c("desktop.loadingThinking")}):x?(0,r.jsx)("div",{className:"text-xs text-red-400",children:x}):(0,r.jsx)(t8,{isStreaming:i,cwd:a,onOpenFile:l,className:d,children:e.deferred?p??"":e.thinking})}let oF=(0,n.memo)(function({block:e,result:t,duration:o,processStyle:s=!1}){let[i,a]=(0,n.useState)(!1),l=(0,n.useMemo)(()=>JSON.stringify(e.input,null,2),[e.input]),d=oH(e.toolName),c=t&&!t.isError?function(e){var t;let o=e.details;if(!("object"==typeof(t=o)&&null!==t&&!Array.isArray(t)))return null;let r="string"==typeof o.patch?o.patch:null;if(r)return{text:r};let n="string"==typeof o.diff?o.diff:null;return n?{text:n}:null}(t):null,p=(0,n.useMemo)(()=>t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,[t]),u=null!==p&&("(no output)"===p.trim()||""===p.trim()),g=t?.isError??!1;return(0,r.jsxs)("div",{className:`tool-call-block ${s?"is-process":""} ${g?"is-error":""}`,children:[(0,r.jsxs)("button",{onClick:()=>a(e=>!e),className:"tool-call-trigger","aria-expanded":i,children:[(0,r.jsx)("span",{className:"tool-call-name",children:e.toolName}),(0,r.jsx)("span",{className:"tool-call-preview",children:function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let o=Object.keys(t);return 0===o.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[o[0]]).slice(0,120)}(e)}),void 0!==o&&(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[o,"s"]}),(0,r.jsx)("span",{className:`tool-call-caret ${i?"is-expanded":""}`,"aria-hidden":"true",children:(0,r.jsx)(m.J,{size:12})})]}),i&&!d&&(0,r.jsx)("pre",{className:"tool-call-input",children:l}),i&&t&&(c?(0,r.jsx)(oW,{diff:c,processStyle:s}):(0,r.jsx)(oB,{text:p??"",isEmpty:u,isError:g,processStyle:s}))]})});function oW({diff:e,processStyle:t=!1}){return(0,r.jsx)("div",{style:{borderTop:t?"1px solid var(--border)":"1px solid rgba(34,197,94,0.15)",background:"var(--bg)"},children:(0,r.jsx)(oN,{text:e.text})})}function oN({text:e}){let{t}=(0,E.s)(),o=(0,n.useMemo)(()=>od(e),[e]);if(!o)return(0,r.jsx)(oO,{text:e});let s=o.length>1;return(0,r.jsx)("div",{style:{maxHeight:560,overflowY:"auto",overflowX:"hidden",background:"var(--bg)"},children:o.map((e,o)=>(0,r.jsxs)("div",{style:{minWidth:0,borderTop:0===o?"none":"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55},children:[s&&(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)(oA,{title:e.oldPath||t("desktop.before"),side:"left"}),(0,r.jsx)(oA,{title:e.newPath||t("desktop.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)(oL,{cell:e.left,side:"left"}),(0,r.jsx)(oL,{cell:e.right,side:"right"})]},t))})]},o))})}function oA({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 oL({cell:e,side:t}){let o="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",n="added"===e.type?"+":"removed"===e.type?"-":" ",s="added"===e.type?"#22c55e":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",minWidth:0,background:o,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:s,userSelect:"none",fontWeight:"context"===e.type||"empty"===e.type?400:700,flexShrink:0},children:n}),(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 oO({text:e}){let t=e.split(/\r?\n/);return(0,r.jsx)("div",{style:{maxHeight:520,overflowY:"auto",overflowX:"hidden",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:0},children:t.map((e,t)=>{let o=e.startsWith("@@")?"hunk":e.startsWith("+")&&!e.startsWith("+++")?"added":e.startsWith("-")&&!e.startsWith("---")?"removed":"context";return(0,r.jsxs)("div",{style:{display:"flex",background:"added"===o?"rgba(34,197,94,0.12)":"removed"===o?"rgba(248,113,113,0.13)":"hunk"===o?"rgba(96,165,250,0.12)":"transparent",borderLeft:"added"===o?"3px solid #22c55e":"removed"===o?"3px solid #f87171":"hunk"===o?"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"===o?"#22c55e":"removed"===o?"#f87171":"hunk"===o?"var(--accent)":"var(--text)"},children:e||"\xa0"})]},t)})})}function oH(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 oB({text:e,isEmpty:t,isError:o,processStyle:s=!1}){let{t:i}=(0,E.s)(),[a,l]=(0,n.useState)(!1),d=!t&&e.length>8e3&&!a,c=d?e.slice(0,8e3):e;return(0,r.jsxs)("div",{style:{borderTop:`1px solid ${s?"var(--border)":o?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:s?"var(--bg-subtle)":o?"rgba(248,113,113,0.04)":"var(--bg-subtle)"},children:[(0,r.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:o?"#f87171":t?"var(--text-dim)":"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",maxHeight:400,background:"var(--bg)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontStyle:t?"italic":"normal",opacity:t?.6:1},children:t?i("desktop.noOutput"):c}),d&&(0,r.jsx)("button",{onClick:()=>l(!0),style:{display:"block",margin:"6px 8px 8px",padding:"4px 10px",border:"1px solid var(--border)",borderRadius:5,background:"transparent",color:"var(--text-dim)",fontSize:11,cursor:"pointer"},children:i("desktop.loadFullOutput")})]})}function oU({message:e,isStreaming:t,cwd:o,onOpenFile:s}){var i,a,l,d,c,p;let u,{t:g}=(0,E.s)(),h=!1===e.display,[x,f]=(0,n.useState)(!h),[m,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(!1),b="string"==typeof(i=e.content)?i:i.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),w="string"==typeof(a=e.content)?[]:a.filter(e=>"image"===e.type),j=void 0!==e.details,S=j?function(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.details):"",C=(l=e.customType,d=g("desktop.extension"),l||d),T=oz(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:h?"var(--bg-subtle)":"var(--bg)",opacity:h&&!x?.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:C}),h&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:g("desktop.hiddenExtensionMessage")}),T&&(0,r.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:T})]}),x?(0,r.jsxs)("div",{style:{padding:"6px 9px"},children:[w.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!b},children:w.map((e,t)=>{var o;let n=(o=e).source?"base64"===o.source.type?`data:${o.source.media_type};base64,${o.source.data}`:o.source.url??"":o.data?`data:${o.mimeType};base64,${o.data}`:"";return n?(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})}),b?(0,r.jsx)(t8,{className:"markdown-custom-message",isStreaming:t,cwd:o,onOpenFile:s,children:b}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:g("desktop.noMessage")})]}):(0,r.jsx)("button",{onClick:()=>f(!0),style:{display:"block",width:"100%",padding:"8px 10px",border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",fontSize:12,textAlign:"left"},children:b?(c=b,p=g("desktop.showExtensionMessage"),(u=c.replace(/\s+/g," ").trim())?u.length>140?`${u.slice(0,140)}...`:u:p):g("desktop.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:[b||S?(0,r.jsx)("button",{onClick:()=>{tD(b||S).then(()=>{y(!0),setTimeout(()=>y(!1),1500)})},style:{padding:"3px 7px",border:"none",background:"none",color:v?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11},children:g(v?"desktop.copied":"desktop.copy")}):null,(j||h)&&(0,r.jsx)("button",{onClick:()=>{h?f(e=>!e):k(e=>!e)},style:{marginLeft:"auto",padding:"3px 7px",border:"none",background:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11},children:g(h?x?"desktop.collapse":"desktop.expand":m?"desktop.hideDetails":"desktop.showDetails")})]}),j&&(h&&x||!h&&m)&&(0,r.jsx)("pre",{style:{margin:0,padding:"9px 10px",borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:360,overflow:"auto",fontFamily:"var(--font-mono)"},children:S})]})})}function o_({message:e,sessionId:t}){let{t:o}=(0,E.s)(),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(null),p=!e.output&&void 0===e.exitCode&&!e.cancelled,u=e.cancelled||void 0!==e.exitCode&&0!==e.exitCode,g=t&&e.fullOutputPath?`/api/agent/${encodeURIComponent(t)}/bash-output?path=${encodeURIComponent(e.fullOutputPath)}`:null,h=s??e.output,x=async()=>{if(g){l(!0),c(null);try{let e=await fetch(g),t=await e.json();if(!e.ok||!t.success)throw Error(t.error??`HTTP ${e.status}`);i(t.data?.output??"")}catch(e){c(e instanceof Error?e.message:String(e))}finally{l(!1)}}},f=e.excludeFromContext?"bash (local)":"bash",m={type:"toolCall",toolCallId:`bash-${e.timestamp??e.command}`,toolName:f,input:{command:e.command}},k=p?void 0:{role:"toolResult",toolCallId:m.toolCallId,toolName:f,content:h?[{type:"text",text:h}]:[],isError:u,timestamp:e.timestamp};return(0,r.jsxs)("div",{style:{margin:"6px 0"},children:[(0,r.jsx)(oF,{block:m,result:k}),e.truncated&&g&&null===s&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void x(),disabled:a,style:{padding:"3px 8px",border:"1px solid var(--border)",borderRadius:4,background:"none",color:"var(--text-muted)",cursor:a?"wait":"pointer",fontSize:11},children:o(a?"desktop.loading":"desktop.loadFullOutput")}),(0,r.jsx)("a",{href:`${g}&download=1`,style:{fontSize:11,color:"var(--accent)"},children:o("desktop.download")})]}),d&&(0,r.jsx)("div",{style:{marginTop:4,color:"var(--accent-red)",fontSize:11},children:d})]})}var oq=o(35828),oV=o(61719),oK=o(259);function oJ({open:e,onExecute:t,onFeedback:o,onExit:s,onClose:i,busy:a=!1}){let{t:l}=(0,E.s)(),[d,c]=(0,n.useState)(!1),[p,u]=(0,n.useState)(""),g=(0,n.useRef)(null);return((0,n.useEffect)(()=>{e&&(c(!1),u(""))},[e]),(0,n.useEffect)(()=>{d&&g.current?.focus()},[d]),e)?(0,r.jsxs)("div",{role:"region","aria-label":l("tasks.planReviewTitle"),style:{maxWidth:820,margin:"12px auto 8px",border:"1px solid color-mix(in srgb, var(--accent) 28%, var(--border))",borderRadius:12,background:"var(--bg-panel)",animation:"plan-card-in 0.18s ease-out",overflow:"hidden"},children:[d&&(0,r.jsxs)("div",{style:{padding:"10px 14px",display:"flex",flexDirection:"column",gap:6,borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("label",{style:{fontSize:11.5,color:"var(--text-muted)"},children:l("tasks.planReviewFeedbackLabel")}),(0,r.jsx)("textarea",{ref:g,value:p,onChange:e=>u(e.target.value),placeholder:l("tasks.planReviewFeedbackPlaceholder"),rows:2,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12.5,outline:"none",fontFamily:"inherit",resize:"vertical"}}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[(0,r.jsx)("button",{type:"button",onClick:()=>c(!1),disabled:a,style:{padding:"5px 10px",borderRadius:6,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",fontSize:11.5,cursor:a?"not-allowed":"pointer"},children:l("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>{p.trim()&&o(p.trim())},disabled:a||!p.trim(),style:{padding:"5px 12px",borderRadius:6,background:"var(--accent)",color:"#fff",border:"none",fontSize:11.5,fontWeight:600,cursor:a||!p.trim()?"not-allowed":"pointer"},children:l("tasks.planReviewSendFeedback")})]})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 10px"},children:[(0,r.jsx)(oq.y,{size:14,weight:"fill",color:"var(--accent)","aria-hidden":"true"}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:650,color:"var(--text)",marginRight:8,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l("tasks.planReviewTitle")}),(0,r.jsxs)("button",{type:"button",onClick:t,disabled:a,title:l("tasks.planReviewExecute"),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 12px",borderRadius:7,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:650,cursor:a?"not-allowed":"pointer",transition:"opacity 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.opacity="0.88")},onMouseLeave:e=>{e.currentTarget.style.opacity="1"},children:[(0,r.jsx)(oV.r,{size:13,weight:"fill","aria-hidden":"true"}),l("tasks.planReviewExecute")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{d?c(!1):(c(!0),requestAnimationFrame(()=>g.current?.focus()))},disabled:a,title:l("tasks.planReviewSuggest"),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 10px",borderRadius:7,background:d?"var(--bg-selected)":"none",border:d?"1px solid var(--accent)":"1px solid var(--border)",color:d?"var(--accent)":"var(--text)",fontSize:12,fontWeight:550,cursor:a?"not-allowed":"pointer",transition:"background 0.12s"},onMouseEnter:e=>{a||d||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{d||(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text)")},children:[(0,r.jsx)(w.S,{size:12,"aria-hidden":"true"}),l("tasks.planReviewSuggest")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{c(!1),s()},disabled:a,title:l("tasks.planReviewExit"),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 8px",borderRadius:7,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:a?"not-allowed":"pointer"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(oK.f,{size:12,"aria-hidden":"true"}),l("tasks.planReviewExit")]}),(0,r.jsx)("button",{type:"button",onClick:i,disabled:a,title:l("i18n.close"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:a?"not-allowed":"pointer",borderRadius:5},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:"✕"})]})]}):null}var oG=o(19336);function oY({goalState:e,onPause:t,onResume:o,onStop:n}){let{t:s}=(0,E.s)();if("idle"===e.status||"complete"===e.status)return null;let i="running"===e.status,a="paused"===e.status||"blocked"===e.status,l=e.startedAt?new Date(e.startedAt).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):null,d=i?"var(--accent)":a?"color-mix(in srgb, #f59e0b 60%, transparent)":"var(--border)";return(0,r.jsxs)("div",{style:{flexShrink:0,marginTop:0,borderTop:`1px solid ${d}`,borderBottom:`1px solid ${d}`,background:`color-mix(in srgb, ${d} 6%, transparent)`,padding:"6px 14px",display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,r.jsx)(oG.d,{size:14,weight:"fill",color:"var(--accent)","aria-hidden":"true"}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:e.goalText??s("desktop.goalRunning")}),l&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap",flexShrink:0},children:l}),i&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap",flexShrink:0},children:[e.turnsUsed,"/",e.turnsLimit]}),e.noProgressTurns>0&&(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-muted)",flexShrink:0},children:s("desktop.goalNoProgress",{n:e.noProgressTurns})}),(0,r.jsx)("button",{type:"button",onClick:t,title:s("desktop.goalPause"),"aria-label":s("desktop.goalPause"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"2px 6px",borderRadius:4,background:"color-mix(in srgb, var(--text-muted) 10%, transparent)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,flexShrink:0},children:s("desktop.goalPauseShort")})]}),a&&(0,r.jsx)("button",{type:"button",onClick:o,title:s("desktop.goalResume"),"aria-label":s("desktop.goalResume"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"2px 6px",borderRadius:4,background:"color-mix(in srgb, #f59e0b 12%, transparent)",border:"1px solid color-mix(in srgb, #f59e0b 30%, transparent)",color:"var(--text)",cursor:"pointer",fontSize:11,fontWeight:600,flexShrink:0},children:s("desktop.goalResumeShort")}),(0,r.jsx)("button",{type:"button",onClick:n,title:s("desktop.goalStop"),"aria-label":s("desktop.goalStop"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,width:20,height:20,borderRadius:4,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:13,opacity:.7,flexShrink:0},children:"✕"})]})}var oZ=o(77229);function oX({request:e,queuedCount:t=0,busy:o=!1,onResolve:s}){let{t:i}=(0,E.s)(),[a,l]=(0,n.useState)(""),d=(0,n.useRef)(null),[p,g]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{e&&(l(""),g(!1))},[e?.id]),!e)return null;let h=function(e){if(null==e)return"{}";if("string"==typeof e)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.args),x=h.length>4e3;return(0,r.jsx)("div",{style:{position:"fixed",left:0,right:0,bottom:130,zIndex:1300,display:"flex",justifyContent:"center",pointerEvents:"none",padding:"0 14px"},children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"false","aria-label":"工具调用审批",style:{pointerEvents:"auto",width:"min(380px, 100%)",maxHeight:"min(60vh, 400px)",display:"flex",flexDirection:"column",background:"var(--bg-panel)",border:"1px solid color-mix(in srgb, #f59e0b 32%, var(--border))",borderRadius:12,boxShadow:"0 12px 36px rgba(0,0,0,0.28)",animation:"plan-card-in 0.18s ease-out",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 16px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)(oZ.Z,{size:18,weight:"fill",color:"var(--accent)","aria-hidden":"true"}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsxs)("div",{style:{fontSize:14,fontWeight:650,color:"var(--text)"},children:[i("approval.title"),t>0&&(0,r.jsxs)("span",{style:{marginLeft:8,fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:["+",t," ",i("approval.queued")]})]}),(0,r.jsx)("div",{style:{fontSize:11.5,color:"var(--text-muted)",marginTop:1},children:i("approval.subtitle")})]}),(0,r.jsx)("button",{type:"button","aria-label":i("i18n.close"),onClick:()=>s(!1,"Dismissed"),disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,background:"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:o?"not-allowed":"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-muted)"},children:(0,r.jsx)(c.u,{size:14,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{padding:"14px 16px",overflowY:"auto",flex:1},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10},children:[(0,r.jsx)("span",{style:{display:"inline-flex",alignItems:"center",padding:"3px 10px",borderRadius:6,background:"var(--bg-selected)",color:"var(--text)",fontSize:12.5,fontWeight:600,fontFamily:"var(--font-mono)"},children:e.toolName}),e.args&&"object"==typeof e.args&&"command"in e.args?(0,r.jsx)("span",{style:{fontSize:11.5,color:"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:String(e.args.command??"")}):null]}),(0,r.jsx)("div",{style:{background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"10px 12px",maxHeight:220,overflow:"auto"},children:(0,r.jsx)("pre",{style:{margin:0,fontSize:11.5,lineHeight:1.55,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:x?`${h.slice(0,4e3)}
|
|
27
|
+
…`:h})}),p&&(0,r.jsx)("textarea",{ref:d,value:a,onChange:e=>l(e.target.value),placeholder:i("approval.reasonPlaceholder"),rows:2,style:{width:"100%",marginTop:10,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12.5,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"10px 14px",borderTop:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>s(!0),disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"9px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12.5,fontWeight:650,cursor:o?"not-allowed":"pointer",transition:"opacity 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.opacity="0.88")},onMouseLeave:e=>{e.currentTarget.style.opacity="1"},children:[(0,r.jsx)(u.S,{size:14,weight:"bold","aria-hidden":"true"}),i("approval.allow")]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{g(e=>!e),p||requestAnimationFrame(()=>d.current?.focus())},disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"9px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12.5,fontWeight:550,cursor:o?"not-allowed":"pointer",transition:"background 0.12s"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,r.jsx)(c.u,{size:13,"aria-hidden":"true"}),i(p?"approval.hideReason":"approval.denyWithReason")]}),(0,r.jsx)("button",{type:"button",onClick:()=>s(!1,a.trim()||void 0),disabled:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",padding:"8px 14px",borderRadius:8,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:o?"not-allowed":"pointer"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:i("approval.deny")})]})]})})}let oQ="pi:create-task-from-text",o0=null,o1="pi-process-display-mode",o2="tabs",o4="pi-process-display-mode-change";function o6(){let e=window.localStorage.getItem(o1);return"timeline"===e||"tabs"===e?e:o2}function o5(e){let t=t=>{t.key===o1&&e()};return window.addEventListener(o4,e),window.addEventListener("storage",t),()=>{window.removeEventListener(o4,e),window.removeEventListener("storage",t)}}function o3(){return o2}function o8(e,t){if(!e)return!1;let o=new Set(t.map(e=>e.toLowerCase()));return Object.keys(e).some(e=>o.has(e.toLowerCase()))}function o7(e,t){if(!e)return;let o=new Set(t.map(e=>e.toLowerCase()));for(let[t,r]of Object.entries(e)){if(!o.has(t.toLowerCase())||"string"!=typeof r)continue;let e=r.trim();if(e)return e}}function o9(e){return"object"==typeof e&&null!==e?e:{}}function re(e){return"add"===e||"added"===e||"create"===e?"create":"delete"===e||"deleted"===e||"remove"===e||"removed"===e?"delete":"update"===e||"modified"===e||"edit"===e||"move"===e?"edit":void 0}function rt(e){if(0!==e.length)return 1===new Set(e).size?e[0]:"edit"}function ro(e){if(Array.isArray(e))return rt(e.map(e=>re(o9(e).type||o9(e).status||o9(e).changeType)).filter(e=>!!e))}function rr(e){if(!e)return;let t=(e.match(/^\*\*\* Add File:/gm)||[]).length,o=(e.match(/^\*\*\* Delete File:/gm)||[]).length,r=(e.match(/^\*\*\* (Update File|Move to):/gm)||[]).length;if(t||o||r){let e=[];if(t)for(let o=0;o<t;o++)e.push("create");if(o)for(let t=0;t<o;t++)e.push("delete");if(r)for(let t=0;t<r;t++)e.push("edit");return rt(e)}return/^@@ -0,0 \+\d+/m.test(e)?"create":/^@@ -\d+(?:,\d+)? \+0,0/m.test(e)?"delete":void 0}function rn(e){let t=o7(e.args,["path","file","filePath","filepath"]);if(t)return t;let o=o7(e.metadata,["relativePath","filePath","filepath","path","file"]);if(o)return o;let r=o7(Array.isArray(e.metadata?.files)?o9(e.metadata.files[0]):{},["relativePath","filePath","filepath","path","file"]);if(r)return r}function rs(e){return e.split(/[\\/]/).filter(Boolean).pop()||e}let ri=new Set(["cd","chdir","pwd","echo","set","export","source",".","pushd","popd","dirs"]),ra=new Set(["timeout"]),rl=new Set(["ls","dir","ll","la","l","tree","eza","exa"]),rd=new Set(["rg","grep","egrep","fgrep","ack","ag","ripgrep"]),rc=new Set(["find","fd","fdfind","locate","mlocate","glob"]),rp=new Set(["cat","head","tail","less","more","bat","nl","wc"]),ru=new Set(["curl","wget","fetch","http","xh","httpx"]),rg=new Set(["rm","del","rmdir","unlink","erase"]),rh=new Set(["cp","mv","copy","move","rename","ren"]);var rx=o(36705),rf=o(94366),rm=o(66129),rk=o(2152),rv=o(30515),ry=o(59304),rb=o(8727),rw=o(60721),rj=o(47208),rS=o(95951),rC=o(29886),rT=o(86756);function rz(e,t){var o,r,n;let s,i,a,l,d,c,p,u,g,h="string"==typeof(l=e.input.label)&&l.trim()?l:e.toolName;if("error"===e.status)return{displayLabel:h,iconName:"warning",tone:void 0};let x=(d=[(r=o={toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0}).toolName,r.title,r.label].filter(Boolean).join("\n").toLowerCase(),c=o8(o.args,["path","file","filePath","filepath"]),p=o8(o.args,["content","oldString","old_string","newString","new_string","patch","diff","edits","text"]),u=o8(o.args,["command","cmd","script"]),g=o8(o.args,["pattern","query"]),u||/\b(bash|shell|terminal|command|run|exec|execute|python|node|npm|pnpm|yarn|cargo|go|pytest|test|build|make|git|docker|kubectl|curl|wget)\b/i.test(d)?"command_execution":/\b(todo|todowrite|todo_write|write_todo|task_list|task\s*list)\b/i.test(d)?"todo_update":/\b(edit|write|patch|apply|modify|replace|update|create|delete|remove|insert|rename|move)\b/i.test(d)||c&&p?"document_change":"ls"===(s=o.toolName.toLowerCase())||"list"===s||"dir"===s||s.startsWith("list_")||s.endsWith("_list")||s.includes("list_directory")||s.includes("list_dir")||/\b(ls|list\s*directory|list\s*dir|dir\s*list|listdir)\b/i.test(d)?"directory_list":"find"===(i=o.toolName.toLowerCase())||"glob"===i||"scan"===i||i.includes("file_search")||i.includes("file_find")||i.startsWith("find_")||i.startsWith("glob_")||i.startsWith("scan_")||/\b(find[_\s]*files?|file[_\s]*find|glob|scan[_\s]*files?)\b/i.test(d)?"file_find":/\b(grep|rg|search|semantic|fuzzy|ripgrep)\b/i.test(d)||(a=o.toolName.toLowerCase()).includes("grep")||a.includes("search")||a.includes("fuzzy")||a.includes("ripgrep")||g&&!p&&!u?"document_search":/\b(read|view|open|cat|show|display)\b/i.test(d)||c&&!p&&!u?"document_read":void 0),f="toolbox";if("document_change"===x){let o,r,s,i=(r=o9((o=(n={toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0}).metadata||{}).filediff),s=function(e){if(!e)return{};try{return o9(JSON.parse(e))}catch{return{}}}(n.result),ro(o.files)??ro(s.files)??re(o.type||o.status||o.changeType)??(!1===o.exists?"create":void 0)??(!0===o.exists?"edit":void 0)??rr("string"==typeof o.diff?o.diff:"")??rr("string"==typeof o.patch?o.patch:"")??rr("string"==typeof r.patch?r.patch:"")??rr("string"==typeof n.args?.patchText?n.args.patchText:"")??function(e){if(!e)return;let t=e.split(/\r?\n/).map(e=>e.trim()).filter(e=>/^[ADM]\s+/.test(e));if(0!==t.length)return rt(t.map(e=>e.startsWith("A ")?"create":e.startsWith("D ")?"delete":"edit"))}(n.result)??function(e){if(!e)return;let t=e.trim().replace(/\s+/g," ").toLowerCase();return/^(?:rm|del|erase|unlink)\b/.test(t)||/^remove-item\b/.test(t)?"delete":/^mkdir\b/.test(t)?"create":void 0}("string"==typeof n.args?.command?n.args.command:void 0)??"edit");f="create"===i?"filePlus":"delete"===i?"trash":"pencilSimpleLine";let a=t("create"===i?"desktop.processStepFileCreate":"delete"===i?"desktop.processStepFileDelete":"desktop.processStepFileEdit"),l=rn({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return l?{displayLabel:`${a} ${rs(l)}`,iconName:f,target:l,tone:x,typeLabel:a}:{displayLabel:`${a}: ${h}`.slice(0,100),iconName:f,tone:x,typeLabel:a}}if("document_read"===x){f="bookOpen";let o=t("desktop.processStepFileRead"),r=rn({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return r?{displayLabel:`${o} ${rs(r)}`,iconName:f,target:r,tone:x,typeLabel:o}:{displayLabel:h,iconName:f,tone:x,typeLabel:o}}if("document_search"===x){f="magnifyingGlass";let o=t("desktop.processStepSearch"),r="string"==typeof e.input.pattern?e.input.pattern:"string"==typeof e.input.query?e.input.query:"";return r?{displayLabel:`${o} "${r.slice(0,60)}"`,iconName:f,tone:x,typeLabel:o}:{displayLabel:h,iconName:f,tone:x,typeLabel:o}}if("directory_list"===x){f="folder";let o=t("desktop.processStepList"),r=rn({toolName:e.toolName,label:"string"==typeof e.input.label?e.input.label:void 0,args:e.input,result:"string"==typeof e.result?e.result:void 0});return r?{displayLabel:`${o} ${rs(r)}`,iconName:f,target:r,tone:x,typeLabel:o}:{displayLabel:h,iconName:f,tone:x,typeLabel:o}}if("file_find"===x){f="magnifyingGlass";let o=t("desktop.processStepFind"),r="string"==typeof e.input.pattern?e.input.pattern:"string"==typeof e.input.glob?e.input.glob:"";return r?{displayLabel:`${o} "${r.slice(0,60)}"`,iconName:f,tone:x,typeLabel:o}:{displayLabel:h,iconName:f,tone:x,typeLabel:o}}if("command_execution"===x){let o="string"==typeof e.input.command?e.input.command:"string"==typeof e.input.cmd?e.input.cmd:"";if(o){let e=function(e){let t=e.split(/&&|\n|;(?!;)|(?<!\|)\|(?!\|)/),o=e.split(/\s+/)[0]?.replace(/^[.\\/]+/,"")||"sh";for(let e of t){var r;let t=(r=e.trim(),r.match(/"[^"]+"|'[^']+'|\S+/g)?.map(e=>e.replace(/^(["'])(.*)\1$/,"$2"))??[]);if(0===t.length)continue;let o=0;for(;o<t.length&&(ri.has(t[o].toLowerCase())||ra.has(t[o].toLowerCase()));){let e=t[o].toLowerCase();if((o+=1)<t.length&&["cd","chdir","pushd"].includes(e)&&(o+=1),"timeout"===e)for(;o<t.length&&(t[o].startsWith("-")||/^\d/.test(t[o]));)o++}if(o>=t.length)continue;let n=t[o].replace(/^[.\\/]+/,"").toLowerCase(),s=n.split(/[/\\]/).pop()||n,i=o+1;for(;i<t.length&&t[i].startsWith("-");)i+=1;let a=i<t.length?t[i]:void 0;if(rl.has(s))return{kind:"list",binary:s,argument:a};if(rd.has(s))return{kind:"search",binary:s,argument:a};if(rc.has(s))return{kind:"find",binary:s,argument:a};if(rp.has(s))return{kind:"read",binary:s,argument:a};if(ru.has(s))return{kind:"fetch",binary:s,argument:a};if(rg.has(s))return{kind:"delete",binary:s,argument:a};if(rh.has(s))return{kind:"copy",binary:s,argument:a};return{kind:"run",binary:s,argument:a}}return{kind:"run",binary:o}}(o);if("list"===e.kind){f="folder";let o=t("desktop.processStepList"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:x,typeLabel:o}}if("search"===e.kind){f="magnifyingGlass";let o=t("desktop.processStepSearch"),r=e.argument?` "${e.argument.slice(0,60)}"`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:x,typeLabel:o}}if("find"===e.kind){f="magnifyingGlass";let o=t("desktop.processStepFind"),r=e.argument?` "${e.argument.slice(0,60)}"`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:x,typeLabel:o}}if("read"===e.kind){f="bookOpen";let o=t("desktop.processStepRead"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:x,typeLabel:o,target:e.argument||void 0}}if("fetch"===e.kind){f="download";let o=t("desktop.processStepFetch"),r=e.argument?` ${e.argument.slice(0,80)}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:x,typeLabel:o}}if("delete"===e.kind){f="trash";let o=t("desktop.processStepDelete"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:x,typeLabel:o}}if("copy"===e.kind){f="copy";let o=t("desktop.processStepCopy"),r=e.argument?` ${e.argument}`:"";return{displayLabel:`${o}${r}`,iconName:f,tone:x,typeLabel:o}}f="terminal";let r=t("desktop.processStepCommand"),n=e.argument?`${e.binary} ${e.argument.length>60?e.argument.slice(0,57)+"...":e.argument}`:e.binary;return{displayLabel:`${r} ${n}`,iconName:f,tone:x,typeLabel:r}}return{displayLabel:h,iconName:f="terminal",tone:x}}return"todo_update"===x?{displayLabel:h,iconName:f="checklist",tone:x,typeLabel:t("desktop.processStepTodo")}:{displayLabel:h,iconName:f,tone:x}}function rR({expanded:e}){return(0,r.jsx)(m.J,{size:12,className:`shrink-0 transition-all duration-150 ${e?"rotate-90":""}`})}function rI(e,t=14){switch(e){case"brain":return(0,r.jsx)(rx.$,{size:t});case"bookOpen":return(0,r.jsx)(rf.R,{size:t});case"magnifyingGlass":return(0,r.jsx)(d.$,{size:t});case"pencilSimpleLine":return(0,r.jsx)(rj.B,{size:t});case"filePlus":return(0,r.jsx)(rv.u,{size:t});case"trash":return(0,r.jsx)(j.u,{size:t});case"folder":return(0,r.jsx)(ry.sj,{size:t});case"download":return(0,r.jsx)(R.e,{size:t});case"copy":return(0,r.jsx)(rk.t,{size:t});case"terminal":return(0,r.jsx)(rC.k,{size:t});case"toolbox":default:return(0,r.jsx)(rT.D,{size:t});case"image":return(0,r.jsx)(rb.x,{size:t});case"listBullets":case"checklist":return(0,r.jsx)(rw.j,{size:t});case"warning":case"circleX":return(0,r.jsx)(ok.M,{size:t})}}function rM({step:e,ts:t}){if("thinking"===e.kind)return rI("brain");if("image"===e.kind)return rI("image");if("custom"===e.kind)return rI("listBullets");if("toolGroup"===e.kind)return rI(e.iconName);let{iconName:o}=rz(e.block,t);return rI(o)}function rE({targets:e,typeLabel:t,count:o,label:n}){if(0===e.length)return(0,r.jsx)("span",{className:"max-w-52 truncate",title:n,children:n});if(2===e.length)return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:t}),(0,r.jsx)(rP,{filePath:e[0]}),(0,r.jsx)(rP,{filePath:e[1]})]});let s=e[0].split(".").pop()?.toLowerCase()||"",i=[],a=new Set([s]);for(let t=1;t<e.length&&i.length<2;t++){let o=e[t].split(".").pop()?.toLowerCase()||"";a.has(o)||(a.add(o),i.push({key:e[t],node:G(e[t],12)}))}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:t}),i.length>0&&(0,r.jsx)("span",{className:"shrink-0 inline-flex gap-px",children:i.map(e=>(0,r.jsx)("span",{className:"inline-flex",children:e.node},e.key))}),(0,r.jsx)(rP,{filePath:e[0]}),(0,r.jsxs)("span",{className:"shrink-0 text-[10px] tabular-nums text-text-dim",children:["+",o-1]})]})}function rP({filePath:e}){let t=e.split(/[\\/]/).filter(Boolean).pop()||e;return(0,r.jsxs)("span",{className:"process-file-tag",title:e,children:[G(e,12),(0,r.jsx)("span",{children:t})]})}function rD({mode:e}){return"timeline"===e?(0,r.jsx)(rS.D,{size:14}):(0,r.jsx)(rm.j,{size:14})}function r$({step:e,cwd:t,onOpenFile:o,sessionId:n,ts:s,isStreaming:i}){let a;if("thinking"===e.kind)return(0,r.jsx)(rF,{blocks:e.blocks,cwd:t,onOpenFile:o,sessionId:n,isStreaming:i});if("tool"===e.kind)return(0,r.jsxs)("div",{className:"space-y-2",children:[e.leadBlocks.length>0&&(0,r.jsx)(rF,{blocks:e.leadBlocks,cwd:t,onOpenFile:o,sessionId:n,isStreaming:i}),(0,r.jsx)(oF,{block:{type:"toolCall",toolCallId:e.block.toolCallId,toolName:e.block.toolName,input:e.block.input},result:e.block.result,duration:e.block.duration,processStyle:!0})]});if("toolGroup"===e.kind)return(0,r.jsx)("div",{className:"space-y-2",children:e.blocks.map((s,a)=>(0,r.jsxs)("div",{children:[e.leadBlocks[a]&&e.leadBlocks[a].length>0&&(0,r.jsx)("div",{className:"mb-2",children:(0,r.jsx)(rF,{blocks:e.leadBlocks[a],cwd:t,onOpenFile:o,sessionId:n,isStreaming:i})}),(0,r.jsx)(oF,{block:{type:"toolCall",toolCallId:s.toolCallId,toolName:s.toolName,input:s.input},result:s.result,duration:s.duration,processStyle:!0})]},s.id))});if("custom"===e.kind)return(0,r.jsx)(oR,{message:e.block.message,cwd:t,onOpenFile:o,isStreaming:i});let l="url"===(a=e.block.source).type?a.url:a.data?`data:${a.media_type??"image/png"};base64,${a.data}`:void 0;return l?(0,r.jsx)("img",{src:l,alt:s("desktop.processOutput"),className:"max-h-72 max-w-full rounded border border-border object-contain"}):null}function rF({blocks:e,cwd:t,onOpenFile:o,sessionId:n,isStreaming:s}){return(0,r.jsx)("div",{className:"space-y-2 pr-2",children:e.map(e=>"text"===e.type?(0,r.jsx)(t8,{cwd:t,onOpenFile:o,className:"!text-text-dim",isStreaming:s,children:e.text},e.id):(0,r.jsx)(oD,{block:{type:"thinking",thinking:e.thinking,deferred:e.deferred},sessionId:n,entryId:e.origin.sourceEntryId,blockIndex:e.origin.sourceBlockIndex??0,contentOnly:!0,cwd:t,onOpenFile:o,className:"!text-text-dim",isStreaming:s},e.id))})}function rW({blocks:e,isStreaming:t,defaultExpanded:o=!1,onAutoExpanded:s,cwd:i,onOpenFile:a,sessionId:l,tokenRate:d=null}){let c,{t:p}=(0,E.s)(),u=(0,n.useCallback)(e=>p(e),[p]),g=(0,n.useMemo)(()=>(function(e,t,o=!1){let r=[],n=[],s=()=>{0!==n.length&&(r.push({kind:"thinking",id:n.map(e=>e.id).join("+"),label:t("desktop.processStepThinking"),blocks:n}),n=[])};for(let o of e){if("thinking"===o.type||"text"===o.type){n.push(o);continue}if("toolCall"===o.type){let{displayLabel:e}=rz(o,t);r.push({kind:"tool",id:o.id,label:e,block:o,leadBlocks:n}),n=[];continue}s(),"custom"===o.type?r.push({kind:"custom",id:o.id,label:o.customType.replace(/[_-]+/g," ").replace(/\b\w/g,e=>e.toUpperCase()),block:o}):"image"===o.type&&r.push({kind:"image",id:o.id,label:t("desktop.processOutput"),block:o})}s();try{return function(e,t,o){if(e.length<2)return e;let r=[],n=0;for(;n<e.length;){let s,i=e[n];if("tool"!==i.kind||"error"===i.block.status){r.push(i),n++;continue}let a=rz(i.block,t).tone;if(!a){r.push(i),n++;continue}let l=n+1;for(;l<e.length&&"tool"===e[l].kind;){let o=e[l];if("error"===o.block.status||rz(o.block,t).tone!==a)break;l++}if(o&&l===e.length&&l>n+1&&l--,l-n<2){r.push(i),n++;continue}let d=e.slice(n,l),c=d.map(e=>rz(e.block,t)),p=c[0].iconName,u=c[0].typeLabel||"",g=d.map(e=>e.block),h=c.map(e=>e.displayLabel),x=c.map(e=>e.target||""),f=c.map(e=>{if(e.target)return rs(e.target);let t=e.displayLabel;return e.typeLabel&&t.startsWith(e.typeLabel+" ")?t.slice(e.typeLabel.length+1):t}),m=new Set,k=new Set,v=[],y=[];for(let e=0;e<f.length;e++){let t=f[e];m.has(t)||(m.add(t),v.push(t));let o=x[e];o&&!k.has(o)&&(k.add(o),y.push(o))}let b=d.length;s=2===b&&2===v.length?`${u} ${v[0]}, ${v[1]}`:1===v.length?1===b?`${u} ${v[0]}`:`${u} ${v[0]} \xd7${b}`:2===v.length?`${u} ${v[0]}, ${v[1]}`:`${u} ${v[0]} +${v.length-1}`,r.push({kind:"toolGroup",id:g.map(e=>e.id).join("+"),label:s,blocks:g,leadBlocks:d.map(e=>e.leadBlocks),iconName:p,tone:a,typeLabel:u,targetLabels:h,targets:y}),n=l}return r}(r,t,o)}catch(e){return console.error("[ProcessGroup] mergeConsecutiveToolSteps crashed:",e),r}})(e,u,t),[e,u,t]),[h,x]=(0,n.useState)(t||o),[f,m]=(0,n.useState)({}),{displayMode:k,setDisplayMode:v}={displayMode:(0,n.useSyncExternalStore)(o5,o6,o3),setDisplayMode:(0,n.useCallback)(e=>{window.localStorage.setItem(o1,e),window.dispatchEvent(new Event(o4))},[])},[y,b]=(0,n.useState)(0),[w,j]=(0,n.useState)(!1),[S,C]=(0,n.useState)(!1),T=(0,n.useRef)(null),z=(0,n.useRef)(!1),R=(0,n.useRef)(!1),I=(0,n.useRef)(!1),M=(0,n.useRef)(!1),P=(0,n.useRef)(0);(0,n.useEffect)(()=>{if(t){z.current=!0,x(!0);return}if(!z.current)return;M.current=!1,m({});let e=window.setTimeout(()=>x(!1),300);return z.current=!1,()=>window.clearTimeout(e)},[t]),(0,n.useEffect)(()=>{if(o&&!t&&!I.current&&g.length>0){let e=g[g.length-1];I.current=!0,m({[e.id]:!0}),window.requestAnimationFrame(()=>s?.())}},[o,t,s,g]),(0,n.useEffect)(()=>{if(0===g.length)return;let e=g[g.length-1];b(e=>R.current&&e<g.length?e:g.length-1),t&&m(t=>!0===t[e.id]&&1===Object.keys(t).length?t:{[e.id]:!0})},[t,g]);let D=(0,n.useCallback)(()=>{let e=T.current;e&&(j(t=>{let o=e.scrollTop>0;return t===o?t:o}),C(t=>{let o=e.scrollHeight-e.scrollTop-e.clientHeight>1;return t===o?t:o}))},[]),$=(0,n.useCallback)(()=>{if(Date.now()<P.current)return;let e=T.current;e&&(M.current=e.scrollHeight-e.scrollTop-e.clientHeight>4)},[]);if((0,n.useEffect)(()=>{let e=T.current;if(!e||!h)return;let t=new ResizeObserver(D);return e.addEventListener("scroll",D,{passive:!0}),t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),D(),()=>{e.removeEventListener("scroll",D),t.disconnect()}},[y,h,k,t,f,g.length,D]),(0,n.useEffect)(()=>{let e=T.current;if(e&&h)return e.addEventListener("scroll",$,{passive:!0}),()=>e.removeEventListener("scroll",$)},[h,k,$]),(0,n.useEffect)(()=>{t&&T.current&&(M.current||(P.current=Date.now()+100,T.current.scrollTop=T.current.scrollHeight,D()))},[e,t,D]),0===g.length)return null;let F=g.reduce((e,t)=>"tool"===t.kind?e+1:"toolGroup"===t.kind?e+t.blocks.length:e,0),W=g.reduce((e,t)=>"tool"===t.kind&&"error"===t.block.status?e+1:"toolGroup"===t.kind?e+t.blocks.filter(e=>"error"===e.status).length:e,0),N=e.filter(e=>"thinking"===e.type||"text"===e.type).length,A=g.filter(e=>"custom"===e.kind).length,L=1===g.length&&"thinking"===g[0].kind&&!t,O=1===g.length&&("tool"===g[0].kind||"toolGroup"===g[0].kind)&&!t;if(t)c=p("desktop.processWorking");else if(L){let e=function(e){let t;if("thinking"===e.kind){for(let o of e.blocks)"thinking"===o.type&&"number"==typeof o.duration&&(t=(t??0)+o.duration);return t}}(g[0]);c=void 0!==e?p("desktop.processThoughtDone",{duration:e}):p("desktop.processThoughtDoneNoDuration")}else if(O){let e=g[0];if("toolGroup"===e.kind){let t=e.blocks.reduce((e,t)=>e+(t.duration??0),0);c=t>0?`${e.label} ${t}s`:e.label}else{let t=e.block,o=rz(t,u),r=t.duration;c=void 0!==r?`${o.displayLabel} ${r}s`:o.displayLabel}}else{let e=[];if(F){let t=1===F?p("desktop.processToolCount",{count:F}):p("desktop.processToolsCount",{count:F});e.push(W>0?t+p("desktop.processFailedCount",{failed:W}):t)}N&&e.push(1===N?p("desktop.processThoughtCount",{count:N}):p("desktop.processThoughtsCount",{count:N})),A&&e.push(1===A?p("desktop.processCustomCount",{count:A}):p("desktop.processCustomsCount",{count:A})),c=e.length>0?p("desktop.processUsed",{summary:e.join(" \xb7 ")}):p("desktop.processCompleted")}return(0,r.jsxs)("div",{className:"group/process relative mb-3 min-w-0",children:[(0,r.jsxs)("div",{className:"group/summary-row flex items-center justify-between",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>x(e=>!e),className:"group/summary flex min-w-0 items-center gap-1.5 text-left text-sm leading-relaxed text-text-muted transition-colors hover:text-text","aria-expanded":h,children:[(0,r.jsx)("span",{className:"truncate",children:c}),t&&null!=d&&d>0&&(0,r.jsx)("span",{className:"shrink-0 text-xs tabular-nums text-text-dim",children:p("desktop.tokensPerSecond",{count:d>=10?String(Math.round(d)):d.toFixed(1)})}),(0,r.jsx)("span",{className:`opacity-0 transition-opacity group-hover/summary:opacity-60 ${h?"rotate-90":""}`,children:(0,r.jsx)(rR,{expanded:!1})})]}),!L&&(0,r.jsx)("button",{type:"button",onClick:()=>{v("timeline"===k?"tabs":"timeline"),x(!0)},className:"shrink-0 p-1 text-text-dim opacity-0 transition-colors hover:text-text group-hover/summary-row:opacity-100",title:"timeline"===k?p("desktop.processTabMode"):p("desktop.processTimelineMode"),children:(0,r.jsx)(rD,{mode:k})})]}),h&&(0,r.jsx)("div",{className:"overflow-hidden",children:L?(0,r.jsxs)("div",{className:"relative mt-2",children:[(0,r.jsx)("div",{ref:T,className:"max-h-[280px] overflow-y-auto pr-2",children:(0,r.jsx)(r$,{step:g[0],cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})}),w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"})]}):"timeline"===k?(0,r.jsxs)("div",{className:"relative mt-2",children:[w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"}),(0,r.jsx)("div",{ref:T,className:t?"max-h-[320px] overflow-y-auto":"",children:(0,r.jsxs)("div",{className:"relative ml-5 space-y-2",children:[(0,r.jsx)("div",{className:"absolute -left-3 -top-1.5 h-4 w-2 rounded-bl border-b border-l border-border"}),g.map((e,o)=>{let n=f[e.id]??!1,s="thinking"===e.kind?e.blocks.some(e=>"text"===e.type?e.text.trim().length>0:e.deferred||e.thinking.trim().length>0):"toolGroup"!==e.kind||e.blocks.length>0,d="tool"===e.kind&&"error"===e.block.status||"toolGroup"===e.kind&&e.blocks.some(e=>"error"===e.status),c="tool"===e.kind?rz(e.block,u):null,h="toolGroup"!==e.kind&&c?.target!==void 0&&c?.typeLabel!==void 0;return(0,r.jsxs)("div",{className:"group/step relative min-w-0",children:[o<g.length-1&&(0,r.jsx)("span",{className:"absolute bottom-[-9px] left-[7px] top-[22px] border-l border-border"}),(0,r.jsxs)("button",{type:"button",onClick:()=>s&&m(t=>({...t,[e.id]:!n})),className:`flex w-full min-w-0 items-center gap-1.5 text-left text-sm leading-relaxed transition-colors ${s?"cursor-pointer":"cursor-default"} ${d?"text-red-400 hover:text-red-300":"text-text-dim hover:text-text-muted"}`,children:[(0,r.jsx)("span",{className:"shrink-0",children:(0,r.jsx)(rM,{step:e,ts:u})}),"toolGroup"===e.kind&&e.targets.length>0?(0,r.jsx)(rE,{targets:e.targets,typeLabel:e.typeLabel,count:e.blocks.length,label:e.label}):h?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:c.typeLabel}),(0,r.jsx)(rP,{filePath:c.target})]}):(0,r.jsx)("span",{className:"truncate",title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,children:e.label}),"tool"===e.kind&&void 0!==e.block.duration&&(0,r.jsxs)("span",{className:"shrink-0 text-[11px] tabular-nums text-text-dim",children:[e.block.duration,"s"]}),d&&(0,r.jsx)("span",{className:"shrink-0 text-[11px] font-medium text-red-400",children:p("desktop.processFailedStep")}),s&&(0,r.jsx)("span",{className:`ml-0.5 shrink-0 opacity-0 transition-opacity group-hover/step:opacity-50 ${n?"rotate-90":""}`,children:(0,r.jsx)(rR,{expanded:!1})})]}),n&&s&&(0,r.jsx)("div",{className:"ml-5 mt-1.5 overflow-hidden",children:(0,r.jsx)(r$,{step:e,cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})})]},e.id)})]})})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:g.map((e,o)=>{let n="tool"===e.kind&&"error"===e.block.status||"toolGroup"===e.kind&&e.blocks.some(e=>"error"===e.status),s="tool"===e.kind?rz(e.block,u):null,i="toolGroup"!==e.kind&&s?.target!==void 0&&s?.typeLabel!==void 0,a=t&&o===g.length-1,l=y===o;return(0,r.jsxs)("button",{type:"button",onClick:()=>{o===g.length-1&&t?(R.current=!1,M.current=!1):R.current=!0,b(o)},"data-has-file-target":i?"true":void 0,title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,className:`process-tab flex items-center gap-1 font-mono text-xs transition-colors ${l?n?"process-tab-error":"process-tab-active":"text-text-dim hover:text-text"}${a?" process-tab-streaming":""}`,children:[(0,r.jsx)(rM,{step:e,ts:u}),"toolGroup"===e.kind&&e.targets.length>0?(0,r.jsx)(rE,{targets:e.targets,typeLabel:e.typeLabel,count:e.blocks.length,label:e.label}):i?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"shrink-0",children:s.typeLabel}),(0,r.jsx)(rP,{filePath:s.target})]}):(0,r.jsx)("span",{className:`truncate ${"toolGroup"===e.kind?"max-w-64":"max-w-52"}`,title:"toolGroup"===e.kind?e.targetLabels.join("\n"):void 0,children:e.label})]},e.id)})}),(0,r.jsxs)("div",{className:"relative mt-2",children:[(0,r.jsx)("div",{ref:T,className:"max-h-[280px] overflow-y-auto pr-2",children:g[y]&&(0,r.jsx)(r$,{step:g[y],cwd:i,onOpenFile:a,sessionId:l,ts:u,isStreaming:t})}),w&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-6 bg-gradient-to-b from-bg to-transparent"}),S&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-6 bg-gradient-to-t from-bg to-transparent"})]})]})})]})}let rN=new Map;function rA(e){return{value:e.value,images:e.images.map(e=>({...e}))}}function rL(e){let t=rN.get(e);return t?rA(t):null}function rO(e,t){t.value||0!==t.images.length?rN.set(e,rA(t)):rN.delete(e)}function rH(e){var t;if(!e||"object"!=typeof e||"image"!==e.type||"string"!=typeof e.data||"string"!=typeof e.mimeType||(t=e.mimeType,!/^image\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$/.test(t)))return!1;let o=function(e){if(!e||e.length%4!=0)return null;let t=e.endsWith("==")?2:+!!e.endsWith("="),o=e.length-t,r=null;for(let t=0;t<o;t+=1){var n;let o=(n=e.charCodeAt(t))>=65&&n<=90?n-65:n>=97&&n<=122?n-97+26:n>=48&&n<=57?n-48+52:43===n?62:47===n?63:null;if(null===o)return null;r=o}for(let t=o;t<e.length;t+=1)if("="!==e[t])return null;return 2===t&&r%16!=0||1===t&&r%4!=0?null:e.length/4*3-t}(e.data);return null!==o&&o<=0xa00000}function rB(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let o=/(?:^|\s)@([^\s"]*)$/.exec(e);return o?{start:e.length-(o[1].length+1),query:o[1],quoted:!1}:null}function rU(e){let t=0;for(let o=0;o<e.length;o++)"/"===e[o]&&t++;return t}function r_(e,t){if(!e)return!0;let o=0;for(let r=0;r<t.length&&o<e.length;r++)t[r]===e[o]&&o++;return o===e.length}function rq(e,t){let o=t?`${e}/`:e;return o.includes(" ")?`@"${o}" `:`@${o} `}let rV="(max-width: 640px)";function rK(e){if(!window.matchMedia)return()=>{};let t=window.matchMedia(rV);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)}function rJ(){return!!window.matchMedia&&window.matchMedia(rV).matches}function rG(){return!1}function rY(){return(0,n.useSyncExternalStore)(rK,rJ,rG)}var rZ=o(23084),rX=o(70312),rQ=o(37597),r0=o(49560),r1=o(21163),r2=o(4615),r4=o(25248),r6=o(58506),r5=o(41789),r3=o(87124),r8=o(65098),r7=o(93587);function r9(e,t,o){let s=({size:n=16,style:s})=>(0,r.jsxs)("svg",{fill:t.fill,fillRule:t.fillRule,height:n,style:{flex:"none",lineHeight:1,...s},viewBox:"0 0 24 24",width:n,xmlns:"http://www.w3.org/2000/svg",children:[(0,r.jsx)("title",{children:e}),o]});return s.displayName=`${e}Icon`,(0,n.memo)(s)}let ne=r9("Anthropic",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M13.827 3.52h3.603L24 20h-3.603l-6.57-16.48zm-7.258 0h3.767L16.906 20h-3.674l-1.343-3.461H5.017l-1.344 3.46H0L6.57 3.522zm4.132 9.959L8.453 7.687 6.205 13.48H10.7z"})})),nt=r9("OpenAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z"})})),no=r9("Google",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M23 12.245c0-.905-.075-1.565-.236-2.25h-10.54v4.083h6.186c-.124 1.014-.797 2.542-2.294 3.569l-.021.136 3.332 2.53.23.022C21.779 18.417 23 15.593 23 12.245z",fill:"#4285F4"}),(0,r.jsx)("path",{d:"M12.225 23c3.03 0 5.574-.978 7.433-2.665l-3.542-2.688c-.948.648-2.22 1.1-3.891 1.1a6.745 6.745 0 01-6.386-4.572l-.132.011-3.465 2.628-.045.124C4.043 20.531 7.835 23 12.225 23z",fill:"#34A853"}),(0,r.jsx)("path",{d:"M5.84 14.175A6.65 6.65 0 015.463 12c0-.758.138-1.491.361-2.175l-.006-.147-3.508-2.67-.115.054A10.831 10.831 0 001 12c0 1.772.436 3.447 1.197 4.938l3.642-2.763z",fill:"#FBBC05"}),(0,r.jsx)("path",{d:"M12.225 5.253c2.108 0 3.529.892 4.34 1.638l3.167-3.031C17.787 2.088 15.255 1 12.225 1 7.834 1 4.043 3.469 2.197 7.062l3.63 2.763a6.77 6.77 0 016.398-4.572z",fill:"#EB4335"})]})),nr=r9("DeepSeek",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M23.748 4.482c-.254-.124-.364.113-.512.234-.051.039-.094.09-.137.136-.372.397-.806.657-1.373.626-.829-.046-1.537.214-2.163.848-.133-.782-.575-1.248-1.247-1.548-.352-.156-.708-.311-.955-.65-.172-.241-.219-.51-.305-.774-.055-.16-.11-.323-.293-.35-.2-.031-.278.136-.356.276-.313.572-.434 1.202-.422 1.84.027 1.436.633 2.58 1.838 3.393.137.093.172.187.129.323-.082.28-.18.552-.266.833-.055.179-.137.217-.329.14a5.526 5.526 0 01-1.736-1.18c-.857-.828-1.631-1.742-2.597-2.458a11.365 11.365 0 00-.689-.471c-.985-.957.13-1.743.388-1.836.27-.098.093-.432-.779-.428-.872.004-1.67.295-2.687.684a3.055 3.055 0 01-.465.137 9.597 9.597 0 00-2.883-.102c-1.885.21-3.39 1.102-4.497 2.623C.082 8.606-.231 10.684.152 12.85c.403 2.284 1.569 4.175 3.36 5.653 1.858 1.533 3.997 2.284 6.438 2.14 1.482-.085 3.133-.284 4.994-1.86.47.234.962.327 1.78.397.63.059 1.236-.03 1.705-.128.735-.156.684-.837.419-.961-2.155-1.004-1.682-.595-2.113-.926 1.096-1.296 2.746-2.642 3.392-7.003.05-.347.007-.565 0-.845-.004-.17.035-.237.23-.256a4.173 4.173 0 001.545-.475c1.396-.763 1.96-2.015 2.093-3.517.02-.23-.004-.467-.247-.588zM11.581 18c-2.089-1.642-3.102-2.183-3.52-2.16-.392.024-.321.471-.235.763.09.288.207.486.371.739.114.167.192.416-.113.603-.673.416-1.842-.14-1.897-.167-1.361-.802-2.5-1.86-3.301-3.307-.774-1.393-1.224-2.887-1.298-4.482-.02-.386.093-.522.477-.592a4.696 4.696 0 011.529-.039c2.132.312 3.946 1.265 5.468 2.774.868.86 1.525 1.887 2.202 2.891.72 1.066 1.494 2.082 2.48 2.914.348.292.625.514.891.677-.802.09-2.14.11-3.054-.614zm1-6.44a.306.306 0 01.415-.287.302.302 0 01.2.288.306.306 0 01-.31.307.303.303 0 01-.304-.308zm3.11 1.596c-.2.081-.399.151-.59.16a1.245 1.245 0 01-.798-.254c-.274-.23-.47-.358-.552-.758a1.73 1.73 0 01.016-.588c.07-.327-.008-.537-.239-.727-.187-.156-.426-.199-.688-.199a.559.559 0 01-.254-.078c-.11-.054-.2-.19-.114-.358.028-.054.16-.186.192-.21.356-.202.767-.136 1.146.016.352.144.618.408 1.001.782.391.451.462.576.685.914.176.265.336.537.445.848.067.195-.019.354-.25.452z",fill:"#4D6BFE"})})),nn=r9("Groq",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12.036 2c-3.853-.035-7 3-7.036 6.781-.035 3.782 3.055 6.872 6.908 6.907h2.42v-2.566h-2.292c-2.407.028-4.38-1.866-4.408-4.23-.029-2.362 1.901-4.298 4.308-4.326h.1c2.407 0 4.358 1.915 4.365 4.278v6.305c0 2.342-1.944 4.25-4.323 4.279a4.375 4.375 0 01-3.033-1.252l-1.851 1.818A7 7 0 0012.029 22h.092c3.803-.056 6.858-3.083 6.879-6.816v-6.5C18.907 4.963 15.817 2 12.036 2z"})})),ns=r9("Mistral",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M3.428 3.4h3.429v3.428H3.428V3.4zm13.714 0h3.43v3.428h-3.43V3.4z",fill:"gold"}),(0,r.jsx)("path",{d:"M3.428 6.828h6.857v3.429H3.429V6.828zm10.286 0h6.857v3.429h-6.857V6.828z",fill:"#FFAF00"}),(0,r.jsx)("path",{d:"M3.428 10.258h17.144v3.428H3.428v-3.428z",fill:"#FF8205"}),(0,r.jsx)("path",{d:"M3.428 13.686h3.429v3.428H3.428v-3.428zm6.858 0h3.429v3.428h-3.429v-3.428zm6.856 0h3.43v3.428h-3.43v-3.428z",fill:"#FA500F"}),(0,r.jsx)("path",{d:"M0 17.114h10.286v3.429H0v-3.429zm13.714 0H24v3.429H13.714v-3.429z",fill:"#E10500"})]})),ni=r9("Moonshot",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M1.052 16.916l9.539 2.552a21.007 21.007 0 00.06 2.033l5.956 1.593a11.997 11.997 0 01-5.586.865l-.18-.016-.044-.004-.084-.009-.094-.01a11.605 11.605 0 01-.157-.02l-.107-.014-.11-.016a11.962 11.962 0 01-.32-.051l-.042-.008-.075-.013-.107-.02-.07-.015-.093-.019-.075-.016-.095-.02-.097-.023-.094-.022-.068-.017-.088-.022-.09-.024-.095-.025-.082-.023-.109-.03-.062-.02-.084-.025-.093-.028-.105-.034-.058-.019-.08-.026-.09-.031-.066-.024a6.293 6.293 0 01-.044-.015l-.068-.025-.101-.037-.057-.022-.08-.03-.087-.035-.088-.035-.079-.032-.095-.04-.063-.028-.063-.027a5.655 5.655 0 01-.041-.018l-.066-.03-.103-.047-.052-.024-.096-.046-.062-.03-.084-.04-.086-.044-.093-.047-.052-.027-.103-.055-.057-.03-.058-.032a6.49 6.49 0 01-.046-.026l-.094-.053-.06-.034-.051-.03-.072-.041-.082-.05-.093-.056-.052-.032-.084-.053-.061-.039-.079-.05-.07-.047-.053-.035a7.785 7.785 0 01-.054-.036l-.044-.03-.044-.03a6.066 6.066 0 01-.04-.028l-.057-.04-.076-.054-.069-.05-.074-.054-.056-.042-.076-.057-.076-.059-.086-.067-.045-.035-.064-.052-.074-.06-.089-.073-.046-.039-.046-.039a7.516 7.516 0 01-.043-.037l-.045-.04-.061-.053-.07-.062-.068-.06-.062-.058-.067-.062-.053-.05-.088-.084a13.28 13.28 0 01-.099-.097l-.029-.028-.041-.042-.069-.07-.05-.051-.05-.053a6.457 6.457 0 01-.168-.179l-.08-.088-.062-.07-.071-.08-.042-.049-.053-.062-.058-.068-.046-.056a7.175 7.175 0 01-.027-.033l-.045-.055-.066-.082-.041-.052-.05-.064-.02-.025a11.99 11.99 0 01-1.44-2.402zm-1.02-5.794l11.353 3.037a20.468 20.468 0 00-.469 2.011l10.817 2.894a12.076 12.076 0 01-1.845 2.005L.657 15.923l-.016-.046-.035-.104a11.965 11.965 0 01-.05-.153l-.007-.023a11.896 11.896 0 01-.207-.741l-.03-.126-.018-.08-.021-.097-.018-.081-.018-.09-.017-.084-.018-.094c-.026-.141-.05-.283-.071-.426l-.017-.118-.011-.083-.013-.102a12.01 12.01 0 01-.019-.161l-.005-.047a12.12 12.12 0 01-.034-2.145zm1.593-5.15l11.948 3.196c-.368.605-.705 1.231-1.01 1.875l11.295 3.022c-.142.82-.368 1.612-.668 2.365l-11.55-3.09L.124 10.26l.015-.1.008-.049.01-.067.015-.087.018-.098c.026-.148.056-.295.088-.442l.028-.124.02-.085.024-.097c.022-.09.045-.18.07-.268l.028-.102.023-.083.03-.1.025-.082.03-.096.026-.082.031-.095a11.896 11.896 0 011.01-2.232zm4.442-4.4L17.352 4.59a20.77 20.77 0 00-1.688 1.721l7.823 2.093c.267.852.442 1.744.513 2.665L2.106 5.213l.045-.065.027-.04.04-.055.046-.065.055-.076.054-.072.064-.086.05-.065.057-.073.055-.07.06-.074.055-.069.065-.077.054-.066.066-.077.053-.06.072-.082.053-.06.067-.074.054-.058.073-.078.058-.06.063-.067.168-.17.1-.098.059-.056.076-.071a12.084 12.084 0 012.272-1.677zM12.017 0h.097l.082.001.069.001.054.002.068.002.046.001.076.003.047.002.06.003.054.002.087.005.105.007.144.011.088.007.044.004.077.008.082.008.047.005.102.012.05.006.108.014.081.01.042.006.065.01.207.032.07.012.065.011.14.026.092.018.11.022.046.01.075.016.041.01L14.7.3l.042.01.065.015.049.012.071.017.096.024.112.03.113.03.113.032.05.015.07.02.078.024.073.023.05.016.05.016.076.025.099.033.102.036.048.017.064.023.093.034.11.041.116.045.1.04.047.02.06.024.041.018.063.026.04.018.057.025.11.048.1.046.074.035.075.036.06.028.092.046.091.045.102.052.053.028.049.026.046.024.06.033.041.022.052.029.088.05.106.06.087.051.057.034.053.032.096.059.088.055.098.062.036.024.064.041.084.056.04.027.062.042.062.043.023.017c.054.037.108.075.161.114l.083.06.065.048.056.043.086.065.082.064.04.03.05.041.086.069.079.065.085.071c.712.6 1.353 1.283 1.909 2.031L7.222.994l.062-.027.065-.028.081-.034.086-.035c.113-.045.227-.09.341-.131l.096-.035.093-.033.084-.03.096-.031c.087-.03.176-.058.264-.085l.091-.027.086-.025.102-.03.085-.023.1-.026L9.04.37l.09-.023.091-.022.095-.022.09-.02.098-.021.091-.02.095-.018.092-.018.1-.018.091-.016.098-.017.092-.014.097-.015.092-.013.102-.013.091-.012.105-.012.09-.01.105-.01c.093-.01.186-.018.28-.024l.106-.008.09-.005.11-.006.093-.004.1-.004.097-.002.099-.002.197-.002z"})})),na=r9("Minimax",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("defs",{children:(0,r.jsxs)("linearGradient",{id:"pi-minimax-lobe-icons-minimax-_R_0_",x1:"0%",x2:"100.182%",y1:"50.057%",y2:"50.057%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#E2167E"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#FE603C"})]})}),(0,r.jsx)("path",{d:"M16.278 2c1.156 0 2.093.927 2.093 2.07v12.501a.74.74 0 00.744.709.74.74 0 00.743-.709V9.099a2.06 2.06 0 012.071-2.049A2.06 2.06 0 0124 9.1v6.561a.649.649 0 01-.652.645.649.649 0 01-.653-.645V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v7.472a2.037 2.037 0 01-2.048 2.026 2.037 2.037 0 01-2.048-2.026v-12.5a.785.785 0 00-.788-.753.785.785 0 00-.789.752l-.001 15.904A2.037 2.037 0 0113.441 22a2.037 2.037 0 01-2.048-2.026V18.04c0-.356.292-.645.652-.645.36 0 .652.289.652.645v1.934c0 .263.142.506.372.638.23.131.514.131.744 0a.734.734 0 00.372-.638V4.07c0-1.143.937-2.07 2.093-2.07zm-5.674 0c1.156 0 2.093.927 2.093 2.07v11.523a.648.648 0 01-.652.645.648.648 0 01-.652-.645V4.07a.785.785 0 00-.789-.78.785.785 0 00-.789.78v14.013a2.06 2.06 0 01-2.07 2.048 2.06 2.06 0 01-2.071-2.048V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v3.8a2.06 2.06 0 01-2.071 2.049A2.06 2.06 0 010 12.9v-1.378c0-.357.292-.646.652-.646.36 0 .653.29.653.646V12.9c0 .418.343.757.766.757s.766-.339.766-.757V9.099a2.06 2.06 0 012.07-2.048 2.06 2.06 0 012.071 2.048v8.984c0 .419.343.758.767.758.423 0 .766-.339.766-.758V4.07c0-1.143.937-2.07 2.093-2.07z",fill:"url(#pi-minimax-lobe-icons-minimax-_R_0_)","fill-rule":"nonzero"})]})),nl=r9("Fireworks",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M14.8 5l-2.801 6.795L9.195 5H7.397l3.072 7.428a1.64 1.64 0 003.038.002L16.598 5H14.8zm1.196 10.352l5.124-5.244-.699-1.669-5.596 5.739a1.664 1.664 0 00-.343 1.807 1.642 1.642 0 001.516 1.012L16 17l8-.02-.699-1.669-7.303.041h-.002zM2.88 10.104l.699-1.669 5.596 5.739c.468.479.603 1.189.343 1.807a1.643 1.643 0 01-1.516 1.012l-8-.018-.002.002.699-1.669 7.303.042-5.122-5.246z",fill:"#5019C5","fill-rule":"evenodd"})})),nd=r9("HuggingFace",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M2.25 11.535c0-3.407 1.847-6.554 4.844-8.258a9.822 9.822 0 019.687 0c2.997 1.704 4.844 4.851 4.844 8.258 0 5.266-4.337 9.535-9.687 9.535S2.25 16.8 2.25 11.535z",fill:"#FF9D0B"}),(0,r.jsx)("path",{d:"M11.938 20.086c4.797 0 8.687-3.829 8.687-8.551 0-4.722-3.89-8.55-8.687-8.55-4.798 0-8.688 3.828-8.688 8.55 0 4.722 3.89 8.55 8.688 8.55z",fill:"#FFD21E"}),(0,r.jsx)("path",{d:"M11.875 15.113c2.457 0 3.25-2.156 3.25-3.263 0-.576-.393-.394-1.023-.089-.582.283-1.365.675-2.224.675-1.798 0-3.25-1.693-3.25-.586 0 1.107.79 3.263 3.25 3.263h-.003z",fill:"#FF323D"}),(0,r.jsx)("path",{d:"M14.76 9.21c.32.108.445.753.767.585.447-.233.707-.708.659-1.204a1.235 1.235 0 00-.879-1.059 1.262 1.262 0 00-1.33.394c-.322.384-.377.92-.14 1.36.153.283.638-.177.925-.079l-.002.003zm-5.887 0c-.32.108-.448.753-.768.585a1.226 1.226 0 01-.658-1.204c.048-.495.395-.913.878-1.059a1.262 1.262 0 011.33.394c.322.384.377.92.14 1.36-.152.283-.64-.177-.925-.079l.003.003zm1.12 5.34a2.166 2.166 0 011.325-1.106c.07-.02.144.06.219.171l.192.306c.069.1.139.175.209.175.074 0 .15-.074.223-.172l.205-.302c.08-.11.157-.188.234-.165.537.168.986.536 1.25 1.026.932-.724 1.275-1.905 1.275-2.633 0-.508-.306-.426-.81-.19l-.616.296c-.52.24-1.148.48-1.824.48-.676 0-1.302-.24-1.823-.48l-.589-.283c-.52-.248-.838-.342-.838.177 0 .703.32 1.831 1.187 2.56l.18.14z",fill:"#3A3B45"}),(0,r.jsx)("path",{d:"M17.812 10.366a.806.806 0 00.813-.8c0-.441-.364-.8-.813-.8a.806.806 0 00-.812.8c0 .442.364.8.812.8zm-11.624 0a.806.806 0 00.812-.8c0-.441-.364-.8-.812-.8a.806.806 0 00-.813.8c0 .442.364.8.813.8zM4.515 13.073c-.405 0-.765.162-1.017.46a1.455 1.455 0 00-.333.925 1.801 1.801 0 00-.485-.074c-.387 0-.737.146-.985.409a1.41 1.41 0 00-.2 1.722 1.302 1.302 0 00-.447.694c-.06.222-.12.69.2 1.166a1.267 1.267 0 00-.093 1.236c.238.533.81.958 1.89 1.405l.24.096c.768.3 1.473.492 1.478.494.89.243 1.808.375 2.732.394 1.465 0 2.513-.443 3.115-1.314.93-1.342.842-2.575-.274-3.763l-.151-.154c-.692-.684-1.155-1.69-1.25-1.912-.195-.655-.71-1.383-1.562-1.383-.46.007-.889.233-1.15.605-.25-.31-.495-.553-.715-.694a1.87 1.87 0 00-.993-.312zm14.97 0c.405 0 .767.162 1.017.46.216.262.333.588.333.925.158-.047.322-.071.487-.074.388 0 .738.146.985.409a1.41 1.41 0 01.2 1.722c.22.178.377.422.445.694.06.222.12.69-.2 1.166.244.37.279.836.093 1.236-.238.533-.81.958-1.889 1.405l-.239.096c-.77.3-1.475.492-1.48.494-.89.243-1.808.375-2.732.394-1.465 0-2.513-.443-3.115-1.314-.93-1.342-.842-2.575.274-3.763l.151-.154c.695-.684 1.157-1.69 1.252-1.912.195-.655.708-1.383 1.56-1.383.46.007.889.233 1.15.605.25-.31.495-.553.718-.694.244-.162.523-.265.814-.3l.176-.012z",fill:"#FF9D0B"}),(0,r.jsx)("path",{d:"M9.785 20.132c.688-.994.638-1.74-.305-2.667-.945-.928-1.495-2.288-1.495-2.288s-.205-.788-.672-.714c-.468.074-.81 1.25.17 1.971.977.721-.195 1.21-.573.534-.375-.677-1.405-2.416-1.94-2.751-.532-.332-.907-.148-.782.541.125.687 2.357 2.35 2.14 2.707-.218.362-.983-.42-.983-.42S2.953 14.9 2.43 15.46c-.52.558.398 1.026 1.7 1.803 1.308.778 1.41.985 1.225 1.28-.187.295-3.07-2.1-3.34-1.083-.27 1.011 2.943 1.304 2.745 2.006-.2.7-2.265-1.324-2.685-.537-.425.79 2.913 1.718 2.94 1.725 1.075.276 3.813.859 4.77-.522zm4.432 0c-.687-.994-.64-1.74.305-2.667.943-.928 1.493-2.288 1.493-2.288s.205-.788.675-.714c.465.074.807 1.25-.17 1.971-.98.721.195 1.21.57.534.377-.677 1.407-2.416 1.94-2.751.532-.332.91-.148.782.541-.125.687-2.355 2.35-2.137 2.707.215.362.98-.42.98-.42S21.05 14.9 21.57 15.46c.52.558-.395 1.026-1.7 1.803-1.308.778-1.408.985-1.225 1.28.187.295 3.07-2.1 3.34-1.083.27 1.011-2.94 1.304-2.743 2.006.2.7 2.263-1.324 2.685-.537.423.79-2.912 1.718-2.94 1.725-1.077.276-3.815.859-4.77-.522z",fill:"#FFD21E"})]})),nc=r9("Cerebras",{fill:"currentColor"},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M14.121 2.701a9.299 9.299 0 000 18.598V22.7c-5.91 0-10.7-4.791-10.7-10.701S8.21 1.299 14.12 1.299V2.7zm4.752 3.677A7.353 7.353 0 109.42 17.643l-.901 1.074a8.754 8.754 0 01-1.08-12.334 8.755 8.755 0 0112.335-1.08l-.901 1.075zm-2.255.844a5.407 5.407 0 00-5.048 9.563l-.656 1.24a6.81 6.81 0 016.358-12.043l-.654 1.24zM14.12 8.539a3.46 3.46 0 100 6.922v1.402a4.863 4.863 0 010-9.726v1.402z",fill:"#F15A29","fill-rule":"evenodd"}),(0,r.jsx)("path",{d:"M15.407 10.836a2.24 2.24 0 00-.51-.409 1.084 1.084 0 00-.544-.152c-.255 0-.483.047-.684.14a1.58 1.58 0 00-.84.912c-.074.203-.11.416-.11.631 0 .218.036.43.11.631a1.594 1.594 0 00.84.913c.2.093.43.14.684.14.216 0 .417-.046.602-.135.188-.09.35-.225.475-.392l.928 1.006c-.14.14-.3.261-.482.363a3.367 3.367 0 01-1.083.38c-.17.026-.317.04-.44.04a3.315 3.315 0 01-1.182-.21 2.825 2.825 0 01-.961-.597 2.816 2.816 0 01-.644-.929 2.987 2.987 0 01-.238-1.21c0-.444.08-.847.238-1.21.15-.35.368-.666.643-.929.278-.261.605-.464.962-.596a3.315 3.315 0 011.182-.21c.355 0 .712.068 1.072.204.361.138.685.36.944.649l-.962.97z"})]})),np=r9("OpenRouter",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M18.654 3.87a5.087 5.087 0 110 10.174L23.7 19.09c.64.641.187 1.737-.72 1.737H8.48a8.479 8.479 0 010-16.958h10.175zM8.479 7.26a5.087 5.087 0 100 10.176 5.087 5.087 0 000-10.175z"})})),nu=r9("XAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z"})})),ng=r9("Cloudflare",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M16.493 17.4c.135-.52.08-.983-.161-1.338-.215-.328-.592-.519-1.05-.519l-8.663-.109a.148.148 0 01-.135-.082c-.027-.054-.027-.109-.027-.163.027-.082.108-.164.189-.164l8.744-.11c1.05-.054 2.153-.9 2.556-1.937l.511-1.31c.027-.055.027-.11.027-.164C17.92 8.91 15.66 7 12.942 7c-2.503 0-4.628 1.638-5.381 3.903a2.432 2.432 0 00-1.803-.491c-1.21.109-2.153 1.092-2.287 2.32-.027.328 0 .628.054.9C1.56 13.688 0 15.326 0 17.319c0 .19.027.355.027.545 0 .082.08.137.161.137h15.983c.08 0 .188-.055.215-.164l.107-.437",fill:"#F38020"}),(0,r.jsx)("path",{d:"M19.238 11.75h-.242c-.054 0-.108.054-.135.109l-.35 1.2c-.134.52-.08.983.162 1.338.215.328.592.518 1.05.518l1.855.11c.054 0 .108.027.135.082.027.054.027.109.027.163-.027.082-.108.164-.188.164l-1.91.11c-1.05.054-2.153.9-2.557 1.937l-.134.355c-.027.055.026.137.107.137h6.592c.081 0 .162-.055.162-.137.107-.41.188-.846.188-1.31-.027-2.62-2.153-4.777-4.762-4.777",fill:"#FCAD32"})]})),nh=r9("Vercel",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12 0l12 20.785H0L12 0z"})})),nx=r9("GithubCopilot",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M19.245 5.364c1.322 1.36 1.877 3.216 2.11 5.817.622 0 1.2.135 1.592.654l.73.964c.21.278.323.61.323.955v2.62c0 .339-.173.669-.453.868C20.239 19.602 16.157 21.5 12 21.5c-4.6 0-9.205-2.583-11.547-4.258-.28-.2-.452-.53-.453-.868v-2.62c0-.345.113-.679.321-.956l.73-.963c.392-.517.974-.654 1.593-.654l.029-.297c.25-2.446.81-4.213 2.082-5.52 2.461-2.54 5.71-2.851 7.146-2.864h.198c1.436.013 4.685.323 7.146 2.864zm-7.244 4.328c-.284 0-.613.016-.962.05-.123.447-.305.85-.57 1.108-1.05 1.023-2.316 1.18-2.994 1.18-.638 0-1.306-.13-1.851-.464-.516.165-1.012.403-1.044.996a65.882 65.882 0 00-.063 2.884l-.002.48c-.002.563-.005 1.126-.013 1.69.002.326.204.63.51.765 2.482 1.102 4.83 1.657 6.99 1.657 2.156 0 4.504-.555 6.985-1.657a.854.854 0 00.51-.766c.03-1.682.006-3.372-.076-5.053-.031-.596-.528-.83-1.046-.996-.546.333-1.212.464-1.85.464-.677 0-1.942-.157-2.993-1.18-.266-.258-.447-.661-.57-1.108-.32-.032-.64-.049-.96-.05zm-2.525 4.013c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zm5 0c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zM7.635 5.087c-1.05.102-1.935.438-2.385.906-.975 1.037-.765 3.668-.21 4.224.405.394 1.17.657 1.995.657h.09c.649-.013 1.785-.176 2.73-1.11.435-.41.705-1.433.675-2.47-.03-.834-.27-1.52-.63-1.813-.39-.336-1.275-.482-2.265-.394zm6.465.394c-.36.292-.6.98-.63 1.813-.03 1.037.24 2.06.675 2.47.968.957 2.136 1.104 2.776 1.11h.044c.825 0 1.59-.263 1.995-.657.555-.556.765-3.187-.21-4.224-.45-.468-1.335-.804-2.385-.906-.99-.088-1.875.058-2.265.394zM12 7.615c-.24 0-.525.015-.84.044.03.16.045.336.06.526l-.001.159a2.94 2.94 0 01-.014.25c.225-.022.425-.027.612-.028h.366c.187 0 .387.006.612.028-.015-.146-.015-.277-.015-.409.015-.19.03-.365.06-.526a9.29 9.29 0 00-.84-.044z"})})),nf=r9("Aws",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M6.763 11.212c0 .296.032.535.088.71.064.176.144.368.256.576.04.063.056.127.056.183 0 .08-.048.16-.152.24l-.503.335a.383.383 0 01-.208.072c-.08 0-.16-.04-.239-.112a2.47 2.47 0 01-.287-.375 6.18 6.18 0 01-.248-.471c-.622.734-1.405 1.101-2.347 1.101-.67 0-1.205-.191-1.596-.574-.39-.384-.59-.894-.59-1.533 0-.678.24-1.23.726-1.644.487-.415 1.133-.623 1.955-.623.272 0 .551.024.846.064.296.04.6.104.918.176v-.583c0-.607-.127-1.03-.375-1.277-.255-.248-.686-.367-1.3-.367-.28 0-.568.031-.863.103-.295.072-.583.16-.862.272a2.4 2.4 0 01-.28.104.488.488 0 01-.127.023c-.112 0-.168-.08-.168-.247v-.391c0-.128.016-.224.056-.28a.597.597 0 01.224-.167 4.577 4.577 0 011.005-.36 4.84 4.84 0 011.246-.151c.95 0 1.644.216 2.091.647.44.43.662 1.085.662 1.963v2.586h.016zm-3.24 1.214c.263 0 .534-.048.822-.144a1.78 1.78 0 00.758-.51 1.27 1.27 0 00.272-.512c.047-.191.08-.423.08-.694v-.335a6.66 6.66 0 00-.735-.136 6.02 6.02 0 00-.75-.048c-.535 0-.926.104-1.19.32-.263.215-.39.518-.39.917 0 .375.095.655.295.846.191.2.47.296.838.296zm6.41.862c-.144 0-.24-.024-.304-.08-.064-.048-.12-.16-.168-.311L7.586 6.726a1.398 1.398 0 01-.072-.32c0-.128.064-.2.191-.2h.783c.151 0 .255.025.31.08.065.048.113.16.16.312l1.342 5.284 1.245-5.284c.04-.16.088-.264.151-.312a.549.549 0 01.32-.08h.638c.152 0 .256.025.32.08.063.048.12.16.151.312l1.261 5.348 1.381-5.348c.048-.16.104-.264.16-.312a.52.52 0 01.311-.08h.743c.127 0 .2.065.2.2 0 .04-.009.08-.017.128a1.137 1.137 0 01-.056.2l-1.923 6.17c-.048.16-.104.263-.168.311a.51.51 0 01-.303.08h-.687c-.15 0-.255-.024-.32-.08-.063-.056-.119-.16-.15-.32L12.32 7.747l-1.23 5.14c-.04.16-.087.264-.15.32-.065.056-.177.08-.32.08l-.686.001zm10.256.215c-.415 0-.83-.048-1.229-.143-.399-.096-.71-.2-.918-.32-.128-.071-.215-.151-.247-.223a.563.563 0 01-.048-.224v-.407c0-.167.064-.247.183-.247.048 0 .096.008.144.024.048.016.12.048.2.08.271.12.566.215.878.279.32.064.63.096.95.096.502 0 .894-.088 1.165-.264a.86.86 0 00.415-.758.777.777 0 00-.215-.559c-.144-.151-.416-.287-.807-.415l-1.157-.36c-.583-.183-1.014-.454-1.277-.813a1.902 1.902 0 01-.4-1.158c0-.335.073-.63.216-.886.144-.255.335-.479.575-.654.24-.184.51-.32.83-.415.32-.096.655-.136 1.006-.136.175 0 .36.008.535.032.183.024.35.056.518.088.16.04.312.08.455.127.144.048.256.096.336.144a.69.69 0 01.24.2.43.43 0 01.071.263v.375c0 .168-.064.256-.184.256a.83.83 0 01-.303-.096 3.652 3.652 0 00-1.532-.311c-.455 0-.815.071-1.062.223-.248.152-.375.383-.375.71 0 .224.08.416.24.567.16.152.454.304.877.44l1.134.358c.574.184.99.44 1.237.767.247.327.367.702.367 1.117 0 .343-.072.655-.207.926a2.157 2.157 0 01-.583.703c-.248.2-.543.343-.886.447-.36.111-.734.167-1.142.167z"}),(0,r.jsx)("path",{d:"M.378 15.475c3.384 1.963 7.56 3.153 11.877 3.153 2.914 0 6.114-.607 9.06-1.852.44-.2.814.287.383.607-2.626 1.94-6.442 2.969-9.722 2.969-4.598 0-8.74-1.7-11.87-4.526-.247-.223-.024-.527.272-.351zm23.531-.2c.287.36-.08 2.826-1.485 4.007-.215.184-.423.088-.327-.151l.175-.439c.343-.88.802-2.198.52-2.555-.336-.43-2.22-.207-3.074-.103-.255.032-.295-.192-.063-.36 1.5-1.053 3.967-.75 4.254-.399z",fill:"#F90"})]})),nm=r9("Azure",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M7.242 1.613A1.11 1.11 0 018.295.857h6.977L8.03 22.316a1.11 1.11 0 01-1.052.755h-5.43a1.11 1.11 0 01-1.053-1.466L7.242 1.613z",fill:"url(#pi-azure-lobe-icons-azure-0-_R_0_)"}),(0,r.jsx)("path",{d:"M18.397 15.296H7.4a.51.51 0 00-.347.882l7.066 6.595c.206.192.477.298.758.298h6.226l-2.706-7.775z",fill:"#0078D4"}),(0,r.jsx)("path",{d:"M15.272.857H7.497L0 23.071h7.775l1.596-4.73 5.068 4.73h6.665l-2.707-7.775h-7.998L15.272.857z",fill:"url(#pi-azure-lobe-icons-azure-1-_R_0_)"}),(0,r.jsx)("path",{d:"M17.193 1.613a1.11 1.11 0 00-1.052-.756h-7.81.035c.477 0 .9.304 1.052.756l6.748 19.992a1.11 1.11 0 01-1.052 1.466h-.12 7.895a1.11 1.11 0 001.052-1.466L17.193 1.613z",fill:"url(#pi-azure-lobe-icons-azure-2-_R_0_)"}),(0,r.jsxs)("defs",{children:[(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-0-_R_0_",x1:"8.247",x2:"1.002",y1:"1.626",y2:"23.03",children:[(0,r.jsx)("stop",{"stop-color":"#114A8B"}),(0,r.jsx)("stop",{offset:"1","stop-color":"#0669BC"})]}),(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-1-_R_0_",x1:"14.042",x2:"12.324",y1:"15.302",y2:"15.888",children:[(0,r.jsx)("stop",{"stop-opacity":".3"}),(0,r.jsx)("stop",{offset:".071","stop-opacity":".2"}),(0,r.jsx)("stop",{offset:".321","stop-opacity":".1"}),(0,r.jsx)("stop",{offset:".623","stop-opacity":".05"}),(0,r.jsx)("stop",{offset:"1","stop-opacity":"0"})]}),(0,r.jsxs)("linearGradient",{gradientUnits:"userSpaceOnUse",id:"pi-azure-lobe-icons-azure-2-_R_0_",x1:"12.841",x2:"20.793",y1:"1.626",y2:"22.814",children:[(0,r.jsx)("stop",{"stop-color":"#3CCBF4"}),(0,r.jsx)("stop",{offset:"1","stop-color":"#2892DF"})]})]})]})),nk=r9("Kimi",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M21.846 0a1.923 1.923 0 110 3.846H20.15a.226.226 0 01-.227-.226V1.923C19.923.861 20.784 0 21.846 0z",fill:"#1783FF"}),(0,r.jsx)("path",{d:"M11.065 11.199l7.257-7.2c.137-.136.06-.41-.116-.41H14.3a.164.164 0 00-.117.051l-7.82 7.756c-.122.12-.302.013-.302-.179V3.82c0-.127-.083-.23-.185-.23H3.186c-.103 0-.186.103-.186.23V19.77c0 .128.083.23.186.23h2.69c.103 0 .186-.102.186-.23v-3.25c0-.069.025-.135.069-.178l2.424-2.406a.158.158 0 01.205-.023l6.484 4.772a7.677 7.677 0 003.453 1.283c.108.012.2-.095.2-.23v-3.06c0-.117-.07-.212-.164-.227a5.028 5.028 0 01-2.027-.807l-5.613-4.064c-.117-.078-.132-.279-.028-.381z",fill:"#fff"})]})),nv=r9("Qwen",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M12.604 1.34c.393.69.784 1.382 1.174 2.075a.18.18 0 00.157.091h5.552c.174 0 .322.11.446.327l1.454 2.57c.19.337.24.478.024.837-.26.43-.513.864-.76 1.3l-.367.658c-.106.196-.223.28-.04.512l2.652 4.637c.172.301.111.494-.043.77-.437.785-.882 1.564-1.335 2.34-.159.272-.352.375-.68.37-.777-.016-1.552-.01-2.327.016a.099.099 0 00-.081.05 575.097 575.097 0 01-2.705 4.74c-.169.293-.38.363-.725.364-.997.003-2.002.004-3.017.002a.537.537 0 01-.465-.271l-1.335-2.323a.09.09 0 00-.083-.049H4.982c-.285.03-.553-.001-.805-.092l-1.603-2.77a.543.543 0 01-.002-.54l1.207-2.12a.198.198 0 000-.197 550.951 550.951 0 01-1.875-3.272l-.79-1.395c-.16-.31-.173-.496.095-.965.465-.813.927-1.625 1.387-2.436.132-.234.304-.334.584-.335a338.3 338.3 0 012.589-.001.124.124 0 00.107-.063l2.806-4.895a.488.488 0 01.422-.246c.524-.001 1.053 0 1.583-.006L11.704 1c.341-.003.724.032.9.34zm-3.432.403a.06.06 0 00-.052.03L6.254 6.788a.157.157 0 01-.135.078H3.253c-.056 0-.07.025-.041.074l5.81 10.156c.025.042.013.062-.034.063l-2.795.015a.218.218 0 00-.2.116l-1.32 2.31c-.044.078-.021.118.068.118l5.716.008c.046 0 .08.02.104.061l1.403 2.454c.046.081.092.082.139 0l5.006-8.76.783-1.382a.055.055 0 01.096 0l1.424 2.53a.122.122 0 00.107.062l2.763-.02a.04.04 0 00.035-.02.041.041 0 000-.04l-2.9-5.086a.108.108 0 010-.113l.293-.507 1.12-1.977c.024-.041.012-.062-.035-.062H9.2c-.059 0-.073-.026-.043-.077l1.434-2.505a.107.107 0 000-.114L9.225 1.774a.06.06 0 00-.053-.031zm6.29 8.02c.046 0 .058.02.034.06l-.832 1.465-2.613 4.585a.056.056 0 01-.05.029.058.058 0 01-.05-.029L8.498 9.841c-.02-.034-.01-.052.028-.054l.216-.012 6.722-.012z",fill:"url(#pi-qwen-lobe-icons-qwen-_R_0_)","fill-rule":"nonzero"}),(0,r.jsx)("defs",{children:(0,r.jsxs)("linearGradient",{id:"pi-qwen-lobe-icons-qwen-_R_0_",x1:"0%",x2:"100%",y1:"0%",y2:"0%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#6336E7","stop-opacity":".84"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#6F69F7","stop-opacity":".84"})]})})]})),ny=r9("Zhipu",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M11.991 23.503a.24.24 0 00-.244.248.24.24 0 00.244.249.24.24 0 00.245-.249.24.24 0 00-.22-.247l-.025-.001zM9.671 5.365a1.697 1.697 0 011.099 2.132l-.071.172-.016.04-.018.054c-.07.16-.104.32-.104.498-.035.71.47 1.279 1.186 1.314h.366c1.309.053 2.338 1.173 2.286 2.523-.052 1.332-1.152 2.38-2.478 2.327h-.174c-.715.018-1.274.64-1.239 1.368 0 .124.018.23.053.337.209.373.54.658.96.8.75.23 1.517-.125 1.9-.782l.018-.035c.402-.64 1.17-.96 1.92-.711.854.284 1.378 1.226 1.099 2.167a1.661 1.661 0 01-2.077 1.102 1.711 1.711 0 01-.907-.711l-.017-.035c-.2-.323-.463-.58-.851-.711l-.056-.018a1.646 1.646 0 00-1.954.746 1.66 1.66 0 01-1.065.764 1.677 1.677 0 01-1.989-1.279c-.209-.906.332-1.83 1.257-2.043a1.51 1.51 0 01.296-.035h.018c.68-.071 1.151-.622 1.116-1.333a1.307 1.307 0 00-.227-.693 2.515 2.515 0 01-.366-1.403 2.39 2.39 0 01.366-1.208c.14-.195.21-.444.227-.693.018-.71-.506-1.261-1.186-1.332l-.07-.018a1.43 1.43 0 01-.299-.07l-.05-.019a1.7 1.7 0 01-1.047-2.114 1.68 1.68 0 012.094-1.101zm-5.575 10.11c.26-.264.639-.367.994-.27.355.096.633.379.728.74.095.362-.007.748-.267 1.013-.402.41-1.053.41-1.455 0a1.062 1.062 0 010-1.482zm14.845-.294c.359-.09.738.024.992.297.254.274.344.665.237 1.025-.107.36-.396.634-.756.718-.551.128-1.1-.22-1.23-.781a1.05 1.05 0 01.757-1.26zm-.064-4.39c.314.32.49.753.49 1.206 0 .452-.176.886-.49 1.206-.315.32-.74.5-1.185.5-.444 0-.87-.18-1.184-.5a1.727 1.727 0 010-2.412 1.654 1.654 0 012.369 0zm-11.243.163c.364.484.447 1.128.218 1.691a1.665 1.665 0 01-2.188.923c-.855-.36-1.26-1.358-.907-2.228a1.68 1.68 0 011.33-1.038c.593-.08 1.183.169 1.547.652zm11.545-4.221c.368 0 .708.2.892.524.184.324.184.724 0 1.048a1.026 1.026 0 01-.892.524c-.568 0-1.03-.47-1.03-1.048 0-.579.462-1.048 1.03-1.048zm-14.358 0c.368 0 .707.2.891.524.184.324.184.724 0 1.048a1.026 1.026 0 01-.891.524c-.569 0-1.03-.47-1.03-1.048 0-.579.461-1.048 1.03-1.048zm10.031-1.475c.925 0 1.675.764 1.675 1.706s-.75 1.705-1.675 1.705-1.674-.763-1.674-1.705c0-.942.75-1.706 1.674-1.706zm-2.626-.684c.362-.082.653-.356.761-.718a1.062 1.062 0 00-.238-1.028 1.017 1.017 0 00-.996-.294c-.547.14-.881.7-.752 1.257.13.558.675.907 1.225.783zm0 16.876c.359-.087.644-.36.75-.72a1.062 1.062 0 00-.237-1.019 1.018 1.018 0 00-.985-.301 1.037 1.037 0 00-.762.717c-.108.361-.017.754.239 1.028.245.263.606.377.953.305l.043-.01zM17.19 3.5a.631.631 0 00.628-.64c0-.355-.279-.64-.628-.64a.631.631 0 00-.628.64c0 .355.28.64.628.64zm-10.38 0a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64a.631.631 0 00-.628.64c0 .355.279.64.628.64zm-5.182 7.852a.631.631 0 00-.628.64c0 .354.28.639.628.639a.63.63 0 00.627-.606l.001-.034a.62.62 0 00-.628-.64zm5.182 9.13a.631.631 0 00-.628.64c0 .355.279.64.628.64a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64zm10.38.018a.631.631 0 00-.628.64c0 .355.28.64.628.64a.631.631 0 00.628-.64c0-.355-.279-.64-.628-.64zm5.182-9.148a.631.631 0 00-.628.64c0 .354.279.639.628.639a.631.631 0 00.628-.64c0-.355-.28-.64-.628-.64zm-.384-4.992a.24.24 0 00.244-.249.24.24 0 00-.244-.249.24.24 0 00-.244.249c0 .142.122.249.244.249zM11.991.497a.24.24 0 00.245-.248A.24.24 0 0011.99 0a.24.24 0 00-.244.249c0 .133.108.236.223.247l.021.001zM2.011 6.36a.24.24 0 00.245-.249.24.24 0 00-.244-.249.24.24 0 00-.244.249.24.24 0 00.244.249zm0 11.263a.24.24 0 00-.243.248.24.24 0 00.244.249.24.24 0 00.244-.249.252.252 0 00-.244-.248zm19.995-.018a.24.24 0 00-.245.248.24.24 0 00.245.25.24.24 0 00.244-.25.252.252 0 00-.244-.248z",fill:"#3859FF","fill-rule":"nonzero"})})),nb=r9("Cohere",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M8.128 14.099c.592 0 1.77-.033 3.398-.703 1.897-.781 5.672-2.2 8.395-3.656 1.905-1.018 2.74-2.366 2.74-4.18A4.56 4.56 0 0018.1 1H7.549A6.55 6.55 0 001 7.55c0 3.617 2.745 6.549 7.128 6.549z",fill:"#39594D","fill-rule":"evenodd"}),(0,r.jsx)("path",{"clip-rule":"evenodd",d:"M9.912 18.61a4.387 4.387 0 012.705-4.052l3.323-1.38c3.361-1.394 7.06 1.076 7.06 4.715a5.104 5.104 0 01-5.105 5.104l-3.597-.001a4.386 4.386 0 01-4.386-4.387z",fill:"#D18EE2","fill-rule":"evenodd"}),(0,r.jsx)("path",{d:"M4.776 14.962A3.775 3.775 0 001 18.738v.489a3.776 3.776 0 007.551 0v-.49a3.775 3.775 0 00-3.775-3.775z",fill:"#FF7759"})]})),nw=r9("Perplexity",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M19.785 0v7.272H22.5V17.62h-2.935V24l-7.037-6.194v6.145h-1.091v-6.152L4.392 24v-6.465H1.5V7.188h2.884V0l7.053 6.494V.19h1.09v6.49L19.786 0zm-7.257 9.044v7.319l5.946 5.234V14.44l-5.946-5.397zm-1.099-.08l-5.946 5.398v7.235l5.946-5.234V8.965zm8.136 7.58h1.844V8.349H13.46l6.105 5.54v2.655zm-8.982-8.28H2.59v8.195h1.8v-2.576l6.192-5.62zM5.475 2.476v4.71h5.115l-5.115-4.71zm13.219 0l-5.115 4.71h5.115v-4.71z",fill:"#22B8CD","fill-rule":"nonzero"})})),nj=r9("Together",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M23.197 4.503A6 6 0 0015 2.307a5.973 5.973 0 00-2.995 4.933l5.996.008v.515h-5.996c.039.937.298 1.87.8 2.74a6 6 0 1010.39-6z",fill:"#EF2CC1"}),(0,r.jsx)("path",{d:"M.805 4.5A6 6 0 003 12.697a5.972 5.972 0 005.77.127L5.779 7.627l.446-.257 2.997 5.192A6 6 0 10.804 4.5z",fill:"#CAAEF5"}),(0,r.jsx)("path",{d:"M12 23.894a6 6 0 005.999-6c0-2.13-1.1-3.996-2.775-5.06l-3.005 5.189-.444-.258 2.997-5.192A6 6 0 1012 23.894z",fill:"#FC4C02"})]})),nS=r9("Grok",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"})})),nC=r9("AntGroup",{},(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("path",{d:"M9.797 6.282a.451.451 0 01-.336-.315 1.019 1.019 0 010-.505c.156-.86.3-1.725.501-2.577.14-.7.42-1.367.823-1.96.305-.431.75-.746 1.262-.89.877-.217 1.24.629.937 1.348-.259.593-.877.914-1.334 1.348-.835.795-1.096 2.14-1.336 3.212a.427.427 0 01-.186.277.437.437 0 01-.331.062z",fill:"url(#pi-antgroup-lobe-icons-antgroup-0-_R_0_)",transform:"translate(3)"}),(0,r.jsx)("path",{d:"M6.334 4.672c.33-.121.682.146.946.297.278.145.587.219.901.214.231.01.466 0 .688.018 4.098.176 7.484 3.22 8.05 7.237.565 4.016-1.852 7.859-5.745 9.134-3.894 1.276-8.153-.38-10.126-3.935A8.339 8.339 0 013.133 7.081c.348-.278.716-.53 1.102-.755a8.404 8.404 0 001.318-.79c.28-.243.45-.742.781-.864zm4.406 2.15c-2.841.003-4.898 2.533-4.628 5.642.27 3.109 2.781 5.641 5.613 5.665 2.832.024 4.932-2.512 4.658-5.644-.273-3.133-2.802-5.666-5.643-5.663zm.357.57a4.707 4.707 0 013.304 1.446 5.703 5.703 0 011.643 3.49 4.841 4.841 0 01-1.141 3.705v.015a3.923 3.923 0 01-2.808 1.303 4.664 4.664 0 01-3.367-1.387 5.678 5.678 0 01-1.71-3.518 4.832 4.832 0 011.14-3.753 3.923 3.923 0 012.813-1.3h.126z",fill:"url(#pi-antgroup-lobe-icons-antgroup-1-_R_0_)",transform:"translate(3)"}),(0,r.jsx)("path",{d:"M2.346 2.054a1.26 1.26 0 01.384-.594.842.842 0 011.165.11c.694.82.169 2.078.142 3.02.013.805.208 1.597.57 2.318.084.134.147.279.186.43a.539.539 0 01-.3.577c-.345.17-.568-.19-.709-.446-.324-.6-.617-1.216-.877-1.846a8.698 8.698 0 01-.618-1.987 7.523 7.523 0 01-.051-.37 3.717 3.717 0 01-.024-.34 2.506 2.506 0 01.132-.872z",fill:"url(#pi-antgroup-lobe-icons-antgroup-2-_R_0_)",transform:"translate(3)"}),(0,r.jsxs)("defs",{children:[(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-0-_R_0_",x1:"31.373%",x2:"61.365%",y1:"95.551%",y2:"-.348%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]}),(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-1-_R_0_",x1:"4.366%",x2:"94.359%",y1:"65.982%",y2:"32.918%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]}),(0,r.jsxs)("linearGradient",{id:"pi-antgroup-lobe-icons-antgroup-2-_R_0_",x1:"56.255%",x2:"45.986%",y1:"99.257%",y2:"1.384%",children:[(0,r.jsx)("stop",{offset:"0%","stop-color":"#06F"}),(0,r.jsx)("stop",{offset:"20%","stop-color":"#1677FF"}),(0,r.jsx)("stop",{offset:"100%","stop-color":"#04A6FF"})]})]})]})),nT=r9("Nvidia",{},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M10.212 8.976V7.62c.127-.01.256-.017.388-.021 3.596-.117 5.957 3.184 5.957 3.184s-2.548 3.647-5.282 3.647a3.227 3.227 0 01-1.063-.175v-4.109c1.4.174 1.681.812 2.523 2.258l1.873-1.627a4.905 4.905 0 00-3.67-1.846 6.594 6.594 0 00-.729.044m0-4.476v2.025c.13-.01.259-.019.388-.024 5.002-.174 8.261 4.226 8.261 4.226s-3.743 4.69-7.643 4.69c-.338 0-.675-.031-1.007-.092v1.25c.278.038.558.057.838.057 3.629 0 6.253-1.91 8.794-4.169.421.347 2.146 1.193 2.501 1.564-2.416 2.083-8.048 3.763-11.24 3.763-.308 0-.603-.02-.894-.048V19.5H24v-15H10.21zm0 9.756v1.068c-3.356-.616-4.287-4.21-4.287-4.21a7.173 7.173 0 014.287-2.138v1.172h-.005a3.182 3.182 0 00-2.502 1.178s.615 2.276 2.507 2.931m-5.961-3.3c1.436-1.935 3.604-3.148 5.961-3.336V6.523C5.81 6.887 2 10.723 2 10.723s2.158 6.427 8.21 7.015v-1.166C5.77 16 4.25 10.958 4.25 10.958h-.002z",fill:"#74B71B","fill-rule":"nonzero"})})),nz=r9("OpenCode",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M16 6H8v12h8V6zm4 16H4V2h16v20z"})})),nR=r9("XiaomiMiMo",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M.958 15.936a.459.459 0 01.459.44v2.729a.46.46 0 01-.918 0v-2.729a.459.459 0 01.459-.44zm4.814-2.035a.46.46 0 01.553.45v4.754a.458.458 0 11-.918 0V15.48L3.74 17.202a.462.462 0 01-.655.016.462.462 0 01-.065-.082L.628 14.67a.459.459 0 01.658-.637l2.124 2.187 2.127-2.188a.46.46 0 01.235-.13zm2.068.004a.46.46 0 01.458.445v4.755a.46.46 0 01-.458.458.459.459 0 01-.458-.458V14.35a.459.459 0 01.458-.445zm1.973 2.014a.46.46 0 01.46.457v2.729a.46.46 0 01-.784.324.46.46 0 01-.134-.324v-2.729a.46.46 0 01.458-.458zm.002-2.045a.458.458 0 01.328.157l2.127 2.19 2.125-2.19a.459.459 0 01.784.318v4.756a.46.46 0 01-.455.458.46.46 0 01-.458-.458V15.48l-1.667 1.723a.46.46 0 01-.65.008l-.005-.005c0-.002-.002-.002-.004-.003l-2.455-2.534a.46.46 0 01-.008-.667.461.461 0 01.338-.128zm6.797 1.206a.46.46 0 01.53.651A1.966 1.966 0 0019.81 18.4a.462.462 0 01.623.18.46.46 0 01-.181.624 2.863 2.863 0 01-1.38.353l-.142-.004a2.88 2.88 0 01-2.393-4.263.461.461 0 01.274-.21zm.864-.931a2.884 2.884 0 013.915 3.914.46.46 0 01-.402.24l-.057-.004a.458.458 0 01-.164-.055.46.46 0 01-.182-.622 1.967 1.967 0 00-2.669-2.67.459.459 0 11-.441-.803zM9.59 6.368c1.481 0 1.696 1.202 1.696 1.654v2.648h-.917v-.432c-.26.346-.792.535-1.36.535-.133 0-1.289-.03-1.384-1.136-.082-.932.675-1.61 2.053-1.61h.691c0-.563-.367-.886-.983-.886-.44.013-.864.174-1.2.458l-.36-.664c.484-.379 1.012-.567 1.764-.567zm4.427.1c1.263 0 2.082.97 2.083 2.15 0 1.181-.824 2.154-2.083 2.154-1.26 0-2.084-.972-2.084-2.152 0-1.18.82-2.153 2.084-2.153zm6.801.015c.68 0 1.202.465 1.197 1.548v2.642H21.1V8.29c0-.312-.002-.98-.63-.98s-.628.667-.628.838v2.524h-.89V8.148c0-.17-.001-.838-.63-.838-.628 0-.628.668-.628.98v2.383h-.917v-4.03h.917V7a1.22 1.22 0 01.947-.516c.398 0 .76.193.982.686a1.321 1.321 0 011.195-.686zm-18.093.872l1.457-1.772H5.32L3.311 8.07l2.14 2.602H4.24L2.725 8.796 1.21 10.672H0L2.138 8.07.13 5.583h1.138l1.458 1.772zm4.149 3.317h-.916V6.644h.916v4.028zm16.99 0h-.916V6.644h.916v4.028zM9.925 8.71c-1.055 0-1.359.412-1.326.742.032.329.324.537.757.537a1.013 1.013 0 001.014-.968l.002-.31h-.447zM14.018 7.3c-.663 0-1.184.487-1.184 1.32 0 .832.52 1.32 1.184 1.32.662 0 1.182-.49 1.182-1.32 0-.832-.52-1.32-1.182-1.32zM6.417 5.001a.568.568 0 01.587.582.588.588 0 01-1.175 0A.57.57 0 016.417 5zm16.991 0a.57.57 0 01.592.582.588.588 0 01-1.174 0 .57.57 0 01.357-.542.572.572 0 01.225-.04z"})})),nI=r9("ZAI",{fill:"currentColor",fillRule:"evenodd"},(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("path",{d:"M12.105 2L9.927 4.953H.653L2.83 2h9.276zM23.254 19.048L21.078 22h-9.242l2.174-2.952h9.244zM24 2L9.264 22H0L14.736 2H24z"})})),nM={anthropic:{Icon:ne,hasColor:!1},openai:{Icon:nt,hasColor:!1},"openai-codex":{Icon:nt,hasColor:!1},reqtoken:{Icon:nt,hasColor:!1},google:{Icon:no,hasColor:!0},"google-vertex":{Icon:no,hasColor:!0},"ant-ling":{Icon:nC,hasColor:!0},deepseek:{Icon:nr,hasColor:!0},groq:{Icon:nn,hasColor:!1},mistral:{Icon:ns,hasColor:!0},moonshotai:{Icon:ni,hasColor:!1},"moonshotai-cn":{Icon:ni,hasColor:!1},moonshot:{Icon:ni,hasColor:!1},minimax:{Icon:na,hasColor:!0},"minimax-cn":{Icon:na,hasColor:!0},fireworks:{Icon:nl,hasColor:!0},huggingface:{Icon:nd,hasColor:!0},cerebras:{Icon:nc,hasColor:!0},openrouter:{Icon:np,hasColor:!1},xai:{Icon:nu,hasColor:!1},"cloudflare-ai-gateway":{Icon:ng,hasColor:!0},"cloudflare-workers-ai":{Icon:ng,hasColor:!0},"vercel-ai-gateway":{Icon:nh,hasColor:!1},"github-copilot":{Icon:nx,hasColor:!1},"amazon-bedrock":{Icon:nf,hasColor:!0},"azure-openai-responses":{Icon:nm,hasColor:!0},"kimi-coding":{Icon:nk,hasColor:!0},nvidia:{Icon:nT,hasColor:!0},opencode:{Icon:nz,hasColor:!1},"opencode-go":{Icon:nz,hasColor:!1},qwen:{Icon:nv,hasColor:!0},xiaomi:{Icon:nR,hasColor:!1},"xiaomi-token-plan-ams":{Icon:nR,hasColor:!1},"xiaomi-token-plan-cn":{Icon:nR,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:nR,hasColor:!1},zai:{Icon:nI,hasColor:!1},"zai-coding-cn":{Icon:nI,hasColor:!1},zhipu:{Icon:ny,hasColor:!0},cohere:{Icon:nb,hasColor:!0},perplexity:{Icon:nw,hasColor:!0},together:{Icon:nj,hasColor:!0},grok:{Icon:nS,hasColor:!1}};function nE({id:e,size:t=14}){let o=nM[e];return o?o.hasColor?(0,r.jsx)(o.Icon,{size:t}):(0,r.jsx)(o.Icon,{size:t,style:{color:"currentColor"}}):(0,r.jsx)(C.G,{size:t,weight:"regular","aria-hidden":"true"})}var nP=o(61394),nD=o(72692),n$=o(73869),nF=o(46874),nW=o(21418),nN=o(64421);let nA=[{value:"normal",Icon:nP.f,titleKey:"modes.collabNormalTitle",descKey:"modes.collabNormalDesc"},{value:"plan",Icon:nW._,titleKey:"modes.collabPlanTitle",descKey:"modes.collabPlanDesc"},{value:"goal",Icon:oG.d,titleKey:"modes.collabGoalTitle",descKey:"modes.collabGoalDesc"}],nL=[{value:"economy",Icon:nF.T,titleKey:"modes.tokenEconomyTitle",descKey:"modes.tokenEconomyDesc"},{value:"full",Icon:nD.R,titleKey:"modes.tokenFullTitle",descKey:"modes.tokenFullDesc"},{value:"delivery",Icon:n$.i,titleKey:"modes.tokenDeliveryTitle",descKey:"modes.tokenDeliveryDesc"}],nO=[{value:"ask",Icon:nN.l,titleKey:"modes.approvalAskTitle",descKey:"modes.approvalAskDesc"},{value:"auto",Icon:oZ.Z,titleKey:"modes.approvalAutoTitle",descKey:"modes.approvalAutoDesc"},{value:"yolo",Icon:p.C,titleKey:"modes.approvalYoloTitle",descKey:"modes.approvalYoloDesc"}],nH={normal:nP.f,plan:nW._,goal:oG.d},nB={economy:nF.T,full:nD.R,delivery:n$.i},nU={ask:nN.l,auto:oZ.Z,yolo:p.C};function n_({collaborationMode:e,tokenMode:t,toolApprovalMode:o,onCollaborationModeChange:s,onTokenModeChange:i,onToolApprovalModeChange:a,disabled:l=!1}){let{t:d}=(0,E.s)(),c=rY(),[p,g]=(0,n.useState)(null),[h,f]=(0,n.useState)(null),[m,k]=(0,n.useState)({}),v=(0,n.useRef)(null),y=(0,n.useRef)(null),b=(0,n.useRef)(null),w=(0,n.useRef)(null);(0,n.useEffect)(()=>()=>{null!==w.current&&window.clearTimeout(w.current)},[]);let j=(e,t)=>()=>{if(l)return;let o=t.current;if(!o)return;let r=o.getBoundingClientRect();k(t=>({...t,[e]:{top:r.top,left:r.left,width:r.width}})),g(t=>t===e?null:e)},S=(0,n.useCallback)(e=>{f(e),window.requestAnimationFrame(()=>g(t=>t===e?null:t)),null!==w.current&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>f(null),150)},[]),C=()=>window.visualViewport?.height??window.innerHeight,T=(n,c,g,x)=>{if(p!==n)return null;let f=m[n];if(!f)return null;let k=Math.min(248,window.innerWidth-16),v=Math.min(f.left,window.innerWidth-k-8),y=C()-f.top+6,b=Math.min(300,Math.max(120,.55*C()));return(0,r.jsx)("div",{role:"menu",style:{position:"fixed",bottom:y,left:v,zIndex:2100,width:k,maxHeight:b,overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 32px rgba(0,0,0,0.22)",padding:4,opacity:+(h!==n),transition:"opacity 0.12s"},children:c.map(c=>{let p=c.value===g,h=c.Icon;return(0,r.jsxs)("button",{type:"button",role:"menuitemradio","aria-checked":p,onClick:()=>{var r;return r=c.value,void(S(n),"collab"===n&&r!==e&&s(r),"token"===n&&r!==t&&i(r),"approval"===n&&r!==o&&a(r))},disabled:l,style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"8px 10px",background:p?"var(--bg-selected)":"none",border:"none",borderRadius:8,cursor:l?"not-allowed":"pointer",textAlign:"left",transition:"background 0.12s"},onMouseEnter:e=>{p||l||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background=p?"var(--bg-selected)":"none"},children:[(0,r.jsx)(h,{size:16,weight:p?"fill":"regular",color:p?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:12.5,fontWeight:550,color:"var(--text)"},children:d(c.titleKey)}),(0,r.jsx)("span",{style:{display:"block",fontSize:10.5,color:"var(--text-muted)",marginTop:1,lineHeight:1.4},children:d(c.descKey)})]}),p&&(0,r.jsx)(u.S,{size:12,weight:"bold",color:"var(--accent)","aria-hidden":"true"})]},c.value)})})},z=(e,t)=>({display:"flex",alignItems:"center",gap:3,padding:c?"0 3px":"3px 6px",height:24,background:e?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:t?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:c?11:12,whiteSpace:"nowrap",opacity:l?.5:1,transition:"background 0.12s, color 0.12s",maxWidth:c?30:void 0}),R=nH[e],I=nB[t],M=nU[o],P="plan"===e?d("modes.collabPlan"):"goal"===e?d("modes.collabGoal"):d("modes.collabNormal"),D="economy"===t?d("modes.tokenEconomy"):"delivery"===t?d("modes.tokenDelivery"):d("modes.tokenFull");return"ask"===o?d("modes.approvalAsk"):"yolo"===o?d("modes.approvalYolo"):d("modes.approvalAuto"),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:2},children:[(0,r.jsxs)("button",{ref:v,type:"button","aria-label":"任务模式",title:d("modes.collabNormalTitle"),"aria-expanded":"collab"===p,onClick:j("collab",v),disabled:l,style:z("collab"===p,"normal"!==e),children:[(0,r.jsx)(R,{size:13,weight:"normal"!==e?"fill":"regular",color:"normal"!==e?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),!c&&(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:P}),(0,r.jsx)(x.b,{size:10,weight:"bold","aria-hidden":"true",style:{transform:"collab"===p?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s",flexShrink:0}})]}),(0,r.jsxs)("button",{ref:y,type:"button","aria-label":"运行档位",title:d("modes.tokenFullTitle"),"aria-expanded":"token"===p,onClick:j("token",y),disabled:l,style:z("token"===p,"full"!==t),children:[(0,r.jsx)(I,{size:13,weight:"full"!==t?"fill":"regular",color:"full"!==t?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),!c&&(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:D}),(0,r.jsx)(x.b,{size:10,weight:"bold","aria-hidden":"true",style:{transform:"token"===p?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s",flexShrink:0}})]}),!c&&(0,r.jsx)("div",{role:"radiogroup","aria-label":"工具权限",style:{display:"flex",alignItems:"center",border:"1px solid var(--border)",borderRadius:7,overflow:"hidden",height:22,marginLeft:2},children:nO.map(e=>{let t=e.value===o,n=e.Icon;return(0,r.jsxs)("button",{type:"button",role:"radio","aria-checked":t,onClick:()=>{e.value!==o&&a(e.value)},title:d(e.descKey),"aria-label":d(e.titleKey),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:"100%",padding:"0 7px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"yolo"===e.value?"var(--accent-red, #ef4444)":"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:t?650:500,transition:"background 0.12s, color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(n,{size:11,weight:t?"fill":"regular","aria-hidden":"true"}),d("ask"===e.value?"modes.approvalAsk":"yolo"===e.value?"modes.approvalYolo":"modes.approvalAuto")]},e.value)})}),c&&(0,r.jsxs)("button",{ref:b,type:"button","aria-label":"工具权限",title:d("modes.approvalAutoTitle"),"aria-expanded":"approval"===p,onClick:j("approval",b),disabled:l,style:{...z("approval"===p,"ask"===o),..."yolo"===o?{color:"var(--accent-red, #ef4444)"}:{}},children:[(0,r.jsx)(M,{size:13,weight:"ask"===o?"fill":"regular",color:"ask"===o?"var(--accent)":"yolo"===o?"var(--accent-red, #ef4444)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsx)(x.b,{size:10,weight:"bold","aria-hidden":"true",style:{transform:"approval"===p?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s",flexShrink:0}})]})]}),T("collab",nA,e,R),T("token",nL,t,I),c&&T("approval",nO,o,M)]})}let nq=["off","default","full"],nV={off:"none",default:"default",full:"full"},nK=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function nJ(e,t){return nK.compare(e.name||e.modelId,t.name||t.modelId)||nK.compare(e.provider,t.provider)||nK.compare(e.modelId,t.modelId)}let nG=["max","xhigh","high","medium","low","minimal","auto","off"];function nY({level:e,size:t=14}){if("off"===e)return(0,r.jsx)(r6.x,{size:t,weight:"regular",color:"var(--text-dim)"});if("auto"===e)return(0,r.jsx)(r7.I,{size:t,weight:"regular",color:"var(--accent)"});let o=["medium","high","xhigh","max"].includes(e),n="var(--accent)";return(0,r.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,r.jsx)(r6.x,{size:t,weight:o?"fill":"regular",color:n}),"high"===e&&(0,r.jsx)(y.c,{size:Math.round(.57*t),weight:"bold",color:n,style:{position:"absolute",right:-4,top:-1}}),"xhigh"===e&&(0,r.jsx)(p.C,{size:Math.round(.57*t),weight:"fill",color:n,style:{position:"absolute",right:-4,top:-1}}),"max"===e&&(0,r.jsxs)("span",{style:{position:"absolute",right:-6,top:-1,display:"inline-flex"},children:[(0,r.jsx)(p.C,{size:Math.round(.5*t),weight:"fill",color:n,style:{marginRight:-3}}),(0,r.jsx)(p.C,{size:Math.round(.5*t),weight:"fill",color:n})]})]})}function nZ(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}let nX=["builtin","extension","prompt","skill"],nQ={builtin:0,extension:1,prompt:2,skill:3};function n0(e,t){let o=e.name.toLowerCase(),r=e.description?.toLowerCase()??"";return o===t?0:o.startsWith(t)?1:o.includes(t)?2:r.includes(t)?3:4}function n1(e,t){return"skill"===e.source&&e.name.startsWith("skill:")&&!0===t[e.name.slice(6)]}function n2(e){return{data:e.data,mimeType:e.mimeType}}function n4(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function n6(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function n5({kind:e,text:t,label:o,index:n,total:s,onMove:i,onRecall:a,onRemove:l}){let{t:d}=(0,E.s)(),p={display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",borderRadius:4,color:"var(--text-dim)",background:"transparent",cursor:"pointer",flexShrink:0};return(0,r.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",padding:"1px 7px",borderRadius:999,border:`1px solid ${"steer"===e?"color-mix(in srgb, var(--accent) 45%, transparent)":"var(--border)"}`,color:"steer"===e?"var(--accent)":"var(--text-dim)"},children:o}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:t}),i&&s>1&&(0,r.jsxs)("span",{style:{display:"inline-flex",gap:1,flexShrink:0},children:[(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueMoveUp"),title:d("desktop.queueMoveUp"),disabled:0===n,onClick:()=>i(-1),style:{...p,opacity:0===n?.3:1},children:"↑"}),(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueMoveDown"),title:d("desktop.queueMoveDown"),disabled:n===s-1,onClick:()=>i(1),style:{...p,opacity:n===s-1?.3:1},children:"↓"})]}),a&&(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueRecallOne"),title:d("desktop.queueRecallOne"),onClick:a,style:p,children:(0,r.jsx)(rX.Y,{size:13})}),l&&(0,r.jsx)("button",{type:"button","aria-label":d("desktop.queueRemove"),title:d("desktop.queueRemove"),onClick:l,style:p,children:(0,r.jsx)(c.u,{size:13})})]})}let n3=(0,n.forwardRef)(function({onSend:e,onBash:t,onAbort:o,onSteer:s,onFollowUp:i,isStreaming:a,model:l,modelNames:g,modelList:h,modelScopeWarnings:f,onModelChange:k,compactResult:v,toolPreset:b,onToolPresetChange:C,planMode:z=!1,onPlanModeChange:R,collaborationMode:I="normal",tokenMode:M="full",toolApprovalMode:P="auto",onCollaborationModeChange:D,onTokenModeChange:$,onToolApprovalModeChange:F,goalState:W,onGoalStart:N,onGoalPause:A,onGoalResume:L,onGoalStop:O,thinkingLevel:H,onThinkingLevelChange:B,availableThinkingLevels:U,thinkingLevelMap:q,retryInfo:V,queuedMessages:K,inputHistory:J=[],onRecallQueue:Y,onMoveQueue:Z,onRecallOne:X,onRequeueAt:Q,onRemoveQueueItem:ee,slashCommands:et,slashCommandsLoading:eo,onLoadSlashCommands:er,onBuiltinCommand:en,onAudioUnlock:es,onPromptWithStreamingBehavior:ei,draftKey:ea,cwd:el},ed){var ec;let ep,eu,eg,eh,ex,ef,em,ek,ev,ey,eb,ew,ej,eS,eC,eT,ez,eR,eI,eM,eE,eP,eD,e$=rY(),{t:eF}=(0,E.s)(),eW={auto:"auto",off:"off",minimal:"minimal",low:"low",medium:"medium",high:"high",xhigh:"xhigh",max:"max"},eN={off:eF("desktop.toolOff"),default:eF("desktop.toolDefault"),full:eF("desktop.toolFull")},eA=[{name:"compact",description:eF("desktop.compactCommandDescription"),source:"builtin"},{name:"reload",description:eF("desktop.reloadCommandDescription"),source:"builtin"},{name:"name",description:eF("desktop.nameCommandDescription"),source:"builtin"},{name:"session",description:eF("desktop.sessionCommandDescription"),source:"builtin"},{name:"copy",description:eF("desktop.copyCommandDescription"),source:"builtin"}],eL={builtin:eF("desktop.builtIn"),extension:eF("desktop.extensions"),prompt:eF("desktop.prompts"),skill:eF("desktop.commandSkills")},[eO,eH]=(0,n.useState)(()=>ea?rL(ea)?.value??"":""),[eB,eU]=(0,n.useState)([]),[e_,eq]=(0,n.useState)([]),eV=(0,n.useRef)(0),[eK,eJ]=(0,n.useState)(!1),[eG,eY]=(0,n.useState)(null),[eZ,eX]=(0,n.useState)(null),[eQ,e0]=(0,n.useState)({height:0,width:0,offsetTop:0}),[e1,e2]=(0,n.useState)(""),[e4,e6]=(0,n.useState)(()=>{try{let e=localStorage.getItem("pi-favorite-models");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}}),[e5,e3]=(0,n.useState)(new Set),[e8,e7]=(0,n.useState)(!1),[e9,te]=(0,n.useState)(null),[tt,to]=(0,n.useState)(!1),[tr,tn]=(0,n.useState)(null),[ts,ti]=(0,n.useState)(!1),[ta,tl]=(0,n.useState)(null),[td,tc]=(0,n.useState)(()=>ea?rL(ea)?.images.map(n4)??[]:[]),tp=eO.trimStart(),tu=0===td.length&&tp.startsWith("!"),tg=tu&&tp.startsWith("!!"),[th,tx]=(0,n.useState)(!1),[tf,tm]=(0,n.useState)(0),[tk,tv]=(0,n.useState)({}),[ty,tb]=(0,n.useState)(()=>{try{return"ctrl-enter"===localStorage.getItem("pi-input-shortcut")?"ctrl-enter":"enter"}catch{return"enter"}}),[tw,tj]=(0,n.useState)(null),[tS,tC]=(0,n.useState)(!1),[tT,tz]=(0,n.useState)(0),[tR,tI]=(0,n.useState)(!1),[tM,tE]=(0,n.useState)(0),[tP,tD]=(0,n.useState)(null),[t$,tF]=(0,n.useState)(!1),[tW,tN]=(0,n.useState)(null),tA=(0,n.useRef)(null),tL=(0,n.useRef)(null),tO=(0,n.useRef)(null),tH=(0,n.useRef)(null),tB=(0,n.useRef)(null),tU=(0,n.useRef)(null),t_=(0,n.useRef)(null),tq=(0,n.useRef)(null),tV=(0,n.useRef)(null),tK=(0,n.useRef)(null),tJ=(0,n.useRef)(!1),tG=(0,n.useRef)(0),tY=(0,n.useRef)(!1),tZ=(0,n.useRef)([]),tX=(0,n.useRef)([]),tQ=(0,n.useRef)([]),t0=(0,n.useRef)(null),t1=(0,n.useRef)(null),t2=(0,n.useRef)(ea),t4=(0,n.useRef)(eO),t6=(0,n.useRef)(td),t5=(0,n.useRef)(null),[t3,t8]=(0,n.useState)(!1);t4.current=eO,t6.current=td,(0,n.useImperativeHandle)(ed,()=>({insertIfEmpty(e){let t=tA.current;(t?t.value:eO).trim()||(eH(e),tj(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},replaceMessage(e){var t,o;let r=tA.current;t=r?r.value:eO,o=t6.current.length,t.trim()||0!==o||(eH("string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n")),tj(null),tI(!1),tc(t=>(t.forEach(n6),(("string"==typeof e.content?[]:e.content.flatMap(e=>{if("image"!==e.type)return[];let t=e.source?.type==="base64"?e.source.data:e.data,o=e.source?.type==="base64"?e.source.media_type:e.mimeType;return"string"!=typeof t||"string"!=typeof o?[]:rH({type:"image",data:t,mimeType:o})?[{data:t,mimeType:o}]:[]}))??[]).filter(rH).slice(0,10).map(n4))),requestAnimationFrame(()=>{r&&(r.focus(),r.style.height="auto",r.style.height=`${Math.min(r.scrollHeight,200)}px`)}))},prependText(e){if(!e.trim())return;let t=tA.current,o=[e,t?t.value:eO].filter(e=>e.trim()).join("\n\n");eH(o),tj(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(o.length,o.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},insertText(e){let t=tA.current;if(!t)return void eH(t=>t+(t?" ":"")+e);let o=t.selectionStart??t.value.length,r=t.selectionEnd??t.value.length,n=t.value.slice(0,o),s=t.value.slice(r),i=n.length>0&&!n.endsWith(" ")?" ":"";eH(n+i+e+s),tj(null),requestAnimationFrame(()=>{if(!t)return;let r=o+i.length+e.length;t.setSelectionRange(r,r),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},addImages(e){t7(e)},addFiles(e,t){let o=function(e,t,o){let r=e.map(()=>null),n=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e&&!e.startsWith("#")).filter(e=>e.startsWith("file://"));if(n.length===e.length){for(let t=0;t<e.length;t+=1)r[t]=function(e){let t;if(!e.startsWith("file://"))return null;try{t=decodeURIComponent(e.slice(7))}catch{return null}return t?(/^\/[A-Za-z]:[\\/]/.test(t)&&(t=t.slice(1)),t):null}(n[t]);return r}if(1===e.length&&o.trim()){let e=o.trim();(e.startsWith("/")||e.startsWith("~")||/^[A-Za-z]:[\\/]/.test(e))&&(r[0]=e)}return r}(e,t?.getData("text/uri-list")??"",t?.getData("text/plain")??""),r=e.filter(e=>e.type.startsWith("image/")),n=e.map((e,t)=>e.type.startsWith("image/")?null:o[t]??e.name).filter(e=>!!e);if(r.length&&t7(r),n.length&&!a){let e=n.join(" ");eH(t=>t+(t&&!t.endsWith(" ")?" ":"")+e)}},measureHeight:()=>tU.current?.getBoundingClientRect().height??0}));let t7=(0,n.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let o=await Promise.all(t.map(e=>new Promise((t,o)=>{let r=new FileReader;r.onload=()=>{t({data:r.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},r.onerror=o,r.readAsDataURL(e)})));tc(e=>[...e,...o])},[]),t9=(0,n.useCallback)((e,t)=>{e6(o=>{let r=`${e}:${t}`,n=new Set(o);return n.has(r)?n.delete(r):n.add(r),localStorage.setItem("pi-favorite-models",JSON.stringify([...n])),n})},[]),oe=(0,n.useCallback)(e=>{e3(t=>{let o=new Set(t);return o.has(e)?o.delete(e):o.add(e),o})},[]),ot=(0,n.useCallback)(e=>{tc(t=>{let o=[...t],[r]=o.splice(e,1);return r&&n6(r),o})},[]),oo=(0,n.useCallback)(()=>{tc(e=>(e.forEach(n6),[]))},[]),or=(0,n.useCallback)(()=>{var e;eH(""),tj(null),eU([]),eq([]),ea&&rN.delete(ea),t2.current&&t2.current!==ea&&(e=t2.current,rN.delete(e)),oo(),tA.current&&(tA.current.style.height="auto")},[oo,ea]),on=(0,n.useCallback)(async(e,t,o)=>{await Z?.(e,t,t+o)},[Z]),os=(0,n.useCallback)(async(e,t)=>{await ee?.(e,t)},[ee]),oi=(0,n.useCallback)(async(e,t)=>{let o=await X?.(e,t);if(!o)return;t5.current={kind:e,index:t,text:o.text,images:o.images},t8(!0);let r=tA.current?.value??eO,n=[o.text,r].filter(e=>e.trim()).join("\n\n");eH(n),tj(null),requestAnimationFrame(()=>{let e=tA.current;e&&(e.focus(),e.setSelectionRange(n.length,n.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[X,eO]);(0,n.useEffect)(()=>{ea&&t2.current===ea&&rO(ea,{value:eO,images:td.map(n2)})},[td,ea,eO]),(0,n.useEffect)(()=>{let e=t2.current;if(e===ea)return;e&&rO(e,{value:t4.current,images:t6.current.map(n2)});let t=ea?rL(ea):null;t2.current=ea,eH(t?.value??""),tj(null),tc(e=>(e.forEach(n6),t?.images.map(n4)??[]))},[ea]),(0,n.useEffect)(()=>{let e=tA.current;e&&(e.style.height="auto",eO&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[eO]),(0,n.useEffect)(()=>{let e=()=>{try{tb("ctrl-enter"===localStorage.getItem("pi-input-shortcut")?"ctrl-enter":"enter")}catch{tb("enter")}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[]),(0,n.useEffect)(()=>()=>{t6.current.forEach(n6)},[]);let oa=(0,n.useCallback)(async()=>{let o=eO;if(eB.length>0)for(let e of eB)o=o.split(e.label).join(e.text);let r=o.trim();if(!r&&!td.length||a)return;es?.();let n=t5.current;if(n&&Q){if(t5.current=null,t8(!1),!await Q(n.kind,n.index,r,td.length?td.map(n2):n.images)){t5.current={...n,text:r},t8(!0);return}or();return}if(!td.length&&r.startsWith("!")&&t){let e=r.startsWith("!!"),o=r.slice(e?2:1).trim();if(!o)return;t(o,e),or();return}if(!td.length&&r.startsWith("/")&&en){let e=await en(r);if(e.handled){e.error||or();return}}e(r,td.length?td:void 0),or()},[eO,eB,td,a,t,en,e,or,es,Q]),ol=eO.startsWith("/")&&!/\s/.test(eO.slice(1))?eO.slice(1).toLowerCase():null,{commands:od,groups:oc}=(ec=null===ol?[]:[...a?[]:eA,...et??[]].filter(e=>{let t=e.name.toLowerCase(),o=e.description?.toLowerCase()??"";return t.includes(ol)||o.includes(ol)}).sort((e,t)=>{let o=n0(e,ol)-n0(t,ol);return 0!==o?o:nQ[e.source]-nQ[t.source]||nK.compare(e.name,t.name)}),ep=0,{commands:(eu=nX.map(e=>{let t=ec.filter(t=>t.source===e),o="skill"===e?[...t.filter(e=>!n1(e,tk)),...t.filter(e=>n1(e,tk))]:t;return{source:e,items:o.map(e=>({command:e,index:ep++}))}}).filter(e=>e.items.length>0)).flatMap(e=>e.items.map(({command:e})=>e)),groups:eu});(0,n.useEffect)(()=>{if(!th||!el)return;let e=!1;return fetch(`/api/skills?cwd=${encodeURIComponent(el)}`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&tv(Object.fromEntries(t.skills.map(e=>[e.name,e.disableModelInvocation])))}).catch(()=>{}),()=>{e=!0}},[el,th]);let op=`${od.length} ${eF(ol?1===od.length?"desktop.match":"desktop.matches":1===od.length?"desktop.command":"desktop.commands")}`,ou=!!eO.trim()||td.length>0,og=(0,n.useCallback)((e,t)=>{if(!el)return void tj(null);let o=t??e.length;tj(rB(e.slice(0,o)))},[el]),[oh,ox]=(0,n.useState)(null),of=(0,n.useRef)(oh);of.current=oh;let[om,ok]=(0,n.useState)([]),ov=(0,n.useRef)(!1),oy=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/snippets");if(!e.ok)return;let t=await e.json();ok(t.snippets??[]),ov.current=!0}catch{}},[]);(0,n.useEffect)(()=>{oy();let e=()=>void oy();return window.addEventListener("pi:snippets-changed",e),()=>window.removeEventListener("pi:snippets-changed",e)},[oy]);let ob=oh?.query??null,ow=n.useMemo(()=>{if(null===ob||!1===ov.current)return[];let e=ob.toLowerCase();return om.filter(t=>t.name.toLowerCase().includes(e))},[ob,om]),[oj,oS]=(0,n.useState)(0);(0,n.useEffect)(()=>{oS(0)},[ob]);let oC=(0,n.useCallback)((e,t)=>{var o;let r,n=t??e.length,s=(o=e.slice(0,n),(r=/(?:^|[\s(])(#[\w-]+)$/.exec(o))?{start:o.length-r[1].length,end:o.length,query:r[1].slice(1)}:null);ox(s),s&&oS(0)},[]),oT=(0,n.useCallback)(e=>{let t=of.current;if(!t)return;let o=eO.slice(0,t.start),r=eO.slice(t.end);eH(o+e.content+r),ox(null);let n=o.length+e.content.length;requestAnimationFrame(()=>{let e=tA.current;e&&(e.focus(),e.setSelectionRange(n,n))})},[eO]),oz=(0,n.useCallback)(e=>{let t=ow[e];t&&oT(t)},[ow,oT]),oR=tw?.query??null,oI=n.useMemo(()=>null!==oR&&tP&&tP.cwd===el?function(e,t,o=20){let r=t.toLowerCase();if(!r)return e.slice(0,o);let n=[];for(let t of e){let e=function(e,t){let o=e.path.toLowerCase(),r=0;if(t.includes("/"))o===t?r=100:o.startsWith(t)?r=80:o.includes(t)?r=50:r_(t,o)&&(r=10);else{let e=o.lastIndexOf("/"),n=-1===e?o:o.slice(e+1);n===t?r=100:n.startsWith(t)?r=80:n.includes(t)?r=50:o.includes(t)?r=30:r_(t,o)&&(r=10)}return e.isDir&&r>0&&(r+=10),r}(t,r);e>0&&n.push({entry:t,score:e})}return n.sort((e,t)=>t.score-e.score||rU(e.entry.path)-rU(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),n.slice(0,o).map(e=>e.entry)}(tP.entries,oR):[],[oR,tP,el]),oM=!!(oR&&tP?.truncated&&tP.cwd===el);(0,n.useEffect)(()=>{if(!oM||!el||!oR)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(el)}&q=${encodeURIComponent(oR)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>tN({cwd:el,query:oR,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[oM,oR,el]);let oE=oM&&null!==tW&&tW.cwd===el&&tW.query===oR,oP=oE?tW.matches:oI,oD=null===tw?null:`${tw.start}:${+!!tw.quoted}:${tw.query}`;(0,n.useEffect)(()=>{if(null===oD){tC(!1),tz(0);return}tC(!0),tz(0)},[oD]);let o$=null!==tw;(0,n.useEffect)(()=>{if(!o$||!el)return;let e=t0.current;e&&e.cwd===el&&Date.now()-e.fetchedAt<1e4||t1.current===el||(t1.current=el,tF(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(el)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{tD({cwd:el,entries:function(e){let t=new Set;for(let o of e){let e=o.indexOf("/");for(;-1!==e;)t.add(o.slice(0,e)),e=o.indexOf("/",e+1)}let o=[];for(let e of t)o.push({path:e,isDir:!0});for(let t of e)t&&o.push({path:t,isDir:!1});return o.sort((e,t)=>rU(e.path)-rU(t.path)||e.path.localeCompare(t.path)),o}(e.files??[]),truncated:!!e.truncated}),t0.current={cwd:el,fetchedAt:Date.now()}}).catch(()=>{t0.current=null}).finally(()=>{t1.current=null,tF(!1)}))},[o$,el]);let oF=(0,n.useCallback)(e=>{if(!tw)return;let t=tA.current,o=t?.selectionStart??eO.length,r=eO.slice(0,tw.start),n=eO.slice(o);tw.quoted&&n.startsWith('"')&&(n=n.slice(1));let s=function(e,t,o=!1){let r=t?`${e}/`:e,n=o||r.includes(" ");if(t){let e=n?`@"${r}"`:`@${r}`;return{text:e,cursorOffset:n?e.length-1:e.length}}let s=n?`@"${r}" `:`@${r} `;return{text:s,cursorOffset:s.length}}(e.path,e.isDir,tw.quoted),i=r+s.text+n,a=r.length+s.cursorOffset;eH(i),tj(rB(i.slice(0,a))),requestAnimationFrame(()=>{let e=tA.current;e&&(e.focus(),e.setSelectionRange(a,a),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[tw,eO]);(0,n.useEffect)(()=>{tT>=oP.length&&tz(Math.max(0,oP.length-1))},[oP.length,tT]),(0,n.useEffect)(()=>{tX.current.length=oP.length},[oP.length]),(0,n.useEffect)(()=>{tS&&tX.current[tT]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tT,tS]);let oW=(0,n.useCallback)(e=>{eH(e),tj(null),tI(!1),tE(0),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`)})},[]),oN=(0,n.useCallback)(e=>{let t=`/${e.name} `;eH(t),tx(!1),tm(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`)})},[]),oA=(0,n.useCallback)(()=>{let e=tA.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"",s=o+n+"@"+r;eH(s);let i=t+n.length+1;og(s,i),requestAnimationFrame(()=>{e&&(e.setSelectionRange(i,i),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oL=(0,n.useCallback)(()=>{let e=tA.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"",s=o+n+"#"+r;eH(s),og(s,t+n.length+1),requestAnimationFrame(()=>{e&&(e.setSelectionRange(t+n.length+1,t+n.length+1),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oO=(0,n.useCallback)(()=>{let e=tA.current;if(!e)return;let t=e.selectionStart??e.value.length,o=e.value.slice(0,t),r=e.value.slice(e.selectionEnd??t),n=o.length>0&&!o.endsWith(" ")?" ":"";eH(o+n+"/"+r);let s=t+n.length+1;requestAnimationFrame(()=>{e&&(e.setSelectionRange(s,s),e.focus(),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),oH=(0,n.useCallback)(e=>{let t=eO.trim();if(t||td.length){if(es?.(),t.startsWith("/")&&ei){ei(t,"steer"===e?"steer":"followUp",td.length?td:void 0),or();return}"steer"===e&&s?s(t,td.length?td:void 0):"followup"===e&&i&&i(t,td.length?td:void 0),or()}},[eO,td,ei,s,i,or,es]),oB=(0,n.useCallback)(e=>{let t=od.length-1;if(t<0)return 0;if("left"===e)return Math.max(0,tf-1);if("right"===e)return Math.min(t,tf+1);let o=tZ.current[tf];if(!o)return"down"===e?Math.min(t,tf+1):Math.max(0,tf-1);let r=o.getBoundingClientRect(),n=r.left+r.width/2,s=r.top+r.height/2,i=-1,a=1/0;for(let o=0;o<=t;o+=1){if(o===tf)continue;let t=tZ.current[o];if(!t)continue;let r=t.getBoundingClientRect(),l=r.top+r.height/2-s;if("down"===e?l<=4:l>=-4)continue;let d=1e3*Math.abs(l)+Math.abs(r.left+r.width/2-n);d<a&&(i=o,a=d)}return i>=0?i:"down"===e?Math.min(t,tf+1):Math.max(0,tf-1)},[od.length,tf]),oU=(0,n.useCallback)(e=>{let t=e.nativeEvent,r=Date.now()-tG.current<100,n=tJ.current||t.isComposing||229===t.keyCode;if("Enter"===e.key&&!e.shiftKey&&(n||r)){r&&e.preventDefault();return}if((e.ctrlKey||e.metaKey)&&!e.altKey&&!e.shiftKey&&"i"===e.key.toLowerCase()&&!n&&el){e.preventDefault();let t=e.currentTarget,o=t.selectionStart??t.value.length,r=t.selectionEnd??o,n=t.value.slice(0,o),s=t.value.slice(r),i=n&&!/[\s@]$/.test(n)?" ":"",a=`${n}${i}@${s}`,l=n.length+i.length+1;eH(a),tj(rB(a.slice(0,l))),tC(!0),requestAnimationFrame(()=>{t.focus(),t.setSelectionRange(l,l)});return}if(tR&&!n){if("ArrowDown"===e.key){e.preventDefault(),tE(e=>Math.min(Math.max(0,(J?.length??0)-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),tE(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),tI(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&J?.[tM]){e.preventDefault(),oW(J[tM]);return}}if(th&&null!==ol){if("ArrowDown"===e.key){e.preventDefault(),tm(oB("down"));return}if("ArrowUp"===e.key){e.preventDefault(),tm(oB("up"));return}if("ArrowRight"===e.key){e.preventDefault(),tm(oB("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),tm(oB("left"));return}if("Escape"===e.key){e.preventDefault(),tx(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&od[tf]){e.preventDefault(),oN(od[tf]);return}}if(tS&&null!==tw&&!n){if("ArrowDown"===e.key){e.preventDefault(),tz(e=>Math.min(Math.max(0,oP.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),tz(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),tC(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&oP[tT]){e.preventDefault(),oF(oP[tT]);return}}if(null!==oh&&ow.length>0&&!n){if("ArrowDown"===e.key){e.preventDefault(),oS(e=>Math.min(Math.max(0,ow.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),oS(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),ox(null);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&ow[oj]){e.preventDefault(),oz(oj);return}}if("ArrowUp"===e.key&&!n&&!a&&(J?.length??0)>0&&0===eO.trim().length){e.preventDefault(),tx(!1),tC(!1),tE(0),tI(!0);return}if("Escape"===e.key&&!n&&a&&o){e.preventDefault(),o();return}if("Enter"===e.key&&!e.shiftKey){if("ctrl-enter"===ty&&!(e.ctrlKey||e.metaKey))return;e.preventDefault(),a&&(s||i)?oH(s?"steer":"followup"):oa()}},[a,s,i,o,th,ol,od,tf,oN,oH,oa,oB,tS,tw,oP,tT,oF,oh,ow,oj,oz,ty,el,tR,J,tM,oW,eO]),o_=(0,n.useCallback)(()=>{let e=tA.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),oq=(0,n.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]),o=t.filter(e=>e.type.startsWith("image/"));if(o.length){e.preventDefault(),t7(o.map(e=>e.getAsFile()).filter(e=>null!==e));return}if(!t.find(e=>e.type.startsWith("text/plain")))return;let r=e.clipboardData.getData("text/plain");if(!r)return;let n=r.split(/\r?\n/).length;if(r.length<2e3&&n<20)return;e.preventDefault();let s=`paste-${++eV.current}`,i=eF("desktop.pastedLabel",{id:eV.current,lines:n}),a=tA.current,l=a?.selectionStart??eO.length,d=a?.selectionEnd??eO.length,c=eO.slice(0,l),p=eO.slice(d),u=!(c.length>0)||c.endsWith("\n")||c.endsWith(" ")?"":"\n\n";eH(c+u+i+p),eU(e=>[...e,{id:s,label:i,text:r}]),requestAnimationFrame(()=>{if(!a)return;let e=l+u.length+i.length;a.setSelectionRange(e,e),a.focus()})},[t7,eF,eO]);(0,n.useEffect)(()=>{tM>=(J?.length??0)&&tE(Math.max(0,(J?.length??0)-1))},[tM,J]),(0,n.useEffect)(()=>{tQ.current.length=J?.length??0},[J]),(0,n.useEffect)(()=>{tR&&tQ.current[tM]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tM,tR]),(0,n.useEffect)(()=>{if(null===ol){tx(!1),tm(0),tY.current=!1;return}tx(!0),tm(0),!tY.current&&er&&(tY.current=!0,Promise.resolve(er()).catch(()=>{tY.current=!1}))},[ol,er]),(0,n.useEffect)(()=>{tf>=od.length&&tm(Math.max(0,od.length-1))},[od.length,tf]),(0,n.useEffect)(()=>{tZ.current.length=od.length},[od.length]),(0,n.useEffect)(()=>{th&&tZ.current[tf]?.scrollIntoView({block:"nearest",inline:"nearest"})},[tf,th]);let oV=h&&h.length>0?h.map(e=>({provider:e.provider,modelId:e.id,name:e.name})).sort(nJ):Object.entries(g??{}).map(([e,t])=>({provider:l?.provider??"unknown",modelId:e,name:t})).sort(nJ),oK=[];for(let e of oV){let t=oK.find(t=>t.provider===e.provider);t?t.options.push(e):oK.push({provider:e.provider,options:[e]})}let oJ=l?oV.find(e=>e.modelId===l.modelId&&e.provider===l.provider)?.name??l.modelId:null,oY=v?Math.max(0,v.tokensBefore-v.estimatedTokensAfter):0,oZ=v?`${eF("desktop.compacted")} ${nZ(v.tokensBefore)} -> ${nZ(v.estimatedTokensAfter)} ${eF("desktop.tokens")} (${nZ(oY)} ${eF("desktop.saved")})`:null,oX="auto"!==(eg=H??"auto")&&q?q[eg]??eW[eg]:eW[eg],oQ=Object.entries(nV).find(([,e])=>e===(b??"default"))?.[0],o0="plan"===b?eF("desktop.planModeLabel"):eN[oQ??"default"];(0,n.useEffect)(()=>{let e=e=>{tL.current&&!tL.current.contains(e.target)&&tO.current&&!tO.current.contains(e.target)&&eJ(!1),tB.current&&!tB.current.contains(e.target)&&e7(!1),t_.current&&!t_.current.contains(e.target)&&ti(!1),tq.current&&!tq.current.contains(e.target)&&to(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=null,t=()=>{e=null;let t=window.visualViewport;e0({height:t?.height??window.innerHeight,width:t?.width??window.innerWidth,offsetTop:t?.offsetTop??0})},o=()=>{null!==e&&window.cancelAnimationFrame(e),e=window.requestAnimationFrame(t)};return o(),window.addEventListener("resize",o),window.visualViewport?.addEventListener("resize",o),window.visualViewport?.addEventListener("scroll",o),window.addEventListener("focusin",o),window.addEventListener("focusout",o),window.addEventListener("pageshow",o),()=>{window.removeEventListener("resize",o),window.visualViewport?.removeEventListener("resize",o),window.visualViewport?.removeEventListener("scroll",o),window.removeEventListener("focusin",o),window.removeEventListener("focusout",o),window.removeEventListener("pageshow",o),null!==e&&window.cancelAnimationFrame(e)}},[]),(0,n.useEffect)(()=>{eK&&tH.current?.focus()},[eK]),(0,n.useEffect)(()=>{if(!eK)return;let e=!1;return fetch("/api/opencode-zen").then(e=>e.ok?e.json():null).then(t=>{!e&&t&&eX(t.accounts?.find(e=>e.id===t.activeAccountId)?.note??null)}).catch(()=>{}),()=>{e=!0}},[eK]);let[o1,o2]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!el)return void o2(null);let e=!1,t=async()=>{try{let t=await fetch("/api/tasks/projects"),{projects:o}=await t.json(),r=o.find(e=>el===e||el.startsWith(e+"/")||e.startsWith(el+"/"));if(!r){e||o2(null);return}let n=await (0,rZ.Vk)(r);if(e)return;o2({running:n.filter(e=>["running","awaiting_input","preparing","merging"].includes(e.status)).length,todo:n.filter(e=>["todo","queued"].includes(e.status)).length})}catch{e||o2(null)}};t();let o=new EventSource("/api/tasks/events");return o.onmessage=()=>void t(),()=>{e=!0,o.close()}},[el]),(0,r.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 15px",paddingRight:e$?16:34},children:[(0,r.jsx)("input",{ref:tK,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{t7(Array.from(e.target.files??[])),e.target.value=""}}),(0,r.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[o1&&(o1.running>0||o1.todo>0)&&(0,r.jsxs)("button",{type:"button",onClick:()=>window.dispatchEvent(new CustomEvent("pi:open-tasks-view")),title:eF("desktop.taskStatusHint"),style:{display:"inline-flex",alignItems:"center",gap:6,marginBottom:8,padding:"3px 10px",borderRadius:999,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",transition:"border-color 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(T.m,{size:12,"aria-hidden":"true"}),o1.running>0&&(0,r.jsxs)("span",{style:{color:"var(--accent)"},children:[o1.running," ",eF("desktop.taskRunning")]}),o1.running>0&&o1.todo>0&&(0,r.jsx)("span",{"aria-hidden":"true",children:"\xb7"}),o1.todo>0&&(0,r.jsxs)("span",{children:[o1.todo," ",eF("desktop.taskTodo")]})]}),f&&f.length>0&&(0,r.jsx)("div",{role:"status",style:{marginBottom:8,padding:"6px 10px",borderRadius:6,border:"1px solid color-mix(in srgb, var(--accent-orange) 45%, var(--border))",background:"color-mix(in srgb, var(--accent-orange) 9%, var(--bg-panel))",color:"var(--text-muted)",fontSize:12,lineHeight:1.45},children:f.join(" ")}),(K?.steering.length??0)+(K?.followUp.length??0)>0&&(0,r.jsxs)("div",{style:{marginBottom:8,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"5px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 8px 4px 10px"},children:[(0,r.jsxs)("span",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:[eF("desktop.queued")," \xb7 ",(K?.steering.length??0)+(K?.followUp.length??0)]}),Y&&(0,r.jsxs)("button",{onClick:Y,title:eF("desktop.recallQueuedMessages"),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",fontSize:12,color:"var(--text)",background:"transparent",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",transition:"background 0.12s, border-color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(rX.Y,{size:13}),eF("desktop.recallToInput")]})]}),K?.steering.map((e,t)=>(0,r.jsx)(n5,{kind:"steer",label:eF("desktop.steer"),text:e,index:t,total:K.steering.length,onMove:Z?e=>void on("steer",t,e):void 0,onRecall:X?()=>void oi("steer",t):void 0,onRemove:ee?()=>void os("steer",t):void 0},`steer-${t}`)),K?.followUp.map((e,t)=>(0,r.jsx)(n5,{kind:"follow-up",label:eF("desktop.followUp"),text:e,index:t,total:K.followUp.length,onMove:Z?e=>void on("followUp",t,e):void 0,onRecall:X?()=>void oi("followUp",t):void 0,onRemove:ee?()=>void os("followUp",t):void 0},`followup-${t}`))]}),t3&&(0,r.jsx)("div",{style:{marginBottom:8,padding:"5px 10px",borderRadius:6,border:"1px solid color-mix(in srgb, var(--accent) 40%, var(--border))",background:"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))",color:"var(--text-muted)",fontSize:12},children:eF("desktop.recalledEditing")}),V&&(0,r.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)(w.B,{size:11,style:{flexShrink:0}}),eF("desktop.retrying")," (",V.attempt,"/",V.maxAttempts,")…",V.errorMessage&&(0,r.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",V.errorMessage]})]}),oZ&&(0,r.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(16,185,129,0.08)",border:"1px solid rgba(16,185,129,0.24)",borderRadius:6,fontSize:12,color:"rgba(5,150,105,0.95)",display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)(u.S,{size:11,style:{flexShrink:0}}),oZ]}),td.length>0&&(0,r.jsx)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap"},children:td.map((e,t)=>(0,r.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,r.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:"1px solid var(--border)",display:"block"}}),(0,r.jsx)("button",{onClick:()=>ot(t),title:eF("desktop.removeImage"),"aria-label":eF("desktop.removeImage"),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,r.jsx)(c.u,{size:8})})]},t))}),(0,r.jsxs)("div",{style:{position:"relative"},children:[tR&&J.length>0&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(38vh, 300px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",color:"var(--text-dim)",fontSize:11},children:[(0,r.jsx)("span",{children:eF("desktop.inputHistory")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eF("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(38vh, 300px) - 24px)",overflowY:"auto",padding:4},children:J.map((e,t)=>(0,r.jsxs)("button",{ref:e=>{tQ.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oW(e)},onMouseEnter:()=>tE(t),style:{width:"100%",display:"flex",alignItems:"flex-start",gap:8,padding:"5px 6px",border:"none",borderRadius:5,background:t===tM?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},children:t+1}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12},children:e})]},`${t}:${e}`))})]}),th&&null!==ol&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(38vh, 300px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,r.jsx)("span",{children:eo?eF("desktop.loadingCommands"):`${eF("desktop.slashCommands")} \xb7 ${op}`}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eF("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(38vh, 300px) - 24px)",overflowY:"auto",padding:4},children:eo||0!==od.length?oc.map(e=>(0,r.jsxs)("section",{style:{marginBottom:6},children:[(0,r.jsxs)("div",{style:{position:"sticky",top:-4,zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 0 4px",background:"var(--bg)",color:"var(--text-dim)",fontSize:10,fontWeight:600,textTransform:"uppercase"},children:[(0,r.jsx)("span",{children:eL[e.source]}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:1},children:e.items.map(({command:e,index:t})=>{let o=t===tf;return(0,r.jsxs)("button",{ref:e=>{tZ.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oN(e)},onMouseEnter:()=>tm(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"3px 6px",border:"none",borderRadius:5,background:o?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,r.jsxs)("span",{style:{fontSize:12.5,fontFamily:"var(--font-mono)",whiteSpace:"nowrap",flexShrink:0},children:["/",e.name]}),e.description&&(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:e.description}),n1(e,tk)&&(0,r.jsx)("span",{style:{marginLeft:"auto",flexShrink:0,padding:"1px 5px",borderRadius:999,border:"1px solid var(--border)",color:"var(--text-dim)",fontSize:10},children:eF("desktop.dormant")})]},`${e.source}:${e.name}`)})})]},e.source)):(0,r.jsx)("div",{style:{padding:"2px 2px 2px",fontSize:12,color:"var(--text-dim)"},children:eF("desktop.noSlashCommands")})})]}),tS&&null!==tw&&(eh=t$&&(!tP||tP.cwd!==el),ex=`${oP.length} ${eF(1===oP.length?"desktop.match":"desktop.matches")}`,ef=tP?.truncated&&!oE?tw.query?` \xb7 ${eF("desktop.searchingAllFiles")}`:` \xb7 ${eF("desktop.indexTruncated")}`:"",(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(30vh, 240px)"},children:[(0,r.jsxs)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,r.jsx)("span",{children:eh?eF("desktop.loadingFiles"):`${eF("desktop.files")} \xb7 ${ex}${ef}`}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:eF("desktop.tabOrEnter")})]}),(0,r.jsx)("div",{style:{maxHeight:"calc(min(30vh, 240px) - 24px)",overflowY:"auto",padding:2},children:eh||0!==oP.length?oP.map((e,t)=>{let o=t===tT,n=e.path.split("/").pop()??e.path,s=e.path.slice(0,e.path.length-n.length);return(0,r.jsxs)("button",{ref:e=>{tX.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),oF(e)},onMouseEnter:()=>tz(t),style:{width:"100%",display:"flex",alignItems:"center",gap:5,padding:"3px 6px",border:"none",borderRadius:5,background:o?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,r.jsx)(_,{size:14,name:n}):G(n,14)}),(0,r.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:s}),n,e.isDir&&(0,r.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,r.jsx)("div",{style:{padding:"4px 6px",fontSize:12,color:"var(--text-dim)"},children:oM&&!oE?eF("desktop.searching"):eF("desktop.noMatchingFiles")})})]})),null!==oh&&ow.length>0&&(0,r.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(30vh, 240px)"},children:[(0,r.jsx)("div",{style:{padding:"4px 8px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",fontWeight:600},children:[ow.length," ",eF("desktop.snippetMatches")]})}),(0,r.jsx)("div",{style:{maxHeight:"min(26vh, 210px)",overflowY:"auto"},children:ow.map((e,t)=>(0,r.jsxs)("button",{type:"button",onMouseEnter:()=>oS(t),onClick:()=>oz(t),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 10px",background:t===oj?"var(--bg-selected)":"none",border:"none",color:t===oj?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,r.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:"#"}),(0,r.jsx)("span",{style:{fontWeight:600,flexShrink:0},children:e.name}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:11},children:e.content.split("\n")[0]})]},e.id))})]}),(0,r.jsxs)("div",{className:`chat-input-shell ${a&&(s||i)?"is-streaming":""} ${"yolo"===P?"is-yolo":""}`,ref:tU,onClick:e=>{e.target.closest("button, input, select, [role=button]")||tA.current?.focus()},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:0,padding:0,transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[a&&(0,r.jsx)("div",{className:"chat-input-streaming-overlay hatch-45","aria-hidden":"true"}),a&&(s||i)&&(0,r.jsxs)("div",{className:"chat-input-streaming-actions",children:[s&&(0,r.jsx)("button",{type:"button",className:"chat-input-streaming-action chat-input-streaming-action-steer",onClick:()=>oH("steer"),disabled:!ou,title:eF("desktop.injectMessageNow"),"aria-label":eF("desktop.steer"),children:(0,r.jsx)(rQ.A,{size:15})}),i&&(0,r.jsx)("button",{type:"button",className:"chat-input-streaming-action",onClick:()=>oH("followup"),disabled:!ou,title:eF("desktop.queueMessageAfterFinish"),"aria-label":eF("desktop.followUp"),children:(0,r.jsx)(r2.M,{size:15})})]}),eB.length>0&&(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4,marginBottom:6},children:eB.map(e=>{let t=e_.includes(e.id);return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-secondary)",fontSize:11,color:"var(--text-muted)"},children:[(0,r.jsx)(r1.d,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:e.label}),(0,r.jsx)("button",{type:"button",onClick:()=>eq(o=>t?o.filter(t=>t!==e.id):[...o,e.id]),title:eF(t?"desktop.pastedHidePreview":"desktop.pastedShowPreview"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(r0.b,{size:12,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:()=>{eU(t=>t.filter(t=>t.id!==e.id)),eH(t=>t.split(e.label).join(""))},title:eF("desktop.pastedRemove"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(j.u,{size:12,"aria-hidden":"true"})}),t&&(0,r.jsx)("div",{style:{position:"relative"},children:(0,r.jsx)("pre",{style:{position:"absolute",left:0,right:0,top:"calc(100% + 4px)",zIndex:50,maxHeight:200,overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,padding:"8px 10px",fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e.text})})]},e.id)})}),(0,r.jsxs)("div",{className:"chat-input-editor-row",style:{borderColor:tu?"var(--tool-bg)":void 0},children:["goal"===I&&W&&"idle"!==W.status&&(0,r.jsxs)("span",{style:{flexShrink:0,display:"inline-flex",alignItems:"center",gap:6,marginRight:8,padding:"2px 8px",borderRadius:6,background:"complete"===W.status?"color-mix(in srgb, var(--accent-green, #22c55e) 14%, transparent)":"blocked"===W.status||"paused"===W.status?"color-mix(in srgb, #f59e0b 14%, transparent)":"color-mix(in srgb, var(--accent) 12%, transparent)",color:"complete"===W.status?"var(--accent-green, #22c55e)":"blocked"===W.status||"paused"===W.status?"#f59e0b":"var(--accent)",fontSize:11,fontWeight:600,whiteSpace:"nowrap",userSelect:"none"},title:W.goalText??"",children:[(0,r.jsx)(oG.d,{size:12,weight:"fill","aria-hidden":"true"}),"running"===W.status&&(0,r.jsxs)("span",{children:[eF("desktop.goalRunning")," \xb7 ",W.turnsUsed,"/",W.turnsLimit]}),"complete"===W.status&&(0,r.jsx)("span",{children:eF("desktop.goalComplete")}),"blocked"===W.status&&(0,r.jsx)("span",{children:eF("desktop.goalBlocked")}),"paused"===W.status&&(0,r.jsx)("span",{children:eF("desktop.goalPaused")}),W.noProgressTurns>0&&"running"===W.status&&(0,r.jsxs)("span",{style:{opacity:.8},children:["\xb7 ",eF("desktop.goalNoProgress",{n:W.noProgressTurns})]}),"running"===W.status&&(0,r.jsx)("button",{type:"button",onClick:A,title:eF("desktop.goalPause"),"aria-label":eF("desktop.goalPause"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,padding:0,background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11},children:eF("desktop.goalPauseShort")}),("paused"===W.status||"blocked"===W.status)&&(0,r.jsx)("button",{type:"button",onClick:L,title:eF("desktop.goalResume"),"aria-label":eF("desktop.goalResume"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0 4px",background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11,fontWeight:600},children:eF("desktop.goalResumeShort")}),(0,r.jsx)("button",{type:"button",onClick:O,title:eF("desktop.goalStop"),"aria-label":eF("desktop.goalStop"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0 3px",background:"none",border:"none",borderRadius:4,color:"inherit",cursor:"pointer",fontSize:11,opacity:.75},children:"✕"})]}),(0,r.jsx)("textarea",{ref:tA,value:eO,spellCheck:!1,onChange:e=>{eH(e.target.value),og(e.target.value,e.target.selectionStart),oC(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;og(t.value,t.selectionStart)},onKeyDown:oU,onCompositionStart:()=>{tJ.current=!0},onCompositionEnd:e=>{tJ.current=!1,tG.current=Date.now();let t=e.currentTarget;og(t.value,t.selectionStart)},onInput:o_,onPaste:oq,placeholder:a&&(s||i)?eF("desktop.steerOrQueueFollowUp"):a?eF("desktop.agentRunning"):eF("desktop.messageWithCommands"),rows:1,className:"chat-input-textarea",style:{flex:1,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",minHeight:24,maxHeight:200,padding:0,overflow:"auto"}})]}),tu&&(0,r.jsxs)("div",{style:{marginTop:4,padding:"2px 8px",fontSize:11,color:tg?"var(--text-muted)":"var(--accent)"},children:[eF("desktop.shellCommand")," \xb7 ",tg?eF("desktop.shellOutputLocal"):eF("desktop.shellOutputModel")]}),(0,r.jsxs)("div",{className:"chat-input-toolbar",style:{display:e$?"grid":"flex",gridTemplateColumns:e$?"auto auto minmax(0, 1fr)":void 0,alignItems:"center",gap:4},children:[(0,r.jsxs)("div",{ref:tq,className:"chat-input-toolbar-attach",style:{position:"relative"},children:[(0,r.jsx)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();tn({top:t.top,left:t.left,width:t.width}),to(e=>!e)},title:eF("desktop.attachMenu"),"aria-label":eF("desktop.attachMenu"),"aria-expanded":tt,style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:tt?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:td.length?"var(--accent)":"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=td.length?"var(--accent)":"var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=tt?"var(--bg-hover)":"none",e.currentTarget.style.color=td.length?"var(--accent)":"var(--text-muted)"},children:(0,r.jsx)(y.c,{size:14})}),tt&&tr&&(em=[{id:"upload",label:eF("desktop.attachUpload"),desc:eF("desktop.attachUploadDesc"),icon:S.J},{id:"reference",label:eF("desktop.attachReference"),desc:eF("desktop.attachReferenceDesc"),icon:ry.sj},{id:"sessions",label:eF("desktop.attachSessions"),desc:eF("desktop.attachSessionsDesc"),icon:r4.v},{id:"slash",label:eF("desktop.attachCommands"),desc:eF("desktop.attachCommandsDesc"),icon:p.C}],ek=window.visualViewport?.height??window.innerHeight,ev=window.innerWidth,ey=Math.min(tr.left,ev-220-8),eb=ek-tr.top+6,(0,r.jsx)("div",{role:"menu",style:{position:"fixed",left:ey,bottom:eb,zIndex:1200,width:220,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 32px rgba(0,0,0,0.22)",padding:4},children:em.map(e=>(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{to(!1),"upload"===e.id?tK.current?.click():"reference"===e.id?oA():"sessions"===e.id?oL():"slash"===e.id&&oO()},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"8px 10px",background:e.active?"var(--bg-selected)":"none",border:"none",borderRadius:8,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},onMouseEnter:t=>{e.active||(t.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:t=>{t.currentTarget.style.background=e.active?"var(--bg-selected)":"none"},children:[(0,r.jsx)(e.icon,{size:16,weight:e.active?"fill":"regular",color:e.active?"var(--accent)":"var(--text-muted)","aria-hidden":"true"}),(0,r.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:12.5,fontWeight:550,color:"var(--text)"},children:e.label}),(0,r.jsx)("span",{style:{display:"block",fontSize:10.5,color:"var(--text-muted)",marginTop:1,lineHeight:1.4},children:e.desc})]}),e.active?(0,r.jsx)(u.S,{size:12,weight:"bold",color:"var(--accent)","aria-hidden":"true"}):null]},e.id))}))]}),(0,r.jsx)("div",{className:"chat-input-toolbar-left",style:{flex:"0 0 auto",minWidth:0,display:"flex",alignItems:"center",gap:2},children:D&&$&&F&&(0,r.jsx)(n_,{collaborationMode:I,tokenMode:M,toolApprovalMode:P,onCollaborationModeChange:D,onTokenModeChange:$,onToolApprovalModeChange:F,disabled:a})}),!e$&&(0,r.jsx)("div",{className:"chat-input-toolbar-spacer",style:{flex:1}}),(0,r.jsx)("div",{ref:tV,className:"chat-input-toolbar-controls",style:{flex:e$?"1 1 auto":"0 0 auto",minWidth:e$?0:void 0,display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:e$?0:"auto"},children:(0,r.jsxs)("div",{className:"chat-input-toolbar-actions",style:{display:"flex",alignItems:"center",gap:e$?1:2,...e$?{flex:"1 1 auto",minWidth:0,justifyContent:"flex-end"}:null},children:[B&&(0,r.jsxs)("div",{ref:t_,className:"chat-input-toolbar-thinking",style:{position:"relative"},children:[(0,r.jsxs)("button",{onClick:e=>{if(a)return;let t=e.currentTarget.getBoundingClientRect();tl({top:t.top,left:t.left,width:t.width}),ti(e=>!e)},disabled:a,title:eF("desktop.changeReasoningLevel",{level:oX}),"aria-label":eF("desktop.reasoningLevel"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:e$?"0 5px":"3px 7px",width:e$?"auto":void 0,height:24,background:ts?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:(H??"auto")==="off"?"var(--text-dim)":"var(--accent)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.background=ts?"var(--bg-hover)":"none"},children:[(0,r.jsx)(nY,{level:H??"auto"}),(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:oX}),(0,r.jsx)(x.b,{size:11,weight:"bold","aria-hidden":"true",style:{transform:ts?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),ts&&ta&&(ew=window.visualViewport?.height??window.innerHeight,eS=Math.min(240,(ej=window.innerWidth)-16),eC=Math.min(ta.left,ej-eS-8),eT=ew-ta.top+4,ez=Math.min(360,Math.max(120,Math.min(ta.top-8,.6*ew))),(0,r.jsx)("div",{style:{position:"fixed",bottom:eT,left:eC,zIndex:2001,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",minWidth:200,maxWidth:eS,maxHeight:ez,overflowY:"auto"},children:nG.filter(e=>!U||"auto"===e||U.includes(e)).map(e=>{let t=(H??"auto")===e,o="auto"!==e&&q?q[e]:void 0,n=null!=o&&o!==e?o:eW[e],s=null!=o&&o!==e;return(0,r.jsxs)("button",{onClick:()=>{ti(!1),t||B(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(nY,{level:e,size:14}),(0,r.jsxs)("span",{style:{flex:1},children:[n,s&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:5},children:["(",e,")"]})]}),t&&(0,r.jsx)(u.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}})]},e)})}))]}),C&&"plan"===b&&(0,r.jsxs)("div",{ref:tB,className:"chat-input-toolbar-tools",style:{position:"relative"},children:[" ",(0,r.jsxs)("button",{onClick:e=>{if(a)return;let t=e.currentTarget.getBoundingClientRect();te({top:t.top,left:t.left,width:t.width}),e7(e=>!e)},disabled:a,title:eF("desktop.changeToolPreset",{preset:o0}),"aria-label":eF("desktop.toolPreset"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:e$?"0 5px":"3px 7px",width:e$?"auto":void 0,height:24,background:e8?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=e8?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)("span",{style:{whiteSpace:"nowrap"},children:o0}),(0,r.jsx)(x.b,{size:11,weight:"bold","aria-hidden":"true",style:{transform:e8?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),e8&&e9&&(eR=window.visualViewport?.height??window.innerHeight,eM=Math.min(200,(eI=window.innerWidth)-16),eE=Math.max(8,eI-(e9.left+e9.width)),eP=eR-e9.top+6,eD=Math.min(320,Math.max(100,Math.min(e9.top-8,.5*eR))),(0,r.jsx)("div",{style:{position:"fixed",bottom:eP,right:eE,zIndex:2001,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",minWidth:120,maxWidth:eM,maxHeight:eD,overflowY:"auto"},children:nq.map(e=>{let t=nV[e],o="plan"!==b&&(b??"default")===t,n="off"===e?eF("desktop.noToolsReadOnly"):"default"===e?eF("desktop.fourBuiltInTools"):eF("desktop.allBuiltInTools");return(0,r.jsxs)("button",{onClick:()=>{e7(!1),o||C(t)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 12px",background:o?"var(--bg-selected)":"none",border:"none",color:o?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flex:1},children:eN[e]}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:n}),o&&(0,r.jsx)(u.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}})]},e)})}))]}),oV.length>0&&k&&(0,r.jsxs)("div",{ref:tL,className:"chat-input-toolbar-model",style:{position:"relative",flex:e$?"1 1 auto":void 0,minWidth:0},children:[(0,r.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();eY({top:t.top,left:t.left,width:t.width}),eK||e2(""),eJ(e=>!e)},disabled:a,style:{display:"flex",alignItems:"center",gap:6,justifyContent:e$?"flex-start":void 0,padding:e$?"4px 6px":"3px 7px",height:24,width:e$?"100%":void 0,maxWidth:e$?"100%":"min(220px, 34vw)",overflow:"hidden",background:eK?"var(--bg-hover)":"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:a?"not-allowed":"pointer",fontSize:12,opacity:a?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eK?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(nE,{id:l?.provider??"unknown",size:14}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:oJ??eF("desktop.selectModel")}),(0,r.jsx)(x.b,{size:11,weight:"bold","aria-hidden":"true",style:{flexShrink:0,transform:eK?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.12s"}})]}),eK&&eG&&(()=>{let e=eQ.height||window.innerHeight,t=eQ.width||window.innerWidth,o=eG.top-eQ.offsetTop,n=Math.max(6,e-o+6),s=Math.min(400,Math.max(120,Math.min(o-8,.6*e))),i=Math.min(320,s),a=eG.width,c=Math.min(360,t-16),p=e$?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{right:Math.max(8,t-(eG.left+eG.width)),width:"max-content",minWidth:Math.min(a,c),maxWidth:c},g=[];for(let e of[...e4]){let[t,o]=e.split(":",2),r=oV.find(e=>e.provider===t&&e.modelId===o);r&&g.push(r)}let h=e1.trim().toLowerCase(),f=h.length>0,v=e=>e.name.toLowerCase().includes(h)||e.modelId.toLowerCase().includes(h)||e.provider.toLowerCase().includes(h),y=f?g.filter(v):g,b=y.length>0,w=f?oK.map(e=>({...e,options:e.options.filter(v)})).filter(e=>e.options.length>0):oK,j=b||w.length>0;return(0,r.jsxs)("div",{ref:tO,className:"chat-input-model-dropdown",style:{position:"fixed",bottom:n,...p,zIndex:2e3,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",overflow:"hidden",height:i,maxHeight:s,display:"flex",flexDirection:"column"},children:[(0,r.jsx)("div",{style:{borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center"},children:[(0,r.jsx)(d.$,{size:13,color:"var(--text-dim)",style:{position:"absolute",left:12,pointerEvents:"none"}}),(0,r.jsx)("input",{ref:tH,value:e1,onChange:e=>e2(e.target.value),onKeyDown:e=>{if("Escape"===e.key)e1?e2(""):eJ(!1);else if("ArrowDown"===e.key){let t=tO.current?.querySelector(".model-row button");t&&(e.preventDefault(),t.focus())}},placeholder:eF("desktop.searchModels"),"aria-label":eF("desktop.searchModels"),style:{width:"100%",padding:"5px 12px 5px 34px",background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"}})]})}),(0,r.jsxs)("div",{style:{overflowY:"auto",flex:1,minHeight:0},children:[b&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:eF("desktop.favorites")}),y.map(e=>{let t=e.modelId===l?.modelId&&e.provider===l?.provider,o=e4.has(`${e.provider}:${e.modelId}`);return(0,r.jsx)("div",{className:"model-row",style:{display:"flex",alignItems:"center",width:"100%"},children:(0,r.jsxs)("button",{onClick:()=>{eJ(!1),k(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(nE,{id:e.provider,size:14}),(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:e.name}),t&&(0,r.jsx)(u.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}}),(0,r.jsx)("span",{onClick:t=>{t.stopPropagation(),t9(e.provider,e.modelId)},className:"model-star",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,cursor:"pointer",color:o?"var(--accent)":"var(--text-dim)",opacity:+!!o,transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{e.stopPropagation(),e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.stopPropagation(),e.currentTarget.style.color=o?"var(--accent)":"var(--text-dim)"},title:o?eF("desktop.unfavorite"):eF("desktop.favorite"),"aria-label":o?eF("desktop.unfavorite"):eF("desktop.favorite"),children:(0,r.jsx)(r8.G,{size:12,weight:o?"fill":"regular"})})]})},`fav-${e.provider}:${e.modelId}`)}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)"}})]}),w.map((e,t)=>{let o=f||e5.has(e.provider),n=o?(0,r.jsx)(x.b,{size:10,color:"var(--text-dim)"}):(0,r.jsx)(m.J,{size:10,color:"var(--text-dim)"});return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{onClick:()=>oe(e.provider),title:("opencode"===e.provider||"opencode-go"===e.provider)&&eZ?`OpenCode Zen \xb7 ${eZ}`:e.provider,style:{display:"flex",alignItems:"center",gap:4,width:"100%",maxWidth:"100%",padding:"6px 12px 4px",background:"none",border:"none",cursor:"pointer",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",overflow:"hidden",whiteSpace:"nowrap",borderTop:t>0?"1px solid var(--border)":"none"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:[n,(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:"opencode"===e.provider||"opencode-go"===e.provider?`OpenCode Zen${eZ?` \xb7 账号:${eZ}`:""}`:e.provider})]}),o&&e.options.map(e=>{let t=e.modelId===l?.modelId&&e.provider===l?.provider,o=e4.has(`${e.provider}:${e.modelId}`);return(0,r.jsx)("div",{className:"model-row",style:{display:"flex",alignItems:"center",width:"100%"},children:(0,r.jsxs)("button",{onClick:()=>{eJ(!1),k(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,padding:"6px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--accent)":"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left",fontFamily:"var(--font-mono)",whiteSpace:"nowrap",overflow:"hidden"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(nE,{id:e.provider,size:14}),(0,r.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:e.name}),t&&(0,r.jsx)(u.S,{size:12,weight:"bold",color:"var(--accent)",style:{flexShrink:0}}),(0,r.jsx)("span",{onClick:t=>{t.stopPropagation(),t9(e.provider,e.modelId)},className:"model-star",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,cursor:"pointer",color:o?"var(--accent)":"var(--text-dim)",opacity:+!!o,transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{e.stopPropagation(),e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.stopPropagation(),e.currentTarget.style.color=o?"var(--accent)":"var(--text-dim)"},title:o?eF("desktop.unfavorite"):eF("desktop.favorite"),"aria-label":o?eF("desktop.unfavorite"):eF("desktop.favorite"),children:(0,r.jsx)(r8.G,{size:12,weight:o?"fill":"regular"})})]})},`${e.provider}:${e.modelId}`)})]},e.provider)}),f&&!j&&(0,r.jsx)("div",{style:{padding:"14px 12px",textAlign:"center",fontSize:12,color:"var(--text-dim)"},children:eF("desktop.noModelsMatch")})]})]})})()]}),!a&&(0,r.jsx)("button",{type:"button",onClick:oa,disabled:!eO.trim()&&!td.length,className:"chat-input-send",title:eF("desktop.sendMessage"),"aria-label":eF("desktop.sendMessage"),children:(0,r.jsx)(r5.l,{size:14})}),a&&(0,r.jsxs)("button",{onClick:o,title:eF("desktop.stopAgent"),"aria-label":eF("desktop.stopAgent"),style:{display:"flex",alignItems:"center",gap:6,padding:"3px 7px",height:24,background:"rgba(239,68,68,0.12)",border:"none",borderRadius:6,color:"#ef4444",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.20)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.12)"},children:[(0,r.jsx)(r3.d,{size:14}),eF("desktop.stop")]})]})})]})]})]})]})]})});function n8(e){return!!e&&"string"==typeof e.type&&"string"==typeof e.data&&"string"==typeof e.mimeType}function n7(e){let t;if(!e||"object"!=typeof e)return null;let o=e.kind;return"steer"!==o&&"followUp"!==o||"string"!=typeof e.text?null:(Array.isArray(e.images)&&0===(t=e.images.filter(n8)).length&&(t=void 0),{kind:o,text:e.text,...t?{images:t}:{}})}function n9({items:e,sessionId:t,onResolve:o,onExport:s,onStageImport:i,onDismiss:a,mode:l="recovery"}){let{t:d}=(0,E.s)(),c=rY(),[p,u]=(0,n.useState)(()=>new Set(e.map(e=>e.id))),[g,h]=(0,n.useState)(!1),[x,f]=(0,n.useState)(null),m=(0,n.useRef)(null);(0,n.useEffect)(()=>{u(new Set(e.map(e=>e.id)))},[e]);let k=e.filter(e=>p.has(e.id)),v=k.length===e.length&&e.length>0,y=e=>u(t=>{let o=new Set(t);return o.has(e)?o.delete(e):o.add(e),o}),b=async(e,t=!1)=>{if(0!==k.length){h(!0),f(null);try{await o("keep"===e?k.map(e=>e.id):[],"discard"===e?k.map(e=>e.id):[],t)}catch(e){f(e instanceof Error?e.message:String(e))}finally{h(!1)}}},w=async e=>{let o=await s();if(!o)return;let r=o.recovery.filter(e=>p.has(e.id));if(r.length){var n;let o,s,i,a,l,c,p;n={sessionId:t,source:"recovery"},s="md"===e?(((o=[]).push("# Queued messages export"),n.sessionId&&o.push(`- Session: ${n.sessionId}`),o.push(`- Source: ${"live"===n.source?"live queue":"pending recovery"}`),o.push(`- Exported: ${n.exportedAt??new Date().toISOString()}`),o.push(""),0===r.length)?o.push("_No entries._"):r.forEach((e,t)=>{var r;o.push(`## ${t+1}. ${"steer"===e.kind?"steer":"follow-up"} \xb7 ${new Date(e.queuedAt).toISOString()}`),e.text&&o.push(e.text),e.images?.length&&o.push(`> _${0===(r=e.images.length)?"":1===r?"(1 image)":`(${r} images)`}_`),o.push("")}),o.join("\n")):JSON.stringify({format:"pi-web-queue",version:1,exportedAt:n.exportedAt??new Date().toISOString(),source:n.source,sessionId:n.sessionId,entries:r.map(({kind:e,text:t,images:o})=>({kind:e,text:t,...o?.length?{images:o}:{}}))},null,2),i=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),a=`${n.sessionId??"session"}-queue-${n.source}-${i}.${e}`,l=new Blob([s],{type:"md"===e?"text/markdown;charset=utf-8":"application/json;charset=utf-8"}),c=URL.createObjectURL(l),(p=document.createElement("a")).href=c,p.download=a,p.click(),setTimeout(()=>URL.revokeObjectURL(c),1e3),f(d("desktop.queueExported",{count:r.length}))}},j=async e=>{let t=function(e){let t;try{t=JSON.parse(e)}catch{return[]}let o=Array.isArray(t)?t:t&&"object"==typeof t&&Array.isArray(t.entries)?t.entries:null;return o?o.map(n7).filter(e=>null!==e):[]}(await e.text());if(!t.length)return void f(d("desktop.queueImportEmpty"));let o=await i(t);f(null===o?d("desktop.queueImportEmpty"):d("desktop.queueImported",{count:o}))};return(0,r.jsxs)("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/40 p-3",role:"presentation",children:[(0,r.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"import"===l?d("desktop.queueImportTitle"):d("desktop.queueRecoveryTitle"),className:"flex max-h-[88dvh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-(--border) bg-(--bg) shadow-2xl",children:[(0,r.jsxs)("header",{className:"flex flex-wrap items-start gap-3 border-b border-(--border) bg-(--bg-panel) px-4 py-3",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("h2",{className:"text-sm font-semibold text-(--text)",children:"import"===l?d("desktop.queueImportTitle"):d("desktop.queueRecoveryTitle")}),(0,r.jsx)("p",{className:"mt-1 text-xs leading-5 text-(--text-muted)",children:"import"===l?d("desktop.queueImportDescription"):d("desktop.queueRecoveryDescription")})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("button",{type:"button",className:"markdown-code-action",onClick:()=>u(new Set(v?[]:e.map(e=>e.id))),children:v?d("desktop.selectNone"):d("desktop.selectAll")}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:g||0===k.length,onClick:()=>void w("json"),children:"JSON"}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:g||0===k.length,onClick:()=>void w("md"),children:"MD"}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",disabled:g,onClick:()=>m.current?.click(),children:d("desktop.import")}),(0,r.jsx)("button",{type:"button",className:"markdown-code-action",onClick:a,"aria-label":d("desktop.close"),children:"\xd7"})]})]}),(0,r.jsx)("div",{className:"grid flex-1 content-start gap-2 overflow-y-auto p-3",children:e.map(e=>{let t=p.has(e.id);return(0,r.jsxs)("button",{type:"button",onClick:()=>y(e.id),"aria-pressed":t,className:["flex w-full items-start gap-3 rounded-lg border p-3 text-left transition",t?"border-(--accent) bg-(--bg-selected)":"border-(--border) bg-(--bg-panel) hover:bg-(--bg-hover)"].join(" "),children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:()=>y(e.id),onClick:e=>e.stopPropagation(),className:"mt-1 accent-[var(--accent)]"}),(0,r.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("span",{className:"flex flex-wrap items-center gap-2 text-[11px] text-(--text-dim)",children:[(0,r.jsx)("span",{className:"rounded-full border border-(--border) px-2 py-0.5 font-mono uppercase",children:"steer"===e.kind?d("desktop.steer"):d("desktop.followUp")}),(0,r.jsx)("span",{children:new Date(e.queuedAt).toLocaleString()}),e.hasImages?(0,r.jsx)("span",{children:d("desktop.queueImages")}):null]}),(0,r.jsx)("span",{className:"mt-2 block whitespace-pre-wrap break-words border-l-2 border-(--border) pl-2 text-xs leading-5 text-(--text)",children:e.text||d("desktop.queueNoText")})]})]},e.id)})}),(0,r.jsxs)("footer",{className:["flex flex-wrap items-center gap-2 border-t border-(--border) px-4 py-3",c?"justify-stretch":"justify-end"].join(" "),children:[x?(0,r.jsx)("span",{className:"mr-auto text-xs text-(--text-muted)",children:x}):null,(0,r.jsx)("button",{type:"button",className:"rounded-md px-3 py-2 text-xs text-(--text-muted) hover:bg-(--bg-hover)",onClick:a,disabled:g,children:d("desktop.dismiss")}),(0,r.jsx)("button",{type:"button",className:"rounded-md border border-red-400/40 px-3 py-2 text-xs text-red-400 disabled:opacity-40",onClick:()=>void b("discard"),disabled:g||0===k.length,children:d("desktop.discard")}),(0,r.jsx)("button",{type:"button",className:"rounded-md border border-(--accent) px-3 py-2 text-xs text-(--accent) disabled:opacity-40",onClick:()=>void b("keep"),disabled:g||0===k.length,children:d("desktop.requeue")}),(0,r.jsx)("button",{type:"button",className:"rounded-md bg-(--accent) px-3 py-2 text-xs text-white disabled:opacity-40",onClick:()=>void b("keep",!0),disabled:g||0===k.length,children:d("desktop.requeueAndContinue")})]})]}),(0,r.jsx)("input",{ref:m,type:"file",accept:".json,application/json",className:"hidden",onChange:e=>{let t=e.target.files?.[0];t&&j(t),e.currentTarget.value=""}})]})}var se=o(36405),st=o(92185),so=o(75877),sr=o(30830),sn=o(86965);function ss(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function si(e){let t=e,o=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],o+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:o}}function sa({node:e,assistantLabel:t,activePathIds:o,depth:n,isLast:s,parentLines:i,onSelect:a}){let{node:l,skipped:d}=si(e),c=o.has(l.entry.id),p=o.has(e.entry.id)||o.has(l.entry.id),u=function(e,t){if("message"===e.type&&"message"in e){let o=e.message,r=o.content,n="";if("string"==typeof r?n=r:Array.isArray(r)&&(n=r.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),n.length>40&&(n=n.slice(0,40)+"…"),n)return n;if("assistant"===o.role)return`[${t}]`}return e.type}(l.entry,t),g="message"===l.entry.type&&"message"in l.entry?l.entry.message.role:null;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>a(l.entry.id),children:[i.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:s?"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:c?"var(--accent)":p?"var(--text-muted)":"var(--border)",border:c?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),g&&(0,r.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===g?"var(--accent)":"var(--text-dim)",background:"user"===g?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===g?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===g?"U":"A"}),d>0&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",d]}),(0,r.jsx)("span",{style:{fontSize:11,color:c?"var(--text)":p?"var(--text-muted)":"var(--text-dim)",fontWeight:c?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:u})]}),l.children.map((e,d)=>(0,r.jsx)(sa,{node:e,assistantLabel:t,activePathIds:o,depth:n+1,isLast:d===l.children.length-1,parentLines:[...i,!s],onSelect:a},e.entry.id))]})}function sl({tree:e,activeLeafId:t,onLeafChange:o,inline:s,containerRef:i,open:a,onToggle:l,hasSession:d,embedded:c}){let{t:p}=(0,E.s)(),[u,g]=(0,n.useState)(!1),h=void 0!==a?a:u,m=(0,n.useRef)(null),[k,v]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!h||!s)return;let e=i?.current??m.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();v({top:t.bottom,left:t.left,width:t.width})};t();let o=new ResizeObserver(t);return o.observe(e),()=>o.disconnect()},[h,s,i]);let y=(0,n.useMemo)(()=>t?new Set(function e(o,r){for(let n of o){let o=[...r,n.entry.id];if(n.entry.id===t||n.compressedEntryIds?.includes(t))return o;let s=e(n.children,o);if(s)return s}return null}(e,[])??[]):new Set,[e,t]),b=(0,n.useCallback)(e=>{o(e)},[o]),w=d?!function e(t){for(let o of t)if(o.children.length>1||e(o.children))return!0;return!1}(e)?p("desktop.sessionHasNoBranches"):null:p("desktop.noActiveSession"),j=e.length>0?si(e[0]):null,S=j?.node??null,C=!w&&S&&S.children.length>1,T=(0,r.jsx)(f.Z,{size:16,"aria-hidden":"true",style:{flexShrink:0}}),z=(0,r.jsx)(x.a,{size:8,color:"var(--text-dim)","aria-hidden":"true",style:{marginLeft:1,transition:"transform 0.15s",transform:h?"rotate(180deg)":"none"}});return s?(0,r.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,r.jsx)("button",{ref:m,className:"app-no-drag",onClick:()=>l?l():g(e=>!e),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:h?"var(--bg-selected)":"none",border:"none",cursor:"pointer",color:h?"var(--text)":"var(--text-muted)",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=h?"var(--bg-selected)":"none",e.currentTarget.style.color=h?"var(--text)":"var(--text-muted)"},title:p("desktop.branches"),"aria-label":p("desktop.branches"),"aria-pressed":h,children:T}),h&&k&&(0,r.jsx)("div",{className:"app-no-drag",style:{position:"fixed",top:k.top,left:k.left,width:k.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:C&&S?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:S.children.map((e,t)=>(0,r.jsx)(sa,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:y,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w})})]}):c?C&&S?(0,r.jsx)("div",{style:{padding:"4px 8px 8px 8px"},children:S.children.map((e,t)=>(0,r.jsx)(sa,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:y,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 12px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w??p("desktop.sessionHasNoBranches")}):(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:[T,(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:p("desktop.branches")}),z]}),h&&(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&&S?(0,r.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:S.children.map((e,t)=>(0,r.jsx)(sa,{node:e,assistantLabel:p("desktop.assistant"),activePathIds:y,depth:0,isLast:t===S.children.length-1,parentLines:[],onSelect:b},e.entry.id))}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w??p("desktop.sessionHasNoBranches")})})]})}var sd=o(45390),sc=o(33846),sp=o(80388);function su({open:e,onOpenChange:t,cwd:o}){let{t:s}=(0,E.s)(),[i,a]=(0,n.useState)([]),[l,d]=(0,n.useState)(""),[p,u]=(0,n.useState)(!1),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(null),m=(0,n.useCallback)(async()=>{if(o)try{let e=await fetch(`/api/git/stash?${new URLSearchParams({cwd:o}).toString()}`,{cache:"no-store"});if(e.ok){let t=await e.json();a(t.entries)}}catch{}},[o]);if((0,n.useEffect)(()=>{e&&m()},[e,m]),!e)return null;let k=async(e,t)=>{u(!0),h(null),f(null);try{let r=await fetch(`/api/git/stash?${new URLSearchParams({cwd:o??""}).toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e,message:l||void 0,ref:t})}),n=await r.json();r.ok&&n.ok?(f(n.output??s("tasks.stashDone")),d(""),m()):h(n.error??`HTTP ${r.status}`)}catch(e){h(e instanceof Error?e.message:String(e))}finally{u(!1)}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",maxHeight:"min(75vh, 560px)",overflow:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("desktop.stashTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[(0,r.jsx)("input",{value:l,onChange:e=>d(e.target.value),placeholder:s("desktop.stashMessagePlaceholder"),style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"7px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit"}}),(0,r.jsxs)("button",{type:"button",onClick:()=>void k("push"),disabled:p,style:{alignSelf:"flex-start",display:"inline-flex",alignItems:"center",gap:5,padding:"7px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:p?"not-allowed":"pointer"},children:[(0,r.jsx)(sc.c,{size:13,"aria-hidden":"true"}),s("desktop.stashPush")]})]}),g&&(0,r.jsx)("div",{style:{padding:"8px 10px",borderRadius:8,background:"rgba(239,68,68,0.10)",color:"#ef4444",fontSize:12,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:g}),x&&(0,r.jsx)("div",{style:{padding:"8px 10px",borderRadius:8,background:"rgba(34,197,94,0.10)",color:"#22c55e",fontSize:12,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:x}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[(0,r.jsxs)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",marginBottom:6},children:[s("desktop.stashList")," (",i.length,")"]}),0===i.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:s("desktop.stashEmpty")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:i.map(e=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg)"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-muted)",flexShrink:0},children:e.index}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.message||e.ref}),(0,r.jsxs)("button",{type:"button",onClick:()=>void k("pop",e.ref),disabled:p,title:s("desktop.stashPop"),style:{display:"inline-flex",alignItems:"center",gap:3,padding:"4px 8px",borderRadius:6,border:"1px solid var(--border)",background:"none",color:"var(--text)",fontSize:11,cursor:p?"not-allowed":"pointer"},children:[(0,r.jsx)(w.S,{size:11,"aria-hidden":"true"}),s("desktop.stashPop")]}),(0,r.jsx)("button",{type:"button",onClick:()=>void k("drop",e.ref),disabled:p,title:s("desktop.stashDrop"),style:{display:"inline-flex",alignItems:"center",padding:"4px 8px",borderRadius:6,border:"1px solid var(--border)",background:"none",color:"#ef4444",fontSize:11,cursor:p?"not-allowed":"pointer"},children:s("desktop.stashDrop")})]},e.ref))})]})]})]})})}function sg({cwd:e}){let{t}=(0,E.s)(),[o,s]=(0,n.useState)(!1),[i,a]=(0,n.useState)("idle"),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(!1),u=(0,n.useCallback)(async()=>{if(e&&!o){s(!0),a("idle");try{let o=await fetch(`/api/git/push?${new URLSearchParams({cwd:e}).toString()}`,{method:"POST",cache:"no-store"}),r=await o.json();o.ok&&r.ok?(a("ok"),d(r.output||t("desktop.pushOk"))):(a("error"),d(r.error??t("desktop.pushFailed")))}catch(e){a("error"),d(e instanceof Error?e.message:t("desktop.pushFailed"))}finally{s(!1),setTimeout(()=>{a("idle"),d(null)},4e3)}}},[e,o,t]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:()=>void u(),disabled:!e||o,title:t("desktop.push"),"aria-label":t("desktop.push"),style:{position:"relative"},children:"ok"===i?(0,r.jsx)(oV.r,{size:13,color:"#22c55e",weight:"fill","aria-hidden":"true"}):"error"===i?(0,r.jsx)(sd.J,{size:13,color:"#ef4444",weight:"fill","aria-hidden":"true"}):(0,r.jsx)(sc.c,{size:13,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:()=>p(!0),disabled:!e,title:t("desktop.stash"),"aria-label":t("desktop.stash"),children:(0,r.jsx)(sp.T,{size:13,"aria-hidden":"true"})}),l&&(0,r.jsx)("div",{style:{position:"fixed",bottom:60,left:"50%",transform:"translateX(-50%)",zIndex:1200,maxWidth:"60vw",padding:"8px 14px",borderRadius:8,background:"var(--bg-panel)",border:`1px solid ${"ok"===i?"#22c55e":"#ef4444"}`,boxShadow:"0 8px 24px rgba(0,0,0,0.2)",fontSize:12,color:"ok"===i?"#22c55e":"#ef4444",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:l}),(0,r.jsx)(su,{open:c,onOpenChange:p,cwd:e})]})}function sh({onViewFullHistory:e,cwd:t,systemPrompt:o,sessionStats:s,contextUsage:i,hasSession:a,showChat:l,soundEnabled:d,onSoundToggle:c,onCompact:p,onAbortCompaction:g,isCompacting:h,compactError:x,branchTree:m,branchActiveLeafId:k,onBranchLeafChange:v,showSoundLabel:y,isDeepSeekOfficial:b,deepseekBalance:w,lastTurnUsage:j}){let{t:S}=(0,E.s)(),[C,T]=(0,n.useState)(null),z=(0,n.useCallback)(()=>T(null),[]),[R,I]=(0,n.useState)(null),M=(0,n.useRef)(null),P=(0,n.useCallback)((e,t)=>{tD(t).then(()=>{M.current&&clearTimeout(M.current),I(e),M.current=setTimeout(()=>I(null),1400)})},[]),D=(0,n.useMemo)(()=>{if(!o)return 0;let e=0;for(let t of o){let o=t.codePointAt(0)??0;o>=19968&&o<=40959||o>=13312&&o<=19903||o>=131072&&o<=173791||o>=12352&&o<=12447||o>=12448&&o<=12543||o>=44032&&o<=55215?e+=1:e+=.25}return Math.max(1,Math.round(e))},[o]),$=(0,n.useMemo)(()=>{if(!w?.available||null==w.totalBalance)return S("desktop.balanceUnavailable");let e=Number(w.grantedBalance)||0,t=Number(w.toppedUpBalance)||0;return`${S("desktop.balance")}:${oj(Number(w.totalBalance)||0)}(${S("desktop.balanceGranted")}:${oj(e)} / ${S("desktop.balanceToppedUp")}:${oj(t)})`},[w,S]);if(!l)return null;let F=s?.tokens,W=s?.cost??0,N=s?.costCNY??0,A=s?.costUSD??0,L=[];N>0&&L.push(oj(N)),A>0&&L.push(A>=.01?`$${A.toFixed(2)}`:"<$0.01"),0===L.length&&W>0&&L.push(W>=.01?`$${W.toFixed(2)}`:"<$0.01");let O=L.length>0?L.join(" + "):null,H="var(--text-muted)";if(i?.contextWindow){let e=i.percent;null!==e&&e>90?H="#ef4444":null!==e&&e>70&&(H="rgba(234,179,8,0.95)")}let B=null!==o&&""!==o,U=s&&F&&(F.input>0||F.output>0),_=a&&v,q=[];if(F&&(q.push(`${S("desktop.sessionInfoInput")}: ${F.input.toLocaleString()}`),q.push(`${S("desktop.sessionInfoOutput")}: ${F.output.toLocaleString()}`),F.cacheRead>0&&q.push(`${S("desktop.sessionInfoCacheRead")}: ${F.cacheRead.toLocaleString()}`),F.cacheWrite>0&&q.push(`${S("desktop.sessionInfoCacheWrite")}: ${F.cacheWrite.toLocaleString()}`),N>0&&q.push(`${S("desktop.sessionInfoCostOfficial")}: ${oj(N)}`),A>0&&q.push(`${S("desktop.sessionInfoCost")}: $${A.toFixed(4)}`),N<=0&&A<=0&&W>0&&q.push(`${S("desktop.sessionInfoCost")}: $${W.toFixed(4)}`)),i?.contextWindow&&null!==i.percent){let e=i.percent,t=i.tokens;q.push(`${S("desktop.sessionInfoContext")}: ${null!==e?`${e.toFixed(1)}%`:"?"} ${null!==t?ss(t):"?"}/${ss(i.contextWindow)}`)}let V=q.join(" | ");return(0,r.jsxs)("div",{className:"session-info-bar",children:[t&&(0,r.jsx)(sg,{cwd:t}),c&&(0,r.jsxs)("button",{type:"button",className:"session-info-bar-button",onClick:c,title:d?S("desktop.disableCompletionSound"):S("desktop.enableCompletionSound"),"aria-label":d?S("desktop.disableCompletionSound"):S("desktop.enableCompletionSound"),children:[d?(0,r.jsx)(se.Q,{size:13}):(0,r.jsx)(st.l,{size:13}),y&&(0,r.jsx)("span",{style:{marginLeft:4},children:d?S("desktop.soundLabelOn"):S("desktop.soundLabelOff")})]}),a&&(0,r.jsx)("button",{type:"button",className:"session-info-bar-button",onClick:e,title:S("desktop.viewFullHistory"),"aria-label":S("desktop.viewFullHistory"),children:(0,r.jsx)(so.n,{size:13,"aria-hidden":"true"})}),_&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${"branches"===C?" is-active":""}`,onClick:()=>T(e=>"branches"===e?null:"branches"),title:S("desktop.branches"),"aria-label":S("desktop.branches"),"aria-pressed":"branches"===C,children:(0,r.jsx)(f.Z,{size:13,"aria-hidden":"true"})}),"branches"===C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:z}),(0,r.jsxs)("div",{className:"session-info-bar-popover is-branches",children:[(0,r.jsxs)("div",{className:"session-info-bar-popover-header",children:[(0,r.jsx)("span",{className:"session-info-bar-popover-title",children:S("desktop.branches")}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-popover-close",onClick:z,title:S("i18n.close"),"aria-label":S("i18n.close"),children:"✕"})]}),(0,r.jsx)("div",{className:"session-info-bar-popover-body",children:(0,r.jsx)(sl,{tree:m??[],activeLeafId:k??null,onLeafChange:e=>{v(e),z()},hasSession:!0,embedded:!0})})]})]})]}),B&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${"system"===C?" is-active":""}`,onClick:()=>T(e=>"system"===e?null:"system"),title:S("desktop.systemPrompt"),"aria-label":S("desktop.systemPrompt"),"aria-pressed":"system"===C,children:(0,r.jsx)(r1.i,{size:13,"aria-hidden":"true"})}),"system"===C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:z}),(0,r.jsxs)("div",{className:"session-info-bar-popover is-system",children:[(0,r.jsxs)("div",{className:"session-info-bar-popover-header",children:[(0,r.jsx)("span",{className:"session-info-bar-popover-title",children:S("desktop.systemPrompt")}),(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:8},children:["~",ss(D)," tokens"]}),(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsx)("button",{type:"button",className:"session-info-bar-popover-close",onClick:z,title:S("i18n.close"),"aria-label":S("i18n.close"),children:"✕"})]}),(0,r.jsx)("div",{className:"session-info-bar-system-body",children:o?(0,r.jsx)(ta.oz,{remarkPlugins:[tL.A],children:o}):(0,r.jsx)("span",{className:"session-info-bar-popover-empty",children:"System prompt is empty (tools are disabled)"})})]})]})]}),(0,r.jsx)("div",{className:"session-info-bar-spacer"}),p&&(0,r.jsxs)("div",{className:"session-info-bar-compact-wrap",children:[x&&(0,r.jsx)("div",{className:"session-info-bar-compact-error",children:x}),(0,r.jsx)("button",{type:"button",className:`session-info-bar-button${h?" is-compacting":""}`,onClick:h?g:p,title:h?S("desktop.stopCompaction"):S("desktop.compactContext"),"aria-label":h?S("desktop.stopCompaction"):S("desktop.compactContext"),children:h?(0,r.jsx)(r3.M,{size:13}):(0,r.jsx)(sr.C,{size:13})})]}),b&&w?.available&&null!=w.totalBalance&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",style:{color:"var(--text-muted)",cursor:"default"},title:$,children:[(0,r.jsx)(sn.u,{size:11,"aria-hidden":"true"}),S("desktop.balance")," ",oj(Number(w.totalBalance)||0)]}),U&&(0,r.jsxs)("div",{className:"session-info-bar-popover-host",children:[(0,r.jsxs)("button",{type:"button",className:`session-info-bar-button is-stats${"session"===C?" is-active":""}`,onClick:()=>T(e=>"session"===e?null:"session"),title:V||S("desktop.sessionInfo"),"aria-label":S("desktop.sessionInfo"),"aria-pressed":"session"===C,children:[F&&F.input>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(oh.D,{size:10,"aria-hidden":"true"}),ss(F.input)]}),F&&F.output>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(og.y,{size:10,"aria-hidden":"true"}),ss(F.output)]}),F&&F.cacheRead>0&&(0,r.jsxs)("span",{className:"session-info-bar-token-chip",children:[(0,r.jsx)(om.W,{size:10,"aria-hidden":"true"}),ss(F.cacheRead)]}),O&&(0,r.jsx)("span",{children:O}),i?.contextWindow&&null!==i.percent&&(0,r.jsx)("span",{className:"session-info-bar-token-chip",style:{color:H},children:(0,r.jsxs)("svg",{className:"session-info-bar-donut",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",children:[(0,r.jsx)("circle",{cx:"8",cy:"8",r:"6.75",fill:"none",stroke:"var(--border)",strokeWidth:"2.5"}),(0,r.jsx)("circle",{className:"session-info-bar-donut-arc",cx:"8",cy:"8",r:"6.75",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",pathLength:100,strokeDasharray:100,strokeDashoffset:null===i.percent?0:100-Math.min(100,Math.max(0,i.percent)),transform:"rotate(-90 8 8)"})]})})]}),"session"===C&&s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-info-bar-popover-cover",onClick:z}),(0,r.jsx)("div",{className:"session-info-bar-popover is-session",children:(0,r.jsx)("div",{className:"session-stats-body",children:(()=>{let e=s.tokens,t=i??s.contextUsage,o=(e,t)=>{let o=R===e;return(0,r.jsx)("button",{type:"button",className:`session-stats-copy${o?" is-copied":""}`,title:o?S("desktop.copied"):"file"===e?S("desktop.copyFilePath"):S("desktop.copySessionId"),onClick:()=>P(e,t),children:o?(0,r.jsx)(u.J,{size:12,"aria-hidden":"true"}):(0,r.jsx)(ti.Q,{size:12,"aria-hidden":"true"})})},n=[];s.sessionName&&n.push((0,r.jsx)("div",{className:"session-stats-info-name",children:s.sessionName},"name")),n.push((0,r.jsxs)("div",{className:"session-stats-info-line",children:[(0,r.jsx)("span",{className:"session-stats-info-text",children:s.sessionFile?s.sessionFile.split(/[/\\]/).pop()??s.sessionFile:S("desktop.sessionInfoInMemory")}),s.sessionFile?o("file",s.sessionFile):null]},"file")),n.push((0,r.jsxs)("div",{className:"session-stats-info-line",children:[(0,r.jsx)("span",{className:"session-stats-info-text",children:s.sessionId}),o("id",s.sessionId)]},"id"));let a=[[S("desktop.sessionInfoUser"),s.userMessages.toLocaleString()],[S("desktop.sessionInfoAssistant"),s.assistantMessages.toLocaleString()],[S("desktop.sessionInfoToolCalls"),s.toolCalls.toLocaleString()],[S("desktop.sessionInfoToolResults"),s.toolResults.toLocaleString()],[S("desktop.sessionInfoTotal"),s.totalMessages.toLocaleString()]],l=[[S("desktop.sessionInfoInput"),e.input.toLocaleString()],[S("desktop.sessionInfoOutput"),e.output.toLocaleString()]];e.cacheRead>0&&l.push([S("desktop.sessionInfoCacheRead"),e.cacheRead.toLocaleString()]),e.cacheWrite>0&&l.push([S("desktop.sessionInfoCacheWrite"),e.cacheWrite.toLocaleString()]),l.push([S("desktop.sessionInfoTotal"),e.total.toLocaleString()]);let d=s.costCNY??0,c=s.costUSD??0;if(d>0&&l.push([S("desktop.sessionInfoCostOfficial"),oj(d)]),c>0&&l.push([S("desktop.sessionInfoCost"),`$${c.toFixed(4)}`]),d<=0&&c<=0&&s.cost>0&&l.push([S("desktop.sessionInfoCost"),`$${s.cost.toFixed(4)}`]),t?.contextWindow&&null!==t.percent){let e=t.percent,o=t.tokens;l.push([S("desktop.sessionInfoContext"),`${null!==e?`${e.toFixed(1)}%`:"?"} ${null!==o?ss(o):"?"}/${ss(t.contextWindow)}`])}(s.totalActiveMs??0)>0&&l.push([S("desktop.sessionInfoActiveTime"),function(e){if(e<=0)return"0s";let t=Math.floor(e/1e3),o=Math.floor(t/3600),r=Math.floor(t%3600/60),n=t%60;return o>0?`${o}h ${r}m`:r>0?`${r}m ${n}s`:`${n}s`}(s.totalActiveMs)]);let p=j?j.costCNY>0?oj(j.costCNY):j.costUSD>0?`$${j.costUSD.toFixed(4)}`:null:null,g=(e,t)=>(0,r.jsxs)("div",{className:"session-stats-row",children:[(0,r.jsx)("div",{className:"session-stats-label",children:e}),(0,r.jsx)("div",{className:"session-stats-value",children:t})]},e);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"session-stats-info-block",children:n}),(0,r.jsxs)("div",{className:"session-stats-side-by-side",children:[(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.sessionInfoMessages")}),(0,r.jsx)("div",{className:"session-stats-compact-grid",children:a.map(([e,t])=>g(e,t))})]}),(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.sessionInfoTokens")}),(0,r.jsx)("div",{className:"session-stats-compact-grid",children:l.map(([e,t])=>g(e,t))})]}),j&&(0,r.jsxs)("div",{className:"session-stats-column",children:[(0,r.jsx)("div",{className:"session-stats-section-title",children:S("desktop.turnUsageTitle")}),(0,r.jsxs)("div",{className:"session-stats-compact-grid",children:[g(S("desktop.sessionInfoInput"),j.input.toLocaleString()),g(S("desktop.sessionInfoOutput"),j.output.toLocaleString()),j.cacheRead>0&&g(S("desktop.sessionInfoCacheRead"),j.cacheRead.toLocaleString()),p&&g(S("desktop.sessionInfoCost"),p)]})]})]})]})})()})})]})]})]})}var sx=o(68635);function sf({scrollElementRef:e,items:t,estimateSize:o=120,overscan:s=8,virtualizerRef:i}){let a=(0,sx.Te)({count:t.length,getScrollElement:()=>e.current,estimateSize:(0,n.useCallback)(()=>o,[o]),overscan:s});a.shouldAdjustScrollPositionOnItemSizeChange=()=>!1,i&&(i.current=a);let l=(0,n.useRef)(!1),d=(0,n.useRef)(a);d.current=a,(0,n.useEffect)(()=>{l.current||0===t.length||e.current&&(l.current=!0,d.current.scrollToIndex(t.length-1,{align:"end"}))},[t.length,e]);let c=a.getVirtualItems();return(0,r.jsx)("div",{style:{position:"relative",width:"100%",minWidth:0,height:a.getTotalSize()},children:c.map(e=>(0,r.jsx)("div",{"data-index":e.index,ref:a.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",minWidth:0,overflow:"hidden",transform:`translateY(${e.start}px)`},children:t[e.index]},e.key))})}function sm(e){return e.replace(/<\/?[\w:-]+\b[^>]*>/g," ").replace(/<\/?[\w:-]+\b[^&]*?>/gi," ").replace(/\s+/g," ").trim()}function sk(e){return"user"===e.role||"assistant"===e.role&&(e.content??[]).some(e=>"text"===e.type)}function sv({messages:e,streamingMessage:t,scrollContainer:o,messageRefs:s,onWidthChange:i,virtualizer:a}){var l;let[d,c]=(0,n.useState)(0),[p,u]=(0,n.useState)(1),[g,h]=(0,n.useState)(!1),[x,f]=(0,n.useState)([]),[m,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(0),j=(0,n.useRef)(!1),S=(0,n.useRef)(null),C=(0,n.useMemo)(()=>t?[...e,t]:e,[e,t]),T=(0,n.useRef)(C);T.current=C;let z=(0,n.useCallback)(()=>{let e=o.current;if(!e)return;let t=e.scrollHeight,r=e.clientHeight,n=t-r;h(n>20),n<=0?(c(0),u(1)):(c(e.scrollTop/n),u(r/t))},[o]),R=(0,n.useRef)(null),I=(0,n.useRef)([]),M=(0,n.useRef)(a);M.current=a;let E=(0,n.useCallback)(()=>{R.current||(R.current=setTimeout(()=>{R.current=null;let e=o.current;if(!e)return;let t=e.scrollHeight;if(t<=0)return;let r=[],n=T.current,i=M.current;if(i){if(0>=i.totalHeight())return;let e=0;for(let o=0;o<n.length;o++){let s=n[o];if("user"!==s.role&&"assistant"!==s.role)continue;if(!sk(s)){e+=1;continue}let a=i.refToItemIndex(e);if(e+=1,void 0===a)continue;let l=i.getOffsetForIndex(a),d=i.sizeFor(a);r.push({topRatio:l/t,heightRatio:Math.max(d/t,1/t),msg:s,index:r.length})}}else{let o=s.current,i=0;for(let s=0;s<n.length;s++){let a=n[s];if("user"!==a.role&&"assistant"!==a.role)continue;let l=o?.[i];if(i++,sk(a)&&l){let o=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=o.top-n.top+e.scrollTop,i=o.height;r.push({topRatio:s/t,heightRatio:i/t,msg:a,index:r.length})}}}let a=I.current;a.length===r.length&&r.every((e,t)=>1e-6>Math.abs(e.topRatio-a[t].topRatio)&&1e-6>Math.abs(e.heightRatio-a[t].heightRatio))||(I.current=r,f(r))},150))},[o,s]);(0,n.useEffect)(()=>{let e=o.current;if(e)return e.addEventListener("scroll",z,{passive:!0}),()=>e.removeEventListener("scroll",z)},[o,z]),(0,n.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>{z(),E()},r=new ResizeObserver(t);return r.observe(e),e.firstElementChild&&r.observe(e.firstElementChild),t(),()=>{r.disconnect(),R.current&&(clearTimeout(R.current),R.current=null)}},[o,E,z]),(0,n.useEffect)(()=>{let e=setTimeout(()=>{z(),E()},50);return()=>clearTimeout(e)},[e.length,E,z]);let P=(0,n.useCallback)(e=>{let t=o.current;if(!t)return;let r=t.scrollHeight-t.clientHeight;r<=0||(t.scrollTop=Math.max(0,Math.min(1-p,e))/(1-p)*r)},[o,p]),D=(0,n.useCallback)(e=>{if(!g)return;j.current=!0;let t=e.currentTarget.getBoundingClientRect(),o=(e.clientY-t.top)/t.height,r=o-d*(1-p),n=r>=0&&r<=p?r:p/2;P(o-n);let s=e=>{j.current&&P((e.clientY-t.top)/t.height-n)},i=()=>{j.current=!1,window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",i)};window.addEventListener("mousemove",s),window.addEventListener("mouseup",i)},[g,p,d,P]);(0,n.useEffect)(()=>{if(!g)return void w(0);let e=S.current;if(!e)return;let t=()=>w(e.clientHeight),o=new ResizeObserver(t);return o.observe(e),t(),()=>o.disconnect()},[g]);let $=(0,n.useMemo)(()=>{if(b<=0)return[];let e=[];return x.map(t=>{let o=t.topRatio*b,r=Math.max(3,Math.min(46,t.heightRatio*b)),n=Math.max(0,o-r/2),s=Math.min(b,o+r/2),i=e.findIndex(e=>n>=e+1);return -1===i?(i=e.length,e.push(s)):e[i]=s,{...t,displayTopPx:o,lane:i}})},[x,b]),F=Math.max(18,4+5*(l=(0,n.useMemo)(()=>$.reduce((e,t)=>Math.max(e,t.lane+1),1),[$]))+(l-1)*1);if((0,n.useEffect)(()=>{i?.(g?F:18)},[F,i,g]),(0,n.useEffect)(()=>()=>i?.(18),[i]),!g)return null;let W=d*(1-p)*100,N=100*p,A=null!==v&&$.length>0?$.reduce((e,t)=>Math.abs(t.displayTopPx/b-v)<Math.abs($[e].displayTopPx/b-v)?t.index:e,0):null,L=null===A?null:$.find(e=>e.index===A)??null;return(0,r.jsxs)("div",{ref:S,onMouseDown:D,onMouseEnter:()=>k(!0),onMouseLeave:()=>{k(!1),y(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();y((e.clientY-t.top)/t.height)},style:{width:F,flexShrink:0,position:"relative",cursor:"pointer",userSelect:"none",background:"transparent",overflow:"visible"},children:[(0,r.jsx)("div",{style:{position:"absolute",left:1,right:1,top:`${W}%`,height:`${N}%`,background:"color-mix(in srgb, var(--text-muted) 14%, transparent)",pointerEvents:"none",zIndex:1}}),$.map(e=>{let t=function(e){if("user"===e.role)return"var(--accent)";let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?"var(--accent-red)":t.some(e=>"toolCall"===e.type)?"var(--accent-green)":"var(--text-dim)"}(e.msg),o=m&&L?.index===e.index,n="user"===e.msg.role,s=Math.max(3,Math.min(46,e.heightRatio*b)),i=2+6*e.lane;return(0,r.jsx)("div",{style:{position:"absolute",top:e.displayTopPx,transform:"translateY(-50%)",left:i,width:5,height:s,display:"flex",alignItems:"stretch",cursor:"pointer",zIndex:function(e){if("user"===e.role)return 6;let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?5:t.some(e=>"text"===e.type&&!!e.text?.trim())?4:t.some(e=>"toolCall"===e.type)?3:2}(e.msg)},children:(0,r.jsx)("div",{style:{width:"100%",height:"100%",borderRadius:1,background:t,opacity:o?1:n?.92:.72,transition:"opacity 0.1s, filter 0.1s",filter:o?"brightness(1.2)":"none"}})},e.index)}),m&&L&&(()=>{let e=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],o=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(o)return sm(o).slice(0,200);let r=t.filter(e=>"thinking"===e.type).map(e=>sm(e.thinking??"")).filter(Boolean).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(L.msg);if(!e)return null;let t=function(e){if("user"===e.role)return"var(--minimap-preview-user-bg)";let t=e.content??[];return t.some(e=>"toolCall"===e.type&&e.error)?"var(--minimap-preview-error-bg)":t.some(e=>"toolCall"===e.type)?"var(--minimap-preview-tool-bg)":"var(--minimap-preview-default-bg)"}(L.msg),o=Math.max(1,Math.min(5,Math.floor(b/120))),n=15*o+4,s=Math.max(n/2,Math.min(b-n/2,L.displayTopPx));return(0,r.jsx)("div",{style:{position:"absolute",top:s,transform:"translateY(-50%)",right:"100%",marginRight:6,background:t,border:"none",borderRadius:4,padding:"2px 7px",width:220,zIndex:100,pointerEvents:"none"},children:(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:"15px",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:o,overflow:"hidden",overflowWrap:"anywhere"},children:e})})})()]})}function sy(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let o=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:o}}async function sb(e,t){let o=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await o.json().catch(()=>({}));if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);return r.data}var sw=o(14755);function sj(){return"u">typeof performance?performance.now():Date.now()}function sS(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function sC(e){return e?"running_command"===e.phase||e.isBashRunning?{kind:"running_command"}:"waiting_model"===e.phase||e.isStreaming||e.isPromptRunning||e.isCompacting?{kind:"waiting_model"}:null:null}let sT=`Continue pursuing the active goal. Do the next useful work, then report your disposition:
|
|
28
|
+
- "continue" with the next concrete step;
|
|
29
|
+
- "complete" only when fully done and verified;
|
|
30
|
+
- "blocked" when only the user can unblock you.`,sz=["goal complete","[goal: complete]","goal is complete"],sR=["goal blocked","[goal: blocked]","blocked:"];function sI(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}let sM=`You are in PLAN MODE. Work as a read-only planning assistant.
|
|
31
|
+
- Analyze, read, search and reason about the codebase; do NOT modify any files.
|
|
32
|
+
- Do NOT run shell commands that mutate state, install packages, or start servers.
|
|
33
|
+
- When you have enough understanding, produce a concrete, step-by-step implementation plan.
|
|
34
|
+
- Structure the plan with clear phases, the files involved, and any risks or open questions.
|
|
35
|
+
- Do not write code yet — the plan itself is the deliverable.`,sE=["You are in PLAN MODE.","<economy-profile>","<delivery-profile>","<goal-profile>"],sP=new Set(["ArrowUp","ArrowDown","PageUp","PageDown","Home","End"," ","Space","Spacebar"]);class sD extends Error{constructor(e){super("timeout"===e?"Timed out connecting to the agent event stream. Please try again.":"Failed to connect to the agent event stream. Please try again."),this.status=e,this.name="EventStreamConnectionError"}}function s$(e){return new Promise(t=>setTimeout(t,e))}function sF(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,o)=>o===t?{...e,exiting:!0}:e)}function sW(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:sF(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:sF(e.visible)};case"remove":return function(e,t){let o=e,r=t;for(;r.length>0&&o.length<5;){let[e,...t]=r;o=[...o,e],r=t}return r.length>0&&!o.some(e=>e.exiting)&&(o=sF(o)),{visible:o,pending:r}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function sN(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 sA(e){let t,o=e.content;return"string"==typeof o?JSON.stringify({text:o,images:[]}):Array.isArray(o)?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:o.map(sN).filter(Boolean)}):JSON.stringify({text:"",images:[]})}function sL(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}let sO="pi-web:modes-global-default",sH="pi:open-tasks-view";function sB(e){return"assistant"===e.role?e5(e).length>0:"custom"===e.role}function sU(e,t,o={}){let r={...e,content:t};return o.omitUsage&&(r.usage=void 0),r}function s_({session:e,newSessionCwd:t,onAgentEnd:s,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:p,onSystemPromptChange:u,onSessionStatsChange:g,onSubagentsChange:h,onSessionStatsPanelOpen:x,onContextUsageChange:f,onOpenFile:m,onWorkspaceControlsHostChange:k,onViewFullHistory:v,systemPrompt:y}){var b;let w,{soundEnabled:j,onSoundToggle:S,playDoneSound:C,unlockAudio:T}=function(){let[e,t]=(0,n.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),o=(0,n.useRef)(e);(0,n.useEffect)(()=>{o.current=e},[e]);let r=(0,n.useRef)(null),s=(0,n.useCallback)(()=>{if(r.current&&"closed"!==r.current.state)return r.current;try{r.current=new AudioContext}catch{return null}return r.current},[]),i=(0,n.useCallback)((e=!1)=>{if(!e&&!o.current)return;let t=s();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[s]);return{soundEnabled:e,onSoundToggle:(0,n.useCallback)(()=>{let e=!o.current;e&&i(!0),o.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[i]),playDoneSound:(0,n.useCallback)(()=>{if(!o.current)return;let e=s();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((o,r)=>{let n=e.createOscillator(),s=e.createGain();n.connect(s),s.connect(e.destination),n.type="sine",n.frequency.value=o;let i=t+.18*r;s.gain.setValueAtTime(0,i),s.gain.linearRampToValueAtTime(.18,i+.02),s.gain.exponentialRampToValueAtTime(.001,i+.45),n.start(i),n.stop(i+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[s]),unlockAudio:i,soundEnabledRef:o}}(),z=rY(),{t:R}=(0,E.s)(),I=(0,n.useRef)(C);I.current=C;let M=(0,n.useRef)(j);M.current=j;let P=(0,n.useRef)(null),D=(0,n.useCallback)(()=>{M.current&&I.current(),s?.()},[s]),$=(0,n.useCallback)(e=>{let t=e;if("string"==typeof e.content){let o=eE(e.content);o&&(t={...e,content:o})}c?.current?.replaceMessage(t)},[c]),F=(0,n.useCallback)(e=>{c?.current?.prependText(e)},[c]),W=(0,n.useCallback)((e,t)=>{o0={text:e,projectRoot:t??null},window.dispatchEvent(new CustomEvent(oQ)),window.dispatchEvent(new Event(sH))},[]),{loading:N,error:A,messages:L,entryIds:O,streamState:H,agentRunning:B,bashRunning:U,pendingBash:_,modelNames:q,modelList:V,modelThinkingLevels:K,modelThinkingLevelMaps:J,modelScopeWarnings:G,toolPreset:Y,thinkingLevel:Z,retryInfo:X,contextUsage:Q,forkingEntryId:ee,isCompacting:et,compactError:eo,compactResult:er,displayModel:en,sessionStats:es,tokenRate:ei,slashCommands:ea,slashCommandsLoading:el,queuedMessages:ed,pendingRecovery:ec,recoveryIsImport:ep,notices:eu,extensionDialog:eg,extensionCustomUi:eh,extensionStatuses:ex,extensionWidgets:ef,respondToExtensionUi:em,sendExtensionCustomInput:ek,agentPhase:ev,isNew:eP,branchTree:eD,activeLeafId:e$,handleLeafChange:eF,sessionIdRef:eW,messagesEndRef:eN,scrollContainerRef:eA,lastUserMsgRef:eL,pendingScrollToUserRef:eO,initialScrollDoneRef:eH,scrollUserMsgToTop:eB,handleSend:eU,executeBash:e_,handleAbort:eq,handleFork:eV,handleNavigate:eK,handleModelChange:eJ,handleCompact:eG,handleSteer:eY,handleFollowUp:eZ,handlePromptWithStreamingBehavior:eX,handleAbortCompaction:eQ,handleRecallQueue:e0,resolveRecovery:e1,exportQueueData:e2,stageQueueImport:e4,moveQueuedMessage:e6,recallQueuedMessage:e5,requeueAt:e8,removeQueuedMessage:e7,handleBuiltinSlashCommand:te,handleToolPresetChange:tt,handleThinkingLevelChange:to,loadSlashCommands:tr,planMode:ti,handlePlanModeChange:ta,collaborationMode:tl,tokenMode:td,toolApprovalMode:tc,handleCollaborationModeChange:tp,handleTokenModeChange:tu,handleToolApprovalModeChange:tg,approvalRequests:th,resolveApproval:tx,goalState:tf,handleGoalStart:tm,handleGoalPause:tk,handleGoalResume:tv,handleGoalStop:ty}=function(e){let{session:t,newSessionCwd:r,onAgentEnd:s,onSessionCreated:i,onSessionForked:a,modelsRefreshKey:l,onBranchDataChange:d,onSystemPromptChange:c,onSessionStatsPanelOpen:p,onSubagentsChange:u}=e,g=null===t&&null!==r,h=`${t?.id??"new"}\0${r??t?.cwd??""}`,[x,f]=(0,n.useState)(null),[m,k]=(0,n.useState)(!g),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(null),[j,S]=(0,n.useState)([]),[C,T]=(0,n.useState)([]),[z,R]=(0,n.useReducer)(sS,{isStreaming:!1,streamingMessage:null}),[I,M]=(0,n.useState)(null),E=(0,n.useRef)({lastChars:0,window:[],charsPerToken:4}),P=(0,n.useCallback)(()=>{E.current={lastChars:0,window:[],charsPerToken:4},M(null)},[]),D=(0,n.useCallback)(e=>{if(!e||"assistant"!==e.role)return 0;let t=e.content;if(!Array.isArray(t))return 0;let o=0;for(let e of t)"string"==typeof e?o+=e.length:e&&"object"==typeof e&&("string"==typeof e.text?o+=e.text.length:"string"==typeof e.thinking&&(o+=e.thinking.length));return o},[]),$=(0,n.useCallback)(e=>{let t=D(e),o=E.current;if(t===o.lastChars)return;let r=Date.now(),n=Math.max(0,t-o.lastChars);o.lastChars=t,o.window.push({at:r,chars:n});let s=r-1e3;for(;o.window.length>0&&o.window[0].at<s;)o.window.shift();let i=o.window.reduce((e,t)=>e+t.chars,0),a=o.window.length>0?r-o.window[0].at:0;a<200||M(Math.max(0,Math.round(10*(i/Math.max(1,a)*1e3/o.charsPerToken))/10))},[D]),[F,W]=(0,n.useState)(!1),[N,A]=(0,n.useState)(!1),[L,O]=(0,n.useState)(null),[H,B]=(0,n.useState)({}),[U,_]=(0,n.useState)([]),[q,V]=(0,n.useState)({}),[K,J]=(0,n.useState)({}),[G,Y]=(0,n.useState)([]),[Z,X]=(0,n.useState)(null),[Q,ee]=(0,n.useState)(null),[et,eo]=(0,n.useState)("full"),[er,en]=(0,n.useState)(!1),es=(0,n.useRef)("default"),ei=(0,n.useRef)(!1);(0,n.useEffect)(()=>{ei.current=er},[er]);let[ea,el]=(0,n.useState)(()=>(function(){try{let e=window.localStorage.getItem(sO);if(!e)return null;let t=JSON.parse(e),o=t.permissionRules;return{collaborationMode:ej(t.collaborationMode),tokenMode:eS(t.tokenMode),toolApprovalMode:eC(t.toolApprovalMode),permissionRules:{allow:Array.isArray(o?.allow)?o.allow:[],ask:Array.isArray(o?.ask)?o.ask:[],deny:Array.isArray(o?.deny)?o.deny:[]}}}catch{return null}})()??{collaborationMode:ey,tokenMode:eb,toolApprovalMode:ew,permissionRules:{allow:[],ask:[],deny:[]}}),ed=(0,n.useRef)(null),ec=(0,n.useRef)(!1),ep=(0,n.useRef)(t?.id??null);ep.current=t?.id??null,(0,n.useEffect)(()=>{let e=!1,t=async()=>{let t=ep.current,o=t?`?session=${encodeURIComponent(t)}`:"";try{let r=await fetch(`/api/modes${o}`);if(!r.ok||e)return;let n=await r.json();if(e)return;let s={collaborationMode:ej(n.collaborationMode),tokenMode:eS(n.tokenMode),toolApprovalMode:eC(n.toolApprovalMode),permissionRules:{allow:Array.isArray(n.permissionRules?.allow)?n.permissionRules.allow:[],ask:Array.isArray(n.permissionRules?.ask)?n.permissionRules.ask:[],deny:Array.isArray(n.permissionRules?.deny)?n.permissionRules.deny:[]}};if(!ec.current&&t&&"plan"===s.collaborationMode){let o=await fetch("/api/modes").catch(()=>null);if(!e&&o?.ok){let r=await o.json().catch(()=>null);if(!e&&r){let e=s.collaborationMode;(s={...s,collaborationMode:ej(r.collaborationMode)}).collaborationMode!==e&&fetch(`/api/modes?session=${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).catch(()=>{})}}}ec.current=!0,el(s),t||function(e){try{window.localStorage.setItem(sO,JSON.stringify(e))}catch{}}(s)}catch{}};t();let o=()=>void t();return window.addEventListener("pi:modes-changed",o),()=>{e=!0,ec.current=!1,window.removeEventListener("pi:modes-changed",o)}},[t?.id]);let eu=ea.collaborationMode,eg=ea.tokenMode,eh=ea.toolApprovalMode,ex=ea.permissionRules,ef=(0,n.useRef)(eu),em=(0,n.useRef)(eg),ek=(0,n.useRef)(eh),ev=(0,n.useRef)(ea.permissionRules),eP=(0,n.useRef)(null),eD=(0,n.useRef)({sessionKey:"",signature:""}),e$=(0,n.useRef)(ea);(0,n.useEffect)(()=>{e$.current=ea},[ea]),(0,n.useEffect)(()=>{ek.current=eh},[eh]),(0,n.useEffect)(()=>{ev.current=ea.permissionRules},[ea.permissionRules]),(0,n.useEffect)(()=>{ef.current=eu,eD.current={sessionKey:"",signature:""}},[eu]),(0,n.useEffect)(()=>{em.current=eg,eD.current={sessionKey:"",signature:""}},[eg]);let[eF,eW]=(0,n.useState)([]),eN=(0,n.useRef)([]);(0,n.useEffect)(()=>{eN.current=eF},[eF]);let[eA,eL]=(0,n.useState)({status:"idle",goalText:null,turnsUsed:0,turnsLimit:10,noProgressTurns:0,noProgressLimit:4,tokensUsed:0}),eO=(0,n.useRef)(eA);(0,n.useEffect)(()=>{eO.current=eA},[eA]);let eH=(0,n.useRef)(!1);(0,n.useRef)(0);let[eB,eU]=(0,n.useState)("auto"),[e_,eq]=(0,n.useState)(null),[eV,eK]=(0,n.useState)(null),[eJ,eG]=(0,n.useState)(null),[eY,eZ]=(0,n.useState)(null),[eX,eQ]=(0,n.useState)(null),[e0,e1]=(0,n.useState)(null),[e2,e4]=(0,n.useState)(!1),[e6,e5]=(0,n.useState)(null),[e3,e8]=(0,n.useState)(null),[e7,e9]=(0,n.useState)(null),[te,tt]=(0,n.useState)(!1),[to,tr]=(0,n.useState)([]),[tn,ts]=(0,n.useState)(!1),[ti,ta]=(0,n.useReducer)(sW,{visible:[],pending:[]}),[tl,td]=(0,n.useState)(null),[tc,tp]=(0,n.useState)(null),[tu,tg]=(0,n.useState)(null),[th,tx]=(0,n.useState)([]),[tf,tm]=(0,n.useState)([]),[tk,tv]=(0,n.useState)({steering:[],followUp:[]}),[ty,tb]=(0,n.useState)([]),[tw,tj]=(0,n.useState)(!1),[tS,tC]=(0,n.useState)([]),tT=(0,n.useRef)([]),tz=(0,n.useMemo)(()=>new Set(["Agent","Task"]),[]),tR=(0,n.useCallback)(e=>{tC(t=>{let o=e(t);return tT.current=o,o})},[]),tI=(0,n.useCallback)((e,t)=>{tR(o=>{if(o.some(t=>t.id===e))return o;let r="string"==typeof t.description&&t.description.trim()?t.description.trim():"string"==typeof t.prompt?t.prompt.slice(0,80):"Agent";return[...o,{id:e,agentType:"string"==typeof t.subagent_type&&t.subagent_type?t.subagent_type:"Agent",description:r,status:"running",startedAt:Date.now()}].slice(-20)})},[tR]),tM=(0,n.useCallback)(e=>{let t="string"==typeof e.id?e.id:"",o="string"==typeof e.type?e.type:"Agent",r="string"==typeof e.description?e.description:"",n="string"==typeof e.status?e.status:"",s="error"===n||"aborted"===n?"failed":"stopped"===n?"stopped":"completed",i="number"==typeof e.startedAt?e.startedAt:Date.now(),a="number"==typeof e.completedAt?e.completedAt:Date.now(),l="object"==typeof e.tokens&&null!==e.tokens?{input:e.tokens.input,output:e.tokens.output,total:e.tokens.total}:void 0,d="number"==typeof e.toolUses?e.toolUses:void 0,c="string"==typeof e.error&&e.error?e.error:void 0;tR(e=>{let n=e.findIndex(e=>e.id===t||e.agentType===o&&e.description===r),p={id:t||e[n]?.id||`${o}-${i}`,agentType:o,description:r,status:s,startedAt:i,completedAt:a,tokens:l,toolUses:d,error:c};if(n>=0){let t=[...e];return t[n]=p,t}return[...e,p].slice(-20)})},[tR]),tE=(0,n.useCallback)(e=>{tR(t=>t.map(t=>t.id!==e||"running"!==t.status?t:{...t,status:"completed",completedAt:Date.now()}))},[tR]),tP=(0,n.useRef)(null),tD=(0,n.useCallback)(()=>{tP.current&&clearTimeout(tP.current),tP.current=setTimeout(async()=>{tP.current=null;let e=tH.current;if(e)try{let t=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!t.ok)return;let o=await t.json();o.state?.queuedMessages!==void 0&&tv(sI(o.state.queuedMessages))}catch{}},8e3)},[]),t$=(0,n.useCallback)(()=>{tP.current&&(clearTimeout(tP.current),tP.current=null)},[]),tF=(0,n.useRef)(null),tW=(0,n.useRef)(null),tN=(0,n.useRef)(null),tA=(0,n.useRef)(null),tL=(0,n.useRef)(0),tO=(0,n.useRef)(!1),tH=(0,n.useRef)(t?.id??null),tB=(0,n.useRef)(!1),tU=(0,n.useRef)(!1),t_=(0,n.useRef)(!1),tq=(0,n.useRef)(-1),tV=(0,n.useRef)(!1),tK=(0,n.useRef)(null),tJ=(0,n.useRef)(!1),tG=(0,n.useRef)(null),tY=(0,n.useRef)(!1),tZ=(0,n.useRef)(!0),tX=(0,n.useRef)(!0),tQ=(0,n.useRef)(0),t0=(0,n.useRef)(0),t1=(0,n.useRef)(null),t2=(0,n.useRef)(null),t4=(0,n.useRef)(null),t6=(0,n.useRef)(!1),t5=(0,n.useRef)(0),t3=(0,n.useRef)(null),t8=(0,n.useRef)(0),t7=(0,n.useRef)(0),t9=(0,n.useRef)(null),oe=(0,n.useRef)(h);oe.current=h;let ot=(0,n.useRef)(null),oo=(0,n.useRef)(null),or=(0,n.useRef)(null);or.current||(or.current=function(e,t={}){let o,r=1e3/Math.max(1,t.maxUpdatesPerSecond??30),n=t.now??sj,s=t.requestFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame:void 0),i=t.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame:void 0),a=t.setTimer??setTimeout,l=t.clearTimer??clearTimeout,d=!1,c=!1,p=null,u=null,g=null,h=()=>{null!==p&&(i?.(p),p=null),null!==u&&(l(u),u=null)},x=(t,r)=>{if(!c||d)return;let n=o;c=!1,o=void 0,g=t;let s=()=>{d||e(n)};r&&"function"==typeof queueMicrotask?queueMicrotask(s):s()},f=()=>{if(!d&&c&&null===p&&null===u){if(!s){let e=null===g?r:n()-g;u=a(()=>{u=null,x(n(),!0),f()},Math.max(0,r-e));return}p=s(e=>{if(p=null,d||!c)return;let t=null===g?r:e-g;if(t<r){u=a(()=>{u=null,f()},r-t);return}x(e,!0),f()})}};return{enqueue(e){d||(o=e,c=!0,f())},flush(){!d&&c&&(h(),x(n(),!1),f())},reset(){h(),c=!1,o=void 0,g=null},destroy(){d||(d=!0,h(),c=!1,o=void 0)}}}(e=>{R({type:"update",message:e})}));let on=(0,n.useCallback)(()=>{or.current?.reset()},[]),os=(0,n.useCallback)(e=>{or.current?.enqueue(e)},[]),oi=e.setToolPreset??eo,oa=x?.context.model,ol=oa&&oa.provider&&oa.modelId?oa:null,od=eX??ol??e0??null,oc=g?Z??Q:od,op=(0,n.useMemo)(()=>{if(tl)return{...tl,totalActiveMs:x?.totalActiveMs};let e={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},o=0,r=0,n=0,s=0,i=0,a=0,l=0;for(let t of j){if("user"===t.role&&(s+=1),"toolResult"===t.role&&(a+=1),"assistant"!==t.role)continue;i+=1;let d=t.usage;if(l+=t.content.filter(e=>"toolCall"===e.type).length,!d)continue;e.input+=d.input??0,e.output+=d.output??0,e.cacheRead+=d.cacheRead??0,e.cacheWrite+=d.cacheWrite??0;let c=d.cost?.total??0;o+=c,ob(t.model)?r+=ow(t.model,d):n+=c}return(e.total=e.input+e.output+e.cacheRead+e.cacheWrite,0===e.total&&0===j.length)?null:{sessionFile:x?.filePath||void 0,sessionId:tH.current??t?.id??"",sessionName:t?.name,userMessages:s,assistantMessages:i,toolCalls:l,toolResults:a,totalMessages:j.length,tokens:e,cost:o,costCNY:r,costUSD:n,totalActiveMs:x?.totalActiveMs,...eV?{contextUsage:eV}:{}}},[j,tl,eV,x?.filePath,x?.totalActiveMs,t?.id,t?.name]),ou=(0,n.useCallback)(async(e,t=!1,o=!1)=>{let r=!1;try{t&&k(!0);let n=new URLSearchParams({deferThinking:"1",deferMedia:"1"}),s=await fetch(`/api/sessions/${encodeURIComponent(e)}?${n}`);if(404===s.status)return t&&(f(null),w(null),S([]),y(null),tR(()=>[])),null;if(!s.ok)throw Error(`HTTP ${s.status}`);let i=await s.json();if(tH.current!==e||(f(i),w(i.leafId),S(i.context.messages),T(i.context.entryIds??[]),eQ(e=>e?i.context.model&&e.provider===i.context.model.provider&&e.modelId===i.context.model.modelId?null:e:null),y(null),i.context.thinkingLevel&&"off"!==i.context.thinkingLevel&&eU(i.context.thinkingLevel),r=!0,t&&k(!1),!o))return null;try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)throw Error(`HTTP ${t.status}`);let o=await t.json();if(tH.current!==e)return null;let r=o.state;return r?(void 0!==r.contextUsage&&eK(r.contextUsage??null),void 0!==r.systemPrompt&&eG(r.systemPrompt??null),void 0!==r.thinkingLevel&&eU(r.thinkingLevel??"auto"),void 0!==r.extensionStatuses&&tx(r.extensionStatuses??[]),void 0!==r.extensionWidgets&&tm(r.extensionWidgets??[]),void 0!==r.queuedMessages&&tv(sI(r.queuedMessages)),void 0!==r.pendingRecovery&&tb(r.pendingRecovery??[])):o.running||tv({steering:[],followUp:[]}),o}catch(e){return console.error("Failed to load agent state:",e),null}}catch(e){return y(String(e)),null}finally{t&&!r&&k(!1)}},[tR]),og=(0,n.useCallback)(async(e,t)=>{try{let o=new URLSearchParams({deferThinking:"1",deferMedia:"1"});t&&o.set("leafId",t);let r=`/api/sessions/${encodeURIComponent(e)}/context?${o}`,n=await fetch(r);if(!n.ok)throw Error(`HTTP ${n.status}`);let s=await n.json();S(s.context.messages),T(s.context.entryIds??[])}catch(e){console.error("Failed to load context:",e)}},[]),oh=(0,n.useCallback)(async e=>{try{let t=await sb(e,{type:"get_tools"});if(t){let{getPresetFromTools:r}=await Promise.resolve().then(o.bind(o,14755)),n=r(t);"plan"!==n||ei.current?oi(n):(await sb(e,{type:"set_tools",toolNames:(0,sw.xG)("default")}).catch(()=>{}),oi("default"))}}catch(e){console.error("Failed to load tools:",e)}},[oi]),ox=(0,n.useCallback)((e=0,t="(no messages)")=>{let o=tH.current;g&&r&&o&&!t6.current&&(t6.current=!0,i?.({id:o,path:"",cwd:r,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:e,firstMessage:t}))},[g,r,i]),of=(0,n.useCallback)(async()=>{if(tH.current||!g||!r)return tH.current;if(t4.current)return t4.current;let e=(async()=>{let e=ot.current,t=oo.current;e&&e1(e);let o=(0,sw.xG)(et),n=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,type:"ensure_session",toolNames:o,...e?{provider:e.provider,modelId:e.modelId}:{},...t?{thinkingLevel:t}:{}})});if(!n.ok){let e=await n.json().catch(()=>null);throw Error(e?.error??`HTTP ${n.status}`)}let s=await n.json();tH.current=s.sessionId;let i=ed.current;return i&&(ed.current=null,fetch(`/api/modes?session=${encodeURIComponent(s.sessionId)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(e=>{console.error("Failed to persist pending mode settings:",e)})),s.model&&ot.current===e&&(e1(s.model),e||ee(s.model)),s.thinkingLevel&&oo.current===t&&eU(s.thinkingLevel),s.sessionId})();t4.current=e;try{return await e}finally{t4.current=null}},[g,r,et]),om=(0,n.useCallback)(async()=>{let e=tH.current??await of();if(!e)return tr([]),[];ts(!0);try{let t=await sb(e,{type:"get_commands"}),o=t?.commands??[];return tr(o),o}catch(e){return console.error("Failed to load slash commands:",e),tr([]),[]}finally{ts(!1)}},[of]),ok=(0,n.useCallback)(()=>{tL.current+=1,tO.current=!1,tA.current&&(clearTimeout(tA.current),tA.current=null)},[]),ov=(0,n.useCallback)(()=>{tF.current?.close(),tF.current=null,tW.current=null,tN.current=null},[]),oy=(0,n.useCallback)(e=>{ov();let t=new EventSource(`/api/agent/${encodeURIComponent(e)}/events`);tF.current=t,tW.current=e;let o=new Promise(o=>{let r=!1,n=e=>{r||(r=!0,clearTimeout(s),tN.current?.source===t&&(tN.current.pending=!1),o({status:e,source:t}))},s=setTimeout(()=>n("timeout"),3e4);t.onmessage=e=>{try{let t=JSON.parse(e.data);"connected"===t.type&&n("connected"),tK.current?.(t)}catch{}},t.onerror=()=>{if(t.readyState!==EventSource.CLOSED||(n("closed"),tF.current!==t||!tB.current&&!tO.current))return;tF.current=null,tW.current=null,tN.current=null;let o=tL.current;setTimeout(()=>{o===tL.current&&!tF.current&&(tB.current||tO.current)&&oy(e)},1e3)}});return tN.current={source:t,promise:o,pending:!0},o},[ov]),oj=(0,n.useCallback)(async e=>{let t=tF.current;if(t&&tW.current===e){if(t.readyState===EventSource.OPEN)return;let e=tN.current;if(e?.source===t&&e.pending&&(await e.promise,tF.current===t&&t.readyState===EventSource.OPEN))return}let o=await oy(e);if("connected"!==o.status&&o.source.readyState!==EventSource.OPEN)throw tF.current===o.source&&(tF.current=null),tW.current===e&&(tW.current=null),tN.current?.source===o.source&&(tN.current=null),o.source.close(),new sD(o.status)},[oy]),oS=(0,n.useCallback)(async(e,t)=>{let o=tH.current;if(tp(t=>t?.id===e.id?null:t),o)try{await sb(o,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),oC=(0,n.useCallback)(async(e,t)=>{let o=tH.current;if(o)try{await sb(o,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),oT=(0,n.useCallback)(e=>{let t=e.message.trim();if(!t)return;let o=e.type??"info";("error"===o||"warning"===o)&&fetch("/api/logs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({level:o,source:"agent-notice",sessionId:tH.current??void 0,message:t})}).catch(()=>{}),ta({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:o}})},[]),oz=(0,n.useCallback)(t=>{switch(t.method){case"select":case"confirm":case"input":case"editor":tp(t);break;case"notify":oT({id:t.id,message:t.message,type:t.notifyType??"info"});break;case"setStatus":tx(e=>{let o=e.filter(e=>e.key!==t.statusKey);return t.statusText?[...o,{key:t.statusKey,text:t.statusText}]:o});break;case"setWidget":tm(e=>{let o=e.filter(e=>e.key!==t.widgetKey);return t.widgetLines?[...o,{key:t.widgetKey,lines:t.widgetLines,placement:t.widgetPlacement??"aboveEditor"}]:o});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":tg(e=>t.closed?e?.id===t.id?null:e:t)}},[oT,e.chatInputRef]),oR=(0,n.useRef)(null),oI=(0,n.useCallback)(()=>{null!==oR.current&&(cancelAnimationFrame(oR.current),oR.current=null)},[]),oM=(0,n.useCallback)(()=>{on(),oI();let e=tB.current;return tB.current=!1,W(!1),e9(null),eq(null),R({type:"end"}),e},[oI,on]),oE=(0,n.useCallback)(e=>tq.current!==e&&(tq.current=e,s?.(),!0),[s]),oP=(0,n.useCallback)(e=>{ok(),tO.current=!0;let t=tL.current,o=async()=>{if(t===tL.current&&tH.current===e&&tO.current)try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let n=await r.json();if(t!==tL.current||tH.current!==e||!tO.current)return;let s=n.state;if(n.running&&s&&(s.isStreaming||s.isPromptRunning)){tO.current=!1,tA.current=null,tU.current=!!s?.isStreaming,t_.current=!!s?.isPromptRunning,tB.current=!0,W(!0),e9(sC(s));return}if(n.running&&s?.isCompacting){e4(!0),tA.current=setTimeout(()=>void o(),600);return}tO.current=!1,tA.current=null,ov()}catch{if(t!==tL.current||tH.current!==e||!tO.current)return;tA.current=setTimeout(()=>void o(),600)}};tA.current=setTimeout(()=>void o(),12e4)},[ok,ov]),oD=(0,n.useCallback)(async(e=tH.current,t=t5.current)=>{if(t5.current===t)try{e&&await ou(e)}finally{if(t5.current!==t)return;let o=t_.current,r=tU.current;t_.current=!1,tU.current=!1,t3.current=null;let n=oM();o?oE(t):r&&n&&s?.(),e&&oP(e)}},[ou,oE,s,oP,oM]),o$=(0,n.useCallback)(async(e,t=t5.current)=>{await s$(800);let o=Date.now();for(;tB.current&&Date.now()-o<2e4;){if(t5.current!==t)return;try{let o=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(o.ok){let r=await o.json(),n=r.state;if(!r.running||!n||!n.isStreaming&&!n.isPromptRunning)return void await oD(e,t)}}catch{}await s$(600)}},[oD]),oF=(0,n.useCallback)(async e=>{if(!tB.current)return;let t=t5.current;try{let o=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!o.ok)return;let r=await o.json();if(t5.current!==t)return;let n=r.state;if(e4(n?.isCompacting??!1),e9(sC(n)),tv(sI(n?.queuedMessages)),tb(n?.pendingRecovery??[]),r.running&&n&&(n.isStreaming||n.isPromptRunning||n.isBashRunning||n.isCompacting)||!tB.current)return;n&&(void 0!==n.contextUsage&&eK(n.contextUsage??null),void 0!==n.systemPrompt&&eG(n.systemPrompt??null),void 0!==n.extensionStatuses&&tx(n.extensionStatuses??[]),void 0!==n.extensionWidgets&&tm(n.extensionWidgets??[])),await oD(e,t)}catch{}},[oD]);(0,n.useEffect)(()=>{if(!F)return;let e=()=>{let e=tH.current;e&&oF(e)},t=()=>{"visible"===document.visibilityState&&e()},o=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(o),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[F,oF]),(0,n.useEffect)(()=>{tB.current=F,F||tt(!1)},[F]);let oW=(0,n.useCallback)((t="smooth")=>{t0.current=Date.now()+700;let o=t2.current,r=t1.current;if(!o||!r)return;let n=Math.max(88,e.chatInputRef?.current?.measureHeight?.()??0),s=()=>{if(!o||!r)return;let e=Math.max(0,r.getBoundingClientRect().top-o.getBoundingClientRect().top+o.scrollTop-96-o.clientHeight+n);o.scrollTo({top:e,behavior:t})};s(),("instant"===t||"auto"===t)&&window.setTimeout(()=>{o&&r&&tX.current&&s()},200)},[]),oN=(0,n.useCallback)(()=>{null===oR.current&&(oR.current=requestAnimationFrame(()=>{oR.current=null,requestAnimationFrame(()=>{if(!tB.current||Date.now()<tQ.current)return;let e=t2.current;if(e){let{scrollTop:t,clientHeight:o,scrollHeight:r}=e;tX.current=t+o>=r-150}tX.current&&oW("auto")})}))},[oW]);tK.current=(0,n.useCallback)(e=>{switch(e.type){case"agent_start":on(),P(),ok(),tU.current=!0,tB.current=!0,W(!0),e9({kind:"waiting_model"}),R({type:"start"}),oN();break;case"agent_end":{if(on(),P(),!tB.current)break;if(e9(null),eq(null),R({type:"end"}),!0!==e.willRetry){let t=e.messages??[];for(let e=t.length-1;e>=0;e--){let o=t[e];if(o?.role==="assistant"){"error"===o.stopReason&&o.errorMessage&&oT({type:"error",message:o.errorMessage});break}}}let t=tH.current;t&&(ou(t),fetch(`/api/agent/${encodeURIComponent(t)}`).then(e=>e.ok?e.json():void 0).then(e=>{let t=e?.state;t?.contextUsage!==void 0&&eK(t.contextUsage??null),t?.systemPrompt!==void 0&&eG(t.systemPrompt??null),t?.extensionStatuses!==void 0&&tx(t.extensionStatuses??[]),t?.extensionWidgets!==void 0&&tm(t.extensionWidgets??[]),tv(sI(t?.queuedMessages)),tb(t?.pendingRecovery??[])}).catch(()=>{}));break}case"agent_settled":{let e=tU.current;if(tU.current=!1,!e||t_.current)break;let t=tH.current,o=oM();e4(!1),t&&(ou(t),oP(t)),o&&s?.(),"goal"===ef.current&&"running"===eO.current.status&&rg.current?.drive();break}case"prompt_done":{let e=t5.current,t=t_.current;t_.current=!1,t3.current=null;let o=oE(e);if(!t&&!o)break;let r=tH.current;r&&ou(r),!tU.current&&(oM(),r&&oP(r));break}case"tool_approval_request":{let t={id:String(e.id??""),toolName:String(e.toolName??""),args:e.args};if(!t.id)break;eW(e=>e.some(e=>e.id===t.id)?e:[...e,t]);break}case"tool_approval_resolved":{let t=String(e.id??"");if(!t)break;eW(e=>e.filter(e=>e.id!==t));break}case"opencode_zen_switch":e.sessionId&&e.sessionId!==tH.current||oT({type:"success",message:`OpenCode Zen 已切换账号和代理:${String(e.to??"unknown")}`});break;case"prompt_error":oT({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":oT({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":{if(!tB.current)break;let t=e.message;if(t?.role==="user")break;t&&($(t),os(sy(t))),e9(e=>null===e?e:null),oN();break}case"message_end":{if(!tB.current)break;let t=e.message;if(t&&"user"===t.role){let e=sy(t);if("user"===e.role&&"content"in e){let t=e.content;if("string"==typeof t)sE.some(e=>t.startsWith(e))&&(e={...e,content:eE(t)});else if(Array.isArray(t)){let o=t.filter(e=>"text"===e.type)[0];o&&"string"==typeof o.text&&sE.some(e=>o.text?.startsWith(e))&&(e={...e,content:t.map((e,t)=>{if("text"!==e.type||0!==t)return e;let o=eE(e.text??"");return{...e,text:o}})})}}let o=sA(e),r=t3.current;t3.current=null,S(t=>{let n=t[t.length-1];return r&&n?.role==="user"&&sA(n)===r?r===o?t:[...t.slice(0,-1),e]:[...t,e]})}else t&&S(e=>[...e,sy(t)]);on(),R({type:"reset"}),e9({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,o=e.toolName;if(tz.has(o)){let o=e.args;tI(t,"object"==typeof o&&null!==o?o:{})}e9(e=>{let r=e?.kind==="running_tools"?[...e.tools]:[];return r.some(e=>e.id===t)||r.push({id:t,name:o}),{kind:"running_tools",tools:r}});break}case"tool_execution_end":{let t=e.toolCallId;tz.has(e.toolName)&&tE(t),e9(e=>{if(e?.kind!=="running_tools")return e;let o=e.tools.filter(e=>e.id!==t);return 0===o.length?{kind:"waiting_model"}:{kind:"running_tools",tools:o}});break}case"entry_appended":{let t=e.entry;t?.customType==="subagents:record"&&"object"==typeof t.data&&null!==t.data&&tM(t.data);break}case"queue_update":tv({steering:[...e.steering??[]],followUp:[...e.followUp??[]]}),(e.steering??[]).length>0||(e.followUp??[]).length>0?tD():t$();break;case"state_sync":{let t=e.state;if(!t)break;if(e4(t.isCompacting??!1),e9(sC(t)),tv(sI(t.queuedMessages)),tb(t.pendingRecovery??[]),void 0!==t.contextUsage&&eK(t.contextUsage??null),void 0!==t.systemPrompt&&eG(t.systemPrompt??null),void 0!==t.extensionStatuses&&tx(t.extensionStatuses??[]),void 0!==t.extensionWidgets&&tm(t.extensionWidgets??[]),t.isStreaming||t.isPromptRunning||t.isBashRunning||t.isCompacting)tB.current=!0,W(!0),R({type:"start"});else if(tB.current&&!t_.current){let e=tH.current;e&&oD(e,t5.current)}break}case"auto_retry_start":eq({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":eq(null);break;case"auto_compaction_start":case"compaction_start":e4(!0),e5(null),e8(null);break;case"auto_compaction_end":case"compaction_end":e4(!1),e.errorMessage?(e5(e.errorMessage),e8(null)):!e.aborted&&(e8(sL(e.result,e.reason??"auto")),tH.current&&ou(tH.current));break;case"extension_ui_request":oz(e)}},[oT,ok,oI,oD,oz,ou,oE,s,oP,oN,oM,os,on,tD,t$,tI,tM,tE,tz,$,P]),(0,n.useEffect)(()=>{let e=new EventSource("/api/events");return e.onmessage=e=>{try{let t=JSON.parse(e.data);if(!t||!t.type||!t.payload||t.sessionId!==tH.current||tF.current?.readyState===EventSource.OPEN)return;tK.current?.(t.payload)}catch{}},()=>e.close()},[]);let oA=(0,n.useCallback)(async(e,o)=>{let n,s=e.trim();if(!s&&!o?.length||tB.current||tV.current)return;let i=!o?.length&&s.startsWith("/"),a=t5.current+1;ok(),on(),t_.current=!0;let l=function(e){let t=[];if("plan"===e.collaborationMode&&t.push(ez),"economy"===e.tokenMode&&t.push(eR),"delivery"===e.tokenMode&&t.push(eI),"goal"===e.collaborationMode){let o=e.goalText?.trim();t.push(o?`${eM}
|
|
36
|
+
|
|
37
|
+
Goal: ${o}`:eM)}return t.join("\n\n")}({collaborationMode:ef.current,tokenMode:em.current,goalText:"goal"===ef.current?eP.current??void 0:void 0}),d=l||!ei.current||i?"":sM,c=l||d,p=[ef.current,em.current,ei.current?"legacy-plan":"",c?String(c.length):""].join("|"),u=t?.id??"new";c&&(eD.current.sessionKey!==u||eD.current.signature!==p)?(eD.current={sessionKey:u,signature:p},n=`${c}
|
|
38
|
+
|
|
39
|
+
${e}`):n=e;let h=n,x=o?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),f={role:"user",content:x?.length?[...e.trim()?[{type:"text",text:e}]:[],...x]:e,timestamp:Date.now()};S(e=>[...e,f]),t3.current=sA(f),t5.current=a,"goal"!==ef.current||i||(eP.current=s,eL(e=>({...e,status:"running",goalText:s,turnsUsed:0,noProgressTurns:0,tokensUsed:0})),eH.current=!0),tB.current=!0,W(!0),e9(i?{kind:"running_command"}:{kind:"waiting_model"}),R({type:"start"}),tY.current=!0,tt(!0),tZ.current=!0;let m=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),k=null,v=!1;try{if(g&&r){let t=tH.current??await t4.current,o=t??await of();o&&(k=o,Z&&(e1(Z),t&&await sb(o,{type:"set_model",provider:Z.provider,modelId:Z.modelId})),await oj(o),v=!0,await sb(o,{type:"prompt",message:h,...m?.length?{images:m}:{}}),ox(1,e))}else t&&(k=t.id,await oj(t.id),v=!0,await sb(t.id,{type:"prompt",message:h,...m?.length?{images:m}:{}}));i&&k&&o$(k,a)}catch(e){if(console.error("Failed to send message:",e),v&&k)return void o$(k,a);if(t_.current=!1,ov(),e instanceof sD){let t=t3.current;t&&S(e=>{let o=e[e.length-1];return o?.role==="user"&&sA(o)===t?e.slice(0,-1):e}),oT({type:"error",message:e.message})}t3.current=null,tB.current=!1,W(!1),e9(null),R({type:"end"})}},[g,r,Z,t,of,oj,ox,o$,oT,ok,ov,on]),oL=(0,n.useCallback)(async(o,r)=>{if(tB.current||tV.current)return;let n=`${r?"!!":"!"}${o}`;tV.current=!0,O({command:o,excludeFromContext:r}),A(!0);try{let e=tH.current??t?.id??await of();if(!e)throw Error("Unable to create a session for the shell command");await sb(e,{type:"bash",command:o,excludeFromContext:r}),await ou(e),ox(1,n)}catch(t){console.error("Failed to execute shell command:",t),oT({type:"error",message:t instanceof Error?t.message:String(t)}),e.chatInputRef?.current?.insertIfEmpty(n)}finally{tV.current=!1,O(null),A(!1)}},[oT,of,ou,e.chatInputRef,ox,t]),oO=(0,n.useCallback)(async()=>{let e=tH.current;if(e)try{await sb(e,{type:tV.current?"abort_bash":"abort"})}catch(e){console.error("Failed to abort:",e)}},[]),oH=(0,n.useCallback)(async e=>{let t=tH.current;if(t){eZ(e);try{let{cancelled:o,newSessionId:r}=await sb(t,{type:"fork",entryId:e})??{};!o&&r&&a?.(r)}catch(e){console.error("Fork failed:",e)}finally{eZ(null)}}},[a]),oB=(0,n.useCallback)(async e=>{let t=tH.current;t&&(sb(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),w(e),await og(t,e))},[og]),oU=(0,n.useCallback)(async e=>{w(e);let t=tH.current;t&&(await og(t,e),e&&sb(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[og]),o_=(0,n.useCallback)(async(e,t)=>{if(g){let o={provider:e,modelId:t};ot.current=o,X(o),e1(o);let r=tH.current??await t4.current;if(!r)return;try{await sb(r,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let o=tH.current;if(!o)return;let r=++t8.current,n=eX??x?.context.model??null;eQ({provider:e,modelId:t});try{await sb(o,{type:"set_model",provider:e,modelId:t})}catch(o){console.error("Failed to set model:",o),t8.current===r&&(eQ(n&&(n.provider!==e||n.modelId!==t)?n:null),oT({type:"error",message:o instanceof Error?o.message:String(o)}))}},[oT,eX,x?.context.model,g,X]),oq=(0,n.useCallback)(async()=>{let e=tH.current;if(e&&!e2){e4(!0),e5(null),e8(null);try{let t=await sb(e,{type:"compact"});e8(sL(t,"manual")),await ou(e,!0)}catch(e){e5(e instanceof Error?e.message:String(e)),e8(null)}finally{e4(!1)}}},[e2,ou]),oV=(0,n.useCallback)(async e=>{let o=++t7.current,n=r??t?.cwd??"",s=n?`/api/models?cwd=${encodeURIComponent(n)}`:"/api/models",i=t9.current;i?.abort();let a=new AbortController;t9.current=a;let l=()=>a.abort();e?.aborted?a.abort():e?.addEventListener("abort",l,{once:!0});try{let e=await fetch(s,{signal:a.signal});if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if(o!==t7.current||h!==oe.current)return;B(t.models),V(t.thinkingLevels??{}),J(t.thinkingLevelMaps??{}),Y(t.modelScopeWarnings??[]);let r=t.modelList??[];if(_(r),g&&!tH.current){let e=(t.defaultModel?r.find(e=>e.id===t.defaultModel?.modelId&&e.provider===t.defaultModel?.provider):void 0)??r[0];ee(e?{provider:e.provider,modelId:e.id}:null);let o=e?t.thinkingLevelPins?.[`${e.provider}/${e.id}`]:void 0;null===oo.current&&eU(o??"auto")}}finally{e?.removeEventListener("abort",l),t9.current===a&&(t9.current=null)}},[g,h,r,t?.cwd]),oK=(0,n.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,o,r=""]=t,n=r.trim(),s=tH.current??await of(),i=e=>(e.handled&&(e.error?oT({type:"error",message:e.error}):"openSessionStats"!==e.action&&oT({type:"success",message:e.message??"Command completed"})),e);try{switch(o){case"compact":{if(!s||e2)return i({handled:!0,error:"No active session to compact"});e4(!0),e5(null),e8(null);let e=await sb(s,{type:"compact",...n?{customInstructions:n}:{}});return e8(sL(e,"manual")),await ou(s,!0)&&ox(),i({handled:!0,message:"Compacted context"})}case"reload":if(!s)return i({handled:!0,error:"No active session to reload"});return await sb(s,{type:"reload"}),await Promise.all([ou(s,!1,!0),oh(s),om(),oV()]),i({handled:!0,message:"Reloaded session resources"});case"name":if(!s)return i({handled:!0,error:"No active session to name"});if(!n)return i({handled:!0,error:"Usage: /name <name>"});return await sb(s,{type:"set_session_name",name:eE(n)}),await ou(s)&&ox(),i({handled:!0,message:`Session renamed to ${n}`});case"session":{if(!s)return i({handled:!0,error:"No active session"});let e=await sb(s,{type:"get_session_stats"});return e&&td(e),p?.(),i({handled:!0,action:"openSessionStats"})}case"copy":{if(!s)return i({handled:!0,error:"No active session"});let e=await sb(s,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return i({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),i({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return i({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===o&&e4(!1)}},[oT,of,e2,oV,ou,om,oh,ox,p]),oJ=(0,n.useCallback)(async(e,t)=>{let o=tH.current;if(!o)return;let r=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await sb(o,{type:"steer",message:e,...r?.length?{images:r}:{}})}catch(e){console.error("Failed to steer:",e)}},[]),oG=(0,n.useCallback)(async(e,t,o)=>{let r=tH.current;if(!r)return;let n=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await sb(r,{type:"prompt",message:e,streamingBehavior:t,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to queue prompt:",e)}},[]),oY=(0,n.useCallback)(async(e,t)=>{let o=tH.current;if(!o)return;let r=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await sb(o,{type:"follow_up",message:e,...r?.length?{images:r}:{}})}catch(e){console.error("Failed to follow up:",e)}},[]),oZ=(0,n.useCallback)(async()=>{let e=tH.current;if(e)try{await sb(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),oX=(0,n.useCallback)(async()=>{let t=tH.current;if(t)try{let o=await sb(t,{type:"clear_queue"});tv({steering:[],followUp:[]});let r=[...o?.steering??[],...o?.followUp??[]];r.length>0&&e.chatInputRef?.current?.prependText(r.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),oT({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,oT]);(0,n.useEffect)(()=>{0===ty.length&&tj(!1)},[ty.length]);let oQ=(0,n.useCallback)(async(e,t,o=!1)=>{let r=tH.current;if(!r)return ty;try{let n=await sb(r,{type:"resolve_recovery",keep:e,discard:t,continueRun:o}),s=n?.remaining??[];return tb(s),o&&e.length>0&&(async()=>{try{let e=await fetch(`/api/agent/${encodeURIComponent(r)}`);if(!e.ok)return;let t=await e.json(),o=t.state;if(!t.running||!o||!o.isStreaming&&!o.isPromptRunning)return;tU.current=!!o.isStreaming,t_.current=!!o.isPromptRunning,tB.current=!0,W(!0),e9(sC(o)),R({type:"start"}),oy(r),!o.isStreaming&&o.isPromptRunning&&o$(r)}catch{}})(),s}catch(e){return console.error("Failed to resolve queued message recovery:",e),oT({type:"error",message:"Failed to resolve queued message recovery"}),ty}},[ty,oT,oy,o$]),o0=(0,n.useCallback)(async()=>{let e=tH.current;if(!e)return null;try{return await sb(e,{type:"export_queue"})}catch(e){return console.error("Failed to export queue:",e),oT({type:"error",message:"Failed to export queue"}),null}},[oT]),o1=(0,n.useCallback)(async e=>{let t=tH.current;if(!t)return null;try{let o=await sb(t,{type:"import_queue",entries:e});return o&&tv(sI(o)),o?.imported??0}catch(e){return console.error("Failed to import queue:",e),oT({type:"error",message:"Failed to import queue"}),null}},[oT]),o2=(0,n.useCallback)(async e=>{let t=tH.current;if(!t)return null;try{let o=await sb(t,{type:"stage_recovery",entries:e});return o?.pendingRecovery&&tb(o.pendingRecovery),(o?.staged??0)>0&&tj(!0),o?.staged??0}catch(e){return console.error("Failed to stage imported queue:",e),oT({type:"error",message:"Failed to stage imported queue"}),null}},[oT]),o4=(0,n.useCallback)(async(e,t,o)=>{let r=tH.current;if(!r)return!1;try{let n=await sb(r,{type:"move_queue",kind:e,fromIndex:t,toIndex:o});return n&&tv(sI(n)),!0}catch(e){return console.error("Failed to move queued message:",e),oT({type:"error",message:e instanceof Error?e.message:"Failed to move queued message"}),!1}},[oT]),o6=(0,n.useCallback)(async(e,t)=>{let o=tH.current;if(!o)return null;try{let r=await sb(o,{type:"recall_queue_item",kind:e,index:t});return r&&(void 0!==r.steering||void 0!==r.followUp)&&tv(sI(r)),r?.entry?{text:r.entry.text,images:r.entry.images?.map(({data:e,mimeType:t})=>({data:e,mimeType:t}))}:null}catch(e){return console.error("Failed to recall queued message:",e),oT({type:"error",message:e instanceof Error?e.message:"Failed to recall queued message"}),null}},[oT]),o5=(0,n.useCallback)(async(e,t,o,r)=>{let n=tH.current;if(!n)return!1;try{let s=await sb(n,{type:"requeue_at",kind:e,index:t,text:o,images:r?.map(({data:e,mimeType:t})=>({type:"image",data:e,mimeType:t}))});return s&&tv(sI(s)),!0}catch(e){return console.error("Failed to requeue message:",e),oT({type:"error",message:e instanceof Error?e.message:"Failed to requeue message"}),!1}},[oT]),o3=(0,n.useCallback)(async(e,t)=>{let o=tH.current;if(!o)return!1;try{let r=await sb(o,{type:"remove_queue_item",kind:e,index:t});return r&&tv(sI(r)),!0}catch(e){return console.error("Failed to remove queued message:",e),oT({type:"error",message:e instanceof Error?e.message:"Failed to remove queued message"}),!1}},[oT]),o8=(0,n.useCallback)(async e=>{if(oo.current="auto"===e?null:e,eU(e),"auto"===e)return;let t=tH.current??await t4.current;if(t)try{await sb(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),o7=(0,n.useCallback)(async e=>{let t=(0,sw.xG)(e);oi(e);let o=tH.current??await t4.current;if(o)try{await sb(o,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[oi]),o9=(0,n.useRef)(0),re=(0,n.useCallback)(async e=>{let t=tH.current??await t4.current,o=++o9.current;if(e){if(es.current="plan"===et?"default":et,en(!0),t)try{if(await sb(t,{type:"prompt",message:"/plan"}),o9.current!==o)return}catch(e){if(o9.current!==o)return;console.error("Failed to enter plan mode:",e)}}else if(en(!1),t)try{if(await sb(t,{type:"prompt",message:"/plan exit"}),o9.current!==o)return}catch(e){if(o9.current!==o)return;console.error("Failed to exit plan mode:",e);try{let e=es.current;await sb(t,{type:"set_tools",toolNames:(0,sw.xG)(e)})}catch{}}},[et]),rt=(0,n.useCallback)(e=>{el(e);let t=tH.current;if(!t){ed.current=e;return}ed.current=null,fetch(`/api/modes?session=${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(e=>{console.error("Failed to persist mode settings:",e)})},[]),ro=(0,n.useCallback)(e=>{rt({...e$.current,collaborationMode:ej(e)}),"goal"!==e&&(eP.current=null,eH.current=!1,eL(e=>"idle"===e.status?e:{...e,status:"idle",goalText:null}))},[rt]),rr=(0,n.useCallback)(async e=>{rt({...e$.current,tokenMode:eS(e)});let t=tH.current??await t4.current;if(t)try{if("economy"!==e||ei.current){if("economy"!==e){let e=ei.current?sw.SC:(0,sw.xG)("plan"===et?"default":et);await sb(t,{type:"set_tools",toolNames:e})}}else await sb(t,{type:"set_tools",toolNames:[...eT]})}catch(e){console.error("Failed to apply token mode tools:",e)}},[rt,et]),rn=(0,n.useCallback)(async e=>{rt({...e$.current,toolApprovalMode:eC(e)});let t=tH.current??await t4.current;if(t)try{await sb(t,{type:"set_approval_mode",mode:eC(e)})}catch(e){console.error("Failed to apply approval mode:",e)}},[rt]),rs=(0,n.useCallback)(async e=>{rt({...e$.current,permissionRules:e});let t=tH.current??await t4.current;if(t)try{await sb(t,{type:"set_approval_policy",policy:e})}catch(e){console.error("Failed to apply permission rules:",e)}},[rt]),ri=(0,n.useCallback)(async(e,t,o)=>{let r=tH.current;if(r)try{await sb(r,{type:"resolve_approval",id:e,approve:t,reason:o})}catch(e){console.error("Failed to resolve approval:",e)}finally{eW(t=>t.filter(t=>t.id!==e))}},[]),ra=(0,n.useCallback)(e=>{eP.current=e},[]),rl=(0,n.useCallback)(e=>{let t=e.trim();t&&(eP.current=t,eL(e=>({...e,status:"running",goalText:t,turnsUsed:0,noProgressTurns:0,startedAt:Date.now()})))},[]),rd=(0,n.useCallback)(()=>{"running"===eO.current.status&&eL(e=>({...e,status:"paused"}))},[]),rc=(0,n.useCallback)(()=>{let e=eO.current;if("paused"!==e.status&&"blocked"!==e.status)return;eL(e=>({...e,status:"running"}));let t=tH.current;t&&!tB.current&&sb(t,{type:"follow_up",message:sT}).catch(()=>{})},[]),rp=(0,n.useCallback)(()=>{eH.current=!1,eP.current=null,eL(e=>({...e,status:"idle",goalText:null,turnsUsed:0,noProgressTurns:0}))},[]),ru=(0,n.useCallback)(async()=>{let e=eO.current;if("running"!==e.status)return;let t=tH.current;if(!t)return;let o="",r=0;for(let e of j)if("assistant"===e.role){let t="string"==typeof e.content?e.content:e.content?.filter(e=>"text"===e.type).map(e=>e.text??"").join("\n")??"";t&&(o=t),r+=e.content?.filter(e=>"toolCall"===e.type).length??0}let n=o.toLowerCase();if(sz.some(e=>n.includes(e))){eL(e=>({...e,status:"complete",turnsUsed:e.turnsUsed+1})),eP.current=null;return}if(sR.some(e=>n.includes(e)))return void eL(e=>({...e,status:"blocked",turnsUsed:e.turnsUsed+1}));let s=e.turnsUsed+1,i=0===r?e.noProgressTurns+1:0;i>=e.noProgressLimit?eL(e=>({...e,status:"blocked",turnsUsed:s,noProgressTurns:i})):s>=e.turnsLimit?eL(e=>({...e,status:"paused",turnsUsed:s,noProgressTurns:i})):(eL(e=>({...e,turnsUsed:s,noProgressTurns:i})),await sb(t,{type:"follow_up",message:sT}).catch(()=>{}))},[j]),rg=(0,n.useRef)(null);(0,n.useEffect)(()=>{rg.current={drive:ru}},[ru]);let rh=tS.map(e=>`${e.id}:${e.status}:${e.completedAt??""}`).join("|"),rx=(0,n.useRef)(tS);rx.current=tS,(0,n.useEffect)(()=>{u?.(rx.current)},[rh,u]),(0,n.useEffect)(()=>()=>{u?.([])},[u]),(0,n.useEffect)(()=>{tR(()=>[])},[t?.id,r??t?.cwd]);let rf=(0,n.useCallback)(()=>{let e=t2.current,t=tG.current;if(!e||!t)return;let o=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,r=Math.max(0,e.scrollHeight-e.clientHeight),n=Math.min(Math.max(0,o-16),r);tX.current=n>=r-150,t0.current=Date.now()+700,e.scrollTo({top:n,behavior:"smooth"})},[]),rm=(0,n.useCallback)(e=>{e instanceof KeyboardEvent&&(!sP.has(e.key)||e.target instanceof Element&&e.target.closest("input, textarea, [contenteditable='true']"))||(tQ.current=Date.now()+1200)},[]),rk=(0,n.useCallback)(()=>{let e=t2.current;if(e){let{scrollTop:t,clientHeight:o,scrollHeight:r}=e;tX.current=t+o>=r-150}if(Date.now()<tQ.current){tZ.current=!1;return}Date.now()<t0.current||(tZ.current=!1)},[]);(0,n.useEffect)(()=>{if(t){tH.current=t.id;let e=ek.current,o=ev.current;("auto"!==e||o.allow.length||o.ask.length||o.deny.length)&&(sb(t.id,{type:"set_approval_mode",mode:e}).catch(()=>{}),sb(t.id,{type:"set_approval_policy",policy:o}).catch(()=>{})),ou(t.id,!0,!0).then(e=>{e?.running&&(e.state?.isBashRunning&&(tV.current=!0,A(!0)),oh(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(tU.current=!!e.state.isStreaming,t_.current=!!e.state.isPromptRunning,tB.current=!0,W(!0),e9(sC(e.state)),R({type:"start"}),oy(t.id),!e.state.isStreaming&&e.state.isPromptRunning&&o$(t.id))),e?.state&&(void 0!==e.state.isCompacting&&e4(e.state.isCompacting),void 0!==e.state.contextUsage&&eK(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&eG(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&eU(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&tx(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&tm(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&tv(sI(e.state.queuedMessages)),void 0!==e.state.pendingRecovery&&tb(e.state.pendingRecovery??[])),e?.running||fetch(`/api/agent/${encodeURIComponent(t.id)}`).then(e=>e.ok?e.json():null).then(e=>{e&&e.running&&oh(t.id)}).catch(()=>{})})}return()=>{on(),t$(),ok(),ov()}},[on]),(0,n.useEffect)(()=>{c?.(eJ)},[eJ,c]),(0,n.useEffect)(()=>{d&&d(x?.tree??[],b,oU)},[x?.tree,b,oU,d]),(0,n.useEffect)(()=>(window.addEventListener("keydown",rm),window.addEventListener("pointerdown",rm,{passive:!0}),()=>{window.removeEventListener("keydown",rm),window.removeEventListener("pointerdown",rm)}),[rm]),(0,n.useEffect)(()=>{let e=t2.current;if(e)return e.addEventListener("wheel",rm,{passive:!0}),e.addEventListener("touchstart",rm,{passive:!0}),e.addEventListener("scroll",rk,{passive:!0}),()=>{e.removeEventListener("wheel",rm),e.removeEventListener("touchstart",rm),e.removeEventListener("scroll",rk)}},[j.length,m,rk,rm]),(0,n.useEffect)(()=>{j.length>0&&(tY.current?(tJ.current=!0,tG.current&&(tY.current=!1,rf())):m||!tJ.current?(m||(tJ.current=!0),oW("instant")):!tB.current&&(tZ.current||tX.current)&&oW("smooth"))},[j.length,m,F,oW,rf]);let rv=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let e;if(m){rv.current=!1;return}if(rv.current||0===j.length)return;rv.current=!0;let t=!1,o=-1,r=0,n=()=>{if(t||tB.current||!(tZ.current||tX.current))return;oW("instant");let s=t2.current;if(s){if(s.scrollHeight===o){if((r+=1)>=2)return}else o=s.scrollHeight,r=0;e=window.setTimeout(n,250)}};return e=window.setTimeout(n,250),()=>{t=!0,void 0!==e&&window.clearTimeout(e)}},[m,j.length,oW]),(0,n.useEffect)(()=>{let e=new AbortController;return oV(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[oV,l]),(0,n.useEffect)(()=>{if(!e6)return;let e=setTimeout(()=>e5(null),3e3);return()=>clearTimeout(e)},[e6]),(0,n.useEffect)(()=>{if(!e3)return;let e=setTimeout(()=>e8(null),6e3);return()=>clearTimeout(e)},[e3]),(0,n.useEffect)(()=>{if(0===ti.visible.length)return;let e=ti.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{ta({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!ti.visible[0])return;let t=setTimeout(()=>{ta({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[ti.visible]),(0,n.useEffect)(()=>{td(null)},[j.length,eV?.tokens,eV?.percent,eV?.contextWindow]);let ry=x?.tree??[];return{data:x,loading:m,error:v,activeLeafId:b,messages:j,entryIds:C,streamState:z,agentRunning:F,bashRunning:N,pendingBash:L,modelNames:H,modelList:U,modelThinkingLevels:q,modelThinkingLevelMaps:K,modelScopeWarnings:G,newSessionModel:Z,toolPreset:et,thinkingLevel:eB,retryInfo:e_,contextUsage:eV,systemPrompt:eJ,forkingEntryId:eY,isCompacting:e2,compactError:e6,compactResult:e3,currentModel:od,displayModel:oc,sessionStats:op,tokenRate:I,planMode:er,subagents:tS,collaborationMode:eu,tokenMode:eg,toolApprovalMode:eh,permissionRules:ex,modeSettings:ea,approvalRequests:eF,handleCollaborationModeChange:ro,handleTokenModeChange:rr,handleToolApprovalModeChange:rn,handlePermissionRulesChange:rs,resolveApproval:ri,setActiveGoalText:ra,goalState:eA,handleGoalStart:rl,handleGoalPause:rd,handleGoalResume:rc,handleGoalStop:rp,slashCommands:to,slashCommandsLoading:tn,queuedMessages:tk,pendingRecovery:ty,recoveryIsImport:tw,notices:ti.visible,extensionDialog:tc,extensionCustomUi:tu,extensionStatuses:th,extensionWidgets:tf,respondToExtensionUi:oS,sendExtensionCustomInput:oC,agentPhase:e7,isNew:g,promptAnchorActive:te,branchTree:ry,sessionIdRef:tH,eventSourceRef:tF,messagesEndRef:t1,scrollContainerRef:t2,lastUserMsgRef:tG,pendingScrollToUserRef:tY,initialScrollDoneRef:tJ,scrollUserMsgToTop:rf,handleSend:oA,executeBash:oL,handleAbort:oO,handleFork:oH,handleNavigate:oB,handleModelChange:o_,handleCompact:oq,handleSteer:oJ,handleFollowUp:oY,handlePromptWithStreamingBehavior:oG,handleAbortCompaction:oZ,handleRecallQueue:oX,resolveRecovery:oQ,exportQueueData:o0,importQueueData:o1,stageQueueImport:o2,moveQueuedMessage:o4,recallQueuedMessage:o6,requeueAt:o5,removeQueuedMessage:o3,handleBuiltinSlashCommand:oK,handleToolPresetChange:o7,handleThinkingLevelChange:o8,handlePlanModeChange:re,loadTools:oh,loadSlashCommands:om,setActiveLeafId:w,setData:f,setMessages:S,dispatch:R,setAgentRunning:W,setForkingEntryId:eZ,handleLeafChange:oU,handleAgentEventRef:tK}}({session:e,newSessionCwd:t,onAgentEnd:D,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:p,onSystemPromptChange:u,onSessionStatsPanelOpen:x,onSubagentsChange:h}),[tb,tw]=(0,n.useState)(!1);(0,n.useEffect)(()=>{0===ec.length&&tw(!1)},[ec.length]);let{balance:tj,refresh:tS,refreshSoon:tC}=function(){let[e,t]=(0,n.useState)(null),[o,r]=(0,n.useState)(!1),s=(0,n.useRef)(null),i=(0,n.useRef)(null),a=(0,n.useRef)(!0);(0,n.useEffect)(()=>(a.current=!0,()=>{a.current=!1,i.current&&clearTimeout(i.current),s.current?.abort()}),[]);let l=(0,n.useCallback)(async()=>{s.current?.abort();let o=new AbortController;s.current=o;try{let n=await fetch("/api/deepseek/balance",{signal:o.signal,cache:"no-store"}),s=await n.json();if(!a.current)return;s?.available&&null!=s.totalBalance?(t(s),r(!1)):null===e&&r(!0)}catch{if(!a.current)return;null===e&&r(!0)}},[e]),d=(0,n.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{i.current=null,l()},2e3)},[l]);return{balance:e,failed:o,refresh:l,refreshSoon:d}}(),tT=en?.provider==="deepseek",tz=(0,n.useRef)(null);(0,n.useEffect)(()=>{tT&&tS()},[tT,tS]),(0,n.useEffect)(()=>{if(tT)for(let e=L.length-1;e>=0;e--){let t=L[e];if("assistant"!==t.role||!t.usage)continue;let o=`${e}:${O[e]??""}`;o!==tz.current&&(tz.current=o,tC());break}},[L,O,tT,tC]);let tR=(0,n.useMemo)(()=>{let e=L.findLast(e=>"assistant"===e.role&&!!e.usage);if(!e?.usage)return null;let t=e.usage;return{model:e.model??"",input:t.input??0,output:t.output??0,cacheRead:t.cacheRead??0,costCNY:ob(e.model)?ow(e.model,t):0,costUSD:ob(e.model)?0:t.cost?.total??0}},[L]),[tI,tM]=(0,n.useState)(!1),[tE,tP]=(0,n.useState)(null),tD=(0,n.useRef)(!1);(0,n.useEffect)(()=>{if(!ti){tD.current=!1;return}if(B){tD.current=!0;return}if(tD.current){tD.current=!1;let e=[...L].reverse().find(e=>"assistant"===e.role);tP((e&&"string"==typeof e.content?e.content:e?.content?.filter(e=>"text"===e.type).map(e=>e.text).join("\n")??null)||null),tM(!0)}},[B,ti,L]);let t$=(0,n.useCallback)(()=>{tM(!1);let e=tF.current;"plan"===tl&&tp("normal"),ta(!1).then(()=>{e&&eU(R("tasks.planReviewExecutePrompt",{plan:e}))})},[ta,eU,R,tl,tp]),tF=(0,n.useRef)(null);(0,n.useEffect)(()=>{tF.current=tE},[tE]);let tW=(0,n.useCallback)(e=>{tM(!1),eY(e)},[eY]),tN=(0,n.useCallback)(()=>{tM(!1),"plan"===tl&&tp("normal"),ta(!1)},[ta,tl,tp]);(0,n.useEffect)(()=>{eg&&P.current!==eg.id&&(P.current=eg.id,M.current&&I.current())},[eg]),(0,n.useEffect)(()=>{a=B||U?eq:null},[B,U,eq]);let[tA,tL]=(0,n.useState)(!1),[tO,tH]=(0,n.useState)(!1),[tB,tU]=(0,n.useState)(!1),t_=(0,n.useCallback)(()=>{let e=eA.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;tL(e.scrollTop>1),tH(t>1),tU(t>240)},[eA]),tq=(0,n.useCallback)(()=>{window.requestAnimationFrame(()=>{let e=eA.current,t=eN.current;if(!e||!t)return;let o=Math.max(88,c?.current?.measureHeight?.()??0),r=()=>{if(!e||!t)return;let r=Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop-96-e.clientHeight+o);e.scrollTo({top:r,behavior:"auto"})};r(),t_(),window.setTimeout(r,200)})},[eN,eA,t_,c]);(0,n.useEffect)(()=>{let e=eA.current;if(!e)return;let t=new ResizeObserver(t_);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),e.addEventListener("scroll",t_,{passive:!0}),t_(),()=>{e.removeEventListener("scroll",t_),t.disconnect()}},[L.length,eA,t_]);let tV=(0,n.useRef)(null),tK=(0,n.useRef)([]),tJ=(0,n.useMemo)(()=>({getOffsetForIndex:e=>tV.current?.getOffsetForIndex(e)?.[0]??0,sizeFor:e=>{let t=tV.current;if(!t)return 0;let o=t.measurementsCache[e];return o?.size??t.options.estimateSize?.(e)??0},totalHeight:()=>tV.current?.getTotalSize()??0,refToItemIndex:e=>tK.current[e],itemCount:tK.current.length}),[]),tG=es?[es.sessionId,es.sessionFile??"",es.sessionName??"",es.userMessages,es.assistantMessages,es.toolCalls,es.toolResults,es.totalMessages,es.tokens.input,es.tokens.output,es.tokens.cacheRead,es.tokens.cacheWrite,es.tokens.total,es.cost??0,es.totalActiveMs??0].join("|"):null,tY=(0,n.useRef)(es);tY.current=es,(0,n.useEffect)(()=>{g?.(tY.current)},[tG,g]),(0,n.useEffect)(()=>()=>{g?.(null)},[g]);let tZ=Q?`${Q.percent??"null"}|${Q.contextWindow}|${Q.tokens??"null"}`:null,tX=(0,n.useRef)(Q);tX.current=Q,(0,n.useEffect)(()=>{f?.(tX.current)},[tZ,f]),(0,n.useEffect)(()=>()=>{f?.(null)},[f]);let{isDragOver:tQ,handleDragEnter:t0,handleDragOver:t1,handleDragLeave:t2,handleDrop:t4}=function(e){let[t,o]=(0,n.useState)(!1),r=(0,n.useRef)(0),s=(0,n.useCallback)(e=>{e.dataTransfer.files.length&&(e.preventDefault(),r.current+=1,o(!0))},[]),i=(0,n.useCallback)(e=>{e.dataTransfer.files.length&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:s,handleDragOver:i,handleDragLeave:(0,n.useCallback)(()=>{r.current-=1,r.current<=0&&(r.current=0,o(!1))},[]),handleDrop:(0,n.useCallback)(t=>{t.preventDefault(),r.current=0,o(!1),e(Array.from(t.dataTransfer.files),t.dataTransfer)},[e])}}((0,n.useCallback)((e,t)=>{if(B){let t=e.filter(e=>e.type.startsWith("image/"));t.length&&c?.current?.addImages(t);return}c?.current?.addFiles(e,t)},[B,c])),t6=L.filter(e=>"user"===e.role||"assistant"===e.role),t5=(0,n.useMemo)(()=>{let e=new Set,t=[];for(let r=L.length-1;r>=0&&t.length<50;r-=1){var o;let n="user"!==(o=L[r]).role?null:("string"==typeof o.content?o.content:o.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n")).trim()||null;!n||e.has(n)||(e.add(n),t.push(n))}return t},[L]),t3=(b=t6.length,(w=(0,n.useRef)([])).current=Array(b).fill(null).map((e,t)=>w.current[t]??null),w),t8=eP&&0===L.length&&!H.isStreaming&&!B,t7=e?.cwd??t??void 0,t9=en?K[`${en.provider}:${en.modelId}`]??null:null,oe=en?J[`${en.provider}:${en.modelId}`]??null:null,ot=(0,r.jsx)(n3,{ref:c,onSend:eU,onBash:e_,onAbort:eq,onSteer:B?eY:void 0,onFollowUp:B?eZ:void 0,onPromptWithStreamingBehavior:B?eX:void 0,isStreaming:B,model:en,modelNames:q,modelList:V,modelScopeWarnings:G,onModelChange:eJ,compactResult:er,toolPreset:Y,onToolPresetChange:e||eP?tt:void 0,planMode:ti,onPlanModeChange:e=>{ta(e),e&&"plan"!==tl?tp("plan"):e||"plan"!==tl||tp("normal")},collaborationMode:tl,tokenMode:td,toolApprovalMode:tc,onCollaborationModeChange:e=>{tp(e),"plan"!==e||ti?"plan"!==e&&ti&&ta(!1):ta(!0)},onTokenModeChange:tu,onToolApprovalModeChange:tg,goalState:tf,onGoalStart:tm,onGoalPause:tk,onGoalResume:tv,onGoalStop:ty,thinkingLevel:Z,onThinkingLevelChange:e||eP?to:void 0,availableThinkingLevels:t9,thinkingLevelMap:oe,retryInfo:X,queuedMessages:ed,inputHistory:t5,onRecallQueue:e0,onMoveQueue:e6,onRecallOne:e5,onRequeueAt:e8,onRemoveQueueItem:e7,slashCommands:ea,slashCommandsLoading:el,onLoadSlashCommands:tr,onBuiltinCommand:te,onAudioUnlock:T,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t}),oo=ef.filter(e=>"belowEditor"!==e.placement),or=ef.filter(e=>"belowEditor"===e.placement),on=et?R("desktop.compacting"):function(e,t){if(e?.kind==="running_tools"){let o=e.tools.map(e=>e.name);return 0===o.length?t("desktop.runningTool"):t("desktop.runningTools",{tools:o.length<=3?o.join(", "):`${o.slice(0,2).join(", ")} (+${o.length-2})`})}return e?.kind==="waiting_model"?t("desktop.waitingForModel"):e?.kind==="running_command"?t("desktop.runningCommand"):null}(ev,R);return N?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:R("desktop.loadingSession")}):A?(0,r.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:A}):(0,r.jsxs)("div",{className:"relative flex h-full min-w-0 flex-col overflow-hidden",onDragEnter:t0,onDragOver:t1,onDragLeave:t2,onDrop:t4,children:[tQ&&(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"})]})]})]}),eg&&(0,r.jsx)(sJ,{request:eg,onRespond:em}),eh&&(0,r.jsx)(sG,{request:eh,onInput:ek}),!eP&&ec.length>0&&!tb&&(0,r.jsx)(n9,{items:ec,sessionId:e?.id,onResolve:e1,onExport:e2,onStageImport:e4,onDismiss:()=>tw(!0),mode:ep?"import":"recovery"}),th.length>0&&(0,r.jsx)(oX,{request:th[0]??null,queuedCount:Math.max(0,th.length-1),busy:!1,onResolve:(e,t)=>{let o=th[0];o&&tx(o.id,e,t)}}),t8?(0,r.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto",children:(0,r.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,r.jsx)("div",{style:{display:"flex",justifyContent:"center",marginBottom:28},children:(0,r.jsxs)("svg",{fill:"currentColor",fillRule:"evenodd",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",style:{width:64,height:64,color:"var(--accent)",opacity:.85},"aria-label":"Pi",children:[(0,r.jsx)("title",{children:"Pi"}),(0,r.jsx)("path",{clipRule:"evenodd",d:"M1 1h16.5v11H12v5.5H6.5V23H1V1zm5.5 5.5V12H12V6.5H6.5z"}),(0,r.jsx)("path",{d:"M17.5 12H23v11h-5.5V12z"})]})}),(0,r.jsx)("div",{style:{padding:"0 34px 6px 7px",paddingRight:z?16:34},children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,r.jsx)("div",{ref:k,style:{display:"flex",alignItems:"center",minWidth:0,flex:1,minHeight:48}}),(0,r.jsxs)("div",{style:{display:z?"none":"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.9.23"]})]}),(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,r.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.84.0"]})]})]})]})}),(0,r.jsx)("div",{style:{padding:"0 16px",paddingRight:z?16:34},children:(0,r.jsx)(sK,{notices:eu,align:"right"})}),"goal"===tl&&(0,r.jsx)(oY,{goalState:tf,onPause:tk,onResume:tv,onStop:ty}),ot,(0,r.jsx)("div",{style:{padding:"0 16px 6px",paddingRight:z?16:34,marginTop:-15},children:(0,r.jsx)(sh,{onViewFullHistory:v,cwd:t7,systemPrompt:y,sessionStats:es,contextUsage:Q,hasSession:!!e,showChat:!0,showSoundLabel:!0,soundEnabled:j,onSoundToggle:S,onCompact:e?eG:void 0,onAbortCompaction:eQ,isCompacting:et,compactError:eo,isDeepSeekOfficial:tT,deepseekBalance:tj,lastTurnUsage:tR})})]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"relative flex flex-1 overflow-hidden z-0",children:[(0,r.jsx)("div",{style:{position:"absolute",top:12,left:0,right:18*!z,zIndex:40,padding:"0 16px",pointerEvents:"none"},children:(0,r.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,r.jsx)(sK,{notices:eu,floating:!0,align:"right"})})}),(0,r.jsxs)("div",{className:"relative flex-1 min-h-0 min-w-0",children:[(0,r.jsx)("div",{ref:eA,className:"h-full min-w-0 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:(0,r.jsx)("div",{style:{minWidth:0,padding:"0 16px"},children:(0,r.jsxs)("div",{style:{width:"100%",minWidth:0,maxWidth:820,margin:"0 auto"},children:[(0,r.jsx)(sq,{statuses:ex}),(0,r.jsx)(sV,{widgets:oo}),(()=>{let t=new Map;for(let e of L)"toolResult"===e.role&&t.set(e.toolCallId,e);let o=-1;for(let e=L.length-1;e>=0;e--)if("user"===L[e].role){o=e;break}let n=new Map,s=0;L.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&n.set(t,s++)});let i=(s,i={})=>{let a=i.messageOverride??L[s],l="user"===a.role&&s>0&&"assistant"===L[s-1].role?O[s-1]:void 0,d="user"===a.role||"assistant"===a.role,c=n.get(s),p=i.keyPrefix??"message",u=!1;if("assistant"===a.role){u=!0;for(let e=s+1;e<L.length;e++){let t=L[e].role;if("user"===t)break;if("assistant"===t){u=!1;break}}u&&H.isStreaming&&s===L.length-1&&(u=!1)}void 0!==i.showTimestamp&&(u=i.showTimestamp);let g=(0,r.jsx)(oR,{message:a,toolResults:t,modelNames:q,cwd:t7,onOpenFile:m,entryId:O[s],onFork:B||eP||0===s&&"user"===a.role?void 0:eV,forking:ee===O[s],onNavigate:B?void 0:eK,prevAssistantEntryId:B?void 0:l,onEditContent:$,onQuoteReply:F,onCreateTask:W,showTimestamp:u,prevTimestamp:s>0?L[s-1].timestamp:void 0,sessionId:e?.id??eW.current??void 0,writtenFiles:i.writtenFiles},`${p}-view-${s}`);return d&&!1!==i.attachRef&&void 0!==c?(0,r.jsx)("div",{ref:e=>{t3.current[c]=e,s===o&&(eL.current=e,e&&eO.current&&(eO.current=!1,eH.current=!0,eB()))},children:g},`${p}-${s}`):g},a=[],l=[],d=(e,t)=>{a.push(e),l.push(t)};for(let s=0;s<L.length;){let a=L[s],l="custom"===a.role&&"compaction"===a.customType;if("user"!==a.role&&!l){d(i(s),n.get(s)),s+=1;continue}let c=s,p=c+1;for(;p<L.length&&"user"!==L[p].role;)p+=1;let u=function(e,t,o){for(let n=o-1;n>t;n--){var r;if("assistant"===(r=e[n]).role&&e3(r).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return n}for(let r=o-1;r>t;r--)if(e[r]?.role==="assistant")return r;return -1}(L,c,p);if((B||H.isStreaming)&&p===L.length&&(c===o||l)){d(i(c),n.get(c));let o=H.streamingMessage?.role==="assistant",a=[],l=!o&&u>=0?u:p;for(let e=c+1;e<l;e++)sB(L[e])&&a.push(e);let g=ts(L,O,a,t),h=null;if(!o&&u>=0){let e=L[u],o=e3(e,{isStreaming:!0}),r=tn(e,{messageIndex:u,entryId:O[u],toolResults:t,isStreaming:!0});g=g.concat(r.processBlocks),o.answerBlocks.length>0&&(h=sU(e,o.answerBlocks,{omitUsage:!0}))}if(o){let e=H.streamingMessage,o=e3(e,{isStreaming:!0}),r=tn(e,{messageIndex:L.length,toolResults:t,isStreaming:!0});g=g.concat(r.processBlocks),o.answerBlocks.length>0&&(h=sU(e,o.answerBlocks,{omitUsage:!0}))}if(g.length>0){let t=a.map(e=>n.get(e)).find(e=>"number"==typeof e);d((0,r.jsx)("div",{ref:void 0===t?void 0:e=>{t3.current[t]=e},children:(0,r.jsx)(rW,{blocks:g,isStreaming:B||H.isStreaming,cwd:t7,onOpenFile:m,sessionId:e?.id??eW.current??void 0,tokenRate:ei})},`live-process-group-${c}`),t)}h&&d((0,r.jsx)(oR,{message:h,isStreaming:!0,modelNames:q,cwd:t7,onOpenFile:m,onQuoteReply:F},`live-answer-${c}`),u>=0?n.get(u):void 0),s=p;continue}if(-1===u){for(let e=c;e<p;e++)d(i(e),n.get(e));s=p;continue}d(i(c),n.get(c));let g=[];for(let e=c+1;e<u;e++)g.push(e);let h=g.filter(e=>sB(L[e])),x=L[u],f=e3(x),k=f.processBlocks.length>0?sU(x,f.processBlocks,{omitUsage:!0}):null,v=f.answerBlocks.length>0?sU(x,f.answerBlocks):null,y=ts(L,O,h,t);if(k&&(y=y.concat(tn(x,{messageIndex:u,entryId:O[u],toolResults:t}).processBlocks)),y.length>0){let t=h.map(e=>n.get(e)).find(e=>"number"==typeof e)??(v?void 0:n.get(u));d((0,r.jsx)("div",{ref:void 0===t?void 0:e=>{t3.current[t]=e},children:(0,r.jsx)(rW,{blocks:y,isStreaming:!1,defaultExpanded:!v,onAutoExpanded:void 0,cwd:t7,onOpenFile:m,sessionId:e?.id??eW.current??void 0})},`process-group-${c}-${u}`),t)}if(v){let e=[];for(let t=c+1;t<=u;t++){let o=L[t];if(o?.role==="assistant")for(let t of o.content??[])e.push(t)}d(i(u,{messageOverride:v,writtenFiles:function(e,t,o){let r=new Set,n=[];for(let s of e){if("toolCall"!==s.type||!function(e){let t,o;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||"edit"===(o=e.toLowerCase())||o.startsWith("edit_")||o.endsWith(".edit")||o.endsWith("_edit")||o.includes("str_replace")||o.includes("replace_editor")}(s.toolName))continue;let e=t?.get(s.toolCallId);if(!e||e.isError)continue;let i=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(s.input);if(!i)continue;let a=function(e,t){let o;if(!e)return null;let r=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),n=e=>r?e.replace(/\\/g,"/"):e,s=n(e),i=t?n(t).replace(/\/+$/,""):void 0,a=/^[a-zA-Z]:\//.test(s),l=s.startsWith("//");if(a||l)o=s;else if(s.startsWith("/")){let e=i?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??i?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];o=e?`${e}${s}`:s}else{if(!i)return null;o=`${i}/${s}`}return e9(o)}(i,o);a&&(r.has(a)||(r.add(a),n.push({filePath:a})))}return n}(e,t,t7)}),n.get(u))}for(let e=u+1;e<p;e++)d(i(e),n.get(e));s=p}let c=[];return l.forEach((e,t)=>{void 0!==e&&(c[e]=t)}),tK.current=c,(0,r.jsx)(sf,{scrollElementRef:eA,items:a,virtualizerRef:tV})})(),on&&(et||B&&!H.streamingMessage)&&(0,r.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,r.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[on,ev?.kind==="waiting_model"&&(0,r.jsx)("span",{style:{display:"inline-block",width:12,height:12,marginLeft:6,verticalAlign:"-2px",border:"1.5px solid var(--text-muted)",borderTopColor:"transparent",borderRadius:"50%",animation:"spin 0.6s linear infinite"}})]})}),_&&(0,r.jsx)(oR,{message:{role:"bashExecution",command:_.command,output:"",excludeFromContext:_.excludeFromContext},sessionId:e?.id??eW.current??void 0}),U&&!_&&(0,r.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,r.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:R("desktop.runningShellCommand")})}),(0,r.jsx)("div",{style:{height:96}}),(0,r.jsx)("div",{ref:eN}),(0,r.jsx)(oJ,{open:tI,planText:tE,busy:B,onExecute:t$,onFeedback:tW,onExit:tN,onClose:()=>tM(!1)})]})})}),tA&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-8 bg-gradient-to-b from-[var(--bg)] to-transparent"}),tO&&(0,r.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8 bg-gradient-to-t from-[var(--bg)] to-transparent"}),tB&&(0,r.jsxs)("button",{type:"button",onClick:()=>tq(),title:R("desktop.scrollToBottom"),"aria-label":R("desktop.scrollToBottom"),style:{position:"absolute",bottom:14,right:18,zIndex:20,display:"flex",alignItems:"center",gap:6,padding:"5px 10px",border:"1px solid var(--border)",borderRadius:999,background:"color-mix(in srgb, var(--bg-panel) 92%, transparent)",color:"var(--text-muted)",fontSize:11,fontWeight:600,cursor:"pointer",boxShadow:"0 4px 14px rgba(0,0,0,0.14)",backdropFilter:"blur(4px)",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)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,r.jsx)(og.Z,{size:12,weight:"bold","aria-hidden":"true"}),R("desktop.scrollToBottom")]})]}),z?null:(0,r.jsx)(sv,{messages:L,streamingMessage:H.streamingMessage,scrollContainer:eA,messageRefs:t3,virtualizer:tJ})]}),(0,r.jsxs)("div",{className:"relative z-10",children:[(0,r.jsx)("div",{style:{padding:"0 16px",paddingRight:z?16:34},children:(0,r.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,r.jsx)(sV,{widgets:or})})}),ot,(0,r.jsx)("div",{className:`session-info-bar-wrap${z?" is-mobile":""}`,children:(0,r.jsx)("div",{className:"session-info-bar-inner",children:(0,r.jsx)(sh,{onViewFullHistory:v,cwd:t7,systemPrompt:y,sessionStats:es,contextUsage:Q,hasSession:!!e,showChat:!0,soundEnabled:j,onSoundToggle:S,onCompact:e?eG:void 0,onAbortCompaction:eQ,isCompacting:et,compactError:eo,branchTree:eD,branchActiveLeafId:e$,onBranchLeafChange:eF,isDeepSeekOfficial:tT,deepseekBalance:tj,lastTurnUsage:tR})})})]})]})]})}function sq({statuses:e}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(e=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,maxWidth:"100%",padding:"4px 8px",border:"1px solid color-mix(in srgb, var(--accent) 24%, var(--border))",borderRadius:6,background:"color-mix(in srgb, var(--accent) 7%, var(--bg))",color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:e.key}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.text})]},e.key))})}function sV({widgets:e}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:e.map(e=>(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{padding:"5px 9px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:e.key}),(0,r.jsx)("pre",{style:{margin:0,padding:"8px 9px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:e.lines.join("\n")})]},e.key))})}function sK({notices:e,floating:t=!1,align:o="left"}){return 0===e.length?null:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:"right"===o?"flex-end":"stretch",marginBottom:10*!t},children:e.map((o,n)=>{let s="error"===o.type?"#ef4444":"warning"===o.type?"#d97706":"success"===o.type?"#10b981":"var(--accent)";return(0,r.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:10,minHeight:44,maxHeight:180,marginBottom:6*(n!==e.length-1),overflowY:"auto",overflowX:"hidden",borderRadius:14,border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",background:"var(--bg)",color:"var(--text-muted)",width:"fit-content",maxWidth:"min(100%, 620px)",boxShadow:t?"0 1px 2px rgba(15,23,42,0.05), 0 10px 28px -14px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",fontSize:13,lineHeight:1.45,transformOrigin:"top center",animation:o.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"0 12px"},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:s,flexShrink:0}}),(0,r.jsx)("span",{style:{padding:"10px 0",minWidth:0,maxWidth:"100%",overflowWrap:"anywhere",whiteSpace:"pre-wrap"},children:o.message})]},o.id)})})}function sJ({request:e,onRespond:t}){let{t:o}=(0,E.s)(),[s,i]=(0,n.useState)("editor"===e.method?e.prefill??"":"");(0,n.useEffect)(()=>{i("editor"===e.method?e.prefill??"":"")},[e]);let a=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:s})};return(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:"min(560px, 100%)",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,r.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:o("desktop.extensionRequest")})]}),(0,r.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap"},children:e.message}),"select"===e.method&&(0,r.jsx)("div",{style:{display:"grid",gap:8},children:e.options.map(o=>(0,r.jsx)("button",{onClick:()=>t(e,{value:o}),style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},children:o},o))}),"input"===e.method&&(0,r.jsx)("input",{autoFocus:!0,value:s,placeholder:e.placeholder,onChange:e=>i(e.target.value),onKeyDown:o=>{"Enter"===o.key&&a(),"Escape"===o.key&&t(e,{cancelled:!0})},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,r.jsx)("textarea",{autoFocus:!0,value:s,onChange:e=>i(e.target.value),onKeyDown:o=>{"Escape"===o.key&&t(e,{cancelled:!0}),(o.metaKey||o.ctrlKey)&&"Enter"===o.key&&a()},style:{width:"100%",minHeight:220,padding:10,borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,r.jsx)("button",{onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:o("desktop.cancel")}),"confirm"===e.method?(0,r.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:o("desktop.confirm")}):"select"!==e.method?(0,r.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:o("desktop.submit")}):null]})]})})}function sG({request:e,onInput:t}){let{t:o}=(0,E.s)(),s=(0,n.useRef)(null),i=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,o=[];for(let r of e){let e=e0(r).trimEnd();if(t.test(e))continue;let n=r,s=e4(n);("│"===s||"┃"===s)&&" "===e4(n=e2(n,0))&&(n=e2(n,0));let i=function(e){let t=e1(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(n),a=i>=0?e1(n)[i]?.char:void 0;("│"===a||"┃"===a)&&(n=e2(n,i)),o.push(function(e){let t=e;for(;;){let e=e1(t),o=e[e.length-1];if(!o||""!==o.char.trim())return t;t=t.slice(0,o.start)+t.slice(o.end)}}(n))}for(;o.length>0&&""===e0(o[0]).trim();)o.shift();for(;o.length>0&&""===e0(o[o.length-1]).trim();)o.pop();return o.length?o:e}(e.lines);return(0,n.useEffect)(()=>{s.current?.focus()},[e.id]),(0,r.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,r.jsxs)("div",{ref:s,tabIndex:0,role:"dialog","aria-modal":"true",onKeyDown:o=>{let r=function(e){if(e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length){let t=e.key.toLowerCase();if(t>="a"&&t<="z")return String.fromCharCode(t.charCodeAt(0)-96)}switch(e.key){case"ArrowUp":return"\x1b[A";case"ArrowDown":return"\x1b[B";case"ArrowRight":return"\x1b[C";case"ArrowLeft":return"\x1b[D";case"Enter":return"\r";case"Escape":return"\x1b";case"Backspace":return"";case"Tab":return" ";case" ":return" ";default:if(!e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length)return e.key;return null}}(o);r&&(o.preventDefault(),o.stopPropagation(),t(e,r))},style:{width:"min(920px, 100%)",maxHeight:"min(760px, calc(100vh - 40px))",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:o("desktop.extensionPanel")}),(0,r.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:o("desktop.close")})]}),(0,r.jsx)("pre",{style:{margin:0,padding:14,maxHeight:"calc(min(760px, 100vh - 40px) - 48px)",overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(i.length?i:[""]).map((e,t,o)=>{var s;return(0,r.jsxs)(n.Fragment,{children:[(s=`line-${t}`,(function(e){let t,o=[],r={},n=0;for(eZ.lastIndex=0;null!==(t=eZ.exec(e));)t.index>n&&o.push({text:e.slice(n,t.index),style:r}),r=function(e,t){let o={...e};for(let e=0;e<t.length;e++){let r=t[e];if(0===r)for(let e of Object.keys(o))delete o[e];else if(1===r)o.fontWeight=700;else if(2===r)o.opacity=.65;else if(3===r)o.fontStyle="italic";else if(4===r)o.textDecoration="underline";else if(22===r)delete o.fontWeight,delete o.opacity;else if(23===r)delete o.fontStyle;else if(24===r)delete o.textDecoration;else if(39===r)delete o.color;else if(49===r)delete o.backgroundColor;else if(r>=30&&r<=37)o.color=eX[r-30];else if(r>=90&&r<=97)o.color=eQ[r-90];else if(r>=40&&r<=47)o.backgroundColor=eX[r-40];else if(r>=100&&r<=107)o.backgroundColor=eQ[r-100];else if((38===r||48===r)&&2===t[e+1]){let[n,s,i]=[t[e+2],t[e+3],t[e+4]];[n,s,i].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===r?o.color=`rgb(${n}, ${s}, ${i})`:o.backgroundColor=`rgb(${n}, ${s}, ${i})`),e+=4}else if((38===r||48===r)&&5===t[e+1]){let n=function(e){if(e>=0&&e<8)return eX[e];if(e>=8&&e<16)return eQ[e-8];if(e>=16&&e<=231){let t=e-16,o=Math.floor(t/36),r=Math.floor(t%36/6),n=e=>0===e?0:55+40*e;return`rgb(${n(o)}, ${n(r)}, ${n(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);n&&(38===r?o.color=n:o.backgroundColor=n),e+=2}}return o}(r,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),n=t.index+t[0].length;return n<e.length&&o.push({text:e.slice(n),style:r}),o})(e).map((e,t)=>Object.keys(e.style).length>0?(0,r.jsx)("span",{style:e.style,children:e.text},`${s}-${t}`):e.text)),t<o.length-1?"\n":null]},t)})})]})})}let sY={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"},sZ={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",weba:"audio/webm",webm:"audio/webm"};function sX(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}function sQ(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function s0(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let o=t.getRangeAt(0);if(!e.contains(o.startContainer)||!e.contains(o.endContainer))return null;let r=Number(sQ(o.startContainer)?.dataset.lineNumber),n=Number(sQ(o.endContainer)?.dataset.lineNumber);return Number.isInteger(r)&&Number.isInteger(n)?r<=n?{startLine:r,endLine:n}:{startLine:n,endLine:r}:null}function s1(e,t,o,r={}){let n=Z(e),s=new URLSearchParams({type:t});for(let[e,t]of(o&&s.set("sessionId",o),Object.entries(r)))void 0!==t&&s.set(e,String(t));return`/api/files/${n}?${s.toString()}`}function s2({filePath:e,sourceSessionId:t}){let{t:o}=(0,E.s)();return(0,r.jsx)("a",{href:s1(e,"download",t),download:X(e),title:o("desktop.downloadFile"),style:{display:"flex",alignItems:"center",justifyContent:"center",height:20,padding:"0 5px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,textDecoration:"none"},children:(0,r.jsx)(R.z,{size:11,"aria-hidden":"true"})})}let s4={delete:"3px solid var(--git-status-deleted)",add:"3px solid var(--git-status-added)",edit:"3px solid var(--git-status-modified)"},s6="var(--git-status-deleted-bg)",s5="var(--git-status-added-bg)",s3="var(--git-status-added)";function s8(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function s7({oldContent:e,newContent:t}){let{t:o}=(0,E.s)(),n=function(e,t){let o=e.length,r=t.length,n=o+r,s=Array(2*n+1).fill(0),i=[];for(let a=0;a<=n;a++){i.push([...s]);for(let l=-a;l<=a;l+=2){let d,c=(d=l===-a||l!==a&&s[l-1+n]<s[l+1+n]?s[l+1+n]:s[l-1+n]+1)-l;for(;d<o&&c<r&&e[d]===t[c];)d++,c++;if(s[l+n]=d,d>=o&&c>=r){let s=[],l=o,d=r;for(let o=a;o>0;o--){let r,a=i[o-1],c=l-d;r=c===-o||c!==o&&a[c-1+n]<a[c+1+n]?c+1:c-1;let p=a[r+n],u=p-r;for(;l>p&&d>u;)l--,d--,s.unshift({type:"unchanged",text:e[l]});o>0&&(l>p?(l--,s.unshift({type:"removed",text:e[l]})):(d--,s.unshift({type:"added",text:t[d]})))}for(;l>0&&d>0;)l--,d--,s.unshift({type:"unchanged",text:e[l]});return s}}}return[...e.map(e=>({type:"removed",text:e})),...t.map(e=>({type:"added",text:e}))]}(e.split("\n"),t.split("\n"));if(!n.some(e=>"unchanged"!==e.type))return(0,r.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:o("desktop.noChanges")});let s=new Set(n.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),i=new Set;for(let e of s)for(let t=Math.max(0,e-3);t<=Math.min(n.length-1,e+3);t++)i.add(t);let a=[],l=0;for(;l<n.length;)if(i.has(l)){let e=[];for(;l<n.length&&i.has(l);)e.push(n[l]),l++;a.push({hidden:!1,lines:e})}else{let e=0;for(;l<n.length&&!i.has(l);)e++,l++;a.push({hidden:!0,count:e})}let d=[],c=1;for(let e of n)"removed"===e.type?d.push(0):d.push(c++);let p=0;return(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,minWidth:"max-content"},children:a.map((e,t)=>{if(e.hidden){let n=(0,r.jsx)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:o("desktop.unchangedLines",{count:e.count})},t);return p+=e.count,n}let n=[],s=[],i=[],a=()=>{if(s.length||i.length){let e=s.length&&i.length?"edit":s.length?"delete":"add";for(let t of s)n.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of i)n.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});s=[],i=[]}};e.lines.forEach((e,o)=>{"unchanged"===e.type?(a(),n.push({key:`${t}:${o}`,kind:"context",text:e.text,lineNo:d[p+o],block:null})):"removed"===e.type?s.push({key:`${t}:${o}`,text:e.text}):i.push({key:`${t}:${o}`,text:e.text,lineNo:d[p+o]})}),a();let l=n.map(e=>{let t="removed"===e.kind?s6:"added"===e.kind?s5:"transparent",o=e.block?s4[e.block]:"3px solid transparent",n="added"===e.kind?s3:"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",background:t,borderLeft:o},children:[(0,r.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:n,userSelect:"none",fontSize:11,lineHeight:1.6,flexShrink:0},children:e.lineNo??""}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)});return p+=e.lines.length,(0,r.jsx)("div",{children:l},t)})})}function s9({patch:e}){let t=od(e);if(!t)return null;let o=[],n=[],s=[],i=()=>{if(n.length||s.length){let e=n.length&&s.length?"edit":n.length?"delete":"add";for(let t of n)o.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of s)o.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});n=[],s=[]}};return t.forEach((e,t)=>{e.rows.forEach((e,r)=>{if("hunk"===e.type){i(),o.push({key:`${t}:${r}:h`,kind:"hunk",text:e.text,lineNo:null,block:null});return}let{left:a,right:l}=e;if("context"===a.type&&"context"===l.type){i(),o.push({key:`${t}:${r}:c`,kind:"context",text:a.text,lineNo:l.lineNo,block:null});return}"removed"===a.type&&n.push({key:`${t}:${r}:l`,text:a.text}),"added"===l.type&&s.push({key:`${t}:${r}:r`,text:l.text,lineNo:l.lineNo})})}),i(),(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:"max-content"},children:o.map(e=>{if("hunk"===e.kind)return(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{height:"1.55em"}}),(0,r.jsx)("div",{style:{padding:"3px 12px",color:"var(--accent-blue)",background:"var(--bg-secondary)"},children:e.text}),(0,r.jsx)("div",{style:{height:"1.55em"}})]},e.key);let t="removed"===e.kind?s6:"added"===e.kind?s5:"transparent",o=e.block?s4[e.block]:"3px solid transparent",n="added"===e.kind?s3:"var(--text-dim)";return(0,r.jsxs)("div",{style:{display:"flex",background:t,borderLeft:o},children:[(0,r.jsx)("span",{style:{width:44,flexShrink:0,padding:"0 8px 0 16px",textAlign:"right",color:n,userSelect:"none",fontSize:11},children:e.lineNo??""}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)})})}function ie({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,E.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),[u,g]=(0,n.useState)(null),h=(0,n.useRef)(null),x=X(e).toLowerCase().split(".").pop()??"";(0,n.useEffect)(()=>{a(0),d(null),p(null),g(null),h.current&&(h.current.close(),h.current=null);let t=new EventSource(s1(e,"watch",o));return h.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}a(e=>e+1)}),()=>{t.close(),h.current=null}},[e,o]);let f=s1(e,"read",o,i?{v:i}:void 0),m=null!=l?s8(l):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:Q(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:x||s("desktop.image")}),c&&(0,r.jsxs)("span",{children:[c.w," \xd7 ",c.h]}),m&&(0,r.jsx)("span",{children:m}),(0,r.jsx)(s2,{filePath:e,sourceSessionId:o})]}),(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:u?(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13},children:u}):(0,r.jsx)("img",{src:f,alt:e,onLoad:e=>{let t=e.currentTarget;p({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>g(s("desktop.failedToLoadImage")),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function it({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,E.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),[u,g]=(0,n.useState)(null),h=(0,n.useRef)(null),x=X(e).toLowerCase().split(".").pop()??"";(0,n.useEffect)(()=>{a(0),d(null),p(null),g(null),h.current&&(h.current.close(),h.current=null);let t=new EventSource(s1(e,"watch",o));return h.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}p(null),g(null),a(e=>e+1)}),()=>{t.close(),h.current=null}},[e,o]);let f=s1(e,"read",o,i?{v:i}: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:Q(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:x||s("desktop.audio")}),null!=c&&(0,r.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),o=Math.floor(t/60);return`${o}:${String(t%60).padStart(2,"0")}`}(c)}),null!=l&&(0,r.jsx)("span",{children:s8(l)}),(0,r.jsx)(s2,{filePath:e,sourceSessionId:o})]}),(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:[u&&(0,r.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:u}),(0,r.jsx)("audio",{controls:!0,preload:"metadata",src:f,onLoadedMetadata:e=>p(e.currentTarget.duration),onError:()=>g(s("desktop.failedToLoadAudio")),style:{width:"100%"}},f)]})})]})}function io({filePath:e,cwd:t,sourceSessionId:o}){let{t:s}=(0,E.s)(),[i,a]=(0,n.useState)(0),[l,d]=(0,n.useState)(null),[c,p]=(0,n.useState)(null),u=(0,n.useRef)(null),g=sX(e),h="pdf"===g,x=h?s1(e,"read",o,i?{v:i}:void 0):s1(e,"preview",o,i?{v:i}:void 0);return(0,n.useEffect)(()=>{a(0),d(null),p(null),u.current&&(u.current.close(),u.current=null),fetch(s1(e,"meta",o)).then(e=>e.json()).then(e=>{e.error&&p(e.error),"number"==typeof e.size&&(d(e.size),!h&&e.size>0xa00000&&p(s("desktop.docxTooLargeForPreview")))}).catch(e=>p(String(e)));let t=new EventSource(s1(e,"watch",o));return u.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(d(t.size),!h&&t.size>0xa00000))return void p(s("desktop.docxTooLargeForPreview"))}catch{}p(null),a(e=>e+1)}),()=>{t.close(),u.current=null}},[e,h,o,s]),(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:Q(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===g?s("desktop.docxPreview"):"pdf"}),null!=l&&(0,r.jsx)("span",{children:s8(l)}),(0,r.jsx)(s2,{filePath:e,sourceSessionId:o})]}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:c?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:c}):(0,r.jsx)("iframe",{src:x,sandbox:h?void 0:"allow-same-origin",title:s("desktop.previewFile",{file:X(e)}),style:{width:"100%",height:"100%",border:"none",background:h?"var(--bg)":"#eef1f5"}},x)})]})}function ir({filePath:e,cwd:t,sourceSessionId:o,onOpenFile:n,onAtMention:s,onMentionLines:i,initialDisplayMode:a}){let l;return null!==(sY[sX(e)]??null)?(0,r.jsx)(ie,{filePath:e,cwd:t,sourceSessionId:o}):null!==(sZ[sX(e)]??null)?(0,r.jsx)(it,{filePath:e,cwd:t,sourceSessionId:o}):null!==("pdf"===(l=sX(e))||"docx"===l?l:null)?(0,r.jsx)(io,{filePath:e,cwd:t,sourceSessionId:o}):(0,r.jsx)(is,{filePath:e,cwd:t,sourceSessionId:o,onOpenFile:n,onAtMention:s,onMentionLines:i,initialDisplayMode:a})}function is({filePath:e,cwd:t,sourceSessionId:o,onOpenFile:s,onAtMention:i,onMentionLines:a,initialDisplayMode:l}){let d,c,{t:p}=(0,E.s)(),[u,g]=(0,n.useState)(null),[h,x]=(0,n.useState)(null),[f,m]=(0,n.useState)(null),[k,v]=(0,n.useState)(!0),[y,b]=(0,n.useState)(null),[w,j]=(0,n.useState)(!1),[S,C]=(0,n.useState)("source"),[T,z]=(0,n.useState)(!1),[R,I]=(0,n.useState)(0),[M,P]=(0,n.useState)(null),D=(0,n.useRef)(null),$=(0,n.useRef)(null),F=(0,n.useCallback)(async e=>{if(!t)return void m(null);try{let o=new URLSearchParams({cwd:t,path:e}),r=await fetch(`/api/git/diff?${o.toString()}`),n=await r.json();m(r.ok&&n.supported&&"string"==typeof n.patch?n:null)}catch{m(null)}},[t]),W=(0,n.useCallback)((e,t=!1)=>fetch(s1(e,"read",o)).then(e=>e.json()).then(e=>e.error?(b(e.error),null):(t?(g(t=>(t&&x(t.content),e)),I(e=>e+1)):g(e),e)).catch(e=>(b(String(e)),null)),[o]);(0,n.useEffect)(()=>{v(!0),b(null),g(null),x(null),m(null),j(!1),C("source"),z(!1),I(0),D.current&&(D.current.close(),D.current=null),W(e).then(e=>{(e?.language==="markdown"||e?.language==="html")&&"diff"!==l&&j(!0)}).finally(()=>v(!1)),F(e);let t=new EventSource(s1(e,"watch",o));return D.current=t,t.addEventListener("change",()=>{W(e,!0),F(e)}),()=>{t.close(),D.current=null}},[e,W,F,l,o]);let N=(0,n.useMemo)(()=>tU(u?.content??""),[u?.content]),A=f?.supported===!0&&"string"==typeof f.patch;(0,n.useEffect)(()=>{"diff"===l&&A&&C("diff")},[A,l]);let L=A&&f?.status==="deleted",O=(0,n.useCallback)(o=>{a&&o&&a(Q(e,t),o.startLine,o.endLine)},[t,e,a]);if((0,n.useEffect)(()=>{let e=()=>{let e=$.current,t="source"===S&&!w;P(a&&t&&e?s0(e,window.getSelection()):null)};if(e(),a&&"source"===S&&!w)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[u?.content,a,w,S]),(0,n.useEffect)(()=>{if(!a||"source"!==S||w)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 o=$.current,r=o?s0(o,window.getSelection()):null;r&&(e.preventDefault(),O(r))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[O,a,w,S]),k)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:p("desktop.loadingFile")});if(L&&!u)return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{padding:"5px 16px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:e,children:Q(e,t)}),(0,r.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:(0,r.jsx)(s9,{patch:f.patch})})]});if(y)return(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:y});if(!u)return null;let H="html"===u.language,B="markdown"===u.language,U=(c=(d=Y(e).replace(/\/+$/,"")).lastIndexOf("/"))<0?"":0===c?"/":2===c&&/^[a-zA-Z]:\//.test(d)?d.slice(0,3):d.slice(0,c),_=u.content.split("\n"),q=null!==h&&h!==u.content||A;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:Q(e,t)}),(0,r.jsx)("span",{style:{marginLeft:"auto"},children:u.language}),"source"===S&&(0,r.jsx)("span",{children:p("desktop.lines",{count:_.length})}),(0,r.jsx)("span",{children:s8(u.size)}),q&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>C("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===S?"var(--bg-selected)":"var(--bg-hover)",color:"source"===S?"var(--text)":"var(--text-muted)",fontWeight:"source"===S?600:400},children:p("desktop.source")}),(0,r.jsxs)("button",{onClick:()=>C("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===S?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===S?"var(--text)":"var(--text-muted)",fontWeight:"diff"===S?600:400},children:[p("desktop.diff")," ",R>0&&(0,r.jsxs)("span",{style:{color:"var(--git-status-added)",marginLeft:2},children:["+",R]})]})]}),"source"===S&&!w&&(0,r.jsx)("button",{onClick:()=>z(e=>!e),title:p(T?"desktop.disableWordWrap":"desktop.enableWordWrap"),style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:T?"var(--bg-selected)":"var(--bg-hover)",color:T?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:T?600:400},children:p("desktop.wrap")}),H&&"source"===S&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>j(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:w?"var(--bg-hover)":"var(--bg-selected)",color:w?"var(--text-muted)":"var(--text)",fontWeight:w?400:600},children:p("desktop.code")}),(0,r.jsx)("button",{onClick:()=>j(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:w?"var(--bg-selected)":"var(--bg-hover)",color:w?"var(--text)":"var(--text-muted)",fontWeight:w?600:400},children:p("desktop.preview")})]}),B&&"source"===S&&(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,r.jsx)("button",{onClick:()=>j(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:w?"var(--bg-selected)":"var(--bg-hover)",color:w?"var(--text)":"var(--text-muted)",fontWeight:w?600:400},children:p("desktop.preview")}),(0,r.jsx)("button",{onClick:()=>j(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:w?"var(--bg-hover)":"var(--bg-selected)",color:w?"var(--text-muted)":"var(--text)",fontWeight:w?400:600},children:p("desktop.raw")})]}),(i||a)&&(0,r.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{M&&a?O(M):i?.(Q(e,t),!1)},title:M?p("desktop.mentionSelectedLines",{start:M.startLine,end:M.endLine}):p("desktop.mentionFile"),"aria-label":M?p("desktop.mentionSelectedLines",{start:M.startLine,end:M.endLine}):p("desktop.mentionFile"),style:{height:20,minWidth:20,padding:"0 5px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:"@"}),(0,r.jsx)(s2,{filePath:e,sourceSessionId:o})]}),(0,r.jsx)("div",{ref:$,style:{flex:1,overflow:"auto",background:"var(--bg)"},children:"diff"===S&&q?A?(0,r.jsx)(s9,{patch:f.patch}):(0,r.jsx)(s7,{oldContent:h,newContent:u.content}):H&&w?(0,r.jsx)("iframe",{srcDoc:u.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:p("desktop.htmlPreview")}):B&&w?(0,r.jsx)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:(0,r.jsx)(ta.oz,{remarkPlugins:tV,rehypePlugins:tK,components:{h1:({children:e})=>(0,r.jsx)("h1",{id:tB(e),children:e}),h2:({children:e})=>(0,r.jsx)("h2",{id:tB(e),children:e}),h3:({children:e})=>(0,r.jsx)("h3",{id:tB(e),children:e}),code({className:e,children:t,...o}){let n=e?.replace("language-","").toLowerCase()??"",s=String(t);return e?.includes("language-")||s.includes("\n")?"mermaid"===n?(0,r.jsx)(t9,{code:s.replace(/\n$/,"")}):(0,r.jsx)(oo,{code:s.replace(/\n$/,""),lang:n}):(0,r.jsx)("code",{className:"inline max-w-full whitespace-normal break-words [overflow-wrap:anywhere] align-baseline bg-(--bg-secondary) border border-(--border) px-1.5 py-0.5 text-xs font-mono text-(--accent-blue)",...o,children:t})},pre:({children:e})=>(0,r.jsx)(r.Fragment,{children:e}),a({href:e,children:o,...n}){delete n.node;let i="text-(--accent-blue) underline underline-offset-2 hover:text-(--accent-blue)/80",a=s?te(e,U,t??U):null;return a&&s?(0,r.jsx)("a",{href:e,...n,className:i,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),s(a))},children:o}):(0,r.jsx)("a",{href:e,...n,className:i,target:"_blank",rel:"noopener noreferrer",children:o})},table:({children:e})=>(0,r.jsx)("div",{className:"my-3 rounded-lg overflow-hidden border border-(--border)",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsx)("table",{className:"w-full text-sm border-collapse [&_tr:last-child>td]:border-b-0",children:e})})})},children:N})}):(0,r.jsx)(tl.A,{language:"text"===u.language?"plaintext":u.language,style:tJ,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal",minWidth:"3em",paddingRight:"1em"},customStyle:{margin:0,padding:"12px 0",background:"var(--bg)",fontSize:13,lineHeight:1.6,fontFamily:"var(--font-mono)",minHeight:"100%"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},lineProps:e=>({className:"file-source-line","data-line-number":String(e)}),wrapLongLines:T,children:u.content})})]})}let ii={running:"var(--accent)",completed:"#22c55e",failed:"#ef4444",stopped:"#d97706"},ia={running:"desktop.subagentsStatusRunning",completed:"desktop.subagentsStatusCompleted",failed:"desktop.subagentsStatusFailed",stopped:"desktop.subagentsStatusStopped"};function il({agent:e,selected:t,onSelect:o}){let[s,i]=(0,n.useState)(!1),{t:a}=(0,E.s)(),[l,d]=(0,n.useState)(()=>Date.now());(0,n.useEffect)(()=>{if("running"!==e.status)return;let t=setInterval(()=>d(Date.now()),1e3);return()=>clearInterval(t)},[e.status]);let c=e.completedAt?e.completedAt-e.startedAt:l-e.startedAt,p=e.tokens?.total??e.tokens?.input??e.tokens?.output,u=ii[e.status];return(0,r.jsxs)("button",{type:"button",onClick:()=>o?.(e),onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),title:e.error||`${e.agentType} \xb7 ${e.description}`,style:{width:"100%",display:"flex",alignItems:"center",gap:7,padding:"5px 10px",border:"none",borderRadius:5,background:t?"var(--bg-selected)":s?"var(--bg-hover)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left",minWidth:0},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{width:7,height:7,flexShrink:0,borderRadius:"50%",background:u,boxShadow:"running"===e.status?`0 0 0 0 ${u}`:"none",animation:"running"===e.status?"subagent-pulse 1.4s ease-out infinite":"none"}}),(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",fontWeight:600,color:"var(--text-dim)"},children:e.agentType}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11.5,color:"var(--text-muted)"},children:e.description||a("desktop.subagentsNoDesc")}),void 0!==p&&p>0&&(0,r.jsxs)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)"},children:[void 0===p?"":p>=1e6?`${(p/1e6).toFixed(1)}M`:p>=1e3?`${(p/1e3).toFixed(1)}k`:`${p}`,"t"]}),(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)"},children:function(e){if(void 0===e)return"…";if(e<1e3)return`${e}ms`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let o=Math.floor(t/60),r=t%60;return r>0?`${o}m ${r}s`:`${o}m`}(c)}),(0,r.jsx)("span",{style:{flexShrink:0,fontSize:10,color:u},children:a(ia[e.status])})]})}function id({subagents:e,onSelect:t,selectedId:o}){let{t:s}=(0,E.s)(),[i,a]=(0,n.useState)(!0),l=e.filter(e=>"running"===e.status).length;return 0===e.length?(0,r.jsx)("div",{style:{padding:"18px 14px",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:s("desktop.subagentsEmpty")}):(0,r.jsxs)("section",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,padding:"6px 10px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>a(e=>!e),"aria-expanded":i,style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,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)(m.K,{size:9,weight:"regular",style:{transform:i?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s("desktop.subagentsPanelTitle")})]}),l>0&&(0,r.jsxs)("span",{style:{marginRight:4,fontSize:10,fontFamily:"var(--font-mono)",color:"var(--accent)"},children:["● ",l," ",s("desktop.subagentsStatusRunning")]})]}),i&&(0,r.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",overflowX:"hidden",padding:"4px 0 8px"},children:e.map(e=>(0,r.jsx)(il,{agent:e,selected:e.id===o,onSelect:t},e.id))})]})}var ic=o(31597);let ip={user:{label:"User",color:"var(--accent)"},assistant:{label:"Assistant",color:"var(--text)"},toolResult:{label:"Result",color:"var(--text-dim)"},bashExecution:{label:"Bash",color:"var(--text-muted)"}};function iu({line:e}){let t=ip[e.role]??ip.toolResult;return(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsxs)("div",{style:{fontSize:10.5,fontWeight:600,color:t.color,marginBottom:2,fontFamily:"var(--font-mono)"},children:["[",t.label,"]"]}),(0,r.jsx)("pre",{style:{margin:0,fontSize:11.5,lineHeight:1.55,color:"var(--text-muted)",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)",maxHeight:240,overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,padding:"6px 8px"},children:e.text})]})}function ig({agent:e,cwd:t,onBack:o}){let{t:s}=(0,E.s)(),[i,a]=(0,n.useState)([]),[l,d]=(0,n.useState)(!0),[c,p]=(0,n.useState)(null),u=(0,n.useRef)(null),g=(0,n.useRef)(!0),h=(0,n.useCallback)(async(o=!1)=>{if(e.id&&t){o||d(!0);try{let r=new URLSearchParams({id:e.id,cwd:t}),n=await fetch(`/api/subagents/transcript?${r}`),s=await n.json();if(!n.ok||s.error){o||p(s.error??`HTTP ${n.status}`);return}a(s.lines??[]),p(null)}catch(e){o||p(e instanceof Error?e.message:String(e))}finally{d(!1)}}},[e.id,t]);(0,n.useEffect)(()=>{h()},[h]),(0,n.useEffect)(()=>{if("running"!==e.status)return;let t=setInterval(()=>void h(!0),2e3);return()=>clearInterval(t)},[e.status,h]),(0,n.useEffect)(()=>{let e=u.current;e&&g.current&&(e.scrollTop=e.scrollHeight)},[i]);let x=e.completedAt?e.completedAt-e.startedAt:void 0,f=e.tokens?.total??e.tokens?.input??e.tokens?.output,m="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":"stopped"===e.status?"#d97706":"var(--accent)";return(0,r.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[(0,r.jsxs)("div",{style:{flexShrink:0,borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",padding:"6px 8px"},children:[(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",gap:8},children:(0,r.jsxs)("button",{type:"button",onClick:o,title:s("desktop.subagentsBack"),style:{display:"inline-flex",alignItems:"center",gap:2,padding:"3px 6px",border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:11},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:[(0,r.jsx)(ic.Z,{size:12,"aria-hidden":"true"}),s("desktop.subagentsBack")]})}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4,minWidth:0},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{width:8,height:8,flexShrink:0,borderRadius:"50%",background:m,boxShadow:"running"===e.status?`0 0 0 0 ${m}`:"none",animation:"running"===e.status?"subagent-pulse 1.4s ease-out infinite":"none"}}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)",fontFamily:"var(--font-mono)",flexShrink:0},children:e.agentType}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11.5,color:"var(--text-muted)"},children:e.description})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:3,fontSize:10.5,fontFamily:"var(--font-mono)",color:"var(--text-dim)"},children:[void 0!==e.toolUses&&e.toolUses>0&&(0,r.jsxs)("span",{children:[e.toolUses," tool",1===e.toolUses?"":"s"]}),void 0!==f&&f>0&&(0,r.jsxs)("span",{children:[void 0===f?"":f>=1e6?`${(f/1e6).toFixed(1)}M`:f>=1e3?`${(f/1e3).toFixed(1)}k`:`${f}`," tokens"]}),void 0!==x&&(0,r.jsx)("span",{children:function(e){if(void 0===e)return"";if(e<1e3)return`${e}ms`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let o=Math.floor(t/60),r=t%60;return r>0?`${o}m ${r}s`:`${o}m`}(x)}),(0,r.jsx)("span",{style:{color:m},children:s(`desktop.subagentsStatus${"running"===e.status?"Running":"completed"===e.status?"Completed":"failed"===e.status?"Failed":"Stopped"}`)})]})]}),(0,r.jsx)("div",{ref:u,onScroll:e=>{let t=e.currentTarget;g.current=t.scrollHeight-t.scrollTop-t.clientHeight<40},style:{flex:1,minHeight:0,overflowY:"auto",overflowX:"hidden",padding:"8px 10px",background:"var(--bg)"},children:l?(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--text-dim)",padding:"12px 4px"},children:[s("desktop.loading"),"…"]}):c?(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",padding:"12px 4px"},children:c}):0===i.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",padding:"12px 4px"},children:s("running"===e.status?"desktop.subagentsWaitingFirstMessage":"desktop.subagentsNoTranscript")}):(0,r.jsx)("div",{style:{paddingBottom:8},children:i.map((e,t)=>(0,r.jsx)(iu,{line:e},t))})})]})}function ih({tabs:e,activeTabId:t,onSelectTab:o,onCloseTab:s}){let{t:i}=(0,E.s)(),[a,l]=(0,n.useState)(null);return(0,r.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let n=e.id===t;return(0,r.jsxs)("div",{onClick:()=>o(e.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:t=>{1===t.button&&(t.preventDefault(),t.stopPropagation(),s(e.id))},style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:n?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:n?"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:n?1:.7,display:"flex",alignItems:"center"},children:G(e.label,13)}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:n?500:400},title:e.filePath,children:e.label}),(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),s(e.id)},onMouseEnter:()=>l(e.id),onMouseLeave:()=>l(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,background:a===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:4,color:a===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:i("desktop.closeTab"),"aria-label":i("desktop.closeTabWithLabel",{label:e.label}),children:(0,r.jsx)(c.X,{size:11,"aria-hidden":"true"})})]},e.id)})})}var ix=o(93534),im=o(45781),ik=o(68731),iv=o(93912),iy=o(23675),ib=o(48716),iw=o(47013),ij=o(51265);let iS={"restore-script":"restore","generate-cmd":"cmd",keep:"keep","keep-with-warning":"warning",manual:"manual"};function iC({cwd:e}){let{t}=(0,E.s)(),o=(0,n.useRef)(null),[s,i]=(0,n.useState)(!0),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(!1),[p,u]=(0,n.useState)(null),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(new Set),[m,k]=(0,n.useState)(new Set),[v,y]=(0,n.useState)(!1),[b,w]=(0,n.useState)(null),[j,S]=(0,n.useState)(!1),[C,T]=(0,n.useState)(null),[z,R]=(0,n.useState)([]),[I,M]=(0,n.useState)(""),[P,D]=(0,n.useState)(null),[$,F]=(0,n.useState)(null);(0,n.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{let t=e.models??[];R(t),t.length>0&&M(`${t[0].provider}/${t[0].id}`)}).catch(()=>{})},[]);let W=(0,n.useCallback)(async()=>{c(!0),u(null);try{let e=await fetch("/api/backup/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({includeSecrets:s,includeSessions:a})});if(!e.ok){let t=await e.json();u(t.error??`HTTP ${e.status}`);return}let t=await e.blob(),o=(e.headers.get("Content-Disposition")??"").match(/filename="?([^";]+)"?/),r=URL.createObjectURL(t),n=document.createElement("a");n.href=r,n.download=o?.[1]??"pi-backup.zip",document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(r)}catch{u(String(t("desktop.backupExportFailed")))}finally{c(!1)}},[s,a,t]),N=(0,n.useCallback)(async e=>{if(e){w(null),T(null),h(null);try{let o=new FormData;o.append("phase","parse"),o.append("file",e);let r=await fetch("/api/backup/import",{method:"POST",body:o}),n=await r.json();if(!r.ok||n.error)return void w(n.error??`HTTP ${r.status}`);if("preview"!==n.phase||!n.preview)return void w(String(t("desktop.backupImportFailed")));h(n),f(new Set(n.preview.categories)),k(new Set),y(!1)}catch{w(String(t("desktop.backupImportFailed")))}}},[t]),A=(0,n.useCallback)(async()=>{if(g){S(!0),w(null);try{let e=new FormData;e.append("phase","restore"),e.append("token",g.token),e.append("selections",JSON.stringify({categories:[...x],skippedMcpServers:[...m],reinstallNpm:v}));let r=await fetch("/api/backup/import",{method:"POST",body:e}),n=await r.json();if(!r.ok||n.error)return void w(n.error??`HTTP ${r.status}`);if("report"!==n.phase||!n.report)return void w(String(t("desktop.backupRestoreFailed")));T(n.report),h(null),o.current&&(o.current.value="")}catch{w(String(t("desktop.backupRestoreFailed")))}finally{S(!1)}}},[g,x,m,v,t]),O=(0,n.useCallback)(async o=>{if(o.installPrompt&&e){D(o.name),F(null);try{let t=I.indexOf("/"),r=t>0?I.slice(0,t):void 0,n=t>0?I.slice(t+1):void 0,s=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,message:o.installPrompt,provider:r,modelId:n})}),i=await s.json();if(!s.ok||i.error)return void w(i.error??`HTTP ${s.status}`);F({server:o.name,sessionId:i.sessionId})}catch{w(String(t("desktop.backupInstallSessionFailed")))}finally{D(null)}}},[e,I,t]),H=e=>"win32"===e?"Windows":"darwin"===e?"macOS":"Linux";return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:[(0,r.jsx)("header",{style:{padding:"18px 22px 14px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("h1",{style:{margin:0,fontSize:16,fontWeight:700,color:"var(--text)"},children:t("desktop.backup")})}),(0,r.jsxs)("section",{style:{padding:"18px 22px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--text)"},children:t("desktop.backupExportTitle")}),(0,r.jsx)("p",{style:{margin:"6px 0 12px",fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:t("desktop.backupExportDescription")}),(0,r.jsxs)("label",{style:{display:"flex",gap:8,alignItems:"flex-start",cursor:"pointer",marginBottom:8},children:[(0,r.jsx)("input",{type:"checkbox",checked:s,onChange:e=>i(e.target.checked),style:{marginTop:2}}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text)"},children:[t("desktop.backupIncludeSecrets"),(0,r.jsx)("span",{style:{display:"block",fontSize:11,color:"#ef4444"},children:t("desktop.backupSecretsWarning")})]})]}),(0,r.jsxs)("label",{style:{display:"flex",gap:8,alignItems:"flex-start",cursor:"pointer",marginBottom:14},children:[(0,r.jsx)("input",{type:"checkbox",checked:a,onChange:e=>l(e.target.checked),style:{marginTop:2}}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text)"},children:[t("desktop.backupIncludeSessions"),(0,r.jsx)("span",{style:{display:"block",fontSize:11,color:"var(--text-dim)"},children:t("desktop.backupSessionsHint")})]})]}),(0,r.jsxs)("button",{type:"button",onClick:W,disabled:d,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--accent)",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:d?"wait":"pointer"},children:[(0,r.jsx)(iw.f,{size:15,"aria-hidden":"true"}),d?t("desktop.backupExporting"):t("desktop.backupExportButton")]}),p&&(0,r.jsx)("p",{style:{margin:"8px 0 0",fontSize:11,color:"#ef4444"},children:p})]}),(0,r.jsxs)("section",{style:{padding:"18px 22px"},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--text)"},children:t("desktop.backupImportTitle")}),(0,r.jsx)("p",{style:{margin:"6px 0 12px",fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:t("desktop.backupImportDescription")}),(0,r.jsx)("input",{ref:o,type:"file",accept:".zip,application/zip",onChange:e=>N(e.target.files?.[0]),style:{display:"none"}}),(0,r.jsxs)("button",{type:"button",onClick:()=>o.current?.click(),style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,r.jsx)(ij._,{size:15,"aria-hidden":"true"}),t("desktop.backupImportButton")]}),b&&(0,r.jsx)("p",{style:{margin:"0 0 10px",fontSize:11,color:"#ef4444",lineHeight:1.5},children:b}),g&&(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,padding:14,background:"var(--bg-panel)",display:"flex",flexDirection:"column",gap:12},children:[(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:[(0,r.jsxs)("span",{style:{color:"var(--text)",fontWeight:600},children:[t("desktop.backupManifest"),":"]})," ",new Date(g.preview.manifest.createdAt).toLocaleString()," \xb7 ",H(g.preview.manifest.sourcePlatform)," →",H(navigator.platform.includes("Win")?"win32":navigator.platform.includes("Linux")?"linux":"darwin")," \xb7 pi-web ",g.preview.manifest.piWebVersion,g.preview.manifest.includeSecrets?"":` \xb7 ${t("desktop.backupNoSecrets")}`]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:6},children:t("desktop.backupCategories")}),(0,r.jsx)("div",{style:{display:"flex",gap:14,flexWrap:"wrap"},children:g.preview.categories.map(e=>(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",cursor:"pointer",fontSize:12,color:"var(--text)"},children:[(0,r.jsx)("input",{type:"checkbox",checked:x.has(e),onChange:t=>{let o=new Set(x);t.target.checked?o.add(e):o.delete(e),f(o)}}),t(`desktop.backupCategory${e}`)]},e))})]}),g.preview.servers.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:6},children:t("desktop.backupMcpServers")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:g.preview.servers.map(o=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,fontSize:12},children:[(0,r.jsx)("input",{type:"checkbox",checked:!m.has(o.name),onChange:e=>{let t=new Set(m);e.target.checked?t.delete(o.name):t.add(o.name),k(t)},style:{marginTop:2}}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:2},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("code",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text)"},children:o.name}),(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:8,background:"manual"===o.action||"keep-with-warning"===o.action?"rgba(239,68,68,0.15)":"var(--bg-selected)",color:"manual"===o.action||"keep-with-warning"===o.action?"#ef4444":"var(--text-muted)"},children:iS[o.action]})]}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:o.original.command}),o.adapted&&o.adapted.command!==o.original.command&&(0,r.jsxs)(r.Fragment,{children:[" → ",(0,r.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:o.adapted.command})]})]}),o.reason&&(0,r.jsx)("div",{style:{fontSize:11,color:"#ef4444"},children:o.reason}),"manual"===o.action&&o.installPrompt&&e&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:2,flexWrap:"wrap"},children:[(0,r.jsx)("select",{value:I,onChange:e=>M(e.target.value),style:{fontSize:11,padding:"4px 6px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",maxWidth:220},title:t("desktop.backupInstallModel"),children:z.map(e=>(0,r.jsxs)("option",{value:`${e.provider}/${e.id}`,children:[e.provider,"/",e.name||e.id]},`${e.provider}/${e.id}`))}),(0,r.jsx)("button",{type:"button",disabled:P===o.name,onClick:()=>O(o),style:{padding:"4px 10px",fontSize:11,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",cursor:P===o.name?"wait":"pointer"},children:P===o.name?"…":t("desktop.backupInstallSession")}),$?.server===o.name&&(0,r.jsx)("a",{href:`?session=${encodeURIComponent($.sessionId)}`,style:{fontSize:11,color:"var(--accent)"},children:t("desktop.backupOpenSession")})]})]})]},o.name))})]}),g.preview.npmPackages.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:6},children:t("desktop.backupNpmPackages")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4,marginBottom:6},children:g.preview.npmPackages.map(e=>(0,r.jsx)("code",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text)"},children:e},e))}),(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"flex-start",cursor:"pointer",fontSize:12,color:"var(--text)",lineHeight:1.4},children:[(0,r.jsx)("input",{type:"checkbox",checked:v,onChange:e=>y(e.target.checked),style:{marginTop:2}}),(0,r.jsxs)("span",{children:[t("desktop.backupReinstallNpm"),(0,r.jsx)("span",{style:{display:"block",fontSize:11,color:"var(--text-dim)"},children:t("desktop.backupReinstallNpmHint")})]})]})]}),g.preview.warnings.length>0&&(0,r.jsx)("div",{style:{fontSize:11,color:"#ef4444",lineHeight:1.5},children:g.preview.warnings.map((e,t)=>(0,r.jsxs)("div",{children:["⚠ ",e]},t))}),(0,r.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,r.jsxs)("button",{type:"button",onClick:A,disabled:j||0===x.size,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--accent)",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:j?"wait":"pointer",opacity:0===x.size?.5:1},children:[(0,r.jsx)(ij._,{size:15,"aria-hidden":"true"}),j?t("desktop.backupRestoring"):t("desktop.backupRestoreButton")]}),(0,r.jsx)("button",{type:"button",onClick:()=>{h(null),o.current&&(o.current.value="")},disabled:j,style:{padding:"8px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",fontSize:12,cursor:"pointer"},children:t("desktop.cancel")})]})]}),C&&(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,padding:14,background:"var(--bg-panel)",display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:600,color:"var(--text)"},children:[(0,r.jsx)(om.W,{size:16,"aria-hidden":"true"}),t("desktop.backupRestoreReport")]}),C.restored.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"#4ade80",marginBottom:4},children:["✓ ",t("desktop.backupReportRestored")]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6,fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:C.restored.join("\n")})]}),C.needsRestart.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"#fbbf24",marginBottom:4},children:["\uD83D\uDD04 ",t("desktop.backupReportRestart")]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6,fontFamily:"var(--font-mono)"},children:C.needsRestart.join("\n")})]}),C.manual.length>0&&(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"#ef4444",marginBottom:4},children:[(0,r.jsx)(L.N,{size:12,style:{verticalAlign:-2},"aria-hidden":"true"})," ",t("desktop.backupReportManual")]}),C.manual.map((e,t)=>(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6},children:[(0,r.jsx)("strong",{style:{color:"var(--text)"},children:e.server}),": ",e.message]},t))]}),C.warnings.length>0&&(0,r.jsx)("div",{style:{fontSize:11,color:"#ef4444",lineHeight:1.6},children:C.warnings.map((e,t)=>(0,r.jsxs)("div",{children:["⚠ ",e]},t))}),C.needsRestart.length>0&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"#fbbf24",lineHeight:1.5},children:t("desktop.backupRestartHint")})]})]})]})}let iT={position:"relative",width:40,height:22,borderRadius:11,border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.18s ease",outline:"none"},iz={position:"absolute",top:3,width:16,height:16,borderRadius:"50%",background:"#fff",transition:"left 0.18s ease, transform 0.18s ease",boxShadow:"0 1px 3px rgba(0,0,0,0.18)"};function iR({checked:e,onChange:t,label:o,description:n}){return(0,r.jsxs)("label",{style:{display:"flex",alignItems:n?"flex-start":"center",justifyContent:"space-between",gap:12,padding:"12px 14px",borderRadius:7,cursor:"pointer",userSelect:"none",transition:"background 0.12s",margin:"0 -14px"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,r.jsxs)("span",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("span",{style:{display:"block",fontSize:13,fontWeight:550,color:"var(--text)",lineHeight:1.4},children:o}),n&&(0,r.jsx)("span",{style:{display:"block",fontSize:11,lineHeight:1.5,color:"var(--text-muted)",marginTop:2},children:n})]}),(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":e,onClick:o=>{o.preventDefault(),t(!e)},style:{...iT,background:e?"var(--accent)":"color-mix(in srgb, var(--border) 70%, var(--bg))"},children:(0,r.jsx)("span",{style:{...iz,left:e?21:3}})})]})}function iI({title:e,description:t,children:o}){return(0,r.jsxs)("section",{style:{padding:"20px 22px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:14,fontWeight:650,color:"var(--text)"},children:e}),(0,r.jsx)("p",{style:{margin:"5px 0 14px",fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:t}),(0,r.jsx)("div",{children:o})]})}let iM="pi-input-shortcut";function iE(){try{let e=localStorage.getItem(iM);return"ctrl-enter"===e?"ctrl-enter":"enter"}catch{return"enter"}}function iP(){let{t:e}=(0,E.s)(),[t,o]=(0,n.useState)(iE);(0,n.useEffect)(()=>{let e=()=>o(iE());return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[]);let s=(0,n.useCallback)(e=>{o(e);try{localStorage.setItem(iM,e),window.dispatchEvent(new StorageEvent("storage",{key:iM,newValue:e}))}catch{}},[]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:[(0,r.jsx)("header",{style:{padding:"18px 22px 14px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("h1",{style:{margin:0,fontSize:16,fontWeight:700,color:"var(--text)"},children:e("desktop.chat")})}),(0,r.jsx)(iI,{title:e("desktop.inputShortcut"),description:e("desktop.inputShortcutDescription"),children:(0,r.jsx)(iR,{checked:"ctrl-enter"===t,onChange:e=>s(e?"ctrl-enter":"enter"),label:e("desktop.useCtrlEnter"),description:e("desktop.useCtrlEnterDescription")})})]})}var iD=o(95650),i$=o(55803),iF=o(23602),iW=o(18613),iN=o(12779);let iA={display:"flex",gap:6,flexWrap:"wrap"};function iL(e,t,o){return{display:"inline-flex",alignItems:"center",gap:7,padding:"7px 14px",border:`1px solid ${e?"var(--accent)":t?"var(--border-hover)":"var(--border)"}`,borderRadius:8,background:e?"color-mix(in srgb, var(--accent) 12%, var(--bg))":t?"var(--bg-hover)":"var(--bg-card)",color:e?"var(--accent)":t?"var(--text)":"var(--text-muted)",fontSize:13,fontWeight:e?600:400,cursor:o?"not-allowed":"pointer",opacity:o?.5:1,transition:"border-color 0.15s, background 0.15s, color 0.15s",outline:"none",whiteSpace:"nowrap"}}function iO({icon:e,label:t,actions:o}){return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10,width:"100%"},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",display:"inline-flex",flexShrink:0},children:e}),(0,r.jsx)("span",{style:{fontSize:11,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),o&&(0,r.jsx)("span",{style:{display:"inline-flex",alignItems:"center",gap:12,marginLeft:"auto"},children:o})]})}let iH={display:"inline-flex",alignItems:"center",gap:6,padding:0,border:0,background:"transparent",color:"var(--accent)",fontSize:11,cursor:"pointer",whiteSpace:"nowrap"},iB={onMouseEnter:e=>{e.currentTarget.style.textDecoration="underline"},onMouseLeave:e=>{e.currentTarget.style.textDecoration="none"}};function iU({title:e,description:t,children:o}){return(0,r.jsxs)("section",{style:{padding:"20px 22px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:14,fontWeight:650,color:"var(--text)"},children:e}),(0,r.jsx)("p",{style:{margin:"5px 0 16px",fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:t}),o]})}function i_({depth:e}){let t=e/100;return(0,r.jsxs)("svg",{width:14,height:14,viewBox:"0 0 14 14",style:{flexShrink:0},children:[(0,r.jsx)("rect",{x:1.5,y:1.5,width:11,height:11,rx:2.5,style:{fill:"none",stroke:"var(--text-dim)",strokeWidth:1+2*t,opacity:.2+.8*t}}),(0,r.jsx)("rect",{x:4,y:4,width:6,height:6,rx:1,style:{fill:"var(--text-dim)",opacity:.05+.35*t}})]})}function iq({hasDark:e,hasLight:t,darkColor:o,lightColor:n,t:s}){return(0,r.jsxs)("span",{style:{display:"inline-flex",gap:3,alignItems:"center",flexShrink:0},children:[e&&(0,r.jsx)("span",{title:s("desktop.darkVariant"),style:{display:"inline-block",width:7,height:7,borderRadius:"50%",background:o??"#7c6f64"}}),t&&(0,r.jsx)("span",{title:s("desktop.lightVariant"),style:{display:"inline-block",width:7,height:7,borderRadius:"50%",background:n??"#d5c4a1",border:"1px solid rgba(0,0,0,0.1)"}})]})}function iV(){let{mode:e,resolvedMode:t,themeName:o,setMode:s,setTheme:i,borderDepth:a,setBorderDepth:l}=tP(),{locale:d,setLocale:c,t:p}=(0,E.s)(),[u,g]=(0,n.useState)([]),[h,x]=(0,n.useState)(!0),[f,m]=(0,n.useState)(null),[k,v]=(0,n.useState)(null);(0,n.useEffect)(()=>{let e=!1;return fetch("/api/themes").then(e=>e.ok?e.json():null).then(t=>{!e&&t&&g(t.themeSets)}).catch(()=>{}).finally(()=>{e||x(!1)}),()=>{e=!0}},[]);let y=(0,n.useCallback)(e=>{m(e),i(e).finally(()=>m(null))},[i]),b=(0,n.useCallback)(e=>{s(e)},[s]),w=(0,n.useCallback)(()=>{window.piDesktop?.openThemeFolder()},[]),j=(0,n.useCallback)(()=>{window.piDesktop?window.piDesktop.openThemeDocs():window.open("https://pi.dev/docs/latest/themes","_blank","noopener,noreferrer")},[]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:[(0,r.jsx)("header",{style:{padding:"18px 22px 14px",borderBottom:"1px solid var(--border)"},children:(0,r.jsx)("h1",{style:{margin:0,fontSize:16,fontWeight:700,color:"var(--text)"},children:p("desktop.display")})}),(0,r.jsxs)(iU,{title:p("desktop.theme"),description:p("desktop.themeDescription"),children:[(0,r.jsx)(iO,{icon:(0,r.jsx)(iD.p,{size:14,weight:"fill"}),label:p("desktop.colorScheme"),actions:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",onClick:w,style:iH,...iB,children:[(0,r.jsx)(i$.N,{size:12,weight:"regular","aria-hidden":"true"}),p("desktop.openThemeFolder")]}),(0,r.jsxs)("button",{type:"button",onClick:j,style:iH,...iB,children:[(0,r.jsx)(iF.B,{size:12,weight:"regular","aria-hidden":"true"}),p("desktop.learnPiThemes")]})]})}),h?(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)"},children:p("desktop.loadingThemes")}):(0,r.jsxs)("div",{style:iA,children:[(0,r.jsx)("button",{type:"button",onClick:()=>y(""),disabled:null!==f,style:iL(""===o,"__default__"===k,null!==f),onMouseEnter:()=>v("__default__"),onMouseLeave:()=>v(null),children:p("desktop.defaultTheme")}),u.map(e=>(0,r.jsxs)("button",{type:"button",onClick:()=>y(e.name),disabled:null!==f,style:iL(o===e.name,k===e.name,f===e.name),onMouseEnter:()=>v(e.name),onMouseLeave:()=>v(null),children:[e.displayName,(0,r.jsx)(iq,{hasDark:e.hasDark,hasLight:e.hasLight,darkColor:e.accent,lightColor:e.accentLight,t:p})]},e.name))]}),(0,r.jsxs)("div",{style:{marginTop:20},children:[(0,r.jsx)(iO,{icon:(0,r.jsx)(i_,{depth:a}),label:`${p("desktop.borderVisibility")} (${a})`}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:p("desktop.borderSubtle")}),(0,r.jsx)("input",{type:"range",min:0,max:100,step:1,value:a,onChange:e=>l(Number(e.target.value)),style:{flex:1,accentColor:"var(--accent)",height:6,cursor:"pointer"}}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:p("desktop.borderBold")})]}),(0,r.jsx)("div",{style:{marginTop:10,display:"flex",gap:10},children:[0,25,50,75,100].map(e=>{let t=a===e,o=e<=50?`color-mix(in srgb, var(--border-orig) ${2*e}%, var(--bg) ${100-2*e}%)`:`color-mix(in srgb, var(--border-orig) ${100-(e-50)*2}%, var(--text) ${(e-50)*2}%)`;return(0,r.jsx)("div",{onClick:()=>l(e),style:{width:28,height:20,border:`2px solid ${t?"var(--accent)":o}`,borderRadius:5,background:"var(--bg-card)",cursor:"pointer",transition:"border-color 0.1s"}},e)})})]}),(0,r.jsxs)("div",{style:{marginTop:20},children:[(0,r.jsx)(iO,{icon:"dark"===t?(0,r.jsx)(iW.A,{size:14,weight:"fill"}):(0,r.jsx)(iN.b,{size:14,weight:"fill"}),label:p("desktop.appearanceMode")}),(0,r.jsx)("div",{style:iA,children:[{value:"light",icon:(0,r.jsx)(iN.b,{size:15,weight:"light"===e?"fill":"regular"})},{value:"dark",icon:(0,r.jsx)(iW.A,{size:15,weight:"dark"===e?"fill":"regular"})},{value:"system",icon:(0,r.jsx)(ix.V,{size:15,weight:"system"===e?"fill":"regular"})}].map(t=>{let o=e===t.value;return(0,r.jsxs)("button",{type:"button",onClick:()=>b(t.value),style:iL(o,k===`mode:${t.value}`),onMouseEnter:()=>v(`mode:${t.value}`),onMouseLeave:()=>v(null),children:[t.icon,p(`desktop.${t.value}`)]},t.value)})})]}),!h&&0===u.length&&(0,r.jsxs)("p",{style:{margin:"14px 0 0",fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[p("desktop.noCustomThemes")," ",p("desktop.noCustomThemesHint")," ",(0,r.jsx)("code",{style:{fontSize:10,background:"var(--bg-secondary)",padding:"1px 5px",borderRadius:3,fontFamily:"var(--font-mono)"},children:"~/.pi/agent/themes/*.json"})," ",p("desktop.noCustomThemesHint2")]})]}),(0,r.jsx)(iU,{title:p("desktop.language"),description:p("desktop.languageDescription"),children:(0,r.jsx)("div",{style:iA,children:["en","zh-CN"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>c("zh-CN"===e?"zh-CN":"en"),style:iL("zh-CN"===e?"zh-CN"===d:"zh-CN"!==d,k===`lang:${e}`),onMouseEnter:()=>v(`lang:${e}`),onMouseLeave:()=>v(null),children:"en"===e?p("desktop.english"):p("desktop.chinese")},e))})})]})}var iK=o(94638);function iJ({children:e}){return(0,r.jsx)("div",{style:{borderRadius:12,border:"1px solid var(--border)",background:"color-mix(in srgb, var(--bg-panel) 55%, transparent)",overflow:"hidden"},children:e})}function iG({children:e}){return(0,r.jsx)("div",{style:{padding:"0 14px"},children:(0,r.jsx)("div",{style:{borderBottom:"1px solid var(--border)"},children:e})})}function iY({children:e}){return(0,r.jsx)("div",{style:{padding:"0 14px"},children:e})}function iZ({children:e}){return(0,r.jsx)("div",{style:{display:"flex",gap:8,borderRadius:10,border:"1px solid var(--border)",background:"color-mix(in srgb, var(--bg-panel) 55%, transparent)",padding:"10px 12px",fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:e})}let iX=[{value:"normal",labelKey:"modes.collabNormal"},{value:"plan",labelKey:"modes.collabPlan"},{value:"goal",labelKey:"modes.collabGoal"}],iQ=[{value:"economy",labelKey:"modes.tokenEconomy"},{value:"full",labelKey:"modes.tokenFull"},{value:"delivery",labelKey:"modes.tokenDelivery"}],i0=[{value:"ask",labelKey:"modes.approvalAsk"},{value:"auto",labelKey:"modes.approvalAuto"},{value:"yolo",labelKey:"modes.approvalYolo"}];function i1({options:e,value:t,onChange:o,disabled:n,accentFor:s}){let{t:i}=(0,E.s)();return(0,r.jsx)("div",{role:"radiogroup",style:{display:"flex",border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",height:28,flexShrink:0},children:e.map(e=>{let a=e.value===t,l=s?.(e.value);return(0,r.jsx)("button",{type:"button",role:"radio","aria-checked":a,disabled:n,onClick:()=>{e.value!==t&&o(e.value)},style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",padding:"0 12px",background:a?"var(--bg-selected)":"none",border:"none",color:a?l??"var(--accent)":"var(--text-muted)",cursor:n?"not-allowed":"pointer",fontSize:11.5,fontWeight:a?650:500,opacity:n?.5:1,whiteSpace:"nowrap",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{a||n||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{a||(e.currentTarget.style.background="none")},children:i(e.labelKey)},e.value)})})}function i2(){let{t:e}=(0,E.s)(),[t,o]=(0,n.useState)({tasksBoard:!0}),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!1;return(async()=>{try{let[t,r]=await Promise.all([fetch("/api/features"),fetch("/api/modes")]);if(!e&&t.ok){let e=await t.json();o(t=>({...t,...e}))}if(!e&&r.ok){let e=await r.json();i({collaborationMode:ej(e.collaborationMode),tokenMode:eS(e.tokenMode),toolApprovalMode:eC(e.toolApprovalMode),permissionRules:e.permissionRules??{allow:[],ask:[],deny:[]}})}e||l(!0)}catch{}})(),()=>{e=!0}},[]);let p=(0,n.useCallback)(async e=>{c(!0);try{let t=await fetch("/api/features",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({tasksBoard:e})});if(t.ok){let e=await t.json();o(t=>({...t,...e.features})),window.dispatchEvent(new CustomEvent("pi:features-changed"))}}catch{}finally{c(!1)}},[]),u=(0,n.useCallback)(async e=>{c(!0);try{let t=await fetch("/api/modes",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(t.ok){let e=await t.json();i(t=>t?{...t,collaborationMode:ej(e.modes?.collaborationMode??t.collaborationMode),tokenMode:eS(e.modes?.tokenMode??t.tokenMode),toolApprovalMode:eC(e.modes?.toolApprovalMode??t.toolApprovalMode),permissionRules:e.modes?.permissionRules??t.permissionRules}:t),window.dispatchEvent(new CustomEvent("pi:modes-changed"))}}catch{}finally{c(!1)}},[]);return(0,r.jsx)("div",{style:{flex:1,overflow:"auto",minWidth:0,padding:"20px 22px",display:"flex",flexDirection:"column",gap:16},children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(iJ,{children:(0,r.jsx)(iY,{children:(0,r.jsx)(iR,{checked:t.tasksBoard,onChange:e=>void p(e),label:(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[(0,r.jsx)(iK.x,{size:14,"aria-hidden":"true"}),e("desktop.featuresTasksBoard"),(0,r.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 7px",fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em"},children:"Beta"})]}),description:e("desktop.featuresTasksBoardDesc")})})}),s&&(0,r.jsxs)(iJ,{children:[(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16,padding:"12px 0"},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e("desktop.featuresCollabDefault")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:e("desktop.featuresCollabDefaultDesc")})]}),(0,r.jsx)(i1,{options:iX,value:s.collaborationMode,onChange:e=>void u({collaborationMode:e}),disabled:d})]})}),(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16,padding:"12px 0"},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e("desktop.featuresTokenDefault")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:e("desktop.featuresTokenDefaultDesc")})]}),(0,r.jsx)(i1,{options:iQ,value:s.tokenMode,onChange:e=>void u({tokenMode:e}),disabled:d})]})}),(0,r.jsx)(iY,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16,padding:"12px 0"},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e("desktop.featuresApprovalDefault")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:e("desktop.featuresApprovalDefaultDesc")})]}),(0,r.jsx)(i1,{options:i0,value:s.toolApprovalMode,onChange:e=>void u({toolApprovalMode:e}),disabled:d,accentFor:e=>"yolo"===e?"var(--accent-red, #ef4444)":void 0})]})})]})]}):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.featuresLoading")}),(0,r.jsx)(iZ,{children:e("desktop.featuresDesc")}),d&&(0,r.jsx)("div",{style:{padding:"0 2px",fontSize:11,color:"var(--text-muted)"},children:e("desktop.featuresSaving")})]})})}var i4=o(76553);function i6({open:e,onClose:t,children:o}){let[s,i]=(0,n.useState)(!1),[a,l]=(0,n.useState)(!1);return((0,n.useEffect)(()=>{if(e)l(!0),requestAnimationFrame(()=>requestAnimationFrame(()=>i(!0)));else{i(!1);let e=setTimeout(()=>l(!1),250);return()=>clearTimeout(e)}},[e]),a)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{onClick:t,style:{position:"fixed",inset:0,zIndex:1001,background:s?"rgba(0,0,0,0.35)":"rgba(0,0,0,0)",transition:"background 0.25s ease"}}),(0,r.jsxs)("div",{style:{position:"fixed",bottom:0,left:0,right:0,zIndex:1002,maxHeight:"85dvh",borderRadius:"16px 16px 0 0",background:"var(--bg)",boxShadow:"0 -4px 24px rgba(0,0,0,0.15)",transform:s?"translateY(0)":"translateY(100%)",transition:"transform 0.25s cubic-bezier(0.32, 0.72, 0, 1)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{display:"flex",justifyContent:"center",padding:"10px 0 4px",flexShrink:0},children:(0,r.jsx)("div",{style:{width:36,height:4,borderRadius:2,background:"var(--border)"}})}),(0,r.jsx)("div",{style:{flex:1,overflow:"auto",minHeight:0},children:o})]})]}):null}function i5({onSessionsChanged:e}){let{t}=(0,E.s)(),o=rY(),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)([]),[d,p]=(0,n.useState)([]),[u,g]=(0,n.useState)(new Set),[h,x]=(0,n.useState)(null),[f,m]=(0,n.useState)({imported:0,skipped:0,errors:0,total:0,done:!1}),[k,v]=(0,n.useState)([]),[y,b]=(0,n.useState)(!1),[w,j]=(0,n.useState)({done:0,total:0}),[S,C]=(0,n.useState)(!1),[T,z]=(0,n.useState)(null),[I,M]=(0,n.useState)(!1),P=(0,n.useCallback)(async()=>{C(!0),z(null);try{let e=await fetch("/api/import/discover"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);l(t.sources),t.reasonix?.available&&(p(t.reasonix.projects),i("reasonix"))}catch(e){z(e instanceof Error?e.message:String(e))}finally{C(!1)}},[]),[D,$]=(0,n.useState)(!1);(0,n.useEffect)(()=>{D||($(!0),P())},[D,P]);let F=(0,n.useCallback)(async()=>{if(0!==u.size&&s){C(!0),z(null);try{let e=await fetch("/api/import/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:s,projects:[...u]})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);x(t.jobId)}catch(e){z(e instanceof Error?e.message:String(e))}finally{C(!1)}}},[s,u]);(0,n.useEffect)(()=>{let t;if(!h)return;let o=!0,r=async()=>{if(o)try{let n=await fetch(`/api/import/status?jobId=${encodeURIComponent(h)}`),s=await n.json();if(!o)return;m({imported:s.imported??0,skipped:s.skipped??0,errors:s.errors??0,total:s.total??0,done:s.done??!1}),s.done&&s.sessionIds&&(v(s.sessionIds),e?.()),s.done||(t=setTimeout(r,800))}catch{o&&(t=setTimeout(r,2e3))}};return r(),()=>{o=!1,clearTimeout(t)}},[h,e]);let W=(0,n.useCallback)(async()=>{if(0===k.length)return;b(!0),j({done:0,total:k.length});let t=0,o=async()=>{for(;t<k.length;){let e=t++,o=k[e];if(o){try{await fetch(`/api/sessions/${encodeURIComponent(o)}/auto-name`,{method:"POST"})}catch{}j({done:e+1,total:k.length})}}},r=Array.from({length:Math.min(4,k.length)},o);await Promise.all(r),b(!1),e?.()},[k,e]);if(f.done&&k.length>0)return(0,r.jsxs)("div",{style:{padding:"18px 22px",display:"flex",flexDirection:"column",gap:14},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,r.jsx)(oV.r,{size:20,weight:"fill",style:{color:"#4ade80"}}),(0,r.jsx)("span",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:t("desktop.importDone")??"导入完成"})]}),(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:[t("desktop.importedSummary",{imported:f.imported})??`成功导入 ${f.imported} 个会话`,f.skipped>0&&(0,r.jsx)("span",{style:{marginLeft:8},children:t("desktop.importSkippedCount",{skipped:f.skipped})??`,${f.skipped} 个跳过`}),f.errors>0&&(0,r.jsx)("span",{style:{marginLeft:8,color:"#ef4444"},children:t("desktop.importErrorsCount",{errors:f.errors})??`,${f.errors} 个失败`})]}),y?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text-muted)"},children:[(0,r.jsx)(N.y,{size:14,style:{animation:"spin 1s linear infinite"}}),t("desktop.importGeneratingTitles")??"正在生成标题…"," ","(",w.done,"/",w.total,")"]}):(0,r.jsxs)("button",{type:"button",onClick:W,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--accent)",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:"pointer",alignSelf:"flex-start"},children:[(0,r.jsx)(i4.o,{size:15}),t("desktop.importGenerateTitles")??"为导入的会话生成标题"]}),(0,r.jsx)("button",{type:"button",onClick:()=>{x(null),m({imported:0,skipped:0,errors:0,total:0,done:!1}),v([]),b(!1),j({done:0,total:0})},style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",fontSize:12,cursor:"pointer",alignSelf:"flex-start"},children:t("desktop.importAgain")??"再次导入"})]});let A=(0,r.jsxs)("div",{style:{padding:o?"12px 18px":"18px 22px",display:"flex",flexDirection:"column",gap:14},children:[T&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,fontSize:12,color:"#ef4444",lineHeight:1.5},children:[(0,r.jsx)(L.N,{size:14,style:{flexShrink:0,marginTop:1}}),(0,r.jsx)("span",{children:T})]}),!h&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:t("desktop.importSessionsDesc")??"从其他 AI 编码工具导入历史对话记录到 pi-web。目前支持 Reasonix,更多工具陆续支持中。"}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:a.map(e=>(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px",border:"1px solid var(--border)",borderRadius:8,cursor:"available"===e.status?"pointer":"default",background:s===e.key?"var(--bg-selected)":"var(--bg-panel)",opacity:"unavailable"===e.status?.5:"coming-soon"===e.status?.7:1,transition:"background 0.12s"},children:[(0,r.jsx)("input",{type:"radio",name:"import-source",value:e.key,checked:s===e.key,disabled:"available"!==e.status,onChange:()=>i(e.key)}),(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e.label}),"coming-soon"===e.status&&(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:1},children:t("desktop.comingSoon")??"即将支持"})]}),"reasonix"===e.key&&d.length>0&&(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[d.length," ",t("desktop.projects")??"个项目"," \xb7 ",d.reduce((e,t)=>e+t.sessions,0)," ",t("desktop.sessions")??"会话"]})]},e.key))}),"reasonix"===s&&d.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:t("desktop.importSelectProjects")??"选择要导入的项目"}),(0,r.jsx)("button",{type:"button",onClick:()=>g(new Set(d.map(e=>e.name))),style:i3,children:t("desktop.importSelectAll")??"全选"}),(0,r.jsx)("button",{type:"button",onClick:()=>g(new Set),style:i3,children:t("desktop.importDeselectAll")??"取消全选"})]}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:d.map(e=>(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 12px",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer",background:u.has(e.name)?"var(--bg-selected)":"transparent",transition:"background 0.12s"},children:[(0,r.jsx)("input",{type:"checkbox",checked:u.has(e.name),onChange:()=>{var t;return t=e.name,void g(e=>{let o=new Set(e);return o.has(t)?o.delete(t):o.add(t),o})}}),(0,r.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:500,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:2},children:[e.sessions," ",t("desktop.sessions")??"会话",e.matched&&(0,r.jsxs)("span",{style:{marginLeft:8,color:"var(--accent)"},children:["→ ",t("desktop.importMerged")??"合并到现有项目",e.existingCount>0&&` (${t("desktop.importExistingCount",{count:e.existingCount})??`${e.existingCount} 个已有`})`]}),!e.matched&&(0,r.jsxs)("span",{style:{marginLeft:8,color:"var(--text-muted)"},children:["→ ",t("desktop.importNewProject")??"新建项目"]})]})]})]},e.name))}),(0,r.jsx)("button",{type:"button",onClick:F,disabled:S||0===u.size,style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",background:"var(--accent)",border:"none",borderRadius:6,color:"#fff",fontSize:12,fontWeight:600,cursor:0===u.size?"not-allowed":"pointer",alignSelf:"flex-start",opacity:0===u.size?.5:1},children:S?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(N.y,{size:14,style:{animation:"spin 1s linear infinite"}})," ",t("desktop.importing")??"导入中…"]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(R.z,{size:15})," ",t("desktop.importStart")??"开始导入"]})})]}),"reasonix"===s&&0===d.length&&!S&&(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",padding:"12px 0"},children:t("desktop.importNoData")??"未找到 Reasonix 数据。请确认 ~/.reasonix/projects/ 目录存在且包含会话文件。"})]}),h&&!f.done&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--text)"},children:[(0,r.jsx)(N.y,{size:14,style:{animation:"spin 1s linear infinite"}}),t("desktop.importing")??"导入中…"]}),(0,r.jsx)("div",{style:{height:6,borderRadius:3,background:"var(--bg-panel)",overflow:"hidden"},children:(0,r.jsx)("div",{style:{height:"100%",borderRadius:3,background:"var(--accent)",width:`${f.total>0?(f.imported+f.skipped+f.errors)/f.total*100:0}%`,transition:"width 0.3s ease"}})}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:[f.imported+f.skipped+f.errors," / ",f.total,f.skipped>0&&` \xb7 ${t("desktop.importSkippedCount",{skipped:f.skipped})??`${f.skipped} 跳过`}`]})]})]});return o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",onClick:()=>M(!0),style:{display:"flex",alignItems:"center",gap:8,padding:"10px 14px",width:"100%",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,r.jsx)(R.z,{size:16}),(0,r.jsx)("span",{style:{fontWeight:500},children:t("desktop.importSessions")??"导入会话"})]}),(0,r.jsxs)(i6,{open:I,onClose:()=>M(!1),children:[(0,r.jsxs)("div",{style:{padding:"4px 18px 14px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:t("desktop.importSessions")??"导入会话"}),(0,r.jsx)("button",{onClick:()=>M(!1),style:i8,children:(0,r.jsx)(c.X,{size:18})})]}),A]})]}):A}let i3={background:"none",border:"none",color:"var(--accent)",fontSize:11,cursor:"pointer",padding:"2px 4px"},i8={background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",padding:4,display:"flex"},i7="deepseek-vision",i9={padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",width:"100%",boxSizing:"border-box"};function ae(){return{fontSize:12,color:"var(--text-muted)"}}let at={padding:"7px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12};function ao({sessionId:e}){let{t}=(0,E.s)(),[o,s]=(0,n.useState)(!1),[i,a]=(0,n.useState)(null),[l,d]=(0,n.useState)(!1),[c,p]=(0,n.useState)(null),[u,g]=(0,n.useState)(!1),[h,x]=(0,n.useState)({}),[f,m]=(0,n.useState)(""),[k,v]=(0,n.useState)(""),[y,b]=(0,n.useState)("eager"),[w,j]=(0,n.useState)(!1),[S,C]=(0,n.useState)(null),[T,z]=(0,n.useState)(!1),[R,I]=(0,n.useState)(!1),[M,P]=(0,n.useState)({provider:"custom",baseUrl:"",apiKey:"",model:"",maxTokens:4096,hasApiKey:!1}),[D,$]=(0,n.useState)(""),[F,W]=(0,n.useState)(""),[N,A]=(0,n.useState)(!1),[L,O]=(0,n.useState)(null),[H,B]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!1;return(async()=>{a(null);try{let[t,o]=await Promise.all([fetch("/api/mcp"),fetch("/api/vision-config")]),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);let n=await o.json();if(!o.ok||n.error)throw Error(n.error??`HTTP ${o.status}`);if(e)return;x(r.mcpServers??{}),m(r.filePath);let i=(r.mcpServers??{})[i7];v(i?.command??""),b(i?.lifecycle==="lazy"?"lazy":"eager"),P({provider:n.provider,baseUrl:n.baseUrl,apiKey:"",model:n.model,maxTokens:n.maxTokens,hasApiKey:n.hasApiKey}),n.path&&W(n.path),s(!0)}catch(t){e||a(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[]);let U=(0,n.useCallback)(async()=>{if(!k.trim())return void C(t("desktop.mcpVisionCommandRequired"));j(!0),C(null),z(!1),I(!1);try{let e=h[i7],t={...h,[i7]:{...e??{},command:k.trim(),args:Array.isArray(e?.args)?e.args:[],transport:"stdio",lifecycle:y}},o=await fetch("/api/mcp",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mcpServers:t})}),r=await o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);x(t),z(!0)}catch(e){C(e instanceof Error?e.message:String(e))}finally{j(!1)}},[h,k,y,t]),_=(0,n.useCallback)(async()=>{j(!0),C(null),z(!1),I(!1);try{let e={...h};delete e[i7];let t=await fetch("/api/mcp",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mcpServers:e})}),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);x(e),v(""),b("eager"),I(!0)}catch(e){C(e instanceof Error?e.message:String(e))}finally{j(!1)}},[h]),q=(0,n.useCallback)(async()=>{A(!0),O(null),B(!1);try{let e=await fetch("/api/vision-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({...M,...D?{apiKey:D}:{}})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);P({...t,apiKey:"",hasApiKey:t.hasApiKey}),$(""),B(!0)}catch(e){O(e instanceof Error?e.message:String(e))}finally{A(!1)}},[M,D]),V=(0,n.useCallback)(async()=>{if(e){d(!0),p(null),g(!1);try{let t=await fetch("/api/mcp/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:e,name:i7})}),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);g(!0)}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}}},[e]),K=!!h[i7];return(0,r.jsxs)(iJ,{children:[(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"12px 0"},children:[(0,r.jsx)(r0.k,{size:15,"aria-hidden":"true"}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:t("desktop.mcpVisionTitle")}),(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:3,background:K?"rgba(37,99,235,0.12)":"rgba(245,158,11,0.12)",color:K?"var(--accent)":"#d97706",textTransform:"capitalize"},children:K?t("desktop.mcpVisionRegistered"):t("desktop.mcpVisionNotRegistered")})]}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:t("desktop.mcpVisionDesc")})]})]})}),o?i?(0,r.jsx)(iY,{children:(0,r.jsx)("div",{style:{padding:"8px 0",fontSize:12,color:"#ef4444"},children:i})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(iG,{children:(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",padding:"10px 0 2px"},children:t("desktop.mcpVisionRegistration")})}),(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 180px) 1fr",gap:8,alignItems:"center",padding:"6px 0"},children:[(0,r.jsxs)("span",{style:ae(),children:[t("desktop.mcpVisionCommand")," *"]}),(0,r.jsx)("input",{value:k,onChange:e=>v(e.target.value),placeholder:"/path/to/deepseek-vision-mcp",style:i9}),(0,r.jsx)("span",{style:ae(),children:t("desktop.mcpVisionLifecycle")}),(0,r.jsxs)("select",{value:y,onChange:e=>b(e.target.value),style:{...i9,fontFamily:"var(--font-mono)"},children:[(0,r.jsx)("option",{value:"eager",children:"eager"}),(0,r.jsx)("option",{value:"lazy",children:"lazy"})]}),(0,r.jsx)("span",{style:ae(),children:t("desktop.mcpVisionTransport")}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontFamily:"var(--font-mono)",padding:"7px 0"},children:t("desktop.mcpVisionTransportFixed")})]})}),(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"6px 0",flexWrap:"wrap"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void U(),disabled:w,style:{...at,cursor:w?"wait":"pointer"},children:w?t("desktop.saving"):t("desktop.mcpVisionSaveReg")}),K&&(0,r.jsx)("button",{type:"button",onClick:()=>void _(),disabled:w,title:t("desktop.mcpVisionRemove"),style:{padding:"7px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"#ef4444",cursor:w?"not-allowed":"pointer",fontSize:12},children:t("desktop.mcpVisionRemove")}),T&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:t("desktop.mcpVisionSavedReg")}),R&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:t("desktop.mcpVisionRemoved")}),S&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:S})]})}),(0,r.jsx)(iG,{children:(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",padding:"10px 0 2px"},children:t("desktop.mcpVisionModelConfig")})}),(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 180px) 1fr",gap:8,alignItems:"center",padding:"6px 0"},children:[(0,r.jsx)("span",{style:ae(),children:t("desktop.mcpVisionProvider")}),(0,r.jsx)("input",{value:M.provider,onChange:e=>P(t=>({...t,provider:e.target.value})),style:i9}),(0,r.jsx)("span",{style:ae(),children:t("desktop.mcpVisionBaseUrl")}),(0,r.jsx)("input",{value:M.baseUrl,onChange:e=>P(t=>({...t,baseUrl:e.target.value})),style:i9}),(0,r.jsx)("span",{style:ae(),children:t("desktop.mcpVisionApiKey")}),(0,r.jsx)("input",{type:"password",value:D,onChange:e=>$(e.target.value),placeholder:M.hasApiKey?"••••••••":"API key",style:i9}),(0,r.jsx)("span",{style:ae(),children:t("desktop.mcpVisionModel")}),(0,r.jsx)("input",{value:M.model,onChange:e=>P(t=>({...t,model:e.target.value})),style:i9}),(0,r.jsx)("span",{style:ae(),children:t("desktop.mcpVisionMaxTokens")}),(0,r.jsx)("input",{type:"number",min:1,value:M.maxTokens,onChange:e=>P(t=>({...t,maxTokens:Number(e.target.value)||1})),style:i9})]})}),(0,r.jsx)(iY,{children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"6px 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void q(),disabled:N,style:{...at,cursor:N?"wait":"pointer"},children:N?t("desktop.saving"):t("desktop.mcpVisionSaveModel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void V(),disabled:l||!e||!K,title:e?t("desktop.mcpVisionRestartTitle"):t("desktop.mcpVisionRestartNoSession"),style:{padding:"7px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:!l&&e&&K?"pointer":"not-allowed",fontSize:12,opacity:!l&&e&&K?1:.5},children:l?t("desktop.mcpVisionRestarting"):t("desktop.mcpVisionRestart")}),H&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:t("desktop.mcpVisionSavedModel")}),u&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:t("desktop.mcpVisionRestarted")}),L&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:L}),c&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:c})]}),(0,r.jsxs)(iZ,{children:[t("desktop.mcpVisionModelNote"),F&&(0,r.jsx)("div",{style:{marginTop:4,fontFamily:"var(--font-mono)",fontSize:10},children:F}),f&&(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:10},children:f})]})]})})]}):(0,r.jsx)(iY,{children:(0,r.jsx)("div",{style:{padding:"8px 0",fontSize:12,color:"var(--text-muted)"},children:t("desktop.loading")})})]})}function ar({sessionId:e,onApplied:t}){let{t:o}=(0,E.s)(),[s,i]=(0,n.useState)(!1),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(null),p=(0,n.useCallback)(async()=>{if(e){i(!0),c(null),l(!1);try{await sb(e,{type:"reload"}),l(!0),await t?.()}catch(e){c(e instanceof Error?e.message:String(e))}finally{i(!1)}}},[e,t]),u=s||!e;return(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void p(),disabled:u,title:o(e?"desktop.applyNowTitle":"desktop.applyNowNoSession"),style:{padding:"7px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:u?"not-allowed":"pointer",fontSize:12,opacity:u?.5:1,whiteSpace:"nowrap"},children:o(s?"desktop.applyNowApplying":"desktop.applyNow")}),a&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:o("desktop.applyNowDone")}),d&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:d})]})}let an=["stdio","sse","http"],as=["eager","lazy"],ai={name:"",command:"",args:"",transport:"stdio",lifecycle:"eager",requestTimeoutMs:"",env:""},aa={padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",width:"100%",boxSizing:"border-box"};function al(){return{fontSize:12,color:"var(--text-muted)"}}function ad(e,t){return{fontSize:10,padding:"1px 6px",borderRadius:3,background:t,color:e,flexShrink:0,textTransform:"capitalize"}}function ac({sessionId:e}){let{t}=(0,E.s)(),[o,s]=(0,n.useState)({}),[i,a]=(0,n.useState)(""),[l,d]=(0,n.useState)(!1),[c,p]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(ai),[m,k]=(0,n.useState)(!1),[v,b]=(0,n.useState)(null),[w,S]=(0,n.useState)(!1),C=(0,n.useCallback)(async()=>{p(null);try{let e=await fetch("/api/mcp"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);s(t.mcpServers??{}),a(t.filePath)}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!0)}},[]);(0,n.useEffect)(()=>{C()},[C]);let T=(0,n.useCallback)(()=>{f(ai),h({name:"",isNew:!0}),b(null),S(!1)},[]),z=(0,n.useCallback)((e,t)=>{f({name:e,command:t.command??"",args:Array.isArray(t.args)?t.args.join("\n"):"",transport:"string"==typeof t.transport?t.transport:"stdio",lifecycle:"string"==typeof t.lifecycle?t.lifecycle:"eager",requestTimeoutMs:"number"==typeof t.requestTimeoutMs?String(t.requestTimeoutMs):"",env:void 0!==t.env?JSON.stringify(t.env,null,2):""}),h({name:e,isNew:!1}),b(null),S(!1)},[]),R=(0,n.useCallback)(async()=>{if(u){k(!0),b(null),S(!1);try{let e=x.name.trim();if(u.isNew&&!e)return void b("Server name is required");if(u.isNew&&!/^[a-zA-Z0-9_-]+$/.test(e))return void b("Allowed characters: a-z, A-Z, 0-9, _ and -");if(u.isNew&&e===i7)return void b(t("desktop.mcpVisionNameReserved"));let r=function(e){if(!e.command.trim())return{error:"Command is required"};let t=e.args.split("\n").map(e=>e.trim()).filter(Boolean),o={command:e.command.trim(),args:t,transport:an.includes(e.transport)?e.transport:"stdio",lifecycle:as.includes(e.lifecycle)?e.lifecycle:"eager"};if(""!==e.requestTimeoutMs.trim()){let t=Number(e.requestTimeoutMs);if(!Number.isFinite(t)||t<=0)return{error:"Request timeout must be a positive number"};o.requestTimeoutMs=t}if(""!==e.env.trim())try{o.env=JSON.parse(e.env)}catch{return{error:"Environment must be valid JSON"}}return{server:o}}(x);if(r.error||!r.server)return void b(r.error??"Invalid server");let n={...o};u.isNew?n[e]=r.server:(delete n[u.name],n[x.name.trim()||u.name]=r.server);let i=await fetch("/api/mcp",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mcpServers:n})}),a=await i.json();if(!i.ok||a.error)throw Error(a.error??`HTTP ${i.status}`);s(n),h(null),S(!0)}catch(e){b(e instanceof Error?e.message:String(e))}finally{k(!1)}}},[u,x,o,t]),I=(0,n.useCallback)(async e=>{k(!0),b(null);try{let t={...o};delete t[e];let r=await fetch("/api/mcp",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mcpServers:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(t),S(!0)}catch(e){b(e instanceof Error?e.message:String(e))}finally{k(!1)}},[o]),M=(0,n.useCallback)((e,t)=>{f(o=>({...o,[e]:t}))},[]),P=Object.entries(o).filter(([e])=>e!==i7);return(0,r.jsx)("div",{style:{flex:1,overflow:"auto",minWidth:0,padding:"20px 22px",display:"flex",flexDirection:"column",gap:16},children:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:l?c?(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444"},children:c}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:t("desktop.mcpServers")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexShrink:0},children:[(0,r.jsx)(ar,{sessionId:e,onApplied:C}),(0,r.jsxs)("button",{type:"button",onClick:T,style:{display:"flex",alignItems:"center",gap:6,padding:"7px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,flexShrink:0},children:[(0,r.jsx)(y.c,{size:13,"aria-hidden":"true"}),t("desktop.mcpAddServer")]})]})]}),(0,r.jsx)(iZ,{children:t("desktop.mcpRestartNote")}),(0,r.jsx)(ao,{sessionId:e}),0!==P.length||u?P.map(([e,o])=>(0,r.jsx)(iJ,{children:(0,r.jsx)(iY,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 0",minWidth:0},children:[(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:13,fontWeight:600,color:"var(--text)",fontFamily:"var(--font-mono)"},children:e}),(0,r.jsx)("span",{style:ad("var(--accent)","rgba(37,99,235,0.12)"),children:o.transport??"stdio"}),(0,r.jsx)("span",{style:ad("#d97706","rgba(245,158,11,0.12)"),children:o.lifecycle??"lazy"})]}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",marginTop:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[o.command,Array.isArray(o.args)&&o.args.length>0?` ${o.args.map(e=>e.includes(" ")?`"${e}"`:e).join(" ")}`:""]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,flexShrink:0},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>z(e,o),disabled:m,style:{display:"flex",alignItems:"center",gap:5,padding:"6px 10px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:m?"not-allowed":"pointer",fontSize:12,opacity:m?.5:1},children:[(0,r.jsx)(g.I,{size:12,"aria-hidden":"true"}),t("desktop.mcpEdit")]}),(0,r.jsx)("button",{type:"button",onClick:()=>void I(e),disabled:m,title:t("desktop.mcpDelete"),"aria-label":t("desktop.mcpDelete"),style:{display:"flex",alignItems:"center",padding:"6px 9px",background:"rgba(239,68,68,0.08)",border:"1px solid var(--border)",borderRadius:6,color:"#ef4444",cursor:m?"not-allowed":"pointer",fontSize:12,opacity:m?.5:1},children:(0,r.jsx)(j.l,{size:12,"aria-hidden":"true"})})]})]})})},e)):(0,r.jsx)(iJ,{children:(0,r.jsx)(iY,{children:(0,r.jsx)("div",{style:{padding:"14px 0",fontSize:12,color:"var(--text-dim)"},children:o[i7]?t("desktop.mcpEmptyOther"):t("desktop.mcpEmpty")})})}),u&&(0,r.jsxs)(iJ,{children:[(0,r.jsx)(iG,{children:(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",padding:"12px 0 4px"},children:u.isNew?t("desktop.mcpNewServer"):t("desktop.mcpEditServer",{name:u.name})})}),(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 220px) 1fr",gap:"8px 12px",alignItems:"center",padding:"8px 0"},children:[(0,r.jsx)("span",{style:al(),children:t("desktop.mcpServerName")}),(0,r.jsx)("input",{value:x.name,onChange:e=>M("name",e.target.value),disabled:!u.isNew,placeholder:"my-server",style:{...aa,opacity:u.isNew?1:.5}}),(0,r.jsxs)("span",{style:al(),children:[t("desktop.mcpCommand")," *"]}),(0,r.jsx)("input",{value:x.command,onChange:e=>M("command",e.target.value),placeholder:"npx @modelcontextprotocol/server-foo",style:aa}),(0,r.jsx)("span",{style:al(),children:t("desktop.mcpArgs")}),(0,r.jsx)("textarea",{value:x.args,onChange:e=>M("args",e.target.value),placeholder:"--port 3000\n--verbose",rows:3,style:{...aa,resize:"vertical",lineHeight:1.5}}),(0,r.jsx)("span",{style:al(),children:t("desktop.mcpTransport")}),(0,r.jsx)("select",{value:x.transport,onChange:e=>M("transport",e.target.value),style:{...aa,fontFamily:"var(--font-mono)"},children:an.map(e=>(0,r.jsx)("option",{value:e,children:e},e))}),(0,r.jsx)("span",{style:al(),children:t("desktop.mcpLifecycle")}),(0,r.jsx)("select",{value:x.lifecycle,onChange:e=>M("lifecycle",e.target.value),style:{...aa,fontFamily:"var(--font-mono)"},children:as.map(e=>(0,r.jsx)("option",{value:e,children:e},e))}),(0,r.jsx)("span",{style:al(),children:t("desktop.mcpRequestTimeoutMs")}),(0,r.jsx)("input",{type:"number",min:1,value:x.requestTimeoutMs,onChange:e=>M("requestTimeoutMs",e.target.value),placeholder:"300000",style:aa}),(0,r.jsx)("span",{style:al(),children:t("desktop.mcpEnv")}),(0,r.jsx)("textarea",{value:x.env,onChange:e=>M("env",e.target.value),placeholder:'{\n "API_KEY": "..."\n}',rows:3,style:{...aa,resize:"vertical",lineHeight:1.5}})]})}),(0,r.jsx)(iY,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 0"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void R(),disabled:m,style:{padding:"7px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:m?"wait":"pointer",fontSize:12},children:m?t("desktop.saving"):t("desktop.mcpSave")}),(0,r.jsx)("button",{type:"button",onClick:()=>h(null),disabled:m,style:{padding:"7px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:m?"not-allowed":"pointer",fontSize:12},children:t("desktop.mcpCancel")}),v&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:v})]})})]}),w&&!u&&(0,r.jsx)("div",{style:{fontSize:12,color:"#22c55e"},children:t("desktop.mcpSavedRestart")})]}):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:t("desktop.loading")})})})}var ap=o(9210);function au(){let{t:e}=(0,E.s)(),[t,o]=(0,n.useState)(null),[s,i]=(0,n.useState)([]),[a,l]=(0,n.useState)(!0),[d,c]=(0,n.useState)(!1),[p,u]=(0,n.useState)(!1),[g,h]=(0,n.useState)(null);(0,n.useEffect)(()=>{fetch("/api/settings/title-model").then(e=>e.json()).then(e=>{o(e.value),i(e.models??[])}).catch(()=>{}).finally(()=>l(!1))},[]);let x=null!==t&&!s.some(e=>e.label===t),f=(0,n.useCallback)(async t=>{c(!0),h(null),u(!1);try{let e=await fetch("/api/settings/title-model",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:""===t?null:t})}),r=await e.json();if(!e.ok||r.error)return void h(r.error??`HTTP ${e.status}`);o(r.value??null),u(!0),setTimeout(()=>u(!1),2e3)}catch{h(String(e("desktop.titleModelSaveError")))}finally{c(!1)}},[e]),m=[...new Set(s.map(e=>e.provider))];return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"12px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:600,color:"var(--text)",whiteSpace:"nowrap"},children:e("desktop.titleModel")}),(0,r.jsxs)("select",{value:t??"",disabled:a||d,onChange:e=>f(e.target.value),style:{flex:1,minWidth:200,maxWidth:420,padding:"6px 9px",fontSize:12,color:"var(--text)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5},children:[(0,r.jsx)("option",{value:"",children:e("desktop.titleModelFollowSession")}),x&&null!==t&&(0,r.jsxs)("option",{value:t,style:{color:"#ef4444"},children:[t,"(",e("desktop.titleModelInvalid"),")"]}),m.map(e=>(0,r.jsx)("optgroup",{label:e,children:s.filter(t=>t.provider===e).map(e=>(0,r.jsxs)("option",{value:e.label,children:[e.name||e.id,e.reasoning?"(reasoning)":""]},e.label))},e))]}),d&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"…"}),!d&&p&&(0,r.jsx)("span",{style:{fontSize:11,color:"#4ade80"},children:e("desktop.titleModelSaved")})]}),(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"var(--text-muted)",lineHeight:1.5},children:e("desktop.titleModelDescription")}),g&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"#ef4444",lineHeight:1.5},children:g}),x&&null!==t&&(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"#ef4444",lineHeight:1.5},children:[t,"(",e("desktop.titleModelInvalid"),")"]})]})}let ag=["name","reasoning","contextWindow","maxTokens","thinkingLevelMap","hidden"];function ah(e){if(""===e.trim())return;let t=Number(e);return Number.isFinite(t)&&t>0?t:void 0}function ax(e){let t=ah(e.contextWindow??""),o=ah(e.maxTokens??""),r=e.thinkingLevelMap&&Object.keys(e.thinkingLevelMap).length>0?{...e.thinkingLevelMap}:void 0;return{...e.name?.trim()?{name:e.name.trim()}:{},..."boolean"==typeof e.reasoning?{reasoning:e.reasoning}:{},...void 0!==t?{contextWindow:t}:{},...void 0!==o?{maxTokens:o}:{},...r?{thinkingLevelMap:r}:{},..."boolean"==typeof e.hidden?{hidden:e.hidden}:{}}}function af({providerId:e,onRegisterFlush:t,onConfigChange:o}){let{t:s}=(0,E.s)(),i=rY(),[a,l]=(0,n.useState)([]),[d,c]=(0,n.useState)({}),[p,u]=(0,n.useState)({}),[g,h]=(0,n.useState)(new Set),[x,f]=(0,n.useState)(!0),[m,k]=(0,n.useState)(!1),[v,y]=(0,n.useState)(null),[b,w]=(0,n.useState)(!1),[j,S]=(0,n.useState)(null),C=(0,n.useRef)(d),T=(0,n.useRef)(p),z=(0,n.useRef)(a),R=(0,n.useRef)(g),I=(0,n.useRef)(0),M=(0,n.useRef)(null);C.current=d,T.current=p,z.current=a,R.current=g,(0,n.useEffect)(()=>{let t=!1;return f(!0),y(null),(async()=>{try{let o=await fetch(`/api/models-config/builtin?provider=${encodeURIComponent(e)}`),r=await o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);if(t)return;let n={};for(let e of r.models){let t=r.overrides[e.id]??{};n[e.id]={name:"string"==typeof t.name&&t.name.length>0?t.name:e.name,reasoning:"boolean"==typeof t.reasoning?t.reasoning:e.reasoning,contextWindow:"number"==typeof t.contextWindow?String(t.contextWindow):null!=e.contextWindow?String(e.contextWindow):"",maxTokens:"number"==typeof t.maxTokens?String(t.maxTokens):null!=e.maxTokens?String(e.maxTokens):"",hidden:"boolean"==typeof t.hidden&&t.hidden,thinkingLevelMap:t.thinkingLevelMap??e.thinkingLevelMap}}l(r.models),c(n),u(n),h(new Set)}catch(e){t||y(e instanceof Error?e.message:String(e))}finally{t||f(!1)}})(),()=>{t=!0}},[e]);let P=(0,n.useCallback)((e,t)=>{I.current+=1,c(o=>({...o,[e]:{...o[e]??{},...t}})),h(t=>new Set(t).add(e))},[]),D=(0,n.useCallback)(async()=>{let t=M.current;if(t)return t;let r=(async()=>{let t=new Set(R.current);if(0===t.size)return;let r=I.current,n={...C.current},s={},i={};for(let e of z.current){let t=n[e.id],o=T.current[e.id];t&&(s[e.id]=ax(t)),o&&(i[e.id]=ax(o))}let a=function(e,t,o){let r={};for(let n of e){let e=t[n],s=o[n];if(!e||!s)continue;let i={};for(let t of ag){let o=e[t],r=s[t];JSON.stringify(o)!==JSON.stringify(r)&&(i[t]=void 0===o?null:o)}Object.keys(i).length>0&&(r[n]=i)}return r}(t,s,i);if(0===Object.keys(a).length)return void h(new Set);k(!0),y(null),w(!1);try{let s=await fetch("/api/models-config/builtin",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,patches:a})}),i=await s.json();if(!s.ok||i.error)throw Error(i.error??`HTTP ${s.status}`);o?.(i.provider??null);let l={...T.current};for(let e of t){let t=n[e];t&&(l[e]={...t})}T.current=l,u(l),I.current===r&&h(e=>new Set([...e].filter(e=>!t.has(e)))),w(!0),setTimeout(()=>w(!1),2e3)}catch(e){throw y(e instanceof Error?e.message:String(e)),e}finally{k(!1)}})();M.current=r;try{await r}finally{M.current===r&&(M.current=null)}},[o,e]);return((0,n.useEffect)(()=>{if(t)return t(e,D)??void 0},[t,e,D]),x)?(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",marginTop:14,paddingTop:12},children:(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-dim)"},children:s("desktop.modelsLoading")})}):(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",marginTop:14,paddingTop:12,display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:s("desktop.builtinModelsTitle")}),v&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"#f87171"},children:v}),0===a.length&&!v&&(0,r.jsx)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)"},children:s("desktop.builtinModelsEmpty")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:a.map(e=>{let t=d[e.id]??{},o=j===e.id,n=g.has(e.id);return(0,r.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"8px 10px"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>S(o?null:e.id),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text)",fontSize:12,fontWeight:600,padding:0,textAlign:"left"},children:[t.name||e.name||e.id,n&&(0,r.jsx)("span",{style:{color:"var(--accent)",marginLeft:6},children:"•"})]}),(0,r.jsx)("code",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:e.id}),(t.reasoning??e.reasoning)&&(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:8,background:"var(--bg-selected)",color:"var(--text-muted)"},children:"reasoning"}),(0,r.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:[s("desktop.builtinModelsContext"),": ",(0,r.jsx)("b",{children:t.contextWindow?Number(t.contextWindow).toLocaleString():"—"})," \xb7 ",s("desktop.builtinModelsMaxTokens"),": ",(0,r.jsx)("b",{children:t.maxTokens?Number(t.maxTokens).toLocaleString():"—"})]})]}),o&&(0,r.jsxs)("div",{style:{marginTop:10,display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12,color:"var(--text)",width:"100%"},children:[s("desktop.modelsName"),(0,r.jsx)("input",{type:"text",value:t.name??"",placeholder:e.name||e.id,onChange:t=>P(e.id,{name:t.target.value.trim()||void 0}),style:{flex:1,minWidth:0,padding:"4px 7px",fontSize:11,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",fontFamily:"var(--font-mono)"}}),(0,r.jsxs)("label",{style:{display:"flex",gap:4,alignItems:"center",fontSize:11,color:t.hidden?"#f87171":"var(--text-muted)",cursor:"pointer",whiteSpace:"nowrap",marginLeft:8},children:[(0,r.jsx)("input",{type:"checkbox",checked:!0===t.hidden,onChange:t=>P(e.id,{hidden:t.target.checked})}),s("desktop.builtinModelsHide")]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:16,flexWrap:"wrap",flexDirection:i?"column":"row",alignItems:i?"flex-start":"center"},children:[(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12,color:"var(--text)",cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:!0===t.reasoning,onChange:t=>P(e.id,{reasoning:t.target.checked})}),s("desktop.builtinModelsReasoning")]}),(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12,color:"var(--text)",flex:i?1:void 0,width:i?"100%":void 0},children:[s("desktop.modelsContextWindow"),(0,r.jsx)("input",{type:"number",min:1,value:t.contextWindow??"",placeholder:null!=e.contextWindow?String(e.contextWindow):"",onChange:t=>P(e.id,{contextWindow:t.target.value}),style:{flex:1,minWidth:0,padding:"4px 7px",fontSize:11,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",fontFamily:"var(--font-mono)"}})]}),(0,r.jsxs)("label",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12,color:"var(--text)",flex:i?1:void 0,width:i?"100%":void 0},children:[s("desktop.modelsMaxOutputTokens"),(0,r.jsx)("input",{type:"number",min:1,value:t.maxTokens??"",placeholder:null!=e.maxTokens?String(e.maxTokens):"",onChange:t=>P(e.id,{maxTokens:t.target.value}),style:{flex:1,minWidth:0,padding:"4px 7px",fontSize:11,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",fontFamily:"var(--font-mono)"}})]})]}),(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)"},children:s("desktop.builtinModelsThinking")}),(0,r.jsx)(aM,{value:t.thinkingLevelMap,onChange:t=>P(e.id,{thinkingLevelMap:t})})]})]},e.id)})}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("button",{type:"button",onClick:()=>{D().catch(()=>{})},disabled:m||0===g.size,style:{alignSelf:"flex-start",padding:"5px 14px",background:g.size>0&&!m?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:g.size>0&&!m?"#fff":"var(--text-dim)",cursor:g.size>0&&!m?"pointer":"not-allowed",fontSize:12,fontWeight:600},children:m?s("desktop.modelsSaving"):b?s("desktop.modelsSaved"):s("desktop.modelsSave")}),g.size>0&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:s("desktop.builtinModelsDirty",{count:g.size})})]})]})}let am=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function ak(){let{t:e}=(0,E.s)();return(0,n.useCallback)((t,o)=>e(t,o),[e])}function av({label:e,children:t}){return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}let ay={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 ab({value:e,onChange:t,placeholder:o,mono:n}){return(0,r.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:o,style:{...ay,fontFamily:n?"var(--font-mono)":"inherit"}})}function aw({value:e,onChange:t,placeholder:o,mono:s,onKeyDown:i,autoComplete:a="off",spellCheck:l=!1,style:d}){let c=ak(),[p,u]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{e||u(!1)},[e]),(0,r.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,r.jsx)("input",{type:p?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:i,placeholder:o,style:{...ay,paddingRight:34,fontFamily:s?"var(--font-mono)":"inherit"},autoComplete:a,spellCheck:l}),(0,r.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":c(p?"desktop.modelsHideApiKey":"desktop.modelsShowApiKey"),title:c(p?"desktop.modelsHideApiKey":"desktop.modelsShowApiKey"),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:p?(0,r.jsx)(ap.G,{size:15}):(0,r.jsx)(r0.b,{size:15})})]})}function aj({value:e,onChange:t,placeholder:o}){return(0,r.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:o,style:ay})}function aS({value:e,onChange:t,options:o,required:n}){let s=ak();return(0,r.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...ay,color:e?"var(--text)":"var(--text-dim)"},children:[!n&&(0,r.jsx)("option",{value:"",children:s("desktop.modelsInheritNone")}),o.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]})}function aC({label:e,checked:t,onChange:o}){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=>o(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function aT({children:e}){return(0,r.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:e})}function az({name:e,provider:t,onChange:o,onRename:s,onDelete:i,onAddModels:a}){let l=ak(),[d,c]=(0,n.useState)(e),[p,u]=(0,n.useState)({phase:"idle"}),[g,h]=(0,n.useState)(""),[x,f]=(0,n.useState)([]),m=(0,n.useRef)(0),k=(0,n.useRef)(null);(0,n.useEffect)(()=>c(e),[e]);let v=(e,r)=>o({...t,[e]:r});(0,n.useEffect)(()=>{t.api||o({...t,api:"openai-completions"})},[t.api]),(0,n.useEffect)(()=>{m.current+=1,u({phase:"idle"}),h(""),f([])},[e,t.baseUrl,t.api,t.apiKey]);let y=(0,n.useCallback)(async()=>{if(!t.baseUrl?.trim()||"loading"===p.phase)return;let o=++m.current;u({phase:"loading"}),f([]);try{let r=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:{...t,models:void 0}})}),n=await r.json();if(o!==m.current)return;if(!r.ok||n.error||!n.models)return void u({phase:"error",message:n.error??`HTTP ${r.status}`});u({phase:"success",models:n.models,endpoint:n.endpoint??t.baseUrl})}catch(e){if(o!==m.current)return;u({phase:"error",message:e instanceof Error?e.message:String(e)})}},[p.phase,e,t]),b=new Set((t.models??[]).map(e=>e.id)),w="success"===p.phase?p.models:[],j=g.trim().toLocaleLowerCase(),S=w.filter(e=>!j||e.id.toLocaleLowerCase().includes(j)||e.name?.toLocaleLowerCase().includes(j)),C=S.slice(0,300),T=C.filter(e=>!b.has(e.id)).map(e=>e.id),z=x.filter(e=>!b.has(e)).length,R=T.length>0&&T.every(e=>x.includes(e)),I=!R&&T.some(e=>x.includes(e));return(0,n.useEffect)(()=>{k.current&&(k.current.indeterminate=I)},[I]),(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)(aT,{children:l("desktop.modelsProvider")}),(0,r.jsx)("button",{onClick:i,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:l("desktop.delete")})]}),(0,r.jsxs)(av,{label:l("desktop.modelsProviderName"),children:[(0,r.jsx)(ab,{value:d,onChange:c,placeholder:"provider-name",mono:!0}),d!==e&&d.trim()&&(0,r.jsx)("button",{onClick:()=>s(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:l("desktop.rename")})]}),(0,r.jsx)(av,{label:l("desktop.modelsBaseUrl"),children:(0,r.jsx)(ab,{value:t.baseUrl??"",onChange:e=>v("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,r.jsxs)(av,{label:l("desktop.modelsApiKey"),children:[(0,r.jsx)(aw,{value:t.apiKey??"",onChange:e=>v("apiKey",e||void 0),placeholder:l("desktop.modelsApiKeyPlaceholder"),mono:!0}),(0,r.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:l("desktop.modelsApiKeyHelp")})]}),(0,r.jsx)(av,{label:l("desktop.modelsApi"),children:(0,r.jsx)(aS,{value:t.api??"openai-completions",onChange:e=>v("api",e),options:am,required:!0})}),(0,r.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:14,display:"flex",flexDirection:"column",gap:10},children:["success"!==p.phase&&(0,r.jsx)("button",{onClick:y,disabled:!t.baseUrl?.trim()||"loading"===p.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"!==p.phase?"var(--text-muted)":"var(--text-dim)",cursor:t.baseUrl?.trim()&&"loading"!==p.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===p.phase?l("desktop.modelsDiscoveryFetching"):l("desktop.modelsDiscoveryFetch")}),"error"===p.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:p.message}),"success"===p.phase&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{value:g,onChange:e=>h(e.target.value),placeholder:l("desktop.modelsDiscoveryFilterPlaceholder",{count:p.models.length}),"aria-label":l("desktop.modelsDiscoveryFilter"),style:{...ay,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:T.length?"pointer":"default",color:"var(--text-muted)",fontSize:10,fontWeight:600},children:[(0,r.jsx)("input",{ref:k,type:"checkbox",checked:R,disabled:0===T.length,onChange:()=>{let e=new Set(T);f(t=>R?t.filter(t=>!e.has(t)):Array.from(new Set([...t,...T])))},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),l("desktop.modelsDiscoverySelectShown")]}),0===C.length?(0,r.jsx)("div",{style:{padding:12,color:"var(--text-dim)",fontSize:11},children:l("desktop.modelsDiscoveryNoMatches")}):C.map((e,t)=>{let o=b.has(e.id),n=x.includes(e.id);return(0,r.jsxs)("label",{style:{minHeight:36,padding:"6px 9px",display:"flex",alignItems:"center",gap:8,borderTop:0===t?"none":"1px solid var(--border)",cursor:o?"default":"pointer",opacity:o?.65:1},children:[(0,r.jsx)("input",{type:"checkbox",checked:n||o,disabled:o,onChange:()=>{var t;return t=e.id,void f(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),(0,r.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11},children:e.name??e.id}),e.name&&(0,r.jsx)("code",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)"},children:e.id})]}),o&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10},children:l("desktop.modelsDiscoveryAdded")})]},e.id)})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,r.jsx)("span",{title:p.endpoint,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:S.length>C.length?l("desktop.modelsDiscoveryShowing",{shown:C.length,total:S.length}):l("desktop.modelsDiscoveryFetched",{count:p.models.length})}),(0,r.jsx)("button",{onClick:()=>{if("success"!==p.phase)return;let e=new Set(x),t=p.models.filter(t=>e.has(t.id)&&!b.has(t.id));0!==t.length&&(a(t),f([]))},disabled:0===z,style:{height:28,padding:"0 11px",border:"none",borderRadius:5,background:z?"var(--accent)":"var(--bg-panel)",color:z?"#fff":"var(--text-dim)",cursor:z?"pointer":"not-allowed",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:z?l("desktop.modelsDiscoveryAddSelectedCount",{count:z}):l("desktop.modelsDiscoveryAddSelected")})]})]})]})]})}let aR=["off","minimal","low","medium","high","xhigh","max"],aI={off:"var(--text-dim)",minimal:"var(--text-muted)",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function aM({value:e,onChange:t}){let o=ak(),n=e??{},s=(e,o)=>{let r={...n};"omit"===o?delete r[e]:r[e]=o,t(Object.keys(r).length?r:void 0)};return(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:aR.map(e=>{let t=n[e],i=e in n?null===t?"null":"string":"omit",a="string"==typeof t?t:"",l=aI[e],d={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)"},c={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:l,flexShrink:0,opacity:"null"===i?.3:1}}),(0,r.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===i?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===i?"line-through":"none"},children:e})]}),(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,r.jsx)("button",{onClick:()=>s(e,"omit"),style:{...d,..."omit"===i?c:{}},children:o("desktop.modelsDefault")}),(0,r.jsx)("button",{onClick:()=>s(e,null),style:{...d,borderLeft:"1px solid var(--border)",..."null"===i?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:o("desktop.modelsDisabled")})]}),(0,r.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===i?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,r.jsx)("button",{onClick:()=>s(e,a||e),style:{...d,..."string"===i?c:{},borderRight:"1px solid var(--border)",flexShrink:0},children:o("desktop.modelsCustom")}),(0,r.jsx)("input",{value:a,onChange:t=>s(e,t.target.value),onFocus:()=>{"string"!==i&&s(e,a||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===i?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===i?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let aE={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function aP({providerName:e,provider:t,model:o,onChange:s,onDelete:i}){let a=ak(),[l,d]=(0,n.useState)({phase:"idle"}),[c,p]=(0,n.useState)({phase:"idle"}),g=(0,n.useRef)(0),h=(0,n.useRef)(null),x=(e,t)=>s({...o,[e]:t}),f=(()=>{if("idle"===l.phase)return null;if("testing"===l.phase)return a("desktop.modelsTestingConnection");let e=[void 0!==l.latencyMs?`${l.latencyMs}ms`:null,void 0!==l.status?`HTTP ${l.status}`:null].filter(Boolean);return"success"===l.phase?[a("desktop.modelsConnected"),...e,l.responseText||null].filter(Boolean).join(" \xb7 "):[a("desktop.modelsFailed"),...e,l.message].filter(Boolean).join(" \xb7 ")})();(0,n.useEffect)(()=>{d({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,o.id,o.api]);let m=(0,n.useCallback)(async()=>{if(o.id.trim()&&"testing"!==l.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:o})}),n=await r.json();if(!r.ok||!n.ok)return void d({phase:"error",message:n.error??`HTTP ${r.status}`,latencyMs:n.latencyMs,status:n.status});d({phase:"success",latencyMs:n.latencyMs,status:n.status,responseText:n.responseText})}catch(e){d({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[o,t,e,l.phase]);(0,n.useEffect)(()=>{g.current+=1,p({phase:"idle"}),h.current=null},[e,t.baseUrl,o.id]);let k=(0,n.useCallback)(async()=>{let r=o.id.trim();if(!r||"loading"===c.phase)return;let n=++g.current;p({phase:"loading"});try{let i=new URLSearchParams({q:r,provider:e,limit:"50"});t.baseUrl?.trim()&&i.set("baseUrl",t.baseUrl.trim());let a=await fetch(`/api/models-config/catalog?${i}`),l=await a.json();if(n!==g.current)return;if(!a.ok||l.error||!l.recommendation)return void p({phase:"error",message:l.error??`HTTP ${a.status}`});let d=function(e,t){let o={...e},r=0;if(!e.name?.trim()&&t.name&&(o.name=t.name,r+=1),void 0===e.reasoning&&!0===t.reasoning&&(o.reasoning=!0,r+=1),!e.input?.length&&t.input?.length&&(o.input=[...t.input],r+=1),void 0===e.contextWindow&&void 0!==t.contextWindow&&(o.contextWindow=t.contextWindow,r+=1),void 0===e.maxTokens&&void 0!==t.maxTokens&&(o.maxTokens=t.maxTokens,r+=1),t.cost){let n={...e.cost??{}},s=!1;for(let e of["input","output","cacheRead","cacheWrite"])void 0===n[e]&&void 0!==t.cost[e]&&(n[e]=t.cost[e],s=!0,r+=1);s&&(o.cost=n)}return{model:o,appliedCount:r}}(o,l.recommendation.preset);d.appliedCount>0&&(h.current=o,s(d.model)),p({phase:"success",recommendation:l.recommendation,appliedCount:d.appliedCount})}catch(e){if(n!==g.current)return;p({phase:"error",message:e instanceof Error?e.message:String(e)})}},[c.phase,o,s,t.baseUrl,e]),v=(()=>{if("success"!==c.phase)return null;let{recommendation:t,appliedCount:o}=c,r=o>0?a("desktop.modelsCatalogFilled",{count:o}):a("desktop.modelsCatalogNoEmptyFields");if("unreliable"===t.price.status){let e="no-exact-match"===t.price.reason?a("desktop.modelsCatalogNoExactMatch"):a("desktop.modelsCatalogPriceUnreliable");return`${r} \xb7 ${e}`}let n="provider"===t.price.method?a("desktop.modelsCatalogPriceProvider",{provider:t.price.providerName??t.price.providerId??e}):"base-url"===t.price.method?a("desktop.modelsCatalogPriceBaseUrl",{provider:t.price.providerName??t.price.providerId??e}):a("desktop.modelsCatalogPriceConsensus",{support:t.price.support,total:t.price.total});return`${r} \xb7 ${n}`})(),y="error"===c.phase?c.message:v,b="error"===c.phase?"#ef4444":"success"===c.phase&&"unreliable"===c.recommendation.price.status?"#d97706":"var(--text-dim)";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)(aT,{children:a("desktop.modelsModelSection")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f&&(0,r.jsx)("span",{title:f,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===l.phase?"#fecaca":"success"===l.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===l.phase?"#fee2e2":"success"===l.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:f}),(0,r.jsxs)("button",{onClick:m,disabled:!o.id.trim()||"testing"===l.phase,title:a("desktop.modelsTestConnection"),style:{height:24,padding:"0 8px",background:"success"===l.phase?"#16a34a":"none",border:`1px solid ${"success"===l.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===l.phase?"#fff":o.id.trim()&&"testing"!==l.phase?"var(--text-muted)":"var(--text-dim)",cursor:o.id.trim()&&"testing"!==l.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===l.phase&&(0,r.jsx)(u.S,{size:11}),"testing"===l.phase?a("desktop.modelsTesting"):"success"===l.phase?a("desktop.modelsOk"):a("desktop.modelsTest")]}),(0,r.jsx)("button",{onClick:i,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:a("desktop.modelsRemove")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,r.jsx)(av,{label:a("desktop.modelsIdRequired"),children:(0,r.jsx)(ab,{value:o.id,onChange:e=>x("id",e),placeholder:"model-id",mono:!0})}),(0,r.jsx)(av,{label:a("desktop.modelsName"),children:(0,r.jsx)(ab,{value:o.name??"",onChange:e=>x("name",e||void 0),placeholder:a("desktop.modelsDisplayName")})})]}),(0,r.jsxs)("div",{style:{padding:"10px 0",borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:()=>void k(),disabled:!o.id.trim()||"loading"===c.phase,style:{height:28,padding:"0 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:o.id.trim()&&"loading"!==c.phase?"var(--text-muted)":"var(--text-dim)",cursor:o.id.trim()&&"loading"!==c.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===c.phase?a("desktop.modelsCatalogFilling"):a("desktop.modelsCatalogFill")}),(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:a("desktop.modelsCatalogSource")})]}),(0,r.jsxs)("div",{"aria-live":"polite",style:{marginTop:6,height:20,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:b,fontSize:10},children:[(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),"success"===c.phase&&h.current&&(0,r.jsx)("button",{onClick:()=>{let e=h.current;e&&(h.current=null,s(e),p({phase:"idle"}))},style:{background:"none",border:"none",color:"var(--accent)",cursor:"pointer",fontSize:10,flexShrink:0},children:a("desktop.modelsCatalogUndo")})]})]}),(0,r.jsx)(av,{label:a("desktop.modelsApiOverride"),children:(0,r.jsx)(aS,{value:o.api??"",onChange:e=>x("api",e||void 0),options:am})}),(0,r.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,r.jsx)(aC,{label:a("desktop.modelsReasoningThinking"),checked:o.reasoning??!1,onChange:e=>x("reasoning",e||void 0)}),(0,r.jsx)(aC,{label:a("desktop.modelsImageInput"),checked:o.input?.includes("image")??!1,onChange:e=>x("input",e?["text","image"]:void 0)})]}),o.reasoning&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(aC,{label:a("desktop.modelsDeepSeekCompat"),checked:o.compat?.thinkingFormat==="deepseek",onChange:e=>s(function(e,t){if(t)return{...e,compat:{...e.compat??{},...aE}};if(!e.compat)return e;let o={...e.compat};return delete o.thinkingFormat,delete o.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(o).length?o:void 0}}(o,e))}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,r.jsx)(aT,{children:a("desktop.modelsThinkingLevelMap")}),o.thinkingLevelMap&&(0,r.jsx)("button",{onClick:()=>x("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 7px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",cursor:"pointer"},children:a("desktop.modelsClearAll")})]}),(0,r.jsx)(aM,{value:o.thinkingLevelMap,onChange:e=>x("thinkingLevelMap",e)})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,r.jsx)(av,{label:a("desktop.modelsContextWindow"),children:(0,r.jsx)(aj,{value:void 0!==o.contextWindow?String(o.contextWindow):"",onChange:e=>x("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,r.jsx)(av,{label:a("desktop.modelsMaxOutputTokens"),children:(0,r.jsx)(aj,{value:void 0!==o.maxTokens?String(o.maxTokens):"",onChange:e=>x("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(aT,{children:a("desktop.modelsCostPerMillionTokens")}),(0,r.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:8},children:["input","output","cacheRead","cacheWrite"].map(e=>(0,r.jsx)(av,{label:e,children:(0,r.jsx)(aj,{value:o.cost?.[e]!==void 0?String(o.cost[e]):"",onChange:t=>{let r;return r=parseFloat(t),void s({...o,cost:{...o.cost??{},[e]:isNaN(r)?void 0:r}})},placeholder:"0"})},e))})]})]})}function aD({provider:e,onRefresh:t,onRegisterBuiltinFlush:o,onBuiltinProviderChange:s}){let i=ak(),[a,l]=(0,n.useState)({phase:"idle"}),[d,c]=(0,n.useState)(""),p=(0,n.useRef)(null),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{("auth"===a.phase||"prompt"===a.phase)&&setTimeout(()=>u.current?.focus(),50)},[a.phase]),(0,n.useEffect)(()=>{l({phase:"idle"}),c(""),p.current?.close(),p.current=null},[e.id]),(0,n.useEffect)(()=>()=>{p.current?.close()},[]);let g=(0,n.useCallback)(()=>{p.current?.close(),l({phase:"connecting"}),c("");let o=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);p.current=o,o.onmessage=e=>{let r=JSON.parse(e.data);"auth"===r.type?(l({phase:"auth",url:r.url,instructions:r.instructions??null,token:r.token}),window.open(r.url,"_blank","noopener,noreferrer")):"device_code"===r.type?(l({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?l({phase:"prompt",message:r.message,placeholder:r.placeholder??null,token:r.token}):"select_request"===r.type?l({phase:"select",message:r.message,options:r.options??[],token:r.token}):"progress"===r.type?l({phase:"progress",message:r.message}):"success"===r.type?(o.close(),l({phase:"success"}),t()):"error"===r.type?(o.close(),l({phase:"error",message:r.message})):"cancelled"===r.type&&(o.close(),l({phase:"idle"}))},o.onerror=()=>{o.close(),l(e=>"success"===e.phase?e:{phase:"error",message:i("desktop.modelsConnectionLost")})}},[e.id,t,i]),h=(0,n.useCallback)(async()=>{try{let t=await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"});if(t.ok)l({phase:"idle"});else{let e=await t.json().catch(()=>null);l({phase:"error",message:409===t.status?i("desktop.modelsAuthenticationStateChanged"):e?.error??`HTTP ${t.status}`})}}catch(e){l({phase:"error",message:e instanceof Error?e.message:String(e)})}finally{t()}},[e.id,t,i]),x=(0,n.useCallback)(async(t,o)=>{if(o.trim()){l({phase:"progress",message:i("desktop.modelsVerifying")});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:o.trim()})});if(!r.ok){let e=await r.json().catch(()=>({}));l({phase:"error",message:e.error??i("desktop.modelsServerError",{status:r.status})});return}c("")}catch(e){l({phase:"error",message:e instanceof Error?e.message:i("desktop.modelsNetworkError")})}}},[e.id,i]),f=(0,n.useCallback)(async(t,o)=>{l({phase:"progress",message:i("desktop.modelsContinuing")});try{let r=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:o})});if(!r.ok){let e=await r.json().catch(()=>({}));l({phase:"error",message:e.error??i("desktop.modelsServerError",{status:r.status})})}}catch(e){l({phase:"error",message:e instanceof Error?e.message:i("desktop.modelsNetworkError")})}},[e.id,i]),m="connecting"===a.phase||"progress"===a.phase||"auth"===a.phase||"device_code"===a.phase||"prompt"===a.phase||"select"===a.phase;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,r.jsx)(aT,{children:i("desktop.modelsSubscription")}),(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:e.loggedIn?i("desktop.modelsConnected"):i("desktop.modelsNotConnected")})]})]}),(0,r.jsxs)("div",{style:{minHeight:48},children:["idle"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?i("desktop.modelsAlreadyConnected"):i("desktop.modelsConnectAccount",{provider:e.name})}),"connecting"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:i("desktop.modelsOpeningBrowser")}),"select"===a.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:a.message}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:a.options.map(e=>(0,r.jsx)("button",{onClick:()=>f(a.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"===a.phase||"prompt"===a.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"===a.phase?i("desktop.modelsCompleteSignIn"):a.message}),"auth"===a.phase&&(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[i("desktop.modelsBrowserDidNotOpen")," ",(0,r.jsx)("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:i("desktop.modelsOpenLoginPage")}),"."]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("input",{ref:u,value:d,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key&&x(a.token,d)},placeholder:"auth"===a.phase?"http://localhost:1455/auth/callback?code=…":a.placeholder??i("desktop.modelsEnterValue"),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:()=>x(a.token,d),disabled:!d.trim(),style:{padding:"6px 12px",background:d.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:d.trim()?"#fff":"var(--text-dim)",cursor:d.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:i("desktop.submit")})]})]}),"device_code"===a.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:i("desktop.modelsOpenVerificationPage")}),(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:a.userCode}),(0,r.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,r.jsx)("a",{href:a.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:a.verificationUri}),a.expiresInSeconds?` ${i("desktop.modelsExpiresInMinutes",{count:Math.ceil(a.expiresInSeconds/60)})}`:""]})]}),"progress"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:a.message}),"success"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:i("desktop.modelsConnectedSuccessfully")}),"error"===a.phase&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:a.message})]}),(0,r.jsx)("div",{style:{display:"flex",gap:8},children:m?(0,r.jsx)("button",{onClick:()=>{p.current?.close(),l({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:i("desktop.cancel")}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:g,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:e.loggedIn?i("desktop.modelsReLogin"):i("desktop.modelsLogin")}),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:i("desktop.modelsDisconnect")})]})}),(0,r.jsx)(af,{providerId:e.id,onRegisterFlush:o,onConfigChange:s})]})}function a$({provider:e,onRefresh:t,onRegisterBuiltinFlush:o,onBuiltinProviderChange:s}){let i=ak(),[a,l]=(0,n.useState)(""),[d,c]=(0,n.useState)(!1),[p,g]=(0,n.useState)(!1),[h,x]=(0,n.useState)(null),[f,m]=(0,n.useState)(!1);(0,n.useEffect)(()=>{l(""),x(null),m(!1)},[e.id]);let k=(0,n.useCallback)(async()=>{if(a.trim()){c(!0),x(null),m(!1);try{let o=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:a.trim()})}),r=await o.json();!o.ok||r.error?x(r.error??`HTTP ${o.status}`):(l(""),m(!0),setTimeout(()=>m(!1),2e3),t())}catch(e){x(String(e))}finally{c(!1)}}},[a,e.id,t]),v=(0,n.useCallback)(async()=>{g(!0),x(null);try{let t=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),o=await t.json();(!t.ok||o.error)&&x(409===t.status?i("desktop.modelsAuthenticationStateChanged"):o.error??`HTTP ${t.status}`)}catch(e){x(String(e))}finally{t(),g(!1)}},[e.id,t,i]);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)(aT,{children:i("desktop.modelsApiKey")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,r.jsx)("span",{style:{fontSize:11,color:e.configured?"#4ade80":"var(--text-dim)"},children:e.configured?i("desktop.modelsConfigured"):i("desktop.modelsNotConfigured")})]})]}),(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.configured?i("desktop.modelsApiKeyStored"):i("desktop.modelsEnableModels",{provider:e.displayName,count:e.modelCount,models:1===e.modelCount?i("desktop.modelsSingular"):i("desktop.modelsPlural")})}),(0,r.jsx)(av,{label:i("desktop.modelsApiKey"),children:(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)(aw,{value:a,onChange:l,onKeyDown:e=>{"Enter"===e.key&&a.trim()&&k()},placeholder:e.configured?i("desktop.modelsEnterNewKey"):"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,r.jsxs)("button",{onClick:k,disabled:d||!a.trim()||f,style:{padding:"6px 12px",background:f?"#16a34a":a.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:a.trim()||f?"#fff":"var(--text-dim)",cursor:d||!a.trim()||f?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[f&&(0,r.jsx)(u.S,{size:12}),f?i("desktop.modelsSaved"):d?i("desktop.modelsSaving"):i("desktop.modelsSave")]})]})}),h&&(0,r.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:h}),e.configured&&(0,r.jsx)("button",{onClick:v,disabled:p,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:p?"not-allowed":"pointer",fontSize:12},children:p?i("desktop.modelsRemoving"):i("desktop.modelsDisconnect")}),(0,r.jsx)(af,{providerId:e.id,onRegisterFlush:o,onConfigChange:s})]})}function aF({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:o,onSelectApiKey:s,onAddCustom:i,onClose:a}){let l=ak(),[c,p]=(0,n.useState)(""),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{setTimeout(()=>u.current?.focus(),30)},[]);let g=c.trim().toLowerCase(),h=e.filter(e=>!e.loggedIn&&(!g||e.name.toLowerCase().includes(g))),x=t.filter(e=>!e.configured&&(!g||e.displayName.toLowerCase().includes(g)||e.id.toLowerCase().includes(g))),f=!g||"custom".includes(g)||"openai-compatible".includes(g)||"anthropic-compatible".includes(g),m=h.length+x.length+ +!!f,k={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&&a()},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.jsx)(d.$,{size:13,style:{color:"var(--text-dim)",flexShrink:0}}),(0,r.jsx)("input",{ref:u,value:c,onChange:e=>p(e.target.value),onKeyDown:e=>{"Escape"===e.key&&a()},placeholder:l("desktop.modelsSearchProviders"),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:l("desktop.modelsNoProvidersMatch")}):(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[f&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:l("desktop.modelsCustom")}),f&&(0,r.jsxs)("button",{onClick:()=>{i(),a()},style:k,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:l("desktop.modelsCompatibleProvider")}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:l("desktop.modelsCustomEndpointFormat")})]}),(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.jsx)(y.c,{size:13,style:{color:"var(--text-dim)"}})})]}),h.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!f,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:l("desktop.modelsSubscriptions")}),h.map(e=>(0,r.jsxs)("button",{onClick:()=>{o(e.id),a()},style:k,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)(nE,{id:e.id,size:28})]},e.id)),x.length>0&&(0,r.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(h.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:l("desktop.modelsApiKey")}),x.map(e=>(0,r.jsxs)("button",{onClick:()=>{s(e.id),a()},style:k,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.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:l("desktop.modelsCount",{count:e.modelCount})})]}),(0,r.jsx)(nE,{id:e.id,size:28})]},e.id))]})})]})})}function aW({embedded:e=!1,sessionId:t,onCloseAction:o,onSavedAction:s,onRegisterFlush:i}){let a=ak(),l=rY(),[d,c]=(0,n.useState)({providers:{}}),[p,g]=(0,n.useState)(!0),[h,x]=(0,n.useState)(!1),[f,m]=(0,n.useState)(null),[k,v]=(0,n.useState)(!1),[y,b]=(0,n.useState)(null),[w,j]=(0,n.useState)([]),[S,T]=(0,n.useState)([]),[z,R]=(0,n.useState)(!1),[I,M]=(0,n.useState)({oauth:!1,apiKey:!1}),E=(0,n.useRef)({providers:{}}),P=(0,n.useRef)(new Map),D=(0,n.useRef)(0),$=(0,n.useRef)(!1);E.current=d;let F=(0,n.useCallback)(e=>{let t=e(E.current);return E.current=t,D.current+=1,c(t),t},[]),W=(0,n.useCallback)(()=>{fetch("/api/auth/combined").then(e=>e.json()).then(e=>{j(e.oauth??[]),T(e.apiKey??[])}).catch(()=>{}).finally(()=>M({oauth:!0,apiKey:!0}))},[]),N=(0,n.useCallback)((e,t)=>(P.current.set(e,t),()=>{P.current.get(e)===t&&P.current.delete(e)}),[]),A=(0,n.useCallback)(async()=>{for(let e of[...P.current.values()])await e()},[]);(0,n.useEffect)(()=>{if(i)return i(A)??void 0},[A,i]);let L=(0,n.useCallback)((e,t)=>{F(o=>{let r={...o.providers??{}};return t?r[e]=t:delete r[e],{...o,providers:r}}),s?.()},[s,F]),O=(0,n.useCallback)(async e=>{if(!$.current){$.current=!0,m(null);try{await A(),b(e)}catch(e){m(e instanceof Error?e.message:String(e))}finally{$.current=!1}}},[A]);(0,n.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};E.current=t,D.current+=1,c(t)}).catch(()=>{let e={providers:{}};E.current=e,D.current+=1,c(e)}).finally(()=>g(!1)),W()},[W]);let H=(0,n.useCallback)(async()=>{if(!$.current){$.current=!0,m(null);try{await A();let e="new-provider",t=1;for(;E.current.providers?.[e];)e=`new-provider-${t++}`;F(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),b({type:"provider",name:e})}catch(e){m(e instanceof Error?e.message:String(e))}finally{$.current=!1}}},[A,F]),B=(0,n.useCallback)((e,t)=>{F(o=>({...o,providers:{...o.providers??{},[e]:t}}))},[F]),U=(0,n.useCallback)((e,t)=>{F(o=>{let r=Object.entries(o.providers??{}),n=r.findIndex(([t])=>t===e);return -1===n?o:(r[n]=[t,r[n][1]],{...o,providers:Object.fromEntries(r)})}),b(o=>o?"provider"===o.type&&o.name===e?{type:"provider",name:t}:"model"===o.type&&o.providerName===e?{...o,providerName:t}:o:o)},[F]),_=(0,n.useCallback)(e=>{let t=Object.keys(F(t=>{let o={...t.providers??{}};return delete o[e],{...t,providers:o}}).providers??{});b(t.length>0?{type:"provider",name:t[0]}:null)},[F]),q=(0,n.useCallback)(async e=>{if(!$.current){$.current=!0,m(null);try{await A();let t=F(t=>{let o=t.providers?.[e]??{},r=[...o.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...o,models:r}}}}),o=(t.providers?.[e]?.models?.length??1)-1;b({type:"model",providerName:e,index:o})}catch(e){m(e instanceof Error?e.message:String(e))}finally{$.current=!1}}},[A,F]),V=(0,n.useCallback)((e,t)=>{F(o=>{let r=o.providers?.[e]??{},n=[...r.models??[]],s=new Set(n.map(e=>e.id));for(let e of t)s.has(e.id)||(s.add(e.id),n.push({id:e.id,name:e.name}));return{...o,providers:{...o.providers??{},[e]:{...r,models:n}}}})},[F]),K=(0,n.useCallback)((e,t,o)=>{F(r=>{let n=r.providers?.[e]??{},s=[...n.models??[]];return s[t]=o,{...r,providers:{...r.providers??{},[e]:{...n,models:s}}}})},[F]),J=(0,n.useCallback)(async(e,t)=>{if(!$.current){$.current=!0,m(null);try{await A(),F(o=>{let r=o.providers?.[e]??{},n=[...r.models??[]];return n.splice(t,1),{...o,providers:{...o.providers??{},[e]:{...r,models:n.length?n:void 0}}}}),b({type:"provider",name:e})}catch(e){m(e instanceof Error?e.message:String(e))}finally{$.current=!1}}},[A,F]),G=(0,n.useCallback)(async()=>{if(!h){x(!0),m(null),v(!1);try{await A();let e=E.current,t=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);o.config&&(E.current=o.config,D.current+=1,c(o.config)),v(!0),s?.(),setTimeout(()=>v(!1),2e3)}catch(e){m(e instanceof Error?e.message:String(e))}finally{x(!1)}}},[A,s,h]),Y=(0,n.useCallback)(async()=>{try{await A(),o?.()}catch(e){m(e instanceof Error?e.message:String(e))}},[A,o]),Z=Object.entries(d.providers??{}),X=new Set([...w.map(e=>e.id),...S.map(e=>e.id)]),Q=Z.filter(([e])=>!X.has(e)&&"opencode"!==e&&"opencode-go"!==e),ee=w.filter(e=>e.loggedIn),et=S.filter(e=>"opencode"!==e.id&&"opencode-go"!==e.id),eo=et.filter(e=>e.configured);(0,n.useEffect)(()=>{if(y||p||!I.oauth||!I.apiKey)return;let e=ee[0]?{type:"oauth",providerId:ee[0].id}:eo[0]?{type:"apikey",providerId:eo[0].id}:Q[0]?.[0]?{type:"provider",name:Q[0][0]}:null;e&&b(e)},[eo,ee,Q,p,I.apiKey,I.oauth,y]);let er=(()=>{if(!y)return null;if("oauth"===y.type){let e=w.find(e=>e.id===y.providerId);return e?(0,r.jsx)(aD,{provider:e,onRefresh:W,onRegisterBuiltinFlush:N,onBuiltinProviderChange:t=>L(e.id,t)},e.id):null}if("apikey"===y.type){let e=S.find(e=>e.id===y.providerId);return e?(0,r.jsx)(a$,{provider:e,onRefresh:W,onRegisterBuiltinFlush:N,onBuiltinProviderChange:t=>L(e.id,t)},e.id):null}if("provider"===y.type){let e=d.providers?.[y.name];return e?(0,r.jsx)(az,{name:y.name,provider:e,onChange:e=>B(y.name,e),onRename:e=>U(y.name,e),onDelete:()=>_(y.name),onAddModels:e=>V(y.name,e)},y.name):null}let e=d.providers?.[y.providerName],t=e?.models?.[y.index];return t?(0,r.jsx)(aP,{providerName:y.providerName,provider:e,model:t,onChange:e=>K(y.providerName,y.index,e),onDelete:()=>{J(y.providerName,y.index)}},`${y.providerName}-${y.index}`):null})();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:e?{display:"flex",flex:1,minWidth:0,minHeight:0,overflow:"hidden"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:t=>{e||t.target!==t.currentTarget||Y()},children:(0,r.jsxs)("div",{style:e?{flex:1,minWidth:0,minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden"}:{width:l?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:l?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!e&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:a("desktop.models")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,r.jsx)("button",{onClick:()=>{Y()},"aria-label":a("desktop.modelsClose"),title:a("desktop.modelsClose"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,r.jsx)(au,{}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:l?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:l?"100%":210,maxHeight:l?"40vh":void 0,borderRight:l?"none":"1px solid var(--border)",borderBottom:l?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[ee.map(e=>{let t=y?.type==="oauth"&&y.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>{O({type:"oauth",providerId:e.id})},style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(nE,{id:e.id,size:16}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),eo.map(e=>{let t=y?.type==="apikey"&&y.providerId===e.id;return(0,r.jsxs)("div",{onClick:()=>{O({type:"apikey",providerId:e.id})},style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(nE,{id:e.id,size:16}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(ee.length>0||eo.length>0)&&Q.length>0&&(0,r.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),p?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:a("desktop.modelsLoading")}):Q.map(([e,t])=>{let o=y?.type==="provider"&&y.name===e,n=t.models??[];return(0,r.jsxs)("div",{style:{marginBottom:2},children:[(0,r.jsxs)("div",{onClick:()=>{O({type:"provider",name:e})},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(C.G,{size:11,style:{color:"var(--text-dim)",flexShrink:0}}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:o?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),n.map((t,o)=>{let n=y?.type==="model"&&y.providerName===e&&y.index===o;return(0,r.jsxs)("div",{onClick:()=>{O({type:"model",providerName:e,index:o})},style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:n?"var(--bg-selected)":"none"},onMouseEnter:e=>{n||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{n||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:t.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.id||a("desktop.modelsNewModel")}),t.reasoning&&(0,r.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},o)}),(0,r.jsx)("div",{onClick:t=>{t.stopPropagation(),q(e)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,r.jsx)("span",{style:{fontSize:11},children:a("desktop.modelsAddModel")})})]},e)})]}),(0,r.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,r.jsx)("button",{onClick:()=>R(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.color="var(--text-muted)"},children:a("desktop.modelsAddProvider")})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:p?null:er??(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:a("desktop.modelsSelectProviderOrModel")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[f&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:f}),!e&&(0,r.jsx)("button",{onClick:()=>{Y()},style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:a("desktop.cancel")}),(0,r.jsx)(ar,{sessionId:t}),(0,r.jsxs)("button",{onClick:G,disabled:h||k,style:{position:"relative",padding:"6px 16px",minWidth:92,background:k?"#16a34a":h?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:k?"#fff":h?"var(--text-muted)":"#fff",cursor:h||k?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:k?"saved-pop 0.45s ease":void 0},children:[k&&(0,r.jsx)(u.S,{size:14,style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0}}),(0,r.jsx)("span",{children:k?a("desktop.modelsSaved"):h?a("desktop.modelsSaving"):a("desktop.modelsSave")})]})]})]})}),z&&(0,r.jsx)(aF,{oauthProviders:w,apiKeyProviders:et,onSelectOAuth:e=>{O({type:"oauth",providerId:e})},onSelectApiKey:e=>{O({type:"apikey",providerId:e})},onAddCustom:H,onClose:()=>R(!1)})]})}function aN(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function aA(e){let t=e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/);return t?.[1]??e}function aL(e){return`${e.scope}\0${e.source}`}function aO(e,t){if(e.disabled)return t("desktop.disabled");let o=[e.counts.extensions?t("desktop.extensionsCount",{count:e.counts.extensions}):"",e.counts.skills?t("desktop.skillsCount",{count:e.counts.skills}):"",e.counts.prompts?t("desktop.promptsCount",{count:e.counts.prompts}):"",e.counts.themes?t("desktop.themesCount",{count:e.counts.themes}):""].filter(Boolean);return o.length?o.join(" \xb7 "):t("desktop.noResources")}function aH(e,t){let o=[];return e.version&&o.push(t("desktop.installedVersion",{version:e.version})),e.configuredVersion&&o.push(t("desktop.configuredVersion",{version:e.configuredVersion})),o.length?o.join(" \xb7 "):t("desktop.unknown")}function aB(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function aU({pkg:e}){let{t}=(0,E.s)(),o=[["extension",t("desktop.extensions")],["skill",t("desktop.skills")],["prompt",t("desktop.prompts")],["theme",t("desktop.themes")]].map(([t,o])=>({kind:t,label:o,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return 0===o.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:t(e.disabled?"desktop.packageDisabled":"desktop.noResolvedResources")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:o.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 a_({scope:e}){let{t}=(0,E.s)();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:t(`desktop.${e}`)})}function aq(e,t){return{padding:"6px 12px",background:t?"rgba(239,68,68,0.08)":"none",border:"1px solid var(--border)",borderRadius:6,color:t?"#ef4444":"var(--text-muted)",cursor:e?"not-allowed":"pointer",fontSize:12,opacity:e?.5:1}}function aV({enabled:e,loading:t,onToggle:o,label:n}){return(0,r.jsx)("button",{type:"button",onClick:o,disabled:t,title:n,"aria-label":n,"aria-pressed":e,style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none",opacity:t?.65:1},children:(0,r.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function aK({value:e,onChange:t}){let{t:o}=(0,E.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(n=>{let s=e===n;return(0,r.jsx)("button",{onClick:()=>t(n),style:{width:76,border:"none",borderRight:"global"===n?"1px solid var(--border)":"none",background:s?"var(--bg-selected)":"none",color:s?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12},children:o(`desktop.${n}`)},n)})})}function aJ({cwd:e,source:t,scope:o,busy:s,actionError:i,onSourceChange:a,onScopeChange:l,onInstall:d}){let{t:c}=(0,E.s)(),p=(0,n.useRef)(null);return(0,n.useEffect)(()=>{p.current?.focus()},[]),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:c("desktop.addPluginTitle")}),(0,r.jsx)("a",{href:"https://pi.dev/packages",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",fontSize:12,textDecoration:"none",whiteSpace:"nowrap"},children:"pi.dev/packages ↗"})]}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"project"===o?`${aN(e)}/.pi/agent/{npm,git}`:"~/.pi/agent/{npm,git}"})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("label",{htmlFor:"plugin-source",style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:c("desktop.pluginSource")}),(0,r.jsx)("input",{id:"plugin-source",ref:p,value:t,onChange:e=>a(e.target.value),onPaste:e=>{let t=e.clipboardData.getData("text"),o=aA(t);o!==t&&(e.preventDefault(),a(o))},onBlur:e=>a(aA(e.currentTarget.value)),placeholder:"npm:@scope/package",style:{width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,outline:"none"},onKeyDown:e=>{"Enter"===e.key&&t.trim()&&!s&&d()}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)(aK,{value:o,onChange:l}),(0,r.jsx)("button",{type:"button",onClick:d,disabled:s||!t.trim(),style:{...aq(s||!t.trim()),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:c(s?"desktop.installing":"desktop.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:c("desktop.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))})]}),i&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:i})]})}function aG({pkg:e,cwd:t,busyKey:o,actionError:n,actionMessage:s,sessionId:i,onAction:a,onReloadSession:l}){let{t:d}=(0,E.s)(),c=aL(e),p=o?.endsWith(c)??!1,u="reload"===o,g=!e.disabled;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20,maxWidth:680},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,minWidth:0,flexWrap:"wrap"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:180,flex:1},children:[(0,r.jsx)(aV,{enabled:g,loading:p||u,onToggle:()=>a(e.disabled?"enable":"disable",e),label:d(e.disabled?"desktop.enablePackage":"desktop.disablePackage")}),(0,r.jsx)(a_,{scope:e.scope}),e.disabled?(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)",color:"var(--text-dim)"},children:d("desktop.disabled")}):e.filtered&&(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(245,158,11,0.12)",color:"#d97706"},children:d("desktop.filtered")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("button",{onClick:()=>a("update",e),disabled:p||u,style:aq(p||u),children:d(o===`update:${c}`?"desktop.updating":"desktop.update")}),(0,r.jsx)("button",{onClick:l,disabled:!i||u||p,style:aq(!i||u||p),title:d(i?"desktop.reloadCurrentSession":"desktop.openSessionToReload"),children:d(u?"desktop.reloading":"desktop.reloadSession")}),(0,r.jsx)("button",{onClick:()=>a("remove",e),disabled:p||u,style:aq(p||u,!0),children:d(o===`remove:${c}`?"desktop.removing":"desktop.remove")})]})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.status")}),(0,r.jsx)("div",{style:{color:aB(e.status),textTransform:"capitalize"},children:e.status}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.version")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:aH(e,d)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.package")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.packageName??d("desktop.unknown")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.resources")}),(0,r.jsx)("div",{style:{color:"var(--text-muted)"},children:aO(e,d)}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.installedPath")}),(0,r.jsx)("div",{style:{color:e.installedPath?"var(--text-muted)":"#ef4444",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.installedPath?aN(e.installedPath):d("desktop.notFound")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)"},children:d("desktop.cwd")}),(0,r.jsx)("div",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:aN(t)})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:d("desktop.resolvedResources")}),(0,r.jsx)(aU,{pkg:e})]}),s&&(0,r.jsx)("div",{style:{fontSize:12,color:"#16a34a"},children:s}),n&&(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:n})]})}function aY({cwd:e,sessionId:t,embedded:o=!1,onCloseAction:s,onReloadedAction:i}){let a=rY(),{t:l}=(0,E.s)(),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(!0),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(null),[m,k]=(0,n.useState)(!1),[v,b]=(0,n.useState)(""),[w,j]=(0,n.useState)("global"),[S,C]=(0,n.useState)(null),[T,z]=(0,n.useState)(null),[R,I]=(0,n.useState)(null),M=(0,n.useMemo)(()=>d?.packages??[],[d?.packages]),P=M.find(e=>aL(e)===x)??null,D=(0,n.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:M.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[M]),$=(0,n.useCallback)(async()=>{u(!0),h(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);c(o),k(e=>0===o.packages.length||e),f(e=>e&&o.packages.some(t=>aL(t)===e)?e:o.packages[0]?aL(o.packages[0]):null)}catch(e){h(e instanceof Error?e.message:String(e))}finally{u(!1)}},[e]);(0,n.useEffect)(()=>{$()},[$]);let F=(0,n.useCallback)(async(t,o)=>{let r=aL(o);C(`${t}:${r}`),z(null),I(null);try{let r=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:o.source,scope:o.scope,cwd:e})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);if(c(n),"remove"===t)f(n.packages[0]?aL(n.packages[0]):null),0===n.packages.length&&k(!0),I(l("desktop.packageRemoved"));else{let e={install:l("desktop.packageInstalled"),update:l("desktop.packageUpdated"),disable:l("desktop.packageDisabledMessage"),enable:l("desktop.packageEnabled")};I(e[t])}}catch(e){z(e instanceof Error?e.message:String(e))}finally{C(null)}},[e,l]),W=(0,n.useCallback)(async()=>{let t=aA(v).trim();if(!t)return;let o=`${w}\0${t}`;C(`install:${o}`),z(null),I(null);try{var r;let n,s,i=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"install",source:t,scope:w,cwd:e})}),a=await i.json();if(!i.ok||a.error)throw Error(a.error??`HTTP ${i.status}`);c(a);let d=(r=a.packages,s=(n=t.trim()).startsWith("npm:")?n.slice(4):n,r.find(e=>e.scope===w&&e.source===n)??r.find(e=>e.scope===w&&e.source===`npm:${s}`)??r.find(e=>e.scope===w&&e.source.endsWith(n)));f(d?aL(d):o),k(!1),b(""),I(l("desktop.packageInstalled"))}catch(e){z(e instanceof Error?e.message:String(e))}finally{C(null)}},[e,w,v,l]),N=(0,n.useCallback)(async()=>{if(t){C("reload"),z(null),I(null);try{await sb(t,{type:"reload"}),i?.(),await $(),I(l("desktop.sessionReloaded"))}catch(e){z(e instanceof Error?e.message:String(e))}finally{C(null)}}},[$,i,t,l]),A=S?.startsWith("install:")??!1;return(0,r.jsx)("div",{style:o?{display:"flex",flex:1,minWidth:0,minHeight:0,overflow:"hidden"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{o||e.target!==e.currentTarget||s?.()},children:(0,r.jsxs)("div",{style:o?{display:"flex",flex:1,minWidth:0,minHeight:0,flexDirection:"column",overflow:"hidden"}:{width:a?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:a?"calc(100dvh - 16px)":"76vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!o&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:l("desktop.plugins")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:aN(e)})]}),(0,r.jsx)("button",{onClick:s,title:l("desktop.close"),"aria-label":l("desktop.close"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:a?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:a?"100%":245,maxHeight:a?"40vh":void 0,borderRight:a?"none":"1px solid var(--border)",borderBottom:a?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:p?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:l("desktop.loading")}):g?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:g}):0===M.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:l("desktop.noPluginsConfigured")}):D.map(e=>(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase"},children:l(`desktop.${e.scope}`)}),e.packages.map(e=>{let t=aL(e),o=!m&&x===t;return(0,r.jsxs)("div",{onClick:()=>{f(t),k(!1),z(null),I(null)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:aB(e.status)}}),(0,r.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:o?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source}),(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:aO(e,l)}),(e.version||e.configuredVersion)&&(0,r.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:aH(e,l)})]})]},t)})]},e.scope))}),(0,r.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("button",{type:"button",onClick:()=>{k(!0),z(null),I(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:m?"var(--bg-selected)":"none",color:m?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{m||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{m||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(y.c,{size:13}),l("desktop.addPlugin")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:m?(0,r.jsx)(aJ,{cwd:e,source:v,scope:w,busy:A,actionError:T,onSourceChange:b,onScopeChange:j,onInstall:W}):p?null:P?(0,r.jsx)(aG,{pkg:P,cwd:e,busyKey:S,actionError:T,actionMessage:R,sessionId:t,onAction:F,onReloadSession:N},aL(P)):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:l("desktop.selectPackage")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsx)("div",{style:{minWidth:0,flex:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden"},children:d?.diagnostics.length?(0,r.jsx)("span",{title:d.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:d.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:l("desktop.diagnosticsCount",{count:d.diagnostics.length,suffix:1===d.diagnostics.length?"":"s"})}):(0,r.jsx)("span",{children:d?l("desktop.pluginResourceTotals",{extensions:d.totals.extensions,skills:d.totals.skills,prompts:d.totals.prompts,themes:d.totals.themes}):""})}),(0,r.jsx)("button",{onClick:()=>void $(),disabled:p||null!==S,style:aq(p||null!==S),children:l("desktop.refresh")}),!o&&(0,r.jsx)("button",{onClick:s,style:aq(!1),children:l("desktop.close")})]})]})})}var aZ=o(36282);function aX(){let{t:e}=(0,E.s)(),[t,o]=(0,n.useState)({enabled:!1,protocol:"http",host:"127.0.0.1",port:7890,username:"",password:"",noProxy:"localhost,127.0.0.1,.local",hasPassword:!1}),[s,i]=(0,n.useState)(!1),[a,l]=(0,n.useState)(!1),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(null),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(!1),[m,k]=(0,n.useState)(!1);(0,n.useEffect)(()=>{(async()=>{try{let e=await fetch("/api/proxy");if(e.ok){let t=await e.json();o(e=>({...e,...t,password:""}))}}catch{}})()},[]);let v=(0,n.useCallback)((e,t)=>{o(o=>({...o,[e]:t})),"password"===e&&k(!0),f(!0),u(null),h(null)},[]),y=(0,n.useCallback)(async()=>{i(!0),u(null),h(null);try{let r={...t};delete r.hasPassword,m||delete r.password;let n=await fetch("/api/proxy",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),s=await n.json();if(n.ok){u(!0),f(!1),k(!1);let e=await fetch("/api/proxy");if(e.ok){let t=await e.json();o(e=>({...e,...t,password:""}))}}else u(!1),h(s.error||e("desktop.proxySaveFailed"))}catch(t){u(!1),h(t instanceof Error?t.message:e("desktop.proxySaveFailed"))}finally{i(!1)}},[t,m,e]),b=(0,n.useCallback)(async()=>{l(!0),c(null),x&&await y();try{let t=await fetch("/api/proxy/test",{method:"POST"}),o=await t.json();o.success?c({ok:!0,message:`${e("desktop.proxyTestSuccess")} \xb7 ${o.latencyMs}ms`,latencyMs:o.latencyMs}):c({ok:!1,message:o.error||e("desktop.proxyTestFailed")})}catch(t){c({ok:!1,message:t instanceof Error?t.message:e("desktop.proxyTestFailed")})}finally{l(!1)}},[x,y,e]),w=(0,n.useCallback)(()=>{if(!t.enabled||!t.host||!t.port)return null;let e="";return t.username&&t.password?e=`${t.username}:${"•".repeat(Math.min(t.password.length,8))}@`:t.username&&(e=`${t.username}@`),`${t.protocol}://${e}${t.host}:${t.port}`},[t.enabled,t.host,t.port,t.protocol,t.username,t.password])();return(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",padding:"16px 20px",overflow:"auto",gap:16},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:4},children:[(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14,fontWeight:500,color:"var(--text)",cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:t.enabled,onChange:e=>v("enabled",e.target.checked),style:{width:16,height:16,accentColor:"var(--accent)"}}),e("desktop.proxyEnable")]}),t.enabled&&w&&(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontFamily:"var(--font-mono)",backgroundColor:"var(--bg-hover)",padding:"2px 10px",borderRadius:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"60%"},title:w,children:w})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px 16px",opacity:t.enabled?1:.5,pointerEvents:t.enabled?"auto":"none"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyProtocol")}),(0,r.jsxs)("select",{value:t.protocol,onChange:e=>v("protocol",e.target.value),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"},children:[(0,r.jsx)("option",{value:"http",children:"HTTP"}),(0,r.jsx)("option",{value:"https",children:"HTTPS"}),(0,r.jsx)("option",{value:"socks5",children:"SOCKS5"})]})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyHost")}),(0,r.jsx)("input",{type:"text",value:t.host,onChange:e=>v("host",e.target.value),placeholder:"127.0.0.1",style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyPort")}),(0,r.jsx)("input",{type:"number",value:t.port,onChange:e=>v("port",parseInt(e.target.value,10)||0),placeholder:"7890",min:1,max:65535,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyUsername")}),(0,r.jsx)("input",{type:"text",value:t.username,onChange:e=>v("username",e.target.value),placeholder:t.username?"":e("desktop.proxyUsername"),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyPassword")}),(0,r.jsx)("input",{type:"password",value:t.password,onChange:e=>v("password",e.target.value),placeholder:t.hasPassword?"••••••••":e("desktop.proxyPassword"),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,gridColumn:"1 / -1"},children:[(0,r.jsx)("label",{style:{fontSize:12,color:"var(--text-muted)"},children:e("desktop.proxyNoProxy")}),(0,r.jsx)("input",{type:"text",value:t.noProxy,onChange:e=>v("noProxy",e.target.value),placeholder:"localhost,127.0.0.1,.local",style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:13,fontFamily:"var(--font-mono)",outline:"none"}})]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:10,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:y,disabled:s,style:{padding:"6px 18px",borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:500,cursor:s?"not-allowed":"pointer",opacity:s?.5:1,transition:"background 0.15s"},onMouseEnter:e=>{s||(e.currentTarget.style.background="var(--accent-hover)")},onMouseLeave:e=>{s||(e.currentTarget.style.background="var(--accent)")},children:s?e("desktop.proxySaving"):e("desktop.proxySave")}),(0,r.jsx)("button",{type:"button",onClick:b,disabled:a||!t.enabled,style:{padding:"6px 18px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:t.enabled?"var(--text)":"var(--text-muted)",fontSize:13,fontWeight:500,cursor:t.enabled?"pointer":"not-allowed",opacity:t.enabled?1:.5,transition:"background 0.15s"},onMouseEnter:e=>{t.enabled&&(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t.enabled&&(e.currentTarget.style.background="var(--bg)")},children:a?e("desktop.proxyTesting"):e("desktop.proxyTest")})]}),!0===p&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderRadius:6,backgroundColor:"rgba(34, 197, 94, 0.12)",color:"#22c55e",fontSize:13},children:[(0,r.jsx)(oV.r,{size:16,weight:"fill"}),e("desktop.proxySaved")]}),!1===p&&g&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderRadius:6,backgroundColor:"rgba(239, 68, 68, 0.10)",color:"#ef4444",fontSize:13},children:[(0,r.jsx)(sd.J,{size:16,weight:"fill"}),g]}),d&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderRadius:6,backgroundColor:d.ok?"rgba(34, 197, 94, 0.10)":"rgba(239, 68, 68, 0.10)",color:d.ok?"#22c55e":"#ef4444",fontSize:13},children:[d.ok?(0,r.jsx)(oV.r,{size:16,weight:"fill"}):(0,r.jsx)(sd.J,{size:16,weight:"fill"}),d.message,void 0!==d.latencyMs&&(0,r.jsxs)("span",{style:{color:"var(--text-muted)",fontSize:12,marginLeft:4},children:["(",d.latencyMs,"ms)"]})]}),x&&!p&&!g&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 12px",borderRadius:6,backgroundColor:"var(--bg-hover)",color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)(aZ.j,{size:12,weight:"fill"}),e("desktop.proxyUnsaved")]})]})}function aQ(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function a0(e){let t=e.sourceInfo?.source,o=e.sourceInfo?.scope;return"user"===o||"user"===t?"global":"project"===o||"project"===t?"project":"path"}function a1(e){let t=a0(e);return"path"===t?t:e.install?.skillsShUrl?`${t} / skills.sh`:t}function a2(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function a4(e,t){return e?e.slice(0,8):t}function a6({enabled:e,loading:t,onToggle:o}){let{t:n}=(0,E.s)();return(0,r.jsx)("button",{onClick:o,disabled:t,title:n(e?"desktop.visibleInModelPrompt":"desktop.hiddenFromModelPrompt"),style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none"},children:(0,r.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function a5({skill:e,cwd:t,onToggle:o,toggling:n,saveError:s,updateStatus:i,checkingUpdate:a,updating:l,updateError:d,onCheckUpdate:c,onUpdate:p}){let{t:u}=(0,E.s)(),g=a0(e),h=!e.disableModelInvocation;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===g?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===g?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:u(`desktop.${g}`)}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if("project"===g&&e.startsWith(t)){let o=e.slice(t.length).replace(/^[/\\]/,"");return`./${o}`}return aQ(e)}(e.filePath)}),(0,r.jsx)(a6,{enabled:h,loading:n,onToggle:()=>o(e)}),s&&(0,r.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:s})]}),!h&&(0,r.jsx)("div",{style:{marginTop:-12,color:"var(--text-dim)",fontSize:12},children:u("desktop.hiddenButInvocable")}),e.install?.skillsShUrl&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:u("desktop.pluginSource")}),(0,r.jsx)("a",{href:e.install.skillsShUrl,target:"_blank",rel:"noreferrer",title:e.install.skillsShUrl,style:{display:"flex",alignItems:"center",gap:8,width:"fit-content",maxWidth:"100%",color:"var(--accent)",textDecoration:"none"},children:(0,r.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.install.skillsShUrl.replace(/^https?:\/\//,"")," ↗"]})})]}),e.install&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:u("desktop.version")}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-muted)"},children:a4(i?.currentVersion??e.install.versionHash,u("desktop.unknown"))}),e.install.canCheckForUpdates&&(0,r.jsx)("button",{onClick:c,disabled:a||l,style:{padding:"4px 9px",border:"1px solid var(--border)",borderRadius:5,background:"none",color:"var(--text-muted)",cursor:a||l?"not-allowed":"pointer",opacity:a||l?.5:1,fontSize:11},children:u("desktop.check")}),i?.state==="update-available"&&(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"#d97706"},children:a4(i.latestVersion,u("desktop.unknown"))}),(a||i&&"update-available"!==i.state)&&(0,r.jsx)("span",{style:{fontSize:12,color:a?"var(--accent)":i?.state==="up-to-date"?"#16a34a":i?.state==="error"?"#ef4444":"var(--text-dim)"},children:a?u("desktop.checking"):i?.state==="up-to-date"?u("desktop.upToDate"):i?.state==="unsupported"?u("desktop.automaticChecksUnavailable"):i?.message||u("desktop.checkFailed")}),i?.state==="update-available"&&(0,r.jsx)("button",{onClick:p,disabled:l||a,style:{padding:"4px 10px",border:"none",borderRadius:5,background:"var(--accent)",color:"#fff",cursor:l||a?"not-allowed":"pointer",opacity:l||a?.5:1,fontSize:11,fontWeight:600},children:u(l?"desktop.updating":"desktop.update")})]}),d&&(0,r.jsx)("span",{style:{fontSize:12,color:"#ef4444"},children:d})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:u("desktop.name")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:u("desktop.description")}),(0,r.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function a3({cwd:e,installedPackages:t,projectResourcesLoaded:o,onInstalled:s}){let{t:i}=(0,E.s)(),[a,l]=(0,n.useState)(""),[d,c]=(0,n.useState)([]),[p,u]=(0,n.useState)(!1),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(null),[m,k]=(0,n.useState)(null),[v,y]=(0,n.useState)(new Set),[b,w]=(0,n.useState)("global"),j=(0,n.useRef)(null);(0,n.useEffect)(()=>{j.current?.focus()},[]),(0,n.useEffect)(()=>{o||w("global")},[o]);let S=(0,n.useCallback)(async e=>{if(e.trim()){u(!0),h(null),c([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),o=await t.json();if(o.error)return void h(o.error);c(o.results??[]),0===(o.results??[]).length&&h(i("desktop.noSkillsFound"))}catch(e){h(String(e))}finally{u(!1)}}},[i]),C=(0,n.useCallback)(async t=>{f(t),k(null);try{let o=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:b,cwd:e})}),r=await o.json();if(!o.ok||r.error)return void k(r.error??`HTTP ${o.status}`);y(e=>new Set(e).add(`${b}:${t}`)),s()}catch(e){k(String(e))}finally{f(null)}},[s,b,e]),T="global"===b?"~/.pi/agent/skills/":`${aQ(e)}/.pi/skills/`;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:i("desktop.addSkillTitle")}),(0,r.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,r.jsx)("input",{ref:j,value:a,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&S(a)},placeholder:i("desktop.skillSearchPlaceholder"),style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,r.jsx)("button",{onClick:()=>S(a),disabled:p||!a.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:p||!a.trim()?"not-allowed":"pointer",opacity:p||!a.trim()?.5:1,flexShrink:0},children:p?i("desktop.searching"):i("desktop.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:()=>w(e),disabled:"project"===e&&!o,title:"project"!==e||o?void 0:i("desktop.projectSkillInstallUnavailable"),style:{padding:"3px 10px",border:"none",cursor:"project"!==e||o?"pointer":"not-allowed",opacity:"project"!==e||o?1:.5,background:b===e?"var(--bg-selected)":"none",color:b===e?"var(--text)":"var(--text-dim)",fontWeight:b===e?600:400,borderRight:"global"===e?"1px solid var(--border)":"none"},children:i(`desktop.${e}`)},e))}),(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",T]})]}),g&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:g}),m&&(0,r.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:m})]}),d.length>0?(0,r.jsx)("div",{style:{flex:1,overflowY:"auto"},children:d.map(e=>{let o=t[b].has(e.package)||v.has(`${b}:${e.package}`),n=x===e.package,s=e.package.indexOf("@"),a=s>-1?e.package.slice(0,s):e.package,l=s>-1?e.package.slice(s+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:l??a}),(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:a}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,r.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,r.jsx)("button",{onClick:()=>!o&&!n&&C(e.package),disabled:o||n||null!==x,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:o||n||null!==x?"not-allowed":"pointer",background:o?"rgba(34,197,94,0.1)":"none",color:o?"#16a34a":n?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:o?`✓ ${i("desktop.installed")}`:n?i("desktop.installing"):i("desktop.install")})]},e.package)})}):!g&&!p&&(0,r.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:[i("desktop.skillSearchHint").split("skills.sh")[0],(0,r.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"}),i("desktop.skillSearchHint").split("skills.sh")[1]]})]})}function a8({cwd:e,embedded:t=!1,sessionId:o,onCloseAction:s}){let i=rY(),{t:a}=(0,E.s)(),[l,d]=(0,n.useState)([]),[c,p]=(0,n.useState)(!0),[u,g]=(0,n.useState)(null),[h,x]=(0,n.useState)(null),[f,m]=(0,n.useState)(new Set),[k,v]=(0,n.useState)(null),[b,w]=(0,n.useState)(!1),[j,S]=(0,n.useState)({}),[C,T]=(0,n.useState)(new Set),[z,R]=(0,n.useState)(!1),[I,M]=(0,n.useState)(null),[P,D]=(0,n.useState)(null),[$,F]=(0,n.useState)(!0),[W,N]=(0,n.useState)({}),A=(0,n.useCallback)(async()=>{p(!0),g(null);try{let t=await fetch(`/api/skills?cwd=${encodeURIComponent(e)}`),o=await t.json();if(!t.ok||o.error)throw Error(o.error??`HTTP ${t.status}`);let r=o.skills??[];if(d(r),F(o.projectResourcesLoaded??!0),r.length>0&&!h){let e=r.find(e=>!e.disableModelInvocation)??r[0];x(e.filePath),e.disableModelInvocation&&N(t=>({...t,[a1(e)]:!0}))}return r}catch(e){return g(String(e)),[]}finally{p(!1)}},[e,h]);(0,n.useEffect)(()=>{S({}),D(null),A()},[e]);let L=(0,n.useCallback)(async t=>{let o=(t?[t]:l.filter(e=>!!e.install)).map(a2).filter(e=>!!e);if(0!==o.length){D(null),T(e=>new Set([...e,...o])),t||R(!0);try{let o=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 o.json();if(!o.ok||r.error)throw Error(r.error??`HTTP ${o.status}`);S(e=>{let t={...e};for(let e of r.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){D(e instanceof Error?e.message:String(e))}finally{T(e=>{let t=new Set(e);for(let e of o)t.delete(e);return t}),t||R(!1)}}},[e,l]),O=(0,n.useCallback)(async t=>{if(!t.install)return;let o=a2(t);M(o),D(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})}),n=await r.json();if(!r.ok||n.error||!n.success)throw Error(n.error??`HTTP ${r.status}`);await A();let s=n.skill?.install?.versionHash;S(e=>({...e,[o]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:s,latestVersion:s}}))}catch(e){D(e instanceof Error?e.message:String(e))}finally{M(null)}},[e,A]),H=(0,n.useCallback)(async t=>{let o=!t.disableModelInvocation;m(e=>new Set(e).add(t.filePath)),v(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t.filePath,disableModelInvocation:o})}),n=await r.json();if(!r.ok||n.error)return void v(n.error??`HTTP ${r.status}`);d(e=>e.map(e=>e.filePath===t.filePath?{...e,disableModelInvocation:o}:e)),o&&N(e=>({...e,[a1(t)]:!0}))}catch(e){v(String(e))}finally{m(e=>{let o=new Set(e);return o.delete(t.filePath),o})}},[e]),B=l.find(e=>e.filePath===h)??null;return(0,r.jsx)("div",{style:t?{display:"flex",flex:1,minWidth:0,minHeight:0,overflow:"hidden"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{t||e.target!==e.currentTarget||s?.()},children:(0,r.jsxs)("div",{style:t?{display:"flex",flex:1,minWidth:0,minHeight:0,flexDirection:"column",overflow:"hidden"}:{width:i?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:i?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!t&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:a("desktop.skills")}),(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:aQ(e)})]}),(0,r.jsx)("button",{onClick:s,title:a("desktop.close"),"aria-label":a("desktop.close"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),!$&&(0,r.jsx)("div",{role:"status",style:{padding:"8px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-subtle)",color:"var(--text-muted)",fontSize:12},children:a("desktop.projectSkillsRestricted")}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:i?"column":"row",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{width:i?"100%":210,maxHeight:i?"40vh":void 0,borderRight:i?"none":"1px solid var(--border)",borderBottom:i?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{padding:"8px 8px 0",display:"flex",justifyContent:"flex-end"},children:(0,r.jsx)(ar,{sessionId:o,onApplied:A})}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:c?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:a("desktop.loading")}):u?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:u}):0===l.length?(0,r.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:a("desktop.noSkillsFound")}):(()=>{let e=[];for(let{key:t,label:o,matches:r}of[{key:"project / skills.sh",label:`${a("desktop.project")} / skills.sh`,matches:e=>"project"===a0(e)&&!!e.install?.skillsShUrl},{key:"project",label:a("desktop.project"),matches:e=>"project"===a0(e)&&!e.install?.skillsShUrl},{key:"global / skills.sh",label:`${a("desktop.global")} / skills.sh`,matches:e=>"global"===a0(e)&&!!e.install?.skillsShUrl},{key:"global",label:a("desktop.global"),matches:e=>"global"===a0(e)&&!e.install?.skillsShUrl},{key:"path",label:a("desktop.path"),matches:e=>"path"===a0(e)}]){let n=l.filter(r);n.length>0&&e.push({key:t,label:o,skills:n})}return e.map(({key:e,label:t,skills:o})=>{let n=o.filter(e=>!e.disableModelInvocation),s=o.filter(e=>e.disableModelInvocation),i=W[e]??!1,l=i?[...n,...s]:n;return(0,r.jsxs)("div",{style:{marginBottom:6},children:[(0,r.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:t}),s.length>0&&(0,r.jsxs)("button",{type:"button",onClick:()=>N(t=>({...t,[e]:!i})),style:{display:"flex",alignItems:"center",gap:5,width:"100%",padding:"4px 8px 3px",border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",fontSize:10,fontWeight:600,letterSpacing:"0.06em",textAlign:"left",textTransform:"uppercase"},children:[(0,r.jsx)("span",{style:{fontSize:8},children:i?"▾":"▸"}),a("desktop.dormant")," (",s.length,")"]}),l.map(e=>{let t,o,n=!b&&h===e.filePath,s=e.disableModelInvocation;return(0,r.jsxs)("div",{onClick:()=>{x(e.filePath),w(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:n?"var(--bg-selected)":"none"},onMouseEnter:e=>{n||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{n||(e.currentTarget.style.background="none")},children:[(0,r.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:s?"var(--border)":"var(--accent)",boxShadow:s?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,r.jsx)("span",{style:{fontSize:12,fontWeight:n?600:400,color:s?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(o=(t=a2(e))?j[t]:void 0,o?.state!=="update-available"?null:(0,r.jsx)("span",{title:a("desktop.updateAvailable"),style:{color:"#d97706",fontSize:13,lineHeight:1,flexShrink:0},children:"↑"}))]},e.filePath)})]},e)})})()}),(0,r.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,r.jsxs)("div",{onClick:()=>w(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:b?"var(--bg-selected)":"none",color:b?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{b||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{b||(e.currentTarget.style.background="none")},children:[(0,r.jsx)(y.c,{size:13}),a("desktop.addSkill")]})})]}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:b?(0,r.jsx)(a3,{cwd:e,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))},projectResourcesLoaded:$,onInstalled:()=>{A()}}):c?null:B?(0,r.jsx)(a5,{skill:B,cwd:e,onToggle:H,toggling:f.has(B.filePath),saveError:k,updateStatus:a2(B)?j[a2(B)]:void 0,checkingUpdate:!!a2(B)&&C.has(a2(B)),updating:I===a2(B),updateError:P,onCheckUpdate:()=>void L(B),onUpdate:()=>void O(B)},B.filePath):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:a("desktop.selectSkill")})})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[l.some(e=>!!e.install)&&(0,r.jsx)("button",{onClick:()=>void L(),disabled:z||null!==I,style:{padding:"6px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:z||null!==I?"not-allowed":"pointer",opacity:z||null!==I?.5:1,fontSize:12},children:z?a("desktop.checking"):a("desktop.checkUpdates")}),Object.values(j).filter(e=>"update-available"===e.state).length>0&&(0,r.jsx)("span",{style:{fontSize:12,color:"#d97706"},children:a("desktop.updatesCount").replace("{count}",String(Object.values(j).filter(e=>"update-available"===e.state).length)).replace("{suffix}",1===Object.values(j).filter(e=>"update-available"===e.state).length?"":"s")})]}),!t&&(0,r.jsx)("button",{onClick:s,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:a("desktop.close")})]})]})})}function a7(){let{t:e}=(0,E.s)(),[t,o]=(0,n.useState)([]),[s,i]=(0,n.useState)(""),[a,l]=(0,n.useState)(""),[d,c]=(0,n.useState)(""),[p,u]=(0,n.useState)(!0),[g,h]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{u(!0),h(null);try{let e=await fetch("/api/logs?limit=500"),t=await e.json();if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);o(t.entries??[])}catch(e){h(e instanceof Error?e.message:String(e))}finally{u(!1)}},[]);(0,n.useEffect)(()=>{x()},[x]);let f=(0,n.useMemo)(()=>[...new Set(t.map(e=>e.source).filter(Boolean))].sort(),[t]),m=(0,n.useMemo)(()=>{let e=d.trim().toLocaleLowerCase();return t.filter(e=>!s||e.statusCode===Number(s)).filter(e=>!a||e.source===a).filter(t=>!e||[t.message,t.details,t.provider,t.model,t.source].filter(Boolean).some(t=>t.toLocaleLowerCase().includes(e))).slice(0,200)},[t,s,a,d]),k=async()=>{try{let e=await fetch("/api/logs",{method:"DELETE"});if(!e.ok)throw Error(`HTTP ${e.status}`);o([])}catch(e){h(e instanceof Error?e.message:String(e))}},v=async e=>{let t=[`[${e.timestamp}] ${e.level.toUpperCase()} ${e.statusCode??"—"}`,`${e.source}${e.provider?` \xb7 ${e.provider}`:""}${e.model?` \xb7 ${e.model}`:""}`,e.message,e.details].filter(Boolean).join("\n");try{await tD(t),h(null)}catch(e){h(e instanceof Error?e.message:String(e))}};return(0,r.jsxs)("div",{style:{flex:1,minWidth:0,minHeight:0,overflow:"auto",padding:"18px 20px",display:"flex",flexDirection:"column",gap:12},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsxs)("select",{value:s,onChange:e=>i(e.target.value),style:{padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12},children:[(0,r.jsx)("option",{value:"",children:e("desktop.logsAllCodes")}),[200,400,401,403,404,408,409,413,429,500,502,503,504].map(e=>(0,r.jsx)("option",{value:e,children:e},e))]}),(0,r.jsxs)("select",{value:a,onChange:e=>l(e.target.value),style:{padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12},children:[(0,r.jsx)("option",{value:"",children:e("desktop.logsAllSources")}),f.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]}),(0,r.jsx)("input",{value:d,onChange:e=>c(e.target.value),placeholder:e("desktop.logsSearch"),style:{flex:1,minWidth:180,padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12}}),(0,r.jsx)("button",{type:"button",onClick:()=>void x(),title:e("desktop.refresh"),"aria-label":e("desktop.refresh"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,r.jsx)(w.S,{size:14})}),(0,r.jsx)("button",{type:"button",onClick:()=>void k(),title:e("desktop.logsClear"),"aria-label":e("desktop.logsClear"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"#ef4444",cursor:"pointer"},children:(0,r.jsx)(j.l,{size:14})})]}),p&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:12},children:e("desktop.loading")}),g&&(0,r.jsx)("div",{style:{color:"#ef4444",fontSize:12},children:g}),!p&&!g&&0===m.length&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:12},children:e("desktop.logsEmpty")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:m.map(t=>(0,r.jsxs)("details",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",padding:"8px 10px"},children:[(0,r.jsxs)("summary",{style:{cursor:"pointer",color:"error"===t.level?"#ef4444":"warning"===t.level?"#f59e0b":"var(--text)",fontSize:12},children:[(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",marginRight:8},children:t.statusCode??"—"}),(0,r.jsx)("span",{style:{marginRight:8},children:new Date(t.timestamp).toLocaleString()}),(0,r.jsx)("span",{style:{overflowWrap:"anywhere"},children:t.message.length>180?`${t.message.slice(0,180)}…`:t.message})]}),(0,r.jsxs)("div",{style:{padding:"8px 0 0 18px",color:"var(--text-muted)",fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:[(0,r.jsxs)("div",{children:[t.source,t.provider?` \xb7 ${t.provider}`:"",t.model?` \xb7 ${t.model}`:""]}),(0,r.jsx)("div",{style:{marginTop:5,maxHeight:260,overflow:"auto"},children:t.message}),t.details&&(0,r.jsx)("div",{style:{marginTop:5,maxHeight:260,overflow:"auto"},children:t.details}),(0,r.jsx)("button",{type:"button",onClick:()=>void v(t),style:{marginTop:8,padding:"4px 7px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:e("desktop.logsCopy")})]})]},t.id))})]})}let a9={padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,width:"100%"},le={padding:"6px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12};function lt(){let{t:e}=(0,E.s)(),[t,o]=(0,n.useState)([]),[s,i]=(0,n.useState)(!0),[a,l]=(0,n.useState)(null),[d,p]=(0,n.useState)(""),[u,h]=(0,n.useState)(""),[x,f]=(0,n.useState)(!1),[m,k]=(0,n.useState)(null),v=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/snippets");if(!e.ok)return;let t=await e.json();o(t.snippets??[]),i(!1)}catch{i(!1)}},[]);(0,n.useEffect)(()=>{v()},[v]);let b=(0,n.useCallback)(()=>{window.dispatchEvent(new Event("pi:snippets-changed"))},[]),w=()=>{l(null),p(""),h(""),k(null)},S=(0,n.useCallback)(async()=>{let t=d.trim();if(!t)return void k(e("desktop.snippetNameRequired"));f(!0),k(null);try{if(a){let e=await fetch(`/api/snippets/${encodeURIComponent(a.id)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,content:u})});if(!e.ok)throw Error(`HTTP ${e.status}`)}else{let e=await fetch("/api/snippets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,content:u})});if(!e.ok)throw Error(`HTTP ${e.status}`)}await v(),b(),w()}catch(e){k(e instanceof Error?e.message:String(e))}finally{f(!1)}},[a,d,u,v,b,e]),C=(0,n.useCallback)(async e=>{try{let t=await fetch(`/api/snippets/${encodeURIComponent(e)}`,{method:"DELETE"});if(!t.ok)throw Error(`HTTP ${t.status}`);a?.id===e&&w(),await v(),b()}catch(e){k(e instanceof Error?e.message:String(e))}},[a,v,b]);return(0,r.jsxs)(iJ,{children:[(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"12px 0"},children:[(0,r.jsx)(rw.c,{size:15,"aria-hidden":"true"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:e("desktop.snippets")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginTop:2},children:e("desktop.snippetsDesc")})]})]})}),(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{width:"100%"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8},children:[(0,r.jsx)("button",{type:"button",onClick:w,style:le,children:(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5},children:[(0,r.jsx)(y.F,{size:13})," ",e("desktop.snippetNew")]})}),a&&(0,r.jsx)("button",{type:"button",onClick:w,style:{...le,background:"var(--bg-hover)",color:"var(--text-muted)"},children:(0,r.jsx)(c.X,{size:13})})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 200px) 1fr",gap:8,alignItems:"start",marginBottom:8},children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",display:"block",marginBottom:4},children:e("desktop.snippetName")}),(0,r.jsx)("input",{value:d,onChange:e=>p(e.target.value),placeholder:"#name",style:a9})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",display:"block",marginBottom:4},children:e("desktop.snippetContent")}),(0,r.jsx)("textarea",{value:u,onChange:e=>h(e.target.value),rows:3,style:{...a9,resize:"vertical",fontFamily:"var(--font-mono)",fontSize:11}})]})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:10},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void S(),disabled:x,style:{...le,cursor:x?"wait":"pointer"},children:e("desktop.snippetSave")}),m&&(0,r.jsx)("span",{style:{color:"var(--status-error, #ef4444)",fontSize:12},children:m})]}),s?(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-dim)"},children:e("desktop.loadingThemes")}):0===t.length?(0,r.jsx)(iZ,{children:e("desktop.snippetEmpty")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.map(t=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 10px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6},children:[(0,r.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:"#"}),(0,r.jsx)("span",{style:{fontWeight:600,fontSize:12,flexShrink:0},children:t.name}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:11,fontFamily:"var(--font-mono)"},children:t.content.split("\n")[0]}),(0,r.jsx)("button",{type:"button",onClick:()=>{l(t),p(t.name),h(t.content),k(null)},title:e("desktop.snippetEdit"),style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",padding:2},children:(0,r.jsx)(g.I,{size:13})}),(0,r.jsx)("button",{type:"button",onClick:()=>void C(t.id),title:e("desktop.snippetDelete"),style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",padding:2},children:(0,r.jsx)(j.l,{size:13})})]},t.id))})]})}),(0,r.jsx)(iY,{children:(0,r.jsx)(iZ,{children:e("desktop.snippetHint")})})]})}var lo=o(2571);function lr(e){return e.apiKey?`${e.apiKey.slice(0,4)}••••${e.apiKey.slice(-4)}`:e.apiKeyMasked}function ln({onRegisterFlush:e}){let{t}=(0,E.s)(),[o,s]=(0,n.useState)([]),[i,a]=(0,n.useState)(null),[l,d]=(0,n.useState)(!0),[c,p]=(0,n.useState)(6e4),[u,g]=(0,n.useState)(""),[h,x]=(0,n.useState)(""),[f,m]=(0,n.useState)(!1),[k,v]=(0,n.useState)(7474),[b,w]=(0,n.useState)(!0),[S,C]=(0,n.useState)(""),[T,z]=(0,n.useState)(!1),[R,I]=(0,n.useState)("••••••••"),[M,P]=(0,n.useState)(null),[D,$]=(0,n.useState)({running:!1}),[F,W]=(0,n.useState)(!1),[N,A]=(0,n.useState)(!1),[L,O]=(0,n.useState)(null),H=`http://127.0.0.1:${k||7474}/v1`,B=!0===D.running,[U,_]=(0,n.useState)(!0),[q,V]=(0,n.useState)(!1),[K,J]=(0,n.useState)(null),[G,Y]=(0,n.useState)(null),Z=(0,n.useRef)({accounts:o,autoSwitch:l,cooldownMs:c,externalEnabled:f,externalPort:k,freeModelsOnly:b,externalApiKeyDraft:S});Z.current={accounts:o,autoSwitch:l,cooldownMs:c,externalEnabled:f,externalPort:k,freeModelsOnly:b,externalApiKeyDraft:S};let X=(0,n.useRef)(null),Q=(0,n.useRef)(!1),[ee,et]=(0,n.useState)(!1),eo=(0,n.useCallback)(async()=>{if(!Q.current){Q.current=!0,et(!0);try{let e=Z.current,t=e.accounts,o=await fetch("/api/opencode-zen",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({accounts:t.map(e=>({...e,...e.apiKeyDraft?{apiKey:e.apiKeyDraft}:{}})),autoSwitch:e.autoSwitch,cooldownMs:e.cooldownMs,externalAccess:{enabled:e.externalEnabled,port:e.externalPort,freeModelsOnly:e.freeModelsOnly,...e.externalApiKeyDraft?{apiKey:e.externalApiKeyDraft}:{}}})}),r=await o.json();if(!o.ok)throw Error(r.error??`HTTP ${o.status}`);z(r.externalAccess.hasApiKey),I(r.externalAccess.apiKeyMasked),$(r.externalAccess.status),P(null),Z.current.accounts===t&&(s(r.accounts.map(e=>({...e,proxy:{...e.proxy},apiKeyDraft:"",passwordDraft:""}))),J("已自动保存"))}catch(e){Y(e instanceof Error?e.message:String(e))}finally{Q.current=!1,et(!1)}}},[]),er=(0,n.useCallback)(()=>{X.current&&clearTimeout(X.current),X.current=setTimeout(()=>{X.current=null,eo()},500)},[eo]),en=(0,n.useCallback)(async()=>{if(X.current)clearTimeout(X.current),X.current=null,await eo();else if(Q.current){let e=Date.now()+5e3;for(;Q.current&&Date.now()<e;)await new Promise(e=>setTimeout(e,50))}},[eo]);(0,n.useEffect)(()=>()=>{X.current&&(clearTimeout(X.current),X.current=null)},[]);let es=(0,n.useCallback)(async()=>{_(!0);try{let e=await fetch("/api/opencode-zen"),t=await e.json();if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);s(t.accounts.map(e=>({...e,proxy:{...e.proxy},apiKeyDraft:"",passwordDraft:""}))),a(t.activeAccountId??null),d(t.autoSwitch),p(t.cooldownMs),m(t.externalAccess.enabled),v(t.externalAccess.port),w(t.externalAccess.freeModelsOnly),C(""),z(t.externalAccess.hasApiKey),I(t.externalAccess.apiKeyMasked),$(t.externalAccess.status)}catch(e){Y(e instanceof Error?e.message:String(e))}finally{_(!1)}},[]);(0,n.useEffect)(()=>{es()},[es]);let ei=(e,t)=>{s(o=>o.map(o=>o.id===e?t(o):o)),er()},ea=async e=>{V(!0),Y(null),J(null);try{let t=await fetch("/api/opencode-zen",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({activeAccountId:e})}),o=await t.json();if(!t.ok)throw Error(o.error??`HTTP ${t.status}`);a(o.activeAccountId??e);let r=(o.accounts??[]).find(e=>e.id===o.activeAccountId);J(`已切换为使用账号「${r?.note??e}」`)}catch(e){Y(e instanceof Error?e.message:String(e))}finally{V(!1)}},el=(0,n.useRef)(null);el.current=en,(0,n.useEffect)(()=>{if(e)return e(()=>el.current?.()??Promise.resolve())},[e]);let ed=async()=>{let e=h.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{if(!/^(https?|socks5):\/\//i.test(e)&&/^[a-z][a-z\d+.-]*:\/\//i.test(e))throw Error(`代理格式错误:仅支持 http/https/socks5:${e}`);let t=new URL(/^(https?|socks5):\/\//i.test(e)?e:`http://${e}`),o=Number(t.port),r="socks5:"===t.protocol?"socks5":"https:"===t.protocol?"https":"http";if(!t.hostname||!Number.isInteger(o)||o<1||o>65535)throw Error(`代理格式错误:${e}`);return{protocol:r,enabled:!0,url:t.hostname,port:o,username:decodeURIComponent(t.username),password:decodeURIComponent(t.password),hasPassword:!!t.password}});if(0===e.length)return;let t=function(e){let t=new Set,o=[];for(let r of e){let e=`${r.protocol}://${r.url.toLowerCase()}:${r.port}`;t.has(e)||(t.add(e),o.push(r))}return o}(e),r=e.length-t.length,n=Math.min(t.length,o.length);J(`已按账号顺序配置 ${n} 个代理${r>0?`(跳过 ${r} 个重复节点)`:""},正在逐个测试可用性…`);let i=await Promise.all(t.slice(0,n).map(async e=>{try{let t=await fetch("/api/opencode-zen/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({proxy:e})}),o=await t.json();if(!t.ok||!0!==o.ok)return{proxy:e,ok:!1,error:o.error??(t.ok?"测试未通过":`HTTP ${t.status}`)};return{proxy:e,ok:!0}}catch{return{proxy:e,ok:!1,error:"测试请求失败"}}})),a=i.filter(e=>e.ok),l=i.filter(e=>!e.ok),d=o.map((e,t)=>{let o=i[t];return o?.ok?{...e,proxy:o.proxy,passwordDraft:o.proxy.password}:e});x("");let c=await fetch("/api/opencode-zen",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({accounts:d.map(e=>({...e,...e.apiKeyDraft?{apiKey:e.apiKeyDraft}:{}}))})}),p=await c.json();if(!c.ok)throw Error(p.error??`HTTP ${c.status}`);s(p.accounts.map(e=>({...e,proxy:{...e.proxy},apiKeyDraft:"",passwordDraft:""}))),0===l.length?J(`代理导入完成:${a.length} 个代理全部通过检测,已按账号顺序绑定并自动保存`):(J(`代理导入完成:${a.length} 个通过并绑定、已自动保存;${l.length} 个未通过检测、未绑定,请检查下方原因`),Y(l.map(e=>`${e.proxy.protocol}://${e.proxy.url}:${e.proxy.port}:${e.error??"不可用"}`).join("\n"))),t.length>o.length&&J(e=>`${e??""};另有 ${t.length-o.length} 个多余代理未分配`)},ec=async()=>{A(!0),O(null),Y(null),J(null);try{let e=!D.running,t=await fetch("/api/opencode-zen",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({externalAccess:{enabled:e,port:k,freeModelsOnly:b,...S?{apiKey:S}:{}}})}),o=await t.json();if(!t.ok)throw Error(o.error??`HTTP ${t.status}`);m(o.externalAccess.enabled),$(o.externalAccess.status),z(o.externalAccess.hasApiKey),I(o.externalAccess.apiKeyMasked),C(""),P(null),o.externalAccess.enabled||J("外部调用已停止")}catch(e){O(e instanceof Error?e.message:String(e))}finally{A(!1)}},ep=async()=>{if(u.trim()){Y(null);try{let e=await fetch("/api/opencode-zen/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:u})}),t=await e.json();if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);s(t.accounts.map(e=>({...e,proxy:{...e.proxy},apiKeyDraft:"",passwordDraft:""}))),a(t.activeAccountId??null),g(""),J("账号导入成功并已自动保存:重复的 Key 只更新备注;代理可用下方「批量导入并测试代理」按账号顺序绑定")}catch(e){Y(e instanceof Error?e.message:String(e))}}},eu=async()=>{W(!0),Y(null),J(null);try{let e=await fetch("/api/opencode-zen/external/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:f,port:k,apiKey:S||void 0})}),t=await e.json();if(t.skipped)return void J(t.message??"外部调用未启用,无需测试");if(!e.ok||!0!==t.ok)throw Error(t.error??(e.ok?"测试未通过":`HTTP ${e.status}`));J(`外部调用测试通过:模型接口返回 ${t.modelCount??"?"} 个模型(${t.latencyMs??"?"}ms)`)}catch(e){Y(e instanceof Error?e.message:String(e))}finally{W(!1)}},eg=async()=>{try{let e=await fetch("/api/opencode-zen/external/key",{method:"POST"}),t=await e.json();if(!e.ok||!t.apiKey)throw Error(t.error??`HTTP ${e.status}`);await tD(t.apiKey),J("外部调用 API Key 已复制")}catch(e){Y(e instanceof Error?e.message:String(e))}};return U?(0,r.jsx)("div",{style:{flex:1,padding:20,color:"var(--text-muted)",fontSize:12},children:t("desktop.loading")}):(0,r.jsxs)("div",{style:{flex:1,minWidth:0,minHeight:0,overflow:"auto",padding:"18px 20px",display:"flex",flexDirection:"column",gap:14},children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"OpenCode Zen"}),(0,r.jsx)("div",{style:{marginTop:4,color:"var(--text-muted)",fontSize:11},children:"账号、独立代理和 429 自动切换只在此处配置,不在普通供应商列表中显示。"})]}),(0,r.jsxs)("section",{style:{border:"1px solid var(--border)",borderRadius:8,padding:12,background:"var(--bg-panel)",display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"外部调用(OpenAI 兼容 API)"}),(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":B,"aria-label":"外部调用开关",onClick:()=>void ec(),disabled:N,title:B?"点击关闭(立即生效)":f?"已开启但网关未运行,点击重新启动":"点击开启(立即生效,需要已设置 API Key)",style:{position:"relative",width:38,height:20,borderRadius:10,border:"1px solid var(--border)",background:B?"#22c55e":"var(--bg)",cursor:N?"wait":"pointer",transition:"background 0.15s",padding:0},children:(0,r.jsx)("span",{style:{position:"absolute",top:2,left:B?18:2,width:14,height:14,borderRadius:7,background:"#fff",opacity:B?1:.7,transition:"left 0.15s"}})}),N?(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"保存中…"}):L?(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:11},children:L}):D.running?(0,r.jsxs)("span",{style:{color:"#22c55e",fontSize:11},children:["运行中(127.0.0.1:",D.port??k,")"]}):D.error?(0,r.jsxs)("span",{style:{color:"#ef4444",fontSize:11},children:["未运行:",D.error]}):f&&!T?(0,r.jsx)("span",{style:{color:"#f59e0b",fontSize:11},children:"已开启但未设置 API Key,服务未启动"}):f?(0,r.jsx)("span",{style:{color:"#f59e0b",fontSize:11},children:"已开启但网关未运行,点击开关重新启动"}):(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"已停止"})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[(0,r.jsxs)("label",{style:{display:"inline-flex",alignItems:"center",gap:5,color:"var(--text-muted)",fontSize:12},children:["端口",(0,r.jsx)("input",{type:"number",min:1,max:65535,value:k||"",onChange:e=>{v(Number(e.target.value)||0),er()},style:{width:90,padding:"6px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:12}})]}),(0,r.jsx)("code",{style:{padding:"6px 8px",background:"var(--bg)",color:"var(--text-muted)",borderRadius:5,fontSize:11},children:H}),(0,r.jsxs)("label",{style:{display:"inline-flex",alignItems:"center",gap:5,color:"var(--text-muted)",fontSize:12},title:"开启时 GET /v1/models 仅返回免费模型(-free 后缀);关闭后返回全部模型(含付费)",children:[(0,r.jsx)("input",{type:"checkbox",checked:b,onChange:e=>{w(e.target.checked),er()}}),"只显示免费模型"]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"API Key(外部客户端 Bearer 认证):"}),(0,r.jsx)("input",{type:"password",value:S,onChange:e=>{C(e.target.value),P(null),er()},placeholder:T?`${R}(留空保持不变)`:"设置外部调用 API Key",style:{width:220,padding:"6px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:11}}),(0,r.jsx)("button",{type:"button",onClick:()=>{let e,t=(e=new Uint8Array(16),crypto.getRandomValues(e),`piweb-${Array.from(e,e=>e.toString(16).padStart(2,"0")).join("")}`);C(t),P(t),J(null),er()},style:{padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"生成随机 Key"}),(0,r.jsxs)("button",{type:"button",onClick:()=>void eg(),disabled:!T,title:"复制已保存的 API Key",style:{padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:T?"pointer":"not-allowed",fontSize:11},children:[(0,r.jsx)(ti.Q,{size:12})," 复制 Key"]}),(0,r.jsxs)("button",{type:"button",onClick:()=>void eu(),disabled:F,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:F?"wait":"pointer",fontSize:11},children:[(0,r.jsx)(lo.j,{size:12})," ",F?"测试中…":"测试连接"]})]}),M&&(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",padding:"8px 10px",border:"1px solid rgba(34,197,94,0.4)",borderRadius:6,background:"rgba(34,197,94,0.08)"},children:[(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:11,fontWeight:600},children:"⚠ 明文仅显示这一次,请立即复制(保存后无法再次查看明文):"}),(0,r.jsx)("code",{style:{padding:"4px 8px",background:"var(--bg)",borderRadius:4,fontSize:11,color:"var(--text)",fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:M}),(0,r.jsxs)("button",{type:"button",onClick:async()=>{await tD(M),J("API Key 已复制")},style:{padding:"4px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:[(0,r.jsx)(ti.Q,{size:12})," 复制"]})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,marginTop:2},children:[(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",fontWeight:600},children:"调用地址与调用方式"}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("code",{style:{padding:"6px 8px",background:"var(--bg)",color:"var(--text-muted)",borderRadius:5,fontSize:11},children:H}),(0,r.jsxs)("button",{type:"button",onClick:async()=>{await tD(H),J("baseURL 已复制")},title:"复制 baseURL",style:{display:"inline-flex",alignItems:"center",gap:4,padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:[(0,r.jsx)(ti.Q,{size:12})," 复制 baseURL"]})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:"curl 示例:"}),(0,r.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",borderRadius:5,fontFamily:"var(--font-mono)",fontSize:10.5,color:"var(--text-muted)",overflowX:"auto",whiteSpace:"pre"},children:`curl ${H}/chat/completions \\
|
|
40
|
+
-H "Authorization: Bearer <你的 Key>" \\
|
|
41
|
+
-H "Content-Type: application/json" \\
|
|
42
|
+
-d '{"model":"<${b?"免费模型,见 GET /v1/models":"模型,见 GET /v1/models"}>","messages":[{"role":"user","content":"Hello"}]}'`}),(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:["OpenAI 兼容客户端(Cline / Roo Code / Open WebUI 等)配置:baseURL = ",(0,r.jsx)("code",{children:H}),",API Key = 上方外部调用 Key,模型列表来自 ",(0,r.jsxs)("code",{children:[H,"/models"]}),b?"(仅返回免费模型)":"(返回全部模型,含付费)","。"]})]})]}),(0,r.jsx)("div",{style:{color:"var(--text-dim)",fontSize:11},children:"流量复用本账号/代理池;仅监听 127.0.0.1,可通过 cloudflared 等隧道对外暴露(Bearer Key 鉴权,未配置 Key 不启动)。开关显示的是实际运行状态(服务重启后自动恢复启动),点击即生效;所有修改自动保存,无需手动保存。"})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{s(e=>[...e,{id:`account-${Date.now()}`,note:"新账号",apiKeyMasked:"••••••••",hasApiKey:!1,enabled:!0,proxy:{protocol:"http",enabled:!0,url:"",port:0,username:"",password:"",hasPassword:!1},apiKeyDraft:""}]),er()},style:{display:"inline-flex",alignItems:"center",gap:5,padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",fontSize:12},children:[(0,r.jsx)(y.F,{size:14})," 添加账号"]}),(0,r.jsxs)("label",{style:{display:"inline-flex",alignItems:"center",gap:6,color:"var(--text-muted)",fontSize:12},children:[(0,r.jsx)("input",{type:"checkbox",checked:l,onChange:e=>{d(e.target.checked),er()}}),"429 自动切换账号+代理"]}),(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},title:"账号返回 429 表示当日免费额度耗尽,冷却至次日 UTC 0 点自动重置",children:"429 限额冷却:至 UTC 0 点自动重置"}),(0,r.jsxs)("label",{style:{display:"inline-flex",alignItems:"center",gap:6,color:"var(--text-muted)",fontSize:12},title:"请求将优先使用此账号;429 自动切换会暂时移开它,冷却结束后回到它",children:["当前使用账号",(0,r.jsxs)("select",{value:i??"",onChange:e=>{e.target.value&&ea(e.target.value)},disabled:q||0===o.length,style:{padding:"6px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:0===o.length?"var(--text-dim)":"var(--text)",fontSize:12,maxWidth:220},children:[0===o.length?(0,r.jsx)("option",{value:"",children:"暂无账号"}):null===i?(0,r.jsx)("option",{value:"",children:"自动轮换"}):null,o.map(e=>(0,r.jsxs)("option",{value:e.id,children:[e.note,"(",lr(e),")"]},e.id))]})]}),ee&&(0,r.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"自动保存中…"})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("textarea",{value:u,onChange:e=>g(e.target.value),placeholder:"每行:账号-apikey\n例如:alice-sk-abc-def",rows:4,style:{width:"100%",resize:"vertical",padding:9,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12}}),(0,r.jsx)("button",{type:"button",onClick:()=>void ep(),style:{alignSelf:"flex-start",padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",fontSize:12},children:"批量导入账号"})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("textarea",{value:h,onChange:e=>x(e.target.value),placeholder:"每行一个代理,按账号顺序分配\n例如:http://user:password@proxy.example.com:7890",rows:3,style:{width:"100%",resize:"vertical",padding:9,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12}}),(0,r.jsx)("button",{type:"button",onClick:()=>{ed().catch(e=>Y(e instanceof Error?e.message:String(e)))},style:{alignSelf:"flex-start",padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",fontSize:12},children:"批量导入并测试代理"})]}),K&&(0,r.jsx)("div",{style:{color:"#22c55e",fontSize:12},children:K}),G&&(0,r.jsx)("div",{style:{color:"#ef4444",fontSize:12,whiteSpace:"pre-wrap"},children:G}),o.map(e=>(0,r.jsxs)("section",{style:{border:"1px solid var(--border)",borderRadius:8,padding:12,background:"var(--bg-panel)",display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("input",{value:e.note,onChange:t=>ei(e.id,e=>({...e,note:t.target.value})),style:{flex:1,minWidth:0,padding:"6px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:12}}),(0,r.jsxs)("label",{style:{display:"inline-flex",alignItems:"center",gap:5,color:"var(--text-muted)",fontSize:11},children:[(0,r.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:t=>ei(e.id,e=>({...e,enabled:t.target.checked}))}),"启用"]}),(0,r.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void(s(e=>e.filter(e=>e.id!==t)),er())},"aria-label":"删除账号",title:"删除账号",style:{border:"none",background:"none",color:"#ef4444",cursor:"pointer"},children:(0,r.jsx)(j.l,{size:15})})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[(0,r.jsx)("code",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"6px 8px",background:"var(--bg)",color:"var(--text-muted)",borderRadius:5,fontSize:11},children:lr(e)}),(0,r.jsx)("input",{type:"password",value:e.apiKeyDraft??"",onChange:t=>ei(e.id,e=>({...e,apiKeyDraft:t.target.value})),placeholder:e.hasApiKey?"替换 Key":"输入 API Key",style:{width:150,padding:"6px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:11}}),(0,r.jsx)("button",{type:"button",onClick:async()=>{try{let t=await fetch("/api/opencode-zen/key",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountId:e.id,proxy:e.proxy})}),o=await t.json();if(!t.ok||!o.apiKey)throw Error(o.error??`HTTP ${t.status}`);await tD(o.apiKey),J(`${e.note} 的 API Key 已复制`)}catch(e){Y(e instanceof Error?e.message:String(e))}},disabled:!e.hasApiKey,title:"复制 API Key","aria-label":"复制 API Key",style:{border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:e.hasApiKey?"pointer":"not-allowed"},children:(0,r.jsx)(ti.Q,{size:14})})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"86px minmax(130px, 1fr) 92px minmax(100px, 1fr) minmax(100px, 1fr)",gap:6},children:[(0,r.jsxs)("select",{value:e.proxy.protocol,onChange:t=>ei(e.id,e=>({...e,proxy:{...e.proxy,protocol:t.target.value}})),style:{padding:"6px 4px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:11},children:[(0,r.jsx)("option",{value:"http",children:"http"}),(0,r.jsx)("option",{value:"https",children:"https"}),(0,r.jsx)("option",{value:"socks5",children:"socks5"})]}),(0,r.jsx)("input",{value:e.proxy.url,onChange:t=>ei(e.id,e=>({...e,proxy:{...e.proxy,url:t.target.value}})),placeholder:"代理主机",style:{padding:"6px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:11}}),(0,r.jsx)("input",{type:"number",value:e.proxy.port||"",onChange:t=>ei(e.id,e=>({...e,proxy:{...e.proxy,port:Number(t.target.value)||0}})),placeholder:"端口",style:{padding:"6px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:11}}),(0,r.jsx)("input",{value:e.proxy.username,onChange:t=>ei(e.id,e=>({...e,proxy:{...e.proxy,username:t.target.value}})),placeholder:"代理账号",style:{padding:"6px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:11}}),(0,r.jsx)("input",{type:"password",value:e.passwordDraft??"",onChange:t=>ei(e.id,e=>({...e,passwordDraft:t.target.value,proxy:{...e.proxy,password:t.target.value,hasPassword:!!t.target.value}})),placeholder:e.proxy.hasPassword?"••••••••":"代理密码",style:{padding:"6px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:11}})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",color:"var(--text-dim)",fontSize:11},children:[(0,r.jsxs)("label",{children:[(0,r.jsx)("input",{type:"checkbox",checked:e.proxy.enabled,onChange:t=>ei(e.id,e=>({...e,proxy:{...e.proxy,enabled:t.target.checked}}))})," 启用此账号独立代理"]}),(0,r.jsxs)("button",{type:"button",onClick:()=>void fetch("/api/opencode-zen/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountId:e.id,proxy:{...e.proxy,password:e.passwordDraft??""}})}).then(async t=>{let o=await t.json();J(o.ok?`${e.note} 代理测试成功`:`${e.note} 代理测试失败:${o.error??o.status??`HTTP ${t.status}`}`)}).catch(e=>Y(e instanceof Error?e.message:String(e))),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:[(0,r.jsx)(lo.j,{size:12})," 测试代理"]})]})]},e.id)),0===o.length&&(0,r.jsx)("div",{style:{color:"var(--text-muted)",fontSize:12},children:"尚未配置 OpenCode Zen 账号。"})]})}let ls=["async","group","smart"],li=["full","compact","custom"],la=["all","background","off"],ll={padding:"7px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",fontSize:12,width:"min(200px, 100%)",fontFamily:"var(--font-mono)"};function ld(){return{fontSize:12,color:"var(--text-muted)"}}function lc({cwd:e,sessionId:t}){let{t:o}=(0,E.s)(),[s,i]=(0,n.useState)({}),[a,l]=(0,n.useState)([]),[d,c]=(0,n.useState)(""),[p,u]=(0,n.useState)(!1),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(!1),[m,k]=(0,n.useState)(null),[v,y]=(0,n.useState)(!1),[b,w]=(0,n.useState)([]),[j,S]=(0,n.useState)({}),C=(0,n.useCallback)(async()=>{h(null);try{let e=await fetch("/api/subagents"),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);i(t.config??{}),l(t.agents??[]),c(t.filePath)}catch(e){h(e instanceof Error?e.message:String(e))}finally{u(!0)}},[]);(0,n.useEffect)(()=>{let t=e?`?cwd=${encodeURIComponent(e)}`:"";fetch(`/api/models${t}`).then(e=>e.ok?e.json():null).then(e=>{e?.modelList&&w(e.modelList)}).catch(()=>{})},[e]),(0,n.useEffect)(()=>{C()},[C]);let T=(0,n.useCallback)((e,t)=>{i(o=>({...o,[e]:t})),y(!1),k(null)},[]),z=(0,n.useCallback)(async()=>{f(!0),k(null),y(!1);try{let e=await fetch("/api/subagents",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);i(t.config??{}),y(!0)}catch(e){k(e instanceof Error?e.message:String(e))}finally{f(!1)}},[s]),R=(0,n.useRef)({}),I=(0,n.useCallback)(async(e,t)=>{let o=(R.current[e]??0)+1;R.current[e]=o,S(t=>({...t,[e]:"saving"}));try{let r=await fetch(`/api/subagents/agents/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:t})});if(R.current[e]!==o)return;let n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);S(t=>({...t,[e]:"saved"})),l(o=>o.map(o=>o.name===e?{...o,model:t??void 0}:o)),setTimeout(()=>{S(t=>{if("saved"===t[e]){let o={...t};return delete o[e],o}return t})},2e3)}catch(t){if(R.current[e]!==o)return;S(o=>({...o,[e]:`error:${t instanceof Error?t.message:String(t)}`}))}},[]),M=(e,t)=>(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 240px) 1fr",gap:"8px 12px",alignItems:"center",padding:"8px 0"},children:[(0,r.jsx)("span",{style:ld(),children:o(t)}),(0,r.jsx)("input",{type:"number",min:0,value:s[e]??"",onChange:t=>T(e,""===t.target.value?void 0:Number(t.target.value)),placeholder:"defaultMaxTurns"===e?"0 = 不限":"",style:ll})]})},e),P=(e,t,n)=>(0,r.jsx)(iG,{children:(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 240px) 1fr",gap:"8px 12px",alignItems:"center",padding:"8px 0"},children:[(0,r.jsx)("span",{style:ld(),children:o(t)}),(0,r.jsx)("select",{value:s[e]??n[0],onChange:t=>T(e,t.target.value),style:{...ll,fontFamily:"var(--font-mono)"},children:n.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]})},e),D=(e,t,n)=>(0,r.jsx)(iG,{children:(0,r.jsx)(iR,{checked:s[e]??!1,onChange:t=>T(e,t),label:o(t),description:n?o(n):void 0})},e);return(0,r.jsx)("div",{style:{flex:1,overflow:"auto",minWidth:0,padding:"20px 22px",display:"flex",flexDirection:"column",gap:16},children:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:p?g?(0,r.jsx)("div",{style:{fontSize:12,color:"#ef4444"},children:g}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:o("desktop.subagents")}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d||"~/.pi/agent/subagents.json"})]}),(0,r.jsx)(iZ,{children:o("desktop.subagentsDesc")}),(0,r.jsxs)(iJ,{children:[M("maxConcurrent","desktop.subagentsMaxConcurrent"),M("defaultMaxTurns","desktop.subagentsDefaultMaxTurns"),M("graceTurns","desktop.subagentsGraceTurns"),P("defaultJoinMode","desktop.subagentsJoinMode",ls),P("widgetMode","desktop.subagentsWidgetMode",la),P("toolDescriptionMode","desktop.subagentsToolDescMode",li),D("schedulingEnabled","desktop.subagentsScheduling","desktop.subagentsSchedulingDesc"),D("scopeModels","desktop.subagentsScopeModels","desktop.subagentsScopeModelsDesc"),D("disableDefaultAgents","desktop.subagentsDisableDefault","desktop.subagentsDisableDefaultDesc"),D("fleetView","desktop.subagentsFleetView","desktop.subagentsFleetViewDesc"),(0,r.jsx)(iY,{children:D("outputTranscript","desktop.subagentsOutputTranscript","desktop.subagentsOutputTranscriptDesc")})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,r.jsx)("button",{type:"button",onClick:()=>void z(),disabled:x,style:{padding:"7px 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:x?"wait":"pointer",fontSize:12},children:x?o("desktop.saving"):o("desktop.mcpSave")}),v&&(0,r.jsx)("span",{style:{color:"#22c55e",fontSize:12},children:o("desktop.subagentsSaved")}),m&&(0,r.jsx)("span",{style:{color:"#ef4444",fontSize:12},children:m}),(0,r.jsx)(ar,{sessionId:t})]}),a.length>0&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,fontSize:13,fontWeight:600,color:"var(--text)"},children:[(0,r.jsx)(ib.d,{size:15,"aria-hidden":"true"}),o("desktop.subagentsDiscovered")]}),(0,r.jsx)(iJ,{children:a.map((e,t)=>(0,r.jsx)(iY,{children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:3,padding:t===a.length-1?"12px 0":"12px 0 0"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:12.5,fontWeight:600,color:"var(--text)",fontFamily:"var(--font-mono)"},children:e.name}),e.displayName&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:e.displayName}),e.model&&(0,r.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:3,background:"rgba(37,99,235,0.12)",color:"var(--accent)",fontFamily:"var(--font-mono)"},children:e.model})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:o("desktop.subagentsModel")}),(0,r.jsxs)("select",{value:e.model??"",onChange:t=>void I(e.name,t.target.value||null),style:{...ll,width:"min(260px, 100%)",maxWidth:260},children:[(0,r.jsx)("option",{value:"",children:o("desktop.subagentsModelDefault")}),e.model&&!b.some(t=>`${t.provider}/${t.id}`===e.model)&&(0,r.jsx)("option",{value:e.model,children:e.model}),b.map(e=>(0,r.jsxs)("option",{value:`${e.provider}/${e.id}`,children:[e.name,"(",e.provider,"/",e.id,")"]},`${e.provider}/${e.id}`))]}),"saving"===j[e.name]&&(0,r.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:[o("desktop.saving"),"…"]}),"saved"===j[e.name]&&(0,r.jsx)("span",{style:{fontSize:10,color:"#22c55e"},children:o("desktop.subagentsSaved")}),j[e.name]?.startsWith("error:")&&(0,r.jsx)("span",{style:{fontSize:10,color:"#ef4444"},children:j[e.name].slice(6)})]}),e.description&&(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.5},children:e.description})]})},e.name))})]})]}):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:o("desktop.loading")})})})}function lp(e){return null==e?"—":ss(e)}function lu({sessionId:e,cwd:t}){let{t:o}=(0,E.s)(),[s,i]=(0,n.useState)(null),[a,l]=(0,n.useState)(null),[d,c]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let t=!1;return e?(fetch(`/api/agent/${encodeURIComponent(e)}`).then(e=>e.ok?e.json():null).then(e=>{t||i(e?.state?.contextUsage??null)}).catch(()=>{}),()=>{t=!0}):void i(null)},[e]);let p=(0,n.useCallback)(async()=>{c(!0);try{let e=await fetch("/api/usage");e.ok&&l(await e.json())}catch{}finally{c(!1)}},[]);(0,n.useEffect)(()=>{p()},[p]);let u=(0,n.useMemo)(()=>a?.daily.slice(-14)??[],[a]),g=(0,n.useMemo)(()=>u.reduce((e,t)=>Math.max(e,t.tokens),0),[u]);return(0,r.jsxs)("div",{style:{flex:1,overflow:"auto",minWidth:0,padding:"16px 20px",display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsx)("h3",{style:{margin:0,fontSize:15,fontWeight:600,color:"var(--text)"},children:o("desktop.usage")}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:o("desktop.usageSession")}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12,borderRadius:12,border:"1px solid var(--border)",padding:16},children:s?(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:16},children:[(0,r.jsxs)("svg",{width:72,height:72,viewBox:"0 0 72 72",style:{flexShrink:0},children:[(0,r.jsx)("circle",{cx:36,cy:36,r:30,fill:"none",stroke:"var(--border)",strokeWidth:7}),(0,r.jsx)("circle",{cx:36,cy:36,r:30,fill:"none",stroke:"var(--accent)",strokeWidth:7,strokeLinecap:"round",strokeDasharray:2*Math.PI*30,strokeDashoffset:2*Math.PI*30*(1-Math.min(1,(s.percent??0)/100)),transform:"rotate(-90 36 36)",style:{transition:"stroke-dashoffset 0.4s ease"}}),(0,r.jsx)("text",{x:36,y:41,textAnchor:"middle",fontSize:15,fontWeight:700,fill:"var(--text)",children:null!=s.percent?`${s.percent.toFixed(0)}%`:"?"})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:[(0,r.jsx)("span",{style:{fontSize:13,color:"var(--text)"},children:o("desktop.usageContext",{used:lp(s.tokens),window:lp(s.contextWindow)})}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:o("desktop.usageContextHint")})]})]})}):(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:o("desktop.usageNoSessionData")})}):(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:o("desktop.usageNoSession")}),t&&(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:o("desktop.usageGlobal")}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))",gap:10},children:[{label:o("desktop.usageTotal"),value:lp(a?.totalTokens),sub:a?`${a.totalSessions} ${o("desktop.usageSessions")}`:"…"},{label:o("desktop.usageMessages"),value:a?String(a.messageCount):"…",sub:o("desktop.usageMessagesHint")}].map(e=>(0,r.jsxs)("div",{style:{borderRadius:12,border:"1px solid var(--border)",padding:"12px 14px",background:"var(--bg-panel)"},children:[(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",marginBottom:4},children:e.label}),(0,r.jsx)("div",{style:{fontSize:18,fontWeight:700,color:"var(--text)"},children:e.value}),(0,r.jsx)("div",{style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2},children:e.sub})]},e.label))}),(0,r.jsxs)("div",{style:{borderRadius:12,border:"1px solid var(--border)",padding:"14px 16px"},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",marginBottom:10},children:o("desktop.usageDaily")}),0===u.length?(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:o(d?"desktop.featuresLoading":"desktop.usageNoData")}):(0,r.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:6,height:96,overflowX:"auto"},children:u.map(e=>{let t=g>0?Math.max(4,Math.round(e.tokens/g*72)):4;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:4,flexShrink:0},children:[(0,r.jsx)("div",{style:{fontSize:9,color:"var(--text-dim)"},children:e.tokens>0?lp(e.tokens):""}),(0,r.jsx)("div",{style:{width:8,height:t,borderRadius:4,background:e.tokens>0?"var(--accent)":"var(--bg-hover)",opacity:e.tokens>0?.85:1},title:`${e.day}: ${lp(e.tokens)}`}),(0,r.jsx)("div",{style:{fontSize:9,color:"var(--text-dim)"},children:e.day.slice(5)})]},e.day)})})]}),(0,r.jsxs)("div",{style:{borderRadius:12,border:"1px solid var(--border)",overflow:"hidden"},children:[(0,r.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",padding:"10px 14px",borderBottom:"1px solid var(--border)"},children:o("desktop.usageTopSessions")}),a&&0===a.sessions.length?(0,r.jsx)("div",{style:{padding:"14px",fontSize:12,color:"var(--text-muted)"},children:o("desktop.usageNoData")}):(a?.sessions??[]).slice(0,12).map(e=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",borderBottom:"1px solid var(--border)"},children:[(0,r.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name??e.firstMessage??e.id}),(0,r.jsx)("span",{style:{flexShrink:0,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:lp(e.tokens)})]},e.path))]})]})]})]})}let lg=[{id:"display",labelKey:"desktop.display",Icon:ix.V},{id:"chat",labelKey:"desktop.chat",Icon:im.W},{id:"models",labelKey:"desktop.models",Icon:C.f},{id:"skills",labelKey:"desktop.skills",Icon:T.B},{id:"plugins",labelKey:"desktop.plugins",Icon:z.F},{id:"opencode-zen",labelKey:"desktop.opencodeZen",Icon:C.f},{id:"proxy",labelKey:"desktop.proxy",Icon:ik.l},{id:"features",labelKey:"desktop.features",Icon:p.l},{id:"logs",labelKey:"desktop.logs",Icon:k.B},{id:"snippets",labelKey:"desktop.snippets",Icon:rw.c},{id:"usage",labelKey:"desktop.usage",Icon:iv._},{id:"mcp",labelKey:"desktop.mcp",Icon:iy.b},{id:"subagents",labelKey:"desktop.subagents",Icon:ib.d},{id:"backup",labelKey:"desktop.backup",Icon:om.W},{id:"import",labelKey:"desktop.importSessions",Icon:R.z}];function lh({initialTab:e="models",cwd:t,sessionId:o,onCloseAction:s,onModelsSavedAction:i,onSessionReloadedAction:a,onSessionsChanged:l}){let d=rY(),{t:p}=(0,E.s)(),[u,g]=(0,n.useState)("skills"===e||"plugins"===e?t?e:"display":e),[h,x]=(0,n.useState)(!1),[f,m]=(0,n.useState)(null),k=(0,n.useRef)(new Set),v=(0,n.useCallback)(e=>(k.current.add(e),()=>{k.current.delete(e)}),[]),y=(0,n.useCallback)(async()=>{if(!h){x(!0),m(null);try{let e=(await Promise.allSettled([...k.current].map(e=>e()))).find(e=>"rejected"===e.status);if(e)throw e.reason;s()}catch(e){m(e instanceof Error?e.message:String(e))}finally{x(!1)}}},[h,s]);return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&y()},children:(0,r.jsxs)("section",{role:"dialog","aria-modal":"true","aria-label":p("desktop.settings"),className:"settings-modal",style:{width:d?"calc(100vw - 16px)":1e3,maxWidth:"calc(100vw - 16px)",height:d?"calc(100dvh - 16px)":"80vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,r.jsxs)("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0},children:[(0,r.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:p("desktop.settings")}),"models"===u?(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"}):t&&(0,r.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]}),(0,r.jsx)("button",{type:"button",onClick:()=>{y()},disabled:h,title:p("desktop.closeSettings"),"aria-label":p("desktop.closeSettings"),style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:18,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:d?"column":"row",minHeight:0,overflow:"hidden",pointerEvents:h?"none":void 0},children:[(0,r.jsx)("nav",{"aria-label":p("desktop.settingsSections"),style:{display:"flex",flexDirection:d?"row":"column",gap:4,width:d?"100%":150,padding:8,flexShrink:0,minWidth:0,background:"var(--bg-panel)",borderRight:d?"none":"1px solid var(--border)",borderBottom:d?"1px solid var(--border)":"none",overflowX:d?"auto":void 0,overflowY:d?"hidden":void 0,WebkitOverflowScrolling:d?"touch":void 0},children:lg.filter(({id:e})=>!(d&&"import"===e)).map(({id:e,labelKey:o,Icon:n})=>{let s=("skills"===e||"plugins"===e)&&!t,i=u===e;return(0,r.jsxs)("button",{type:"button",disabled:s,onClick:()=>g(e),"aria-current":i?"page":void 0,style:{display:"flex",alignItems:"center",gap:8,flex:d?"0 0 auto":void 0,whiteSpace:"nowrap",width:d?void 0:"100%",padding:"8px 10px",border:"none",borderRadius:6,background:i?"var(--bg-selected)":"none",color:i?"var(--text)":"var(--text-muted)",cursor:s?"not-allowed":"pointer",opacity:s?.4:1,fontSize:12,fontWeight:i?600:400,textAlign:"left",transition:"background 0.12s, color 0.12s"},title:p(o),"aria-label":p(o),onMouseEnter:e=>{i||s||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)")},children:[(0,r.jsx)(n,{size:16,"aria-hidden":"true"}),!d&&(0,r.jsx)("span",{children:p(o)})]},e)})}),(0,r.jsx)("div",{style:{display:"display"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(iV,{})}),(0,r.jsx)("div",{style:{display:"chat"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(iP,{})}),(0,r.jsx)("div",{style:{display:"models"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(aW,{embedded:!0,sessionId:o,onSavedAction:i,onRegisterFlush:v})}),t&&(0,r.jsx)("div",{style:{display:"skills"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(a8,{cwd:t,embedded:!0,sessionId:o})}),t&&(0,r.jsx)("div",{style:{display:"plugins"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(aY,{cwd:t,sessionId:o,embedded:!0,onReloadedAction:a})}),(0,r.jsx)("div",{style:{display:"opencode-zen"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(ln,{onRegisterFlush:v})}),(0,r.jsx)("div",{style:{display:"proxy"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(aX,{})}),(0,r.jsx)("div",{style:{display:"features"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(i2,{})}),(0,r.jsx)("div",{style:{display:"logs"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(a7,{})}),(0,r.jsx)("div",{style:{display:"snippets"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(lt,{})}),(0,r.jsx)("div",{style:{display:"usage"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(lu,{sessionId:o,cwd:t})}),(0,r.jsx)("div",{style:{display:"mcp"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(ac,{sessionId:o})}),(0,r.jsx)("div",{style:{display:"subagents"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(lc,{cwd:t,sessionId:o})}),(0,r.jsx)("div",{style:{display:"backup"===u?"flex":"none",flex:1,minWidth:0,minHeight:0},children:(0,r.jsx)(iC,{cwd:t})}),(0,r.jsx)("div",{style:{display:"import"===u?"flex":"none",flex:1,minWidth:0,minHeight:0,overflowY:"auto"},children:(0,r.jsx)(i5,{onSessionsChanged:l})})]}),f&&(0,r.jsx)("div",{style:{padding:"6px 18px",borderTop:"1px solid var(--border)",color:"#f87171",fontSize:11},children:f})]})})}let lx=new Set(["awaiting_input","review","failed"]),lf=(0,n.createContext)(null);function lm(){let e=(0,n.useContext)(lf);if(!e)throw Error("useTasksView must be used within TasksViewProvider");return e}function lk({children:e}){let{t}=(0,E.s)(),o=(0,n.useRef)(t);(0,n.useEffect)(()=>{o.current=t},[t]);let[s,i]=(0,n.useState)([]),[a,l]=(0,n.useState)([]),d=(0,n.useRef)(0),c=(0,n.useCallback)(async()=>{let e=++d.current;try{let t=await (0,rZ.Wt)(),o=(await Promise.all(t.map(e=>(0,rZ.Vk)(e).catch(()=>[])))).flat().sort((e,t)=>t.id-e.id);if(e!==d.current)return;l(e=>lv(e,t)?e:t),i(e=>lv(e,o)?e:o)}catch{}},[]);(0,n.useEffect)(()=>{c();let e=null,t=!1,o=()=>{t||((e=new EventSource("/api/tasks/events")).onmessage=()=>{c()},e.onerror=()=>{e?.close(),e=null,c(),setTimeout(o,2e3)})};o();let r=()=>{"visible"===document.visibilityState&&c()},n=()=>void c();document.addEventListener("visibilitychange",r),window.addEventListener("online",n);let s=setInterval(()=>void c(),6e4);return()=>{t=!0,e?.close(),document.removeEventListener("visibilitychange",r),window.removeEventListener("online",n),clearInterval(s)}},[c]);let p=(0,n.useMemo)(()=>s.filter(e=>lx.has(e.status)&&null==e.archivedAt).length,[s]),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{let e=u.current;if((u.current=new Map(s.map(e=>[e.id,e.status])),e&&0!==s.length)&&"Notification"in window){for(let o of s)if(e.get(o.id)!==o.status&&("review"===o.status||"failed"===o.status)&&null==o.archivedAt&&"visible"!==document.visibilityState)try{let e="review"===o.status?t("tasks.notifyReview",{title:o.title}):t("tasks.notifyFailed",{title:o.title});!function(e,t){new Promise(o=>{if(!("Notification"in window))return void o();let r=()=>{try{new Notification(e,{body:t,tag:"pi-tasks"})}catch{}o()};"granted"===Notification.permission?r():"denied"!==Notification.permission?Notification.requestPermission().then(e=>{"granted"===e?r():o()}):o()})}("Pi Web Tasks",e)}catch{}}},[s,t]);let g=(0,n.useMemo)(()=>({tasks:s,projects:a,attentionCount:p,refetch:c}),[s,a,p,c]);return(0,r.jsx)(lf.Provider,{value:g,children:e})}function lv(e,t){return JSON.stringify(e)===JSON.stringify(t)}var ly=o(4539),lb=o(12449);let lw=["todo","inProgress","attention","done"];function lj(e){return"review"===e.status&&0===e.filesChanged}function lS(){return{defaultAgentType:null,modeId:null,configValues:{},autoProcess:!0,maxConcurrent:1,mergeStrategy:"merge",deleteWorktreeDefault:!0,preflightCommand:null,initCommand:null,stagePrompts:null}}let lC=["todo","inProgress","attention","done"],lT={todo:{id:"todo",marker:"var(--text-dim)"},inProgress:{id:"inProgress",marker:"var(--accent)"},attention:{id:"attention",marker:"#f59e0b"},done:{id:"done",marker:"#10b981"}};var lz=o(54775),lR=o(98998),lI=o(36668);function lM({task:e}){let{t}=(0,E.s)(),o=t("failed"===e.status&&"interrupted"===e.failureReason?"tasks.statusInterrupted":function(e){switch(e){case"todo":return"tasks.statusTodo";case"queued":return"tasks.statusQueued";case"preparing":return"tasks.statusPreparing";case"running":return"tasks.statusRunning";case"awaiting_input":return"tasks.statusAwaitingInput";case"review":return"tasks.statusReview";case"merging":return"tasks.statusMerging";case"done":return"tasks.statusDone";case"failed":return"tasks.statusFailed";case"canceled":return"tasks.statusCanceled"}}(e.status)),n={display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:600,lineHeight:1.4,flexShrink:0,whiteSpace:"nowrap"};switch(e.status){case"queued":case"preparing":case"running":case"merging":return(0,r.jsxs)("span",{style:{...n,color:"var(--accent)"},children:[(0,r.jsx)(lz.N,{size:11,className:"pi-spin",style:{animation:"pi-spin 1s linear infinite"},"aria-hidden":"true"}),o]});case"awaiting_input":case"review":return(0,r.jsx)("span",{style:{...n,border:"1px solid rgba(245,158,11,0.45)",background:"rgba(245,158,11,0.08)",color:"#d97706"},children:o});case"done":return(0,r.jsxs)("span",{style:{...n,background:"rgba(16,185,129,0.12)",color:"#059669"},children:[(0,r.jsx)(u.J,{size:10,weight:"bold","aria-hidden":"true"}),o]});case"failed":return(0,r.jsx)("span",{style:{...n,background:"rgba(239,68,68,0.12)",color:"#dc2626"},children:o});default:return(0,r.jsx)("span",{style:{...n,background:"var(--bg-hover)",color:"var(--text-muted)"},children:o})}}function lE({task:e}){let t=e.preflight;if(!t||"review"!==e.status)return null;let o="passed"===t.status?{background:"rgba(16,185,129,0.12)",color:"#059669"}:"failed"===t.status?{background:"rgba(239,68,68,0.12)",color:"#dc2626"}:{background:"var(--bg-hover)",color:"var(--text-muted)"};return(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,padding:"1px 6px",fontSize:10,fontWeight:500,lineHeight:1.5,maxWidth:"100%",...o},title:t.command,children:["running"===t.status?(0,r.jsx)(lz.N,{size:10,style:{animation:"pi-spin 1s linear infinite"},"aria-hidden":"true"}):"passed"===t.status?(0,r.jsx)(oV.r,{size:10,"aria-hidden":"true"}):(0,r.jsx)(sd.J,{size:10,"aria-hidden":"true"}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.command})]})}function lP({task:e,folderName:t,now:o,onOpen:n,onStart:s,onCancel:i,onRetry:a,onRequeue:l,onViewSession:d,onMerge:c,onArchive:p,onEdit:g}){let{t:h}=(0,E.s)(),x=null!=e.archivedAt,f="running"===e.status||"awaiting_input"===e.status||"merging"===e.status,m=null!=e.filesChanged&&e.filesChanged>0?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontFamily:"var(--font-mono)",fontSize:10},children:[(0,r.jsxs)("span",{style:{color:"#059669"},children:["+",e.additions??0]}),(0,r.jsxs)("span",{style:{color:"#dc2626"},children:["-",e.deletions??0]})]}):null,k=function(e,t){if(!e)return"";let o=new Date(e).getTime();if(Number.isNaN(o))return"";let r=Math.floor(Math.max(0,t-o)/6e4);if(r<1)return"now";if(r<60)return`${r}m`;let n=Math.floor(r/60);if(n<24)return`${n}h`;let s=Math.floor(n/24);return`${s}d`}(e.finishedAt??e.settledAt??e.startedAt??e.createdAt,o),{primary:v,more:y}=(()=>{let t=[],o=null;if(x)return{primary:o={icon:sp.T,label:h("tasks.actionUnarchive"),onClick:p},more:t};switch(e.status){case"todo":o={icon:lo.j,label:h("tasks.actionStart"),onClick:s},t.push({icon:rj.S,label:h("tasks.actionEdit"),onClick:g});break;case"queued":case"preparing":case"running":case"awaiting_input":o={icon:lR.k,label:h("tasks.actionCancel"),onClick:i};break;case"review":o=lj(e)?{icon:u.J,label:h("tasks.actionComplete"),onClick:c}:{icon:lI.r,label:h("tasks.actionMerge"),onClick:c};break;case"merging":break;case"failed":o={icon:w.S,label:h("tasks.actionRetry"),onClick:a},t.push({icon:rj.S,label:h("tasks.actionEdit"),onClick:g}),t.push({icon:sp.T,label:h("tasks.actionArchive"),onClick:p});break;case"done":o={icon:sp.T,label:h("tasks.actionArchive"),onClick:p};break;case"canceled":o={icon:oK.f,label:h("tasks.actionRequeue"),onClick:l},t.push({icon:sp.T,label:h("tasks.actionArchive"),onClick:p})}return{primary:o,more:t}})(),b=[...y];return null!=e.conversationId&&b.push({icon:oq.y,label:h("tasks.actionViewSession"),onClick:d}),(0,r.jsxs)("div",{role:"button",tabIndex:0,onClick:n,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),n())},style:{display:"flex",flexDirection:"column",cursor:"pointer",borderRadius:12,border:"1px solid color-mix(in srgb, var(--border) 85%, transparent)",background:"var(--bg-panel)",padding:12,textAlign:"left",transition:"border-color 0.12s",opacity:x?.6:1,boxShadow:"0 1px 2px rgba(0,0,0,0.04)"},className:"task-card-hover",onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="color-mix(in srgb, var(--border) 85%, transparent)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[(0,r.jsx)("span",{style:{minWidth:0,overflowWrap:"break-word",fontSize:13,fontWeight:500,lineHeight:1.4},children:e.title}),(0,r.jsx)(lM,{task:e})]}),(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"2px 6px",marginTop:6,fontSize:11,color:"var(--text-muted)"},children:[t?(0,r.jsx)("span",{style:{maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}):null,t&&e.workBranch?(0,r.jsx)("span",{style:{opacity:.5},children:"/"}):null,e.workBranch?(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:180},children:e.workBranch}):null,(t||e.workBranch)&&(m||k)?(0,r.jsx)("span",{style:{opacity:.5},children:"\xb7"}):null,m,m&&k?(0,r.jsx)("span",{style:{opacity:.5},children:"\xb7"}):null,k?(0,r.jsx)("span",{style:{flexShrink:0},children:k}):null,(0,r.jsx)(lE,{task:e})]}),e.lastError&&("failed"===e.status||"review"===e.status)?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:8,borderRadius:8,background:"rgba(239,68,68,0.08)",padding:"6px 8px",fontSize:11,color:"#dc2626"},children:[(0,r.jsx)(ok.t,{size:13,style:{flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{minWidth:0,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.lastError}),(0,r.jsx)("button",{type:"button",style:{flexShrink:0,fontWeight:600,background:"none",border:"none",cursor:"pointer",color:"inherit",fontSize:11,textDecoration:"underline"},onClick:e=>{e.stopPropagation(),n()},children:h("tasks.errorView")})]}):null,"review"===e.status&&e.resultSummary?(0,r.jsx)("p",{style:{margin:"6px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:11,lineHeight:1.5,color:"var(--text-muted)"},children:e.resultSummary}):null,f&&e.latestProgress?(0,r.jsx)("p",{style:{margin:"6px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:11,lineHeight:1.5,color:"var(--text-muted)",fontStyle:"italic"},children:e.latestProgress}):null,v||b.length>0?(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:12,paddingTop:12,borderTop:"1px solid var(--border)"},children:[v?(0,r.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),v.onClick()},style:{display:"inline-flex",alignItems:"center",gap:5,padding:"4px 10px",borderRadius:7,background:"var(--accent)",color:"#fff",border:"none",cursor:"pointer",fontSize:11,fontWeight:600},children:[(0,r.jsx)(v.icon,{size:12,weight:"bold","aria-hidden":"true"}),v.label]}):null,(0,r.jsx)("div",{style:{flex:1}}),b.map(e=>(0,r.jsx)("button",{type:"button",title:e.label,"aria-label":e.label,onClick:t=>{t.stopPropagation(),e.onClick()},style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,borderRadius:999,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",opacity:0,transition:"opacity 0.12s, background 0.12s, color 0.12s"},className:"task-card-secondary",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(e.icon,{size:13,"aria-hidden":"true"})},e.label))]}):null]})}function lD({open:e,onOpenChange:t,task:o}){let{t:s}=(0,E.s)(),{refetch:i}=lm(),[a,l]=(0,n.useState)(""),[d,p]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{e&&(l(""),p(!1))},[e,o]),!e||!o)return null;let u=async()=>{if(!d){p(!0);try{await (0,rZ.oQ)(o.id,o.projectRoot,"cancel",{reason:a.trim()||null}),t(!1),i()}catch(e){console.error("cancel failed",e)}finally{p(!1)}}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.cancelTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:s("tasks.cancelDescription")}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:s("tasks.cancelReasonLabel")}),(0,r.jsx)("textarea",{value:a,onChange:e=>l(e.target.value),placeholder:s("tasks.cancelReasonPlaceholder"),rows:3,autoFocus:!0,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:d,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("tasks.cancelKeep")}),(0,r.jsx)("button",{type:"button",onClick:()=>void u(),disabled:d,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("tasks.cancelSubmit")})]})]})]})})}function l$({open:e,onOpenChange:t,task:o}){let{t:s}=(0,E.s)(),{refetch:i}=lm(),[a,l]=(0,n.useState)(!0),[d,p]=(0,n.useState)(!1),u=o?.worktreePath!=null;if((0,n.useEffect)(()=>{if(!e||!o)return;p(!1);let t=!1;return(0,rZ.CG)(o.projectRoot).then(e=>{t||l(e.deleteWorktreeDefault)}).catch(()=>{t||l(!0)}),()=>{t=!0}},[e,o]),!e||!o)return null;let g=async()=>{if(!d){p(!0);try{await (0,rZ.ZX)(o.id,o.projectRoot,u&&a),t(!1),i()}catch(e){console.error("complete failed",e)}finally{p(!1)}}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.completeTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:s("tasks.completeDescription")}),u?(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:a,onChange:e=>l(e.target.checked),style:{accentColor:"var(--accent)"}}),s("tasks.completeDeleteWorktree")]}):null,(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:d,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void g(),disabled:d,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("tasks.completeSubmit")})]})]})]})})}var lF=o(51285),lW=o(16894);function lN({open:e,onOpenChange:t,task:o,onViewSession:s,onMerge:i,onEdit:a,onCancel:l,onRetry:d,onRequeue:p,onComplete:g}){let{t:h}=(0,E.s)(),{refetch:x}=lm(),[m,k]=(0,n.useState)([]),[v,y]=(0,n.useState)([]),[b,S]=(0,n.useState)(null),[C,T]=(0,n.useState)(null),[z,R]=(0,n.useState)(!1),[I,M]=(0,n.useState)(!1),[P,D]=(0,n.useState)(""),[$,F]=(0,n.useState)(!1),[W,N]=(0,n.useState)(!1),[A,L]=(0,n.useState)(!1),O=o?.id??null,H=o?.projectRoot??null,B=(0,n.useCallback)(async()=>{if(null==O||null==H)return;let[e,t]=await Promise.all([(0,rZ.HB)(H,O).catch(()=>[]),o?.worktreePath?(0,rZ.JH)(H,O).then(e=>e.files).catch(()=>[]):Promise.resolve([])]);k(e),y(t)},[O,H,o?.worktreePath]);(0,n.useEffect)(()=>{if(!e||null==O)return;k([]),y([]),M(!1),D(""),B();let t=window.setInterval(()=>void B(),5e3);return()=>window.clearInterval(t)},[e,O,B]);let U=(0,n.useCallback)(async e=>{L(!0);try{await e()}catch(e){console.error("detail action failed",e)}finally{L(!1),x()}},[x]),_=(0,n.useCallback)(async e=>{if(null!=H&&null!=O){R(!0);try{let t=await (0,rZ.h)(H,O,e);T(t.supported&&t.patch?t.patch:null)}catch{T(null)}finally{R(!1)}}},[H,O]),q=async()=>{null!=o&&null!=H&&(await U(()=>(0,rZ.bH)(o.id,H,W)),t(!1))},V=async()=>{null!=o&&null!=H&&P.trim()&&(await U(()=>(0,rZ.in)(o.id,H,P.trim())),M(!1),D(""))};if(!e||null==o||null==H)return null;let K=[];if(null==o.archivedAt)switch(o.status){case"todo":K.push({label:h("tasks.actionStart"),icon:lo.j,onClick:()=>void U(()=>(0,rZ.oQ)(o.id,H,"start")),filled:!0}),K.push({label:h("tasks.actionEdit"),icon:rj.S,onClick:()=>a(o)});break;case"queued":case"preparing":case"running":case"awaiting_input":K.push({label:h("tasks.actionCancel"),icon:lR.k,onClick:()=>l(o),danger:!0});break;case"review":K.push({label:lj(o)?h("tasks.actionComplete"):h("tasks.actionMerge"),icon:lj(o)?u.J:lF.Y,onClick:()=>lj(o)?g(o):i(o),filled:!0}),K.push({label:h("tasks.actionReturn"),icon:oK.f,onClick:()=>M(!0)});break;case"failed":K.push({label:h("tasks.actionRetry"),icon:w.S,onClick:()=>d(o),filled:!0}),K.push({label:h("tasks.actionEdit"),icon:rj.S,onClick:()=>a(o)});break;case"done":K.push({label:h("tasks.actionArchive"),icon:sp.T,onClick:()=>void U(()=>(0,rZ.et)(o.id,H,!0))});break;case"canceled":K.push({label:h("tasks.actionRequeue"),icon:oK.f,onClick:()=>p(o),filled:!0})}else K.push({label:h("tasks.actionUnarchive"),icon:sp.T,onClick:()=>void U(()=>(0,rZ.et)(o.id,H,!1))});return null!=o.conversationId&&K.push({label:h("tasks.actionViewSession"),icon:oq.y,onClick:()=>s(o)}),(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:800,background:"rgba(0,0,0,0.35)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{position:"absolute",top:0,right:0,bottom:0,width:"min(480px, 90vw)",background:"var(--bg-panel)",borderLeft:"1px solid var(--border)",display:"flex",flexDirection:"column",boxShadow:"-8px 0 32px rgba(0,0,0,0.2)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,padding:"16px 16px 0"},children:[(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("h3",{style:{margin:0,fontSize:15,fontWeight:600,lineHeight:1.4,overflowWrap:"break-word"},children:o.title}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:6},children:[(0,r.jsx)(lM,{task:o}),o.workBranch?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-muted)"},children:[(0,r.jsx)(f.Z,{size:12,"aria-hidden":"true"}),o.workBranch]}):null]})]}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":h("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex",flexShrink:0},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:8,padding:"14px 16px 0"},children:K.map(e=>{let t,o;return(0,r.jsxs)("button",{type:"button",onClick:e.onClick,disabled:A,style:(t=e.filled,o=e.danger,{display:"inline-flex",alignItems:"center",gap:5,padding:"7px 12px",borderRadius:8,fontSize:12,fontWeight:600,cursor:"pointer",background:t?"var(--accent)":o?"rgba(239,68,68,0.1)":"var(--bg-hover)",color:t?"#fff":o?"#dc2626":"var(--text)",border:t||o?"none":"1px solid var(--border)"}),children:[(0,r.jsx)(e.icon,{size:13,weight:"bold","aria-hidden":"true"}),e.label]},e.label)})}),I&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"12px 16px 0"},children:[(0,r.jsx)("textarea",{value:P,onChange:e=>D(e.target.value),placeholder:h("tasks.returnPlaceholder"),rows:3,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12,resize:"vertical",fontFamily:"inherit"}}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[(0,r.jsx)("button",{type:"button",onClick:()=>M(!1),style:{padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:h("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void V(),disabled:!P.trim(),style:{padding:"6px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:h("tasks.returnSubmit")})]})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"14px 16px 0",fontSize:12,color:"var(--text-muted)"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:h("tasks.metaProject")}),(0,r.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11},children:o.projectRoot})]}),o.createdAt?(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:h("tasks.metaCreated")}),(0,r.jsx)("span",{children:new Date(o.createdAt).toLocaleString()})]}):null,o.mergeCommit?(0,r.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,r.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:h("tasks.metaCommit")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11},children:o.mergeCommit})]}):null]}),v.length>0&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"14px 16px 0"},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:h("tasks.changedFiles")}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2,maxHeight:140,overflowY:"auto"},children:v.map(e=>(0,r.jsxs)("button",{type:"button",onClick:()=>{var t;S(t=e.file),T(null),_(t)},style:{display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"4px 6px",borderRadius:6,background:"none",border:"none",color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,r.jsx)(lW.o,{size:13,style:{flexShrink:0,color:"var(--text-muted)"},"aria-hidden":"true"}),(0,r.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11},children:e.file}),(0,r.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"#059669",flexShrink:0},children:["+",e.additions]}),(0,r.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"#dc2626",flexShrink:0},children:["-",e.deletions]})]},e.file))})]}),null!=b&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"12px 16px 0",minHeight:0,flexShrink:0},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)"},children:h("tasks.diff")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:b}),(0,r.jsx)("button",{type:"button",onClick:()=>S(null),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,r.jsx)(c.X,{size:12,"aria-hidden":"true"})})]}),z?(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",padding:8},children:h("tasks.loading")}):C?(0,r.jsx)("pre",{style:{margin:0,maxHeight:200,overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10,fontSize:11,lineHeight:1.5,fontFamily:"var(--font-mono)",color:"var(--text-muted)",whiteSpace:"pre"},children:C.split("\n").map((e,t)=>{let o;return e.startsWith("+")&&!e.startsWith("+++")?o="#059669":e.startsWith("-")&&!e.startsWith("---")?o="#dc2626":e.startsWith("@@")&&(o="var(--accent)"),(0,r.jsx)("div",{style:{color:o},children:e||" "},t)})}):(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",padding:8},children:h("tasks.noDiff")})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"14px 16px 0",flex:1,minHeight:0},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:h("tasks.timeline")}),(0,r.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",paddingBottom:8},children:0===m.length?(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:8},children:h("tasks.noEvents")}):(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[...m].reverse().map(e=>{var t;let o,n;return(0,r.jsxs)("div",{style:{display:"flex",gap:8,padding:"4px 6px",borderRadius:6,fontSize:11},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0,fontFamily:"var(--font-mono)",fontSize:10,paddingTop:1},children:new Date(e.createdAt).toLocaleTimeString()}),(0,r.jsx)("span",{style:{color:"var(--text)",flexShrink:0,fontWeight:500},children:(t=e.kind,(n=h(o=`tasks.event_${t}`))===o?t:n)}),e.payload?.feedback?(0,r.jsx)("span",{style:{color:"var(--text-muted)",fontStyle:"italic",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:String(e.payload.feedback)}):null]},e.id)})})})]}),(0,r.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:$?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:W,onChange:e=>N(e.target.checked),style:{accentColor:"var(--accent)"}}),h("tasks.deleteWorktree")]}),(0,r.jsx)("button",{type:"button",onClick:()=>F(!1),style:{padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:h("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void q(),disabled:A,style:{padding:"6px 14px",borderRadius:8,background:"#dc2626",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:h("tasks.deleteConfirm")})]}):(0,r.jsxs)("button",{type:"button",onClick:()=>F(!0),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"#dc2626",fontSize:12,cursor:"pointer"},children:[(0,r.jsx)(j.l,{size:13,"aria-hidden":"true"}),h("tasks.delete")]})})]})})}var lA=o(17757);function lL({open:e,onOpenChange:t,task:o,defaultProject:s,projects:i,prefillTitle:a,prefillPrompt:l,onSubmit:d}){let{t:p}=(0,E.s)(),[u,g]=(0,n.useState)(""),[h,x]=(0,n.useState)(""),[f,m]=(0,n.useState)(""),[k,v]=(0,n.useState)([]),[y,b]=(0,n.useState)(""),[w,S]=(0,n.useState)(!1),C=(0,n.useRef)(!1);if((0,n.useEffect)(()=>{if(!e){C.current=!1;return}C.current||(C.current=!0,g(o?.projectRoot??s??i[0]??""),x(o?.title??a??""),m(o?.config?.prompt??l??""),(0,rZ.VB)().then(v).catch(()=>void 0))},[e,o,s,i,a,l]),!e)return null;let T=async()=>{if(u&&h.trim()&&!w){S(!0);try{await d(u,h.trim(),{prompt:f.trim(),agentType:o?.config?.agentType??null,modelId:o?.config?.modelId??null,thinkingLevel:o?.config?.thinkingLevel??null}),t(!1)}catch(e){console.error("submit task failed",e)}finally{S(!1)}}},z=async()=>{if(y.trim()&&h.trim())try{await (0,rZ.nY)({name:y.trim(),title:h.trim(),config:{prompt:f.trim()}}),b(""),(0,rZ.VB)().then(v).catch(()=>void 0)}catch(e){console.error("save template failed",e)}},R=async e=>{try{await (0,rZ.B_)(e),(0,rZ.VB)().then(v).catch(()=>void 0)}catch(e){console.error("delete template failed",e)}},I={width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none"};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:900,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",maxHeight:"80vh",overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:o?p("tasks.editTitle"):p("tasks.newTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":p("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[k.length>0&&(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:p("tasks.templates")}),(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:k.map(e=>(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,background:"var(--bg-hover)",padding:"3px 8px",fontSize:11},children:[(0,r.jsx)("button",{type:"button",onClick:()=>{x(e.title),m(e.config?.prompt??"")},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text)",fontSize:11,padding:0},children:e.name}),(0,r.jsx)("button",{type:"button",onClick:()=>void R(e.id),"aria-label":p("tasks.deleteTemplate"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)",padding:0,display:"flex"},children:(0,r.jsx)(j.l,{size:10,"aria-hidden":"true"})})]},e.id))})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:p("tasks.fieldProject")}),(0,r.jsx)("select",{value:u,onChange:e=>g(e.target.value),style:I,children:i.map(e=>(0,r.jsx)("option",{value:e,children:e.split("/").filter(Boolean).pop()??e},e))})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:p("tasks.fieldTitle")}),(0,r.jsx)("input",{value:h,onChange:e=>x(e.target.value),placeholder:p("tasks.fieldTitlePlaceholder"),style:I,autoFocus:!0})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:p("tasks.fieldPrompt")}),(0,r.jsx)("textarea",{value:f,onChange:e=>m(e.target.value),placeholder:p("tasks.fieldPromptPlaceholder"),rows:6,style:{...I,resize:"vertical",fontFamily:"inherit",lineHeight:1.5}})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,r.jsx)("input",{value:y,onChange:e=>b(e.target.value),placeholder:p("tasks.templateNamePlaceholder"),style:{...I,flex:1}}),(0,r.jsxs)("button",{type:"button",onClick:()=>void z(),disabled:!y.trim()||!h.trim(),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"8px 12px",borderRadius:8,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,r.jsx)(lA.D,{size:13,"aria-hidden":"true"}),p("tasks.saveAsTemplate")]})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:p("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void T(),disabled:!u||!h.trim()||w,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:p("tasks.save")})]})]})]})})}function lO({open:e,onOpenChange:t,task:o}){let{t:s}=(0,E.s)(),{refetch:i}=lm(),[a,l]=(0,n.useState)(!0),[d,p]=(0,n.useState)(""),[u,g]=(0,n.useState)(!0),[h,x]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{e&&o&&(l(!0),p(o.title),x(!1),(0,rZ.CG)(o.projectRoot).then(e=>g(e.deleteWorktreeDefault)).catch(()=>g(!0)))},[e,o]),!e||!o)return null;let f=async()=>{if((a||d.trim())&&!h){x(!0);try{await (0,rZ.oB)(o.id,o.projectRoot,a?null:d.trim(),u),t(!1),i()}catch(e){console.error("merge failed",e)}finally{x(!1)}}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.mergeTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"radio",checked:a,onChange:()=>l(!0),style:{accentColor:"var(--accent)"}}),s("tasks.mergeAutoMessage")]}),(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"radio",checked:!a,onChange:()=>l(!1),style:{accentColor:"var(--accent)"}}),s("tasks.mergeManualMessage")]}),!a&&(0,r.jsx)("input",{value:d,onChange:e=>p(e.target.value),placeholder:s("tasks.mergeMessagePlaceholder"),style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit"}}),(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:u,onChange:e=>g(e.target.checked),style:{accentColor:"var(--accent)"}}),s("tasks.mergeDeleteWorktree")]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void f(),disabled:!a&&!d.trim()||h,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("tasks.mergeConfirm")})]})]})]})})}function lH({open:e,onOpenChange:t,task:o,kind:s}){let{t:i}=(0,E.s)(),{refetch:a}=lm(),[l,d]=(0,n.useState)(""),[p,u]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{e&&(d(""),u(!1))},[e,o]),!e||!o)return null;let g="retry"===s,h=async()=>{if(!p){u(!0);try{await (0,rZ.oQ)(o.id,o.projectRoot,s,{note:l.trim()||null}),t(!1),a()}catch(e){console.error("restart failed",e)}finally{u(!1)}}};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(480px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i(g?"tasks.restartTitleRetry":"tasks.restartTitleRequeue")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,r.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:i("tasks.restartDescription")}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,r.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:i("tasks.actionAddNote")}),(0,r.jsx)("textarea",{value:l,onChange:e=>d(e.target.value),placeholder:i(g?"tasks.followUpPlaceholderRetry":"tasks.followUpPlaceholderRequeue"),rows:3,autoFocus:!0,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:p,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void h(),disabled:p,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i(g?"tasks.actionRetry":"tasks.actionRequeue")})]})]})]})})}let lB=["work","retry","return","merge"];function lU({open:e,onOpenChange:t,projectRoot:o}){let{t:s}=(0,E.s)(),{projects:i}=lm(),[a,l]=(0,n.useState)(""),[d,p]=(0,n.useState)(()=>lS()),[u,g]=(0,n.useState)(!1),[h,x]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{if(!e)return;let t=o??i[0]??"";l(t),t&&(0,rZ.Pf)(t).then(e=>{g(null!=e),p(e??lS())}).catch(()=>{g(!1),p(lS())})},[e,o,i]),!e)return null;let f=(e,t)=>{p(o=>({...o,[e]:t}))},m=async()=>{if(a&&!h){x(!0);try{await (0,rZ.eA)(a,d),g(!0),t(!1)}catch(e){console.error("save settings failed",e)}finally{x(!1)}}},k=async()=>{if(a)try{await (0,rZ.E)(a),g(!1),p(lS())}catch(e){console.error("reset settings failed",e)}},v={width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"7px 10px",color:"var(--text)",fontSize:12,outline:"none",fontFamily:"inherit"},y={display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 0",borderBottom:"1px solid var(--border)"};return(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:960,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(560px, calc(100vw - 48px))",maxHeight:"82vh",overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.settingsTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"14px 16px 16px"},children:[(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500},children:s("tasks.settingsProject")}),(0,r.jsx)("select",{value:a,onChange:e=>l(e.target.value),style:v,children:i.map(e=>(0,r.jsx)("option",{value:e,children:e.split("/").filter(Boolean).pop()??e},e))})]}),a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:y,children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsAutoProcess")}),(0,r.jsx)("input",{type:"checkbox",checked:d.autoProcess,onChange:e=>f("autoProcess",e.target.checked),style:{accentColor:"var(--accent)"}})]}),(0,r.jsxs)("div",{style:y,children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsMaxConcurrent")}),(0,r.jsx)("input",{type:"number",min:0,value:d.maxConcurrent,onChange:e=>f("maxConcurrent",Math.max(0,Number(e.target.value)||0)),style:{...v,width:90}})]}),(0,r.jsxs)("div",{style:y,children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsMergeStrategy")}),(0,r.jsxs)("select",{value:d.mergeStrategy,onChange:e=>f("mergeStrategy",e.target.value),style:{...v,width:140},children:[(0,r.jsx)("option",{value:"merge",children:s("tasks.mergeStrategyMerge")}),(0,r.jsx)("option",{value:"squash",children:s("tasks.mergeStrategySquash")})]})]}),(0,r.jsxs)("div",{style:y,children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsDeleteWorktree")}),(0,r.jsx)("input",{type:"checkbox",checked:d.deleteWorktreeDefault,onChange:e=>f("deleteWorktreeDefault",e.target.checked),style:{accentColor:"var(--accent)"}})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsPreflightCommand")}),(0,r.jsx)("input",{value:d.preflightCommand??"",onChange:e=>f("preflightCommand",e.target.value||null),placeholder:s("tasks.settingsPreflightPlaceholder"),style:{...v,fontFamily:"var(--font-mono)",fontSize:11}})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:12},children:s("tasks.settingsInitCommand")}),(0,r.jsx)("input",{value:d.initCommand??"",onChange:e=>f("initCommand",e.target.value||null),placeholder:s("tasks.settingsInitPlaceholder"),style:{...v,fontFamily:"var(--font-mono)",fontSize:11}})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,paddingTop:4},children:[(0,r.jsx)("span",{style:{fontSize:12,fontWeight:500},children:s("tasks.settingsStagePrompts")}),lB.map(e=>(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:s(`tasks.stage.${e}`)}),(0,r.jsx)("input",{value:d.stagePrompts?.[e]??"",onChange:t=>f("stagePrompts",{...d.stagePrompts??{},[e]:t.target.value}),style:{...v,fontSize:11}})]},e))]}),u&&(0,r.jsx)("button",{type:"button",onClick:()=>void k(),style:{alignSelf:"flex-start",padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",fontSize:12,cursor:"pointer"},children:s("tasks.settingsReset")})]}):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",padding:8},children:s("tasks.settingsNoProject")}),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("i18n.cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>void m(),disabled:!a||h,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("tasks.save")})]})]})]})})}function l_({open:e,onOpenChange:t,task:o}){let{t:s}=(0,E.s)();return((0,n.useEffect)(()=>{if(!e)return},[e,o]),e&&o)?(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:970,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},onMouseDown:e=>{e.target===e.currentTarget&&t(!1)},children:(0,r.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,r.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s("tasks.sessionTitle")}),(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,r.jsx)(c.X,{size:16,"aria-hidden":"true"})})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"14px 16px 16px",fontSize:12},children:[(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10},children:[(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:s("tasks.sessionId")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:o.conversationId??"—"})]}),o.sessionFile?(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10},children:[(0,r.jsx)("span",{style:{color:"var(--text-muted)"},children:s("tasks.sessionFile")}),(0,r.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:o.sessionFile})]}):null,(0,r.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6},children:s("tasks.sessionHint")}),(0,r.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:4},children:(0,r.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s("i18n.close")})})]})]})}):null}let lq="__all__",lV="pi-tasks-board-filter",lK={showCanceled:!1,showArchived:!1},lJ="pi:open-task-settings";function lG(){let{t:e}=(0,E.s)(),{attentionCount:t}=lm();return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,height:36,flexShrink:0,padding:"0 16px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,r.jsxs)("h1",{style:{margin:0,display:"flex",alignItems:"center",gap:6,fontSize:13,fontWeight:600},children:[(0,r.jsx)(iK.x,{size:15,color:"var(--text-muted)","aria-hidden":"true"}),e("tasks.title"),(0,r.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 8px",fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em"},children:"Beta"})]}),t>0?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,background:"rgba(239,68,68,0.12)",color:"#dc2626",padding:"1px 8px",fontSize:10,fontWeight:700},children:[t," ",e("tasks.attentionBadge")]}):null,(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsxs)("button",{type:"button",onClick:()=>window.dispatchEvent(new Event(lJ)),style:{display:"inline-flex",alignItems:"center",gap:5,height:26,padding:"0 10px",borderRadius:7,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:"pointer"},title:e("tasks.settingsTitle"),children:[(0,r.jsx)(ly.O,{size:13,"aria-hidden":"true"}),e("tasks.settingsTitle")]})]})}function lY({activeProject:e}){let{t}=(0,E.s)(),{tasks:s,projects:i,refetch:a}=lm(),[d,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(()=>(function(){try{let e=window.localStorage.getItem(lV);if(e){let t=JSON.parse(e);return{showCanceled:t.showCanceled??!1,showArchived:t.showArchived??!1}}}catch{}return lK})()),[g,h]=(0,n.useState)(!1);(0,n.useEffect)(()=>{try{window.localStorage.setItem(lV,JSON.stringify(p))}catch{}},[p]);let[x,f]=(0,n.useState)(null),[m,k]=(0,n.useState)(!1),v=(0,n.useRef)(null),b=(0,n.useRef)({x:0,y:0}),w=(0,n.useRef)(null),j=(0,n.useRef)(null),[S,C]=(0,n.useState)(null),T=(0,n.useRef)(null);T.current=S;let z=(0,n.useRef)(!1),R=(0,n.useRef)(!1),[I,M]=(0,n.useState)(()=>Date.now());(0,n.useEffect)(()=>{let e=window.setInterval(()=>M(Date.now()),6e4);return()=>window.clearInterval(e)},[]);let[P,D]=(0,n.useState)(!1),[$,F]=(0,n.useState)(null),[W,N]=(0,n.useState)(null);(0,n.useEffect)(()=>{let e=()=>{let e,t=(e=o0,o0=null,e);t&&(F(null),N(t),D(!0))};return e(),window.addEventListener(oQ,e),()=>window.removeEventListener(oQ,e)},[]);let[A,L]=(0,n.useState)(null),[O,H]=(0,n.useState)(null),[B,U]=(0,n.useState)(!1),[_,q]=(0,n.useState)(null),[V,K]=(0,n.useState)(!1),[J,G]=(0,n.useState)(null),[Y,Z]=(0,n.useState)("retry"),[X,Q]=(0,n.useState)(!1),[ee,et]=(0,n.useState)(null),[eo,er]=(0,n.useState)(!1),[en,es]=(0,n.useState)(!1),[ei,ea]=(0,n.useState)(null),[el,ed]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=()=>es(!0);return window.addEventListener(lJ,e),()=>window.removeEventListener(lJ,e)},[]);let ec=(0,n.useMemo)(()=>null==d?s:s.filter(e=>e.projectRoot===d),[s,d]),ep=(0,n.useMemo)(()=>(function(e,t,o=!1){let r={todo:[],inProgress:[],attention:[],done:[]};for(let n of e)("canceled"!==n.status||t)&&(null==n.archivedAt||o)&&r[function(e){switch(e){case"todo":case"queued":return"todo";case"preparing":case"running":return"inProgress";case"awaiting_input":case"review":case"merging":case"failed":return"attention";case"done":case"canceled":return"done"}}(n.status)].push(n);for(let e of lw)r[e].sort((e,t)=>(t.updatedAt??"").localeCompare(e.updatedAt??""));return r})(ec,p.showCanceled,p.showArchived),[ec,p]),eu=(0,n.useMemo)(()=>{let e=ep.todo;if(null==S)return e;let t=new Map(e.map(e=>[e.id,e])),o=S.flatMap(e=>t.get(e)??[]);for(let t of e)S.includes(t.id)||o.push(t);return o},[ep.todo,S]),eg=(0,n.useMemo)(()=>s.find(e=>e.id===A)??null,[s,A]),eh=(0,n.useMemo)(()=>s.find(e=>e.id===ei)??null,[s,ei]),ex=(0,n.useCallback)(async e=>{try{await e()}catch(e){console.error("task action failed",e)}finally{a()}},[a]),ef=(0,n.useCallback)(e=>{null!=e.conversationId&&(ea(e.id),ed(!0))},[ea,ed]),em=(0,n.useCallback)(e=>{H(e),U(!0)},[H,U]),ek=(0,n.useCallback)(()=>{F(null),D(!0)},[F,D]),ev=(0,n.useCallback)((e,t)=>{let o=w.current,r=v.current;o&&r&&(o.style.transform=`translate3d(${e-r.dx}px, ${t-r.dy}px, 0)`)},[]),ey=e=>{let t=e.currentTarget.getBoundingClientRect();v.current={dx:e.clientX-t.left,dy:e.clientY-t.top,width:t.width}},eb=(0,n.useCallback)(e=>{if(f(null),k(!1),e){z.current=!1;return}requestAnimationFrame(()=>{z.current=!1})},[f,k]),ew=(0,n.useCallback)(()=>{R.current=!0,C(null),eb(!0)},[eb,C]);(0,n.useEffect)(()=>{if(!x)return;let e=()=>{document.hidden&&ew()};return window.addEventListener("blur",ew),document.addEventListener("visibilitychange",e),()=>{window.removeEventListener("blur",ew),document.removeEventListener("visibilitychange",e)}},[x,ew]),(0,n.useEffect)(()=>{x&&!eu.some(e=>e.id===x.task.id)&&ew()},[x,eu,ew]);let ej=(0,n.useCallback)((e,t,o)=>{if(R.current){eb(!0),C(null);return}let r=j.current?.getBoundingClientRect(),n=null!=r&&t>=r.left&&t<=r.right&&o>=r.top&&o<=r.bottom;if(eb(!1),n){C(null);let t=s.find(t=>t.id===e.id);t?.status==="todo"&&null!=d&&ex(()=>(0,rZ.oQ)(e.id,e.projectRoot,"start"));return}let i=T.current;null!=d&&null!=i&&(async()=>{try{await (0,rZ.Lu)(d,i)}catch(e){console.error("reorder failed",e)}await a(),C(null)})()},[ex,eb,d,a,s]),eS=(0,n.useCallback)(()=>{ex(async()=>{let e=await (0,rZ.a5)(d);e>0&&console.log(`started ${e} tasks`)})},[ex,d]),eC=(0,n.useCallback)(()=>{let e=ep.done.filter(e=>null==e.archivedAt);0!==e.length&&ex(()=>Promise.all(e.map(e=>(0,rZ.et)(e.id,e.projectRoot,!0))))},[ex,ep.done]),eT=+(p.showCanceled!==lK.showCanceled)+ +(p.showArchived!==lK.showArchived),ez=s.length>0,eR=(0,n.useMemo)(()=>{let t=new Set(i);return e&&t.add(e),[...t].sort()},[i,e]),eI=(0,n.useMemo)(()=>{let e=new Map;for(let t of eR)e.set(t,t.split("/").filter(Boolean).pop()??t);return e},[eR]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[ez&&(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:8,padding:"14px 16px 8px"},children:[(0,r.jsxs)("select",{value:d??lq,onChange:e=>c(e.target.value===lq?null:e.target.value),style:{height:30,borderRadius:999,padding:"0 10px",background:"var(--bg-panel)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,fontWeight:500,cursor:"pointer",maxWidth:"14rem"},"aria-label":t("tasks.allFolders"),children:[(0,r.jsx)("option",{value:lq,children:t("tasks.allFolders")}),eR.map(e=>(0,r.jsx)("option",{value:e,children:eI.get(e)??e},e))]}),(0,r.jsxs)("div",{style:{position:"relative"},children:[(0,r.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,fontWeight:500,cursor:"pointer"},children:[(0,r.jsx)(lb.n,{size:13,"aria-hidden":"true"}),t("tasks.filter"),eT>0?(0,r.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 6px",fontSize:10,fontWeight:700},children:eT}):null]}),g&&(0,r.jsx)("div",{style:{position:"absolute",top:34,left:0,zIndex:50,width:200,borderRadius:12,padding:6,background:"var(--bg-panel)",border:"1px solid var(--border)",boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[["showCanceled",t("tasks.showCanceled")],["showArchived",t("tasks.showArchived")]].map(([e,t])=>(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:8,cursor:"pointer",fontSize:12},children:[(0,r.jsx)("input",{type:"checkbox",checked:p[e],onChange:t=>u(o=>({...o,[e]:t.target.checked})),style:{accentColor:"var(--accent)"}}),t]},e))})]}),(0,r.jsx)("div",{style:{flex:1}}),(0,r.jsxs)("button",{type:"button",onClick:eS,style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 12px",background:"none",border:"none",color:"var(--text)",fontSize:12,cursor:"pointer"},title:t("tasks.startAll"),children:[(0,r.jsx)(lo.j,{size:13,"aria-hidden":"true"}),t("tasks.startAll")]}),(0,r.jsxs)("button",{type:"button",onClick:ek,style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 14px",background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,r.jsx)(y.F,{size:13,weight:"bold","aria-hidden":"true"}),t("tasks.new")]})]}),ez?(0,r.jsx)("div",{style:{flex:1,minHeight:0,overflowX:"auto"},children:(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:16,minWidth:"56rem",height:"100%",padding:"4px 16px 16px"},children:lC.map(e=>{let o="todo"===e?eu:ep[e],n=lT[e],s=e=>(0,r.jsx)(lP,{task:e,folderName:e.projectRoot?eI.get(e.projectRoot)??null:null,now:I,onOpen:()=>{z.current||L(e.id)},onStart:()=>void ex(()=>(0,rZ.oQ)(e.id,e.projectRoot,"start")),onCancel:()=>{q(e),K(!0)},onRetry:()=>{G(e),Z("retry"),Q(!0)},onRequeue:()=>{G(e),Z("requeue"),Q(!0)},onViewSession:()=>ef(e),onMerge:()=>{lj(e)?(et(e),er(!0)):em(e)},onArchive:()=>void ex(()=>(0,rZ.et)(e.id,e.projectRoot,null==e.archivedAt)),onEdit:()=>{F(e),D(!0)}},e.id);return(0,r.jsxs)("div",{ref:"inProgress"===e?j:void 0,style:{display:"flex",flexDirection:"column",minHeight:0,gap:8},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,height:24,flexShrink:0,padding:"0 2px"},children:[(0,r.jsx)("span",{style:{width:3,height:14,borderRadius:999,background:n.marker,flexShrink:0},"aria-hidden":"true"}),(0,r.jsx)("h2",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:t(`tasks.col${e[0].toUpperCase()}${e.slice(1)}`)}),(0,r.jsx)("span",{style:{borderRadius:999,background:"var(--bg-hover)",padding:"1px 8px",fontSize:10,fontWeight:600,color:"var(--text-muted)"},children:o.length}),(0,r.jsx)("div",{style:{flex:1}}),"done"===e&&ep.done.some(e=>null==e.archivedAt)?(0,r.jsx)("button",{type:"button",onClick:eC,style:{background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--text-muted)",padding:"2px 6px",borderRadius:6},children:t("tasks.archiveAllDone")}):null]}),0===o.length?(0,r.jsx)("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:4,borderRadius:12,border:"1px dashed var(--border)",padding:16,textAlign:"center",..."inProgress"===e&&x?m?{borderColor:"var(--accent)",background:"rgba(37,99,235,0.08)"}:{borderColor:"var(--accent)"}:{}},children:(0,r.jsx)("p",{style:{fontSize:12,color:"var(--text-muted)"},children:t(`tasks.emptyCol${e[0].toUpperCase()}${e.slice(1)}`)})}):(0,r.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",borderRadius:12,transition:"background 0.15s, box-shadow 0.15s",..."inProgress"===e&&x?m?{background:"rgba(37,99,235,0.06)",boxShadow:"inset 0 0 0 2px var(--accent)"}:{boxShadow:"inset 0 0 0 1px rgba(37,99,235,0.25)"}:{}},children:(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:16,paddingBottom:4},children:o.map(t=>"todo"===e?(0,r.jsx)("div",{draggable:!0,onDragStart:e=>{var o,r;e.dataTransfer.effectAllowed="move",o=e.clientX,r=e.clientY,z.current=!0,R.current=!1,b.current={x:o,y:r},f({task:t,width:v.current?.width??280})},onDrag:e=>{var t,o;let r,n;return b.current={x:t=e.clientX,y:o=e.clientY},ev(t,o),void((n=null!=(r=j.current?.getBoundingClientRect())&&t>=r.left&&t<=r.right&&o>=r.top&&o<=r.bottom)!==m&&k(n))},onDragEnd:e=>ej(t,e.clientX,e.clientY),onPointerDown:ey,style:{cursor:"grab",opacity:x?.task.id===t.id?.4:1},children:s(t)},t.id):(0,r.jsx)("div",{children:s(t)},t.id))})})]},e)})})}):(0,r.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12,padding:32,textAlign:"center"},children:[(0,r.jsx)(iK.x,{size:40,color:"var(--text-dim)",opacity:.4,"aria-hidden":"true"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,r.jsx)("p",{style:{fontSize:14,fontWeight:500,color:"var(--text)"},children:t("tasks.empty")}),(0,r.jsx)("p",{style:{maxWidth:320,fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:t("tasks.emptyHint")})]}),(0,r.jsxs)("button",{type:"button",onClick:ek,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 14px",borderRadius:8,background:"var(--accent)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,r.jsx)(y.F,{size:13,weight:"bold","aria-hidden":"true"}),t("tasks.new")]})]}),(0,r.jsx)(lL,{open:P,onOpenChange:D,task:$,defaultProject:W?.projectRoot??d??e??null,projects:eR,prefillTitle:W?W.text.slice(0,80):void 0,prefillPrompt:W?W.text:void 0,onSubmit:async(e,t,r)=>{await ex(async()=>{let{createTaskApi:n}=await Promise.resolve().then(o.bind(o,23084)),{updateTaskApi:s}=await Promise.resolve().then(o.bind(o,23084));$?await s($.id,e,{title:t,config:r}):await n({projectRoot:e,title:t,config:r})}),D(!1),N(null)}}),(0,r.jsx)(lN,{open:null!=A,onOpenChange:e=>{e||L(null)},task:eg,onViewSession:ef,onMerge:em,onEdit:e=>{F(e),D(!0)},onCancel:e=>{q(e),K(!0)},onRetry:e=>{G(e),Z("retry"),Q(!0)},onRequeue:e=>{G(e),Z("requeue"),Q(!0)},onComplete:e=>{et(e),er(!0)}}),(0,r.jsx)(lO,{open:B,onOpenChange:U,task:O}),(0,r.jsx)(lD,{open:V,onOpenChange:K,task:_}),(0,r.jsx)(lH,{open:X,onOpenChange:Q,task:J,kind:Y}),(0,r.jsx)(l$,{open:eo,onOpenChange:er,task:ee}),(0,r.jsx)(l_,{open:el&&null!=eh,onOpenChange:ed,task:eh}),(0,r.jsx)(lU,{open:en,onOpenChange:es,projectRoot:d}),x?(0,l.createPortal)((0,r.jsx)("div",{ref:w,style:{position:"fixed",left:0,top:0,zIndex:999,pointerEvents:"none",width:x.width,willChange:"transform"},"aria-hidden":"true",children:(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,borderRadius:12,border:m?"1px solid var(--accent)":"1px solid var(--border)",background:"var(--bg-panel)",padding:12,boxShadow:"0 8px 24px rgba(0,0,0,0.2)",transform:"rotate(-1deg)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[(0,r.jsx)("span",{style:{minWidth:0,overflowWrap:"break-word",fontSize:13,fontWeight:500},children:x.task.title}),(0,r.jsx)(lM,{task:x.task})]}),m?(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:"var(--accent)"},children:[(0,r.jsx)(lo.j,{size:11,weight:"bold","aria-hidden":"true"}),t("tasks.dropToStart")]}):null]})}),document.body):null]})}var lZ=o(62235);function lX({isDark:e,toggleTheme:t,translate:o}){let[s,i]=(0,n.useState)(!1);(0,n.useEffect)(()=>{i(!0)},[]);let a=o(s?e?"desktop.switchToLight":"desktop.switchToDark":"desktop.switchToLight");return(0,r.jsx)("button",{className:"app-no-drag",suppressHydrationWarning:!0,onClick:e=>{let o=e.currentTarget.getBoundingClientRect();t({x:o.left+o.width/2,y:o.top+o.height/2})},title:a,"aria-label":a,"aria-pressed":!s||e,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:s?e?(0,r.jsx)(iN.b,{size:16,"aria-hidden":"true"}):(0,r.jsx)(iW.A,{size:16,"aria-hidden":"true"}):(0,r.jsx)(iN.b,{size:16,"aria-hidden":"true"})})}function lQ({topBarRef:e,sidebarOpen:t,onSidebarToggle:o,isDark:s,toggleTheme:i,isMobile:a,showChat:l,showTasks:d,tasksBoardEnabled:c,onToggleTasks:p,systemPrompt:g,activeTopPanel:h,topPanelPos:x,sessionStats:f,contextUsage:m,copiedSessionField:v,onCopySessionField:y,rightPanelOpen:b,onToggleFilePanel:w,onOpenSettings:j,sessionTitle:S,onWorkspaceControlsHostChange:C}){let T,z,R,I,M,P,D,$,{t:F}=(0,E.s)(),[W,N]=(0,n.useState)(!1);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{ref:e,className:"app-title-bar",style:{display:"flex",alignItems:"center",flexShrink:0,borderBottom:"1px solid var(--border)",height:36,background:"var(--bg-panel)",position:"relative",zIndex:600},children:[(0,r.jsx)("button",{className:"app-no-drag",onClick:o,title:t?F("desktop.hideSidebar"):F("desktop.showSidebar"),"aria-label":t?F("desktop.hideSidebar"):F("desktop.showSidebar"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=t?"var(--bg-selected)":"none",e.currentTarget.style.color=t?"var(--text)":"var(--text-muted)"},children:t?(0,r.jsx)(lZ.V,{size:16,"aria-hidden":"true"}):(0,r.jsx)(k.B,{size:16,"aria-hidden":"true"})}),(0,r.jsx)("div",{className:"app-no-drag",ref:C,style:{flex:"0 1 auto",minWidth:0,maxWidth:"min(52vw, 560px)",height:"100%",display:"flex",alignItems:"center",padding:"0 8px 0 0",overflow:"visible"}}),l&&(0,r.jsx)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"}}),(0,r.jsx)("div",{className:"app-title-drag",style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",height:"100%",minWidth:0,padding:"0 12px",userSelect:"none"},children:S&&(0,r.jsx)("button",{type:"button",onClick:()=>{a&&N(!0)},title:a?S:void 0,style:{display:"block",maxWidth:"100%",fontSize:12,fontWeight:500,color:"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",background:"none",border:"none",cursor:"pointer",padding:"2px 6px",borderRadius:5},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:S})}),!a&&c&&(0,r.jsx)("button",{className:"app-no-drag",onClick:p,title:d?F("desktop.hideTaskBoard"):F("desktop.showTaskBoard"),"aria-label":d?F("desktop.hideTaskBoard"):F("desktop.showTaskBoard"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:d?"var(--bg-selected)":"none",border:"none",color:d?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=d?"var(--bg-selected)":"none",e.currentTarget.style.color=d?"var(--text)":"var(--text-muted)"},children:(0,r.jsx)(iK.x,{size:16,"aria-hidden":"true"})}),(0,r.jsx)("button",{className:"app-no-drag",onClick:w,title:b?F("desktop.hideFilePanel"):F("desktop.showFilePanel"),"aria-label":b?F("desktop.hideFilePanel"):F("desktop.showFilePanel"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=b?"var(--bg-selected)":"none",e.currentTarget.style.color=b?"var(--text)":"var(--text-muted)"},children:(0,r.jsx)(lZ.V,{size:16,"aria-hidden":"true",style:{transform:"scaleX(-1)"}})}),(0,r.jsx)(lX,{isDark:s,toggleTheme:i,translate:F}),(0,r.jsx)("button",{className:"app-no-drag",type:"button",onClick:j,title:F("desktop.settings"),"aria-label":F("desktop.settings"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,r.jsx)(ly.O,{size:16,"aria-hidden":"true"})})]}),h&&x&&(0,r.jsxs)("div",{style:{position:"fixed",top:x.top,left:x.left,width:x.width,maxHeight:`calc(100dvh - ${x.top}px)`,overflowY:"auto",zIndex:500},children:["system"===h&&(0,r.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:g?(0,r.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:g}):""===g?(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,r.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})}),"session"===h&&(0,r.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",padding:"12px 16px"},children:f?(T=[...f.sessionName?[{label:F("desktop.name"),value:f.sessionName,copyField:null}]:[],{label:F("desktop.sessionInfoFile"),value:f.sessionFile??F("desktop.sessionInfoInMemory"),copyField:"file"},{label:F("desktop.sessionInfoId"),value:f.sessionId,copyField:"id"}],z=[[F("desktop.sessionInfoUser"),f.userMessages.toLocaleString()],[F("desktop.sessionInfoAssistant"),f.assistantMessages.toLocaleString()],[F("desktop.sessionInfoToolCalls"),f.toolCalls.toLocaleString()],[F("desktop.sessionInfoToolResults"),f.toolResults.toLocaleString()],[F("desktop.sessionInfoTotal"),f.totalMessages.toLocaleString()]],R=[[F("desktop.sessionInfoInput"),f.tokens.input.toLocaleString()],[F("desktop.sessionInfoOutput"),f.tokens.output.toLocaleString()],...f.tokens.cacheRead>0?[[F("desktop.sessionInfoCacheRead"),f.tokens.cacheRead.toLocaleString()]]:[],...f.tokens.cacheWrite>0?[[F("desktop.sessionInfoCacheWrite"),f.tokens.cacheWrite.toLocaleString()]]:[],[F("desktop.sessionInfoTotal"),f.tokens.total.toLocaleString()]],I=m??f.contextUsage,P=[...f.cost>0?[[F("desktop.sessionInfoCost"),`$${f.cost.toFixed(4)}`]]:[],...I?.contextWindow?[[F("desktop.sessionInfoContext"),`${null!==I.percent?`${I.percent.toFixed(1)}%`:"?"} / ${(M=I.contextWindow)>=1e6?`${(M/1e6).toFixed(1)}M`:M>=1e3?`${(M/1e3).toFixed(0)}k`:String(M)}`]]:[]],D=(e,t,o="left",n=!1)=>(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:e}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:n?"max-content max-content":"auto minmax(0, 1fr)",columnGap:n?14:12,rowGap:4,justifyContent:n?"start":void 0},children:t.map(([t,s])=>(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:t}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:n?"normal":"anywhere",textAlign:o,whiteSpace:"right"===o?"nowrap":"normal"},children:s})]},`${e}:${t}`))})]}),$=(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:F("desktop.sessionInfoTitle")}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:T.map(e=>{var t,o;let n;return(0,r.jsxs)("div",{style:{display:"contents"},children:[(0,r.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,r.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,r.jsx)("div",{children:e.copyField?(t=e.copyField,o=e.value,n=v===t,(0,r.jsx)("button",{type:"button",title:n?F("desktop.copied"):"file"===t?F("desktop.copyFilePath"):F("desktop.copySessionId"),onClick:()=>y(t,o),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:n?"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=n?"var(--accent)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:n?(0,r.jsx)(u.J,{size:12,"aria-hidden":"true"}):(0,r.jsx)(ti.Q,{size:12,"aria-hidden":"true"})})):null})]},`session-info:${e.label}`)})})]}),(0,r.jsxs)("div",{style:{display:"grid",gridTemplateColumns:a?"1fr":"minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)",gap:a?16:24,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[$,D(F("desktop.sessionInfoMessages"),z),D(F("desktop.sessionInfoTokens"),[...R,...P],"right",!0)]})):(0,r.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:F("desktop.sendMessageForSessionInfo")})})]}),W&&S&&(0,r.jsx)("div",{style:{position:"fixed",inset:0,zIndex:3e3,display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:48,background:"rgba(0,0,0,0.35)"},onMouseDown:e=>{e.target===e.currentTarget&&N(!1)},children:(0,r.jsx)("div",{role:"dialog","aria-label":S,style:{maxWidth:"min(560px, calc(100vw - 32px))",maxHeight:"min(60vh, 400px)",overflow:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 16px 40px rgba(0,0,0,0.3)",padding:"14px 18px",fontSize:13,lineHeight:1.6,color:"var(--text)",wordBreak:"break-word",whiteSpace:"pre-wrap"},children:S})})]})}function l0({cwd:e,busy:t,error:o,onCancelAction:n,onConfirmAction:s}){let{t:i}=(0,E.s)();return(0,r.jsx)("div",{role:"presentation",style:{position:"fixed",inset:0,zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center",padding:16,background:"rgba(0, 0, 0, 0.4)"},onClick:e=>{t||e.target!==e.currentTarget||n()},children:(0,r.jsxs)("section",{role:"dialog","aria-modal":"true","aria-labelledby":"project-trust-title",style:{width:440,maxWidth:"100%",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",boxShadow:"0 12px 36px rgba(0, 0, 0, 0.24)",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",gap:12,padding:"18px 18px 14px"},children:[(0,r.jsx)(oZ.o,{size:21,weight:"duotone",color:"var(--accent-orange)",style:{flexShrink:0,marginTop:1},"aria-hidden":"true"}),(0,r.jsxs)("div",{style:{minWidth:0},children:[(0,r.jsx)("h2",{id:"project-trust-title",style:{margin:0,fontSize:15,fontWeight:700,color:"var(--text)"},children:i("desktop.trustProjectTitle")}),(0,r.jsx)("p",{style:{margin:"7px 0 0",fontSize:12,lineHeight:1.6,color:"var(--text-muted)"},children:i("desktop.trustProjectBody")}),(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}),o&&(0,r.jsx)("div",{role:"alert",style:{marginTop:10,color:"var(--accent-red)",fontSize:12,lineHeight:1.5},children:o})]})]}),(0,r.jsxs)("footer",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,r.jsx)("button",{type:"button",onClick:n,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:i("desktop.cancel")}),(0,r.jsx)("button",{type:"button",onClick:s,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:i(t?"desktop.trustingProject":"desktop.trustProject")})]})]})})}function l1(e,t,o){let r=Number.isFinite(e)?e:t,n=Math.max(t,o);return Math.round(Math.max(t,Math.min(n,r)))}function l2(e){return l1(.42*e,360,640)}function l4(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function l6(e){let{ariaLabel:t,cssVariable:o,defaultWidth:r,getDefaultWidth:s,getMaxWidth:i,growthDirection:a,maxWidth:l,minWidth:d,storageKey:c,widthRef:p}=e,u=(0,n.useRef)(null),g=(0,n.useRef)(null),h=(0,n.useRef)(!1),[x,f]=(0,n.useState)(r),[m,k]=(0,n.useState)(!1),v=(0,n.useCallback)(()=>Math.min(l,Math.max(d,i())),[i,l,d]),y=(0,n.useCallback)(e=>l1(e,d,v()),[v,d]),b=(0,n.useCallback)(e=>{p.current=e;let t=`${e}px`;u.current?.style.setProperty(o,t),u.current?.parentElement?.style.setProperty(o,t)},[o,p]),w=(0,n.useCallback)((e,t={})=>{let{forcePersist:o=!1,persist:r=!0}=t,n=y(e),s=n!==p.current;return b(n),f(n),r&&(s||o)&&l4(c,n),n},[b,y,c,p]),j=(0,n.useCallback)(e=>{document.body.style.cursor=e.previousCursor,document.body.style.userSelect=e.previousUserSelect},[]),S=(0,n.useCallback)(e=>{let t=g.current;if(t&&t.pointerId===e){g.current=null,j(t),k(!1),w(p.current,{forcePersist:!0});try{t.target.hasPointerCapture(e)&&t.target.releasePointerCapture(e)}catch{}}},[w,j,p]),C=(0,n.useCallback)(e=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),e.stopPropagation();let t=g.current;t&&S(t.pointerId);let o=e.currentTarget;o.focus({preventScroll:!0}),o.setPointerCapture(e.pointerId),g.current={pointerId:e.pointerId,startX:e.clientX,startWidth:p.current,target:o,previousCursor:document.body.style.cursor,previousUserSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none",k(!0)},[S,p]),T=(0,n.useCallback)(e=>{let t=g.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void S(e.pointerId);e.preventDefault();let o="right"===a?1:-1,r=y(t.startWidth+(e.clientX-t.startX)*o);b(r),e.currentTarget.setAttribute("aria-valuenow",String(r)),e.currentTarget.setAttribute("aria-valuetext",`${r} px`)},[b,y,S,a]),z=(0,n.useCallback)(e=>{S(e.pointerId)},[S]),R=(0,n.useCallback)(e=>{S(e.pointerId)},[S]),I=(0,n.useCallback)(e=>{S(e.pointerId)},[S]),M=(0,n.useCallback)(()=>{w(s?.()??r,{forcePersist:!0})},[w,r,s]),E=(0,n.useCallback)(()=>{w(p.current)},[w,p]),P=(0,n.useCallback)(e=>{let t=e.shiftKey?32:12,o="right"===a?"ArrowRight":"ArrowLeft",r="right"===a?"ArrowLeft":"ArrowRight";e.key===o?(e.preventDefault(),w(p.current+t,{forcePersist:!0})):e.key===r?(e.preventDefault(),w(p.current-t,{forcePersist:!0})):"Home"===e.key?(e.preventDefault(),w(d,{forcePersist:!0})):"End"===e.key?(e.preventDefault(),w(v(),{forcePersist:!0})):"Enter"===e.key&&(e.preventDefault(),M())},[w,v,a,d,M,p]);return(0,n.useEffect)(()=>{if(h.current)return;h.current=!0;let e=function(e){try{let t=window.localStorage.getItem(e);if(null===t)return null;let o=Number.parseInt(t,10);return Number.isFinite(o)?o:null}catch{return null}}(c),t=w(e??s?.()??r,{persist:!1});null!==e&&e!==t&&l4(c,t)},[w,r,s,c]),(0,n.useEffect)(()=>{if(!h.current)return;w(p.current);let e=()=>{w(p.current)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[w,p]),(0,n.useEffect)(()=>{if(!m)return;let e=()=>{let e=g.current;e&&S(e.pointerId)},t=()=>{"visible"!==document.visibilityState&&e()};return window.addEventListener("blur",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("blur",e),document.removeEventListener("visibilitychange",t)}},[S,m]),(0,n.useEffect)(()=>()=>{let e=g.current;e&&(g.current=null,j(e))},[j]),{isResizing:m,panelRef:u,reclampWidth:E,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":v(),"aria-valuemin":d,"aria-valuenow":x,"aria-valuetext":`${x} px`,onDoubleClick:M,onKeyDown:P,onLostPointerCapture:I,onPointerCancel:R,onPointerDown:C,onPointerMove:T,onPointerUp:z,role:"separator",tabIndex:0},width:x}}function l5(){let e,t=(0,i.useRouter)(),o=(0,i.useSearchParams)(),l=(0,n.useMemo)(()=>{let e;return{requestedCwd:e=o.get("cwd")?.trim()||null,sessionId:e?null:o.get("session")}},[o]),{isDark:d,toggleTheme:c}=tP(),{t:p}=(0,E.s)(),u=rY(),[g,h]=(0,n.useState)(null),[x,f]=(0,n.useState)(null),[m,k]=(0,n.useState)(0),[v,y]=(0,n.useState)(0),[b,w]=(0,n.useState)(0),[j,S]=(0,n.useState)(!1),[C,T]=(0,n.useState)("models"),[z,R]=(0,n.useState)(0),[I,M]=(0,n.useState)(null),[P,D]=(0,n.useState)(!1),[$,F]=(0,n.useState)(!1),[W,N]=(0,n.useState)(null),[A,L]=(0,n.useState)(!0),[O,H]=(0,n.useState)(!1);(0,n.useEffect)(()=>{u&&L(!1)},[u]),(0,n.useEffect)(()=>{H(!0)},[]);let B=(0,n.useRef)(null),U=(0,n.useRef)(null),[_,q]=(0,n.useState)(null),[V,K]=(0,n.useState)(null),[J,G]=(0,n.useState)(null),Y=(0,n.useCallback)(e=>{G(e)},[]),[Z,Q]=(0,n.useState)(null),ee=(0,n.useCallback)(e=>{Q(e)},[]),[et,eo]=(0,n.useState)([]),er=(0,n.useCallback)(e=>{eo(e)},[]),en=et.filter(e=>"running"===e.status).length,[es,ei]=(0,n.useState)(null),ea=(0,n.useRef)(null),el=(0,n.useCallback)((e,t)=>{tD(t).then(()=>{ea.current&&clearTimeout(ea.current),ei(e),ea.current=setTimeout(()=>ei(null),1400)})},[]);(0,n.useEffect)(()=>()=>{ea.current&&clearTimeout(ea.current)},[]);let[ed,ec]=(0,n.useState)(null),ep=(0,n.useCallback)(e=>{ec(e)},[]),[eu,eg]=(0,n.useState)(null),[eh,ex]=(0,n.useState)(null),ef=(0,n.useCallback)(()=>{u&&L(!1),eg("session")},[u]),em=(0,n.useCallback)(()=>{u&&eg(null),L(e=>!e)},[u]);(0,n.useEffect)(()=>{if(!eu||!U.current)return;let e=()=>{let e=U.current.getBoundingClientRect();ex({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(U.current),()=>t.disconnect()},[eu]);let[ek,ey]=(0,n.useState)([]),[eb,ew]=(0,n.useState)(null),[ej,eS]=(0,n.useState)(!1),[eC,eT]=(0,n.useState)(!1),[ez,eR]=(0,n.useState)(null),eI=(0,n.useCallback)(e=>{eR(e??null),eT(!0),eS(!0),u&&L(!1)},[u]),eM=(0,n.useCallback)(()=>{eT(!1),eR(null)},[]),eP=(0,n.useRef)(260),eD=(0,n.useRef)(l2(1366)),e$=(0,n.useCallback)(()=>l2(window.innerWidth),[]),eF=(0,n.useCallback)(()=>(function(e){let{viewportWidth:t,rightPanelOpen:o,rightPanelWidth:r}=e;if(t<=640)return 480;let n=t<960;return Math.min(480,t-(n?320:420)-(!n&&o?r:0))})({viewportWidth:window.innerWidth,rightPanelOpen:ej,rightPanelWidth:eD.current}),[ej]),eW=(0,n.useCallback)(()=>(function(e){let{viewportWidth:t,sidebarOpen:o,sidebarWidth:r}=e;return t<960?1200:Math.min(1200,t-420-(o?r:0))})({viewportWidth:window.innerWidth,sidebarOpen:A,sidebarWidth:eP.current}),[A]),eN=l6({ariaLabel:p("desktop.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:eF,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:eP}),eA=l6({ariaLabel:p("desktop.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:l2(1366),getDefaultWidth:e$,getMaxWidth:eW,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:eD}),eL=eN.reclampWidth,eO=eA.reclampWidth;(0,n.useEffect)(()=>{ej&&(eL(),eO())},[eO,eL,ej]);let eH=(0,n.useCallback)((e,t)=>{B.current?.insertText(rq(e,t))},[]),eU=(0,n.useCallback)(e=>{let t=e.map(e=>rq(e,!1)).join("");t&&B.current?.insertText(t)},[]),e_=(0,n.useCallback)((e,t,o)=>{let r,n,s,i;B.current?.insertText((r=Math.max(1,Math.min(t,o)),n=Math.max(1,Math.max(t,o)),s=e.includes(" ")?`@"${e}"`:`@${e}`,i=r===n?`:${r}`:`:${r}-${n}`,`${s}${i} `))},[]),[eq,eV]=(0,n.useState)(()=>l.sessionId),[eK,eJ]=(0,n.useState)(null),[eG,eY]=(0,n.useState)(()=>l.requestedCwd?"validating":"idle"),[eZ,eX]=(0,n.useState)(null),[eQ,e0]=(0,n.useState)(()=>!eq),e1=(0,n.useRef)(!1),e2=(0,n.useRef)("");(0,n.useEffect)(()=>{let e=`${l.requestedCwd??""}|${l.sessionId??""}`;e2.current!==e&&(e2.current=e,eV(l.sessionId),e0(!l.sessionId),l.requestedCwd||eY("idle"),eX(null))},[l]),(0,n.useEffect)(()=>{let e=l.requestedCwd;if(!e)return;let t=new AbortController;return eY("validating"),eX(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok||!t.cwd)throw Error(t.error??`HTTP ${e.status}`);e1.current=!0,f(t.cwd),eY("ready")}).catch(e=>{t.signal.aborted||(eX(e instanceof Error?e.message:String(e)),eY("error"))}),()=>t.abort()},[l]);let e4=(0,n.useCallback)((e,t)=>{if(!e)return;if(eJ(e),e1.current){e1.current=!1;return}let o=t??e;g&&ev(g.projectRoot??g.cwd,o)||(h(null),f(t=>t&&t!==e?null:t),y(e=>e+1),G(null),eg(null))},[g]);(0,n.useEffect)(()=>{let e=eK?X(eK)||eK:null;document.title=e?`${e} — Pi Agent Web`:"Pi Agent Web"},[eK]);let e6=(0,n.useCallback)((e,t=!1)=>{if(!t&&g){let t=ev(g.projectRoot??g.cwd,e.projectRoot??e.cwd);if(g.id===e.id&&t){u&&L(!1);return}}f(null),h(e),y(e=>e+1),G(null),e0(!0),u&&!t&&L(!1),t&&(e1.current=!0),t||window.history.replaceState(null,"",`?session=${encodeURIComponent(e.id)}`)},[u,g]),e5=(0,n.useCallback)((e,t)=>{h(null),f(t),y(e=>e+1),G(null),eg(null),u&&L(!1),window.history.replaceState(null,"","/")},[t,u]);!function(e){let{onNewSession:t,activeCwd:o}=e;(0,n.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(!a)return;let t=e.target?.tagName;if("TEXTAREA"===t||"INPUT"===t)return;e.preventDefault(),a();return}if("n"===e.key&&e.ctrlKey&&e.altKey){if(!o||!t)return;e.preventDefault(),t(o)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,t])}({onNewSession:e=>e5(`kb-${Date.now()}`,e),activeCwd:eK});let e3=(0,n.useCallback)(e=>{fetch("/api/sessions").then(e=>e.ok?e.json():null).then(t=>{let o=t?.sessions.find(t=>t.id===e);o&&h(t=>t&&t.id===e&&!t.projectRoot?o:t)}).catch(()=>{})},[]),e8=(0,n.useCallback)(e=>{f(null),h(e),e.cwd&&eJ(e.cwd),k(e=>e+1),e3(e.id),window.history.replaceState(null,"",`?session=${encodeURIComponent(e.id)}`),window.setTimeout(()=>k(e=>e+1),1200)},[t,e3]),e7=(0,n.useCallback)(()=>{k(e=>e+1),w(e=>e+1)},[]),e9=(0,n.useCallback)(e=>{k(e=>e+1),y(e=>e+1),f(null),h(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e})),e3(e),window.history.replaceState(null,"",`?session=${encodeURIComponent(e)}`)},[t,e3]),te=(0,n.useCallback)(()=>{e0(!0)},[]),tt=(0,n.useCallback)(e=>{if(k(e=>e+1),g?.id===e){let e=g.cwd;h(null),f(e??null),y(e=>e+1),G(null),eg(null),window.history.replaceState(null,"","/")}},[t,g]),to=(0,n.useCallback)((e,t,o,r)=>{let n="string"==typeof o||null===o?o:void 0,s="object"==typeof o&&null!==o?o:r,i=`file:${e}`;ey(o=>{let r=o.find(e=>e.id===i);return r?n&&r.sourceSessionId!==n||s?.initialDisplayMode&&r.initialDisplayMode!==s.initialDisplayMode?o.map(e=>e.id===i?{...e,sourceSessionId:n??e.sourceSessionId,initialDisplayMode:s?.initialDisplayMode??e.initialDisplayMode}:e):o:[...o,{id:i,label:t,filePath:e,sourceSessionId:n,initialDisplayMode:s?.initialDisplayMode}]}),ew(i),eS(!0),u&&L(!1)},[u]),tr=(0,n.useCallback)(e=>{to(e,X(e),g?.id??null)},[to,g?.id]),tn=(0,n.useCallback)(e=>{ey(t=>{let o=t.filter(t=>t.id!==e);return 0===o.length&&eS(!1),o}),ew(t=>{if(t!==e)return t;let o=ek.filter(t=>t.id!==e);return o.length>0?o[o.length-1].id:null})},[ek]),ts=g?eE(g.name)||g.firstMessage.slice(0,50)||g.id.slice(0,12):null,ti=(0,n.useCallback)(()=>{g&&window.open(`/api/sessions/${encodeURIComponent(g.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[g]),ta=x??(null===g&&eK?eK:null),tl="validating"!==eG&&"error"!==eG&&(null!==g||null!==ta),td=g?.cwd??ta,[tc,tp]=(0,n.useState)(!1),tu=(0,n.useCallback)(()=>{u||tp(e=>!e)},[u]),[tg,th]=(0,n.useState)(!0);(0,n.useEffect)(()=>{let e=!1,t=()=>fetch("/api/features").then(e=>e.ok?e.json():null).then(t=>{!e&&t&&"boolean"==typeof t.tasksBoard&&(th(t.tasksBoard),t.tasksBoard||tp(!1))}).catch(()=>{});t();let o=()=>t();return window.addEventListener("pi:features-changed",o),()=>{e=!0,window.removeEventListener("pi:features-changed",o)}},[]);let tx=eQ&&!tl;(0,n.useEffect)(()=>{let e=()=>{u||tp(!0)};return window.addEventListener(sH,e),()=>window.removeEventListener(sH,e)},[u]),(0,n.useEffect)(()=>{if(M(null),D(!1),N(null),!td)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(td)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);M(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[td]);let tf=(0,n.useCallback)(async()=>{if(td&&!$){F(!0),N(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:td})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);M(t),D(!1),R(e=>e+1),y(e=>e+1)}catch(e){N(e instanceof Error?e.message:String(e))}finally{F(!1)}}},[$,td]),tm=ek.find(e=>e.id===eb)??null,tk=eK??g?.cwd??x,tv=(0,n.useCallback)(e=>{T(e),S(!0)},[]),ty=(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(eB,{selectedSessionId:g?.id??null,onSelectSession:e6,onNewSession:e5,initialSessionId:eq,onInitialRestoreDone:te,refreshKey:m,onSessionDeleted:tt,selectedCwd:g?.cwd??x??null,onCwdChange:e4,onOpenFile:to,selectedSessionStats:Z,onOpenSettings:e=>{tv(["models","skills","plugins","opencode-zen","chat","features","logs"].includes(e)?e:"models")},explorerRefreshKey:b,onAtMention:eH,onAtMentions:eU,workspaceControlsHosts:{title:_,welcome:V},showWorkspaceControls:!0})});return(0,r.jsxs)(lk,{children:[(0,r.jsx)("style",{children:`
|
|
43
|
+
@media (max-width: 640px) {
|
|
44
|
+
.sidebar-overlay-backdrop.sidebar-mobile-pending {
|
|
45
|
+
opacity: 0 !important;
|
|
46
|
+
pointer-events: none !important;
|
|
47
|
+
}
|
|
48
|
+
.sidebar-container.sidebar-mobile-pending.sidebar-open {
|
|
49
|
+
transform: translateX(-100%);
|
|
50
|
+
box-shadow: none;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,r.jsx)(lQ,{topBarRef:U,sidebarOpen:A,onSidebarToggle:em,isDark:d,toggleTheme:c,isMobile:u,showChat:tl,showTasks:tc,tasksBoardEnabled:tg,onToggleTasks:tu,systemPrompt:J,activeTopPanel:eu,topPanelPos:eh,sessionStats:Z,contextUsage:ed,copiedSessionField:es,onCopySessionField:el,rightPanelOpen:ej,onToggleFilePanel:()=>eS(e=>!e),onOpenSettings:()=>tv("models"),sessionTitle:ts,onWorkspaceControlsHostChange:q}),tl&&I?.requiresTrust&&!I.trusted&&(0,r.jsxs)("button",{type:"button",onClick:()=>{N(null),D(!0)},title:p("desktop.projectResourcesRestricted"),"aria-label":p("desktop.projectResourcesRestricted"),style:{position:"fixed",top:48,right:u?12:20,zIndex:700,display:"inline-flex",alignItems:"center",gap:7,padding:"8px 11px",border:"1px solid color-mix(in srgb, var(--accent-orange) 52%, var(--border))",borderRadius:7,background:"color-mix(in srgb, var(--accent-orange) 11%, var(--bg-panel))",color:"var(--accent-orange)",boxShadow:"0 8px 24px rgba(0, 0, 0, 0.16)",cursor:"pointer",fontSize:12,fontWeight:600},children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"⚠"}),p("desktop.trustProject")]}),(0,r.jsxs)("div",{style:{"--right-panel-width":`${eA.width}px`,flex:1,display:"flex",overflow:"hidden",minWidth:0,position:"relative"},children:[(0,r.jsx)("div",{className:`sidebar-overlay-backdrop${O?"":" sidebar-mobile-pending"}`,onClick:()=>L(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!A,pointerEvents:A?"auto":"none",transition:"opacity 0.25s ease"}}),(0,r.jsx)("div",{ref:eN.panelRef,className:`sidebar-container${A?" sidebar-open":" sidebar-closed"}${O?"":" sidebar-mobile-pending"}${eN.isResizing?" panel-is-resizing":""}`,style:{"--sidebar-width":`${eN.width}px`,background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200},children:ty}),A&&(0,r.jsx)("div",{...eN.separatorProps,className:"workspace-panel-splitter sidebar-panel-splitter"}),(0,r.jsx)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:(0,r.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:tc&&tg?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lG,{}),(0,r.jsx)(lY,{activeProject:eK??void 0})]}):tl?(0,r.jsx)(s_,{session:g,newSessionCwd:ta,onAgentEnd:e7,onSessionCreated:e8,onSessionForked:e9,modelsRefreshKey:z,chatInputRef:B,onSystemPromptChange:Y,onSessionStatsChange:ee,onSubagentsChange:er,onSessionStatsPanelOpen:ef,onContextUsageChange:ep,onOpenFile:tr,onWorkspaceControlsHostChange:K,onViewFullHistory:ti,systemPrompt:J},v):"validating"===eG?(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:p("desktop.openingWorkspace")}),(0,r.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:l.requestedCwd})]}):"error"===eG?(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:p("desktop.unableToOpenWorkspace")}),(0,r.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:l.requestedCwd}),(0,r.jsx)("div",{style:{maxWidth:720,fontSize:12},children:eZ})]}):tx?eK?(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:p("desktop.selectSessionFromSidebar")}):(0,r.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,r.jsx)(s.n,{size:44,color:"var(--accent)","aria-hidden":"true",style:{opacity:.7,flexShrink:0}}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:p("desktop.getStarted")}),(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,r.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),p("desktop.selectProjectDirectory"),(0,r.jsx)("br",{}),(0,r.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),p("desktop.addModelsFromBottom")]})]})]}):null})}),en>0&&(0,r.jsxs)("button",{type:"button",onClick:()=>eI(),title:p("desktop.subagentsViewTitle"),"aria-label":p("desktop.subagentsViewTitle"),style:{position:"fixed",top:46,right:u?12:ej&&!eC?`calc(${eA.width}px + 16px)`:16,zIndex:500,display:"inline-flex",alignItems:"center",gap:7,padding:"6px 12px",border:"1px solid color-mix(in srgb, var(--accent) 45%, var(--border))",borderRadius:999,background:"color-mix(in srgb, var(--accent) 12%, var(--bg-panel))",color:"var(--accent)",boxShadow:"0 6px 20px rgba(0,0,0,0.14)",cursor:"pointer",fontSize:12,fontWeight:600},onMouseEnter:e=>{e.currentTarget.style.background="color-mix(in srgb, var(--accent) 20%, var(--bg-panel))"},onMouseLeave:e=>{e.currentTarget.style.background="color-mix(in srgb, var(--accent) 12%, var(--bg-panel))"},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{width:8,height:8,borderRadius:"50%",background:"var(--accent)",boxShadow:"0 0 0 0 var(--accent)",animation:"subagent-pulse 1.4s ease-out infinite"}}),en," ",p("desktop.subagentsRunningBubble")]}),ej&&(0,r.jsx)("div",{...eA.separatorProps,className:"workspace-panel-splitter right-panel-splitter"}),(0,r.jsxs)("div",{ref:eA.panelRef,className:`right-panel-container${ej?" right-panel-open":" right-panel-closed"}${eA.isResizing?" panel-is-resizing":""}`,style:{display:"flex",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:[(0,r.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,r.jsx)(ih,{tabs:ek,activeTabId:eb??"",onSelectTab:ew,onCloseTab:tn})}),(0,r.jsxs)("button",{type:"button",onClick:()=>eC?eM():eI(),title:p(eC?"desktop.subagentsBackToFiles":"desktop.subagentsViewTitle"),style:{display:"inline-flex",alignItems:"center",gap:5,flexShrink:0,height:28,marginRight:6,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:eC?"var(--bg-selected)":"transparent",color:eC?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:11},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{width:7,height:7,borderRadius:"50%",background:en>0?"var(--accent)":"var(--text-dim)",boxShadow:en>0?"0 0 0 0 var(--accent)":"none",animation:en>0?"subagent-pulse 1.4s ease-out infinite":"none"}}),p(eC?"desktop.subagentsBackToFiles":"desktop.subagentsViewTitle")]})]}),(0,r.jsx)("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",minHeight:0},children:eC?ez?(e=et.find(e=>e.id===ez)??null)?(0,r.jsx)(ig,{agent:e,cwd:eK??g?.cwd??void 0,onBack:()=>eR(null)}):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:p("desktop.subagentsNotFound")}):(0,r.jsx)(id,{subagents:et,selectedId:ez,onSelect:e=>eR(e.id)}):tm?.filePath?(0,r.jsx)(ir,{filePath:tm.filePath,cwd:eK??void 0,sourceSessionId:tm.sourceSessionId,initialDisplayMode:tm.initialDisplayMode,onOpenFile:e=>to(e,X(e),tm.sourceSessionId),onAtMention:eH,onMentionLines:e_}):(0,r.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),P&&td&&(0,r.jsx)(l0,{cwd:td,busy:$,error:W,onCancelAction:()=>{$||D(!1)},onConfirmAction:()=>void tf()}),j&&(0,r.jsx)(lh,{initialTab:C,cwd:tk,sessionId:g?.id??null,onCloseAction:()=>{S(!1),R(e=>e+1)},onModelsSavedAction:()=>R(e=>e+1),onSessionReloadedAction:()=>y(e=>e+1),onSessionsChanged:()=>k(e=>e+1)})]})]})}}},e=>{e.O(0,[7330,711,8441,3794,7358],()=>e(e.s=79023)),_N_E=e.O()}]);
|