@omnicross/core 0.1.2 → 0.1.4
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 -21
- package/NOTICE +57 -57
- package/README.md +15 -15
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -1
- package/dist/auth/GeminiCodeAssistProjectResolver.js +6 -1
- package/dist/chunk-3QFXFCHG.js +33 -0
- package/dist/chunk-4IH4EL7M.cjs +9 -0
- package/dist/chunk-4YINUUKQ.cjs +33 -0
- package/dist/chunk-5ENKBSWO.js +311 -0
- package/dist/chunk-6RPZADX3.cjs +92 -0
- package/dist/chunk-7Y47UCF2.js +142 -0
- package/dist/chunk-AEOZIDEB.cjs +32 -0
- package/dist/chunk-APYG5QD7.cjs +50 -0
- package/dist/{chunk-MNYKI4CI.js → chunk-BPKCU575.js} +29 -0
- package/dist/{chunk-SN3YWBX7.cjs → chunk-DKPXN34V.cjs} +2108 -538
- package/dist/{chunk-4NBS6KPV.cjs → chunk-DQ5VAYZ6.cjs} +7 -8
- package/dist/chunk-E3UCVHLP.cjs +142 -0
- package/dist/chunk-FCR77GYM.cjs +33 -0
- package/dist/{chunk-74TMJA7Z.js → chunk-HRRYG2AX.js} +8 -4
- package/dist/chunk-HUZZZ3JL.js +32 -0
- package/dist/{chunk-KUU2RNG6.cjs → chunk-HYN75H6G.cjs} +3 -0
- package/dist/{chunk-QOCNX236.js → chunk-IAXWICZU.js} +24 -1
- package/dist/{chunk-JO5NLTLY.js → chunk-IK3KE3AU.js} +3 -0
- package/dist/{chunk-V5KPWNYX.cjs → chunk-JMJBSACD.cjs} +3 -3
- package/dist/chunk-K5NM7VAH.js +33 -0
- package/dist/{chunk-N3V2J5ZO.cjs → chunk-KFI44N2R.cjs} +8 -4
- package/dist/chunk-L74VDN4A.cjs +32 -0
- package/dist/chunk-OCEUVQHW.cjs +112 -0
- package/dist/chunk-OE6TDIWW.js +22 -0
- package/dist/chunk-OZFM4X3S.js +18 -0
- package/dist/{chunk-LKZJEL6E.cjs → chunk-Q27JY5RG.cjs} +6 -4
- package/dist/{chunk-SPVWWUHX.cjs → chunk-QWBWGODS.cjs} +24 -1
- package/dist/{chunk-2FEVTJWG.js → chunk-QYTT6GE3.js} +1929 -359
- package/dist/{chunk-UYPEN5XE.cjs → chunk-RGTR7CIO.cjs} +6 -6
- package/dist/chunk-RPII3E6Z.cjs +145 -0
- package/dist/{chunk-XBSYYZIY.cjs → chunk-SNYBEXLB.cjs} +31 -2
- package/dist/{chunk-2DCNB7DF.cjs → chunk-SU2GCLAC.cjs} +30 -10
- package/dist/{chunk-5HTVET6E.js → chunk-TIER4SUC.js} +24 -4
- package/dist/chunk-TKJMZBAH.js +32 -0
- package/dist/{chunk-ZSVQT3PW.js → chunk-UBWEBKRC.js} +5 -6
- package/dist/chunk-UHGVBFU3.js +385 -0
- package/dist/chunk-UIBD2YY5.cjs +22 -0
- package/dist/chunk-UNEFIWXI.cjs +32 -0
- package/dist/chunk-VACWOIRE.cjs +385 -0
- package/dist/{chunk-O466Y272.js → chunk-VPBAUQ2M.js} +7 -7
- package/dist/chunk-VQY5W4YW.cjs +311 -0
- package/dist/chunk-WLYIIEAF.js +50 -0
- package/dist/chunk-WNY4WMRF.js +32 -0
- package/dist/chunk-XEKD23J5.js +9 -0
- package/dist/chunk-XK5CIRMQ.js +112 -0
- package/dist/chunk-XSVNC2UD.cjs +18 -0
- package/dist/chunk-XTEI64OU.js +145 -0
- package/dist/chunk-XX6NQJMA.js +92 -0
- package/dist/{chunk-745DV5FL.js → chunk-Y7FO65VT.js} +3 -3
- package/dist/{chunk-PXUJF5HS.js → chunk-ZY6KU6P3.js} +4 -2
- package/dist/completion/CompletionService.cjs +30 -17
- package/dist/completion/CompletionService.js +29 -16
- package/dist/completion/NativeSearchInjector.cjs +3 -3
- package/dist/completion/NativeSearchInjector.js +2 -2
- package/dist/completion/openrouter-headers.cjs +3 -6
- package/dist/completion/openrouter-headers.d.cts +9 -12
- package/dist/completion/openrouter-headers.d.ts +9 -12
- package/dist/completion/openrouter-headers.js +2 -5
- package/dist/completion/openrouter-models.cjs +4 -3
- package/dist/completion/openrouter-models.js +2 -1
- package/dist/completion.cjs +30 -17
- package/dist/completion.js +29 -16
- package/dist/index.cjs +151 -20
- package/dist/index.d.cts +44 -10
- package/dist/index.d.ts +44 -10
- package/dist/index.js +160 -29
- package/dist/keyPolicy-Cp0FntZl.d.cts +90 -0
- package/dist/keyPolicy-Cp0FntZl.d.ts +90 -0
- package/dist/outbound-api/auditCapture.cjs +9 -0
- package/dist/outbound-api/auditCapture.d.cts +52 -0
- package/dist/outbound-api/auditCapture.d.ts +52 -0
- package/dist/outbound-api/auditCapture.js +9 -0
- package/dist/outbound-api/auditRedact.cjs +8 -0
- package/dist/outbound-api/auditRedact.d.cts +30 -0
- package/dist/outbound-api/auditRedact.d.ts +30 -0
- package/dist/outbound-api/auditRedact.js +8 -0
- package/dist/outbound-api/billingCapture.cjs +8 -0
- package/dist/outbound-api/billingCapture.d.cts +61 -0
- package/dist/outbound-api/billingCapture.d.ts +61 -0
- package/dist/outbound-api/billingCapture.js +8 -0
- package/dist/outbound-api/quotaWarn.cjs +12 -0
- package/dist/outbound-api/quotaWarn.d.cts +43 -0
- package/dist/outbound-api/quotaWarn.d.ts +43 -0
- package/dist/outbound-api/quotaWarn.js +12 -0
- package/dist/outbound-api/routeResolver.cjs +5 -2
- package/dist/outbound-api/routeResolver.d.cts +9 -2
- package/dist/outbound-api/routeResolver.d.ts +9 -2
- package/dist/outbound-api/routeResolver.js +4 -1
- package/dist/outbound-api/types.cjs +6 -1
- package/dist/outbound-api/types.d.cts +12 -144
- package/dist/outbound-api/types.d.ts +12 -144
- package/dist/outbound-api/types.js +6 -0
- package/dist/outbound-api.cjs +144 -17
- package/dist/outbound-api.d.cts +655 -25
- package/dist/outbound-api.d.ts +655 -25
- package/dist/outbound-api.js +148 -21
- package/dist/pipeline/AuthSource.d.cts +29 -1
- package/dist/pipeline/AuthSource.d.ts +29 -1
- package/dist/pipeline/LlmConfigProviderAuth.cjs +3 -3
- package/dist/pipeline/LlmConfigProviderAuth.js +2 -2
- package/dist/pipeline/SubscriptionAccountHealth.cjs +22 -0
- package/dist/pipeline/SubscriptionAccountHealth.d.cts +235 -0
- package/dist/pipeline/SubscriptionAccountHealth.d.ts +235 -0
- package/dist/pipeline/SubscriptionAccountHealth.js +22 -0
- package/dist/pipeline/SubscriptionAuthSource.cjs +2 -2
- package/dist/pipeline/SubscriptionAuthSource.d.cts +3 -2
- package/dist/pipeline/SubscriptionAuthSource.d.ts +3 -2
- package/dist/pipeline/SubscriptionAuthSource.js +1 -1
- package/dist/pipeline/SubscriptionAuthStrategy.d.cts +30 -1
- package/dist/pipeline/SubscriptionAuthStrategy.d.ts +30 -1
- package/dist/pipeline/auditSink.cjs +14 -0
- package/dist/pipeline/auditSink.d.cts +48 -0
- package/dist/pipeline/auditSink.d.ts +48 -0
- package/dist/pipeline/auditSink.js +14 -0
- package/dist/pipeline/auditUsageStash.cjs +10 -0
- package/dist/pipeline/auditUsageStash.d.cts +37 -0
- package/dist/pipeline/auditUsageStash.d.ts +37 -0
- package/dist/pipeline/auditUsageStash.js +10 -0
- package/dist/pipeline/billingEmit.cjs +14 -0
- package/dist/pipeline/billingEmit.d.cts +49 -0
- package/dist/pipeline/billingEmit.d.ts +49 -0
- package/dist/pipeline/billingEmit.js +14 -0
- package/dist/pipeline/executeProviderCall.cjs +2 -2
- package/dist/pipeline/executeProviderCall.js +1 -1
- package/dist/pipeline/upstreamFetch.cjs +14 -0
- package/dist/pipeline/upstreamFetch.d.cts +83 -0
- package/dist/pipeline/upstreamFetch.d.ts +83 -0
- package/dist/pipeline/upstreamFetch.js +14 -0
- package/dist/pipeline/webhookEmit.cjs +10 -0
- package/dist/pipeline/webhookEmit.d.cts +36 -0
- package/dist/pipeline/webhookEmit.d.ts +36 -0
- package/dist/pipeline/webhookEmit.js +10 -0
- package/dist/ports/usage-event-store.d.cts +26 -1
- package/dist/ports/usage-event-store.d.ts +26 -1
- package/dist/ports.d.cts +8 -1
- package/dist/ports.d.ts +8 -1
- package/dist/provider-proxy/ProviderProxy.cjs +30 -17
- package/dist/provider-proxy/ProviderProxy.js +29 -16
- package/dist/provider-proxy/identity/SubscriptionIdentityStore.cjs +15 -0
- package/dist/provider-proxy/identity/SubscriptionIdentityStore.d.cts +121 -0
- package/dist/provider-proxy/identity/SubscriptionIdentityStore.d.ts +121 -0
- package/dist/provider-proxy/identity/SubscriptionIdentityStore.js +15 -0
- package/dist/provider-proxy/identity/fingerprintHeaders.cjs +20 -0
- package/dist/provider-proxy/identity/fingerprintHeaders.d.cts +89 -0
- package/dist/provider-proxy/identity/fingerprintHeaders.d.ts +89 -0
- package/dist/provider-proxy/identity/fingerprintHeaders.js +20 -0
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +30 -17
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +11 -2
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +11 -2
- package/dist/provider-proxy/ingress/providerProxyShared.js +29 -16
- package/dist/provider-proxy/matchText.cjs +4 -2
- package/dist/provider-proxy/matchText.d.cts +14 -1
- package/dist/provider-proxy/matchText.d.ts +14 -1
- package/dist/provider-proxy/matchText.js +3 -1
- package/dist/provider-proxy/types.d.cts +30 -0
- package/dist/provider-proxy/types.d.ts +30 -0
- package/dist/provider-proxy.cjs +30 -17
- package/dist/provider-proxy.js +29 -16
- package/dist/{routeResolver-HE-ZO0fO.d.ts → routeResolver-C4T7yClx.d.ts} +36 -10
- package/dist/{routeResolver-BrbK6ja9.d.cts → routeResolver-CB3tvJKy.d.cts} +36 -10
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
- package/dist/transformer/transformers.cjs +7 -7
- package/dist/transformer/transformers.js +8 -8
- package/dist/transformer.cjs +9 -9
- package/dist/transformer.js +8 -8
- package/dist/types-B8Arpxn0.d.cts +754 -0
- package/dist/types-lgPYQuZS.d.ts +754 -0
- package/dist/usage/usage-recorder.cjs +3 -2
- package/dist/usage/usage-recorder.d.cts +19 -1
- package/dist/usage/usage-recorder.d.ts +19 -1
- package/dist/usage/usage-recorder.js +2 -1
- package/dist/usage.cjs +3 -2
- package/dist/usage.js +2 -1
- package/package.json +64 -62
- package/dist/chunk-3MEACFK3.js +0 -193
- package/dist/chunk-6VIXXLMX.cjs +0 -14
- package/dist/chunk-E3WHL7CO.js +0 -14
- package/dist/chunk-G2FUJNA2.cjs +0 -193
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; } var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkDWKQZ2SKcjs = require('./chunk-DWKQZ2SK.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk4VAVYUZScjs = require('./chunk-4VAVYUZS.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunk7YN22L2Hcjs = require('./chunk-7YN22L2H.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkSU2GCLACcjs = require('./chunk-SU2GCLAC.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkC72S6TTVcjs = require('./chunk-C72S6TTV.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
var _chunkRSJ3TWJQcjs = require('./chunk-RSJ3TWJQ.cjs');
|
|
@@ -207,7 +207,7 @@ var BuiltinTransformers = {
|
|
|
207
207
|
GeminiTransformer: _chunk7YN22L2Hcjs.GeminiTransformer,
|
|
208
208
|
GeminiCodeAssistTransformer: _chunkRSJ3TWJQcjs.GeminiCodeAssistTransformer,
|
|
209
209
|
AnthropicTransformer: _chunk4VAVYUZScjs.AnthropicTransformer,
|
|
210
|
-
OpenAIResponseTransformer:
|
|
210
|
+
OpenAIResponseTransformer: _chunkSU2GCLACcjs.OpenAIResponseTransformer,
|
|
211
211
|
OpenCodeGoTransformer: _chunkC72S6TTVcjs.OpenCodeGoTransformer
|
|
212
212
|
};
|
|
213
213
|
function getBuiltinTransformers() {
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; } var _class;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk6RPZADX3cjs = require('./chunk-6RPZADX3.cjs');
|
|
5
|
+
|
|
6
|
+
// src/provider-proxy/identity/SubscriptionIdentityStore.ts
|
|
7
|
+
var CC_HEADER_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
8
|
+
var KEY_SEP = "\0";
|
|
9
|
+
function normalizeUa(ua) {
|
|
10
|
+
if (typeof ua !== "string") return void 0;
|
|
11
|
+
const trimmed = ua.trim();
|
|
12
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
13
|
+
}
|
|
14
|
+
var SubscriptionIdentityStore = (_class = class {
|
|
15
|
+
__init() {this.identities = /* @__PURE__ */ new Map()}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
__init2() {this.persistence = null}
|
|
21
|
+
constructor(opts = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
22
|
+
this.now = _nullishCoalesce(opts.now, () => ( Date.now));
|
|
23
|
+
this.enabled = _nullishCoalesce(opts.enabled, () => ( false));
|
|
24
|
+
this.ua = normalizeUa(opts.ua);
|
|
25
|
+
this.ccHeaderTtlMs = _nullishCoalesce(opts.ccHeaderTtlMs, () => ( CC_HEADER_TTL_MS));
|
|
26
|
+
}
|
|
27
|
+
/** Whether capture/replay is engaged (config flag). */
|
|
28
|
+
isEnabled() {
|
|
29
|
+
return this.enabled;
|
|
30
|
+
}
|
|
31
|
+
/** The operator UA baseline (piece 4), or undefined when unset. */
|
|
32
|
+
uaBaseline() {
|
|
33
|
+
return this.ua;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Re-apply config to the LIVE shared instance (bootstrap, mirroring the health
|
|
37
|
+
* tracker's `configure`). Only defined fields override; `ua: null` clears the
|
|
38
|
+
* baseline.
|
|
39
|
+
*/
|
|
40
|
+
configure(opts) {
|
|
41
|
+
if (opts.enabled !== void 0) this.enabled = opts.enabled;
|
|
42
|
+
if (opts.ua !== void 0) this.ua = normalizeUa(_nullishCoalesce(opts.ua, () => ( void 0)));
|
|
43
|
+
}
|
|
44
|
+
/** Install (or clear) the write-through persistence port (P2). */
|
|
45
|
+
setPersistence(port) {
|
|
46
|
+
this.persistence = port;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Boot seed (P2, D5): install a PERSISTED identity for an account, but NEVER
|
|
50
|
+
* over a live in-memory capture (a re-captured identity from this session wins).
|
|
51
|
+
* A no-op for an empty/absent identity. Does NOT write back through the port.
|
|
52
|
+
*/
|
|
53
|
+
seed(providerId, accountId, identity) {
|
|
54
|
+
if (!accountId || !identity) return;
|
|
55
|
+
const headers = _chunk6RPZADX3cjs.sanitizeFrozenHeaders.call(void 0, _nullishCoalesce(identity.headers, () => ( {})));
|
|
56
|
+
if (Object.keys(headers).length === 0) return;
|
|
57
|
+
const key = this.key(providerId, accountId);
|
|
58
|
+
if (this.identities.has(key)) return;
|
|
59
|
+
this.identities.set(key, {
|
|
60
|
+
headers,
|
|
61
|
+
capturedAt: typeof identity.capturedAt === "number" ? identity.capturedAt : this.now()
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Capture a real client's fingerprint headers for an account. First-seen ⇒
|
|
66
|
+
* FREEZE the whole (sanitized) bag. Already-frozen ⇒ within the TTL, no change
|
|
67
|
+
* (stable identity); past the TTL, refresh the NON-stainless headers from the
|
|
68
|
+
* new observation while keeping stainless frozen-stable (P2). An empty/absent
|
|
69
|
+
* account id or an empty sanitized bag is a no-op (so an account with no
|
|
70
|
+
* fingerprint headers never freezes an empty identity → the caller falls back
|
|
71
|
+
* to the UA baseline). Fires the persistence port on a freeze/refresh.
|
|
72
|
+
*/
|
|
73
|
+
capture(providerId, accountId, incoming, now = this.now()) {
|
|
74
|
+
if (!accountId) return;
|
|
75
|
+
const clean = _chunk6RPZADX3cjs.sanitizeFrozenHeaders.call(void 0, incoming);
|
|
76
|
+
if (Object.keys(clean).length === 0) return;
|
|
77
|
+
const key = this.key(providerId, accountId);
|
|
78
|
+
const existing = this.identities.get(key);
|
|
79
|
+
if (!existing) {
|
|
80
|
+
const frozen = { headers: clean, capturedAt: now };
|
|
81
|
+
this.identities.set(key, frozen);
|
|
82
|
+
this.emitPersist(providerId, accountId, frozen);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (now - existing.capturedAt < this.ccHeaderTtlMs) return;
|
|
86
|
+
const refreshed = {
|
|
87
|
+
headers: _chunk6RPZADX3cjs.refreshNonStainless.call(void 0, existing.headers, clean),
|
|
88
|
+
capturedAt: now
|
|
89
|
+
};
|
|
90
|
+
this.identities.set(key, refreshed);
|
|
91
|
+
this.emitPersist(providerId, accountId, refreshed);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The frozen identity headers for an account, or `undefined` when none is
|
|
95
|
+
* frozen (or the frozen set is empty). Returns a COPY (the caller merges it into
|
|
96
|
+
* a mutable outbound header bag).
|
|
97
|
+
*/
|
|
98
|
+
replay(providerId, accountId) {
|
|
99
|
+
if (!accountId) return void 0;
|
|
100
|
+
const frozen = this.identities.get(this.key(providerId, accountId));
|
|
101
|
+
if (!frozen || Object.keys(frozen.headers).length === 0) return void 0;
|
|
102
|
+
return { ...frozen.headers };
|
|
103
|
+
}
|
|
104
|
+
/** Whether an identity is frozen for an account (admin coarse status — D7). */
|
|
105
|
+
hasIdentity(providerId, accountId) {
|
|
106
|
+
const frozen = this.identities.get(this.key(providerId, accountId));
|
|
107
|
+
return !!frozen && Object.keys(frozen.headers).length > 0;
|
|
108
|
+
}
|
|
109
|
+
/** The freeze/refresh time for an account's identity (admin coarse status). */
|
|
110
|
+
capturedAt(providerId, accountId) {
|
|
111
|
+
return _optionalChain([this, 'access', _ => _.identities, 'access', _2 => _2.get, 'call', _3 => _3(this.key(providerId, accountId)), 'optionalAccess', _4 => _4.capturedAt]);
|
|
112
|
+
}
|
|
113
|
+
emitPersist(providerId, accountId, identity) {
|
|
114
|
+
if (!this.persistence) return;
|
|
115
|
+
try {
|
|
116
|
+
this.persistence.persist(providerId, accountId, {
|
|
117
|
+
headers: { ...identity.headers },
|
|
118
|
+
capturedAt: identity.capturedAt
|
|
119
|
+
});
|
|
120
|
+
} catch (e) {
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
key(providerId, accountId) {
|
|
124
|
+
return `${providerId}${KEY_SEP}${accountId}`;
|
|
125
|
+
}
|
|
126
|
+
}, _class);
|
|
127
|
+
var _shared = null;
|
|
128
|
+
function getSharedIdentityStore() {
|
|
129
|
+
if (!_shared) _shared = new SubscriptionIdentityStore();
|
|
130
|
+
return _shared;
|
|
131
|
+
}
|
|
132
|
+
function setSharedIdentityStore(instance) {
|
|
133
|
+
_shared = instance;
|
|
134
|
+
}
|
|
135
|
+
function __resetSharedIdentityStoreForTests() {
|
|
136
|
+
_shared = null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
exports.CC_HEADER_TTL_MS = CC_HEADER_TTL_MS; exports.SubscriptionIdentityStore = SubscriptionIdentityStore; exports.getSharedIdentityStore = getSharedIdentityStore; exports.setSharedIdentityStore = setSharedIdentityStore; exports.__resetSharedIdentityStoreForTests = __resetSharedIdentityStoreForTests;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkXSVNC2UDcjs = require('./chunk-XSVNC2UD.cjs');
|
|
4
|
+
|
|
5
|
+
// src/usage/usage-recorder.ts
|
|
2
6
|
var UsageRecorder = class {
|
|
3
7
|
constructor(store, pricing, logger, options = {}) {
|
|
4
8
|
this.store = store;
|
|
5
9
|
this.pricing = pricing;
|
|
6
10
|
this.logger = logger;
|
|
7
11
|
this.defer = _nullishCoalesce(options.defer, () => ( ((fn) => setTimeout(fn, 0))));
|
|
12
|
+
this.onRecord = options.onRecord;
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
|
|
11
16
|
|
|
12
17
|
|
|
18
|
+
|
|
13
19
|
/**
|
|
14
20
|
* Record one LLM request. Returns immediately — the actual store insert is
|
|
15
21
|
* deferred so the caller's response path is unblocked.
|
|
@@ -17,6 +23,14 @@ var UsageRecorder = class {
|
|
|
17
23
|
* Errors during the insert are logged but never thrown.
|
|
18
24
|
*/
|
|
19
25
|
record(input) {
|
|
26
|
+
if (input.auditResponse) {
|
|
27
|
+
_chunkXSVNC2UDcjs.stashAuditUsage.call(void 0, input.auditResponse, {
|
|
28
|
+
inputTokens: input.usage.inputTokens,
|
|
29
|
+
outputTokens: input.usage.outputTokens,
|
|
30
|
+
model: input.model,
|
|
31
|
+
provider: input.providerId
|
|
32
|
+
});
|
|
33
|
+
}
|
|
20
34
|
this.defer(() => {
|
|
21
35
|
void this.recordAsync(input).catch((err) => {
|
|
22
36
|
this.logger.warn("[UsageRecorder] failed to persist usage event", {
|
|
@@ -35,6 +49,18 @@ var UsageRecorder = class {
|
|
|
35
49
|
input.model,
|
|
36
50
|
input.usage
|
|
37
51
|
);
|
|
52
|
+
if (input.auditResponse) {
|
|
53
|
+
try {
|
|
54
|
+
_chunkXSVNC2UDcjs.stashAuditUsage.call(void 0, input.auditResponse, { costUsd });
|
|
55
|
+
} catch (e) {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (this.onRecord && input.apiKeyId) {
|
|
59
|
+
try {
|
|
60
|
+
this.onRecord(input.apiKeyId, costUsd, Date.now());
|
|
61
|
+
} catch (e2) {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
38
64
|
const row = {
|
|
39
65
|
messageId: _nullishCoalesce(input.messageId, () => ( null)),
|
|
40
66
|
parentMessageId: _nullishCoalesce(input.parentMessageId, () => ( null)),
|
|
@@ -73,6 +99,9 @@ var UsageRecorder = class {
|
|
|
73
99
|
getByApiKey(range) {
|
|
74
100
|
return this.store.getByApiKey(range);
|
|
75
101
|
}
|
|
102
|
+
getTimeSeries(range, bucket) {
|
|
103
|
+
return this.store.getTimeSeries(range, bucket);
|
|
104
|
+
}
|
|
76
105
|
getMessagesForSession(sessionId) {
|
|
77
106
|
return this.store.getMessagesForSession(sessionId);
|
|
78
107
|
}
|
|
@@ -84,7 +113,7 @@ var UsageRecorder = class {
|
|
|
84
113
|
var safeStringify = (value) => {
|
|
85
114
|
try {
|
|
86
115
|
return JSON.stringify(value);
|
|
87
|
-
} catch (
|
|
116
|
+
} catch (e3) {
|
|
88
117
|
return "";
|
|
89
118
|
}
|
|
90
119
|
};
|
|
@@ -25,9 +25,10 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
|
|
|
25
25
|
const input = [];
|
|
26
26
|
for (const msg of request.messages) {
|
|
27
27
|
if (msg.role === "system") {
|
|
28
|
+
const sysText = typeof msg.content === "string" ? msg.content : flattenContent(msg.content);
|
|
28
29
|
input.push({
|
|
29
30
|
role: "developer",
|
|
30
|
-
content:
|
|
31
|
+
content: [{ type: "input_text", text: sysText }]
|
|
31
32
|
});
|
|
32
33
|
} else if (msg.role === "tool") {
|
|
33
34
|
input.push({
|
|
@@ -36,9 +37,10 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
|
|
|
36
37
|
output: typeof msg.content === "string" ? msg.content : ""
|
|
37
38
|
});
|
|
38
39
|
} else {
|
|
40
|
+
const text = typeof msg.content === "string" ? msg.content : flattenContent(msg.content);
|
|
39
41
|
const entry = {
|
|
40
42
|
role: msg.role,
|
|
41
|
-
content:
|
|
43
|
+
content: [{ type: msg.role === "assistant" ? "output_text" : "input_text", text }]
|
|
42
44
|
};
|
|
43
45
|
if (msg.role === "assistant" && _optionalChain([msg, 'access', _ => _.tool_calls, 'optionalAccess', _2 => _2.length])) {
|
|
44
46
|
input.push(entry);
|
|
@@ -60,7 +62,13 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
|
|
|
60
62
|
model: request.model,
|
|
61
63
|
input,
|
|
62
64
|
stream: _nullishCoalesce(request.stream, () => ( false)),
|
|
63
|
-
|
|
65
|
+
// `store:false` is required by the codex backend and accepted by the
|
|
66
|
+
// public Responses API (which defaults to store:true). Always set it so
|
|
67
|
+
// codex relays (no discoverable url token) work without configuration.
|
|
68
|
+
store: false,
|
|
69
|
+
// `max_output_tokens` is intentionally omitted: the codex backend rejects
|
|
70
|
+
// it, and the public API falls back to its default when absent. If a
|
|
71
|
+
// public provider ever needs it honored, gate that on an opt-out flag.
|
|
64
72
|
...request.temperature !== void 0 ? { temperature: request.temperature } : {}
|
|
65
73
|
};
|
|
66
74
|
if (_optionalChain([request, 'access', _3 => _3.reasoning, 'optionalAccess', _4 => _4.effort]) && request.reasoning.effort !== "none") {
|
|
@@ -162,7 +170,19 @@ var OpenAIResponseTransformer = (_class = class {constructor() { _class.prototyp
|
|
|
162
170
|
*/
|
|
163
171
|
async transformResponseOut(response, _context) {
|
|
164
172
|
const contentType = _nullishCoalesce(response.headers.get("Content-Type"), () => ( ""));
|
|
165
|
-
|
|
173
|
+
let isSse = contentType.includes("text/event-stream");
|
|
174
|
+
if (!isSse && response.body) {
|
|
175
|
+
const peek = response.clone();
|
|
176
|
+
try {
|
|
177
|
+
const reader = peek.body.getReader();
|
|
178
|
+
const { value } = await reader.read();
|
|
179
|
+
reader.releaseLock();
|
|
180
|
+
const head = value ? new TextDecoder().decode(value).trimStart() : "";
|
|
181
|
+
isSse = head.startsWith("event:") || head.startsWith("data:");
|
|
182
|
+
} catch (e2) {
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (isSse) {
|
|
166
186
|
if (!response.body) {
|
|
167
187
|
throw new Error("Stream response body is null");
|
|
168
188
|
}
|
|
@@ -319,7 +339,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
319
339
|
if (!isClosed) {
|
|
320
340
|
try {
|
|
321
341
|
controller.enqueue(encoder.encode(str));
|
|
322
|
-
} catch (
|
|
342
|
+
} catch (e3) {
|
|
323
343
|
isClosed = true;
|
|
324
344
|
}
|
|
325
345
|
}
|
|
@@ -393,7 +413,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
393
413
|
default:
|
|
394
414
|
break;
|
|
395
415
|
}
|
|
396
|
-
} catch (
|
|
416
|
+
} catch (e4) {
|
|
397
417
|
}
|
|
398
418
|
}
|
|
399
419
|
}
|
|
@@ -403,7 +423,7 @@ function convertResponseApiStreamToOpenAI(responseApiStream) {
|
|
|
403
423
|
if (!isClosed) {
|
|
404
424
|
try {
|
|
405
425
|
controller.close();
|
|
406
|
-
} catch (
|
|
426
|
+
} catch (e5) {
|
|
407
427
|
}
|
|
408
428
|
}
|
|
409
429
|
reader.releaseLock();
|
|
@@ -426,7 +446,7 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
|
|
|
426
446
|
if (!isClosed) {
|
|
427
447
|
try {
|
|
428
448
|
controller.enqueue(encoder.encode(str));
|
|
429
|
-
} catch (
|
|
449
|
+
} catch (e6) {
|
|
430
450
|
isClosed = true;
|
|
431
451
|
}
|
|
432
452
|
}
|
|
@@ -490,7 +510,7 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
|
|
|
490
510
|
}
|
|
491
511
|
});
|
|
492
512
|
}
|
|
493
|
-
} catch (
|
|
513
|
+
} catch (e7) {
|
|
494
514
|
}
|
|
495
515
|
}
|
|
496
516
|
}
|
|
@@ -500,7 +520,7 @@ function convertOpenAIStreamToResponseApi(openaiStream) {
|
|
|
500
520
|
if (!isClosed) {
|
|
501
521
|
try {
|
|
502
522
|
controller.close();
|
|
503
|
-
} catch (
|
|
523
|
+
} catch (e8) {
|
|
504
524
|
}
|
|
505
525
|
}
|
|
506
526
|
reader.releaseLock();
|
|
@@ -25,9 +25,10 @@ var OpenAIResponseTransformer = class {
|
|
|
25
25
|
const input = [];
|
|
26
26
|
for (const msg of request.messages) {
|
|
27
27
|
if (msg.role === "system") {
|
|
28
|
+
const sysText = typeof msg.content === "string" ? msg.content : flattenContent(msg.content);
|
|
28
29
|
input.push({
|
|
29
30
|
role: "developer",
|
|
30
|
-
content:
|
|
31
|
+
content: [{ type: "input_text", text: sysText }]
|
|
31
32
|
});
|
|
32
33
|
} else if (msg.role === "tool") {
|
|
33
34
|
input.push({
|
|
@@ -36,9 +37,10 @@ var OpenAIResponseTransformer = class {
|
|
|
36
37
|
output: typeof msg.content === "string" ? msg.content : ""
|
|
37
38
|
});
|
|
38
39
|
} else {
|
|
40
|
+
const text = typeof msg.content === "string" ? msg.content : flattenContent(msg.content);
|
|
39
41
|
const entry = {
|
|
40
42
|
role: msg.role,
|
|
41
|
-
content:
|
|
43
|
+
content: [{ type: msg.role === "assistant" ? "output_text" : "input_text", text }]
|
|
42
44
|
};
|
|
43
45
|
if (msg.role === "assistant" && msg.tool_calls?.length) {
|
|
44
46
|
input.push(entry);
|
|
@@ -60,7 +62,13 @@ var OpenAIResponseTransformer = class {
|
|
|
60
62
|
model: request.model,
|
|
61
63
|
input,
|
|
62
64
|
stream: request.stream ?? false,
|
|
63
|
-
|
|
65
|
+
// `store:false` is required by the codex backend and accepted by the
|
|
66
|
+
// public Responses API (which defaults to store:true). Always set it so
|
|
67
|
+
// codex relays (no discoverable url token) work without configuration.
|
|
68
|
+
store: false,
|
|
69
|
+
// `max_output_tokens` is intentionally omitted: the codex backend rejects
|
|
70
|
+
// it, and the public API falls back to its default when absent. If a
|
|
71
|
+
// public provider ever needs it honored, gate that on an opt-out flag.
|
|
64
72
|
...request.temperature !== void 0 ? { temperature: request.temperature } : {}
|
|
65
73
|
};
|
|
66
74
|
if (request.reasoning?.effort && request.reasoning.effort !== "none") {
|
|
@@ -162,7 +170,19 @@ var OpenAIResponseTransformer = class {
|
|
|
162
170
|
*/
|
|
163
171
|
async transformResponseOut(response, _context) {
|
|
164
172
|
const contentType = response.headers.get("Content-Type") ?? "";
|
|
165
|
-
|
|
173
|
+
let isSse = contentType.includes("text/event-stream");
|
|
174
|
+
if (!isSse && response.body) {
|
|
175
|
+
const peek = response.clone();
|
|
176
|
+
try {
|
|
177
|
+
const reader = peek.body.getReader();
|
|
178
|
+
const { value } = await reader.read();
|
|
179
|
+
reader.releaseLock();
|
|
180
|
+
const head = value ? new TextDecoder().decode(value).trimStart() : "";
|
|
181
|
+
isSse = head.startsWith("event:") || head.startsWith("data:");
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (isSse) {
|
|
166
186
|
if (!response.body) {
|
|
167
187
|
throw new Error("Stream response body is null");
|
|
168
188
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/pipeline/billingEmit.ts
|
|
2
|
+
var sink = null;
|
|
3
|
+
var captureConfig = null;
|
|
4
|
+
function setBillingSink(fn) {
|
|
5
|
+
sink = fn;
|
|
6
|
+
}
|
|
7
|
+
function setBillingCaptureConfig(config) {
|
|
8
|
+
captureConfig = config && config.enabled ? config : null;
|
|
9
|
+
}
|
|
10
|
+
function getBillingCaptureConfig() {
|
|
11
|
+
return captureConfig;
|
|
12
|
+
}
|
|
13
|
+
function publishBillingEvent(event) {
|
|
14
|
+
const active = sink;
|
|
15
|
+
if (!active) return;
|
|
16
|
+
try {
|
|
17
|
+
active(event);
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function __resetBillingSinkForTests() {
|
|
22
|
+
sink = null;
|
|
23
|
+
captureConfig = null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
setBillingSink,
|
|
28
|
+
setBillingCaptureConfig,
|
|
29
|
+
getBillingCaptureConfig,
|
|
30
|
+
publishBillingEvent,
|
|
31
|
+
__resetBillingSinkForTests
|
|
32
|
+
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OPENROUTER_APP_HEADERS
|
|
3
|
+
} from "./chunk-HUZZZ3JL.js";
|
|
4
|
+
|
|
1
5
|
// src/completion/openrouter-headers.ts
|
|
2
6
|
var OPENROUTER_DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
|
|
3
|
-
var OPENROUTER_HTTP_REFERER = "https://omnicross.dev";
|
|
4
|
-
var OPENROUTER_X_TITLE = "Omnicross";
|
|
5
7
|
function buildOpenRouterHeaders(credentials, options = {}) {
|
|
6
8
|
const apiKey = credentials.apiKey?.trim();
|
|
7
9
|
if (!apiKey) {
|
|
@@ -9,8 +11,7 @@ function buildOpenRouterHeaders(credentials, options = {}) {
|
|
|
9
11
|
}
|
|
10
12
|
const headers = {
|
|
11
13
|
Authorization: `Bearer ${apiKey}`,
|
|
12
|
-
|
|
13
|
-
"X-Title": OPENROUTER_X_TITLE
|
|
14
|
+
...OPENROUTER_APP_HEADERS
|
|
14
15
|
};
|
|
15
16
|
if (options.contentType !== false) {
|
|
16
17
|
headers["Content-Type"] = options.contentType ?? "application/json";
|
|
@@ -35,8 +36,6 @@ function buildOpenRouterUrl(endpoint, path) {
|
|
|
35
36
|
|
|
36
37
|
export {
|
|
37
38
|
OPENROUTER_DEFAULT_BASE_URL,
|
|
38
|
-
OPENROUTER_HTTP_REFERER,
|
|
39
|
-
OPENROUTER_X_TITLE,
|
|
40
39
|
buildOpenRouterHeaders,
|
|
41
40
|
resolveOpenRouterBaseUrl,
|
|
42
41
|
buildOpenRouterUrl
|