@remodex/rmx 1.0.2
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/AGENTS_INSTALL.md +91 -0
- package/LICENSE +21 -0
- package/README.md +242 -0
- package/assets/architecture.png +0 -0
- package/assets/banner.png +0 -0
- package/assets/claude-code-models.gif +0 -0
- package/assets/codex-app-picker.png +0 -0
- package/bin/ocx.mjs +584 -0
- package/bin/package-main.mjs +9 -0
- package/gui/dist/assets/index-CZqebSPQ.css +1 -0
- package/gui/dist/assets/index-CkETtt7P.js +71 -0
- package/gui/dist/favicon.png +0 -0
- package/gui/dist/fonts/google-sans-cyrillic.woff2 +0 -0
- package/gui/dist/fonts/google-sans-latin.woff2 +0 -0
- package/gui/dist/icons.svg +24 -0
- package/gui/dist/index.html +25 -0
- package/gui/dist/logo.png +0 -0
- package/gui/dist/provider-icons/alibaba-color.svg +1 -0
- package/gui/dist/provider-icons/antigravity-color.svg +1 -0
- package/gui/dist/provider-icons/claude-color.svg +1 -0
- package/gui/dist/provider-icons/cline-color.svg +16 -0
- package/gui/dist/provider-icons/cloudflare-ai-gateway-color.svg +1 -0
- package/gui/dist/provider-icons/commandcode-color.svg +1 -0
- package/gui/dist/provider-icons/copilot-color.svg +1 -0
- package/gui/dist/provider-icons/cursor-color.svg +2 -0
- package/gui/dist/provider-icons/deepseek-color.svg +1 -0
- package/gui/dist/provider-icons/discord.svg +1 -0
- package/gui/dist/provider-icons/firepass-color.svg +1 -0
- package/gui/dist/provider-icons/fireworks-color.svg +1 -0
- package/gui/dist/provider-icons/gemini-color.svg +1 -0
- package/gui/dist/provider-icons/github-copilot-color.svg +1 -0
- package/gui/dist/provider-icons/gitlab-duo-color.svg +1 -0
- package/gui/dist/provider-icons/grok.svg +1 -0
- package/gui/dist/provider-icons/groq-color.svg +1 -0
- package/gui/dist/provider-icons/huggingface-color.svg +1 -0
- package/gui/dist/provider-icons/kimi-color.svg +1 -0
- package/gui/dist/provider-icons/kiro-color.svg +15 -0
- package/gui/dist/provider-icons/lm-studio-color.svg +1 -0
- package/gui/dist/provider-icons/mistral-color.svg +1 -0
- package/gui/dist/provider-icons/moonshot-color.svg +1 -0
- package/gui/dist/provider-icons/nvidia-color.svg +1 -0
- package/gui/dist/provider-icons/ollama-color.svg +1 -0
- package/gui/dist/provider-icons/openai.svg +1 -0
- package/gui/dist/provider-icons/opencode.svg +2 -0
- package/gui/dist/provider-icons/openrouter-color.svg +1 -0
- package/gui/dist/provider-icons/pi.svg +21 -0
- package/gui/dist/provider-icons/qianfan-color.svg +1 -0
- package/gui/dist/provider-icons/qwen-portal-color.svg +1 -0
- package/gui/dist/provider-icons/telegram.svg +1 -0
- package/gui/dist/provider-icons/vercel-ai-gateway-color.svg +1 -0
- package/gui/dist/provider-icons/vllm-color.svg +1 -0
- package/gui/dist/provider-icons/xiaomi-color.svg +1 -0
- package/package.json +118 -0
- package/src/AGENTS.md +28 -0
- package/src/adapters/anthropic-image-guard.ts +251 -0
- package/src/adapters/anthropic-image-normalize.ts +518 -0
- package/src/adapters/anthropic.ts +1205 -0
- package/src/adapters/azure.ts +36 -0
- package/src/adapters/base.ts +83 -0
- package/src/adapters/client-fingerprint.ts +59 -0
- package/src/adapters/command-code.ts +453 -0
- package/src/adapters/cursor/arg-codec.ts +38 -0
- package/src/adapters/cursor/arg-normalize.ts +104 -0
- package/src/adapters/cursor/cursor-errors.ts +165 -0
- package/src/adapters/cursor/discovery.ts +276 -0
- package/src/adapters/cursor/effort-map.ts +139 -0
- package/src/adapters/cursor/exec-policy.ts +88 -0
- package/src/adapters/cursor/framing.ts +250 -0
- package/src/adapters/cursor/gen/agent_pb.ts +15274 -0
- package/src/adapters/cursor/kv-store.ts +52 -0
- package/src/adapters/cursor/live-models.ts +153 -0
- package/src/adapters/cursor/live-smoke-gate.ts +41 -0
- package/src/adapters/cursor/live-transport.ts +1235 -0
- package/src/adapters/cursor/mcp-config.ts +42 -0
- package/src/adapters/cursor/mcp-manager.ts +333 -0
- package/src/adapters/cursor/message-mapper.ts +49 -0
- package/src/adapters/cursor/native-exec-common.ts +59 -0
- package/src/adapters/cursor/native-exec-desktop.ts +184 -0
- package/src/adapters/cursor/native-exec-fs.ts +332 -0
- package/src/adapters/cursor/native-exec-mcp.ts +153 -0
- package/src/adapters/cursor/native-exec-network.ts +43 -0
- package/src/adapters/cursor/native-exec-shell.ts +548 -0
- package/src/adapters/cursor/native-exec-tools.ts +118 -0
- package/src/adapters/cursor/native-exec.ts +604 -0
- package/src/adapters/cursor/protobuf-events.ts +735 -0
- package/src/adapters/cursor/protobuf-request.ts +719 -0
- package/src/adapters/cursor/request-builder.ts +280 -0
- package/src/adapters/cursor/thread-continuity.ts +67 -0
- package/src/adapters/cursor/tool-definitions.ts +621 -0
- package/src/adapters/cursor/transport-retry.ts +132 -0
- package/src/adapters/cursor/transport.ts +57 -0
- package/src/adapters/cursor/types.ts +59 -0
- package/src/adapters/cursor.ts +196 -0
- package/src/adapters/google-antigravity-replay.ts +520 -0
- package/src/adapters/google-antigravity-wire.ts +140 -0
- package/src/adapters/google-errors.ts +85 -0
- package/src/adapters/google-http.ts +100 -0
- package/src/adapters/google-tool-schema.ts +173 -0
- package/src/adapters/google-truncation.ts +24 -0
- package/src/adapters/google-wire-compiler.ts +232 -0
- package/src/adapters/google.ts +859 -0
- package/src/adapters/identity.ts +77 -0
- package/src/adapters/image.ts +23 -0
- package/src/adapters/kiro-constants.ts +16 -0
- package/src/adapters/kiro-errors.ts +208 -0
- package/src/adapters/kiro-events.ts +197 -0
- package/src/adapters/kiro-images.ts +129 -0
- package/src/adapters/kiro-retry.ts +312 -0
- package/src/adapters/kiro-thinking.ts +104 -0
- package/src/adapters/kiro-tool-fallback.ts +36 -0
- package/src/adapters/kiro-tools.ts +224 -0
- package/src/adapters/kiro-truncation.ts +33 -0
- package/src/adapters/kiro-wire.ts +129 -0
- package/src/adapters/kiro.ts +1924 -0
- package/src/adapters/mimo-free.ts +263 -0
- package/src/adapters/openai-chat.ts +1265 -0
- package/src/adapters/openai-responses.ts +1309 -0
- package/src/adapters/run-turn-queue.ts +114 -0
- package/src/adapters/tool-catalog-nudge.ts +71 -0
- package/src/adapters/upstream-http-error.ts +48 -0
- package/src/android-remote/assets.ts +218 -0
- package/src/android-remote/attachments.ts +168 -0
- package/src/android-remote/auth.ts +237 -0
- package/src/android-remote/cloudflare-provisioning.ts +409 -0
- package/src/android-remote/cloudflare-secret.ts +106 -0
- package/src/android-remote/cloudflare-tunnel.ts +488 -0
- package/src/android-remote/cloudflared.ts +286 -0
- package/src/android-remote/codex-app-server.ts +565 -0
- package/src/android-remote/desktop-history-page.ts +936 -0
- package/src/android-remote/desktop-ipc.ts +3643 -0
- package/src/android-remote/desktop-ownership-store.ts +98 -0
- package/src/android-remote/desktop-project-registration.ts +129 -0
- package/src/android-remote/desktop-session-stream.ts +1110 -0
- package/src/android-remote/desktop-workspace-state.ts +443 -0
- package/src/android-remote/file-change-parser.ts +112 -0
- package/src/android-remote/gateway.ts +9108 -0
- package/src/android-remote/mutation-store.ts +299 -0
- package/src/android-remote/projection.ts +1780 -0
- package/src/android-remote/queued-turn-store.ts +248 -0
- package/src/android-remote/session-command-recovery.ts +1384 -0
- package/src/android-remote/store.ts +466 -0
- package/src/android-remote/thread-reconciliation.ts +133 -0
- package/src/android-remote/thread-source-paths.ts +307 -0
- package/src/android-remote/thread-stream.ts +546 -0
- package/src/android-remote/turn-activity.ts +235 -0
- package/src/android-remote/user-message-identity.ts +94 -0
- package/src/bridge.ts +1793 -0
- package/src/chat/inbound.ts +295 -0
- package/src/chat/outbound.ts +821 -0
- package/src/claude/agents-inject.ts +267 -0
- package/src/claude/alias.ts +149 -0
- package/src/claude/auth-detect.ts +229 -0
- package/src/claude/auth-mode-migration.ts +32 -0
- package/src/claude/auth-mode.ts +62 -0
- package/src/claude/context-windows.ts +189 -0
- package/src/claude/desktop-3p-guard.ts +35 -0
- package/src/claude/desktop-3p-paths.ts +84 -0
- package/src/claude/desktop-3p.ts +601 -0
- package/src/claude/desktop-health.ts +26 -0
- package/src/claude/desktop-profile.ts +263 -0
- package/src/claude/gateway-cache.ts +70 -0
- package/src/claude/inbound-debug.ts +163 -0
- package/src/claude/inbound.ts +519 -0
- package/src/claude/model-info.ts +154 -0
- package/src/claude/outbound.ts +898 -0
- package/src/cli/access.ts +108 -0
- package/src/cli/account-api.ts +296 -0
- package/src/cli/account-auth.ts +250 -0
- package/src/cli/account-catalog-refresh.ts +14 -0
- package/src/cli/account-extended.ts +476 -0
- package/src/cli/account-main.ts +317 -0
- package/src/cli/account.ts +297 -0
- package/src/cli/agent-driven.ts +70 -0
- package/src/cli/agent.ts +184 -0
- package/src/cli/catalog-prewarm.ts +27 -0
- package/src/cli/claude-desktop.ts +211 -0
- package/src/cli/claude.ts +302 -0
- package/src/cli/codex-shim-autorestore.ts +45 -0
- package/src/cli/codex-shim-readiness.ts +69 -0
- package/src/cli/combo.ts +124 -0
- package/src/cli/config-command.ts +183 -0
- package/src/cli/debug.ts +228 -0
- package/src/cli/desktop-first-run.ts +25 -0
- package/src/cli/doctor.ts +1022 -0
- package/src/cli/export-command.ts +201 -0
- package/src/cli/help.ts +370 -0
- package/src/cli/index.ts +1565 -0
- package/src/cli/init.ts +224 -0
- package/src/cli/integrations.ts +225 -0
- package/src/cli/interactive-confirm.ts +133 -0
- package/src/cli/internal-dispatch.ts +35 -0
- package/src/cli/launcher-context.ts +77 -0
- package/src/cli/models-runtime.ts +224 -0
- package/src/cli/models.ts +340 -0
- package/src/cli/observe.ts +170 -0
- package/src/cli/opencode.ts +587 -0
- package/src/cli/provider-runtime.ts +179 -0
- package/src/cli/provider.ts +476 -0
- package/src/cli/ready.ts +301 -0
- package/src/cli/route-policy.ts +92 -0
- package/src/cli/runtime-api.ts +328 -0
- package/src/cli/star-prompt.ts +211 -0
- package/src/cli/status-oauth.ts +78 -0
- package/src/cli/status.ts +321 -0
- package/src/cli/system-command.ts +196 -0
- package/src/cli/system-restart-client.ts +146 -0
- package/src/cli/tray-proxy.ts +205 -0
- package/src/cli/v2.ts +200 -0
- package/src/cli.ts +10 -0
- package/src/clients/config-export.ts +1109 -0
- package/src/codex/account-id.ts +34 -0
- package/src/codex/account-label.ts +34 -0
- package/src/codex/account-lifecycle.ts +172 -0
- package/src/codex/account-namespace-match.ts +63 -0
- package/src/codex/account-namespaces.ts +195 -0
- package/src/codex/account-pause.ts +20 -0
- package/src/codex/account-priority.ts +83 -0
- package/src/codex/account-runtime-state.ts +31 -0
- package/src/codex/account-store.ts +517 -0
- package/src/codex/account-usability.ts +40 -0
- package/src/codex/admission.ts +263 -0
- package/src/codex/app-server-processes.ts +799 -0
- package/src/codex/auth-api.ts +2098 -0
- package/src/codex/auth-collision.ts +107 -0
- package/src/codex/auth-context.ts +480 -0
- package/src/codex/autostart-health.ts +156 -0
- package/src/codex/catalog/account-models.ts +67 -0
- package/src/codex/catalog/aggregation.ts +471 -0
- package/src/codex/catalog/bundled.ts +533 -0
- package/src/codex/catalog/effort.ts +432 -0
- package/src/codex/catalog/filesystem-evidence.ts +302 -0
- package/src/codex/catalog/kinds.ts +2 -0
- package/src/codex/catalog/metadata.ts +287 -0
- package/src/codex/catalog/native-models.ts +7 -0
- package/src/codex/catalog/parsing.ts +503 -0
- package/src/codex/catalog/provider-fetch.ts +2267 -0
- package/src/codex/catalog/sync.ts +1606 -0
- package/src/codex/catalog-admission.ts +197 -0
- package/src/codex/catalog-refresh-status.ts +87 -0
- package/src/codex/catalog-write-serialization.ts +242 -0
- package/src/codex/catalog.ts +15 -0
- package/src/codex/codex-write-lock.ts +384 -0
- package/src/codex/convergence-types.ts +593 -0
- package/src/codex/convergence.ts +580 -0
- package/src/codex/custom-model-catalog-migration.ts +176 -0
- package/src/codex/data/upstream-models.json +830 -0
- package/src/codex/desired-state.ts +230 -0
- package/src/codex/desktop-client-processes.ts +521 -0
- package/src/codex/exec-invocation.ts +22 -0
- package/src/codex/features.ts +1091 -0
- package/src/codex/generation.ts +202 -0
- package/src/codex/history-job.ts +347 -0
- package/src/codex/history-lock.ts +242 -0
- package/src/codex/history-migration-guardian.ts +115 -0
- package/src/codex/history-provider.ts +1075 -0
- package/src/codex/history-transition.ts +105 -0
- package/src/codex/history-worker.ts +204 -0
- package/src/codex/home.ts +206 -0
- package/src/codex/inject-coordination.ts +257 -0
- package/src/codex/inject.ts +1857 -0
- package/src/codex/injected-marker.ts +79 -0
- package/src/codex/integration-record.ts +266 -0
- package/src/codex/internal/catalog-writer.ts +203 -0
- package/src/codex/internal/history-writer.ts +105 -0
- package/src/codex/journal.ts +172 -0
- package/src/codex/main-account-cache.ts +56 -0
- package/src/codex/main-account.ts +40 -0
- package/src/codex/management-convergence.ts +114 -0
- package/src/codex/model-cache.ts +267 -0
- package/src/codex/native-main-admission.ts +47 -0
- package/src/codex/native-main-auth-temp.ts +187 -0
- package/src/codex/native-main-claim.ts +167 -0
- package/src/codex/native-main-lock-file.ts +162 -0
- package/src/codex/native-main-owner.ts +329 -0
- package/src/codex/native-profile-api.ts +247 -0
- package/src/codex/native-profile-manager.ts +1531 -0
- package/src/codex/native-profile-processes.ts +121 -0
- package/src/codex/native-profile-recovery.ts +99 -0
- package/src/codex/native-profile-stage-store.ts +387 -0
- package/src/codex/native-profile-startup.ts +348 -0
- package/src/codex/native-profile-store.ts +855 -0
- package/src/codex/native-profile-types.ts +120 -0
- package/src/codex/native-residue.ts +691 -0
- package/src/codex/paths.ts +78 -0
- package/src/codex/plugins-doctor.ts +242 -0
- package/src/codex/pool-rotation.ts +295 -0
- package/src/codex/project-config-warnings.ts +426 -0
- package/src/codex/prompt-journal.ts +311 -0
- package/src/codex/prompt-layers.ts +967 -0
- package/src/codex/prompt-lock.ts +143 -0
- package/src/codex/provider-adoption.ts +242 -0
- package/src/codex/quota-rejection.ts +224 -0
- package/src/codex/quota.ts +494 -0
- package/src/codex/refresh.ts +60 -0
- package/src/codex/routing.ts +1855 -0
- package/src/codex/runtime.ts +659 -0
- package/src/codex/shim.ts +1215 -0
- package/src/codex/subagent-defaults.ts +557 -0
- package/src/codex/subagent-model-fallback.ts +560 -0
- package/src/codex/sync.ts +238 -0
- package/src/codex/transition-state.ts +612 -0
- package/src/codex/upstream-host-health.ts +368 -0
- package/src/codex/user-identity.ts +374 -0
- package/src/codex/warmup.ts +192 -0
- package/src/codex/websocket-registry.ts +100 -0
- package/src/codex/write-coordination.ts +114 -0
- package/src/combos/failover.ts +140 -0
- package/src/combos/index.ts +44 -0
- package/src/combos/request.ts +64 -0
- package/src/combos/resolve.ts +232 -0
- package/src/combos/types.ts +392 -0
- package/src/config.ts +3270 -0
- package/src/generated/model-metadata.ts +144 -0
- package/src/github/star-state.ts +203 -0
- package/src/grok/inject.ts +540 -0
- package/src/grok/inspect.ts +45 -0
- package/src/grok/status.ts +127 -0
- package/src/grok/sync.ts +66 -0
- package/src/images/artifacts.ts +516 -0
- package/src/images/fulfill-video.ts +163 -0
- package/src/images/fulfill.ts +149 -0
- package/src/images/index.ts +4 -0
- package/src/images/loop.ts +922 -0
- package/src/images/plan.ts +133 -0
- package/src/images/synthetic-tool.ts +133 -0
- package/src/images/types.ts +41 -0
- package/src/images/xai-client.ts +141 -0
- package/src/images/xai-video-client.ts +163 -0
- package/src/index.ts +22 -0
- package/src/integrations/config-io.ts +151 -0
- package/src/integrations/journal.ts +315 -0
- package/src/integrations/merge.ts +135 -0
- package/src/integrations/native/ownership-preflight.ts +202 -0
- package/src/integrations/ownership.ts +111 -0
- package/src/integrations/registry.ts +108 -0
- package/src/integrations/serialize.ts +235 -0
- package/src/integrations/state.ts +290 -0
- package/src/integrations/store.ts +103 -0
- package/src/integrations/writer.ts +492 -0
- package/src/lib/abort.ts +146 -0
- package/src/lib/admin-secrets.ts +25 -0
- package/src/lib/admission.ts +83 -0
- package/src/lib/app-owned-memory-stores.ts +173 -0
- package/src/lib/app-owned-memory.ts +265 -0
- package/src/lib/bounded-body.ts +242 -0
- package/src/lib/bun-binary-validator.d.mts +3 -0
- package/src/lib/bun-binary-validator.mjs +18 -0
- package/src/lib/bun-runtime.ts +184 -0
- package/src/lib/bun-stream-caps.ts +127 -0
- package/src/lib/config-ownership.ts +438 -0
- package/src/lib/crash-guard.ts +344 -0
- package/src/lib/debug-log-buffer.ts +83 -0
- package/src/lib/debug-settings.ts +108 -0
- package/src/lib/debug.ts +31 -0
- package/src/lib/destination-policy.ts +316 -0
- package/src/lib/errors.ts +364 -0
- package/src/lib/eventstream-decoder.ts +253 -0
- package/src/lib/gcp-adc.ts +341 -0
- package/src/lib/injection-debug-log.ts +58 -0
- package/src/lib/local-management-attestation.ts +51 -0
- package/src/lib/open-url.ts +25 -0
- package/src/lib/pinned-http.ts +182 -0
- package/src/lib/privacy.ts +20 -0
- package/src/lib/process-control.ts +168 -0
- package/src/lib/provider-environment.ts +470 -0
- package/src/lib/provider-outbound.ts +203 -0
- package/src/lib/provider-url.ts +14 -0
- package/src/lib/proxy-env.ts +18 -0
- package/src/lib/redact.ts +510 -0
- package/src/lib/remodex-home.ts +616 -0
- package/src/lib/retry-after.ts +55 -0
- package/src/lib/service-secrets.ts +178 -0
- package/src/lib/shadow-call.ts +54 -0
- package/src/lib/sidecar-tracker.ts +52 -0
- package/src/lib/sse-decoder.ts +364 -0
- package/src/lib/state-store-registrations.ts +109 -0
- package/src/lib/state-store-sweeper.ts +184 -0
- package/src/lib/system-restart-contract.ts +73 -0
- package/src/lib/test-home-guard.ts +98 -0
- package/src/lib/token-estimate.ts +69 -0
- package/src/lib/translator-budget.ts +366 -0
- package/src/lib/upstream-reachability.ts +91 -0
- package/src/lib/upstream-retry.ts +508 -0
- package/src/lib/win-exec.ts +115 -0
- package/src/lib/win-paths.ts +68 -0
- package/src/lib/windows-elevation.ts +705 -0
- package/src/lib/windows-secret-acl.ts +817 -0
- package/src/lib/windows-user-principal.ts +283 -0
- package/src/lib/winsw.ts +402 -0
- package/src/model-sources.ts +73 -0
- package/src/oauth/anthropic-routing.ts +594 -0
- package/src/oauth/anthropic.ts +177 -0
- package/src/oauth/callback-server.ts +294 -0
- package/src/oauth/chatgpt.ts +150 -0
- package/src/oauth/command-code.ts +239 -0
- package/src/oauth/cursor.ts +231 -0
- package/src/oauth/github-copilot.ts +428 -0
- package/src/oauth/google-antigravity.ts +230 -0
- package/src/oauth/health.ts +443 -0
- package/src/oauth/index.ts +1280 -0
- package/src/oauth/key-providers.ts +128 -0
- package/src/oauth/kimi.ts +213 -0
- package/src/oauth/kiro-credentials.ts +726 -0
- package/src/oauth/kiro.ts +621 -0
- package/src/oauth/local-token-detect.ts +121 -0
- package/src/oauth/log.ts +48 -0
- package/src/oauth/login-cli.ts +163 -0
- package/src/oauth/pkce.ts +15 -0
- package/src/oauth/store.ts +655 -0
- package/src/oauth/token-guardian.ts +309 -0
- package/src/oauth/types.ts +62 -0
- package/src/oauth/xai.ts +241 -0
- package/src/providers/alibaba-region-backup.ts +75 -0
- package/src/providers/alibaba-region-migration.ts +156 -0
- package/src/providers/alibaba-region-startup.ts +36 -0
- package/src/providers/antigravity-models.ts +317 -0
- package/src/providers/api-keys.ts +140 -0
- package/src/providers/base-url-choices.ts +64 -0
- package/src/providers/codex-capacity.ts +288 -0
- package/src/providers/command-code-efforts.ts +85 -0
- package/src/providers/context-cap.ts +73 -0
- package/src/providers/derive.ts +451 -0
- package/src/providers/free-directory.ts +187 -0
- package/src/providers/github-copilot-transport.ts +56 -0
- package/src/providers/google-vertex-location.ts +14 -0
- package/src/providers/key-failover.ts +271 -0
- package/src/providers/kiro-models.ts +67 -0
- package/src/providers/label.ts +19 -0
- package/src/providers/model-discovery-limits.ts +16 -0
- package/src/providers/model-discovery.ts +361 -0
- package/src/providers/openai-sidecar.ts +235 -0
- package/src/providers/openai-tier-startup.ts +27 -0
- package/src/providers/openai-tiers.ts +301 -0
- package/src/providers/openai-virtual-models.ts +83 -0
- package/src/providers/openrouter-routing.ts +102 -0
- package/src/providers/provider-id-rewrite.ts +179 -0
- package/src/providers/quota.ts +1942 -0
- package/src/providers/reasoning-capabilities.ts +336 -0
- package/src/providers/registry.ts +2375 -0
- package/src/providers/slug-codec.ts +74 -0
- package/src/providers/xai-transport.ts +149 -0
- package/src/reasoning-effort.ts +243 -0
- package/src/responses/compaction.ts +124 -0
- package/src/responses/hosted-tool-policy.ts +9 -0
- package/src/responses/parser.ts +714 -0
- package/src/responses/reasoning-envelope.ts +60 -0
- package/src/responses/reasoning-replay-cache.ts +106 -0
- package/src/responses/schema.ts +159 -0
- package/src/responses/spill-store.ts +431 -0
- package/src/responses/state.ts +1039 -0
- package/src/responses/tool-groups.ts +19 -0
- package/src/router.ts +802 -0
- package/src/routing/analytics.ts +377 -0
- package/src/routing/capability.ts +205 -0
- package/src/routing/cost.ts +77 -0
- package/src/routing/evaluator.ts +444 -0
- package/src/routing/health.ts +401 -0
- package/src/routing/history/cursor.ts +43 -0
- package/src/routing/history/indexer.ts +605 -0
- package/src/routing/history/schema.ts +72 -0
- package/src/routing/profile-namespace.ts +15 -0
- package/src/routing/profile.ts +424 -0
- package/src/routing/quota.ts +145 -0
- package/src/routing/request-evidence.ts +45 -0
- package/src/routing/trace.ts +686 -0
- package/src/server/adapter-resolve.ts +83 -0
- package/src/server/auth-cors.ts +606 -0
- package/src/server/chat-completions.ts +379 -0
- package/src/server/claude-messages.ts +980 -0
- package/src/server/effort-policy.ts +251 -0
- package/src/server/github-copilot-responses-repair.ts +338 -0
- package/src/server/gui-static.ts +152 -0
- package/src/server/image-retry.ts +42 -0
- package/src/server/images.ts +485 -0
- package/src/server/index.ts +1633 -0
- package/src/server/lifecycle.ts +482 -0
- package/src/server/live.ts +609 -0
- package/src/server/management/agent-settings-routes.ts +1180 -0
- package/src/server/management/android-remote-routes.ts +390 -0
- package/src/server/management/api-access.ts +141 -0
- package/src/server/management/api-key-usage.ts +167 -0
- package/src/server/management/body.ts +35 -0
- package/src/server/management/combo-routes.ts +244 -0
- package/src/server/management/config-routes.ts +602 -0
- package/src/server/management/context.ts +88 -0
- package/src/server/management/integration-routes.ts +538 -0
- package/src/server/management/logs-usage-routes.ts +516 -0
- package/src/server/management/model-routes.ts +519 -0
- package/src/server/management/model-rows.ts +143 -0
- package/src/server/management/native-integration-routes.ts +781 -0
- package/src/server/management/oauth-account-routes.ts +573 -0
- package/src/server/management/provider-routes.ts +781 -0
- package/src/server/management/request-history-routes.ts +191 -0
- package/src/server/management/routing-analytics-routes.ts +74 -0
- package/src/server/management/routing-profile-routes.ts +384 -0
- package/src/server/management/shared.ts +277 -0
- package/src/server/management/sidebar-routes.ts +106 -0
- package/src/server/management/sync-response.ts +69 -0
- package/src/server/management/system-restart.ts +433 -0
- package/src/server/management/system-routes.ts +141 -0
- package/src/server/management/usage-summary-cache.ts +86 -0
- package/src/server/management-api.ts +269 -0
- package/src/server/management-auth.ts +353 -0
- package/src/server/memory-watchdog.ts +156 -0
- package/src/server/port-reclaim.ts +307 -0
- package/src/server/ports.ts +156 -0
- package/src/server/proxy-liveness.ts +326 -0
- package/src/server/proxy-stop.ts +92 -0
- package/src/server/readiness.ts +99 -0
- package/src/server/relay-eager.ts +353 -0
- package/src/server/relay.ts +1179 -0
- package/src/server/request-decompress.ts +132 -0
- package/src/server/request-log-conversation.ts +168 -0
- package/src/server/request-log.ts +1072 -0
- package/src/server/responses/collaboration.ts +409 -0
- package/src/server/responses/compact.ts +710 -0
- package/src/server/responses/core.ts +3561 -0
- package/src/server/responses/encrypted-payload.ts +308 -0
- package/src/server/responses/fetch-helpers.ts +171 -0
- package/src/server/responses/passthrough-error.ts +78 -0
- package/src/server/responses/policy-fallback.ts +152 -0
- package/src/server/responses/terminal-guard.ts +230 -0
- package/src/server/responses/upstream-error.ts +48 -0
- package/src/server/responses-image-gen-repair.ts +132 -0
- package/src/server/responses-item-id-repair.ts +272 -0
- package/src/server/responses-json-events.ts +52 -0
- package/src/server/responses-model-rewrite.ts +29 -0
- package/src/server/responses-snapshot-repair.ts +621 -0
- package/src/server/responses.ts +10 -0
- package/src/server/search.ts +181 -0
- package/src/server/sse-frame-buffer.ts +292 -0
- package/src/server/sse-payload-rewrite.ts +263 -0
- package/src/server/startup-action-control.ts +308 -0
- package/src/server/startup-health-cache.ts +119 -0
- package/src/server/system-env.ts +418 -0
- package/src/server/windows-tcp-drop.ts +184 -0
- package/src/server/windows-tray-control.ts +41 -0
- package/src/server/ws-bridge.ts +470 -0
- package/src/service-manager-probe.ts +824 -0
- package/src/service.ts +3011 -0
- package/src/stall-timeout.ts +20 -0
- package/src/storage/cleanup-job.ts +57 -0
- package/src/storage/cleanup.ts +3085 -0
- package/src/storage/policy-job.ts +457 -0
- package/src/storage/policy-scheduler.ts +40 -0
- package/src/storage/policy-worker.ts +59 -0
- package/src/storage/policy.ts +527 -0
- package/src/storage/restore-job.ts +299 -0
- package/src/storage/restore-worker.ts +58 -0
- package/src/storage/scanner.ts +238 -0
- package/src/storage/storage-mutation-coordinator.ts +139 -0
- package/src/storage/worker-lifecycle.ts +215 -0
- package/src/tray/assets/opencodex-tray-offline.ico +0 -0
- package/src/tray/assets/opencodex-tray-online.ico +0 -0
- package/src/tray/assets/opencodex-tray-warning.ico +0 -0
- package/src/tray/assets/opencodex-tray.png +0 -0
- package/src/tray/windows-tray.ps1 +364 -0
- package/src/tray/windows.ts +738 -0
- package/src/types.ts +1531 -0
- package/src/update/badge.ts +72 -0
- package/src/update/desktop-release.ts +1620 -0
- package/src/update/index.ts +402 -0
- package/src/update/job.ts +1906 -0
- package/src/update/notify.ts +261 -0
- package/src/update/npm-cache-preflight.d.mts +47 -0
- package/src/update/npm-cache-preflight.mjs +201 -0
- package/src/update/npm-invocation.d.mts +23 -0
- package/src/update/npm-invocation.mjs +94 -0
- package/src/update/tray-update-plan.d.mts +18 -0
- package/src/update/tray-update-plan.mjs +38 -0
- package/src/usage/cost.ts +0 -0
- package/src/usage/debug.ts +97 -0
- package/src/usage/expected-prices.ts +283 -0
- package/src/usage/log.ts +695 -0
- package/src/usage/summary.ts +585 -0
- package/src/usage/totals.ts +14 -0
- package/src/vision/anthropic-describe.ts +185 -0
- package/src/vision/describe.ts +127 -0
- package/src/vision/index.ts +558 -0
- package/src/vision/reasoning.ts +55 -0
- package/src/web-search/anthropic-executor.ts +189 -0
- package/src/web-search/executor.ts +105 -0
- package/src/web-search/format-result.ts +89 -0
- package/src/web-search/index.ts +196 -0
- package/src/web-search/loop.ts +791 -0
- package/src/web-search/parse.ts +235 -0
- package/src/web-search/progress-stream.ts +342 -0
- package/src/web-search/synthetic-tool.ts +47 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Qwen Cloud OpenAI-compatible endpoint presets.
|
|
3
|
+
* Token plan is the GUI default; pay-as-you-go and custom are selectable.
|
|
4
|
+
*/
|
|
5
|
+
export const QWEN_CLOUD_TOKEN_PLAN_BASE_URL =
|
|
6
|
+
"https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1";
|
|
7
|
+
export const QWEN_CLOUD_PAYG_BASE_URL =
|
|
8
|
+
"https://dashscope.aliyuncs.com/compatible-mode/v1";
|
|
9
|
+
|
|
10
|
+
export type ProviderBaseUrlChoice = {
|
|
11
|
+
id: string;
|
|
12
|
+
/** English label projected to the GUI; GUI may i18n by `id`. */
|
|
13
|
+
label: string;
|
|
14
|
+
/** Omitted for `custom` — user supplies the URL. */
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const QWEN_CLOUD_BASE_URL_CHOICES: readonly ProviderBaseUrlChoice[] = [
|
|
19
|
+
{ id: "token-plan", label: "Token plan", baseUrl: QWEN_CLOUD_TOKEN_PLAN_BASE_URL },
|
|
20
|
+
{ id: "payg", label: "Pay as you go", baseUrl: QWEN_CLOUD_PAYG_BASE_URL },
|
|
21
|
+
{ id: "custom", label: "Custom" },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Alibaba Token Plan International (ap-southeast-1) endpoint presets.
|
|
26
|
+
* Same product as the Beijing Token Plan but for international accounts.
|
|
27
|
+
* Note: ALIBABA_INTL_TOKEN_PLAN_BASE_URL intentionally duplicates
|
|
28
|
+
* QWEN_CLOUD_TOKEN_PLAN_BASE_URL — same host, different product branding
|
|
29
|
+
* and model lineup. Kept as a separate constant for clarity.
|
|
30
|
+
*/
|
|
31
|
+
export const ALIBABA_INTL_TOKEN_PLAN_BASE_URL =
|
|
32
|
+
"https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1";
|
|
33
|
+
export const ALIBABA_INTL_PAYG_BASE_URL =
|
|
34
|
+
"https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
|
|
35
|
+
|
|
36
|
+
export const ALIBABA_INTL_BASE_URL_CHOICES: readonly ProviderBaseUrlChoice[] = [
|
|
37
|
+
{ id: "token-plan", label: "Token plan", baseUrl: ALIBABA_INTL_TOKEN_PLAN_BASE_URL },
|
|
38
|
+
{ id: "payg", label: "Pay as you go", baseUrl: ALIBABA_INTL_PAYG_BASE_URL },
|
|
39
|
+
{ id: "custom", label: "Custom" },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
/** Alibaba Coding Plan endpoint presets (international default; China mainland selectable). */
|
|
43
|
+
export const ALIBABA_CODING_INTL_BASE_URL = "https://coding-intl.dashscope.aliyuncs.com/v1";
|
|
44
|
+
export const ALIBABA_CODING_CN_BASE_URL = "https://coding.dashscope.aliyuncs.com/v1";
|
|
45
|
+
|
|
46
|
+
export const ALIBABA_CODING_BASE_URL_CHOICES: readonly ProviderBaseUrlChoice[] = [
|
|
47
|
+
{ id: "intl", label: "International", baseUrl: ALIBABA_CODING_INTL_BASE_URL },
|
|
48
|
+
{ id: "china", label: "China", baseUrl: ALIBABA_CODING_CN_BASE_URL },
|
|
49
|
+
{ id: "custom", label: "Custom" },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** Match a saved baseUrl to a known choice id (`custom` when it does not match). */
|
|
53
|
+
export function matchBaseUrlChoice(
|
|
54
|
+
choices: readonly ProviderBaseUrlChoice[],
|
|
55
|
+
baseUrl: string,
|
|
56
|
+
): string {
|
|
57
|
+
if (!choices.length) return "custom";
|
|
58
|
+
const normalized = baseUrl.trim().replace(/\/+$/, "");
|
|
59
|
+
for (const choice of choices) {
|
|
60
|
+
if (!choice.baseUrl) continue;
|
|
61
|
+
if (choice.baseUrl.trim().replace(/\/+$/, "") === normalized) return choice.id;
|
|
62
|
+
}
|
|
63
|
+
return choices.some(c => c.id === "custom") ? "custom" : choices[0]!.id;
|
|
64
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
export const CODEX_CONFIGURED_CAPACITY_WEIGHTS = {
|
|
2
|
+
plus: 1,
|
|
3
|
+
business: 1,
|
|
4
|
+
prolite: 5,
|
|
5
|
+
pro: 20,
|
|
6
|
+
} as const;
|
|
7
|
+
|
|
8
|
+
/** Match the provider-report last-good freshness bound. */
|
|
9
|
+
export const CODEX_CAPACITY_MAX_QUOTA_AGE_MS = 30 * 60_000;
|
|
10
|
+
|
|
11
|
+
export type CodexCapacityQuota = {
|
|
12
|
+
fiveHourPercent?: number;
|
|
13
|
+
fiveHourResetAt?: number;
|
|
14
|
+
weeklyPercent?: number;
|
|
15
|
+
weeklyResetAt?: number;
|
|
16
|
+
monthlyPercent?: number;
|
|
17
|
+
monthlyResetAt?: number;
|
|
18
|
+
customWindows?: Array<{ label: string; percent: number; resetAt?: number }>;
|
|
19
|
+
updatedAt: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface CodexCapacityAccount {
|
|
23
|
+
isMain: boolean;
|
|
24
|
+
active?: boolean;
|
|
25
|
+
plan?: string | null;
|
|
26
|
+
paused: boolean;
|
|
27
|
+
needsReauth?: boolean;
|
|
28
|
+
quota: CodexCapacityQuota | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface CodexCapacityWindowAggregation {
|
|
32
|
+
usedPercent: number;
|
|
33
|
+
includedAccounts: number;
|
|
34
|
+
excludedAccounts: number;
|
|
35
|
+
incomplete: boolean;
|
|
36
|
+
/** Internal calculation evidence; stripped from the management API response. */
|
|
37
|
+
totalWeight?: number;
|
|
38
|
+
/** Internal calculation evidence; stripped from the management API response. */
|
|
39
|
+
consumedWeight?: number;
|
|
40
|
+
/** Internal calculation evidence; stripped from the management API response. */
|
|
41
|
+
remainingWeight?: number;
|
|
42
|
+
updatedAt: number;
|
|
43
|
+
nextRecoveryAt?: number;
|
|
44
|
+
nextRecoveryPercent?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface CodexCapacityAggregation {
|
|
48
|
+
kind: "capacity-weighted-v1";
|
|
49
|
+
scope: "routable-known";
|
|
50
|
+
includedAccounts: number;
|
|
51
|
+
excludedAccounts: number;
|
|
52
|
+
unknownPlanAccounts: number;
|
|
53
|
+
missingQuotaAccounts: number;
|
|
54
|
+
pausedAccounts: number;
|
|
55
|
+
reauthAccounts: number;
|
|
56
|
+
staleQuotaAccounts: number;
|
|
57
|
+
partialWindowAccounts: number;
|
|
58
|
+
incomplete: boolean;
|
|
59
|
+
presentation?: "aggregate" | "effective-account-fallback" | "coverage-only";
|
|
60
|
+
fiveHour?: CodexCapacityWindowAggregation;
|
|
61
|
+
weekly?: CodexCapacityWindowAggregation;
|
|
62
|
+
monthly?: CodexCapacityWindowAggregation;
|
|
63
|
+
customWindows?: Array<CodexCapacityWindowAggregation & { label: string }>;
|
|
64
|
+
currentAccount?: {
|
|
65
|
+
isMain: boolean;
|
|
66
|
+
plan?: string | null;
|
|
67
|
+
quota: CodexCapacityQuota | null;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface CodexCapacityResult {
|
|
72
|
+
quota: CodexCapacityQuota | null;
|
|
73
|
+
aggregation: CodexCapacityAggregation | null;
|
|
74
|
+
currentAccount?: CodexCapacityAggregation["currentAccount"];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type MutableWindow = {
|
|
78
|
+
totalWeight: number;
|
|
79
|
+
consumedWeight: number;
|
|
80
|
+
includedAccounts: number;
|
|
81
|
+
recoveries: Map<number, number>;
|
|
82
|
+
oldestUpdatedAt: number;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
function configuredWeight(plan: string | null | undefined): number | undefined {
|
|
86
|
+
const normalized = plan?.trim().toLowerCase();
|
|
87
|
+
return normalized && Object.hasOwn(CODEX_CONFIGURED_CAPACITY_WEIGHTS, normalized)
|
|
88
|
+
? CODEX_CONFIGURED_CAPACITY_WEIGHTS[normalized as keyof typeof CODEX_CONFIGURED_CAPACITY_WEIGHTS]
|
|
89
|
+
: undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function normalizedPercent(value: unknown): number | undefined {
|
|
93
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
94
|
+
? Math.max(0, Math.min(100, value))
|
|
95
|
+
: undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function futureResetMs(value: unknown, now: number): number | undefined {
|
|
99
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return undefined;
|
|
100
|
+
const milliseconds = value > 10_000_000_000 ? value : value * 1000;
|
|
101
|
+
return milliseconds > now ? milliseconds : undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function hasKnownQuotaWindow(quota: CodexCapacityQuota | null): quota is CodexCapacityQuota {
|
|
105
|
+
if (!quota) return false;
|
|
106
|
+
return normalizedPercent(quota.fiveHourPercent) !== undefined
|
|
107
|
+
|| normalizedPercent(quota.weeklyPercent) !== undefined
|
|
108
|
+
|| normalizedPercent(quota.monthlyPercent) !== undefined
|
|
109
|
+
|| !!quota.customWindows?.some(window => normalizedPercent(window.percent) !== undefined);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function currentQuotaForDisplay(account: CodexCapacityAccount, now: number): CodexCapacityQuota | null {
|
|
113
|
+
const quota = account.quota;
|
|
114
|
+
const fresh = !!quota
|
|
115
|
+
&& Number.isFinite(quota.updatedAt)
|
|
116
|
+
&& now - quota.updatedAt <= CODEX_CAPACITY_MAX_QUOTA_AGE_MS;
|
|
117
|
+
return !account.paused && !account.needsReauth && fresh && hasKnownQuotaWindow(quota) ? quota : null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function addWindow(
|
|
121
|
+
windows: Map<string, MutableWindow>,
|
|
122
|
+
key: string,
|
|
123
|
+
weight: number,
|
|
124
|
+
percent: number,
|
|
125
|
+
resetAt: number | undefined,
|
|
126
|
+
updatedAt: number,
|
|
127
|
+
): void {
|
|
128
|
+
const window = windows.get(key) ?? {
|
|
129
|
+
totalWeight: 0,
|
|
130
|
+
consumedWeight: 0,
|
|
131
|
+
includedAccounts: 0,
|
|
132
|
+
recoveries: new Map<number, number>(),
|
|
133
|
+
oldestUpdatedAt: updatedAt,
|
|
134
|
+
};
|
|
135
|
+
const consumed = weight * percent / 100;
|
|
136
|
+
window.totalWeight += weight;
|
|
137
|
+
window.consumedWeight += consumed;
|
|
138
|
+
window.includedAccounts += 1;
|
|
139
|
+
window.oldestUpdatedAt = Math.min(window.oldestUpdatedAt, updatedAt);
|
|
140
|
+
if (resetAt !== undefined && consumed > 0) {
|
|
141
|
+
window.recoveries.set(resetAt, (window.recoveries.get(resetAt) ?? 0) + consumed);
|
|
142
|
+
}
|
|
143
|
+
windows.set(key, window);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function finalizeWindow(window: MutableWindow, totalAccounts: number): CodexCapacityWindowAggregation {
|
|
147
|
+
const nextRecoveryAt = [...window.recoveries.keys()].sort((a, b) => a - b)[0];
|
|
148
|
+
const recovered = nextRecoveryAt === undefined ? undefined : window.recoveries.get(nextRecoveryAt);
|
|
149
|
+
return {
|
|
150
|
+
usedPercent: window.consumedWeight / window.totalWeight * 100,
|
|
151
|
+
includedAccounts: window.includedAccounts,
|
|
152
|
+
excludedAccounts: totalAccounts - window.includedAccounts,
|
|
153
|
+
incomplete: window.includedAccounts < totalAccounts,
|
|
154
|
+
totalWeight: window.totalWeight,
|
|
155
|
+
consumedWeight: window.consumedWeight,
|
|
156
|
+
remainingWeight: window.totalWeight - window.consumedWeight,
|
|
157
|
+
updatedAt: window.oldestUpdatedAt,
|
|
158
|
+
...(nextRecoveryAt !== undefined ? { nextRecoveryAt } : {}),
|
|
159
|
+
...(recovered !== undefined ? { nextRecoveryPercent: recovered / window.totalWeight * 100 } : {}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Display-only configured-weight estimate. It never participates in account selection or routing. */
|
|
164
|
+
export function aggregateCodexPoolCapacity(
|
|
165
|
+
accounts: readonly CodexCapacityAccount[],
|
|
166
|
+
now = Date.now(),
|
|
167
|
+
): CodexCapacityResult {
|
|
168
|
+
const current = accounts.find(account => account.active)
|
|
169
|
+
?? accounts.find(account => account.isMain)
|
|
170
|
+
?? accounts[0];
|
|
171
|
+
const currentAccount = current ? {
|
|
172
|
+
isMain: current.isMain,
|
|
173
|
+
...(current.plan !== undefined ? { plan: current.plan } : {}),
|
|
174
|
+
quota: currentQuotaForDisplay(current, now),
|
|
175
|
+
} : undefined;
|
|
176
|
+
const windows = new Map<string, MutableWindow>();
|
|
177
|
+
const included = new Set<CodexCapacityAccount>();
|
|
178
|
+
const contributions = new Map<CodexCapacityAccount, Set<string>>();
|
|
179
|
+
let unknownPlanAccounts = 0;
|
|
180
|
+
let missingQuotaAccounts = 0;
|
|
181
|
+
let pausedAccounts = 0;
|
|
182
|
+
let reauthAccounts = 0;
|
|
183
|
+
let staleQuotaAccounts = 0;
|
|
184
|
+
|
|
185
|
+
for (const account of accounts) {
|
|
186
|
+
const weight = configuredWeight(account.plan);
|
|
187
|
+
if (weight === undefined) unknownPlanAccounts += 1;
|
|
188
|
+
if (account.paused) pausedAccounts += 1;
|
|
189
|
+
if (account.needsReauth) reauthAccounts += 1;
|
|
190
|
+
const quota = account.quota;
|
|
191
|
+
const quotaFresh = !!quota
|
|
192
|
+
&& Number.isFinite(quota.updatedAt)
|
|
193
|
+
&& now - quota.updatedAt <= CODEX_CAPACITY_MAX_QUOTA_AGE_MS;
|
|
194
|
+
if (quota && !quotaFresh) staleQuotaAccounts += 1;
|
|
195
|
+
const standard = quota ? [
|
|
196
|
+
["fiveHour", quota.fiveHourPercent, quota.fiveHourResetAt],
|
|
197
|
+
["weekly", quota.weeklyPercent, quota.weeklyResetAt],
|
|
198
|
+
["monthly", quota.monthlyPercent, quota.monthlyResetAt],
|
|
199
|
+
] as const : [];
|
|
200
|
+
const custom = quota?.customWindows ?? [];
|
|
201
|
+
const hasQuota = hasKnownQuotaWindow(quota);
|
|
202
|
+
if (!hasQuota) missingQuotaAccounts += 1;
|
|
203
|
+
if (account.paused || account.needsReauth || weight === undefined || !quota || !hasQuota || !quotaFresh) continue;
|
|
204
|
+
|
|
205
|
+
let contributed = false;
|
|
206
|
+
const contributionKeys = new Set<string>();
|
|
207
|
+
for (const [key, rawPercent, rawReset] of standard) {
|
|
208
|
+
const percent = normalizedPercent(rawPercent);
|
|
209
|
+
if (percent === undefined) continue;
|
|
210
|
+
addWindow(windows, key, weight, percent, futureResetMs(rawReset, now), quota.updatedAt);
|
|
211
|
+
contributionKeys.add(key);
|
|
212
|
+
contributed = true;
|
|
213
|
+
}
|
|
214
|
+
for (const customWindow of custom) {
|
|
215
|
+
const percent = normalizedPercent(customWindow.percent);
|
|
216
|
+
if (percent === undefined) continue;
|
|
217
|
+
addWindow(windows, `custom:${customWindow.label}`, weight, percent, futureResetMs(customWindow.resetAt, now), quota.updatedAt);
|
|
218
|
+
contributionKeys.add(`custom:${customWindow.label}`);
|
|
219
|
+
contributed = true;
|
|
220
|
+
}
|
|
221
|
+
if (contributed) {
|
|
222
|
+
included.add(account);
|
|
223
|
+
contributions.set(account, contributionKeys);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (windows.size === 0) {
|
|
228
|
+
if (accounts.length === 0) return { quota: null, aggregation: null, ...(currentAccount ? { currentAccount } : {}) };
|
|
229
|
+
const aggregation: CodexCapacityAggregation = {
|
|
230
|
+
kind: "capacity-weighted-v1",
|
|
231
|
+
scope: "routable-known",
|
|
232
|
+
includedAccounts: 0,
|
|
233
|
+
excludedAccounts: accounts.length,
|
|
234
|
+
unknownPlanAccounts,
|
|
235
|
+
missingQuotaAccounts,
|
|
236
|
+
pausedAccounts,
|
|
237
|
+
reauthAccounts,
|
|
238
|
+
staleQuotaAccounts,
|
|
239
|
+
partialWindowAccounts: 0,
|
|
240
|
+
incomplete: true,
|
|
241
|
+
...(currentAccount ? { currentAccount } : {}),
|
|
242
|
+
};
|
|
243
|
+
return { quota: null, aggregation, ...(currentAccount ? { currentAccount } : {}) };
|
|
244
|
+
}
|
|
245
|
+
const fiveHour = windows.get("fiveHour") ? finalizeWindow(windows.get("fiveHour")!, accounts.length) : undefined;
|
|
246
|
+
const weekly = windows.get("weekly") ? finalizeWindow(windows.get("weekly")!, accounts.length) : undefined;
|
|
247
|
+
const monthly = windows.get("monthly") ? finalizeWindow(windows.get("monthly")!, accounts.length) : undefined;
|
|
248
|
+
const customWindows = [...windows.entries()].flatMap(([key, window]) => key.startsWith("custom:")
|
|
249
|
+
? [{ label: key.slice("custom:".length), ...finalizeWindow(window, accounts.length) }]
|
|
250
|
+
: []);
|
|
251
|
+
const quota: CodexCapacityQuota = {
|
|
252
|
+
...(fiveHour ? { fiveHourPercent: fiveHour.usedPercent } : {}),
|
|
253
|
+
...(weekly ? { weeklyPercent: weekly.usedPercent } : {}),
|
|
254
|
+
...(monthly ? { monthlyPercent: monthly.usedPercent } : {}),
|
|
255
|
+
...(customWindows.length > 0 ? {
|
|
256
|
+
customWindows: customWindows.map(window => ({ label: window.label, percent: window.usedPercent })),
|
|
257
|
+
} : {}),
|
|
258
|
+
updatedAt: Math.min(
|
|
259
|
+
...[fiveHour, weekly, monthly, ...customWindows]
|
|
260
|
+
.flatMap(window => window ? [window.updatedAt] : []),
|
|
261
|
+
),
|
|
262
|
+
};
|
|
263
|
+
const visibleWindowKeys = [...windows.keys()];
|
|
264
|
+
const partialWindowAccounts = accounts.filter(account => {
|
|
265
|
+
const keys = contributions.get(account);
|
|
266
|
+
return !!keys && visibleWindowKeys.some(key => !keys.has(key));
|
|
267
|
+
}).length;
|
|
268
|
+
const excludedAccounts = accounts.length - included.size;
|
|
269
|
+
const aggregation: CodexCapacityAggregation = {
|
|
270
|
+
kind: "capacity-weighted-v1",
|
|
271
|
+
scope: "routable-known",
|
|
272
|
+
includedAccounts: included.size,
|
|
273
|
+
excludedAccounts,
|
|
274
|
+
unknownPlanAccounts,
|
|
275
|
+
missingQuotaAccounts,
|
|
276
|
+
pausedAccounts,
|
|
277
|
+
reauthAccounts,
|
|
278
|
+
staleQuotaAccounts,
|
|
279
|
+
partialWindowAccounts,
|
|
280
|
+
incomplete: excludedAccounts > 0 || partialWindowAccounts > 0,
|
|
281
|
+
...(fiveHour ? { fiveHour } : {}),
|
|
282
|
+
...(weekly ? { weekly } : {}),
|
|
283
|
+
...(monthly ? { monthly } : {}),
|
|
284
|
+
...(customWindows.length > 0 ? { customWindows } : {}),
|
|
285
|
+
...(currentAccount ? { currentAccount } : {}),
|
|
286
|
+
};
|
|
287
|
+
return { quota, aggregation, ...(currentAccount ? { currentAccount } : {}) };
|
|
288
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
2
|
+
|
|
3
|
+
const COMMAND_CODE_MODEL_EFFORTS = {
|
|
4
|
+
"deepseek/deepseek-v4-pro": {
|
|
5
|
+
efforts: ["high", "max"],
|
|
6
|
+
profileUrl: "https://commandcode.ai/models/deepseek-v4-pro",
|
|
7
|
+
},
|
|
8
|
+
"deepseek/deepseek-v4-flash": {
|
|
9
|
+
efforts: ["high", "max"],
|
|
10
|
+
profileUrl: "https://commandcode.ai/models/deepseek-v4-flash",
|
|
11
|
+
},
|
|
12
|
+
"zai-org/glm-5.2": {
|
|
13
|
+
efforts: ["high", "max"],
|
|
14
|
+
profileUrl: "https://commandcode.ai/models/glm-5-2",
|
|
15
|
+
},
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Official Command Code model-profile facts, not a model catalog. Models remain
|
|
20
|
+
* account-scoped and come exclusively from the authenticated /provider/v1/models endpoint.
|
|
21
|
+
*/
|
|
22
|
+
export const COMMAND_CODE_MODEL_REASONING_EFFORTS: Record<string, string[]> = Object.fromEntries(
|
|
23
|
+
Object.entries(COMMAND_CODE_MODEL_EFFORTS).map(([id, row]) => [id, [...row.efforts]]),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const refreshedEfforts = new Map<string, string[]>();
|
|
27
|
+
|
|
28
|
+
function keyFor(modelId: string): string {
|
|
29
|
+
return modelId.trim().toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function commandCodeReasoningEfforts(modelId: string): readonly string[] | undefined {
|
|
33
|
+
const key = keyFor(modelId);
|
|
34
|
+
return refreshedEfforts.get(key) ?? COMMAND_CODE_MODEL_REASONING_EFFORTS[key];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parsedProfileEfforts(page: string): string[] | undefined {
|
|
38
|
+
const match = page.match(/Reasoning efforts\s+([^.;]+?)\s+are supported;\s*([^.]*)/i);
|
|
39
|
+
if (!match) return undefined;
|
|
40
|
+
const listed = match[1]!.toLowerCase().match(/\b(?:low|medium|high|xhigh|max)\b/g) ?? [];
|
|
41
|
+
const mapped = match[2]!.toLowerCase().match(/\b(?:low|medium|high|xhigh|max)\s+maps to\s+(?:low|medium|high|xhigh|max)\b/g) ?? [];
|
|
42
|
+
const normalized = new Set(listed);
|
|
43
|
+
for (const mapping of mapped) {
|
|
44
|
+
const [, source, target] = mapping.match(/(low|medium|high|xhigh|max)\s+maps to\s+(low|medium|high|xhigh|max)/) ?? [];
|
|
45
|
+
if (source && target) {
|
|
46
|
+
normalized.delete(source);
|
|
47
|
+
normalized.add(target);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return normalized.size > 0 ? [...normalized] : [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Refresh one stale effort record only after the upstream rejects an effort request.
|
|
55
|
+
* A failed or unparseable public profile deliberately leaves the known table unchanged.
|
|
56
|
+
*/
|
|
57
|
+
export async function refreshCommandCodeReasoningEfforts(
|
|
58
|
+
modelId: string,
|
|
59
|
+
fetchFn: typeof globalThis.fetch = globalThis.fetch,
|
|
60
|
+
): Promise<readonly string[] | undefined> {
|
|
61
|
+
const key = keyFor(modelId);
|
|
62
|
+
const profile = COMMAND_CODE_MODEL_EFFORTS[key as keyof typeof COMMAND_CODE_MODEL_EFFORTS];
|
|
63
|
+
if (!profile) return undefined;
|
|
64
|
+
try {
|
|
65
|
+
const response = await fetchFn(profile.profileUrl, {
|
|
66
|
+
headers: { Accept: "text/html" },
|
|
67
|
+
signal: AbortSignal.timeout(10_000),
|
|
68
|
+
});
|
|
69
|
+
if (!response.ok) return undefined;
|
|
70
|
+
// Bound the profile page before parsing: a large or malformed page must not
|
|
71
|
+
// allocate unbounded memory on the request path.
|
|
72
|
+
const observed = await readBoundedResponseBody(response, { maxBytes: 256 * 1024 });
|
|
73
|
+
if (!observed.displaySafe) return undefined;
|
|
74
|
+
const efforts = parsedProfileEfforts(observed.text);
|
|
75
|
+
if (efforts === undefined) return undefined;
|
|
76
|
+
refreshedEfforts.set(key, efforts);
|
|
77
|
+
return efforts;
|
|
78
|
+
} catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function resetCommandCodeReasoningEffortsForTest(): void {
|
|
84
|
+
refreshedEfforts.clear();
|
|
85
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { OcxConfig } from "../types";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_PROVIDER_CONTEXT_CAP = 350_000;
|
|
4
|
+
|
|
5
|
+
function isValidContextCap(value: unknown): value is number {
|
|
6
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function providerContextCap(config: Pick<OcxConfig, "providerContextCaps">, provider: string): number | undefined {
|
|
10
|
+
const value = config.providerContextCaps?.[provider];
|
|
11
|
+
return isValidContextCap(value) ? value : undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function providerContextCaps(config: Pick<OcxConfig, "providerContextCaps">): Record<string, number> {
|
|
15
|
+
const caps = config.providerContextCaps;
|
|
16
|
+
if (!caps || typeof caps !== "object" || Array.isArray(caps)) return {};
|
|
17
|
+
const out: Record<string, number> = {};
|
|
18
|
+
for (const [provider, value] of Object.entries(caps)) {
|
|
19
|
+
if (isValidContextCap(value)) out[provider] = value;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function applyProviderContextCap(contextWindow: number | undefined, cap: number | undefined): number | undefined {
|
|
25
|
+
if (!isValidContextCap(cap)) return contextWindow;
|
|
26
|
+
if (!isValidContextCap(contextWindow)) return contextWindow;
|
|
27
|
+
return contextWindow > cap ? cap : contextWindow;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Effective global cap value: explicit config value, else the built-in default. */
|
|
31
|
+
export function globalContextCapValue(config: Pick<OcxConfig, "contextCapValue">): number {
|
|
32
|
+
const value = config.contextCapValue;
|
|
33
|
+
return isValidContextCap(value) ? Math.floor(value) : DEFAULT_PROVIDER_CONTEXT_CAP;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function setProviderContextCap(config: OcxConfig, provider: string, enabled: boolean, value?: number): void {
|
|
37
|
+
const next = providerContextCaps(config);
|
|
38
|
+
if (enabled) {
|
|
39
|
+
next[provider] = isValidContextCap(value) ? Math.floor(value) : globalContextCapValue(config);
|
|
40
|
+
} else {
|
|
41
|
+
delete next[provider];
|
|
42
|
+
}
|
|
43
|
+
if (Object.keys(next).length > 0) config.providerContextCaps = next;
|
|
44
|
+
else delete config.providerContextCaps;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Set the global cap value (the default used by per-provider toggles and "set all").
|
|
49
|
+
* Re-points every already-enabled provider only when `applyToAll` is true (the dashboard's
|
|
50
|
+
* "apply to every routed provider" toggle); otherwise each provider keeps its own cap value.
|
|
51
|
+
*/
|
|
52
|
+
export function setGlobalContextCapValue(config: OcxConfig, value: number, applyToAll: boolean): void {
|
|
53
|
+
if (!isValidContextCap(value)) return;
|
|
54
|
+
const next = Math.floor(value);
|
|
55
|
+
config.contextCapValue = next;
|
|
56
|
+
if (!applyToAll) return;
|
|
57
|
+
const caps = providerContextCaps(config);
|
|
58
|
+
for (const provider of Object.keys(caps)) caps[provider] = next;
|
|
59
|
+
if (Object.keys(caps).length > 0) config.providerContextCaps = caps;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Enable the cap for every named provider at the current value, or clear all caps. */
|
|
63
|
+
export function setAllProviderContextCaps(config: OcxConfig, providerNames: string[], enabled: boolean): void {
|
|
64
|
+
if (!enabled) {
|
|
65
|
+
delete config.providerContextCaps;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const value = globalContextCapValue(config);
|
|
69
|
+
const next: Record<string, number> = {};
|
|
70
|
+
for (const name of providerNames) next[name] = value;
|
|
71
|
+
if (Object.keys(next).length > 0) config.providerContextCaps = next;
|
|
72
|
+
else delete config.providerContextCaps;
|
|
73
|
+
}
|