@omnicross/core 0.1.3 → 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 +4 -4
- package/dist/auth/GeminiCodeAssistProjectResolver.js +3 -3
- package/dist/chunk-3QFXFCHG.js +33 -0
- package/dist/chunk-4YINUUKQ.cjs +33 -0
- package/dist/chunk-7Y47UCF2.js +142 -0
- package/dist/chunk-APYG5QD7.cjs +50 -0
- package/dist/{chunk-CWM2ZDU5.js → chunk-BPKCU575.js} +3 -10
- package/dist/{chunk-2FMI2B6V.cjs → chunk-DKPXN34V.cjs} +222 -448
- package/dist/chunk-E3UCVHLP.cjs +142 -0
- package/dist/chunk-FCR77GYM.cjs +33 -0
- package/dist/{chunk-N5QFKSDO.js → chunk-HRRYG2AX.js} +2 -1
- package/dist/{chunk-KUU2RNG6.cjs → chunk-HYN75H6G.cjs} +3 -0
- package/dist/{chunk-JO5NLTLY.js → chunk-IK3KE3AU.js} +3 -0
- package/dist/chunk-K5NM7VAH.js +33 -0
- package/dist/{chunk-Y6OM7EV7.cjs → chunk-KFI44N2R.cjs} +2 -1
- package/dist/{chunk-S6JGLF3G.cjs → chunk-OCEUVQHW.cjs} +27 -4
- package/dist/chunk-OE6TDIWW.js +22 -0
- package/dist/chunk-OZFM4X3S.js +18 -0
- package/dist/{chunk-4DECIFU7.js → chunk-QYTT6GE3.js} +62 -288
- package/dist/{chunk-FFALUUZZ.cjs → chunk-RGTR7CIO.cjs} +5 -5
- package/dist/{chunk-3QOSDDNI.cjs → chunk-SNYBEXLB.cjs} +6 -13
- package/dist/{chunk-2DCNB7DF.cjs → chunk-SU2GCLAC.cjs} +30 -10
- package/dist/{chunk-5HTVET6E.js → chunk-TIER4SUC.js} +24 -4
- package/dist/{chunk-CZHZGRU7.js → chunk-UHGVBFU3.js} +2 -0
- package/dist/chunk-UIBD2YY5.cjs +22 -0
- package/dist/{chunk-SVXC36MU.cjs → chunk-VACWOIRE.cjs} +2 -0
- package/dist/{chunk-MQNDWYPN.js → chunk-VPBAUQ2M.js} +4 -4
- package/dist/chunk-WLYIIEAF.js +50 -0
- package/dist/{chunk-BO4RFWBR.js → chunk-XK5CIRMQ.js} +24 -1
- package/dist/chunk-XSVNC2UD.cjs +18 -0
- package/dist/completion/CompletionService.cjs +22 -16
- package/dist/completion/CompletionService.js +21 -15
- package/dist/completion.cjs +24 -18
- package/dist/completion.js +23 -17
- package/dist/index.cjs +33 -24
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +42 -33
- 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 +2 -2
- package/dist/outbound-api/routeResolver.d.cts +3 -2
- package/dist/outbound-api/routeResolver.d.ts +3 -2
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api/types.d.cts +2 -1
- package/dist/outbound-api/types.d.ts +2 -1
- package/dist/outbound-api.cjs +29 -20
- package/dist/outbound-api.d.cts +9 -140
- package/dist/outbound-api.d.ts +9 -140
- package/dist/outbound-api.js +28 -19
- package/dist/pipeline/AuthSource.d.cts +6 -0
- package/dist/pipeline/AuthSource.d.ts +6 -0
- package/dist/pipeline/SubscriptionAuthSource.cjs +2 -2
- package/dist/pipeline/SubscriptionAuthSource.js +1 -1
- package/dist/pipeline/SubscriptionAuthStrategy.d.cts +6 -0
- package/dist/pipeline/SubscriptionAuthStrategy.d.ts +6 -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/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.d.cts +2 -1
- package/dist/ports.d.ts +2 -1
- package/dist/provider-proxy/ProviderProxy.cjs +22 -16
- package/dist/provider-proxy/ProviderProxy.js +21 -15
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +22 -16
- package/dist/provider-proxy/ingress/providerProxyShared.js +21 -15
- package/dist/provider-proxy/types.d.cts +7 -0
- package/dist/provider-proxy/types.d.ts +7 -0
- package/dist/provider-proxy.cjs +22 -16
- package/dist/provider-proxy.js +21 -15
- package/dist/{routeResolver-B1NglTfe.d.ts → routeResolver-C4T7yClx.d.ts} +1 -1
- package/dist/{routeResolver-CbG5uBgm.d.cts → routeResolver-CB3tvJKy.d.cts} +1 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
- package/dist/transformer/transformers.cjs +6 -6
- package/dist/transformer/transformers.js +5 -5
- package/dist/transformer.cjs +7 -7
- package/dist/transformer.js +6 -6
- package/dist/{types-aBFFXoBz.d.cts → types-B8Arpxn0.d.cts} +14 -90
- package/dist/{types-6OUY_xfA.d.ts → types-lgPYQuZS.d.ts} +14 -90
- package/dist/usage/usage-recorder.cjs +3 -2
- package/dist/usage/usage-recorder.js +2 -1
- package/dist/usage.cjs +3 -2
- package/dist/usage.js +2 -1
- package/package.json +64 -64
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
streamSSEResponse
|
|
3
3
|
} from "./chunk-VVEHS2LI.js";
|
|
4
|
-
import {
|
|
5
|
-
TransformerChainExecutor
|
|
6
|
-
} from "./chunk-G2UTNSGU.js";
|
|
7
4
|
import {
|
|
8
5
|
AnthropicTransformer
|
|
9
6
|
} from "./chunk-FTQ7IQUC.js";
|
|
@@ -12,10 +9,10 @@ import {
|
|
|
12
9
|
} from "./chunk-C7PSERMH.js";
|
|
13
10
|
import {
|
|
14
11
|
OpenAIResponseTransformer
|
|
15
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-TIER4SUC.js";
|
|
16
13
|
import {
|
|
17
|
-
|
|
18
|
-
} from "./chunk-
|
|
14
|
+
TransformerChainExecutor
|
|
15
|
+
} from "./chunk-G2UTNSGU.js";
|
|
19
16
|
import {
|
|
20
17
|
injectExtendedContextBeta
|
|
21
18
|
} from "./chunk-MZNPGW5Q.js";
|
|
@@ -31,32 +28,14 @@ import {
|
|
|
31
28
|
deriveSubscriptionSessionKey
|
|
32
29
|
} from "./chunk-IAXWICZU.js";
|
|
33
30
|
import {
|
|
34
|
-
|
|
35
|
-
} from "./chunk-
|
|
36
|
-
import {
|
|
37
|
-
getSharedAccountHealth,
|
|
38
|
-
resolveResetSeconds
|
|
39
|
-
} from "./chunk-5ENKBSWO.js";
|
|
40
|
-
import {
|
|
41
|
-
SubscriptionAuthSource
|
|
42
|
-
} from "./chunk-N5QFKSDO.js";
|
|
43
|
-
import {
|
|
44
|
-
serializeError
|
|
45
|
-
} from "./chunk-AVYJ4YBN.js";
|
|
31
|
+
emitWebhookEvent
|
|
32
|
+
} from "./chunk-OE6TDIWW.js";
|
|
46
33
|
import {
|
|
47
34
|
getGeminiCodeAssistResolver
|
|
48
35
|
} from "./chunk-DRWHTIIZ.js";
|
|
49
|
-
import {
|
|
50
|
-
getAuditCaptureConfig,
|
|
51
|
-
recordAudit
|
|
52
|
-
} from "./chunk-WNY4WMRF.js";
|
|
53
|
-
import {
|
|
54
|
-
getBillingCaptureConfig,
|
|
55
|
-
publishBillingEvent
|
|
56
|
-
} from "./chunk-TKJMZBAH.js";
|
|
57
36
|
import {
|
|
58
37
|
executeProviderCall
|
|
59
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-IK3KE3AU.js";
|
|
60
39
|
import {
|
|
61
40
|
LlmConfigProviderAuth,
|
|
62
41
|
getProviderHeaders
|
|
@@ -65,10 +44,25 @@ import {
|
|
|
65
44
|
resolveProviderChain
|
|
66
45
|
} from "./chunk-JWC6APFQ.js";
|
|
67
46
|
import {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
resolveSubscriptionChain
|
|
48
|
+
} from "./chunk-5ERIZW3D.js";
|
|
49
|
+
import {
|
|
50
|
+
getSharedAccountHealth,
|
|
51
|
+
resolveResetSeconds
|
|
52
|
+
} from "./chunk-5ENKBSWO.js";
|
|
53
|
+
import {
|
|
54
|
+
SubscriptionAuthSource
|
|
55
|
+
} from "./chunk-HRRYG2AX.js";
|
|
56
|
+
import {
|
|
57
|
+
serializeError
|
|
58
|
+
} from "./chunk-AVYJ4YBN.js";
|
|
59
|
+
import {
|
|
60
|
+
beginBillingCapture
|
|
61
|
+
} from "./chunk-WLYIIEAF.js";
|
|
62
|
+
import {
|
|
63
|
+
computeQuotaWarnings,
|
|
64
|
+
markQuotaWarnedOnce
|
|
65
|
+
} from "./chunk-3QFXFCHG.js";
|
|
72
66
|
import {
|
|
73
67
|
detectRequestRole,
|
|
74
68
|
endpointToIngressFormat,
|
|
@@ -78,14 +72,22 @@ import {
|
|
|
78
72
|
parseModelRef,
|
|
79
73
|
resolveRoute,
|
|
80
74
|
validateServerModelConfig
|
|
81
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-UHGVBFU3.js";
|
|
76
|
+
import {
|
|
77
|
+
buildProviderApiUrl,
|
|
78
|
+
resolveApiFormat,
|
|
79
|
+
resolveProviderEndpoint
|
|
80
|
+
} from "./chunk-H5JUT3KV.js";
|
|
81
|
+
import {
|
|
82
|
+
beginAuditCapture
|
|
83
|
+
} from "./chunk-7Y47UCF2.js";
|
|
82
84
|
import {
|
|
83
85
|
convertAnthropicToOpenAI,
|
|
84
86
|
convertOpenAIToAnthropic
|
|
85
87
|
} from "./chunk-5ZQBEOMD.js";
|
|
86
88
|
import {
|
|
87
89
|
fetchUpstream
|
|
88
|
-
} from "./chunk-
|
|
90
|
+
} from "./chunk-XK5CIRMQ.js";
|
|
89
91
|
import {
|
|
90
92
|
applyAugmentation
|
|
91
93
|
} from "./chunk-Y7FO65VT.js";
|
|
@@ -715,6 +717,7 @@ function buildSubscriptionIterationPlan(profile, route, deps, resolvedModel, isS
|
|
|
715
717
|
};
|
|
716
718
|
return {
|
|
717
719
|
auth,
|
|
720
|
+
preferredAccountId: route.preferredAccountId,
|
|
718
721
|
chain,
|
|
719
722
|
transformerProvider,
|
|
720
723
|
resolvedModel,
|
|
@@ -788,6 +791,7 @@ async function runPipeline(anthropicBody, plan, reportSelection) {
|
|
|
788
791
|
upstreamUrl,
|
|
789
792
|
model: resolvedModel,
|
|
790
793
|
sessionKey: plan.sessionKey,
|
|
794
|
+
preferredAccountId: plan.preferredAccountId,
|
|
791
795
|
reportSelection: (accountId, isActive) => {
|
|
792
796
|
proxyAccountId = accountId;
|
|
793
797
|
reportSelection?.(accountId, isActive);
|
|
@@ -833,6 +837,7 @@ async function runSubscriptionSameFormatFetch(rawBody, plan, reportSelection, op
|
|
|
833
837
|
upstreamUrl: plan.upstreamUrl,
|
|
834
838
|
model: plan.resolvedModel,
|
|
835
839
|
sessionKey: plan.sessionKey,
|
|
840
|
+
preferredAccountId: plan.preferredAccountId,
|
|
836
841
|
reportSelection: (accountId, isActive, remapped) => {
|
|
837
842
|
proxyAccountId = accountId;
|
|
838
843
|
remappedModel = remapped;
|
|
@@ -1754,6 +1759,7 @@ async function buildSubscriptionPlan3(res, route, deps, resolvedModel, isStream)
|
|
|
1754
1759
|
}
|
|
1755
1760
|
return {
|
|
1756
1761
|
auth,
|
|
1762
|
+
preferredAccountId: route.preferredAccountId,
|
|
1757
1763
|
chain,
|
|
1758
1764
|
transformerProvider,
|
|
1759
1765
|
resolvedModel,
|
|
@@ -1785,6 +1791,7 @@ async function runPipeline4(responsesBody, plan) {
|
|
|
1785
1791
|
await auth.applyHeaders(authHeaders, {
|
|
1786
1792
|
upstreamUrl,
|
|
1787
1793
|
model: resolvedModel,
|
|
1794
|
+
preferredAccountId: plan.preferredAccountId,
|
|
1788
1795
|
reportSelection: (accountId) => {
|
|
1789
1796
|
proxyAccountId = accountId;
|
|
1790
1797
|
}
|
|
@@ -2044,17 +2051,6 @@ var KeyedMutex = class {
|
|
|
2044
2051
|
// src/outbound-api/outboundApiRouter.ts
|
|
2045
2052
|
import { Readable } from "stream";
|
|
2046
2053
|
|
|
2047
|
-
// src/pipeline/webhookEmit.ts
|
|
2048
|
-
var sink = null;
|
|
2049
|
-
function emitWebhookEvent(event) {
|
|
2050
|
-
const active = sink;
|
|
2051
|
-
if (!active) return;
|
|
2052
|
-
try {
|
|
2053
|
-
active(event);
|
|
2054
|
-
} catch {
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
2054
|
// src/outbound-api/apiServerConfig.ts
|
|
2059
2055
|
import { DEFAULT_AUDIT_CONFIG } from "@omnicross/contracts/audit-types";
|
|
2060
2056
|
import { DEFAULT_BILLING_CONFIG } from "@omnicross/contracts/billing-types";
|
|
@@ -2291,6 +2287,9 @@ function normalizePrefixTargets(raw) {
|
|
|
2291
2287
|
function normalizeEndpointConfig(e) {
|
|
2292
2288
|
const endpoint = e.endpoint;
|
|
2293
2289
|
const useSubscription = e.useSubscription === true;
|
|
2290
|
+
const boundAccountId = typeof e.boundAccountId === "string" && e.boundAccountId.trim() !== "" ? e.boundAccountId : void 0;
|
|
2291
|
+
const boundKeyId = typeof e.boundKeyId === "string" && e.boundKeyId.trim() !== "" ? e.boundKeyId : void 0;
|
|
2292
|
+
let config;
|
|
2294
2293
|
if (isKindMappedEndpoint(endpoint)) {
|
|
2295
2294
|
const rawMap = e.modelMap && typeof e.modelMap === "object" ? e.modelMap : {};
|
|
2296
2295
|
const modelMap = {};
|
|
@@ -2298,27 +2297,28 @@ function normalizeEndpointConfig(e) {
|
|
|
2298
2297
|
const v = rawMap[kind];
|
|
2299
2298
|
modelMap[kind] = typeof v === "string" ? v : "";
|
|
2300
2299
|
}
|
|
2301
|
-
|
|
2302
|
-
}
|
|
2303
|
-
if (endpoint === "chat") {
|
|
2300
|
+
config = { endpoint, modelMap, useSubscription };
|
|
2301
|
+
} else if (endpoint === "chat") {
|
|
2304
2302
|
const models = Array.isArray(e.models) ? e.models.filter((m) => typeof m === "string" && m.trim() !== "") : [];
|
|
2305
|
-
|
|
2303
|
+
config = { endpoint, models, useSubscription };
|
|
2306
2304
|
if (e.dispatchMode === "prefix") {
|
|
2307
|
-
|
|
2305
|
+
config.dispatchMode = "prefix";
|
|
2308
2306
|
const targets = normalizePrefixTargets(e.prefixTargets);
|
|
2309
|
-
if (targets)
|
|
2307
|
+
if (targets) config.prefixTargets = targets;
|
|
2308
|
+
}
|
|
2309
|
+
} else {
|
|
2310
|
+
config = {
|
|
2311
|
+
endpoint,
|
|
2312
|
+
defaultModel: typeof e.defaultModel === "string" ? e.defaultModel : "",
|
|
2313
|
+
backgroundModel: typeof e.backgroundModel === "string" ? e.backgroundModel : "",
|
|
2314
|
+
useSubscription
|
|
2315
|
+
};
|
|
2316
|
+
if (Array.isArray(e.backgroundModelIds)) {
|
|
2317
|
+
config.backgroundModelIds = e.backgroundModelIds;
|
|
2310
2318
|
}
|
|
2311
|
-
return config2;
|
|
2312
|
-
}
|
|
2313
|
-
const config = {
|
|
2314
|
-
endpoint,
|
|
2315
|
-
defaultModel: typeof e.defaultModel === "string" ? e.defaultModel : "",
|
|
2316
|
-
backgroundModel: typeof e.backgroundModel === "string" ? e.backgroundModel : "",
|
|
2317
|
-
useSubscription
|
|
2318
|
-
};
|
|
2319
|
-
if (Array.isArray(e.backgroundModelIds)) {
|
|
2320
|
-
config.backgroundModelIds = e.backgroundModelIds;
|
|
2321
2319
|
}
|
|
2320
|
+
if (boundAccountId) config.boundAccountId = boundAccountId;
|
|
2321
|
+
if (boundKeyId) config.boundKeyId = boundKeyId;
|
|
2322
2322
|
return config;
|
|
2323
2323
|
}
|
|
2324
2324
|
function defaultServerConfig() {
|
|
@@ -2406,204 +2406,6 @@ function mergeServerConfig(current, patch) {
|
|
|
2406
2406
|
});
|
|
2407
2407
|
}
|
|
2408
2408
|
|
|
2409
|
-
// src/outbound-api/auditCapture.ts
|
|
2410
|
-
import { randomUUID } from "crypto";
|
|
2411
|
-
|
|
2412
|
-
// src/outbound-api/auditRedact.ts
|
|
2413
|
-
var AUDIT_REDACTED = "***REDACTED***";
|
|
2414
|
-
var RULES = [
|
|
2415
|
-
// `sk-…` family (Anthropic sk-ant-, omnicross sk-omnicross-, OpenAI sk-proj-/sk-).
|
|
2416
|
-
{ re: /\bsk-[A-Za-z0-9_-]{6,}/g, replace: AUDIT_REDACTED },
|
|
2417
|
-
// Google API keys.
|
|
2418
|
-
{ re: /\bAIza[A-Za-z0-9_-]{10,}/g, replace: AUDIT_REDACTED },
|
|
2419
|
-
// `Bearer <token>` (auth headers echoed into a body / SSE error).
|
|
2420
|
-
{ re: /\bBearer\s+[A-Za-z0-9._~+/=-]{6,}/gi, replace: `Bearer ${AUDIT_REDACTED}` },
|
|
2421
|
-
// Inline `x-api-key` / `api-key` / `authorization` label followed by a value.
|
|
2422
|
-
{
|
|
2423
|
-
re: /\b(x-api-key|api[_-]?key|authorization)(["']?\s*[:=]\s*["']?)[A-Za-z0-9._~+/=-]{6,}/gi,
|
|
2424
|
-
replace: `$1$2${AUDIT_REDACTED}`
|
|
2425
|
-
},
|
|
2426
|
-
// `x-goog-api-key` header echoed inline.
|
|
2427
|
-
{
|
|
2428
|
-
re: /\b(x-goog-api-key)(["']?\s*[:=]\s*["']?)[A-Za-z0-9._~+/=-]{6,}/gi,
|
|
2429
|
-
replace: `$1$2${AUDIT_REDACTED}`
|
|
2430
|
-
}
|
|
2431
|
-
];
|
|
2432
|
-
function redactAuditText(text) {
|
|
2433
|
-
if (typeof text !== "string" || text.length === 0) return text ?? "";
|
|
2434
|
-
let out = text;
|
|
2435
|
-
for (const { re, replace } of RULES) {
|
|
2436
|
-
out = out.replace(re, replace);
|
|
2437
|
-
}
|
|
2438
|
-
return out;
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
// src/outbound-api/auditCapture.ts
|
|
2442
|
-
function isStreamingContentType(res) {
|
|
2443
|
-
const ct = res.getHeader("content-type");
|
|
2444
|
-
const value = Array.isArray(ct) ? ct.join(";") : String(ct ?? "");
|
|
2445
|
-
return value.toLowerCase().includes("text/event-stream");
|
|
2446
|
-
}
|
|
2447
|
-
function resolveClientIp(req, trustForwardedFor) {
|
|
2448
|
-
if (trustForwardedFor) {
|
|
2449
|
-
const xff = req.headers["x-forwarded-for"];
|
|
2450
|
-
const raw = Array.isArray(xff) ? xff[0] : xff;
|
|
2451
|
-
if (typeof raw === "string" && raw.trim()) {
|
|
2452
|
-
const first = raw.split(",")[0]?.trim();
|
|
2453
|
-
if (first) return first;
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
return req.socket?.remoteAddress ?? void 0;
|
|
2457
|
-
}
|
|
2458
|
-
function truncateToBytes(text, maxBytes) {
|
|
2459
|
-
const buf = Buffer.from(text, "utf8");
|
|
2460
|
-
if (buf.length <= maxBytes) return text;
|
|
2461
|
-
return buf.subarray(0, maxBytes).toString("utf8");
|
|
2462
|
-
}
|
|
2463
|
-
function beginAuditCapture(req, res, now) {
|
|
2464
|
-
const config = getAuditCaptureConfig();
|
|
2465
|
-
if (!config) return null;
|
|
2466
|
-
let rawRequestBody;
|
|
2467
|
-
const responseChunks = [];
|
|
2468
|
-
let responseBytes = 0;
|
|
2469
|
-
let streamDetected = false;
|
|
2470
|
-
let finished = false;
|
|
2471
|
-
const ctx = {
|
|
2472
|
-
setRequestBody(raw) {
|
|
2473
|
-
if (config.captureBodies) rawRequestBody = raw;
|
|
2474
|
-
}
|
|
2475
|
-
};
|
|
2476
|
-
if (config.captureBodies) {
|
|
2477
|
-
installResponseCapture(res, config.maxBodyBytes, {
|
|
2478
|
-
push(chunk) {
|
|
2479
|
-
responseBytes += chunk.length;
|
|
2480
|
-
responseChunks.push(chunk);
|
|
2481
|
-
},
|
|
2482
|
-
get bytes() {
|
|
2483
|
-
return responseBytes;
|
|
2484
|
-
},
|
|
2485
|
-
markStream() {
|
|
2486
|
-
streamDetected = true;
|
|
2487
|
-
},
|
|
2488
|
-
get isStream() {
|
|
2489
|
-
return streamDetected;
|
|
2490
|
-
}
|
|
2491
|
-
});
|
|
2492
|
-
}
|
|
2493
|
-
const finalize = () => {
|
|
2494
|
-
if (finished) return;
|
|
2495
|
-
finished = true;
|
|
2496
|
-
try {
|
|
2497
|
-
const record = {
|
|
2498
|
-
id: randomUUID(),
|
|
2499
|
-
ts: now,
|
|
2500
|
-
method: req.method ?? "",
|
|
2501
|
-
path: (req.url ?? "").split("?")[0] ?? "",
|
|
2502
|
-
status: res.statusCode,
|
|
2503
|
-
latencyMs: Math.max(0, Date.now() - now)
|
|
2504
|
-
};
|
|
2505
|
-
if (ctx.keyId != null) record.keyId = ctx.keyId;
|
|
2506
|
-
const ip = resolveClientIp(req, config.trustForwardedFor);
|
|
2507
|
-
if (ip) record.ip = ip;
|
|
2508
|
-
const ua = req.headers["user-agent"];
|
|
2509
|
-
if (typeof ua === "string" && ua) record.ua = ua;
|
|
2510
|
-
if (ctx.model) record.model = ctx.model;
|
|
2511
|
-
if (ctx.provider) record.provider = ctx.provider;
|
|
2512
|
-
const usage = readAuditUsage(res);
|
|
2513
|
-
if (usage) {
|
|
2514
|
-
if (typeof usage.inputTokens === "number") record.inputTokens = usage.inputTokens;
|
|
2515
|
-
if (typeof usage.outputTokens === "number") record.outputTokens = usage.outputTokens;
|
|
2516
|
-
if (typeof usage.costUsd === "number") record.costUsd = usage.costUsd;
|
|
2517
|
-
if (!record.model && usage.model) record.model = usage.model;
|
|
2518
|
-
if (!record.provider && usage.provider) record.provider = usage.provider;
|
|
2519
|
-
}
|
|
2520
|
-
if (ctx.error) record.error = redactAuditText(ctx.error);
|
|
2521
|
-
if (config.captureBodies) {
|
|
2522
|
-
if (rawRequestBody != null && rawRequestBody.length > 0) {
|
|
2523
|
-
record.requestBody = redactAuditText(truncateToBytes(rawRequestBody, config.maxBodyBytes));
|
|
2524
|
-
}
|
|
2525
|
-
if (!streamDetected && responseChunks.length > 0) {
|
|
2526
|
-
const body = Buffer.concat(responseChunks).toString("utf8");
|
|
2527
|
-
record.responseBody = redactAuditText(body);
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
recordAudit(record);
|
|
2531
|
-
} catch {
|
|
2532
|
-
}
|
|
2533
|
-
};
|
|
2534
|
-
res.once("close", finalize);
|
|
2535
|
-
return ctx;
|
|
2536
|
-
}
|
|
2537
|
-
function installResponseCapture(res, maxBodyBytes, sink2) {
|
|
2538
|
-
let contentTypeChecked = false;
|
|
2539
|
-
const capture = (chunk) => {
|
|
2540
|
-
if (sink2.isStream) return;
|
|
2541
|
-
if (!contentTypeChecked) {
|
|
2542
|
-
contentTypeChecked = true;
|
|
2543
|
-
if (isStreamingContentType(res)) {
|
|
2544
|
-
sink2.markStream();
|
|
2545
|
-
return;
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
if (sink2.bytes >= maxBodyBytes) return;
|
|
2549
|
-
let buf = null;
|
|
2550
|
-
if (Buffer.isBuffer(chunk)) buf = chunk;
|
|
2551
|
-
else if (typeof chunk === "string") buf = Buffer.from(chunk, "utf8");
|
|
2552
|
-
if (!buf || buf.length === 0) return;
|
|
2553
|
-
const remaining = maxBodyBytes - sink2.bytes;
|
|
2554
|
-
sink2.push(buf.length > remaining ? buf.subarray(0, remaining) : buf);
|
|
2555
|
-
};
|
|
2556
|
-
const originalWrite = res.write.bind(res);
|
|
2557
|
-
const originalEnd = res.end.bind(res);
|
|
2558
|
-
res.write = ((chunk, ...args) => {
|
|
2559
|
-
if (chunk != null) capture(chunk);
|
|
2560
|
-
return originalWrite(chunk, ...args);
|
|
2561
|
-
});
|
|
2562
|
-
res.end = ((chunk, ...args) => {
|
|
2563
|
-
if (chunk != null && typeof chunk !== "function") capture(chunk);
|
|
2564
|
-
return originalEnd(chunk, ...args);
|
|
2565
|
-
});
|
|
2566
|
-
}
|
|
2567
|
-
|
|
2568
|
-
// src/outbound-api/billingCapture.ts
|
|
2569
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
2570
|
-
var defaultDefer = (fn) => {
|
|
2571
|
-
setTimeout(fn, 0);
|
|
2572
|
-
};
|
|
2573
|
-
function beginBillingCapture(_req, res, now, defer = defaultDefer) {
|
|
2574
|
-
if (!getBillingCaptureConfig()) return null;
|
|
2575
|
-
const ctx = {};
|
|
2576
|
-
let finished = false;
|
|
2577
|
-
const finalize = () => {
|
|
2578
|
-
if (finished) return;
|
|
2579
|
-
finished = true;
|
|
2580
|
-
const status = res.statusCode;
|
|
2581
|
-
defer(() => {
|
|
2582
|
-
try {
|
|
2583
|
-
const usage = readAuditUsage(res);
|
|
2584
|
-
if (!usage) return;
|
|
2585
|
-
const event = {
|
|
2586
|
-
id: randomUUID2(),
|
|
2587
|
-
ts: now,
|
|
2588
|
-
model: ctx.model ?? usage.model ?? "",
|
|
2589
|
-
authMode: ctx.authMode ?? "byo",
|
|
2590
|
-
inputTokens: usage.inputTokens ?? 0,
|
|
2591
|
-
outputTokens: usage.outputTokens ?? 0,
|
|
2592
|
-
costUsd: usage.costUsd ?? 0,
|
|
2593
|
-
status
|
|
2594
|
-
};
|
|
2595
|
-
if (ctx.keyId != null) event.keyId = ctx.keyId;
|
|
2596
|
-
const provider = ctx.provider ?? usage.provider;
|
|
2597
|
-
if (provider) event.provider = provider;
|
|
2598
|
-
publishBillingEvent(event);
|
|
2599
|
-
} catch {
|
|
2600
|
-
}
|
|
2601
|
-
});
|
|
2602
|
-
};
|
|
2603
|
-
res.once("close", finalize);
|
|
2604
|
-
return ctx;
|
|
2605
|
-
}
|
|
2606
|
-
|
|
2607
2409
|
// src/outbound-api/outboundApiKeyAuth.ts
|
|
2608
2410
|
import { createHash, randomBytes as randomBytes2 } from "crypto";
|
|
2609
2411
|
|
|
@@ -2752,30 +2554,6 @@ async function verifyPresentedKey(db, presentedKey) {
|
|
|
2752
2554
|
return result.status === "ok" ? result.key : null;
|
|
2753
2555
|
}
|
|
2754
2556
|
|
|
2755
|
-
// src/outbound-api/quotaWarn.ts
|
|
2756
|
-
var WEBHOOK_QUOTA_WARN_RATIO = 0.8;
|
|
2757
|
-
function computeQuotaWarnings(limits, spend, ratio = WEBHOOK_QUOTA_WARN_RATIO) {
|
|
2758
|
-
const out = [];
|
|
2759
|
-
const consider = (scope, limit, spent, windowStart) => {
|
|
2760
|
-
if (limit == null || limit <= 0) return;
|
|
2761
|
-
if (spent >= limit) return;
|
|
2762
|
-
if (spent >= ratio * limit) out.push({ scope, limitUsd: limit, spentUsd: spent, windowStart });
|
|
2763
|
-
};
|
|
2764
|
-
consider("daily", limits.dailyUsd, spend.dailyUsd, spend.dailyWindowStart);
|
|
2765
|
-
consider("weekly", limits.weeklyUsd, spend.weeklyUsd, spend.weeklyWindowStart);
|
|
2766
|
-
consider("total", limits.totalUsd, spend.totalUsd, 0);
|
|
2767
|
-
return out;
|
|
2768
|
-
}
|
|
2769
|
-
var WARN_GUARD_MAX = 1e4;
|
|
2770
|
-
var warned = /* @__PURE__ */ new Set();
|
|
2771
|
-
function markQuotaWarnedOnce(keyId, scope, windowStart) {
|
|
2772
|
-
const key = `${keyId}\0${scope}\0${windowStart}`;
|
|
2773
|
-
if (warned.has(key)) return false;
|
|
2774
|
-
if (warned.size >= WARN_GUARD_MAX) warned.clear();
|
|
2775
|
-
warned.add(key);
|
|
2776
|
-
return true;
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2779
2557
|
// src/outbound-api/outboundConcurrencyGate.ts
|
|
2780
2558
|
var ConcurrencyQueueFullError = class extends Error {
|
|
2781
2559
|
constructor(apiKeyId, maxQueueSize) {
|
|
@@ -5646,8 +5424,8 @@ var CompletionService = class {
|
|
|
5646
5424
|
* emission is unconditional in production. Optional — when unset (unit-test
|
|
5647
5425
|
* constructors), the emit calls no-op, identical to `usageRecorder`.
|
|
5648
5426
|
*/
|
|
5649
|
-
setUsageEventSink(
|
|
5650
|
-
this.usageEventSink =
|
|
5427
|
+
setUsageEventSink(sink) {
|
|
5428
|
+
this.usageEventSink = sink;
|
|
5651
5429
|
}
|
|
5652
5430
|
/**
|
|
5653
5431
|
* Set the vision-fallback provider used by `applyVisionFallback` to describe
|
|
@@ -6155,10 +5933,6 @@ export {
|
|
|
6155
5933
|
loadServerConfig,
|
|
6156
5934
|
saveServerConfig,
|
|
6157
5935
|
mergeServerConfig,
|
|
6158
|
-
AUDIT_REDACTED,
|
|
6159
|
-
redactAuditText,
|
|
6160
|
-
beginAuditCapture,
|
|
6161
|
-
beginBillingCapture,
|
|
6162
5936
|
computeKeyExpiry,
|
|
6163
5937
|
checkKeyQuota,
|
|
6164
5938
|
randomBase62,
|
|
@@ -1,8 +1,5 @@
|
|
|
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 _chunkC72S6TTVcjs = require('./chunk-C72S6TTV.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
3
|
var _chunkDWKQZ2SKcjs = require('./chunk-DWKQZ2SK.cjs');
|
|
7
4
|
|
|
8
5
|
|
|
@@ -12,7 +9,10 @@ var _chunk4VAVYUZScjs = require('./chunk-4VAVYUZS.cjs');
|
|
|
12
9
|
var _chunk7YN22L2Hcjs = require('./chunk-7YN22L2H.cjs');
|
|
13
10
|
|
|
14
11
|
|
|
15
|
-
var
|
|
12
|
+
var _chunkSU2GCLACcjs = require('./chunk-SU2GCLAC.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
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() {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const existing = stash.get(key);
|
|
5
|
-
stash.set(key, existing ? { ...existing, ...detail } : { ...detail });
|
|
6
|
-
}
|
|
7
|
-
function readAuditUsage(key) {
|
|
8
|
-
return stash.get(key);
|
|
9
|
-
}
|
|
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');
|
|
10
4
|
|
|
11
5
|
// src/usage/usage-recorder.ts
|
|
12
6
|
var UsageRecorder = class {
|
|
@@ -30,7 +24,7 @@ var UsageRecorder = class {
|
|
|
30
24
|
*/
|
|
31
25
|
record(input) {
|
|
32
26
|
if (input.auditResponse) {
|
|
33
|
-
stashAuditUsage(input.auditResponse, {
|
|
27
|
+
_chunkXSVNC2UDcjs.stashAuditUsage.call(void 0, input.auditResponse, {
|
|
34
28
|
inputTokens: input.usage.inputTokens,
|
|
35
29
|
outputTokens: input.usage.outputTokens,
|
|
36
30
|
model: input.model,
|
|
@@ -57,7 +51,7 @@ var UsageRecorder = class {
|
|
|
57
51
|
);
|
|
58
52
|
if (input.auditResponse) {
|
|
59
53
|
try {
|
|
60
|
-
stashAuditUsage(input.auditResponse, { costUsd });
|
|
54
|
+
_chunkXSVNC2UDcjs.stashAuditUsage.call(void 0, input.auditResponse, { costUsd });
|
|
61
55
|
} catch (e) {
|
|
62
56
|
}
|
|
63
57
|
}
|
|
@@ -126,5 +120,4 @@ var safeStringify = (value) => {
|
|
|
126
120
|
|
|
127
121
|
|
|
128
122
|
|
|
129
|
-
|
|
130
|
-
exports.readAuditUsage = readAuditUsage; exports.UsageRecorder = UsageRecorder;
|
|
123
|
+
exports.UsageRecorder = UsageRecorder;
|
|
@@ -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();
|