@caeliq/llms 1.0.58 → 1.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +82 -686
- package/dist/api/routes.d.ts +2 -0
- package/dist/cjs/server.cjs +286 -236
- package/dist/cjs/server.cjs.map +4 -4
- package/dist/cursor-sdk/session.d.ts +2 -1
- package/dist/esm/server.mjs +286 -236
- package/dist/esm/server.mjs.map +4 -4
- package/dist/routing/inbound-pipeline.d.ts +31 -0
- package/dist/routing/protocol-adapter.d.ts +37 -0
- package/dist/routing/protocol-endpoints.d.ts +77 -0
- package/dist/routing/protocol-errors.d.ts +10 -0
- package/dist/server.d.ts +3 -1
- package/dist/services/provider.d.ts +1 -1
- package/dist/tests/anthropic.provider-wire.d.ts +1 -0
- package/dist/tests/claude-auth.identity.d.ts +1 -0
- package/dist/tests/client-abort-classification.test.d.ts +1 -0
- package/dist/tests/inbound-protocol-routes.d.ts +1 -0
- package/dist/tests/inbound-routing-pipeline.d.ts +1 -0
- package/dist/tests/openai.inbound-chat.d.ts +1 -0
- package/dist/tests/openai.inbound-responses.d.ts +1 -0
- package/dist/tests/protocol-endpoints.d.ts +1 -0
- package/dist/tests/redact.body-for-log.d.ts +1 -0
- package/dist/tests/responses.call-id-sanitize.d.ts +1 -0
- package/dist/tests/responses.parallel-and-failure.d.ts +1 -0
- package/dist/tests/router-scenario-precedence.d.ts +1 -0
- package/dist/tests/system-instructions-fold.d.ts +1 -0
- package/dist/tests/upstream-error-semantics.d.ts +1 -0
- package/dist/transformer/anthropic.transformer.d.ts +15 -2
- package/dist/transformer/claude-auth.transformer.d.ts +36 -4
- package/dist/transformer/openai.responses.transformer.d.ts +17 -1
- package/dist/transformer/openai.transformer.d.ts +26 -32
- package/dist/transformer/tooluse.transformer.d.ts +1 -1
- package/dist/transformer/vercel.transformer.d.ts +1 -1
- package/dist/transformer/vertex-claude.transformer.d.ts +1 -1
- package/dist/transformer/vertex-gemini.transformer.d.ts +1 -1
- package/dist/types/transformer.d.ts +9 -0
- package/dist/utils/claude-auth.d.ts +9 -2
- package/dist/utils/claude-billing.d.ts +58 -0
- package/dist/utils/claude-model-catalog.d.ts +49 -0
- package/dist/utils/headers.d.ts +10 -0
- package/dist/utils/mistral.util.d.ts +1 -1
- package/dist/utils/openai.responses.util.d.ts +53 -0
- package/dist/utils/redact.d.ts +18 -0
- package/dist/utils/request.d.ts +1 -1
- package/dist/utils/retry.d.ts +7 -0
- package/dist/utils/router.d.ts +7 -0
- package/dist/utils/stream.d.ts +2 -0
- package/dist/utils/toolCallId.d.ts +8 -0
- package/package.json +25 -21
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { UnifiedChatRequest } from "../types/llm";
|
|
2
|
+
export interface ResponsesCallIdMap {
|
|
3
|
+
/** Original client call_id → sanitized id (and reverse). */
|
|
4
|
+
forward: Map<string, string>;
|
|
5
|
+
reverse: Map<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createCallIdMap(): ResponsesCallIdMap;
|
|
8
|
+
/** Sanitize and remember a stable per-turn mapping for function call correlation. */
|
|
9
|
+
export declare function mapCallId(map: ResponsesCallIdMap, id: unknown, direction?: "client_to_unified" | "unified_to_client"): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Client Responses wire → Unified (Chat Completions shape).
|
|
12
|
+
* Supports the Responses MVP subset; rejects CCR-unsupported stateful fields.
|
|
13
|
+
*/
|
|
14
|
+
export declare function responsesRequestToUnified(body: any, callIdMap?: ResponsesCallIdMap): UnifiedChatRequest;
|
|
15
|
+
/** Unified Chat JSON → Responses API non-stream response. */
|
|
16
|
+
export declare function unifiedResponseToResponses(chat: any, options?: {
|
|
17
|
+
originalModel?: string;
|
|
18
|
+
callIdMap?: ResponsesCallIdMap;
|
|
19
|
+
}): any;
|
|
20
|
+
export interface ResponsesStreamState {
|
|
21
|
+
responseId: string;
|
|
22
|
+
model?: string;
|
|
23
|
+
textItemId: string;
|
|
24
|
+
textStarted: boolean;
|
|
25
|
+
textOutputIndex?: number;
|
|
26
|
+
textContent: string;
|
|
27
|
+
toolCalls: Map<number, {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
arguments: string;
|
|
31
|
+
added: boolean;
|
|
32
|
+
outputIndex: number;
|
|
33
|
+
emittedArgumentsLength: number;
|
|
34
|
+
}>;
|
|
35
|
+
nextOutputIndex: number;
|
|
36
|
+
finished: boolean;
|
|
37
|
+
created: boolean;
|
|
38
|
+
sequenceNumber: number;
|
|
39
|
+
finishReasonSeen: boolean;
|
|
40
|
+
usage?: any;
|
|
41
|
+
callIdMap: ResponsesCallIdMap;
|
|
42
|
+
}
|
|
43
|
+
export declare function createResponsesStreamState(options?: {
|
|
44
|
+
model?: string;
|
|
45
|
+
callIdMap?: ResponsesCallIdMap;
|
|
46
|
+
}): ResponsesStreamState;
|
|
47
|
+
/**
|
|
48
|
+
* Convert one Unified Chat Completions chunk into zero or more Responses
|
|
49
|
+
* stream events, including the mandatory content_part lifecycle for Codex.
|
|
50
|
+
*/
|
|
51
|
+
export declare function unifiedChunkToResponsesEvents(chunk: any, state: ResponsesStreamState): any[];
|
|
52
|
+
export declare function finalizeResponsesStream(state: ResponsesStreamState, usage?: any): any[];
|
|
53
|
+
export declare function responsesFailedEvent(message: string, state?: ResponsesStreamState): any;
|
package/dist/utils/redact.d.ts
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
* Keep enough diagnostic signal (status, error type) without leaking secrets.
|
|
4
4
|
*/
|
|
5
5
|
export declare function sanitizeUpstreamErrorText(value: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Deep-sanitize a parsed upstream error body before it is logged or
|
|
8
|
+
* serialized to a client: secret-bearing keys are redacted outright and
|
|
9
|
+
* every string value passes through sanitizeUpstreamErrorText. Depth and
|
|
10
|
+
* array length are bounded so an adversarial body cannot balloon.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sanitizeUpstreamErrorBody(value: unknown, depth?: number): unknown;
|
|
13
|
+
/** Default cap for a single logged request body. */
|
|
14
|
+
export declare const DEFAULT_LOG_BODY_MAX_BYTES = 32768;
|
|
15
|
+
/**
|
|
16
|
+
* Redact secrets from a request body that is about to be logged verbatim.
|
|
17
|
+
*
|
|
18
|
+
* Unlike sanitizeUpstreamErrorText this preserves whitespace, newlines and
|
|
19
|
+
* full string values: the point of body capture is to read prompts and
|
|
20
|
+
* message content back, so per-string truncation would defeat it. Only
|
|
21
|
+
* secret-bearing patterns are rewritten, then the whole payload is capped.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sanitizeBodyForLog(value: string, maxBytes?: number): string;
|
|
6
24
|
export declare function sanitizeErrorForLog(error: unknown): {
|
|
7
25
|
message: string;
|
|
8
26
|
code?: string;
|
package/dist/utils/request.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UnifiedChatRequest } from "../types/llm";
|
|
2
2
|
/** Loopback and NO_PROXY/no_proxy hosts should not go through HTTPS_PROXY. */
|
|
3
3
|
export declare function shouldBypassProxy(target: URL | string): boolean;
|
|
4
|
-
export declare function sendUnifiedRequest(url: URL | string, request: UnifiedChatRequest, config: any,
|
|
4
|
+
export declare function sendUnifiedRequest(url: URL | string, request: UnifiedChatRequest, config: any, _context: any, _logger?: any): Promise<Response>;
|
package/dist/utils/retry.d.ts
CHANGED
|
@@ -24,4 +24,11 @@ export declare function toClientAbortError(reason?: unknown): Error;
|
|
|
24
24
|
export declare function isClientAbortError(error: unknown): boolean;
|
|
25
25
|
export declare function isResponseSocketGone(reply: FastifyReply): boolean;
|
|
26
26
|
export declare function isProviderNetworkError(error: unknown): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* HTTP statuses worth trying another model for: transient throttling,
|
|
29
|
+
* contention, and server-side failures. Ordinary 4xx responses (validation,
|
|
30
|
+
* authentication, permissions, model-not-found) are terminal — resending the
|
|
31
|
+
* identical request to a fallback model would fail the same way.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isFallbackEligibleStatus(status: number | undefined): boolean;
|
|
27
34
|
export declare function isFallbackEligibleError(error: unknown): boolean;
|
package/dist/utils/router.d.ts
CHANGED
|
@@ -13,8 +13,10 @@ interface MessageParam {
|
|
|
13
13
|
role: string;
|
|
14
14
|
content: string | ContentBlockParam[];
|
|
15
15
|
}
|
|
16
|
+
export declare const CLAUDE_CODE_BILLING_SYSTEM_HEADER_PREFIX = "x-anthropic-billing-header";
|
|
16
17
|
/** Normalize `provider/model` or `provider,model` into our `provider,model` form. */
|
|
17
18
|
export declare function normalizeModelSelector(value: string | undefined | null): string | undefined;
|
|
19
|
+
export declare function claudeCodeBillingMetadataIsSubagent(text: string): boolean;
|
|
18
20
|
/**
|
|
19
21
|
* Strip Claude Code's billing helper system block.
|
|
20
22
|
* Returns true when that block marks the request as a subagent.
|
|
@@ -22,6 +24,11 @@ export declare function normalizeModelSelector(value: string | undefined | null)
|
|
|
22
24
|
export declare function removeClaudeCodeBillingSystemHeader(body: any): boolean;
|
|
23
25
|
/** Prefer system tag, then early user-message tag; strip whichever matched. */
|
|
24
26
|
export declare function extractAndRemoveClaudeCodeSubagentModelTag(body: any): string | undefined;
|
|
27
|
+
/** Read Claude Code's billing/subagent marker without mutating the source body. */
|
|
28
|
+
export declare function inspectClaudeCodeBillingSystemHeader(body: any): {
|
|
29
|
+
present: boolean;
|
|
30
|
+
isSubagent: boolean;
|
|
31
|
+
};
|
|
25
32
|
export declare const calculateTokenCount: (messages: MessageParam[], system: any, tools: Tool[]) => number;
|
|
26
33
|
export interface RouterContext {
|
|
27
34
|
configService: ConfigService;
|
package/dist/utils/stream.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface StreamContext {
|
|
|
5
5
|
export declare function createSSEStreamReader(response: Response, processLine: (line: string, context: StreamContext) => void, options?: {
|
|
6
6
|
bufferSize?: number;
|
|
7
7
|
onComplete?: (context: StreamContext) => void;
|
|
8
|
+
/** Return true when the protocol adapter emitted its own terminal error. */
|
|
9
|
+
onError?: (error: unknown, context: StreamContext) => boolean | void;
|
|
8
10
|
logger?: any;
|
|
9
11
|
}): Response;
|
|
10
12
|
export declare function encodeSSEData(data: string, encoder: TextEncoder): Uint8Array;
|
|
@@ -13,3 +13,11 @@ export declare function isValidAnthropicToolCallId(id: unknown): id is string;
|
|
|
13
13
|
* `tool_use` / `tool_result` pair stops matching.
|
|
14
14
|
*/
|
|
15
15
|
export declare function sanitizeToolCallId(id: unknown): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Bound a Responses API call id without losing tool-call/result pairing.
|
|
18
|
+
*
|
|
19
|
+
* Invalid or overlong ids use a readable prefix plus a deterministic hash of
|
|
20
|
+
* the original value. Hashing avoids collisions from either normalization or
|
|
21
|
+
* plain truncation, while the conforming fast path makes this idempotent.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sanitizeResponsesCallId(id: unknown): string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caeliq/llms",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.59",
|
|
4
4
|
"description": "A universal LLM API transformation server",
|
|
5
5
|
"main": "dist/cjs/server.cjs",
|
|
6
6
|
"module": "dist/esm/server.mjs",
|
|
@@ -29,30 +29,34 @@
|
|
|
29
29
|
"LICENSE"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@anthropic-ai/sdk": "^0.
|
|
33
|
-
"@caeliq/ccr-shared": "^2.1.
|
|
34
|
-
"@cursor/sdk": "^1.0.
|
|
35
|
-
"@fastify/cors": "^11.0
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"fastify
|
|
41
|
-
"
|
|
32
|
+
"@anthropic-ai/sdk": "^0.115.0",
|
|
33
|
+
"@caeliq/ccr-shared": "^2.1.1",
|
|
34
|
+
"@cursor/sdk": "^1.0.26",
|
|
35
|
+
"@fastify/cors": "^11.3.0",
|
|
36
|
+
"@fastify/rate-limit": "^10.3.0",
|
|
37
|
+
"@google/genai": "^2.15.0",
|
|
38
|
+
"@huggingface/tokenizers": "^0.1.3",
|
|
39
|
+
"dotenv": "^17.4.2",
|
|
40
|
+
"fastify": "^5.11.2",
|
|
41
|
+
"fastify-plugin": "^6.0.0",
|
|
42
|
+
"google-auth-library": "^11.0.0",
|
|
42
43
|
"json5": "^2.2.3",
|
|
43
|
-
"jsonrepair": "^3.
|
|
44
|
+
"jsonrepair": "^3.15.0",
|
|
44
45
|
"latex-to-unicode": "^0.1.0",
|
|
45
|
-
"lru-cache": "^11.
|
|
46
|
-
"openai": "^
|
|
47
|
-
"tiktoken": "^1.0.
|
|
48
|
-
"undici": "^
|
|
49
|
-
"uuid": "^
|
|
46
|
+
"lru-cache": "^11.5.2",
|
|
47
|
+
"openai": "^7.2.0",
|
|
48
|
+
"tiktoken": "^1.0.22",
|
|
49
|
+
"undici": "^8.9.0",
|
|
50
|
+
"uuid": "^14.0.1"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"esbuild": "^0.
|
|
54
|
-
"tsx": "^4.
|
|
55
|
-
"typescript": "^
|
|
53
|
+
"@types/node": "^26.1.2",
|
|
54
|
+
"esbuild": "^0.28.1",
|
|
55
|
+
"tsx": "^4.23.1",
|
|
56
|
+
"typescript": "^6.0.3"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=22.19.0"
|
|
56
60
|
},
|
|
57
61
|
"repository": {
|
|
58
62
|
"type": "git",
|