@seqyuan/annovibe 0.8.130 → 0.8.134
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 +14 -13
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/routes-manifest.json +8 -0
- package/.next/server/app/_global-error/page.js +2 -2
- 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]/events/route.js +2 -2
- package/.next/server/app/api/agent/[id]/prepare/route.js +1 -1
- 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 +2 -2
- package/.next/server/app/api/agent/running/route.js +1 -1
- package/.next/server/app/api/agent/runtime/route.js +1 -1
- package/.next/server/app/api/apps/[id]/[[...path]]/route.js +2 -2
- package/.next/server/app/api/apps/route.js +2 -2
- 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/login/[provider]/route.js +1 -1
- package/.next/server/app/api/auth/login/route.js +1 -1
- 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/auth/status/route.js +1 -1
- package/.next/server/app/api/auth/totp/route.js +1 -1
- package/.next/server/app/api/debug-models/route.js +1 -1
- package/.next/server/app/api/default-cwd/route.js +1 -1
- package/.next/server/app/api/file-tree/delete/route.js +1 -1
- package/.next/server/app/api/file-tree/mkdir/route.js +1 -1
- package/.next/server/app/api/file-tree/rename/route.js +1 -1
- package/.next/server/app/api/file-tree/reveal/route.js +1 -1
- package/.next/server/app/api/file-tree/write/route.js +1 -1
- package/.next/server/app/api/file-watch/route.js +2 -2
- package/.next/server/app/api/files/[...path]/route.js +1 -1
- package/.next/server/app/api/harness/route.js +1 -1
- package/.next/server/app/api/home/route.js +1 -1
- package/.next/server/app/api/im/cancel/route.js +1 -1
- package/.next/server/app/api/im/gateway-status/route.js +1 -1
- package/.next/server/app/api/im/gateway-token/route.js +1 -1
- package/.next/server/app/api/im/project/route.js +1 -1
- package/.next/server/app/api/im/projects/route.js +1 -1
- package/.next/server/app/api/im/session-ids/route.js +1 -1
- package/.next/server/app/api/im/turn/route.js +2 -2
- package/.next/server/app/api/images/upload/route.js +1 -1
- package/.next/server/app/api/internal/runtime/route.js +1 -1
- package/.next/server/app/api/memory/dismiss/route.js +2 -2
- package/.next/server/app/api/memory/promote/route.js +2 -2
- package/.next/server/app/api/models/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/plot-kernels/route.js +1 -1
- package/.next/server/app/api/plot-kernels/save/route.js +1 -1
- package/.next/server/app/api/plot-kernels/status/route.js +1 -1
- package/.next/server/app/api/plot-kernels/stop/route.js +1 -1
- package/.next/server/app/api/projects/browse/route.js +1 -1
- package/.next/server/app/api/projects/route.js +1 -1
- package/.next/server/app/api/search/route.js +1 -1
- package/.next/server/app/api/session-index/events/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/auto-name/route.js +34 -0
- package/.next/server/app/api/sessions/[id]/auto-name/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/sessions/[id]/context/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/kernel-state/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/shadowed/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/workbench-artifact/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/workbench-review/route.js +1 -1
- package/.next/server/app/api/sessions/new/route.js +1 -1
- package/.next/server/app/api/sessions/route.js +1 -1
- package/.next/server/app/api/settings/route.js +1 -1
- package/.next/server/app/api/skills/install/route.js +2 -2
- 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/smoke/prompt-admission/route.js +1 -1
- package/.next/server/app/api/soul/route.js +1 -1
- package/.next/server/app/api/subagents/status/route.js +1 -1
- package/.next/server/app/api/version/route.js +1 -1
- package/.next/server/app/favicon.ico/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 +3 -3
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +3 -3
- 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/login/page.js +2 -2
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +2 -2
- package/.next/server/app/login.segments/_full.segment.rsc +2 -2
- package/.next/server/app/login.segments/_head.segment.rsc +1 -1
- package/.next/server/app/login.segments/_index.segment.rsc +2 -2
- package/.next/server/app/login.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/login.segments/login.segment.rsc +1 -1
- package/.next/server/app/page.js +7 -7
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke/page.js +3 -3
- package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke/session-stream/page.js +2 -2
- package/.next/server/app/smoke/session-stream/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke/session-stream.html +1 -1
- package/.next/server/app/smoke/session-stream.rsc +2 -2
- package/.next/server/app/smoke/session-stream.segments/_full.segment.rsc +2 -2
- package/.next/server/app/smoke/session-stream.segments/_head.segment.rsc +1 -1
- package/.next/server/app/smoke/session-stream.segments/_index.segment.rsc +2 -2
- package/.next/server/app/smoke/session-stream.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/smoke/session-stream.segments/smoke/session-stream/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/smoke/session-stream.segments/smoke/session-stream.segment.rsc +1 -1
- package/.next/server/app/smoke/session-stream.segments/smoke.segment.rsc +1 -1
- package/.next/server/app/smoke.html +2 -2
- package/.next/server/app/smoke.rsc +2 -2
- package/.next/server/app/smoke.segments/_full.segment.rsc +2 -2
- package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_index.segment.rsc +2 -2
- package/.next/server/app/smoke.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/smoke.segment.rsc +1 -1
- package/.next/server/app-paths-manifest.json +14 -13
- package/.next/server/chunks/402.js +2 -2
- package/.next/server/chunks/6429.js +1 -1
- package/.next/server/chunks/7890.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/next-font-manifest.js +1 -1
- package/.next/server/next-font-manifest.json +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/app/_global-error/page-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/events/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/prepare/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/agent/new/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/agent/running/events/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/agent/running/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/agent/runtime/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/apps/[id]/[[...path]]/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/apps/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/auth/all-providers/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/auth/api-key/[provider]/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/auth/login/[provider]/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/auth/login/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/auth/logout/[provider]/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/auth/providers/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/auth/status/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/auth/totp/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/debug-models/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/default-cwd/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/file-tree/delete/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/file-tree/mkdir/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/file-tree/rename/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/file-tree/reveal/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/file-tree/write/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/file-watch/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/files/[...path]/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/harness/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/home/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/im/cancel/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/im/gateway-status/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/im/gateway-token/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/im/project/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/im/projects/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/im/session-ids/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/im/turn/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/images/upload/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/internal/runtime/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/memory/dismiss/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/memory/promote/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/models/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/models-config/discover/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/models-config/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/models-config/test/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/plot-kernels/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/plot-kernels/save/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/plot-kernels/status/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/plot-kernels/stop/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/projects/browse/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/projects/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/search/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/session-index/events/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/auto-name/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/context/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/kernel-state/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/shadowed/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/workbench-artifact/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/workbench-review/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/new/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/sessions/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/settings/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/skills/install/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/skills/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/skills/search/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/smoke/prompt-admission/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/soul/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/subagents/status/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/api/version/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/favicon.ico/route-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/app/{page-252ec85583b84aaa.js → page-959c2935e21471e4.js} +6 -6
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-c47e15c89def27e4.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-c47e15c89def27e4.js +1 -0
- package/.next/static/css/fdfd4d4bcfae3c6a.css +1 -0
- package/package.json +2 -1
- package/.next/static/chunks/app/_global-error/page-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/events/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/prepare/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/agent/new/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/agent/running/events/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/agent/running/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/agent/runtime/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/apps/[id]/[[...path]]/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/apps/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/auth/all-providers/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/auth/api-key/[provider]/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/auth/login/[provider]/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/auth/login/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/auth/logout/[provider]/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/auth/providers/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/auth/status/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/auth/totp/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/debug-models/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/default-cwd/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/file-tree/delete/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/file-tree/mkdir/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/file-tree/rename/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/file-tree/reveal/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/file-tree/write/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/file-watch/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/files/[...path]/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/harness/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/home/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/im/cancel/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/im/gateway-status/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/im/gateway-token/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/im/project/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/im/projects/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/im/session-ids/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/im/turn/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/images/upload/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/internal/runtime/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/memory/dismiss/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/memory/promote/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/models/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/models-config/discover/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/models-config/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/models-config/test/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/plot-kernels/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/plot-kernels/save/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/plot-kernels/status/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/plot-kernels/stop/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/projects/browse/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/projects/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/search/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/session-index/events/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/context/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/kernel-state/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/shadowed/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/workbench-artifact/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/workbench-review/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/sessions/new/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/sessions/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/settings/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/skills/install/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/skills/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/skills/search/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/smoke/prompt-admission/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/soul/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/subagents/status/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/api/version/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/app/favicon.ico/route-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-12f2c8373df5bb6a.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-12f2c8373df5bb6a.js +0 -1
- package/.next/static/css/98d226d636ddce16.css +0 -1
- /package/.next/static/{pD4GKzugLztRoTHeAKj_C → 2gyhgfAo_GNB2lRPOJwF9}/_buildManifest.js +0 -0
- /package/.next/static/{pD4GKzugLztRoTHeAKj_C → 2gyhgfAo_GNB2lRPOJwF9}/_ssgManifest.js +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{43322:(e,t,r)=>{Promise.resolve().then(r.bind(r,84978))},84978:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>nW});var n=r(95155),i=r(12115),o=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"..."+n+i.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:o,onSelectSession:d}){let[c,u]=(0,i.useState)(""),[p,h]=(0,i.useState)("current"),[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),[b,m]=(0,i.useState)(null),[y,j]=(0,i.useState)(!1),k=(0,i.useRef)(null);if((0,i.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,o]),(0,i.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),m(null),j(!1);return}let n=new AbortController,i=setTimeout(async()=>{v(!0),m(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let i=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();if(o.error)throw Error(o.error);g(o.results??[]),j(o.truncated??!1)}catch(e){"AbortError"!==e.name&&m(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(i),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&o()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:o,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),b&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:b}),w.length>=2&&!f&&!b&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let i=e.toLowerCase().indexOf(r.toLowerCase());return i<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,i),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(i,i+r.length)}),e.slice(i+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${y?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}let d="Home";function c(e){return e instanceof Error?e.message:String(e)}function u(e,t){let r=e.crumbs.findIndex(t=>t.path===e.home);if(-1===r)return e.crumbs;let n=e.crumbs.slice(r+1);return[{name:t,path:e.home},...n]}function p(e){return e.home.includes("\\")?"\\":"/"}function h(e,t,r){let n,i,o=-1===(n="\\"===p(e)?Math.max(t.lastIndexOf("\\"),t.lastIndexOf("/")):t.lastIndexOf("/"))?null:t.slice(0,n+1);if(null===o)return{directory:null,tail:null};let l=o===(i=p(e),e.current.endsWith(i)?e.current:`${e.current}${i}`)||null!==r&&r.directory===o&&r.landed===e.current;return{directory:o,tail:l?t.slice(o.length):null}}let x={display:"flex",flexDirection:"column",gap:2,flex:"1 1 0",minWidth:256,overflowY:"auto",paddingRight:8},g={width:"100%",display:"flex",alignItems:"center",gap:5,height:28,flex:"none",padding:"0 6px",border:"none",borderRadius:6,background:"transparent",textAlign:"left",cursor:"pointer",color:"var(--text)",fontSize:12.5,fontFamily:"inherit"},f={background:"var(--bg-selected)"},v={flex:"1 1 0",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12.5};function b({entries:e,selectedPath:t,busy:r,onPick:i,showHidden:o,filterPrefix:l}){let s,a,d,c=(s=null===l?"":l.toLowerCase(),a=e=>(o||!e.hidden||s.startsWith("."))&&e.name.toLowerCase().startsWith(s),d=""!==s&&e.some(a),e.filter(e=>e.path===t||(d?a(e):o||!e.hidden)));return(0,n.jsx)("div",{style:x,role:"list",children:c.map(e=>{let o=e.path===t;return(0,n.jsxs)("button",{type:"button",role:"listitem","aria-current":o||void 0,disabled:r,onClick:()=>i(e),title:e.path,style:{...g,...o?f:null},children:[(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:o?"var(--accent)":"var(--text-muted)"},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:v,children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path)})})}function m({open:e,initialPath:t,onClose:r,onSelect:o}){let[l,s]=(0,i.useState)(null),[a,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[v,y]=(0,i.useState)(!1),[j,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)(0),[C,T]=(0,i.useState)(null),[z,I]=(0,i.useState)(null),[R,M]=(0,i.useState)(!1),[W,L]=(0,i.useState)(null),[E,$]=(0,i.useState)(!1),[P,D]=(0,i.useState)(null),B=(0,i.useRef)(0),O=(0,i.useRef)(null),N=(0,i.useRef)(0),A=(0,i.useRef)(!1),H=(0,i.useRef)(!1),F=(0,i.useRef)(null),U=(0,i.useRef)({parent:null,child:null}),_=(0,i.useRef)(null),K=(0,i.useRef)(null);(0,i.useEffect)(()=>{U.current={parent:l,child:g}},[l,g]),(0,i.useEffect)(()=>()=>{B.current+=1,N.current+=1,O.current?.abort()},[]);let J=(0,i.useCallback)((e,t)=>fetch(e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",{signal:t}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);return t}),[]),q=(0,i.useCallback)(()=>(O.current?.abort(),O.current=null,++B.current),[]),V=(0,i.useCallback)(()=>{k(!1),S(e=>e+1)},[]),Y=(0,i.useCallback)(e=>{let t=q(),r=new AbortController;return O.current=r,V(),{seq:t,scan:J(e,r.signal)}},[q,V,J]),G=(0,i.useCallback)(e=>{let t=new AbortController;return O.current=t,V(),J(e,t.signal)},[V,J]),Z=(0,i.useCallback)((e,t)=>{let r=t?.closeEditor??!1,n=t?.announce??!1,{seq:i,scan:o}=Y(e);y(!0),n&&T(null);let l=()=>{(y(!1),r)?I(null):T(null)};o.then(t=>{if(i!==B.current)return;r||void 0===e||(F.current={directory:e,landed:t.current});let n=!1,o=()=>{n||i!==B.current||(n=!0,s(t),x(null),f(null),l())};if(u(t,"").length<2)return void o();let a=t.crumbs.at(-2);void 0===a?o():(G(a.path).then(e=>{if(i!==B.current)return;let r=p(e),a=e=>"\\"===r?e.toLowerCase():e,d=e.directories.find(e=>a(e.path)===a(t.current));void 0===d?o():(n=!0,s(e),x(d),f(t),l())},()=>{o()}),r&&window.setTimeout(o,200))},e=>{i===B.current&&(y(!1),n&&T(c(e)))})},[Y,G]),X=(0,i.useCallback)(e=>{Z(e,{closeEditor:!0,announce:!0})},[Z]),Q=(0,i.useCallback)(e=>{let{seq:t,scan:r}=Y(e.path);null!==z&&I(null),x(e),f(null),y(!0),T(null),r.then(e=>{t===B.current&&(f(e),y(!1))},e=>{t===B.current&&(y(!1),T(c(e)),x(null))})},[Y,z]),ee=(0,i.useCallback)(e=>{null!==g&&(s(g),Q(e))},[g,Q]),et=(0,i.useCallback)(e=>{Z(e,{closeEditor:!1,announce:!1})},[Z]),er=(0,i.useCallback)(()=>{q(),y(!1),I(null),T(null),null===g&&x(null),null===l&&X()},[q,g,l,X]);(0,i.useEffect)(()=>{if(N.current+=1,e){s(null),x(null),f(null),$(!1),M(!1),X(t??void 0);return}q(),y(!1),T(null),I(null),L(null),D(null)},[e,X,q,t]),(0,i.useEffect)(()=>{if(!v)return void k(!1);let e=window.setTimeout(()=>{k(!0)},300);return()=>{window.clearTimeout(e)}},[v,w]),(0,i.useEffect)(()=>{if(null===z)return;let e=window.setTimeout(()=>{if(H.current)return;let e=U.current.child??U.current.parent;if(null===e)return;let{directory:t,tail:r}=h(e,z,F.current);null!==t&&null===r&&et(t)},250);return()=>{window.clearTimeout(e)}},[z,et]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{if("Escape"===e.key){if(null!==W){E||L(null);return}if(null!==z){e.stopPropagation(),er();return}r()}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e,z,W,E,er]);let en=g??l,ei=null===en?[]:u(en,d),eo=ei.at(-1)?.path,el=g?.current,es=a?.path??l?.current??null;(0,i.useEffect)(()=>{let e=_.current;null!==e&&(e.scrollLeft=e.scrollWidth)},[eo]),(0,i.useEffect)(()=>{let e=K.current;null!==e&&void 0!==el&&(e.scrollLeft=e.scrollWidth)},[el]);let ea=(0,i.useCallback)(()=>{if(null===es||null===W||E||""===W.trim())return;$(!0),D(null);let e=N.current;fetch("/api/projects/browse",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:es,name:W})}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);if("string"!=typeof t.path)throw Error("No path returned");return t.path}).then(t=>{if(e!==N.current)return;$(!1),L(null);let{seq:r,scan:n}=Y(es);y(!0),T(null),n.then(e=>{r===B.current&&(s(e),y(!1),Q({name:W,path:t,hidden:W.startsWith(".")}))},e=>{r===B.current&&(y(!1),T(c(e)))})},t=>{e===N.current&&($(!1),D(c(t)))})},[es,W,E,Y,Q]),ed={onCompositionStart:()=>{A.current=!0},onCompositionEnd:()=>{A.current=!1}};if(!e)return null;let ec=null!==a,eu=null===en||null===z?null:h(en,z,F.current).tail,ep=a?.name??(null===l?"":u(l,d).at(-1)?.name??l.current),eh=null!==W||E,ex=null!==z,eg=en?.drives??[],ef=en?p(en):"/";return(0,n.jsxs)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:[(0,n.jsxs)("div",{style:{width:"min(680px, 100%)",height:"min(500px, calc(100dvh - 32px))",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,flex:"none",padding:"16px 14px 8px 24px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",minHeight:24},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700},children:"Select project path"}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:18,lineHeight:1},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:"\xd7"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,boxSizing:"border-box",minHeight:26,marginLeft:-9,padding:"0 8px",border:`1px solid ${null!==z?"var(--border)":"transparent"}`,borderRadius:8},children:[eg.length>0&&(0,n.jsxs)("select",{value:eg.find(e=>(en?.current??"").toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&X(e.target.value)},disabled:eh,title:"Drive",style:{height:24,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:11,maxWidth:72},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),eg.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),null===z?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{ref:_,role:"navigation",style:{display:"flex",alignItems:"center",gap:4,flex:"0 1 auto",minWidth:0,overflowX:"auto",scrollbarWidth:"none"},children:ei.map((e,t)=>(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,flex:"none",minWidth:0},children:[t>0&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})}),(0,n.jsx)("button",{type:"button",disabled:eh,onClick:()=>X(e.path),title:e.path,style:{border:"none",background:"transparent",padding:0,maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-muted)",cursor:"pointer"},children:e.name})]},e.path))}),(0,n.jsx)("button",{type:"button","aria-label":"Edit path",title:"Edit path",disabled:eh,onClick:()=>{if(q(),y(!1),H.current=!1,null===l)return void I("");let e=a?.path??l.current;I(e.endsWith(ef)?e:`${e}${ef}`)},style:{display:"flex",alignItems:"center",justifyContent:"flex-end",flex:"1 0 34px",minWidth:34,height:22,padding:0,border:"none",background:"transparent",cursor:"text"},children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:(0,n.jsx)("path",{d:"M11.3 2.2a1.9 1.9 0 0 1 2.5 2.5L6 12.5 2.5 13.5 3.5 10l7.8-7.8Z"})})})]}):(0,n.jsx)("input",{value:z,autoFocus:!0,"aria-label":"Edit path",disabled:eh,spellCheck:!1,onChange:e=>{q(),y(!1),H.current=!1,I(e.target.value)},...ed,onKeyDown:e=>{"Enter"!==e.key||A.current||(e.preventDefault(),""!==z.trim()&&(H.current=!0,X(z)))},onBlur:e=>{if(null===z||!document.hasFocus())return;let t=e.currentTarget.closest('[role="dialog"]');null===t||e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||er()},style:{boxSizing:"border-box",flex:"1 1 0",minWidth:0,height:22,padding:0,border:"none",outline:"none",background:"transparent",fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)"}})]})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:"1 1 0",minHeight:0,position:"relative",padding:"16px 16px 16px 24px"},children:[(0,n.jsxs)("div",{ref:K,style:{display:"flex",alignItems:"stretch",flex:"1 1 0",minHeight:0,gap:12,overflowX:"auto",scrollbarWidth:"none"},children:[null!==l&&(0,n.jsx)(b,{entries:l.directories,selectedPath:a?.path??null,busy:eh,onPick:Q,showHidden:R,filterPrefix:null===g?eu:null}),ec&&(0,n.jsx)("span",{style:{flex:"none",width:1,background:"var(--border)"}}),ec&&null!==g&&(0,n.jsx)(b,{entries:g.directories,selectedPath:null,busy:eh,onPick:ee,showHidden:R,filterPrefix:eu})]}),v&&j&&(0,n.jsx)("div",{role:"status",style:{position:"absolute",right:16,bottom:8,padding:"2px 8px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",fontSize:11},children:"Loading…"}),(l?.truncated===!0||g?.truncated===!0)&&(0,n.jsx)("div",{role:"status",style:{padding:"4px 4px 4px 0",color:"var(--text-muted)",fontSize:11},children:"Large directory — list may be incomplete"}),null!==C&&(0,n.jsx)("div",{role:"alert",style:{padding:"4px 4px 4px 0",color:"#f87171",fontSize:11},children:C})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,flex:"none",padding:"14px 24px",borderTop:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",disabled:null===l||v||eh||ex,onClick:()=>{L(""),D(null)},style:{display:"inline-flex",alignItems:"center",gap:5,height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:null===l||v||eh||ex?"var(--text-dim)":"var(--text-muted)",cursor:null===l||v||eh||ex?"default":"pointer",fontSize:12},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M8 3v10M3 8h10"})}),"New folder"]}),(0,n.jsxs)("button",{type:"button","aria-pressed":R,disabled:eh,onClick:()=>M(e=>!e),style:{display:"inline-flex",alignItems:"center",gap:4,border:"none",background:"transparent",padding:0,fontSize:12,fontWeight:500,color:R?"var(--text)":"var(--text-muted)",cursor:"pointer",whiteSpace:"nowrap"},children:["Show hidden files",R&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2.5 8.5 6 12 13.5 4.5"})})]}),(0,n.jsx)("div",{style:{flex:"1 1 0"}}),(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",disabled:null===es||v||eh||ex,onClick:()=>{null!==es&&o(es)},style:{height:32,padding:"0 14px",border:"none",borderRadius:6,background:null===es||v||eh||ex?"var(--bg-hover)":"var(--accent)",color:null===es||v||eh||ex?"var(--text-dim)":"#fff",cursor:null===es||v||eh||ex?"default":"pointer",fontSize:12,fontWeight:650},children:"Open"})]})]}),null!==W&&(0,n.jsx)("div",{onMouseDown:e=>{e.target!==e.currentTarget||E||L(null)},style:{position:"fixed",inset:0,zIndex:1300,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.25)"},children:(0,n.jsxs)("div",{style:{width:"min(380px, 100%)",display:"flex",flexDirection:"column",gap:12,padding:"20px 24px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.3)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700},children:"New folder"}),(0,n.jsxs)("div",{style:{color:"var(--text)",fontSize:12.5},children:["in ",(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text-muted)"},children:ep})]}),(0,n.jsx)("input",{value:W,"aria-label":"Folder name",placeholder:"untitled folder",autoFocus:!0,disabled:E,spellCheck:!1,onChange:e=>L(e.target.value),...ed,onKeyDown:e=>{"Enter"!==e.key||A.current||(e.preventDefault(),ea()),"Escape"!==e.key||E||(e.stopPropagation(),L(null))},style:{boxSizing:"border-box",width:"100%",height:36,padding:"0 12px",border:"1px solid var(--border)",borderRadius:8,outline:"none",background:"var(--bg-panel)",fontSize:13,color:"var(--text)"}}),null!==P&&(0,n.jsx)("div",{role:"alert",style:{color:"#f87171",fontSize:11},children:P}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{type:"button",disabled:E,onClick:()=>L(null),style:{height:30,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",disabled:E||""===W.trim(),onClick:ea,style:{height:30,padding:"0 14px",border:"none",borderRadius:6,background:E||""===W.trim()?"var(--bg-hover)":"var(--accent)",color:E||""===W.trim()?"var(--text-dim)":"#fff",cursor:E||""===W.trim()?"default":"pointer",fontSize:12,fontWeight:650},children:E?"Creating…":"Create"})]})]})})]})}let y="AnnoVibe";var j=r(16865);let k="annovibe:sidebar:collapsed-projects",w="annovibe:sidebar:collapsed-projects:init-v3";function S(e){window.localStorage.setItem(k,JSON.stringify([...e]))}async function C(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function T(e){return new DOMException(e,"TimeoutError")}function z(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}function I(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function R(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"…/"+i.slice(-2).join(n)}function M(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||R(e,t)}function W(e){return e+.2*e*(2*Math.random()-1)}let L="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function E(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),s=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:L[Math.floor(Math.random()*L.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"v0.8.130":y,r),a=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function $({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:o,initialSessionId:l,onInitialRestoreDone:s,refreshKey:d,onSessionDeleted:c,selectedCwd:u,onCwdChange:p}){let[h,x]=(0,i.useState)([]),[g,f]=(0,i.useState)({}),[v,b]=(0,i.useState)(()=>new Set),y=(0,i.useRef)(!1),[I,L]=(0,i.useState)(!0),[A,H]=(0,i.useState)(!1),[F,U]=(0,i.useState)(null),[_,K]=(0,i.useState)(null),[J,q]=(0,i.useState)(""),[V,Y]=(0,i.useState)(null),[G,Z]=(0,i.useState)(!1),[X,Q]=(0,i.useState)("project"),[ee,et]=(0,i.useState)(null),[er,en]=(0,i.useState)(!1),[ei,eo]=(0,i.useState)(!1),[el,es]=(0,i.useState)(()=>new Set),[ea,ed]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(k)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[ec,eu]=(0,i.useState)(null),[ep,eh]=(0,i.useState)(null),[ex,eg]=(0,i.useState)(null),[ef,ev]=(0,i.useState)(!1),eb=(0,i.useRef)(null),em=(0,i.useRef)(!1),ey=(0,i.useRef)(!1),ej=(0,i.useRef)(!1),ek=(0,i.useRef)(new Map),ew=(0,i.useRef)({revision:null,seq:0,retry:0,inFlight:!1}),eS=(0,i.useRef)({}),eC=(0,i.useRef)({}),eT=(0,i.useRef)({}),ez=(0,i.useRef)(new Set);function eI(e){let t=eS.current[e];return t||(t={revision:null,seq:0,retry:0,inFlight:!1},eS.current[e]=t),t}let eR=(0,i.useCallback)((e,t,r)=>{let n=eC.current[e];n&&clearTimeout(n),eC.current[e]=setTimeout(()=>{eC.current[e]=null,r()},Math.random()*([250,500,1e3,2e3][Math.min(Math.max(t,0),3)]??2e3))},[]),eM=(0,i.useCallback)((e,t)=>{let r=eT.current[e];r&&clearTimeout(r),eT.current[e]=setTimeout(()=>{eT.current[e]=null,t()},120)},[]),eW=(0,i.useCallback)(async(e=!1,t={})=>{let r=ew.current,n=++r.seq;r.inFlight=!0;try{let i;e&&L(!0);let o=new AbortController;try{i=setTimeout(()=>o.abort(T("Project loading timed out")),6e4);let e=t.force?"/api/projects?force=1":"/api/projects",l=await fetch(e,{signal:o.signal});if(!l.ok)throw Error(await C("projects",l));let s=await l.json();if(n!==r.seq)return;if(s.stale)return void eR("projects",r.retry++,()=>void eW(!1));r.retry=0,s.revision&&(r.revision=s.revision),x(s.projects),U(null)}finally{clearTimeout(i)}}catch(e){if(n!==r.seq)return;U(z(e,"Loading projects timed out. Codex may still be starting; click Refresh to retry.")),eR("projects",r.retry++,()=>void eW(!1))}finally{n===r.seq&&(r.inFlight=!1),e&&L(!1)}},[eR]),eL=(0,i.useCallback)(async(e,t=!1,r={})=>{if(!e)return;let n=ek.current.get(e);if(n)return n;let i=(async()=>{let n=eI(e),i=++n.seq;n.inFlight=!0,f(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{let o;t&&L(!0);let l=new AbortController;try{o=setTimeout(()=>l.abort(T("Chat loading timed out")),6e4);let t=r.force?`/api/sessions?cwd=${encodeURIComponent(e)}&force=1`:`/api/sessions?cwd=${encodeURIComponent(e)}`,s=await fetch(t,{signal:l.signal});if(!s.ok)throw Error(await C("sessions",s));let a=await s.json();if(i!==n.seq)return;if(a.runningSessionIds&&!y.current&&b(new Set(a.runningSessionIds)),a.stale){f(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,loading:!1,error:null,stale:(t[e]?.sessions?.length??0)>0}})),eR(`cwd:${e}`,n.retry++,()=>void eL(e,!1));return}n.retry=0,a.revision&&(n.revision=a.revision),ez.current.add(e),f(t=>({...t,[e]:{sessions:a.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(o)}}catch(r){if(i!==n.seq)return;let t=z(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");f(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}})),eR(`cwd:${e}`,n.retry++,()=>void eL(e,!1))}finally{i===n.seq&&(n.inFlight=!1),t&&L(!1),ek.current.delete(e)}})();return ek.current.set(e,i),i},[eR]),eE=(0,i.useCallback)(async()=>{let e=ew.current;if(e.inFlight)return;let t=e.revision?`/api/projects?fingerprint=1&revision=${encodeURIComponent(e.revision)}`:"/api/projects?fingerprint=1";try{let r=await fetch(t);if(!r.ok)throw Error(await C("projects",r));let n=await r.json();if(n.stale)return void eR("projects",e.retry++,()=>void eE());if(!0===n.unchanged)return;eW(!1)}catch{eR("projects",e.retry++,()=>void eE())}},[eW,eR]),e$=(0,i.useCallback)(async e=>{let t=eI(e);if(t.inFlight)return;let r=t.revision?`/api/sessions?cwd=${encodeURIComponent(e)}&fingerprint=1&revision=${encodeURIComponent(t.revision)}`:`/api/sessions?cwd=${encodeURIComponent(e)}&fingerprint=1`;try{let n=await fetch(r);if(!n.ok)throw Error(await C("sessions",n));let i=await n.json();if(i.stale)return void eR(`cwd:${e}`,t.retry++,()=>void e$(e));if(!0===i.unchanged)return;eL(e,!1)}catch{eR(`cwd:${e}`,t.retry++,()=>void e$(e))}},[eL,eR]),eP=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eP.current;eP.current=!0,eW(e)},[eW,d]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&q(e.home)}).catch(()=>{})},[]);let eD=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(em.current){em.current=!1;return}if(ey.current){ey.current=!1;return}p?.(_)},[_,p]);let eB=(0,i.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return Y(n.error??`HTTP ${r.status}`),null;return eW(!1),n.project?.cwd??e}catch(e){return Y(e instanceof Error?e.message:String(e)),null}},[eW]),eO=(0,i.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eN=(0,i.useCallback)(e=>{ey.current=!0,K(e),Y(null),ed(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),S(r),r}),p?.(e),eO(e),eL(e,!1)},[eL,p,eO]);(0,i.useEffect)(()=>{if(0!==h.length&&null===_){if(l&&!eD.current){eD.current=!0;let e=Object.values(g).flatMap(e=>e.sessions).find(e=>e.id===l);if(e){K(e.cwd),eO(e.cwd),t(e,!0);return}fetch(`/api/sessions/${encodeURIComponent(l)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(e=>{e?.info?(K(e.info.cwd),eO(e.info.cwd),t(e.info,!0)):s?.()}).catch(()=>s?.());return}let e=h[0]?.cwd;e&&(K(e),eO(e))}},[h,_,l,t,s,g,eO]);let eA=u??_;(0,i.useEffect)(()=>(0,j.O)(e=>{y.current=!0,b(new Set(e))}),[]);let eH=(0,i.useRef)(null);(0,i.useEffect)(()=>{eH.current=eA},[eA]),(0,i.useEffect)(()=>{let e=new EventSource("/api/session-index/events");return e.onmessage=e=>{let t=null;try{t=JSON.parse(String(e.data))}catch{return}if(t&&"index-invalidated"===t.type&&t.scope){if(("projects"===t.scope||"all-cwds"===t.scope)&&eM("projects",()=>void eE()),"cwd"===t.scope&&t.cwd){let e=t.cwd;eM(`cwd:${e}`,()=>void e$(e))}if("all-cwds"===t.scope)for(let e of ez.current)eM(`cwd:${e}`,()=>void e$(e))}},e.onerror=()=>{},()=>e.close()},[eE,e$,eM]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{eE()},W(3e4));return()=>window.clearInterval(e)},[eE]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{let e=new Set;for(let t of(eH.current&&e.add(eH.current),ez.current))e.add(t);for(let t of e)e$(t)},W(1e4));return()=>window.clearInterval(e)},[e$]),(0,i.useEffect)(()=>{let e=()=>{if("visible"!==document.visibilityState)return;eE();let e=new Set;for(let t of(eH.current&&e.add(eH.current),ez.current))e.add(t);for(let t of e)e$(t)};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[eE,e$]),(0,i.useEffect)(()=>{let e=()=>{eA&&eL(eA,!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eA,eL]);let eF=(0,i.useCallback)(e=>{if(!e){Q("agent"),Z(!0);return}let t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(t,e)},[r]),eU=(0,i.useCallback)(e=>{if(!e){Q("workbench"),Z(!0);return}o?.(e)},[o]),e_=(0,i.useCallback)(async e=>{let t=await eB(e,!0);t&&(eN(t),Z(!1),Y(null),"agent"===X&&eF(t),"workbench"===X&&eU(t))},[eN,eF,eU,X,eB]),eK=(0,i.useCallback)(e=>{et(e),en(!0)},[]),eJ=(0,i.useCallback)(()=>{en(!1),et(null)},[]),eq=(0,i.useCallback)(e=>{let t=ee??eA;eJ(),"agent"===e?eF(t):eU(t)},[eJ,eF,eU,eA,ee]),eV=(0,i.useCallback)(()=>{eK(eA)},[eA,eK]),eY=(0,i.useCallback)(()=>{Q("project"),Y(null),Z(!0)},[]),eG=(0,i.useMemo)(()=>[...eA&&!h.some(e=>e.cwd===eA)?[{cwd:eA,displayName:M(eA,J),chatCount:g[eA]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...h].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,i="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==i?n-i:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[eA,J,h,g]),eZ=(0,i.useMemo)(()=>{let e=e=>{var t,r;let n,i,o=g[e.cwd],l=[...o?.sessions??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||"")),s=o?.loaded?o.sessions.length:e.chatCount,a=(t=e.lastAccessed,r=o?.loaded?o.sessions[0]?.modified:null,n=t?new Date(t).getTime():-1/0,i=r?new Date(r).getTime():-1/0,Number.isFinite(n)||Number.isFinite(i)?n>=i?t??null:r??null:null);return{project:e,cwd:e.cwd,displayName:e.displayName||M(e.cwd,J),sessions:l,sessionsState:o,chatCount:s??0,lastAccessed:a??""}},t=eG.filter(e=>!0===e.pinned).map(e);if(eA){let r=eG.find(e=>e.cwd===eA);r&&!0!==r.pinned&&t.push(e(r))}return t},[eA,J,g,eG]);(0,i.useEffect)(()=>{if(0===eZ.length||ej.current||(ej.current=!0,!eZ[0]?.cwd||window.localStorage.getItem(w)))return;let e=new Set(eZ.slice(1).map(e=>e.cwd));ed(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(S(e),e):t),window.localStorage.setItem(w,"1")},[eZ]);let eX=(0,i.useCallback)((e,r=!1)=>{e.cwd!==eA&&(em.current=!0,K(e.cwd)),ed(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),S(r),r}),eO(e.cwd),t(e,r)},[t,eA,eO]),eQ=(0,i.useCallback)(e=>{ed(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),S(r),r})},[]);(0,i.useEffect)(()=>{for(let e of eZ){let t=g[e.cwd];if(!t?.loaded&&!t?.loading){let t=e.cwd===eA,r=ea.has(e.cwd);if(!t&&r)continue;eL(e.cwd,!1)}}},[ea,eA,eL,eZ,g]);let e0=(0,i.useCallback)(e=>{es(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),e1=(0,i.useCallback)(async e=>{eg("reorder");try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);U(null),eW(!1)}catch(e){U(e instanceof Error?e.message:String(e)),eW(!1)}finally{eg(null)}},[eW]),e2=(0,i.useCallback)(async(e,t)=>{eg(`pin:${e}`);try{let r=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,pinned:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);U(null),eW(!1)}catch(e){U(e instanceof Error?e.message:String(e)),eW(!1)}finally{eg(null)}},[eW]),e5=(0,i.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eG.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),i=r.indexOf(t);if(-1===n||-1===i)return;let o=[...r];o.splice(n,1);let l=o.indexOf(t);o.splice(l,0,e),e1(o)},[e1,eG]),e4=(0,i.useCallback)(async()=>{H(!0);try{await eW(!1,{force:!0});let e=new Set([...Object.entries(g).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eA?[eA]:[]]);await Promise.all([...e].map(e=>eL(e,!1,{force:!0})))}finally{H(!1)}},[eA,eW,eL,g]);return(0,i.useEffect)(()=>{if(!ef)return;let e=e=>{eb.current&&!eb.current.contains(e.target)&&ev(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[ef]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)(E,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eV,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:eA?`New chat in ${eA}`:"New chat in a project path",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New Chat"]}),(0,n.jsx)("button",{onClick:()=>eo(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,n.jsx)(a,{open:ei,cwd:eA,homeDir:J,onClose:()=>eo(!1),onSelectSession:e=>{eX(e)}}),(0,n.jsxs)("div",{ref:eb,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>ev(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eA?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eA?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eA??"Select project",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:eA?"var(--text)":"var(--text-dim)"},children:eA?eG.find(e=>e.cwd===eA)?.displayName??R(eA,J):"Select project…"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:ef?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eA&&(0,n.jsx)(D,{pinned:eG.find(e=>e.cwd===eA)?.pinned===!0,onToggle:()=>void e2(eA,eG.find(e=>e.cwd===eA)?.pinned!==!0)}),ef&&(0,n.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:10,right:10,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===eG.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eG.map(e=>{let t=e.cwd===eA;return(0,n.jsx)(B,{project:e,homeDir:J,isCurrent:t,onSelect:()=>{eN(e.cwd),ev(!1)},onTogglePinned:()=>void e2(e.cwd,!0!==e.pinned)},e.cwd)})]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,n.jsx)("button",{type:"button",onClick:e4,disabled:A,title:"Refresh projects and chats","aria-label":"Refresh projects and chats",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:A?"var(--accent)":"var(--text-dim)",cursor:A?"default":"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:A?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsx)("button",{type:"button",onClick:eY,title:"New project","aria-label":"New project",style:{width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:"50%",background:"transparent",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="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",style:{flexShrink:0,display:"block"},children:[(0,n.jsx)("path",{transform:"translate(9.52 2.52)",d:"M3.55246 0L3.55246 2.44252L6 2.44252L6 3.55748L3.55246 3.55748L3.55246 6L2.43834 6L2.43834 3.55748L0 3.55748L0 2.44252L2.43834 2.44252L2.43834 0L3.55246 0Z",fill:"currentColor"}),(0,n.jsx)("path",{transform:"translate(0.3496 2.35)",d:"M4.76367 0C5.36861 1.80598e-05 5.93113 0.310294 6.25488 0.821289L6.78027 1.64941C6.79685 1.67558 6.81791 1.69775 6.83887 1.71973C6.72186 2.15521 6.65702 2.61192 6.65137 3.08301C6.25601 2.96045 5.90909 2.70478 5.68164 2.3457L5.15723 1.5166C5.07183 1.38189 4.92318 1.3008 4.76367 1.30078L2.32422 1.30078C1.7589 1.30078 1.30078 1.7589 1.30078 2.32422L1.30078 10.1338C1.30078 10.6991 1.7589 11.1572 2.32422 11.1572L11.9766 11.1572C12.5419 11.1572 13 10.6991 13 10.1338L13 8.58398C13.4545 8.5135 13.8903 8.38748 14.3008 8.21289L14.3008 10.1338C14.3008 11.4171 13.2598 12.458 11.9766 12.458L2.32422 12.458C1.04093 12.458 0 11.4171 0 10.1338L0 2.32422C0 1.04093 1.04093 0 2.32422 0L4.76367 0Z",fill:"currentColor"})]})})]})]}),V&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:V})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[I&&0===h.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading…"}),F&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:F}),!I&&!F&&0===eZ.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!I&&!F&&eZ.map(t=>{let r,i=ea.has(t.cwd),o=t.cwd===eA,l=el.has(t.cwd),s=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>i(e.children))};return i(n),n}(t.sessions),a=s.length,d=s;if(a>10&&!l){d=s.slice(0,10);let t=s.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!d.includes(t)&&(d=[...d,t])}let u=a-d.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:ep===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ep===t.cwd),opacity:ec===t.cwd?.55:1},onDragOver:e=>{ec&&ec!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eh(t.cwd))},onDragLeave:()=>{ep===t.cwd&&eh(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||ec;eh(null),eu(null),r&&e5(r,t.cwd)},children:[(0,n.jsx)(O,{group:t,isCurrent:o,isCollapsed:i,isDragging:ec===t.cwd,pinBusy:ex===`pin:${t.cwd}`,onToggle:()=>eQ(t.cwd),onSelect:()=>eN(t.cwd),onTogglePinned:()=>void e2(t.cwd,!0!==t.project.pinned),onDragStart:e=>{eu(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{eu(null),eh(null)}}),!i&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(r=t.sessionsState,r?.loading&&!r?.loaded?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):r?.error&&!r?.stale?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:r.error}):0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,n.jsxs)(n.Fragment,{children:[r?.stale&&(0,n.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),d.map(r=>(0,n.jsx)(N,{node:r,selectedSessionId:e,onSelectSession:eX,onRenamed:()=>void eL(t.cwd,!1),onSessionDeleted:e=>{c?.(e),eL(t.cwd,!1)},depth:0,runningSessionIds:v},r.session.id))]})),(l||u>0)&&a>10&&(0,n.jsx)("button",{type:"button",onClick:()=>e0(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:l?"Show less":`Show ${Math.max(0,u)} more`})]})]},t.cwd||"__no_project")})]}),er&&(0,n.jsx)(P,{cwd:ee,onChoose:eq,onClose:eJ}),(0,n.jsx)(m,{open:G,initialPath:eA,onClose:()=>Z(!1),onSelect:e=>e_(e)})]})}function P({cwd:e,onChoose:t,onClose:r}){let i=e?M(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function D({pinned:e,onToggle:t}){return(0,n.jsx)("button",{type:"button",onClick:t,title:e?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:e?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:e?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function B({project:e,homeDir:t,isCurrent:r,onSelect:o,onTogglePinned:l}){let[s,a]=(0,i.useState)(!1),d=e.displayName||M(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:o,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:s?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!s,pointerEvents:s?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function O({group:e,isCurrent:t,isCollapsed:r,isDragging:o,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:u}){let[p,h]=(0,i.useState)(!1),x=e.lastAccessed,g=Math.max(0,e.chatCount??0),f=!0===e.project.pinned,v=(0,i.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:v,onDragStart:c,onDragEnd:u,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),v())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:o?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:o?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!p&&g>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[g," ",1===g?"chat":"chats"]}),!p&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:I(x)}),f?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:p?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!p,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:p?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function N({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s,runningSessionIds:a}){let[d,c]=(0,i.useState)(!1),u=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(A,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:o,onDeleted:e=>l?.(e),depth:s,hasChildren:u,collapsed:d,onToggleCollapse:()=>c(e=>!e),isRunning:a.has(e.session.id)})]}),u&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(N,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s+1,runningSessionIds:a},e.session.id))})]})}function A({session:e,isSelected:t,onClick:r,onRenamed:o,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c,isRunning:u=!1}){let[p,h]=(0,i.useState)(!1),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[b,m]=(0,i.useState)(!1),[y,j]=(0,i.useState)(!1),k=(0,i.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,i.useCallback)(t=>{t.stopPropagation(),v(e.name??""),g(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),C=(0,i.useCallback)(async()=>{let t=f.trim();if(g(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),o?.()}catch{}},[f,e.id,e.name,o]),T=(0,i.useCallback)(e=>{e.stopPropagation(),m(!0)},[]),z=(0,i.useCallback)(async t=>{t.stopPropagation(),m(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),R=(0,i.useCallback)(e=>{e.stopPropagation(),m(!1)},[]),M="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:b||x?void 0:r,onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:b||x?"default":"pointer",background:b?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:b?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:y?.5:1,gap:6,overflow:"hidden"},children:b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",w.slice(0,22),w.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:z,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:R,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):x?(0,n.jsx)("input",{ref:k,value:f,onChange:e=>v(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&g(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:u?7:5,height:u?7:5,borderRadius:"50%",background:u?"#22c55e":t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0,...u?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),M&&(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:M?"var(--accent)":"var(--text)"},title:w,children:w}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:I(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),a&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),p&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:S,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:T,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var H=r(94456),F=r(14755);let U=new Map,_=["off","default","full","agent"],K={off:"none",default:"default",full:"full",agent:"agent"},J={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},q={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},V=["auto","off","minimal","low","medium","high","xhigh"],Y={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},G=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function Z({doc:e,onRemove:t}){var r;let i=e.fileName.split(".").pop()?.toLowerCase()??"",o=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(i),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:o.color,fontSize:14,flexShrink:0},children:o.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[i.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function X(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function Q(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,i=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&i.push(`Page ${e}
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{43322:(e,t,r)=>{Promise.resolve().then(r.bind(r,84978))},84978:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>nW});var n=r(95155),i=r(12115),o=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"..."+n+i.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:o,onSelectSession:d}){let[c,u]=(0,i.useState)(""),[p,h]=(0,i.useState)("current"),[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),[b,m]=(0,i.useState)(null),[y,j]=(0,i.useState)(!1),k=(0,i.useRef)(null);if((0,i.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,o]),(0,i.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),m(null),j(!1);return}let n=new AbortController,i=setTimeout(async()=>{v(!0),m(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let i=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();if(o.error)throw Error(o.error);g(o.results??[]),j(o.truncated??!1)}catch(e){"AbortError"!==e.name&&m(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(i),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&o()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:o,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),b&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:b}),w.length>=2&&!f&&!b&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let i=e.toLowerCase().indexOf(r.toLowerCase());return i<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,i),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(i,i+r.length)}),e.slice(i+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${y?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}let d="Home";function c(e){return e instanceof Error?e.message:String(e)}function u(e,t){let r=e.crumbs.findIndex(t=>t.path===e.home);if(-1===r)return e.crumbs;let n=e.crumbs.slice(r+1);return[{name:t,path:e.home},...n]}function p(e){return e.home.includes("\\")?"\\":"/"}function h(e,t,r){let n,i,o=-1===(n="\\"===p(e)?Math.max(t.lastIndexOf("\\"),t.lastIndexOf("/")):t.lastIndexOf("/"))?null:t.slice(0,n+1);if(null===o)return{directory:null,tail:null};let l=o===(i=p(e),e.current.endsWith(i)?e.current:`${e.current}${i}`)||null!==r&&r.directory===o&&r.landed===e.current;return{directory:o,tail:l?t.slice(o.length):null}}let x={display:"flex",flexDirection:"column",gap:2,flex:"1 1 0",minWidth:256,overflowY:"auto",paddingRight:8},g={width:"100%",display:"flex",alignItems:"center",gap:5,height:28,flex:"none",padding:"0 6px",border:"none",borderRadius:6,background:"transparent",textAlign:"left",cursor:"pointer",color:"var(--text)",fontSize:12.5,fontFamily:"inherit"},f={background:"var(--bg-selected)"},v={flex:"1 1 0",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12.5};function b({entries:e,selectedPath:t,busy:r,onPick:i,showHidden:o,filterPrefix:l}){let s,a,d,c=(s=null===l?"":l.toLowerCase(),a=e=>(o||!e.hidden||s.startsWith("."))&&e.name.toLowerCase().startsWith(s),d=""!==s&&e.some(a),e.filter(e=>e.path===t||(d?a(e):o||!e.hidden)));return(0,n.jsx)("div",{style:x,role:"list",children:c.map(e=>{let o=e.path===t;return(0,n.jsxs)("button",{type:"button",role:"listitem","aria-current":o||void 0,disabled:r,onClick:()=>i(e),title:e.path,style:{...g,...o?f:null},children:[(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:o?"var(--accent)":"var(--text-muted)"},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:v,children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path)})})}function m({open:e,initialPath:t,onClose:r,onSelect:o}){let[l,s]=(0,i.useState)(null),[a,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[v,y]=(0,i.useState)(!1),[j,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)(0),[C,T]=(0,i.useState)(null),[z,I]=(0,i.useState)(null),[R,M]=(0,i.useState)(!1),[W,L]=(0,i.useState)(null),[E,$]=(0,i.useState)(!1),[P,D]=(0,i.useState)(null),B=(0,i.useRef)(0),O=(0,i.useRef)(null),N=(0,i.useRef)(0),A=(0,i.useRef)(!1),H=(0,i.useRef)(!1),F=(0,i.useRef)(null),U=(0,i.useRef)({parent:null,child:null}),_=(0,i.useRef)(null),K=(0,i.useRef)(null);(0,i.useEffect)(()=>{U.current={parent:l,child:g}},[l,g]),(0,i.useEffect)(()=>()=>{B.current+=1,N.current+=1,O.current?.abort()},[]);let J=(0,i.useCallback)((e,t)=>fetch(e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",{signal:t}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);return t}),[]),q=(0,i.useCallback)(()=>(O.current?.abort(),O.current=null,++B.current),[]),V=(0,i.useCallback)(()=>{k(!1),S(e=>e+1)},[]),Y=(0,i.useCallback)(e=>{let t=q(),r=new AbortController;return O.current=r,V(),{seq:t,scan:J(e,r.signal)}},[q,V,J]),G=(0,i.useCallback)(e=>{let t=new AbortController;return O.current=t,V(),J(e,t.signal)},[V,J]),Z=(0,i.useCallback)((e,t)=>{let r=t?.closeEditor??!1,n=t?.announce??!1,{seq:i,scan:o}=Y(e);y(!0),n&&T(null);let l=()=>{(y(!1),r)?I(null):T(null)};o.then(t=>{if(i!==B.current)return;r||void 0===e||(F.current={directory:e,landed:t.current});let n=!1,o=()=>{n||i!==B.current||(n=!0,s(t),x(null),f(null),l())};if(u(t,"").length<2)return void o();let a=t.crumbs.at(-2);void 0===a?o():(G(a.path).then(e=>{if(i!==B.current)return;let r=p(e),a=e=>"\\"===r?e.toLowerCase():e,d=e.directories.find(e=>a(e.path)===a(t.current));void 0===d?o():(n=!0,s(e),x(d),f(t),l())},()=>{o()}),r&&window.setTimeout(o,200))},e=>{i===B.current&&(y(!1),n&&T(c(e)))})},[Y,G]),X=(0,i.useCallback)(e=>{Z(e,{closeEditor:!0,announce:!0})},[Z]),Q=(0,i.useCallback)(e=>{let{seq:t,scan:r}=Y(e.path);null!==z&&I(null),x(e),f(null),y(!0),T(null),r.then(e=>{t===B.current&&(f(e),y(!1))},e=>{t===B.current&&(y(!1),T(c(e)),x(null))})},[Y,z]),ee=(0,i.useCallback)(e=>{null!==g&&(s(g),Q(e))},[g,Q]),et=(0,i.useCallback)(e=>{Z(e,{closeEditor:!1,announce:!1})},[Z]),er=(0,i.useCallback)(()=>{q(),y(!1),I(null),T(null),null===g&&x(null),null===l&&X()},[q,g,l,X]);(0,i.useEffect)(()=>{if(N.current+=1,e){s(null),x(null),f(null),$(!1),M(!1),X(t??void 0);return}q(),y(!1),T(null),I(null),L(null),D(null)},[e,X,q,t]),(0,i.useEffect)(()=>{if(!v)return void k(!1);let e=window.setTimeout(()=>{k(!0)},300);return()=>{window.clearTimeout(e)}},[v,w]),(0,i.useEffect)(()=>{if(null===z)return;let e=window.setTimeout(()=>{if(H.current)return;let e=U.current.child??U.current.parent;if(null===e)return;let{directory:t,tail:r}=h(e,z,F.current);null!==t&&null===r&&et(t)},250);return()=>{window.clearTimeout(e)}},[z,et]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{if("Escape"===e.key){if(null!==W){E||L(null);return}if(null!==z){e.stopPropagation(),er();return}r()}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e,z,W,E,er]);let en=g??l,ei=null===en?[]:u(en,d),eo=ei.at(-1)?.path,el=g?.current,es=a?.path??l?.current??null;(0,i.useEffect)(()=>{let e=_.current;null!==e&&(e.scrollLeft=e.scrollWidth)},[eo]),(0,i.useEffect)(()=>{let e=K.current;null!==e&&void 0!==el&&(e.scrollLeft=e.scrollWidth)},[el]);let ea=(0,i.useCallback)(()=>{if(null===es||null===W||E||""===W.trim())return;$(!0),D(null);let e=N.current;fetch("/api/projects/browse",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dir:es,name:W})}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);if("string"!=typeof t.path)throw Error("No path returned");return t.path}).then(t=>{if(e!==N.current)return;$(!1),L(null);let{seq:r,scan:n}=Y(es);y(!0),T(null),n.then(e=>{r===B.current&&(s(e),y(!1),Q({name:W,path:t,hidden:W.startsWith(".")}))},e=>{r===B.current&&(y(!1),T(c(e)))})},t=>{e===N.current&&($(!1),D(c(t)))})},[es,W,E,Y,Q]),ed={onCompositionStart:()=>{A.current=!0},onCompositionEnd:()=>{A.current=!1}};if(!e)return null;let ec=null!==a,eu=null===en||null===z?null:h(en,z,F.current).tail,ep=a?.name??(null===l?"":u(l,d).at(-1)?.name??l.current),eh=null!==W||E,ex=null!==z,eg=en?.drives??[],ef=en?p(en):"/";return(0,n.jsxs)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:[(0,n.jsxs)("div",{style:{width:"min(680px, 100%)",height:"min(500px, calc(100dvh - 32px))",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,flex:"none",padding:"16px 14px 8px 24px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",minHeight:24},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700},children:"Select project path"}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:18,lineHeight:1},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:"\xd7"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,boxSizing:"border-box",minHeight:26,marginLeft:-9,padding:"0 8px",border:`1px solid ${null!==z?"var(--border)":"transparent"}`,borderRadius:8},children:[eg.length>0&&(0,n.jsxs)("select",{value:eg.find(e=>(en?.current??"").toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&X(e.target.value)},disabled:eh,title:"Drive",style:{height:24,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:11,maxWidth:72},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),eg.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),null===z?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{ref:_,role:"navigation",style:{display:"flex",alignItems:"center",gap:4,flex:"0 1 auto",minWidth:0,overflowX:"auto",scrollbarWidth:"none"},children:ei.map((e,t)=>(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,flex:"none",minWidth:0},children:[t>0&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})}),(0,n.jsx)("button",{type:"button",disabled:eh,onClick:()=>X(e.path),title:e.path,style:{border:"none",background:"transparent",padding:0,maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-muted)",cursor:"pointer"},children:e.name})]},e.path))}),(0,n.jsx)("button",{type:"button","aria-label":"Edit path",title:"Edit path",disabled:eh,onClick:()=>{if(q(),y(!1),H.current=!1,null===l)return void I("");let e=a?.path??l.current;I(e.endsWith(ef)?e:`${e}${ef}`)},style:{display:"flex",alignItems:"center",justifyContent:"flex-end",flex:"1 0 34px",minWidth:34,height:22,padding:0,border:"none",background:"transparent",cursor:"text"},children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:(0,n.jsx)("path",{d:"M11.3 2.2a1.9 1.9 0 0 1 2.5 2.5L6 12.5 2.5 13.5 3.5 10l7.8-7.8Z"})})})]}):(0,n.jsx)("input",{value:z,autoFocus:!0,"aria-label":"Edit path",disabled:eh,spellCheck:!1,onChange:e=>{q(),y(!1),H.current=!1,I(e.target.value)},...ed,onKeyDown:e=>{"Enter"!==e.key||A.current||(e.preventDefault(),""!==z.trim()&&(H.current=!0,X(z)))},onBlur:e=>{if(null===z||!document.hasFocus())return;let t=e.currentTarget.closest('[role="dialog"]');null===t||e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||er()},style:{boxSizing:"border-box",flex:"1 1 0",minWidth:0,height:22,padding:0,border:"none",outline:"none",background:"transparent",fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)"}})]})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:"1 1 0",minHeight:0,position:"relative",padding:"16px 16px 16px 24px"},children:[(0,n.jsxs)("div",{ref:K,style:{display:"flex",alignItems:"stretch",flex:"1 1 0",minHeight:0,gap:12,overflowX:"auto",scrollbarWidth:"none"},children:[null!==l&&(0,n.jsx)(b,{entries:l.directories,selectedPath:a?.path??null,busy:eh,onPick:Q,showHidden:R,filterPrefix:null===g?eu:null}),ec&&(0,n.jsx)("span",{style:{flex:"none",width:1,background:"var(--border)"}}),ec&&null!==g&&(0,n.jsx)(b,{entries:g.directories,selectedPath:null,busy:eh,onPick:ee,showHidden:R,filterPrefix:eu})]}),v&&j&&(0,n.jsx)("div",{role:"status",style:{position:"absolute",right:16,bottom:8,padding:"2px 8px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",fontSize:11},children:"Loading…"}),(l?.truncated===!0||g?.truncated===!0)&&(0,n.jsx)("div",{role:"status",style:{padding:"4px 4px 4px 0",color:"var(--text-muted)",fontSize:11},children:"Large directory — list may be incomplete"}),null!==C&&(0,n.jsx)("div",{role:"alert",style:{padding:"4px 4px 4px 0",color:"#f87171",fontSize:11},children:C})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,flex:"none",padding:"14px 24px",borderTop:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",disabled:null===l||v||eh||ex,onClick:()=>{L(""),D(null)},style:{display:"inline-flex",alignItems:"center",gap:5,height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:null===l||v||eh||ex?"var(--text-dim)":"var(--text-muted)",cursor:null===l||v||eh||ex?"default":"pointer",fontSize:12},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M8 3v10M3 8h10"})}),"New folder"]}),(0,n.jsxs)("button",{type:"button","aria-pressed":R,disabled:eh,onClick:()=>M(e=>!e),style:{display:"inline-flex",alignItems:"center",gap:4,border:"none",background:"transparent",padding:0,fontSize:12,fontWeight:500,color:R?"var(--text)":"var(--text-muted)",cursor:"pointer",whiteSpace:"nowrap"},children:["Show hidden files",R&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2.5 8.5 6 12 13.5 4.5"})})]}),(0,n.jsx)("div",{style:{flex:"1 1 0"}}),(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",disabled:null===es||v||eh||ex,onClick:()=>{null!==es&&o(es)},style:{height:32,padding:"0 14px",border:"none",borderRadius:6,background:null===es||v||eh||ex?"var(--bg-hover)":"var(--accent)",color:null===es||v||eh||ex?"var(--text-dim)":"#fff",cursor:null===es||v||eh||ex?"default":"pointer",fontSize:12,fontWeight:650},children:"Open"})]})]}),null!==W&&(0,n.jsx)("div",{onMouseDown:e=>{e.target!==e.currentTarget||E||L(null)},style:{position:"fixed",inset:0,zIndex:1300,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.25)"},children:(0,n.jsxs)("div",{style:{width:"min(380px, 100%)",display:"flex",flexDirection:"column",gap:12,padding:"20px 24px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.3)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700},children:"New folder"}),(0,n.jsxs)("div",{style:{color:"var(--text)",fontSize:12.5},children:["in ",(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text-muted)"},children:ep})]}),(0,n.jsx)("input",{value:W,"aria-label":"Folder name",placeholder:"untitled folder",autoFocus:!0,disabled:E,spellCheck:!1,onChange:e=>L(e.target.value),...ed,onKeyDown:e=>{"Enter"!==e.key||A.current||(e.preventDefault(),ea()),"Escape"!==e.key||E||(e.stopPropagation(),L(null))},style:{boxSizing:"border-box",width:"100%",height:36,padding:"0 12px",border:"1px solid var(--border)",borderRadius:8,outline:"none",background:"var(--bg-panel)",fontSize:13,color:"var(--text)"}}),null!==P&&(0,n.jsx)("div",{role:"alert",style:{color:"#f87171",fontSize:11},children:P}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{type:"button",disabled:E,onClick:()=>L(null),style:{height:30,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",disabled:E||""===W.trim(),onClick:ea,style:{height:30,padding:"0 14px",border:"none",borderRadius:6,background:E||""===W.trim()?"var(--bg-hover)":"var(--accent)",color:E||""===W.trim()?"var(--text-dim)":"#fff",cursor:E||""===W.trim()?"default":"pointer",fontSize:12,fontWeight:650},children:E?"Creating…":"Create"})]})]})})]})}let y="AnnoVibe";var j=r(16865);let k="annovibe:sidebar:collapsed-projects",w="annovibe:sidebar:collapsed-projects:init-v3";function S(e){window.localStorage.setItem(k,JSON.stringify([...e]))}async function C(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function T(e){return new DOMException(e,"TimeoutError")}function z(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}function I(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function R(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"…/"+i.slice(-2).join(n)}function M(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||R(e,t)}function W(e){return e+.2*e*(2*Math.random()-1)}let L="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function E(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),s=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:L[Math.floor(Math.random()*L.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"v0.8.134":y,r),a=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function $({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:o,initialSessionId:l,onInitialRestoreDone:s,refreshKey:d,onSessionDeleted:c,selectedCwd:u,onCwdChange:p}){let[h,x]=(0,i.useState)([]),[g,f]=(0,i.useState)({}),[v,b]=(0,i.useState)(()=>new Set),y=(0,i.useRef)(!1),[I,L]=(0,i.useState)(!0),[A,H]=(0,i.useState)(!1),[F,U]=(0,i.useState)(null),[_,K]=(0,i.useState)(null),[J,q]=(0,i.useState)(""),[V,Y]=(0,i.useState)(null),[G,Z]=(0,i.useState)(!1),[X,Q]=(0,i.useState)("project"),[ee,et]=(0,i.useState)(null),[er,en]=(0,i.useState)(!1),[ei,eo]=(0,i.useState)(!1),[el,es]=(0,i.useState)(()=>new Set),[ea,ed]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(k)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[ec,eu]=(0,i.useState)(null),[ep,eh]=(0,i.useState)(null),[ex,eg]=(0,i.useState)(null),[ef,ev]=(0,i.useState)(!1),eb=(0,i.useRef)(null),em=(0,i.useRef)(!1),ey=(0,i.useRef)(!1),ej=(0,i.useRef)(!1),ek=(0,i.useRef)(new Map),ew=(0,i.useRef)({revision:null,seq:0,retry:0,inFlight:!1}),eS=(0,i.useRef)({}),eC=(0,i.useRef)({}),eT=(0,i.useRef)({}),ez=(0,i.useRef)(new Set);function eI(e){let t=eS.current[e];return t||(t={revision:null,seq:0,retry:0,inFlight:!1},eS.current[e]=t),t}let eR=(0,i.useCallback)((e,t,r)=>{let n=eC.current[e];n&&clearTimeout(n),eC.current[e]=setTimeout(()=>{eC.current[e]=null,r()},Math.random()*([250,500,1e3,2e3][Math.min(Math.max(t,0),3)]??2e3))},[]),eM=(0,i.useCallback)((e,t)=>{let r=eT.current[e];r&&clearTimeout(r),eT.current[e]=setTimeout(()=>{eT.current[e]=null,t()},120)},[]),eW=(0,i.useCallback)(async(e=!1,t={})=>{let r=ew.current,n=++r.seq;r.inFlight=!0;try{let i;e&&L(!0);let o=new AbortController;try{i=setTimeout(()=>o.abort(T("Project loading timed out")),6e4);let e=t.force?"/api/projects?force=1":"/api/projects",l=await fetch(e,{signal:o.signal});if(!l.ok)throw Error(await C("projects",l));let s=await l.json();if(n!==r.seq)return;if(s.stale)return void eR("projects",r.retry++,()=>void eW(!1));r.retry=0,s.revision&&(r.revision=s.revision),x(s.projects),U(null)}finally{clearTimeout(i)}}catch(e){if(n!==r.seq)return;U(z(e,"Loading projects timed out. Codex may still be starting; click Refresh to retry.")),eR("projects",r.retry++,()=>void eW(!1))}finally{n===r.seq&&(r.inFlight=!1),e&&L(!1)}},[eR]),eL=(0,i.useCallback)(async(e,t=!1,r={})=>{if(!e)return;let n=ek.current.get(e);if(n)return n;let i=(async()=>{let n=eI(e),i=++n.seq;n.inFlight=!0,f(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{let o;t&&L(!0);let l=new AbortController;try{o=setTimeout(()=>l.abort(T("Chat loading timed out")),6e4);let t=r.force?`/api/sessions?cwd=${encodeURIComponent(e)}&force=1`:`/api/sessions?cwd=${encodeURIComponent(e)}`,s=await fetch(t,{signal:l.signal});if(!s.ok)throw Error(await C("sessions",s));let a=await s.json();if(i!==n.seq)return;if(a.runningSessionIds&&!y.current&&b(new Set(a.runningSessionIds)),a.stale){f(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,loading:!1,error:null,stale:(t[e]?.sessions?.length??0)>0}})),eR(`cwd:${e}`,n.retry++,()=>void eL(e,!1));return}n.retry=0,a.revision&&(n.revision=a.revision),ez.current.add(e),f(t=>({...t,[e]:{sessions:a.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(o)}}catch(r){if(i!==n.seq)return;let t=z(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");f(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}})),eR(`cwd:${e}`,n.retry++,()=>void eL(e,!1))}finally{i===n.seq&&(n.inFlight=!1),t&&L(!1),ek.current.delete(e)}})();return ek.current.set(e,i),i},[eR]),eE=(0,i.useCallback)(async()=>{let e=ew.current;if(e.inFlight)return;let t=e.revision?`/api/projects?fingerprint=1&revision=${encodeURIComponent(e.revision)}`:"/api/projects?fingerprint=1";try{let r=await fetch(t);if(!r.ok)throw Error(await C("projects",r));let n=await r.json();if(n.stale)return void eR("projects",e.retry++,()=>void eE());if(!0===n.unchanged)return;eW(!1)}catch{eR("projects",e.retry++,()=>void eE())}},[eW,eR]),e$=(0,i.useCallback)(async e=>{let t=eI(e);if(t.inFlight)return;let r=t.revision?`/api/sessions?cwd=${encodeURIComponent(e)}&fingerprint=1&revision=${encodeURIComponent(t.revision)}`:`/api/sessions?cwd=${encodeURIComponent(e)}&fingerprint=1`;try{let n=await fetch(r);if(!n.ok)throw Error(await C("sessions",n));let i=await n.json();if(i.stale)return void eR(`cwd:${e}`,t.retry++,()=>void e$(e));if(!0===i.unchanged)return;eL(e,!1)}catch{eR(`cwd:${e}`,t.retry++,()=>void e$(e))}},[eL,eR]),eP=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eP.current;eP.current=!0,eW(e)},[eW,d]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&q(e.home)}).catch(()=>{})},[]);let eD=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(em.current){em.current=!1;return}if(ey.current){ey.current=!1;return}p?.(_)},[_,p]);let eB=(0,i.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return Y(n.error??`HTTP ${r.status}`),null;return eW(!1),n.project?.cwd??e}catch(e){return Y(e instanceof Error?e.message:String(e)),null}},[eW]),eO=(0,i.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eN=(0,i.useCallback)(e=>{ey.current=!0,K(e),Y(null),ed(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),S(r),r}),p?.(e),eO(e),eL(e,!1)},[eL,p,eO]);(0,i.useEffect)(()=>{if(0!==h.length&&null===_){if(l&&!eD.current){eD.current=!0;let e=Object.values(g).flatMap(e=>e.sessions).find(e=>e.id===l);if(e){K(e.cwd),eO(e.cwd),t(e,!0);return}fetch(`/api/sessions/${encodeURIComponent(l)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(e=>{e?.info?(K(e.info.cwd),eO(e.info.cwd),t(e.info,!0)):s?.()}).catch(()=>s?.());return}let e=h[0]?.cwd;e&&(K(e),eO(e))}},[h,_,l,t,s,g,eO]);let eA=u??_;(0,i.useEffect)(()=>(0,j.O)(e=>{y.current=!0,b(new Set(e))}),[]);let eH=(0,i.useRef)(null);(0,i.useEffect)(()=>{eH.current=eA},[eA]),(0,i.useEffect)(()=>{let e=new EventSource("/api/session-index/events");return e.onmessage=e=>{let t=null;try{t=JSON.parse(String(e.data))}catch{return}if(t&&"index-invalidated"===t.type&&t.scope){if(("projects"===t.scope||"all-cwds"===t.scope)&&eM("projects",()=>void eE()),"cwd"===t.scope&&t.cwd){let e=t.cwd;eM(`cwd:${e}`,()=>void e$(e))}if("all-cwds"===t.scope)for(let e of ez.current)eM(`cwd:${e}`,()=>void e$(e))}},e.onerror=()=>{},()=>e.close()},[eE,e$,eM]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{eE()},W(3e4));return()=>window.clearInterval(e)},[eE]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{let e=new Set;for(let t of(eH.current&&e.add(eH.current),ez.current))e.add(t);for(let t of e)e$(t)},W(1e4));return()=>window.clearInterval(e)},[e$]),(0,i.useEffect)(()=>{let e=()=>{if("visible"!==document.visibilityState)return;eE();let e=new Set;for(let t of(eH.current&&e.add(eH.current),ez.current))e.add(t);for(let t of e)e$(t)};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[eE,e$]),(0,i.useEffect)(()=>{let e=()=>{eA&&eL(eA,!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eA,eL]);let eF=(0,i.useCallback)(e=>{if(!e){Q("agent"),Z(!0);return}let t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(t,e)},[r]),eU=(0,i.useCallback)(e=>{if(!e){Q("workbench"),Z(!0);return}o?.(e)},[o]),e_=(0,i.useCallback)(async e=>{let t=await eB(e,!0);t&&(eN(t),Z(!1),Y(null),"agent"===X&&eF(t),"workbench"===X&&eU(t))},[eN,eF,eU,X,eB]),eK=(0,i.useCallback)(e=>{et(e),en(!0)},[]),eJ=(0,i.useCallback)(()=>{en(!1),et(null)},[]),eq=(0,i.useCallback)(e=>{let t=ee??eA;eJ(),"agent"===e?eF(t):eU(t)},[eJ,eF,eU,eA,ee]),eV=(0,i.useCallback)(()=>{eK(eA)},[eA,eK]),eY=(0,i.useCallback)(()=>{Q("project"),Y(null),Z(!0)},[]),eG=(0,i.useMemo)(()=>[...eA&&!h.some(e=>e.cwd===eA)?[{cwd:eA,displayName:M(eA,J),chatCount:g[eA]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...h].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,i="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==i?n-i:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[eA,J,h,g]),eZ=(0,i.useMemo)(()=>{let e=e=>{var t,r;let n,i,o=g[e.cwd],l=[...o?.sessions??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||"")),s=o?.loaded?o.sessions.length:e.chatCount,a=(t=e.lastAccessed,r=o?.loaded?o.sessions[0]?.modified:null,n=t?new Date(t).getTime():-1/0,i=r?new Date(r).getTime():-1/0,Number.isFinite(n)||Number.isFinite(i)?n>=i?t??null:r??null:null);return{project:e,cwd:e.cwd,displayName:e.displayName||M(e.cwd,J),sessions:l,sessionsState:o,chatCount:s??0,lastAccessed:a??""}},t=eG.filter(e=>!0===e.pinned).map(e);if(eA){let r=eG.find(e=>e.cwd===eA);r&&!0!==r.pinned&&t.push(e(r))}return t},[eA,J,g,eG]);(0,i.useEffect)(()=>{if(0===eZ.length||ej.current||(ej.current=!0,!eZ[0]?.cwd||window.localStorage.getItem(w)))return;let e=new Set(eZ.slice(1).map(e=>e.cwd));ed(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(S(e),e):t),window.localStorage.setItem(w,"1")},[eZ]);let eX=(0,i.useCallback)((e,r=!1)=>{e.cwd!==eA&&(em.current=!0,K(e.cwd)),ed(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),S(r),r}),eO(e.cwd),t(e,r)},[t,eA,eO]),eQ=(0,i.useCallback)(e=>{ed(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),S(r),r})},[]);(0,i.useEffect)(()=>{for(let e of eZ){let t=g[e.cwd];if(!t?.loaded&&!t?.loading){let t=e.cwd===eA,r=ea.has(e.cwd);if(!t&&r)continue;eL(e.cwd,!1)}}},[ea,eA,eL,eZ,g]);let e0=(0,i.useCallback)(e=>{es(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),e1=(0,i.useCallback)(async e=>{eg("reorder");try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);U(null),eW(!1)}catch(e){U(e instanceof Error?e.message:String(e)),eW(!1)}finally{eg(null)}},[eW]),e2=(0,i.useCallback)(async(e,t)=>{eg(`pin:${e}`);try{let r=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,pinned:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);U(null),eW(!1)}catch(e){U(e instanceof Error?e.message:String(e)),eW(!1)}finally{eg(null)}},[eW]),e5=(0,i.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eG.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),i=r.indexOf(t);if(-1===n||-1===i)return;let o=[...r];o.splice(n,1);let l=o.indexOf(t);o.splice(l,0,e),e1(o)},[e1,eG]),e4=(0,i.useCallback)(async()=>{H(!0);try{await eW(!1,{force:!0});let e=new Set([...Object.entries(g).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eA?[eA]:[]]);await Promise.all([...e].map(e=>eL(e,!1,{force:!0})))}finally{H(!1)}},[eA,eW,eL,g]);return(0,i.useEffect)(()=>{if(!ef)return;let e=e=>{eb.current&&!eb.current.contains(e.target)&&ev(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[ef]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)(E,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eV,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:eA?`New chat in ${eA}`:"New chat in a project path",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New Chat"]}),(0,n.jsx)("button",{onClick:()=>eo(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,n.jsx)(a,{open:ei,cwd:eA,homeDir:J,onClose:()=>eo(!1),onSelectSession:e=>{eX(e)}}),(0,n.jsxs)("div",{ref:eb,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>ev(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eA?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eA?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eA??"Select project",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:eA?"var(--text)":"var(--text-dim)"},children:eA?eG.find(e=>e.cwd===eA)?.displayName??R(eA,J):"Select project…"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:ef?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eA&&(0,n.jsx)(D,{pinned:eG.find(e=>e.cwd===eA)?.pinned===!0,onToggle:()=>void e2(eA,eG.find(e=>e.cwd===eA)?.pinned!==!0)}),ef&&(0,n.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:10,right:10,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===eG.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eG.map(e=>{let t=e.cwd===eA;return(0,n.jsx)(B,{project:e,homeDir:J,isCurrent:t,onSelect:()=>{eN(e.cwd),ev(!1)},onTogglePinned:()=>void e2(e.cwd,!0!==e.pinned)},e.cwd)})]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,n.jsx)("button",{type:"button",onClick:e4,disabled:A,title:"Refresh projects and chats","aria-label":"Refresh projects and chats",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:A?"var(--accent)":"var(--text-dim)",cursor:A?"default":"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:A?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsx)("button",{type:"button",onClick:eY,title:"New project","aria-label":"New project",style:{width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:"50%",background:"transparent",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="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",style:{flexShrink:0,display:"block"},children:[(0,n.jsx)("path",{transform:"translate(9.52 2.52)",d:"M3.55246 0L3.55246 2.44252L6 2.44252L6 3.55748L3.55246 3.55748L3.55246 6L2.43834 6L2.43834 3.55748L0 3.55748L0 2.44252L2.43834 2.44252L2.43834 0L3.55246 0Z",fill:"currentColor"}),(0,n.jsx)("path",{transform:"translate(0.3496 2.35)",d:"M4.76367 0C5.36861 1.80598e-05 5.93113 0.310294 6.25488 0.821289L6.78027 1.64941C6.79685 1.67558 6.81791 1.69775 6.83887 1.71973C6.72186 2.15521 6.65702 2.61192 6.65137 3.08301C6.25601 2.96045 5.90909 2.70478 5.68164 2.3457L5.15723 1.5166C5.07183 1.38189 4.92318 1.3008 4.76367 1.30078L2.32422 1.30078C1.7589 1.30078 1.30078 1.7589 1.30078 2.32422L1.30078 10.1338C1.30078 10.6991 1.7589 11.1572 2.32422 11.1572L11.9766 11.1572C12.5419 11.1572 13 10.6991 13 10.1338L13 8.58398C13.4545 8.5135 13.8903 8.38748 14.3008 8.21289L14.3008 10.1338C14.3008 11.4171 13.2598 12.458 11.9766 12.458L2.32422 12.458C1.04093 12.458 0 11.4171 0 10.1338L0 2.32422C0 1.04093 1.04093 0 2.32422 0L4.76367 0Z",fill:"currentColor"})]})})]})]}),V&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:V})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[I&&0===h.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading…"}),F&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:F}),!I&&!F&&0===eZ.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!I&&!F&&eZ.map(t=>{let r,i=ea.has(t.cwd),o=t.cwd===eA,l=el.has(t.cwd),s=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>i(e.children))};return i(n),n}(t.sessions),a=s.length,d=s;if(a>10&&!l){d=s.slice(0,10);let t=s.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!d.includes(t)&&(d=[...d,t])}let u=a-d.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:ep===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ep===t.cwd),opacity:ec===t.cwd?.55:1},onDragOver:e=>{ec&&ec!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eh(t.cwd))},onDragLeave:()=>{ep===t.cwd&&eh(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||ec;eh(null),eu(null),r&&e5(r,t.cwd)},children:[(0,n.jsx)(O,{group:t,isCurrent:o,isCollapsed:i,isDragging:ec===t.cwd,pinBusy:ex===`pin:${t.cwd}`,onToggle:()=>eQ(t.cwd),onSelect:()=>eN(t.cwd),onTogglePinned:()=>void e2(t.cwd,!0!==t.project.pinned),onDragStart:e=>{eu(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{eu(null),eh(null)}}),!i&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(r=t.sessionsState,r?.loading&&!r?.loaded?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):r?.error&&!r?.stale?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:r.error}):0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,n.jsxs)(n.Fragment,{children:[r?.stale&&(0,n.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),d.map(r=>(0,n.jsx)(N,{node:r,selectedSessionId:e,onSelectSession:eX,onRenamed:()=>void eL(t.cwd,!1),onSessionDeleted:e=>{c?.(e),eL(t.cwd,!1)},depth:0,runningSessionIds:v},r.session.id))]})),(l||u>0)&&a>10&&(0,n.jsx)("button",{type:"button",onClick:()=>e0(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:l?"Show less":`Show ${Math.max(0,u)} more`})]})]},t.cwd||"__no_project")})]}),er&&(0,n.jsx)(P,{cwd:ee,onChoose:eq,onClose:eJ}),(0,n.jsx)(m,{open:G,initialPath:eA,onClose:()=>Z(!1),onSelect:e=>e_(e)})]})}function P({cwd:e,onChoose:t,onClose:r}){let i=e?M(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function D({pinned:e,onToggle:t}){return(0,n.jsx)("button",{type:"button",onClick:t,title:e?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:e?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:e?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function B({project:e,homeDir:t,isCurrent:r,onSelect:o,onTogglePinned:l}){let[s,a]=(0,i.useState)(!1),d=e.displayName||M(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:o,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:s?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!s,pointerEvents:s?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function O({group:e,isCurrent:t,isCollapsed:r,isDragging:o,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:u}){let[p,h]=(0,i.useState)(!1),x=e.lastAccessed,g=Math.max(0,e.chatCount??0),f=!0===e.project.pinned,v=(0,i.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:v,onDragStart:c,onDragEnd:u,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),v())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:o?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:o?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!p&&g>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[g," ",1===g?"chat":"chats"]}),!p&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:I(x)}),f?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:p?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!p,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:p?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function N({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s,runningSessionIds:a}){let[d,c]=(0,i.useState)(!1),u=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(A,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:o,onDeleted:e=>l?.(e),depth:s,hasChildren:u,collapsed:d,onToggleCollapse:()=>c(e=>!e),isRunning:a.has(e.session.id)})]}),u&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(N,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s+1,runningSessionIds:a},e.session.id))})]})}function A({session:e,isSelected:t,onClick:r,onRenamed:o,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c,isRunning:u=!1}){let[p,h]=(0,i.useState)(!1),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[b,m]=(0,i.useState)(!1),[y,j]=(0,i.useState)(!1),k=(0,i.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,i.useCallback)(t=>{t.stopPropagation(),v(e.name??""),g(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),C=(0,i.useCallback)(async()=>{let t=f.trim();if(g(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),o?.()}catch{}},[f,e.id,e.name,o]),T=(0,i.useCallback)(e=>{e.stopPropagation(),m(!0)},[]),z=(0,i.useCallback)(async t=>{t.stopPropagation(),m(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),R=(0,i.useCallback)(e=>{e.stopPropagation(),m(!1)},[]),M="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:b||x?void 0:r,onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:b||x?"default":"pointer",background:b?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:b?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:y?.5:1,gap:6,overflow:"hidden"},children:b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",w.slice(0,22),w.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:z,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:R,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):x?(0,n.jsx)("input",{ref:k,value:f,onChange:e=>v(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&g(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:u?7:5,height:u?7:5,borderRadius:"50%",background:u?"#22c55e":t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0,...u?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),M&&(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:M?"var(--accent)":"var(--text)"},title:w,children:w}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:I(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),a&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),p&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:S,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:T,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var H=r(94456),F=r(14755);let U=new Map,_=["off","default","full","agent"],K={off:"none",default:"default",full:"full",agent:"agent"},J={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},q={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},V=["auto","off","minimal","low","medium","high","xhigh"],Y={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},G=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function Z({doc:e,onRemove:t}){var r;let i=e.fileName.split(".").pop()?.toLowerCase()??"",o=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(i),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:o.color,fontSize:14,flexShrink:0},children:o.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[i.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function X(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function Q(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,i=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&i.push(`Page ${e}
|
|
2
2
|
${r}`)}return i.join("\n\n")}async function ee(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),i=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],o=[];for(let e of i){let t=n.file(e);if(!t)continue;let r=[...(await t.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];o.push(...r.map(e=>X(e[1])))}return o.join("").replace(/[ \t]+\n/g,"\n")}async function et(e){let t=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),n=t.read(e,{type:"array"});return n.SheetNames.map(e=>{let r=n.Sheets[e],i=t.utils.sheet_to_csv(r);return`Sheet: ${e}
|
|
3
3
|
${i}`}).join("\n\n")}async function er(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),i=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),o=[];for(let{name:e,match:t}of i){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>X(e[1]).trim()).filter(Boolean);r.length&&o.push(`Slide ${t[1]}
|
|
4
4
|
${r.join("\n")}`)}return o.join("\n\n")}async function en(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,i="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))i=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)i=await Q(t);else if("docx"===r)i=await ee(t);else if("xlsx"===r)i=await et(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};i=await er(t)}let{text:o,truncated:l}=(n=i.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:n,truncated:!1}:{text:`${n.slice(0,6e4)}
|
|
5
5
|
|
|
6
|
-
[truncated after 60000 characters]`,truncated:!0};if(!o)return{extractionError:"No extractable text found"};return{extractedText:o,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let ei=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,compactInfo:g,toolPreset:f,sessionKind:v,onToolPresetChange:b,memoryTools:m,onMemoryToolsChange:y,thinkingLevel:j,onThinkingLevelChange:k,availableThinkingLevels:w,thinkingLevelMap:S,retryInfo:C,cornerBadge:T,promptHistory:z,sessionHistoryKey:I,activeFilePath:R,onDismissFileContext:M},W){let[L,E]=(0,i.useState)(""),[$,P]=(0,i.useState)(!1),[D,B]=(0,i.useState)("root"),[O,N]=(0,i.useState)(null),[A,H]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,et]=(0,i.useState)(!1),[er,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(null),[es,ea]=(0,i.useState)([]),[ed,ec]=(0,i.useState)([]),eu=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),ep=eu?{display:"none"}:void 0,eh=eu?28:32,ex=eu?"6px 8px":"8px 12px",eg=eu&&!l,ef=er?"var(--text)":"var(--text-muted)",ev={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},eb=eu?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[em,ey]=(0,i.useState)(null),ej=(0,i.useRef)(null),ek=(0,i.useRef)(null),ew=(0,i.useRef)(null),eS=(0,i.useRef)(null),eC=(0,i.useRef)(null),eT=(0,i.useRef)(null),ez=(0,i.useRef)(null),eI=(0,i.useRef)(null),eR=(0,i.useRef)(null),eM=(0,i.useCallback)(e=>{let t=ej.current;if(!t)return void E(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=!(i.length>0)||i.endsWith(" ")||i.endsWith("\n")?"":" ";E(i+l+e+o),requestAnimationFrame(()=>{let t=ej.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,i.useImperativeHandle)(W,()=>({insertIfEmpty(e){let t=ej.current;(t?t.value:L).trim()||(E(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eM(e)},addImages(e){eW(e)},addFiles(e){eL(e)}}));let eW=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ea(e=>[...e,...r])},[]),eL=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eW(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,i=await en(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...i})},n.onerror=r,n.readAsArrayBuffer(e)})));ec(t=>[...t,...e])}},[eW]),eE=(0,i.useCallback)(e=>{ea(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),e$=(0,i.useCallback)(e=>{ec(t=>{let r=[...t];return r.splice(e,1),r})},[]),eP=(0,i.useCallback)(()=>{ea(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ec([])},[]),eD=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(a??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})),eB=[];for(let e of eD){let t=eB.find(t=>t.provider===e.provider);t?t.options.push(e):eB.push({provider:e.provider,options:[e]})}let eO=s?eD.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eD.length>0?eD[0].name:null,eN=s?eD.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eD[0],eA=eN?.input?.includes("image")??!0,eH=es.length>0&&eN?.input!==void 0&&!eA,eF=(!!L.trim()||es.length>0||ed.length>0)&&!eH,eU=u?G:G.filter(e=>"/compact"!==e.command),e_=eU.filter(e=>"native"===e.kind),eK=eU.filter(e=>"shortcut"===e.kind),eJ=m??[],eq=eJ.length>0?`${eJ.length} enabled`:"off",eV=eD.length>0&&!!eO&&!!c,eY=!!b&&"workbench"!==v,eG=!!k&&!!w&&w.some(e=>"off"!==e),eZ=(()=>{let e=j??"auto";if("auto"===e)return"Default";if(!S)return e;let t=S[e];return null!=t?t:e})(),eX=eO??"Default",eQ=eG?`${eX} \xb7 ${eZ}`:eX,e0=(f??"full")==="workbench"?"workbench":Object.entries(K).find(([,e])=>e===(f??"full"))?.[0]??"full",e1=eu?26:32,e2=eu?7:9,e5=eu?3:6,e4={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},e3=eu&&($||A||X||ee||er);(0,i.useEffect)(()=>{eH||ey(null)},[eH]);let e8=(0,i.useCallback)(e=>{if(!L.trim()){E(e),requestAnimationFrame(()=>{let t=ej.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eM(e)},[eM,L]),e6=(0,i.useCallback)(()=>{let t=L.trim();if(t||es.length||ed.length){if(es.length&&!eA)return void ey("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!es.length&&!ed.length&&u){h?p?.():u(),E(""),ej.current&&(ej.current.style.height="auto");return}e(t,es.length?es:void 0,ed.length?ed:void 0),E(""),eP(),ej.current&&(ej.current.style.height="auto")}}},[L,es,ed,eA,l,e,eP,u,p,h]),e7=(0,i.useCallback)(e=>{let t=L.trim();if(!t&&!es.length&&!ed.length)return;if(es.length&&!eA)return void ey("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=es.length?es:void 0,i=ed.length?ed:void 0;"steer"===e&&r?r(t,n,i):"followup"===e&&o&&o(t,n,i),E(""),eP(),ej.current&&(ej.current.style.height="auto")},[L,es,ed,eA,r,o,eP]),e9=z??[],te=I??null,tt=(0,i.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&e9.length>0){let t=ej.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let i=((n=U.get(e))||(n={cursor:-1,draftSnapshot:""},U.set(e,n)),n);if(-1===i.cursor)i.draftSnapshot=t,i.cursor=0;else{if(!(i.cursor<r.length-1))return null;i.cursor+=1}return r[i.cursor]??null}(te,t.value,e9);null!==n&&(E(n),requestAnimationFrame(()=>{t.setSelectionRange(n.length,n.length)}));return}if("ArrowDown"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&function(e){if(!e)return!1;let t=U.get(e);return(t?.cursor??-1)>=0}(te)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=U.get(e);if(!r||-1===r.cursor)return null;if(r.cursor>0)return r.cursor-=1,{text:t[r.cursor]??"",returnedToPresent:!1};let n=r.draftSnapshot;return r.cursor=-1,r.draftSnapshot="",{text:n,returnedToPresent:!0}}(te,e9);t&&(E(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=ej.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),te&&U.set(te,{cursor:-1,draftSnapshot:""}),l&&(r||o)?e7(r?"steer":"followup"):e6())},[l,r,o,e7,e6,e9,te]),tr=(0,i.useCallback)(()=>{let e=ej.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tn=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eL(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eL]);(0,i.useEffect)(()=>{if(!$&&!A&&!X&&!ee&&!er)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!ek.current?.contains(t),n=!!ew.current?.contains(t);r||n||P(!1),eS.current?.contains(t)||H(!1),eC.current?.contains(t)||Q(!1),eT.current?.contains(t)||et(!1),ez.current?.contains(t)||ei(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[$,A,X,ee,er]),(0,i.useEffect)(()=>{if(!b)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||el(!!t?.ready)}).catch(()=>{e||el(!1)}),()=>{e=!0}},[b]),(0,i.useEffect)(()=>{if(!$)return;let e=e=>{"Escape"===e.key&&("root"!==D?B("root"):P(!1))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[$,D]);let ti=e=>(0,n.jsx)("svg",{width:e,height:e,viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}),to=(e,t)=>(0,n.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0,...t},children:(0,n.jsx)("path",{d:"M9 6l6 6-6 6",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})}),tl=()=>{let e=()=>{P(!1),B("root")},t=V.filter(e=>!w||"auto"===e||w.includes(e)),r=(0,n.jsxs)(n.Fragment,{children:["root"===D&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>B("model"),style:{display:"flex",alignItems:"center",gap:8,width:"100%",height:40,padding:"0 10px",border:"none",borderRadius:10,background:"transparent",color:"var(--text)",fontSize:14,lineHeight:"22px",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{style:{flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"模型"}),(0,n.jsx)("span",{style:{flex:"0 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:13},children:eX}),to(14,{color:"var(--text-dim)"})]}),eG&&(0,n.jsxs)("button",{onClick:()=>B("effort"),style:{display:"flex",alignItems:"center",gap:8,width:"100%",height:40,padding:"0 10px",border:"none",borderRadius:10,background:"transparent",color:"var(--text)",fontSize:14,lineHeight:"22px",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("span",{style:{flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"推理等级"}),(0,n.jsx)("span",{style:{flex:"0 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:13},children:eZ}),to(14,{color:"var(--text-dim)"})]})]}),"model"===D&&(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:eB.map(t=>(0,n.jsxs)("div",{children:[eB.length>1&&(0,n.jsx)("div",{style:{position:"sticky",top:0,zIndex:1,padding:"5px 8px 3px",background:"var(--bg)",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",fontWeight:500},children:t.provider}),t.options.map(t=>{let r=t.modelId===s?.modelId&&t.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{e(),r||c(t.provider,t.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",minHeight:38,padding:"6px 8px",border:"none",borderRadius:10,background:"transparent",color:"var(--text)",textAlign:"left",cursor:"pointer",fontFamily:"inherit"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[r?ti(12):(0,n.jsx)("span",{style:{width:12,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:14,lineHeight:"20px",fontWeight:500},children:t.name})]},`${t.provider}:${t.modelId}`)})]},t.provider))}),"effort"===D&&eG&&(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:t.map(t=>{let r=(j??"auto")===t,i=Y[t],o="auto"!==t&&S?S[t]:void 0,l="auto"===t?"Default":null!=o&&o!==t?o:t;return(0,n.jsxs)("button",{onClick:()=>{e(),r||k(t)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",minHeight:38,padding:"6px 8px",border:"none",borderRadius:10,background:"transparent",color:"var(--text)",textAlign:"left",cursor:"pointer",fontFamily:"inherit"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[r?ti(12):(0,n.jsx)("span",{style:{width:12,flexShrink:0}}),(0,n.jsxs)("span",{style:{display:"flex",flex:1,flexDirection:"column",minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:14,lineHeight:"20px",fontWeight:500},children:l}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,lineHeight:"18px",color:"var(--text-dim)"},children:i})]})]},t)})})]}),i=window.visualViewport?.width??window.innerWidth,o=window.visualViewport?.height??window.innerHeight,a=O?o-O.top+6:0,d=O?Math.max(120,Math.min(O.top-8,.6*o)):240,u=O?Math.max(8,i-(O.left+O.width)):0;return(0,n.jsxs)("div",{ref:ek,style:{position:"relative",flex:eu?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!eu){let t=e.currentTarget.getBoundingClientRect();N({top:t.top,left:t.left,width:t.width})}H(!1),Q(!1),et(!1),ei(!1),B("root"),P(e=>!e)},disabled:l,title:"选择模型与推理强度",style:{display:"flex",alignItems:"center",gap:4,height:eu?eh:28,padding:eu?ex:"0 4px 0 8px",width:eu?"100%":void 0,maxWidth:eu?"100%":220,overflow:"hidden",background:$?"var(--bg-hover)":"none",border:"none",borderRadius:eu?8:24,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eu?11:13,lineHeight:eu?void 0:"20px",fontWeight:eu?void 0:500,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=$?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eO}),eG&&(0,n.jsxs)("span",{style:{flex:"0 0 auto",color:"var(--text-dim)"},children:[" \xb7 ",eZ]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{flex:"0 0 auto",color:"var(--text-dim)",transform:$?"rotate(180deg)":"none",transition:"transform 120ms ease"},children:(0,n.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),$&&(eu?(0,n.jsxs)("div",{ref:ew,style:{...e4,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:["root"!==D&&(0,n.jsx)("button",{onClick:()=>B("root"),"aria-label":"返回",style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,flexShrink:0,background:"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:(0,n.jsx)("path",{d:"M15 6l-6 6 6 6",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"model"===D?"Models":"effort"===D?"推理等级":"模型 \xb7 推理"})]}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:eQ})]}),r]}):O&&(0,n.jsx)("div",{ref:ew,style:{position:"fixed",bottom:a,right:u,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 8px 24px -8px rgba(0,0,0,0.18)",width:"min(240px, calc(100vw - 32px))",maxHeight:d,overflow:"hidden",display:"flex",flexDirection:"column",padding:4},children:r}))]})};return(0,n.jsxs)("div",{style:eb,children:[e3&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{P(!1),H(!1),Q(!1),et(!1),ei(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,n.jsx)("input",{ref:eI,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eW(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eR,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{eL(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:eu?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:eu?"0 8px":void 0,boxSizing:"border-box"},children:[T&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:T}),C&&(0,n.jsxs)("div",{style:{marginBottom:eu?6:8,padding:eu?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:eu?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",C.attempt,"/",C.maxAttempts,")…",C.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",C.errorMessage]})]}),R&&(0,n.jsxs)("div",{style:{marginBottom:eu?6:8,padding:eu?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:eu?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R.replace(/^.*[\\/]/,"")}),M&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),M()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(es.length>0||ed.length>0)&&(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[es.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${eH?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eE(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${t}`)),ed.map((e,t)=>(0,n.jsx)(Z,{doc:e,onRemove:()=>e$(t)},`doc-${t}`))]}),(eH||em)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:eu?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,n.jsx)("span",{children:em??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:eu?4:8,alignItems:eu?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:eu?13:14,padding:eu?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:ej,value:L,onChange:e=>E(e.target.value),onKeyDown:tt,onInput:tr,onPaste:tn,placeholder:l&&(r||o)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:eu?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!eu,paddingBottom:+!!eu}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:eu?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>e7("steer"),disabled:!eF,title:eH?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!eu,padding:eu?"6px 8px":"7px 12px",background:eF?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eF?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eF?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!eu&&"Steer"]}),o&&(0,n.jsxs)("button",{onClick:()=>e7("followup"),disabled:!eF,title:eH?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!eu,padding:eu?"6px 8px":"7px 12px",background:eF?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eF?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eF?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!eu&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:e6,disabled:!eF,title:eH?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eu?3:6,padding:eu?"5px 9px":"7px 14px",marginBottom:+!!eu,background:eF?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eF?"#fff":"var(--text-dim)",cursor:eF?"pointer":"not-allowed",fontSize:eu?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eF?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:eu?13:14,height:eu?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:eu?5:8,display:"flex",alignItems:eu?"flex-start":"center",gap:e5,flexWrap:eu?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:eu?"1 1 100%":"0 0 auto",width:eu?"100%":void 0,display:"flex",alignItems:"center",gap:2*!eu,flexWrap:eu?"wrap":"nowrap",rowGap:4*!!eu},children:[(0,n.jsx)("button",{onClick:()=>eI.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e1,height:e1,padding:0,background:"none",border:"none",borderRadius:e2,color:es.length||ed.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=es.length||ed.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=es.length||ed.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eR.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,n.jsxs)("div",{ref:eS,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(H(e=>!e),Q(!1),P(!1),et(!1),ei(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e1,height:e1,padding:0,background:A?"var(--bg-hover)":"none",border:"none",borderRadius:e2,color:x?"#ef4444":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=x?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=A?"var(--bg-hover)":"none",e.currentTarget.style.color=x?"#ef4444":"var(--text-muted)"},children:["/",x&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),A&&(0,n.jsxs)("div",{style:{...eu?e4:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:x?"1px solid var(--border)":"none"},children:"Commands"}),x&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:x}),g&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#34d399",background:"rgba(52,211,153,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:g}),e_.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),e_.map(e=>(0,n.jsxs)("button",{onClick:()=>{(H(!1),"/compact"===e.command&&h)?p?.():e8(e.command)},style:{display:"flex",alignItems:"center",gap:eu?6:8,width:"100%",padding:ex,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:eu?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===e.command&&h?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&h?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===e.command&&h?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&h?"中止当前压缩任务":e.description})]})]},e.command))]}),eK.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(e_.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:e_.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eK.map(e=>(0,n.jsxs)("button",{onClick:()=>{H(!1),e8(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ex,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eu?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:e.description})]})]},e.command))]})]})]}),y&&(0,n.jsxs)("div",{ref:eC,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(Q(e=>!e),H(!1),P(!1),et(!1),ei(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:eh,padding:0,background:X?"var(--bg-hover)":"none",border:"none",borderRadius:eu?8:9,color:eJ.length>0?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eJ.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=X?"var(--bg-hover)":"none",e.currentTarget.style.color=eJ.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),eJ.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),X&&(0,n.jsxs)("div",{style:{...eu?e4:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),F.SN.map(e=>{let t=eJ.includes(e),r=q[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?eJ.filter(t=>t!==e):[...eJ,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ex,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eu?11:12,textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:r.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:r.description})]})]},e)})]})]}),eV&&eu&&tl(),eu&&!l&&(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{ref:ez,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>{H(!1),Q(!1),P(!1),et(!1),ei(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:er?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ef,cursor:"pointer",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=er?"var(--bg-hover)":"none",e.currentTarget.style.color=er?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),er&&(0,n.jsxs)("div",{style:{...e4,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[eV&&(0,n.jsxs)("button",{onClick:()=>{ei(!1),et(!1),Q(!1),P(!0),B("root")},style:ev,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:eQ})]}),eY&&(0,n.jsxs)("button",{onClick:()=>{ei(!1),P(!1),Q(!1),et(!0)},style:ev,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e0})]}),!!y&&(0,n.jsxs)("button",{onClick:()=>{ei(!1),P(!1),et(!1),Q(!0)},style:ev,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:eJ.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eq})]})]})]})]})})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:eg?"none":void 0,flex:eu?"0 0 auto":1,width:eu?0:void 0,height:eu?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:eu?"auto":void 0,display:"flex",alignItems:"center",gap:eu?4:2,marginLeft:eu?0:"auto",marginTop:0},children:[(!eg&&!l||eu&&ee)&&eY&&(0,n.jsxs)("div",{ref:eT,style:{position:"relative"},children:[!eg&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(H(!1),Q(!1),P(!1),ei(!1),et(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:eu?3:5,padding:ex,height:eh,background:ee?"var(--bg-hover)":"none",border:"none",borderRadius:eu?8:9,color:(f??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eu?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=(f??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ee?"var(--bg-hover)":"none",e.currentTarget.style.color=(f??"full")==="workbench"?"var(--accent)":"var(--text-muted)"},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(0,n.jsx)("span",{style:ep,children:e0})]}),ee&&(0,n.jsx)("div",{style:{...eu?e4:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:_.map(e=>{let t=K[e],r=(f??"full")===t,i="agent"===e&&!1===eo,o=i?"需安装 pi-subagents":J[e];return(0,n.jsxs)("button",{onClick:()=>{!i&&(et(!1),r||b(t))},disabled:i,title:i?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:i?"not-allowed":"pointer",fontSize:eu?11:12,textAlign:"left",fontWeight:r?600:400,opacity:i?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),eV&&!eu&&tl(),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:eh,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:eu?8:9,color:"#ef4444",cursor:"pointer",fontSize:eu?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]})]})]})]})]})});function eo(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function el({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o}){let[l,s]=(0,i.useState)(0),[a,d]=(0,i.useState)(1),[c,u]=(0,i.useState)(!1),[p,h]=(0,i.useState)([]),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),b=(0,i.useRef)(!1),m=(0,i.useRef)(null),y=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,i.useRef)(y);j.current=y;let k=(0,i.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,i=t-n;u(i>20),i<=0?(s(0),d(1)):(s(e.scrollTop/i),d(n/t));let l=o.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let i=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&i&&t>0){let r=i.getBoundingClientRect(),o=e.getBoundingClientRect(),l=r.top-o.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,i.useCallback)(()=>k.current(),[]);(0,i.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,i.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,i.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,i.useCallback)(e=>{if(!c)return;b.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),i=n>=0&&n<=a?n:a/2;S(r-i);let o=e=>{b.current&&S((e.clientY-t.top)/t.height-i)},s=()=>{b.current=!1,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",s)},[c,a,l,S]),T=m.current?.clientHeight??600,z=(0,i.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-a)*100,R=100*a,M=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:m,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${R}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=eo(e.msg),r=x&&M===e.index,i="user"===e.msg.role,o=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${o}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:i?8:6,height:i?8:6,borderRadius:i?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),i=eo(e.msg),o=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${o?i.border:"var(--border)"}`,borderRight:`1px solid ${o?i.border:"var(--border)"}`,borderBottom:`1px solid ${o?i.border:"var(--border)"}`,borderLeft:`2px solid ${i.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:o?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:o?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function es(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ea(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function ed(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ec(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function eu(e){let t=new Map;for(let r of e){if("custom"===r.role&&"subagent-notify"===r.customType&&"string"==typeof r.content){let e=r.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(e){let n=`bg-${e[2]}-${r.timestamp??""}`;t.set(n,{id:n,agent:e[2],status:e[1],task:e[3],summary:ea(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,i=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),o="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${i}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:i,status:"running",task:o,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!es(t))return{...e,summary:ea(r)};let i=Array.isArray(t.results)?t.results.filter(es):[],o=i[0],l=o?.progressSummary,s=o&&(n=o.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=ed(o?.finalOutput,o?.output,r);return{...e,mode:ed(t.mode),runId:ed(t.runId),agent:ed(o?.agent,e.agent)??e.agent,task:ed(o?.task,e.task),summary:ea(a),model:ed(o?.model),durationMs:ec(l?.durationMs),toolCount:ec(l?.toolCount),tokens:ec(l?.tokens),outputPath:ed(o?.savedOutputPath,o?.artifactPaths?.outputPath),sessionFile:ed(o?.sessionFile,o?.artifactPaths?.jsonlPath),artifacts:s,resultCount:i.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return es(t)&&Array.isArray(t.results)&&t.results.some(e=>es(e)&&"number"==typeof e.exitCode&&0!==e.exitCode)?"failed":"completed"}(r)},r.details,n))}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function ep({messages:e,runs:t}){let r=(0,i.useMemo)(()=>eu(e??[]),[e]),o=t??r,l=o.filter(e=>"running"===e.status),s=o.filter(e=>"running"!==e.status);return 0===o.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(eh,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(eh,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function eh({title:e,runs:t,compact:r}){return(0,n.jsxs)("div",{style:{marginBottom:r?10:16},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t.map(e=>(0,n.jsx)(ex,{run:e},e.id))]})}function ex({run:e}){let[t,r]=(0,i.useState)(!1),o="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":o?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":o?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":o?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(eg,{running:o,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:ea(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${s}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[e.summary&&(0,n.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.summary}),(0,n.jsx)(ef,{run:e})]})]})}function eg({running:e,color:t}){return(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:t,display:"inline-block",animation:e?"pulse 1.5s infinite":void 0,flexShrink:0}})}function ef({run:e}){let t=[e.model?["model",e.model]:void 0,e.runId?["run",e.runId]:void 0,e.outputPath?["output",e.outputPath]:void 0,e.sessionFile?["session",e.sessionFile]:void 0,...(e.artifacts??[]).slice(0,4).map((e,t)=>[`artifact ${t+1}`,e])].filter(Boolean);return 0===t.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:t.map(([e,t])=>(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:e}),(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t,children:t})]},`${e}:${t}`))})}function ev({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:i,isNew:o,isStreaming:l=!1,onResume:s,onDismiss:a}){if(o||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),i&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",i.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:a,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,n.jsx)("button",{type:"button",onClick:s,disabled:l,title:l?"Wait until the agent finishes before updating Workbench":c?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:l?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:l?.55:1,whiteSpace:"nowrap"},children:c?"Reload Initial Data":"Resume Workbench"})]})}var eb=r(9544);let em=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ey(e){return em.some(t=>e.type.startsWith(t))}function ej({agentPhase:e,startedAt:t}){let[r,o]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!t)return void o(0);let e=()=>o(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.args??e.name);return 0===t.length?"Running tool…":1===t.length?`Running ${t[0]}…`:`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e),"\xa0\xa0",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(r)]})})}function ek(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function ew({goal:e}){if(!(e&&"dropped"!==e.status))return null;let t=e.tokenBudget&&e.tokenBudget>0?Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)):null;return(0,n.jsx)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:(0,n.jsxs)("div",{style:{padding:"10px 14px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(e.status)},children:function(e){switch(e){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,n.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:e.objective}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)}),(0,n.jsxs)("span",{children:[ek(e.tokensUsed),e.tokenBudget?` / ${ek(e.tokenBudget)} tokens`:" tokens"]}),null!=t&&(0,n.jsxs)("span",{children:[t,"%"]})]}),null!=t&&(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,n.jsx)("div",{style:{height:"100%",borderRadius:999,background:t>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(t,100)}%`,transition:"width 0.3s"}})})]})})}function eS(e){let t=e.content;return"string"==typeof t?t:Array.isArray(t)?t.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"):""}let eC=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function eT({phrases:e}){let[t,r]=(0,i.useState)(()=>Math.floor(Math.random()*e.length)),[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,i.useEffect)(()=>{let n,i=e[t];if(s||o!==i)if(s&&""===o)a(!1),r(t=>(t+1)%e.length);else{let e=s?i.slice(0,o.length-1):i.slice(0,o.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[o,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[o,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function ez({status:e}){let t=e?.current??"0.8.130"??"0.0.0";if(e?.updateAvailable){let r=e.latest?`v${e.latest}`:"latest";return(0,n.jsxs)("span",{title:`Current v${t}; latest ${r}; run ${e.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:e.updateCommand})]})}return(0,n.jsxs)("span",{title:`AnnoVibe v${t}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",t]})}function eI({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSessionStatsChange:c,onContextUsageChange:u,onToolPresetActive:p,generativeUI:h,forkSettings:x,activeFilePath:g,onOpenFileAtLine:f}){var v;let b,[m,j]=(0,i.useState)(null),[k,w]=(0,i.useState)(!1),S=g&&!k?g:null;(0,i.useEffect)(()=>{w(!1)},[g]);let{data:C,loading:T,error:z,messages:I,entryIds:R,streamState:M,agentRunning:W,modelNames:L,modelList:E,modelThinkingLevels:$,modelThinkingLevelMaps:P,toolPreset:D,memoryTools:B,thinkingLevel:O,retryInfo:N,contextUsage:A,forkingEntryId:F,isCompacting:U,compactError:_,compactInfo:K,displayModel:J,sessionStats:q,agentPhase:V,agentError:Y,isNew:G,loadMoreMessages:Z,hasMoreMessages:X,totalMessages:Q,loadedMessagesCount:ee,loadShadowedMessages:et,messagesEndRef:er,scrollContainerRef:en,lastUserMsgRef:eo,handleSend:es,handleAbort:ea,handleFork:ed,handleNavigate:ec,handleModelChange:eh,handleCompact:ex,handleSteer:eg,handleFollowUp:ef,handleAbortCompaction:em,handleToolPresetChange:ek,handleMemoryToolsChange:eR,handleThinkingLevelChange:eM,handleAgentEventRef:eW,forkToNewSession:eL}=(0,eb.T)({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:d}),eE=(0,i.useMemo)(()=>{let e=new Map;for(let t of C?.context.compactions??[])e.set(t.entryId,t.shadowedCount);return e},[C?.context.compactions]),[e$,eP]=(0,i.useState)(!1),[eD,eB]=(0,i.useState)(null),eO=(0,i.useRef)(!1),eN=x??{enabled:!0,suggestTokens:18e4,autoTokens:4e5,minMessages:20};(0,i.useEffect)(()=>{eB(null),eO.current=!1},[e?.id]);let eA=(0,i.useCallback)(()=>{let r=C?.info?.cwd??e?.cwd??t??null,n=I.filter(e=>"user"===e.role||"assistant"===e.role),i=n.filter(e=>"user"===e.role),o=n.filter(e=>"assistant"===e.role),l=i[0],s=i[i.length-1],a=o[o.length-1],d=(e,t)=>{let r=e.replace(/\s+/g," ").trim();return r.length>t?`${r.slice(0,t)}…`:r};return["以下是从父会话 fork 出的新会话。工作仍在原项目目录中进行,但本会话只携带精简摘要,完整历史不再重发(避免模型 prefill 变慢)。",r?`工作目录: ${r}`:"",l?`最初目标: ${d(eS(l),500)}`:"",s?`最近一次请求: ${d(eS(s),500)}`:"",a?`最近回复要点: ${d(eS(a),900)}`:"",`父会话共 ${Q||n.length} 条消息。若需要更早的细节,请说明是哪个任务,我会让你查看父会话文件或重新提供。`].filter(Boolean).join("\n\n")},[C?.info?.cwd,e?.cwd,t,I,Q]),eH=(0,i.useCallback)(async()=>{if(W||e$)return{ok:!1,error:"Session is busy"};eP(!0),eB(null);try{let e=await eL(eA());return e.ok||eB(e.error??"Fork failed"),e}finally{eP(!1)}},[W,e$,eL,eA]),eF=A?.tokens??null,eU=I.filter(e=>"user"===e.role||"assistant"===e.role).length,e_=!G&&!W&&eN.enabled&&null!=eF&&eF>=eN.suggestTokens&&eU>=eN.minMessages;(0,i.useEffect)(()=>{if(!eN.enabled||G||W)return;let t=A?.tokens;if(null==t||t<eN.autoTokens||eU<eN.minMessages||eO.current)return;let r=e?.id;if(r){try{if(localStorage.getItem(`annovibe.autoFork.dismiss.${r}`))return}catch{}eO.current=!0,(async()=>{let e=await eL(eA());if(e.ok)try{localStorage.setItem(`annovibe.autoFork.dismiss.${r}`,String(Date.now()))}catch{}else eO.current=!1,eB(e.error??"Auto-fork failed")})()}},[eN.enabled,eN.autoTokens,eN.minMessages,G,W,A?.tokens,eU,e?.id,eL,eA]),(0,i.useEffect)(()=>{W&&!m&&j(Date.now()),W||j(null)},[W,m]);let eK=eW.current;(0,i.useEffect)(()=>{eW.current=e=>{"agent_start"===e.type&&j(Date.now()),"agent_end"===e.type&&!0!==e.willRetry&&j(null),eK?.(e)}},[eK,eW]);let eJ=q?`${q.tokens.input}|${q.tokens.output}|${q.tokens.cacheRead}|${q.tokens.cacheWrite}`:null,eq=(0,i.useRef)(q);eq.current=q,(0,i.useEffect)(()=>{c?.(eq.current)},[eJ,c]),(0,i.useEffect)(()=>()=>{c?.(null)},[c]),(0,i.useEffect)(()=>(p?.("workbench"===D),()=>{p?.(!1)}),[D,p]);let eV=A?`${A.percent??"null"}|${A.contextWindow}|${A.tokens??"null"}`:null,eY=(0,i.useRef)(A);eY.current=A,(0,i.useEffect)(()=>{u?.(eY.current)},[eV,u]),(0,i.useEffect)(()=>()=>{u?.(null)},[u]);let eG=(0,i.useCallback)(e=>{a?.current?.addFiles(e)},[a]),eZ=(0,i.useCallback)((e,t,r)=>{let n=r?.findIndex(t=>t.src===e)??-1;e8({src:e,gallery:r,index:n>=0?n:0})},[]),{isDragOver:eX,handleDragEnter:eQ,handleDragOver:e0,handleDragLeave:e1,handleDrop:e2}=function(e){let[t,r]=(0,i.useState)(!1),n=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ey)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ey)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}(eG),[e5,e4]=(0,i.useState)(null),[e3,e8]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!G)return;let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&e4(t)}).catch(()=>{}),()=>{e=!0}},[G]);let e6=I.filter(e=>"user"===e.role||"assistant"===e.role),e7=(v=e6.length,(b=(0,i.useRef)([])).current=Array(v).fill(null).map((e,t)=>b.current[t]??null),b),e9=(0,i.useMemo)(()=>{let e=new Map;for(let t of I)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[I]),te=G&&0===I.length&&!M.isStreaming&&!W,tt=C?.info?.cwd??e?.cwd??t??null,tr=function(e){if(!e)return null;let t=e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return t[t.length-1]||e}(tt),tn=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[ti,to]=(0,i.useState)(!1),[tl,ts]=(0,i.useState)(!1),ta=eu(I),td=ta.filter(e=>"running"===e.status).length;(0,i.useEffect)(()=>{0===ta.length&&ti&&to(!1)},[ta.length,ti]),(0,i.useEffect)(()=>{tn&&ti&&to(!1)},[tn,ti]),(0,i.useEffect)(()=>{ts(!1)},[e?.id]);let tc=(0,i.useCallback)(()=>{e?.id&&!W&&(async()=>{await ek("workbench");let e=C?.sessionMeta;if(e?.initialSourcePath&&e.initialKernel){let t=`Resume this Workbench session. Reload only the initial data file \`${e.initialSourcePath}\` using the ${e.initialKernel.toUpperCase()} runtime. Do not rerun previous analyses or load extra files unless I ask. Use the chat history only as context for what to do next.`;await es(t)}})()},[W,C?.sessionMeta,es,ek,e?.id]),tu=J?$[`${J.provider}:${J.modelId}`]??null:null,tp=J?P[`${J.provider}:${J.modelId}`]??null:null,th=C?.sessionMeta?.sessionKind??null,tx=e?.id??t??"new-chat",tg=(0,i.useMemo)(()=>(function(e){let t=[];for(let r=e.length-1;r>=0;r-=1){let n=e[r];if("user"!==n.role)continue;let i=n.text.trim();i&&t.push(i)}return t})(e6.map(e=>({role:e.role,text:eS(e)}))),[e6]),tf=(0,i.useCallback)(async(e,t,r)=>{let n=e;S&&e.trim()&&(n=`${e}
|
|
6
|
+
[truncated after 60000 characters]`,truncated:!0};if(!o)return{extractionError:"No extractable text found"};return{extractedText:o,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let ei=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,compactInfo:g,toolPreset:f,sessionKind:v,onToolPresetChange:b,memoryTools:m,onMemoryToolsChange:y,thinkingLevel:j,onThinkingLevelChange:k,availableThinkingLevels:w,thinkingLevelMap:S,retryInfo:C,cornerBadge:T,promptHistory:z,sessionHistoryKey:I,activeFilePath:R,onDismissFileContext:M},W){let[L,E]=(0,i.useState)(""),[$,P]=(0,i.useState)(!1),[D,B]=(0,i.useState)("root"),[O,N]=(0,i.useState)(null),[A,H]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(!1),[ee,et]=(0,i.useState)(!1),[er,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(!1),[es,ea]=(0,i.useState)(null),[ed,ec]=(0,i.useState)([]),[eu,ep]=(0,i.useState)([]),eh=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),ex=eh?{display:"none"}:void 0,eg=eh?28:32,ef=eh?"6px 8px":"8px 12px",ev=eh&&!l,eb=eo?"var(--text)":"var(--text-muted)",em={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},ey=eh?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[ej,ek]=(0,i.useState)(null),ew=(0,i.useRef)(null),eS=(0,i.useRef)(null),eC=(0,i.useRef)(null),eT=(0,i.useRef)(null),ez=(0,i.useRef)(null),eI=(0,i.useRef)(null),eR=(0,i.useRef)(null),eM=(0,i.useRef)(null),eW=(0,i.useRef)(null),eL=(0,i.useRef)(null),eE=(0,i.useCallback)(e=>{let t=ew.current;if(!t)return void E(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=!(i.length>0)||i.endsWith(" ")||i.endsWith("\n")?"":" ";E(i+l+e+o),requestAnimationFrame(()=>{let t=ew.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,i.useImperativeHandle)(W,()=>({insertIfEmpty(e){let t=ew.current;(t?t.value:L).trim()||(E(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eE(e)},addImages(e){e$(e)},addFiles(e){eP(e)}}));let e$=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ec(e=>[...e,...r])},[]),eP=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&e$(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,i=await en(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...i})},n.onerror=r,n.readAsArrayBuffer(e)})));ep(t=>[...t,...e])}},[e$]),eD=(0,i.useCallback)(e=>{ec(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eB=(0,i.useCallback)(e=>{ep(t=>{let r=[...t];return r.splice(e,1),r})},[]),eO=(0,i.useCallback)(()=>{ec(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ep([])},[]),eN=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(a??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})),eA=[];for(let e of eN){let t=eA.find(t=>t.provider===e.provider);t?t.options.push(e):eA.push({provider:e.provider,options:[e]})}let eH=s?eN.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eN.length>0?eN[0].name:null,eF=s?eN.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eN[0],eU=eF?.input?.includes("image")??!0,e_=ed.length>0&&eF?.input!==void 0&&!eU,eK=(!!L.trim()||ed.length>0||eu.length>0)&&!e_,eJ=u?G:G.filter(e=>"/compact"!==e.command),eq=eJ.filter(e=>"native"===e.kind),eV=eJ.filter(e=>"shortcut"===e.kind),eY=m??[],eG=eY.length>0?`${eY.length} enabled`:"off",eZ=eN.length>0&&!!eH&&!!c,eX=!!k,eQ=!!b&&"workbench"!==v,e0=(()=>{let e=j??"auto";if("auto"===e)return"Default";if(!S)return e;let t=S[e];return null!=t?t:e})(),e1=eH??"Default",e2=(f??"full")==="workbench"?"workbench":Object.entries(K).find(([,e])=>e===(f??"full"))?.[0]??"full",e5=eh?26:32,e4=eh?7:9,e3=eh?3:6,e8={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},e6=eh&&($||A||X||ee||er||eo);(0,i.useEffect)(()=>{e_||ek(null)},[e_]);let e7=(0,i.useCallback)(e=>{if(!L.trim()){E(e),requestAnimationFrame(()=>{let t=ew.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eE(e)},[eE,L]),e9=(0,i.useCallback)(()=>{let t=L.trim();if(t||ed.length||eu.length){if(ed.length&&!eU)return void ek("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!ed.length&&!eu.length&&u){h?p?.():u(),E(""),ew.current&&(ew.current.style.height="auto");return}e(t,ed.length?ed:void 0,eu.length?eu:void 0),E(""),eO(),ew.current&&(ew.current.style.height="auto")}}},[L,ed,eu,eU,l,e,eO,u,p,h]),te=(0,i.useCallback)(e=>{let t=L.trim();if(!t&&!ed.length&&!eu.length)return;if(ed.length&&!eU)return void ek("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=ed.length?ed:void 0,i=eu.length?eu:void 0;"steer"===e&&r?r(t,n,i):"followup"===e&&o&&o(t,n,i),E(""),eO(),ew.current&&(ew.current.style.height="auto")},[L,ed,eu,eU,r,o,eO]),tt=z??[],tr=I??null,tn=(0,i.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&tt.length>0){let t=ew.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let i=((n=U.get(e))||(n={cursor:-1,draftSnapshot:""},U.set(e,n)),n);if(-1===i.cursor)i.draftSnapshot=t,i.cursor=0;else{if(!(i.cursor<r.length-1))return null;i.cursor+=1}return r[i.cursor]??null}(tr,t.value,tt);null!==n&&(E(n),requestAnimationFrame(()=>{t.setSelectionRange(n.length,n.length)}));return}if("ArrowDown"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&function(e){if(!e)return!1;let t=U.get(e);return(t?.cursor??-1)>=0}(tr)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=U.get(e);if(!r||-1===r.cursor)return null;if(r.cursor>0)return r.cursor-=1,{text:t[r.cursor]??"",returnedToPresent:!1};let n=r.draftSnapshot;return r.cursor=-1,r.draftSnapshot="",{text:n,returnedToPresent:!0}}(tr,tt);t&&(E(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=ew.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),tr&&U.set(tr,{cursor:-1,draftSnapshot:""}),l&&(r||o)?te(r?"steer":"followup"):e9())},[l,r,o,te,e9,tt,tr]),ti=(0,i.useCallback)(()=>{let e=ew.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),to=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eP(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eP]);(0,i.useEffect)(()=>{if(!$&&!A&&!X&&!ee&&!er&&!eo)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eS.current?.contains(t),n=!!eC.current?.contains(t);r||n||P(!1),eT.current?.contains(t)||H(!1),ez.current?.contains(t)||Q(!1),eI.current?.contains(t)||et(!1),eR.current?.contains(t)||ei(!1),eM.current?.contains(t)||el(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[$,A,X,ee,er,eo]),(0,i.useEffect)(()=>{if(!b)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||ea(!!t?.ready)}).catch(()=>{e||ea(!1)}),()=>{e=!0}},[b]),(0,i.useEffect)(()=>{if(!$)return;let e=e=>{"Escape"===e.key&&("root"!==D?B("root"):P(!1))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[$,D]);let tl=e=>(0,n.jsx)("svg",{width:e,height:e,viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}),ts=(e,t)=>(0,n.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0,...t},children:(0,n.jsx)("path",{d:"M9 6l6 6-6 6",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})}),ta=()=>{let e=()=>{P(!1),B("root")},t=e=>{e.currentTarget.style.background="var(--bg-hover)"},r=e=>{e.currentTarget.style.background="transparent"},i={display:"flex",alignItems:"center",gap:8,width:"100%",height:40,padding:"0 10px",border:"none",borderRadius:10,background:"transparent",color:"var(--text)",fontSize:14,lineHeight:"22px",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},o={display:"flex",alignItems:"center",gap:8,width:"100%",minHeight:38,padding:"6px 8px",border:"none",borderRadius:10,background:"transparent",color:"var(--text)",textAlign:"left",cursor:"pointer",fontFamily:"inherit"},a={position:"sticky",top:0,zIndex:1,padding:"5px 8px 3px",background:"var(--bg)",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",fontWeight:500},d=V.filter(e=>!w||"auto"===e||w.includes(e)),u=(0,n.jsxs)(n.Fragment,{children:["root"===D&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>B("model"),role:"menuitem",style:i,onMouseEnter:t,onMouseLeave:r,children:[(0,n.jsx)("span",{style:{flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"模型"}),(0,n.jsx)("span",{style:{flex:"0 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:13},children:e1}),ts(14,{color:"var(--text-dim)"})]}),eX&&(0,n.jsxs)("button",{onClick:()=>B("effort"),role:"menuitem",style:i,onMouseEnter:t,onMouseLeave:r,children:[(0,n.jsx)("span",{style:{flex:"1 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"推理强度"}),(0,n.jsx)("span",{style:{flex:"0 1 auto",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:13},children:e0}),ts(14,{color:"var(--text-dim)"})]})]}),"model"===D&&(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:eA.map(i=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:a,children:i.provider}),i.options.map(i=>{let l=i.modelId===s?.modelId&&i.provider===s?.provider,a=i.input&&i.input.length>0?i.input.join(" \xb7 "):void 0;return(0,n.jsxs)("button",{onClick:()=>{e(),l||c(i.provider,i.modelId)},role:"menuitemradio","aria-checked":l,style:o,onMouseEnter:t,onMouseLeave:r,children:[(0,n.jsxs)("span",{style:{display:"flex",flex:1,flexDirection:"column",minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",color:"inherit",fontSize:14,lineHeight:"20px",fontWeight:500,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.name}),void 0!==a&&(0,n.jsx)("span",{style:{overflow:"hidden",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]}),(0,n.jsx)("span",{style:{display:"grid",placeItems:"center",flex:"0 0 18px",color:"var(--text)"},children:l?tl(14):null})]},`${i.provider}:${i.modelId}`)})]},i.provider))}),"effort"===D&&eX&&(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:d.map(i=>{let l=(j??"auto")===i,s="auto"!==i?S?.[i]:void 0,a="auto"===i?"Default":null!=s&&s!==i?s:i,d="auto"!==i&&null!=s&&s!==i;return(0,n.jsxs)("button",{onClick:()=>{e(),l||k?.(i)},role:"menuitemradio","aria-checked":l,style:o,onMouseEnter:t,onMouseLeave:r,children:[(0,n.jsxs)("span",{style:{display:"flex",flex:1,flexDirection:"column",minWidth:0},children:[(0,n.jsxs)("span",{style:{overflow:"hidden",color:"inherit",fontSize:14,lineHeight:"20px",fontWeight:500,textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a,d&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",i,")"]})]}),(0,n.jsx)("span",{style:{overflow:"hidden",color:"var(--text-dim)",fontSize:12,lineHeight:"18px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Y[i]})]}),(0,n.jsx)("span",{style:{display:"grid",placeItems:"center",flex:"0 0 18px",color:"var(--text)"},children:l?tl(14):null})]},i)})})]}),p=window.visualViewport?.width??window.innerWidth,h=window.visualViewport?.height??window.innerHeight,x=O?h-O.top+6:0,g=O?Math.max(120,Math.min(O.top-8,.6*h)):240,f=O?Math.max(8,p-(O.left+O.width)):0;return(0,n.jsxs)("div",{ref:eS,style:{position:"relative",flex:eh?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!eh){let t=e.currentTarget.getBoundingClientRect();N({top:t.top,left:t.left,width:t.width})}H(!1),Q(!1),et(!1),ei(!1),el(!1),B("root"),P(e=>!e)},disabled:l,title:"选择模型与推理强度",style:{display:"flex",alignItems:"center",gap:4,height:eh?eg:28,padding:eh?ef:"0 4px 0 8px",width:eh?"100%":void 0,maxWidth:eh?"100%":220,overflow:"hidden",background:$?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:24,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eh?11:13,lineHeight:eh?void 0:"20px",fontWeight:eh?void 0:500,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=$?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eH??"Default"}),eX&&(0,n.jsxs)("span",{style:{flex:"0 0 auto",color:"var(--text-dim)"},children:["\xb7 ",e0]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{flex:"0 0 auto",color:"var(--text-dim)",transform:$?"rotate(180deg)":"none",transition:"transform 120ms ease"},children:(0,n.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),$&&(eh?(0,n.jsxs)("div",{ref:eC,style:{...e8,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:["root"!==D&&(0,n.jsx)("button",{onClick:()=>B("root"),"aria-label":"返回",style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,flexShrink:0,background:"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:(0,n.jsx)("path",{d:"M15 6l-6 6 6 6",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"model"===D?"Models":"effort"===D?"推理强度":"模型"})]}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:"effort"===D?e0:e1})]}),u]}):O&&(0,n.jsx)("div",{ref:eC,role:"menu","aria-label":"模型与推理等级",onKeyDown:e=>{("ArrowDown"===e.key||"ArrowUp"===e.key)&&(e.preventDefault(),(e=>{let t=eC.current;if(!t)return;let r=Array.from(t.querySelectorAll('button[role="menuitem"], button[role="menuitemradio"]'));if(0===r.length)return;let n=(Math.max(r.findIndex(e=>e===document.activeElement),0)+e+r.length)%r.length;r[n]?.focus()})("ArrowDown"===e.key?1:-1))},style:{position:"fixed",bottom:x,right:f,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 8px 24px -8px rgba(0,0,0,0.18)",width:"min(240px, calc(100vw - 32px))",maxHeight:g,overflow:"hidden",display:"flex",flexDirection:"column",padding:4},children:u}))]})};return(0,n.jsxs)("div",{style:ey,children:[e6&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{P(!1),H(!1),Q(!1),et(!1),ei(!1),el(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,n.jsx)("input",{ref:eW,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{e$(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eL,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{eP(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:eh?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:eh?"0 8px":void 0,boxSizing:"border-box"},children:[T&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:T}),C&&(0,n.jsxs)("div",{style:{marginBottom:eh?6:8,padding:eh?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:eh?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",C.attempt,"/",C.maxAttempts,")…",C.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",C.errorMessage]})]}),R&&(0,n.jsxs)("div",{style:{marginBottom:eh?6:8,padding:eh?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:eh?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R.replace(/^.*[\\/]/,"")}),M&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),M()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(ed.length>0||eu.length>0)&&(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[ed.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${e_?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eD(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${t}`)),eu.map((e,t)=>(0,n.jsx)(Z,{doc:e,onRemove:()=>eB(t)},`doc-${t}`))]}),(e_||ej)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:eh?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,n.jsx)("span",{children:ej??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:eh?4:8,alignItems:eh?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:eh?13:14,padding:eh?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:ew,value:L,onChange:e=>E(e.target.value),onKeyDown:tn,onInput:ti,onPaste:to,placeholder:l&&(r||o)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:eh?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!eh,paddingBottom:+!!eh}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:eh?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>te("steer"),disabled:!eK,title:e_?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!eh,padding:eh?"6px 8px":"7px 12px",background:eK?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eK?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eK?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!eh&&"Steer"]}),o&&(0,n.jsxs)("button",{onClick:()=>te("followup"),disabled:!eK,title:e_?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!eh,padding:eh?"6px 8px":"7px 12px",background:eK?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eK?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eK?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!eh&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:e9,disabled:!eK,title:e_?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eh?3:6,padding:eh?"5px 9px":"7px 14px",marginBottom:+!!eh,background:eK?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eK?"#fff":"var(--text-dim)",cursor:eK?"pointer":"not-allowed",fontSize:eh?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eK?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:eh?13:14,height:eh?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:eh?5:8,display:"flex",alignItems:eh?"flex-start":"center",gap:e3,flexWrap:eh?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:eh?"1 1 100%":"0 0 auto",width:eh?"100%":void 0,display:"flex",alignItems:"center",gap:2*!eh,flexWrap:eh?"wrap":"nowrap",rowGap:4*!!eh},children:[(0,n.jsx)("button",{onClick:()=>eW.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e5,height:e5,padding:0,background:"none",border:"none",borderRadius:e4,color:ed.length||eu.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=ed.length||eu.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=ed.length||eu.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eL.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,n.jsxs)("div",{ref:eT,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(H(e=>!e),Q(!1),P(!1),et(!1),el(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e5,height:e5,padding:0,background:A?"var(--bg-hover)":"none",border:"none",borderRadius:e4,color:x?"#ef4444":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=x?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=A?"var(--bg-hover)":"none",e.currentTarget.style.color=x?"#ef4444":"var(--text-muted)"},children:["/",x&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),A&&(0,n.jsxs)("div",{style:{...eh?e8:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:x?"1px solid var(--border)":"none"},children:"Commands"}),x&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:x}),g&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#34d399",background:"rgba(52,211,153,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:g}),eq.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),eq.map(e=>(0,n.jsxs)("button",{onClick:()=>{(H(!1),"/compact"===e.command&&h)?p?.():e7(e.command)},style:{display:"flex",alignItems:"center",gap:eh?6:8,width:"100%",padding:ef,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:eh?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===e.command&&h?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&h?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===e.command&&h?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&h?"中止当前压缩任务":e.description})]})]},e.command))]}),eV.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eq.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eq.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eV.map(e=>(0,n.jsxs)("button",{onClick:()=>{H(!1),e7(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ef,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eh?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:e.description})]})]},e.command))]})]})]}),y&&(0,n.jsxs)("div",{ref:ez,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(Q(e=>!e),H(!1),P(!1),et(!1),el(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:eg,padding:0,background:X?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:eY.length>0?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eY.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=X?"var(--bg-hover)":"none",e.currentTarget.style.color=eY.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),eY.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),X&&(0,n.jsxs)("div",{style:{...eh?e8:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),F.SN.map(e=>{let t=eY.includes(e),r=q[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?eY.filter(t=>t!==e):[...eY,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ef,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eh?11:12,textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:r.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:r.description})]})]},e)})]})]}),eh&&(eZ||eX)&&ta(),eh&&!l&&(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{ref:eM,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>{H(!1),Q(!1),P(!1),et(!1),ei(!1),el(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:eo?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:eb,cursor:"pointer",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=eo?"var(--bg-hover)":"none",e.currentTarget.style.color=eo?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),eo&&(0,n.jsxs)("div",{style:{...e8,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[eZ&&(0,n.jsxs)("button",{onClick:()=>{el(!1),et(!1),ei(!1),Q(!1),P(!0),B("root")},style:em,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e1})]}),eX&&(0,n.jsxs)("button",{onClick:()=>{el(!1),et(!1),Q(!1),ei(!1),P(!0),B("effort")},style:em,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e0})]}),eQ&&(0,n.jsxs)("button",{onClick:()=>{el(!1),P(!1),ei(!1),Q(!1),et(!0)},style:em,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e2})]}),!!y&&(0,n.jsxs)("button",{onClick:()=>{el(!1),P(!1),et(!1),ei(!1),Q(!0)},style:em,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:eY.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eG})]})]})]})]})})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:ev?"none":void 0,flex:eh?"0 0 auto":1,width:eh?0:void 0,height:eh?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:eh?"auto":void 0,display:"flex",alignItems:"center",gap:eh?4:2,marginLeft:eh?0:"auto",marginTop:0},children:[(!ev&&!l||eh&&ee)&&eQ&&(0,n.jsxs)("div",{ref:eI,style:{position:"relative"},children:[!ev&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(H(!1),Q(!1),P(!1),ei(!1),el(!1),et(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:eh?3:5,padding:ef,height:eg,background:ee?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:(f??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eh?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=(f??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ee?"var(--bg-hover)":"none",e.currentTarget.style.color=(f??"full")==="workbench"?"var(--accent)":"var(--text-muted)"},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(0,n.jsx)("span",{style:ex,children:e2})]}),ee&&(0,n.jsx)("div",{style:{...eh?e8:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:_.map(e=>{let t=K[e],r=(f??"full")===t,i="agent"===e&&!1===es,o=i?"需安装 pi-subagents":J[e];return(0,n.jsxs)("button",{onClick:()=>{!i&&(et(!1),r||b(t))},disabled:i,title:i?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:i?"not-allowed":"pointer",fontSize:eh?11:12,textAlign:"left",fontWeight:r?600:400,opacity:i?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),!eh&&(eZ||eX)&&ta(),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:eg,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:eh?8:9,color:"#ef4444",cursor:"pointer",fontSize:eh?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]})]})]})]})]})});function eo(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function el({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o}){let[l,s]=(0,i.useState)(0),[a,d]=(0,i.useState)(1),[c,u]=(0,i.useState)(!1),[p,h]=(0,i.useState)([]),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),b=(0,i.useRef)(!1),m=(0,i.useRef)(null),y=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,i.useRef)(y);j.current=y;let k=(0,i.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,i=t-n;u(i>20),i<=0?(s(0),d(1)):(s(e.scrollTop/i),d(n/t));let l=o.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let i=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&i&&t>0){let r=i.getBoundingClientRect(),o=e.getBoundingClientRect(),l=r.top-o.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,i.useCallback)(()=>k.current(),[]);(0,i.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,i.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,i.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,i.useCallback)(e=>{if(!c)return;b.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),i=n>=0&&n<=a?n:a/2;S(r-i);let o=e=>{b.current&&S((e.clientY-t.top)/t.height-i)},s=()=>{b.current=!1,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",s)},[c,a,l,S]),T=m.current?.clientHeight??600,z=(0,i.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-a)*100,R=100*a,M=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:m,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${R}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=eo(e.msg),r=x&&M===e.index,i="user"===e.msg.role,o=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${o}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:i?8:6,height:i?8:6,borderRadius:i?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),i=eo(e.msg),o=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${o?i.border:"var(--border)"}`,borderRight:`1px solid ${o?i.border:"var(--border)"}`,borderBottom:`1px solid ${o?i.border:"var(--border)"}`,borderLeft:`2px solid ${i.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:o?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:o?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function es(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ea(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function ed(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ec(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function eu(e){let t=new Map;for(let r of e){if("custom"===r.role&&"subagent-notify"===r.customType&&"string"==typeof r.content){let e=r.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(e){let n=`bg-${e[2]}-${r.timestamp??""}`;t.set(n,{id:n,agent:e[2],status:e[1],task:e[3],summary:ea(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,i=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),o="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${i}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:i,status:"running",task:o,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!es(t))return{...e,summary:ea(r)};let i=Array.isArray(t.results)?t.results.filter(es):[],o=i[0],l=o?.progressSummary,s=o&&(n=o.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=ed(o?.finalOutput,o?.output,r);return{...e,mode:ed(t.mode),runId:ed(t.runId),agent:ed(o?.agent,e.agent)??e.agent,task:ed(o?.task,e.task),summary:ea(a),model:ed(o?.model),durationMs:ec(l?.durationMs),toolCount:ec(l?.toolCount),tokens:ec(l?.tokens),outputPath:ed(o?.savedOutputPath,o?.artifactPaths?.outputPath),sessionFile:ed(o?.sessionFile,o?.artifactPaths?.jsonlPath),artifacts:s,resultCount:i.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return es(t)&&Array.isArray(t.results)&&t.results.some(e=>es(e)&&"number"==typeof e.exitCode&&0!==e.exitCode)?"failed":"completed"}(r)},r.details,n))}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function ep({messages:e,runs:t}){let r=(0,i.useMemo)(()=>eu(e??[]),[e]),o=t??r,l=o.filter(e=>"running"===e.status),s=o.filter(e=>"running"!==e.status);return 0===o.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(eh,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(eh,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function eh({title:e,runs:t,compact:r}){return(0,n.jsxs)("div",{style:{marginBottom:r?10:16},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t.map(e=>(0,n.jsx)(ex,{run:e},e.id))]})}function ex({run:e}){let[t,r]=(0,i.useState)(!1),o="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":o?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":o?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":o?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(eg,{running:o,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:ea(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${s}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[e.summary&&(0,n.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.summary}),(0,n.jsx)(ef,{run:e})]})]})}function eg({running:e,color:t}){return(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:t,display:"inline-block",animation:e?"pulse 1.5s infinite":void 0,flexShrink:0}})}function ef({run:e}){let t=[e.model?["model",e.model]:void 0,e.runId?["run",e.runId]:void 0,e.outputPath?["output",e.outputPath]:void 0,e.sessionFile?["session",e.sessionFile]:void 0,...(e.artifacts??[]).slice(0,4).map((e,t)=>[`artifact ${t+1}`,e])].filter(Boolean);return 0===t.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:t.map(([e,t])=>(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:e}),(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t,children:t})]},`${e}:${t}`))})}function ev({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:i,isNew:o,isStreaming:l=!1,onResume:s,onDismiss:a}){if(o||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),i&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",i.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:a,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,n.jsx)("button",{type:"button",onClick:s,disabled:l,title:l?"Wait until the agent finishes before updating Workbench":c?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:l?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:l?.55:1,whiteSpace:"nowrap"},children:c?"Reload Initial Data":"Resume Workbench"})]})}var eb=r(9544);let em=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ey(e){return em.some(t=>e.type.startsWith(t))}function ej({agentPhase:e,startedAt:t}){let[r,o]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!t)return void o(0);let e=()=>o(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.args??e.name);return 0===t.length?"Running tool…":1===t.length?`Running ${t[0]}…`:`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e),"\xa0\xa0",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(r)]})})}function ek(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function ew({goal:e}){if(!(e&&"dropped"!==e.status))return null;let t=e.tokenBudget&&e.tokenBudget>0?Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)):null;return(0,n.jsx)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:(0,n.jsxs)("div",{style:{padding:"10px 14px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(e.status)},children:function(e){switch(e){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,n.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:e.objective}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)}),(0,n.jsxs)("span",{children:[ek(e.tokensUsed),e.tokenBudget?` / ${ek(e.tokenBudget)} tokens`:" tokens"]}),null!=t&&(0,n.jsxs)("span",{children:[t,"%"]})]}),null!=t&&(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,n.jsx)("div",{style:{height:"100%",borderRadius:999,background:t>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(t,100)}%`,transition:"width 0.3s"}})})]})})}function eS(e){let t=e.content;return"string"==typeof t?t:Array.isArray(t)?t.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"):""}let eC=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function eT({phrases:e}){let[t,r]=(0,i.useState)(()=>Math.floor(Math.random()*e.length)),[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,i.useEffect)(()=>{let n,i=e[t];if(s||o!==i)if(s&&""===o)a(!1),r(t=>(t+1)%e.length);else{let e=s?i.slice(0,o.length-1):i.slice(0,o.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[o,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[o,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function ez({status:e}){let t=e?.current??"0.8.134"??"0.0.0";if(e?.updateAvailable){let r=e.latest?`v${e.latest}`:"latest";return(0,n.jsxs)("span",{title:`Current v${t}; latest ${r}; run ${e.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:e.updateCommand})]})}return(0,n.jsxs)("span",{title:`AnnoVibe v${t}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",t]})}function eI({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSessionStatsChange:c,onContextUsageChange:u,onToolPresetActive:p,generativeUI:h,forkSettings:x,activeFilePath:g,onOpenFileAtLine:f}){var v;let b,[m,j]=(0,i.useState)(null),[k,w]=(0,i.useState)(!1),S=g&&!k?g:null;(0,i.useEffect)(()=>{w(!1)},[g]);let{data:C,loading:T,error:z,messages:I,entryIds:R,streamState:M,agentRunning:W,modelNames:L,modelList:E,modelThinkingLevels:$,modelThinkingLevelMaps:P,toolPreset:D,memoryTools:B,thinkingLevel:O,retryInfo:N,contextUsage:A,forkingEntryId:F,isCompacting:U,compactError:_,compactInfo:K,displayModel:J,sessionStats:q,agentPhase:V,agentError:Y,isNew:G,loadMoreMessages:Z,hasMoreMessages:X,totalMessages:Q,loadedMessagesCount:ee,loadShadowedMessages:et,messagesEndRef:er,scrollContainerRef:en,lastUserMsgRef:eo,handleSend:es,handleAbort:ea,handleFork:ed,handleNavigate:ec,handleModelChange:eh,handleCompact:ex,handleSteer:eg,handleFollowUp:ef,handleAbortCompaction:em,handleToolPresetChange:ek,handleMemoryToolsChange:eR,handleThinkingLevelChange:eM,handleAgentEventRef:eW,forkToNewSession:eL}=(0,eb.T)({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:d}),eE=(0,i.useMemo)(()=>{let e=new Map;for(let t of C?.context.compactions??[])e.set(t.entryId,t.shadowedCount);return e},[C?.context.compactions]),[e$,eP]=(0,i.useState)(!1),[eD,eB]=(0,i.useState)(null),eO=(0,i.useRef)(!1),eN=x??{enabled:!0,suggestTokens:18e4,autoTokens:4e5,minMessages:20};(0,i.useEffect)(()=>{eB(null),eO.current=!1},[e?.id]);let eA=(0,i.useCallback)(()=>{let r=C?.info?.cwd??e?.cwd??t??null,n=I.filter(e=>"user"===e.role||"assistant"===e.role),i=n.filter(e=>"user"===e.role),o=n.filter(e=>"assistant"===e.role),l=i[0],s=i[i.length-1],a=o[o.length-1],d=(e,t)=>{let r=e.replace(/\s+/g," ").trim();return r.length>t?`${r.slice(0,t)}…`:r};return["以下是从父会话 fork 出的新会话。工作仍在原项目目录中进行,但本会话只携带精简摘要,完整历史不再重发(避免模型 prefill 变慢)。",r?`工作目录: ${r}`:"",l?`最初目标: ${d(eS(l),500)}`:"",s?`最近一次请求: ${d(eS(s),500)}`:"",a?`最近回复要点: ${d(eS(a),900)}`:"",`父会话共 ${Q||n.length} 条消息。若需要更早的细节,请说明是哪个任务,我会让你查看父会话文件或重新提供。`].filter(Boolean).join("\n\n")},[C?.info?.cwd,e?.cwd,t,I,Q]),eH=(0,i.useCallback)(async()=>{if(W||e$)return{ok:!1,error:"Session is busy"};eP(!0),eB(null);try{let e=await eL(eA());return e.ok||eB(e.error??"Fork failed"),e}finally{eP(!1)}},[W,e$,eL,eA]),eF=A?.tokens??null,eU=I.filter(e=>"user"===e.role||"assistant"===e.role).length,e_=!G&&!W&&eN.enabled&&null!=eF&&eF>=eN.suggestTokens&&eU>=eN.minMessages;(0,i.useEffect)(()=>{if(!eN.enabled||G||W)return;let t=A?.tokens;if(null==t||t<eN.autoTokens||eU<eN.minMessages||eO.current)return;let r=e?.id;if(r){try{if(localStorage.getItem(`annovibe.autoFork.dismiss.${r}`))return}catch{}eO.current=!0,(async()=>{let e=await eL(eA());if(e.ok)try{localStorage.setItem(`annovibe.autoFork.dismiss.${r}`,String(Date.now()))}catch{}else eO.current=!1,eB(e.error??"Auto-fork failed")})()}},[eN.enabled,eN.autoTokens,eN.minMessages,G,W,A?.tokens,eU,e?.id,eL,eA]),(0,i.useEffect)(()=>{W&&!m&&j(Date.now()),W||j(null)},[W,m]);let eK=eW.current;(0,i.useEffect)(()=>{eW.current=e=>{"agent_start"===e.type&&j(Date.now()),"agent_end"===e.type&&!0!==e.willRetry&&j(null),eK?.(e)}},[eK,eW]);let eJ=q?`${q.tokens.input}|${q.tokens.output}|${q.tokens.cacheRead}|${q.tokens.cacheWrite}`:null,eq=(0,i.useRef)(q);eq.current=q,(0,i.useEffect)(()=>{c?.(eq.current)},[eJ,c]),(0,i.useEffect)(()=>()=>{c?.(null)},[c]),(0,i.useEffect)(()=>(p?.("workbench"===D),()=>{p?.(!1)}),[D,p]);let eV=A?`${A.percent??"null"}|${A.contextWindow}|${A.tokens??"null"}`:null,eY=(0,i.useRef)(A);eY.current=A,(0,i.useEffect)(()=>{u?.(eY.current)},[eV,u]),(0,i.useEffect)(()=>()=>{u?.(null)},[u]);let eG=(0,i.useCallback)(e=>{a?.current?.addFiles(e)},[a]),eZ=(0,i.useCallback)((e,t,r)=>{let n=r?.findIndex(t=>t.src===e)??-1;e8({src:e,gallery:r,index:n>=0?n:0})},[]),{isDragOver:eX,handleDragEnter:eQ,handleDragOver:e0,handleDragLeave:e1,handleDrop:e2}=function(e){let[t,r]=(0,i.useState)(!1),n=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ey)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ey)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}(eG),[e5,e4]=(0,i.useState)(null),[e3,e8]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!G)return;let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&e4(t)}).catch(()=>{}),()=>{e=!0}},[G]);let e6=I.filter(e=>"user"===e.role||"assistant"===e.role),e7=(v=e6.length,(b=(0,i.useRef)([])).current=Array(v).fill(null).map((e,t)=>b.current[t]??null),b),e9=(0,i.useMemo)(()=>{let e=new Map;for(let t of I)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[I]),te=G&&0===I.length&&!M.isStreaming&&!W,tt=C?.info?.cwd??e?.cwd??t??null,tr=function(e){if(!e)return null;let t=e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return t[t.length-1]||e}(tt),tn=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[ti,to]=(0,i.useState)(!1),[tl,ts]=(0,i.useState)(!1),ta=eu(I),td=ta.filter(e=>"running"===e.status).length;(0,i.useEffect)(()=>{0===ta.length&&ti&&to(!1)},[ta.length,ti]),(0,i.useEffect)(()=>{tn&&ti&&to(!1)},[tn,ti]),(0,i.useEffect)(()=>{ts(!1)},[e?.id]);let tc=(0,i.useCallback)(()=>{e?.id&&!W&&(async()=>{await ek("workbench");let e=C?.sessionMeta;if(e?.initialSourcePath&&e.initialKernel){let t=`Resume this Workbench session. Reload only the initial data file \`${e.initialSourcePath}\` using the ${e.initialKernel.toUpperCase()} runtime. Do not rerun previous analyses or load extra files unless I ask. Use the chat history only as context for what to do next.`;await es(t)}})()},[W,C?.sessionMeta,es,ek,e?.id]),tu=J?$[`${J.provider}:${J.modelId}`]??null:null,tp=J?P[`${J.provider}:${J.modelId}`]??null:null,th=C?.sessionMeta?.sessionKind??null,tx=e?.id??t??"new-chat",tg=(0,i.useMemo)(()=>(function(e){let t=[];for(let r=e.length-1;r>=0;r-=1){let n=e[r];if("user"!==n.role)continue;let i=n.text.trim();i&&t.push(i)}return t})(e6.map(e=>({role:e.role,text:eS(e)}))),[e6]),tf=(0,i.useCallback)(async(e,t,r)=>{let n=e;S&&e.trim()&&(n=`${e}
|
|
7
7
|
|
|
8
8
|
[Current file: \`${S}\`]`),await es(n,t,r)},[es,S]),tv=(0,n.jsx)(ei,{ref:a,onSend:tf,onAbort:ea,onSteer:W?eg:void 0,onFollowUp:W?ef:void 0,isStreaming:W,model:J,modelNames:L,modelList:E,onModelChange:eh,onCompact:e||G?ex:void 0,onAbortCompaction:em,isCompacting:U,compactError:_,compactInfo:K,toolPreset:D,sessionKind:th,onToolPresetChange:e||G?ek:void 0,memoryTools:B,onMemoryToolsChange:e||G?eR:void 0,thinkingLevel:O,onThinkingLevelChange:e||G?eM:void 0,availableThinkingLevels:tu,thinkingLevelMap:tp,retryInfo:N,cornerBadge:te?(0,n.jsx)(ez,{status:e5}):void 0,promptHistory:tg,sessionHistoryKey:tx,activeFilePath:S,onDismissFileContext:()=>w(!0)}),tb=(0,i.useCallback)(e=>{W?a?.current?.insertText(e):es(e)},[W,a,es]),tm=(0,i.useCallback)((e,t,r)=>{if(W)return;let n=e.includes("```")?"````":"```",i=`${n}${t||""}
|
|
9
9
|
${e}
|
|
@@ -35,10 +35,10 @@ ${nk(e.provenance.stdoutPreview,1500)}
|
|
|
35
35
|
Stderr excerpt:
|
|
36
36
|
\`\`\`
|
|
37
37
|
${nk(e.provenance.stderrPreview,1500)}
|
|
38
|
-
\`\`\``:""].filter(Boolean).join("\n")}let nC=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function nT(e){return!Number.isFinite(e)||e<=0?"0.0G":`${(e/1024/1024/1024).toFixed(1)}G`}function nz(e){if(e<=0)return"never";let t=e/60/60/1e3;return t>=24&&Number.isInteger(t/24)?`${t/24}d`:Number.isInteger(t)?`${t}h`:`${Math.round(e/60/1e3)}m`}function nI(e){let t=e.toLowerCase();return t.endsWith(".rds")||t.endsWith(".qs")}function nR(e){return e.toLowerCase().endsWith(".h5ad")}function nM(e){let t=(e.split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return nC.has(t)}function nW(){let e=(0,o.useRouter)(),
|
|
39
|
-
Latest: v${
|
|
40
|
-
Run: ${eg.updateCommand}`}:null,[eb,em]=(0,i.useState)([]),[ey,ej]=(0,i.useState)("files"),[ek,ew]=(0,i.useState)(!1),[eS,eC]=(0,i.useState)(null),[eT,ez]=(0,i.useState)(0),[eM,eL]=(0,i.useState)([]),e$=(0,i.useCallback)(e=>{M.current?.insertText("`"+e+"`")},[]),[eP]=(0,i.useState)(()=>t.get("session")),[eD,eB]=(0,i.useState)(null),[eO,eN]=(0,i.useState)(()=>!t.get("session")),eA=(0,i.useRef)(!1),eH=(0,i.useCallback)(t=>{eB(t),eC(null),el(!1),ec(null),t&&!eA.current&&(d(e=>e&&e.cwd!==t?null:e),u(e=>e&&e!==t?null:e),g(e=>e+1),v(e=>e+1),P([]),B(null),e.replace("/",{scroll:!1}))},[e]),eF=(0,i.useCallback)((e,t)=>{eH(e),t?.closeDialog!==!1&&j(!1),h(e=>e+1)},[eH]),eU=(0,i.useCallback)((t,r=!1)=>{u(null),eB(t.cwd),d(t),el(!1),ec(null),g(e=>e+1),eN(!0),r&&(eA.current=!0,setTimeout(()=>{eA.current=!1},0)),r||e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),e_=(0,i.useCallback)((t,r)=>{d(null),u(r),eB(r),el(!1),ec(null),g(e=>e+1),P([]),B(null),e.replace("/",{scroll:!1})},[e]),eK=(0,i.useCallback)(t=>{u(null),eB(t.cwd),d(t),el(!1),ec(null),h(e=>e+1),e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[e]),eJ=(0,i.useCallback)(()=>{h(e=>e+1),v(e=>e+1)},[]),eq=(0,i.useCallback)(t=>{h(e=>e+1),g(e=>e+1),u(null),d(e=>({...e??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:t})),e.replace(`?session=${encodeURIComponent(t)}`,{scroll:!1})},[e]),eV=(0,i.useCallback)(()=>{eN(!0)},[]),eY=(0,i.useCallback)(t=>{if(h(e=>e+1),a?.id===t){let t=a.cwd;d(null),u(t??null),el(!1),ec(null),g(e=>e+1),P([]),B(null),e.replace("/",{scroll:!1})}},[a,e]),eG=a?.cwd??c??eD??null,[eZ,eX]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(null!==eZ){let e=setTimeout(()=>eX(null),500);return()=>clearTimeout(e)}},[eZ]);let eQ=(0,i.useCallback)((e,t)=>{if(nI(e)||nI(t))return void eC({mode:"start",appType:"stexp",filePath:e,cwd:eG,appId:null});if(nM(e)||nM(t)){let r=`preview:${e}`;eL(n=>{let i=n.find(e=>e.id===r),o=n.filter(e=>e.id!==r);return o.push(i?{...i,filePath:e,fileName:t}:{id:r,filePath:e,fileName:t}),o});return}let r=`file:${e}`;em(n=>n.find(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:e}]),ej(r),ew(!0)},[eG]),e0=(0,i.useCallback)((e,t,r)=>{r&&r>0&&eX(r),eQ(e,t)},[eQ]),e1=(0,i.useCallback)((e,t)=>{(nR(e)||nR(t))&&eC({mode:"start",appType:"h5adexp",filePath:e,cwd:eG,appId:null})},[eG]),e2=(0,i.useCallback)(e=>{ec(e),el(!0)},[]),e5=(0,i.useCallback)(()=>{el(!1),ec(null)},[]),e4=(0,i.useCallback)(()=>{ej("tools"),ew(!0),ez(e=>e+1)},[]),e3=(0,i.useCallback)(e=>{eC({mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}),ez(e=>e+1)},[]),e8=(0,i.useCallback)(e=>{ez(e=>e+1),eC(t=>t&&(t.appId===e.id||t.appType===e.appType&&t.filePath===e.filePath&&t.cwd===e.cwd)?"stopped"===e.status||"error"===e.status?null:{mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}:t)},[]),e6=(0,i.useCallback)(e=>{eL(t=>t.filter(t=>t.id!==e))},[]),e7=(0,i.useCallback)(e=>{eL(t=>{let r=t.findIndex(t=>t.id===e);if(r<0||r===t.length-1)return t;let n=[...t],[i]=n.splice(r,1);return n.push(i),n})},[]),e9=(0,i.useCallback)(e=>{"files"!==e&&(em(t=>t.filter(t=>t.id!==e)),ej(t=>{if(t!==e)return t;let r=eb.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:"files"}))},[eb]),te=c??(null===a&&eD?eD:null),tt=null!==a||null!==te,tr=eO&&!tt,tn=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...a?.sessionKind==="workbench"?[{id:"workbench",label:"Workbench",closable:!1,icon:"report"}]:[],...eb],ti=eb.find(e=>e.id===ey)??null,to=a?V(a):te?"New chat":"No session",tl=a?.cwd??te??eD??"",ts=tl?tl.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||tl:"",ta=a?.id??null,td=ed??eG,tc=(0,i.useCallback)((e="projects")=>{w(e),j(!0)},[]),[tu,tp]=(0,i.useState)(null),[th,tx]=(0,i.useState)(null),[tg,tf]=(0,i.useState)(null),tb=`${ta??""}|${eG??""}`,ty=tu?.totalBytes??0,tk=tu?.currentSessionBytes??0,tS=(0,i.useCallback)(async()=>{let e=new URLSearchParams;eG&&e.set("cwd",eG),ta&&e.set("sessionId",ta);try{let t=await fetch(`/api/plot-kernels/status${e.toString()?`?${e}`:""}`),r=await t.json();if(!t.ok||!("totalBytes"in r)||!("kernels"in r))throw Error(r.error??`HTTP ${t.status}`);tp(r),tx(null)}catch(e){tx(e instanceof Error?e.message:String(e))}},[ta,eG]);(0,i.useEffect)(()=>{let e=!1,t=async()=>{await tS(),e||(r=window.setTimeout(t,eo||es?3e3:8e3))},r=window.setTimeout(t,0);return()=>{e=!0,window.clearTimeout(r)}},[tS,tb,eo,es]);let tC=(0,i.useCallback)(async()=>{if(ta&&!tg){tf("all"),tx(null);try{let e=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:ta})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);window.setTimeout(()=>{tS()},600)}catch(e){tx(e instanceof Error?e.message:String(e))}finally{tf(null)}}},[tS,tg,ta]),tT=(0,i.useCallback)(async e=>{if(!tg&&0!==e.length){tf(e[0].pid),tx(null);try{for(let t of e){let e=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:t.pid,cwd:t.cwd,sessionId:t.sessionId,language:t.language})}),r=await e.json();if(!e.ok||r.error)throw Error(r.error??`HTTP ${e.status}`)}window.setTimeout(()=>{tS()},600)}catch(e){tx(e instanceof Error?e.message:String(e))}finally{tf(null)}}},[tS,tg]),tz=(0,i.useCallback)(()=>{ea(e=>!e),tS()},[tS]),tR=(0,i.useCallback)(()=>{ea(!1),e4()},[e4]),tM=(0,i.useCallback)(()=>{ea(!1),el(!1),ec(null),tc("workbench-runtime")},[tc]),tW=(0,i.useCallback)(async t=>{let r,n,i;if(!td||eu)return;ep(!0),tx(null);let o=new Date().toISOString(),l=`Workbench \xb7 ${"r"===t.kernel?"R":"Python"}`,s=(r=["Workbench session start.","",`Kernel: ${"r"===t.kernel?"R":"Python"}`],t.kernelId&&r.push(`Kernel ID: ${t.kernelId}${t.kernelDisplayName?` (${t.kernelDisplayName})`:""}`),t.sourcePath?r.push(`Primary source: ${t.sourcePath}`):r.push("Primary source: none selected"),t.notes&&(r.push("Notes:"),r.push(t.notes)),n=t.kernelId?`When calling \`kernel_plot_run\` or \`kernel_plot_render\`, pass kernelId: ${JSON.stringify(t.kernelId)}.`:"Use the current project/default Workbench kernel for tool calls.",i=t.sourcePath?'Initialize this workbench for analysis. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) for loading data, inspecting object structure, and generating figures or tables. Use `kernel_plot_render` for quick iterative plots that appear inline. Use `kernel_plot_run` + `runtime: "kernel-lite"` when working with data already in warm memory or when saving final artifacts — this keeps loaded data persistent. First, verify the provided input path, load or inspect only that explicit source plus any files mentioned in Notes, and prepare the session for iterative analysis. Keep the first response concise and operational.':"Quick-start this workbench without loading data. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) when the user later asks for analysis, plots, or saved artifacts. Do not search the project for `.rds`, `.qs`, `.h5ad`, or other dataset files unless the user explicitly asks. For now, only confirm the selected kernel/runtime is ready and ask what data or task to use next. Keep the first response concise and operational.",r.push("",n,"","CRITICAL — runtime mode:",'- ALWAYS pass `runtime: "kernel-lite"` to every `kernel_plot_run` call. This keeps loaded data, imported packages (library/import), and variables in warm memory across turns. If you use `runtime: "worker"` (one-shot), all loaded state is lost between calls and the analysis restarts from scratch on the next turn.','- Only use `runtime: "worker"` for quick one-shot scripts where memory persistence is not needed.',"- `kernel_plot_render` is always one-shot and does not share memory — use `kernel_plot_run` with `kernel-lite` for iterative work.",...t.isDescribeMode?["","DESCRIBE MODE — the user is a domain expert, not necessarily a coder:",'- The user will describe what they want in high-level terms (e.g. "compare gene expression between clusters", "make a circos plot").',"- Proactively suggest analysis approaches and explain your reasoning in plain language before writing code.","- After each result, summarize what was found in domain terms and suggest logical next steps.","- When the user mentions a figure type (heatmap, volcano, UMAP, circos, dotplot, etc.), pick the appropriate library and parameters without asking for low-level details.","- If you need a parameter the user didn't specify (e.g. which genes to plot), ask clearly and concisely.","- Always confirm what the output means for the user's research question."]:[],"",i),r.join("\n"));try{if(t.kernelId){let e=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:td,language:t.kernel,kernelId:t.kernelId})}),r=await e.json().catch(()=>({}));if(!e.ok||r.error)throw Error(r.error??`HTTP ${e.status}`)}let r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:td,type:"prompt",message:s,toolNames:(0,F.xG)("workbench"),sessionName:l,workbenchMeta:{sourcePath:t.sourcePath,kernel:t.kernel,kernelId:t.kernelId,kernelDisplayName:t.kernelDisplayName}})}),n=await r.json().catch(()=>({}));if(!r.ok||n.error||!n.sessionId)throw Error(n.error??`HTTP ${r.status}`);e5(),u(null),eB(td),d({id:n.sessionId,path:"",cwd:td,name:l,created:o,modified:o,messageCount:1,firstMessage:s,sessionKind:"workbench",createdBy:"launcher",sessionMeta:{sessionKind:"workbench",lastToolNames:(0,F.xG)("workbench"),createdBy:"launcher",createdAt:o,initialSourcePath:t.sourcePath||void 0,initialKernel:t.kernel}}),ej("workbench"),ew(!0),P([]),B(null),g(e=>e+1),h(e=>e+1),e.replace(`?session=${encodeURIComponent(n.sessionId)}`,{scroll:!1}),window.setTimeout(()=>{tS()},600)}catch(e){tx(e instanceof Error?e.message:String(e))}finally{ep(!1)}},[e5,tS,e,eu,td]),tL=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{selectedSessionId:a?.id??null,onSelectSession:eU,onNewSession:e_,onNewWorkbench:e2,initialSessionId:eP,onInitialRestoreDone:eV,refreshKey:p,onSessionDeleted:eY,selectedCwd:a?.cwd??c??eD??null,onCwdChange:eH}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,n.jsx)("button",{type:"button",onClick:()=>tc("projects"),title:"Settings","aria-label":"Settings",style:{width:34,display:"flex",alignItems:"center",justifyContent:"center",height:34,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",fontSize:12,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,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})})]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("div",{className:"sidebar-overlay-backdrop",onClick:()=>z(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!T,pointerEvents:T?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${T?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:I.width,minWidth:I.width,transition:T||I.isResizing?"none":void 0},children:tL}),T&&(0,n.jsx)(tw,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:I.beginResize,onResize:I.resizeBy,onResizeEnd:I.endResize}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:W,className:"app-topbar",style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,borderBottom:"1px solid var(--border)",height:48,padding:"0 8px",background:"var(--bg)"},children:[(0,n.jsx)("button",{className:"topbar-sidebar-toggle",onClick:()=>z(e=>!e),title:T?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:T?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,n.jsxs)("div",{className:"topbar-title-area",style:{display:"flex",alignItems:"center",gap:7,minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:6},children:H&&a?(0,n.jsx)("input",{ref:J,value:_,onChange:e=>K(e.target.value),onKeyDown:Z,onBlur:()=>void G(),style:{width:"min(360px, 34vw)",height:28,boxSizing:"border-box",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",padding:"0 8px",fontSize:13,fontWeight:500,outline:"none"}}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"topbar-session-title",title:to,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:tt?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:to}),a&&(0,n.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:Y,title:"Rename session",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 20h9"}),(0,n.jsx)("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})})]})}),ts&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"topbar-project-crumb",style:{color:"var(--text-dim)",fontSize:12,flexShrink:0},children:"/"}),(0,n.jsx)("span",{className:"topbar-project-crumb",title:tl||ts,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:ts})]})]}),tt&&!s&&(0,n.jsx)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:(0,n.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:L,onClick:tz,title:ty>0?`Open Workbench runtime \xb7 ${nT(ty)}${tk>0?` (this session: ${nT(tk)})`:""}`:"Open Workbench runtime status","aria-label":ty>0?`Open Workbench runtime \xb7 ${nT(ty)}${tk>0?` (this session: ${nT(tk)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:es?"var(--bg-selected)":ty>0||eh?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${es||ty>0||eh?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:ty>0||eh?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",fontVariantNumeric:"tabular-nums"},onMouseEnter:e=>{e.currentTarget.style.color=ty>0||eh?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=ty>0||eh?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=es?"var(--bg-selected)":ty>0||eh?"rgba(37,99,235,0.08)":"var(--bg-panel)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsx)("span",{className:"topbar-plot-label",children:"Workbench"}),ty>0&&(0,n.jsx)("span",{className:"topbar-plot-memory",children:tk>0&&tk!==ty?`${nT(tk)} / ${nT(ty)}`:nT(ty)})]})}),ev&&(0,n.jsx)("button",{type:"button",className:"topbar-update-button",title:ev.title,onClick:()=>navigator.clipboard?.writeText(eg?.updateCommand??"").catch(()=>{}),style:{height:28,padding:"0 9px",borderRadius:7,border:"1px solid rgba(34,197,94,0.35)",background:"rgba(34,197,94,0.10)",color:"rgba(34,197,94,0.95)",cursor:"pointer",fontSize:11,fontWeight:650,whiteSpace:"nowrap",flexShrink:0},children:ev.label}),tt&&s&&(0,n.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:L,onClick:tz,title:ty>0?`Open Workbench runtime \xb7 ${nT(ty)}${tk>0?` (this session: ${nT(tk)})`:""}`:"Open Workbench runtime status","aria-label":ty>0?`Open Workbench runtime \xb7 ${nT(ty)}${tk>0?` (this session: ${nT(tk)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:4,height:28,padding:"0 7px",flexShrink:0,background:es?"var(--bg-selected)":ty>0||eh?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${es||ty>0||eh?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:ty>0||eh?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsx)("span",{className:"topbar-plot-label",children:"WB"}),ty>0&&(0,n.jsx)("span",{className:"topbar-plot-memory",children:tk>0&&tk!==ty?`${nT(tk)} / ${nT(ty)}`:nT(ty)})]}),tt&&(Q||er)&&(()=>{let e=Q?.tokens,t=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),r="var(--text-muted)",i=null;if(er?.contextWindow){let e=er.percent;null!==e&&e>90?r="#ef4444":null!==e&&e>70&&(r="rgba(234,179,8,0.95)"),i=null!==e?`${e.toFixed(0)}% / ${t(er.contextWindow)}`:`? / ${t(er.contextWindow)}`}let o=[];if(e&&(o.push(`in: ${e.input.toLocaleString()}`),o.push(`out: ${e.output.toLocaleString()}`),o.push(`cache read: ${e.cacheRead.toLocaleString()}`),o.push(`cache write: ${e.cacheWrite.toLocaleString()}`)),er?.contextWindow){let e=er.percent;o.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${er.contextWindow.toLocaleString()} tokens`)}let l=o.join(" | ");return(0,n.jsxs)("div",{className:"topbar-session-stats",title:l,style:{display:"flex",alignItems:"center",gap:10,padding:"0 8px",height:28,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[e&&e.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),t(e.input)]}),e&&e.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),t(e.output)]}),e&&e.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),t(e.cacheRead)]}),i&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:r},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),i]})]})})(),(0,n.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:X,title:`生成式 UI: ${S.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${S.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:S.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${S.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:S.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=S.generativeUI?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=S.generativeUI?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=S.generativeUI?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-theme-toggle",onClick:e=>{let t=e.currentTarget.getBoundingClientRect();l({x:t.left+t.width/2,y:t.top+t.height/2})},title:r?"Switch to light mode":"Switch to dark mode","aria-label":r?"Switch to light mode":"Switch to dark mode","aria-pressed":r,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:r?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,n.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,n.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,n.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,n.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,n.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,n.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,n.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,n.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-right-panel-toggle",onClick:()=>ew(e=>!e),title:ek?"Hide right panel":"Show right panel","aria-label":ek?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:ek?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${ek?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:ek?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=ek?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=ek?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=ek?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:tt?(0,n.jsx)(eI,{session:a,newSessionCwd:te,onAgentEnd:eJ,onSessionCreated:eK,onSessionForked:eq,modelsRefreshKey:b,chatInputRef:M,onBranchDataChange:N,onSessionStatsChange:et,onContextUsageChange:ei,onToolPresetActive:ex,generativeUI:S.generativeUI,forkSettings:{enabled:S.forkEnabled,suggestTokens:S.forkSuggestTokens,autoTokens:S.forkAutoTokens,minMessages:S.forkMinMessages},activeFilePath:ti?.filePath??null,onOpenFileAtLine:e0},x):tr?eD?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,n.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,n.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,n.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,n.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),ek&&(0,n.jsx)(tw,{side:"left",ariaLabel:"Resize right panel",onResizeStart:R.beginResize,onResize:R.resizeBy,onResizeEnd:R.endResize}),(0,n.jsxs)("div",{className:`right-panel-container${ek?" right-panel-open":" right-panel-closed"}`,style:{display:ek?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:R.width,minWidth:R.width,transition:R.isResizing?"none":void 0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:[(0,n.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>ew(!1),title:"Back to chat","aria-label":"Back to chat",style:{height:36,padding:"0 10px",border:"none",borderRight:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,alignItems:"center",gap:6,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"19",y1:"12",x2:"5",y2:"12"}),(0,n.jsx)("polyline",{points:"12 19 5 12 12 5"})]}),(0,n.jsx)("span",{children:"Chat"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(tH,{tabs:tn,activeTabId:ey,onSelectTab:ej,onCloseTab:e9,onAskAI:e=>{let t=`I'm looking at \`${e}\`. `;M?.current?.insertIfEmpty(t)}})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===ey?(0,n.jsx)(tv,{cwd:eD??a?.cwd??c??null,refreshKey:f,onOpenFile:eQ,onExploreFile:e1,onAtMention:e$,watchEnabled:ek&&"files"===ey}):"tools"===ey?(0,n.jsx)(tP,{refreshKey:eT,visibleAppId:eS?.appId??null,cwd:eD??a?.cwd??c??null,onOpenApp:e3,onAppChanged:e8,agentRuntimeExtra:(0,n.jsx)(tX,{tree:E,activeLeafId:D,onLeafChange:A,hasSession:!!a,embedded:!0})}):"workbench"===ey&&a?(0,n.jsx)(tY,{sessionId:a.id,cwd:a.cwd,onAskAboutCell:(e,t)=>{let r=e.length>400?e.slice(0,400)+"...":e;M?.current?.insertText(`Explain the code in workbench cell #${t}:
|
|
38
|
+
\`\`\``:""].filter(Boolean).join("\n")}let nC=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function nT(e){return!Number.isFinite(e)||e<=0?"0.0G":`${(e/1024/1024/1024).toFixed(1)}G`}function nz(e){if(e<=0)return"never";let t=e/60/60/1e3;return t>=24&&Number.isInteger(t/24)?`${t/24}d`:Number.isInteger(t)?`${t}h`:`${Math.round(e/60/1e3)}m`}function nI(e){let t=e.toLowerCase();return t.endsWith(".rds")||t.endsWith(".qs")}function nR(e){return e.toLowerCase().endsWith(".h5ad")}function nM(e){let t=(e.split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return nC.has(t)}function nW(){let e,t,r,l,s,a,d,c=(0,o.useRouter)(),u=(0,o.useSearchParams)(),{isDark:p,toggleTheme:h}=(0,tm.D)(),x=function(){let[e,t]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=()=>t(window.innerWidth<=768);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),e}(),[g,f]=(0,i.useState)(null),[v,b]=(0,i.useState)(null),[m,y]=(0,i.useState)(0),[j,k]=(0,i.useState)(0),[w,S]=(0,i.useState)(0),[C,T]=(0,i.useState)(0),[z,I]=(0,i.useState)(!1),[R,M]=(0,i.useState)("projects"),[W,L]=(0,i.useState)({generativeUI:!0,plotIdleTimeoutMs:1728e5,forkEnabled:!0,forkSuggestTokens:18e4,forkAutoTokens:4e5,forkMinMessages:20}),[E,P]=(0,i.useState)(!0),D=nj({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),B=nj({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),O=(0,i.useRef)(null),N=(0,i.useRef)(null),A=(0,i.useRef)(null),[H,U]=(0,i.useState)([]),[_,K]=(0,i.useState)(null),J=(0,i.useRef)(null),q=(0,i.useCallback)((e,t,r)=>{U(e),K(t),J.current=r},[]),V=(0,i.useCallback)(e=>{J.current?.(e)},[]),[Y,G]=(0,i.useState)(!1),[Z,X]=(0,i.useState)(""),Q=(0,i.useRef)(null),ee=(0,i.useRef)(!1),[et,er]=(0,i.useState)({kind:"idle"}),en=(0,i.useRef)(null),ei=(0,i.useCallback)(async()=>{let e=g?.id;if(e&&"naming"!==et.kind){en.current&&clearTimeout(en.current),er({kind:"naming"});try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/auto-name`,{method:"POST"}),r=await t.json().catch(()=>({}));if(!t.ok||!r.title)throw Error(r.error||`HTTP ${t.status}`);let n=r.title.trim();y(e=>e+1),f(t=>t?.id===e?{...t,name:n}:t),er({kind:"success"}),en.current=setTimeout(()=>er({kind:"idle"}),1800)}catch(e){er({kind:"error",message:e instanceof Error?e.message:String(e)}),en.current=setTimeout(()=>er({kind:"idle"}),5e3)}}},[et.kind,g?.id]);(0,i.useEffect)(()=>{en.current&&clearTimeout(en.current),er({kind:"idle"})},[g?.id]),(0,i.useEffect)(()=>{G(!1)},[g?.id]);let eo=(0,i.useCallback)(e=>e?e.name||e.firstMessage.slice(0,80)||e.id.slice(0,12):"",[]),el=(0,i.useCallback)(()=>{g&&(ee.current=!1,X(g.name||eo(g)),G(!0),setTimeout(()=>Q.current?.select(),0))},[eo,g]),es=(0,i.useCallback)(async()=>{if(ee.current){ee.current=!1,G(!1);return}if(!g)return void G(!1);let e=Z.trim(),t=eo(g);if(G(!1),e!==(g.name??"")&&(g.name||e!==t))try{(await fetch(`/api/sessions/${encodeURIComponent(g.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})).ok&&(f(t=>t&&t.id===g.id?{...t,name:e}:t),y(e=>e+1))}catch{}},[eo,g,Z]),ea=(0,i.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),es()):"Escape"===e.key&&(ee.current=!0,G(!1))},[es]);(0,i.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():null).then(t=>{e||L(e=>({generativeUI:"boolean"==typeof t?.settings?.generativeUI?t.settings.generativeUI:e.generativeUI,plotIdleTimeoutMs:"number"==typeof t?.settings?.plotIdleTimeoutMs?t.settings.plotIdleTimeoutMs:e.plotIdleTimeoutMs,forkEnabled:"boolean"==typeof t?.settings?.forkEnabled?t.settings.forkEnabled:e.forkEnabled,forkSuggestTokens:"number"==typeof t?.settings?.forkSuggestTokens?t.settings.forkSuggestTokens:e.forkSuggestTokens,forkAutoTokens:"number"==typeof t?.settings?.forkAutoTokens?t.settings.forkAutoTokens:e.forkAutoTokens,forkMinMessages:"number"==typeof t?.settings?.forkMinMessages?t.settings.forkMinMessages:e.forkMinMessages}))}).catch(()=>{}),()=>{e=!0}},[]);let ed=(0,i.useCallback)(()=>{let e=!W.generativeUI;L(t=>({...t,generativeUI:e})),fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{generativeUI:e}})}).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(e=>{L(t=>({...t,..."boolean"==typeof e.settings?.generativeUI?{generativeUI:e.settings.generativeUI}:{},..."number"==typeof e.settings?.plotIdleTimeoutMs?{plotIdleTimeoutMs:e.settings.plotIdleTimeoutMs}:{}}))}).catch(()=>L(e=>({...e,generativeUI:!e.generativeUI})))},[W.generativeUI]),[ec,eu]=(0,i.useState)(null),ep=(0,i.useCallback)(e=>{eu(e)},[]),[eh,ex]=(0,i.useState)(null),eg=(0,i.useCallback)(e=>{ex(e)},[]),[ef,ev]=(0,i.useState)(!1),[eb,em]=(0,i.useState)(!1),[ey,ej]=(0,i.useState)(null),[ek,ew]=(0,i.useState)(!1),[eS,eC]=(0,i.useState)(!1),[eT,ez]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&ez(t)}).catch(()=>{}),()=>{e=!0}},[]);let eM=eT?.updateAvailable&&eT.latest?{label:`Update ${eT.latest}`,title:`Current: v${eT.current}
|
|
39
|
+
Latest: v${eT.latest}
|
|
40
|
+
Run: ${eT.updateCommand}`}:null,[eL,e$]=(0,i.useState)([]),[eP,eD]=(0,i.useState)("files"),[eB,eO]=(0,i.useState)(!1),[eN,eA]=(0,i.useState)(null),[eH,eF]=(0,i.useState)(0),[eU,e_]=(0,i.useState)([]),eK=(0,i.useCallback)(e=>{O.current?.insertText("`"+e+"`")},[]),[eJ]=(0,i.useState)(()=>u.get("session")),[eq,eV]=(0,i.useState)(null),[eY,eG]=(0,i.useState)(()=>!u.get("session")),eZ=(0,i.useRef)(!1),eX=(0,i.useCallback)(e=>{eV(e),eA(null),ev(!1),ej(null),e&&!eZ.current&&(f(t=>t&&t.cwd!==e?null:t),b(t=>t&&t!==e?null:t),k(e=>e+1),S(e=>e+1),U([]),K(null),c.replace("/",{scroll:!1}))},[c]),eQ=(0,i.useCallback)((e,t)=>{eX(e),t?.closeDialog!==!1&&I(!1),y(e=>e+1)},[eX]),e0=(0,i.useCallback)((e,t=!1)=>{b(null),eV(e.cwd),f(e),ev(!1),ej(null),k(e=>e+1),eG(!0),t&&(eZ.current=!0,setTimeout(()=>{eZ.current=!1},0)),t||c.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[c]),e1=(0,i.useCallback)((e,t)=>{f(null),b(t),eV(t),ev(!1),ej(null),k(e=>e+1),U([]),K(null),c.replace("/",{scroll:!1})},[c]),e2=(0,i.useCallback)(e=>{b(null),eV(e.cwd),f(e),ev(!1),ej(null),y(e=>e+1),c.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[c]),e5=(0,i.useCallback)(()=>{y(e=>e+1),S(e=>e+1)},[]),e4=(0,i.useCallback)(e=>{y(e=>e+1),k(e=>e+1),b(null),f(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e})),c.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[c]),e3=(0,i.useCallback)(()=>{eG(!0)},[]),e8=(0,i.useCallback)(e=>{if(y(e=>e+1),g?.id===e){let e=g.cwd;f(null),b(e??null),ev(!1),ej(null),k(e=>e+1),U([]),K(null),c.replace("/",{scroll:!1})}},[g,c]),e6=g?.cwd??v??eq??null,[e7,e9]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(null!==e7){let e=setTimeout(()=>e9(null),500);return()=>clearTimeout(e)}},[e7]);let te=(0,i.useCallback)((e,t)=>{if(nI(e)||nI(t))return void eA({mode:"start",appType:"stexp",filePath:e,cwd:e6,appId:null});if(nM(e)||nM(t)){let r=`preview:${e}`;e_(n=>{let i=n.find(e=>e.id===r),o=n.filter(e=>e.id!==r);return o.push(i?{...i,filePath:e,fileName:t}:{id:r,filePath:e,fileName:t}),o});return}let r=`file:${e}`;e$(n=>n.find(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:e}]),eD(r),eO(!0)},[e6]),tt=(0,i.useCallback)((e,t,r)=>{r&&r>0&&e9(r),te(e,t)},[te]),tr=(0,i.useCallback)((e,t)=>{(nR(e)||nR(t))&&eA({mode:"start",appType:"h5adexp",filePath:e,cwd:e6,appId:null})},[e6]),tn=(0,i.useCallback)(e=>{ej(e),ev(!0)},[]),ti=(0,i.useCallback)(()=>{ev(!1),ej(null)},[]),to=(0,i.useCallback)(()=>{eD("tools"),eO(!0),eF(e=>e+1)},[]),tl=(0,i.useCallback)(e=>{eA({mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}),eF(e=>e+1)},[]),ts=(0,i.useCallback)(e=>{eF(e=>e+1),eA(t=>t&&(t.appId===e.id||t.appType===e.appType&&t.filePath===e.filePath&&t.cwd===e.cwd)?"stopped"===e.status||"error"===e.status?null:{mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}:t)},[]),ta=(0,i.useCallback)(e=>{e_(t=>t.filter(t=>t.id!==e))},[]),td=(0,i.useCallback)(e=>{e_(t=>{let r=t.findIndex(t=>t.id===e);if(r<0||r===t.length-1)return t;let n=[...t],[i]=n.splice(r,1);return n.push(i),n})},[]),tc=(0,i.useCallback)(e=>{"files"!==e&&(e$(t=>t.filter(t=>t.id!==e)),eD(t=>{if(t!==e)return t;let r=eL.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:"files"}))},[eL]),tu=v??(null===g&&eq?eq:null),tp=null!==g||null!==tu,th=eY&&!tp,tx=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...g?.sessionKind==="workbench"?[{id:"workbench",label:"Workbench",closable:!1,icon:"report"}]:[],...eL],tg=eL.find(e=>e.id===eP)??null,tf=g?eo(g):tu?"New chat":"No session",tb=g?.cwd??tu??eq??"",ty=tb?tb.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||tb:"",tk=g?.id??null,tS=ey??e6,tC=(0,i.useCallback)((e="projects")=>{M(e),I(!0)},[]),[tT,tz]=(0,i.useState)(null),[tR,tM]=(0,i.useState)(null),[tW,tL]=(0,i.useState)(null),tE=`${tk??""}|${e6??""}`,t$=tT?.totalBytes??0,tD=tT?.currentSessionBytes??0,tB=(0,i.useCallback)(async()=>{let e=new URLSearchParams;e6&&e.set("cwd",e6),tk&&e.set("sessionId",tk);try{let t=await fetch(`/api/plot-kernels/status${e.toString()?`?${e}`:""}`),r=await t.json();if(!t.ok||!("totalBytes"in r)||!("kernels"in r))throw Error(r.error??`HTTP ${t.status}`);tz(r),tM(null)}catch(e){tM(e instanceof Error?e.message:String(e))}},[tk,e6]);(0,i.useEffect)(()=>{let e=!1,t=async()=>{await tB(),e||(r=window.setTimeout(t,ef||eb?3e3:8e3))},r=window.setTimeout(t,0);return()=>{e=!0,window.clearTimeout(r)}},[tB,tE,ef,eb]);let tO=(0,i.useCallback)(async()=>{if(tk&&!tW){tL("all"),tM(null);try{let e=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:tk})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);window.setTimeout(()=>{tB()},600)}catch(e){tM(e instanceof Error?e.message:String(e))}finally{tL(null)}}},[tB,tW,tk]),tN=(0,i.useCallback)(async e=>{if(!tW&&0!==e.length){tL(e[0].pid),tM(null);try{for(let t of e){let e=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:t.pid,cwd:t.cwd,sessionId:t.sessionId,language:t.language})}),r=await e.json();if(!e.ok||r.error)throw Error(r.error??`HTTP ${e.status}`)}window.setTimeout(()=>{tB()},600)}catch(e){tM(e instanceof Error?e.message:String(e))}finally{tL(null)}}},[tB,tW]),tA=(0,i.useCallback)(()=>{em(e=>!e),tB()},[tB]),tF=(0,i.useCallback)(()=>{em(!1),to()},[to]),tU=(0,i.useCallback)(()=>{em(!1),ev(!1),ej(null),tC("workbench-runtime")},[tC]),t_=(0,i.useCallback)(async e=>{let t,r,n;if(!tS||ek)return;ew(!0),tM(null);let i=new Date().toISOString(),o=`Workbench \xb7 ${"r"===e.kernel?"R":"Python"}`,l=(t=["Workbench session start.","",`Kernel: ${"r"===e.kernel?"R":"Python"}`],e.kernelId&&t.push(`Kernel ID: ${e.kernelId}${e.kernelDisplayName?` (${e.kernelDisplayName})`:""}`),e.sourcePath?t.push(`Primary source: ${e.sourcePath}`):t.push("Primary source: none selected"),e.notes&&(t.push("Notes:"),t.push(e.notes)),r=e.kernelId?`When calling \`kernel_plot_run\` or \`kernel_plot_render\`, pass kernelId: ${JSON.stringify(e.kernelId)}.`:"Use the current project/default Workbench kernel for tool calls.",n=e.sourcePath?'Initialize this workbench for analysis. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) for loading data, inspecting object structure, and generating figures or tables. Use `kernel_plot_render` for quick iterative plots that appear inline. Use `kernel_plot_run` + `runtime: "kernel-lite"` when working with data already in warm memory or when saving final artifacts — this keeps loaded data persistent. First, verify the provided input path, load or inspect only that explicit source plus any files mentioned in Notes, and prepare the session for iterative analysis. Keep the first response concise and operational.':"Quick-start this workbench without loading data. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) when the user later asks for analysis, plots, or saved artifacts. Do not search the project for `.rds`, `.qs`, `.h5ad`, or other dataset files unless the user explicitly asks. For now, only confirm the selected kernel/runtime is ready and ask what data or task to use next. Keep the first response concise and operational.",t.push("",r,"","CRITICAL — runtime mode:",'- ALWAYS pass `runtime: "kernel-lite"` to every `kernel_plot_run` call. This keeps loaded data, imported packages (library/import), and variables in warm memory across turns. If you use `runtime: "worker"` (one-shot), all loaded state is lost between calls and the analysis restarts from scratch on the next turn.','- Only use `runtime: "worker"` for quick one-shot scripts where memory persistence is not needed.',"- `kernel_plot_render` is always one-shot and does not share memory — use `kernel_plot_run` with `kernel-lite` for iterative work.",...e.isDescribeMode?["","DESCRIBE MODE — the user is a domain expert, not necessarily a coder:",'- The user will describe what they want in high-level terms (e.g. "compare gene expression between clusters", "make a circos plot").',"- Proactively suggest analysis approaches and explain your reasoning in plain language before writing code.","- After each result, summarize what was found in domain terms and suggest logical next steps.","- When the user mentions a figure type (heatmap, volcano, UMAP, circos, dotplot, etc.), pick the appropriate library and parameters without asking for low-level details.","- If you need a parameter the user didn't specify (e.g. which genes to plot), ask clearly and concisely.","- Always confirm what the output means for the user's research question."]:[],"",n),t.join("\n"));try{if(e.kernelId){let t=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:tS,language:e.kernel,kernelId:e.kernelId})}),r=await t.json().catch(()=>({}));if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`)}let t=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:tS,type:"prompt",message:l,toolNames:(0,F.xG)("workbench"),sessionName:o,workbenchMeta:{sourcePath:e.sourcePath,kernel:e.kernel,kernelId:e.kernelId,kernelDisplayName:e.kernelDisplayName}})}),r=await t.json().catch(()=>({}));if(!t.ok||r.error||!r.sessionId)throw Error(r.error??`HTTP ${t.status}`);ti(),b(null),eV(tS),f({id:r.sessionId,path:"",cwd:tS,name:o,created:i,modified:i,messageCount:1,firstMessage:l,sessionKind:"workbench",createdBy:"launcher",sessionMeta:{sessionKind:"workbench",lastToolNames:(0,F.xG)("workbench"),createdBy:"launcher",createdAt:i,initialSourcePath:e.sourcePath||void 0,initialKernel:e.kernel}}),eD("workbench"),eO(!0),U([]),K(null),k(e=>e+1),y(e=>e+1),c.replace(`?session=${encodeURIComponent(r.sessionId)}`,{scroll:!1}),window.setTimeout(()=>{tB()},600)}catch(e){tM(e instanceof Error?e.message:String(e))}finally{ew(!1)}},[ti,tB,c,ek,tS]),tK=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{selectedSessionId:g?.id??null,onSelectSession:e0,onNewSession:e1,onNewWorkbench:tn,initialSessionId:eJ,onInitialRestoreDone:e3,refreshKey:m,onSessionDeleted:e8,selectedCwd:g?.cwd??v??eq??null,onCwdChange:eX}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,n.jsx)("button",{type:"button",onClick:()=>tC("projects"),title:"Settings","aria-label":"Settings",style:{width:34,display:"flex",alignItems:"center",justifyContent:"center",height:34,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",fontSize:12,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,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})})]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("div",{className:"sidebar-overlay-backdrop",onClick:()=>P(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!E,pointerEvents:E?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${E?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:D.width,minWidth:D.width,transition:E||D.isResizing?"none":void 0},children:tK}),E&&(0,n.jsx)(tw,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:D.beginResize,onResize:D.resizeBy,onResizeEnd:D.endResize}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:N,className:"app-topbar",style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,borderBottom:"1px solid var(--border)",height:48,padding:"0 8px",background:"var(--bg)"},children:[(0,n.jsx)("button",{className:"topbar-sidebar-toggle",onClick:()=>P(e=>!e),title:E?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:E?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,n.jsxs)("div",{className:"topbar-title-area",style:{display:"flex",alignItems:"center",gap:7,minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:6},children:Y&&g?(0,n.jsx)("input",{ref:Q,value:Z,onChange:e=>X(e.target.value),onKeyDown:ea,onBlur:()=>void es(),style:{width:"min(360px, 34vw)",height:28,boxSizing:"border-box",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",padding:"0 8px",fontSize:13,fontWeight:500,outline:"none"}}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"topbar-session-title",title:tf,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:tp?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:tf}),g&&(0,n.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:el,title:"Rename session",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 20h9"}),(0,n.jsx)("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})})]})}),ty&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"topbar-project-crumb",style:{color:"var(--text-dim)",fontSize:12,flexShrink:0},children:"/"}),(0,n.jsx)("span",{className:"topbar-project-crumb",title:tb||ty,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:ty})]})]}),tp&&!x&&(0,n.jsxs)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:[(e=!!(g&&g.messageCount>0),t="naming"===et.kind,r="success"===et.kind,l="error"===et.kind,s=!g||!e||t,a=t?"Naming…":r?"Title updated":l?"Title failed":"Auto title",d=g?e?l?et.message??"Title generation failed":t?"Generating a title from the conversation…":"Generate a title with the current model":"No messages yet":"No session selected",(0,n.jsxs)("button",{type:"button",className:"topbar-auto-title-button",onClick:()=>{ei()},disabled:s,title:d,"aria-label":a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:28,padding:"0 9px",background:r?"rgba(34,197,94,0.10)":l?"rgba(239,68,68,0.10)":"var(--bg-panel)",border:`1px solid ${r?"rgba(34,197,94,0.45)":l?"rgba(239,68,68,0.45)":"var(--border)"}`,borderRadius:7,cursor:s?"not-allowed":"pointer",color:r?"rgba(34,197,94,0.95)":l?"#dc2626":s?"var(--text-dim)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",opacity:s&&!t?.55:1},onMouseEnter:e=>{s||(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=r?"rgba(34,197,94,0.95)":l?"#dc2626":"var(--text-muted)",e.currentTarget.style.background=r?"rgba(34,197,94,0.10)":l?"rgba(239,68,68,0.10)":"var(--bg-panel)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M12 3v2"}),(0,n.jsx)("path",{d:"M12 19v2"}),(0,n.jsx)("path",{d:"M3 12h2"}),(0,n.jsx)("path",{d:"M19 12h2"}),(0,n.jsx)("path",{d:"m5.6 5.6 1.4 1.4"}),(0,n.jsx)("path",{d:"m17 17 1.4 1.4"}),(0,n.jsx)("path",{d:"m5.6 18.4 1.4-1.4"}),(0,n.jsx)("path",{d:"m17 7 1.4-1.4"})]}),(0,n.jsx)("span",{className:"topbar-auto-title-label",children:a})]})),(0,n.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:A,onClick:tA,title:t$>0?`Open Workbench runtime \xb7 ${nT(t$)}${tD>0?` (this session: ${nT(tD)})`:""}`:"Open Workbench runtime status","aria-label":t$>0?`Open Workbench runtime \xb7 ${nT(t$)}${tD>0?` (this session: ${nT(tD)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:eb?"var(--bg-selected)":t$>0||eS?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${eb||t$>0||eS?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:t$>0||eS?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",fontVariantNumeric:"tabular-nums"},onMouseEnter:e=>{e.currentTarget.style.color=t$>0||eS?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=t$>0||eS?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=eb?"var(--bg-selected)":t$>0||eS?"rgba(37,99,235,0.08)":"var(--bg-panel)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsx)("span",{className:"topbar-plot-label",children:"Workbench"}),t$>0&&(0,n.jsx)("span",{className:"topbar-plot-memory",children:tD>0&&tD!==t$?`${nT(tD)} / ${nT(t$)}`:nT(t$)})]})]}),eM&&(0,n.jsx)("button",{type:"button",className:"topbar-update-button",title:eM.title,onClick:()=>navigator.clipboard?.writeText(eT?.updateCommand??"").catch(()=>{}),style:{height:28,padding:"0 9px",borderRadius:7,border:"1px solid rgba(34,197,94,0.35)",background:"rgba(34,197,94,0.10)",color:"rgba(34,197,94,0.95)",cursor:"pointer",fontSize:11,fontWeight:650,whiteSpace:"nowrap",flexShrink:0},children:eM.label}),tp&&x&&(0,n.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:A,onClick:tA,title:t$>0?`Open Workbench runtime \xb7 ${nT(t$)}${tD>0?` (this session: ${nT(tD)})`:""}`:"Open Workbench runtime status","aria-label":t$>0?`Open Workbench runtime \xb7 ${nT(t$)}${tD>0?` (this session: ${nT(tD)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:4,height:28,padding:"0 7px",flexShrink:0,background:eb?"var(--bg-selected)":t$>0||eS?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${eb||t$>0||eS?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:t$>0||eS?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsx)("span",{className:"topbar-plot-label",children:"WB"}),t$>0&&(0,n.jsx)("span",{className:"topbar-plot-memory",children:tD>0&&tD!==t$?`${nT(tD)} / ${nT(t$)}`:nT(t$)})]}),tp&&(ec||eh)&&(()=>{let e=ec?.tokens,t=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),r="var(--text-muted)",i=null;if(eh?.contextWindow){let e=eh.percent;null!==e&&e>90?r="#ef4444":null!==e&&e>70&&(r="rgba(234,179,8,0.95)"),i=null!==e?`${e.toFixed(0)}% / ${t(eh.contextWindow)}`:`? / ${t(eh.contextWindow)}`}let o=[];if(e&&(o.push(`in: ${e.input.toLocaleString()}`),o.push(`out: ${e.output.toLocaleString()}`),o.push(`cache read: ${e.cacheRead.toLocaleString()}`),o.push(`cache write: ${e.cacheWrite.toLocaleString()}`)),eh?.contextWindow){let e=eh.percent;o.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${eh.contextWindow.toLocaleString()} tokens`)}let l=o.join(" | ");return(0,n.jsxs)("div",{className:"topbar-session-stats",title:l,style:{display:"flex",alignItems:"center",gap:10,padding:"0 8px",height:28,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[e&&e.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),t(e.input)]}),e&&e.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),t(e.output)]}),e&&e.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),t(e.cacheRead)]}),i&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:r},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),i]})]})})(),(0,n.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:ed,title:`生成式 UI: ${W.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${W.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:W.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${W.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:W.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=W.generativeUI?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=W.generativeUI?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=W.generativeUI?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-theme-toggle",onClick:e=>{let t=e.currentTarget.getBoundingClientRect();h({x:t.left+t.width/2,y:t.top+t.height/2})},title:p?"Switch to light mode":"Switch to dark mode","aria-label":p?"Switch to light mode":"Switch to dark mode","aria-pressed":p,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:p?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,n.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,n.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,n.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,n.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,n.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,n.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,n.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,n.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-right-panel-toggle",onClick:()=>eO(e=>!e),title:eB?"Hide right panel":"Show right panel","aria-label":eB?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:eB?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${eB?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:eB?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=eB?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=eB?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=eB?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:tp?(0,n.jsx)(eI,{session:g,newSessionCwd:tu,onAgentEnd:e5,onSessionCreated:e2,onSessionForked:e4,modelsRefreshKey:C,chatInputRef:O,onBranchDataChange:q,onSessionStatsChange:ep,onContextUsageChange:eg,onToolPresetActive:eC,generativeUI:W.generativeUI,forkSettings:{enabled:W.forkEnabled,suggestTokens:W.forkSuggestTokens,autoTokens:W.forkAutoTokens,minMessages:W.forkMinMessages},activeFilePath:tg?.filePath??null,onOpenFileAtLine:tt},j):th?eq?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,n.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,n.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,n.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,n.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),eB&&(0,n.jsx)(tw,{side:"left",ariaLabel:"Resize right panel",onResizeStart:B.beginResize,onResize:B.resizeBy,onResizeEnd:B.endResize}),(0,n.jsxs)("div",{className:`right-panel-container${eB?" right-panel-open":" right-panel-closed"}`,style:{display:eB?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:B.width,minWidth:B.width,transition:B.isResizing?"none":void 0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:[(0,n.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>eO(!1),title:"Back to chat","aria-label":"Back to chat",style:{height:36,padding:"0 10px",border:"none",borderRight:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,alignItems:"center",gap:6,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"19",y1:"12",x2:"5",y2:"12"}),(0,n.jsx)("polyline",{points:"12 19 5 12 12 5"})]}),(0,n.jsx)("span",{children:"Chat"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(tH,{tabs:tx,activeTabId:eP,onSelectTab:eD,onCloseTab:tc,onAskAI:e=>{let t=`I'm looking at \`${e}\`. `;O?.current?.insertIfEmpty(t)}})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===eP?(0,n.jsx)(tv,{cwd:eq??g?.cwd??v??null,refreshKey:w,onOpenFile:te,onExploreFile:tr,onAtMention:eK,watchEnabled:eB&&"files"===eP}):"tools"===eP?(0,n.jsx)(tP,{refreshKey:eH,visibleAppId:eN?.appId??null,cwd:eq??g?.cwd??v??null,onOpenApp:tl,onAppChanged:ts,agentRuntimeExtra:(0,n.jsx)(tX,{tree:H,activeLeafId:_,onLeafChange:V,hasSession:!!g,embedded:!0})}):"workbench"===eP&&g?(0,n.jsx)(tY,{sessionId:g.id,cwd:g.cwd,onAskAboutCell:(e,t)=>{let r=e.length>400?e.slice(0,400)+"...":e;O?.current?.insertText(`Explain the code in workbench cell #${t}:
|
|
41
41
|
\`\`\`
|
|
42
42
|
${r}
|
|
43
43
|
\`\`\`
|
|
44
|
-
`)},onAskAboutArtifact:e=>{
|
|
44
|
+
`)},onAskAboutArtifact:e=>{O?.current?.insertText(nw(e))},onEditArtifact:e=>{O?.current?.insertText(nS(e))},onOpenArtifact:e=>{let t=e.split(/[\\/]/).pop()||e;te(e,t)}}):tg?.filePath?tg.filePath.startsWith("__")?(0,n.jsx)(tj,{filePath:tg.filePath}):(0,n.jsx)(eW,{filePath:tg.filePath,children:(0,n.jsx)(eR.h,{filePath:tg.filePath,cwd:eq??void 0,onOpenFile:te,scrollToLine:e7,workbenchSessionId:g?.sessionKind==="workbench"?g.id:null,onAskAboutArtifact:e=>O?.current?.insertText(nw(e)),onEditArtifact:e=>O?.current?.insertText(nS(e))})}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),(0,n.jsx)(ny,{open:eb,anchorRef:A,status:tT,error:tR,currentSessionId:tk,currentCwd:e6,idleTimeoutLabel:nz(W.plotIdleTimeoutMs),busyPid:"number"==typeof tW?tW:null,onClose:()=>em(!1),onRefresh:()=>{tB()},onReleaseKernels:e=>{tN(e)},onOpenSettings:tU,onOpenStatus:tF}),z&&(0,n.jsx)(nc,{cwd:e6,generativeUI:W.generativeUI,initialTab:R,onGenerativeUIToggle:ed,onModelsChanged:()=>T(e=>e+1),onProjectSelect:eQ,onProjectsChanged:()=>y(e=>e+1),onClose:()=>{I(!1),T(e=>e+1)}}),ef&&(0,n.jsx)(nx,{cwd:tS,runtime:{totalBytes:t$,currentSessionBytes:tD,idleTimeoutLabel:nz(W.plotIdleTimeoutMs)},runtimeError:tR,busy:ek,onClose:ti,onLaunch:e=>t_(e),onReleaseCurrentRuntime:g?.id&&g.cwd===tS?()=>{tO()}:void 0,onOpenSettings:tU}),(0,n.jsx)(tI,{appType:eN?.appType??"stexp",filePath:eN?.filePath??null,cwd:eN?.cwd??null,appId:eN?.appId??null,sessionId:g?.id??null,onClose:()=>eA(null),onAppChanged:ts,onOpenTools:to}),eU.map((e,t)=>(0,n.jsx)(eE,{id:e.id,filePath:e.filePath,fileName:e.fileName,cwd:eq??g?.cwd??v??void 0,active:t===eU.length-1,stackIndex:t,zIndex:700+t,onClose:ta,onFocus:td,onOpenFile:te},e.id))]})}}},e=>{e.O(0,[7330,2941,2995,6079,2693,2254,4936,4456,5618,9544,8441,3794,7358],()=>e(e.s=43322)),_N_E=e.O()}]);
|