@oh-my-pi/pi-ai 18.2.6 → 18.2.7

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 (49) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/THIRD-PARTY-NOTICES.txt +0 -37
  3. package/dist/types/auth-retry.d.ts +2 -0
  4. package/dist/types/auth-storage.d.ts +2 -2
  5. package/dist/types/error/classes.d.ts +4 -1
  6. package/dist/types/error/flags.d.ts +12 -4
  7. package/dist/types/index.d.ts +14 -12
  8. package/dist/types/judgment/types.d.ts +5 -2
  9. package/dist/types/judgment/typesafe.d.ts +16 -22
  10. package/dist/types/providers/anthropic-compaction.d.ts +10 -0
  11. package/dist/types/providers/anthropic-identity.d.ts +18 -0
  12. package/dist/types/providers/anthropic-state.d.ts +13 -0
  13. package/dist/types/providers/anthropic.d.ts +6 -59
  14. package/dist/types/providers/gitlab-duo.d.ts +0 -1
  15. package/dist/types/providers/kimi.d.ts +1 -5
  16. package/dist/types/providers/openai-codex-attestation.d.ts +6 -0
  17. package/dist/types/providers/openai-codex-compaction.d.ts +6 -0
  18. package/dist/types/providers/openai-codex-responses.d.ts +3 -27
  19. package/dist/types/providers/openai-codex-transport.d.ts +7 -0
  20. package/dist/types/providers/openai-shared.d.ts +0 -9
  21. package/dist/types/providers/register-builtins.d.ts +20 -22
  22. package/dist/types/providers/synthetic.d.ts +1 -5
  23. package/package.json +6 -6
  24. package/src/auth-retry.ts +3 -0
  25. package/src/auth-storage.ts +28 -22
  26. package/src/error/auth-classify.ts +10 -2
  27. package/src/error/classes.ts +23 -3
  28. package/src/error/flags.ts +51 -16
  29. package/src/index.ts +15 -12
  30. package/src/judgment/types.ts +6 -3
  31. package/src/judgment/typesafe.ts +53 -48
  32. package/src/provider-session-state.ts +1 -1
  33. package/src/providers/anthropic-compaction.ts +54 -0
  34. package/src/providers/anthropic-identity.ts +136 -0
  35. package/src/providers/anthropic-state.ts +55 -0
  36. package/src/providers/anthropic.ts +39 -296
  37. package/src/providers/bedrock-mantle.ts +1 -1
  38. package/src/providers/gitlab-duo.ts +0 -4
  39. package/src/providers/kimi.ts +1 -8
  40. package/src/providers/openai-codex-attestation.ts +19 -0
  41. package/src/providers/openai-codex-compaction.ts +18 -0
  42. package/src/providers/openai-codex-responses.ts +9 -68
  43. package/src/providers/openai-codex-transport.ts +18 -0
  44. package/src/providers/openai-shared.ts +1 -10
  45. package/src/providers/register-builtins.ts +113 -320
  46. package/src/providers/synthetic.ts +1 -8
  47. package/src/registry/cloudflare-ai-gateway.ts +1 -1
  48. package/src/stream.ts +7 -15
  49. package/src/utils/anthropic-auth.ts +3 -6
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [18.2.7] - 2026-09-21
6
+
7
+ ### Breaking Changes
8
+
9
+ - Anthropic streaming and provider request helpers must now be imported from `@oh-my-pi/pi-ai/providers/anthropic` instead of the package root.
10
+ - Moved the public `NO_AUTH_SENTINEL` export from `providers/openai-shared` to `auth-retry`.
11
+
12
+ ### Fixed
13
+
14
+ - Anthropic organization-level OAuth permission errors now reliably rotate to sibling credentials and persist blocks across usage reports.
15
+ - Fixed error handling for provider responses that do not include token usage information.
16
+
5
17
  ## [18.2.6] - 2026-09-18
6
18
 
7
19
  ### Fixed
@@ -78,7 +90,7 @@
78
90
  - Fixed openai-responses replay wedging a repaired orphan tool-result note between another call's `function_call` and `function_call_output`, which broke round pairing on strict validators (e.g. DeepSeek) with `400 No tool output found for tool call …`: orphan-output/call repair now runs before the interleaved-message hoist, so any injected note is relocated out of the tool-call batch ([#11473](https://github.com/can1357/oh-my-pi/issues/11473)).
79
91
  - A stale Anthropic tier block (`tier:fable`, `tier:mythos`) is now cleared once a live usage report shows headroom on both the tier row and the shared windows, instead of idling a usable account until the reported reset. Healing requires a live report, and a credential held by an unscoped block spends no usage request on a probe that cannot lift it ([#11334](https://github.com/can1357/oh-my-pi/pull/11334) by [@AshishKumar4](https://github.com/AshishKumar4)).
80
92
  - A running session now picks up credentials another process committed: adding an account in a second terminal is visible to credential selection and rotation without restarting the session, and a session's pinned account is re-resolved by row id so a row another process deleted cannot hand its slot to a sibling ([#11329](https://github.com/can1357/oh-my-pi/pull/11329) by [@AshishKumar4](https://github.com/AshishKumar4)).
81
- - Fixed rate-limit/overload failures that arrive *inside* an HTTP 200 body (Azure, LiteLLM-style aggregators, and reverse proxies that already committed to the stream) not advancing `retry.fallbackChains`: a `{"error":{…}}`/`{"code":429}` chunk or a plain-text throttle frame (`429 Too Many Requests`, an nginx page) is now classified as a retryable 429/5xx through the same path an HTTP-status 429 takes, so a busy provider backs off and fails over instead of ending the session. Only bodies the provider actually reported are used: no status is inferred from error wording, and an unreadable body can no longer consume a credential.
93
+ - Fixed rate-limit/overload failures that arrive _inside_ an HTTP 200 body (Azure, LiteLLM-style aggregators, and reverse proxies that already committed to the stream) not advancing `retry.fallbackChains`: a `{"error":{…}}`/`{"code":429}` chunk or a plain-text throttle frame (`429 Too Many Requests`, an nginx page) is now classified as a retryable 429/5xx through the same path an HTTP-status 429 takes, so a busy provider backs off and fails over instead of ending the session. Only bodies the provider actually reported are used: no status is inferred from error wording, and an unreadable body can no longer consume a credential.
82
94
  - Fixed tool schema normalization and cycle detection for frozen, sealed, and nonextensible schemas.
83
95
  - Reduced memory retained by `complete()` and `completeSimple()` while streaming responses.
84
96
  - Antigravity quota summaries now identify Claude/GPT routing copies as one shared upstream pool while preserving model-specific quota selection ([#11268](https://github.com/can1357/oh-my-pi/issues/11268)).
@@ -335,43 +335,6 @@ This license allows the work and adaptations of it to be shared and used
335
335
  commercially, as long as it is attributed to Poppy Works. The font is bundled
336
336
  here (crates/pi-natives/src/fonts/Silver.ttf) as a CJK/Unicode bitmap fallback.
337
337
 
338
- -------------------------------------------------------------------------------
339
- packages/utils/src/vendor/mermaid-ascii/NOTICE
340
-
341
- This directory contains an in-house Mermaid-diagram-to-ASCII renderer adapted
342
- from beautiful-mermaid (https://github.com/lukilabs/beautiful-mermaid), used
343
- under the MIT License.
344
-
345
- Copyright (c) 2026 Craft Docs
346
-
347
- Only the ASCII rendering pipeline is ported (flowchart/state, sequence, class,
348
- ER, and xychart diagrams); the SVG renderer and its `elkjs` graph-layout
349
- dependency, the browser entry point, and the SVG theme/style modules were
350
- dropped. Terminal display width is reimplemented on `Bun.stringWidth`, and
351
- inline label formatting (HTML tags, markdown emphasis) is reduced to plain text
352
- for ASCII output. Layout and edge-routing logic is preserved faithfully so
353
- ASCII output matches the upstream package.
354
-
355
- MIT License
356
-
357
- Permission is hereby granted, free of charge, to any person obtaining a copy
358
- of this software and associated documentation files (the "Software"), to deal
359
- in the Software without restriction, including without limitation the rights
360
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
361
- copies of the Software, and to permit persons to whom the Software is
362
- furnished to do so, subject to the following conditions:
363
-
364
- The above copyright notice and this permission notice shall be included in all
365
- copies or substantial portions of the Software.
366
-
367
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
368
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
369
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
370
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
371
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
372
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
373
- SOFTWARE.
374
-
375
338
  -------------------------------------------------------------------------------
376
339
  packages/coding-agent/src/markit/NOTICE
377
340
 
@@ -35,6 +35,8 @@ export interface ApiKeyResolveContext {
35
35
  export type ApiKeyResolver = (ctx: ApiKeyResolveContext) => Promise<string | undefined> | string | undefined;
36
36
  /** A static bearer string, or a {@link ApiKeyResolver} that mints/rotates one. */
37
37
  export type ApiKey = string | ApiKeyResolver;
38
+ /** Keyless-provider credential marker; transports must not send it in authentication headers. */
39
+ export declare const NO_AUTH_SENTINEL = "N/A";
38
40
  /** Narrows {@link ApiKey} to its resolver form. */
39
41
  export declare function isApiKeyResolver(key: ApiKey | undefined): key is ApiKeyResolver;
40
42
  /**
@@ -1218,8 +1218,8 @@ export declare class AuthStorage {
1218
1218
  * stale session stickiness. Fall back to the session-sticky credential only
1219
1219
  * when neither explicit target is available. For hard-auth errors, an explicit
1220
1220
  * target that no longer matches storage returns `false` without mutation.
1221
- * Delayed usage-limit errors may instead recover the durable OAuth row from
1222
- * the bearer fingerprint recorded when the request resolved.
1221
+ * Delayed usage-limit and account-policy errors may instead recover the durable
1222
+ * OAuth row from the bearer fingerprint recorded when the request resolved.
1223
1223
  *
1224
1224
  * - usage-limit / account-rate-limit error → {@link AuthStorage.markUsageLimitReached}
1225
1225
  * (temporary block via its own backoff — default plus server usage-report
@@ -39,7 +39,10 @@ export declare const __anthropicApiErrorForTesting: {
39
39
  export declare class AnthropicApiError extends ProviderHttpError {
40
40
  readonly headers: Headers;
41
41
  readonly requestId: string | null;
42
- constructor(status: number, message: string, headers: Headers);
42
+ constructor(status: number, message: string, headers: Headers, options?: {
43
+ code?: string;
44
+ cause?: unknown;
45
+ });
43
46
  static fromResponse(response: Response, signal?: AbortSignal): Promise<AnthropicApiError>;
44
47
  }
45
48
  /** Network-level failure (DNS, TLS, socket reset) after retries were exhausted. */
@@ -1,4 +1,4 @@
1
- import type { Api, AssistantMessage } from "../types.js";
1
+ import type { Api, AssistantMessage, Usage } from "../types.js";
2
2
  export declare const Flag: {
3
3
  readonly Class: 4096;
4
4
  readonly ThinkingLoop: 65536;
@@ -44,6 +44,9 @@ export declare function isResponsesRequestBodyReadTimeout(message: {
44
44
  requestBodyReadTimeoutFullReplay?: boolean;
45
45
  }): boolean;
46
46
  export declare const TRANSIENT_TRANSPORT_PATTERN: RegExp;
47
+ export declare const ANTHROPIC_ACCOUNT_POLICY_PATTERN: RegExp;
48
+ /** Whether an error message represents an Anthropic account-scoped permission/policy denial. */
49
+ export declare function isAnthropicAccountPolicyText(text: string, provider?: string, statusArg?: number): boolean;
47
50
  /**
48
51
  * Local llama.cpp / Ollama deterministic tool-call argument JSON parse failure.
49
52
  * The model emitted invalid JSON in a tool call and the server returned HTTP 500
@@ -121,16 +124,21 @@ export declare function classifyMessage(message: {
121
124
  errorStatus?: number;
122
125
  }): number;
123
126
  export declare function attach<E extends object>(error: E, id: number): E;
127
+ /** Overflow-classification evidence, including errors received before token usage is available. */
128
+ export interface ContextOverflowMessage extends Pick<AssistantMessage, "errorId" | "stopReason" | "errorMessage"> {
129
+ readonly usage?: Pick<Usage, "input" | "cacheRead" | "cacheWrite">;
130
+ }
124
131
  /** Provider-reported usage proves context-window excess — authoritative, compaction-owned (#9235). */
125
- export declare function isUsageBackedContextOverflow(message: AssistantMessage, contextWindow?: number): boolean;
126
- export declare function isContextOverflow(message: AssistantMessage, contextWindow?: number): boolean;
132
+ export declare function isUsageBackedContextOverflow(message: ContextOverflowMessage, contextWindow?: number): boolean;
133
+ /** Classify overflow from error flags, available token usage, or provider error text. */
134
+ export declare function isContextOverflow(message: ContextOverflowMessage, contextWindow?: number): boolean;
127
135
  /** HTTP 413 byte/media rejection (#9235); may co-occur with {@link isContextOverflow} for bare `413 (no body)`.
128
136
  * Callers with local headroom should skip compaction when this returns true. */
129
137
  export declare function isPayloadRejection(message: AssistantMessage): boolean;
130
138
  /** Dual-flagged 413 (PayloadRejected + ContextOverflow) with no provider-reported token excess (#9235).
131
139
  * The co-flag means a different provider's larger byte/media budget may accept the request.
132
140
  * Usage-backed overflows are authoritative window excesses and never ambiguous. */
133
- export declare function isTextAmbiguousContextOverflow(errorId: number, message: AssistantMessage | undefined, contextWindow?: number): boolean;
141
+ export declare function isTextAmbiguousContextOverflow(errorId: number, message: ContextOverflowMessage | undefined, contextWindow?: number): boolean;
134
142
  export declare function stringify(id: number | undefined): string;
135
143
  /**
136
144
  * Transient stream corruption where the response was truncated mid-JSON.
@@ -10,22 +10,24 @@ export * from "./judgment/index.js";
10
10
  export * from "./oneshot-retry.js";
11
11
  export * from "./provider-details.js";
12
12
  export * from "./provider-session-state.js";
13
- export * from "./providers/anthropic.js";
14
- export * from "./providers/anthropic-client.js";
15
- export * from "./providers/azure-openai-responses.js";
13
+ export type * from "./providers/anthropic.js";
14
+ export * from "./providers/anthropic-identity.js";
15
+ export * from "./providers/anthropic-state.js";
16
+ export type * from "./providers/anthropic-client.js";
17
+ export type * from "./providers/azure-openai-responses.js";
16
18
  export type * from "./providers/cursor.js";
17
- export * from "./providers/gitlab-duo.js";
18
- export * from "./providers/gitlab-duo-workflow.js";
19
+ export type * from "./providers/gitlab-duo.js";
20
+ export type * from "./providers/gitlab-duo-workflow.js";
19
21
  export type * from "./providers/google.js";
20
22
  export type * from "./providers/google-gemini-cli.js";
21
23
  export type * from "./providers/google-vertex.js";
22
- export * from "./providers/kimi.js";
23
- export * from "./providers/mock.js";
24
- export * from "./providers/ollama.js";
25
- export * from "./providers/openai-codex-responses.js";
26
- export * from "./providers/openai-completions.js";
27
- export * from "./providers/openai-responses.js";
28
- export * from "./providers/synthetic.js";
24
+ export type * from "./providers/kimi.js";
25
+ export type * from "./providers/mock.js";
26
+ export type * from "./providers/ollama.js";
27
+ export type * from "./providers/openai-codex-responses.js";
28
+ export type * from "./providers/openai-completions.js";
29
+ export type * from "./providers/openai-responses.js";
30
+ export type * from "./providers/synthetic.js";
29
31
  export * from "./registry/index.js";
30
32
  export * from "./stream.js";
31
33
  export * from "./types.js";
@@ -99,5 +99,8 @@ export declare class JudgmentParseError extends Error {
99
99
  readonly output: string;
100
100
  constructor(questionId: string, output: string, detail: string);
101
101
  }
102
- /** Zero-cost usage for a request whose backend reports only token counts. */
103
- export declare function tokenUsage(input: number, output: number): Usage;
102
+ /**
103
+ * Usage from a backend that reports token counts and, optionally, one billed
104
+ * USD amount. Judgment pricing is input-only, so the amount lands on `input`.
105
+ */
106
+ export declare function tokenUsage(input: number, output: number, cost?: number): Usage;
@@ -1,28 +1,28 @@
1
- /**
2
- * TypeSafe System One client: the native {@link Judge} backend.
3
- *
4
- * Forwards a {@link JudgmentRequest} verbatim to `POST /v1/systemone` and maps
5
- * the typed answers back. Credentials flow through {@link withAuth}, so a
6
- * stored key rotates on 401/403 exactly like chat providers; transient
7
- * 429/5xx responses retry with bounded, `retry-after`-aware backoff.
8
- *
9
- * Environment (mirrors the official SDK): `TYPESAFE_API_KEY` is resolved by
10
- * the auth registry (`rules/auth/typesafe.kdl`), `TYPESAFE_BASE_URL`
11
- * overrides the API root, `TYPESAFE_DEFAULT_MODEL` the model.
12
- */
13
- import type { FetchImpl } from "@oh-my-pi/pi-catalog/types";
1
+ import type { Api, FetchImpl } from "@oh-my-pi/pi-catalog/types";
14
2
  import { type ApiKey } from "../auth-retry.js";
15
3
  import * as AIError from "../error/index.js";
16
4
  import { type Judge, type JudgeOptions, type JudgmentRequest, type JudgmentResult, type Questions } from "./types.js";
17
5
  export declare const TYPESAFE_PROVIDER = "typesafe";
18
- export declare const TYPESAFE_DEFAULT_BASE_URL = "https://api.typesafe.ai";
19
6
  export declare const TYPESAFE_DEFAULT_MODEL = "jev-latest";
7
+ /** Judgment `POST` path under a model's base URL, per System One–compatible API. */
8
+ export declare const JUDGMENT_ROUTES: {
9
+ readonly typesafe: "/v1/systemone";
10
+ readonly "openrouter-decisions": "/decisions";
11
+ };
12
+ /** APIs {@link TypeSafeJudge} can serve. */
13
+ export type JudgmentApi = keyof typeof JUDGMENT_ROUTES;
14
+ /** Whether a catalog API answers System One judgments natively. */
15
+ export declare function isJudgmentApi(api: Api): api is JudgmentApi;
20
16
  /** `TYPESAFE_BASE_URL` when set, else the public API root; trailing slashes stripped. */
21
17
  export declare function typesafeBaseUrl(): string;
22
18
  /** `TYPESAFE_DEFAULT_MODEL` when set, else {@link TYPESAFE_DEFAULT_MODEL}. */
23
19
  export declare function typesafeModel(): string;
24
20
  export interface TypeSafeJudgeOptions {
25
21
  apiKey: ApiKey;
22
+ /** Wire route; defaults to TypeSafe's own API. */
23
+ api?: JudgmentApi;
24
+ /** Catalog provider reported on results; defaults to {@link TYPESAFE_PROVIDER}. */
25
+ provider?: string;
26
26
  /** Defaults to {@link typesafeBaseUrl}. */
27
27
  baseUrl?: string;
28
28
  /** Defaults to {@link typesafeModel}. */
@@ -35,19 +35,13 @@ export interface TypeSafeJudgeOptions {
35
35
  export declare class TypeSafeApiError extends AIError.ProviderHttpError {
36
36
  readonly name = "TypeSafeApiError";
37
37
  }
38
- /** Wire shape of `GET /v1/models`. */
39
- export interface TypeSafeModelCard {
40
- name: string;
41
- description: string;
42
- release_date: string;
43
- }
44
38
  export declare class TypeSafeJudge implements Judge {
45
39
  #private;
46
40
  readonly label: string;
41
+ readonly api: JudgmentApi;
42
+ readonly provider: string;
47
43
  readonly model: string;
48
44
  readonly baseUrl: string;
49
45
  constructor(options: TypeSafeJudgeOptions);
50
46
  judge<Q extends Questions>(request: JudgmentRequest<Q>, options?: JudgeOptions): Promise<JudgmentResult<Q>>;
51
- /** Models available to the account (`GET /v1/models`); also the login validation probe. */
52
- listModels(signal?: AbortSignal): Promise<TypeSafeModelCard[]>;
53
47
  }
@@ -0,0 +1,10 @@
1
+ import type { Model } from "../types.js";
2
+ import type { AnthropicMessagesClientLike } from "./anthropic-client.js";
3
+ /** Whether the model's effective first-party route is the official Anthropic API. */
4
+ export declare function resolvesToOfficialAnthropicEndpoint(model: Model<"anthropic-messages">): boolean;
5
+ /** Whether the model and effective endpoint support Anthropic native compaction. */
6
+ export declare function supportsAnthropicCompaction(model: Model<"anthropic-messages">, effectiveBaseUrl?: string): boolean;
7
+ /** Read a caller-owned client's endpoint for request and compaction routing. */
8
+ export declare function injectedClientBaseUrl(client: AnthropicMessagesClientLike): string | undefined;
9
+ /** Whether a caller-owned Anthropic client targets a compaction-capable endpoint. */
10
+ export declare function supportsAnthropicCompactionOnClient(model: Model<"anthropic-messages">, client: AnthropicMessagesClientLike): boolean;
@@ -0,0 +1,18 @@
1
+ /** Whether a metadata id uses Claude Code's legacy cloaking shape. */
2
+ export declare function isClaudeCloakingUserId(userId: string): boolean;
3
+ /** Extract a stable session id from a supported Anthropic metadata user id. */
4
+ export declare function extractClaudeMetadataSessionId(userId: unknown): string | undefined;
5
+ /** Generate a legacy Claude Code cloaking metadata id. */
6
+ export declare function generateClaudeCloakingUserId(): string;
7
+ /** Derive the stable Claude device id for an installation and optional account. */
8
+ export declare function deriveClaudeDeviceId(installId: string, accountId?: string): string;
9
+ /** Read a non-empty string from provider metadata. */
10
+ export declare function readAnthropicMetadataString(metadata: Record<string, unknown> | undefined, key: string): string | undefined;
11
+ /** Resolve the account id aliases accepted in Anthropic request metadata. */
12
+ export declare function readAnthropicMetadataAccountId(metadata: Record<string, unknown> | undefined): string | undefined;
13
+ /** Resolve the provider-facing metadata user id for API-key or OAuth requests. */
14
+ export declare function resolveAnthropicMetadataUserId(userId: unknown, isOAuthToken: boolean, sessionId?: string, accountId?: string): string | undefined;
15
+ /** Apply Claude Code's wire-only tool prefix. */
16
+ export declare const applyClaudeToolPrefix: (name: string) => string;
17
+ /** Remove one Claude Code wire-only tool prefix. */
18
+ export declare const stripClaudeToolPrefix: (name: string) => string;
@@ -0,0 +1,13 @@
1
+ import type { Api, Model, ProviderSessionState } from "../types.js";
2
+ /** Root key for Anthropic's per-session provider state. */
3
+ export declare const ANTHROPIC_PROVIDER_SESSION_STATE_KEY = "anthropic-messages";
4
+ /** Normalize an Anthropic base URL to its origin path without `/v1`. */
5
+ export declare function normalizeAnthropicBaseUrl(baseUrl?: string): string | undefined;
6
+ /** Resolve the endpoint for a first-party Anthropic model without loading its provider implementation. */
7
+ export declare function resolveDirectAnthropicBaseUrl(model: Model<Api>): string;
8
+ /** Build the endpoint-and-model-scoped Anthropic session-state key. */
9
+ export declare function anthropicProviderSessionStateKey(baseUrl: string, modelId: string): string;
10
+ /** Re-arm fast mode across materialized Anthropic session-state entries. */
11
+ export declare function clearAnthropicFastModeFallback(providerSessionState: Map<string, ProviderSessionState> | undefined): void;
12
+ /** Inspect the direct model's fast-mode fallback without materializing state. */
13
+ export declare function isAnthropicFastModeFallbackDisabled(providerSessionState: Map<string, ProviderSessionState> | undefined, model: Model<Api>): boolean;
@@ -1,6 +1,11 @@
1
- import type { Api, FetchImpl, Message, Model, ProviderSessionState, ServiceTier, SimpleStreamOptions, StreamFunction, StreamOptions, Usage } from "../types.js";
1
+ import type { FetchImpl, Message, Model, ServiceTier, SimpleStreamOptions, StreamFunction, StreamOptions, Usage } from "../types.js";
2
2
  import { type AnthropicFetchOptions, type AnthropicMessagesClientLike } from "./anthropic-client.js";
3
3
  import { type FallbackParam, type MessageParam, type TextBlockParam } from "./anthropic-wire.js";
4
+ import { resolvesToOfficialAnthropicEndpoint, supportsAnthropicCompaction, supportsAnthropicCompactionOnClient } from "./anthropic-compaction.js";
5
+ import { applyClaudeToolPrefix, deriveClaudeDeviceId, generateClaudeCloakingUserId, isClaudeCloakingUserId, resolveAnthropicMetadataUserId, stripClaudeToolPrefix } from "./anthropic-identity.js";
6
+ import { clearAnthropicFastModeFallback, isAnthropicFastModeFallbackDisabled, normalizeAnthropicBaseUrl } from "./anthropic-state.js";
7
+ export { applyClaudeToolPrefix, clearAnthropicFastModeFallback, deriveClaudeDeviceId, generateClaudeCloakingUserId, isAnthropicFastModeFallbackDisabled, isClaudeCloakingUserId, normalizeAnthropicBaseUrl, resolveAnthropicMetadataUserId, stripClaudeToolPrefix, };
8
+ export { resolvesToOfficialAnthropicEndpoint, supportsAnthropicCompaction, supportsAnthropicCompactionOnClient };
4
9
  export type AnthropicHeaderOptions = {
5
10
  apiKey: string;
6
11
  baseUrl?: string;
@@ -14,24 +19,9 @@ export type AnthropicHeaderOptions = {
14
19
  /** Allow explicit fingerprint headers to replace OAuth defaults on non-official endpoints. */
15
20
  allowAnthropicHeaderOverrides?: boolean;
16
21
  };
17
- export declare function normalizeAnthropicBaseUrl(baseUrl?: string): string | undefined;
18
22
  export declare function buildBetaHeader(baseBetas: readonly string[], extraBetas: readonly string[]): string;
19
23
  export declare function buildAnthropicHeaders(options: AnthropicHeaderOptions): Record<string, string>;
20
24
  type AnthropicCacheControl = NonNullable<TextBlockParam["cache_control"]>;
21
- /**
22
- * Clears the in-session "server rejected fast mode" sticky flag. Call when the
23
- * caller is explicitly re-arming `serviceTier: "priority"` (e.g. user toggled
24
- * `/fast on` after a previous turn auto-disabled it) so the next request
25
- * actually carries `speed: "fast"` again. No-op when the map or state entry
26
- * hasn't been materialized yet.
27
- */
28
- export declare function clearAnthropicFastModeFallback(providerSessionState: Map<string, ProviderSessionState> | undefined): void;
29
- /**
30
- * Whether the direct Anthropic model's endpoint-scoped fast-mode fallback is
31
- * currently active. Reading the map directly is intentional: inspection must
32
- * not materialize a state entry for a model that has never streamed.
33
- */
34
- export declare function isAnthropicFastModeFallbackDisabled(providerSessionState: Map<string, ProviderSessionState> | undefined, model: Model<Api>): boolean;
35
25
  export * from "./claude-code-fingerprint.js";
36
26
  /** Maps Node's platform identifier to the Stainless wire value. */
37
27
  export declare function mapStainlessOs(platform: string): "MacOS" | "Windows" | "Linux" | "FreeBSD" | `Other::${string}`;
@@ -54,23 +44,6 @@ export declare const claudeCodeHeaders: {
54
44
  * pass through untouched, so installing it on every OAuth flow is safe.
55
45
  */
56
46
  export declare function wrapFetchForCch(base: FetchImpl): FetchImpl;
57
- export declare function isClaudeCloakingUserId(userId: string): boolean;
58
- export declare function generateClaudeCloakingUserId(): string;
59
- export declare function deriveClaudeDeviceId(installId: string, accountId?: string): string;
60
- /**
61
- * Resolve the `metadata.user_id` field for an Anthropic Messages request.
62
- *
63
- * For API-key tokens, an explicit caller-supplied `userId` is forwarded
64
- * verbatim and `undefined` yields no metadata. For OAuth tokens the value
65
- * must match the Claude Code attribution shape (`isClaudeCloakingUserId` or
66
- * the `{session_id, account_uuid?, device_id?}` JSON envelope) — anything
67
- * else is dropped and a fresh Claude-Code-style JSON id is generated from
68
- * `sessionId`/`accountId` so attribution stays consistent across the main
69
- * streaming path and provider-specific request builders (e.g. web search).
70
- */
71
- export declare function resolveAnthropicMetadataUserId(userId: unknown, isOAuthToken: boolean, sessionId?: string, accountId?: string): string | undefined;
72
- export declare const applyClaudeToolPrefix: (name: string) => string;
73
- export declare const stripClaudeToolPrefix: (name: string) => string;
74
47
  export type AnthropicOutputEffort = "low" | "medium" | "high" | "xhigh" | "max";
75
48
  export type AnthropicEffort = AnthropicOutputEffort | "adaptive";
76
49
  export type AnthropicThinkingDisplay = "summarized" | "omitted";
@@ -212,32 +185,6 @@ export type AnthropicUsageLike = {
212
185
  * zero-valued objects clear prior extras from earlier stream usage snapshots.
213
186
  */
214
187
  export declare function applyAnthropicUsageExtras(usage: Usage, source: AnthropicUsageLike): void;
215
- /**
216
- * Whether this model's requests reach the official Anthropic API, resolved the
217
- * way the transport resolves it — including the Foundry and
218
- * `ANTHROPIC_BASE_URL` reroutes that leave `compat.officialEndpoint` stale.
219
- */
220
- export declare function resolvesToOfficialAnthropicEndpoint(model: Model<"anthropic-messages">): boolean;
221
- /**
222
- * Whether server-side compaction (`compact-2026-01-12`) may be spoken for
223
- * this model to the endpoint a request actually reaches: a model line the
224
- * beta supports (`compat.supportsServerCompaction`, rule-owned in the
225
- * catalog), on the official API for the first-party provider or on any
226
- * endpoint that opted in through `remoteCompaction.enabled`, and never on one
227
- * whose deployment contract excludes context management. The same predicate
228
- * gates emitting the edit, attaching the beta, and replaying a persisted
229
- * block, so a route or model change can never leave a session sending a block
230
- * its endpoint rejects.
231
- */
232
- export declare function supportsAnthropicCompaction(model: Model<"anthropic-messages">, effectiveBaseUrl?: string): boolean;
233
- /**
234
- * {@link supportsAnthropicCompaction} for a request on a caller-owned client:
235
- * the endpoint is whatever the client targets (an `AnthropicVertex` client
236
- * carries an Anthropic model to Vertex), never the model's own routing. SDK
237
- * clients expose it as `baseURL`; a client that exposes no endpoint only
238
- * compacts through an explicit `remoteCompaction.enabled` opt-in.
239
- */
240
- export declare function supportsAnthropicCompactionOnClient(model: Model<"anthropic-messages">, client: AnthropicMessagesClientLike): boolean;
241
188
  /** Detects the preserved-thinking error caused by rewriting a signed block's conversation prefix. */
242
189
  export declare function isThinkingPrefixBindingError(message: string): boolean;
243
190
  export declare function isInvalidThinkingSignatureError(message: string): boolean;
@@ -3,5 +3,4 @@ import type { Api, Context, Model, SimpleStreamOptions } from "../types.js";
3
3
  import { AssistantMessageEventStream } from "../utils/event-stream.js";
4
4
  export { getGitLabDuoModels };
5
5
  export declare function clearGitLabDuoDirectAccessCache(): void;
6
- export declare function isGitLabDuoModel(model: Model<Api>): boolean;
7
6
  export declare function streamGitLabDuo(model: Model<Api>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
@@ -8,7 +8,7 @@
8
8
  * Each discovered model selects its server-declared protocol; legacy models
9
9
  * without protocol metadata retain the Anthropic-compatible default.
10
10
  */
11
- import type { Api, Context, Model } from "../types.js";
11
+ import type { Context, Model } from "../types.js";
12
12
  import type { AssistantMessageEventStream } from "../utils/event-stream.js";
13
13
  import { type OpenAIAnthropicApiFormat, type OpenAIAnthropicShimOptions } from "./openai-anthropic-shim.js";
14
14
  export type KimiApiFormat = OpenAIAnthropicApiFormat;
@@ -21,7 +21,3 @@ export interface KimiOptions extends OpenAIAnthropicShimOptions {
21
21
  * Returns synchronously like other providers - async header fetching happens internally.
22
22
  */
23
23
  export declare function streamKimi(model: Model<"openai-completions">, context: Context, options?: KimiOptions): AssistantMessageEventStream;
24
- /**
25
- * Check if a model is a Kimi Code model.
26
- */
27
- export declare function isKimiModel(model: Model<Api>): boolean;
@@ -0,0 +1,6 @@
1
+ /** Host integration boundary for just-in-time `x-oai-attestation` values. */
2
+ export type CodexAttestationProvider = () => Promise<string | undefined>;
3
+ /** Install the process-wide just-in-time Codex attestation provider. */
4
+ export declare function setCodexAttestationProvider(provider: CodexAttestationProvider | undefined): void;
5
+ /** Resolve an attestation only for ChatGPT-OAuth credentials. */
6
+ export declare function getCodexAttestationHeader(accountId: string | undefined): Promise<string | undefined>;
@@ -0,0 +1,6 @@
1
+ import type { CodexCompactionContext, CodexCompactionRequestContext } from "../types.js";
2
+ /** Add the selected wire implementation to one logical compaction context. */
3
+ export declare function createOpenAICodexCompactionRequestContext(options: {
4
+ context: CodexCompactionContext | undefined;
5
+ implementation: "responses" | "responses_compaction_v2" | "responses_compact";
6
+ }): CodexCompactionRequestContext | undefined;
@@ -1,5 +1,8 @@
1
1
  import type { CodexCompactionContext, CodexCompactionRequestContext, Context, Model, ProviderSessionState, ServiceTier, StreamFunction, StreamOptions, Tool, ToolChoice } from "../types.js";
2
2
  import { type CodexLiteShapedBody, type CodexReasoningContext, type InputItem, type RequestBody } from "./openai-codex/request-transformer.js";
3
+ export { createOpenAICodexCompactionRequestContext } from "./openai-codex-compaction.js";
4
+ export { setCodexAttestationProvider } from "./openai-codex-attestation.js";
5
+ export type { CodexAttestationProvider } from "./openai-codex-attestation.js";
3
6
  import type { ResponseInput } from "./openai-responses-wire.js";
4
7
  export interface OpenAICodexResponsesOptions extends StreamOptions {
5
8
  reasoning?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
@@ -73,33 +76,6 @@ export interface OpenAICodexCompactionResetOptions {
73
76
  sessionId?: string;
74
77
  compaction: CodexCompactionContext;
75
78
  }
76
- /** Add the selected wire implementation to one logical compaction context. */
77
- export declare function createOpenAICodexCompactionRequestContext(options: {
78
- context: CodexCompactionContext | undefined;
79
- implementation: "responses" | "responses_compaction_v2" | "responses_compact";
80
- }): CodexCompactionRequestContext | undefined;
81
- /**
82
- * Host integration boundary for just-in-time `x-oai-attestation` header
83
- * values (codex-rs `AttestationProvider`). Resolves to the full header value
84
- * — an `{"v":1,"s":0,"t":"v1.…"}` envelope — or `undefined` when no
85
- * attestation should be sent.
86
- */
87
- export type CodexAttestationProvider = () => Promise<string | undefined>;
88
- /**
89
- * Install the process-wide attestation hook consulted for upstream Codex
90
- * requests (codex-rs stores its provider on `ModelClient` construction). The
91
- * hook is only consulted for ChatGPT-OAuth credentials and runs just-in-time
92
- * per request; WebSocket handshakes resolve once per connection because the
93
- * header is connection-scoped there.
94
- */
95
- export declare function setCodexAttestationProvider(provider: CodexAttestationProvider | undefined): void;
96
- /**
97
- * Resolve the `x-oai-attestation` header value for one upstream request.
98
- * Gated on ChatGPT-OAuth credentials (a Codex JWT carries `chatgpt_account_id`;
99
- * codex-rs gates on `auth.is_chatgpt_auth()`). A throwing hook degrades to no
100
- * header rather than failing the request.
101
- */
102
- export declare function getCodexAttestationHeader(accountId: string | undefined): Promise<string | undefined>;
103
79
  type CodexTransport = "sse" | "websocket";
104
80
  /** Shape of the Codex request sent on the latest provider turn. */
105
81
  export interface OpenAICodexTurnRequestDiagnostics {
@@ -0,0 +1,7 @@
1
+ import type { Model } from "../types.js";
2
+ /** Read the optional process-wide Codex WebSocket override. */
3
+ export declare function getOpenAICodexWebSocketEnvValue(): boolean | undefined;
4
+ /** Resolve the public WebSocket preference using env, caller, then model precedence. */
5
+ export declare function isOpenAICodexWebSocketPreferred(model: Model<"openai-codex-responses">, options?: {
6
+ preferWebsockets?: boolean;
7
+ }): boolean;
@@ -8,15 +8,6 @@ import type { CapturedHttpErrorResponse } from "../utils/http-inspector.js";
8
8
  import type { ChatCompletionCreateParamsStreaming } from "./openai-chat-wire.js";
9
9
  import { type InputItem } from "./openai-codex/request-transformer.js";
10
10
  import type { ResponseComputerToolCall, ResponseContentPartAddedEvent, ResponseCreateParamsStreaming, ResponseInput, ResponseInputContent, ResponseInputItem, ResponseOutputItem, ResponseOutputMessage, ResponseReasoningItem, ResponseStatus, ResponseStreamEvent } from "./openai-responses-wire.js";
11
- /**
12
- * Keyless-provider sentinel. Custom providers configured with `auth: none`
13
- * (models.yml) have no credential, so the coding-agent resolves their API key
14
- * to this literal instead of a real secret. Providers must treat it as "no
15
- * credential" and suppress any credential-bearing header (e.g. `Authorization:
16
- * Bearer …`) rather than forwarding the sentinel on the wire. See #6188; the
17
- * google-vertex and amazon-bedrock transports apply the same guard inline.
18
- */
19
- export declare const NO_AUTH_SENTINEL = "N/A";
20
11
  export interface OpenAIModelIdentity {
21
12
  provider: string;
22
13
  id: string;
@@ -1,37 +1,35 @@
1
1
  /**
2
- * Lazy provider module loading.
3
- *
4
- * Each provider module is loaded only when its stream function is first called.
5
- * This avoids eagerly importing heavy SDK dependencies (e.g., openai) at
6
- * startup. The loaded module promise is cached so subsequent calls
7
- * reuse the same import.
8
- *
9
- * NOTE: stream.ts currently imports providers directly, so this file is not yet
10
- * wired into the main streaming path. It provides the infrastructure for lazy
11
- * loading that can be integrated when stream.ts is refactored.
2
+ * Built-in provider stream dispatch with shared error, cancellation, and timeout handling.
12
3
  */
13
- import type { AssistantMessageEventStream, Context, Model, OptionsForApi } from "../types.js";
4
+ import type { Context, Model, OptionsForApi } from "../types.js";
14
5
  import { AssistantMessageEventStream as EventStreamImpl } from "../utils/event-stream.js";
15
- import type { BedrockOptions } from "./amazon-bedrock.js";
16
- import type { CursorOptions } from "./cursor.js";
17
- interface CursorProviderModule {
18
- streamCursor: (model: Model<"cursor-agent">, context: Context, options: CursorOptions) => AssistantMessageEventStream;
19
- }
20
- interface BedrockProviderModule {
21
- streamBedrock: (model: Model<"bedrock-converse-stream">, context: Context, options: BedrockOptions) => AssistantMessageEventStream;
22
- }
23
- export declare function setBedrockProviderModule(module: BedrockProviderModule): void;
24
- export declare function setCursorProviderModule(module: CursorProviderModule): void;
6
+ import * as BedrockProvider from "./amazon-bedrock.js";
7
+ import * as CursorProvider from "./cursor.js";
8
+ /** Install a host-supplied Bedrock transport in place of the built-in provider. */
9
+ export declare function setBedrockProviderModule(module: Pick<typeof BedrockProvider, "streamBedrock">): void;
10
+ /** Install a host-supplied Cursor transport in place of the built-in provider. */
11
+ export declare function setCursorProviderModule(module: Pick<typeof CursorProvider, "streamCursor">): void;
12
+ /** Stream Anthropic responses with provider-owned timeout handling. */
25
13
  export declare const streamAnthropic: (model: Model<"anthropic-messages">, context: Context, options: OptionsForApi<"anthropic-messages">) => EventStreamImpl;
14
+ /** Stream Azure Responses with provider-owned timeout handling. */
26
15
  export declare const streamAzureOpenAIResponses: (model: Model<"azure-openai-responses">, context: Context, options: OptionsForApi<"azure-openai-responses">) => EventStreamImpl;
16
+ /** Stream Google's direct API through the shared watchdog. */
27
17
  export declare const streamGoogle: (model: Model<"google-generative-ai">, context: Context, options: OptionsForApi<"google-generative-ai">) => EventStreamImpl;
18
+ /** Stream Cloud Code Assist while retaining its first-event watchdog. */
28
19
  export declare const streamGoogleGeminiCli: (model: Model<"google-gemini-cli">, context: Context, options: OptionsForApi<"google-gemini-cli">) => EventStreamImpl;
20
+ /** Stream the Vertex API through the shared watchdog. */
29
21
  export declare const streamGoogleVertex: (model: Model<"google-vertex">, context: Context, options: OptionsForApi<"google-vertex">) => EventStreamImpl;
22
+ /** Stream Codex with provider-owned timeout handling. */
30
23
  export declare const streamOpenAICodexResponses: (model: Model<"openai-codex-responses">, context: Context, options: OptionsForApi<"openai-codex-responses">) => EventStreamImpl;
24
+ /** Stream Chat Completions with provider-owned timeout handling. */
31
25
  export declare const streamOpenAICompletions: (model: Model<"openai-completions">, context: Context, options: OptionsForApi<"openai-completions">) => EventStreamImpl;
26
+ /** Stream Responses with provider-owned timeout handling. */
32
27
  export declare const streamOpenAIResponses: (model: Model<"openai-responses">, context: Context, options: OptionsForApi<"openai-responses">) => EventStreamImpl;
28
+ /** Stream through the host Cursor transport when installed, otherwise the built-in transport. */
33
29
  export declare const streamCursor: (model: Model<"cursor-agent">, context: Context, options: OptionsForApi<"cursor-agent">) => EventStreamImpl;
30
+ /** Stream Devin through the shared watchdog. */
34
31
  export declare const streamDevin: (model: Model<"devin-agent">, context: Context, options: OptionsForApi<"devin-agent">) => EventStreamImpl;
32
+ /** Stream Ollama with OpenAI-compatible idle timeout precedence. */
35
33
  export declare const streamOllama: (model: Model<"ollama-chat">, context: Context, options: OptionsForApi<"ollama-chat">) => EventStreamImpl;
34
+ /** Stream through the host Bedrock transport when installed, otherwise the built-in transport. */
36
35
  export declare const streamBedrock: (model: Model<"bedrock-converse-stream">, context: Context, options: OptionsForApi<"bedrock-converse-stream">) => EventStreamImpl;
37
- export {};
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @see https://dev.synthetic.new/docs/api/overview
9
9
  */
10
- import type { Api, Context, Model } from "../types.js";
10
+ import type { Context, Model } from "../types.js";
11
11
  import type { AssistantMessageEventStream } from "../utils/event-stream.js";
12
12
  import { type OpenAIAnthropicApiFormat, type OpenAIAnthropicShimOptions } from "./openai-anthropic-shim.js";
13
13
  export type SyntheticApiFormat = OpenAIAnthropicApiFormat;
@@ -20,7 +20,3 @@ export interface SyntheticOptions extends OpenAIAnthropicShimOptions {
20
20
  * Returns synchronously like other providers - async processing happens internally.
21
21
  */
22
22
  export declare function streamSynthetic(model: Model<"openai-completions">, context: Context, options?: SyntheticOptions): AssistantMessageEventStream;
23
- /**
24
- * Check if a model is a Synthetic model.
25
- */
26
- export declare function isSyntheticModel(model: Model<Api>): boolean;