@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
package/dist/ApiConverter.cjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkGDIXXKF2cjs = require('./chunk-GDIXXKF2.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -21,4 +21,4 @@ var _chunkWYTEQ4Q5cjs = require('./chunk-WYTEQ4Q5.cjs');
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
exports.convertAnthropicRequestToOpenAI =
|
|
24
|
+
exports.convertAnthropicRequestToOpenAI = _chunkGDIXXKF2cjs.convertAnthropicRequestToOpenAI; exports.convertAnthropicStreamToOpenAI = _chunkGDIXXKF2cjs.convertAnthropicStreamToOpenAI; exports.convertAnthropicToOpenAI = _chunkGDIXXKF2cjs.convertAnthropicToOpenAI; exports.convertAnthropicToOpenAIWithThinking = _chunkGDIXXKF2cjs.convertAnthropicToOpenAIWithThinking; exports.convertOpenAIResponseToAnthropic = _chunkGDIXXKF2cjs.convertOpenAIResponseToAnthropic; exports.convertOpenAIStreamToAnthropic = _chunkGDIXXKF2cjs.convertOpenAIStreamToAnthropic; exports.convertOpenAIToAnthropic = _chunkGDIXXKF2cjs.convertOpenAIToAnthropic; exports.convertOpenAIToAnthropicWithThinking = _chunkGDIXXKF2cjs.convertOpenAIToAnthropicWithThinking; exports.hasImageContent = _chunkGDIXXKF2cjs.hasImageContent; exports.hasThinkingEnabled = _chunkGDIXXKF2cjs.hasThinkingEnabled;
|
package/dist/ApiConverter.js
CHANGED
|
@@ -5,9 +5,10 @@ var _chunkOKMJLEXXcjs = require('../chunk-OKMJLEXX.cjs');
|
|
|
5
5
|
require('../chunk-KBM2W6UY.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
require('../chunk-
|
|
8
|
+
var _chunkRJUONLUQcjs = require('../chunk-RJUONLUQ.cjs');
|
|
9
|
+
require('../chunk-235MXAGX.cjs');
|
|
10
10
|
require('../chunk-HVBBDBS3.cjs');
|
|
11
|
+
require('../chunk-NKVZ6Z3Y.cjs');
|
|
11
12
|
|
|
12
13
|
// src/auth/GeminiCodeAssistProjectResolver.ts
|
|
13
14
|
var FREE_TIER_ID = "free-tier";
|
|
@@ -27,7 +28,7 @@ var GeminiCodeAssistHandshakeError = class extends Error {
|
|
|
27
28
|
var GeminiCodeAssistProjectResolver = (_class = class {
|
|
28
29
|
// upstream-proxy: the Code Assist handshake is upstream egress → honor the
|
|
29
30
|
// gemini proxy by default (still injectable for tests).
|
|
30
|
-
constructor(fetchImpl = (url, init) =>
|
|
31
|
+
constructor(fetchImpl = (url, init) => _chunkRJUONLUQcjs.fetchUpstream.call(void 0, url, init, { providerId: "gemini" })) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
31
32
|
this.fetchImpl = fetchImpl;
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -5,9 +5,10 @@ import {
|
|
|
5
5
|
import "../chunk-TOVPMMHM.js";
|
|
6
6
|
import {
|
|
7
7
|
fetchUpstream
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
} from "../chunk-RJ5ZGNI3.js";
|
|
9
|
+
import "../chunk-3WD4HTR2.js";
|
|
10
10
|
import "../chunk-MKF46GNZ.js";
|
|
11
|
+
import "../chunk-GL6XM527.js";
|
|
11
12
|
|
|
12
13
|
// src/auth/GeminiCodeAssistProjectResolver.ts
|
|
13
14
|
var FREE_TIER_ID = "free-tier";
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var _promises = require('fs/promises');
|
|
3
3
|
var _path = require('path');
|
|
4
4
|
var tracePath = null;
|
|
5
|
+
var REDACTED_BODY = "***REDACTED (credential exchange)***";
|
|
5
6
|
var SECRET_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
6
7
|
"authorization",
|
|
7
8
|
"api-key",
|
|
@@ -49,4 +50,5 @@ function __resetUpstreamTraceForTests() {
|
|
|
49
50
|
|
|
50
51
|
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
|
|
54
|
+
exports.REDACTED_BODY = REDACTED_BODY; exports.setUpstreamTracePath = setUpstreamTracePath; exports.getUpstreamTracePath = getUpstreamTracePath; exports.redactHeaders = redactHeaders; exports.writeUpstreamTrace = writeUpstreamTrace; exports.__resetUpstreamTraceForTests = __resetUpstreamTraceForTests;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
var _pricingtypes = require('@omnicross/contracts/pricing-types');
|
|
6
6
|
var PricingEngine = (_class = class {
|
|
7
|
-
constructor(store, logger, options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);
|
|
7
|
+
constructor(store, logger, options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);
|
|
8
8
|
this.store = store;
|
|
9
9
|
this.logger = logger;
|
|
10
10
|
this.options = options;
|
|
@@ -21,9 +21,18 @@ var PricingEngine = (_class = class {
|
|
|
21
21
|
* non-wildcard entry per model wins.
|
|
22
22
|
*/
|
|
23
23
|
__init2() {this.cacheByModel = /* @__PURE__ */ new Map()}
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Last-resort fuzzy index: `[normalizedModelId, entry]` pairs over the same
|
|
26
|
+
* non-wildcard, non-openrouter rows as `cacheByModel`. Used when even the
|
|
27
|
+
* model-name fallback misses — e.g. usage recorded under a bare model id
|
|
28
|
+
* (`glm-5.2`) while the catalog only knows prefixed slugs
|
|
29
|
+
* (`cloudflare/@cf/zai-org/glm-5.2`). This is an ESTIMATE: the matched row
|
|
30
|
+
* may be an aggregate-route price rather than the direct-vendor rate.
|
|
31
|
+
*/
|
|
32
|
+
__init3() {this.fuzzyEntries = []}
|
|
33
|
+
__init4() {this.cacheLoaded = false}
|
|
25
34
|
/** Coalesce manual and background refreshes to prevent a catalog stampede. */
|
|
26
|
-
|
|
35
|
+
__init5() {this.refreshInFlight = null}
|
|
27
36
|
// ===== Cache management =====
|
|
28
37
|
/** Lazy-load and cache the full pricing table. */
|
|
29
38
|
async ensureCache() {
|
|
@@ -31,9 +40,11 @@ var PricingEngine = (_class = class {
|
|
|
31
40
|
const rows = await this.store.getAll();
|
|
32
41
|
this.cache = new Map(rows.map((r) => [keyOf(r.providerId, r.modelId), r]));
|
|
33
42
|
this.cacheByModel = /* @__PURE__ */ new Map();
|
|
43
|
+
this.fuzzyEntries = [];
|
|
34
44
|
for (const r of rows) {
|
|
35
45
|
if (r.providerId === "*" || r.providerId === "openrouter" || r.source === "openrouter") continue;
|
|
36
46
|
if (!this.cacheByModel.has(r.modelId)) this.cacheByModel.set(r.modelId, r);
|
|
47
|
+
this.fuzzyEntries.push([normalizeModelId(r.modelId), r]);
|
|
37
48
|
}
|
|
38
49
|
this.cacheLoaded = true;
|
|
39
50
|
}
|
|
@@ -53,10 +64,36 @@ var PricingEngine = (_class = class {
|
|
|
53
64
|
* 2. wildcard provider ('*', modelId)
|
|
54
65
|
* 3. model name alone (any provider) — tolerates a runtime-alias vs
|
|
55
66
|
* canonical provider-id mismatch for the same model.
|
|
67
|
+
* 4. normalized fuzzy match (last resort) — matches a bare id like
|
|
68
|
+
* `glm-5.2` against prefixed catalog slugs like
|
|
69
|
+
* `cloudflare/@cf/zai-org/glm-5.2`. ESTIMATE only: the matched row may
|
|
70
|
+
* be an aggregate-route price, not the direct-vendor rate.
|
|
56
71
|
*/
|
|
57
72
|
async getEntry(providerId, modelId) {
|
|
58
73
|
await this.ensureCache();
|
|
59
|
-
|
|
74
|
+
const exact = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(this.cache.get(keyOf(providerId, modelId)), () => ( this.cache.get(keyOf("*", modelId)))), () => ( this.cacheByModel.get(modelId))), () => ( null));
|
|
75
|
+
if (exact) return exact;
|
|
76
|
+
return this.fuzzyMatch(modelId);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Normalized substring match over the catalog's non-openrouter rows. Lowercases
|
|
80
|
+
* and strips all non-alphanumerics, then matches bidirectionally, preferring
|
|
81
|
+
* the shortest catalog key (tightest match) to reduce over-matching version
|
|
82
|
+
* variants. Returns null when nothing matches.
|
|
83
|
+
*/
|
|
84
|
+
fuzzyMatch(modelId) {
|
|
85
|
+
const normQuery = normalizeModelId(modelId);
|
|
86
|
+
if (!normQuery) return null;
|
|
87
|
+
let best = null;
|
|
88
|
+
let bestLen = Infinity;
|
|
89
|
+
for (const [key, entry] of this.fuzzyEntries) {
|
|
90
|
+
if (!key || !key.includes(normQuery) && !normQuery.includes(key)) continue;
|
|
91
|
+
if (key.length < bestLen) {
|
|
92
|
+
best = entry;
|
|
93
|
+
bestLen = key.length;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return best;
|
|
60
97
|
}
|
|
61
98
|
// ===== Cost calculation =====
|
|
62
99
|
/**
|
|
@@ -187,6 +224,7 @@ var PricingEngine = (_class = class {
|
|
|
187
224
|
}
|
|
188
225
|
}, _class);
|
|
189
226
|
var keyOf = (providerId, modelId) => `${providerId}::${modelId}`;
|
|
227
|
+
var normalizeModelId = (modelId) => (_nullishCoalesce(modelId, () => ( ""))).toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
190
228
|
var PROVIDER_ALIASES = {
|
|
191
229
|
vertex_ai: "gemini",
|
|
192
230
|
google: "gemini",
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkOXHNSZ53cjs = require('./chunk-OXHNSZ53.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkV4TXMEJScjs = require('./chunk-V4TXMEJS.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkOVQBNVSVcjs = require('./chunk-OVQBNVSV.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkOF3BECU2cjs = require('./chunk-OF3BECU2.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
var _chunkOKMJLEXXcjs = require('./chunk-OKMJLEXX.cjs');
|
|
@@ -19,8 +19,8 @@ var BuiltinTransformers = {
|
|
|
19
19
|
OpenAITransformer: _chunkOF3BECU2cjs.OpenAITransformer,
|
|
20
20
|
GeminiTransformer: _chunkV4TXMEJScjs.GeminiTransformer,
|
|
21
21
|
GeminiCodeAssistTransformer: _chunkOKMJLEXXcjs.GeminiCodeAssistTransformer,
|
|
22
|
-
AnthropicTransformer:
|
|
23
|
-
OpenAIResponseTransformer:
|
|
22
|
+
AnthropicTransformer: _chunkOXHNSZ53cjs.AnthropicTransformer,
|
|
23
|
+
OpenAIResponseTransformer: _chunkOVQBNVSVcjs.OpenAIResponseTransformer
|
|
24
24
|
};
|
|
25
25
|
function getBuiltinTransformers() {
|
|
26
26
|
return BuiltinTransformers;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chatUsageToResponsesUsage,
|
|
3
|
+
responsesUsageToChatUsage
|
|
4
|
+
} from "./chunk-FU7EAR73.js";
|
|
5
|
+
|
|
1
6
|
// src/transformer/transformers/OpenAIResponseTransformer.ts
|
|
2
7
|
var OpenAIResponseTransformer = class {
|
|
3
8
|
static TransformerName = "openai-response";
|
|
@@ -433,11 +438,7 @@ function convertResponseApiJsonToOpenAI(data) {
|
|
|
433
438
|
finish_reason: toolCalls.length > 0 ? "tool_calls" : "stop"
|
|
434
439
|
}
|
|
435
440
|
],
|
|
436
|
-
usage: usage
|
|
437
|
-
prompt_tokens: usage.input_tokens || 0,
|
|
438
|
-
completion_tokens: usage.output_tokens || 0,
|
|
439
|
-
total_tokens: (usage.input_tokens || 0) + (usage.output_tokens || 0)
|
|
440
|
-
} : void 0
|
|
441
|
+
usage: responsesUsageToChatUsage(usage)
|
|
441
442
|
};
|
|
442
443
|
}
|
|
443
444
|
function convertOpenAIJsonToResponseApi(data, codexTools) {
|
|
@@ -475,11 +476,7 @@ function convertOpenAIJsonToResponseApi(data, codexTools) {
|
|
|
475
476
|
status: "completed",
|
|
476
477
|
model: data.model || "unknown",
|
|
477
478
|
output,
|
|
478
|
-
usage: usage
|
|
479
|
-
input_tokens: usage.prompt_tokens || 0,
|
|
480
|
-
output_tokens: usage.completion_tokens || 0,
|
|
481
|
-
total_tokens: usage.total_tokens || (usage.prompt_tokens || 0) + (usage.completion_tokens || 0)
|
|
482
|
-
} : void 0
|
|
479
|
+
usage: chatUsageToResponsesUsage(usage)
|
|
483
480
|
};
|
|
484
481
|
}
|
|
485
482
|
function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
@@ -589,11 +586,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
589
586
|
case "response.completed": {
|
|
590
587
|
const resp = event.response;
|
|
591
588
|
const respUsage = resp?.usage;
|
|
592
|
-
const usage = respUsage
|
|
593
|
-
prompt_tokens: respUsage.input_tokens || 0,
|
|
594
|
-
completion_tokens: respUsage.output_tokens || 0,
|
|
595
|
-
total_tokens: (respUsage.input_tokens || 0) + (respUsage.output_tokens || 0)
|
|
596
|
-
} : void 0;
|
|
589
|
+
const usage = responsesUsageToChatUsage(respUsage);
|
|
597
590
|
emitChunk([{ index: 0, delta: {}, finish_reason: hasToolCalls ? "tool_calls" : "stop" }], usage);
|
|
598
591
|
safeEnqueue("data: [DONE]\n\n");
|
|
599
592
|
break;
|
|
@@ -801,11 +794,7 @@ function convertOpenAIStreamToResponseApi(openaiStream, codexTools) {
|
|
|
801
794
|
status: "completed",
|
|
802
795
|
model,
|
|
803
796
|
output,
|
|
804
|
-
usage: chunk.usage
|
|
805
|
-
input_tokens: chunk.usage.prompt_tokens || 0,
|
|
806
|
-
output_tokens: chunk.usage.completion_tokens || 0,
|
|
807
|
-
total_tokens: chunk.usage.total_tokens || 0
|
|
808
|
-
} : void 0
|
|
797
|
+
usage: chatUsageToResponsesUsage(chunk.usage)
|
|
809
798
|
}
|
|
810
799
|
});
|
|
811
800
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/provider-proxy/identity/headerMerge.ts
|
|
2
|
+
function fillMissingHeaders(headers, source) {
|
|
3
|
+
const present = new Set(Object.keys(headers).map((k) => k.toLowerCase()));
|
|
4
|
+
for (const [key, value] of Object.entries(source)) {
|
|
5
|
+
const lower = key.toLowerCase();
|
|
6
|
+
if (present.has(lower)) continue;
|
|
7
|
+
headers[lower] = value;
|
|
8
|
+
present.add(lower);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function flattenHeaderValue(raw) {
|
|
12
|
+
if (raw === void 0) return void 0;
|
|
13
|
+
const value = Array.isArray(raw) ? raw.filter((v) => typeof v === "string").join(", ") : raw;
|
|
14
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
15
|
+
}
|
|
16
|
+
var NEVER_FORWARD_HEADERS = /* @__PURE__ */ new Set([
|
|
17
|
+
"authorization",
|
|
18
|
+
"x-api-key",
|
|
19
|
+
"cookie",
|
|
20
|
+
"proxy-authorization",
|
|
21
|
+
"host",
|
|
22
|
+
"connection",
|
|
23
|
+
"content-length",
|
|
24
|
+
"content-type",
|
|
25
|
+
"accept-encoding"
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
// src/provider-proxy/identity/codexCliHeaders.ts
|
|
29
|
+
var DEFAULT_CODEX_CLI_HEADERS = Object.freeze({
|
|
30
|
+
originator: "codex_cli_rs",
|
|
31
|
+
"user-agent": "codex_cli_rs/0.144.5",
|
|
32
|
+
version: "0.144.5"
|
|
33
|
+
});
|
|
34
|
+
var CODEX_FORWARD_ALLOWLIST = /* @__PURE__ */ new Set([
|
|
35
|
+
"version",
|
|
36
|
+
"openai-beta",
|
|
37
|
+
"session_id",
|
|
38
|
+
"originator",
|
|
39
|
+
"user-agent"
|
|
40
|
+
]);
|
|
41
|
+
function extractCodexClientHeaders(reqHeaders) {
|
|
42
|
+
const out = {};
|
|
43
|
+
for (const [rawKey, rawVal] of Object.entries(reqHeaders)) {
|
|
44
|
+
const key = rawKey.toLowerCase();
|
|
45
|
+
if (NEVER_FORWARD_HEADERS.has(key)) continue;
|
|
46
|
+
if (!CODEX_FORWARD_ALLOWLIST.has(key)) continue;
|
|
47
|
+
const value = flattenHeaderValue(rawVal);
|
|
48
|
+
if (value !== void 0) out[key] = value;
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
function codexAcceptHeader(isStream) {
|
|
53
|
+
return isStream ? "text/event-stream" : "application/json";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
exports.fillMissingHeaders = fillMissingHeaders; exports.flattenHeaderValue = flattenHeaderValue; exports.NEVER_FORWARD_HEADERS = NEVER_FORWARD_HEADERS; exports.DEFAULT_CODEX_CLI_HEADERS = DEFAULT_CODEX_CLI_HEADERS; exports.extractCodexClientHeaders = extractCodexClientHeaders; exports.codexAcceptHeader = codexAcceptHeader;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { appendFile, mkdir } from "fs/promises";
|
|
3
3
|
import { dirname } from "path";
|
|
4
4
|
var tracePath = null;
|
|
5
|
+
var REDACTED_BODY = "***REDACTED (credential exchange)***";
|
|
5
6
|
var SECRET_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
6
7
|
"authorization",
|
|
7
8
|
"api-key",
|
|
@@ -44,6 +45,7 @@ function __resetUpstreamTraceForTests() {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export {
|
|
48
|
+
REDACTED_BODY,
|
|
47
49
|
setUpstreamTracePath,
|
|
48
50
|
getUpstreamTracePath,
|
|
49
51
|
redactHeaders,
|