@omnicross/core 0.1.8 → 0.1.10
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/dist/auth/GeminiCodeAssistProjectResolver.cjs +5 -3
- package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -2
- package/dist/{chunk-N5T4M4GU.js → chunk-2UTGX6FM.js} +2 -2
- package/dist/{chunk-32O35CIF.js → chunk-45FHEOKW.js} +22 -7
- package/dist/{chunk-LVUCAWMK.js → chunk-55FMGZ3L.js} +13 -5
- package/dist/{chunk-OF3BECU2.cjs → chunk-56QD3YW6.cjs} +18 -5
- package/dist/{chunk-V4TXMEJS.cjs → chunk-5LNYGCIW.cjs} +15 -7
- package/dist/{chunk-EPN67EGP.cjs → chunk-5UK3KLE2.cjs} +9 -1
- package/dist/chunk-6D4W22P4.js +150 -0
- package/dist/chunk-77USGNRW.cjs +37 -0
- package/dist/chunk-AOFWNWLT.cjs +203 -0
- package/dist/{chunk-UAPBLNN2.js → chunk-AQDON6MB.js} +8 -0
- package/dist/{chunk-LB6EBS6Y.js → chunk-CCVRRJOX.js} +17 -4
- package/dist/{chunk-OVQBNVSV.cjs → chunk-CMVXX7ON.cjs} +42 -27
- package/dist/{chunk-QYC54PMG.js → chunk-FEBAQI5A.js} +255 -92
- package/dist/{chunk-7C7DET6S.js → chunk-GXEZ2R3E.js} +156 -1
- package/dist/{chunk-PEGTIPB3.js → chunk-HKB656B4.js} +37 -43
- package/dist/chunk-N2EIM2XJ.js +203 -0
- package/dist/{chunk-MYYR3HZL.js → chunk-NGYOO5TO.js} +5 -5
- package/dist/{chunk-OKMJLEXX.cjs → chunk-OC6DOOFX.cjs} +5 -5
- package/dist/{chunk-2Z4XM3H5.cjs → chunk-P7EM6BND.cjs} +10 -10
- package/dist/chunk-QUSEZNYS.cjs +150 -0
- package/dist/{chunk-KBM2W6UY.cjs → chunk-RICPANBY.cjs} +41 -24
- package/dist/{chunk-TOVPMMHM.js → chunk-S3DYFEBE.js} +37 -20
- package/dist/{chunk-26K6T2YS.cjs → chunk-TIT74RIL.cjs} +407 -244
- package/dist/{chunk-XPIOJQS2.cjs → chunk-UWDW6PN3.cjs} +159 -4
- package/dist/chunk-WYVGULTQ.js +37 -0
- package/dist/{chunk-OXHNSZ53.cjs → chunk-ZQQUD66M.cjs} +54 -60
- package/dist/completion/CompletionService.cjs +15 -13
- package/dist/completion/CompletionService.js +14 -12
- package/dist/completion.cjs +15 -13
- package/dist/completion.js +14 -12
- package/dist/index.cjs +15 -13
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -12
- package/dist/outbound-api/auditCapture.cjs +2 -2
- package/dist/outbound-api/auditCapture.d.cts +6 -0
- package/dist/outbound-api/auditCapture.d.ts +6 -0
- package/dist/outbound-api/auditCapture.js +1 -1
- package/dist/outbound-api/routeResolver.d.cts +1 -1
- package/dist/outbound-api/routeResolver.d.ts +1 -1
- package/dist/outbound-api/types.d.cts +1 -1
- package/dist/outbound-api/types.d.ts +1 -1
- package/dist/outbound-api.cjs +15 -13
- package/dist/outbound-api.d.cts +3 -2
- package/dist/outbound-api.d.ts +3 -2
- package/dist/outbound-api.js +14 -12
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +1 -1
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +1 -1
- package/dist/pipeline/executeProviderCall.d.cts +2 -0
- package/dist/pipeline/executeProviderCall.d.ts +2 -0
- package/dist/pipeline/resolveProviderChain.d.cts +1 -0
- package/dist/pipeline/resolveProviderChain.d.ts +1 -0
- package/dist/pipeline/resolveSubscriptionChain.d.cts +2 -0
- package/dist/pipeline/resolveSubscriptionChain.d.ts +2 -0
- package/dist/ports/provider-config-source.d.cts +1 -0
- package/dist/ports/provider-config-source.d.ts +1 -0
- package/dist/ports.d.cts +1 -1
- package/dist/ports.d.ts +1 -1
- package/dist/provider-proxy/ProviderProxy.cjs +15 -13
- package/dist/provider-proxy/ProviderProxy.js +14 -12
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +15 -13
- package/dist/provider-proxy/ingress/providerProxyShared.js +14 -12
- package/dist/provider-proxy.cjs +15 -13
- package/dist/provider-proxy.js +14 -12
- package/dist/transformer/TransformerChainExecutor.d.cts +2 -0
- package/dist/transformer/TransformerChainExecutor.d.ts +2 -0
- package/dist/transformer/TransformerService.d.cts +2 -0
- package/dist/transformer/TransformerService.d.ts +2 -0
- package/dist/transformer/transformers/AnthropicTransformer.cjs +4 -2
- package/dist/transformer/transformers/AnthropicTransformer.d.cts +7 -2
- package/dist/transformer/transformers/AnthropicTransformer.d.ts +7 -2
- package/dist/transformer/transformers/AnthropicTransformer.js +3 -1
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +5 -3
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.d.cts +2 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.d.ts +2 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +4 -2
- package/dist/transformer/transformers/GeminiTransformer.cjs +5 -3
- package/dist/transformer/transformers/GeminiTransformer.d.cts +4 -2
- package/dist/transformer/transformers/GeminiTransformer.d.ts +4 -2
- package/dist/transformer/transformers/GeminiTransformer.js +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -1
- package/dist/transformer/transformers/OpenAITransformer.cjs +3 -2
- package/dist/transformer/transformers/OpenAITransformer.d.cts +3 -1
- package/dist/transformer/transformers/OpenAITransformer.d.ts +3 -1
- package/dist/transformer/transformers/OpenAITransformer.js +2 -1
- package/dist/transformer/transformers.cjs +10 -8
- package/dist/transformer/transformers.d.cts +2 -0
- package/dist/transformer/transformers.d.ts +2 -0
- package/dist/transformer/transformers.js +9 -7
- package/dist/transformer/types.d.cts +16 -5
- package/dist/transformer/types.d.ts +16 -5
- package/dist/transformer.cjs +28 -9
- package/dist/transformer.d.cts +76 -1
- package/dist/transformer.d.ts +76 -1
- package/dist/transformer.js +28 -9
- package/dist/usage/usage-recorder.cjs +2 -2
- package/dist/usage/usage-recorder.d.cts +12 -2
- package/dist/usage/usage-recorder.d.ts +12 -2
- package/dist/usage/usage-recorder.js +1 -1
- package/dist/usage.cjs +20 -3
- package/dist/usage.d.cts +149 -0
- package/dist/usage.d.ts +149 -0
- package/dist/usage.js +20 -3
- package/package.json +2 -2
- package/dist/chunk-7VU7V2E4.js +0 -0
- package/dist/chunk-FZ46M34D.cjs +0 -1
- /package/dist/{chunk-EYZYXJTJ.cjs → chunk-QVOB2DNX.cjs} +0 -0
- /package/dist/{chunk-46RLHI7D.js → chunk-WTQMX2Q6.js} +0 -0
|
@@ -11,6 +11,156 @@ import {
|
|
|
11
11
|
|
|
12
12
|
// src/outbound-api/auditCapture.ts
|
|
13
13
|
import { randomUUID } from "crypto";
|
|
14
|
+
|
|
15
|
+
// src/outbound-api/auditSseCompact.ts
|
|
16
|
+
var MERGED_FRAMES_FIELD = "_omnicrossMergedFrames";
|
|
17
|
+
function asObject(value) {
|
|
18
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
19
|
+
}
|
|
20
|
+
function scalar(value) {
|
|
21
|
+
return typeof value === "string" || typeof value === "number" ? String(value) : "";
|
|
22
|
+
}
|
|
23
|
+
function classify(payload) {
|
|
24
|
+
const type = scalar(payload["type"]);
|
|
25
|
+
if (type === "content_block_delta") {
|
|
26
|
+
const delta = asObject(payload["delta"]);
|
|
27
|
+
const deltaType = scalar(delta?.["type"]);
|
|
28
|
+
const field = deltaType === "text_delta" ? "text" : deltaType === "thinking_delta" ? "thinking" : deltaType === "input_json_delta" ? "partial_json" : null;
|
|
29
|
+
if (!delta || !field || typeof delta[field] !== "string") return null;
|
|
30
|
+
return {
|
|
31
|
+
channel: "anthropic:" + scalar(payload["index"]) + ":" + deltaType,
|
|
32
|
+
text: delta[field],
|
|
33
|
+
payload,
|
|
34
|
+
textPath: ["delta", field]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (type.endsWith(".delta") && typeof payload["delta"] === "string") {
|
|
38
|
+
const channel = [
|
|
39
|
+
"responses",
|
|
40
|
+
type,
|
|
41
|
+
scalar(payload["item_id"]),
|
|
42
|
+
scalar(payload["output_index"]),
|
|
43
|
+
scalar(payload["content_index"])
|
|
44
|
+
].join(":");
|
|
45
|
+
return { channel, text: payload["delta"], payload, textPath: ["delta"] };
|
|
46
|
+
}
|
|
47
|
+
const choices = payload["choices"];
|
|
48
|
+
if (Array.isArray(choices) && choices.length === 1) {
|
|
49
|
+
const choice = asObject(choices[0]);
|
|
50
|
+
const delta = asObject(choice?.["delta"]);
|
|
51
|
+
if (choice && delta && typeof delta["content"] === "string" && choice["finish_reason"] == null && delta["tool_calls"] === void 0 && delta["function_call"] === void 0) {
|
|
52
|
+
return {
|
|
53
|
+
channel: "chat:" + scalar(choice["index"]),
|
|
54
|
+
text: delta["content"],
|
|
55
|
+
payload,
|
|
56
|
+
textPath: ["choices", "0", "delta", "content"]
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function withMergedText(frame, text, mergedCount) {
|
|
63
|
+
const clone = JSON.parse(JSON.stringify(frame.payload));
|
|
64
|
+
let cursor = clone;
|
|
65
|
+
for (let i = 0; i < frame.textPath.length - 1; i += 1) {
|
|
66
|
+
const step = frame.textPath[i];
|
|
67
|
+
const next = Array.isArray(cursor) ? cursor[Number(step)] : cursor[step];
|
|
68
|
+
if (next === null || typeof next !== "object") return clone;
|
|
69
|
+
cursor = next;
|
|
70
|
+
}
|
|
71
|
+
const leaf = frame.textPath[frame.textPath.length - 1];
|
|
72
|
+
if (Array.isArray(cursor)) cursor[Number(leaf)] = text;
|
|
73
|
+
else cursor[leaf] = text;
|
|
74
|
+
clone[MERGED_FRAMES_FIELD] = mergedCount;
|
|
75
|
+
return clone;
|
|
76
|
+
}
|
|
77
|
+
function splitBlocks(text, nl) {
|
|
78
|
+
const blocks = [];
|
|
79
|
+
let head = [];
|
|
80
|
+
let data = null;
|
|
81
|
+
let raw = [];
|
|
82
|
+
const flush = () => {
|
|
83
|
+
if (raw.length === 0) return;
|
|
84
|
+
blocks.push({ head, data, raw: raw.join(nl) });
|
|
85
|
+
head = [];
|
|
86
|
+
data = null;
|
|
87
|
+
raw = [];
|
|
88
|
+
};
|
|
89
|
+
for (const line of text.split(nl)) {
|
|
90
|
+
if (line.trim() === "") {
|
|
91
|
+
flush();
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
raw.push(line);
|
|
95
|
+
if (line.startsWith("data:")) {
|
|
96
|
+
const payload = line.slice("data:".length).trimStart();
|
|
97
|
+
data = data === null ? payload : data + nl + payload;
|
|
98
|
+
} else {
|
|
99
|
+
head.push(line);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
flush();
|
|
103
|
+
return blocks;
|
|
104
|
+
}
|
|
105
|
+
function compactSseBody(text) {
|
|
106
|
+
if (!text || !text.includes("data:")) return text;
|
|
107
|
+
const nl = "\n";
|
|
108
|
+
const blocks = splitBlocks(text, nl);
|
|
109
|
+
if (blocks.length === 0) return text;
|
|
110
|
+
const out = [];
|
|
111
|
+
let runFrame = null;
|
|
112
|
+
let runBlock = null;
|
|
113
|
+
let runText = "";
|
|
114
|
+
let runCount = 0;
|
|
115
|
+
let merged = 0;
|
|
116
|
+
const flushRun = () => {
|
|
117
|
+
if (runFrame === null || runBlock === null) return;
|
|
118
|
+
if (runCount === 1) {
|
|
119
|
+
out.push(runBlock.raw);
|
|
120
|
+
} else {
|
|
121
|
+
const payload = withMergedText(runFrame, runText, runCount);
|
|
122
|
+
out.push([...runBlock.head, "data: " + JSON.stringify(payload)].join(nl));
|
|
123
|
+
merged += runCount;
|
|
124
|
+
}
|
|
125
|
+
runFrame = null;
|
|
126
|
+
runBlock = null;
|
|
127
|
+
runText = "";
|
|
128
|
+
runCount = 0;
|
|
129
|
+
};
|
|
130
|
+
for (const block of blocks) {
|
|
131
|
+
let frame = null;
|
|
132
|
+
if (block.data !== null && block.data !== "[DONE]") {
|
|
133
|
+
try {
|
|
134
|
+
const parsed = asObject(JSON.parse(block.data));
|
|
135
|
+
if (parsed) frame = classify(parsed);
|
|
136
|
+
} catch {
|
|
137
|
+
frame = null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (frame === null) {
|
|
141
|
+
flushRun();
|
|
142
|
+
out.push(block.raw);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const open = runFrame;
|
|
146
|
+
if (open !== null && open.channel === frame.channel) {
|
|
147
|
+
runText += frame.text;
|
|
148
|
+
runCount += 1;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
flushRun();
|
|
152
|
+
runFrame = frame;
|
|
153
|
+
runBlock = block;
|
|
154
|
+
runText = frame.text;
|
|
155
|
+
runCount = 1;
|
|
156
|
+
}
|
|
157
|
+
flushRun();
|
|
158
|
+
if (merged === 0) return text;
|
|
159
|
+
const trailer = /\s$/.test(text) ? nl + nl : "";
|
|
160
|
+
return out.join(nl + nl) + trailer;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/outbound-api/auditCapture.ts
|
|
14
164
|
function completeUtf8PrefixLength(buf) {
|
|
15
165
|
if (buf.length === 0) return 0;
|
|
16
166
|
let leadIndex = buf.length - 1;
|
|
@@ -112,15 +262,20 @@ function beginAuditCapture(req, res, now) {
|
|
|
112
262
|
if (!record.provider && usage.provider) record.provider = usage.provider;
|
|
113
263
|
}
|
|
114
264
|
if (ctx.error) record.error = redactAuditText(ctx.error);
|
|
265
|
+
if (ctx.sessionKey) record.sessionKey = ctx.sessionKey;
|
|
115
266
|
if (config.captureBodies) {
|
|
116
267
|
if (requestBody != null && requestBody.length > 0) {
|
|
117
268
|
record.requestBody = requestBody;
|
|
118
269
|
}
|
|
119
270
|
if (responseChunks.length > 0) {
|
|
120
271
|
const captured = Buffer.concat(responseChunks, responseBytes);
|
|
121
|
-
const
|
|
272
|
+
const decoded = decodeCapturedBody(captured, responseTruncated);
|
|
273
|
+
const body = config.compactStreamingBodies ? compactSseBody(decoded) : decoded;
|
|
122
274
|
record.responseBody = truncateToBytes(redactAuditText(body), config.maxBodyBytes);
|
|
123
275
|
}
|
|
276
|
+
if (record.requestBody !== void 0 || record.responseBody !== void 0) {
|
|
277
|
+
record.hasBody = true;
|
|
278
|
+
}
|
|
124
279
|
}
|
|
125
280
|
recordAudit(record);
|
|
126
281
|
} catch {
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
anthropicUsageToChatUsage
|
|
3
3
|
} from "./chunk-FU7EAR73.js";
|
|
4
|
+
import {
|
|
5
|
+
flattenToolResultContent,
|
|
6
|
+
formatBase64,
|
|
7
|
+
getThinkLevel
|
|
8
|
+
} from "./chunk-WYVGULTQ.js";
|
|
9
|
+
import {
|
|
10
|
+
extractReasoningIntent,
|
|
11
|
+
normalizeThinkLevel,
|
|
12
|
+
resolveReasoningPlan
|
|
13
|
+
} from "./chunk-N2EIM2XJ.js";
|
|
4
14
|
|
|
5
15
|
// src/transformer/transformers/AnthropicToolHandling.ts
|
|
6
16
|
function isServerSideTool(tool) {
|
|
@@ -18,38 +28,6 @@ function convertAnthropicToolsToOpenAI(tools) {
|
|
|
18
28
|
}));
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
// src/transformer/transformers/AnthropicTypes.ts
|
|
22
|
-
function getThinkLevel(budgetTokens) {
|
|
23
|
-
if (!budgetTokens || budgetTokens <= 0) return "none";
|
|
24
|
-
if (budgetTokens < 4096) return "low";
|
|
25
|
-
if (budgetTokens < 16384) return "medium";
|
|
26
|
-
return "high";
|
|
27
|
-
}
|
|
28
|
-
function formatBase64(data, mediaType) {
|
|
29
|
-
if (data.startsWith("data:")) return data;
|
|
30
|
-
return `data:${mediaType || "image/png"};base64,${data}`;
|
|
31
|
-
}
|
|
32
|
-
function flattenToolResultContent(content) {
|
|
33
|
-
if (typeof content === "string") return content;
|
|
34
|
-
if (content == null) return "";
|
|
35
|
-
if (!Array.isArray(content)) return JSON.stringify(content);
|
|
36
|
-
const parts = [];
|
|
37
|
-
for (const block of content) {
|
|
38
|
-
if (typeof block === "string") {
|
|
39
|
-
parts.push(block);
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (!block || typeof block !== "object") continue;
|
|
43
|
-
const typed = block;
|
|
44
|
-
if (typed.type === "image" || typed.type === "image_url") {
|
|
45
|
-
parts.push("[image omitted]");
|
|
46
|
-
} else if (typeof typed.text === "string") {
|
|
47
|
-
parts.push(typed.text);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return parts.filter((text) => text !== "").join("\n");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
31
|
// src/anthropicMaxTokens.ts
|
|
54
32
|
import { lookupCanonicalCapabilities } from "@omnicross/contracts/canonical-models";
|
|
55
33
|
var ANTHROPIC_FALLBACK_MAX_TOKENS = 128e3;
|
|
@@ -65,7 +43,7 @@ function resolveAnthropicMaxTokens(model, requested) {
|
|
|
65
43
|
}
|
|
66
44
|
|
|
67
45
|
// src/transformer/transformers/AnthropicRequestBuilder.ts
|
|
68
|
-
function buildAnthropicRequestBody(request) {
|
|
46
|
+
function buildAnthropicRequestBody(request, provider) {
|
|
69
47
|
let systemContent;
|
|
70
48
|
const anthropicMessages = [];
|
|
71
49
|
for (let i = 0; i < request.messages.length; i++) {
|
|
@@ -202,10 +180,18 @@ function buildAnthropicRequestBody(request) {
|
|
|
202
180
|
body.tool_choice = { type: "tool", name: request.tool_choice.function.name };
|
|
203
181
|
}
|
|
204
182
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
183
|
+
const reasoningPlan = resolveReasoningPlan({
|
|
184
|
+
intent: extractReasoningIntent(request),
|
|
185
|
+
model: request.model,
|
|
186
|
+
provider,
|
|
187
|
+
target: "anthropic",
|
|
188
|
+
requestMaxTokens: request.max_tokens
|
|
189
|
+
});
|
|
190
|
+
if (reasoningPlan?.kind === "level" && reasoningPlan.enabled) {
|
|
191
|
+
body.thinking = { type: "adaptive" };
|
|
192
|
+
body.output_config = { effort: reasoningPlan.effort };
|
|
193
|
+
} else if (reasoningPlan?.kind === "budget" && reasoningPlan.enabled) {
|
|
194
|
+
body.thinking = { type: "enabled", budget_tokens: reasoningPlan.budgetTokens };
|
|
209
195
|
body.temperature = 1;
|
|
210
196
|
}
|
|
211
197
|
return body;
|
|
@@ -461,10 +447,18 @@ function transformAnthropicRequestToUnified(request) {
|
|
|
461
447
|
result._serverSideTools = serverSideTools;
|
|
462
448
|
}
|
|
463
449
|
if (anthropicRequest.thinking) {
|
|
464
|
-
|
|
465
|
-
effort:
|
|
466
|
-
|
|
467
|
-
|
|
450
|
+
if (anthropicRequest.thinking.type === "disabled") {
|
|
451
|
+
result.reasoning = { effort: "none", enabled: false };
|
|
452
|
+
} else if (anthropicRequest.thinking.type === "adaptive") {
|
|
453
|
+
const effort = normalizeThinkLevel(anthropicRequest.output_config?.effort);
|
|
454
|
+
if (effort) result.reasoning = { effort, enabled: effort !== "none" };
|
|
455
|
+
} else {
|
|
456
|
+
result.reasoning = {
|
|
457
|
+
effort: getThinkLevel(anthropicRequest.thinking.budget_tokens),
|
|
458
|
+
enabled: true,
|
|
459
|
+
...typeof anthropicRequest.thinking.budget_tokens === "number" ? { max_tokens: anthropicRequest.thinking.budget_tokens } : {}
|
|
460
|
+
};
|
|
461
|
+
}
|
|
468
462
|
}
|
|
469
463
|
if (anthropicRequest.tool_choice) {
|
|
470
464
|
if (anthropicRequest.tool_choice.type === "tool" && anthropicRequest.tool_choice.name) {
|
|
@@ -994,8 +988,8 @@ var AnthropicTransformer = class {
|
|
|
994
988
|
* This is the reverse of transformRequestOut — converts OpenAI/unified format
|
|
995
989
|
* to Anthropic's expected request body structure.
|
|
996
990
|
*/
|
|
997
|
-
async transformRequestIn(request,
|
|
998
|
-
return buildAnthropicRequestBody(request);
|
|
991
|
+
async transformRequestIn(request, provider, _context) {
|
|
992
|
+
return buildAnthropicRequestBody(request, provider);
|
|
999
993
|
}
|
|
1000
994
|
/**
|
|
1001
995
|
* Transform Anthropic response to OpenAI/unified format
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// src/reasoning/reasoning-plan.ts
|
|
2
|
+
import {
|
|
3
|
+
applyAlias,
|
|
4
|
+
normalizeModelId,
|
|
5
|
+
resolveModelCapabilities
|
|
6
|
+
} from "@omnicross/contracts/canonical-models";
|
|
7
|
+
import {
|
|
8
|
+
EFFORT_RATIO,
|
|
9
|
+
findLegacyTokenLimit
|
|
10
|
+
} from "@omnicross/contracts/thinking-config";
|
|
11
|
+
var THINK_LEVELS = [
|
|
12
|
+
"none",
|
|
13
|
+
"minimal",
|
|
14
|
+
"low",
|
|
15
|
+
"medium",
|
|
16
|
+
"high",
|
|
17
|
+
"xhigh",
|
|
18
|
+
"max"
|
|
19
|
+
];
|
|
20
|
+
var THINK_LEVEL_SET = new Set(THINK_LEVELS);
|
|
21
|
+
var ANTHROPIC_FALLBACK_BUDGET = {
|
|
22
|
+
minimal: 1024,
|
|
23
|
+
low: 2048,
|
|
24
|
+
medium: 8192,
|
|
25
|
+
high: 32768,
|
|
26
|
+
xhigh: 32768,
|
|
27
|
+
max: 32768
|
|
28
|
+
};
|
|
29
|
+
function normalizeThinkLevel(value) {
|
|
30
|
+
if (typeof value !== "string") return void 0;
|
|
31
|
+
const normalized = value.toLowerCase();
|
|
32
|
+
return THINK_LEVEL_SET.has(normalized) ? normalized : void 0;
|
|
33
|
+
}
|
|
34
|
+
function extractReasoningIntent(request) {
|
|
35
|
+
const reasoning = request.reasoning;
|
|
36
|
+
if (reasoning) {
|
|
37
|
+
if (reasoning.enabled === false) {
|
|
38
|
+
return { ...reasoning, effort: "none", enabled: false };
|
|
39
|
+
}
|
|
40
|
+
const effort = normalizeThinkLevel(reasoning.effort);
|
|
41
|
+
if (effort) {
|
|
42
|
+
return { ...reasoning, effort, enabled: effort !== "none" };
|
|
43
|
+
}
|
|
44
|
+
if (reasoning.enabled === true || isPositiveFinite(reasoning.max_tokens)) {
|
|
45
|
+
return { ...reasoning, effort: "medium", enabled: true };
|
|
46
|
+
}
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
const nativeEffort = normalizeThinkLevel(request.reasoning_effort);
|
|
50
|
+
if (!nativeEffort) return void 0;
|
|
51
|
+
return { effort: nativeEffort, enabled: nativeEffort !== "none" };
|
|
52
|
+
}
|
|
53
|
+
function canonicalModelId(model) {
|
|
54
|
+
return applyAlias(normalizeModelId(model));
|
|
55
|
+
}
|
|
56
|
+
function findModelOverride(targetModel, modelConfigs) {
|
|
57
|
+
if (!modelConfigs) return void 0;
|
|
58
|
+
const targetId = canonicalModelId(targetModel);
|
|
59
|
+
return modelConfigs.find(
|
|
60
|
+
(config) => config.id === targetModel || canonicalModelId(config.id) === targetId
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function resolveTargetModelCapabilities(targetModel, provider) {
|
|
64
|
+
const rowOverride = findModelOverride(targetModel, provider?.modelConfigs);
|
|
65
|
+
return resolveModelCapabilities(targetModel, void 0, rowOverride);
|
|
66
|
+
}
|
|
67
|
+
function resolveReasoningEffort(requested, targetModel, provider) {
|
|
68
|
+
if (requested === "none") return "none";
|
|
69
|
+
const capabilities = resolveTargetModelCapabilities(targetModel, provider);
|
|
70
|
+
const candidates = capabilities.thinkingLevels?.map(normalizeThinkLevel).filter((level) => level !== void 0 && level !== "none") ?? [];
|
|
71
|
+
if (candidates.includes(requested)) return requested;
|
|
72
|
+
if (capabilities.thinkingLevels?.length && candidates.length === 0) return "none";
|
|
73
|
+
if (candidates.length === 0) return requested;
|
|
74
|
+
const requestedRatio = EFFORT_RATIO[requested];
|
|
75
|
+
return candidates.reduce((best, candidate) => {
|
|
76
|
+
const distance = Math.abs(EFFORT_RATIO[candidate] - requestedRatio);
|
|
77
|
+
const bestDistance = Math.abs(EFFORT_RATIO[best] - requestedRatio);
|
|
78
|
+
if (distance < bestDistance - Number.EPSILON) return candidate;
|
|
79
|
+
if (Math.abs(distance - bestDistance) <= Number.EPSILON && EFFORT_RATIO[candidate] < EFFORT_RATIO[best]) {
|
|
80
|
+
return candidate;
|
|
81
|
+
}
|
|
82
|
+
return best;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function protocolFallback(model, target) {
|
|
86
|
+
if (target === "anthropic") return { min: 1024, max: 128e3 };
|
|
87
|
+
if (target === "gemini") {
|
|
88
|
+
return model.toLowerCase().includes("pro") ? { min: 128, max: 32768 } : { min: 0, max: 24576 };
|
|
89
|
+
}
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
function resolveTokenLimit(model, provider, target) {
|
|
93
|
+
const capabilities = resolveTargetModelCapabilities(model, provider);
|
|
94
|
+
if (capabilities.thinkingTokenLimit) {
|
|
95
|
+
return { limits: capabilities.thinkingTokenLimit, source: "capability" };
|
|
96
|
+
}
|
|
97
|
+
const legacy = findLegacyTokenLimit(model);
|
|
98
|
+
if (legacy) return { limits: legacy, source: "legacy" };
|
|
99
|
+
const fallback = protocolFallback(model, target);
|
|
100
|
+
return fallback ? { limits: fallback, source: "protocol" } : void 0;
|
|
101
|
+
}
|
|
102
|
+
function resolveReasoningTokenLimit(model, provider, target) {
|
|
103
|
+
return resolveTokenLimit(model, provider, target)?.limits;
|
|
104
|
+
}
|
|
105
|
+
function isPositiveFinite(value) {
|
|
106
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
107
|
+
}
|
|
108
|
+
function isFiniteNumber(value) {
|
|
109
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
110
|
+
}
|
|
111
|
+
function clampBudget(rawBudget, limits, target, effort, requestMaxTokens, explicitBudget = false) {
|
|
112
|
+
const protocolMin = target === "anthropic" ? 1024 : 0;
|
|
113
|
+
const min = Math.max(protocolMin, Math.floor(limits.min));
|
|
114
|
+
let max = Math.max(min, Math.floor(limits.max));
|
|
115
|
+
if (isPositiveFinite(requestMaxTokens)) {
|
|
116
|
+
const requestCeiling = target === "anthropic" ? explicitBudget ? Math.floor(requestMaxTokens) - 1 : Math.max(
|
|
117
|
+
min,
|
|
118
|
+
Math.floor(requestMaxTokens * Math.min(EFFORT_RATIO[effort], 0.75))
|
|
119
|
+
) : Math.floor(requestMaxTokens);
|
|
120
|
+
if (requestCeiling < min) return void 0;
|
|
121
|
+
max = Math.min(max, requestCeiling);
|
|
122
|
+
}
|
|
123
|
+
return Math.max(min, Math.min(max, Math.floor(rawBudget)));
|
|
124
|
+
}
|
|
125
|
+
function resolveBudget(intent, effort, model, provider, target, requestMaxTokens) {
|
|
126
|
+
const resolved = resolveTokenLimit(model, provider, target);
|
|
127
|
+
if (!resolved) return void 0;
|
|
128
|
+
const { limits, source } = resolved;
|
|
129
|
+
const explicitBudget = isFiniteNumber(intent.max_tokens) ? Math.floor(intent.max_tokens) : void 0;
|
|
130
|
+
const interpolated = source === "protocol" && target === "anthropic" ? ANTHROPIC_FALLBACK_BUDGET[effort] : Math.floor((limits.max - limits.min) * EFFORT_RATIO[effort] + limits.min);
|
|
131
|
+
return clampBudget(
|
|
132
|
+
explicitBudget ?? interpolated,
|
|
133
|
+
limits,
|
|
134
|
+
target,
|
|
135
|
+
effort,
|
|
136
|
+
requestMaxTokens,
|
|
137
|
+
explicitBudget !== void 0
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
function resolveReasoningPlan(input) {
|
|
141
|
+
const normalizedIntent = input.intent ? extractReasoningIntent({ model: input.model, reasoning: input.intent }) : void 0;
|
|
142
|
+
if (!normalizedIntent?.effort) return void 0;
|
|
143
|
+
const capabilities = resolveTargetModelCapabilities(input.model, input.provider);
|
|
144
|
+
const nativeEffort = normalizedIntent.effort;
|
|
145
|
+
if (nativeEffort === "none") {
|
|
146
|
+
if (input.target === "gemini" && capabilities.thinkingLevels?.length && capabilities.thinkingLevels.includes("none")) {
|
|
147
|
+
return { kind: "level", effort: "none", enabled: false };
|
|
148
|
+
}
|
|
149
|
+
if (input.target === "gemini" && !capabilities.thinkingLevels?.length) {
|
|
150
|
+
const limits = resolveTokenLimit(input.model, input.provider, input.target)?.limits;
|
|
151
|
+
if (limits?.min === 0) {
|
|
152
|
+
return { kind: "budget", effort: "none", enabled: false, budgetTokens: 0 };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { kind: "off" };
|
|
156
|
+
}
|
|
157
|
+
if (capabilities.thinkingLevels?.length && !capabilities.thinkingLevels.some((level) => level !== "none")) {
|
|
158
|
+
return { kind: "off" };
|
|
159
|
+
}
|
|
160
|
+
const effort = input.preserveNativeEffort ? nativeEffort : resolveReasoningEffort(nativeEffort, input.model, input.provider);
|
|
161
|
+
if (effort === "none") return { kind: "off" };
|
|
162
|
+
if (input.target === "openai-chat" || input.target === "openai-responses") {
|
|
163
|
+
return { kind: "level", effort, enabled: true };
|
|
164
|
+
}
|
|
165
|
+
if (capabilities.thinkingLevels?.length) {
|
|
166
|
+
return { kind: "level", effort, enabled: true };
|
|
167
|
+
}
|
|
168
|
+
const budgetTokens = resolveBudget(
|
|
169
|
+
normalizedIntent,
|
|
170
|
+
effort,
|
|
171
|
+
input.model,
|
|
172
|
+
input.provider,
|
|
173
|
+
input.target,
|
|
174
|
+
input.requestMaxTokens
|
|
175
|
+
);
|
|
176
|
+
if (budgetTokens === void 0) return { kind: "off" };
|
|
177
|
+
return { kind: "budget", effort, enabled: true, budgetTokens };
|
|
178
|
+
}
|
|
179
|
+
function resolveRequestReasoning(request, provider, options = {}) {
|
|
180
|
+
const intent = extractReasoningIntent(request);
|
|
181
|
+
if (!intent?.effort) return void 0;
|
|
182
|
+
const plan = resolveReasoningPlan({
|
|
183
|
+
intent,
|
|
184
|
+
model: request.model,
|
|
185
|
+
provider,
|
|
186
|
+
target: "openai-chat",
|
|
187
|
+
preserveNativeEffort: options.preserveNativeEffort
|
|
188
|
+
});
|
|
189
|
+
if (!plan) return void 0;
|
|
190
|
+
if (plan.kind === "off") return { ...intent, effort: "none", enabled: false };
|
|
191
|
+
return { ...intent, effort: plan.effort, enabled: plan.enabled };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export {
|
|
195
|
+
THINK_LEVELS,
|
|
196
|
+
normalizeThinkLevel,
|
|
197
|
+
extractReasoningIntent,
|
|
198
|
+
resolveTargetModelCapabilities,
|
|
199
|
+
resolveReasoningEffort,
|
|
200
|
+
resolveReasoningTokenLimit,
|
|
201
|
+
resolveReasoningPlan,
|
|
202
|
+
resolveRequestReasoning
|
|
203
|
+
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AnthropicTransformer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HKB656B4.js";
|
|
4
4
|
import {
|
|
5
5
|
GeminiTransformer
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-55FMGZ3L.js";
|
|
7
7
|
import {
|
|
8
8
|
OpenAIResponseTransformer
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-45FHEOKW.js";
|
|
10
10
|
import {
|
|
11
11
|
OpenAITransformer
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-CCVRRJOX.js";
|
|
13
13
|
import {
|
|
14
14
|
GeminiCodeAssistTransformer
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-2UTGX6FM.js";
|
|
16
16
|
|
|
17
17
|
// src/transformer/transformers/index.ts
|
|
18
18
|
var BuiltinTransformers = {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkRICPANBYcjs = require('./chunk-RICPANBY.cjs');
|
|
7
7
|
|
|
8
8
|
// src/transformer/transformers/GeminiCodeAssistTransformer.ts
|
|
9
9
|
var DEFAULT_CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
@@ -117,7 +117,7 @@ var GeminiCodeAssistTransformer = (_class = class {constructor() { _class.protot
|
|
|
117
117
|
* openaiResponsesIngress). `undefined` is the valid fresh free-tier value.
|
|
118
118
|
*/
|
|
119
119
|
async transformRequestIn(request, provider, _context) {
|
|
120
|
-
const inner =
|
|
120
|
+
const inner = _chunkRICPANBYcjs.buildRequestBody.call(void 0, request, provider);
|
|
121
121
|
const envelope = {
|
|
122
122
|
model: request.model,
|
|
123
123
|
project: provider.geminiProject,
|
|
@@ -147,7 +147,7 @@ var GeminiCodeAssistTransformer = (_class = class {constructor() { _class.protot
|
|
|
147
147
|
if (inner && typeof inner === "object" && !("model" in inner) && "model" in r) {
|
|
148
148
|
inner.model = r.model;
|
|
149
149
|
}
|
|
150
|
-
return
|
|
150
|
+
return _chunkRICPANBYcjs.transformRequestOut.call(void 0, inner);
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
153
|
* Code Assist response → OpenAI-compatible. PEEL the `.response` envelope from
|
|
@@ -155,7 +155,7 @@ var GeminiCodeAssistTransformer = (_class = class {constructor() { _class.protot
|
|
|
155
155
|
*/
|
|
156
156
|
async transformResponseOut(response, _context) {
|
|
157
157
|
const unwrapped = await unwrapCodeAssistResponse(response);
|
|
158
|
-
return
|
|
158
|
+
return _chunkRICPANBYcjs.transformResponseOut.call(void 0, unwrapped, this.name, this.logger);
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* OpenAI-compatible response → Code Assist (endpoint-encode parity). Re-wraps
|
|
@@ -164,7 +164,7 @@ var GeminiCodeAssistTransformer = (_class = class {constructor() { _class.protot
|
|
|
164
164
|
* `transformResponseOut`'s peel.
|
|
165
165
|
*/
|
|
166
166
|
async transformResponseIn(response, _context) {
|
|
167
|
-
const geminiResponse = await
|
|
167
|
+
const geminiResponse = await _chunkRICPANBYcjs.transformResponseIn.call(void 0, response, this.logger);
|
|
168
168
|
const contentType = _nullishCoalesce(geminiResponse.headers.get("Content-Type"), () => ( ""));
|
|
169
169
|
if (contentType.includes("text/event-stream")) {
|
|
170
170
|
return geminiResponse;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkZQQUD66Mcjs = require('./chunk-ZQQUD66M.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk5LNYGCIWcjs = require('./chunk-5LNYGCIW.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkCMVXX7ONcjs = require('./chunk-CMVXX7ON.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunk56QD3YW6cjs = require('./chunk-56QD3YW6.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkOC6DOOFXcjs = require('./chunk-OC6DOOFX.cjs');
|
|
16
16
|
|
|
17
17
|
// src/transformer/transformers/index.ts
|
|
18
18
|
var BuiltinTransformers = {
|
|
19
|
-
OpenAITransformer:
|
|
20
|
-
GeminiTransformer:
|
|
21
|
-
GeminiCodeAssistTransformer:
|
|
22
|
-
AnthropicTransformer:
|
|
23
|
-
OpenAIResponseTransformer:
|
|
19
|
+
OpenAITransformer: _chunk56QD3YW6cjs.OpenAITransformer,
|
|
20
|
+
GeminiTransformer: _chunk5LNYGCIWcjs.GeminiTransformer,
|
|
21
|
+
GeminiCodeAssistTransformer: _chunkOC6DOOFXcjs.GeminiCodeAssistTransformer,
|
|
22
|
+
AnthropicTransformer: _chunkZQQUD66Mcjs.AnthropicTransformer,
|
|
23
|
+
OpenAIResponseTransformer: _chunkCMVXX7ONcjs.OpenAIResponseTransformer
|
|
24
24
|
};
|
|
25
25
|
function getBuiltinTransformers() {
|
|
26
26
|
return BuiltinTransformers;
|