@caeliq/llms 1.0.59 → 1.0.60

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.
@@ -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;
@@ -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
@@ -84,7 +84,8 @@ export interface UnifiedTool {
84
84
  ttl?: "5m" | "1h";
85
85
  };
86
86
  }
87
- export type ThinkLevel = "none" | "low" | "medium" | "high" | "xhigh" | "max";
87
+ export declare const THINK_LEVELS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"];
88
+ export type ThinkLevel = (typeof THINK_LEVELS)[number];
88
89
  export interface UnifiedChatRequest {
89
90
  messages: UnifiedMessage[];
90
91
  model: 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;
@@ -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
  /**
@@ -11,11 +11,15 @@ export declare function mapCallId(map: ResponsesCallIdMap, id: unknown, directio
11
11
  * Client Responses wire → Unified (Chat Completions shape).
12
12
  * Supports the Responses MVP subset; rejects CCR-unsupported stateful fields.
13
13
  */
14
- export declare function responsesRequestToUnified(body: any, callIdMap?: ResponsesCallIdMap): UnifiedChatRequest;
14
+ export declare function responsesRequestToUnified(body: any, callIdMap?: ResponsesCallIdMap, customToolNames?: Set<string>): UnifiedChatRequest;
15
+ /** Synthetic argument key used to carry a `custom` tool's freeform text
16
+ * through the Unified/Chat Completions function-call shape. */
17
+ export declare const CUSTOM_TOOL_INPUT_KEY = "input";
15
18
  /** Unified Chat JSON → Responses API non-stream response. */
16
19
  export declare function unifiedResponseToResponses(chat: any, options?: {
17
20
  originalModel?: string;
18
21
  callIdMap?: ResponsesCallIdMap;
22
+ customToolNames?: Set<string>;
19
23
  }): any;
20
24
  export interface ResponsesStreamState {
21
25
  responseId: string;
@@ -31,6 +35,7 @@ export interface ResponsesStreamState {
31
35
  added: boolean;
32
36
  outputIndex: number;
33
37
  emittedArgumentsLength: number;
38
+ isCustom: boolean;
34
39
  }>;
35
40
  nextOutputIndex: number;
36
41
  finished: boolean;
@@ -39,10 +44,12 @@ export interface ResponsesStreamState {
39
44
  finishReasonSeen: boolean;
40
45
  usage?: any;
41
46
  callIdMap: ResponsesCallIdMap;
47
+ customToolNames: Set<string>;
42
48
  }
43
49
  export declare function createResponsesStreamState(options?: {
44
50
  model?: string;
45
51
  callIdMap?: ResponsesCallIdMap;
52
+ customToolNames?: Set<string>;
46
53
  }): ResponsesStreamState;
47
54
  /**
48
55
  * Convert one Unified Chat Completions chunk into zero or more Responses
@@ -0,0 +1,13 @@
1
+ import type { ThinkLevel, UnifiedChatRequest } from "../types/llm";
2
+ type UnifiedReasoning = UnifiedChatRequest["reasoning"];
3
+ /** Normalize effort tokens at the protocol boundary without rejecting extensions. */
4
+ export declare function normalizeReasoningEffort(value: unknown): ThinkLevel | undefined;
5
+ /** `none` and an explicit enabled:false are the canonical off signals. */
6
+ export declare function isReasoningDisabled(reasoning: UnifiedReasoning | undefined, thinking?: UnifiedChatRequest["thinking"]): boolean;
7
+ /** Build the canonical reasoning state used by every inbound protocol. */
8
+ export declare function canonicalReasoning(effortValue: unknown, enabledWhenEffortAbsent?: boolean): UnifiedReasoning | undefined;
9
+ /** Serialize Unified reasoning onto the Chat Completions wire shape in place. */
10
+ export declare function applyOpenAIChatReasoning(request: UnifiedChatRequest): UnifiedChatRequest;
11
+ /** Anthropic accepts low..max, while CCR/OpenAI may additionally emit minimal/ultra/none. */
12
+ export declare function toAnthropicReasoningEffort(effortValue: unknown): Exclude<ThinkLevel, "none" | "minimal" | "ultra"> | undefined;
13
+ export {};
@@ -24,6 +24,7 @@ export declare function sanitizeBodyForLog(value: string, maxBytes?: number): st
24
24
  export declare function sanitizeErrorForLog(error: unknown): {
25
25
  message: string;
26
26
  code?: string;
27
+ type?: string;
27
28
  name?: string;
28
29
  statusCode?: number;
29
30
  stack?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caeliq/llms",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "A universal LLM API transformation server",
5
5
  "main": "dist/cjs/server.cjs",
6
6
  "module": "dist/esm/server.mjs",
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@anthropic-ai/sdk": "^0.115.0",
33
- "@caeliq/ccr-shared": "^2.1.1",
33
+ "@caeliq/ccr-shared": "^2.1.2",
34
34
  "@cursor/sdk": "^1.0.26",
35
35
  "@fastify/cors": "^11.3.0",
36
36
  "@fastify/rate-limit": "^10.3.0",