jeopi-ai 16.2.13
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/CHANGELOG.md +4347 -0
- package/README.md +1193 -0
- package/dist/types/api-registry.d.ts +30 -0
- package/dist/types/auth-broker/client.d.ts +73 -0
- package/dist/types/auth-broker/discover.d.ts +35 -0
- package/dist/types/auth-broker/index.d.ts +7 -0
- package/dist/types/auth-broker/refresher.d.ts +25 -0
- package/dist/types/auth-broker/remote-store.d.ts +102 -0
- package/dist/types/auth-broker/server.d.ts +43 -0
- package/dist/types/auth-broker/snapshot-cache.d.ts +17 -0
- package/dist/types/auth-broker/types.d.ts +107 -0
- package/dist/types/auth-broker/wire-schemas.d.ts +411 -0
- package/dist/types/auth-gateway/http.d.ts +39 -0
- package/dist/types/auth-gateway/index.d.ts +3 -0
- package/dist/types/auth-gateway/server.d.ts +36 -0
- package/dist/types/auth-gateway/types.d.ts +123 -0
- package/dist/types/auth-retry.d.ts +124 -0
- package/dist/types/auth-storage.d.ts +1026 -0
- package/dist/types/dialect/anthropic.d.ts +15 -0
- package/dist/types/dialect/catalog.d.ts +3 -0
- package/dist/types/dialect/coercion.d.ts +23 -0
- package/dist/types/dialect/deepseek.d.ts +14 -0
- package/dist/types/dialect/demotion.d.ts +23 -0
- package/dist/types/dialect/examples.d.ts +2 -0
- package/dist/types/dialect/factory.d.ts +3 -0
- package/dist/types/dialect/fenced-thinking.d.ts +53 -0
- package/dist/types/dialect/gemini.d.ts +17 -0
- package/dist/types/dialect/gemma.d.ts +15 -0
- package/dist/types/dialect/glm.d.ts +9 -0
- package/dist/types/dialect/harmony.d.ts +8 -0
- package/dist/types/dialect/hermes.d.ts +9 -0
- package/dist/types/dialect/history.d.ts +3 -0
- package/dist/types/dialect/index.d.ts +11 -0
- package/dist/types/dialect/inventory.d.ts +12 -0
- package/dist/types/dialect/kimi.d.ts +14 -0
- package/dist/types/dialect/minimax.d.ts +3 -0
- package/dist/types/dialect/owned-stream.d.ts +4 -0
- package/dist/types/dialect/qwen3.d.ts +9 -0
- package/dist/types/dialect/rendering.d.ts +45 -0
- package/dist/types/dialect/thinking.d.ts +6 -0
- package/dist/types/dialect/types.d.ts +69 -0
- package/dist/types/dialect/xml.d.ts +9 -0
- package/dist/types/error/abort.d.ts +14 -0
- package/dist/types/error/auth-classify.d.ts +16 -0
- package/dist/types/error/auth.d.ts +27 -0
- package/dist/types/error/aws.d.ts +23 -0
- package/dist/types/error/classes.d.ts +102 -0
- package/dist/types/error/finalize.d.ts +39 -0
- package/dist/types/error/flags.d.ts +79 -0
- package/dist/types/error/format.d.ts +20 -0
- package/dist/types/error/gateway.d.ts +20 -0
- package/dist/types/error/index.d.ts +13 -0
- package/dist/types/error/oauth.d.ts +43 -0
- package/dist/types/error/provider.d.ts +42 -0
- package/dist/types/error/rate-limit.d.ts +59 -0
- package/dist/types/error/retryable.d.ts +27 -0
- package/dist/types/error/validation.d.ts +32 -0
- package/dist/types/index.d.ts +49 -0
- package/dist/types/provider-details.d.ts +24 -0
- package/dist/types/providers/__tests__/google-auth.test.d.ts +1 -0
- package/dist/types/providers/__tests__/kimi-code-thinking.test.d.ts +1 -0
- package/dist/types/providers/__tests__/openai-codex-error.test.d.ts +1 -0
- package/dist/types/providers/amazon-bedrock.d.ts +39 -0
- package/dist/types/providers/anthropic-client.d.ts +94 -0
- package/dist/types/providers/anthropic-messages-server-schema.d.ts +497 -0
- package/dist/types/providers/anthropic-messages-server.d.ts +17 -0
- package/dist/types/providers/anthropic-wire.d.ts +318 -0
- package/dist/types/providers/anthropic.d.ts +248 -0
- package/dist/types/providers/aws-credentials.d.ts +53 -0
- package/dist/types/providers/aws-eventstream.d.ts +39 -0
- package/dist/types/providers/aws-sigv4.d.ts +55 -0
- package/dist/types/providers/azure-openai-responses.d.ts +16 -0
- package/dist/types/providers/cursor.d.ts +91 -0
- package/dist/types/providers/devin.d.ts +12 -0
- package/dist/types/providers/error-message.d.ts +27 -0
- package/dist/types/providers/github-copilot-headers.d.ts +40 -0
- package/dist/types/providers/gitlab-duo-workflow.d.ts +254 -0
- package/dist/types/providers/gitlab-duo.d.ts +27 -0
- package/dist/types/providers/google-auth.d.ts +32 -0
- package/dist/types/providers/google-gemini-cli.d.ts +118 -0
- package/dist/types/providers/google-interactions.d.ts +65 -0
- package/dist/types/providers/google-shared.d.ts +203 -0
- package/dist/types/providers/google-types.d.ts +155 -0
- package/dist/types/providers/google-vertex.d.ts +7 -0
- package/dist/types/providers/google.d.ts +4 -0
- package/dist/types/providers/grammar.d.ts +1 -0
- package/dist/types/providers/kimi.d.ts +27 -0
- package/dist/types/providers/mock.d.ts +178 -0
- package/dist/types/providers/ollama.d.ts +7 -0
- package/dist/types/providers/openai-anthropic-shim.d.ts +31 -0
- package/dist/types/providers/openai-chat-server-schema.d.ts +695 -0
- package/dist/types/providers/openai-chat-server.d.ts +16 -0
- package/dist/types/providers/openai-chat-wire.d.ts +644 -0
- package/dist/types/providers/openai-codex/request-transformer.d.ts +54 -0
- package/dist/types/providers/openai-codex/response-handler.d.ts +26 -0
- package/dist/types/providers/openai-codex-responses.d.ts +108 -0
- package/dist/types/providers/openai-completions.d.ts +45 -0
- package/dist/types/providers/openai-reasoning-fallback.d.ts +25 -0
- package/dist/types/providers/openai-responses-server-schema.d.ts +349 -0
- package/dist/types/providers/openai-responses-server.d.ts +17 -0
- package/dist/types/providers/openai-responses-wire.d.ts +6065 -0
- package/dist/types/providers/openai-responses.d.ts +126 -0
- package/dist/types/providers/openai-shared.d.ts +506 -0
- package/dist/types/providers/pi-native-client.d.ts +13 -0
- package/dist/types/providers/pi-native-server.d.ts +69 -0
- package/dist/types/providers/register-builtins.d.ts +32 -0
- package/dist/types/providers/synthetic.d.ts +26 -0
- package/dist/types/providers/transform-messages.d.ts +11 -0
- package/dist/types/providers/vision-guard.d.ts +20 -0
- package/dist/types/registry/aimlapi.d.ts +4 -0
- package/dist/types/registry/alibaba-coding-plan.d.ts +8 -0
- package/dist/types/registry/amazon-bedrock.d.ts +5 -0
- package/dist/types/registry/anthropic.d.ts +10 -0
- package/dist/types/registry/api-key-login.d.ts +42 -0
- package/dist/types/registry/api-key-validation.d.ts +43 -0
- package/dist/types/registry/azure.d.ts +4 -0
- package/dist/types/registry/cerebras.d.ts +7 -0
- package/dist/types/registry/cloudflare-ai-gateway.d.ts +13 -0
- package/dist/types/registry/coreweave.d.ts +7 -0
- package/dist/types/registry/cursor.d.ts +7 -0
- package/dist/types/registry/deepseek.d.ts +8 -0
- package/dist/types/registry/derived.d.ts +5 -0
- package/dist/types/registry/devin.d.ts +8 -0
- package/dist/types/registry/firepass.d.ts +16 -0
- package/dist/types/registry/fireworks.d.ts +7 -0
- package/dist/types/registry/github-copilot.d.ts +7 -0
- package/dist/types/registry/gitlab-duo-workflow.d.ts +10 -0
- package/dist/types/registry/gitlab-duo.d.ts +9 -0
- package/dist/types/registry/google-antigravity.d.ts +9 -0
- package/dist/types/registry/google-gemini-cli.d.ts +9 -0
- package/dist/types/registry/google-vertex.d.ts +5 -0
- package/dist/types/registry/google.d.ts +4 -0
- package/dist/types/registry/groq.d.ts +4 -0
- package/dist/types/registry/huggingface.d.ts +7 -0
- package/dist/types/registry/index.d.ts +4 -0
- package/dist/types/registry/kagi.d.ts +14 -0
- package/dist/types/registry/kilo.d.ts +7 -0
- package/dist/types/registry/kimi-code.d.ts +7 -0
- package/dist/types/registry/litellm.d.ts +13 -0
- package/dist/types/registry/llama-cpp.d.ts +8 -0
- package/dist/types/registry/lm-studio.d.ts +8 -0
- package/dist/types/registry/minimax-code-cn.d.ts +6 -0
- package/dist/types/registry/minimax-code.d.ts +6 -0
- package/dist/types/registry/minimax.d.ts +4 -0
- package/dist/types/registry/mistral.d.ts +4 -0
- package/dist/types/registry/moonshot.d.ts +7 -0
- package/dist/types/registry/nanogpt.d.ts +7 -0
- package/dist/types/registry/nvidia.d.ts +7 -0
- package/dist/types/registry/oauth/__tests__/xai-oauth.test.d.ts +1 -0
- package/dist/types/registry/oauth/anthropic.d.ts +23 -0
- package/dist/types/registry/oauth/callback-server.d.ts +72 -0
- package/dist/types/registry/oauth/cursor.d.ts +15 -0
- package/dist/types/registry/oauth/devin.d.ts +5 -0
- package/dist/types/registry/oauth/github-copilot.d.ts +30 -0
- package/dist/types/registry/oauth/gitlab-duo-workflow.d.ts +6 -0
- package/dist/types/registry/oauth/gitlab-duo.d.ts +3 -0
- package/dist/types/registry/oauth/google-antigravity.d.ts +11 -0
- package/dist/types/registry/oauth/google-gemini-cli.d.ts +10 -0
- package/dist/types/registry/oauth/google-oauth-shared.d.ts +22 -0
- package/dist/types/registry/oauth/index.d.ts +64 -0
- package/dist/types/registry/oauth/kimi.d.ts +21 -0
- package/dist/types/registry/oauth/minimax-code.d.ts +27 -0
- package/dist/types/registry/oauth/openai-codex.d.ts +33 -0
- package/dist/types/registry/oauth/opencode.d.ts +18 -0
- package/dist/types/registry/oauth/perplexity.d.ts +9 -0
- package/dist/types/registry/oauth/pkce.d.ts +8 -0
- package/dist/types/registry/oauth/types.d.ts +56 -0
- package/dist/types/registry/oauth/wafer.d.ts +1 -0
- package/dist/types/registry/oauth/xai-oauth.d.ts +52 -0
- package/dist/types/registry/oauth/xiaomi.d.ts +25 -0
- package/dist/types/registry/ollama-cloud.d.ts +7 -0
- package/dist/types/registry/ollama.d.ts +12 -0
- package/dist/types/registry/openai-codex-device.d.ts +8 -0
- package/dist/types/registry/openai-codex.d.ts +9 -0
- package/dist/types/registry/openai.d.ts +4 -0
- package/dist/types/registry/opencode-go.d.ts +6 -0
- package/dist/types/registry/opencode-zen.d.ts +6 -0
- package/dist/types/registry/openrouter.d.ts +13 -0
- package/dist/types/registry/parallel.d.ts +14 -0
- package/dist/types/registry/perplexity.d.ts +7 -0
- package/dist/types/registry/qianfan.d.ts +7 -0
- package/dist/types/registry/qwen-portal.d.ts +7 -0
- package/dist/types/registry/registry.d.ts +303 -0
- package/dist/types/registry/sakana.d.ts +7 -0
- package/dist/types/registry/synthetic.d.ts +6 -0
- package/dist/types/registry/tavily.d.ts +14 -0
- package/dist/types/registry/together.d.ts +6 -0
- package/dist/types/registry/types.d.ts +51 -0
- package/dist/types/registry/umans.d.ts +7 -0
- package/dist/types/registry/venice.d.ts +13 -0
- package/dist/types/registry/vercel-ai-gateway.d.ts +7 -0
- package/dist/types/registry/vllm.d.ts +7 -0
- package/dist/types/registry/wafer-serverless.d.ts +6 -0
- package/dist/types/registry/xai-oauth.d.ts +7 -0
- package/dist/types/registry/xai.d.ts +4 -0
- package/dist/types/registry/xiaomi-token-plan-ams.d.ts +6 -0
- package/dist/types/registry/xiaomi-token-plan-cn.d.ts +6 -0
- package/dist/types/registry/xiaomi-token-plan-sgp.d.ts +6 -0
- package/dist/types/registry/xiaomi.d.ts +6 -0
- package/dist/types/registry/zai.d.ts +7 -0
- package/dist/types/registry/zenmux.d.ts +7 -0
- package/dist/types/registry/zhipu-coding-plan.d.ts +7 -0
- package/dist/types/stream.d.ts +44 -0
- package/dist/types/types.d.ts +715 -0
- package/dist/types/usage/claude.d.ts +4 -0
- package/dist/types/usage/gemini.d.ts +2 -0
- package/dist/types/usage/github-copilot.d.ts +7 -0
- package/dist/types/usage/google-antigravity.d.ts +15 -0
- package/dist/types/usage/kimi.d.ts +2 -0
- package/dist/types/usage/minimax-code.d.ts +2 -0
- package/dist/types/usage/ollama.d.ts +5 -0
- package/dist/types/usage/openai-codex-base-url.d.ts +18 -0
- package/dist/types/usage/openai-codex-reset.d.ts +79 -0
- package/dist/types/usage/openai-codex.d.ts +3 -0
- package/dist/types/usage/opencode-go.d.ts +2 -0
- package/dist/types/usage/shared.d.ts +1 -0
- package/dist/types/usage/zai.d.ts +2 -0
- package/dist/types/usage.d.ts +346 -0
- package/dist/types/utils/abort.d.ts +25 -0
- package/dist/types/utils/anthropic-auth.d.ts +35 -0
- package/dist/types/utils/block-symbols.d.ts +20 -0
- package/dist/types/utils/deterministic-id.d.ts +16 -0
- package/dist/types/utils/empty-completion-retry.d.ts +21 -0
- package/dist/types/utils/event-stream.d.ts +30 -0
- package/dist/types/utils/foundry.d.ts +1 -0
- package/dist/types/utils/google-validation.d.ts +2 -0
- package/dist/types/utils/harmony-leak.d.ts +118 -0
- package/dist/types/utils/http-inspector.d.ts +30 -0
- package/dist/types/utils/idle-iterator.d.ts +137 -0
- package/dist/types/utils/leaked-thinking-stream.d.ts +29 -0
- package/dist/types/utils/openai-http.d.ts +54 -0
- package/dist/types/utils/openrouter-headers.d.ts +1 -0
- package/dist/types/utils/parse-bind.d.ts +23 -0
- package/dist/types/utils/provider-response.d.ts +3 -0
- package/dist/types/utils/proxy.d.ts +29 -0
- package/dist/types/utils/request-debug.d.ts +29 -0
- package/dist/types/utils/retry-after.d.ts +4 -0
- package/dist/types/utils/retry.d.ts +14 -0
- package/dist/types/utils/schema/adapt.d.ts +24 -0
- package/dist/types/utils/schema/compatibility.d.ts +30 -0
- package/dist/types/utils/schema/dereference.d.ts +11 -0
- package/dist/types/utils/schema/draft.d.ts +10 -0
- package/dist/types/utils/schema/equality.d.ts +4 -0
- package/dist/types/utils/schema/fields.d.ts +54 -0
- package/dist/types/utils/schema/index.d.ts +15 -0
- package/dist/types/utils/schema/json-schema-validator.d.ts +20 -0
- package/dist/types/utils/schema/meta-validator.d.ts +2 -0
- package/dist/types/utils/schema/normalize.d.ts +124 -0
- package/dist/types/utils/schema/spill.d.ts +8 -0
- package/dist/types/utils/schema/stamps.d.ts +17 -0
- package/dist/types/utils/schema/strict-tool-validation.d.ts +16 -0
- package/dist/types/utils/schema/types.d.ts +4 -0
- package/dist/types/utils/schema/typescript.d.ts +18 -0
- package/dist/types/utils/schema/wire.d.ts +92 -0
- package/dist/types/utils/schema/zod-decontaminate.d.ts +31 -0
- package/dist/types/utils/sdk-stream-timeout.d.ts +33 -0
- package/dist/types/utils/sse-debug.d.ts +5 -0
- package/dist/types/utils/stream-markup-healing.d.ts +87 -0
- package/dist/types/utils/thinking-loop.d.ts +102 -0
- package/dist/types/utils/tool-call-loop-guard.d.ts +26 -0
- package/dist/types/utils/tool-choice.d.ts +50 -0
- package/dist/types/utils/validation.d.ts +42 -0
- package/dist/types/utils.d.ts +24 -0
- package/package.json +139 -0
- package/src/api-registry.ts +109 -0
- package/src/auth-broker/client.ts +359 -0
- package/src/auth-broker/discover.ts +222 -0
- package/src/auth-broker/index.ts +7 -0
- package/src/auth-broker/refresher.ts +117 -0
- package/src/auth-broker/remote-store.ts +657 -0
- package/src/auth-broker/server.ts +646 -0
- package/src/auth-broker/snapshot-cache.ts +191 -0
- package/src/auth-broker/types.ts +130 -0
- package/src/auth-broker/wire-schemas.ts +249 -0
- package/src/auth-gateway/http.ts +194 -0
- package/src/auth-gateway/index.ts +3 -0
- package/src/auth-gateway/server.ts +802 -0
- package/src/auth-gateway/types.ts +151 -0
- package/src/auth-retry.ts +250 -0
- package/src/auth-storage.ts +5576 -0
- package/src/dialect/anthropic.md +31 -0
- package/src/dialect/anthropic.ts +608 -0
- package/src/dialect/catalog.ts +29 -0
- package/src/dialect/coercion.ts +136 -0
- package/src/dialect/deepseek.md +24 -0
- package/src/dialect/deepseek.ts +609 -0
- package/src/dialect/demotion.ts +36 -0
- package/src/dialect/examples.ts +33 -0
- package/src/dialect/factory.ts +34 -0
- package/src/dialect/fenced-thinking.ts +184 -0
- package/src/dialect/gemini.md +44 -0
- package/src/dialect/gemini.ts +597 -0
- package/src/dialect/gemma.md +33 -0
- package/src/dialect/gemma.ts +387 -0
- package/src/dialect/glm.md +32 -0
- package/src/dialect/glm.ts +456 -0
- package/src/dialect/harmony.md +31 -0
- package/src/dialect/harmony.ts +346 -0
- package/src/dialect/hermes.md +25 -0
- package/src/dialect/hermes.ts +206 -0
- package/src/dialect/history.ts +81 -0
- package/src/dialect/index.ts +15 -0
- package/src/dialect/inventory.ts +73 -0
- package/src/dialect/kimi.md +24 -0
- package/src/dialect/kimi.ts +340 -0
- package/src/dialect/minimax.md +31 -0
- package/src/dialect/minimax.ts +95 -0
- package/src/dialect/owned-stream.ts +470 -0
- package/src/dialect/prompt-template.md +12 -0
- package/src/dialect/qwen3.md +28 -0
- package/src/dialect/qwen3.ts +240 -0
- package/src/dialect/rendering.ts +249 -0
- package/src/dialect/thinking.ts +122 -0
- package/src/dialect/types.ts +57 -0
- package/src/dialect/xml.md +22 -0
- package/src/dialect/xml.ts +90 -0
- package/src/error/abort.ts +18 -0
- package/src/error/auth-classify.ts +30 -0
- package/src/error/auth.ts +48 -0
- package/src/error/aws.ts +31 -0
- package/src/error/classes.ts +186 -0
- package/src/error/finalize.ts +69 -0
- package/src/error/flags.ts +506 -0
- package/src/error/format.ts +45 -0
- package/src/error/gateway.ts +96 -0
- package/src/error/index.ts +13 -0
- package/src/error/oauth.ts +58 -0
- package/src/error/provider.ts +62 -0
- package/src/error/rate-limit.ts +161 -0
- package/src/error/retryable.ts +70 -0
- package/src/error/validation.ts +44 -0
- package/src/index.ts +49 -0
- package/src/provider-details.ts +90 -0
- package/src/providers/__tests__/google-auth.test.ts +144 -0
- package/src/providers/__tests__/kimi-code-thinking.test.ts +112 -0
- package/src/providers/__tests__/openai-codex-error.test.ts +84 -0
- package/src/providers/amazon-bedrock.ts +1042 -0
- package/src/providers/anthropic-client.ts +295 -0
- package/src/providers/anthropic-messages-server-schema.ts +252 -0
- package/src/providers/anthropic-messages-server.ts +756 -0
- package/src/providers/anthropic-wire.ts +318 -0
- package/src/providers/anthropic.ts +4078 -0
- package/src/providers/aws-credentials.ts +586 -0
- package/src/providers/aws-eventstream.ts +181 -0
- package/src/providers/aws-sigv4.ts +218 -0
- package/src/providers/azure-openai-responses.ts +382 -0
- package/src/providers/cursor/proto/agent.proto +3526 -0
- package/src/providers/cursor/proto/buf.gen.yaml +6 -0
- package/src/providers/cursor/proto/buf.yaml +17 -0
- package/src/providers/cursor.ts +2695 -0
- package/src/providers/devin/proto/buf/validate/validate.proto +468 -0
- package/src/providers/devin/proto/buf.gen.yaml +33 -0
- package/src/providers/devin/proto/buf.yaml +17 -0
- package/src/providers/devin/proto/cel/expr/checked.proto +103 -0
- package/src/providers/devin/proto/cel/expr/eval.proto +38 -0
- package/src/providers/devin/proto/cel/expr/explain.proto +15 -0
- package/src/providers/devin/proto/cel/expr/syntax.proto +113 -0
- package/src/providers/devin/proto/cel/expr/value.proto +41 -0
- package/src/providers/devin/proto/connectext/grpc/status/v1/status.proto +11 -0
- package/src/providers/devin/proto/errorspb/errors.proto +56 -0
- package/src/providers/devin/proto/errorspb/hintdetail.proto +7 -0
- package/src/providers/devin/proto/errorspb/markers.proto +10 -0
- package/src/providers/devin/proto/errorspb/tags.proto +12 -0
- package/src/providers/devin/proto/errorspb/testing.proto +6 -0
- package/src/providers/devin/proto/exa/analytics_pb/analytics.proto +188 -0
- package/src/providers/devin/proto/exa/api_server_pb/api_server.proto +2461 -0
- package/src/providers/devin/proto/exa/auth_pb/auth.proto +19 -0
- package/src/providers/devin/proto/exa/auto_cascade_common_pb/auto_cascade_common.proto +79 -0
- package/src/providers/devin/proto/exa/browser_preview_pb/browser_preview.proto +32 -0
- package/src/providers/devin/proto/exa/bug_checker_pb/bug_checker.proto +22 -0
- package/src/providers/devin/proto/exa/cascade_plugins_pb/cascade_plugins.proto +262 -0
- package/src/providers/devin/proto/exa/chat_client_server_pb/chat_client_server.proto +57 -0
- package/src/providers/devin/proto/exa/chat_pb/chat.proto +449 -0
- package/src/providers/devin/proto/exa/code_edit/code_edit_pb/code_edit.proto +186 -0
- package/src/providers/devin/proto/exa/codeium_common_pb/codeium_common.proto +4157 -0
- package/src/providers/devin/proto/exa/context_module_pb/context_module.proto +175 -0
- package/src/providers/devin/proto/exa/cortex_pb/cortex.proto +3268 -0
- package/src/providers/devin/proto/exa/dev_pb/dev.proto +26 -0
- package/src/providers/devin/proto/exa/diff_action_pb/diff_action.proto +75 -0
- package/src/providers/devin/proto/exa/eval/pr_eval/datasets_pb/datasets.proto +103 -0
- package/src/providers/devin/proto/exa/eval_pb/eval.proto +1315 -0
- package/src/providers/devin/proto/exa/extension_server_pb/extension_server.proto +556 -0
- package/src/providers/devin/proto/exa/file_system_provider_pb/file_system_provider.proto +75 -0
- package/src/providers/devin/proto/exa/index_pb/index.proto +461 -0
- package/src/providers/devin/proto/exa/knowledge_base_pb/knowledge_base.proto +144 -0
- package/src/providers/devin/proto/exa/language_server_pb/language_server.proto +2385 -0
- package/src/providers/devin/proto/exa/model_management_pb/model_management.proto +186 -0
- package/src/providers/devin/proto/exa/opensearch_clients_pb/opensearch_clients.proto +503 -0
- package/src/providers/devin/proto/exa/product_analytics_pb/product_analytics.proto +37 -0
- package/src/providers/devin/proto/exa/prompt_pb/prompt.proto +92 -0
- package/src/providers/devin/proto/exa/reactive_component_pb/reactive_component.proto +96 -0
- package/src/providers/devin/proto/exa/seat_management_pb/seat_management.proto +2680 -0
- package/src/providers/devin/proto/exa/tokenizer_pb/tokenizer.proto +37 -0
- package/src/providers/devin/proto/exa/trainer_pb/config.proto +647 -0
- package/src/providers/devin/proto/exa/tree_sitter/language_data_pb/language_data.proto +14 -0
- package/src/providers/devin/proto/exa/trust_pb/trust.proto +157 -0
- package/src/providers/devin/proto/exa/user_analytics_pb/user_analytics.proto +519 -0
- package/src/providers/devin/proto/google.golang.org/appengine/internal/base/api_base.proto +28 -0
- package/src/providers/devin/proto/google.golang.org/appengine/internal/datastore/datastore_v3.proto +484 -0
- package/src/providers/devin/proto/google.golang.org/appengine/internal/log/log_service.proto +136 -0
- package/src/providers/devin/proto/google.golang.org/appengine/internal/remote_api/remote_api.proto +42 -0
- package/src/providers/devin/proto/google.golang.org/appengine/internal/urlfetch/urlfetch_service.proto +61 -0
- package/src/providers/devin/proto/grpc/binlog/v1/binarylog.proto +84 -0
- package/src/providers/devin/proto/io/prometheus/client/metrics.proto +98 -0
- package/src/providers/devin.ts +577 -0
- package/src/providers/error-message.ts +21 -0
- package/src/providers/github-copilot-headers.ts +141 -0
- package/src/providers/gitlab-duo-workflow-chatml-note.md +1 -0
- package/src/providers/gitlab-duo-workflow.ts +3058 -0
- package/src/providers/gitlab-duo.ts +395 -0
- package/src/providers/google-auth.ts +350 -0
- package/src/providers/google-gemini-cli.ts +1362 -0
- package/src/providers/google-interactions.ts +753 -0
- package/src/providers/google-shared.ts +1103 -0
- package/src/providers/google-types.ts +180 -0
- package/src/providers/google-vertex.ts +183 -0
- package/src/providers/google.ts +87 -0
- package/src/providers/grammar.ts +70 -0
- package/src/providers/kimi.ts +52 -0
- package/src/providers/mock.ts +507 -0
- package/src/providers/ollama.ts +773 -0
- package/src/providers/openai-anthropic-shim.ts +152 -0
- package/src/providers/openai-chat-server-schema.ts +242 -0
- package/src/providers/openai-chat-server.ts +715 -0
- package/src/providers/openai-chat-wire.ts +847 -0
- package/src/providers/openai-codex/request-transformer.ts +295 -0
- package/src/providers/openai-codex/response-handler.ts +102 -0
- package/src/providers/openai-codex-responses.ts +3468 -0
- package/src/providers/openai-completions.ts +2173 -0
- package/src/providers/openai-reasoning-fallback.ts +269 -0
- package/src/providers/openai-responses-reasoning-suppression.md +1 -0
- package/src/providers/openai-responses-server-schema.ts +282 -0
- package/src/providers/openai-responses-server.ts +1280 -0
- package/src/providers/openai-responses-wire.ts +6391 -0
- package/src/providers/openai-responses.ts +1022 -0
- package/src/providers/openai-shared.ts +2648 -0
- package/src/providers/pi-native-client.ts +266 -0
- package/src/providers/pi-native-server.ts +242 -0
- package/src/providers/register-builtins.ts +475 -0
- package/src/providers/synthetic.ts +50 -0
- package/src/providers/transform-messages.ts +787 -0
- package/src/providers/vision-guard.ts +54 -0
- package/src/registry/aimlapi.ts +6 -0
- package/src/registry/alibaba-coding-plan.ts +95 -0
- package/src/registry/amazon-bedrock.ts +22 -0
- package/src/registry/anthropic.ts +26 -0
- package/src/registry/api-key-login.ts +112 -0
- package/src/registry/api-key-validation.ts +161 -0
- package/src/registry/azure.ts +6 -0
- package/src/registry/cerebras.ts +23 -0
- package/src/registry/cloudflare-ai-gateway.ts +45 -0
- package/src/registry/coreweave.ts +40 -0
- package/src/registry/cursor.ts +20 -0
- package/src/registry/deepseek.ts +46 -0
- package/src/registry/derived.ts +9 -0
- package/src/registry/devin.ts +15 -0
- package/src/registry/firepass.ts +32 -0
- package/src/registry/fireworks.ts +28 -0
- package/src/registry/github-copilot.ts +22 -0
- package/src/registry/gitlab-duo-workflow.ts +20 -0
- package/src/registry/gitlab-duo.ts +19 -0
- package/src/registry/google-antigravity.ts +22 -0
- package/src/registry/google-gemini-cli.ts +22 -0
- package/src/registry/google-vertex.ts +38 -0
- package/src/registry/google.ts +6 -0
- package/src/registry/groq.ts +6 -0
- package/src/registry/huggingface.ts +29 -0
- package/src/registry/index.ts +4 -0
- package/src/registry/kagi.ts +46 -0
- package/src/registry/kilo.ts +114 -0
- package/src/registry/kimi-code.ts +17 -0
- package/src/registry/litellm.ts +45 -0
- package/src/registry/llama-cpp.ts +35 -0
- package/src/registry/lm-studio.ts +31 -0
- package/src/registry/minimax-code-cn.ts +12 -0
- package/src/registry/minimax-code.ts +12 -0
- package/src/registry/minimax.ts +6 -0
- package/src/registry/mistral.ts +6 -0
- package/src/registry/moonshot.ts +22 -0
- package/src/registry/nanogpt.ts +22 -0
- package/src/registry/nvidia.ts +61 -0
- package/src/registry/oauth/__tests__/xai-oauth.test.ts +104 -0
- package/src/registry/oauth/anthropic.ts +311 -0
- package/src/registry/oauth/callback-server.ts +315 -0
- package/src/registry/oauth/cursor.ts +171 -0
- package/src/registry/oauth/devin.ts +124 -0
- package/src/registry/oauth/github-copilot.ts +369 -0
- package/src/registry/oauth/gitlab-duo-workflow.ts +146 -0
- package/src/registry/oauth/gitlab-duo.ts +222 -0
- package/src/registry/oauth/google-antigravity.ts +209 -0
- package/src/registry/oauth/google-gemini-cli.ts +273 -0
- package/src/registry/oauth/google-oauth-shared.ts +125 -0
- package/src/registry/oauth/index.ts +269 -0
- package/src/registry/oauth/kimi.ts +289 -0
- package/src/registry/oauth/minimax-code.ts +53 -0
- package/src/registry/oauth/oauth.html +311 -0
- package/src/registry/oauth/openai-codex.ts +364 -0
- package/src/registry/oauth/opencode.ts +50 -0
- package/src/registry/oauth/perplexity.ts +228 -0
- package/src/registry/oauth/pkce.ts +18 -0
- package/src/registry/oauth/types.ts +65 -0
- package/src/registry/oauth/wafer.ts +24 -0
- package/src/registry/oauth/xai-oauth.ts +394 -0
- package/src/registry/oauth/xiaomi.ts +211 -0
- package/src/registry/ollama-cloud.ts +36 -0
- package/src/registry/ollama.ts +43 -0
- package/src/registry/openai-codex-device.ts +18 -0
- package/src/registry/openai-codex.ts +19 -0
- package/src/registry/openai.ts +6 -0
- package/src/registry/opencode-go.ts +12 -0
- package/src/registry/opencode-zen.ts +12 -0
- package/src/registry/openrouter.ts +28 -0
- package/src/registry/parallel.ts +45 -0
- package/src/registry/perplexity.ts +13 -0
- package/src/registry/qianfan.ts +27 -0
- package/src/registry/qwen-portal.ts +50 -0
- package/src/registry/registry.ts +161 -0
- package/src/registry/sakana.ts +22 -0
- package/src/registry/synthetic.ts +21 -0
- package/src/registry/tavily.ts +45 -0
- package/src/registry/together.ts +22 -0
- package/src/registry/types.ts +56 -0
- package/src/registry/umans.ts +23 -0
- package/src/registry/venice.ts +33 -0
- package/src/registry/vercel-ai-gateway.ts +38 -0
- package/src/registry/vllm.ts +34 -0
- package/src/registry/wafer-serverless.ts +12 -0
- package/src/registry/xai-oauth.ts +17 -0
- package/src/registry/xai.ts +6 -0
- package/src/registry/xiaomi-token-plan-ams.ts +12 -0
- package/src/registry/xiaomi-token-plan-cn.ts +12 -0
- package/src/registry/xiaomi-token-plan-sgp.ts +12 -0
- package/src/registry/xiaomi.ts +12 -0
- package/src/registry/zai.ts +27 -0
- package/src/registry/zenmux.ts +22 -0
- package/src/registry/zhipu-coding-plan.ts +27 -0
- package/src/stream.ts +1778 -0
- package/src/types.ts +856 -0
- package/src/usage/claude.ts +485 -0
- package/src/usage/gemini.ts +258 -0
- package/src/usage/github-copilot.ts +424 -0
- package/src/usage/google-antigravity.ts +497 -0
- package/src/usage/kimi.ts +271 -0
- package/src/usage/minimax-code.ts +30 -0
- package/src/usage/ollama.ts +41 -0
- package/src/usage/openai-codex-base-url.ts +35 -0
- package/src/usage/openai-codex-reset.ts +174 -0
- package/src/usage/openai-codex.ts +535 -0
- package/src/usage/opencode-go.ts +89 -0
- package/src/usage/shared.ts +10 -0
- package/src/usage/zai.ts +321 -0
- package/src/usage.ts +333 -0
- package/src/utils/abort.ts +67 -0
- package/src/utils/anthropic-auth.ts +93 -0
- package/src/utils/block-symbols.ts +32 -0
- package/src/utils/deterministic-id.ts +20 -0
- package/src/utils/empty-completion-retry.ts +159 -0
- package/src/utils/event-stream.ts +171 -0
- package/src/utils/foundry.ts +8 -0
- package/src/utils/google-validation.ts +25 -0
- package/src/utils/harmony-leak.ts +456 -0
- package/src/utils/http-inspector.ts +168 -0
- package/src/utils/idle-iterator.ts +473 -0
- package/src/utils/leaked-thinking-stream.ts +294 -0
- package/src/utils/openai-http.ts +122 -0
- package/src/utils/openrouter-headers.ts +12 -0
- package/src/utils/parse-bind.ts +56 -0
- package/src/utils/provider-response.ts +30 -0
- package/src/utils/proxy.ts +240 -0
- package/src/utils/request-debug.ts +351 -0
- package/src/utils/retry-after.ts +110 -0
- package/src/utils/retry.ts +59 -0
- package/src/utils/schema/CONSTRAINTS.md +166 -0
- package/src/utils/schema/adapt.ts +36 -0
- package/src/utils/schema/compatibility.ts +435 -0
- package/src/utils/schema/dereference.ts +98 -0
- package/src/utils/schema/draft.ts +341 -0
- package/src/utils/schema/equality.ts +97 -0
- package/src/utils/schema/fields.ts +207 -0
- package/src/utils/schema/index.ts +15 -0
- package/src/utils/schema/json-schema-validator.ts +595 -0
- package/src/utils/schema/meta-validator.ts +167 -0
- package/src/utils/schema/normalize.ts +1901 -0
- package/src/utils/schema/spill.ts +43 -0
- package/src/utils/schema/stamps.ts +109 -0
- package/src/utils/schema/strict-tool-validation.ts +117 -0
- package/src/utils/schema/types.ts +10 -0
- package/src/utils/schema/typescript.ts +198 -0
- package/src/utils/schema/wire.ts +789 -0
- package/src/utils/schema/zod-decontaminate.ts +331 -0
- package/src/utils/sdk-stream-timeout.ts +43 -0
- package/src/utils/sse-debug.ts +18 -0
- package/src/utils/stream-markup-healing.ts +247 -0
- package/src/utils/thinking-loop.ts +552 -0
- package/src/utils/tool-call-loop-guard.ts +107 -0
- package/src/utils/tool-choice.ts +99 -0
- package/src/utils/validation.ts +1507 -0
- package/src/utils.ts +171 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import type {
|
|
3
|
+
CredentialRankingStrategy,
|
|
4
|
+
UsageAmount,
|
|
5
|
+
UsageFetchContext,
|
|
6
|
+
UsageFetchParams,
|
|
7
|
+
UsageLimit,
|
|
8
|
+
UsageProvider,
|
|
9
|
+
UsageReport,
|
|
10
|
+
UsageResetCredits,
|
|
11
|
+
UsageWindow,
|
|
12
|
+
} from "../usage";
|
|
13
|
+
import { isRecord } from "../utils";
|
|
14
|
+
import { normalizeCodexBaseUrl } from "./openai-codex-base-url";
|
|
15
|
+
import { listCodexResetCredits } from "./openai-codex-reset";
|
|
16
|
+
import { toNumber } from "./shared";
|
|
17
|
+
|
|
18
|
+
const CODEX_USAGE_PATH = "wham/usage";
|
|
19
|
+
const JWT_AUTH_CLAIM = "https://api.openai.com/auth";
|
|
20
|
+
const JWT_PROFILE_CLAIM = "https://api.openai.com/profile";
|
|
21
|
+
|
|
22
|
+
interface CodexUsageWindowPayload {
|
|
23
|
+
used_percent?: number;
|
|
24
|
+
limit_window_seconds?: number;
|
|
25
|
+
reset_after_seconds?: number;
|
|
26
|
+
reset_at?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface CodexUsageRateLimitPayload {
|
|
30
|
+
allowed?: boolean;
|
|
31
|
+
limit_reached?: boolean;
|
|
32
|
+
primary_window?: CodexUsageWindowPayload | null;
|
|
33
|
+
secondary_window?: CodexUsageWindowPayload | null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface CodexUsageAdditionalRateLimitPayload {
|
|
37
|
+
limit_name?: string;
|
|
38
|
+
metered_feature?: string;
|
|
39
|
+
rate_limit?: CodexUsageRateLimitPayload | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface CodexUsagePayload {
|
|
43
|
+
plan_type?: string;
|
|
44
|
+
rate_limit?: CodexUsageRateLimitPayload | null;
|
|
45
|
+
additional_rate_limits?: CodexUsageAdditionalRateLimitPayload[] | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ParsedUsageWindow {
|
|
49
|
+
usedPercent?: number;
|
|
50
|
+
limitWindowSeconds?: number;
|
|
51
|
+
resetAfterSeconds?: number;
|
|
52
|
+
resetAt?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface ParsedAdditionalUsage {
|
|
56
|
+
limitName?: string;
|
|
57
|
+
meteredFeature?: string;
|
|
58
|
+
allowed?: boolean;
|
|
59
|
+
limitReached?: boolean;
|
|
60
|
+
primary?: ParsedUsageWindow;
|
|
61
|
+
secondary?: ParsedUsageWindow;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface ParsedUsage {
|
|
65
|
+
planType?: string;
|
|
66
|
+
allowed?: boolean;
|
|
67
|
+
limitReached?: boolean;
|
|
68
|
+
primary?: ParsedUsageWindow;
|
|
69
|
+
secondary?: ParsedUsageWindow;
|
|
70
|
+
additional: ParsedAdditionalUsage[];
|
|
71
|
+
raw: CodexUsagePayload;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface JwtPayload {
|
|
75
|
+
[JWT_AUTH_CLAIM]?: {
|
|
76
|
+
chatgpt_account_id?: string;
|
|
77
|
+
};
|
|
78
|
+
[JWT_PROFILE_CLAIM]?: {
|
|
79
|
+
email?: string;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const toBoolean = (value: unknown): boolean | undefined => {
|
|
84
|
+
if (typeof value === "boolean") return value;
|
|
85
|
+
return undefined;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
function base64UrlDecode(input: string): string {
|
|
89
|
+
const base64 = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
90
|
+
const padLen = (4 - (base64.length % 4)) % 4;
|
|
91
|
+
const padded = base64 + "=".repeat(padLen);
|
|
92
|
+
return Buffer.from(padded, "base64").toString("utf8");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function parseJwt(token: string): JwtPayload | null {
|
|
96
|
+
const parts = token.split(".");
|
|
97
|
+
if (parts.length !== 3) return null;
|
|
98
|
+
try {
|
|
99
|
+
const payloadJson = base64UrlDecode(parts[1]);
|
|
100
|
+
return JSON.parse(payloadJson) as JwtPayload;
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function normalizeEmail(email: string | undefined): string | undefined {
|
|
107
|
+
if (!email) return undefined;
|
|
108
|
+
const normalized = email.trim().toLowerCase();
|
|
109
|
+
return normalized || undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function extractAccountId(token: string | undefined): string | undefined {
|
|
113
|
+
if (!token) return undefined;
|
|
114
|
+
const payload = parseJwt(token);
|
|
115
|
+
return payload?.[JWT_AUTH_CLAIM]?.chatgpt_account_id ?? undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function extractEmail(token: string | undefined): string | undefined {
|
|
119
|
+
if (!token) return undefined;
|
|
120
|
+
const payload = parseJwt(token);
|
|
121
|
+
return normalizeEmail(payload?.[JWT_PROFILE_CLAIM]?.email);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function parseUsageWindow(payload: unknown): ParsedUsageWindow | undefined {
|
|
125
|
+
if (!isRecord(payload)) return undefined;
|
|
126
|
+
const usedPercent = toNumber(payload.used_percent);
|
|
127
|
+
const limitWindowSeconds = toNumber(payload.limit_window_seconds);
|
|
128
|
+
const resetAfterSeconds = toNumber(payload.reset_after_seconds);
|
|
129
|
+
const resetAt = toNumber(payload.reset_at);
|
|
130
|
+
if (
|
|
131
|
+
usedPercent === undefined &&
|
|
132
|
+
limitWindowSeconds === undefined &&
|
|
133
|
+
resetAfterSeconds === undefined &&
|
|
134
|
+
resetAt === undefined
|
|
135
|
+
) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
usedPercent,
|
|
140
|
+
limitWindowSeconds,
|
|
141
|
+
resetAfterSeconds,
|
|
142
|
+
resetAt,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function parseAdditionalRateLimit(payload: unknown): ParsedAdditionalUsage | null {
|
|
147
|
+
if (!isRecord(payload)) return null;
|
|
148
|
+
const limitName = typeof payload.limit_name === "string" ? payload.limit_name : undefined;
|
|
149
|
+
const meteredFeature = typeof payload.metered_feature === "string" ? payload.metered_feature : undefined;
|
|
150
|
+
const rateLimit = isRecord(payload.rate_limit) ? payload.rate_limit : undefined;
|
|
151
|
+
if (!rateLimit) return null;
|
|
152
|
+
const primary = parseUsageWindow(rateLimit.primary_window);
|
|
153
|
+
const secondary = parseUsageWindow(rateLimit.secondary_window);
|
|
154
|
+
const allowed = toBoolean(rateLimit.allowed);
|
|
155
|
+
const limitReached = toBoolean(rateLimit.limit_reached);
|
|
156
|
+
if (!primary && !secondary && allowed === undefined && limitReached === undefined) return null;
|
|
157
|
+
return { limitName, meteredFeature, allowed, limitReached, primary, secondary };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function parseUsagePayload(payload: unknown): ParsedUsage | null {
|
|
161
|
+
if (!isRecord(payload)) return null;
|
|
162
|
+
const planType = typeof payload.plan_type === "string" ? payload.plan_type : undefined;
|
|
163
|
+
const rateLimit = isRecord(payload.rate_limit) ? payload.rate_limit : undefined;
|
|
164
|
+
const additionalRaw = Array.isArray(payload.additional_rate_limits) ? payload.additional_rate_limits : [];
|
|
165
|
+
const additional = additionalRaw
|
|
166
|
+
.map(parseAdditionalRateLimit)
|
|
167
|
+
.filter((value): value is ParsedAdditionalUsage => value !== null);
|
|
168
|
+
if (!rateLimit && additional.length === 0) return null;
|
|
169
|
+
const parsed: ParsedUsage = {
|
|
170
|
+
planType,
|
|
171
|
+
allowed: rateLimit ? toBoolean(rateLimit.allowed) : undefined,
|
|
172
|
+
limitReached: rateLimit ? toBoolean(rateLimit.limit_reached) : undefined,
|
|
173
|
+
primary: rateLimit ? parseUsageWindow(rateLimit.primary_window) : undefined,
|
|
174
|
+
secondary: rateLimit ? parseUsageWindow(rateLimit.secondary_window) : undefined,
|
|
175
|
+
additional,
|
|
176
|
+
raw: payload as CodexUsagePayload,
|
|
177
|
+
};
|
|
178
|
+
if (
|
|
179
|
+
!parsed.primary &&
|
|
180
|
+
!parsed.secondary &&
|
|
181
|
+
parsed.allowed === undefined &&
|
|
182
|
+
parsed.limitReached === undefined &&
|
|
183
|
+
parsed.additional.length === 0
|
|
184
|
+
) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
return parsed;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Parse the `rate_limit_reset_credits` block from `/wham/usage`. OpenAI Codex
|
|
192
|
+
* reports the count of saved rate-limit resets the account can redeem here; the
|
|
193
|
+
* redeem action itself lives in `./openai-codex-reset`.
|
|
194
|
+
*/
|
|
195
|
+
function parseResetCredits(payload: unknown): UsageResetCredits | undefined {
|
|
196
|
+
if (!isRecord(payload)) return undefined;
|
|
197
|
+
const block = payload.rate_limit_reset_credits;
|
|
198
|
+
if (!isRecord(block)) return undefined;
|
|
199
|
+
const availableCount = toNumber(block.available_count);
|
|
200
|
+
if (availableCount === undefined) return undefined;
|
|
201
|
+
return { availableCount: Math.max(0, Math.trunc(availableCount)) };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function buildCodexUsageUrl(baseUrl: string): string {
|
|
205
|
+
const normalized = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
206
|
+
return `${normalized}${CODEX_USAGE_PATH}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function formatWindowLabel(value: number, unit: "hour" | "day"): string {
|
|
210
|
+
const rounded = Math.round(value);
|
|
211
|
+
const suffix = rounded === 1 ? unit : `${unit}s`;
|
|
212
|
+
return `${rounded} ${suffix}`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function buildWindowLabel(seconds: number): { id: string; label: string } {
|
|
216
|
+
const daySeconds = 86_400;
|
|
217
|
+
if (seconds >= daySeconds) {
|
|
218
|
+
const days = Math.round(seconds / daySeconds);
|
|
219
|
+
return { id: `${days}d`, label: formatWindowLabel(days, "day") };
|
|
220
|
+
}
|
|
221
|
+
const hours = Math.max(1, Math.round(seconds / 3600));
|
|
222
|
+
return { id: `${hours}h`, label: formatWindowLabel(hours, "hour") };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function resolveResetTime(window: ParsedUsageWindow, nowMs: number): number | undefined {
|
|
226
|
+
const resetAt = window.resetAt;
|
|
227
|
+
if (resetAt !== undefined) {
|
|
228
|
+
const resetAtMs = resetAt > 1_000_000_000_000 ? resetAt : resetAt * 1000;
|
|
229
|
+
if (Number.isFinite(resetAtMs)) return resetAtMs;
|
|
230
|
+
}
|
|
231
|
+
if (window.resetAfterSeconds !== undefined) {
|
|
232
|
+
return nowMs + window.resetAfterSeconds * 1000;
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function buildUsageWindow(window: ParsedUsageWindow, key: string, nowMs: number): UsageWindow {
|
|
238
|
+
const resetsAt = resolveResetTime(window, nowMs);
|
|
239
|
+
if (window.limitWindowSeconds !== undefined) {
|
|
240
|
+
const { id, label } = buildWindowLabel(window.limitWindowSeconds);
|
|
241
|
+
const durationMs = window.limitWindowSeconds * 1000;
|
|
242
|
+
return { id, label, durationMs, ...(resetsAt !== undefined ? { resetsAt } : {}) };
|
|
243
|
+
}
|
|
244
|
+
const fallbackLabel = key === "primary" ? "Primary window" : "Secondary window";
|
|
245
|
+
return { id: key, label: fallbackLabel, ...(resetsAt !== undefined ? { resetsAt } : {}) };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function buildUsageAmount(window: ParsedUsageWindow): UsageAmount {
|
|
249
|
+
const usedPercent = window.usedPercent;
|
|
250
|
+
if (usedPercent === undefined) {
|
|
251
|
+
return { unit: "percent" };
|
|
252
|
+
}
|
|
253
|
+
const clamped = Math.min(Math.max(usedPercent, 0), 100);
|
|
254
|
+
const usedFraction = clamped / 100;
|
|
255
|
+
return {
|
|
256
|
+
used: clamped,
|
|
257
|
+
limit: 100,
|
|
258
|
+
remaining: Math.max(0, 100 - clamped),
|
|
259
|
+
usedFraction,
|
|
260
|
+
remainingFraction: Math.max(0, 1 - usedFraction),
|
|
261
|
+
unit: "percent",
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function buildUsageStatus(usedFraction?: number, limitReached?: boolean): UsageLimit["status"] {
|
|
266
|
+
if (limitReached) return "exhausted";
|
|
267
|
+
if (usedFraction === undefined) return "unknown";
|
|
268
|
+
if (usedFraction >= 1) return "exhausted";
|
|
269
|
+
if (usedFraction >= 0.9) return "warning";
|
|
270
|
+
return "ok";
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function buildUsageLimit(args: {
|
|
274
|
+
key: "primary" | "secondary";
|
|
275
|
+
window: ParsedUsageWindow;
|
|
276
|
+
accountId?: string;
|
|
277
|
+
planType?: string;
|
|
278
|
+
limitReached?: boolean;
|
|
279
|
+
nowMs: number;
|
|
280
|
+
}): UsageLimit {
|
|
281
|
+
const usageWindow = buildUsageWindow(args.window, args.key, args.nowMs);
|
|
282
|
+
const amount = buildUsageAmount(args.window);
|
|
283
|
+
return {
|
|
284
|
+
id: `openai-codex:${args.key}`,
|
|
285
|
+
label: usageWindow.label,
|
|
286
|
+
scope: {
|
|
287
|
+
provider: "openai-codex",
|
|
288
|
+
accountId: args.accountId,
|
|
289
|
+
tier: args.planType,
|
|
290
|
+
windowId: usageWindow.id,
|
|
291
|
+
shared: true,
|
|
292
|
+
},
|
|
293
|
+
window: usageWindow,
|
|
294
|
+
amount,
|
|
295
|
+
status: buildUsageStatus(amount.usedFraction, args.limitReached),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function additionalLimitSlug(args: { limitName?: string; meteredFeature?: string }): string {
|
|
299
|
+
const probe = `${args.limitName ?? ""} ${args.meteredFeature ?? ""}`.toLowerCase();
|
|
300
|
+
if (probe.includes("spark") || probe.includes("bengalfox")) return "spark";
|
|
301
|
+
const source = (args.meteredFeature ?? args.limitName ?? "extra").toLowerCase();
|
|
302
|
+
return (
|
|
303
|
+
source
|
|
304
|
+
.replace(/^codex[-_]/, "")
|
|
305
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
306
|
+
.replace(/^-+|-+$/g, "") || "extra"
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function additionalDisplayName(slug: string, limitName?: string): string {
|
|
311
|
+
if (slug === "spark") return "Spark";
|
|
312
|
+
if (limitName) return limitName;
|
|
313
|
+
return slug.replace(
|
|
314
|
+
/(^|-)([a-z])/g,
|
|
315
|
+
(_match, sep: string, ch: string) => `${sep === "-" ? " " : ""}${ch.toUpperCase()}`,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function buildAdditionalUsageLimit(args: {
|
|
320
|
+
key: "primary" | "secondary";
|
|
321
|
+
slug: string;
|
|
322
|
+
displayName: string;
|
|
323
|
+
window: ParsedUsageWindow;
|
|
324
|
+
accountId?: string;
|
|
325
|
+
limitReached?: boolean;
|
|
326
|
+
limitName?: string;
|
|
327
|
+
meteredFeature?: string;
|
|
328
|
+
nowMs: number;
|
|
329
|
+
}): UsageLimit {
|
|
330
|
+
const usageWindow = buildUsageWindow(args.window, args.key, args.nowMs);
|
|
331
|
+
const amount = buildUsageAmount(args.window);
|
|
332
|
+
return {
|
|
333
|
+
id: `openai-codex:${args.slug}:${args.key}`,
|
|
334
|
+
label: `${usageWindow.label} (${args.displayName})`,
|
|
335
|
+
scope: {
|
|
336
|
+
provider: "openai-codex",
|
|
337
|
+
accountId: args.accountId,
|
|
338
|
+
tier: args.slug,
|
|
339
|
+
modelId: args.limitName,
|
|
340
|
+
windowId: usageWindow.id,
|
|
341
|
+
shared: true,
|
|
342
|
+
},
|
|
343
|
+
window: usageWindow,
|
|
344
|
+
amount,
|
|
345
|
+
status: buildUsageStatus(amount.usedFraction, args.limitReached),
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export const openaiCodexUsageProvider: UsageProvider = {
|
|
350
|
+
id: "openai-codex",
|
|
351
|
+
supports(params: UsageFetchParams): boolean {
|
|
352
|
+
return params.provider === "openai-codex" && params.credential.type === "oauth";
|
|
353
|
+
},
|
|
354
|
+
async fetchUsage(params: UsageFetchParams, ctx: UsageFetchContext): Promise<UsageReport | null> {
|
|
355
|
+
if (params.provider !== "openai-codex") return null;
|
|
356
|
+
const { credential } = params;
|
|
357
|
+
if (credential.type !== "oauth") return null;
|
|
358
|
+
|
|
359
|
+
const accessToken = credential.accessToken;
|
|
360
|
+
if (!accessToken) return null;
|
|
361
|
+
|
|
362
|
+
const nowMs = Date.now();
|
|
363
|
+
if (credential.expiresAt !== undefined && credential.expiresAt <= nowMs) {
|
|
364
|
+
ctx.logger?.warn("Codex usage token expired", { provider: params.provider });
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const baseUrl = normalizeCodexBaseUrl(params.baseUrl);
|
|
369
|
+
const accountId = credential.accountId ?? extractAccountId(accessToken);
|
|
370
|
+
const email = normalizeEmail(credential.email ?? extractEmail(accessToken));
|
|
371
|
+
|
|
372
|
+
const headers: Record<string, string> = {
|
|
373
|
+
Authorization: `Bearer ${accessToken}`,
|
|
374
|
+
"User-Agent": "OpenCode-Status-Plugin/1.0",
|
|
375
|
+
};
|
|
376
|
+
if (accountId) {
|
|
377
|
+
headers["ChatGPT-Account-Id"] = accountId;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const url = buildCodexUsageUrl(baseUrl);
|
|
381
|
+
let payload: unknown;
|
|
382
|
+
try {
|
|
383
|
+
const response = await ctx.fetch(url, { headers, signal: params.signal });
|
|
384
|
+
if (!response.ok) {
|
|
385
|
+
ctx.logger?.warn("Codex usage request failed", { status: response.status, provider: params.provider });
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
payload = await response.json();
|
|
389
|
+
} catch (error) {
|
|
390
|
+
ctx.logger?.warn("Codex usage request error", { provider: params.provider, error: String(error) });
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const parsed = parseUsagePayload(payload);
|
|
395
|
+
const planType =
|
|
396
|
+
parsed?.planType ??
|
|
397
|
+
(isRecord(payload) && typeof payload.plan_type === "string" ? payload.plan_type : undefined);
|
|
398
|
+
|
|
399
|
+
const limits: UsageLimit[] = [];
|
|
400
|
+
if (parsed?.primary) {
|
|
401
|
+
limits.push(
|
|
402
|
+
buildUsageLimit({
|
|
403
|
+
key: "primary",
|
|
404
|
+
window: parsed.primary,
|
|
405
|
+
accountId,
|
|
406
|
+
planType,
|
|
407
|
+
limitReached: parsed.limitReached,
|
|
408
|
+
nowMs,
|
|
409
|
+
}),
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
if (parsed?.secondary) {
|
|
413
|
+
limits.push(
|
|
414
|
+
buildUsageLimit({
|
|
415
|
+
key: "secondary",
|
|
416
|
+
window: parsed.secondary,
|
|
417
|
+
accountId,
|
|
418
|
+
planType,
|
|
419
|
+
limitReached: parsed.limitReached,
|
|
420
|
+
nowMs,
|
|
421
|
+
}),
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
for (const extra of parsed?.additional ?? []) {
|
|
425
|
+
const slug = additionalLimitSlug({ limitName: extra.limitName, meteredFeature: extra.meteredFeature });
|
|
426
|
+
const displayName = additionalDisplayName(slug, extra.limitName);
|
|
427
|
+
if (extra.primary) {
|
|
428
|
+
limits.push(
|
|
429
|
+
buildAdditionalUsageLimit({
|
|
430
|
+
key: "primary",
|
|
431
|
+
slug,
|
|
432
|
+
displayName,
|
|
433
|
+
window: extra.primary,
|
|
434
|
+
accountId,
|
|
435
|
+
limitReached: extra.limitReached,
|
|
436
|
+
limitName: extra.limitName,
|
|
437
|
+
meteredFeature: extra.meteredFeature,
|
|
438
|
+
nowMs,
|
|
439
|
+
}),
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
if (extra.secondary) {
|
|
443
|
+
limits.push(
|
|
444
|
+
buildAdditionalUsageLimit({
|
|
445
|
+
key: "secondary",
|
|
446
|
+
slug,
|
|
447
|
+
displayName,
|
|
448
|
+
window: extra.secondary,
|
|
449
|
+
accountId,
|
|
450
|
+
limitReached: extra.limitReached,
|
|
451
|
+
limitName: extra.limitName,
|
|
452
|
+
meteredFeature: extra.meteredFeature,
|
|
453
|
+
nowMs,
|
|
454
|
+
}),
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const resetCredits = parseResetCredits(payload);
|
|
460
|
+
if (resetCredits && resetCredits.availableCount > 0) {
|
|
461
|
+
try {
|
|
462
|
+
const list = await listCodexResetCredits({
|
|
463
|
+
accessToken,
|
|
464
|
+
accountId,
|
|
465
|
+
baseUrl: params.baseUrl,
|
|
466
|
+
fetch: ctx.fetch,
|
|
467
|
+
signal: params.signal,
|
|
468
|
+
});
|
|
469
|
+
if (list?.credits.length) {
|
|
470
|
+
resetCredits.credits = list.credits
|
|
471
|
+
.filter(c => (c.status ?? "available") === "available")
|
|
472
|
+
.map(c => ({
|
|
473
|
+
grantedAt: c.grantedAt,
|
|
474
|
+
expiresAt: c.expiresAt,
|
|
475
|
+
status: c.status,
|
|
476
|
+
}));
|
|
477
|
+
}
|
|
478
|
+
// Always sync the live count from the detail endpoint — it may report
|
|
479
|
+
// fewer or zero available credits after expiry/redeem, even when the
|
|
480
|
+
// /wham/usage payload still has a stale count.
|
|
481
|
+
if (list) {
|
|
482
|
+
resetCredits.availableCount = list.availableCount;
|
|
483
|
+
}
|
|
484
|
+
} catch (error) {
|
|
485
|
+
ctx.logger?.warn("Codex reset credits detail fetch failed", { error: String(error) });
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const report: UsageReport = {
|
|
489
|
+
provider: "openai-codex",
|
|
490
|
+
fetchedAt: nowMs,
|
|
491
|
+
limits,
|
|
492
|
+
...(resetCredits ? { resetCredits } : {}),
|
|
493
|
+
metadata: {
|
|
494
|
+
planType,
|
|
495
|
+
allowed: parsed?.allowed,
|
|
496
|
+
limitReached: parsed?.limitReached,
|
|
497
|
+
email,
|
|
498
|
+
accountId,
|
|
499
|
+
},
|
|
500
|
+
raw: parsed?.raw ?? payload,
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
return report;
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
const FIVE_HOUR_MS = 5 * 60 * 60 * 1000;
|
|
508
|
+
|
|
509
|
+
export const codexRankingStrategy: CredentialRankingStrategy = {
|
|
510
|
+
findWindowLimits(report) {
|
|
511
|
+
const findLimit = (key: "primary" | "secondary"): UsageLimit | undefined => {
|
|
512
|
+
const direct = report.limits.find(l => l.id === `openai-codex:${key}`);
|
|
513
|
+
if (direct) return direct;
|
|
514
|
+
const byId = report.limits.find(l => l.id.toLowerCase().includes(key));
|
|
515
|
+
if (byId) return byId;
|
|
516
|
+
const windowId = key === "secondary" ? "7d" : "1h";
|
|
517
|
+
return report.limits.find(l => l.scope.windowId?.toLowerCase() === windowId);
|
|
518
|
+
};
|
|
519
|
+
return { primary: findLimit("primary"), secondary: findLimit("secondary") };
|
|
520
|
+
},
|
|
521
|
+
windowDefaults: { primaryMs: 60 * 60 * 1000, secondaryMs: 7 * 24 * 60 * 60 * 1000 },
|
|
522
|
+
hasPriorityBoost(primary) {
|
|
523
|
+
if (!primary) return false;
|
|
524
|
+
const windowId = primary.scope.windowId?.toLowerCase();
|
|
525
|
+
const durationMs = primary.window?.durationMs;
|
|
526
|
+
const isFiveHourWindow =
|
|
527
|
+
windowId === "5h" ||
|
|
528
|
+
(typeof durationMs === "number" &&
|
|
529
|
+
Number.isFinite(durationMs) &&
|
|
530
|
+
Math.abs(durationMs - FIVE_HOUR_MS) <= 60_000);
|
|
531
|
+
if (!isFiveHourWindow) return false;
|
|
532
|
+
const usedFraction = primary.amount.usedFraction;
|
|
533
|
+
return typeof usedFraction === "number" && Number.isFinite(usedFraction) && usedFraction === 0;
|
|
534
|
+
},
|
|
535
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { UsageCostHistoryEntry, UsageLimit, UsageProvider, UsageWindow } from "../usage";
|
|
2
|
+
|
|
3
|
+
const OPENCODE_GO_PROVIDER = "opencode-go";
|
|
4
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
5
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
6
|
+
const OPENCODE_GO_LIMITS = [
|
|
7
|
+
{ id: "rolling-5h", label: "5 Hour", durationMs: 5 * HOUR_MS, limitUsd: 12 },
|
|
8
|
+
{ id: "weekly", label: "Weekly", durationMs: 7 * DAY_MS, limitUsd: 30 },
|
|
9
|
+
{ id: "monthly", label: "Monthly", durationMs: 30 * DAY_MS, limitUsd: 60 },
|
|
10
|
+
] as const;
|
|
11
|
+
|
|
12
|
+
function sumWindowCosts(entries: UsageCostHistoryEntry[], sinceMs: number): { used: number; resetsAt?: number } {
|
|
13
|
+
let used = 0;
|
|
14
|
+
let firstRecordedAt: number | undefined;
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
if (entry.recordedAt < sinceMs) continue;
|
|
17
|
+
used += entry.costUsd;
|
|
18
|
+
if (firstRecordedAt === undefined || entry.recordedAt < firstRecordedAt) {
|
|
19
|
+
firstRecordedAt = entry.recordedAt;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { used, resetsAt: firstRecordedAt };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function resolveStatus(usedFraction: number): UsageLimit["status"] {
|
|
26
|
+
if (usedFraction >= 1) return "exhausted";
|
|
27
|
+
if (usedFraction >= 0.8) return "warning";
|
|
28
|
+
return "ok";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function buildWindowLimit(
|
|
32
|
+
limit: (typeof OPENCODE_GO_LIMITS)[number],
|
|
33
|
+
entries: UsageCostHistoryEntry[],
|
|
34
|
+
nowMs: number,
|
|
35
|
+
): UsageLimit {
|
|
36
|
+
const sinceMs = nowMs - limit.durationMs;
|
|
37
|
+
const windowCost = sumWindowCosts(entries, sinceMs);
|
|
38
|
+
const used = Number(windowCost.used.toFixed(6));
|
|
39
|
+
const usedFraction = used / limit.limitUsd;
|
|
40
|
+
const window: UsageWindow = {
|
|
41
|
+
id: limit.id,
|
|
42
|
+
label: limit.label,
|
|
43
|
+
durationMs: limit.durationMs,
|
|
44
|
+
};
|
|
45
|
+
if (windowCost.resetsAt !== undefined) {
|
|
46
|
+
window.resetsAt = windowCost.resetsAt + limit.durationMs;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
id: limit.id,
|
|
50
|
+
label: `${limit.label} limit`,
|
|
51
|
+
scope: {
|
|
52
|
+
provider: OPENCODE_GO_PROVIDER,
|
|
53
|
+
windowId: limit.id,
|
|
54
|
+
},
|
|
55
|
+
window,
|
|
56
|
+
amount: {
|
|
57
|
+
used,
|
|
58
|
+
limit: limit.limitUsd,
|
|
59
|
+
remaining: Math.max(0, limit.limitUsd - used),
|
|
60
|
+
usedFraction,
|
|
61
|
+
remainingFraction: Math.max(0, 1 - usedFraction),
|
|
62
|
+
unit: "usd",
|
|
63
|
+
},
|
|
64
|
+
status: resolveStatus(usedFraction),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const opencodeGoUsageProvider: UsageProvider = {
|
|
69
|
+
id: OPENCODE_GO_PROVIDER,
|
|
70
|
+
supports: params => params.provider === OPENCODE_GO_PROVIDER && params.credential.type === "api_key",
|
|
71
|
+
validatesCredentials: false,
|
|
72
|
+
async fetchUsage(params, ctx) {
|
|
73
|
+
if (params.provider !== OPENCODE_GO_PROVIDER || params.credential.type !== "api_key") return null;
|
|
74
|
+
const nowMs = Date.now();
|
|
75
|
+
const sinceMs = nowMs - OPENCODE_GO_LIMITS[OPENCODE_GO_LIMITS.length - 1]!.durationMs;
|
|
76
|
+
const entries =
|
|
77
|
+
ctx.listUsageCosts?.({ provider: OPENCODE_GO_PROVIDER, accountKey: params.accountKey, sinceMs }) ?? [];
|
|
78
|
+
return {
|
|
79
|
+
provider: OPENCODE_GO_PROVIDER,
|
|
80
|
+
fetchedAt: nowMs,
|
|
81
|
+
limits: OPENCODE_GO_LIMITS.map(limit => buildWindowLimit(limit, entries, nowMs)),
|
|
82
|
+
notes: ["OMP-observed spend only; OpenCode usage outside OMP is not included."],
|
|
83
|
+
metadata: {
|
|
84
|
+
planType: "OpenCode Go",
|
|
85
|
+
source: "omp-observed-request-costs",
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const toNumber = (value: unknown): number | undefined => {
|
|
2
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
3
|
+
if (typeof value === "string") {
|
|
4
|
+
const trimmed = value.trim();
|
|
5
|
+
if (!trimmed) return undefined;
|
|
6
|
+
const parsed = Number(trimmed);
|
|
7
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
};
|