@caeliq/llms 1.0.59 → 1.0.61

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 (41) hide show
  1. package/README.md +41 -3
  2. package/dist/cjs/server.cjs +259 -224
  3. package/dist/cjs/server.cjs.map +4 -4
  4. package/dist/esm/server.mjs +260 -225
  5. package/dist/esm/server.mjs.map +4 -4
  6. package/dist/routing/inbound-pipeline.d.ts +8 -5
  7. package/dist/routing/protocol-adapter.d.ts +3 -4
  8. package/dist/routing/protocol-endpoints.d.ts +14 -2
  9. package/dist/server.d.ts +2 -0
  10. package/dist/tests/anthropic.client-policy.d.ts +1 -0
  11. package/dist/tests/assistant-turn-order.d.ts +1 -0
  12. package/dist/tests/cache-prefix-debug.d.ts +1 -0
  13. package/dist/tests/cross-protocol.cache-prefix.d.ts +1 -0
  14. package/dist/tests/cross-protocol.config-matrix.d.ts +1 -0
  15. package/dist/tests/cross-protocol.responses-grok.d.ts +1 -0
  16. package/dist/tests/mistral.thinking-history.d.ts +1 -0
  17. package/dist/tests/reasoning.effort-levels.d.ts +1 -0
  18. package/dist/tests/responses.reasoning-duplication.d.ts +1 -0
  19. package/dist/tests/sse-debug-tap.d.ts +1 -0
  20. package/dist/tests/sse.client-keepalive.d.ts +1 -0
  21. package/dist/tests/xai-auth.reliability.d.ts +1 -0
  22. package/dist/transformer/claude-auth.transformer.d.ts +26 -3
  23. package/dist/transformer/index.d.ts +2 -0
  24. package/dist/transformer/openai.responses.transformer.d.ts +1 -0
  25. package/dist/transformer/xai-auth.transformer.d.ts +24 -0
  26. package/dist/types/llm.d.ts +9 -1
  27. package/dist/utils/anthropic-client-policy.d.ts +45 -0
  28. package/dist/utils/anthropic-url.d.ts +1 -0
  29. package/dist/utils/cache-prefix-debug.d.ts +120 -0
  30. package/dist/utils/claude-billing.d.ts +12 -6
  31. package/dist/utils/claude-model-catalog.d.ts +2 -1
  32. package/dist/utils/gemini-thinking.d.ts +2 -1
  33. package/dist/utils/health-reporter.d.ts +13 -0
  34. package/dist/utils/openai.responses.util.d.ts +157 -1
  35. package/dist/utils/reasoning-effort.d.ts +13 -0
  36. package/dist/utils/redact.d.ts +1 -0
  37. package/dist/utils/sse/client-keepalive.d.ts +19 -0
  38. package/dist/utils/sse/index.d.ts +1 -0
  39. package/dist/utils/sse-debug-tap.d.ts +62 -0
  40. package/dist/utils/xai-auth.d.ts +37 -0
  41. package/package.json +12 -12
@@ -7,14 +7,12 @@ export interface PreparedInboundRequest {
7
7
  protocolContext: ClientProtocolContext;
8
8
  /** Original client wire body (preserved for Anthropic custom routers). */
9
9
  originalBody: any;
10
- /**
11
- * Client wire body after protocol adaptation and CCR-only cleanup
12
- * (subagent tag stripped, REWRITE_SYSTEM_PROMPT applied). This — not
13
- * originalBody — is what an exact-wire passthrough must send upstream.
14
- */
10
+ /** Client wire body after protocol adaptation and CCR-only cleanup. */
15
11
  clientWireBody: any;
16
12
  /** Normalized Unified body used for routing and provider conversion. */
17
13
  unifiedBody: UnifiedChatRequest;
14
+ /** Unified projection before destination-specific Anthropic emulation. */
15
+ prePolicyUnifiedBody: UnifiedChatRequest;
18
16
  providerName: string;
19
17
  modelName: string;
20
18
  }
@@ -27,5 +25,10 @@ export declare function resolveDestination(model: string | undefined, protocol?:
27
25
  providerName: string;
28
26
  modelName: string;
29
27
  };
28
+ /**
29
+ * Decode a discovery alias before scenario routing. Aliases are constrained to
30
+ * configured canonical routes; ordinary `provider,model` ids are unchanged.
31
+ */
32
+ export declare function resolveConfiguredClaudeModelAlias(model: string | undefined, isConfigured: (canonicalId: string) => boolean, protocol?: ClientProtocolContext["protocol"]): string | undefined;
30
33
  export declare function throwProtocolError(protocol: ClientProtocolContext["protocol"] | undefined, message: string, statusCode: number, code: string, type?: string): never;
31
34
  export declare function protocolAwareBypass(provider: any, transformer: Transformer, protocolContext: ClientProtocolContext | undefined, modelName: string | undefined): boolean;
@@ -24,10 +24,9 @@ export declare function normalizeClientToUnified(protocol: ClientProtocolContext
24
24
  */
25
25
  export declare function cloneProtocolBody<T>(value: T): T;
26
26
  /**
27
- * Preserve only known protocol/version and SDK metadata headers for exact-wire
28
- * passthrough. An allowlist prevents an arbitrary client header from becoming
29
- * an upstream credential or tenant-routing secret. Provider authentication is
30
- * generated independently.
27
+ * Preserve all end-to-end application headers for a native client. Only
28
+ * credentials, cookies, CCR/proxy routing metadata and hop-by-hop transport
29
+ * headers are removed; provider authentication is generated independently.
31
30
  */
32
31
  export declare function sanitizePassthroughHeaders(headers: Headers | Record<string, unknown> | undefined): Record<string, string>;
33
32
  /**
@@ -1,4 +1,5 @@
1
1
  import type { RouterScenarioType } from "../utils/router";
2
+ import type { AnthropicClientKind, AnthropicProviderMode } from "../utils/anthropic-client-policy";
2
3
  /**
3
4
  * Inbound client protocols supported by CCR's gateway lifecycle.
4
5
  */
@@ -17,12 +18,23 @@ export interface ClientProtocolContext {
17
18
  /** Alias path that matched, if different from canonical */
18
19
  matchedPath: string;
19
20
  originalModel?: string;
21
+ /** Client selected the gateway's trailing `[1m]` context variant. */
22
+ requestedOneMillion?: boolean;
20
23
  stream: boolean;
21
24
  scenarioType?: RouterScenarioType;
22
25
  /** Source-only Anthropic semantics retained before destination routing. */
23
26
  anthropicSource?: AnthropicSourceRequestFields;
24
- /** Keep explicit source cache directives or add provider-native automatic caching. */
25
- anthropicCacheMode?: "preserve" | "automatic";
27
+ /** Client fingerprint captured before Anthropic normalization. */
28
+ anthropicClientKind?: AnthropicClientKind;
29
+ /** In-scope Anthropic destination/auth variant selected after routing. */
30
+ anthropicProviderMode?: AnthropicProviderMode;
31
+ anthropicDestinationInScope?: boolean;
32
+ /** Native Desktop/CLI requests must bypass body and response conversion. */
33
+ anthropicNativeWire?: boolean;
34
+ /** Third-party emulation has already modified the Unified projection. */
35
+ anthropicPolicyApplied?: boolean;
36
+ anthropicSystemTransformed?: boolean;
37
+ claudeAuthToolNameMap?: Map<string, string>;
26
38
  /** Claude Code routing metadata extracted without mutating the source billing block. */
27
39
  claudeCodeSubagent?: boolean;
28
40
  taggedSubagentModel?: string;
package/dist/server.d.ts CHANGED
@@ -60,3 +60,5 @@ export { sanitizeHeadersForLog, diffHeadersForLog, sanitizeBodyForLog, DEFAULT_L
60
60
  export { exchangeAuthorizationCode, fetchUserEmail, resolveProjectId, saveTokens, loadTokens, getValidAccessToken, ANTIGRAVITY_CLIENT_ID, ANTIGRAVITY_CLIENT_SECRET, ANTIGRAVITY_REDIRECT_URI, ANTIGRAVITY_SCOPES, type AntigravityTokens, } from "./utils/antigravity-auth";
61
61
  export { matchClientProtocol, isRoutedLlmPost, listClientRouteRegistrations, type ClientProtocol, type ClientProtocolContext, type ProtocolRouteMatch, } from "./routing/protocol-endpoints";
62
62
  export { protocolErrorBody } from "./routing/protocol-errors";
63
+ export { setHealthReporter } from "./utils/health-reporter";
64
+ export type { HealthReporter } from "./utils/health-reporter";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { UnifiedChatRequest } from "../types/llm";
2
2
  import { Transformer, TransformerContext } from "../types/transformer";
3
+ import { HeaderRecord } from "../utils/headers";
3
4
  import { ClaudeModelCatalogEntry } from "../utils/claude-model-catalog";
4
5
  /** Anthropic beta required for Claude subscription / Claude Code OAuth Bearer auth. */
5
6
  export declare const CLAUDE_OAUTH_REQUIRED_BETA = "oauth-2025-04-20";
@@ -20,13 +21,26 @@ export declare function resolveClaudeAuthAnthropicBeta(input: {
20
21
  }): string;
21
22
  /**
22
23
  * Build outbound anthropic-beta for the non-Claude-Code (full synthesis)
23
- * branch, mirroring Claude Code's own model-driven beta selection. Never
24
- * derived from model-name prefix matching always from the capability
25
- * catalog. `ANTHROPIC_BETA_FLAGS` replaces the list wholesale.
24
+ * branch, mirroring Claude Code's current model-driven beta selection. Model
25
+ * capabilities come from the catalog; the CLI's one family-level exception
26
+ * (the ordinary Haiku profile omits the Claude Code beta) is retained from the
27
+ * decompiled `cui()` branch. Current CLI `ANTHROPIC_BETAS` values are appended
28
+ * to the profile; OAuth callers still add their required OAuth beta at the auth
29
+ * boundary.
26
30
  */
27
31
  export declare function resolveClaudeAuthBetas(modelId: string | undefined, opts?: {
28
32
  envBeta?: string;
33
+ includeOAuthBeta?: boolean;
34
+ includeToolSearch?: boolean;
35
+ includeEffort?: boolean;
36
+ includeFallbackCredit?: boolean;
29
37
  }): string;
38
+ /**
39
+ * Recreate the SDK's context marker only for models whose 1M window is a beta.
40
+ * Native-1M models still accept the gateway picker suffix, but must not receive
41
+ * the legacy context beta upstream.
42
+ */
43
+ export declare function modelIdForRequestedOneMillionBeta(modelId: string | undefined, requestedOneMillion: boolean | undefined): string | undefined;
30
44
  /**
31
45
  * Reshape a built Anthropic body's `thinking`/`output_config`/`max_tokens`
32
46
  * to what the resolved model actually supports, replacing a hand-rolled
@@ -37,10 +51,19 @@ export declare function resolveClaudeAuthBetas(modelId: string | undefined, opts
37
51
  export declare function applyClaudeModelCapabilityAdjustments(anthropicBody: Record<string, any>, entry: ClaudeModelCatalogEntry | undefined): void;
38
52
  /** Test-only reset hook so session-id state doesn't leak across test cases. */
39
53
  export declare function __resetClaudeAuthTransformerStateForTests(): void;
54
+ /** Synthesized Claude Code identity headers for the non-Claude-Code branch. */
55
+ export declare function buildSynthesizedIdentityHeaders(): HeaderRecord;
56
+ export declare function buildSynthesizedUserMetadata(): Record<string, string>;
40
57
  export declare class ClaudeAuthTransformer implements Transformer {
41
58
  name: string;
42
59
  logger?: any;
43
60
  transformRequestIn(request: UnifiedChatRequest, provider: any, context?: TransformerContext): Promise<Record<string, any>>;
61
+ /**
62
+ * Auth-only path used by native Desktop/CLI raw-wire requests. It keeps the
63
+ * original body and application headers untouched while still replacing the
64
+ * caller credential with CCR's OAuth token.
65
+ */
66
+ auth(request: any, provider: any, context?: TransformerContext): Promise<any>;
44
67
  /**
45
68
  * Body/URL/wire-format conversion belong to AnthropicTransformer's
46
69
  * provider pair, which already ran (response-side order is reversed, so
@@ -29,6 +29,7 @@ import { OpencodeHeadersTransformer } from "./opencode-headers.transformer";
29
29
  import { ClaudeAuthTransformer } from "./claude-auth.transformer";
30
30
  import { CursorSdkTransformer } from "./cursor-sdk.transformer";
31
31
  import { AntigravityAuthTransformer } from "./antigravity-auth.transformer";
32
+ import { XaiAuthTransformer } from "./xai-auth.transformer";
32
33
  declare const _default: {
33
34
  AnthropicTransformer: typeof AnthropicTransformer;
34
35
  GeminiTransformer: typeof GeminiTransformer;
@@ -61,5 +62,6 @@ declare const _default: {
61
62
  ClaudeAuthTransformer: typeof ClaudeAuthTransformer;
62
63
  CursorSdkTransformer: typeof CursorSdkTransformer;
63
64
  AntigravityAuthTransformer: typeof AntigravityAuthTransformer;
65
+ XaiAuthTransformer: typeof XaiAuthTransformer;
64
66
  };
65
67
  export default _default;
@@ -23,6 +23,7 @@ export declare class OpenAIResponsesTransformer implements Transformer {
23
23
  * allocated per Responses item by `toolIndexFor`.
24
24
  */
25
25
  private convertStreamEvent;
26
+ private convertStreamEventCore;
26
27
  private normalizeRequestContent;
27
28
  private convertResponseToChat;
28
29
  private buildImageContent;
@@ -0,0 +1,24 @@
1
+ import { Transformer } from "../types/transformer";
2
+ export declare class XaiAuthTransformer implements Transformer {
3
+ name: string;
4
+ logger?: any;
5
+ private resolveAuth;
6
+ /**
7
+ * openai-responses only converts the body — it doesn't own the outbound
8
+ * URL (its endPoint is a client-facing inbound route registration, not an
9
+ * outbound path). The generic pipeline falls back to a bare
10
+ * `provider.baseUrl` when no transformer sets config.url (routes.ts:739),
11
+ * so this transformer must build the actual `/responses` URL itself,
12
+ * mirroring CodexTransformer's `${baseUrl}/responses`.
13
+ */
14
+ private buildConfig;
15
+ transformRequestIn(request: any, provider: any): Promise<Record<string, any>>;
16
+ auth(_request: any, provider: any): Promise<any>;
17
+ /**
18
+ * 401 recovery. PAT mode has nothing to recover — a bad literal key or
19
+ * env value can't be fixed by CCR. OAuth mode reloads the token file
20
+ * (another process may have already refreshed it), otherwise refreshes
21
+ * and persists, mirroring ClaudeAuthTransformer.recoverUnauthorizedAuth.
22
+ */
23
+ private recoverUnauthorizedAuth;
24
+ }
@@ -63,7 +63,12 @@ export interface UnifiedMessage {
63
63
  };
64
64
  thinking?: {
65
65
  content: string;
66
+ /** Anthropic thinking signature; never treat as Responses ciphertext. */
66
67
  signature?: string;
68
+ /** Provider-minted Responses/Codex reasoning ciphertext for replay. */
69
+ encrypted_content?: string;
70
+ /** Responses reasoning item id (`rs_…`); not interchangeable with ciphertext. */
71
+ id?: string;
67
72
  };
68
73
  }
69
74
  export interface UnifiedTool {
@@ -84,7 +89,8 @@ export interface UnifiedTool {
84
89
  ttl?: "5m" | "1h";
85
90
  };
86
91
  }
87
- export type ThinkLevel = "none" | "low" | "medium" | "high" | "xhigh" | "max";
92
+ export declare const THINK_LEVELS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"];
93
+ export type ThinkLevel = (typeof THINK_LEVELS)[number];
88
94
  export interface UnifiedChatRequest {
89
95
  messages: UnifiedMessage[];
90
96
  model: string;
@@ -160,6 +166,8 @@ export interface StreamChunk {
160
166
  thinking?: {
161
167
  content?: string;
162
168
  signature?: string;
169
+ encrypted_content?: string;
170
+ id?: string;
163
171
  };
164
172
  tool_calls?: Array<{
165
173
  id?: string;
@@ -0,0 +1,45 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ export type AnthropicClientKind = "claude_desktop" | "claude_code" | "other";
3
+ export type AnthropicProviderMode = "api_key" | "claude_oauth" | "out_of_scope";
4
+ export interface AnthropicClientFingerprintSignals {
5
+ desktopMarker: boolean;
6
+ desktopUserAgent: boolean;
7
+ desktopAgentSdkUserAgent: boolean;
8
+ cliUserAgent: boolean;
9
+ cliApp: boolean;
10
+ cliSession: boolean;
11
+ stainlessPackage: boolean;
12
+ billingSystem: boolean;
13
+ identitySystem: boolean;
14
+ }
15
+ export interface AnthropicClientPolicyContext {
16
+ anthropicClientKind?: AnthropicClientKind;
17
+ anthropicProviderMode?: AnthropicProviderMode;
18
+ anthropicDestinationInScope?: boolean;
19
+ anthropicNativeWire?: boolean;
20
+ anthropicPolicyApplied?: boolean;
21
+ anthropicSystemTransformed?: boolean;
22
+ claudeAuthToolNameMap?: Map<string, string>;
23
+ }
24
+ export declare function readHeaderValue(headers: Record<string, unknown> | undefined, name: string): string | undefined;
25
+ /**
26
+ * Classify the original Anthropic wire request. A generic SDK UA is never
27
+ * enough to grant native pass-through; incomplete fingerprints fail closed to
28
+ * the third-party emulation path.
29
+ */
30
+ export declare function classifyAnthropicClient(headers: Record<string, unknown> | undefined, body: any): AnthropicClientKind;
31
+ /** Return only non-sensitive boolean fingerprint signals for debug logging. */
32
+ export declare function inspectAnthropicClientFingerprint(headers: Record<string, unknown> | undefined, body: any): AnthropicClientFingerprintSignals;
33
+ /**
34
+ * The feature is intentionally scoped to CCR's real Anthropic provider, with
35
+ * either the exact Anthropic API-key chain or the exact claude-auth + Anthropic
36
+ * OAuth chain. Adjacent middleware makes a provider out of scope.
37
+ */
38
+ export declare function getAnthropicProviderMode(provider: any, endpointTransformerName?: string): AnthropicProviderMode;
39
+ export declare function isNativeAnthropicClient(kind: AnthropicClientKind): boolean;
40
+ /**
41
+ * Apply the one and only system transformation allowed by the gateway policy.
42
+ * This runs after routing has identified an in-scope Anthropic destination and
43
+ * before the provider's Anthropic body builder runs.
44
+ */
45
+ export declare function applyThirdPartyAnthropicPolicy(request: UnifiedChatRequest, context: AnthropicClientPolicyContext, configService: any): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function buildAnthropicMessagesUrl(baseUrl: string | undefined): string;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Pipeline position a snapshot was taken at. `client` is the Unified/exact-wire
3
+ * body handed to the provider chain; `wire` is what actually left for upstream.
4
+ * Comparing the two attributes a broken prefix to the client or to our own
5
+ * transformer chain without a bisect.
6
+ */
7
+ export type CachePrefixStage = "client" | "wire";
8
+ export type CacheAffinityHeaders = {
9
+ sessionId?: string;
10
+ threadId?: string;
11
+ clientRequestId?: string;
12
+ };
13
+ export type CachePrefixSegment = {
14
+ path: string;
15
+ role?: string;
16
+ type?: string;
17
+ hash: string;
18
+ /** Rough token weight (JSON chars / 4) — enough to rank misses by cost. */
19
+ approxTokens: number;
20
+ breakpoints: number;
21
+ reasoningId?: string;
22
+ };
23
+ export type CachePrefixSnapshot = {
24
+ createdAt: number;
25
+ model?: string;
26
+ prompt_cache_key?: string;
27
+ session_id?: string;
28
+ affinity?: CacheAffinityHeaders;
29
+ lastAssistantBlockOrder?: string[];
30
+ breakpointPaths: string[];
31
+ systemHash?: string;
32
+ toolsHash?: string;
33
+ approxTokens: number;
34
+ unstableIds: string[];
35
+ segments: CachePrefixSegment[];
36
+ };
37
+ export type CachePrefixChange = "none" | "appended" | "modified" | "removed";
38
+ export type CachePrefixIdSource = "session" | "cache_key" | "fingerprint";
39
+ export type CachePrefixDiff = {
40
+ conversationId: string;
41
+ conversationIdSource: CachePrefixIdSource;
42
+ stage: CachePrefixStage;
43
+ firstTurn: boolean;
44
+ prefixIntact: boolean;
45
+ change: CachePrefixChange;
46
+ unchangedPrefixCount: number;
47
+ previousSegmentCount: number;
48
+ currentSegmentCount: number;
49
+ /** Approximate tokens of prefix that stayed byte-identical. */
50
+ unchangedPrefixApproxTokens: number;
51
+ /** Approximate tokens the provider must re-read because the prefix moved. */
52
+ approxPrefixTokensLost: number;
53
+ /** Gap since the previous turn — separates a real break from TTL expiry. */
54
+ msSinceLastTurn?: number;
55
+ prompt_cache_keyChanged: boolean;
56
+ affinityChanged: boolean;
57
+ lastAssistantBlockOrderChanged: boolean;
58
+ modelChanged: boolean;
59
+ systemHashChanged: boolean;
60
+ toolsHashChanged: boolean;
61
+ breakpointsMoved: boolean;
62
+ /** Ids carrying an embedded timestamp — they rewrite the prefix every turn. */
63
+ unstableIds?: string[];
64
+ firstDivergencePath?: string;
65
+ firstDivergence?: {
66
+ previous?: DivergenceSide;
67
+ current?: DivergenceSide;
68
+ };
69
+ appendedPaths?: string[];
70
+ removedPaths?: string[];
71
+ prompt_cache_key?: {
72
+ previous?: string;
73
+ current?: string;
74
+ };
75
+ affinity?: {
76
+ previous?: CacheAffinityHeaders;
77
+ current?: CacheAffinityHeaders;
78
+ };
79
+ lastAssistantBlockOrder?: {
80
+ previous?: string[];
81
+ current?: string[];
82
+ };
83
+ };
84
+ export type CachePrefixDiffOptions = {
85
+ stage?: CachePrefixStage;
86
+ provider?: string;
87
+ model?: string;
88
+ /**
89
+ * Persist this snapshot as the baseline for the next turn. Pass false when
90
+ * upstream rejected the request — a body that was never cached must not
91
+ * become the baseline the following turn is judged against.
92
+ */
93
+ commit?: boolean;
94
+ };
95
+ export declare function __resetCachePrefixSnapshotsForTests(): void;
96
+ /**
97
+ * Compact, content-free snapshot of the outbound fields prompt caching uses.
98
+ */
99
+ export declare function snapshotOutboundCachePrefix(body: Record<string, any> | null | undefined, affinity?: CacheAffinityHeaders): CachePrefixSnapshot | null;
100
+ type DivergenceSide = Pick<CachePrefixSegment, "path" | "role" | "type" | "approxTokens" | "breakpoints" | "reasoningId">;
101
+ export declare function diffCachePrefixSnapshots(conversationId: string, previous: CachePrefixSnapshot | undefined, current: CachePrefixSnapshot, meta?: {
102
+ stage?: CachePrefixStage;
103
+ conversationIdSource?: CachePrefixIdSource;
104
+ }): CachePrefixDiff;
105
+ /**
106
+ * Compare this outbound body to the last one for the conversation, then
107
+ * remember the current snapshot. Returns null when there is nothing cacheable.
108
+ *
109
+ * Snapshots are keyed per stage and per provider/model: a routed fallback to a
110
+ * different destination is a legitimate cache miss, not prefix corruption, and
111
+ * must not be reported as one.
112
+ */
113
+ export declare function rememberAndDiffOutboundCachePrefix(conversationId: string | undefined, body: Record<string, any> | null | undefined, affinity?: CacheAffinityHeaders, options?: CachePrefixDiffOptions): CachePrefixDiff | null;
114
+ /**
115
+ * Attribute a broken wire prefix to the stage that broke it. The client leg is
116
+ * checked first: if Claude Code itself rewrote history there is nothing our
117
+ * transformer chain could have preserved.
118
+ */
119
+ export declare function attributeDivergenceStage(clientDiff: CachePrefixDiff | null | undefined, wireDiff: CachePrefixDiff | null | undefined): CachePrefixStage | "none" | undefined;
120
+ export {};
@@ -3,10 +3,15 @@ import { TextContent, UnifiedChatRequest, UnifiedMessage } from "../types/llm";
3
3
  export declare const BILLING_SALT = "59cf53e54c78";
4
4
  export declare const CC_VERSION: string;
5
5
  export declare const CC_ENTRYPOINT: string;
6
+ export declare const CC_USER_AGENT_ENTRYPOINT: string;
6
7
  export declare const SYSTEM_IDENTITY = "You are Claude Code, Anthropic's official CLI for Claude.";
7
8
  export declare function extractFirstUserMessageText(messages: UnifiedMessage[] | undefined): string;
8
9
  export declare function computeVersionSuffix(text: string, version: string): string;
9
- /** 5 lowercase hex chars, cached per process — not a content hash. */
10
+ /**
11
+ * Current first-party Anthropic requests use the literal cch marker. Older
12
+ * captures showed a random session value; the current 2.1.226 decompilation
13
+ * gates this field to first-party/Vertex and emits `00000`.
14
+ */
10
15
  export declare function sessionCch(): string;
11
16
  export declare function __resetClaudeBillingStateForTests(): void;
12
17
  export declare function buildClaudeBillingHeaderValue(messages: UnifiedMessage[] | undefined, version?: string, entrypoint?: string): string;
@@ -21,14 +26,15 @@ export declare function normalizeSystemToArray(request: UnifiedChatRequest): Tex
21
26
  /** Drop any existing billing entry (dedupe) and prepend a fresh one at system[0]. */
22
27
  export declare function applyClaudeBillingSystemBlock(system: TextContent[], messages: UnifiedMessage[] | undefined): void;
23
28
  /**
24
- * Insert SYSTEM_IDENTITY as its own entry at system[1]. Any remaining
25
- * caller system content is left in place here — relocateForeignSystemContent
26
- * (called separately, afterwards) is what moves it out of system[].
29
+ * Insert SYSTEM_IDENTITY after the billing block (normally system[1], or
30
+ * system[0] when attribution is disabled). Any remaining caller system
31
+ * content is left in place here relocateForeignSystemContent (called
32
+ * separately, afterwards) is what moves it out of system[].
27
33
  */
28
34
  export declare function applyClaudeSystemIdentity(system: TextContent[]): void;
29
35
  /**
30
- * Move everything in `system[]` past the identity block (index 1) into the
31
- * first user message instead. Anthropic's OAuth billing validator appears to
36
+ * Move everything in `system[]` past the identity block into the first user
37
+ * message instead. Anthropic's OAuth billing validator appears to
32
38
  * inspect `system[]` content beyond the identity prefix and reject requests
33
39
  * whose system array carries a foreign harness prompt with an "out of extra
34
40
  * usage" 400 — the same approach used by third-party Claude Code OAuth
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Claude Code's bundled model capability catalog (extracted from v2.1.220).
2
+ * Claude Code's bundled model capability catalog, revalidated against the
3
+ * installed v2.1.226 CLI decompilation.
3
4
  *
4
5
  * Every model-dependent decision in the claude-auth impersonation path (beta
5
6
  * flags, effort support, thinking shape, max_tokens ceiling) is driven by
@@ -51,7 +51,8 @@ export declare function resolveThinkingDialect(model: string): ThinkingDialect;
51
51
  *
52
52
  * Rounds *up* when the exact level is missing so a request never silently loses
53
53
  * reasoning depth: `medium` on Gemini 3 Pro (low|high) becomes `high`, and
54
- * Claude's `xhigh`/`max` — which are not Gemini enum values — become `high`.
54
+ * Claude/CCR's `xhigh`/`max`/`ultra` — which are not Gemini enum values —
55
+ * become `high`.
55
56
  */
56
57
  export declare function translateThinkingLevel(effort: string, levels: GeminiThinkingLevel[]): GeminiThinkingLevel;
57
58
  /**
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Optional process vitals for the `/health` probe.
3
+ *
4
+ * The API routes are registered inside encapsulated Fastify plugins, which
5
+ * snapshot the instance they inherit from at registration time — a decorator
6
+ * added to the root afterwards is invisible to them. Whoever owns the process
7
+ * (the server package, which builds its health heartbeat after the routes are
8
+ * up) therefore publishes the reporter here instead.
9
+ */
10
+ export type HealthReporter = () => unknown;
11
+ export declare function setHealthReporter(fn: HealthReporter | undefined): void;
12
+ /** Vitals for the current instant, or `undefined` when none are published. */
13
+ export declare function readHealthVitals(): unknown;