n9router 0.4.41 → 0.4.43
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/app/.next/BUILD_ID +1 -1
- package/app/.next/app-path-routes-manifest.json +11 -11
- package/app/.next/build-manifest.json +2 -2
- package/app/.next/prerender-manifest.json +3 -3
- package/app/.next/server/app/(dashboard)/dashboard/basic-chat/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/cli-tools/[toolId]/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/cli-tools/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/console-log/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/media-providers/[kind]/[id]/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/media-providers/[kind]/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/media-providers/combo/[id]/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/media-providers/web/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/mitm/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/proxy-pools/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/quota/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/skills/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/_global-error.html +1 -1
- package/app/.next/server/app/_global-error.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/_not-found.html +1 -1
- package/app/.next/server/app/_not-found.rsc +4 -4
- package/app/.next/server/app/_not-found.segments/_full.segment.rsc +4 -4
- package/app/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/_not-found.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/app/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/api/cli-tools/all-statuses/route.js +4 -4
- package/app/.next/server/app/api/cli-tools/antigravity-mitm/alias/route.js +1 -1
- package/app/.next/server/app/api/cli-tools/claude-settings/route.js +2 -2
- package/app/.next/server/app/api/cli-tools/cline-settings/route.js +2 -2
- package/app/.next/server/app/api/cli-tools/codex-settings/route.js +1 -1
- package/app/.next/server/app/api/cli-tools/copilot-settings/route.js +2 -2
- package/app/.next/server/app/api/cli-tools/cowork-mcp-registry/route.js +2 -2
- package/app/.next/server/app/api/cli-tools/cowork-mcp-tools/route.js +2 -2
- package/app/.next/server/app/api/cli-tools/cowork-settings/route.js +1 -1
- package/app/.next/server/app/api/cli-tools/deepseek-tui-settings/route.js +2 -2
- package/app/.next/server/app/api/cli-tools/droid-settings/route.js +1 -1
- package/app/.next/server/app/api/cli-tools/hermes-settings/route.js +2 -2
- package/app/.next/server/app/api/cli-tools/jcode-settings/route.js +1 -1
- package/app/.next/server/app/api/cli-tools/kilo-settings/route.js +1 -1
- package/app/.next/server/app/api/cli-tools/openclaw-settings/route.js +2 -2
- package/app/.next/server/app/api/cli-tools/opencode-settings/route.js +2 -2
- package/app/.next/server/app/api/donate/route.js +1 -1
- package/app/.next/server/app/api/models/route.js +1 -1
- package/app/.next/server/app/api/models/test/route.js +1 -1
- package/app/.next/server/app/api/providers/[id]/test/route.js +1 -1
- package/app/.next/server/app/api/providers/[id]/test-models/route.js +1 -1
- package/app/.next/server/app/api/providers/route.js +1 -1
- package/app/.next/server/app/api/translator/console-logs/route.js +1 -1
- package/app/.next/server/app/api/translator/console-logs/stream/route.js +1 -1
- package/app/.next/server/app/api/tunnel/tailscale-install/route.js +2 -2
- package/app/.next/server/app/api/version/route.js +1 -1
- package/app/.next/server/app/callback/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/callback.html +1 -1
- package/app/.next/server/app/callback.rsc +4 -4
- package/app/.next/server/app/callback.segments/_full.segment.rsc +4 -4
- package/app/.next/server/app/callback.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/callback.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/callback.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/callback.segments/callback/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/callback.segments/callback.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/basic-chat.html +1 -1
- package/app/.next/server/app/dashboard/basic-chat.rsc +6 -6
- package/app/.next/server/app/dashboard/basic-chat.segments/!KGRhc2hib2FyZCk/dashboard/basic-chat/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/basic-chat.segments/!KGRhc2hib2FyZCk/dashboard/basic-chat.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/basic-chat.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/basic-chat.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/basic-chat.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/basic-chat.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/basic-chat.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/basic-chat.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/cli-tools.html +1 -1
- package/app/.next/server/app/dashboard/cli-tools.rsc +6 -6
- package/app/.next/server/app/dashboard/cli-tools.segments/!KGRhc2hib2FyZCk/dashboard/cli-tools/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/cli-tools.segments/!KGRhc2hib2FyZCk/dashboard/cli-tools.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/cli-tools.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/cli-tools.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/cli-tools.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/cli-tools.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/cli-tools.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/cli-tools.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/combos.html +1 -1
- package/app/.next/server/app/dashboard/combos.rsc +6 -6
- package/app/.next/server/app/dashboard/combos.segments/!KGRhc2hib2FyZCk/dashboard/combos/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/combos.segments/!KGRhc2hib2FyZCk/dashboard/combos.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/combos.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/combos.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/combos.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/combos.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/combos.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/combos.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/endpoint.html +1 -1
- package/app/.next/server/app/dashboard/endpoint.rsc +6 -6
- package/app/.next/server/app/dashboard/endpoint.segments/!KGRhc2hib2FyZCk/dashboard/endpoint/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/endpoint.segments/!KGRhc2hib2FyZCk/dashboard/endpoint.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/endpoint.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/endpoint.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/endpoint.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/endpoint.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/endpoint.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/endpoint.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/media-providers/web.html +1 -1
- package/app/.next/server/app/dashboard/media-providers/web.rsc +6 -6
- package/app/.next/server/app/dashboard/media-providers/web.segments/!KGRhc2hib2FyZCk/dashboard/media-providers/web/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/media-providers/web.segments/!KGRhc2hib2FyZCk/dashboard/media-providers/web.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/media-providers/web.segments/!KGRhc2hib2FyZCk/dashboard/media-providers.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/media-providers/web.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/media-providers/web.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/media-providers/web.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/media-providers/web.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/media-providers/web.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/media-providers/web.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/mitm.html +1 -1
- package/app/.next/server/app/dashboard/mitm.rsc +6 -6
- package/app/.next/server/app/dashboard/mitm.segments/!KGRhc2hib2FyZCk/dashboard/mitm/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/mitm.segments/!KGRhc2hib2FyZCk/dashboard/mitm.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/mitm.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/mitm.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/mitm.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/mitm.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/mitm.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/mitm.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/profile.html +1 -1
- package/app/.next/server/app/dashboard/profile.rsc +6 -6
- package/app/.next/server/app/dashboard/profile.segments/!KGRhc2hib2FyZCk/dashboard/profile/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/profile.segments/!KGRhc2hib2FyZCk/dashboard/profile.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/profile.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/profile.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/profile.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/profile.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/profile.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/profile.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/providers/new.html +1 -1
- package/app/.next/server/app/dashboard/providers/new.rsc +6 -6
- package/app/.next/server/app/dashboard/providers/new.segments/!KGRhc2hib2FyZCk/dashboard/providers/new/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/providers/new.segments/!KGRhc2hib2FyZCk/dashboard/providers/new.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/providers/new.segments/!KGRhc2hib2FyZCk/dashboard/providers.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/providers/new.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/providers/new.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/providers/new.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/providers/new.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/providers/new.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/providers/new.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/providers.html +1 -1
- package/app/.next/server/app/dashboard/providers.rsc +6 -6
- package/app/.next/server/app/dashboard/providers.segments/!KGRhc2hib2FyZCk/dashboard/providers/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/providers.segments/!KGRhc2hib2FyZCk/dashboard/providers.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/providers.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/providers.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/providers.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/providers.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/providers.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/providers.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/proxy-pools.html +1 -1
- package/app/.next/server/app/dashboard/proxy-pools.rsc +6 -6
- package/app/.next/server/app/dashboard/proxy-pools.segments/!KGRhc2hib2FyZCk/dashboard/proxy-pools/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/proxy-pools.segments/!KGRhc2hib2FyZCk/dashboard/proxy-pools.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/proxy-pools.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/proxy-pools.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/proxy-pools.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/proxy-pools.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/proxy-pools.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/proxy-pools.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/quota.html +2 -2
- package/app/.next/server/app/dashboard/quota.rsc +7 -7
- package/app/.next/server/app/dashboard/quota.segments/!KGRhc2hib2FyZCk/dashboard/quota/__PAGE__.segment.rsc +3 -3
- package/app/.next/server/app/dashboard/quota.segments/!KGRhc2hib2FyZCk/dashboard/quota.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/quota.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/quota.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/quota.segments/_full.segment.rsc +7 -7
- package/app/.next/server/app/dashboard/quota.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/quota.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/quota.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/dashboard/settings/pricing.html +1 -1
- package/app/.next/server/app/dashboard/settings/pricing.rsc +4 -4
- package/app/.next/server/app/dashboard/settings/pricing.segments/_full.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/settings/pricing.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/settings/pricing.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/settings/pricing.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings/pricing.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard/settings.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/settings/pricing.segments/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/skills.html +1 -1
- package/app/.next/server/app/dashboard/skills.rsc +6 -6
- package/app/.next/server/app/dashboard/skills.segments/!KGRhc2hib2FyZCk/dashboard/skills/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/skills.segments/!KGRhc2hib2FyZCk/dashboard/skills.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/skills.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/skills.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/skills.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/skills.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/skills.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/skills.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/translator.html +1 -1
- package/app/.next/server/app/dashboard/translator.rsc +6 -6
- package/app/.next/server/app/dashboard/translator.segments/!KGRhc2hib2FyZCk/dashboard/translator/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/translator.segments/!KGRhc2hib2FyZCk/dashboard/translator.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/translator.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/translator.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/translator.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/translator.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/translator.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/translator.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/usage.html +1 -1
- package/app/.next/server/app/dashboard/usage.rsc +6 -6
- package/app/.next/server/app/dashboard/usage.segments/!KGRhc2hib2FyZCk/dashboard/usage/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/usage.segments/!KGRhc2hib2FyZCk/dashboard/usage.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/usage.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/usage.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard/usage.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard/usage.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard/usage.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard/usage.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/dashboard.html +1 -1
- package/app/.next/server/app/dashboard.rsc +6 -6
- package/app/.next/server/app/dashboard.segments/!KGRhc2hib2FyZCk/dashboard/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/dashboard.segments/!KGRhc2hib2FyZCk/dashboard.segment.rsc +1 -1
- package/app/.next/server/app/dashboard.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/app/.next/server/app/dashboard.segments/_full.segment.rsc +6 -6
- package/app/.next/server/app/dashboard.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/dashboard.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/dashboard.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/index.html +1 -1
- package/app/.next/server/app/index.rsc +4 -4
- package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/index.segments/_full.segment.rsc +4 -4
- package/app/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/index.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/landing/page.js +1 -1
- package/app/.next/server/app/landing/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/landing.html +1 -1
- package/app/.next/server/app/landing.rsc +4 -4
- package/app/.next/server/app/landing.segments/_full.segment.rsc +4 -4
- package/app/.next/server/app/landing.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/landing.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/landing.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/landing.segments/landing/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/landing.segments/landing.segment.rsc +1 -1
- package/app/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/login.html +1 -1
- package/app/.next/server/app/login.rsc +5 -5
- package/app/.next/server/app/login.segments/_full.segment.rsc +5 -5
- package/app/.next/server/app/login.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/login.segments/_index.segment.rsc +4 -4
- package/app/.next/server/app/login.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/login.segments/login/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/login.segments/login.segment.rsc +1 -1
- package/app/.next/server/app/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app-paths-manifest.json +11 -11
- package/app/.next/server/chunks/3110.js +1 -1
- package/app/.next/server/chunks/3588.js +1 -1
- package/app/.next/server/chunks/412.js +1 -1
- package/app/.next/server/chunks/5995.js +1 -1
- package/app/.next/server/chunks/6251.js +1 -1
- package/app/.next/server/chunks/6811.js +1 -1
- package/app/.next/server/chunks/9807.js +1 -1
- package/app/.next/server/middleware-build-manifest.js +1 -1
- package/app/.next/server/pages/404.html +1 -1
- package/app/.next/server/pages/500.html +1 -1
- package/app/.next/server/server-reference-manifest.js +1 -1
- package/app/.next/server/server-reference-manifest.json +1 -1
- package/app/.next/static/chunks/{1321-25379bf821e14ce8.js → 1321-03808de72db0a766.js} +1 -1
- package/app/.next/static/chunks/{4406-05ac5641472f331e.js → 4406-abc51cf55210026c.js} +5 -5
- package/app/.next/static/chunks/{5497-73d5899267432022.js → 5497-6693628388854075.js} +1 -1
- package/app/.next/static/css/{440b3581c215aef0.css → 958bcd529c8d4b7c.css} +1 -1
- package/app/package.json +1 -1
- package/app/src/mitm/server.js +66 -41
- package/app/src/mitm/tokenPool.js +147 -13
- package/app/src/mitm/tokenSwapRetry.js +108 -0
- package/package.json +1 -1
- /package/app/.next/static/{II4U3Zq-L5XToPtNDSJfG → p_zZZ7bGM2zUCztNMVhuB}/_buildManifest.js +0 -0
- /package/app/.next/static/{II4U3Zq-L5XToPtNDSJfG → p_zZZ7bGM2zUCztNMVhuB}/_ssgManifest.js +0 -0
|
@@ -20,7 +20,7 @@ amp --model "{{model}}"
|
|
|
20
20
|
"model": {
|
|
21
21
|
"name": "{{model}}"
|
|
22
22
|
}
|
|
23
|
-
}`}},"deepseek-tui":{id:"deepseek-tui",name:"DeepSeek TUI",image:"/providers/deepseek-tui.png",color:"#4D6BFE",description:"DeepSeek Terminal Coding Agent (Rust TUI)",docsUrl:"https://github.com/DeepSeek-TUI/DeepSeek-TUI",configType:"custom",defaultCommand:"deepseek",modelAliases:["deepseek-v4-pro","deepseek-v4-flash","deepseek-chat","deepseek-reasoner"],defaultModels:[{id:"deepseek-v4-pro",name:"DeepSeek V4 Pro",alias:"deepseek-v4-pro"},{id:"deepseek-v4-flash",name:"DeepSeek V4 Flash",alias:"deepseek-v4-flash"},{id:"deepseek-chat",name:"DeepSeek V3 Chat",alias:"deepseek-chat"}],notes:[{type:"info",text:"DeepSeek TUI uses ~/.deepseek/config.toml for configuration. 9Router will update the provider to 'openai' mode with your base_url, api_key, and model."},{type:"warning",text:"Config path: Linux/macOS ~/.deepseek/config.toml • Windows %USERPROFILE%\\.deepseek\\config.toml"}]},jcode:{id:"jcode",name:"jcode",image:"/providers/jcode.png",color:"#FF6B35",description:"High-performance Rust-based coding agent harness",configType:"custom",docsUrl:"https://github.com/1jehuang/jcode",notes:[{type:"info",text:"jcode is a Rust-based coding agent with semantic memory, multi-agent swarms, and extreme performance (27.8 MB RAM, 14ms boot)."},{type:"info",text:"Configure 9router as an OpenAI-compatible provider to route all jcode requests through 9router's optimization layer."},{type:"warning",text:"Requires jcode installed. Install via: curl -fsSL https://raw.githubusercontent.com/1jehuang/jcode/master/scripts/install.sh | bash"}],defaultModels:[{id:"claude-opus-4-7",name:"Claude Opus 4.7",alias:"opus",defaultValue:"cc/claude-opus-4-7"},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",alias:"sonnet",defaultValue:"cc/claude-sonnet-4-6"},{id:"gpt-5.5",name:"GPT 5.5",alias:"gpt5",defaultValue:"cx/gpt-5.5"},{id:"gemini-3.1-pro",name:"Gemini 3.1 Pro",alias:"gemini",defaultValue:"gemini/gemini-3.1-pro"}]}}},40295:e=>{e.exports={TOOL_HOSTS:{antigravity:["daily-cloudcode-pa.googleapis.com","cloudcode-pa.googleapis.com"],copilot:["api.individual.githubcopilot.com"],kiro:["q.us-east-1.amazonaws.com","codewhisperer.us-east-1.amazonaws.com"],cursor:["api2.cursor.sh"]}}},57294:(e,t,s)=>{s.d(t,{$4:()=>n,$L:()=>i,W_:()=>o,mO:()=>l,sQ:()=>r});var a=s(45564);function l(e){if(!e)return"-";try{let t="string"==typeof e?new Date(e):e,s=new Date,a=t-s;if(a<=0)return"-";let l=Math.ceil(a/6e4);if(l<60)return`${l}m`;let r=Math.floor(l/60),n=l%60;if(r<24)return`${r}h ${n}m`;let i=Math.floor(r/24);return`${i}d ${r%24}h ${n}m`}catch(e){return"-"}}function r(e){if(!e)return null;try{let t="string"==typeof e?new Date(e):e,s=new Date,a=new Date(s.getFullYear(),s.getMonth(),s.getDate()),l=new Date(a);l.setDate(l.getDate()+1);let r=new Date(l);r.setDate(r.getDate()+1);let n="";n=t>=a&&t<l?"Today":t>=l&&t<r?"Tomorrow":t.toLocaleDateString("en-US",{month:"short",day:"numeric"});let i=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return`${n}, ${i}`}catch{return null}}function n(e,t){return t&&0!==t?!e||e<0?100:e>=t?0:Math.round((t-e)/t*100):0}function i(e){return e?.remaining!==void 0?Math.max(0,Math.round(e.remaining)):e?.remainingPercentage!==void 0?Math.round(e.remainingPercentage):n(e?.used,e?.total)}function o(e,t){if(!t||"object"!=typeof t)return[];let s=[];try{switch(e.toLowerCase()){case"github":default:t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:e,used:t.used||0,total:t.total||0,resetAt:t.resetAt||null})});break;case"antigravity":t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:t.displayName||e,modelKey:e,used:t.used||0,total:t.total||0,resetAt:t.resetAt||null,remainingPercentage:t.remainingPercentage})});break;case"codex":t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:e,used:t.used||0,total:t.total||0,remaining:t.remaining,resetAt:t.resetAt||null})});break;case"kiro":t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:e,used:t.used||0,total:t.total||0,resetAt:t.resetAt||null})});break;case"qoder":t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{("organization"!==e||t&&0!==(Number(t.total)||0))&&s.push({name:"user"===e?"Personal":"organization"===e?"Organization":e,used:t.used||0,total:t.total||0,unit:t.unit,resetAt:t.resetAt||null})});break;case"claude":t.message?s.push({name:"error",used:0,total:0,resetAt:null,message:t.message}):t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:e,used:t.used||0,total:t.total||0,resetAt:t.resetAt||null})})}}catch(t){return console.error(`Error parsing quota data for ${e}:`,t),[]}let l=(0,a.KC)(e);if(l.length>0){let e=new Map(l.map((e,t)=>[e.id,t]));s.sort((t,s)=>{let a=t.modelKey||t.name,l=s.modelKey||s.name;return(e.get(a)??999)-(e.get(l)??999)})}return s}},83433:(e,t,s)=>{s.d(t,{Tk:()=>f,aG:()=>F,Ah:()=>y,h1:()=>L,Q6:()=>I,lF:()=>B,a7:()=>k,ZM:()=>b,RF:()=>N,mW:()=>J,c9:()=>q,gY:()=>eo,tA:()=>W,kn:()=>V,yZ:()=>j,qO:()=>T,xm:()=>ei});var a=s(95155),l=s(12115),r=s(35497),n=s(5772),i=s(90620);let o="9router.cliToolEndpointPresets",d="__custom__",c="__save__",m=e=>{window.localStorage.setItem(o,JSON.stringify(e))};function x({value:e,onChange:t,requiresExternalUrl:s=!1,tunnelEnabled:r=!1,tunnelPublicUrl:n="",tailscaleEnabled:u=!1,tailscaleUrl:p="",cloudEnabled:h=!1,cloudUrl:g="",withV1:f=!0}){let[y,b]=(0,l.useState)([]),[j,v]=(0,l.useState)(""),[N,w]=(0,l.useState)(""),k=(0,l.useRef)(!1);(0,l.useEffect)(()=>{b((()=>{try{let e=JSON.parse(window.localStorage.getItem(o)||"[]");if(!Array.isArray(e))return[];return e.filter(e=>e?.name&&e?.baseUrl)}catch{return[]}})())},[]);let C=(0,l.useMemo)(()=>(({requiresExternalUrl:e,tunnelEnabled:t,tunnelPublicUrl:s,tailscaleEnabled:a,tailscaleUrl:l,cloudEnabled:r,cloudUrl:n,savedPresets:o,withV1:c})=>{let m=[],x=e=>{let t;return c?(t=(e||"").replace(/\/+$/,""))?/\/v1$/.test(t)?t:`${t}/v1`:"":(e||"").replace(/\/+$/,"")};if(!e){let e=x(`http://127.0.0.1:${i.h0.appPort}`);m.push({value:"local",label:e,url:e})}if(t&&s){let e=x(s);m.push({value:"tunnel",label:e,url:e})}if(a&&l){let e=x(l);m.push({value:"tailscale",label:e,url:e})}if(r&&n){let e=x(n);m.push({value:"cloud",label:e,url:e})}return o.forEach(e=>{m.push({value:`saved:${e.name}`,label:e.baseUrl,url:e.baseUrl,saved:!0})}),m.push({value:d,label:"Custom URL...",url:""}),m})({requiresExternalUrl:s,tunnelEnabled:r,tunnelPublicUrl:n,tailscaleEnabled:u,tailscaleUrl:p,cloudEnabled:h,cloudUrl:g,savedPresets:y,withV1:f}),[s,r,n,u,p,h,g,y,f]);(0,l.useEffect)(()=>{if(k.current||0===C.length)return;k.current=!0;let e=C.find(e=>e.value!==d);e?(v(e.value),t(e.url)):v(d)},[C,t]);let S=j.startsWith("saved:"),_=j===d,A=_&&(N||"").trim().length>0;return(0,a.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("select",{value:j,onChange:s=>{let a=s.target.value;if(a===c){let t=(e||"").trim();if(!t)return;let s=t;try{s=new URL(t).host}catch{}let a=window.prompt("Save endpoint as:",s);if(!a?.trim())return;let l=[...y.filter(e=>e.name!==a.trim()),{name:a.trim(),baseUrl:t}].sort((e,t)=>e.name.localeCompare(t.name));b(l),m(l);return}if(v(a),a===d){w(""),t("");return}let l=C.find(e=>e.value===a);l&&t(l.url)},className:"flex-1 min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[C.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value)),A&&(0,a.jsx)("option",{value:c,children:"+ Save current as..."})]}),S&&(0,a.jsx)("button",{type:"button",onClick:()=>{if(!j.startsWith("saved:"))return;let e=j.slice(6),s=y.filter(t=>t.name!==e);b(s),m(s),v(d),w(""),t("")},className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors shrink-0",title:"Delete saved endpoint",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"delete"})})]}),_&&(0,a.jsx)("input",{type:"text",value:N,onChange:e=>{let s=e.target.value;w(s),t(s)},placeholder:f?"https://example.com/v1":"https://example.com",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}let u="__custom__";function p({value:e,onChange:t,apiKeys:s=[],cloudEnabled:r=!1,className:n=""}){let i=!s.some(t=>t.key===e)&&""!==e,[o,d]=(0,l.useState)(()=>e?s.some(t=>t.key===e)?e:u:s.length>0?s[0].key:u),[c,m]=(0,l.useState)(i?e:"");return 0===s.length&&o!==u&&o!==u?(0,a.jsx)("span",{className:`min-w-0 rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5 ${n}`,children:r?"No API keys - Create one in Keys page":"sk_9router (default)"}):(0,a.jsxs)("div",{className:`flex flex-col gap-1.5 ${n}`,children:[(0,a.jsxs)("select",{value:o,onChange:e=>{let s=e.target.value;d(s),s===u?(m(""),t("")):t(s)},className:"w-full min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[s.map(e=>(0,a.jsx)("option",{value:e.key,children:e.key},e.id)),(0,a.jsx)("option",{value:u,children:"Custom..."})]}),o===u&&(0,a.jsx)("input",{type:"text",value:c,onChange:e=>{let s=e.target.value;m(s),t(s)},placeholder:"sk-...",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}let h=e=>(e||"").replace(/\/+$/,"");function g(e,t={}){if(!e)return!1;let s=h(e),{tunnelPublicUrl:a,tailscaleUrl:l,cloudUrl:r}=t;return!!(/localhost|127\.0\.0\.1|0\.0\.0\.0/.test(s)||a&&s.startsWith(h(a))||l&&s.startsWith(h(l))||r&&s.startsWith(h(r)))}function f({tool:e,isExpanded:t,onToggle:s,activeProviders:i,modelMappings:o,onModelMappingChange:d,baseUrl:c,hasActiveProviders:m,apiKeys:u,cloudEnabled:h,initialStatus:y,tunnelEnabled:b,tunnelPublicUrl:j,tailscaleEnabled:v,tailscaleUrl:N}){let w,k,C,[S,_]=(0,l.useState)(y||null),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(!1),[O,T]=(0,l.useState)(!1),[P,R]=(0,l.useState)(null),[I,U]=(0,l.useState)(!1),[D,K]=(0,l.useState)(!1),[z,L]=(0,l.useState)(null),[F,q]=(0,l.useState)(""),[H,B]=(0,l.useState)({}),[J,G]=(0,l.useState)(!1),[W,Y]=(0,l.useState)(""),[V,Z]=(0,l.useState)(!1),Q=(0,l.useRef)(!1),X=(()=>{if(!S?.installed)return null;let e=S.settings?.env?.ANTHROPIC_BASE_URL;return e?g(e,{tunnelPublicUrl:j,tailscaleUrl:N,cloudUrl:h?"https://9router.com":null})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{u?.length>0&&!F&&q(u[0].key)},[u,F]),(0,l.useEffect)(()=>{y&&_(y)},[y]),(0,l.useEffect)(()=>{t&&!S&&(es(),et()),t&&et()},[t]),(0,l.useEffect)(()=>{fetch("/api/settings").then(e=>e.json()).then(e=>{Z(!!e.ccFilterNaming)}).catch(()=>{})},[]);let ee=async e=>{let t=e.target.checked;Z(t),await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({ccFilterNaming:t})}).catch(()=>{})},et=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&B(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(S?.installed&&!Q.current){Q.current=!0;let t=S.settings?.env||{};e.defaultModels.forEach(e=>{if(e.envKey){let s=t[e.envKey]||e.defaultValue||"";s&&d(e.alias,s)}});let s=t.ANTHROPIC_AUTH_TOKEN;s&&u?.some(e=>e.key===s)&&q(s)}},[S,u,e.defaultModels,d]);let es=async()=>{E(!0);try{let e=await fetch("/api/cli-tools/claude-settings"),t=await e.json();_(t)}catch(e){_({installed:!1,error:e.message})}finally{E(!1)}},ea=()=>{let e=W||c;return e.endsWith("/v1")?e:`${e}/v1`},el=async()=>{M(!0),R(null);try{let t={ANTHROPIC_BASE_URL:ea()},s=F?.trim()||(u?.length>0?u[0].key:null)||(h?null:"sk_9router");s&&(t.ANTHROPIC_AUTH_TOKEN=s),e.defaultModels.forEach(e=>{let s=o[e.alias];s&&e.envKey&&(t[e.envKey]=s)});let a=await fetch("/api/cli-tools/claude-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({env:t})}),l=await a.json();a.ok?(R({type:"success",text:"Settings applied successfully!"}),_(e=>({...e,hasBackup:!0,settings:{...e?.settings,env:t}}))):R({type:"error",text:l.error||"Failed to apply settings"})}catch(e){R({type:"error",text:e.message})}finally{M(!1)}},er=async()=>{T(!0),R(null);try{let t=await fetch("/api/cli-tools/claude-settings",{method:"DELETE"}),s=await t.json();t.ok?(R({type:"success",text:"Settings reset successfully!"}),e.defaultModels.forEach(e=>d(e.alias,e.defaultValue||"")),q("")):R({type:"error",text:s.error||"Failed to reset settings"})}catch(e){R({type:"error",text:e.message})}finally{T(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/claude.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[A&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Claude CLI..."})]}),!A&&S&&!S.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Claude CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>G(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>U(!I),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:I?"expand_less":"help"}),I?"Hide":"How to Install"]})]})]}),I&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),(0,a.jsx)("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g @anthropic-ai/claude-code"})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:["After installation, run ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"claude"})," to verify."]})]})]})]}),!A&&S?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:W||((w=W||c).endsWith("/v1")?w:`${w}/v1`),onChange:Y,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:b,tunnelPublicUrl:j,tailscaleEnabled:v,tailscaleUrl:N})]}),S?.settings?.env?.ANTHROPIC_BASE_URL&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:S.settings.env.ANTHROPIC_BASE_URL})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:F,onChange:q,apiKeys:u,cloudEnabled:h})]}),e.defaultModels.map(e=>(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:e.name}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:o[e.alias]||"",onChange:t=>d(e.alias,t.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),o[e.alias]&&(0,a.jsx)("button",{onClick:()=>d(e.alias,""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>{L(e.alias),K(!0)},disabled:!m,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${m?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]},e.alias)),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Filter naming"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",checked:V,onChange:ee,className:"w-3.5 h-3.5 accent-primary cursor-pointer"}),(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"Filter naming requests"})]}),(0,a.jsx)(r.m_,{text:"Intercepts Claude Code's topic-naming requests and returns a fake response locally, saving API tokens.",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] cursor-help",children:"info"})})]})]}),P&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===P.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===P.type?"check_circle":"error"}),(0,a.jsx)("span",{children:P.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:el,disabled:!m,loading:$,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:er,disabled:!S?.has9Router,loading:O,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>G(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:D,onClose:()=>K(!1),onSelect:e=>{z&&d(z,e.value)},selectedModel:z?o[z]:null,activeProviders:i,modelAliases:H,title:`Select model for ${z}`}),(0,a.jsx)(r.uR,{isOpen:J,onClose:()=>G(!1),title:"Claude CLI - Manual Configuration",configs:(k=F&&F.trim()?F:h?"<API_KEY_FROM_DASHBOARD>":"sk_9router",C={ANTHROPIC_BASE_URL:ea(),ANTHROPIC_AUTH_TOKEN:k},e.defaultModels.forEach(e=>{let t=o[e.alias];t&&e.envKey&&(C[e.envKey]=t)}),[{filename:"~/.claude/settings.json",content:JSON.stringify({hasCompletedOnboarding:!0,env:C},null,2)}])})]})}function y({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:b}){let j,v,N,w,[k,C]=(0,l.useState)(m||null),[S,_]=(0,l.useState)(!1),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(!1),[O,T]=(0,l.useState)(null),[P,R]=(0,l.useState)(!1),[I,U]=(0,l.useState)(""),[D,K]=(0,l.useState)(""),[z,L]=(0,l.useState)(""),[F,q]=(0,l.useState)(!1),[H,B]=(0,l.useState)(!1),[J,G]=(0,l.useState)({}),[W,Y]=(0,l.useState)(!1),[V,Z]=(0,l.useState)("");(0,l.useEffect)(()=>{o?.length>0&&!I&&U(o[0].key)},[o,I]),(0,l.useEffect)(()=>{m&&C(m)},[m]),(0,l.useEffect)(()=>{t&&!k&&(et(),Q()),t&&Q()},[t]);let Q=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&G(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(k?.config){let e=k.config.match(/^model\s*=\s*"([^"]+)"/m);e&&K(e[1]);let t=k.config.match(/\[agents\.subagent\]\s*\n\s*model\s*=\s*"([^"]+)"/m);t&&L(t[1])}},[k]);let X=(()=>{if(!k?.installed)return null;if(!k.config)return"not_configured";let e=k.config.match(/base_url\s*=\s*"([^"]+)"/);return g(e?e[1]:"",{tunnelPublicUrl:h,tailscaleUrl:b})?"configured":"other"})(),ee=()=>{let e=V||`${i}/v1`;return e.endsWith("/v1")?e:`${e}/v1`},et=async()=>{_(!0);try{let e=await fetch("/api/cli-tools/codex-settings"),t=await e.json();C(t)}catch(e){C({installed:!1,error:e.message})}finally{_(!1)}},es=async()=>{E(!0),T(null);try{let e=I&&I.trim()||c?I:"sk_9router",t=await fetch("/api/cli-tools/codex-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ee(),apiKey:e,model:D,subagentModel:z||D})}),s=await t.json();t.ok?(T({type:"success",text:"Settings applied successfully!"}),et()):T({type:"error",text:s.error||"Failed to apply settings"})}catch(e){T({type:"error",text:e.message})}finally{E(!1)}},ea=async()=>{M(!0),T(null);try{let e=await fetch("/api/cli-tools/codex-settings",{method:"DELETE"}),t=await e.json();e.ok?(T({type:"success",text:"Settings reset successfully!"}),K(""),L(""),et()):T({type:"error",text:t.error||"Failed to reset settings"})}catch(e){T({type:"error",text:e.message})}finally{M(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/codex.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[S&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Codex CLI..."})]}),!S&&k&&!k.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Codex CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>Y(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>R(!P),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:P?"expand_less":"help"}),P?"Hide":"How to Install"]})]})]}),P&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),(0,a.jsx)("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g @openai/codex"})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:["After installation, run ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"codex"})," to verify."]}),(0,a.jsx)("div",{className:"pt-2 border-t border-border",children:(0,a.jsxs)("p",{className:"text-text-muted text-xs",children:["Codex uses ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"~/.codex/auth.json"})," with ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"OPENAI_API_KEY"}),'. Click "Apply" to auto-configure.']})})]})]})]}),!S&&k?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:V||V||`${i}/v1`,onChange:Z,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:b})]}),k?.config&&((v=(j=k.config.match(/base_url\s*=\s*"([^"]+)"/))?j[1]:null)?(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:v})]}):null),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:I,onChange:U,apiKeys:o,cloudEnabled:c})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:D,onChange:e=>K(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),D&&(0,a.jsx)("button",{onClick:()=>K(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>q(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Subagent Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:z,onChange:e=>L(e.target.value),placeholder:D||"provider/model-id (defaults to main model)",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),z&&(0,a.jsx)("button",{onClick:()=>L(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear (will use main model)",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>B(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),O&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===O.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===O.type?"check_circle":"error"}),(0,a.jsx)("span",{children:O.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:es,disabled:!I&&c&&o.length>0||!D,loading:A,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:ea,disabled:$,loading:$,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>Y(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:F,onClose:()=>q(!1),onSelect:e=>{K(e.value),z||L(e.value),q(!1)},selectedModel:D,activeProviders:d,modelAliases:J,title:"Select Model for Codex"}),(0,a.jsx)(r.rq,{isOpen:H,onClose:()=>B(!1),onSelect:e=>{L(e.value),B(!1)},selectedModel:z,activeProviders:d,modelAliases:J,title:"Select Subagent Model for Codex"}),(0,a.jsx)(r.uR,{isOpen:W,onClose:()=>Y(!1),title:"Codex CLI - Manual Configuration",configs:(N=I&&I.trim()?I:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",w=z||D,[{filename:"~/.codex/config.toml",content:`# 9Router Configuration for Codex CLI
|
|
23
|
+
}`}},"deepseek-tui":{id:"deepseek-tui",name:"DeepSeek TUI",image:"/providers/deepseek-tui.png",color:"#4D6BFE",description:"DeepSeek Terminal Coding Agent (Rust TUI)",docsUrl:"https://github.com/DeepSeek-TUI/DeepSeek-TUI",configType:"custom",defaultCommand:"deepseek",modelAliases:["deepseek-v4-pro","deepseek-v4-flash","deepseek-chat","deepseek-reasoner"],defaultModels:[{id:"deepseek-v4-pro",name:"DeepSeek V4 Pro",alias:"deepseek-v4-pro"},{id:"deepseek-v4-flash",name:"DeepSeek V4 Flash",alias:"deepseek-v4-flash"},{id:"deepseek-chat",name:"DeepSeek V3 Chat",alias:"deepseek-chat"}],notes:[{type:"info",text:"DeepSeek TUI uses ~/.deepseek/config.toml for configuration. 9Router will update the provider to 'openai' mode with your base_url, api_key, and model."},{type:"warning",text:"Config path: Linux/macOS ~/.deepseek/config.toml • Windows %USERPROFILE%\\.deepseek\\config.toml"}]},jcode:{id:"jcode",name:"jcode",image:"/providers/jcode.png",color:"#FF6B35",description:"High-performance Rust-based coding agent harness",configType:"custom",docsUrl:"https://github.com/1jehuang/jcode",notes:[{type:"info",text:"jcode is a Rust-based coding agent with semantic memory, multi-agent swarms, and extreme performance (27.8 MB RAM, 14ms boot)."},{type:"info",text:"Configure 9router as an OpenAI-compatible provider to route all jcode requests through 9router's optimization layer."},{type:"warning",text:"Requires jcode installed. Install via: curl -fsSL https://raw.githubusercontent.com/1jehuang/jcode/master/scripts/install.sh | bash"}],defaultModels:[{id:"claude-opus-4-7",name:"Claude Opus 4.7",alias:"opus",defaultValue:"cc/claude-opus-4-7"},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",alias:"sonnet",defaultValue:"cc/claude-sonnet-4-6"},{id:"gpt-5.5",name:"GPT 5.5",alias:"gpt5",defaultValue:"cx/gpt-5.5"},{id:"gemini-3.1-pro",name:"Gemini 3.1 Pro",alias:"gemini",defaultValue:"gemini/gemini-3.1-pro"}]}}},40295:e=>{e.exports={TOOL_HOSTS:{antigravity:["daily-cloudcode-pa.googleapis.com","cloudcode-pa.googleapis.com"],copilot:["api.individual.githubcopilot.com"],kiro:["q.us-east-1.amazonaws.com","codewhisperer.us-east-1.amazonaws.com"],cursor:["api2.cursor.sh"]}}},57294:(e,t,s)=>{s.d(t,{$4:()=>n,$L:()=>i,W_:()=>o,mO:()=>l,sQ:()=>r});var a=s(45564);function l(e){if(!e)return"-";try{let t="string"==typeof e?new Date(e):e,s=new Date,a=t-s;if(a<=0)return"-";let l=Math.ceil(a/6e4);if(l<60)return`${l}m`;let r=Math.floor(l/60),n=l%60;if(r<24)return`${r}h ${n}m`;let i=Math.floor(r/24);return`${i}d ${r%24}h ${n}m`}catch(e){return"-"}}function r(e){if(!e)return null;try{let t="string"==typeof e?new Date(e):e,s=new Date,a=new Date(s.getFullYear(),s.getMonth(),s.getDate()),l=new Date(a);l.setDate(l.getDate()+1);let r=new Date(l);r.setDate(r.getDate()+1);let n="";n=t>=a&&t<l?"Today":t>=l&&t<r?"Tomorrow":t.toLocaleDateString("en-US",{month:"short",day:"numeric"});let i=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return`${n}, ${i}`}catch{return null}}function n(e,t){return t&&0!==t?!e||e<0?100:e>=t?0:Math.round((t-e)/t*100):0}function i(e){return e?.remaining!==void 0?Math.max(0,Math.round(e.remaining)):e?.remainingPercentage!==void 0?Math.round(e.remainingPercentage):n(e?.used,e?.total)}function o(e,t){if(!t||"object"!=typeof t)return[];let s=[];try{switch(e.toLowerCase()){case"github":default:t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:e,used:t.used||0,total:t.total||0,resetAt:t.resetAt||null})});break;case"antigravity":t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:t.displayName||e,modelKey:e,used:t.used||0,total:t.total||0,resetAt:t.resetAt||null,remainingPercentage:t.remainingPercentage})});break;case"codex":t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:e,used:t.used||0,total:t.total||0,remaining:t.remaining,resetAt:t.resetAt||null})});break;case"kiro":t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:e,used:t.used||0,total:t.total||0,resetAt:t.resetAt||null})});break;case"qoder":t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{("organization"!==e||t&&0!==(Number(t.total)||0))&&s.push({name:"user"===e?"Personal":"organization"===e?"Organization":e,used:t.used||0,total:t.total||0,unit:t.unit,resetAt:t.resetAt||null})});break;case"claude":t.message?s.push({name:"error",used:0,total:0,resetAt:null,message:t.message}):t.quotas&&Object.entries(t.quotas).forEach(([e,t])=>{s.push({name:e,used:t.used||0,total:t.total||0,resetAt:t.resetAt||null})})}}catch(t){return console.error(`Error parsing quota data for ${e}:`,t),[]}let l=(0,a.KC)(e);if(l.length>0){let e=new Map(l.map((e,t)=>[e.id,t]));s.sort((t,s)=>{let a=t.modelKey||t.name,l=s.modelKey||s.name;return(e.get(a)??999)-(e.get(l)??999)})}return s}},83433:(e,t,s)=>{s.d(t,{Tk:()=>f,aG:()=>F,Ah:()=>y,h1:()=>L,Q6:()=>I,lF:()=>B,a7:()=>k,ZM:()=>b,RF:()=>N,mW:()=>J,c9:()=>q,gY:()=>ed,tA:()=>G,kn:()=>V,yZ:()=>j,qO:()=>T,xm:()=>eo});var a=s(95155),l=s(12115),r=s(35497),n=s(5772),i=s(90620);let o="9router.cliToolEndpointPresets",d="__custom__",c="__save__",m=e=>{window.localStorage.setItem(o,JSON.stringify(e))};function x({value:e,onChange:t,requiresExternalUrl:s=!1,tunnelEnabled:r=!1,tunnelPublicUrl:n="",tailscaleEnabled:u=!1,tailscaleUrl:p="",cloudEnabled:h=!1,cloudUrl:g="",withV1:f=!0}){let[y,b]=(0,l.useState)([]),[j,v]=(0,l.useState)(""),[N,w]=(0,l.useState)(""),k=(0,l.useRef)(!1);(0,l.useEffect)(()=>{b((()=>{try{let e=JSON.parse(window.localStorage.getItem(o)||"[]");if(!Array.isArray(e))return[];return e.filter(e=>e?.name&&e?.baseUrl)}catch{return[]}})())},[]);let C=(0,l.useMemo)(()=>(({requiresExternalUrl:e,tunnelEnabled:t,tunnelPublicUrl:s,tailscaleEnabled:a,tailscaleUrl:l,cloudEnabled:r,cloudUrl:n,savedPresets:o,withV1:c})=>{let m=[],x=e=>{let t;return c?(t=(e||"").replace(/\/+$/,""))?/\/v1$/.test(t)?t:`${t}/v1`:"":(e||"").replace(/\/+$/,"")};if(!e){let e=x(`http://127.0.0.1:${i.h0.appPort}`);m.push({value:"local",label:e,url:e})}if(t&&s){let e=x(s);m.push({value:"tunnel",label:e,url:e})}if(a&&l){let e=x(l);m.push({value:"tailscale",label:e,url:e})}if(r&&n){let e=x(n);m.push({value:"cloud",label:e,url:e})}return o.forEach(e=>{m.push({value:`saved:${e.name}`,label:e.baseUrl,url:e.baseUrl,saved:!0})}),m.push({value:d,label:"Custom URL...",url:""}),m})({requiresExternalUrl:s,tunnelEnabled:r,tunnelPublicUrl:n,tailscaleEnabled:u,tailscaleUrl:p,cloudEnabled:h,cloudUrl:g,savedPresets:y,withV1:f}),[s,r,n,u,p,h,g,y,f]);(0,l.useEffect)(()=>{if(k.current||0===C.length)return;k.current=!0;let e=C.find(e=>e.value!==d);e?(v(e.value),t(e.url)):v(d)},[C,t]);let S=j.startsWith("saved:"),_=j===d,A=_&&(N||"").trim().length>0;return(0,a.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("select",{value:j,onChange:s=>{let a=s.target.value;if(a===c){let t=(e||"").trim();if(!t)return;let s=t;try{s=new URL(t).host}catch{}let a=window.prompt("Save endpoint as:",s);if(!a?.trim())return;let l=[...y.filter(e=>e.name!==a.trim()),{name:a.trim(),baseUrl:t}].sort((e,t)=>e.name.localeCompare(t.name));b(l),m(l);return}if(v(a),a===d){w(""),t("");return}let l=C.find(e=>e.value===a);l&&t(l.url)},className:"flex-1 min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[C.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value)),A&&(0,a.jsx)("option",{value:c,children:"+ Save current as..."})]}),S&&(0,a.jsx)("button",{type:"button",onClick:()=>{if(!j.startsWith("saved:"))return;let e=j.slice(6),s=y.filter(t=>t.name!==e);b(s),m(s),v(d),w(""),t("")},className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors shrink-0",title:"Delete saved endpoint",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"delete"})})]}),_&&(0,a.jsx)("input",{type:"text",value:N,onChange:e=>{let s=e.target.value;w(s),t(s)},placeholder:f?"https://example.com/v1":"https://example.com",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}let u="__custom__";function p({value:e,onChange:t,apiKeys:s=[],cloudEnabled:r=!1,className:n=""}){let i=!s.some(t=>t.key===e)&&""!==e,[o,d]=(0,l.useState)(()=>e?s.some(t=>t.key===e)?e:u:s.length>0?s[0].key:u),[c,m]=(0,l.useState)(i?e:"");return 0===s.length&&o!==u&&o!==u?(0,a.jsx)("span",{className:`min-w-0 rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5 ${n}`,children:r?"No API keys - Create one in Keys page":"sk_9router (default)"}):(0,a.jsxs)("div",{className:`flex flex-col gap-1.5 ${n}`,children:[(0,a.jsxs)("select",{value:o,onChange:e=>{let s=e.target.value;d(s),s===u?(m(""),t("")):t(s)},className:"w-full min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[s.map(e=>(0,a.jsx)("option",{value:e.key,children:e.key},e.id)),(0,a.jsx)("option",{value:u,children:"Custom..."})]}),o===u&&(0,a.jsx)("input",{type:"text",value:c,onChange:e=>{let s=e.target.value;m(s),t(s)},placeholder:"sk-...",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}let h=e=>(e||"").replace(/\/+$/,"");function g(e,t={}){if(!e)return!1;let s=h(e),{tunnelPublicUrl:a,tailscaleUrl:l,cloudUrl:r}=t;return!!(/localhost|127\.0\.0\.1|0\.0\.0\.0/.test(s)||a&&s.startsWith(h(a))||l&&s.startsWith(h(l))||r&&s.startsWith(h(r)))}function f({tool:e,isExpanded:t,onToggle:s,activeProviders:i,modelMappings:o,onModelMappingChange:d,baseUrl:c,hasActiveProviders:m,apiKeys:u,cloudEnabled:h,initialStatus:y,tunnelEnabled:b,tunnelPublicUrl:j,tailscaleEnabled:v,tailscaleUrl:N}){let w,k,C,[S,_]=(0,l.useState)(y||null),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(!1),[O,T]=(0,l.useState)(!1),[P,R]=(0,l.useState)(null),[I,U]=(0,l.useState)(!1),[D,K]=(0,l.useState)(!1),[z,L]=(0,l.useState)(null),[F,q]=(0,l.useState)(""),[H,B]=(0,l.useState)({}),[J,W]=(0,l.useState)(!1),[G,Y]=(0,l.useState)(""),[V,Z]=(0,l.useState)(!1),Q=(0,l.useRef)(!1),X=(()=>{if(!S?.installed)return null;let e=S.settings?.env?.ANTHROPIC_BASE_URL;return e?g(e,{tunnelPublicUrl:j,tailscaleUrl:N,cloudUrl:h?"https://9router.com":null})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{u?.length>0&&!F&&q(u[0].key)},[u,F]),(0,l.useEffect)(()=>{y&&_(y)},[y]),(0,l.useEffect)(()=>{t&&!S&&(es(),et()),t&&et()},[t]),(0,l.useEffect)(()=>{fetch("/api/settings").then(e=>e.json()).then(e=>{Z(!!e.ccFilterNaming)}).catch(()=>{})},[]);let ee=async e=>{let t=e.target.checked;Z(t),await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({ccFilterNaming:t})}).catch(()=>{})},et=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&B(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(S?.installed&&!Q.current){Q.current=!0;let t=S.settings?.env||{};e.defaultModels.forEach(e=>{if(e.envKey){let s=t[e.envKey]||e.defaultValue||"";s&&d(e.alias,s)}});let s=t.ANTHROPIC_AUTH_TOKEN;s&&u?.some(e=>e.key===s)&&q(s)}},[S,u,e.defaultModels,d]);let es=async()=>{E(!0);try{let e=await fetch("/api/cli-tools/claude-settings"),t=await e.json();_(t)}catch(e){_({installed:!1,error:e.message})}finally{E(!1)}},ea=()=>{let e=G||c;return e.endsWith("/v1")?e:`${e}/v1`},el=async()=>{M(!0),R(null);try{let t={ANTHROPIC_BASE_URL:ea()},s=F?.trim()||(u?.length>0?u[0].key:null)||(h?null:"sk_9router");s&&(t.ANTHROPIC_AUTH_TOKEN=s),e.defaultModels.forEach(e=>{let s=o[e.alias];s&&e.envKey&&(t[e.envKey]=s)});let a=await fetch("/api/cli-tools/claude-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({env:t})}),l=await a.json();a.ok?(R({type:"success",text:"Settings applied successfully!"}),_(e=>({...e,hasBackup:!0,settings:{...e?.settings,env:t}}))):R({type:"error",text:l.error||"Failed to apply settings"})}catch(e){R({type:"error",text:e.message})}finally{M(!1)}},er=async()=>{T(!0),R(null);try{let t=await fetch("/api/cli-tools/claude-settings",{method:"DELETE"}),s=await t.json();t.ok?(R({type:"success",text:"Settings reset successfully!"}),e.defaultModels.forEach(e=>d(e.alias,e.defaultValue||"")),q("")):R({type:"error",text:s.error||"Failed to reset settings"})}catch(e){R({type:"error",text:e.message})}finally{T(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/claude.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[A&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Claude CLI..."})]}),!A&&S&&!S.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Claude CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>W(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>U(!I),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:I?"expand_less":"help"}),I?"Hide":"How to Install"]})]})]}),I&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),(0,a.jsx)("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g @anthropic-ai/claude-code"})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:["After installation, run ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"claude"})," to verify."]})]})]})]}),!A&&S?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:G||((w=G||c).endsWith("/v1")?w:`${w}/v1`),onChange:Y,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:b,tunnelPublicUrl:j,tailscaleEnabled:v,tailscaleUrl:N})]}),S?.settings?.env?.ANTHROPIC_BASE_URL&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:S.settings.env.ANTHROPIC_BASE_URL})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:F,onChange:q,apiKeys:u,cloudEnabled:h})]}),e.defaultModels.map(e=>(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:e.name}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:o[e.alias]||"",onChange:t=>d(e.alias,t.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),o[e.alias]&&(0,a.jsx)("button",{onClick:()=>d(e.alias,""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>{L(e.alias),K(!0)},disabled:!m,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${m?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]},e.alias)),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Filter naming"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",checked:V,onChange:ee,className:"w-3.5 h-3.5 accent-primary cursor-pointer"}),(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"Filter naming requests"})]}),(0,a.jsx)(r.m_,{text:"Intercepts Claude Code's topic-naming requests and returns a fake response locally, saving API tokens.",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] cursor-help",children:"info"})})]})]}),P&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===P.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===P.type?"check_circle":"error"}),(0,a.jsx)("span",{children:P.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:el,disabled:!m,loading:$,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:er,disabled:!S?.has9Router,loading:O,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>W(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:D,onClose:()=>K(!1),onSelect:e=>{z&&d(z,e.value)},selectedModel:z?o[z]:null,activeProviders:i,modelAliases:H,title:`Select model for ${z}`}),(0,a.jsx)(r.uR,{isOpen:J,onClose:()=>W(!1),title:"Claude CLI - Manual Configuration",configs:(k=F&&F.trim()?F:h?"<API_KEY_FROM_DASHBOARD>":"sk_9router",C={ANTHROPIC_BASE_URL:ea(),ANTHROPIC_AUTH_TOKEN:k},e.defaultModels.forEach(e=>{let t=o[e.alias];t&&e.envKey&&(C[e.envKey]=t)}),[{filename:"~/.claude/settings.json",content:JSON.stringify({hasCompletedOnboarding:!0,env:C},null,2)}])})]})}function y({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:b}){let j,v,N,w,[k,C]=(0,l.useState)(m||null),[S,_]=(0,l.useState)(!1),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(!1),[O,T]=(0,l.useState)(null),[P,R]=(0,l.useState)(!1),[I,U]=(0,l.useState)(""),[D,K]=(0,l.useState)(""),[z,L]=(0,l.useState)(""),[F,q]=(0,l.useState)(!1),[H,B]=(0,l.useState)(!1),[J,W]=(0,l.useState)({}),[G,Y]=(0,l.useState)(!1),[V,Z]=(0,l.useState)("");(0,l.useEffect)(()=>{o?.length>0&&!I&&U(o[0].key)},[o,I]),(0,l.useEffect)(()=>{m&&C(m)},[m]),(0,l.useEffect)(()=>{t&&!k&&(et(),Q()),t&&Q()},[t]);let Q=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&W(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(k?.config){let e=k.config.match(/^model\s*=\s*"([^"]+)"/m);e&&K(e[1]);let t=k.config.match(/\[agents\.subagent\]\s*\n\s*model\s*=\s*"([^"]+)"/m);t&&L(t[1])}},[k]);let X=(()=>{if(!k?.installed)return null;if(!k.config)return"not_configured";let e=k.config.match(/base_url\s*=\s*"([^"]+)"/);return g(e?e[1]:"",{tunnelPublicUrl:h,tailscaleUrl:b})?"configured":"other"})(),ee=()=>{let e=V||`${i}/v1`;return e.endsWith("/v1")?e:`${e}/v1`},et=async()=>{_(!0);try{let e=await fetch("/api/cli-tools/codex-settings"),t=await e.json();C(t)}catch(e){C({installed:!1,error:e.message})}finally{_(!1)}},es=async()=>{E(!0),T(null);try{let e=I&&I.trim()||c?I:"sk_9router",t=await fetch("/api/cli-tools/codex-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ee(),apiKey:e,model:D,subagentModel:z||D})}),s=await t.json();t.ok?(T({type:"success",text:"Settings applied successfully!"}),et()):T({type:"error",text:s.error||"Failed to apply settings"})}catch(e){T({type:"error",text:e.message})}finally{E(!1)}},ea=async()=>{M(!0),T(null);try{let e=await fetch("/api/cli-tools/codex-settings",{method:"DELETE"}),t=await e.json();e.ok?(T({type:"success",text:"Settings reset successfully!"}),K(""),L(""),et()):T({type:"error",text:t.error||"Failed to reset settings"})}catch(e){T({type:"error",text:e.message})}finally{M(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/codex.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===X&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[S&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Codex CLI..."})]}),!S&&k&&!k.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Codex CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>Y(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>R(!P),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:P?"expand_less":"help"}),P?"Hide":"How to Install"]})]})]}),P&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),(0,a.jsx)("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g @openai/codex"})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:["After installation, run ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"codex"})," to verify."]}),(0,a.jsx)("div",{className:"pt-2 border-t border-border",children:(0,a.jsxs)("p",{className:"text-text-muted text-xs",children:["Codex uses ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"~/.codex/auth.json"})," with ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"OPENAI_API_KEY"}),'. Click "Apply" to auto-configure.']})})]})]})]}),!S&&k?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:V||V||`${i}/v1`,onChange:Z,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:b})]}),k?.config&&((v=(j=k.config.match(/base_url\s*=\s*"([^"]+)"/))?j[1]:null)?(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:v})]}):null),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:I,onChange:U,apiKeys:o,cloudEnabled:c})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:D,onChange:e=>K(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),D&&(0,a.jsx)("button",{onClick:()=>K(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>q(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Subagent Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:z,onChange:e=>L(e.target.value),placeholder:D||"provider/model-id (defaults to main model)",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),z&&(0,a.jsx)("button",{onClick:()=>L(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear (will use main model)",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>B(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),O&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===O.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===O.type?"check_circle":"error"}),(0,a.jsx)("span",{children:O.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:es,disabled:!I&&c&&o.length>0||!D,loading:A,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:ea,disabled:$,loading:$,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>Y(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:F,onClose:()=>q(!1),onSelect:e=>{K(e.value),z||L(e.value),q(!1)},selectedModel:D,activeProviders:d,modelAliases:J,title:"Select Model for Codex"}),(0,a.jsx)(r.rq,{isOpen:H,onClose:()=>B(!1),onSelect:e=>{L(e.value),B(!1)},selectedModel:z,activeProviders:d,modelAliases:J,title:"Select Subagent Model for Codex"}),(0,a.jsx)(r.uR,{isOpen:G,onClose:()=>Y(!1),title:"Codex CLI - Manual Configuration",configs:(N=I&&I.trim()?I:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",w=z||D,[{filename:"~/.codex/config.toml",content:`# 9Router Configuration for Codex CLI
|
|
24
24
|
model = "${D}"
|
|
25
25
|
model_provider = "9router"
|
|
26
26
|
|
|
@@ -31,16 +31,16 @@ wire_api = "responses"
|
|
|
31
31
|
|
|
32
32
|
[agents.subagent]
|
|
33
33
|
model = "${w}"
|
|
34
|
-
`},{filename:"~/.codex/auth.json",content:JSON.stringify({auth_mode:"apikey",OPENAI_API_KEY:N},null,2)}])})]})}function b({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:j}){let v,N,w,k,[C,S]=(0,l.useState)(u||null),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(!1),[M,O]=(0,l.useState)(!1),[T,P]=(0,l.useState)(null),[R,I]=(0,l.useState)(""),[U,D]=(0,l.useState)([]),[K,z]=(0,l.useState)(""),[L,F]=(0,l.useState)(!1),[q,H]=(0,l.useState)({}),[B,J]=(0,l.useState)(!1),[G,W]=(0,l.useState)(!1),[Y,V]=(0,l.useState)(""),Z=(0,l.useRef)(!1),Q=(()=>{if(!C?.installed)return null;let e=C.settings?.customModels?.find(e=>e.id?.startsWith("custom:9Router"));return e?g(e.baseUrl,{tunnelPublicUrl:f,tailscaleUrl:j,cloudUrl:m?"https://9router.com":null})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!R&&I(d[0].key)},[d,R]),(0,l.useEffect)(()=>{u&&S(u)},[u]),(0,l.useEffect)(()=>{t&&!C&&(ee(),X()),t&&X()},[t]);let X=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&H(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(C?.installed&&!Z.current){Z.current=!0;let e=(C.settings?.customModels||[]).filter(e=>e.id?.startsWith("custom:9Router")).sort((e,t)=>(e.index||0)-(t.index||0)).map(e=>e.model);if(e.length>0)D(e);else{let e=C.settings?.customModels?.find(e=>"custom:9Router-0"===e.id);e?.model&&D([e.model])}}},[C]);let ee=async()=>{A(!0);try{let e=await fetch("/api/cli-tools/droid-settings"),t=await e.json();S(t)}catch(e){S({installed:!1,error:e.message})}finally{A(!1)}},et=()=>{let e=Y||i;return e.endsWith("/v1")?e:`${e}/v1`},es=()=>{let e=K.trim();!e||U.includes(e)||(D(t=>[...t,e]),z(""))},ea=async()=>{$(!0),P(null);try{let e=R?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch("/api/cli-tools/droid-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:et(),apiKey:e,models:U,activeModel:U[0]||""})}),s=await t.json();t.ok?(P({type:"success",text:"Settings applied successfully!"}),ee()):P({type:"error",text:s.error||"Failed to apply settings"})}catch(e){P({type:"error",text:e.message})}finally{$(!1)}},el=async()=>{O(!0),P(null);try{let e=await fetch("/api/cli-tools/droid-settings",{method:"DELETE"}),t=await e.json();e.ok?(P({type:"success",text:"Settings reset successfully!"}),D([]),ee()):P({type:"error",text:t.error||"Failed to reset settings"})}catch(e){P({type:"error",text:e.message})}finally{O(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/droid.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===Q&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===Q&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===Q&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[_&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Factory Droid CLI..."})]}),!_&&C&&!C.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Factory Droid CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>J(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>W(!G),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:G?"expand_less":"help"}),G?"Hide":"How to Install"]})]})]}),G&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),(0,a.jsx)("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"curl -fsSL https://app.factory.ai/cli | sh"})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:["After installation, run ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"droid"})," to verify."]})]})]})]}),!_&&C?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:Y||((v=Y||i).endsWith("/v1")?v:`${v}/v1`),onChange:V,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:j})]}),C?.settings?.customModels?.find(e=>e.id?.startsWith("custom:9Router"))?.baseUrl&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:C.settings.customModels.find(e=>e.id?.startsWith("custom:9Router")).baseUrl})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:R,onChange:I,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsxs)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:["Models ",U.length>0&&(0,a.jsxs)("span",{className:"text-primary",children:["(",U.length,")"]})]}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-1",children:[U.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-0.5 mb-1",children:U.map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-bg-secondary rounded border border-border",children:[(0,a.jsx)("span",{className:"flex-1 text-xs font-mono truncate",children:e}),(0,a.jsx)("button",{onClick:()=>D(t=>t.filter(t=>t!==e)),className:"text-text-muted hover:text-red-500 transition-colors shrink-0",title:"Remove",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e))}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)("input",{type:"text",value:K,onChange:e=>z(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),es())},placeholder:"provider/model-id",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),(0,a.jsx)("button",{onClick:()=>F(!0),disabled:!o,className:`px-2 py-1.5 rounded border text-xs shrink-0 ${o?"bg-surface border-border hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"}),(0,a.jsx)("button",{onClick:es,disabled:!K.trim(),className:"px-2 py-1.5 rounded border bg-surface border-border hover:border-primary text-xs shrink-0 disabled:opacity-50",title:"Add model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"add"})})]})]})]})]}),T&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===T.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===T.type?"check_circle":"error"}),(0,a.jsx)("span",{children:T.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:ea,disabled:0===U.length,loading:E,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:el,disabled:!C?.has9Router,loading:M,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>J(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:L,onClose:()=>F(!1),onSelect:e=>{!e.value||U.includes(e.value)||(D(t=>[...t,e.value]),F(!1))},selectedModel:null,activeProviders:c,modelAliases:q,title:"Select Model for Factory Droid"}),(0,a.jsx)(r.uR,{isOpen:B,onClose:()=>J(!1),title:"Factory Droid - Manual Configuration",configs:(N=R&&R.trim()?R:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",w={customModels:U.map((e,t)=>({model:e,id:`custom:9Router-${t}`,index:t,baseUrl:et(),apiKey:N,displayName:e,maxOutputTokens:131072,noImageSupport:!1,provider:"openai"}))},k="u">typeof navigator&&navigator.platform,[{filename:k?.toLowerCase().includes("win")?"%USERPROFILE%\\.factory\\settings.json":"~/.factory/settings.json",content:JSON.stringify(w,null,2)}])})]})}function j({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b}){let v,N,[w,k]=(0,l.useState)(u||null),[C,S]=(0,l.useState)(!1),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(!1),[M,O]=(0,l.useState)(null),[T,P]=(0,l.useState)(""),[R,I]=(0,l.useState)(""),[U,D]=(0,l.useState)({}),[K,z]=(0,l.useState)(null),[L,F]=(0,l.useState)(!1),[q,H]=(0,l.useState)({}),[B,J]=(0,l.useState)(!1),[G,W]=(0,l.useState)(""),Y=(0,l.useRef)(!1),V=(()=>{if(!w?.installed)return null;let e=w.settings?.models?.providers?.["9router"];return e?g(e.baseUrl,{tunnelPublicUrl:f,tailscaleUrl:b})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!T&&P(d[0].key)},[d,T]),(0,l.useEffect)(()=>{u&&k(u)},[u]),(0,l.useEffect)(()=>{t&&!w&&(Q(),Z()),t&&Z()},[t]);let Z=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&H(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(w?.installed&&!Y.current){Y.current=!0;let e=w.settings?.models?.providers?.["9router"];if(e){let t=w.settings?.agents?.defaults?.model?.primary;t&&I(t.replace("9router/","")),e.apiKey&&d?.some(t=>t.key===e.apiKey)&&P(e.apiKey)}let t=w.agents||[],s={};t.forEach(e=>{e.currentModel&&(s[e.id]=e.currentModel)}),D(s)}},[w,d]);let Q=async()=>{S(!0);try{let e=await fetch("/api/cli-tools/openclaw-settings"),t=await e.json();k(t)}catch(e){k({installed:!1,error:e.message})}finally{S(!1)}},X=()=>window.location.origin.replace("://localhost","://127.0.0.1"),ee=()=>{let e=G||X();return e.endsWith("/v1")?e:`${e}/v1`},et=async()=>{A(!0),O(null);try{let e=T?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch("/api/cli-tools/openclaw-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ee(),apiKey:e,model:R,agentModels:U})}),s=await t.json();t.ok?(O({type:"success",text:"Settings applied successfully!"}),Q()):O({type:"error",text:s.error||"Failed to apply settings"})}catch(e){O({type:"error",text:e.message})}finally{A(!1)}},es=async()=>{$(!0),O(null);try{let e=await fetch("/api/cli-tools/openclaw-settings",{method:"DELETE"}),t=await e.json();e.ok?(O({type:"success",text:"Settings reset successfully!"}),I(""),P(""),Q()):O({type:"error",text:t.error||"Failed to reset settings"})}catch(e){O({type:"error",text:e.message})}finally{$(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/openclaw.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===V&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===V&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===V&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[C&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Open Claw CLI..."})]}),!C&&w&&!w.installed&&(0,a.jsx)("div",{className:"flex flex-col gap-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Open Claw CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsx)("div",{className:"flex items-center gap-2 pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>J(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!C&&w?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:G||((v=G||X()).endsWith("/v1")?v:`${v}/v1`),onChange:W,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b})]}),w?.settings?.models?.providers?.["9router"]?.baseUrl&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:w.settings.models.providers["9router"].baseUrl})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:T,onChange:P,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:R,onChange:e=>I(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),R&&(0,a.jsx)("button",{onClick:()=>I(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>{z(null),F(!0)},disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]}),(w.agents||[]).filter(e=>e.agentDir).map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-4",children:[(0,a.jsxs)("span",{className:"w-32 shrink-0 text-xs text-primary text-right truncate",title:e.name||e.id,children:["Agent ",e.name||e.id]}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:U[e.id]||"",onChange:t=>D(s=>({...s,[e.id]:t.target.value})),placeholder:`default (${R||"provider/model-id"})`,className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),U[e.id]&&(0,a.jsx)("button",{onClick:()=>D(t=>({...t,[e.id]:""})),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>{z(e.id),F(!0)},disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]},e.id))]}),M&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===M.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===M.type?"check_circle":"error"}),(0,a.jsx)("span",{children:M.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:et,disabled:!R,loading:_,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:es,disabled:!w?.has9Router,loading:E,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>J(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:L,onClose:()=>F(!1),onSelect:e=>{K?(D(t=>({...t,[K]:e.value})),z(null)):I(e.value),F(!1)},selectedModel:R,activeProviders:c,modelAliases:q,title:"Select Model for Open Claw"}),(0,a.jsx)(r.uR,{isOpen:B,onClose:()=>J(!1),title:"Open Claw - Manual Configuration",configs:(N=T&&T.trim()?T:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.openclaw/openclaw.json",content:JSON.stringify({agents:{defaults:{model:{primary:`9router/${R||"provider/model-id"}`}}},models:{providers:{"9router":{baseUrl:ee(),apiKey:N,api:"openai-completions",models:[{id:R||"provider/model-id",name:(R||"provider/model-id").split("/").pop()}]}}}},null,2)}])})]})}let v="/api/cli-tools/hermes-settings";function N({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b}){let j,[w,k]=(0,l.useState)(u||null),[C,S]=(0,l.useState)(!1),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(!1),[M,O]=(0,l.useState)(null),[T,P]=(0,l.useState)(""),[R,I]=(0,l.useState)(""),[U,D]=(0,l.useState)(!1),[K,z]=(0,l.useState)({}),[L,F]=(0,l.useState)(!1),[q,H]=(0,l.useState)(""),B=(0,l.useRef)(!1),J=(()=>{if(!w?.installed)return null;let e=w.settings?.model;return e?.base_url?g(e.base_url,{tunnelPublicUrl:f,tailscaleUrl:b})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!T&&P(d[0].key)},[d,T]),(0,l.useEffect)(()=>{u&&k(u)},[u]),(0,l.useEffect)(()=>{t&&!w&&(W(),G()),t&&G()},[t]);let G=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&z(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(w?.installed&&!B.current){B.current=!0;let e=w.settings?.model;e?.default&&I(e.default)}},[w]);let W=async()=>{S(!0);try{let e=await fetch(v),t=await e.json();k(t)}catch(e){k({installed:!1,error:e.message})}finally{S(!1)}},Y=()=>{let e=q||window.location.origin.replace("://localhost","://127.0.0.1");return e.endsWith("/v1")?e:`${e}/v1`},V=async()=>{A(!0),O(null);try{let e=T?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch(v,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:Y(),apiKey:e,model:R})}),s=await t.json();t.ok?(O({type:"success",text:"Settings applied successfully!"}),W()):O({type:"error",text:s.error||"Failed to apply settings"})}catch(e){O({type:"error",text:e.message})}finally{A(!1)}},Z=async()=>{$(!0),O(null);try{let e=await fetch(v,{method:"DELETE"}),t=await e.json();e.ok?(O({type:"success",text:"Settings reset successfully!"}),I(""),W()):O({type:"error",text:t.error||"Failed to reset settings"})}catch(e){O({type:"error",text:e.message})}finally{$(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/hermes.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[C&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Hermes Agent..."})]}),!C&&w&&!w.installed&&(0,a.jsx)("div",{className:"flex flex-col gap-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Hermes Agent not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Install: curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash"})]})]}),(0,a.jsx)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 pl-0 sm:pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>F(!0),className:"w-full sm:w-auto !bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!C&&w?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:q||Y(),onChange:H,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b})]}),w?.settings?.model?.base_url&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:w.settings.model.base_url})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:T,onChange:P,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:R,onChange:e=>I(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),R&&(0,a.jsx)("button",{onClick:()=>I(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>D(!0),disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]})]}),M&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===M.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===M.type?"check_circle":"error"}),(0,a.jsx)("span",{children:M.text})]}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:V,disabled:!R,loading:_,className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:Z,disabled:!w?.has9Router,loading:E,className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>F(!0),className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:U,onClose:()=>D(!1),onSelect:e=>{I(e.value),D(!1)},selectedModel:R,activeProviders:c,modelAliases:K,title:"Select Model for Hermes Agent"}),(0,a.jsx)(r.uR,{isOpen:L,onClose:()=>F(!1),title:"Hermes Agent - Manual Configuration",configs:(j=T&&T.trim()?T:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.hermes/config.yaml",content:`model:
|
|
34
|
+
`},{filename:"~/.codex/auth.json",content:JSON.stringify({auth_mode:"apikey",OPENAI_API_KEY:N},null,2)}])})]})}function b({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:j}){let v,N,w,k,[C,S]=(0,l.useState)(u||null),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(!1),[M,O]=(0,l.useState)(!1),[T,P]=(0,l.useState)(null),[R,I]=(0,l.useState)(""),[U,D]=(0,l.useState)([]),[K,z]=(0,l.useState)(""),[L,F]=(0,l.useState)(!1),[q,H]=(0,l.useState)({}),[B,J]=(0,l.useState)(!1),[W,G]=(0,l.useState)(!1),[Y,V]=(0,l.useState)(""),Z=(0,l.useRef)(!1),Q=(()=>{if(!C?.installed)return null;let e=C.settings?.customModels?.find(e=>e.id?.startsWith("custom:9Router"));return e?g(e.baseUrl,{tunnelPublicUrl:f,tailscaleUrl:j,cloudUrl:m?"https://9router.com":null})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!R&&I(d[0].key)},[d,R]),(0,l.useEffect)(()=>{u&&S(u)},[u]),(0,l.useEffect)(()=>{t&&!C&&(ee(),X()),t&&X()},[t]);let X=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&H(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(C?.installed&&!Z.current){Z.current=!0;let e=(C.settings?.customModels||[]).filter(e=>e.id?.startsWith("custom:9Router")).sort((e,t)=>(e.index||0)-(t.index||0)).map(e=>e.model);if(e.length>0)D(e);else{let e=C.settings?.customModels?.find(e=>"custom:9Router-0"===e.id);e?.model&&D([e.model])}}},[C]);let ee=async()=>{A(!0);try{let e=await fetch("/api/cli-tools/droid-settings"),t=await e.json();S(t)}catch(e){S({installed:!1,error:e.message})}finally{A(!1)}},et=()=>{let e=Y||i;return e.endsWith("/v1")?e:`${e}/v1`},es=()=>{let e=K.trim();!e||U.includes(e)||(D(t=>[...t,e]),z(""))},ea=async()=>{$(!0),P(null);try{let e=R?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch("/api/cli-tools/droid-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:et(),apiKey:e,models:U,activeModel:U[0]||""})}),s=await t.json();t.ok?(P({type:"success",text:"Settings applied successfully!"}),ee()):P({type:"error",text:s.error||"Failed to apply settings"})}catch(e){P({type:"error",text:e.message})}finally{$(!1)}},el=async()=>{O(!0),P(null);try{let e=await fetch("/api/cli-tools/droid-settings",{method:"DELETE"}),t=await e.json();e.ok?(P({type:"success",text:"Settings reset successfully!"}),D([]),ee()):P({type:"error",text:t.error||"Failed to reset settings"})}catch(e){P({type:"error",text:e.message})}finally{O(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/droid.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===Q&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===Q&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===Q&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[_&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Factory Droid CLI..."})]}),!_&&C&&!C.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Factory Droid CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>J(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>G(!W),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:W?"expand_less":"help"}),W?"Hide":"How to Install"]})]})]}),W&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),(0,a.jsx)("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"curl -fsSL https://app.factory.ai/cli | sh"})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:["After installation, run ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"droid"})," to verify."]})]})]})]}),!_&&C?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:Y||((v=Y||i).endsWith("/v1")?v:`${v}/v1`),onChange:V,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:j})]}),C?.settings?.customModels?.find(e=>e.id?.startsWith("custom:9Router"))?.baseUrl&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:C.settings.customModels.find(e=>e.id?.startsWith("custom:9Router")).baseUrl})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:R,onChange:I,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsxs)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:["Models ",U.length>0&&(0,a.jsxs)("span",{className:"text-primary",children:["(",U.length,")"]})]}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-1",children:[U.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-0.5 mb-1",children:U.map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-bg-secondary rounded border border-border",children:[(0,a.jsx)("span",{className:"flex-1 text-xs font-mono truncate",children:e}),(0,a.jsx)("button",{onClick:()=>D(t=>t.filter(t=>t!==e)),className:"text-text-muted hover:text-red-500 transition-colors shrink-0",title:"Remove",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e))}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)("input",{type:"text",value:K,onChange:e=>z(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),es())},placeholder:"provider/model-id",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),(0,a.jsx)("button",{onClick:()=>F(!0),disabled:!o,className:`px-2 py-1.5 rounded border text-xs shrink-0 ${o?"bg-surface border-border hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"}),(0,a.jsx)("button",{onClick:es,disabled:!K.trim(),className:"px-2 py-1.5 rounded border bg-surface border-border hover:border-primary text-xs shrink-0 disabled:opacity-50",title:"Add model",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"add"})})]})]})]})]}),T&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===T.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===T.type?"check_circle":"error"}),(0,a.jsx)("span",{children:T.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:ea,disabled:0===U.length,loading:E,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:el,disabled:!C?.has9Router,loading:M,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>J(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:L,onClose:()=>F(!1),onSelect:e=>{!e.value||U.includes(e.value)||(D(t=>[...t,e.value]),F(!1))},selectedModel:null,activeProviders:c,modelAliases:q,title:"Select Model for Factory Droid"}),(0,a.jsx)(r.uR,{isOpen:B,onClose:()=>J(!1),title:"Factory Droid - Manual Configuration",configs:(N=R&&R.trim()?R:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",w={customModels:U.map((e,t)=>({model:e,id:`custom:9Router-${t}`,index:t,baseUrl:et(),apiKey:N,displayName:e,maxOutputTokens:131072,noImageSupport:!1,provider:"openai"}))},k="u">typeof navigator&&navigator.platform,[{filename:k?.toLowerCase().includes("win")?"%USERPROFILE%\\.factory\\settings.json":"~/.factory/settings.json",content:JSON.stringify(w,null,2)}])})]})}function j({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b}){let v,N,[w,k]=(0,l.useState)(u||null),[C,S]=(0,l.useState)(!1),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(!1),[M,O]=(0,l.useState)(null),[T,P]=(0,l.useState)(""),[R,I]=(0,l.useState)(""),[U,D]=(0,l.useState)({}),[K,z]=(0,l.useState)(null),[L,F]=(0,l.useState)(!1),[q,H]=(0,l.useState)({}),[B,J]=(0,l.useState)(!1),[W,G]=(0,l.useState)(""),Y=(0,l.useRef)(!1),V=(()=>{if(!w?.installed)return null;let e=w.settings?.models?.providers?.["9router"];return e?g(e.baseUrl,{tunnelPublicUrl:f,tailscaleUrl:b})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!T&&P(d[0].key)},[d,T]),(0,l.useEffect)(()=>{u&&k(u)},[u]),(0,l.useEffect)(()=>{t&&!w&&(Q(),Z()),t&&Z()},[t]);let Z=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&H(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(w?.installed&&!Y.current){Y.current=!0;let e=w.settings?.models?.providers?.["9router"];if(e){let t=w.settings?.agents?.defaults?.model?.primary;t&&I(t.replace("9router/","")),e.apiKey&&d?.some(t=>t.key===e.apiKey)&&P(e.apiKey)}let t=w.agents||[],s={};t.forEach(e=>{e.currentModel&&(s[e.id]=e.currentModel)}),D(s)}},[w,d]);let Q=async()=>{S(!0);try{let e=await fetch("/api/cli-tools/openclaw-settings"),t=await e.json();k(t)}catch(e){k({installed:!1,error:e.message})}finally{S(!1)}},X=()=>window.location.origin.replace("://localhost","://127.0.0.1"),ee=()=>{let e=W||X();return e.endsWith("/v1")?e:`${e}/v1`},et=async()=>{A(!0),O(null);try{let e=T?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch("/api/cli-tools/openclaw-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ee(),apiKey:e,model:R,agentModels:U})}),s=await t.json();t.ok?(O({type:"success",text:"Settings applied successfully!"}),Q()):O({type:"error",text:s.error||"Failed to apply settings"})}catch(e){O({type:"error",text:e.message})}finally{A(!1)}},es=async()=>{$(!0),O(null);try{let e=await fetch("/api/cli-tools/openclaw-settings",{method:"DELETE"}),t=await e.json();e.ok?(O({type:"success",text:"Settings reset successfully!"}),I(""),P(""),Q()):O({type:"error",text:t.error||"Failed to reset settings"})}catch(e){O({type:"error",text:e.message})}finally{$(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/openclaw.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===V&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===V&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===V&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[C&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Open Claw CLI..."})]}),!C&&w&&!w.installed&&(0,a.jsx)("div",{className:"flex flex-col gap-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Open Claw CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsx)("div",{className:"flex items-center gap-2 pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>J(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!C&&w?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:W||((v=W||X()).endsWith("/v1")?v:`${v}/v1`),onChange:G,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b})]}),w?.settings?.models?.providers?.["9router"]?.baseUrl&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:w.settings.models.providers["9router"].baseUrl})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:T,onChange:P,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:R,onChange:e=>I(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),R&&(0,a.jsx)("button",{onClick:()=>I(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>{z(null),F(!0)},disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]}),(w.agents||[]).filter(e=>e.agentDir).map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-4",children:[(0,a.jsxs)("span",{className:"w-32 shrink-0 text-xs text-primary text-right truncate",title:e.name||e.id,children:["Agent ",e.name||e.id]}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:U[e.id]||"",onChange:t=>D(s=>({...s,[e.id]:t.target.value})),placeholder:`default (${R||"provider/model-id"})`,className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),U[e.id]&&(0,a.jsx)("button",{onClick:()=>D(t=>({...t,[e.id]:""})),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>{z(e.id),F(!0)},disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]},e.id))]}),M&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===M.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===M.type?"check_circle":"error"}),(0,a.jsx)("span",{children:M.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:et,disabled:!R,loading:_,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:es,disabled:!w?.has9Router,loading:E,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>J(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:L,onClose:()=>F(!1),onSelect:e=>{K?(D(t=>({...t,[K]:e.value})),z(null)):I(e.value),F(!1)},selectedModel:R,activeProviders:c,modelAliases:q,title:"Select Model for Open Claw"}),(0,a.jsx)(r.uR,{isOpen:B,onClose:()=>J(!1),title:"Open Claw - Manual Configuration",configs:(N=T&&T.trim()?T:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.openclaw/openclaw.json",content:JSON.stringify({agents:{defaults:{model:{primary:`9router/${R||"provider/model-id"}`}}},models:{providers:{"9router":{baseUrl:ee(),apiKey:N,api:"openai-completions",models:[{id:R||"provider/model-id",name:(R||"provider/model-id").split("/").pop()}]}}}},null,2)}])})]})}let v="/api/cli-tools/hermes-settings";function N({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b}){let j,[w,k]=(0,l.useState)(u||null),[C,S]=(0,l.useState)(!1),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(!1),[M,O]=(0,l.useState)(null),[T,P]=(0,l.useState)(""),[R,I]=(0,l.useState)(""),[U,D]=(0,l.useState)(!1),[K,z]=(0,l.useState)({}),[L,F]=(0,l.useState)(!1),[q,H]=(0,l.useState)(""),B=(0,l.useRef)(!1),J=(()=>{if(!w?.installed)return null;let e=w.settings?.model;return e?.base_url?g(e.base_url,{tunnelPublicUrl:f,tailscaleUrl:b})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!T&&P(d[0].key)},[d,T]),(0,l.useEffect)(()=>{u&&k(u)},[u]),(0,l.useEffect)(()=>{t&&!w&&(G(),W()),t&&W()},[t]);let W=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&z(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(w?.installed&&!B.current){B.current=!0;let e=w.settings?.model;e?.default&&I(e.default)}},[w]);let G=async()=>{S(!0);try{let e=await fetch(v),t=await e.json();k(t)}catch(e){k({installed:!1,error:e.message})}finally{S(!1)}},Y=()=>{let e=q||window.location.origin.replace("://localhost","://127.0.0.1");return e.endsWith("/v1")?e:`${e}/v1`},V=async()=>{A(!0),O(null);try{let e=T?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch(v,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:Y(),apiKey:e,model:R})}),s=await t.json();t.ok?(O({type:"success",text:"Settings applied successfully!"}),G()):O({type:"error",text:s.error||"Failed to apply settings"})}catch(e){O({type:"error",text:e.message})}finally{A(!1)}},Z=async()=>{$(!0),O(null);try{let e=await fetch(v,{method:"DELETE"}),t=await e.json();e.ok?(O({type:"success",text:"Settings reset successfully!"}),I(""),G()):O({type:"error",text:t.error||"Failed to reset settings"})}catch(e){O({type:"error",text:e.message})}finally{$(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/hermes.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[C&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Hermes Agent..."})]}),!C&&w&&!w.installed&&(0,a.jsx)("div",{className:"flex flex-col gap-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Hermes Agent not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Install: curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash"})]})]}),(0,a.jsx)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 pl-0 sm:pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>F(!0),className:"w-full sm:w-auto !bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!C&&w?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:q||Y(),onChange:H,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b})]}),w?.settings?.model?.base_url&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:w.settings.model.base_url})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:T,onChange:P,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:R,onChange:e=>I(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),R&&(0,a.jsx)("button",{onClick:()=>I(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>D(!0),disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]})]}),M&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===M.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===M.type?"check_circle":"error"}),(0,a.jsx)("span",{children:M.text})]}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:V,disabled:!R,loading:_,className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:Z,disabled:!w?.has9Router,loading:E,className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>F(!0),className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:U,onClose:()=>D(!1),onSelect:e=>{I(e.value),D(!1)},selectedModel:R,activeProviders:c,modelAliases:K,title:"Select Model for Hermes Agent"}),(0,a.jsx)(r.uR,{isOpen:L,onClose:()=>F(!1),title:"Hermes Agent - Manual Configuration",configs:(j=T&&T.trim()?T:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.hermes/config.yaml",content:`model:
|
|
35
35
|
default: "${R||"provider/model-id"}"
|
|
36
36
|
provider: "custom"
|
|
37
37
|
base_url: "${Y()}"
|
|
38
38
|
`},{filename:"~/.hermes/.env",content:`OPENAI_API_KEY=${j}
|
|
39
|
-
`}])})]})}var w=s(11059);function k({toolId:e,tool:t,isExpanded:s,onToggle:i,baseUrl:o,apiKeys:d,activeProviders:c=[],cloudEnabled:m=!1,tunnelEnabled:x=!1}){let[u,h]=(0,l.useState)(null),[g,f]=(0,l.useState)(!1),[y,b]=(0,l.useState)(""),[j,v]=(0,l.useState)(()=>d?.length>0?d[0].key:""),N=e=>{let t=j&&j.trim()?j:m?"your-api-key":"sk_9router",s=o||"http://localhost:20128",a=s.endsWith("/v1")?s:`${s}/v1`;return e.replace(/\{\{baseUrl\}\}/g,a).replace(/\{\{apiKey\}\}/g,t).replace(/\{\{model\}\}/g,y||"provider/model-id")},{copy:C}=(0,w.C)(),S=async(e,t)=>{await C(N(e),`toolcard-${t}`),h(t),setTimeout(()=>h(null),2e3)},_=c.length>0,A=()=>(!t.requiresExternalUrl||!!m||!!x)&&(!t.requiresCloud||!!m);return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden overflow-x-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between hover:cursor-pointer",onClick:i,children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 rounded-lg flex items-center justify-center shrink-0",children:t.image?(0,a.jsx)(n.default,{src:t.image,alt:t.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}}):t.icon?(0,a.jsx)("span",{className:"material-symbols-outlined text-xl",style:{color:t.color},children:t.icon}):(0,a.jsx)(n.default,{src:`/providers/${e}.png`,alt:t.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:t.name}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:t.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${s?"rotate-180":""}`,children:"expand_more"})]}),s&&(0,a.jsx)("div",{className:"mt-6 pt-6 border-t border-border",children:t.guideSteps?(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[t.notes&&0!==t.notes.length?(0,a.jsx)("div",{className:"flex flex-col gap-2 mb-4",children:t.notes.map((e,t)=>{if("cloudCheck"===e.type&&(m||x))return null;let s="warning"===e.type,l="cloudCheck"===e.type&&!m&&!x,r="bg-blue-500/10 border-blue-500/30",n="text-blue-600 dark:text-blue-400",i="text-blue-500",o="info";return s?(r="bg-yellow-500/10 border-yellow-500/30",n="text-yellow-600 dark:text-yellow-400",i="text-yellow-500",o="warning"):l&&(r="bg-red-500/10 border-red-500/30",n="text-red-600 dark:text-red-400",i="text-red-500",o="error"),(0,a.jsxs)("div",{className:`flex items-start gap-3 p-3 rounded-lg border ${r}`,children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-lg ${i}`,children:o}),(0,a.jsx)("p",{className:`text-sm ${n}`,children:e.text})]},t)})}):null,A()&&t.guideSteps.map(e=>(0,a.jsxs)("div",{className:"flex items-start gap-4",children:[(0,a.jsx)("div",{className:"size-8 rounded-full flex items-center justify-center shrink-0 text-sm font-semibold text-white",style:{backgroundColor:t.color},children:e.step}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"font-medium text-text",children:e.title}),e.desc&&(0,a.jsx)("p",{className:"text-sm text-text-muted mt-0.5",children:e.desc}),"apiKeySelector"===e.type&&(0,a.jsx)("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:(0,a.jsx)(p,{value:j,onChange:v,apiKeys:d,cloudEnabled:m,className:"flex-1"})}),"modelSelector"===e.type&&(0,a.jsxs)("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,a.jsx)("input",{type:"text",value:y,onChange:e=>b(e.target.value),placeholder:"provider/model-id",className:"w-full sm:w-auto flex-1 px-3 py-2 bg-bg-secondary rounded-lg text-sm border border-border focus:outline-none focus:ring-1 focus:ring-primary/50"}),(0,a.jsx)("button",{onClick:()=>f(!0),disabled:!_,className:`shrink-0 px-3 py-2 rounded-lg border text-sm transition-colors ${_?"bg-bg-secondary border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"}),y&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{onClick:()=>S(y,"model"),className:"shrink-0 px-3 py-2 bg-bg-secondary hover:bg-bg-tertiary rounded-lg border border-border transition-colors",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-lg",children:"model"===u?"check":"content_copy"})}),(0,a.jsx)("button",{onClick:()=>b(""),className:"p-2 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-lg",children:"close"})})]})]}),e.value&&(0,a.jsxs)("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,a.jsx)("code",{className:"w-full sm:w-auto flex-1 px-3 py-2 bg-bg-secondary rounded-lg text-sm font-mono border border-border truncate",children:N(e.value)}),e.copyable&&(0,a.jsx)("button",{onClick:()=>S(e.value,`${e.step}-${e.title}`),className:"shrink-0 px-3 py-2 bg-bg-secondary hover:bg-bg-tertiary rounded-lg border border-border transition-colors",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-lg",children:u===`${e.step}-${e.title}`?"check":"content_copy"})})]})]})]},e.step)),A()&&t.codeBlock&&(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:t.codeBlock.language}),(0,a.jsxs)("button",{onClick:()=>S(t.codeBlock.code,"codeblock"),className:"flex items-center gap-1 px-2 py-1 text-xs bg-bg-secondary hover:bg-bg-tertiary rounded border border-border transition-colors",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"codeblock"===u?"check":"content_copy"}),"codeblock"===u?"Copied!":"Copy"]})]}),(0,a.jsx)("pre",{className:"p-4 bg-bg-secondary rounded-lg border border-border overflow-x-auto",children:(0,a.jsx)("code",{className:"text-sm font-mono whitespace-pre",children:N(t.codeBlock.code)})})]})]}):(0,a.jsx)("p",{className:"text-text-muted text-sm",children:"Coming soon..."})}),(0,a.jsx)(r.rq,{isOpen:g,onClose:()=>f(!1),onSelect:e=>{b(e.value)},selectedModel:y,activeProviders:c,title:"Select Model"})]})}let C="round-robin",S=[{value:"round-robin",label:"Round-Robin"},{value:"fallback",label:"Fallback"}];function _({tool:e,mappings:t,strategy:s=C,dnsActive:l=!0,hasActiveProviders:n,onChangeEntry:i,onBlurEntry:o,onOpenSelector:d,onAddEntry:c,onRemoveEntry:m,onReorderEntry:x,onChangeStrategy:u,feedback:p,compact:h=!1}){let g=h?"w-32 shrink-0 text-sm font-semibold text-text-main text-right":"w-36 shrink-0 text-xs font-semibold text-text-main text-right",f=h?"px-2 py-1.5 rounded border text-xs transition-colors shrink-0 whitespace-nowrap":"px-2 py-1.5 rounded border text-xs transition-colors shrink-0",y="h-8 min-w-8 inline-flex items-center justify-center rounded-md border border-border text-text-muted transition-colors",b=h?"h-8 px-2.5 inline-flex items-center justify-center rounded-md border border-border text-[11px] font-medium text-text-main transition-colors shrink-0 whitespace-nowrap":"h-8 px-2.5 inline-flex items-center justify-center rounded-md border border-border text-[11px] font-medium text-text-main transition-colors shrink-0",j=!l;return(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsx)("div",{className:"rounded-xl border border-border/70 bg-surface/60 p-3",children:(0,a.jsxs)("div",{className:"flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs font-semibold text-text-main",children:"Routing strategy"}),(0,a.jsx)("p",{className:"text-[11px] text-text-muted",children:"Round-robin spreads load. Fallback keeps priority order."}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted mt-1",children:"Tip: paste comma-separated models into one row to expand multiple targets at once."})]}),(0,a.jsx)("div",{className:"sm:w-44",children:(0,a.jsx)(r.l6,{value:s,onChange:e=>u(e.target.value),disabled:j,options:S,selectClassName:"py-1.5 px-2 pr-8 text-xs bg-surface border-border","aria-label":`${e.name} MITM strategy`})})]})}),p&&(0,a.jsx)("div",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-[11px] text-text-muted",children:p}),(0,a.jsx)("div",{className:"flex flex-col gap-2",children:e.defaultModels?.map(e=>{let s=Array.isArray(t?.[e.alias])?t[e.alias]:[],r=l&&s.length<5;return(0,a.jsx)("div",{className:"rounded-xl border border-border/70 bg-surface/40 p-3",children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("div",{className:g,children:(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("span",{children:e.name}),(0,a.jsxs)("span",{className:"text-[10px] font-normal text-text-muted",children:["Max ",5," targets"]})]})}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[s.length>0?s.map((t,l)=>{let r=j||0===l,c=j||l===s.length-1;return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"w-6 text-center text-[11px] font-semibold text-text-muted",children:l+1}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),(0,a.jsx)("input",{type:"text",value:t,onChange:t=>i(e.alias,l,t.target.value),onBlur:t=>o(e.alias,l,t.target.value),placeholder:"provider/model-id",disabled:j,className:`flex-1 px-2 py-1.5 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 ${j?"opacity-50 cursor-not-allowed":""}`}),(0,a.jsx)("button",{type:"button",onClick:()=>d(e.alias,l),disabled:!n||j,className:`${b} ${n&&!j?"hover:border-primary hover:text-primary cursor-pointer":"opacity-40 cursor-not-allowed"}`,title:"Select model",children:"Select"}),(0,a.jsx)("button",{type:"button",onClick:()=>x(e.alias,l,l-1),disabled:r,className:`${y} ${r?"opacity-40 cursor-not-allowed":"hover:border-primary hover:text-primary cursor-pointer"}`,title:"Move up",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"keyboard_arrow_up"})}),(0,a.jsx)("button",{type:"button",onClick:()=>x(e.alias,l,l+1),disabled:c,className:`${y} ${c?"opacity-40 cursor-not-allowed":"hover:border-primary hover:text-primary cursor-pointer"}`,title:"Move down",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"keyboard_arrow_down"})}),(0,a.jsx)("button",{type:"button",onClick:()=>m(e.alias,l),disabled:j,className:`${y} ${j?"opacity-40 cursor-not-allowed":"hover:border-red-500 hover:text-red-500 cursor-pointer"}`,title:"Remove",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},`${e.alias}-${l}`)}):(0,a.jsx)("div",{className:"rounded-lg border border-dashed border-border px-3 py-2 text-[11px] text-text-muted",children:"No mapping — passthrough"}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2 pl-8",children:[(0,a.jsx)("button",{type:"button",onClick:()=>c(e.alias),disabled:!r,className:`${f} ${r?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"+ Add"}),(0,a.jsxs)("span",{className:"text-[10px] text-text-muted",children:[s.length,"/",5," mapped"]})]})]})]})},e.alias)})})]})}function A(e){return Array.isArray(e)?e.map(e=>"string"==typeof e?e.trim():"").filter(Boolean).slice(0,5):"string"==typeof e&&e.trim()?[e.trim()]:[]}function E(e){return Object.fromEntries(Object.entries(e||{}).map(([e,t])=>[e,A(t)]).filter(([,e])=>e.length>0))}function $(e,t,s){let a="string"==typeof s?s.trim():"";if(!t||!a)return e;let l=A(e?.[t]);return l.length>=5?e:{...e,[t]:[...l,a]}}function M(e,t,s,a){let l=Array.isArray(e?.[t])?[...e[t]]:[];return s<0||s>=l.length?e:(l[s]=a,{...e,[t]:l})}function O(e){return"fallback"===(e||C)?"fallback":C}function T({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:y}){let b,j,v,N,w,[k,C]=(0,l.useState)(m||null),[S,_]=(0,l.useState)(!1),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(!1),[O,P]=(0,l.useState)(null),[R,I]=(0,l.useState)(!1),[U,D]=(0,l.useState)(""),[K,z]=(0,l.useState)(""),[L,F]=(0,l.useState)(""),[q,H]=(0,l.useState)(!1),[B,J]=(0,l.useState)(!1),[G,W]=(0,l.useState)({}),[Y,V]=(0,l.useState)(!1),[Z,Q]=(0,l.useState)(""),[X,ee]=(0,l.useState)([]),[et,es]=(0,l.useState)(""),ea=(0,l.useRef)([]);(0,l.useEffect)(()=>{ea.current=X},[X]),(0,l.useEffect)(()=>{o?.length>0&&!U&&D(o[0].key)},[o,U]),(0,l.useEffect)(()=>{m&&C(m)},[m]),(0,l.useEffect)(()=>{t&&!k&&(eo(),el()),t&&el()},[t]),(0,l.useEffect)(()=>{k?.opencode?.models&&ee(k.opencode.models),k?.opencode?.activeModel&&es(k.opencode.activeModel),k?.config?.agent?.explorer?.model?.startsWith("9router/")&&F(k.config.agent.explorer.model.replace("9router/",""))},[k]);let el=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&W(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}},er=async e=>{try{let t=U&&U.trim()||c?U:"sk_9router",s=e.includes(et)?et:e[0]||"";await fetch("/api/cli-tools/opencode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ei(),apiKey:t,models:e,activeModel:s,subagentModel:L})})}catch(e){console.log("Error saving models:",e)}},en=k?.installed?k.config&&k.has9Router?g(k.config?.provider?.["9router"]?.options?.baseURL||"",{tunnelPublicUrl:h,tailscaleUrl:y})?"configured":"other":"not_configured":null,ei=()=>{let e=Z||i;return e.endsWith("/v1")?e:`${e}/v1`},eo=async()=>{_(!0);try{let e=await fetch("/api/cli-tools/opencode-settings"),t=await e.json();C(t)}catch(e){C({installed:!1,error:e.message})}finally{_(!1)}},ed=async()=>{E(!0),P(null);try{let e=U&&U.trim()||c?U:"sk_9router",t=await fetch("/api/cli-tools/opencode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ei(),apiKey:e,models:X,activeModel:""===et?"":et||X[0],subagentModel:L})}),s=await t.json();t.ok?(P({type:"success",text:"Settings applied successfully!"}),eo()):P({type:"error",text:s.error||"Failed to apply settings"})}catch(e){P({type:"error",text:e.message})}finally{E(!1)}},ec=async()=>{M(!0),P(null);try{let e=await fetch("/api/cli-tools/opencode-settings",{method:"DELETE"}),t=await e.json();e.ok?(P({type:"success",text:"Settings reset successfully!"}),z(""),F(""),ee([]),es(""),eo()):P({type:"error",text:t.error||"Failed to reset settings"})}catch(e){P({type:"error",text:e.message})}finally{M(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/opencode.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===en&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===en&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===en&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[S&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking OpenCode CLI..."})]}),!S&&k&&!k.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"OpenCode CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>V(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>I(!R),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:R?"expand_less":"help"}),R?"Hide":"How to Install"]})]})]}),R&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-text-muted mb-1",children:"macOS / Linux:"}),(0,a.jsx)("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g opencode-ai"})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:["After installation, run ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"opencode"})," to verify."]})]})]})]}),!S&&k?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:Z||Z||`${i}/v1`,onChange:Q,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:y})]}),k?.config?.provider?.["9router"]?.options?.baseURL&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:k.config.provider["9router"].options.baseURL})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:U,onChange:D,apiKeys:o,cloudEnabled:c})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Models"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:0===X.length?(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"No models selected"}):X.map(e=>(0,a.jsxs)("span",{onClick:async()=>{if(e===et)try{(await fetch("/api/cli-tools/opencode-settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({clearActiveModel:!0})})).ok&&(es(""),eo())}catch(e){console.log("Error clearing active model:",e)}else es(e)},className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs cursor-pointer transition-colors ${e===et?"bg-primary/10 text-primary border border-primary":"bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border"}`,title:e===et?"Click to clear active model":"Click to set as active",children:[e===et&&(0,a.jsx)("span",{className:"material-symbols-outlined text-[10px]",children:"star"}),e,(0,a.jsx)("button",{onClick:async t=>{t.stopPropagation();try{if((await fetch(`/api/cli-tools/opencode-settings?model=${encodeURIComponent(e)}`,{method:"DELETE"})).ok){let t=X.filter(t=>t!==e);ee(t),et===e&&es(""),eo()}}catch(e){console.log("Error removing model:",e)}},className:"ml-0.5 hover:text-red-500",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e))}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("button",{onClick:()=>H(!0),disabled:!d?.length,className:`px-2 py-1 rounded border text-xs transition-colors ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Add Model"}),(0,a.jsx)("span",{className:"text-xs text-text-muted",children:X.length>0&&et?(0,a.jsxs)(a.Fragment,{children:["Active: ",(0,a.jsx)("span",{className:"text-primary",children:et})]}):X.length>0?(0,a.jsx)("span",{className:"text-yellow-500",children:"Click a model to set/clear active"}):"Select models to add"})]})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Subagent Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("input",{type:"text",value:L,onChange:e=>F(e.target.value),placeholder:K||"provider/model-id (defaults to main model)",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),(0,a.jsx)("button",{onClick:()=>J(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"}),L&&(0,a.jsx)("button",{onClick:()=>F(""),className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear (will use main model)",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})]}),O&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===O.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===O.type?"check_circle":"error"}),(0,a.jsx)("span",{children:O.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:ed,disabled:0===X.length,loading:A,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:ec,disabled:!k.has9Router,loading:$,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>V(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:q,onClose:()=>{H(!1),er(ea.current)},onSelect:e=>{!X.includes(e.value)&&(ee([...X,e.value]),et||es(e.value))},onDeselect:e=>{let t=X.filter(t=>t!==e.value);ee(t),et===e.value&&es(t[0]||"")},selectedModel:null,activeProviders:d,modelAliases:G,addedModelValues:X,closeOnSelect:!1,title:"Add Model for OpenCode"}),(0,a.jsx)(r.rq,{isOpen:B,onClose:()=>J(!1),onSelect:e=>{F(e.value),J(!1)},selectedModel:L,activeProviders:d,modelAliases:G,title:"Select Subagent Model for OpenCode"}),(0,a.jsx)(r.uR,{isOpen:Y,onClose:()=>V(!1),title:"OpenCode - Manual Configuration",configs:(b=U&&U.trim()?U:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",j=X.length>0?X:["provider/model-id"],v=et||X[0]||j[0],N=L||v,w={},j.forEach(e=>{w[e]={name:e,modalities:{input:["text","image"],output:["text"]}}}),[{filename:"~/.config/opencode/opencode.json",content:JSON.stringify({provider:{"9router":{npm:"@ai-sdk/openai-compatible",options:{baseURL:ei(),apiKey:b},models:w}},model:`9router/${v}`,agent:{explorer:{description:"Fast explorer subagent for codebase exploration",mode:"subagent",model:`9router/${N}`}}},null,2)}])})]})}let P="/api/cli-tools/cowork-settings",R=e=>(e||"").replace(/\/v1\/?$/,"");function I({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,hasActiveProviders:c,cloudEnabled:m,cloudUrl:u,tunnelEnabled:h,tunnelPublicUrl:g,tailscaleEnabled:f,tailscaleUrl:y,initialStatus:b}){let j,v,N,w,[k,C]=(0,l.useState)(b||null),[S,_]=(0,l.useState)(!1),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(!1),[O,T]=(0,l.useState)(null),[U,D]=(0,l.useState)(""),[K,z]=(0,l.useState)([]),[L,F]=(0,l.useState)(!1),[q,H]=(0,l.useState)(""),[B,J]=(0,l.useState)([]),[G,W]=(0,l.useState)([]),[Y,V]=(0,l.useState)([]),[Z,Q]=(0,l.useState)({}),[X,ee]=(0,l.useState)(!1),[et,es]=(0,l.useState)(!1),[ea,el]=(0,l.useState)(!1),[er,en]=(0,l.useState)(!1),[ei,eo]=(0,l.useState)({type:"url",name:"",url:"",command:"",args:""});(0,l.useEffect)(()=>{o?.length>0&&!U&&D(o[0].key)},[o,U]),(0,l.useEffect)(()=>{b&&C(b)},[b]),(0,l.useEffect)(()=>{t&&!k&&ed()},[t]),(0,l.useEffect)(()=>{t&&fetch("/api/models/alias").then(e=>e.ok?e.json():null).then(e=>{e&&Q(e.aliases||{})}).catch(()=>{})},[t]),(0,l.useEffect)(()=>{k?.cowork?.models?.length&&z(k.cowork.models),k?.cowork?.baseUrl&&!q&&H(R(k.cowork.baseUrl)),Array.isArray(k?.cowork?.plugins)&&k.cowork.plugins.length>0?J(k.cowork.plugins):0===B.length&&Array.isArray(k?.defaultPlugins)&&J(k.defaultPlugins),Array.isArray(k?.cowork?.localPlugins)&&W(k.cowork.localPlugins),Array.isArray(k?.cowork?.customPlugins)&&k.cowork.customPlugins.length>0&&V(k.cowork.customPlugins)},[k]);let ed=async()=>{_(!0);try{let e=await fetch(P),t=await e.json();C(t)}catch(e){C({installed:!1,error:e.message})}finally{_(!1)}},ec=()=>{let e;return(e=(q||"").replace(/\/+$/,""))?/\/v1$/.test(e)?e:`${e}/v1`:""},em=k?.installed?k?.cowork?.baseUrl?k.has9Router?"configured":"other":"not_configured":null,ex=async()=>{T(null);let e=ec();if(0===K.length)return void T({type:"error",text:"Please select at least one model"});E(!0);try{let t=U?.trim()||(o?.length>0?o[0].key:null)||(m?null:"sk_9router"),s=await fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:e,apiKey:t,models:K,plugins:B,localPlugins:G,customPlugins:Y})}),a=await s.json();s.ok?(T({type:"success",text:"Settings applied. Quit & reopen Claude Desktop to load."}),ed()):T({type:"error",text:a.error||"Failed to apply settings"})}catch(e){T({type:"error",text:e.message})}finally{E(!1)}},eu=async({name:e,models:t})=>{try{let s=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,models:t})});if(!s.ok){let e=await s.json();T({type:"error",text:e.error||"Failed to create combo"});return}K.includes(e)||z([...K,e]),ee(!1),T({type:"success",text:`Combo "${e}" created and added.`})}catch(e){T({type:"error",text:e.message})}},ep=e=>{let t=e?.value||e?.name||e;z(e=>e.filter(e=>e!==t))},eh=async()=>{M(!0),T(null);try{let e=await fetch(P,{method:"DELETE"}),t=await e.json();e.ok?(T({type:"success",text:"Settings reset successfully"}),z([]),J(k?.defaultPlugins||[]),W([]),V([]),ed()):T({type:"error",text:t.error||"Failed to reset"})}catch(e){T({type:"error",text:e.message})}finally{M(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image,alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===em&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===em&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===em&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[S&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Claude Cowork..."})]}),!S&&k&&!k.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Claude Desktop (Cowork mode) not detected"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Open Claude Desktop → Help → Troubleshooting → Enable Developer mode → Configure third-party inference, then return here."})]})]}),(0,a.jsx)("div",{className:"pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>F(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]}),!S&&k?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:ec(),onChange:e=>H(R(e)),tunnelEnabled:h,tunnelPublicUrl:g,tailscaleEnabled:f,tailscaleUrl:y,cloudEnabled:m,cloudUrl:u})]}),k?.cowork?.baseUrl&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:k.cowork.baseUrl})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:U,onChange:D,apiKeys:o,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right",children:"Models"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex items-center gap-2",children:[(0,a.jsx)("div",{className:"flex-1 flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:0===K.length?(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"No models selected"}):K.map(e=>(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border",children:[e,(0,a.jsx)("button",{onClick:()=>ep(e),className:"ml-0.5 hover:text-red-500",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e))}),(0,a.jsx)("button",{onClick:()=>ee(!0),disabled:!c,className:`shrink-0 px-2 py-1.5 rounded border text-xs whitespace-nowrap transition-colors ${c?"bg-primary/10 border-primary/40 text-primary hover:bg-primary/20 cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"+ Combo"})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-2",children:"MCP"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-2",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-1",children:[B.filter(e=>"exa"!==e.name).map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1 bg-surface rounded border border-border",children:[(0,a.jsx)("span",{className:"text-xs font-medium min-w-0 truncate flex-shrink-0",children:e.title||e.name}),e.oauth&&(0,a.jsx)("span",{className:"text-[8px] text-amber-600 shrink-0",children:"OAuth"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-wrap gap-1 overflow-hidden",style:{maxHeight:"1.5rem"},children:[Array.isArray(e.toolNames)&&e.toolNames.slice(0,6).map(e=>(0,a.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-black/5 dark:bg-white/5 text-text-muted whitespace-nowrap",children:e},e)),Array.isArray(e.toolNames)&&e.toolNames.length>6&&(0,a.jsxs)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-black/5 dark:bg-white/5 text-text-muted whitespace-nowrap",children:["+",e.toolNames.length-6]})]}),(0,a.jsx)("button",{onClick:()=>{var t;return t=e.name,void J(B.filter(e=>e.name!==t))},className:"shrink-0 hover:text-red-500 ml-auto",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e.name)),Y.map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1 bg-surface rounded border border-border",children:[(0,a.jsx)("span",{className:"text-xs font-medium min-w-0 truncate flex-shrink-0",children:e.name}),(0,a.jsx)("span",{className:"text-[8px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-500 shrink-0",children:"custom"}),(0,a.jsx)("span",{className:"flex-1 text-[9px] text-text-muted truncate",children:e.url||e.command}),(0,a.jsx)("button",{onClick:()=>V(Y.filter(t=>t.name!==e.name)),className:"shrink-0 hover:text-red-500 ml-auto",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e.name)),0===B.filter(e=>"exa"!==e.name).length&&0===Y.length&&(0,a.jsx)("div",{className:"px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-muted",children:"No MCPs added"}),(0,a.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[(0,a.jsx)("button",{onClick:()=>el(!0),className:"px-2 py-1 rounded border text-xs bg-primary/10 border-primary/40 text-primary hover:bg-primary/20 cursor-pointer whitespace-nowrap",children:"+ Browse"}),(0,a.jsx)("button",{onClick:()=>{eo({type:"url",name:"",url:"",command:"",args:""}),en(!0)},className:"px-2 py-1 rounded border text-xs bg-surface border-border text-text-muted hover:border-primary hover:text-primary cursor-pointer whitespace-nowrap",children:"+ Custom"}),(0,a.jsx)("a",{href:"https://mcp.so",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-text-muted hover:text-primary underline ml-auto",children:"Find MCPs →"})]})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Tools"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-1.5",children:[(j=B.some(e=>"exa"===e.name),v=(k?.defaultPlugins||[]).find(e=>"exa"===e.name),(0,a.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer px-2 py-1.5 bg-surface rounded border border-border",children:[(0,a.jsx)("input",{type:"checkbox",checked:j,onChange:e=>{e.target.checked&&v?J([...B.filter(e=>"exa"!==e.name),v]):J(B.filter(e=>"exa"!==e.name))},className:"mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-xs font-medium",children:"Web Search & Fetch (Exa)"}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted leading-snug",children:"Replaces built-in WebSearch/WebFetch. Auto-strips duplicates from tool list."})]})]})),(()=>{let e=(k?.localStdioPlugins||[]).find(e=>"browsermcp"===e.name);if(!e)return null;let t=G.includes("browsermcp");return(0,a.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer px-2 py-1.5 bg-surface rounded border border-border",children:[(0,a.jsx)("input",{type:"checkbox",checked:t,onChange:e=>W(e.target.checked?[...G,"browsermcp"]:G.filter(e=>"browsermcp"!==e)),className:"mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-xs font-medium",children:"Browser Control (Browser MCP)"}),(0,a.jsxs)("p",{className:"text-[10px] text-text-muted leading-snug",children:["Controls your running Chrome. Auto-strips Cowork's built-in browser tools."," ",(0,a.jsx)("a",{href:e.extensionUrl,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"Install Chrome extension"})]})]})]})})()]})]}),Array.isArray(k?.localStdioPlugins)&&k.localStdioPlugins.filter(e=>"browsermcp"!==e.name).length>0&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Local Plugins"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,a.jsx)("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 bg-surface rounded border border-border",children:k.localStdioPlugins.filter(e=>"browsermcp"!==e.name).map(e=>{let t=G.includes(e.name);return(0,a.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer",children:[(0,a.jsx)("input",{type:"checkbox",checked:t,onChange:t=>W(t.target.checked?[...G,e.name]:G.filter(t=>t!==e.name)),className:"mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[(0,a.jsx)("span",{className:"text-xs font-medium",children:e.title}),(0,a.jsx)("span",{className:"text-[8px] text-amber-600",children:"stdio"})]}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted leading-snug",children:e.description}),e.extensionUrl&&(0,a.jsx)("a",{href:e.extensionUrl,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-primary underline",children:"Install Chrome extension"})]})]},e.name)})}),(0,a.jsxs)("p",{className:"text-[10px] text-text-muted leading-snug",children:["⚠️ Local plugins run as subprocess via ",(0,a.jsx)("code",{className:"px-1 py-0.5 rounded bg-black/5 dark:bg-white/5",children:"npx"}),". Requires Node.js installed."]})]})]})]}),O&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===O.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===O.type?"check_circle":"error"}),(0,a.jsx)("span",{children:O.text})]}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:ex,disabled:0===K.length,loading:A,className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:eh,disabled:!k.has9Router,loading:$,className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>F(!0),className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.uR,{isOpen:L,onClose:()=>F(!1),title:"Claude Cowork - Manual Configuration",configs:(N=U&&U.trim()?U:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",w=K.length>0?K:["provider/model-id"],[{filename:"~/Library/Application Support/Claude-3p/configLibrary/<appliedId>.json",content:JSON.stringify({inferenceProvider:"gateway",inferenceGatewayBaseUrl:ec()||"https://your-public-host/v1",inferenceGatewayApiKey:N,inferenceModels:w.map(e=>({name:e}))},null,2)}])}),(0,a.jsx)(r.CK,{isOpen:X,combo:null,onClose:()=>ee(!1),onSave:eu,activeProviders:d,forcePrefix:"claude-",title:"Create Cowork Combo"}),(0,a.jsx)(r.rq,{isOpen:et,onClose:()=>es(!1),onSelect:e=>{let t=e?.value||e?.name||e;!t||K.includes(t)||z(e=>[...e,t])},onDeselect:ep,activeProviders:d,modelAliases:Z,title:"Select Cowork Model",addedModelValues:K,closeOnSelect:!1}),(0,a.jsx)(r.Nf,{isOpen:ea,onClose:()=>el(!1),onAdd:e=>{B.some(t=>t.name===e.name)||J([...B,e])},addedNames:B.map(e=>e.name)}),er&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:()=>en(!1),children:(0,a.jsxs)("div",{className:"bg-surface border border-border rounded-xl shadow-xl w-full max-w-sm mx-4 p-5 flex flex-col gap-4",onClick:e=>e.stopPropagation(),children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("h3",{className:"font-semibold text-sm",children:"Add Custom MCP"}),(0,a.jsx)("button",{onClick:()=>en(!1),className:"text-text-muted hover:text-text-main",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{onClick:()=>eo(e=>({...e,type:"url"})),className:`flex-1 py-1.5 rounded border text-xs font-medium transition-colors ${"url"===ei.type?"bg-primary/10 border-primary/40 text-primary":"border-border text-text-muted hover:border-primary/40"}`,children:"URL (SSE)"}),(0,a.jsx)("button",{onClick:()=>eo(e=>({...e,type:"cmd"})),className:`flex-1 py-1.5 rounded border text-xs font-medium transition-colors ${"cmd"===ei.type?"bg-primary/10 border-primary/40 text-primary":"border-border text-text-muted hover:border-primary/40"}`,children:"Command (stdio)"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-[11px] text-text-muted font-medium",children:"Name"}),(0,a.jsx)("input",{type:"text",placeholder:"my-mcp",value:ei.name,onChange:e=>eo(t=>({...t,name:e.target.value.replace(/\s+/g,"-").toLowerCase()})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}),"url"===ei.type?(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-[11px] text-text-muted font-medium",children:"SSE URL"}),(0,a.jsx)("input",{type:"text",placeholder:"https://your-mcp-server.com/sse",value:ei.url,onChange:e=>eo(t=>({...t,url:e.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-[11px] text-text-muted font-medium",children:"Command"}),(0,a.jsx)("input",{type:"text",placeholder:"npx",value:ei.command,onChange:e=>eo(t=>({...t,command:e.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsxs)("label",{className:"text-[11px] text-text-muted font-medium",children:["Args ",(0,a.jsx)("span",{className:"font-normal",children:"(comma-separated)"})]}),(0,a.jsx)("input",{type:"text",placeholder:"-y, @some/mcp-package",value:ei.args,onChange:e=>eo(t=>({...t,args:e.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]})]})]}),(0,a.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,a.jsx)("button",{onClick:()=>en(!1),className:"px-3 py-1.5 rounded border border-border text-xs text-text-muted hover:bg-surface cursor-pointer",children:"Cancel"}),(0,a.jsx)("button",{onClick:()=>{let e=ei.name.trim();if(e){if("url"===ei.type){if(!ei.url.trim())return;V(t=>[...t.filter(t=>t.name!==e),{name:e,url:ei.url.trim(),transport:"sse",custom:!0}])}else{if(!ei.command.trim())return;let t=ei.args.split(",").map(e=>e.trim()).filter(Boolean);V(s=>[...s.filter(t=>t.name!==e),{name:e,command:ei.command.trim(),args:t,custom:!0}])}en(!1)}},className:"px-3 py-1.5 rounded bg-primary text-white text-xs font-medium hover:opacity-90 cursor-pointer",children:"Add"})]})]})})]})}let U="9router.cliToolEndpointPresets";function D(e){return Array.isArray(e)?e.filter(e=>e?.name&&e?.baseUrl&&e?.apiKey):[]}function K(e){window.localStorage.setItem(U,JSON.stringify(D(e)))}function z({baseUrl:e,apiKey:t,onBaseUrlChange:s,onApiKeyChange:r}){let[n,i]=(0,l.useState)([]),[o,d]=(0,l.useState)("");(0,l.useEffect)(()=>{i(function(){try{return D(JSON.parse(window.localStorage.getItem(U)||"[]"))}catch{return[]}}())},[]);let c=(0,l.useMemo)(()=>n.find(e=>e.name===o)||null,[n,o]);return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right",children:"Preset"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),(0,a.jsxs)("select",{value:o,onChange:e=>{var t;let a;return d(t=e.target.value),void((a=n.find(e=>e.name===t))&&(s(a.baseUrl),r(a.apiKey)))},className:"flex-1 px-2 py-1.5 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50",children:[(0,a.jsx)("option",{value:"",children:"Manual / current endpoint"}),n.map(e=>{var t;return(0,a.jsxs)("option",{value:e.name,children:[e.name," - ",e.baseUrl," (",(t=e.apiKey)?t.length<=12?`${t.slice(0,4)}...`:`${t.slice(0,8)}...${t.slice(-4)}`:"No API key",")"]},e.name)})]}),(0,a.jsx)("button",{type:"button",onClick:()=>{let s=(e||"").trim(),a=(t||"").trim();if(!s||!a)return;let l=c?.name||s;try{l=c?.name||new URL(s).host}catch{l=c?.name||s}let r=window.prompt("Preset name",l);if(!r?.trim())return;let o={name:r.trim(),baseUrl:s,apiKey:a},m=[...n.filter(e=>e.name!==o.name),o].sort((e,t)=>e.name.localeCompare(t.name));i(m),d(o.name),K(m)},disabled:!e||!t,className:"px-2 py-1.5 rounded border text-xs bg-surface border-border text-text-main hover:border-primary disabled:opacity-50 disabled:cursor-not-allowed shrink-0",title:"Save current Base URL and API key as a browser-local preset",children:"Save"}),c&&(0,a.jsx)("button",{type:"button",onClick:()=>{if(!c)return;let e=n.filter(e=>e.name!==c.name);i(e),d(""),K(e)},className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors",title:"Delete selected preset",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"delete"})})]})}function L({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m}){let x,u,[p,h]=(0,l.useState)(m||null),[g,f]=(0,l.useState)(!1),[y,b]=(0,l.useState)(!1),[j,v]=(0,l.useState)(!1),[N,w]=(0,l.useState)(null),[k,C]=(0,l.useState)(""),[S,_]=(0,l.useState)(""),[A,E]=(0,l.useState)({}),[$,M]=(0,l.useState)(!1),[O,T]=(0,l.useState)([]),[P,R]=(0,l.useState)(!1),I=(0,l.useRef)([]);(0,l.useEffect)(()=>{I.current=O},[O]),(0,l.useEffect)(()=>{o?.length>0&&!k&&C(o[0].key)},[o,k]),(0,l.useEffect)(()=>{m&&h(m)},[m]),(0,l.useEffect)(()=>{t&&!p&&(H(),U()),t&&U()},[t]),(0,l.useEffect)(()=>{if(p?.config&&Array.isArray(p.config)&&0===O.length){let e=p.config.find(e=>"9Router"===e.name);e?.models?.length>0&&T(e.models.map(e=>e.id))}},[p]);let U=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&E(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}},D=async e=>{try{let t=k&&k.trim()||c?k:"sk_9router";await fetch("/api/cli-tools/copilot-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:F(),apiKey:t,models:e})})}catch(e){console.log("Error saving models:",e)}},K=(()=>{if(!p)return null;if(!p.has9Router)return"not_configured";let e=p.currentUrl||"";return e.includes("localhost")||e.includes("127.0.0.1")||e.includes(i)?"configured":"other"})(),F=()=>{let e=S||i;return e.endsWith("/v1")?e:`${e}/v1`},q=k&&!o.some(e=>e.key===k),H=async()=>{f(!0);try{let e=await fetch("/api/cli-tools/copilot-settings"),t=await e.json();h(t)}catch(e){h({error:e.message})}finally{f(!1)}},B=async()=>{b(!0),w(null);try{let e=k&&k.trim()||c?k:"sk_9router",t=await fetch("/api/cli-tools/copilot-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:F(),apiKey:e,models:O})}),s=await t.json();t.ok?(w({type:"success",text:s.message||"Settings applied! Reload VS Code."}),H()):w({type:"error",text:s.error||"Failed to apply settings"})}catch(e){w({type:"error",text:e.message})}finally{b(!1)}},J=async()=>{v(!0),w(null);try{let e=await fetch("/api/cli-tools/copilot-settings",{method:"DELETE"}),t=await e.json();e.ok?(w({type:"success",text:"Settings reset successfully!"}),T([]),H()):w({type:"error",text:t.error||"Failed to reset settings"})}catch(e){w({type:"error",text:e.message})}finally{v(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/copilot.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===K&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===K&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===K&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[g&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Copilot config..."})]}),!g&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-blue-500 text-lg",children:"info"}),(0,a.jsxs)("div",{className:"text-xs text-blue-700 dark:text-blue-300",children:[(0,a.jsxs)("p",{className:"font-medium",children:["Writes to ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/10 rounded",children:"chatLanguageModels.json"})]}),(0,a.jsx)("p",{className:"mt-0.5 opacity-80",children:"Reload VS Code after applying for changes to take effect."})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsx)(z,{baseUrl:F(),apiKey:k,onBaseUrlChange:_,onApiKeyChange:C}),(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium text-text-muted",children:"Base URL"}),(0,a.jsx)("input",{type:"text",value:F(),onChange:e=>_(e.target.value),placeholder:"https://.../v1",className:"px-3 py-2 bg-bg-secondary rounded-lg text-sm border border-border focus:outline-none focus:ring-1 focus:ring-primary/50"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium text-text-muted",children:"API Key"}),o.length>0||k?(0,a.jsxs)("select",{value:k,onChange:e=>C(e.target.value),className:"px-3 py-2 bg-bg-secondary rounded-lg text-sm border border-border focus:outline-none focus:ring-1 focus:ring-primary/50",children:[q&&(0,a.jsx)("option",{value:k,children:k}),o.map(e=>(0,a.jsxs)("option",{value:e.key,children:[e.key," (",e.name,")"]},e.id))]}):(0,a.jsx)("span",{className:"text-sm text-text-muted",children:c?"No API keys - Create one in Keys page":"sk_9router (default)"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Models"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:0===O.length?(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"No models selected"}):O.map(e=>(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border",children:[e,(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),T(t=>t.filter(t=>t!==e))},className:"ml-0.5 hover:text-red-500",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e))}),(0,a.jsx)("div",{children:(0,a.jsx)("button",{onClick:()=>R(!0),disabled:!d?.length,className:`px-2 py-1 rounded border text-xs transition-colors ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Add Model"})})]})]})]}),N&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===N.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===N.type?"check_circle":"error"}),(0,a.jsx)("span",{children:N.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:B,disabled:0===O.length,loading:y,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:J,disabled:!p?.has9Router,loading:j,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>M(!0),disabled:0===O.length,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:P,onClose:()=>{R(!1),D(I.current)},onSelect:e=>{O.includes(e.value)||T([...O,e.value])},onDeselect:e=>{T(O.filter(t=>t!==e.value))},selectedModel:null,activeProviders:d,modelAliases:A,addedModelValues:O,closeOnSelect:!1,title:"Add Model for GitHub Copilot"}),(0,a.jsx)(r.uR,{isOpen:$,onClose:()=>M(!1),title:"GitHub Copilot - Manual Configuration",configs:(x=k&&k.trim()?k:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",u=F(),[{filename:"~/Library/Application Support/Code/User/chatLanguageModels.json",content:JSON.stringify([{name:"9Router",vendor:"azure",apiKey:x,models:(O.length>0?O:["provider/model-id"]).map(e=>({id:e,name:e,url:`${u}/chat/completions#models.ai.azure.com`,toolCalling:!0,vision:!1,maxInputTokens:128e3,maxOutputTokens:16e3}))}],null,2)}])})]})}function F({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:y}){let b,j,[v,N]=(0,l.useState)(m||null),[w,k]=(0,l.useState)(!1),[C,S]=(0,l.useState)(!1),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(null),[M,O]=(0,l.useState)(!1),[T,P]=(0,l.useState)(""),[R,I]=(0,l.useState)(""),[U,D]=(0,l.useState)(!1),[K,z]=(0,l.useState)({}),[L,q]=(0,l.useState)(!1),[H,B]=(0,l.useState)("");(0,l.useEffect)(()=>{o?.length>0&&!T&&P(o[0].key)},[o,T]),(0,l.useEffect)(()=>{m&&N(m)},[m]),(0,l.useEffect)(()=>{t&&!v&&(Y(),J()),t&&J()},[t]),(0,l.useEffect)(()=>{v?.settings?.openAiModelId&&I(v.settings.openAiModelId)},[v]);let J=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&z(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}},G=v?.installed?v.has9Router?g(v.settings?.openAiBaseUrl||"",{tunnelPublicUrl:h,tailscaleUrl:y})?"configured":"other":"not_configured":null,W=()=>{let e=H||`${i}/v1`;return e.endsWith("/v1")?e:`${e}/v1`},Y=async()=>{k(!0);try{let e=await fetch("/api/cli-tools/cline-settings"),t=await e.json();N(t)}catch(e){N({installed:!1,error:e.message})}finally{k(!1)}},V=async()=>{S(!0),$(null);try{let e=T&&T.trim()||c?T:"sk_9router",t=await fetch("/api/cli-tools/cline-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:W(),apiKey:e,model:R})}),s=await t.json();t.ok?($({type:"success",text:"Settings applied successfully!"}),Y()):$({type:"error",text:s.error||"Failed to apply settings"})}catch(e){$({type:"error",text:e.message})}finally{S(!1)}},Z=async()=>{A(!0),$(null);try{let e=await fetch("/api/cli-tools/cline-settings",{method:"DELETE"}),t=await e.json();e.ok?($({type:"success",text:"Settings reset successfully!"}),I(""),Y()):$({type:"error",text:t.error||"Failed to reset settings"})}catch(e){$({type:"error",text:e.message})}finally{A(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/cline.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===G&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===G&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===G&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[w&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Cline..."})]}),!w&&v&&!v.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Cline not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>q(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>O(!M),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:M?"expand_less":"help"}),M?"Hide":"How to Install"]})]})]}),M&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsx)("div",{className:"space-y-3 text-sm",children:(0,a.jsxs)("p",{className:"text-text-muted",children:["Install Cline VS Code extension or CLI from ",(0,a.jsx)("a",{className:"text-primary underline",href:"https://docs.cline.bot/",target:"_blank",rel:"noreferrer",children:"docs.cline.bot"}),"."]})})]})]}),!w&&v?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:H||H||`${i}/v1`,onChange:B,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:y})]}),v?.settings?.openAiBaseUrl&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:v.settings.openAiBaseUrl})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:T,onChange:P,apiKeys:o,cloudEnabled:c})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:R,onChange:e=>I(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),R&&(0,a.jsx)("button",{onClick:()=>I(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>D(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),E&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===E.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===E.type?"check_circle":"error"}),(0,a.jsx)("span",{children:E.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:V,disabled:!T&&c&&o.length>0||!R,loading:C,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:Z,disabled:_,loading:_,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>q(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:U,onClose:()=>D(!1),onSelect:e=>{I(e.value),D(!1)},selectedModel:R,activeProviders:d,modelAliases:K,title:"Select Model for Cline"}),(0,a.jsx)(r.uR,{isOpen:L,onClose:()=>q(!1),title:"Cline - Manual Configuration",configs:(b=T&&T.trim()?T:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.cline/data/globalState.json",content:JSON.stringify({actModeApiProvider:"openai",planModeApiProvider:"openai",openAiBaseUrl:(j=W()).endsWith("/v1")?j.slice(0,-3):j,openAiModelId:R||"provider/model-id",planModeOpenAiModelId:R||"provider/model-id"},null,2)},{filename:"~/.cline/data/secrets.json",content:JSON.stringify({openAiApiKey:b},null,2)}])})]})}function q({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:g,tailscaleUrl:f}){let[y,b]=(0,l.useState)(m||null),[j,v]=(0,l.useState)(!1),[N,w]=(0,l.useState)(!1),[k,C]=(0,l.useState)(!1),[S,_]=(0,l.useState)(null),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(""),[O,T]=(0,l.useState)(""),[P,R]=(0,l.useState)(!1),[I,U]=(0,l.useState)({}),[D,K]=(0,l.useState)(!1),[z,L]=(0,l.useState)("");(0,l.useEffect)(()=>{o?.length>0&&!$&&M(o[0].key)},[o,$]),(0,l.useEffect)(()=>{m&&b(m)},[m]),(0,l.useEffect)(()=>{t&&!y&&(J(),F()),t&&F()},[t]);let F=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&U(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}},H=y?.installed?y.has9Router?"configured":"not_configured":null,B=()=>{let e=z||`${i}/v1`;return e.endsWith("/v1")?e:`${e}/v1`},J=async()=>{v(!0);try{let e=await fetch("/api/cli-tools/kilo-settings"),t=await e.json();b(t)}catch(e){b({installed:!1,error:e.message})}finally{v(!1)}},G=async()=>{w(!0),_(null);try{let e=$&&$.trim()||c?$:"sk_9router",t=await fetch("/api/cli-tools/kilo-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:B(),apiKey:e,model:O})}),s=await t.json();t.ok?(_({type:"success",text:"Settings applied successfully!"}),J()):_({type:"error",text:s.error||"Failed to apply settings"})}catch(e){_({type:"error",text:e.message})}finally{w(!1)}},W=async()=>{C(!0),_(null);try{let e=await fetch("/api/cli-tools/kilo-settings",{method:"DELETE"}),t=await e.json();e.ok?(_({type:"success",text:"Settings reset successfully!"}),T(""),J()):_({type:"error",text:t.error||"Failed to reset settings"})}catch(e){_({type:"error",text:e.message})}finally{C(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/kilocode.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===H&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===H&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[j&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Kilo Code..."})]}),!j&&y&&!y.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Kilo Code not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>K(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>E(!A),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:A?"expand_less":"help"}),A?"Hide":"How to Install"]})]})]}),A&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("p",{className:"text-sm text-text-muted",children:["Install Kilo Code from ",(0,a.jsx)("a",{className:"text-primary underline",href:"https://kilocode.ai",target:"_blank",rel:"noreferrer",children:"kilocode.ai"})," or VS Code extension marketplace."]})]})]}),!j&&y?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:z||z||`${i}/v1`,onChange:L,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:g,tailscaleUrl:f})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:$,onChange:M,apiKeys:o,cloudEnabled:c})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:O,onChange:e=>T(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),O&&(0,a.jsx)("button",{onClick:()=>T(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>R(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),S&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===S.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===S.type?"check_circle":"error"}),(0,a.jsx)("span",{children:S.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:G,disabled:!$&&c&&o.length>0||!O,loading:N,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:W,disabled:k,loading:k,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>K(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:P,onClose:()=>R(!1),onSelect:e=>{T(e.value),R(!1)},selectedModel:O,activeProviders:d,modelAliases:I,title:"Select Model for Kilo Code"}),(0,a.jsx)(r.uR,{isOpen:D,onClose:()=>K(!1),title:"Kilo Code - Manual Configuration",configs:[{filename:"~/.local/share/kilo/auth.json",content:JSON.stringify({"openai-compatible":{type:"api-key",apiKey:$&&$.trim()?$:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",baseUrl:B(),model:O||"provider/model-id"}},null,2)}]})]})}let H="/api/cli-tools/deepseek-tui-settings";function B({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b}){let j,[v,N]=(0,l.useState)(u||null),[w,k]=(0,l.useState)(!1),[C,S]=(0,l.useState)(!1),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(null),[M,O]=(0,l.useState)(""),[T,P]=(0,l.useState)(""),[R,I]=(0,l.useState)(!1),[U,D]=(0,l.useState)({}),[K,z]=(0,l.useState)(!1),[L,F]=(0,l.useState)(""),q=(0,l.useRef)(!1),J=(()=>{if(!v?.installed)return null;let e=v.settings?.["providers.openai"];return e?.base_url?g(e.base_url,{tunnelPublicUrl:f,tailscaleUrl:b})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!M&&O(d[0].key)},[d,M]),(0,l.useEffect)(()=>{u&&N(u)},[u]),(0,l.useEffect)(()=>{t&&!v&&(W(),G()),t&&G()},[t]);let G=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&D(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(v?.installed&&!q.current){q.current=!0;let e=v.settings?.["providers.openai"];e?.model&&P(e.model)}},[v]);let W=async()=>{k(!0);try{let e=await fetch(H),t=await e.json();N(t)}catch(e){N({installed:!1,error:e.message})}finally{k(!1)}},Y=()=>{let e=L||window.location.origin.replace("://localhost","://127.0.0.1");return e.endsWith("/v1")?e:`${e}/v1`},V=async()=>{S(!0),$(null);try{let e=M?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch(H,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:Y(),apiKey:e,model:T})}),s=await t.json();t.ok?($({type:"success",text:"Settings applied successfully!"}),W()):$({type:"error",text:s.error||"Failed to apply settings"})}catch(e){$({type:"error",text:e.message})}finally{S(!1)}},Z=async()=>{A(!0),$(null);try{let e=await fetch(H,{method:"DELETE"}),t=await e.json();e.ok?($({type:"success",text:"Settings reset successfully!"}),P(""),W()):$({type:"error",text:t.error||"Failed to reset settings"})}catch(e){$({type:"error",text:e.message})}finally{A(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image||"/providers/deepseek-tui.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[w&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking DeepSeek TUI..."})]}),!w&&v&&!v.installed&&(0,a.jsx)("div",{className:"flex flex-col gap-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"DeepSeek TUI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-1",children:"Install via npm:"}),(0,a.jsx)("code",{className:"block mt-2 p-2 bg-black/20 rounded text-xs font-mono",children:"npm install -g deepseek-tui"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-2",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsx)("div",{className:"flex items-center gap-2 pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>z(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!w&&v?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[e.notes&&e.notes.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-2 mb-2",children:e.notes.map((e,t)=>(0,a.jsxs)("div",{className:`flex items-start gap-2 p-2 rounded text-xs ${"warning"===e.type?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":"error"===e.type?"bg-red-500/10 text-red-600 dark:text-red-400":"bg-blue-500/10 text-blue-600 dark:text-blue-400"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mt-0.5",children:"warning"===e.type?"warning":"error"===e.type?"error":"info"}),(0,a.jsx)("span",{children:e.text})]},t))}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:L||Y(),onChange:F,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b})]}),v?.settings?.["providers.openai"]?.base_url&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:v.settings["providers.openai"].base_url})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:M,onChange:O,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:T,onChange:e=>P(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),T&&(0,a.jsx)("button",{onClick:()=>P(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>I(!0),disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]})]}),E&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===E.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===E.type?"check_circle":"error"}),(0,a.jsx)("span",{children:E.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:V,disabled:!T,loading:C,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:Z,disabled:!v?.has9Router,loading:_,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>z(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:R,onClose:()=>I(!1),onSelect:e=>{P(e.value),I(!1)},selectedModel:T,activeProviders:c,modelAliases:U,title:"Select Model for DeepSeek TUI"}),(0,a.jsx)(r.uR,{isOpen:K,onClose:()=>z(!1),title:"DeepSeek TUI - Manual Configuration",configs:(j=M&&M.trim()?M:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.deepseek/config.toml",content:`[providers.openai]
|
|
39
|
+
`}])})]})}var w=s(11059);function k({toolId:e,tool:t,isExpanded:s,onToggle:i,baseUrl:o,apiKeys:d,activeProviders:c=[],cloudEnabled:m=!1,tunnelEnabled:x=!1}){let[u,h]=(0,l.useState)(null),[g,f]=(0,l.useState)(!1),[y,b]=(0,l.useState)(""),[j,v]=(0,l.useState)(()=>d?.length>0?d[0].key:""),N=e=>{let t=j&&j.trim()?j:m?"your-api-key":"sk_9router",s=o||"http://localhost:20128",a=s.endsWith("/v1")?s:`${s}/v1`;return e.replace(/\{\{baseUrl\}\}/g,a).replace(/\{\{apiKey\}\}/g,t).replace(/\{\{model\}\}/g,y||"provider/model-id")},{copy:C}=(0,w.C)(),S=async(e,t)=>{await C(N(e),`toolcard-${t}`),h(t),setTimeout(()=>h(null),2e3)},_=c.length>0,A=()=>(!t.requiresExternalUrl||!!m||!!x)&&(!t.requiresCloud||!!m);return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden overflow-x-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between hover:cursor-pointer",onClick:i,children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 rounded-lg flex items-center justify-center shrink-0",children:t.image?(0,a.jsx)(n.default,{src:t.image,alt:t.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}}):t.icon?(0,a.jsx)("span",{className:"material-symbols-outlined text-xl",style:{color:t.color},children:t.icon}):(0,a.jsx)(n.default,{src:`/providers/${e}.png`,alt:t.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:t.name}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:t.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${s?"rotate-180":""}`,children:"expand_more"})]}),s&&(0,a.jsx)("div",{className:"mt-6 pt-6 border-t border-border",children:t.guideSteps?(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[t.notes&&0!==t.notes.length?(0,a.jsx)("div",{className:"flex flex-col gap-2 mb-4",children:t.notes.map((e,t)=>{if("cloudCheck"===e.type&&(m||x))return null;let s="warning"===e.type,l="cloudCheck"===e.type&&!m&&!x,r="bg-blue-500/10 border-blue-500/30",n="text-blue-600 dark:text-blue-400",i="text-blue-500",o="info";return s?(r="bg-yellow-500/10 border-yellow-500/30",n="text-yellow-600 dark:text-yellow-400",i="text-yellow-500",o="warning"):l&&(r="bg-red-500/10 border-red-500/30",n="text-red-600 dark:text-red-400",i="text-red-500",o="error"),(0,a.jsxs)("div",{className:`flex items-start gap-3 p-3 rounded-lg border ${r}`,children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-lg ${i}`,children:o}),(0,a.jsx)("p",{className:`text-sm ${n}`,children:e.text})]},t)})}):null,A()&&t.guideSteps.map(e=>(0,a.jsxs)("div",{className:"flex items-start gap-4",children:[(0,a.jsx)("div",{className:"size-8 rounded-full flex items-center justify-center shrink-0 text-sm font-semibold text-white",style:{backgroundColor:t.color},children:e.step}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"font-medium text-text",children:e.title}),e.desc&&(0,a.jsx)("p",{className:"text-sm text-text-muted mt-0.5",children:e.desc}),"apiKeySelector"===e.type&&(0,a.jsx)("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:(0,a.jsx)(p,{value:j,onChange:v,apiKeys:d,cloudEnabled:m,className:"flex-1"})}),"modelSelector"===e.type&&(0,a.jsxs)("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,a.jsx)("input",{type:"text",value:y,onChange:e=>b(e.target.value),placeholder:"provider/model-id",className:"w-full sm:w-auto flex-1 px-3 py-2 bg-bg-secondary rounded-lg text-sm border border-border focus:outline-none focus:ring-1 focus:ring-primary/50"}),(0,a.jsx)("button",{onClick:()=>f(!0),disabled:!_,className:`shrink-0 px-3 py-2 rounded-lg border text-sm transition-colors ${_?"bg-bg-secondary border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"}),y&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{onClick:()=>S(y,"model"),className:"shrink-0 px-3 py-2 bg-bg-secondary hover:bg-bg-tertiary rounded-lg border border-border transition-colors",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-lg",children:"model"===u?"check":"content_copy"})}),(0,a.jsx)("button",{onClick:()=>b(""),className:"p-2 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-lg",children:"close"})})]})]}),e.value&&(0,a.jsxs)("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,a.jsx)("code",{className:"w-full sm:w-auto flex-1 px-3 py-2 bg-bg-secondary rounded-lg text-sm font-mono border border-border truncate",children:N(e.value)}),e.copyable&&(0,a.jsx)("button",{onClick:()=>S(e.value,`${e.step}-${e.title}`),className:"shrink-0 px-3 py-2 bg-bg-secondary hover:bg-bg-tertiary rounded-lg border border-border transition-colors",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-lg",children:u===`${e.step}-${e.title}`?"check":"content_copy"})})]})]})]},e.step)),A()&&t.codeBlock&&(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:t.codeBlock.language}),(0,a.jsxs)("button",{onClick:()=>S(t.codeBlock.code,"codeblock"),className:"flex items-center gap-1 px-2 py-1 text-xs bg-bg-secondary hover:bg-bg-tertiary rounded border border-border transition-colors",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-sm",children:"codeblock"===u?"check":"content_copy"}),"codeblock"===u?"Copied!":"Copy"]})]}),(0,a.jsx)("pre",{className:"p-4 bg-bg-secondary rounded-lg border border-border overflow-x-auto",children:(0,a.jsx)("code",{className:"text-sm font-mono whitespace-pre",children:N(t.codeBlock.code)})})]})]}):(0,a.jsx)("p",{className:"text-text-muted text-sm",children:"Coming soon..."})}),(0,a.jsx)(r.rq,{isOpen:g,onClose:()=>f(!1),onSelect:e=>{b(e.value)},selectedModel:y,activeProviders:c,title:"Select Model"})]})}let C="round-robin",S=[{value:"round-robin",label:"Round-Robin"},{value:"fallback",label:"Fallback"}];function _({tool:e,mappings:t,strategy:s=C,dnsActive:l=!0,hasActiveProviders:n,onChangeEntry:i,onBlurEntry:o,onOpenSelector:d,onAddEntry:c,onRemoveEntry:m,onReorderEntry:x,onChangeStrategy:u,feedback:p,compact:h=!1}){let g=h?"w-32 shrink-0 text-sm font-semibold text-text-main text-right":"w-36 shrink-0 text-xs font-semibold text-text-main text-right",f=h?"px-2 py-1.5 rounded border text-xs transition-colors shrink-0 whitespace-nowrap":"px-2 py-1.5 rounded border text-xs transition-colors shrink-0",y="h-8 min-w-8 inline-flex items-center justify-center rounded-md border border-border text-text-muted transition-colors",b=h?"h-8 px-2.5 inline-flex items-center justify-center rounded-md border border-border text-[11px] font-medium text-text-main transition-colors shrink-0 whitespace-nowrap":"h-8 px-2.5 inline-flex items-center justify-center rounded-md border border-border text-[11px] font-medium text-text-main transition-colors shrink-0",j=!l;return(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsx)("div",{className:"rounded-xl border border-border/70 bg-surface/60 p-3",children:(0,a.jsxs)("div",{className:"flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs font-semibold text-text-main",children:"Routing strategy"}),(0,a.jsx)("p",{className:"text-[11px] text-text-muted",children:"Round-robin spreads load. Fallback keeps priority order."}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted mt-1",children:"Tip: paste comma-separated models into one row to expand multiple targets at once."})]}),(0,a.jsx)("div",{className:"sm:w-44",children:(0,a.jsx)(r.l6,{value:s,onChange:e=>u(e.target.value),disabled:j,options:S,selectClassName:"py-1.5 px-2 pr-8 text-xs bg-surface border-border","aria-label":`${e.name} MITM strategy`})})]})}),p&&(0,a.jsx)("div",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-[11px] text-text-muted",children:p}),(0,a.jsx)("div",{className:"flex flex-col gap-2",children:e.defaultModels?.map(e=>{let s=Array.isArray(t?.[e.alias])?t[e.alias]:[],r=l&&s.length<5;return(0,a.jsx)("div",{className:"rounded-xl border border-border/70 bg-surface/40 p-3",children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("div",{className:g,children:(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("span",{children:e.name}),(0,a.jsxs)("span",{className:"text-[10px] font-normal text-text-muted",children:["Max ",5," targets"]})]})}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[s.length>0?s.map((t,l)=>{let r=j||0===l,c=j||l===s.length-1;return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"w-6 text-center text-[11px] font-semibold text-text-muted",children:l+1}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),(0,a.jsx)("input",{type:"text",value:t,onChange:t=>i(e.alias,l,t.target.value),onBlur:t=>o(e.alias,l,t.target.value),placeholder:"provider/model-id",disabled:j,className:`flex-1 px-2 py-1.5 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 ${j?"opacity-50 cursor-not-allowed":""}`}),(0,a.jsx)("button",{type:"button",onClick:()=>d(e.alias,l),disabled:!n||j,className:`${b} ${n&&!j?"hover:border-primary hover:text-primary cursor-pointer":"opacity-40 cursor-not-allowed"}`,title:"Select model",children:"Select"}),(0,a.jsx)("button",{type:"button",onClick:()=>x(e.alias,l,l-1),disabled:r,className:`${y} ${r?"opacity-40 cursor-not-allowed":"hover:border-primary hover:text-primary cursor-pointer"}`,title:"Move up",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"keyboard_arrow_up"})}),(0,a.jsx)("button",{type:"button",onClick:()=>x(e.alias,l,l+1),disabled:c,className:`${y} ${c?"opacity-40 cursor-not-allowed":"hover:border-primary hover:text-primary cursor-pointer"}`,title:"Move down",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"keyboard_arrow_down"})}),(0,a.jsx)("button",{type:"button",onClick:()=>m(e.alias,l),disabled:j,className:`${y} ${j?"opacity-40 cursor-not-allowed":"hover:border-red-500 hover:text-red-500 cursor-pointer"}`,title:"Remove",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},`${e.alias}-${l}`)}):(0,a.jsx)("div",{className:"rounded-lg border border-dashed border-border px-3 py-2 text-[11px] text-text-muted",children:"No mapping — passthrough"}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2 pl-8",children:[(0,a.jsx)("button",{type:"button",onClick:()=>c(e.alias),disabled:!r,className:`${f} ${r?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"+ Add"}),(0,a.jsxs)("span",{className:"text-[10px] text-text-muted",children:[s.length,"/",5," mapped"]})]})]})]})},e.alias)})})]})}function A(e){return Array.isArray(e)?e.map(e=>"string"==typeof e?e.trim():"").filter(Boolean).slice(0,5):"string"==typeof e&&e.trim()?[e.trim()]:[]}function E(e){return Object.fromEntries(Object.entries(e||{}).map(([e,t])=>[e,A(t)]).filter(([,e])=>e.length>0))}function $(e,t,s){let a="string"==typeof s?s.trim():"";if(!t||!a)return e;let l=A(e?.[t]);return l.length>=5?e:{...e,[t]:[...l,a]}}function M(e,t,s,a){let l=Array.isArray(e?.[t])?[...e[t]]:[];return s<0||s>=l.length?e:(l[s]=a,{...e,[t]:l})}function O(e){return"fallback"===(e||C)?"fallback":C}function T({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:y}){let b,j,v,N,w,[k,C]=(0,l.useState)(m||null),[S,_]=(0,l.useState)(!1),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(!1),[O,P]=(0,l.useState)(null),[R,I]=(0,l.useState)(!1),[U,D]=(0,l.useState)(""),[K,z]=(0,l.useState)(""),[L,F]=(0,l.useState)(""),[q,H]=(0,l.useState)(!1),[B,J]=(0,l.useState)(!1),[W,G]=(0,l.useState)({}),[Y,V]=(0,l.useState)(!1),[Z,Q]=(0,l.useState)(""),[X,ee]=(0,l.useState)([]),[et,es]=(0,l.useState)(""),ea=(0,l.useRef)([]);(0,l.useEffect)(()=>{ea.current=X},[X]),(0,l.useEffect)(()=>{o?.length>0&&!U&&D(o[0].key)},[o,U]),(0,l.useEffect)(()=>{m&&C(m)},[m]),(0,l.useEffect)(()=>{t&&!k&&(eo(),el()),t&&el()},[t]),(0,l.useEffect)(()=>{k?.opencode?.models&&ee(k.opencode.models),k?.opencode?.activeModel&&es(k.opencode.activeModel),k?.config?.agent?.explorer?.model?.startsWith("9router/")&&F(k.config.agent.explorer.model.replace("9router/",""))},[k]);let el=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&G(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}},er=async e=>{try{let t=U&&U.trim()||c?U:"sk_9router",s=e.includes(et)?et:e[0]||"";await fetch("/api/cli-tools/opencode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ei(),apiKey:t,models:e,activeModel:s,subagentModel:L})})}catch(e){console.log("Error saving models:",e)}},en=k?.installed?k.config&&k.has9Router?g(k.config?.provider?.["9router"]?.options?.baseURL||"",{tunnelPublicUrl:h,tailscaleUrl:y})?"configured":"other":"not_configured":null,ei=()=>{let e=Z||i;return e.endsWith("/v1")?e:`${e}/v1`},eo=async()=>{_(!0);try{let e=await fetch("/api/cli-tools/opencode-settings"),t=await e.json();C(t)}catch(e){C({installed:!1,error:e.message})}finally{_(!1)}},ed=async()=>{E(!0),P(null);try{let e=U&&U.trim()||c?U:"sk_9router",t=await fetch("/api/cli-tools/opencode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ei(),apiKey:e,models:X,activeModel:""===et?"":et||X[0],subagentModel:L})}),s=await t.json();t.ok?(P({type:"success",text:"Settings applied successfully!"}),eo()):P({type:"error",text:s.error||"Failed to apply settings"})}catch(e){P({type:"error",text:e.message})}finally{E(!1)}},ec=async()=>{M(!0),P(null);try{let e=await fetch("/api/cli-tools/opencode-settings",{method:"DELETE"}),t=await e.json();e.ok?(P({type:"success",text:"Settings reset successfully!"}),z(""),F(""),ee([]),es(""),eo()):P({type:"error",text:t.error||"Failed to reset settings"})}catch(e){P({type:"error",text:e.message})}finally{M(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/opencode.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===en&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===en&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===en&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[S&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking OpenCode CLI..."})]}),!S&&k&&!k.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"OpenCode CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>V(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>I(!R),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:R?"expand_less":"help"}),R?"Hide":"How to Install"]})]})]}),R&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-text-muted mb-1",children:"macOS / Linux:"}),(0,a.jsx)("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g opencode-ai"})]}),(0,a.jsxs)("p",{className:"text-text-muted",children:["After installation, run ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"opencode"})," to verify."]})]})]})]}),!S&&k?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:Z||Z||`${i}/v1`,onChange:Q,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:y})]}),k?.config?.provider?.["9router"]?.options?.baseURL&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:k.config.provider["9router"].options.baseURL})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:U,onChange:D,apiKeys:o,cloudEnabled:c})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Models"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:0===X.length?(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"No models selected"}):X.map(e=>(0,a.jsxs)("span",{onClick:async()=>{if(e===et)try{(await fetch("/api/cli-tools/opencode-settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({clearActiveModel:!0})})).ok&&(es(""),eo())}catch(e){console.log("Error clearing active model:",e)}else es(e)},className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs cursor-pointer transition-colors ${e===et?"bg-primary/10 text-primary border border-primary":"bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border"}`,title:e===et?"Click to clear active model":"Click to set as active",children:[e===et&&(0,a.jsx)("span",{className:"material-symbols-outlined text-[10px]",children:"star"}),e,(0,a.jsx)("button",{onClick:async t=>{t.stopPropagation();try{if((await fetch(`/api/cli-tools/opencode-settings?model=${encodeURIComponent(e)}`,{method:"DELETE"})).ok){let t=X.filter(t=>t!==e);ee(t),et===e&&es(""),eo()}}catch(e){console.log("Error removing model:",e)}},className:"ml-0.5 hover:text-red-500",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e))}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("button",{onClick:()=>H(!0),disabled:!d?.length,className:`px-2 py-1 rounded border text-xs transition-colors ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Add Model"}),(0,a.jsx)("span",{className:"text-xs text-text-muted",children:X.length>0&&et?(0,a.jsxs)(a.Fragment,{children:["Active: ",(0,a.jsx)("span",{className:"text-primary",children:et})]}):X.length>0?(0,a.jsx)("span",{className:"text-yellow-500",children:"Click a model to set/clear active"}):"Select models to add"})]})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Subagent Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("input",{type:"text",value:L,onChange:e=>F(e.target.value),placeholder:K||"provider/model-id (defaults to main model)",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),(0,a.jsx)("button",{onClick:()=>J(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"}),L&&(0,a.jsx)("button",{onClick:()=>F(""),className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear (will use main model)",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})]}),O&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===O.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===O.type?"check_circle":"error"}),(0,a.jsx)("span",{children:O.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:ed,disabled:0===X.length,loading:A,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:ec,disabled:!k.has9Router,loading:$,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>V(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:q,onClose:()=>{H(!1),er(ea.current)},onSelect:e=>{!X.includes(e.value)&&(ee([...X,e.value]),et||es(e.value))},onDeselect:e=>{let t=X.filter(t=>t!==e.value);ee(t),et===e.value&&es(t[0]||"")},selectedModel:null,activeProviders:d,modelAliases:W,addedModelValues:X,closeOnSelect:!1,title:"Add Model for OpenCode"}),(0,a.jsx)(r.rq,{isOpen:B,onClose:()=>J(!1),onSelect:e=>{F(e.value),J(!1)},selectedModel:L,activeProviders:d,modelAliases:W,title:"Select Subagent Model for OpenCode"}),(0,a.jsx)(r.uR,{isOpen:Y,onClose:()=>V(!1),title:"OpenCode - Manual Configuration",configs:(b=U&&U.trim()?U:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",j=X.length>0?X:["provider/model-id"],v=et||X[0]||j[0],N=L||v,w={},j.forEach(e=>{w[e]={name:e,modalities:{input:["text","image"],output:["text"]}}}),[{filename:"~/.config/opencode/opencode.json",content:JSON.stringify({provider:{"9router":{npm:"@ai-sdk/openai-compatible",options:{baseURL:ei(),apiKey:b},models:w}},model:`9router/${v}`,agent:{explorer:{description:"Fast explorer subagent for codebase exploration",mode:"subagent",model:`9router/${N}`}}},null,2)}])})]})}let P="/api/cli-tools/cowork-settings",R=e=>(e||"").replace(/\/v1\/?$/,"");function I({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,hasActiveProviders:c,cloudEnabled:m,cloudUrl:u,tunnelEnabled:h,tunnelPublicUrl:g,tailscaleEnabled:f,tailscaleUrl:y,initialStatus:b}){let j,v,N,w,[k,C]=(0,l.useState)(b||null),[S,_]=(0,l.useState)(!1),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(!1),[O,T]=(0,l.useState)(null),[U,D]=(0,l.useState)(""),[K,z]=(0,l.useState)([]),[L,F]=(0,l.useState)(!1),[q,H]=(0,l.useState)(""),[B,J]=(0,l.useState)([]),[W,G]=(0,l.useState)([]),[Y,V]=(0,l.useState)([]),[Z,Q]=(0,l.useState)({}),[X,ee]=(0,l.useState)(!1),[et,es]=(0,l.useState)(!1),[ea,el]=(0,l.useState)(!1),[er,en]=(0,l.useState)(!1),[ei,eo]=(0,l.useState)({type:"url",name:"",url:"",command:"",args:""});(0,l.useEffect)(()=>{o?.length>0&&!U&&D(o[0].key)},[o,U]),(0,l.useEffect)(()=>{b&&C(b)},[b]),(0,l.useEffect)(()=>{t&&!k&&ed()},[t]),(0,l.useEffect)(()=>{t&&fetch("/api/models/alias").then(e=>e.ok?e.json():null).then(e=>{e&&Q(e.aliases||{})}).catch(()=>{})},[t]),(0,l.useEffect)(()=>{k?.cowork?.models?.length&&z(k.cowork.models),k?.cowork?.baseUrl&&!q&&H(R(k.cowork.baseUrl)),Array.isArray(k?.cowork?.plugins)&&k.cowork.plugins.length>0?J(k.cowork.plugins):0===B.length&&Array.isArray(k?.defaultPlugins)&&J(k.defaultPlugins),Array.isArray(k?.cowork?.localPlugins)&&G(k.cowork.localPlugins),Array.isArray(k?.cowork?.customPlugins)&&k.cowork.customPlugins.length>0&&V(k.cowork.customPlugins)},[k]);let ed=async()=>{_(!0);try{let e=await fetch(P),t=await e.json();C(t)}catch(e){C({installed:!1,error:e.message})}finally{_(!1)}},ec=()=>{let e;return(e=(q||"").replace(/\/+$/,""))?/\/v1$/.test(e)?e:`${e}/v1`:""},em=k?.installed?k?.cowork?.baseUrl?k.has9Router?"configured":"other":"not_configured":null,ex=async()=>{T(null);let e=ec();if(0===K.length)return void T({type:"error",text:"Please select at least one model"});E(!0);try{let t=U?.trim()||(o?.length>0?o[0].key:null)||(m?null:"sk_9router"),s=await fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:e,apiKey:t,models:K,plugins:B,localPlugins:W,customPlugins:Y})}),a=await s.json();s.ok?(T({type:"success",text:"Settings applied. Quit & reopen Claude Desktop to load."}),ed()):T({type:"error",text:a.error||"Failed to apply settings"})}catch(e){T({type:"error",text:e.message})}finally{E(!1)}},eu=async({name:e,models:t})=>{try{let s=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,models:t})});if(!s.ok){let e=await s.json();T({type:"error",text:e.error||"Failed to create combo"});return}K.includes(e)||z([...K,e]),ee(!1),T({type:"success",text:`Combo "${e}" created and added.`})}catch(e){T({type:"error",text:e.message})}},ep=e=>{let t=e?.value||e?.name||e;z(e=>e.filter(e=>e!==t))},eh=async()=>{M(!0),T(null);try{let e=await fetch(P,{method:"DELETE"}),t=await e.json();e.ok?(T({type:"success",text:"Settings reset successfully"}),z([]),J(k?.defaultPlugins||[]),G([]),V([]),ed()):T({type:"error",text:t.error||"Failed to reset"})}catch(e){T({type:"error",text:e.message})}finally{M(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image,alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===em&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===em&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===em&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[S&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Claude Cowork..."})]}),!S&&k&&!k.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Claude Desktop (Cowork mode) not detected"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Open Claude Desktop → Help → Troubleshooting → Enable Developer mode → Configure third-party inference, then return here."})]})]}),(0,a.jsx)("div",{className:"pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>F(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]}),!S&&k?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:ec(),onChange:e=>H(R(e)),tunnelEnabled:h,tunnelPublicUrl:g,tailscaleEnabled:f,tailscaleUrl:y,cloudEnabled:m,cloudUrl:u})]}),k?.cowork?.baseUrl&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:k.cowork.baseUrl})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:U,onChange:D,apiKeys:o,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right",children:"Models"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex items-center gap-2",children:[(0,a.jsx)("div",{className:"flex-1 flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:0===K.length?(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"No models selected"}):K.map(e=>(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border",children:[e,(0,a.jsx)("button",{onClick:()=>ep(e),className:"ml-0.5 hover:text-red-500",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e))}),(0,a.jsx)("button",{onClick:()=>ee(!0),disabled:!c,className:`shrink-0 px-2 py-1.5 rounded border text-xs whitespace-nowrap transition-colors ${c?"bg-primary/10 border-primary/40 text-primary hover:bg-primary/20 cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"+ Combo"})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-2",children:"MCP"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-2",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-1",children:[B.filter(e=>"exa"!==e.name).map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1 bg-surface rounded border border-border",children:[(0,a.jsx)("span",{className:"text-xs font-medium min-w-0 truncate flex-shrink-0",children:e.title||e.name}),e.oauth&&(0,a.jsx)("span",{className:"text-[8px] text-amber-600 shrink-0",children:"OAuth"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-wrap gap-1 overflow-hidden",style:{maxHeight:"1.5rem"},children:[Array.isArray(e.toolNames)&&e.toolNames.slice(0,6).map(e=>(0,a.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-black/5 dark:bg-white/5 text-text-muted whitespace-nowrap",children:e},e)),Array.isArray(e.toolNames)&&e.toolNames.length>6&&(0,a.jsxs)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-black/5 dark:bg-white/5 text-text-muted whitespace-nowrap",children:["+",e.toolNames.length-6]})]}),(0,a.jsx)("button",{onClick:()=>{var t;return t=e.name,void J(B.filter(e=>e.name!==t))},className:"shrink-0 hover:text-red-500 ml-auto",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e.name)),Y.map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1 bg-surface rounded border border-border",children:[(0,a.jsx)("span",{className:"text-xs font-medium min-w-0 truncate flex-shrink-0",children:e.name}),(0,a.jsx)("span",{className:"text-[8px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-500 shrink-0",children:"custom"}),(0,a.jsx)("span",{className:"flex-1 text-[9px] text-text-muted truncate",children:e.url||e.command}),(0,a.jsx)("button",{onClick:()=>V(Y.filter(t=>t.name!==e.name)),className:"shrink-0 hover:text-red-500 ml-auto",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e.name)),0===B.filter(e=>"exa"!==e.name).length&&0===Y.length&&(0,a.jsx)("div",{className:"px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-muted",children:"No MCPs added"}),(0,a.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[(0,a.jsx)("button",{onClick:()=>el(!0),className:"px-2 py-1 rounded border text-xs bg-primary/10 border-primary/40 text-primary hover:bg-primary/20 cursor-pointer whitespace-nowrap",children:"+ Browse"}),(0,a.jsx)("button",{onClick:()=>{eo({type:"url",name:"",url:"",command:"",args:""}),en(!0)},className:"px-2 py-1 rounded border text-xs bg-surface border-border text-text-muted hover:border-primary hover:text-primary cursor-pointer whitespace-nowrap",children:"+ Custom"}),(0,a.jsx)("a",{href:"https://mcp.so",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-text-muted hover:text-primary underline ml-auto",children:"Find MCPs →"})]})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Tools"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-1.5",children:[(j=B.some(e=>"exa"===e.name),v=(k?.defaultPlugins||[]).find(e=>"exa"===e.name),(0,a.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer px-2 py-1.5 bg-surface rounded border border-border",children:[(0,a.jsx)("input",{type:"checkbox",checked:j,onChange:e=>{e.target.checked&&v?J([...B.filter(e=>"exa"!==e.name),v]):J(B.filter(e=>"exa"!==e.name))},className:"mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-xs font-medium",children:"Web Search & Fetch (Exa)"}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted leading-snug",children:"Replaces built-in WebSearch/WebFetch. Auto-strips duplicates from tool list."})]})]})),(()=>{let e=(k?.localStdioPlugins||[]).find(e=>"browsermcp"===e.name);if(!e)return null;let t=W.includes("browsermcp");return(0,a.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer px-2 py-1.5 bg-surface rounded border border-border",children:[(0,a.jsx)("input",{type:"checkbox",checked:t,onChange:e=>G(e.target.checked?[...W,"browsermcp"]:W.filter(e=>"browsermcp"!==e)),className:"mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-xs font-medium",children:"Browser Control (Browser MCP)"}),(0,a.jsxs)("p",{className:"text-[10px] text-text-muted leading-snug",children:["Controls your running Chrome. Auto-strips Cowork's built-in browser tools."," ",(0,a.jsx)("a",{href:e.extensionUrl,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"Install Chrome extension"})]})]})]})})()]})]}),Array.isArray(k?.localStdioPlugins)&&k.localStdioPlugins.filter(e=>"browsermcp"!==e.name).length>0&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Local Plugins"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,a.jsx)("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 bg-surface rounded border border-border",children:k.localStdioPlugins.filter(e=>"browsermcp"!==e.name).map(e=>{let t=W.includes(e.name);return(0,a.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer",children:[(0,a.jsx)("input",{type:"checkbox",checked:t,onChange:t=>G(t.target.checked?[...W,e.name]:W.filter(t=>t!==e.name)),className:"mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[(0,a.jsx)("span",{className:"text-xs font-medium",children:e.title}),(0,a.jsx)("span",{className:"text-[8px] text-amber-600",children:"stdio"})]}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted leading-snug",children:e.description}),e.extensionUrl&&(0,a.jsx)("a",{href:e.extensionUrl,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-primary underline",children:"Install Chrome extension"})]})]},e.name)})}),(0,a.jsxs)("p",{className:"text-[10px] text-text-muted leading-snug",children:["⚠️ Local plugins run as subprocess via ",(0,a.jsx)("code",{className:"px-1 py-0.5 rounded bg-black/5 dark:bg-white/5",children:"npx"}),". Requires Node.js installed."]})]})]})]}),O&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===O.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===O.type?"check_circle":"error"}),(0,a.jsx)("span",{children:O.text})]}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:ex,disabled:0===K.length,loading:A,className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:eh,disabled:!k.has9Router,loading:$,className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>F(!0),className:"w-full sm:w-auto",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.uR,{isOpen:L,onClose:()=>F(!1),title:"Claude Cowork - Manual Configuration",configs:(N=U&&U.trim()?U:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",w=K.length>0?K:["provider/model-id"],[{filename:"~/Library/Application Support/Claude-3p/configLibrary/<appliedId>.json",content:JSON.stringify({inferenceProvider:"gateway",inferenceGatewayBaseUrl:ec()||"https://your-public-host/v1",inferenceGatewayApiKey:N,inferenceModels:w.map(e=>({name:e}))},null,2)}])}),(0,a.jsx)(r.CK,{isOpen:X,combo:null,onClose:()=>ee(!1),onSave:eu,activeProviders:d,forcePrefix:"claude-",title:"Create Cowork Combo"}),(0,a.jsx)(r.rq,{isOpen:et,onClose:()=>es(!1),onSelect:e=>{let t=e?.value||e?.name||e;!t||K.includes(t)||z(e=>[...e,t])},onDeselect:ep,activeProviders:d,modelAliases:Z,title:"Select Cowork Model",addedModelValues:K,closeOnSelect:!1}),(0,a.jsx)(r.Nf,{isOpen:ea,onClose:()=>el(!1),onAdd:e=>{B.some(t=>t.name===e.name)||J([...B,e])},addedNames:B.map(e=>e.name)}),er&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:()=>en(!1),children:(0,a.jsxs)("div",{className:"bg-surface border border-border rounded-xl shadow-xl w-full max-w-sm mx-4 p-5 flex flex-col gap-4",onClick:e=>e.stopPropagation(),children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("h3",{className:"font-semibold text-sm",children:"Add Custom MCP"}),(0,a.jsx)("button",{onClick:()=>en(!1),className:"text-text-muted hover:text-text-main",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{onClick:()=>eo(e=>({...e,type:"url"})),className:`flex-1 py-1.5 rounded border text-xs font-medium transition-colors ${"url"===ei.type?"bg-primary/10 border-primary/40 text-primary":"border-border text-text-muted hover:border-primary/40"}`,children:"URL (SSE)"}),(0,a.jsx)("button",{onClick:()=>eo(e=>({...e,type:"cmd"})),className:`flex-1 py-1.5 rounded border text-xs font-medium transition-colors ${"cmd"===ei.type?"bg-primary/10 border-primary/40 text-primary":"border-border text-text-muted hover:border-primary/40"}`,children:"Command (stdio)"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-[11px] text-text-muted font-medium",children:"Name"}),(0,a.jsx)("input",{type:"text",placeholder:"my-mcp",value:ei.name,onChange:e=>eo(t=>({...t,name:e.target.value.replace(/\s+/g,"-").toLowerCase()})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}),"url"===ei.type?(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-[11px] text-text-muted font-medium",children:"SSE URL"}),(0,a.jsx)("input",{type:"text",placeholder:"https://your-mcp-server.com/sse",value:ei.url,onChange:e=>eo(t=>({...t,url:e.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-[11px] text-text-muted font-medium",children:"Command"}),(0,a.jsx)("input",{type:"text",placeholder:"npx",value:ei.command,onChange:e=>eo(t=>({...t,command:e.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsxs)("label",{className:"text-[11px] text-text-muted font-medium",children:["Args ",(0,a.jsx)("span",{className:"font-normal",children:"(comma-separated)"})]}),(0,a.jsx)("input",{type:"text",placeholder:"-y, @some/mcp-package",value:ei.args,onChange:e=>eo(t=>({...t,args:e.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]})]})]}),(0,a.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,a.jsx)("button",{onClick:()=>en(!1),className:"px-3 py-1.5 rounded border border-border text-xs text-text-muted hover:bg-surface cursor-pointer",children:"Cancel"}),(0,a.jsx)("button",{onClick:()=>{let e=ei.name.trim();if(e){if("url"===ei.type){if(!ei.url.trim())return;V(t=>[...t.filter(t=>t.name!==e),{name:e,url:ei.url.trim(),transport:"sse",custom:!0}])}else{if(!ei.command.trim())return;let t=ei.args.split(",").map(e=>e.trim()).filter(Boolean);V(s=>[...s.filter(t=>t.name!==e),{name:e,command:ei.command.trim(),args:t,custom:!0}])}en(!1)}},className:"px-3 py-1.5 rounded bg-primary text-white text-xs font-medium hover:opacity-90 cursor-pointer",children:"Add"})]})]})})]})}let U="9router.cliToolEndpointPresets";function D(e){return Array.isArray(e)?e.filter(e=>e?.name&&e?.baseUrl&&e?.apiKey):[]}function K(e){window.localStorage.setItem(U,JSON.stringify(D(e)))}function z({baseUrl:e,apiKey:t,onBaseUrlChange:s,onApiKeyChange:r}){let[n,i]=(0,l.useState)([]),[o,d]=(0,l.useState)("");(0,l.useEffect)(()=>{i(function(){try{return D(JSON.parse(window.localStorage.getItem(U)||"[]"))}catch{return[]}}())},[]);let c=(0,l.useMemo)(()=>n.find(e=>e.name===o)||null,[n,o]);return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right",children:"Preset"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),(0,a.jsxs)("select",{value:o,onChange:e=>{var t;let a;return d(t=e.target.value),void((a=n.find(e=>e.name===t))&&(s(a.baseUrl),r(a.apiKey)))},className:"flex-1 px-2 py-1.5 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50",children:[(0,a.jsx)("option",{value:"",children:"Manual / current endpoint"}),n.map(e=>{var t;return(0,a.jsxs)("option",{value:e.name,children:[e.name," - ",e.baseUrl," (",(t=e.apiKey)?t.length<=12?`${t.slice(0,4)}...`:`${t.slice(0,8)}...${t.slice(-4)}`:"No API key",")"]},e.name)})]}),(0,a.jsx)("button",{type:"button",onClick:()=>{let s=(e||"").trim(),a=(t||"").trim();if(!s||!a)return;let l=c?.name||s;try{l=c?.name||new URL(s).host}catch{l=c?.name||s}let r=window.prompt("Preset name",l);if(!r?.trim())return;let o={name:r.trim(),baseUrl:s,apiKey:a},m=[...n.filter(e=>e.name!==o.name),o].sort((e,t)=>e.name.localeCompare(t.name));i(m),d(o.name),K(m)},disabled:!e||!t,className:"px-2 py-1.5 rounded border text-xs bg-surface border-border text-text-main hover:border-primary disabled:opacity-50 disabled:cursor-not-allowed shrink-0",title:"Save current Base URL and API key as a browser-local preset",children:"Save"}),c&&(0,a.jsx)("button",{type:"button",onClick:()=>{if(!c)return;let e=n.filter(e=>e.name!==c.name);i(e),d(""),K(e)},className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors",title:"Delete selected preset",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"delete"})})]})}function L({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m}){let x,u,[p,h]=(0,l.useState)(m||null),[g,f]=(0,l.useState)(!1),[y,b]=(0,l.useState)(!1),[j,v]=(0,l.useState)(!1),[N,w]=(0,l.useState)(null),[k,C]=(0,l.useState)(""),[S,_]=(0,l.useState)(""),[A,E]=(0,l.useState)({}),[$,M]=(0,l.useState)(!1),[O,T]=(0,l.useState)([]),[P,R]=(0,l.useState)(!1),I=(0,l.useRef)([]);(0,l.useEffect)(()=>{I.current=O},[O]),(0,l.useEffect)(()=>{o?.length>0&&!k&&C(o[0].key)},[o,k]),(0,l.useEffect)(()=>{m&&h(m)},[m]),(0,l.useEffect)(()=>{t&&!p&&(H(),U()),t&&U()},[t]),(0,l.useEffect)(()=>{if(p?.config&&Array.isArray(p.config)&&0===O.length){let e=p.config.find(e=>"9Router"===e.name);e?.models?.length>0&&T(e.models.map(e=>e.id))}},[p]);let U=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&E(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}},D=async e=>{try{let t=k&&k.trim()||c?k:"sk_9router";await fetch("/api/cli-tools/copilot-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:F(),apiKey:t,models:e})})}catch(e){console.log("Error saving models:",e)}},K=(()=>{if(!p)return null;if(!p.has9Router)return"not_configured";let e=p.currentUrl||"";return e.includes("localhost")||e.includes("127.0.0.1")||e.includes(i)?"configured":"other"})(),F=()=>{let e=S||i;return e.endsWith("/v1")?e:`${e}/v1`},q=k&&!o.some(e=>e.key===k),H=async()=>{f(!0);try{let e=await fetch("/api/cli-tools/copilot-settings"),t=await e.json();h(t)}catch(e){h({error:e.message})}finally{f(!1)}},B=async()=>{b(!0),w(null);try{let e=k&&k.trim()||c?k:"sk_9router",t=await fetch("/api/cli-tools/copilot-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:F(),apiKey:e,models:O})}),s=await t.json();t.ok?(w({type:"success",text:s.message||"Settings applied! Reload VS Code."}),H()):w({type:"error",text:s.error||"Failed to apply settings"})}catch(e){w({type:"error",text:e.message})}finally{b(!1)}},J=async()=>{v(!0),w(null);try{let e=await fetch("/api/cli-tools/copilot-settings",{method:"DELETE"}),t=await e.json();e.ok?(w({type:"success",text:"Settings reset successfully!"}),T([]),H()):w({type:"error",text:t.error||"Failed to reset settings"})}catch(e){w({type:"error",text:e.message})}finally{v(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/copilot.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===K&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===K&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===K&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[g&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Copilot config..."})]}),!g&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-blue-500 text-lg",children:"info"}),(0,a.jsxs)("div",{className:"text-xs text-blue-700 dark:text-blue-300",children:[(0,a.jsxs)("p",{className:"font-medium",children:["Writes to ",(0,a.jsx)("code",{className:"px-1 bg-black/5 dark:bg-white/10 rounded",children:"chatLanguageModels.json"})]}),(0,a.jsx)("p",{className:"mt-0.5 opacity-80",children:"Reload VS Code after applying for changes to take effect."})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsx)(z,{baseUrl:F(),apiKey:k,onBaseUrlChange:_,onApiKeyChange:C}),(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium text-text-muted",children:"Base URL"}),(0,a.jsx)("input",{type:"text",value:F(),onChange:e=>_(e.target.value),placeholder:"https://.../v1",className:"px-3 py-2 bg-bg-secondary rounded-lg text-sm border border-border focus:outline-none focus:ring-1 focus:ring-primary/50"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium text-text-muted",children:"API Key"}),o.length>0||k?(0,a.jsxs)("select",{value:k,onChange:e=>C(e.target.value),className:"px-3 py-2 bg-bg-secondary rounded-lg text-sm border border-border focus:outline-none focus:ring-1 focus:ring-primary/50",children:[q&&(0,a.jsx)("option",{value:k,children:k}),o.map(e=>(0,a.jsxs)("option",{value:e.key,children:[e.key," (",e.name,")"]},e.id))]}):(0,a.jsx)("span",{className:"text-sm text-text-muted",children:c?"No API keys - Create one in Keys page":"sk_9router (default)"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[(0,a.jsx)("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Models"}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:0===O.length?(0,a.jsx)("span",{className:"text-xs text-text-muted",children:"No models selected"}):O.map(e=>(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border",children:[e,(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),T(t=>t.filter(t=>t!==e))},className:"ml-0.5 hover:text-red-500",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},e))}),(0,a.jsx)("div",{children:(0,a.jsx)("button",{onClick:()=>R(!0),disabled:!d?.length,className:`px-2 py-1 rounded border text-xs transition-colors ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Add Model"})})]})]})]}),N&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===N.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===N.type?"check_circle":"error"}),(0,a.jsx)("span",{children:N.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:B,disabled:0===O.length,loading:y,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:J,disabled:!p?.has9Router,loading:j,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>M(!0),disabled:0===O.length,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:P,onClose:()=>{R(!1),D(I.current)},onSelect:e=>{O.includes(e.value)||T([...O,e.value])},onDeselect:e=>{T(O.filter(t=>t!==e.value))},selectedModel:null,activeProviders:d,modelAliases:A,addedModelValues:O,closeOnSelect:!1,title:"Add Model for GitHub Copilot"}),(0,a.jsx)(r.uR,{isOpen:$,onClose:()=>M(!1),title:"GitHub Copilot - Manual Configuration",configs:(x=k&&k.trim()?k:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",u=F(),[{filename:"~/Library/Application Support/Code/User/chatLanguageModels.json",content:JSON.stringify([{name:"9Router",vendor:"azure",apiKey:x,models:(O.length>0?O:["provider/model-id"]).map(e=>({id:e,name:e,url:`${u}/chat/completions#models.ai.azure.com`,toolCalling:!0,vision:!1,maxInputTokens:128e3,maxOutputTokens:16e3}))}],null,2)}])})]})}function F({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:y}){let b,j,[v,N]=(0,l.useState)(m||null),[w,k]=(0,l.useState)(!1),[C,S]=(0,l.useState)(!1),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(null),[M,O]=(0,l.useState)(!1),[T,P]=(0,l.useState)(""),[R,I]=(0,l.useState)(""),[U,D]=(0,l.useState)(!1),[K,z]=(0,l.useState)({}),[L,q]=(0,l.useState)(!1),[H,B]=(0,l.useState)("");(0,l.useEffect)(()=>{o?.length>0&&!T&&P(o[0].key)},[o,T]),(0,l.useEffect)(()=>{m&&N(m)},[m]),(0,l.useEffect)(()=>{t&&!v&&(Y(),J()),t&&J()},[t]),(0,l.useEffect)(()=>{v?.settings?.openAiModelId&&I(v.settings.openAiModelId)},[v]);let J=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&z(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}},W=v?.installed?v.has9Router?g(v.settings?.openAiBaseUrl||"",{tunnelPublicUrl:h,tailscaleUrl:y})?"configured":"other":"not_configured":null,G=()=>{let e=H||`${i}/v1`;return e.endsWith("/v1")?e:`${e}/v1`},Y=async()=>{k(!0);try{let e=await fetch("/api/cli-tools/cline-settings"),t=await e.json();N(t)}catch(e){N({installed:!1,error:e.message})}finally{k(!1)}},V=async()=>{S(!0),$(null);try{let e=T&&T.trim()||c?T:"sk_9router",t=await fetch("/api/cli-tools/cline-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:G(),apiKey:e,model:R})}),s=await t.json();t.ok?($({type:"success",text:"Settings applied successfully!"}),Y()):$({type:"error",text:s.error||"Failed to apply settings"})}catch(e){$({type:"error",text:e.message})}finally{S(!1)}},Z=async()=>{A(!0),$(null);try{let e=await fetch("/api/cli-tools/cline-settings",{method:"DELETE"}),t=await e.json();e.ok?($({type:"success",text:"Settings reset successfully!"}),I(""),Y()):$({type:"error",text:t.error||"Failed to reset settings"})}catch(e){$({type:"error",text:e.message})}finally{A(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/cline.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===W&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===W&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===W&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[w&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Cline..."})]}),!w&&v&&!v.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Cline not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>q(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>O(!M),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:M?"expand_less":"help"}),M?"Hide":"How to Install"]})]})]}),M&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsx)("div",{className:"space-y-3 text-sm",children:(0,a.jsxs)("p",{className:"text-text-muted",children:["Install Cline VS Code extension or CLI from ",(0,a.jsx)("a",{className:"text-primary underline",href:"https://docs.cline.bot/",target:"_blank",rel:"noreferrer",children:"docs.cline.bot"}),"."]})})]})]}),!w&&v?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:H||H||`${i}/v1`,onChange:B,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:f,tailscaleUrl:y})]}),v?.settings?.openAiBaseUrl&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:v.settings.openAiBaseUrl})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:T,onChange:P,apiKeys:o,cloudEnabled:c})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:R,onChange:e=>I(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),R&&(0,a.jsx)("button",{onClick:()=>I(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>D(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),E&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===E.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===E.type?"check_circle":"error"}),(0,a.jsx)("span",{children:E.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:V,disabled:!T&&c&&o.length>0||!R,loading:C,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:Z,disabled:_,loading:_,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>q(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:U,onClose:()=>D(!1),onSelect:e=>{I(e.value),D(!1)},selectedModel:R,activeProviders:d,modelAliases:K,title:"Select Model for Cline"}),(0,a.jsx)(r.uR,{isOpen:L,onClose:()=>q(!1),title:"Cline - Manual Configuration",configs:(b=T&&T.trim()?T:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.cline/data/globalState.json",content:JSON.stringify({actModeApiProvider:"openai",planModeApiProvider:"openai",openAiBaseUrl:(j=G()).endsWith("/v1")?j.slice(0,-3):j,openAiModelId:R||"provider/model-id",planModeOpenAiModelId:R||"provider/model-id"},null,2)},{filename:"~/.cline/data/secrets.json",content:JSON.stringify({openAiApiKey:b},null,2)}])})]})}function q({tool:e,isExpanded:t,onToggle:s,baseUrl:i,apiKeys:o,activeProviders:d,cloudEnabled:c,initialStatus:m,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:g,tailscaleUrl:f}){let[y,b]=(0,l.useState)(m||null),[j,v]=(0,l.useState)(!1),[N,w]=(0,l.useState)(!1),[k,C]=(0,l.useState)(!1),[S,_]=(0,l.useState)(null),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(""),[O,T]=(0,l.useState)(""),[P,R]=(0,l.useState)(!1),[I,U]=(0,l.useState)({}),[D,K]=(0,l.useState)(!1),[z,L]=(0,l.useState)("");(0,l.useEffect)(()=>{o?.length>0&&!$&&M(o[0].key)},[o,$]),(0,l.useEffect)(()=>{m&&b(m)},[m]),(0,l.useEffect)(()=>{t&&!y&&(J(),F()),t&&F()},[t]);let F=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&U(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}},H=y?.installed?y.has9Router?"configured":"not_configured":null,B=()=>{let e=z||`${i}/v1`;return e.endsWith("/v1")?e:`${e}/v1`},J=async()=>{v(!0);try{let e=await fetch("/api/cli-tools/kilo-settings"),t=await e.json();b(t)}catch(e){b({installed:!1,error:e.message})}finally{v(!1)}},W=async()=>{w(!0),_(null);try{let e=$&&$.trim()||c?$:"sk_9router",t=await fetch("/api/cli-tools/kilo-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:B(),apiKey:e,model:O})}),s=await t.json();t.ok?(_({type:"success",text:"Settings applied successfully!"}),J()):_({type:"error",text:s.error||"Failed to apply settings"})}catch(e){_({type:"error",text:e.message})}finally{w(!1)}},G=async()=>{C(!0),_(null);try{let e=await fetch("/api/cli-tools/kilo-settings",{method:"DELETE"}),t=await e.json();e.ok?(_({type:"success",text:"Settings reset successfully!"}),T(""),J()):_({type:"error",text:t.error||"Failed to reset settings"})}catch(e){_({type:"error",text:e.message})}finally{C(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:"/providers/kilocode.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===H&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===H&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[j&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking Kilo Code..."})]}),!j&&y&&!y.installed&&(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Kilo Code not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-9",children:[(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>K(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:()=>E(!A),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:A?"expand_less":"help"}),A?"Hide":"How to Install"]})]})]}),A&&(0,a.jsxs)("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[(0,a.jsx)("h4",{className:"font-medium mb-3",children:"Installation Guide"}),(0,a.jsxs)("p",{className:"text-sm text-text-muted",children:["Install Kilo Code from ",(0,a.jsx)("a",{className:"text-primary underline",href:"https://kilocode.ai",target:"_blank",rel:"noreferrer",children:"kilocode.ai"})," or VS Code extension marketplace."]})]})]}),!j&&y?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:z||z||`${i}/v1`,onChange:L,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:u,tunnelPublicUrl:h,tailscaleEnabled:g,tailscaleUrl:f})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:$,onChange:M,apiKeys:o,cloudEnabled:c})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:O,onChange:e=>T(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),O&&(0,a.jsx)("button",{onClick:()=>T(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>R(!0),disabled:!d?.length,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${d?.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),S&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===S.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===S.type?"check_circle":"error"}),(0,a.jsx)("span",{children:S.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:W,disabled:!$&&c&&o.length>0||!O,loading:N,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:G,disabled:k,loading:k,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>K(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:P,onClose:()=>R(!1),onSelect:e=>{T(e.value),R(!1)},selectedModel:O,activeProviders:d,modelAliases:I,title:"Select Model for Kilo Code"}),(0,a.jsx)(r.uR,{isOpen:D,onClose:()=>K(!1),title:"Kilo Code - Manual Configuration",configs:[{filename:"~/.local/share/kilo/auth.json",content:JSON.stringify({"openai-compatible":{type:"api-key",apiKey:$&&$.trim()?$:c?"<API_KEY_FROM_DASHBOARD>":"sk_9router",baseUrl:B(),model:O||"provider/model-id"}},null,2)}]})]})}let H="/api/cli-tools/deepseek-tui-settings";function B({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b}){let j,[v,N]=(0,l.useState)(u||null),[w,k]=(0,l.useState)(!1),[C,S]=(0,l.useState)(!1),[_,A]=(0,l.useState)(!1),[E,$]=(0,l.useState)(null),[M,O]=(0,l.useState)(""),[T,P]=(0,l.useState)(""),[R,I]=(0,l.useState)(!1),[U,D]=(0,l.useState)({}),[K,z]=(0,l.useState)(!1),[L,F]=(0,l.useState)(""),q=(0,l.useRef)(!1),J=(()=>{if(!v?.installed)return null;let e=v.settings?.["providers.openai"];return e?.base_url?g(e.base_url,{tunnelPublicUrl:f,tailscaleUrl:b})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!M&&O(d[0].key)},[d,M]),(0,l.useEffect)(()=>{u&&N(u)},[u]),(0,l.useEffect)(()=>{t&&!v&&(G(),W()),t&&W()},[t]);let W=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&D(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(v?.installed&&!q.current){q.current=!0;let e=v.settings?.["providers.openai"];e?.model&&P(e.model)}},[v]);let G=async()=>{k(!0);try{let e=await fetch(H),t=await e.json();N(t)}catch(e){N({installed:!1,error:e.message})}finally{k(!1)}},Y=()=>{let e=L||window.location.origin.replace("://localhost","://127.0.0.1");return e.endsWith("/v1")?e:`${e}/v1`},V=async()=>{S(!0),$(null);try{let e=M?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch(H,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:Y(),apiKey:e,model:T})}),s=await t.json();t.ok?($({type:"success",text:"Settings applied successfully!"}),G()):$({type:"error",text:s.error||"Failed to apply settings"})}catch(e){$({type:"error",text:e.message})}finally{S(!1)}},Z=async()=>{A(!0),$(null);try{let e=await fetch(H,{method:"DELETE"}),t=await e.json();e.ok?($({type:"success",text:"Settings reset successfully!"}),P(""),G()):$({type:"error",text:t.error||"Failed to reset settings"})}catch(e){$({type:"error",text:e.message})}finally{A(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image||"/providers/deepseek-tui.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===J&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[w&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking DeepSeek TUI..."})]}),!w&&v&&!v.installed&&(0,a.jsx)("div",{className:"flex flex-col gap-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"DeepSeek TUI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-1",children:"Install via npm:"}),(0,a.jsx)("code",{className:"block mt-2 p-2 bg-black/20 rounded text-xs font-mono",children:"npm install -g deepseek-tui"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-2",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsx)("div",{className:"flex items-center gap-2 pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>z(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!w&&v?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[e.notes&&e.notes.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-2 mb-2",children:e.notes.map((e,t)=>(0,a.jsxs)("div",{className:`flex items-start gap-2 p-2 rounded text-xs ${"warning"===e.type?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":"error"===e.type?"bg-red-500/10 text-red-600 dark:text-red-400":"bg-blue-500/10 text-blue-600 dark:text-blue-400"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mt-0.5",children:"warning"===e.type?"warning":"error"===e.type?"error":"info"}),(0,a.jsx)("span",{children:e.text})]},t))}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:L||Y(),onChange:F,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b})]}),v?.settings?.["providers.openai"]?.base_url&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:v.settings["providers.openai"].base_url})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:M,onChange:O,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:T,onChange:e=>P(e.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),T&&(0,a.jsx)("button",{onClick:()=>P(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>I(!0),disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]})]}),E&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===E.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===E.type?"check_circle":"error"}),(0,a.jsx)("span",{children:E.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:V,disabled:!T,loading:C,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:Z,disabled:!v?.has9Router,loading:_,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>z(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:R,onClose:()=>I(!1),onSelect:e=>{P(e.value),I(!1)},selectedModel:T,activeProviders:c,modelAliases:U,title:"Select Model for DeepSeek TUI"}),(0,a.jsx)(r.uR,{isOpen:K,onClose:()=>z(!1),title:"DeepSeek TUI - Manual Configuration",configs:(j=M&&M.trim()?M:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.deepseek/config.toml",content:`[providers.openai]
|
|
40
40
|
base_url = "${Y()}"
|
|
41
41
|
api_key = "${j}"
|
|
42
42
|
model = "${T||"provider/model-id"}"
|
|
43
|
-
`}])})]})}function J({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b}){let j,v,[N,w]=(0,l.useState)(u||null),[k,C]=(0,l.useState)(!1),[S,_]=(0,l.useState)(!1),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(null),[O,T]=(0,l.useState)(""),[P,R]=(0,l.useState)(""),[I,U]=(0,l.useState)(!1),[D,K]=(0,l.useState)({}),[z,L]=(0,l.useState)(!1),[F,q]=(0,l.useState)(""),H=(0,l.useRef)(!1),B=(()=>{if(!N?.installed)return null;if(!N?.has9Router)return"not_configured";let e=N.config?.providers?.["9router"];return e?g(e.base_url,{tunnelPublicUrl:f,tailscaleUrl:b})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!O&&T(d[0].key)},[d,O]),(0,l.useEffect)(()=>{u&&w(u)},[u]),(0,l.useEffect)(()=>{t&&!N&&(W(),G()),t&&G()},[t]);let G=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&K(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(N?.installed&&!H.current){H.current=!0;let e=N.config?.providers?.["9router"];if(e){e.default_model&&R(e.default_model);let t=N.envApiKey;t&&d?.some(e=>e.key===t)&&T(t)}}},[N,d]);let W=async()=>{C(!0);try{let e=await fetch("/api/cli-tools/jcode-settings"),t=await e.json();w(t)}catch(e){w({installed:!1,error:e.message})}finally{C(!1)}},Y=()=>window.location.origin.replace("://localhost","://127.0.0.1"),V=()=>{let e=F||Y();return e.endsWith("/v1")?e:`${e}/v1`},Z=async()=>{_(!0),M(null);try{let e=O?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch("/api/cli-tools/jcode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:V(),apiKey:e,models:P?[P]:[]})}),s=await t.json();t.ok?(M({type:"success",text:"Settings applied successfully!"}),W()):M({type:"error",text:s.error||"Failed to apply settings"})}catch(e){M({type:"error",text:e.message})}finally{_(!1)}},Q=async()=>{E(!0),M(null);try{let e=await fetch("/api/cli-tools/jcode-settings",{method:"DELETE"}),t=await e.json();e.ok?(M({type:"success",text:"Settings reset successfully!"}),R(""),T(""),W()):M({type:"error",text:t.error||"Failed to reset settings"})}catch(e){M({type:"error",text:e.message})}finally{E(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image||"/providers/jcode.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===B&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===B&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===B&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[k&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking jcode CLI..."})]}),!k&&N&&!N.installed&&(0,a.jsx)("div",{className:"flex flex-col gap-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"jcode CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-1",children:"Install jcode to enable automatic configuration:"}),(0,a.jsx)("code",{className:"block mt-2 p-2 bg-black/20 rounded text-xs font-mono",children:"curl -fsSL https://raw.githubusercontent.com/1jehuang/jcode/master/scripts/install.sh | bash"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-2",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsx)("div",{className:"flex items-center gap-2 pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>L(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!k&&N?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[e.notes&&e.notes.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-2 mb-2",children:e.notes.map((e,t)=>(0,a.jsxs)("div",{className:`flex items-start gap-2 p-2 rounded text-xs ${"info"===e.type?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"warning"===e.type?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":"bg-gray-500/10 text-text-muted"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mt-0.5",children:"info"===e.type?"info":"warning"===e.type?"warning":"help"}),(0,a.jsx)("span",{children:e.text})]},t))}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:F||((j=F||Y()).endsWith("/v1")?j:`${j}/v1`),onChange:q,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b})]}),N?.config?.providers?.["9router"]?.base_url&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:N.config.providers["9router"].base_url})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:O,onChange:T,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:P,onChange:e=>R(e.target.value),placeholder:"cc/claude-opus-4-7",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),P&&(0,a.jsx)("button",{onClick:()=>R(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>U(!0),disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 p-3 bg-blue-500/5 border border-blue-500/20 rounded-lg",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-blue-600 dark:text-blue-400",children:"Usage:"}),(0,a.jsx)("code",{className:"text-xs font-mono text-text-muted",children:"jcode --provider-profile 9router"}),(0,a.jsxs)("code",{className:"text-xs font-mono text-text-muted",children:["jcode --provider-profile 9router --model ",P||"cc/claude-opus-4-7"]})]})]}),$&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===$.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===$.type?"check_circle":"error"}),(0,a.jsx)("span",{children:$.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:Z,disabled:!P,loading:S,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:Q,disabled:!N?.has9Router,loading:A,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>L(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:I,onClose:()=>U(!1),onSelect:e=>{R(e.value),U(!1)},selectedModel:P,activeProviders:c,modelAliases:D,title:"Select Model for jcode"}),(0,a.jsx)(r.uR,{isOpen:z,onClose:()=>L(!1),title:"jcode - Manual Configuration",configs:(v=O&&O.trim()?O:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.jcode/config.toml",content:`[providers.9router]
|
|
43
|
+
`}])})]})}function J({tool:e,isExpanded:t,onToggle:s,baseUrl:i,hasActiveProviders:o,apiKeys:d,activeProviders:c,cloudEnabled:m,initialStatus:u,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b}){let j,v,[N,w]=(0,l.useState)(u||null),[k,C]=(0,l.useState)(!1),[S,_]=(0,l.useState)(!1),[A,E]=(0,l.useState)(!1),[$,M]=(0,l.useState)(null),[O,T]=(0,l.useState)(""),[P,R]=(0,l.useState)(""),[I,U]=(0,l.useState)(!1),[D,K]=(0,l.useState)({}),[z,L]=(0,l.useState)(!1),[F,q]=(0,l.useState)(""),H=(0,l.useRef)(!1),B=(()=>{if(!N?.installed)return null;if(!N?.has9Router)return"not_configured";let e=N.config?.providers?.["9router"];return e?g(e.base_url,{tunnelPublicUrl:f,tailscaleUrl:b})?"configured":"other":"not_configured"})();(0,l.useEffect)(()=>{d?.length>0&&!O&&T(d[0].key)},[d,O]),(0,l.useEffect)(()=>{u&&w(u)},[u]),(0,l.useEffect)(()=>{t&&!N&&(G(),W()),t&&W()},[t]);let W=async()=>{try{let e=await fetch("/api/models/alias"),t=await e.json();e.ok&&K(t.aliases||{})}catch(e){console.log("Error fetching model aliases:",e)}};(0,l.useEffect)(()=>{if(N?.installed&&!H.current){H.current=!0;let e=N.config?.providers?.["9router"];if(e){e.default_model&&R(e.default_model);let t=N.envApiKey;t&&d?.some(e=>e.key===t)&&T(t)}}},[N,d]);let G=async()=>{C(!0);try{let e=await fetch("/api/cli-tools/jcode-settings"),t=await e.json();w(t)}catch(e){w({installed:!1,error:e.message})}finally{C(!1)}},Y=()=>window.location.origin.replace("://localhost","://127.0.0.1"),V=()=>{let e=F||Y();return e.endsWith("/v1")?e:`${e}/v1`},Z=async()=>{_(!0),M(null);try{let e=O?.trim()||(d?.length>0?d[0].key:null)||(m?null:"sk_9router"),t=await fetch("/api/cli-tools/jcode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:V(),apiKey:e,models:P?[P]:[]})}),s=await t.json();t.ok?(M({type:"success",text:"Settings applied successfully!"}),G()):M({type:"error",text:s.error||"Failed to apply settings"})}catch(e){M({type:"error",text:e.message})}finally{_(!1)}},Q=async()=>{E(!0),M(null);try{let e=await fetch("/api/cli-tools/jcode-settings",{method:"DELETE"}),t=await e.json();e.ok?(M({type:"success",text:"Settings reset successfully!"}),R(""),T(""),G()):M({type:"error",text:t.error||"Failed to reset settings"})}catch(e){M({type:"error",text:e.message})}finally{E(!1)}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:s,children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image||"/providers/jcode.png",alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),"configured"===B&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),"not_configured"===B&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),"other"===B&&(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[k&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-text-muted",children:[(0,a.jsx)("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),(0,a.jsx)("span",{children:"Checking jcode CLI..."})]}),!k&&N&&!N.installed&&(0,a.jsx)("div",{className:"flex flex-col gap-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"jcode CLI not detected locally"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-1",children:"Install jcode to enable automatic configuration:"}),(0,a.jsx)("code",{className:"block mt-2 p-2 bg-black/20 rounded text-xs font-mono",children:"curl -fsSL https://raw.githubusercontent.com/1jehuang/jcode/master/scripts/install.sh | bash"}),(0,a.jsx)("p",{className:"text-sm text-text-muted mt-2",children:"Manual configuration is still available if 9router is deployed on a remote server."})]})]}),(0,a.jsx)("div",{className:"flex items-center gap-2 pl-9",children:(0,a.jsxs)(r.$n,{variant:"secondary",size:"sm",onClick:()=>L(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!k&&N?.installed&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[e.notes&&e.notes.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-2 mb-2",children:e.notes.map((e,t)=>(0,a.jsxs)("div",{className:`flex items-start gap-2 p-2 rounded text-xs ${"info"===e.type?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"warning"===e.type?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":"bg-gray-500/10 text-text-muted"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mt-0.5",children:"info"===e.type?"info":"warning"===e.type?"warning":"help"}),(0,a.jsx)("span",{children:e.text})]},t))}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(x,{value:F||((j=F||Y()).endsWith("/v1")?j:`${j}/v1`),onChange:q,requiresExternalUrl:e.requiresExternalUrl,tunnelEnabled:h,tunnelPublicUrl:f,tailscaleEnabled:y,tailscaleUrl:b})]}),N?.config?.providers?.["9router"]?.base_url&&(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:N.config.providers["9router"].base_url})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)(p,{value:O,onChange:T,apiKeys:d,cloudEnabled:m})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsxs)("div",{className:"relative w-full min-w-0",children:[(0,a.jsx)("input",{type:"text",value:P,onChange:e=>R(e.target.value),placeholder:"cc/claude-opus-4-7",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),P&&(0,a.jsx)("button",{onClick:()=>R(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),(0,a.jsx)("button",{onClick:()=>U(!0),disabled:!o,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${o?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 p-3 bg-blue-500/5 border border-blue-500/20 rounded-lg",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-blue-600 dark:text-blue-400",children:"Usage:"}),(0,a.jsx)("code",{className:"text-xs font-mono text-text-muted",children:"jcode --provider-profile 9router"}),(0,a.jsxs)("code",{className:"text-xs font-mono text-text-muted",children:["jcode --provider-profile 9router --model ",P||"cc/claude-opus-4-7"]})]})]}),$&&(0,a.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${"success"===$.type?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"success"===$.type?"check_circle":"error"}),(0,a.jsx)("span",{children:$.text})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(r.$n,{variant:"primary",size:"sm",onClick:Z,disabled:!P,loading:S,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),(0,a.jsxs)(r.$n,{variant:"outline",size:"sm",onClick:Q,disabled:!N?.has9Router,loading:A,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),(0,a.jsxs)(r.$n,{variant:"ghost",size:"sm",onClick:()=>L(!0),children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),(0,a.jsx)(r.rq,{isOpen:I,onClose:()=>U(!1),onSelect:e=>{R(e.value),U(!1)},selectedModel:P,activeProviders:c,modelAliases:D,title:"Select Model for jcode"}),(0,a.jsx)(r.uR,{isOpen:z,onClose:()=>L(!1),title:"jcode - Manual Configuration",configs:(v=O&&O.trim()?O:m?"<API_KEY_FROM_DASHBOARD>":"sk_9router",[{filename:"~/.jcode/config.toml",content:`[providers.9router]
|
|
44
44
|
type = "openai-compatible"
|
|
45
45
|
base_url = "${V()}"
|
|
46
46
|
auth = "bearer"
|
|
@@ -50,4 +50,4 @@ default_model = "${P||"cc/claude-opus-4-7"}"
|
|
|
50
50
|
requires_api_key = true
|
|
51
51
|
|
|
52
52
|
[[providers.9router.models]]
|
|
53
|
-
id = "${P||"cc/claude-opus-4-7"}"`},{filename:"~/.config/jcode/provider-9router.env",content:`JCODE_9ROUTER_API_KEY="${v}"`}])})]})}let G="http://localhost:20128";function W({apiKeys:e,cloudEnabled:t,onStatusChange:s}){let[n,i]=(0,l.useState)(null),[o,d]=(0,l.useState)(!1),[c,m]=(0,l.useState)(!1),[x,u]=(0,l.useState)(""),[p,h]=(0,l.useState)(()=>e?.[0]?.key||""),[g,f]=(0,l.useState)(null),[y,b]=(0,l.useState)(null),[j,v]=(0,l.useState)(null),[N,w]=(0,l.useState)(G),[k,C]=(0,l.useState)(null),S=n?.isWin===!0,_=S||n?.hasCachedPassword||n?.needsSudoPassword===!1,A=n?.isAdmin!==!1;!A&&(S||n?.hasCachedPassword||n?.needsSudoPassword);let E=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/cli-tools/antigravity-mitm");if(e.ok){let t=await e.json();i(t),t.mitmRouterBaseUrl&&w(t.mitmRouterBaseUrl),s?.(t)}}catch{i({running:!1,certExists:!1,dnsStatus:{}})}},[s]);(0,l.useEffect)(()=>{queueMicrotask(()=>{E()})},[E]);let $=e=>{v(null),n&&(_?M(e,""):(f(e),m(!0),b(null)))},M=async(s,a,l=!1)=>{d(!0),v(null);try{let r;if("trust-cert"===s)r=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"trust-cert",sudoPassword:a})});else if("start"===s){let s=p?.trim()||(e?.length>0?e[0].key:null)||(t?null:"sk_9router");r=await fetch("/api/cli-tools/antigravity-mitm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:s,sudoPassword:a,mitmRouterBaseUrl:N.trim()||G,forceKillPort443:l})})}else r=await fetch("/api/cli-tools/antigravity-mitm",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:a})});if(!r.ok){let e=await r.json().catch(()=>({}));if("PORT_443_BUSY"===e.code&&e.portOwner){m(!1),C({owner:e.portOwner,password:a});return}v(e.error||`Failed to ${s} MITM server`);return}m(!1),u(""),C(null),await E()}catch(e){v(e.message||"Network error")}finally{d(!1),f(null)}},O=()=>{x.trim()?M(g,x):b("Sudo password is required")},T=n?.running;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.Zp,{padding:"sm",className:"border-primary/20 bg-primary/5",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-primary text-[20px]",children:"security"}),(0,a.jsx)("span",{className:"font-semibold text-sm text-text-main",children:"MITM Server"}),T?(0,a.jsx)(r.Ex,{variant:"success",size:"sm",children:"Running"}):(0,a.jsx)(r.Ex,{variant:"default",size:"sm",children:"Stopped"})]}),(0,a.jsx)("div",{className:"flex flex-wrap items-center gap-1 text-xs text-text-muted","data-i18n-skip":"true",children:[{label:"Cert",ok:n?.certExists},{label:"Trusted",ok:n?.certTrusted},{label:"Server",ok:T}].map(({label:e,ok:t})=>(0,a.jsxs)("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded ${t?"text-green-600":"text-text-muted"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:t?"check_circle":"cancel"}),e]},e))})]}),(0,a.jsxs)("div",{className:"px-2 py-2 rounded-lg bg-surface/50 border border-border/50 flex flex-col gap-2",children:[(0,a.jsxs)("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[(0,a.jsx)("span",{className:"font-medium text-text-main",children:"Purpose:"})," Use Antigravity IDE & GitHub Copilot → with ANY provider/model from 9Router"]}),(0,a.jsxs)("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[(0,a.jsx)("span",{className:"font-medium text-text-main",children:"How it works:"})," Antigravity/Copilot IDE request → DNS redirect to localhost:443 → MITM proxy intercepts → 9Router → response to Antigravity/Copilot"]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"9Router Base URL"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("input",{type:"text",value:N,onChange:e=>w(e.target.value),placeholder:G,disabled:T,className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50 disabled:opacity-50"})]}),!T&&(0,a.jsxs)("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("input",{type:"text",list:"mitm-api-keys",value:p,onChange:e=>h(e.target.value),placeholder:t?"Enter or pick API key":"sk_9router (default)",className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50"}),e?.length>0&&(0,a.jsx)("datalist",{id:"mitm-api-keys",children:e.map(e=>(0,a.jsx)("option",{value:e.key,children:e.name||e.key},e.id))})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center","data-i18n-skip":"true",children:[n?.certExists&&!n?.certTrusted&&(0,a.jsxs)("button",{onClick:()=>$("trust-cert"),disabled:o,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-yellow-500/30 bg-yellow-500/10 px-4 py-2 text-xs font-medium text-yellow-600 transition-colors hover:bg-yellow-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"verified_user"}),"Trust Cert"]}),T?(0,a.jsxs)("button",{onClick:()=>$("stop"),disabled:o,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"stop_circle"}),"Stop Server"]}):(0,a.jsxs)("button",{onClick:()=>$("start"),disabled:o||!n||S&&!A,title:S&&!A?"Administrator required":void 0,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/30 bg-primary/10 px-4 py-2 text-xs font-medium text-primary transition-colors hover:bg-primary/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"play_circle"}),"Start Server"]}),T&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Enable DNS per tool below to activate interception"})]}),j&&(0,a.jsxs)("div",{className:"flex items-start gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 dark:text-red-400 border border-red-500/20",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mt-0.5 shrink-0",children:"error"}),(0,a.jsx)("span",{children:j})]}),S&&!A&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 border border-red-500/20",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"shield_lock"}),(0,a.jsx)("span",{children:"Administrator required — restart 9Router as Administrator to use MITM"})]})]})}),c&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[(0,a.jsx)("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Required for SSL certificate and server startup"})]}),(0,a.jsx)(r.pd,{type:"password",placeholder:"Enter sudo password",value:x,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"!==e.key||o||O()}}),y&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),(0,a.jsx)("span",{children:y})]}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,a.jsx)(r.$n,{variant:"ghost",size:"sm",onClick:()=>{m(!1),u(""),b(null)},disabled:o,children:"Cancel"}),(0,a.jsx)(r.$n,{variant:"primary",size:"sm",onClick:O,loading:o,children:"Confirm"})]})]})}),k&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[(0,a.jsx)("h3",{className:"font-semibold text-text-main",children:"Port 443 Already In Use"}),(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 text-xs text-text-muted",children:[(0,a.jsx)("p",{children:"Port 443 is currently used by another process:"}),(0,a.jsxs)("p",{className:"font-mono text-text-main","data-i18n-skip":"true",children:[k.owner.name," (PID ",k.owner.pid,")"]}),(0,a.jsx)("p",{children:"Kill this process to start MITM Server?"})]})]}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,a.jsx)(r.$n,{variant:"ghost",size:"sm",onClick:()=>{C(null),d(!1)},disabled:o,children:"Cancel"}),(0,a.jsx)(r.$n,{variant:"primary",size:"sm",onClick:()=>{M("start",k?.password||"",!0)},loading:o,children:"Kill & Start"})]})]})})]})}var Y=s(40295);function V({tool:e,isExpanded:t,onToggle:s,serverRunning:i,dnsActive:o,hasCachedPassword:d,apiKeys:c,activeProviders:m,hasActiveProviders:x,modelAliases:u={},cloudEnabled:p,onDnsChange:h,tokenSwapActive:g=!1}){let[f,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[v,N]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[C,S]=(0,l.useState)(""),[A,T]=(0,l.useState)(null),[P,R]=(0,l.useState)(null),{currentEditingAlias:I,handleAddMapping:U,handleMappingBlur:D,handleModelMappingChange:K,handleModelSelect:z,handleRemoveMapping:L,handleReorderMapping:F,handleStrategyChange:q,loadSavedMappings:H,mappingFeedback:B,modalOpen:J,modelMappings:G,openModelSelector:W,selectedStrategy:Q,setModalOpen:ee}=function(e){let[t,s]=(0,l.useState)({}),[a,r]=(0,l.useState)("round-robin"),[n,i]=(0,l.useState)(!1),[o,d]=(0,l.useState)(null),[c,m]=(0,l.useState)(null),[x,u]=(0,l.useState)(null),p=(0,l.useCallback)(async()=>{try{let t=await fetch(`/api/cli-tools/antigravity-mitm/alias?tool=${e}`);if(!t.ok)return;let a=await t.json();s(E(a.aliases)),r(O(a.strategy))}catch{}},[e]),h=(0,l.useCallback)(async(t,s)=>{try{await fetch("/api/cli-tools/antigravity-mitm/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:e,mappings:E(t),strategy:O(s)})})}catch{}},[e]),g=(0,l.useCallback)((e,t=null)=>{d(e),m(t),i(!0)},[]),f=(0,l.useCallback)((e,t="")=>{s(s=>$(s,e,t))},[]),y=(0,l.useCallback)((e,t,a)=>{s(s=>M(s,e,t,a))},[]),b=(0,l.useCallback)((e,t,l)=>{s(s=>{let r=Array.isArray(s?.[e])?s[e].length:0,n=function(e,t,s,a){let l=Array.isArray(e?.[t])?[...e[t]]:[];if(s<0||s>=l.length)return e;let r=l.slice(0,s),n=l.slice(s+1),i=Math.max(0,5-r.length-n.length),o=[...r,...String(a||"").split(",").map(e=>e.trim()).filter(Boolean).slice(0,i),...n].slice(0,5);if(0===o.length){let{[t]:s,...a}=e||{};return a}return{...e,[t]:o}}(s,e,t,l),i=Array.isArray(n?.[e])?n[e].length:0,o=String(l||"").split(",").map(e=>e.trim()).filter(Boolean).length;return o>1||i<r?u(i<r?`Max 5 targets per alias. Extra models were ignored for ${e}.`:`Expanded ${o} targets for ${e}.`):u(null),h(n,a),n})},[h,a]),j=(0,l.useCallback)((e,t)=>{s(s=>{let l=function(e,t,s){let a=(Array.isArray(e?.[t])?e[t]:[]).filter((e,t)=>t!==s);if(0===a.length){let{[t]:s,...a}=e||{};return a}return{...e,[t]:a}}(s,e,t);return h(l,a),l})},[h,a]),v=(0,l.useCallback)((e,t,l)=>{s(s=>{let r=function(e,t,s,a){let l=Array.isArray(e?.[t])?[...e[t]]:[];if(s<0||a<0||s>=l.length||a>=l.length||s===a)return e;let[r]=l.splice(s,1);return l.splice(a,0,r),{...e,[t]:l}}(s,e,t,l);return h(r,a),r})},[h,a]),N=(0,l.useCallback)(e=>{o&&!e.isPlaceholder&&(s(t=>{let s=null===c?$(t,o,e.value):M(t,o,c,e.value),l=Array.isArray(t?.[o])?t[o].length:0,r=Array.isArray(s?.[o])?s[o].length:0;return u(null===c&&r===l?`Max 5 targets per alias. Remove one before adding another for ${o}.`:null),h(s,a),s}),i(!1),m(null))},[o,c,h,a]);return{currentEditingAlias:o,currentEditingIndex:c,handleAddMapping:f,handleMappingBlur:b,handleModelMappingChange:y,handleModelSelect:N,handleRemoveMapping:j,handleReorderMapping:v,handleStrategyChange:(0,l.useCallback)(e=>{let t=O(e);r(t),s(e=>(h(e,t),e))},[h]),loadSavedMappings:p,mappingFeedback:x,modalOpen:n,modelMappings:t,openModelSelector:g,selectedStrategy:a,setCurrentEditingIndex:m,setMappingFeedback:u,setModalOpen:i}}(e.id),et=Y.TOOL_HOSTS[e.id]??[],es="u">typeof navigator&&navigator.userAgent?.includes("Windows"),ea="antigravity"===e.id&&!t;(0,l.useEffect)(()=>{t&&H()},[t,H]);let el=()=>{if(!i)return;let e=o?"disable":"enable";es||d?er(e,""):(T(e),k(!0),R(null))},er=async(t,s)=>{y(!0),j(null),N(null);try{let a=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:e.id,action:t,sudoPassword:s})}),l=await a.json().catch(()=>({}));if(!a.ok)throw Error(l.error||`Failed to ${t} DNS`);"enable"===t&&j(`Restart ${e.name} to apply changes`),k(!1),S(""),h?.(l)}catch(e){N(e.message||`Failed to ${t} DNS`)}finally{y(!1),T(null)}},en=()=>{C?er(A,C):R("Sudo password is required")};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3 hover:cursor-pointer",onClick:s,children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image,alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),e.supportsTokenSwap&&(0,a.jsx)("span",{className:"text-[9px] uppercase tracking-wider text-text-muted bg-surface border border-border px-1.5 py-0.5 rounded font-semibold",children:"Mode A"}),i?g?(0,a.jsx)(r.Ex,{variant:"default",size:"sm",children:"Bypassed"}):o?(0,a.jsx)(r.Ex,{variant:"success",size:"sm",children:"Active"}):(0,a.jsx)(r.Ex,{variant:"warning",size:"sm",children:"DNS off"}):(0,a.jsx)(r.Ex,{variant:"default",size:"sm",children:"Server off"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Model routing — remap model IDs in intercepted requests"})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[ea&&(0,a.jsxs)("div",{className:"flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)(X,{compact:!0}),(0,a.jsx)(Z,{dnsActive:o,loading:f,serverRunning:i,onClick:el,compact:!0})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[g&&(0,a.jsxs)("div",{className:"flex items-start gap-2 px-2 py-2 rounded-lg bg-violet-500/5 border border-violet-500/15",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] text-violet-400 mt-0.5 shrink-0",children:"info"}),(0,a.jsx)("p",{className:"text-[11px] text-violet-400",children:"Token Rotation (Mode B) is active — model routing is currently bypassed. Disable Token Rotation to use model routing."})]}),"antigravity"===e.id&&(0,a.jsx)(X,{}),et.length>0&&(0,a.jsxs)("div",{className:"mt-2 rounded-md border border-border bg-surface/50 px-2 py-1.5",children:[(0,a.jsx)("p",{className:"text-[10px] font-medium tracking-wide text-text-main/80 mb-1",children:"Edit hosts file manually to add the following entries:"}),(0,a.jsx)("ul",{className:"list-none space-y-0.5 font-mono text-[10px] text-text-muted break-all",children:et.map(e=>(0,a.jsxs)("li",{children:["127.0.0.1 ",e]},e))})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-0.5 text-[11px] text-text-muted px-1",children:[(0,a.jsxs)("p",{children:["Toggle DNS to redirect ",e.name," traffic through 9Router via MITM."]}),!o&&(0,a.jsx)("p",{className:"text-amber-600 text-[10px] mt-1",children:"⚠️ Enable DNS to edit model mappings"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 items-start",children:[(0,a.jsx)(Z,{dnsActive:o,loading:f,serverRunning:i,onClick:el}),b&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs text-amber-500",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"warning"}),(0,a.jsx)("span",{children:b})]}),v&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),(0,a.jsx)("span",{children:v})]})]}),e.defaultModels?.length>0&&(0,a.jsx)(_,{tool:e,mappings:G,strategy:Q,dnsActive:o,hasActiveProviders:x,onChangeEntry:K,onBlurEntry:D,onOpenSelector:W,onAddEntry:t=>U(t,`${e.id}/model-id`),onRemoveEntry:L,onReorderEntry:F,onChangeStrategy:q,feedback:B}),e.defaultModels?.length===0&&(0,a.jsx)("p",{className:"text-xs text-text-muted px-1",children:"Model mappings will be available soon."})]})]}),w&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[(0,a.jsx)("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Required to modify /etc/hosts and flush DNS cache"})]}),(0,a.jsx)(r.pd,{type:"password",placeholder:"Enter sudo password",value:C,onChange:e=>S(e.target.value),onKeyDown:e=>{"Enter"!==e.key||f||en()}}),P&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),(0,a.jsx)("span",{children:P})]}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,a.jsx)(r.$n,{variant:"ghost",size:"sm",onClick:()=>{k(!1),S(""),R(null)},disabled:f,children:"Cancel"}),(0,a.jsx)(r.$n,{variant:"primary",size:"sm",onClick:en,loading:f,children:"Confirm"})]})]})}),(0,a.jsx)(r.rq,{isOpen:J,onClose:()=>ee(!1),onSelect:z,selectedModel:I?G[I]?.[0]:null,activeProviders:m,modelAliases:u,title:`Add mapped model for ${I}`})]})}function Z({dnsActive:e,loading:t,serverRunning:s,onClick:l,compact:r=!1}){let n=e?"Stop DNS":"Start DNS";return(0,a.jsxs)("button",{type:"button",onClick:l,disabled:!s||t,className:`${r?"px-2.5 py-1.5":"px-4 py-1.5"} rounded-lg border font-medium text-xs flex items-center gap-1.5 transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e?"bg-red-500/10 border-red-500/30 text-red-500 hover:bg-red-500/20":"bg-primary/10 border-primary/30 text-primary hover:bg-primary/20"}`,title:s?n:"MITM server is not running",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[16px] ${t?"animate-spin":""}`,children:t?"progress_activity":e?"stop_circle":"play_circle"}),(0,a.jsx)("span",{className:r?"hidden sm:inline":"",children:t?"Working...":n})]})}let Q=[{id:"antigravity-app",route:"/api/antigravity-app",label:"Close AGYv1",title:"Close Antigravity AGY processes",stoppedTitle:"Antigravity AGY is stopped"},{id:"antigravity-app-v2",route:"/api/antigravity-app-v2",label:"Close AGYv2",title:"Close Antigravity AGYv2 processes",stoppedTitle:"Antigravity AGYv2 is stopped"},{id:"antigravity-ide",route:"/api/antigravity-ide",label:"Close AGY-IDE",title:"Close Antigravity IDE processes",stoppedTitle:"Antigravity IDE is stopped"}];function X({compact:e=!1}){return(0,a.jsx)("div",{className:`flex flex-wrap items-center gap-2 ${e?"":"px-1"}`,children:Q.map(t=>(0,a.jsx)(ee,{target:t,compact:e},t.id))})}function ee({target:e,compact:t=!1}){let[s,r]=(0,l.useState)(null),[n,i]=(0,l.useState)(!1),[o,d]=(0,l.useState)(null),c=(0,l.useCallback)(async({signal:t}={})=>{try{let s=await fetch(e.route,{signal:t});s.ok&&r(await s.json())}catch(e){if(e?.name==="AbortError")return}},[e.route]);(0,l.useEffect)(()=>{let e=new AbortController,t=window.setTimeout(()=>{c({signal:e.signal})},0),s=window.setInterval(()=>{c({signal:e.signal})},5e3);return()=>{e.abort(),window.clearTimeout(t),window.clearInterval(s)}},[c]);let m=async()=>{i(!0),d(null);try{let t=await fetch(e.route,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"close"})}),s=await t.json();d(s),setTimeout(c,1e3)}catch(e){d({success:!1,error:e.message})}i(!1)};return s?.installed?(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("button",{type:"button",onClick:m,disabled:n||!s.running,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium border border-red-500/30 text-red-500 bg-red-500/5 hover:bg-red-500/15 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:s.running?e.title:e.stoppedTitle,children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[14px] ${n?"animate-spin":""}`,children:n?"progress_activity":"close"}),(0,a.jsx)("span",{className:t?"hidden sm:inline":"",children:n?"Closing...":e.label})]}),s&&(0,a.jsxs)("span",{className:"flex items-center gap-1 text-[10px] text-text-muted whitespace-nowrap",children:[(0,a.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${s.running?"bg-green-500":"bg-red-400"}`}),(0,a.jsx)("span",{className:t?"hidden xl:inline":"",children:s.running?"Running":"Stopped"})]}),o&&!n&&!t&&(0,a.jsxs)("span",{className:`text-[10px] ${o.success?"text-green-500":"text-red-400"}`,children:[o.success?"✓":"✗"," ",o.message||o.error]})]}):null}var et=s(98500),es=s.n(et),ea=s(11017),el=s(57294);function er(e){return e?.resetAt&&new Date(e.resetAt).getTime()>Date.now()?e.resetAt:null}function en(e){if(!e||"string"!=typeof e)return e;let t=e.indexOf("@");if(t<=0||t===e.length-1)return e;let s=e.slice(0,t),a=e.slice(t+1);return 1===s.length?`${s[0]}**@${a}`:2===s.length?`${s[0]}**${s[1]}@${a}`:`${s[0]}**${s[s.length-1]}@${a}`}function ei({tool:e,connections:t=[],serverRunning:s,dnsActive:n,onToggle:i,onRefreshConnections:o}){let[d,c]=(0,l.useState)(!1),[m,x]=(0,l.useState)(!1),[u,p]=(0,l.useState)("round-robin"),[h,g]=(0,l.useState)(!1),[f,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(!1),[v,N]=(0,l.useState)(3),[w,k]=(0,l.useState)({}),[C,S]=(0,l.useState)(new Set),[_,A]=(0,l.useState)(new Set),[E,$]=(0,l.useState)(!1),[M,O]=(0,l.useState)({}),T=(0,l.useRef)({}),P=(0,l.useRef)(null),R=(0,l.useRef)({}),[I,U]=(0,l.useState)({}),D=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/settings");if(e.ok){let t=await e.json();c(!!t.tokenSwapEnabled),p(t.tokenSwapStrategy||"round-robin"),y(!!t.tokenSwapMaskEmails),N(t.antigravity503RetryCount??3)}}catch{}},[]);(0,l.useEffect)(()=>{D()},[D]),(0,l.useEffect)(()=>{k(e=>{let s={...e};return t.forEach(e=>{e.id in s||(s[e.id]=null!=e.antigravity503RetryCount?String(e.antigravity503RetryCount):"")}),s})},[t]);let K=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/internal/account-health");if(!e.ok)return;let t=await e.json();U(t.accounts||{})}catch{}},[]),z=(0,l.useCallback)(async(t,s=!1)=>{if(!t||0===t.length)return;let a=Date.now(),l=[],r={};if(t.forEach(e=>{let t=T.current[e.id];!s&&t&&a-t.ts<12e4?r[e.id]={quotas:t.data,error:t.error,loading:!1,accountType:t.accountType||null}:l.push(e)}),Object.keys(r).length>0&&O(e=>({...e,...r})),0===l.length)return;let n={};l.forEach(e=>{n[e.id]={quotas:[],error:null,loading:!0}}),O(e=>({...e,...n})),await Promise.all(l.map(async t=>{try{let s=await fetch(`/api/usage/${t.id}`);if(!s.ok){let e=(await s.json().catch(()=>({}))).error||`HTTP ${s.status}`;T.current[t.id]={data:[],error:e,ts:Date.now(),accountType:null},O(s=>({...s,[t.id]:{quotas:[],error:e,loading:!1,accountType:null}}));return}let a=await s.json(),l=(0,el.W_)(e.tokenSwapProvider||"antigravity",a),r=(0,ea._P)(a);T.current[t.id]={data:l,error:null,ts:Date.now(),accountType:r},O(e=>({...e,[t.id]:{quotas:l,error:null,loading:!1,accountType:r}}))}catch(s){let e=s.message||"Failed";T.current[t.id]={data:[],error:e,ts:Date.now(),accountType:null},O(s=>({...s,[t.id]:{quotas:[],error:e,loading:!1,accountType:null}}))}}))},[e.tokenSwapProvider]);if(!e?.supportsTokenSwap)return null;let L=async()=>{x(!0);let e=!d;try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tokenSwapEnabled:e})})).ok&&(c(e),i?.(e))}catch{}x(!1)},F=async e=>{if(e!==u&&!h){g(!0);try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tokenSwapStrategy:e})})).ok&&p(e)}catch{}g(!1)}},q=async()=>{if(b)return;j(!0);let e=!f;try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tokenSwapMaskEmails:e})})).ok&&y(e)}catch{}j(!1)},H=t.filter(t=>t.provider===e.tokenSwapProvider),B=H.filter(e=>!1!==e.isActive),J=B.length,G=H.map(e=>`${e.id}:${!1===e.isActive?"0":"1"}`).join("|"),W=function(e,t){if(!e||0===e.length)return null;if(1===e.length)return e[0].id;let s=[...e].sort((e,t)=>e.lastUsedAt||t.lastUsedAt?e.lastUsedAt?t.lastUsedAt?new Date(t.lastUsedAt)-new Date(e.lastUsedAt):-1:1:(e.priority||999)-(t.priority||999));if("sticky"===t)return s[0]?.id||null;let a=[...e].sort((e,t)=>e.lastUsedAt||t.lastUsedAt?e.lastUsedAt?t.lastUsedAt?new Date(e.lastUsedAt)-new Date(t.lastUsedAt):1:-1:(e.priority||999)-(t.priority||999));return a[0]?.id||null}(B,u);(0,l.useEffect)(()=>{d&&H.length>0&&z(H)},[d,H.length,G,z]),(0,l.useEffect)(()=>{if(!d||0===J)return;K();let e=setInterval(K,1e4);return()=>clearInterval(e)},[d,J,K]);let Y=s&&n,V=d&&Y&&J>0,Z=e=>{let t=(e=>{let t=M[e];if(!t)return{state:"empty"};if(t.loading)return{state:"loading"};if(t.error)return{state:"error",error:t.error};if(!t.quotas||0===t.quotas.length)return{state:"no-data"};let s=[t.quotas.find(e=>e.modelKey?.includes("claude-sonnet-4-6")||e.name?.toLowerCase().includes("sonnet"))||t.quotas.find(e=>e.name?.toLowerCase().includes("opus"))||t.quotas[0],t.quotas.find(e=>{let t;return t="flash",e.modelKey?.toLowerCase().includes(t)||e.name?.toLowerCase().includes(t)})].filter(Boolean).filter((e,t,s)=>s.findIndex(t=>t.modelKey===e.modelKey&&t.name===e.name)===t).map(e=>({quota:e,pct:e?void 0!==e.remainingPercentage?Math.round(e.remainingPercentage):e.total>0?Math.round((e.total-e.used)/e.total*100):null:null})).filter(({pct:e})=>null!==e);if(0===s.length)return{state:"no-data"};let a=s.map(({quota:e})=>er(e)).filter(Boolean).sort((e,t)=>new Date(e).getTime()-new Date(t).getTime())[0]||[...t.quotas].map(e=>e.resetAt).filter(Boolean).filter(e=>new Date(e).getTime()>Date.now()).sort((e,t)=>new Date(e).getTime()-new Date(t).getTime())[0]||null;return{state:"ready",highlights:s,accountType:t.accountType||null,nextResetAt:a,resetCountdown:(0,el.mO)(a),resetDisplay:(0,el.sQ)(a)}})(e);if(!t||"empty"===t.state)return(0,a.jsx)("span",{className:"text-[10px] text-text-muted",children:"Enable to load quota data"});if("loading"===t.state)return(0,a.jsx)("span",{className:"text-[10px] text-text-muted animate-pulse",children:"Loading quota…"});if("error"===t.state)return(0,a.jsx)("span",{className:"text-[10px] text-red-400",title:t.error,children:"Quota unavailable"});if("no-data"===t.state)return(0,a.jsx)("span",{className:"text-[10px] text-text-muted",children:"No quota data"});let{highlights:s}=t;return(0,a.jsx)("div",{className:"flex flex-col gap-1.5 min-w-0",children:(0,a.jsx)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:s.map(({quota:e,pct:t})=>{let s=er(e),l=(0,el.mO)(s),r=(0,el.sQ)(s);return(0,a.jsxs)("div",{className:"min-w-0 rounded-md border border-border/70 bg-surface/60 px-2 py-1",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)("span",{className:"text-[10px] text-text-muted truncate",children:e.name}),(0,a.jsxs)("span",{className:`text-[10px] font-medium shrink-0 ${t>70?"text-green-500":t>=30?"text-yellow-500":"text-red-500"}`,children:[t,"%"]})]}),(0,a.jsx)("div",{className:"mt-1 h-1.5 rounded-full bg-surface-alt overflow-hidden",children:(0,a.jsx)("div",{className:`h-full rounded-full ${t>70?"bg-green-500":t>=30?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(t,100)}%`}})}),"-"!==l&&r?(0,a.jsxs)("div",{className:"mt-1 text-[9px] text-text-muted/70 truncate",children:["↺ ",(0,a.jsx)("span",{className:"text-text-muted",children:l}),(0,a.jsxs)("span",{className:"opacity-60",children:[" \xb7 ",r]})]}):(0,a.jsx)("div",{className:"mt-1 text-[9px] text-text-muted/50",children:"Reset unavailable"})]},`${e.modelKey||e.name}-${e.name}`)})})})},Q=async(e,t)=>{if(!(!e||C.has(e))){S(t=>new Set([...t,e]));try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&await o?.()}catch{}S(t=>{let s=new Set(t);return s.delete(e),s})}},X=async e=>{!e?.id||_.has(e.id)||E||C.has(e.id)||(A(t=>new Set([...t,e.id])),delete T.current[e.id],await z([e],!0),A(t=>{let s=new Set(t);return s.delete(e.id),s}))},ee=async()=>{E||_.size>0||0===H.length||($(!0),H.forEach(e=>{delete T.current[e.id]}),await z(H,!0),$(!1))},et=async e=>{let t=Math.max(0,Math.min(20,isNaN(e)?3:e));N(t),P.current&&clearTimeout(P.current),P.current=setTimeout(async()=>{try{await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravity503RetryCount:t})})}catch{}},500)},eo=(e,t)=>{if(t)k(t=>({...t,[e]:""})),R.current[e]&&clearTimeout(R.current[e]),fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravity503RetryCount:null})}).catch(()=>{});else{let t=String(v);k(s=>({...s,[e]:t})),fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravity503RetryCount:v})}).catch(()=>{})}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0 rounded-lg bg-violet-500/10",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-violet-400 text-[18px]",children:"swap_horiz"})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:"Token Rotation"}),(0,a.jsx)("span",{className:"text-[9px] uppercase tracking-wider text-text-muted bg-surface border border-border px-1.5 py-0.5 rounded font-semibold",children:"Mode B"}),V?(0,a.jsx)(r.Ex,{variant:"success",size:"sm",children:"Active"}):d?(0,a.jsx)(r.Ex,{variant:"warning",size:"sm",children:"Enabled"}):(0,a.jsx)(r.Ex,{variant:"default",size:"sm",children:"Off"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Rotate auth tokens across pool accounts to bypass per-account quota"})]})]}),(0,a.jsx)("button",{onClick:L,disabled:m,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors shrink-0 ${d?"bg-violet-500":"bg-surface-alt border border-border"} ${m?"opacity-50":"cursor-pointer"}`,title:d?"Disable Token Rotation":"Enable Token Rotation",children:(0,a.jsx)("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform shadow-sm ${d?"translate-x-4":"translate-x-0.5"}`})})]}),d&&(0,a.jsxs)("div",{className:"mt-3 pt-3 border-t border-border/50 flex flex-col gap-3",children:[(0,a.jsxs)("div",{className:"flex items-start gap-2 px-2 py-2 rounded-lg bg-violet-500/5 border border-violet-500/15",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] text-violet-400 mt-0.5 shrink-0",children:"info"}),(0,a.jsxs)("div",{className:"text-[11px] text-text-muted leading-relaxed",children:[(0,a.jsx)("p",{children:"Intercepts Antigravity requests → swaps IDE's auth token with a pool account → auto-retries on 429 quota error with next account in pool."}),(0,a.jsx)("p",{className:"mt-1 text-violet-400/80 font-medium",children:"⚠ When active, Model Routing (Mode A) is bypassed."})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1.5 px-1",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold",children:"Rotation Strategy"}),(0,a.jsxs)("div",{className:"flex gap-1.5",children:[(0,a.jsxs)("button",{onClick:()=>F("round-robin"),disabled:h,className:`flex-1 flex flex-col items-center gap-0.5 px-2 py-2 rounded-lg border text-[11px] font-medium transition-colors ${"round-robin"===u?"border-violet-500/50 bg-violet-500/10 text-violet-400":"border-border bg-surface text-text-muted hover:border-border-alt"} disabled:opacity-50`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"autorenew"}),"Round Robin"]}),(0,a.jsxs)("button",{onClick:()=>F("sticky"),disabled:h,className:`flex-1 flex flex-col items-center gap-0.5 px-2 py-2 rounded-lg border text-[11px] font-medium transition-colors ${"sticky"===u?"border-violet-500/50 bg-violet-500/10 text-violet-400":"border-border bg-surface text-text-muted hover:border-border-alt"} disabled:opacity-50`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"push_pin"}),"Sticky"]})]}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted px-0.5",children:"sticky"===u?"Stays on the same account until its quota is exhausted for the requested model, then switches. Optimizes session-level token cache.":"Chooses the least recently used eligible account first. Each successful request updates that account's last-used time."})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 px-1",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold mb-0.5",children:"Prerequisites"}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[14px] ${s?"text-green-500":"text-red-400"}`,children:s?"check_circle":"cancel"}),(0,a.jsx)("span",{className:s?"text-text-main":"text-text-muted",children:"MITM Server"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[14px] ${n?"text-green-500":"text-red-400"}`,children:n?"check_circle":"cancel"}),(0,a.jsxs)("span",{className:n?"text-text-main":"text-text-muted",children:["DNS redirect",!n&&(0,a.jsx)("span",{className:"text-[10px] text-text-muted ml-1",children:"— enable via Antigravity card above"})]})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 px-1",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-0.5",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold",children:"Pool Accounts"}),(0,a.jsx)("span",{className:"text-[10px] text-text-muted",children:H.length>0?`${J}/${H.length} active`:"none"}),J>1&&(0,a.jsx)("span",{className:"text-[9px] text-text-muted bg-surface border border-border px-1 py-0.5 rounded",children:"round-robin"})]}),H.length>0&&(0,a.jsxs)("button",{onClick:ee,disabled:E||_.size>0,className:"inline-flex items-center gap-1 rounded-md border border-border bg-surface px-2 py-1 text-[10px] font-medium text-text-main hover:border-border-alt hover:bg-surface-alt disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Refresh quotas for all pool accounts, including disabled accounts",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[12px] ${E?"animate-spin":""}`,children:"refresh"}),E?"Refreshing…":"Refresh All"]})]}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted px-0.5",children:"Round robin uses least-recently-used ordering. Accounts with no usage timestamp are tried first, then older timestamps rotate ahead of newer ones."}),(0,a.jsxs)("div",{className:"flex items-center gap-2 px-1.5 py-1.5 rounded-lg border border-border bg-surface-alt/40",children:[(0,a.jsxs)("button",{onClick:q,disabled:b,title:`${f?"Disable":"Enable"} email masking — hides pool account emails in logs and this panel (e.g. ${en("email@gmail.com")})`,className:`flex items-center gap-1.5 flex-1 min-w-0 px-1.5 py-1 rounded-md transition-colors text-left ${b?"opacity-50":"hover:bg-surface-alt cursor-pointer"}`,children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[13px] shrink-0 ${f?"text-violet-400":"text-text-muted"}`,children:"alternate_email"}),(0,a.jsx)("span",{className:`text-[11px] font-medium truncate ${f?"text-violet-300":"text-text-muted"}`,children:"Mask emails"}),(0,a.jsx)("span",{className:`relative inline-flex h-4 w-7 items-center rounded-full transition-colors shrink-0 ml-auto ${f?"bg-violet-500":"bg-surface-alt border border-border"}`,children:(0,a.jsx)("span",{className:`inline-block h-2.5 w-2.5 transform rounded-full bg-white transition-transform shadow-sm ${f?"translate-x-3.5":"translate-x-0.5"}`})})]}),(0,a.jsx)("div",{className:"w-px h-5 bg-border shrink-0"}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",title:'Global 503 retry count (0–20). Retry "high traffic" errors on same account before switching. Each account row can override this.',children:[(0,a.jsx)("span",{className:"text-[11px] text-text-muted whitespace-nowrap",children:"503 retries"}),(0,a.jsx)("input",{type:"number",min:"0",max:"20",step:"1",value:v,onChange:e=>et(parseInt(e.target.value)),className:"w-10 rounded border border-border bg-surface px-1 py-0.5 text-[11px] text-text-main text-center focus:outline-none focus:border-violet-500 transition-colors",title:"Global 503 retry count (0-20). Each account can override this."})]})]}),H.length>0?(0,a.jsxs)(a.Fragment,{children:[H.map(e=>{let t,s=(0,ea.fd)(M[e.id]?.accountType)||(0,ea.fd)(e.accountType)||null;return(0,a.jsxs)("div",{className:`rounded-xl border border-border bg-surface-alt/30 px-3 py-2.5 transition-colors ${!1===e.isActive?"opacity-65":"hover:bg-surface-alt/50"}`,children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[14px] shrink-0 ${!1===e.isActive?"text-text-muted":"text-green-500"}`,children:!1===e.isActive?"pause_circle":"check_circle"}),(0,a.jsx)("span",{className:"text-xs font-medium text-text-main truncate",children:e.email?f?en(e.email):e.email:e.name||e.id.slice(0,16)}),s&&(0,a.jsx)(r.Ex,{variant:"Ultra"===s?"warning":"Pro"===s?"primary":"Plus"===s?"success":"Free"===s?"info":"default",size:"sm",children:s}),W===e.id&&!1!==e.isActive&&(0,a.jsx)("span",{className:"text-[9px] text-violet-300 bg-violet-500/10 border border-violet-500/20 px-1 py-0.5 rounded shrink-0",children:"next"}),(0,a.jsx)(r.Ex,{variant:!1===e.isActive?"default":"success",size:"sm",children:!1===e.isActive?"disabled":"active"})]}),(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-2 flex-wrap text-[10px] text-text-muted",children:[(0,a.jsxs)("span",{children:["Priority #",e.priority??"-"]}),e.lastUsedAt&&(0,a.jsxs)("span",{children:["Last used ",new Date(e.lastUsedAt).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})]}),null!=(t=w[e.id])&&""!==t?(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 rounded bg-violet-500/10 border border-violet-500/20 px-1.5 py-0.5",title:`Custom 503 retry count for this account. Global default: ${v}. Auto-saves. Click ↩ to revert.`,children:[(0,a.jsx)("span",{className:"text-violet-300",children:"503:"}),(0,a.jsx)("input",{type:"number",min:"0",max:"20",step:"1",value:t,onChange:t=>{var s,a;return s=e.id,a=t.target.value,void(k(e=>({...e,[s]:a})),R.current[s]&&clearTimeout(R.current[s]),R.current[s]=setTimeout(async()=>{let e=""===a?null:Math.max(0,Math.min(20,parseInt(a)||0));try{await fetch(`/api/providers/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravity503RetryCount:e})})}catch{}},500))},className:"w-8 rounded border-none bg-transparent text-[10px] text-center text-violet-200 focus:outline-none [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",title:`Custom 503 retry count for this account (global: ${v}). Auto-saves as you type.`,autoFocus:!0}),(0,a.jsx)("button",{onClick:()=>eo(e.id,!0),className:"text-violet-400/70 hover:text-text-muted transition-colors leading-none",title:`Revert to global default (${v})`,children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"undo"})})]}):(0,a.jsxs)("button",{onClick:()=>eo(e.id,!1),className:"inline-flex items-center gap-0.5 rounded px-1.5 py-0.5 text-text-muted hover:bg-surface-alt hover:text-text-main transition-colors",title:`Using global 503 retry count (${v}). Click to set a custom value for this account only.`,children:[(0,a.jsxs)("span",{children:["503: ",v]}),(0,a.jsx)("span",{className:"text-[10px] opacity-60 leading-none",children:"✎"})]})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-3 shrink-0",children:[(0,a.jsxs)("button",{onClick:()=>X(e),disabled:_.has(e.id)||C.has(e.id),className:"inline-flex items-center gap-1 rounded-md border border-border bg-surface px-2 py-1 text-[10px] font-medium text-text-main hover:border-border-alt hover:bg-surface-alt disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Force-refresh quota for this account",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"refresh"}),_.has(e.id)?"…":"Refresh Quota"]}),(0,a.jsx)(r.lM,{size:"sm",checked:!1!==e.isActive,disabled:_.has(e.id)||C.has(e.id),onChange:t=>Q(e.id,t)})]})]}),(0,a.jsxs)("div",{className:"mt-2 pl-6",children:[!1===e.isActive?(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("div",{className:"text-[10px] text-text-muted",children:"Disabled; excluded from token rotation."}),Z(e.id)]}):Z(e.id),(e=>{let t=I[e];if(!t||0===t.length)return null;let s=t.filter(e=>"success"===e.status).length,l=t.filter(e=>"retry_success"===e.status).length,r=t.filter(e=>"fail"===e.status).length;return(0,a.jsxs)("div",{className:"mt-1.5",children:[(0,a.jsx)("div",{className:"flex flex-wrap gap-[2px]",title:`Last ${t.length} call${1!==t.length?"s":""}${s?` \xb7 ${s} ok`:""}${l?` \xb7 ${l} retry`:""}${r?` \xb7 ${r} fail`:""}`,children:t.map((e,t)=>{var s;let l,r,n,i,o=(s=e.ts,l=new Date,(r=new Date(s)).getFullYear()===l.getFullYear()&&r.getMonth()===l.getMonth()&&r.getDate()===l.getDate()),d="success"===e.status?"#22c55e":"fail"===e.status?"#ef4444":e.attempts<=2?"#fb923c":e.attempts<=3?"#f97316":"#ea580c";return(0,a.jsx)("div",{className:`shrink-0 rounded-[1px]${o?" animate-pulse":""}`,style:{width:o?"7px":"6px",height:o?"7px":"6px",backgroundColor:d,opacity:o?1:.45,boxShadow:o?`0 0 5px 1px ${d}`:void 0},title:(n=new Date(e.ts).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"}),i=Number(e.attempts)||1,"success"===e.status?`${n} — ✅ Success`:"fail"===e.status?`${n} — ❌ Failed`:`${n} — 🔄 Success after ${i} attempt${1!==i?"s":""}`)},t)})}),(0,a.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[(0,a.jsxs)("span",{className:"text-[9px] text-text-muted",children:["last ",t.length," call",1!==t.length?"s":""]}),s>0&&(0,a.jsxs)("span",{className:"text-[9px] text-green-500",children:[s," ok"]}),l>0&&(0,a.jsxs)("span",{className:"text-[9px] text-orange-400",children:[l," retry"]}),r>0&&(0,a.jsxs)("span",{className:"text-[9px] text-red-400",children:[r," fail"]})]})]})})(e.email||e.id)]})]},e.id)}),(0,a.jsxs)(es(),{href:"/dashboard/providers",className:"text-[11px] text-primary hover:underline flex items-center gap-1 px-1 mt-1",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"open_in_new"}),"Manage accounts"]})]}):(0,a.jsx)("div",{className:"px-1",children:(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:["No active ",e.name," accounts in pool."," ",(0,a.jsx)(es(),{href:"/dashboard/providers",className:"text-primary hover:underline",children:"Add account →"})]})})]}),!Y&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-amber-500/10 text-amber-600 border border-amber-500/20",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"warning"}),(0,a.jsx)("span",{children:"Start MITM server and enable DNS to activate token rotation"})]})]})]})}function eo({tool:e}){return(0,a.jsx)(es(),{href:"/dashboard/mitm",className:"block",children:(0,a.jsx)(r.Zp,{padding:"sm",className:"overflow-hidden hover:border-primary/50 transition-colors cursor-pointer",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image,alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-purple-500/10 text-purple-600 dark:text-purple-400 rounded-full",children:"MITM"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[20px]",children:"chevron_right"})]})})})}}}]);
|
|
53
|
+
id = "${P||"cc/claude-opus-4-7"}"`},{filename:"~/.config/jcode/provider-9router.env",content:`JCODE_9ROUTER_API_KEY="${v}"`}])})]})}let W="http://localhost:20128";function G({apiKeys:e,cloudEnabled:t,onStatusChange:s}){let[n,i]=(0,l.useState)(null),[o,d]=(0,l.useState)(!1),[c,m]=(0,l.useState)(!1),[x,u]=(0,l.useState)(""),[p,h]=(0,l.useState)(()=>e?.[0]?.key||""),[g,f]=(0,l.useState)(null),[y,b]=(0,l.useState)(null),[j,v]=(0,l.useState)(null),[N,w]=(0,l.useState)(W),[k,C]=(0,l.useState)(null),S=n?.isWin===!0,_=S||n?.hasCachedPassword||n?.needsSudoPassword===!1,A=n?.isAdmin!==!1;!A&&(S||n?.hasCachedPassword||n?.needsSudoPassword);let E=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/cli-tools/antigravity-mitm");if(e.ok){let t=await e.json();i(t),t.mitmRouterBaseUrl&&w(t.mitmRouterBaseUrl),s?.(t)}}catch{i({running:!1,certExists:!1,dnsStatus:{}})}},[s]);(0,l.useEffect)(()=>{queueMicrotask(()=>{E()})},[E]);let $=e=>{v(null),n&&(_?M(e,""):(f(e),m(!0),b(null)))},M=async(s,a,l=!1)=>{d(!0),v(null);try{let r;if("trust-cert"===s)r=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"trust-cert",sudoPassword:a})});else if("start"===s){let s=p?.trim()||(e?.length>0?e[0].key:null)||(t?null:"sk_9router");r=await fetch("/api/cli-tools/antigravity-mitm",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:s,sudoPassword:a,mitmRouterBaseUrl:N.trim()||W,forceKillPort443:l})})}else r=await fetch("/api/cli-tools/antigravity-mitm",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({sudoPassword:a})});if(!r.ok){let e=await r.json().catch(()=>({}));if("PORT_443_BUSY"===e.code&&e.portOwner){m(!1),C({owner:e.portOwner,password:a});return}v(e.error||`Failed to ${s} MITM server`);return}m(!1),u(""),C(null),await E()}catch(e){v(e.message||"Network error")}finally{d(!1),f(null)}},O=()=>{x.trim()?M(g,x):b("Sudo password is required")},T=n?.running;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.Zp,{padding:"sm",className:"border-primary/20 bg-primary/5",children:(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-primary text-[20px]",children:"security"}),(0,a.jsx)("span",{className:"font-semibold text-sm text-text-main",children:"MITM Server"}),T?(0,a.jsx)(r.Ex,{variant:"success",size:"sm",children:"Running"}):(0,a.jsx)(r.Ex,{variant:"default",size:"sm",children:"Stopped"})]}),(0,a.jsx)("div",{className:"flex flex-wrap items-center gap-1 text-xs text-text-muted","data-i18n-skip":"true",children:[{label:"Cert",ok:n?.certExists},{label:"Trusted",ok:n?.certTrusted},{label:"Server",ok:T}].map(({label:e,ok:t})=>(0,a.jsxs)("span",{className:`flex items-center gap-0.5 px-1.5 py-0.5 rounded ${t?"text-green-600":"text-text-muted"}`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:t?"check_circle":"cancel"}),e]},e))})]}),(0,a.jsxs)("div",{className:"px-2 py-2 rounded-lg bg-surface/50 border border-border/50 flex flex-col gap-2",children:[(0,a.jsxs)("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[(0,a.jsx)("span",{className:"font-medium text-text-main",children:"Purpose:"})," Use Antigravity IDE & GitHub Copilot → with ANY provider/model from 9Router"]}),(0,a.jsxs)("p",{className:"text-[11px] text-text-muted leading-relaxed",children:[(0,a.jsx)("span",{className:"font-medium text-text-main",children:"How it works:"})," Antigravity/Copilot IDE request → DNS redirect to localhost:443 → MITM proxy intercepts → 9Router → response to Antigravity/Copilot"]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"9Router Base URL"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("input",{type:"text",value:N,onChange:e=>w(e.target.value),placeholder:W,disabled:T,className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50 disabled:opacity-50"})]}),!T&&(0,a.jsxs)("div",{className:"grid gap-1 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[(0,a.jsx)("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),(0,a.jsx)("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),(0,a.jsx)("input",{type:"text",list:"mitm-api-keys",value:p,onChange:e=>h(e.target.value),placeholder:t?"Enter or pick API key":"sk_9router (default)",className:"flex-1 min-w-0 px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50"}),e?.length>0&&(0,a.jsx)("datalist",{id:"mitm-api-keys",children:e.map(e=>(0,a.jsx)("option",{value:e.key,children:e.name||e.key},e.id))})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center","data-i18n-skip":"true",children:[n?.certExists&&!n?.certTrusted&&(0,a.jsxs)("button",{onClick:()=>$("trust-cert"),disabled:o,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-yellow-500/30 bg-yellow-500/10 px-4 py-2 text-xs font-medium text-yellow-600 transition-colors hover:bg-yellow-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"verified_user"}),"Trust Cert"]}),T?(0,a.jsxs)("button",{onClick:()=>$("stop"),disabled:o,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-2 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"stop_circle"}),"Stop Server"]}):(0,a.jsxs)("button",{onClick:()=>$("start"),disabled:o||!n||S&&!A,title:S&&!A?"Administrator required":void 0,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/30 bg-primary/10 px-4 py-2 text-xs font-medium text-primary transition-colors hover:bg-primary/20 disabled:opacity-50 sm:w-auto sm:py-1.5",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"play_circle"}),"Start Server"]}),T&&(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Enable DNS per tool below to activate interception"})]}),j&&(0,a.jsxs)("div",{className:"flex items-start gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 dark:text-red-400 border border-red-500/20",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] mt-0.5 shrink-0",children:"error"}),(0,a.jsx)("span",{children:j})]}),S&&!A&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600 border border-red-500/20",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"shield_lock"}),(0,a.jsx)("span",{children:"Administrator required — restart 9Router as Administrator to use MITM"})]})]})}),c&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[(0,a.jsx)("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Required for SSL certificate and server startup"})]}),(0,a.jsx)(r.pd,{type:"password",placeholder:"Enter sudo password",value:x,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"!==e.key||o||O()}}),y&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),(0,a.jsx)("span",{children:y})]}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,a.jsx)(r.$n,{variant:"ghost",size:"sm",onClick:()=>{m(!1),u(""),b(null)},disabled:o,children:"Cancel"}),(0,a.jsx)(r.$n,{variant:"primary",size:"sm",onClick:O,loading:o,children:"Confirm"})]})]})}),k&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[(0,a.jsx)("h3",{className:"font-semibold text-text-main",children:"Port 443 Already In Use"}),(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 text-xs text-text-muted",children:[(0,a.jsx)("p",{children:"Port 443 is currently used by another process:"}),(0,a.jsxs)("p",{className:"font-mono text-text-main","data-i18n-skip":"true",children:[k.owner.name," (PID ",k.owner.pid,")"]}),(0,a.jsx)("p",{children:"Kill this process to start MITM Server?"})]})]}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,a.jsx)(r.$n,{variant:"ghost",size:"sm",onClick:()=>{C(null),d(!1)},disabled:o,children:"Cancel"}),(0,a.jsx)(r.$n,{variant:"primary",size:"sm",onClick:()=>{M("start",k?.password||"",!0)},loading:o,children:"Kill & Start"})]})]})})]})}var Y=s(40295);function V({tool:e,isExpanded:t,onToggle:s,serverRunning:i,dnsActive:o,hasCachedPassword:d,apiKeys:c,activeProviders:m,hasActiveProviders:x,modelAliases:u={},cloudEnabled:p,onDnsChange:h,tokenSwapActive:g=!1}){let[f,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[v,N]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[C,S]=(0,l.useState)(""),[A,T]=(0,l.useState)(null),[P,R]=(0,l.useState)(null),{currentEditingAlias:I,handleAddMapping:U,handleMappingBlur:D,handleModelMappingChange:K,handleModelSelect:z,handleRemoveMapping:L,handleReorderMapping:F,handleStrategyChange:q,loadSavedMappings:H,mappingFeedback:B,modalOpen:J,modelMappings:W,openModelSelector:G,selectedStrategy:Q,setModalOpen:ee}=function(e){let[t,s]=(0,l.useState)({}),[a,r]=(0,l.useState)("round-robin"),[n,i]=(0,l.useState)(!1),[o,d]=(0,l.useState)(null),[c,m]=(0,l.useState)(null),[x,u]=(0,l.useState)(null),p=(0,l.useCallback)(async()=>{try{let t=await fetch(`/api/cli-tools/antigravity-mitm/alias?tool=${e}`);if(!t.ok)return;let a=await t.json();s(E(a.aliases)),r(O(a.strategy))}catch{}},[e]),h=(0,l.useCallback)(async(t,s)=>{try{await fetch("/api/cli-tools/antigravity-mitm/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:e,mappings:E(t),strategy:O(s)})})}catch{}},[e]),g=(0,l.useCallback)((e,t=null)=>{d(e),m(t),i(!0)},[]),f=(0,l.useCallback)((e,t="")=>{s(s=>$(s,e,t))},[]),y=(0,l.useCallback)((e,t,a)=>{s(s=>M(s,e,t,a))},[]),b=(0,l.useCallback)((e,t,l)=>{s(s=>{let r=Array.isArray(s?.[e])?s[e].length:0,n=function(e,t,s,a){let l=Array.isArray(e?.[t])?[...e[t]]:[];if(s<0||s>=l.length)return e;let r=l.slice(0,s),n=l.slice(s+1),i=Math.max(0,5-r.length-n.length),o=[...r,...String(a||"").split(",").map(e=>e.trim()).filter(Boolean).slice(0,i),...n].slice(0,5);if(0===o.length){let{[t]:s,...a}=e||{};return a}return{...e,[t]:o}}(s,e,t,l),i=Array.isArray(n?.[e])?n[e].length:0,o=String(l||"").split(",").map(e=>e.trim()).filter(Boolean).length;return o>1||i<r?u(i<r?`Max 5 targets per alias. Extra models were ignored for ${e}.`:`Expanded ${o} targets for ${e}.`):u(null),h(n,a),n})},[h,a]),j=(0,l.useCallback)((e,t)=>{s(s=>{let l=function(e,t,s){let a=(Array.isArray(e?.[t])?e[t]:[]).filter((e,t)=>t!==s);if(0===a.length){let{[t]:s,...a}=e||{};return a}return{...e,[t]:a}}(s,e,t);return h(l,a),l})},[h,a]),v=(0,l.useCallback)((e,t,l)=>{s(s=>{let r=function(e,t,s,a){let l=Array.isArray(e?.[t])?[...e[t]]:[];if(s<0||a<0||s>=l.length||a>=l.length||s===a)return e;let[r]=l.splice(s,1);return l.splice(a,0,r),{...e,[t]:l}}(s,e,t,l);return h(r,a),r})},[h,a]),N=(0,l.useCallback)(e=>{o&&!e.isPlaceholder&&(s(t=>{let s=null===c?$(t,o,e.value):M(t,o,c,e.value),l=Array.isArray(t?.[o])?t[o].length:0,r=Array.isArray(s?.[o])?s[o].length:0;return u(null===c&&r===l?`Max 5 targets per alias. Remove one before adding another for ${o}.`:null),h(s,a),s}),i(!1),m(null))},[o,c,h,a]);return{currentEditingAlias:o,currentEditingIndex:c,handleAddMapping:f,handleMappingBlur:b,handleModelMappingChange:y,handleModelSelect:N,handleRemoveMapping:j,handleReorderMapping:v,handleStrategyChange:(0,l.useCallback)(e=>{let t=O(e);r(t),s(e=>(h(e,t),e))},[h]),loadSavedMappings:p,mappingFeedback:x,modalOpen:n,modelMappings:t,openModelSelector:g,selectedStrategy:a,setCurrentEditingIndex:m,setMappingFeedback:u,setModalOpen:i}}(e.id),et=Y.TOOL_HOSTS[e.id]??[],es="u">typeof navigator&&navigator.userAgent?.includes("Windows"),ea="antigravity"===e.id&&!t;(0,l.useEffect)(()=>{t&&H()},[t,H]);let el=()=>{if(!i)return;let e=o?"disable":"enable";es||d?er(e,""):(T(e),k(!0),R(null))},er=async(t,s)=>{y(!0),j(null),N(null);try{let a=await fetch("/api/cli-tools/antigravity-mitm",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:e.id,action:t,sudoPassword:s})}),l=await a.json().catch(()=>({}));if(!a.ok)throw Error(l.error||`Failed to ${t} DNS`);"enable"===t&&j(`Restart ${e.name} to apply changes`),k(!1),S(""),h?.(l)}catch(e){N(e.message||`Failed to ${t} DNS`)}finally{y(!1),T(null)}},en=()=>{C?er(A,C):R("Sudo password is required")};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3 hover:cursor-pointer",onClick:s,children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image,alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),e.supportsTokenSwap&&(0,a.jsx)("span",{className:"text-[9px] uppercase tracking-wider text-text-muted bg-surface border border-border px-1.5 py-0.5 rounded font-semibold",children:"Mode A"}),i?g?(0,a.jsx)(r.Ex,{variant:"default",size:"sm",children:"Bypassed"}):o?(0,a.jsx)(r.Ex,{variant:"success",size:"sm",children:"Active"}):(0,a.jsx)(r.Ex,{variant:"warning",size:"sm",children:"DNS off"}):(0,a.jsx)(r.Ex,{variant:"default",size:"sm",children:"Server off"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Model routing — remap model IDs in intercepted requests"})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[ea&&(0,a.jsxs)("div",{className:"flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)(X,{compact:!0}),(0,a.jsx)(Z,{dnsActive:o,loading:f,serverRunning:i,onClick:el,compact:!0})]}),(0,a.jsx)("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${t?"rotate-180":""}`,children:"expand_more"})]})]}),t&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[g&&(0,a.jsxs)("div",{className:"flex items-start gap-2 px-2 py-2 rounded-lg bg-violet-500/5 border border-violet-500/15",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] text-violet-400 mt-0.5 shrink-0",children:"info"}),(0,a.jsx)("p",{className:"text-[11px] text-violet-400",children:"Token Rotation (Mode B) is active — model routing is currently bypassed. Disable Token Rotation to use model routing."})]}),"antigravity"===e.id&&(0,a.jsx)(X,{}),et.length>0&&(0,a.jsxs)("div",{className:"mt-2 rounded-md border border-border bg-surface/50 px-2 py-1.5",children:[(0,a.jsx)("p",{className:"text-[10px] font-medium tracking-wide text-text-main/80 mb-1",children:"Edit hosts file manually to add the following entries:"}),(0,a.jsx)("ul",{className:"list-none space-y-0.5 font-mono text-[10px] text-text-muted break-all",children:et.map(e=>(0,a.jsxs)("li",{children:["127.0.0.1 ",e]},e))})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-0.5 text-[11px] text-text-muted px-1",children:[(0,a.jsxs)("p",{children:["Toggle DNS to redirect ",e.name," traffic through 9Router via MITM."]}),!o&&(0,a.jsx)("p",{className:"text-amber-600 text-[10px] mt-1",children:"⚠️ Enable DNS to edit model mappings"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 items-start",children:[(0,a.jsx)(Z,{dnsActive:o,loading:f,serverRunning:i,onClick:el}),b&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs text-amber-500",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"warning"}),(0,a.jsx)("span",{children:b})]}),v&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),(0,a.jsx)("span",{children:v})]})]}),e.defaultModels?.length>0&&(0,a.jsx)(_,{tool:e,mappings:W,strategy:Q,dnsActive:o,hasActiveProviders:x,onChangeEntry:K,onBlurEntry:D,onOpenSelector:G,onAddEntry:t=>U(t,`${e.id}/model-id`),onRemoveEntry:L,onReorderEntry:F,onChangeStrategy:q,feedback:B}),e.defaultModels?.length===0&&(0,a.jsx)("p",{className:"text-xs text-text-muted px-1",children:"Model mappings will be available soon."})]})]}),w&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"mx-4 flex w-full max-w-sm flex-col gap-4 rounded-xl border border-border bg-surface p-5 shadow-xl sm:p-6",children:[(0,a.jsx)("h3",{className:"font-semibold text-text-main",children:"Sudo Password Required"}),(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-yellow-500 text-[20px]",children:"warning"}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Required to modify /etc/hosts and flush DNS cache"})]}),(0,a.jsx)(r.pd,{type:"password",placeholder:"Enter sudo password",value:C,onChange:e=>S(e.target.value),onKeyDown:e=>{"Enter"!==e.key||f||en()}}),P&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),(0,a.jsx)("span",{children:P})]}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,a.jsx)(r.$n,{variant:"ghost",size:"sm",onClick:()=>{k(!1),S(""),R(null)},disabled:f,children:"Cancel"}),(0,a.jsx)(r.$n,{variant:"primary",size:"sm",onClick:en,loading:f,children:"Confirm"})]})]})}),(0,a.jsx)(r.rq,{isOpen:J,onClose:()=>ee(!1),onSelect:z,selectedModel:I?W[I]?.[0]:null,activeProviders:m,modelAliases:u,title:`Add mapped model for ${I}`})]})}function Z({dnsActive:e,loading:t,serverRunning:s,onClick:l,compact:r=!1}){let n=e?"Stop DNS":"Start DNS";return(0,a.jsxs)("button",{type:"button",onClick:l,disabled:!s||t,className:`${r?"px-2.5 py-1.5":"px-4 py-1.5"} rounded-lg border font-medium text-xs flex items-center gap-1.5 transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e?"bg-red-500/10 border-red-500/30 text-red-500 hover:bg-red-500/20":"bg-primary/10 border-primary/30 text-primary hover:bg-primary/20"}`,title:s?n:"MITM server is not running",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[16px] ${t?"animate-spin":""}`,children:t?"progress_activity":e?"stop_circle":"play_circle"}),(0,a.jsx)("span",{className:r?"hidden sm:inline":"",children:t?"Working...":n})]})}let Q=[{id:"antigravity-app",route:"/api/antigravity-app",label:"Close AGYv1",title:"Close Antigravity AGY processes",stoppedTitle:"Antigravity AGY is stopped"},{id:"antigravity-app-v2",route:"/api/antigravity-app-v2",label:"Close AGYv2",title:"Close Antigravity AGYv2 processes",stoppedTitle:"Antigravity AGYv2 is stopped"},{id:"antigravity-ide",route:"/api/antigravity-ide",label:"Close AGY-IDE",title:"Close Antigravity IDE processes",stoppedTitle:"Antigravity IDE is stopped"}];function X({compact:e=!1}){return(0,a.jsx)("div",{className:`flex flex-wrap items-center gap-2 ${e?"":"px-1"}`,children:Q.map(t=>(0,a.jsx)(ee,{target:t,compact:e},t.id))})}function ee({target:e,compact:t=!1}){let[s,r]=(0,l.useState)(null),[n,i]=(0,l.useState)(!1),[o,d]=(0,l.useState)(null),c=(0,l.useCallback)(async({signal:t}={})=>{try{let s=await fetch(e.route,{signal:t});s.ok&&r(await s.json())}catch(e){if(e?.name==="AbortError")return}},[e.route]);(0,l.useEffect)(()=>{let e=new AbortController,t=window.setTimeout(()=>{c({signal:e.signal})},0),s=window.setInterval(()=>{c({signal:e.signal})},5e3);return()=>{e.abort(),window.clearTimeout(t),window.clearInterval(s)}},[c]);let m=async()=>{i(!0),d(null);try{let t=await fetch(e.route,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"close"})}),s=await t.json();d(s),setTimeout(c,1e3)}catch(e){d({success:!1,error:e.message})}i(!1)};return s?.installed?(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("button",{type:"button",onClick:m,disabled:n||!s.running,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium border border-red-500/30 text-red-500 bg-red-500/5 hover:bg-red-500/15 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:s.running?e.title:e.stoppedTitle,children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[14px] ${n?"animate-spin":""}`,children:n?"progress_activity":"close"}),(0,a.jsx)("span",{className:t?"hidden sm:inline":"",children:n?"Closing...":e.label})]}),s&&(0,a.jsxs)("span",{className:"flex items-center gap-1 text-[10px] text-text-muted whitespace-nowrap",children:[(0,a.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${s.running?"bg-green-500":"bg-red-400"}`}),(0,a.jsx)("span",{className:t?"hidden xl:inline":"",children:s.running?"Running":"Stopped"})]}),o&&!n&&!t&&(0,a.jsxs)("span",{className:`text-[10px] ${o.success?"text-green-500":"text-red-400"}`,children:[o.success?"✓":"✗"," ",o.message||o.error]})]}):null}var et=s(98500),es=s.n(et),ea=s(11017),el=s(57294);function er(e){return e?.resetAt&&new Date(e.resetAt).getTime()>Date.now()?e.resetAt:null}function en(e){if(!e||"string"!=typeof e)return e;let t=e.indexOf("@");if(t<=0||t===e.length-1)return e;let s=e.slice(0,t),a=e.slice(t+1);return 1===s.length?`${s[0]}**@${a}`:2===s.length?`${s[0]}**${s[1]}@${a}`:`${s[0]}**${s[s.length-1]}@${a}`}function ei(e,t=Date.now()){if(!e)return null;let s=[];e.rateLimitedUntil&&s.push({type:"account",until:e.rateLimitedUntil}),Object.entries(e).forEach(([e,t])=>{e.startsWith("modelLock_")&&t&&s.push({type:"model",until:t})});let a=s.map(e=>({...e,untilMs:new Date(e.until).getTime()})).filter(e=>Number.isFinite(e.untilMs)&&e.untilMs>t).sort((e,t)=>e.untilMs-t.untilMs)[0];if(!a)return null;let l=function(e,t=Date.now()){let s=e-t;if(!Number.isFinite(s)||s<=0)return null;let a=Math.ceil(s/1e3),l=Math.floor(a/3600),r=Math.floor(a%3600/60),n=a%60,i=[];return l&&i.push(`${l}h`),(r||l)&&i.push(`${r}m`),!l&&n&&i.push(`${n}s`),0===i.length&&i.push("0s"),i.join(" ")}(a.untilMs,t);return l?{duration:l,title:`${"model"===a.type?"Model":"Account"} cooldown until ${new Date(a.untilMs).toLocaleString()}`}:null}function eo({tool:e,connections:t=[],serverRunning:s,dnsActive:n,onToggle:i,onRefreshConnections:o}){let[d,c]=(0,l.useState)(!1),[m,x]=(0,l.useState)(!1),[u,p]=(0,l.useState)("round-robin"),[h,g]=(0,l.useState)(!1),[f,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(!1),[v,N]=(0,l.useState)(3),[w,k]=(0,l.useState)({}),[C,S]=(0,l.useState)(new Set),[_,A]=(0,l.useState)(new Set),[E,$]=(0,l.useState)(!1),[M,O]=(0,l.useState)({}),T=(0,l.useRef)({}),P=(0,l.useRef)(null),R=(0,l.useRef)({}),[I,U]=(0,l.useState)({}),[D,K]=(0,l.useState)(Date.now()),z=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/settings");if(e.ok){let t=await e.json();c(!!t.tokenSwapEnabled),p(t.tokenSwapStrategy||"round-robin"),y(!!t.tokenSwapMaskEmails),N(t.antigravity503RetryCount??3)}}catch{}},[]);(0,l.useEffect)(()=>{z()},[z]),(0,l.useEffect)(()=>{k(e=>{let s={...e};return t.forEach(e=>{e.id in s||(s[e.id]=null!=e.antigravity503RetryCount?String(e.antigravity503RetryCount):"")}),s})},[t]);let L=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/internal/account-health");if(!e.ok)return;let t=await e.json();U(t.accounts||{})}catch{}},[]),F=(0,l.useCallback)(async(t,s=!1)=>{if(!t||0===t.length)return;let a=Date.now(),l=[],r={};if(t.forEach(e=>{let t=T.current[e.id];!s&&t&&a-t.ts<12e4?r[e.id]={quotas:t.data,error:t.error,loading:!1,accountType:t.accountType||null}:l.push(e)}),Object.keys(r).length>0&&O(e=>({...e,...r})),0===l.length)return;let n={};l.forEach(e=>{n[e.id]={quotas:[],error:null,loading:!0}}),O(e=>({...e,...n})),await Promise.all(l.map(async t=>{try{let s=await fetch(`/api/usage/${t.id}`);if(!s.ok){let e=(await s.json().catch(()=>({}))).error||`HTTP ${s.status}`;T.current[t.id]={data:[],error:e,ts:Date.now(),accountType:null},O(s=>({...s,[t.id]:{quotas:[],error:e,loading:!1,accountType:null}}));return}let a=await s.json(),l=(0,el.W_)(e.tokenSwapProvider||"antigravity",a),r=(0,ea._P)(a);T.current[t.id]={data:l,error:null,ts:Date.now(),accountType:r},O(e=>({...e,[t.id]:{quotas:l,error:null,loading:!1,accountType:r}}))}catch(s){let e=s.message||"Failed";T.current[t.id]={data:[],error:e,ts:Date.now(),accountType:null},O(s=>({...s,[t.id]:{quotas:[],error:e,loading:!1,accountType:null}}))}}))},[e.tokenSwapProvider]);if(!e?.supportsTokenSwap)return null;let q=async()=>{x(!0);let e=!d;try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tokenSwapEnabled:e})})).ok&&(c(e),i?.(e))}catch{}x(!1)},H=async e=>{if(e!==u&&!h){g(!0);try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tokenSwapStrategy:e})})).ok&&p(e)}catch{}g(!1)}},B=async()=>{if(b)return;j(!0);let e=!f;try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tokenSwapMaskEmails:e})})).ok&&y(e)}catch{}j(!1)},J=t.filter(t=>t.provider===e.tokenSwapProvider),W=J.filter(e=>!1!==e.isActive),G=W.length,Y=J.map(e=>e.id).join("|"),V=J.map(e=>{let t=Object.entries(e).filter(([e,t])=>e.startsWith("modelLock_")&&t).map(([e,t])=>`${e}:${t}`).sort().join(",");return`${e.id}:${e.rateLimitedUntil||""}:${t}`}).join("|"),Z=function(e,t){if(!e||0===e.length)return null;if(1===e.length)return e[0].id;let s=[...e].sort((e,t)=>e.lastUsedAt||t.lastUsedAt?e.lastUsedAt?t.lastUsedAt?new Date(t.lastUsedAt)-new Date(e.lastUsedAt):-1:1:(e.priority||999)-(t.priority||999));if("sticky"===t)return s[0]?.id||null;let a=[...e].sort((e,t)=>e.lastUsedAt||t.lastUsedAt?e.lastUsedAt?t.lastUsedAt?new Date(e.lastUsedAt)-new Date(t.lastUsedAt):1:-1:(e.priority||999)-(t.priority||999));return a[0]?.id||null}(W,u);(0,l.useEffect)(()=>{if(!J.some(e=>ei(e)))return;let e=setInterval(()=>K(Date.now()),1e3);return()=>clearInterval(e)},[V]),(0,l.useEffect)(()=>{d&&J.length>0&&F(J)},[d,J.length,Y,F]),(0,l.useEffect)(()=>{if(!d||0===G)return;L();let e=setInterval(L,1e4);return()=>clearInterval(e)},[d,G,L]);let Q=s&&n,X=d&&Q&&G>0,ee=async(e,t)=>{if(!(!e||C.has(e))){S(t=>new Set([...t,e]));try{(await fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok&&await o?.()}catch{}S(t=>{let s=new Set(t);return s.delete(e),s})}},et=async e=>{!e?.id||_.has(e.id)||E||C.has(e.id)||(A(t=>new Set([...t,e.id])),delete T.current[e.id],await F([e],!0),A(t=>{let s=new Set(t);return s.delete(e.id),s}))},ed=async()=>{E||_.size>0||0===J.length||($(!0),J.forEach(e=>{delete T.current[e.id]}),await F(J,!0),$(!1))},ec=async e=>{let t=Math.max(0,Math.min(20,isNaN(e)?3:e));N(t),P.current&&clearTimeout(P.current),P.current=setTimeout(async()=>{try{await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravity503RetryCount:t})})}catch{}},500)},em=(e,t)=>{if(t)k(t=>({...t,[e]:""})),R.current[e]&&clearTimeout(R.current[e]),fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravity503RetryCount:null})}).catch(()=>{});else{let t=String(v);k(s=>({...s,[e]:t})),fetch(`/api/providers/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravity503RetryCount:v})}).catch(()=>{})}};return(0,a.jsxs)(r.Zp,{padding:"xs",className:"overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0 rounded-lg bg-violet-500/10",children:(0,a.jsx)("span",{className:"material-symbols-outlined text-violet-400 text-[18px]",children:"swap_horiz"})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:"Token Rotation"}),(0,a.jsx)("span",{className:"text-[9px] uppercase tracking-wider text-text-muted bg-surface border border-border px-1.5 py-0.5 rounded font-semibold",children:"Mode B"}),X?(0,a.jsx)(r.Ex,{variant:"success",size:"sm",children:"Active"}):d?(0,a.jsx)(r.Ex,{variant:"warning",size:"sm",children:"Enabled"}):(0,a.jsx)(r.Ex,{variant:"default",size:"sm",children:"Off"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted",children:"Rotate auth tokens across pool accounts to bypass per-account quota"})]})]}),(0,a.jsx)("button",{onClick:q,disabled:m,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors shrink-0 ${d?"bg-violet-500":"bg-surface-alt border border-border"} ${m?"opacity-50":"cursor-pointer"}`,title:d?"Disable Token Rotation":"Enable Token Rotation",children:(0,a.jsx)("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform shadow-sm ${d?"translate-x-4":"translate-x-0.5"}`})})]}),d&&(0,a.jsxs)("div",{className:"mt-3 pt-3 border-t border-border/50 flex flex-col gap-3",children:[(0,a.jsxs)("div",{className:"flex items-start gap-2 px-2 py-2 rounded-lg bg-violet-500/5 border border-violet-500/15",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px] text-violet-400 mt-0.5 shrink-0",children:"info"}),(0,a.jsxs)("div",{className:"text-[11px] text-text-muted leading-relaxed",children:[(0,a.jsx)("p",{children:"Intercepts Antigravity requests → swaps IDE's auth token with a pool account → auto-retries on 429 quota error with next account in pool."}),(0,a.jsx)("p",{className:"mt-1 text-violet-400/80 font-medium",children:"⚠ When active, Model Routing (Mode A) is bypassed."})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1.5 px-1",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold",children:"Rotation Strategy"}),(0,a.jsxs)("div",{className:"flex gap-1.5",children:[(0,a.jsxs)("button",{onClick:()=>H("round-robin"),disabled:h,className:`flex-1 flex flex-col items-center gap-0.5 px-2 py-2 rounded-lg border text-[11px] font-medium transition-colors ${"round-robin"===u?"border-violet-500/50 bg-violet-500/10 text-violet-400":"border-border bg-surface text-text-muted hover:border-border-alt"} disabled:opacity-50`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"autorenew"}),"Round Robin"]}),(0,a.jsxs)("button",{onClick:()=>H("sticky"),disabled:h,className:`flex-1 flex flex-col items-center gap-0.5 px-2 py-2 rounded-lg border text-[11px] font-medium transition-colors ${"sticky"===u?"border-violet-500/50 bg-violet-500/10 text-violet-400":"border-border bg-surface text-text-muted hover:border-border-alt"} disabled:opacity-50`,children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"push_pin"}),"Sticky"]})]}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted px-0.5",children:"sticky"===u?"Stays on the same account until its quota is exhausted for the requested model, then switches. Optimizes session-level token cache.":"Chooses the least recently used eligible account first. Each successful request updates that account's last-used time."})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 px-1",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold mb-0.5",children:"Prerequisites"}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[14px] ${s?"text-green-500":"text-red-400"}`,children:s?"check_circle":"cancel"}),(0,a.jsx)("span",{className:s?"text-text-main":"text-text-muted",children:"MITM Server"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[14px] ${n?"text-green-500":"text-red-400"}`,children:n?"check_circle":"cancel"}),(0,a.jsxs)("span",{className:n?"text-text-main":"text-text-muted",children:["DNS redirect",!n&&(0,a.jsx)("span",{className:"text-[10px] text-text-muted ml-1",children:"— enable via Antigravity card above"})]})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 px-1",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-0.5",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold",children:"Pool Accounts"}),(0,a.jsx)("span",{className:"text-[10px] text-text-muted",children:J.length>0?`${G}/${J.length} active`:"none"}),G>1&&(0,a.jsx)("span",{className:"text-[9px] text-text-muted bg-surface border border-border px-1 py-0.5 rounded",children:"round-robin"})]}),J.length>0&&(0,a.jsxs)("button",{onClick:ed,disabled:E||_.size>0,className:"inline-flex items-center gap-1 rounded-md border border-border bg-surface px-2 py-1 text-[10px] font-medium text-text-main hover:border-border-alt hover:bg-surface-alt disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Refresh quotas for all pool accounts, including disabled accounts",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[12px] ${E?"animate-spin":""}`,children:"refresh"}),E?"Refreshing…":"Refresh All"]})]}),(0,a.jsx)("p",{className:"text-[10px] text-text-muted px-0.5",children:"Round robin uses least-recently-used ordering. Accounts with no usage timestamp are tried first, then older timestamps rotate ahead of newer ones."}),(0,a.jsxs)("div",{className:"flex items-center gap-2 px-1.5 py-1.5 rounded-lg border border-border bg-surface-alt/40",children:[(0,a.jsxs)("button",{onClick:B,disabled:b,title:`${f?"Disable":"Enable"} email masking — hides pool account emails in logs and this panel (e.g. ${en("email@gmail.com")})`,className:`flex items-center gap-1.5 flex-1 min-w-0 px-1.5 py-1 rounded-md transition-colors text-left ${b?"opacity-50":"hover:bg-surface-alt cursor-pointer"}`,children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[13px] shrink-0 ${f?"text-violet-400":"text-text-muted"}`,children:"alternate_email"}),(0,a.jsx)("span",{className:`text-[11px] font-medium truncate ${f?"text-violet-300":"text-text-muted"}`,children:"Mask emails"}),(0,a.jsx)("span",{className:`relative inline-flex h-4 w-7 items-center rounded-full transition-colors shrink-0 ml-auto ${f?"bg-violet-500":"bg-surface-alt border border-border"}`,children:(0,a.jsx)("span",{className:`inline-block h-2.5 w-2.5 transform rounded-full bg-white transition-transform shadow-sm ${f?"translate-x-3.5":"translate-x-0.5"}`})})]}),(0,a.jsx)("div",{className:"w-px h-5 bg-border shrink-0"}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",title:'Global 503 retry count (0–20). Retry "high traffic" errors on same account before switching. Each account row can override this.',children:[(0,a.jsx)("span",{className:"text-[11px] text-text-muted whitespace-nowrap",children:"503 retries"}),(0,a.jsx)("input",{type:"number",min:"0",max:"20",step:"1",value:v,onChange:e=>ec(parseInt(e.target.value)),className:"w-10 rounded border border-border bg-surface px-1 py-0.5 text-[11px] text-text-main text-center focus:outline-none focus:border-violet-500 transition-colors",title:"Global 503 retry count (0-20). Each account can override this."})]})]}),J.length>0?(0,a.jsxs)(a.Fragment,{children:[J.map(e=>{let t,s=(0,ea.fd)(M[e.id]?.accountType)||(0,ea.fd)(e.accountType)||null,l=ei(e,D);return(0,a.jsxs)("div",{className:`rounded-xl border border-border bg-surface-alt/30 px-3 py-2.5 transition-colors ${!1===e.isActive?"opacity-65":"hover:bg-surface-alt/50"}`,children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)("span",{className:`material-symbols-outlined text-[14px] shrink-0 ${!1===e.isActive?"text-text-muted":"text-green-500"}`,children:!1===e.isActive?"pause_circle":"check_circle"}),(0,a.jsx)("span",{className:"text-xs font-medium text-text-main truncate",children:e.email?f?en(e.email):e.email:e.name||e.id.slice(0,16)}),s&&(0,a.jsx)(r.Ex,{variant:"Ultra"===s?"warning":"Pro"===s?"primary":"Plus"===s?"success":"Free"===s?"info":"default",size:"sm",children:s}),Z===e.id&&!1!==e.isActive&&(0,a.jsx)("span",{className:"text-[9px] text-violet-300 bg-violet-500/10 border border-violet-500/20 px-1 py-0.5 rounded shrink-0",children:"next"}),(0,a.jsx)("span",{title:!1===e.isActive?"Disabled - excluded from token rotation.":"Included in token rotation.",children:(0,a.jsx)(r.Ex,{variant:!1===e.isActive?"default":"success",size:"sm",children:!1===e.isActive?"disabled":"active"})}),l&&(0,a.jsxs)("span",{className:"text-[9px] font-medium text-amber-300 bg-amber-500/10 border border-amber-500/20 px-1.5 py-0.5 rounded shrink-0",title:l.title,children:["cooldown ",l.duration]})]}),(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-2 flex-wrap text-[10px] text-text-muted",children:[(0,a.jsxs)("span",{children:["Priority #",e.priority??"-"]}),e.lastUsedAt&&(0,a.jsxs)("span",{children:["Last used ",new Date(e.lastUsedAt).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})]}),null!=(t=w[e.id])&&""!==t?(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 rounded bg-violet-500/10 border border-violet-500/20 px-1.5 py-0.5",title:`Custom 503 retry count for this account. Global default: ${v}. Auto-saves. Click ↩ to revert.`,children:[(0,a.jsx)("span",{className:"text-violet-300",children:"503:"}),(0,a.jsx)("input",{type:"number",min:"0",max:"20",step:"1",value:t,onChange:t=>{var s,a;return s=e.id,a=t.target.value,void(k(e=>({...e,[s]:a})),R.current[s]&&clearTimeout(R.current[s]),R.current[s]=setTimeout(async()=>{let e=""===a?null:Math.max(0,Math.min(20,parseInt(a)||0));try{await fetch(`/api/providers/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravity503RetryCount:e})})}catch{}},500))},className:"w-8 rounded border-none bg-transparent text-[10px] text-center text-violet-200 focus:outline-none [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",title:`Custom 503 retry count for this account (global: ${v}). Auto-saves as you type.`,autoFocus:!0}),(0,a.jsx)("button",{onClick:()=>em(e.id,!0),className:"text-violet-400/70 hover:text-text-muted transition-colors leading-none",title:`Revert to global default (${v})`,children:(0,a.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"undo"})})]}):(0,a.jsxs)("button",{onClick:()=>em(e.id,!1),className:"inline-flex items-center gap-0.5 rounded px-1.5 py-0.5 text-text-muted hover:bg-surface-alt hover:text-text-main transition-colors",title:`Using global 503 retry count (${v}). Click to set a custom value for this account only.`,children:[(0,a.jsxs)("span",{children:["503: ",v]}),(0,a.jsx)("span",{className:"text-[10px] opacity-60 leading-none",children:"✎"})]})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-3 shrink-0",children:[(0,a.jsxs)("button",{onClick:()=>et(e),disabled:_.has(e.id)||C.has(e.id),className:"inline-flex items-center gap-1 rounded-md border border-border bg-surface px-2 py-1 text-[10px] font-medium text-text-main hover:border-border-alt hover:bg-surface-alt disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Force-refresh quota for this account",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"refresh"}),_.has(e.id)?"…":"Refresh Quota"]}),(0,a.jsx)(r.lM,{size:"sm",checked:!1!==e.isActive,disabled:_.has(e.id)||C.has(e.id),onChange:t=>ee(e.id,t)})]})]}),(0,a.jsxs)("div",{className:"mt-2 pl-6",children:[(e=>{let t=(e=>{let t=M[e];if(!t)return{state:"empty"};if(t.loading)return{state:"loading"};if(t.error)return{state:"error",error:t.error};if(!t.quotas||0===t.quotas.length)return{state:"no-data"};let s=[t.quotas.find(e=>e.modelKey?.includes("claude-sonnet-4-6")||e.name?.toLowerCase().includes("sonnet"))||t.quotas.find(e=>e.name?.toLowerCase().includes("opus"))||t.quotas[0],t.quotas.find(e=>{let t;return t="flash",e.modelKey?.toLowerCase().includes(t)||e.name?.toLowerCase().includes(t)})].filter(Boolean).filter((e,t,s)=>s.findIndex(t=>t.modelKey===e.modelKey&&t.name===e.name)===t).map(e=>({quota:e,pct:e?void 0!==e.remainingPercentage?Math.round(e.remainingPercentage):e.total>0?Math.round((e.total-e.used)/e.total*100):null:null})).filter(({pct:e})=>null!==e);if(0===s.length)return{state:"no-data"};let a=s.map(({quota:e})=>er(e)).filter(Boolean).sort((e,t)=>new Date(e).getTime()-new Date(t).getTime())[0]||[...t.quotas].map(e=>e.resetAt).filter(Boolean).filter(e=>new Date(e).getTime()>Date.now()).sort((e,t)=>new Date(e).getTime()-new Date(t).getTime())[0]||null;return{state:"ready",highlights:s,accountType:t.accountType||null,nextResetAt:a,resetCountdown:(0,el.mO)(a),resetDisplay:(0,el.sQ)(a)}})(e);if(!t||"empty"===t.state)return(0,a.jsx)("span",{className:"text-[10px] text-text-muted",children:"Enable to load quota data"});if("loading"===t.state)return(0,a.jsx)("span",{className:"text-[10px] text-text-muted animate-pulse",children:"Loading quota…"});if("error"===t.state)return(0,a.jsx)("span",{className:"text-[10px] text-red-400",title:t.error,children:"Quota unavailable"});if("no-data"===t.state)return(0,a.jsx)("span",{className:"text-[10px] text-text-muted",children:"No quota data"});let{highlights:s}=t;return(0,a.jsx)("div",{className:"flex flex-col gap-1.5 min-w-0",children:(0,a.jsx)("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:s.map(({quota:e,pct:t})=>{let s=er(e),l=(0,el.mO)(s),r=(0,el.sQ)(s);return(0,a.jsxs)("div",{className:"min-w-0 rounded-md border border-border/70 bg-surface/60 px-2 py-1",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)("span",{className:"text-[10px] text-text-muted truncate",children:e.name}),(0,a.jsxs)("span",{className:`text-[10px] font-medium shrink-0 ${t>70?"text-green-500":t>=30?"text-yellow-500":"text-red-500"}`,children:[t,"%"]})]}),(0,a.jsx)("div",{className:"mt-1 h-1.5 rounded-full bg-surface-alt overflow-hidden",children:(0,a.jsx)("div",{className:`h-full rounded-full ${t>70?"bg-green-500":t>=30?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(t,100)}%`}})}),"-"!==l&&r?(0,a.jsxs)("div",{className:"mt-1 text-[9px] text-text-muted/70 truncate",children:["↺ ",(0,a.jsx)("span",{className:"text-text-muted",children:l}),(0,a.jsxs)("span",{className:"opacity-60",children:[" \xb7 ",r]})]}):(0,a.jsx)("div",{className:"mt-1 text-[9px] text-text-muted/50",children:"Reset unavailable"})]},`${e.modelKey||e.name}-${e.name}`)})})})})(e.id),(e=>{let t=I[e];if(!t||0===t.length)return null;let s=t.filter(e=>"success"===e.status).length,l=t.filter(e=>"retry_success"===e.status).length,r=t.filter(e=>"fail"===e.status).length;return(0,a.jsxs)("div",{className:"mt-1.5",children:[(0,a.jsx)("div",{className:"flex flex-wrap gap-[2px]",title:`Last ${t.length} call${1!==t.length?"s":""}${s?` \xb7 ${s} ok`:""}${l?` \xb7 ${l} retry`:""}${r?` \xb7 ${r} fail`:""}`,children:t.map((e,t)=>{var s;let l,r,n,i,o=(s=e.ts,l=new Date,(r=new Date(s)).getFullYear()===l.getFullYear()&&r.getMonth()===l.getMonth()&&r.getDate()===l.getDate()),d="success"===e.status?"#22c55e":"fail"===e.status?"#ef4444":e.attempts<=2?"#fb923c":e.attempts<=3?"#f97316":"#ea580c";return(0,a.jsx)("div",{className:`shrink-0 rounded-[1px]${o?" animate-pulse":""}`,style:{width:o?"7px":"6px",height:o?"7px":"6px",backgroundColor:d,opacity:o?1:.45,boxShadow:o?`0 0 5px 1px ${d}`:void 0},title:(n=new Date(e.ts).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"}),i=Number(e.attempts)||1,"success"===e.status?`${n} — ✅ Success`:"fail"===e.status?`${n} — ❌ Failed`:`${n} — 🔄 Success after ${i} attempt${1!==i?"s":""}`)},t)})}),(0,a.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[(0,a.jsxs)("span",{className:"text-[9px] text-text-muted",children:["last ",t.length," call",1!==t.length?"s":""]}),s>0&&(0,a.jsxs)("span",{className:"text-[9px] text-green-500",children:[s," ok"]}),l>0&&(0,a.jsxs)("span",{className:"text-[9px] text-orange-400",children:[l," retry"]}),r>0&&(0,a.jsxs)("span",{className:"text-[9px] text-red-400",children:[r," fail"]})]})]})})(e.email||e.id)]})]},e.id)}),(0,a.jsxs)(es(),{href:"/dashboard/providers",className:"text-[11px] text-primary hover:underline flex items-center gap-1 px-1 mt-1",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"open_in_new"}),"Manage accounts"]})]}):(0,a.jsx)("div",{className:"px-1",children:(0,a.jsxs)("p",{className:"text-xs text-text-muted",children:["No active ",e.name," accounts in pool."," ",(0,a.jsx)(es(),{href:"/dashboard/providers",className:"text-primary hover:underline",children:"Add account →"})]})})]}),!Q&&(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-xs bg-amber-500/10 text-amber-600 border border-amber-500/20",children:[(0,a.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"warning"}),(0,a.jsx)("span",{children:"Start MITM server and enable DNS to activate token rotation"})]})]})]})}function ed({tool:e}){return(0,a.jsx)(es(),{href:"/dashboard/mitm",className:"block",children:(0,a.jsx)(r.Zp,{padding:"sm",className:"overflow-hidden hover:border-primary/50 transition-colors cursor-pointer",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("div",{className:"size-8 flex items-center justify-center shrink-0",children:(0,a.jsx)(n.default,{src:e.image,alt:e.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:e=>{e.target.style.display="none"}})}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h3",{className:"font-medium text-sm",children:e.name}),(0,a.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-purple-500/10 text-purple-600 dark:text-purple-400 rounded-full",children:"MITM"})]}),(0,a.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.description})]})]}),(0,a.jsx)("span",{className:"material-symbols-outlined text-text-muted text-[20px]",children:"chevron_right"})]})})})}}}]);
|