@omnicross/core 0.1.6 → 0.1.7
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/ApiConverter.cjs +2 -2
- package/dist/ApiConverter.js +1 -1
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +4 -3
- package/dist/auth/GeminiCodeAssistProjectResolver.js +3 -2
- package/dist/{chunk-3Z5BQZFM.cjs → chunk-235MXAGX.cjs} +3 -1
- package/dist/{chunk-DLXZEZWO.cjs → chunk-2E42SAW3.cjs} +42 -4
- package/dist/{chunk-7AK7B36B.cjs → chunk-2Z4XM3H5.cjs} +6 -6
- package/dist/{chunk-OEWZUX4G.js → chunk-32O35CIF.js} +9 -20
- package/dist/chunk-3SCOLIPT.cjs +63 -0
- package/dist/{chunk-SYQF7OIR.js → chunk-3WD4HTR2.js} +2 -0
- package/dist/{chunk-SQYVORNP.cjs → chunk-4BB343BI.cjs} +527 -267
- package/dist/{chunk-AT7B7SOZ.js → chunk-5NJLQ6T6.js} +21 -10
- package/dist/chunk-5RSZYQJH.cjs +62 -0
- package/dist/{chunk-IFXJ2BG7.js → chunk-7C7DET6S.js} +51 -6
- package/dist/{chunk-UDCC7EMR.js → chunk-E3COOKUP.js} +307 -47
- package/dist/chunk-FU7EAR73.js +62 -0
- package/dist/{chunk-UX7VWA46.js → chunk-FXR6N3SR.js} +39 -1
- package/dist/{chunk-WYTEQ4Q5.cjs → chunk-GDIXXKF2.cjs} +21 -10
- package/dist/{chunk-WB6PH56J.js → chunk-GFIZ6LQI.js} +12 -8
- package/dist/chunk-GL6XM527.js +61 -0
- package/dist/{chunk-EJLH6NFT.cjs → chunk-J3QQ6JS5.cjs} +12 -8
- package/dist/{chunk-VRFBB5DB.js → chunk-MYYR3HZL.js} +4 -4
- package/dist/{chunk-YJVHCHQX.js → chunk-N7OOJI5V.js} +46 -2
- package/dist/chunk-NKVZ6Z3Y.cjs +61 -0
- package/dist/{chunk-SNYBEXLB.cjs → chunk-OJGQKHN5.cjs} +3 -1
- package/dist/chunk-OTZC4TNH.cjs +79 -0
- package/dist/{chunk-6VUQPOV3.cjs → chunk-OVQBNVSV.cjs} +10 -21
- package/dist/{chunk-4VLRHHFE.cjs → chunk-OXHNSZ53.cjs} +9 -11
- package/dist/{chunk-6CL5HTPQ.js → chunk-PEGTIPB3.js} +8 -10
- package/dist/chunk-PO3XB56Z.js +79 -0
- package/dist/{chunk-SIZQQD6T.js → chunk-RJ5ZGNI3.js} +42 -5
- package/dist/{chunk-KCVJWJST.cjs → chunk-RJUONLUQ.cjs} +47 -10
- package/dist/{chunk-BPKCU575.js → chunk-SOO562NM.js} +3 -1
- package/dist/{chunk-UNWKG6EI.cjs → chunk-XPIOJQS2.cjs} +51 -6
- package/dist/chunk-XXFYLL7R.js +63 -0
- package/dist/{chunk-YK57NMIF.cjs → chunk-YWL7YZWS.cjs} +47 -3
- package/dist/completion/CompletionService.cjs +23 -19
- package/dist/completion/CompletionService.d.cts +1 -0
- package/dist/completion/CompletionService.d.ts +1 -0
- package/dist/completion/CompletionService.js +22 -18
- package/dist/completion.cjs +23 -19
- package/dist/completion.d.cts +1 -0
- package/dist/completion.d.ts +1 -0
- package/dist/completion.js +22 -18
- package/dist/index.cjs +26 -22
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +26 -22
- package/dist/outbound-api/auditCapture.cjs +2 -2
- package/dist/outbound-api/auditCapture.d.cts +3 -4
- package/dist/outbound-api/auditCapture.d.ts +3 -4
- package/dist/outbound-api/auditCapture.js +1 -1
- package/dist/outbound-api/routeResolver.d.cts +3 -2
- package/dist/outbound-api/routeResolver.d.ts +3 -2
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
- package/dist/outbound-api/types.d.cts +2 -1
- package/dist/outbound-api/types.d.ts +2 -1
- package/dist/outbound-api.cjs +23 -19
- package/dist/outbound-api.d.cts +7 -5
- package/dist/outbound-api.d.ts +7 -5
- package/dist/outbound-api.js +22 -18
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +2 -1
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +2 -1
- package/dist/pipeline/AccountRouteActivity.cjs +10 -0
- package/dist/pipeline/AccountRouteActivity.d.cts +61 -0
- package/dist/pipeline/AccountRouteActivity.d.ts +61 -0
- package/dist/pipeline/AccountRouteActivity.js +10 -0
- package/dist/pipeline/ServerOverloadCounter.cjs +16 -0
- package/dist/pipeline/ServerOverloadCounter.d.cts +77 -0
- package/dist/pipeline/ServerOverloadCounter.d.ts +77 -0
- package/dist/pipeline/ServerOverloadCounter.js +16 -0
- package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
- package/dist/pipeline/SubscriptionAccountHealth.d.cts +32 -3
- package/dist/pipeline/SubscriptionAccountHealth.d.ts +32 -3
- package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
- package/dist/pipeline/upstreamFetch.cjs +4 -3
- package/dist/pipeline/upstreamFetch.d.cts +35 -6
- package/dist/pipeline/upstreamFetch.d.ts +35 -6
- package/dist/pipeline/upstreamFetch.js +3 -2
- package/dist/pipeline/upstreamTrace.cjs +4 -2
- package/dist/pipeline/upstreamTrace.d.cts +22 -8
- package/dist/pipeline/upstreamTrace.d.ts +22 -8
- package/dist/pipeline/upstreamTrace.js +3 -1
- package/dist/ports.d.cts +1 -1
- package/dist/ports.d.ts +1 -1
- package/dist/provider-proxy/ProviderProxy.cjs +23 -19
- package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
- package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
- package/dist/provider-proxy/ProviderProxy.js +22 -18
- package/dist/provider-proxy/identity/codexCliHeaders.cjs +10 -0
- package/dist/provider-proxy/identity/codexCliHeaders.d.cts +45 -0
- package/dist/provider-proxy/identity/codexCliHeaders.d.ts +45 -0
- package/dist/provider-proxy/identity/codexCliHeaders.js +10 -0
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +23 -19
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +11 -1
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +11 -1
- package/dist/provider-proxy/ingress/providerProxyShared.js +22 -18
- package/dist/provider-proxy/matchText.cjs +2 -2
- package/dist/provider-proxy/matchText.d.cts +1 -3
- package/dist/provider-proxy/matchText.d.ts +1 -3
- package/dist/provider-proxy/matchText.js +1 -1
- package/dist/provider-proxy/types.d.cts +5 -0
- package/dist/provider-proxy/types.d.ts +5 -0
- package/dist/provider-proxy.cjs +23 -19
- package/dist/provider-proxy.d.cts +1 -0
- package/dist/provider-proxy.d.ts +1 -0
- package/dist/provider-proxy.js +22 -18
- package/dist/{routeResolver-CHTv_Bs5.d.ts → routeResolver-BxOfunbm.d.ts} +1 -1
- package/dist/{routeResolver-kepxnfcC.d.cts → routeResolver-D5OzD0iM.d.cts} +1 -1
- package/dist/transformer/transformers/AnthropicTransformer.cjs +3 -2
- package/dist/transformer/transformers/AnthropicTransformer.js +2 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -1
- package/dist/transformer/transformers.cjs +7 -6
- package/dist/transformer/transformers.js +6 -5
- package/dist/transformer.cjs +9 -8
- package/dist/transformer.js +8 -7
- package/dist/{types-hsoKrVQS.d.ts → types-CqZD77rS.d.ts} +39 -0
- package/dist/{types-H3wGZSOo.d.cts → types-gjJ5lJ5n.d.cts} +39 -0
- package/dist/usage/pricing-engine.cjs +2 -2
- package/dist/usage/pricing-engine.d.cts +20 -0
- package/dist/usage/pricing-engine.d.ts +20 -0
- package/dist/usage/pricing-engine.js +1 -1
- package/dist/usage/usage-recorder.cjs +2 -2
- package/dist/usage/usage-recorder.d.cts +5 -1
- package/dist/usage/usage-recorder.d.ts +5 -1
- package/dist/usage/usage-recorder.js +1 -1
- package/dist/usage.cjs +3 -3
- package/dist/usage.js +2 -2
- package/package.json +1 -1
|
@@ -81,6 +81,20 @@ function flattenToolResultContent(content) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// src/api-converter/anthropic-to-openai.ts
|
|
84
|
+
function anthropicUsageToChatUsage(usage) {
|
|
85
|
+
const input = usage.input_tokens || 0;
|
|
86
|
+
const output = usage.output_tokens || 0;
|
|
87
|
+
const cacheRead = usage.cache_read_input_tokens || 0;
|
|
88
|
+
const cacheCreation = usage.cache_creation_input_tokens || 0;
|
|
89
|
+
const promptTokens = input + cacheRead + cacheCreation;
|
|
90
|
+
const out = {
|
|
91
|
+
prompt_tokens: promptTokens,
|
|
92
|
+
completion_tokens: output,
|
|
93
|
+
total_tokens: promptTokens + output
|
|
94
|
+
};
|
|
95
|
+
if (cacheRead > 0) out.prompt_tokens_details = { cached_tokens: cacheRead };
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
84
98
|
function convertAnthropicToOpenAI(response) {
|
|
85
99
|
const content = [];
|
|
86
100
|
const toolCalls = [];
|
|
@@ -118,11 +132,7 @@ function convertAnthropicToOpenAI(response) {
|
|
|
118
132
|
finish_reason: finishReason
|
|
119
133
|
}
|
|
120
134
|
],
|
|
121
|
-
usage:
|
|
122
|
-
prompt_tokens: response.usage.input_tokens,
|
|
123
|
-
completion_tokens: response.usage.output_tokens,
|
|
124
|
-
total_tokens: response.usage.input_tokens + response.usage.output_tokens
|
|
125
|
-
}
|
|
135
|
+
usage: anthropicUsageToChatUsage(response.usage)
|
|
126
136
|
};
|
|
127
137
|
if (reasoningContent) {
|
|
128
138
|
result.reasoning_content = reasoningContent;
|
|
@@ -352,11 +362,12 @@ async function* convertAnthropicStreamToOpenAI(anthropicStream) {
|
|
|
352
362
|
delta: {},
|
|
353
363
|
finish_reason: finishReason
|
|
354
364
|
}],
|
|
355
|
-
usage: event.usage ? {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
365
|
+
usage: event.usage ? anthropicUsageToChatUsage({
|
|
366
|
+
input_tokens: event.usage.input_tokens || 0,
|
|
367
|
+
output_tokens: event.usage.output_tokens || 0,
|
|
368
|
+
cache_read_input_tokens: event.usage.cache_read_input_tokens,
|
|
369
|
+
cache_creation_input_tokens: event.usage.cache_creation_input_tokens
|
|
370
|
+
}) : void 0
|
|
360
371
|
})}
|
|
361
372
|
|
|
362
373
|
`;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/transformer/transformers/utils/usage-mapping.ts
|
|
2
|
+
function num(obj, key) {
|
|
3
|
+
const v = _optionalChain([obj, 'optionalAccess', _ => _[key]]);
|
|
4
|
+
return typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
5
|
+
}
|
|
6
|
+
function detailCachedTokens(obj, detailKey) {
|
|
7
|
+
const detail = _optionalChain([obj, 'optionalAccess', _2 => _2[detailKey]]);
|
|
8
|
+
return num(detail, "cached_tokens");
|
|
9
|
+
}
|
|
10
|
+
function anthropicUsageToChatUsage(usage) {
|
|
11
|
+
if (!usage) return void 0;
|
|
12
|
+
const input = num(usage, "input_tokens");
|
|
13
|
+
const output = num(usage, "output_tokens");
|
|
14
|
+
const cacheRead = num(usage, "cache_read_input_tokens");
|
|
15
|
+
const cacheCreation = num(usage, "cache_creation_input_tokens");
|
|
16
|
+
const promptTokens = input + cacheRead + cacheCreation;
|
|
17
|
+
const out = {
|
|
18
|
+
prompt_tokens: promptTokens,
|
|
19
|
+
completion_tokens: output,
|
|
20
|
+
total_tokens: promptTokens + output
|
|
21
|
+
};
|
|
22
|
+
if (cacheRead > 0) {
|
|
23
|
+
out.prompt_tokens_details = { cached_tokens: cacheRead };
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function chatUsageToResponsesUsage(usage) {
|
|
28
|
+
if (!usage) return void 0;
|
|
29
|
+
const prompt = num(usage, "prompt_tokens");
|
|
30
|
+
const completion = num(usage, "completion_tokens");
|
|
31
|
+
const out = {
|
|
32
|
+
input_tokens: prompt,
|
|
33
|
+
output_tokens: completion,
|
|
34
|
+
total_tokens: num(usage, "total_tokens") || prompt + completion
|
|
35
|
+
};
|
|
36
|
+
const cacheRead = detailCachedTokens(usage, "prompt_tokens_details");
|
|
37
|
+
if (cacheRead > 0) {
|
|
38
|
+
out.input_tokens_details = { cached_tokens: cacheRead };
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
function responsesUsageToChatUsage(usage) {
|
|
43
|
+
if (!usage) return void 0;
|
|
44
|
+
const input = num(usage, "input_tokens");
|
|
45
|
+
const output = num(usage, "output_tokens");
|
|
46
|
+
const out = {
|
|
47
|
+
prompt_tokens: input,
|
|
48
|
+
completion_tokens: output,
|
|
49
|
+
total_tokens: num(usage, "total_tokens") || input + output
|
|
50
|
+
};
|
|
51
|
+
const cacheRead = detailCachedTokens(usage, "input_tokens_details");
|
|
52
|
+
if (cacheRead > 0) {
|
|
53
|
+
out.prompt_tokens_details = { cached_tokens: cacheRead };
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
exports.anthropicUsageToChatUsage = anthropicUsageToChatUsage; exports.chatUsageToResponsesUsage = chatUsageToResponsesUsage; exports.responsesUsageToChatUsage = responsesUsageToChatUsage;
|
|
@@ -11,6 +11,29 @@ import {
|
|
|
11
11
|
|
|
12
12
|
// src/outbound-api/auditCapture.ts
|
|
13
13
|
import { randomUUID } from "crypto";
|
|
14
|
+
function completeUtf8PrefixLength(buf) {
|
|
15
|
+
if (buf.length === 0) return 0;
|
|
16
|
+
let leadIndex = buf.length - 1;
|
|
17
|
+
while (leadIndex >= 0 && (buf[leadIndex] & 192) === 128) leadIndex -= 1;
|
|
18
|
+
if (leadIndex < 0) return 0;
|
|
19
|
+
const lead = buf[leadIndex];
|
|
20
|
+
let expectedLength = 1;
|
|
21
|
+
if ((lead & 224) === 192) expectedLength = 2;
|
|
22
|
+
else if ((lead & 240) === 224) expectedLength = 3;
|
|
23
|
+
else if ((lead & 248) === 240) expectedLength = 4;
|
|
24
|
+
return buf.length - leadIndex < expectedLength ? leadIndex : buf.length;
|
|
25
|
+
}
|
|
26
|
+
function truncateToBytes(text, maxBytes) {
|
|
27
|
+
if (maxBytes < 0) return text;
|
|
28
|
+
const buf = Buffer.from(text, "utf8");
|
|
29
|
+
if (buf.length <= maxBytes) return text;
|
|
30
|
+
const head = buf.subarray(0, maxBytes);
|
|
31
|
+
return head.subarray(0, completeUtf8PrefixLength(head)).toString("utf8");
|
|
32
|
+
}
|
|
33
|
+
function decodeCapturedBody(body, truncated) {
|
|
34
|
+
if (!truncated) return body.toString("utf8");
|
|
35
|
+
return body.subarray(0, completeUtf8PrefixLength(body)).toString("utf8");
|
|
36
|
+
}
|
|
14
37
|
function resolveClientIp(req, trustForwardedFor) {
|
|
15
38
|
if (trustForwardedFor) {
|
|
16
39
|
const xff = req.headers["x-forwarded-for"];
|
|
@@ -25,18 +48,39 @@ function resolveClientIp(req, trustForwardedFor) {
|
|
|
25
48
|
function beginAuditCapture(req, res, now) {
|
|
26
49
|
const config = getAuditCaptureConfig();
|
|
27
50
|
if (!config) return null;
|
|
28
|
-
let
|
|
51
|
+
let requestBody;
|
|
29
52
|
const responseChunks = [];
|
|
53
|
+
let responseBytes = 0;
|
|
54
|
+
let responseTruncated = false;
|
|
30
55
|
let finished = false;
|
|
31
56
|
const ctx = {
|
|
32
57
|
setRequestBody(raw) {
|
|
33
|
-
if (config.captureBodies)
|
|
58
|
+
if (config.captureBodies) {
|
|
59
|
+
requestBody = truncateToBytes(redactAuditText(raw), config.maxBodyBytes);
|
|
60
|
+
}
|
|
34
61
|
}
|
|
35
62
|
};
|
|
36
63
|
if (config.captureBodies) {
|
|
37
64
|
installResponseCapture(res, {
|
|
38
65
|
push(chunk) {
|
|
66
|
+
if (config.maxBodyBytes < 0) {
|
|
67
|
+
responseChunks.push(chunk);
|
|
68
|
+
responseBytes += chunk.length;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const remaining = config.maxBodyBytes - responseBytes;
|
|
72
|
+
if (remaining <= 0) {
|
|
73
|
+
responseTruncated = true;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (chunk.length > remaining) {
|
|
77
|
+
responseChunks.push(chunk.subarray(0, remaining));
|
|
78
|
+
responseBytes += remaining;
|
|
79
|
+
responseTruncated = true;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
39
82
|
responseChunks.push(chunk);
|
|
83
|
+
responseBytes += chunk.length;
|
|
40
84
|
}
|
|
41
85
|
});
|
|
42
86
|
}
|
|
@@ -69,12 +113,13 @@ function beginAuditCapture(req, res, now) {
|
|
|
69
113
|
}
|
|
70
114
|
if (ctx.error) record.error = redactAuditText(ctx.error);
|
|
71
115
|
if (config.captureBodies) {
|
|
72
|
-
if (
|
|
73
|
-
record.requestBody =
|
|
116
|
+
if (requestBody != null && requestBody.length > 0) {
|
|
117
|
+
record.requestBody = requestBody;
|
|
74
118
|
}
|
|
75
119
|
if (responseChunks.length > 0) {
|
|
76
|
-
const
|
|
77
|
-
|
|
120
|
+
const captured = Buffer.concat(responseChunks, responseBytes);
|
|
121
|
+
const body = decodeCapturedBody(captured, responseTruncated);
|
|
122
|
+
record.responseBody = truncateToBytes(redactAuditText(body), config.maxBodyBytes);
|
|
78
123
|
}
|
|
79
124
|
}
|
|
80
125
|
recordAudit(record);
|