@omnicross/core 0.1.0
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 +21 -0
- package/NOTICE +57 -0
- package/README.md +15 -0
- package/dist/ApiKeyPoolService-BmMkau07.d.cts +170 -0
- package/dist/ApiKeyPoolService-BmMkau07.d.ts +170 -0
- package/dist/ProviderProxy-f_8ziIhW.d.cts +120 -0
- package/dist/ProviderProxy-vjt8sQQk.d.ts +120 -0
- package/dist/SubscriptionAuthSource-Cr4fVEYY.d.cts +264 -0
- package/dist/SubscriptionAuthSource-D89zmiSS.d.ts +264 -0
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +218 -0
- package/dist/auth/GeminiCodeAssistProjectResolver.d.cts +68 -0
- package/dist/auth/GeminiCodeAssistProjectResolver.d.ts +68 -0
- package/dist/auth/GeminiCodeAssistProjectResolver.js +189 -0
- package/dist/completion/ApiKeyPoolService.cjs +331 -0
- package/dist/completion/ApiKeyPoolService.d.cts +2 -0
- package/dist/completion/ApiKeyPoolService.d.ts +2 -0
- package/dist/completion/ApiKeyPoolService.js +306 -0
- package/dist/completion.cjs +4027 -0
- package/dist/completion.d.cts +17 -0
- package/dist/completion.d.ts +17 -0
- package/dist/completion.js +3983 -0
- package/dist/index-BTSmc9Sm.d.ts +645 -0
- package/dist/index-DXazdTzZ.d.cts +645 -0
- package/dist/index.cjs +10428 -0
- package/dist/index.d.cts +128 -0
- package/dist/index.d.ts +128 -0
- package/dist/index.js +10339 -0
- package/dist/outbound-api/subscriptionRegistryPort.cjs +38 -0
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +73 -0
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +73 -0
- package/dist/outbound-api/subscriptionRegistryPort.js +12 -0
- package/dist/outbound-api.cjs +5264 -0
- package/dist/outbound-api.d.cts +320 -0
- package/dist/outbound-api.d.ts +320 -0
- package/dist/outbound-api.js +5218 -0
- package/dist/pipeline/SubscriptionAuthSource.cjs +131 -0
- package/dist/pipeline/SubscriptionAuthSource.d.cts +3 -0
- package/dist/pipeline/SubscriptionAuthSource.d.ts +3 -0
- package/dist/pipeline/SubscriptionAuthSource.js +103 -0
- package/dist/pipeline/SubscriptionAuthStrategy.cjs +18 -0
- package/dist/pipeline/SubscriptionAuthStrategy.d.cts +61 -0
- package/dist/pipeline/SubscriptionAuthStrategy.d.ts +61 -0
- package/dist/pipeline/SubscriptionAuthStrategy.js +0 -0
- package/dist/ports/gemini-code-assist-resolver.cjs +38 -0
- package/dist/ports/gemini-code-assist-resolver.d.cts +26 -0
- package/dist/ports/gemini-code-assist-resolver.d.ts +26 -0
- package/dist/ports/gemini-code-assist-resolver.js +12 -0
- package/dist/ports.cjs +18 -0
- package/dist/ports.d.cts +15 -0
- package/dist/ports.d.ts +15 -0
- package/dist/ports.js +0 -0
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +2958 -0
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +77 -0
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +77 -0
- package/dist/provider-proxy/ingress/providerProxyShared.js +2925 -0
- package/dist/provider-proxy/matchText.cjs +73 -0
- package/dist/provider-proxy/matchText.d.cts +47 -0
- package/dist/provider-proxy/matchText.d.ts +47 -0
- package/dist/provider-proxy/matchText.js +45 -0
- package/dist/provider-proxy/types.cjs +18 -0
- package/dist/provider-proxy/types.d.cts +12 -0
- package/dist/provider-proxy/types.d.ts +12 -0
- package/dist/provider-proxy/types.js +0 -0
- package/dist/provider-proxy.cjs +4667 -0
- package/dist/provider-proxy.d.cts +69 -0
- package/dist/provider-proxy.d.ts +69 -0
- package/dist/provider-proxy.js +4636 -0
- package/dist/serializeError.cjs +82 -0
- package/dist/serializeError.d.cts +24 -0
- package/dist/serializeError.d.ts +24 -0
- package/dist/serializeError.js +57 -0
- package/dist/sse-parser.cjs +456 -0
- package/dist/sse-parser.d.cts +143 -0
- package/dist/sse-parser.d.ts +143 -0
- package/dist/sse-parser.js +430 -0
- package/dist/transformer/TransformerChainExecutor.cjs +321 -0
- package/dist/transformer/TransformerChainExecutor.d.cts +104 -0
- package/dist/transformer/TransformerChainExecutor.d.ts +104 -0
- package/dist/transformer/TransformerChainExecutor.js +294 -0
- package/dist/transformer/TransformerService.cjs +290 -0
- package/dist/transformer/TransformerService.d.cts +138 -0
- package/dist/transformer/TransformerService.d.ts +138 -0
- package/dist/transformer/TransformerService.js +265 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +1115 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.d.cts +102 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.d.ts +102 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +1085 -0
- package/dist/transformer/transformers/GeminiTransformer.cjs +1013 -0
- package/dist/transformer/transformers/GeminiTransformer.d.cts +70 -0
- package/dist/transformer/transformers/GeminiTransformer.d.ts +70 -0
- package/dist/transformer/transformers/GeminiTransformer.js +986 -0
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +538 -0
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +53 -0
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +53 -0
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +513 -0
- package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +73 -0
- package/dist/transformer/transformers/OpenCodeGoTransformer.d.cts +51 -0
- package/dist/transformer/transformers/OpenCodeGoTransformer.d.ts +51 -0
- package/dist/transformer/transformers/OpenCodeGoTransformer.js +48 -0
- package/dist/transformer/types.cjs +18 -0
- package/dist/transformer/types.d.cts +405 -0
- package/dist/transformer/types.d.ts +405 -0
- package/dist/transformer/types.js +0 -0
- package/dist/transformer.cjs +3736 -0
- package/dist/transformer.d.cts +33 -0
- package/dist/transformer.d.ts +33 -0
- package/dist/transformer.js +3712 -0
- package/dist/types-CGGrKqC_.d.cts +142 -0
- package/dist/types-CbCN2NQP.d.ts +142 -0
- package/dist/types-DCzHkhJt.d.ts +467 -0
- package/dist/types-DZIQbgp0.d.cts +467 -0
- package/dist/usage-event-sink-BX7FE1NL.d.cts +59 -0
- package/dist/usage-event-sink-BX7FE1NL.d.ts +59 -0
- package/package.json +62 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/transformer/transformers/OpenCodeGoTransformer.ts
|
|
2
|
+
var OpenCodeGoTransformer = class {
|
|
3
|
+
static TransformerName = "opencodego";
|
|
4
|
+
name = "opencodego";
|
|
5
|
+
endPoint = "/v1/chat/completions";
|
|
6
|
+
logger;
|
|
7
|
+
async auth(request, _provider, _context) {
|
|
8
|
+
return { body: request, config: { headers: {} } };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Unified → OpenAI Chat Completions.
|
|
12
|
+
* Unified IS chat completions shape; this is mostly stripping `meta` and
|
|
13
|
+
* normalizing string-content single-block messages.
|
|
14
|
+
*/
|
|
15
|
+
async transformRequestIn(request, _provider, _context) {
|
|
16
|
+
const messages = request.messages.map((m) => {
|
|
17
|
+
const content = m.content;
|
|
18
|
+
if (Array.isArray(content) && content.length === 1 && content[0]?.type === "text") {
|
|
19
|
+
return { ...m, content: content[0].text };
|
|
20
|
+
}
|
|
21
|
+
return m;
|
|
22
|
+
});
|
|
23
|
+
const out = {
|
|
24
|
+
model: request.model,
|
|
25
|
+
messages,
|
|
26
|
+
stream: request.stream
|
|
27
|
+
};
|
|
28
|
+
if (request.temperature !== void 0) out.temperature = request.temperature;
|
|
29
|
+
if (request.max_tokens !== void 0) out.max_tokens = request.max_tokens;
|
|
30
|
+
if (request.tools && request.tools.length > 0) out.tools = request.tools;
|
|
31
|
+
if (request.tool_choice !== void 0) out.tool_choice = request.tool_choice;
|
|
32
|
+
if (request.reasoning?.effort && request.reasoning.effort !== "none") {
|
|
33
|
+
out.reasoning_effort = request.reasoning.effort;
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* OpenAI Chat Completions response → Unified.
|
|
39
|
+
* The upstream's response shape already matches Unified — pass through.
|
|
40
|
+
* The endpoint AnthropicTransformer re-encodes to Anthropic for the SDK.
|
|
41
|
+
*/
|
|
42
|
+
async transformResponseOut(response, _context) {
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
OpenCodeGoTransformer
|
|
48
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/transformer/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TransformerService Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the Transformer system, providing unified
|
|
5
|
+
* request/response formats and transformer chain configuration.
|
|
6
|
+
*
|
|
7
|
+
* @module transformer/types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Thinking effort level for reasoning models
|
|
11
|
+
*/
|
|
12
|
+
type ThinkLevel = 'none' | 'low' | 'medium' | 'high';
|
|
13
|
+
/**
|
|
14
|
+
* Thinking content with optional signature for extended context
|
|
15
|
+
*/
|
|
16
|
+
interface ThinkingContent {
|
|
17
|
+
content: string;
|
|
18
|
+
signature?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reasoning configuration for request
|
|
22
|
+
*/
|
|
23
|
+
interface ReasoningConfig {
|
|
24
|
+
/** OpenAI-style effort level */
|
|
25
|
+
effort?: ThinkLevel;
|
|
26
|
+
/** Anthropic-style max tokens for thinking */
|
|
27
|
+
max_tokens?: number;
|
|
28
|
+
/** Whether reasoning is enabled */
|
|
29
|
+
enabled?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Text content block
|
|
33
|
+
*/
|
|
34
|
+
interface TextContent {
|
|
35
|
+
type: 'text';
|
|
36
|
+
text: string;
|
|
37
|
+
cache_control?: {
|
|
38
|
+
type?: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Image content block
|
|
43
|
+
*/
|
|
44
|
+
interface ImageContent {
|
|
45
|
+
type: 'image_url';
|
|
46
|
+
image_url: {
|
|
47
|
+
url: string;
|
|
48
|
+
};
|
|
49
|
+
media_type?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Union of all content types
|
|
53
|
+
*/
|
|
54
|
+
type MessageContent = TextContent | ImageContent;
|
|
55
|
+
/**
|
|
56
|
+
* Tool call definition
|
|
57
|
+
*/
|
|
58
|
+
interface ToolCall {
|
|
59
|
+
id: string;
|
|
60
|
+
type: 'function';
|
|
61
|
+
function: {
|
|
62
|
+
name: string;
|
|
63
|
+
arguments: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Unified message format that works across all providers
|
|
68
|
+
*/
|
|
69
|
+
interface UnifiedMessage {
|
|
70
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
71
|
+
content: string | null | MessageContent[];
|
|
72
|
+
tool_calls?: ToolCall[];
|
|
73
|
+
tool_call_id?: string;
|
|
74
|
+
cache_control?: {
|
|
75
|
+
type?: string;
|
|
76
|
+
};
|
|
77
|
+
thinking?: ThinkingContent;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Tool parameter schema
|
|
81
|
+
*/
|
|
82
|
+
interface ToolParameterSchema {
|
|
83
|
+
type: 'object';
|
|
84
|
+
properties: Record<string, unknown>;
|
|
85
|
+
required?: string[];
|
|
86
|
+
additionalProperties?: boolean;
|
|
87
|
+
$schema?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Unified tool definition
|
|
91
|
+
*/
|
|
92
|
+
interface UnifiedTool {
|
|
93
|
+
type: 'function';
|
|
94
|
+
function: {
|
|
95
|
+
name: string;
|
|
96
|
+
description: string;
|
|
97
|
+
parameters: ToolParameterSchema;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Tool choice configuration
|
|
102
|
+
*/
|
|
103
|
+
type ToolChoice = 'auto' | 'none' | 'required' | string | {
|
|
104
|
+
type: 'function';
|
|
105
|
+
function: {
|
|
106
|
+
name: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Unified chat request format
|
|
111
|
+
*/
|
|
112
|
+
interface UnifiedChatRequest {
|
|
113
|
+
messages: UnifiedMessage[];
|
|
114
|
+
model: string;
|
|
115
|
+
max_tokens?: number;
|
|
116
|
+
temperature?: number;
|
|
117
|
+
stream?: boolean;
|
|
118
|
+
tools?: UnifiedTool[];
|
|
119
|
+
tool_choice?: ToolChoice;
|
|
120
|
+
reasoning?: ReasoningConfig;
|
|
121
|
+
/**
|
|
122
|
+
* Internal-only routing metadata. Populated by callers (CompletionService /
|
|
123
|
+
* the host's engine adapters and proxy servers) so the usage-capture hook can attribute
|
|
124
|
+
* the recorded event to a chat message, session, engine origin, and api key.
|
|
125
|
+
*
|
|
126
|
+
* **Must not be serialised into the outbound HTTP body.** The transformer chain
|
|
127
|
+
* passes this object alongside the request internally; transformers that build
|
|
128
|
+
* provider request payloads must drop `meta` from their output.
|
|
129
|
+
*/
|
|
130
|
+
meta?: UnifiedChatRequestMeta;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Routing metadata threaded through the transformer chain so the usage-capture
|
|
134
|
+
* hook can identify which chat message / session / api key produced the call.
|
|
135
|
+
* See `UnifiedChatRequest.meta`.
|
|
136
|
+
*/
|
|
137
|
+
interface UnifiedChatRequestMeta {
|
|
138
|
+
/** Host message id of the assistant message being produced, when known. */
|
|
139
|
+
messageId?: string | null;
|
|
140
|
+
/** Parent assistant message id (for subagent dispatches that have a parent). */
|
|
141
|
+
parentMessageId?: string | null;
|
|
142
|
+
/** Host session id, when applicable. */
|
|
143
|
+
sessionId?: string | null;
|
|
144
|
+
/** Which engine path is making the call. See `UsageEngineOrigin`. */
|
|
145
|
+
engineOrigin?: 'completion' | 'claude-sdk' | 'claude-sdk-direct' | 'codex-ingress' | (string & {});
|
|
146
|
+
/** The api-key-pool entry id selected for this request. */
|
|
147
|
+
apiKeyId?: string | null;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* URL citation annotation
|
|
151
|
+
*/
|
|
152
|
+
interface UrlCitation {
|
|
153
|
+
url: string;
|
|
154
|
+
title: string;
|
|
155
|
+
content: string;
|
|
156
|
+
start_index: number;
|
|
157
|
+
end_index: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Response annotation
|
|
161
|
+
*/
|
|
162
|
+
interface Annotation {
|
|
163
|
+
type: 'url_citation';
|
|
164
|
+
url_citation?: UrlCitation;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Unified chat response format
|
|
168
|
+
*/
|
|
169
|
+
interface UnifiedChatResponse {
|
|
170
|
+
id: string;
|
|
171
|
+
model: string;
|
|
172
|
+
content: string | null;
|
|
173
|
+
usage?: {
|
|
174
|
+
prompt_tokens: number;
|
|
175
|
+
completion_tokens: number;
|
|
176
|
+
total_tokens: number;
|
|
177
|
+
/**
|
|
178
|
+
* Anthropic prompt-cache hit count. Optional — providers without prompt
|
|
179
|
+
* caching omit it. Counted from the response's raw usage block by the
|
|
180
|
+
* provider's transformer.
|
|
181
|
+
*/
|
|
182
|
+
cache_read_input_tokens?: number;
|
|
183
|
+
/** Anthropic prompt-cache write count. Optional, see `cache_read_input_tokens`. */
|
|
184
|
+
cache_creation_input_tokens?: number;
|
|
185
|
+
/** OpenAI o1 / Anthropic extended-thinking — already part of completion_tokens by some providers. */
|
|
186
|
+
reasoning_tokens?: number;
|
|
187
|
+
};
|
|
188
|
+
tool_calls?: ToolCall[];
|
|
189
|
+
annotations?: Annotation[];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Stream chunk format
|
|
193
|
+
*/
|
|
194
|
+
interface StreamChunk {
|
|
195
|
+
id: string;
|
|
196
|
+
object: string;
|
|
197
|
+
created: number;
|
|
198
|
+
model: string;
|
|
199
|
+
choices?: Array<{
|
|
200
|
+
index: number;
|
|
201
|
+
delta: {
|
|
202
|
+
role?: string;
|
|
203
|
+
content?: string;
|
|
204
|
+
thinking?: {
|
|
205
|
+
content?: string;
|
|
206
|
+
signature?: string;
|
|
207
|
+
};
|
|
208
|
+
tool_calls?: Array<{
|
|
209
|
+
id?: string;
|
|
210
|
+
type?: 'function';
|
|
211
|
+
function?: {
|
|
212
|
+
name?: string;
|
|
213
|
+
arguments?: string;
|
|
214
|
+
};
|
|
215
|
+
index?: number;
|
|
216
|
+
}>;
|
|
217
|
+
annotations?: Annotation[];
|
|
218
|
+
};
|
|
219
|
+
finish_reason?: string | null;
|
|
220
|
+
}>;
|
|
221
|
+
usage?: {
|
|
222
|
+
completion_tokens?: number;
|
|
223
|
+
prompt_tokens?: number;
|
|
224
|
+
total_tokens?: number;
|
|
225
|
+
prompt_tokens_details?: {
|
|
226
|
+
cached_tokens?: number;
|
|
227
|
+
};
|
|
228
|
+
output_tokens_details?: {
|
|
229
|
+
reasoning_tokens?: number;
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* LLM Provider configuration (runtime format)
|
|
235
|
+
*/
|
|
236
|
+
interface LLMProvider {
|
|
237
|
+
name: string;
|
|
238
|
+
baseUrl: string;
|
|
239
|
+
apiKey: string;
|
|
240
|
+
models: string[];
|
|
241
|
+
transformer?: TransformerChainConfig;
|
|
242
|
+
/**
|
|
243
|
+
* Resolved Google **Code Assist** project id, threaded onto the transformer
|
|
244
|
+
* provider object by the subscription dispatch seam (SubscriptionDispatcher /
|
|
245
|
+
* openaiResponsesIngress) so `GeminiCodeAssistTransformer.transformRequestIn`
|
|
246
|
+
* can embed it in the top-level envelope. `undefined` is the valid fresh
|
|
247
|
+
* free-tier value (sending a project on free/legacy-tier → Precondition
|
|
248
|
+
* Failed). Only ever set for the gemini subscription profile; inert otherwise.
|
|
249
|
+
*/
|
|
250
|
+
geminiProject?: string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Model route information
|
|
254
|
+
*/
|
|
255
|
+
interface ModelRoute {
|
|
256
|
+
provider: string;
|
|
257
|
+
model: string;
|
|
258
|
+
fullModel: string;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Request routing information
|
|
262
|
+
*/
|
|
263
|
+
interface RequestRouteInfo {
|
|
264
|
+
provider: LLMProvider;
|
|
265
|
+
originalModel: string;
|
|
266
|
+
targetModel: string;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Transformer options passed during instantiation
|
|
270
|
+
*/
|
|
271
|
+
interface TransformerOptions {
|
|
272
|
+
[key: string]: unknown;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Context passed through transformer chain
|
|
276
|
+
*/
|
|
277
|
+
interface TransformerContext {
|
|
278
|
+
/** Original request object */
|
|
279
|
+
req?: unknown;
|
|
280
|
+
/** Logger instance */
|
|
281
|
+
logger?: TransformerLogger;
|
|
282
|
+
/** Provider name */
|
|
283
|
+
providerName?: string;
|
|
284
|
+
/** Additional context data */
|
|
285
|
+
[key: string]: unknown;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Logger interface for transformers
|
|
289
|
+
*/
|
|
290
|
+
interface TransformerLogger {
|
|
291
|
+
debug(message: string, ...args: unknown[]): void;
|
|
292
|
+
info(message: string, ...args: unknown[]): void;
|
|
293
|
+
warn(message: string, ...args: unknown[]): void;
|
|
294
|
+
error(message: string, ...args: unknown[]): void;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Transformer interface - defines the contract for all transformers
|
|
298
|
+
*/
|
|
299
|
+
interface Transformer {
|
|
300
|
+
/** Unique name for the transformer */
|
|
301
|
+
name?: string;
|
|
302
|
+
/** API endpoint path (e.g., '/v1/chat/completions') */
|
|
303
|
+
endPoint?: string;
|
|
304
|
+
/** Logger instance */
|
|
305
|
+
logger?: TransformerLogger;
|
|
306
|
+
/**
|
|
307
|
+
* Transform incoming request (provider-specific → unified format)
|
|
308
|
+
* Called when request enters the transformer chain
|
|
309
|
+
*/
|
|
310
|
+
transformRequestIn?: (request: UnifiedChatRequest, provider: LLMProvider, context: TransformerContext) => Promise<Record<string, unknown>>;
|
|
311
|
+
/**
|
|
312
|
+
* Transform outgoing request (unified → provider-specific format)
|
|
313
|
+
* Called before sending to LLM provider
|
|
314
|
+
*/
|
|
315
|
+
transformRequestOut?: (request: unknown, context: TransformerContext) => Promise<UnifiedChatRequest>;
|
|
316
|
+
/**
|
|
317
|
+
* Transform incoming response (provider-specific → unified format)
|
|
318
|
+
* Called after receiving response from provider
|
|
319
|
+
*/
|
|
320
|
+
transformResponseIn?: (response: Response, context?: TransformerContext) => Promise<Response>;
|
|
321
|
+
/**
|
|
322
|
+
* Transform outgoing response (unified → client format)
|
|
323
|
+
* Called before returning response to client
|
|
324
|
+
*/
|
|
325
|
+
transformResponseOut?: (response: Response, context: TransformerContext) => Promise<Response>;
|
|
326
|
+
/**
|
|
327
|
+
* Handle authentication for the request
|
|
328
|
+
*/
|
|
329
|
+
auth?: (request: unknown, provider: LLMProvider, context: TransformerContext) => Promise<unknown>;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Transformer constructor interface
|
|
333
|
+
*/
|
|
334
|
+
interface TransformerConstructor {
|
|
335
|
+
new (options?: TransformerOptions): Transformer;
|
|
336
|
+
TransformerName?: string;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Individual transformer reference in chain
|
|
340
|
+
* Can be a string name or [name, options] tuple
|
|
341
|
+
*/
|
|
342
|
+
type TransformerReference = string | [string, TransformerOptions];
|
|
343
|
+
/**
|
|
344
|
+
* Model-specific transformer configuration
|
|
345
|
+
*/
|
|
346
|
+
interface ModelTransformerConfig {
|
|
347
|
+
use?: TransformerReference[];
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Transformer chain configuration for a provider
|
|
351
|
+
*/
|
|
352
|
+
interface TransformerChainConfig {
|
|
353
|
+
/** Provider-level transformers applied to all models */
|
|
354
|
+
use?: TransformerReference[];
|
|
355
|
+
/** Model-specific transformer overrides */
|
|
356
|
+
[modelName: string]: ModelTransformerConfig | TransformerReference[] | undefined;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Resolved transformer chain (instances ready to execute)
|
|
360
|
+
*/
|
|
361
|
+
interface ResolvedTransformerChain {
|
|
362
|
+
/** Provider-level transformer instances */
|
|
363
|
+
providerTransformers: Transformer[];
|
|
364
|
+
/** Model-specific transformer instances */
|
|
365
|
+
modelTransformers: Transformer[];
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Result of request transformation
|
|
369
|
+
*/
|
|
370
|
+
interface TransformRequestResult {
|
|
371
|
+
/** Transformed request body */
|
|
372
|
+
requestBody: unknown;
|
|
373
|
+
/** Additional request configuration */
|
|
374
|
+
config: RequestConfig;
|
|
375
|
+
/** Whether to bypass further transformations */
|
|
376
|
+
bypass: boolean;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Request configuration for HTTP call
|
|
380
|
+
*/
|
|
381
|
+
interface RequestConfig {
|
|
382
|
+
/** Request URL */
|
|
383
|
+
url?: URL | string;
|
|
384
|
+
/** Request headers */
|
|
385
|
+
headers?: Record<string, string>;
|
|
386
|
+
/** Additional fetch options */
|
|
387
|
+
[key: string]: unknown;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Transformer registration from configuration
|
|
391
|
+
*/
|
|
392
|
+
interface TransformerConfigEntry {
|
|
393
|
+
name: string;
|
|
394
|
+
type?: 'class' | 'module';
|
|
395
|
+
path?: string;
|
|
396
|
+
options?: TransformerOptions;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Service configuration
|
|
400
|
+
*/
|
|
401
|
+
interface TransformerServiceConfig {
|
|
402
|
+
transformers?: TransformerConfigEntry[];
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export type { Annotation, ImageContent, LLMProvider, MessageContent, ModelRoute, ModelTransformerConfig, ReasoningConfig, RequestConfig, RequestRouteInfo, ResolvedTransformerChain, StreamChunk, TextContent, ThinkLevel, ThinkingContent, ToolCall, ToolChoice, ToolParameterSchema, TransformRequestResult, Transformer, TransformerChainConfig, TransformerConfigEntry, TransformerConstructor, TransformerContext, TransformerLogger, TransformerOptions, TransformerReference, TransformerServiceConfig, UnifiedChatRequest, UnifiedChatRequestMeta, UnifiedChatResponse, UnifiedMessage, UnifiedTool, UrlCitation };
|