@caeliq/llms 1.0.55 → 1.0.57

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 (128) hide show
  1. package/README.md +102 -12
  2. package/dist/api/middleware.d.ts +9 -0
  3. package/dist/api/routes.d.ts +15 -0
  4. package/dist/cjs/server.cjs +238 -230
  5. package/dist/cjs/server.cjs.map +4 -4
  6. package/dist/cursor-sdk/events-to-sse.d.ts +113 -0
  7. package/dist/cursor-sdk/hooks-template.d.ts +1 -0
  8. package/dist/cursor-sdk/prompt.d.ts +29 -0
  9. package/dist/cursor-sdk/runner.d.ts +11 -0
  10. package/dist/cursor-sdk/send.d.ts +9 -0
  11. package/dist/cursor-sdk/session.d.ts +146 -0
  12. package/dist/cursor-sdk/shared.d.ts +14 -0
  13. package/dist/cursor-sdk/tools.d.ts +4 -0
  14. package/dist/cursor-sdk/usage.d.ts +28 -0
  15. package/dist/esm/server.mjs +233 -225
  16. package/dist/esm/server.mjs.map +4 -4
  17. package/dist/index.d.ts +2 -0
  18. package/dist/plugins/index.d.ts +4 -0
  19. package/dist/plugins/output/console-handler.d.ts +23 -0
  20. package/dist/plugins/output/index.d.ts +29 -0
  21. package/dist/plugins/output/output-manager.d.ts +110 -0
  22. package/dist/plugins/output/temp-file-handler.d.ts +53 -0
  23. package/dist/plugins/output/types.d.ts +157 -0
  24. package/dist/plugins/output/webhook-handler.d.ts +37 -0
  25. package/dist/plugins/plugin-manager.d.ts +62 -0
  26. package/dist/plugins/token-speed.d.ts +22 -0
  27. package/dist/plugins/types.d.ts +25 -0
  28. package/dist/server.d.ts +60 -0
  29. package/dist/services/config.d.ts +32 -0
  30. package/dist/services/provider.d.ts +34 -0
  31. package/dist/services/tokenizer.d.ts +44 -0
  32. package/dist/services/transformer.d.ts +28 -0
  33. package/dist/tests/anthropic.stream-boundaries.d.ts +1 -0
  34. package/dist/tests/anthropic.stream-cancel.d.ts +1 -0
  35. package/dist/tests/antigravity.claude-tool-schema.d.ts +1 -0
  36. package/dist/tests/antigravity.endpoint-fallback.d.ts +1 -0
  37. package/dist/tests/cache-control.strip.d.ts +1 -0
  38. package/dist/tests/cache-paths.integration.d.ts +1 -0
  39. package/dist/tests/claude-auth.beta-headers.d.ts +1 -0
  40. package/dist/tests/codex-auth.reliability.d.ts +1 -0
  41. package/dist/tests/cursor-sdk.cancel.d.ts +1 -0
  42. package/dist/tests/cursor-sdk.on-delta-thinking.d.ts +1 -0
  43. package/dist/tests/cursor-sdk.progress-only.d.ts +1 -0
  44. package/dist/tests/cursor-sdk.runner-recovery.d.ts +1 -0
  45. package/dist/tests/cursor-sdk.send.d.ts +1 -0
  46. package/dist/tests/cursor-sdk.stream-error.d.ts +1 -0
  47. package/dist/tests/cursor-sdk.thinking-signature.d.ts +1 -0
  48. package/dist/tests/cursor-sdk.usage.d.ts +1 -0
  49. package/dist/tests/deepseek.reasoning.d.ts +1 -0
  50. package/dist/tests/gemini.abnormal-finish.d.ts +1 -0
  51. package/dist/tests/gemini.dual-dialect-request.d.ts +1 -0
  52. package/dist/tests/gemini.function-call-signatures.d.ts +1 -0
  53. package/dist/tests/gemini.parity.d.ts +1 -0
  54. package/dist/tests/gemini.thinking-effort.d.ts +1 -0
  55. package/dist/tests/gemini.thought-signature-roundtrip.d.ts +1 -0
  56. package/dist/tests/opencode-headers.no-provider-retry.d.ts +1 -0
  57. package/dist/tests/thinking-sequencer.dual-dialect.d.ts +1 -0
  58. package/dist/tests/transformer-service.endpoints.d.ts +1 -0
  59. package/dist/tests/upstream-ports.smoke.d.ts +1 -0
  60. package/dist/tokenizer/api-tokenizer.d.ts +45 -0
  61. package/dist/tokenizer/huggingface-tokenizer.d.ts +52 -0
  62. package/dist/tokenizer/tiktoken-tokenizer.d.ts +20 -0
  63. package/dist/transformer/anthropic.transformer.d.ts +22 -0
  64. package/dist/transformer/antigravity-auth.transformer.d.ts +15 -0
  65. package/dist/transformer/cerebras.transformer.d.ts +16 -0
  66. package/dist/transformer/chrome-on-device.transformer.d.ts +7 -0
  67. package/dist/transformer/claude-auth.transformer.d.ts +25 -0
  68. package/dist/transformer/cleancache.transformer.d.ts +6 -0
  69. package/dist/transformer/codex.transformer.d.ts +61 -0
  70. package/dist/transformer/cursor-sdk.transformer.d.ts +23 -0
  71. package/dist/transformer/customparams.transformer.d.ts +30 -0
  72. package/dist/transformer/deepseek.transformer.d.ts +7 -0
  73. package/dist/transformer/enhancetool.transformer.d.ts +6 -0
  74. package/dist/transformer/extrathinktag.transformer.d.ts +10 -0
  75. package/dist/transformer/forcereasoning.transformer.d.ts +8 -0
  76. package/dist/transformer/gemini.transformer.d.ts +15 -0
  77. package/dist/transformer/groq.transformer.d.ts +7 -0
  78. package/dist/transformer/index.d.ts +65 -0
  79. package/dist/transformer/maxcompletiontokens.transformer.d.ts +6 -0
  80. package/dist/transformer/maxtoken.transformer.d.ts +9 -0
  81. package/dist/transformer/mistral.transformer.d.ts +25 -0
  82. package/dist/transformer/openai.responses.transformer.d.ts +13 -0
  83. package/dist/transformer/openai.transformer.d.ts +52 -0
  84. package/dist/transformer/opencode-headers.transformer.d.ts +30 -0
  85. package/dist/transformer/openrouter.transformer.d.ts +10 -0
  86. package/dist/transformer/qwen-auth.transformer.d.ts +9 -0
  87. package/dist/transformer/reasoning.transformer.d.ts +10 -0
  88. package/dist/transformer/sampling.transformer.d.ts +13 -0
  89. package/dist/transformer/streamoptions.transformer.d.ts +6 -0
  90. package/dist/transformer/tooluse.transformer.d.ts +7 -0
  91. package/dist/transformer/vercel.transformer.d.ts +11 -0
  92. package/dist/transformer/vertex-claude.transformer.d.ts +9 -0
  93. package/dist/transformer/vertex-gemini.transformer.d.ts +12 -0
  94. package/dist/transformer/vertex-openai.transformer.d.ts +19 -0
  95. package/dist/types/llm.d.ts +255 -0
  96. package/dist/types/transformer.d.ts +23 -0
  97. package/dist/utils/antigravity-auth.d.ts +75 -0
  98. package/dist/utils/auth-recovery.d.ts +2 -0
  99. package/dist/utils/cache.d.ts +14 -0
  100. package/dist/utils/cacheControl.d.ts +44 -0
  101. package/dist/utils/claude-auth.d.ts +22 -0
  102. package/dist/utils/codex-auth.d.ts +33 -0
  103. package/dist/utils/converter.d.ts +11 -0
  104. package/dist/utils/cursor-auth.d.ts +3 -0
  105. package/dist/utils/deepseek.util.d.ts +28 -0
  106. package/dist/utils/gemini-cache.d.ts +8 -0
  107. package/dist/utils/gemini-thinking.d.ts +66 -0
  108. package/dist/utils/gemini.util.d.ts +43 -0
  109. package/dist/utils/google.util.d.ts +160 -0
  110. package/dist/utils/image.d.ts +1 -0
  111. package/dist/utils/mistral.util.d.ts +14 -0
  112. package/dist/utils/openai.util.d.ts +17 -0
  113. package/dist/utils/qwen-auth.d.ts +13 -0
  114. package/dist/utils/redact.d.ts +30 -0
  115. package/dist/utils/request.d.ts +4 -0
  116. package/dist/utils/retry.d.ts +27 -0
  117. package/dist/utils/router.d.ts +42 -0
  118. package/dist/utils/schema.d.ts +46 -0
  119. package/dist/utils/sse/SSEParser.transform.d.ts +6 -0
  120. package/dist/utils/sse/SSESerializer.transform.d.ts +3 -0
  121. package/dist/utils/sse/index.d.ts +3 -0
  122. package/dist/utils/sse/rewriteStream.d.ts +9 -0
  123. package/dist/utils/stream.d.ts +11 -0
  124. package/dist/utils/thinking.d.ts +33 -0
  125. package/dist/utils/thought-signature-cache.d.ts +34 -0
  126. package/dist/utils/toolArgumentsParser.d.ts +8 -0
  127. package/dist/utils/vertex-claude.util.d.ts +47 -0
  128. package/package.json +3 -3
@@ -0,0 +1,9 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer, TransformerOptions } from "../types/transformer";
3
+ export declare class MaxTokenTransformer implements Transformer {
4
+ private readonly options?;
5
+ static TransformerName: string;
6
+ max_tokens: number;
7
+ constructor(options?: TransformerOptions | undefined);
8
+ transformRequestIn(request: UnifiedChatRequest): Promise<UnifiedChatRequest>;
9
+ }
@@ -0,0 +1,25 @@
1
+ import { LLMProvider, UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer, TransformerContext } from "../types/transformer";
3
+ import { transformRequestOut } from "../utils/mistral.util";
4
+ /**
5
+ * Mistral Transformer for Claude Code Router
6
+ *
7
+ * Transforms Anthropic-style requests to Mistral's OpenAI-compatible API format.
8
+ */
9
+ export declare class MistralTransformer implements Transformer {
10
+ name: string;
11
+ logger?: any;
12
+ /**
13
+ * Transform incoming request to Mistral-compatible format
14
+ */
15
+ transformRequestIn(request: UnifiedChatRequest, provider: LLMProvider, context: TransformerContext): Promise<Record<string, any>>;
16
+ /**
17
+ * Transform Mistral-specific request back to UnifiedChatRequest
18
+ */
19
+ transformRequestOut: typeof transformRequestOut;
20
+ /**
21
+ * Transform response back — convert Mistral's content-array thinking format
22
+ * to the delta.thinking / delta.content shape expected by @caeliq/llms.
23
+ */
24
+ transformResponseOut(response: Response, _context: TransformerContext): Promise<Response>;
25
+ }
@@ -0,0 +1,13 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer } from "../types/transformer";
3
+ export declare class OpenAIResponsesTransformer implements Transformer {
4
+ logger?: any;
5
+ name: string;
6
+ endPoint: string;
7
+ transformRequestIn(request: UnifiedChatRequest, provider?: any, context?: any): Promise<UnifiedChatRequest>;
8
+ transformResponseOut(response: Response): Promise<Response>;
9
+ private convertStreamEvent;
10
+ private normalizeRequestContent;
11
+ private convertResponseToChat;
12
+ private buildImageContent;
13
+ }
@@ -0,0 +1,52 @@
1
+ import { Transformer } from "../types/transformer";
2
+ import { UnifiedChatRequest } from "../types/llm";
3
+ /**
4
+ * Server-side route handler for the OpenAI Chat Completions API.
5
+ *
6
+ * ## How endPoint works
7
+ *
8
+ * At startup, `registerApiRoutes` (see `api/routes.ts`) scans all registered
9
+ * transformers for ones that define `endPoint`. For each, it registers a
10
+ * `POST` route at that path. When a request hits the route,
11
+ * `handleTransformerEndpoint` is invoked with the matching transformer as
12
+ * the "endpoint transformer" — the one responsible for converting between
13
+ * the external wire format and the internal Unified format.
14
+ *
15
+ * ## Request handling
16
+ *
17
+ * The Unified format IS the OpenAI Chat Completions format. The conversion
18
+ * from Anthropic → Unified already happened in
19
+ * `AnthropicTransformer.transformRequestOut()` (which runs first in the
20
+ * pipeline). So by the time the provider chain executes, the body is already
21
+ * in the right shape — no further conversion is needed.
22
+ *
23
+ * `transformRequestIn` also translates Claude Code cache intent to the
24
+ * selected provider's native Chat Completions behavior. The provider identity
25
+ * is checked before adding request-level fields so OpenAI-compatible services
26
+ * do not receive OpenAI-only parameters.
27
+ *
28
+ * ## Relationship to OpenAIResponsesTransformer
29
+ *
30
+ * `OpenAIResponsesTransformer` (in `openai.responses.transformer.ts`) is the
31
+ * counterpart for the Responses API (`/v1/responses`). Unlike this
32
+ * transformer, it defines `transformRequestIn` / `transformResponseOut`
33
+ * because the Responses API uses a different wire format (e.g. `messages`
34
+ * → `input`, function tools → flat tool definitions). It also uses the
35
+ * shared utilities in `openai.util.ts` (`validateOpenAIToolCalls`,
36
+ * `injectPromptCaching`) to sanitize the Unified body before converting it.
37
+ *
38
+ * ## Full request pipeline (for context)
39
+ *
40
+ * Client → POST /v1/messages
41
+ * → AnthropicTransformer.transformRequestOut() // Anthropic → Unified (OpenAI)
42
+ * → provider.transformer.use[].transformRequestIn() // provider middleware
43
+ * → sendRequestToProvider() // HTTP call upstream
44
+ * → provider.transformer.use[].transformResponseOut() // provider middleware (reversed)
45
+ * → AnthropicTransformer.transformResponseIn() // Unified (OpenAI) → Anthropic
46
+ * → Client
47
+ */
48
+ export declare class OpenAITransformer implements Transformer {
49
+ name: string;
50
+ endPoint: string;
51
+ transformRequestIn(request: UnifiedChatRequest, provider: any, context: any): Promise<UnifiedChatRequest>;
52
+ }
@@ -0,0 +1,30 @@
1
+ import { Transformer } from "../types/transformer";
2
+ export declare class OpencodeHeadersTransformer implements Transformer {
3
+ name: string;
4
+ private sessionCache;
5
+ private readonly MAX_SESSIONS;
6
+ private lastTimestamp;
7
+ private counter;
8
+ transformRequestIn(request: any, provider: any, context: any): Promise<Record<string, any>>;
9
+ /**
10
+ * Own the full upstream call so a `No provider available` 401 can be retried
11
+ * with a fresh session in isolation. Any other non-ok response is re-thrown in
12
+ * the exact shape sendRequestToProvider would have produced, so genuine
13
+ * auth/rate/server errors keep flowing through the normal error + fallback
14
+ * path unchanged.
15
+ */
16
+ private sendWithSessionRetry;
17
+ private buildHeaders;
18
+ /**
19
+ * True only for the two Zen session-hash routing failures — a re-roll can
20
+ * recover these. Kept deliberately narrow (exact status + message) so genuine
21
+ * auth errors (401 invalid key) and request errors (400 validation) are never
22
+ * mistaken for routing failures and pass straight through.
23
+ */
24
+ private isZenRoutingFailure;
25
+ private retryAfterHeaders;
26
+ private fingerprintConversation;
27
+ private getOrCreateSessionId;
28
+ private invalidateSession;
29
+ private generateId;
30
+ }
@@ -0,0 +1,10 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer, TransformerOptions } from "../types/transformer";
3
+ export declare class OpenrouterTransformer implements Transformer {
4
+ private readonly options?;
5
+ static TransformerName: string;
6
+ logger?: any;
7
+ constructor(options?: TransformerOptions | undefined);
8
+ transformRequestIn(request: UnifiedChatRequest, provider?: any, context?: any): Promise<UnifiedChatRequest>;
9
+ transformResponseOut(response: Response): Promise<Response>;
10
+ }
@@ -0,0 +1,9 @@
1
+ import { Transformer } from "../types/transformer";
2
+ export declare class QwenAuthTransformer implements Transformer {
3
+ name: string;
4
+ logger?: any;
5
+ private buildAuthConfig;
6
+ transformRequestIn(request: any, provider: any): Promise<Record<string, any>>;
7
+ auth(_request: any, provider: any): Promise<any>;
8
+ transformResponseOut(response: Response): Promise<Response>;
9
+ }
@@ -0,0 +1,10 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer, TransformerOptions } from "../types/transformer";
3
+ export declare class ReasoningTransformer implements Transformer {
4
+ private readonly options?;
5
+ static TransformerName: string;
6
+ enable: any;
7
+ constructor(options?: TransformerOptions | undefined);
8
+ transformRequestIn(request: UnifiedChatRequest, provider?: any, context?: any): Promise<UnifiedChatRequest>;
9
+ transformResponseOut(response: Response, context?: any): Promise<Response>;
10
+ }
@@ -0,0 +1,13 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer, TransformerOptions } from "../types/transformer";
3
+ export declare class SamplingTransformer implements Transformer {
4
+ private readonly options?;
5
+ static TransformerName: string;
6
+ max_tokens: number;
7
+ temperature: number;
8
+ top_p: number;
9
+ top_k: number;
10
+ repetition_penalty: number;
11
+ constructor(options?: TransformerOptions | undefined);
12
+ transformRequestIn(request: UnifiedChatRequest): Promise<UnifiedChatRequest>;
13
+ }
@@ -0,0 +1,6 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer } from "../types/transformer";
3
+ export declare class StreamOptionsTransformer implements Transformer {
4
+ name: string;
5
+ transformRequestIn(request: UnifiedChatRequest): Promise<UnifiedChatRequest>;
6
+ }
@@ -0,0 +1,7 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer } from "../types/transformer";
3
+ export declare class TooluseTransformer implements Transformer {
4
+ name: string;
5
+ transformRequestIn(request: UnifiedChatRequest, provider?: any, context?: any): Promise<any>;
6
+ transformResponseOut(response: Response): Promise<Response>;
7
+ }
@@ -0,0 +1,11 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer, TransformerOptions } from "../types/transformer";
3
+ export declare class VercelTransformer implements Transformer {
4
+ private readonly options?;
5
+ static TransformerName: string;
6
+ logger?: any;
7
+ endPoint: string;
8
+ constructor(options?: TransformerOptions | undefined);
9
+ transformRequestIn(request: UnifiedChatRequest, provider?: any, context?: any): Promise<UnifiedChatRequest>;
10
+ transformResponseOut(response: Response): Promise<Response>;
11
+ }
@@ -0,0 +1,9 @@
1
+ import { LLMProvider, UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer } from "../types/transformer";
3
+ export declare class VertexClaudeTransformer implements Transformer {
4
+ logger?: any;
5
+ name: string;
6
+ transformRequestIn(request: UnifiedChatRequest, provider: LLMProvider): Promise<Record<string, any>>;
7
+ transformRequestOut(request: Record<string, any>): Promise<UnifiedChatRequest>;
8
+ transformResponseOut(response: Response): Promise<Response>;
9
+ }
@@ -0,0 +1,12 @@
1
+ import { LLMProvider, UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer, TransformerContext, TransformerOptions } from "../types/transformer";
3
+ export declare class VertexGeminiTransformer implements Transformer {
4
+ static TransformerName: string;
5
+ logger?: any;
6
+ name: string;
7
+ private readonly thoughtSignatureFallback;
8
+ constructor(options?: TransformerOptions);
9
+ transformRequestIn(request: UnifiedChatRequest, provider: LLMProvider, context?: any): Promise<Record<string, any>>;
10
+ transformRequestOut(request: Record<string, any>): Promise<UnifiedChatRequest>;
11
+ transformResponseOut(response: Response, context?: TransformerContext): Promise<Response>;
12
+ }
@@ -0,0 +1,19 @@
1
+ import { UnifiedChatRequest } from "../types/llm";
2
+ import { Transformer, TransformerOptions } from "../types/transformer";
3
+ export interface VertexOpenaiOptions extends TransformerOptions {
4
+ client_email?: string;
5
+ private_key?: string;
6
+ }
7
+ /**
8
+ * Auth-only transformer for Vertex AI OpenAI-compatible endpoints.
9
+ * Injects a Google service-account Bearer token into outbound requests.
10
+ */
11
+ export declare class VertexOpenaiTransformer implements Transformer {
12
+ static TransformerName: string;
13
+ private client?;
14
+ private readonly client_email?;
15
+ private readonly private_key?;
16
+ constructor(options?: VertexOpenaiOptions);
17
+ private getClient;
18
+ transformRequestIn(request: UnifiedChatRequest): Promise<Record<string, any>>;
19
+ }
@@ -0,0 +1,255 @@
1
+ import type { ChatCompletionMessageParam as OpenAIMessage } from "openai/resources/chat/completions";
2
+ import type { MessageParam as AnthropicMessage } from "@anthropic-ai/sdk/resources/messages";
3
+ import type { ChatCompletionChunk } from "openai/resources/chat/completions";
4
+ import type { MessageStreamEvent } from "@anthropic-ai/sdk/resources/messages";
5
+ import type { ChatCompletionTool } from "openai/resources/chat/completions";
6
+ import type { Tool as AnthropicTool } from "@anthropic-ai/sdk/resources/messages";
7
+ import { Transformer } from "./transformer";
8
+ import type { ProviderTokenizerConfig } from "./tokenizer";
9
+ export type TransformerConfigEntry = string | [string, Record<string, any>?];
10
+ export interface UrlCitation {
11
+ url: string;
12
+ title: string;
13
+ content: string;
14
+ start_index: number;
15
+ end_index: number;
16
+ }
17
+ export interface Annotation {
18
+ type: "url_citation";
19
+ url_citation?: UrlCitation;
20
+ }
21
+ export interface TextContent {
22
+ type: "text";
23
+ text: string;
24
+ cache_control?: {
25
+ type?: string;
26
+ ttl?: "5m" | "1h";
27
+ };
28
+ }
29
+ export interface ImageContent {
30
+ type: "image_url";
31
+ image_url: {
32
+ url: string;
33
+ };
34
+ media_type: string;
35
+ cache_control?: {
36
+ type?: string;
37
+ ttl?: "5m" | "1h";
38
+ };
39
+ }
40
+ export type MessageContent = TextContent | ImageContent;
41
+ export interface UnifiedMessage {
42
+ role: "user" | "assistant" | "system" | "tool";
43
+ content: string | null | MessageContent[];
44
+ reasoning_content?: string;
45
+ tool_calls?: Array<{
46
+ id: string;
47
+ type: "function";
48
+ function: {
49
+ name: string;
50
+ arguments: string;
51
+ };
52
+ /** Gemini/Antigravity thought signature; must round-trip on functionCall parts. */
53
+ thought_signature?: string;
54
+ cache_control?: {
55
+ type?: string;
56
+ ttl?: "5m" | "1h";
57
+ };
58
+ }>;
59
+ tool_call_id?: string;
60
+ cache_control?: {
61
+ type?: string;
62
+ ttl?: "5m" | "1h";
63
+ };
64
+ thinking?: {
65
+ content: string;
66
+ signature?: string;
67
+ };
68
+ }
69
+ export interface UnifiedTool {
70
+ type: "function";
71
+ function: {
72
+ name: string;
73
+ description: string;
74
+ parameters: {
75
+ type: "object";
76
+ properties: Record<string, any>;
77
+ required?: string[];
78
+ additionalProperties?: boolean;
79
+ $schema?: string;
80
+ };
81
+ };
82
+ cache_control?: {
83
+ type?: string;
84
+ ttl?: "5m" | "1h";
85
+ };
86
+ }
87
+ export type ThinkLevel = "none" | "low" | "medium" | "high" | "xhigh" | "max";
88
+ export interface UnifiedChatRequest {
89
+ messages: UnifiedMessage[];
90
+ model: string;
91
+ system?: string | MessageContent[];
92
+ max_tokens?: number;
93
+ max_completion_tokens?: number;
94
+ temperature?: number;
95
+ top_p?: number;
96
+ top_k?: number;
97
+ repetition_penalty?: number;
98
+ stream?: boolean;
99
+ stream_options?: {
100
+ include_usage?: boolean;
101
+ [key: string]: any;
102
+ };
103
+ tools?: UnifiedTool[];
104
+ tool_choice?: "auto" | "none" | "required" | string | {
105
+ type: "function";
106
+ function: {
107
+ name: string;
108
+ };
109
+ };
110
+ reasoning?: {
111
+ effort?: ThinkLevel;
112
+ max_tokens?: number;
113
+ enabled?: boolean;
114
+ };
115
+ enable_thinking?: boolean;
116
+ thinking?: {
117
+ type: "enabled" | "disabled";
118
+ budget_tokens?: number;
119
+ };
120
+ parallel_tool_calls?: boolean;
121
+ cache_control?: {
122
+ type?: string;
123
+ ttl?: "5m" | "1h";
124
+ };
125
+ anthropic_thinking?: Record<string, any>;
126
+ anthropic_output_config?: Record<string, any>;
127
+ anthropic_metadata?: Record<string, any>;
128
+ anthropic_stop_sequences?: string[];
129
+ reasoning_effort?: string;
130
+ }
131
+ export interface UnifiedChatResponse {
132
+ id: string;
133
+ model: string;
134
+ content: string | null;
135
+ usage?: {
136
+ prompt_tokens: number;
137
+ completion_tokens: number;
138
+ total_tokens: number;
139
+ };
140
+ tool_calls?: Array<{
141
+ id: string;
142
+ type: "function";
143
+ function: {
144
+ name: string;
145
+ arguments: string;
146
+ };
147
+ }>;
148
+ annotations?: Annotation[];
149
+ }
150
+ export interface StreamChunk {
151
+ id: string;
152
+ object: string;
153
+ created: number;
154
+ model: string;
155
+ choices?: Array<{
156
+ index: number;
157
+ delta: {
158
+ role?: string;
159
+ content?: string;
160
+ thinking?: {
161
+ content?: string;
162
+ signature?: string;
163
+ };
164
+ tool_calls?: Array<{
165
+ id?: string;
166
+ type?: "function";
167
+ function?: {
168
+ name?: string;
169
+ arguments?: string;
170
+ };
171
+ thought_signature?: string;
172
+ }>;
173
+ annotations?: Annotation[];
174
+ };
175
+ finish_reason?: string | null;
176
+ }>;
177
+ }
178
+ export type AnthropicStreamEvent = MessageStreamEvent;
179
+ export type OpenAIStreamChunk = ChatCompletionChunk;
180
+ export interface OpenAIChatRequest {
181
+ messages: OpenAIMessage[];
182
+ model: string;
183
+ max_tokens?: number;
184
+ temperature?: number;
185
+ stream?: boolean;
186
+ tools?: ChatCompletionTool[];
187
+ tool_choice?: "auto" | "none" | {
188
+ type: "function";
189
+ function: {
190
+ name: string;
191
+ };
192
+ };
193
+ }
194
+ export interface AnthropicChatRequest {
195
+ messages: AnthropicMessage[];
196
+ model: string;
197
+ max_tokens: number;
198
+ temperature?: number;
199
+ stream?: boolean;
200
+ system?: string;
201
+ tools?: AnthropicTool[];
202
+ tool_choice?: {
203
+ type: "auto";
204
+ } | {
205
+ type: "tool";
206
+ name: string;
207
+ };
208
+ }
209
+ export interface ConversionOptions {
210
+ targetProvider: "openai" | "anthropic";
211
+ sourceProvider: "openai" | "anthropic";
212
+ }
213
+ export interface LLMProvider {
214
+ name: string;
215
+ baseUrl: string;
216
+ apiKey: string;
217
+ models: string[];
218
+ /** Optional GCP / Antigravity project id (provider-specific). */
219
+ project_id?: string;
220
+ transformer?: {
221
+ [key: string]: {
222
+ use?: Transformer[];
223
+ } | any;
224
+ } & {
225
+ use?: Transformer[];
226
+ passthrough?: any;
227
+ };
228
+ }
229
+ export type RegisterProviderRequest = LLMProvider;
230
+ export interface ModelRoute {
231
+ provider: string;
232
+ model: string;
233
+ fullModel: string;
234
+ }
235
+ export interface RequestRouteInfo {
236
+ provider: LLMProvider;
237
+ originalModel: string;
238
+ targetModel: string;
239
+ }
240
+ export interface ConfigProvider {
241
+ name: string;
242
+ api_base_url: string;
243
+ api_key: string;
244
+ models: string[];
245
+ /** Optional GCP / Antigravity project id (kept as `$ENV` placeholders in config). */
246
+ project_id?: string;
247
+ transformer: {
248
+ use?: TransformerConfigEntry[];
249
+ } & {
250
+ [key: string]: {
251
+ use?: TransformerConfigEntry[];
252
+ } | any;
253
+ };
254
+ tokenizer?: ProviderTokenizerConfig;
255
+ }
@@ -0,0 +1,23 @@
1
+ import { LLMProvider, UnifiedChatRequest } from "./llm";
2
+ export interface TransformerOptions {
3
+ [key: string]: any;
4
+ }
5
+ interface TransformerWithStaticName {
6
+ new (options?: TransformerOptions): Transformer;
7
+ TransformerName?: string;
8
+ }
9
+ export type TransformerConstructor = TransformerWithStaticName;
10
+ export interface TransformerContext {
11
+ [key: string]: any;
12
+ }
13
+ export type Transformer = {
14
+ transformRequestIn?: (request: UnifiedChatRequest, provider: LLMProvider, context: TransformerContext) => Promise<Record<string, any>>;
15
+ transformResponseIn?: (response: Response, context?: TransformerContext) => Promise<Response>;
16
+ transformRequestOut?: (request: any, context: TransformerContext) => Promise<UnifiedChatRequest>;
17
+ transformResponseOut?: (response: Response, context: TransformerContext) => Promise<Response>;
18
+ endPoint?: string;
19
+ name?: string;
20
+ auth?: (request: any, provider: LLMProvider, context: TransformerContext) => Promise<any>;
21
+ logger?: any;
22
+ };
23
+ export {};
@@ -0,0 +1,75 @@
1
+ export declare const ANTIGRAVITY_CLIENT_ID = "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
2
+ export declare const ANTIGRAVITY_CLIENT_SECRET = "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";
3
+ export declare const ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
4
+ export declare const ANTIGRAVITY_SCOPES: readonly ["https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/cclog", "https://www.googleapis.com/auth/experimentsandconfigs"];
5
+ export declare const ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.sandbox.googleapis.com";
6
+ export declare const ANTIGRAVITY_ENDPOINT_AUTOPUSH = "https://autopush-cloudcode-pa.sandbox.googleapis.com";
7
+ export declare const ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
8
+ /** generateContent fallback order */
9
+ export declare const ANTIGRAVITY_ENDPOINT_FALLBACKS: readonly ["https://daily-cloudcode-pa.sandbox.googleapis.com", "https://autopush-cloudcode-pa.sandbox.googleapis.com", "https://cloudcode-pa.googleapis.com"];
10
+ /** loadCodeAssist / fetchAvailableModels prefer prod first */
11
+ export declare const ANTIGRAVITY_LOAD_ENDPOINTS: readonly ["https://cloudcode-pa.googleapis.com", "https://daily-cloudcode-pa.sandbox.googleapis.com", "https://autopush-cloudcode-pa.sandbox.googleapis.com"];
12
+ export declare const ANTIGRAVITY_VERSION = "1.18.3";
13
+ export interface AntigravityTokens {
14
+ access_token: string;
15
+ refresh_token: string;
16
+ expires_at: number;
17
+ email?: string;
18
+ project_id?: string;
19
+ }
20
+ export declare function getAuthFilePath(): string;
21
+ export declare function getAntigravityHeaders(): Record<string, string>;
22
+ export declare function loadTokens(): AntigravityTokens | null;
23
+ export declare function saveTokens(tokens: AntigravityTokens): void;
24
+ /**
25
+ * Load a valid access token, refreshing with single-flight dedupe when near expiry.
26
+ */
27
+ export declare function getValidAccessToken(options?: {
28
+ force?: boolean;
29
+ }): Promise<AntigravityTokens>;
30
+ /**
31
+ * Resolve GCP project id: provider config → auth file → loadCodeAssist/onboardUser.
32
+ * Optional — many Antigravity accounts work with OAuth alone; missing project is fine.
33
+ */
34
+ export declare function resolveProjectId(provider: {
35
+ project_id?: string;
36
+ } | undefined, accessToken: string): Promise<string | undefined>;
37
+ export declare function getPreferredEndpoint(): string;
38
+ export declare function rememberEndpoint(endpoint: string): void;
39
+ export declare function clearPreferredEndpoint(): void;
40
+ /** A 403 SERVICE_DISABLED means the host's API is not enabled for the project. */
41
+ export declare function isEndpointDisabledError(body: string): boolean;
42
+ export declare function markEndpointUnusable(endpoint: string): void;
43
+ export declare function isEndpointUnusable(endpoint: string): boolean;
44
+ export declare function clearUnusableEndpoints(): void;
45
+ /**
46
+ * Whether a failing response should move on to the next endpoint rather than be
47
+ * reported to the client.
48
+ *
49
+ * 404 and 5xx are the classic "wrong or unhealthy host" signals. 403 belongs
50
+ * here too: the sandbox hosts answer with PERMISSION_DENIED / SERVICE_DISABLED
51
+ * when the account's project is not entitled to that deployment, which is not
52
+ * something the caller can act on — as long as another endpoint (prod is last)
53
+ * is still untried. The final endpoint's error is always surfaced.
54
+ */
55
+ export declare function shouldWalkEndpoint(status: number, hasMoreEndpoints: boolean): boolean;
56
+ /**
57
+ * Ordered endpoint candidates, skipping hosts already known to be unusable.
58
+ * Never returns an empty list: if every host is marked, re-probe them all.
59
+ */
60
+ export declare function antigravityEndpointCandidates(preferredBase?: string): string[];
61
+ export declare function buildGenerateContentUrl(endpoint: string, stream: boolean): string;
62
+ export declare function wrapAntigravityRequest(options: {
63
+ project?: string;
64
+ model: string;
65
+ request: Record<string, any>;
66
+ }): Record<string, any>;
67
+ export declare function fetchUserEmail(accessToken: string): Promise<string | undefined>;
68
+ export declare function exchangeAuthorizationCode(code: string, codeVerifier: string): Promise<AntigravityTokens>;
69
+ /** Parse RetryInfo.retryDelay like "3.957525076s" into milliseconds. */
70
+ export declare function parseRetryDelayMs(errorBody: string): number | undefined;
71
+ /**
72
+ * List models available to the authenticated Antigravity account/project.
73
+ * POST /v1internal:fetchAvailableModels — Google requires a project for this call.
74
+ */
75
+ export declare function fetchAvailableModels(accessToken: string, projectId?: string, baseUrl?: string): Promise<string[]>;
@@ -0,0 +1,2 @@
1
+ export type UnauthorizedAuthRecovery = () => Promise<Record<string, string> | null>;
2
+ export declare function sendWithUnauthorizedAuthRecovery(send: (headers: Record<string, string>) => Promise<Response>, requestHeaders: Record<string, string>, recover?: UnauthorizedAuthRecovery): Promise<Response>;
@@ -0,0 +1,14 @@
1
+ export interface Usage {
2
+ input_tokens: number;
3
+ output_tokens: number;
4
+ }
5
+ declare class LRUCache<K, V> {
6
+ private capacity;
7
+ private cache;
8
+ constructor(capacity: number);
9
+ get(key: K): V | undefined;
10
+ put(key: K, value: V): void;
11
+ values(): V[];
12
+ }
13
+ export declare const sessionUsageCache: LRUCache<string, Usage>;
14
+ export {};