@gajae-code/ai 0.11.10 → 0.12.0

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/README.md +3 -0
  3. package/dist/types/provider-models/openai-compat.d.ts +7 -0
  4. package/dist/types/providers/anthropic.d.ts +2 -1
  5. package/dist/types/providers/azure-openai-responses.d.ts +6 -1
  6. package/dist/types/providers/google-auth.d.ts +2 -0
  7. package/dist/types/providers/google-gemini-headers.d.ts +1 -1
  8. package/dist/types/providers/google-vertex.d.ts +2 -0
  9. package/dist/types/providers/openai-codex-responses.d.ts +4 -0
  10. package/dist/types/providers/openai-completions.d.ts +2 -0
  11. package/dist/types/providers/openai-responses.d.ts +2 -0
  12. package/dist/types/types.d.ts +1 -1
  13. package/dist/types/usage/grok-cli.d.ts +3 -1
  14. package/dist/types/usage/kimi.d.ts +2 -0
  15. package/dist/types/utils/anthropic-auth.d.ts +8 -0
  16. package/dist/types/utils/foundry.d.ts +10 -0
  17. package/dist/types/utils/http-inspector.d.ts +13 -0
  18. package/dist/types/utils/idle-iterator.d.ts +2 -2
  19. package/dist/types/utils/oauth/bizrouter.d.ts +1 -0
  20. package/dist/types/utils/oauth/types.d.ts +1 -1
  21. package/package.json +2 -2
  22. package/src/auth-storage.ts +6 -0
  23. package/src/cli.ts +1 -0
  24. package/src/models.json +72 -0
  25. package/src/provider-models/descriptors.ts +7 -0
  26. package/src/provider-models/openai-compat.ts +67 -6
  27. package/src/providers/anthropic.ts +44 -4
  28. package/src/providers/azure-openai-responses.ts +16 -3
  29. package/src/providers/google-auth.ts +13 -2
  30. package/src/providers/google-gemini-headers.ts +1 -1
  31. package/src/providers/google-vertex.ts +7 -2
  32. package/src/providers/openai-codex-responses.ts +52 -10
  33. package/src/providers/openai-completions.ts +12 -2
  34. package/src/providers/openai-responses.ts +13 -9
  35. package/src/stream.ts +1 -0
  36. package/src/types.ts +1 -0
  37. package/src/usage/claude.ts +21 -3
  38. package/src/usage/grok-cli.ts +12 -1
  39. package/src/usage/kimi.ts +16 -2
  40. package/src/utils/anthropic-auth.ts +11 -3
  41. package/src/utils/foundry.ts +12 -2
  42. package/src/utils/http-inspector.ts +77 -0
  43. package/src/utils/idle-iterator.ts +15 -7
  44. package/src/utils/oauth/bizrouter.ts +15 -0
  45. package/src/utils/oauth/index.ts +6 -0
  46. package/src/utils/oauth/types.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -2,7 +2,34 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
- ## [0.11.10] - 2026-07-25
5
+ ## [0.12.0] - 2026-07-28
6
+
7
+ ### Added
8
+
9
+ - Added first-class support for **BizRouter**, an OpenAI-compatible Korean enterprise LLM gateway. Registers the `bizrouter` provider descriptor, `/login` entry (API-key paste validated against `https://api.bizrouter.ai/v1/models`), `BIZROUTER_API_KEY` environment resolution, and bundled `models.json` seed models. Models are discovered dynamically from `GET /v1/models` (base URL `https://api.bizrouter.ai/v1`).
10
+ ### Fixed
11
+
12
+ - Anthropic subscription OAuth requests now use the current Claude Code compatibility attribution (`2.1.219`, `sdk-cli`) instead of the stale `2.1.63` CLI fingerprint that Anthropic can misclassify as extra usage.
13
+ - Connection failures now name the transport code and the target URL. Bun reports DNS and socket failures as a bare `Error` whose message is a standalone hint ("Was there a typo in the url or port?", "Unable to connect. Is the computer able to access the url?") and keeps the actionable facts on `code` and `path`, but only `message` reached the assistant message. A provider outage, a local DNS failure, and a mistyped custom base URL therefore all rendered as the same context-free sentence with no host in it. Such failures now read `... (transport=FailedToOpenSocket url=https://chatgpt.com/backend-api/codex/responses)`; the URL is reduced to origin and path so a key carried in the query string is not surfaced.
14
+
15
+ ### Documentation
16
+
17
+ - `docs/environment-variables.md` now names the Anthropic Foundry gateway variables that are actually read: `CLAUDE_CODE_USE_FOUNDRY`, `CLAUDE_CODE_CLIENT_CERT`, and `CLAUDE_CODE_CLIENT_KEY`. The page advertised `ANTHROPIC_MODEL_CODE_*` spellings that no code path reads, so an operator following it could not enable Foundry mode at all, and the mTLS client material was silently ignored.
18
+
19
+ ## [0.11.11] - 2026-07-26
20
+
21
+ ### Fixed
22
+
23
+ - The Kimi usage endpoint base (`KIMI_CODE_BASE_URL`) is now resolved from trusted environment sources only. That base becomes the URL the usage request sends `Authorization: Bearer <accessToken>` to, so reading it through the merged view that includes the caller's `cwd/.env` let a repository collect the user's Kimi access token. An explicit caller-supplied base URL still takes precedence, and shell / user-level configuration is unchanged.
24
+ - The Gemini CLI compatibility version used in the outbound `User-Agent` is refreshed from `0.50.0` to `0.52.0`, matching the current upstream release. The repository ships `check-spoofed-versions` for exactly this, but that check is not wired into CI, so the value had drifted two minor releases behind.
25
+ - The OpenAI and Azure endpoint decisions are now resolved from trusted environment sources only: `OPENAI_BASE_URL` (streaming responses, completions, and the model manager) and `AZURE_OPENAI_BASE_URL`. `Bun.env` is `process.env` and the env module merges the caller's `cwd/.env` into it, so a repository could previously plant a `.env` that redirected authenticated requests; the two provider paths already reached for `$inheritedEnv` but re-admitted the project `.env` through a fallback. Resolution now goes through the non-project resolver (launching shell plus GJC/user-owned `.env` files); shell and user-level configuration is unchanged.
26
+ - The OpenAI and Azure endpoint decisions are now resolved from trusted environment sources only: `OPENAI_BASE_URL` (streaming responses, completions, and the model manager), `AZURE_OPENAI_BASE_URL`, and `AZURE_OPENAI_RESOURCE_NAME` (the alternate constructor for the same Azure host). `Bun.env` is `process.env` and the env module merges the caller's `cwd/.env` into it, so a repository could previously plant a `.env` that redirected authenticated requests; the two provider paths already reached for `$inheritedEnv` but re-admitted the project `.env` through a fallback. Resolution now goes through the non-project resolver (launching shell plus GJC/user-owned `.env` files); shell and user-level configuration is unchanged.
27
+ - Google credential material is now resolved from trusted environment sources only: the `GOOGLE_APPLICATION_CREDENTIALS` service-account / authorized-user file path used by the ADC loader, and `GOOGLE_CLOUD_API_KEY` used as the Vertex API key. Both were read through the merged view that includes the caller's `cwd/.env`, so a repository could ship a key file and point the agent at it, making it authenticate to Google as an identity the repository chose. `stream.ts` already resolved the same ADC variable through the non-project resolver; the two now agree. An explicit caller-supplied API key still takes precedence.
28
+ - The Grok usage token fallback (`GROK_CLI_OAUTH_TOKEN`) is now resolved from trusted environment sources only. It authenticates the billing/usage call, and reading it through the merged view that includes the caller's `cwd/.env` let a repository decide which account that call ran against. Stored credentials keep precedence, and shell / user-level configuration is unchanged.
29
+ - Anthropic `ping` keepalives no longer reset stream progress, so responses that stop producing content now reach the idle timeout instead of hanging indefinitely.
30
+ - The Anthropic endpoint decision is now resolved from trusted environment sources only: `ANTHROPIC_BASE_URL`, `FOUNDRY_BASE_URL`, `ZCODE_PLAN_ANTHROPIC_BASE_URL`, and the `CLAUDE_CODE_USE_FOUNDRY` mode switch. `Bun.env` is `process.env` and the env module merges the caller's `cwd/.env` into it, so a repository could previously plant a `.env` that redirected authenticated Anthropic requests — the resolved base URL becomes `${baseUrl}/v1/messages` while the headers carry the API key or OAuth token. Resolution now goes through the non-project resolver (launching shell plus GJC/user-owned `.env` files); shell and user-level configuration is unchanged.
31
+ - The documented `GJC_OPENAI_STREAM_IDLE_TIMEOUT_MS` environment variable now takes effect: the stream-watchdog idle-timeout helpers resolve it GJC-first before the legacy `PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` / `PI_STREAM_IDLE_TIMEOUT_MS` aliases (previously only the `PI_`-prefixed names were read, so setting the documented GJC name was a silent no-op).
32
+ - The documented OpenAI-code provider knobs now take effect: `GJC_OPENAI_CODE_DEBUG`, `GJC_OPENAI_CODE_WEBSOCKET`, `GJC_OPENAI_CODE_WEBSOCKET_IDLE_TIMEOUT_MS`, `GJC_OPENAI_CODE_WEBSOCKET_RETRY_BUDGET`, and `GJC_OPENAI_CODE_WEBSOCKET_RETRY_DELAY_MS` are resolved GJC-first ahead of the legacy `PI_CODEX_*` names. The Codex → OpenAI-code rename had updated the documentation but not the reads, so every documented name was a silent no-op.
6
33
 
7
34
  ## [0.11.9] - 2026-07-24
8
35
  ### Fixed
package/README.md CHANGED
@@ -70,6 +70,7 @@ Unified LLM API with automatic model discovery, provider configuration, token an
70
70
  - **Xiaomi MiMo** (requires `XIAOMI_API_KEY`)
71
71
  - **ZenMux** (requires `ZENMUX_API_KEY`)
72
72
  - **OpenGateway by Sionic AI** (requires `OPENGATEWAY_API_KEY`)
73
+ - **BizRouter** (requires `BIZROUTER_API_KEY`)
73
74
  - **Qwen Portal** (supports `QWEN_OAUTH_TOKEN` or `QWEN_PORTAL_API_KEY`)
74
75
  - **Cloudflare AI Gateway** (requires `CLOUDFLARE_AI_GATEWAY_API_KEY` and provider-specific gateway base URL)
75
76
  - **Ollama** (local OpenAI-compatible runtime; optional `OLLAMA_API_KEY`)
@@ -956,6 +957,7 @@ In Node.js environments, you can set environment variables to avoid passing API
956
957
  | Xiaomi MiMo | `XIAOMI_API_KEY` |
957
958
  | ZenMux | `ZENMUX_API_KEY` |
958
959
  | OpenGateway | `OPENGATEWAY_API_KEY` |
960
+ | BizRouter | `BIZROUTER_API_KEY` |
959
961
  | vLLM | `VLLM_API_KEY` |
960
962
  | Cloudflare AI Gateway | `CLOUDFLARE_AI_GATEWAY_API_KEY` |
961
963
  | GitHub Copilot | `COPILOT_GITHUB_TOKEN` or `GH_TOKEN` or `GITHUB_TOKEN` |
@@ -980,6 +982,7 @@ Provider endpoint defaults for the current OpenAI-compatible integrations:
980
982
  - ZenMux (OpenAI): `https://zenmux.ai/api/v1`
981
983
  - ZenMux (Anthropic models): `https://zenmux.ai/api/anthropic`
982
984
  - OpenGateway by Sionic AI: `https://apis.opengateway.ai/v1`
985
+ - BizRouter: `https://api.bizrouter.ai/v1`
983
986
  - vLLM: `http://127.0.0.1:8000/v1`
984
987
  - Ollama: local OpenAI-compatible runtime (`http://127.0.0.1:11434/v1`)
985
988
  - Ollama Cloud: native Ollama API host (`https://ollama.com/api`, configured here as base URL `https://ollama.com`)
@@ -27,6 +27,8 @@ export interface OpenAIModelManagerConfig {
27
27
  apiKey?: string;
28
28
  baseUrl?: string;
29
29
  }
30
+ /** Test seam: the model-manager base URL as resolved from trusted env. */
31
+ export declare function resolveOpenAIModelManagerBaseUrlForTest(config?: OpenAIModelManagerConfig): string;
30
32
  export declare function openaiModelManagerOptions(config?: OpenAIModelManagerConfig): ModelManagerOptions<"openai-responses">;
31
33
  export interface GroqModelManagerConfig {
32
34
  apiKey?: string;
@@ -121,6 +123,11 @@ export interface OpenGatewayModelManagerConfig {
121
123
  * the OpenAI-compatible `/v1/models` endpoint.
122
124
  */
123
125
  export declare function opengatewayModelManagerOptions(config?: OpenGatewayModelManagerConfig): ModelManagerOptions<"openai-completions">;
126
+ export interface BizRouterModelManagerConfig {
127
+ apiKey?: string;
128
+ baseUrl?: string;
129
+ }
130
+ export declare function bizrouterModelManagerOptions(config?: BizRouterModelManagerConfig): ModelManagerOptions<"openai-completions">;
124
131
  export interface KiloModelManagerConfig {
125
132
  apiKey?: string;
126
133
  baseUrl?: string;
@@ -50,7 +50,8 @@ export declare function isAnthropicThinkingBlockMutationError(error: unknown): b
50
50
  * than only the latest one.
51
51
  */
52
52
  export declare function isAnthropicThinkingSignatureInvalidError(error: unknown): boolean;
53
- export declare const claudeCodeVersion = "2.1.63";
53
+ export declare const claudeCodeVersion = "2.1.219";
54
+ export declare const claudeCodeEntrypoint = "sdk-cli";
54
55
  export declare const claudeToolPrefix: string;
55
56
  export declare const claudeCodeSystemInstruction = "You are a Claude agent, built on Anthropic's Claude Agent SDK.";
56
57
  export declare function mapStainlessOs(platform: string): "MacOS" | "Windows" | "Linux" | "FreeBSD" | `Other::${string}`;
@@ -1,4 +1,4 @@
1
- import type { ServiceTier, StreamFunction, StreamOptions, ToolChoice } from "../types";
1
+ import type { Model, ServiceTier, StreamFunction, StreamOptions, ToolChoice } from "../types";
2
2
  export interface AzureOpenAIResponsesOptions extends StreamOptions {
3
3
  reasoning?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
4
4
  reasoningSummary?: "auto" | "detailed" | "concise" | null;
@@ -13,3 +13,8 @@ export interface AzureOpenAIResponsesOptions extends StreamOptions {
13
13
  * Generate function for Azure OpenAI Responses API
14
14
  */
15
15
  export declare const streamAzureOpenAIResponses: StreamFunction<"azure-openai-responses">;
16
+ /** Test seam: the Azure endpoint config as resolved from trusted env. */
17
+ export declare function resolveAzureConfigForTest(model: Model<"azure-openai-responses">, options?: AzureOpenAIResponsesOptions): {
18
+ baseUrl: string;
19
+ apiVersion: string;
20
+ };
@@ -12,6 +12,8 @@
12
12
  * (default 60s). Concurrent callers waiting on a refresh share the same in-flight promise.
13
13
  */
14
14
  import type { FetchImpl } from "../types";
15
+ /** Test seam: the ADC credentials file path as resolved from trusted env. */
16
+ export declare function resolveAdcCredentialsPathForTest(): string | undefined;
15
17
  /**
16
18
  * Returns a Bearer access token suitable for the `Authorization` header on Vertex AI calls.
17
19
  * The token is cached in module scope and refreshed `GOOGLE_VERTEX_REFRESH_SKEW_MS` ms before it expires.
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export declare const GEMINI_CLI_VERSION_ENV = "GJC_AI_GEMINI_CLI_VERSION";
7
7
  export declare const LEGACY_GEMINI_CLI_VERSION_ENV = "PI_AI_GEMINI_CLI_VERSION";
8
- export declare const DEFAULT_GEMINI_CLI_VERSION = "0.50.0";
8
+ export declare const DEFAULT_GEMINI_CLI_VERSION = "0.52.0";
9
9
  export declare function getGeminiCliUserAgent(modelId?: string): string;
10
10
  export declare const getGeminiCliHeaders: (modelId?: string) => {
11
11
  "User-Agent": string;
@@ -5,3 +5,5 @@ export interface GoogleVertexOptions extends GoogleSharedStreamOptions {
5
5
  location?: string;
6
6
  }
7
7
  export declare const streamGoogleVertex: StreamFunction<"google-vertex">;
8
+ /** Test seam: the Vertex API key as resolved from options plus trusted env. */
9
+ export declare function resolveVertexApiKeyForTest(options?: GoogleVertexOptions): string | undefined;
@@ -10,6 +10,10 @@ export interface OpenAICodexResponsesOptions extends StreamOptions {
10
10
  preferWebsockets?: boolean;
11
11
  serviceTier?: ServiceTier;
12
12
  }
13
+ /** Maps a canonical tool name to the name Codex accepts on the wire. */
14
+ export declare function codexToolWireName(name: string): string;
15
+ /** Maps a Codex wire tool name back to the canonical harness tool name. */
16
+ export declare function codexToolCanonicalName(wireName: string): string;
13
17
  type CodexTransport = "sse" | "websocket";
14
18
  export interface OpenAICodexWebSocketDebugStats {
15
19
  fullContextRequests: number;
@@ -1,6 +1,8 @@
1
1
  import type { ChatCompletionMessageParam } from "openai/resources/chat/completions";
2
2
  import { type AssistantMessage, type Context, type Model, type ServiceTier, type StreamFunction, type StreamOptions, type ToolChoice } from "../types";
3
3
  import { type ResolvedOpenAICompat } from "./openai-completions-compat";
4
+ /** Test seam: the provider base URL as resolved from trusted env. */
5
+ export declare function resolveOpenAICompletionsBaseUrlForTest(baseUrl: string | undefined, authCredentialType: "api_key" | "oauth" | undefined): string;
4
6
  /**
5
7
  * Identify "real progress" stream chunks vs. keepalives, role-only preambles,
6
8
  * and empty `{choices:[]}` no-ops emitted by some OpenAI-compatible endpoints.
@@ -13,6 +13,8 @@ export interface OpenAIResponsesOptions extends StreamOptions {
13
13
  */
14
14
  strictResponsesPairing?: boolean;
15
15
  }
16
+ /** Test seam: the provider base URL as resolved from trusted env. */
17
+ export declare function resolveOpenAIProviderBaseUrlForTest(baseUrl: string | undefined, authCredentialType: "api_key" | "oauth" | undefined): string;
16
18
  /**
17
19
  * Generate function for OpenAI Responses API
18
20
  */
@@ -51,7 +51,7 @@ export interface ThinkingConfig {
51
51
  /** Provider-specific transport used to encode the selected effort. */
52
52
  mode: ThinkingControlMode;
53
53
  }
54
- export type KnownProvider = "alibaba-token-plan" | "amazon-bedrock" | "azure-openai" | "anthropic" | "google" | "google-gemini-cli" | "google-antigravity" | "google-vertex" | "openai" | "openai-codex" | "kimi-code" | "minimax-code" | "minimax-code-cn" | "github-copilot" | "fireworks" | "firepass" | "fugu" | "gitlab-duo" | "cursor" | "deepseek" | "deepinfra" | "xai" | "groq" | "cerebras" | "openrouter" | "kilo" | "vercel-ai-gateway" | "zai" | "glm-zcode" | "mistral" | "minimax" | "opencode-go" | "opencode-zen" | "opengateway" | "synthetic" | "cloudflare-ai-gateway" | "huggingface" | "litellm" | "moonshot" | "nvidia" | "nanogpt" | "ollama" | "ollama-cloud" | "qianfan" | "qwen-portal" | "together" | "venice" | "vllm" | "xiaomi" | "xiaomi-token-plan-sgp" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-cn" | "zenmux" | "lm-studio";
54
+ export type KnownProvider = "alibaba-token-plan" | "amazon-bedrock" | "azure-openai" | "anthropic" | "google" | "google-gemini-cli" | "google-antigravity" | "google-vertex" | "openai" | "openai-codex" | "kimi-code" | "minimax-code" | "minimax-code-cn" | "github-copilot" | "fireworks" | "firepass" | "fugu" | "gitlab-duo" | "cursor" | "deepseek" | "deepinfra" | "xai" | "groq" | "cerebras" | "openrouter" | "kilo" | "vercel-ai-gateway" | "zai" | "glm-zcode" | "mistral" | "minimax" | "opencode-go" | "opencode-zen" | "opengateway" | "bizrouter" | "synthetic" | "cloudflare-ai-gateway" | "huggingface" | "litellm" | "moonshot" | "nvidia" | "nanogpt" | "ollama" | "ollama-cloud" | "qianfan" | "qwen-portal" | "together" | "venice" | "vllm" | "xiaomi" | "xiaomi-token-plan-sgp" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-cn" | "zenmux" | "lm-studio";
55
55
  export type Provider = KnownProvider | string;
56
56
  import type { Effort } from "./model-thinking";
57
57
  /** Token budgets for each thinking level (token-based providers only) */
@@ -1,10 +1,12 @@
1
- import type { CredentialRankingStrategy, UsageProvider } from "../usage";
1
+ import type { CredentialRankingStrategy, UsageFetchParams, UsageProvider } from "../usage";
2
2
  interface BillingUsage {
3
3
  monthlyLimit: number;
4
4
  used: number;
5
5
  billingPeriodEnd: string;
6
6
  }
7
7
  export declare function parseGrokCliBillingUsage(payload: unknown): BillingUsage;
8
+ /** Test seam: the usage access token as resolved from a credential plus trusted env. */
9
+ export declare function resolveGrokAccessTokenForTest(params: UsageFetchParams): string | undefined;
8
10
  export declare const grokCliUsageProvider: UsageProvider;
9
11
  export declare const grokCliRankingStrategy: CredentialRankingStrategy;
10
12
  export {};
@@ -1,2 +1,4 @@
1
1
  import type { UsageProvider } from "../usage";
2
+ /** Test seam: the usage base URL as resolved from a caller value plus trusted env. */
3
+ export declare function normalizeKimiUsageBaseUrlForTest(baseUrl?: string): string;
2
4
  export declare const kimiUsageProvider: UsageProvider;
@@ -4,6 +4,14 @@ export interface AnthropicAuthConfig {
4
4
  baseUrl: string;
5
5
  isOAuth: boolean;
6
6
  }
7
+ /**
8
+ * Resolve the Anthropic base URL from the environment.
9
+ *
10
+ * Trusted sources only: the result becomes the request URL that carries the
11
+ * Anthropic API key / OAuth token, so whatever can set it can redirect
12
+ * authenticated traffic. `$env` merges the caller's `cwd/.env`, so reading it
13
+ * there would let repository content choose where credentials are sent.
14
+ */
7
15
  export declare function resolveAnthropicBaseUrlFromEnv(): string | undefined;
8
16
  /**
9
17
  * Checks if a token is an OAuth token by looking for sk-ant-oat prefix.
@@ -1 +1,11 @@
1
+ /**
2
+ * Whether Anthropic requests run in Foundry gateway mode.
3
+ *
4
+ * Resolved from trusted environment sources only. Enabling Foundry switches the
5
+ * request base URL and injects TLS client material, so whatever can set this
6
+ * redirects authenticated traffic. `$env` merges the caller's `cwd/.env`, so
7
+ * reading it there would let repository content flip the mode; resolve it the
8
+ * same way the credentials themselves are (launching shell plus GJC/user-owned
9
+ * `.env` files, never the project `.env`).
10
+ */
1
11
  export declare function isFoundryEnabled(): boolean;
@@ -18,6 +18,19 @@ export declare function isModelUnavailableError(message: string, error: unknown)
18
18
  /** Actionable guidance for selecting an available model/provider. */
19
19
  export declare function formatModelUnavailableGuidance(dump: RawHttpRequestDump | undefined): string;
20
20
  export declare function appendRawHttpRequestDumpFor400(message: string, error: unknown, dump: RawHttpRequestDump | undefined): Promise<string>;
21
+ /**
22
+ * Name the failed connection when the request never produced an HTTP status.
23
+ *
24
+ * Bun raises DNS and socket failures as a bare `Error` whose message is a
25
+ * standalone hint ("Was there a typo in the url or port?", "Unable to connect.
26
+ * Is the computer able to access the url?") while the actionable facts live on
27
+ * `code` and `path`. Those properties are dropped when only `message` reaches
28
+ * the assistant message, so a provider outage, a local DNS failure, and a
29
+ * mistyped custom base URL all render as the same context-free sentence.
30
+ * Appending the code and the target URL tells the user which host failed and
31
+ * whether the fault is theirs.
32
+ */
33
+ export declare function appendTransportFailureContext(message: string, error: unknown, rawRequestDump: RawHttpRequestDump | undefined): string;
21
34
  export declare function finalizeErrorMessage(error: unknown, rawRequestDump: RawHttpRequestDump | undefined, capturedErrorResponse?: CapturedHttpErrorResponse): Promise<string>;
22
35
  export declare function withHttpStatus(error: unknown, status: number): Error;
23
36
  /**
@@ -2,7 +2,7 @@ export declare function getProviderFirstEventTimeoutFallbackMs(provider: string)
2
2
  /**
3
3
  * Returns the idle timeout used for provider streaming transports.
4
4
  *
5
- * `PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` is accepted as a backward-compatible alias.
5
+ * `GJC_OPENAI_STREAM_IDLE_TIMEOUT_MS` is honored first; `PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` is a backward-compatible alias.
6
6
  * Set `PI_STREAM_IDLE_TIMEOUT_MS=0` to disable the watchdog.
7
7
  *
8
8
  * Providers that legitimately stream much slower than the global default can pass
@@ -13,7 +13,7 @@ export declare function getStreamIdleTimeoutMs(fallbackMs?: number): number | un
13
13
  /**
14
14
  * Returns the idle timeout used for OpenAI-family streaming transports.
15
15
  *
16
- * Set `PI_OPENAI_STREAM_IDLE_TIMEOUT_MS=0` to disable the watchdog.
16
+ * Honors `GJC_OPENAI_STREAM_IDLE_TIMEOUT_MS` first (`PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` is the legacy alias). Set `=0` to disable.
17
17
  */
18
18
  export declare function getOpenAIStreamIdleTimeoutMs(): number | undefined;
19
19
  /**
@@ -0,0 +1 @@
1
+ export declare const loginBizRouter: (options: import("./types").OAuthController) => Promise<string>;
@@ -7,7 +7,7 @@ export type OAuthCredentials = {
7
7
  email?: string;
8
8
  accountId?: string;
9
9
  };
10
- export type OAuthProvider = "alibaba-token-plan" | "anthropic" | "cerebras" | "cloudflare-ai-gateway" | "cursor" | "deepseek" | "deepinfra" | "fireworks" | "firepass" | "fugu" | "github-copilot" | "google-gemini-cli" | "google-antigravity" | "gitlab-duo" | "huggingface" | "kimi-code" | "kilo" | "kagi" | "litellm" | "lm-studio" | "minimax-code" | "minimax-code-cn" | "moonshot" | "nvidia" | "nanogpt" | "ollama" | "ollama-cloud" | "openai-codex" | "openai-codex-device" | "opencode-go" | "opencode-zen" | "opengateway" | "parallel" | "perplexity" | "qianfan" | "qwen-portal" | "synthetic" | "tavily" | "together" | "venice" | "vercel-ai-gateway" | "vllm" | "xai" | "glm-zcode" | "xiaomi" | "xiaomi-token-plan-sgp" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-cn" | "zenmux" | "zai";
10
+ export type OAuthProvider = "alibaba-token-plan" | "anthropic" | "bizrouter" | "cerebras" | "cloudflare-ai-gateway" | "cursor" | "deepseek" | "deepinfra" | "fireworks" | "firepass" | "fugu" | "github-copilot" | "google-gemini-cli" | "google-antigravity" | "gitlab-duo" | "huggingface" | "kimi-code" | "kilo" | "kagi" | "litellm" | "lm-studio" | "minimax-code" | "minimax-code-cn" | "moonshot" | "nvidia" | "nanogpt" | "ollama" | "ollama-cloud" | "openai-codex" | "openai-codex-device" | "opencode-go" | "opencode-zen" | "opengateway" | "parallel" | "perplexity" | "qianfan" | "qwen-portal" | "synthetic" | "tavily" | "together" | "venice" | "vercel-ai-gateway" | "vllm" | "xai" | "glm-zcode" | "xiaomi" | "xiaomi-token-plan-sgp" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-cn" | "zenmux" | "zai";
11
11
  export type OAuthProviderId = OAuthProvider | (string & {});
12
12
  export type OAuthPrompt = {
13
13
  message: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@gajae-code/ai",
4
- "version": "0.11.10",
4
+ "version": "0.12.0",
5
5
  "description": "Unified LLM API with automatic model discovery and provider configuration",
6
6
  "homepage": "https://gajae-code.com",
7
7
  "author": "Yeachan-Heo and Gajae Code Contributors",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "@anthropic-ai/sdk": "^0.94.0",
42
42
  "@bufbuild/protobuf": "^2.12.0",
43
- "@gajae-code/utils": "0.11.10",
43
+ "@gajae-code/utils": "0.12.0",
44
44
  "openai": "^6.36.0",
45
45
  "partial-json": "^0.1.7",
46
46
  "zod": "4.4.3"
@@ -1998,6 +1998,12 @@ export class AuthStorage {
1998
1998
  await saveApiKeyCredential(apiKey);
1999
1999
  return;
2000
2000
  }
2001
+ case "bizrouter": {
2002
+ const { loginBizRouter } = await import("./utils/oauth/bizrouter");
2003
+ const apiKey = await loginBizRouter(ctrl);
2004
+ await saveApiKeyCredential(apiKey);
2005
+ return;
2006
+ }
2001
2007
  case "opengateway": {
2002
2008
  const { loginOpenGateway } = await import("./utils/oauth/opengateway");
2003
2009
  const apiKey = await loginOpenGateway(ctrl);
package/src/cli.ts CHANGED
@@ -119,6 +119,7 @@ Providers:
119
119
  cursor Cursor (Anthropic, GPT, etc.)
120
120
  zenmux ZenMux
121
121
  opengateway OpenGateway by Sionic AI
122
+ bizrouter BizRouter
122
123
  ollama-cloud Ollama Cloud
123
124
 
124
125
  Examples:
package/src/models.json CHANGED
@@ -4030,6 +4030,78 @@
4030
4030
  }
4031
4031
  }
4032
4032
  },
4033
+ "bizrouter": {
4034
+ "anthropic/claude-sonnet-4.5": {
4035
+ "id": "anthropic/claude-sonnet-4.5",
4036
+ "name": "Anthropic Sonnet 4.5",
4037
+ "api": "openai-completions",
4038
+ "provider": "bizrouter",
4039
+ "baseUrl": "https://api.bizrouter.ai/v1",
4040
+ "reasoning": true,
4041
+ "input": [
4042
+ "text",
4043
+ "image"
4044
+ ],
4045
+ "cost": {
4046
+ "input": 3,
4047
+ "output": 15,
4048
+ "cacheRead": 0.3,
4049
+ "cacheWrite": 3.75
4050
+ },
4051
+ "contextWindow": 200000,
4052
+ "maxTokens": 64000,
4053
+ "thinking": {
4054
+ "mode": "effort",
4055
+ "minLevel": "minimal",
4056
+ "maxLevel": "xhigh"
4057
+ }
4058
+ },
4059
+ "google/gemini-2.5-pro": {
4060
+ "id": "google/gemini-2.5-pro",
4061
+ "name": "Gemini 2.5 Pro",
4062
+ "api": "openai-completions",
4063
+ "provider": "bizrouter",
4064
+ "baseUrl": "https://api.bizrouter.ai/v1",
4065
+ "reasoning": true,
4066
+ "input": [
4067
+ "text",
4068
+ "image"
4069
+ ],
4070
+ "cost": {
4071
+ "input": 1.25,
4072
+ "output": 10,
4073
+ "cacheRead": 0.31,
4074
+ "cacheWrite": 0
4075
+ },
4076
+ "contextWindow": 1048576,
4077
+ "maxTokens": 65536,
4078
+ "thinking": {
4079
+ "mode": "effort",
4080
+ "minLevel": "minimal",
4081
+ "maxLevel": "high"
4082
+ }
4083
+ },
4084
+ "openai/gpt-4o": {
4085
+ "id": "openai/gpt-4o",
4086
+ "name": "GPT-4o",
4087
+ "api": "openai-completions",
4088
+ "provider": "bizrouter",
4089
+ "baseUrl": "https://api.bizrouter.ai/v1",
4090
+ "reasoning": false,
4091
+ "input": [
4092
+ "text",
4093
+ "image"
4094
+ ],
4095
+ "cost": {
4096
+ "input": 2.5,
4097
+ "output": 10,
4098
+ "cacheRead": 1.25,
4099
+ "cacheWrite": 0
4100
+ },
4101
+ "contextWindow": 128000,
4102
+ "maxTokens": 16384
4103
+ }
4104
+ },
4033
4105
  "cerebras": {
4034
4106
  "gemma-4-31b": {
4035
4107
  "id": "gemma-4-31b",
@@ -11,6 +11,7 @@ import { ollamaCloudModelManagerOptions } from "./ollama";
11
11
  import {
12
12
  alibabaTokenPlanModelManagerOptions,
13
13
  anthropicModelManagerOptions,
14
+ bizrouterModelManagerOptions,
14
15
  cerebrasModelManagerOptions,
15
16
  cloudflareAiGatewayModelManagerOptions,
16
17
  deepinfraModelManagerOptions,
@@ -319,6 +320,12 @@ export const PROVIDER_DESCRIPTORS: readonly ProviderDescriptor[] = [
319
320
  config => opengatewayModelManagerOptions(config),
320
321
  catalog("OpenGateway by Sionic AI", ["OPENGATEWAY_API_KEY"]),
321
322
  ),
323
+ catalogDescriptor(
324
+ "bizrouter",
325
+ "anthropic/claude-sonnet-4.5",
326
+ config => bizrouterModelManagerOptions(config),
327
+ catalog("BizRouter", ["BIZROUTER_API_KEY"]),
328
+ ),
322
329
  catalogDescriptor("zai", "glm-5.2", config => zaiModelManagerOptions(config), catalog("zAI", ["ZAI_API_KEY"])),
323
330
  catalogDescriptor(
324
331
  "glm-zcode",
@@ -1,4 +1,4 @@
1
- import { $env, $inheritedEnv } from "@gajae-code/utils";
1
+ import { $credentialEnv } from "@gajae-code/utils";
2
2
  import type { ModelManagerOptions } from "../model-manager";
3
3
  import { Effort } from "../model-thinking";
4
4
  import { getBundledModels } from "../models";
@@ -553,13 +553,19 @@ export interface OpenAIModelManagerConfig {
553
553
  baseUrl?: string;
554
554
  }
555
555
 
556
+ /** Base URL for the OpenAI model manager, from trusted env only (`$env` merges the caller's `cwd/.env`). */
557
+ function resolveOpenAIModelManagerBaseUrl(config?: OpenAIModelManagerConfig): string {
558
+ return config?.baseUrl?.trim() || $credentialEnv("OPENAI_BASE_URL") || OPENAI_DEFAULT_BASE_URL;
559
+ }
560
+
561
+ /** Test seam: the model-manager base URL as resolved from trusted env. */
562
+ export function resolveOpenAIModelManagerBaseUrlForTest(config?: OpenAIModelManagerConfig): string {
563
+ return resolveOpenAIModelManagerBaseUrl(config);
564
+ }
565
+
556
566
  export function openaiModelManagerOptions(config?: OpenAIModelManagerConfig): ModelManagerOptions<"openai-responses"> {
557
567
  const apiKey = config?.apiKey;
558
- const baseUrl =
559
- config?.baseUrl?.trim() ||
560
- $inheritedEnv("OPENAI_BASE_URL") ||
561
- $env.OPENAI_BASE_URL?.trim() ||
562
- OPENAI_DEFAULT_BASE_URL;
568
+ const baseUrl = resolveOpenAIModelManagerBaseUrl(config);
563
569
  const references = createBundledReferenceMap<"openai-responses">("openai");
564
570
  return {
565
571
  providerId: "openai",
@@ -1119,6 +1125,61 @@ export function opengatewayModelManagerOptions(
1119
1125
  return createSimpleOpenAICompletionsOptions("opengateway", "https://apis.opengateway.ai/v1", config);
1120
1126
  }
1121
1127
 
1128
+ // ---------------------------------------------------------------------------
1129
+ // 10.5.2 BizRouter
1130
+ // ---------------------------------------------------------------------------
1131
+
1132
+ const BIZROUTER_BASE_URL = "https://api.bizrouter.ai/v1";
1133
+
1134
+ function toBizRouterPrice(value: unknown, fallback: number): number {
1135
+ const parsed = toNumber(value);
1136
+ return parsed === undefined || parsed < 0 ? fallback : parsed;
1137
+ }
1138
+
1139
+ export interface BizRouterModelManagerConfig {
1140
+ apiKey?: string;
1141
+ baseUrl?: string;
1142
+ }
1143
+
1144
+ export function bizrouterModelManagerOptions(
1145
+ config?: BizRouterModelManagerConfig,
1146
+ ): ModelManagerOptions<"openai-completions"> {
1147
+ const apiKey = config?.apiKey;
1148
+ const baseUrl = config?.baseUrl ?? BIZROUTER_BASE_URL;
1149
+ const references = createBundledReferenceMap<"openai-completions">("bizrouter");
1150
+ return {
1151
+ providerId: "bizrouter",
1152
+ ...(apiKey && {
1153
+ fetchDynamicModels: () =>
1154
+ fetchOpenAICompatibleModels({
1155
+ api: "openai-completions",
1156
+ provider: "bizrouter",
1157
+ baseUrl,
1158
+ apiKey,
1159
+ mapModel: (entry, defaults) => {
1160
+ const mapped = mapWithBundledReference(entry, defaults, references.get(defaults.id));
1161
+ return {
1162
+ ...mapped,
1163
+ name: toModelName(entry.display_name, mapped.name),
1164
+ contextWindow: toPositiveNumber(entry.context_length, mapped.contextWindow),
1165
+ maxTokens: toPositiveNumber(entry.max_output_tokens, mapped.maxTokens),
1166
+ input: toInputCapabilities(entry.input_modalities),
1167
+ cost: {
1168
+ input: toBizRouterPrice(entry.input_price_per_1m_usd, mapped.cost.input),
1169
+ output: toBizRouterPrice(entry.output_price_per_1m_usd, mapped.cost.output),
1170
+ cacheRead: mapped.cost.cacheRead,
1171
+ cacheWrite: mapped.cost.cacheWrite,
1172
+ },
1173
+ api: "openai-completions",
1174
+ provider: "bizrouter",
1175
+ baseUrl,
1176
+ };
1177
+ },
1178
+ }),
1179
+ }),
1180
+ };
1181
+ }
1182
+
1122
1183
  // ---------------------------------------------------------------------------
1123
1184
  // 10.6 Kilo Gateway
1124
1185
  // ---------------------------------------------------------------------------
@@ -11,6 +11,7 @@ import type {
11
11
  RawMessageStreamEvent,
12
12
  } from "@anthropic-ai/sdk/resources/messages";
13
13
  import {
14
+ $credentialEnv,
14
15
  $env,
15
16
  extractHttpStatusFromError,
16
17
  isEnoent,
@@ -490,7 +491,8 @@ function getCacheControl(
490
491
  }
491
492
 
492
493
  // Stealth mode: Mimic Anthropic Code headers and tool prefixing.
493
- export const claudeCodeVersion = "2.1.63";
494
+ export const claudeCodeVersion = "2.1.219";
495
+ export const claudeCodeEntrypoint = "sdk-cli";
494
496
  export const claudeToolPrefix: string = "proxy_";
495
497
  export const claudeCodeSystemInstruction = "You are a Claude agent, built on Anthropic's Claude Agent SDK.";
496
498
 
@@ -566,7 +568,7 @@ function createClaudeBillingHeader(payload: unknown): string {
566
568
  const buildHash = Array.from(randomBytes, byte => byte.toString(16).padStart(2, "0"))
567
569
  .join("")
568
570
  .slice(0, 3);
569
- return `${CLAUDE_BILLING_HEADER_PREFIX} cc_version=${claudeCodeVersion}.${buildHash}; cc_entrypoint=cli; cch=${cch};`;
571
+ return `${CLAUDE_BILLING_HEADER_PREFIX} cc_version=${claudeCodeVersion}.${buildHash}; cc_entrypoint=${claudeCodeEntrypoint}; cch=${cch};`;
570
572
  }
571
573
 
572
574
  const CLAUDE_CLOAKING_USER_ID_REGEX =
@@ -816,10 +818,12 @@ function resolveAnthropicBaseUrl(model: Model<"anthropic-messages">, apiKey?: st
816
818
  // calls api.z.ai directly (no zcode.z.ai gateway, no captcha). Pin the base so dynamic
817
819
  // discovery / stale bundled catalogs / model cache can't redirect it elsewhere.
818
820
  if (model.provider === "glm-zcode") {
819
- return normalizeAnthropicBaseUrl(process.env.ZCODE_PLAN_ANTHROPIC_BASE_URL) ?? "https://api.z.ai/api/anthropic";
821
+ return (
822
+ normalizeAnthropicBaseUrl($credentialEnv("ZCODE_PLAN_ANTHROPIC_BASE_URL")) ?? "https://api.z.ai/api/anthropic"
823
+ );
820
824
  }
821
825
  if (model.provider === "anthropic" && isFoundryEnabled()) {
822
- const foundryBaseUrl = normalizeAnthropicBaseUrl($env.FOUNDRY_BASE_URL);
826
+ const foundryBaseUrl = normalizeAnthropicBaseUrl($credentialEnv("FOUNDRY_BASE_URL"));
823
827
  if (foundryBaseUrl) {
824
828
  return foundryBaseUrl;
825
829
  }
@@ -1182,6 +1186,40 @@ function shouldIgnoreAnthropicPreambleEvent(eventType: unknown): boolean {
1182
1186
  return !ANTHROPIC_PRE_MESSAGE_START_EVENT_TYPES.has(eventType);
1183
1187
  }
1184
1188
 
1189
+ function createAnthropicStreamProgressPredicate(): (event: unknown) => boolean {
1190
+ let outputTokens = -1;
1191
+
1192
+ return event => {
1193
+ if (!isRecord(event) || typeof event.type !== "string") return false;
1194
+ if (
1195
+ event.type === "message_start" ||
1196
+ event.type === "content_block_start" ||
1197
+ event.type === "content_block_stop" ||
1198
+ event.type === "message_stop"
1199
+ ) {
1200
+ return true;
1201
+ }
1202
+ if (event.type === "content_block_delta") {
1203
+ if (!isRecord(event.delta)) return false;
1204
+ const delta = event.delta;
1205
+ return (
1206
+ (typeof delta.text === "string" && delta.text.length > 0) ||
1207
+ (typeof delta.thinking === "string" && delta.thinking.length > 0) ||
1208
+ (typeof delta.partial_json === "string" && delta.partial_json.length > 0) ||
1209
+ (typeof delta.signature === "string" && delta.signature.length > 0)
1210
+ );
1211
+ }
1212
+ if (event.type === "message_delta") {
1213
+ if (isRecord(event.delta) && event.delta.stop_reason != null) return true;
1214
+ if (!isRecord(event.usage) || typeof event.usage.output_tokens !== "number") return false;
1215
+ if (event.usage.output_tokens <= outputTokens) return false;
1216
+ outputTokens = event.usage.output_tokens;
1217
+ return true;
1218
+ }
1219
+ return false;
1220
+ };
1221
+ }
1222
+
1185
1223
  function isTransientStreamEnvelopeError(error: unknown): boolean {
1186
1224
  if (!(error instanceof Error)) return false;
1187
1225
  return (
@@ -1457,6 +1495,7 @@ export const streamAnthropic: StreamFunction<"anthropic-messages"> = (
1457
1495
  let sawEvent = false;
1458
1496
  let sawMessageStart = false;
1459
1497
  let sawTerminalEnvelope = false;
1498
+ const isProgressEvent = createAnthropicStreamProgressPredicate();
1460
1499
 
1461
1500
  for await (const event of iterateWithIdleTimeout(anthropicStream, {
1462
1501
  idleTimeoutMs,
@@ -1466,6 +1505,7 @@ export const streamAnthropic: StreamFunction<"anthropic-messages"> = (
1466
1505
  onIdle: () => activeAbortTracker.abortLocally(idleTimeoutAbortError),
1467
1506
  onFirstItemTimeout: () => activeAbortTracker.abortLocally(firstEventTimeoutAbortError),
1468
1507
  abortSignal: options?.signal,
1508
+ isProgressItem: isProgressEvent,
1469
1509
  })) {
1470
1510
  sawEvent = true;
1471
1511
  if (sawProviderSafetyStop) {