@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
package/dist/index.js
CHANGED
|
@@ -1,77 +1,146 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CompletionService,
|
|
3
|
+
ConcurrencyQueueFullError,
|
|
4
|
+
ConcurrencyWaitCancelledError,
|
|
5
|
+
ConcurrencyWaitTimeoutError,
|
|
6
|
+
DEFAULT_ACCOUNT_PROBE,
|
|
7
|
+
DEFAULT_CONCURRENCY_QUEUE,
|
|
8
|
+
DEFAULT_FINGERPRINT,
|
|
3
9
|
DEFAULT_OUTBOUND_PORT,
|
|
4
10
|
DEFAULT_ROUTE_IDLE_MS,
|
|
11
|
+
DEFAULT_USER_MESSAGE_QUEUE,
|
|
12
|
+
KeySpendTracker,
|
|
13
|
+
KeyedMutex,
|
|
5
14
|
OUTBOUND_API_SERVER_CONFIG_KEY,
|
|
15
|
+
OutboundApiConfigError,
|
|
6
16
|
OutboundApiServer,
|
|
17
|
+
OutboundConcurrencyGate,
|
|
7
18
|
OutboundRateLimiter,
|
|
8
19
|
ProviderProxy,
|
|
9
20
|
ProviderProxyRouteMap,
|
|
21
|
+
SerialQueueTimeoutError,
|
|
22
|
+
UserMessageSerialQueue,
|
|
10
23
|
__resetOutboundApiServerForTests,
|
|
11
24
|
__resetProviderProxyForTests,
|
|
12
25
|
addOpenRouterProviderToRequest,
|
|
13
26
|
attach,
|
|
27
|
+
checkKeyQuota,
|
|
28
|
+
computeKeyExpiry,
|
|
29
|
+
computeVoucherGrant,
|
|
14
30
|
convertMessageToAnthropic,
|
|
15
31
|
convertMessageToGemini,
|
|
16
32
|
convertMessageToOpenAI,
|
|
17
33
|
createNamedKey,
|
|
18
34
|
defaultServerConfig,
|
|
19
|
-
detectRequestRole,
|
|
20
35
|
emit,
|
|
21
|
-
endpointToIngressFormat,
|
|
22
36
|
extractRouteToken,
|
|
23
37
|
formatUrls,
|
|
38
|
+
generateVoucherCode,
|
|
24
39
|
getOpenRouterProviderConfig,
|
|
25
40
|
getOutboundApiServer,
|
|
26
41
|
getProviderProxy,
|
|
42
|
+
handleVoucherRedeem,
|
|
27
43
|
hashKey,
|
|
44
|
+
hashVoucherCode,
|
|
45
|
+
isConcurrencyRejection,
|
|
46
|
+
isRedeemRequest,
|
|
47
|
+
isSerialQueueTimeout,
|
|
48
|
+
isUserMessageRequest,
|
|
28
49
|
loadServerConfig,
|
|
29
50
|
mergeServerConfig,
|
|
51
|
+
newVoucherId,
|
|
52
|
+
normalizeAccountProbe,
|
|
53
|
+
normalizeAudit,
|
|
54
|
+
normalizeBilling,
|
|
55
|
+
normalizeFingerprint,
|
|
56
|
+
normalizePrefixTargets,
|
|
57
|
+
normalizeProxyConfig,
|
|
58
|
+
normalizeProxySegment,
|
|
59
|
+
normalizeQueueSegments,
|
|
30
60
|
normalizeServerConfig,
|
|
61
|
+
normalizeVoucher,
|
|
62
|
+
normalizeWebhookDestination,
|
|
63
|
+
normalizeWebhookSegment,
|
|
64
|
+
randomBase62,
|
|
31
65
|
register,
|
|
32
66
|
release,
|
|
33
67
|
saveServerConfig,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
68
|
+
startOfLocalDay,
|
|
69
|
+
startOfLocalWeek,
|
|
70
|
+
toVoucherInfo,
|
|
71
|
+
verifyKey,
|
|
72
|
+
verifyPresentedKey,
|
|
73
|
+
voucherCodePrefix
|
|
74
|
+
} from "./chunk-QYTT6GE3.js";
|
|
37
75
|
import {
|
|
38
76
|
createSSEParser,
|
|
39
77
|
streamSSEResponse
|
|
40
78
|
} from "./chunk-VVEHS2LI.js";
|
|
41
79
|
import "./chunk-46RLHI7D.js";
|
|
42
|
-
import {
|
|
43
|
-
TransformerChainExecutor
|
|
44
|
-
} from "./chunk-G2UTNSGU.js";
|
|
45
|
-
import "./chunk-MZNPGW5Q.js";
|
|
46
80
|
import {
|
|
47
81
|
TransformerService
|
|
48
82
|
} from "./chunk-DK4A7DLE.js";
|
|
49
83
|
import {
|
|
50
84
|
registerBuiltinTransformers
|
|
51
|
-
} from "./chunk-
|
|
52
|
-
import "./chunk-C7PSERMH.js";
|
|
53
|
-
import "./chunk-5HTVET6E.js";
|
|
54
|
-
import "./chunk-Z7LUNECE.js";
|
|
85
|
+
} from "./chunk-VPBAUQ2M.js";
|
|
55
86
|
import "./chunk-ZJZAOKI7.js";
|
|
56
87
|
import "./chunk-FTQ7IQUC.js";
|
|
88
|
+
import "./chunk-C7PSERMH.js";
|
|
89
|
+
import "./chunk-TIER4SUC.js";
|
|
90
|
+
import "./chunk-Z7LUNECE.js";
|
|
57
91
|
import "./chunk-7VU7V2E4.js";
|
|
58
92
|
import {
|
|
59
93
|
PricingEngine
|
|
60
94
|
} from "./chunk-ZLX3KGXX.js";
|
|
61
95
|
import {
|
|
62
96
|
UsageRecorder
|
|
63
|
-
} from "./chunk-
|
|
97
|
+
} from "./chunk-BPKCU575.js";
|
|
98
|
+
import {
|
|
99
|
+
TransformerChainExecutor
|
|
100
|
+
} from "./chunk-G2UTNSGU.js";
|
|
101
|
+
import "./chunk-MZNPGW5Q.js";
|
|
102
|
+
import "./chunk-XTEI64OU.js";
|
|
103
|
+
import "./chunk-XX6NQJMA.js";
|
|
104
|
+
import "./chunk-IAXWICZU.js";
|
|
105
|
+
import "./chunk-OE6TDIWW.js";
|
|
64
106
|
import "./chunk-DRWHTIIZ.js";
|
|
65
|
-
import "./chunk-
|
|
107
|
+
import "./chunk-IK3KE3AU.js";
|
|
66
108
|
import {
|
|
67
109
|
getProviderHeaders
|
|
68
|
-
} from "./chunk-
|
|
110
|
+
} from "./chunk-ZY6KU6P3.js";
|
|
69
111
|
import "./chunk-JWC6APFQ.js";
|
|
70
112
|
import "./chunk-5ERIZW3D.js";
|
|
71
|
-
import "./chunk-
|
|
113
|
+
import "./chunk-5ENKBSWO.js";
|
|
114
|
+
import "./chunk-HRRYG2AX.js";
|
|
72
115
|
import {
|
|
73
116
|
serializeError
|
|
74
117
|
} from "./chunk-AVYJ4YBN.js";
|
|
118
|
+
import {
|
|
119
|
+
beginBillingCapture
|
|
120
|
+
} from "./chunk-WLYIIEAF.js";
|
|
121
|
+
import "./chunk-TKJMZBAH.js";
|
|
122
|
+
import "./chunk-3QFXFCHG.js";
|
|
123
|
+
import {
|
|
124
|
+
SUBSCRIPTION_PROVIDER_IDS,
|
|
125
|
+
classifyModelPrefix,
|
|
126
|
+
detectModelKind,
|
|
127
|
+
detectRequestRole,
|
|
128
|
+
endpointSupportsSubscription,
|
|
129
|
+
endpointToIngressFormat,
|
|
130
|
+
isKindMappedEndpoint,
|
|
131
|
+
isSubscriptionProviderId,
|
|
132
|
+
modelKindsForEndpoint,
|
|
133
|
+
parseModelRef,
|
|
134
|
+
pickModelRefFromList,
|
|
135
|
+
resolvePrefixTarget,
|
|
136
|
+
resolveRoute,
|
|
137
|
+
validateEndpointModelConfig,
|
|
138
|
+
validateServerModelConfig
|
|
139
|
+
} from "./chunk-UHGVBFU3.js";
|
|
140
|
+
import "./chunk-AQ5TNQB7.js";
|
|
141
|
+
import {
|
|
142
|
+
ENDPOINT_MODEL_KINDS
|
|
143
|
+
} from "./chunk-XEKD23J5.js";
|
|
75
144
|
import {
|
|
76
145
|
buildAnthropicApiUrl,
|
|
77
146
|
buildAzureOpenAIApiUrl,
|
|
@@ -84,12 +153,14 @@ import {
|
|
|
84
153
|
resolveProviderEndpoint
|
|
85
154
|
} from "./chunk-H5JUT3KV.js";
|
|
86
155
|
import {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
156
|
+
beginAuditCapture
|
|
157
|
+
} from "./chunk-7Y47UCF2.js";
|
|
158
|
+
import {
|
|
159
|
+
AUDIT_REDACTED,
|
|
160
|
+
redactAuditText
|
|
161
|
+
} from "./chunk-K5NM7VAH.js";
|
|
162
|
+
import "./chunk-WNY4WMRF.js";
|
|
163
|
+
import "./chunk-OZFM4X3S.js";
|
|
93
164
|
import {
|
|
94
165
|
convertAnthropicRequestToOpenAI,
|
|
95
166
|
convertAnthropicStreamToOpenAI,
|
|
@@ -104,6 +175,7 @@ import {
|
|
|
104
175
|
} from "./chunk-5ZQBEOMD.js";
|
|
105
176
|
import "./chunk-Z7Y2NPHY.js";
|
|
106
177
|
import "./chunk-S4WBV25P.js";
|
|
178
|
+
import "./chunk-XK5CIRMQ.js";
|
|
107
179
|
import {
|
|
108
180
|
BuiltinToolExecutor,
|
|
109
181
|
getBuiltinSearchTools
|
|
@@ -112,36 +184,55 @@ import {
|
|
|
112
184
|
applyAugmentation,
|
|
113
185
|
buildNativeSearchAugmentation,
|
|
114
186
|
detectNativeSearch
|
|
115
|
-
} from "./chunk-
|
|
116
|
-
import {
|
|
117
|
-
OPENROUTER_APP_HEADERS,
|
|
118
|
-
isOpenRouterProvider
|
|
119
|
-
} from "./chunk-E3WHL7CO.js";
|
|
187
|
+
} from "./chunk-Y7FO65VT.js";
|
|
120
188
|
import {
|
|
121
189
|
NATIVE_SEARCH_TOOL_NAMES
|
|
122
190
|
} from "./chunk-FMOBD2OQ.js";
|
|
191
|
+
import {
|
|
192
|
+
OPENROUTER_APP_HEADERS,
|
|
193
|
+
getOpenRouterAppIdentity,
|
|
194
|
+
isOpenRouterProvider,
|
|
195
|
+
setOpenRouterAppIdentity
|
|
196
|
+
} from "./chunk-HUZZZ3JL.js";
|
|
123
197
|
export {
|
|
198
|
+
AUDIT_REDACTED,
|
|
124
199
|
BuiltinToolExecutor,
|
|
125
200
|
CompletionService,
|
|
201
|
+
ConcurrencyQueueFullError,
|
|
202
|
+
ConcurrencyWaitCancelledError,
|
|
203
|
+
ConcurrencyWaitTimeoutError,
|
|
204
|
+
DEFAULT_ACCOUNT_PROBE,
|
|
205
|
+
DEFAULT_CONCURRENCY_QUEUE,
|
|
206
|
+
DEFAULT_FINGERPRINT,
|
|
126
207
|
DEFAULT_OUTBOUND_PORT,
|
|
127
208
|
DEFAULT_ROUTE_IDLE_MS,
|
|
209
|
+
DEFAULT_USER_MESSAGE_QUEUE,
|
|
210
|
+
ENDPOINT_MODEL_KINDS,
|
|
211
|
+
KeySpendTracker,
|
|
212
|
+
KeyedMutex,
|
|
128
213
|
NATIVE_SEARCH_TOOL_NAMES,
|
|
129
214
|
OPENROUTER_APP_HEADERS,
|
|
130
215
|
OUTBOUND_API_SERVER_CONFIG_KEY,
|
|
216
|
+
OutboundApiConfigError,
|
|
131
217
|
OutboundApiServer,
|
|
218
|
+
OutboundConcurrencyGate,
|
|
132
219
|
OutboundRateLimiter,
|
|
133
220
|
PricingEngine,
|
|
134
221
|
ProviderProxy,
|
|
135
222
|
ProviderProxyRouteMap,
|
|
136
223
|
SUBSCRIPTION_PROVIDER_IDS,
|
|
224
|
+
SerialQueueTimeoutError,
|
|
137
225
|
TransformerChainExecutor,
|
|
138
226
|
TransformerService,
|
|
139
227
|
UsageRecorder,
|
|
228
|
+
UserMessageSerialQueue,
|
|
140
229
|
__resetOutboundApiServerForTests,
|
|
141
230
|
__resetProviderProxyForTests,
|
|
142
231
|
addOpenRouterProviderToRequest,
|
|
143
232
|
applyAugmentation,
|
|
144
233
|
attach as attachStreamEventBuffer,
|
|
234
|
+
beginAuditCapture,
|
|
235
|
+
beginBillingCapture,
|
|
145
236
|
buildAnthropicApiUrl,
|
|
146
237
|
buildAzureOpenAIApiUrl,
|
|
147
238
|
buildGeminiApiUrl,
|
|
@@ -149,6 +240,10 @@ export {
|
|
|
149
240
|
buildOpenAIApiUrl,
|
|
150
241
|
buildOpenAIResponseApiUrl,
|
|
151
242
|
buildProviderApiUrl,
|
|
243
|
+
checkKeyQuota,
|
|
244
|
+
classifyModelPrefix,
|
|
245
|
+
computeKeyExpiry,
|
|
246
|
+
computeVoucherGrant,
|
|
152
247
|
convertAnthropicRequestToOpenAI,
|
|
153
248
|
convertAnthropicStreamToOpenAI,
|
|
154
249
|
convertAnthropicToOpenAI,
|
|
@@ -163,6 +258,7 @@ export {
|
|
|
163
258
|
createNamedKey,
|
|
164
259
|
createSSEParser,
|
|
165
260
|
defaultServerConfig,
|
|
261
|
+
detectModelKind,
|
|
166
262
|
detectNativeSearch,
|
|
167
263
|
detectRequestRole,
|
|
168
264
|
emit as emitStreamEvent,
|
|
@@ -170,28 +266,63 @@ export {
|
|
|
170
266
|
endpointToIngressFormat,
|
|
171
267
|
extractRouteToken,
|
|
172
268
|
formatUrls,
|
|
269
|
+
generateVoucherCode,
|
|
173
270
|
getBuiltinSearchTools,
|
|
271
|
+
getOpenRouterAppIdentity,
|
|
174
272
|
getOpenRouterProviderConfig,
|
|
175
273
|
getOutboundApiServer,
|
|
176
274
|
getProviderHeaders,
|
|
177
275
|
getProviderProxy,
|
|
276
|
+
handleVoucherRedeem,
|
|
178
277
|
hasImageContent,
|
|
179
278
|
hasThinkingEnabled,
|
|
180
279
|
hashKey,
|
|
280
|
+
hashVoucherCode,
|
|
281
|
+
isConcurrencyRejection,
|
|
282
|
+
isKindMappedEndpoint,
|
|
181
283
|
isOpenRouterProvider,
|
|
284
|
+
isRedeemRequest,
|
|
285
|
+
isSerialQueueTimeout,
|
|
182
286
|
isSubscriptionProviderId,
|
|
287
|
+
isUserMessageRequest,
|
|
183
288
|
loadServerConfig,
|
|
184
289
|
mergeServerConfig,
|
|
290
|
+
modelKindsForEndpoint,
|
|
291
|
+
newVoucherId,
|
|
292
|
+
normalizeAccountProbe,
|
|
293
|
+
normalizeAudit,
|
|
185
294
|
normalizeAzureEndpoint,
|
|
295
|
+
normalizeBilling,
|
|
296
|
+
normalizeFingerprint,
|
|
297
|
+
normalizePrefixTargets,
|
|
298
|
+
normalizeProxyConfig,
|
|
299
|
+
normalizeProxySegment,
|
|
300
|
+
normalizeQueueSegments,
|
|
186
301
|
normalizeServerConfig,
|
|
302
|
+
normalizeVoucher,
|
|
303
|
+
normalizeWebhookDestination,
|
|
304
|
+
normalizeWebhookSegment,
|
|
305
|
+
parseModelRef,
|
|
306
|
+
pickModelRefFromList,
|
|
307
|
+
randomBase62,
|
|
308
|
+
redactAuditText,
|
|
187
309
|
registerBuiltinTransformers,
|
|
188
310
|
register as registerStreamEventBuffer,
|
|
189
311
|
release as releaseStreamEventBuffer,
|
|
190
312
|
resolveApiFormat,
|
|
313
|
+
resolvePrefixTarget,
|
|
191
314
|
resolveProviderEndpoint,
|
|
192
315
|
resolveRoute,
|
|
193
316
|
saveServerConfig,
|
|
194
317
|
serializeError,
|
|
318
|
+
setOpenRouterAppIdentity,
|
|
319
|
+
startOfLocalDay,
|
|
320
|
+
startOfLocalWeek,
|
|
195
321
|
streamSSEResponse,
|
|
196
|
-
|
|
322
|
+
toVoucherInfo,
|
|
323
|
+
validateEndpointModelConfig,
|
|
324
|
+
validateServerModelConfig,
|
|
325
|
+
verifyKey,
|
|
326
|
+
verifyPresentedKey,
|
|
327
|
+
voucherCodePrefix
|
|
197
328
|
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* keyPolicy — PURE decision helpers for the outbound key-policy envelope
|
|
3
|
+
* (`outbound-key-policy`, design D2/D4). Expiry/activation resolution +
|
|
4
|
+
* cost-quota decision. No I/O, no clock ownership (the caller passes `now`), so
|
|
5
|
+
* these are trivially unit-testable and reused by both the auth path
|
|
6
|
+
* (`verifyKey`) and the wire path (`outboundApiRouter`).
|
|
7
|
+
*
|
|
8
|
+
* The #6 (`restrictedModels`) and #9 (voucher) children EXTEND the key-policy
|
|
9
|
+
* schema; they must not change the shapes frozen here.
|
|
10
|
+
*
|
|
11
|
+
* @module outbound-api/keyPolicy
|
|
12
|
+
*/
|
|
13
|
+
/** The expiry/activation subset of a key row `computeKeyExpiry` reads. */
|
|
14
|
+
interface KeyExpiryInput {
|
|
15
|
+
/** Fixed-mode absolute expiry (epoch ms). */
|
|
16
|
+
expiresAt?: number | null;
|
|
17
|
+
/** Expiry mode; absent ⇒ `'fixed'`. */
|
|
18
|
+
activationMode?: 'fixed' | 'activation';
|
|
19
|
+
/** Activation-mode lifetime in days (absent/null ⇒ never expires). */
|
|
20
|
+
activationDays?: number | null;
|
|
21
|
+
/** First-use activation stamp (epoch ms); null ⇒ not yet activated. */
|
|
22
|
+
activatedAt?: number | null;
|
|
23
|
+
}
|
|
24
|
+
/** Result of {@link computeKeyExpiry}. */
|
|
25
|
+
interface KeyExpiryResult {
|
|
26
|
+
expired: boolean;
|
|
27
|
+
/** The resolved absolute expiry (epoch ms), when the key has one. */
|
|
28
|
+
effectiveExpiresAt?: number;
|
|
29
|
+
/**
|
|
30
|
+
* True when this is an activation-mode key that has NOT been activated yet, so
|
|
31
|
+
* the caller SHOULD stamp the activation (best-effort) on a successful verify.
|
|
32
|
+
*/
|
|
33
|
+
needsActivation?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolve whether a key is past its effective expiry (design D2).
|
|
37
|
+
* - `fixed`: expired when `expiresAt != null && now >= expiresAt`.
|
|
38
|
+
* - `activation`: while `activatedAt == null` the key is NOT expired (it
|
|
39
|
+
* activates on THIS use → `needsActivation`); once activated, expired when
|
|
40
|
+
* `now >= activatedAt + activationDays*DAY`. A null `activationDays` never
|
|
41
|
+
* expires.
|
|
42
|
+
* A key with no expiry configured never expires.
|
|
43
|
+
*/
|
|
44
|
+
declare function computeKeyExpiry(row: KeyExpiryInput, now: number): KeyExpiryResult;
|
|
45
|
+
/** Per-key USD cost limits carried on the verified key (absent scope ⇒ no cap). */
|
|
46
|
+
interface KeyCostLimits {
|
|
47
|
+
dailyUsd?: number;
|
|
48
|
+
totalUsd?: number;
|
|
49
|
+
weeklyUsd?: number;
|
|
50
|
+
}
|
|
51
|
+
/** In-memory per-key accumulated spend snapshot (see `keySpendTracker`). */
|
|
52
|
+
interface KeySpend {
|
|
53
|
+
dailyUsd: number;
|
|
54
|
+
/** Local-midnight boundary the `dailyUsd` window opened at (epoch ms). */
|
|
55
|
+
dailyWindowStart: number;
|
|
56
|
+
weeklyUsd: number;
|
|
57
|
+
/** Local week-start boundary the `weeklyUsd` window opened at (epoch ms). */
|
|
58
|
+
weeklyWindowStart: number;
|
|
59
|
+
totalUsd: number;
|
|
60
|
+
}
|
|
61
|
+
/** Decision returned by {@link checkKeyQuota}. */
|
|
62
|
+
type QuotaDecision = {
|
|
63
|
+
allowed: true;
|
|
64
|
+
} | {
|
|
65
|
+
allowed: false;
|
|
66
|
+
scope: 'daily' | 'weekly' | 'total';
|
|
67
|
+
limitUsd: number;
|
|
68
|
+
spentUsd: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Decide whether the key's accumulated spend already meets/exceeds any
|
|
72
|
+
* configured cost limit (design D4). `allowed:false` when a scope's PRIOR spend
|
|
73
|
+
* is `>= limit` (the triggering request's own cost is unknown pre-flight →
|
|
74
|
+
* bounded one-request overage, CRS-equivalent). An unconfigured scope is never
|
|
75
|
+
* gated; a `limits`-less key always passes.
|
|
76
|
+
*/
|
|
77
|
+
declare function checkKeyQuota(limits: KeyCostLimits | undefined, spend: KeySpend): QuotaDecision;
|
|
78
|
+
/**
|
|
79
|
+
* Per-key model restriction carried on the verified key (outbound-key-policy #6).
|
|
80
|
+
* Present ONLY when the key has `enableModelRestriction === true` — so the wire
|
|
81
|
+
* layer's presence check (`if (key.modelRestriction) …`) is the zero-regression
|
|
82
|
+
* gate.
|
|
83
|
+
*/
|
|
84
|
+
interface ModelRestriction {
|
|
85
|
+
mode: 'blacklist' | 'allowlist';
|
|
86
|
+
/** Bare modelIds the mode acts on. Empty allowlist denies every model. */
|
|
87
|
+
models: string[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { type KeyCostLimits as K, type ModelRestriction as M, type QuotaDecision as Q, type KeyExpiryInput as a, type KeyExpiryResult as b, type KeySpend as c, checkKeyQuota as d, computeKeyExpiry as e };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* keyPolicy — PURE decision helpers for the outbound key-policy envelope
|
|
3
|
+
* (`outbound-key-policy`, design D2/D4). Expiry/activation resolution +
|
|
4
|
+
* cost-quota decision. No I/O, no clock ownership (the caller passes `now`), so
|
|
5
|
+
* these are trivially unit-testable and reused by both the auth path
|
|
6
|
+
* (`verifyKey`) and the wire path (`outboundApiRouter`).
|
|
7
|
+
*
|
|
8
|
+
* The #6 (`restrictedModels`) and #9 (voucher) children EXTEND the key-policy
|
|
9
|
+
* schema; they must not change the shapes frozen here.
|
|
10
|
+
*
|
|
11
|
+
* @module outbound-api/keyPolicy
|
|
12
|
+
*/
|
|
13
|
+
/** The expiry/activation subset of a key row `computeKeyExpiry` reads. */
|
|
14
|
+
interface KeyExpiryInput {
|
|
15
|
+
/** Fixed-mode absolute expiry (epoch ms). */
|
|
16
|
+
expiresAt?: number | null;
|
|
17
|
+
/** Expiry mode; absent ⇒ `'fixed'`. */
|
|
18
|
+
activationMode?: 'fixed' | 'activation';
|
|
19
|
+
/** Activation-mode lifetime in days (absent/null ⇒ never expires). */
|
|
20
|
+
activationDays?: number | null;
|
|
21
|
+
/** First-use activation stamp (epoch ms); null ⇒ not yet activated. */
|
|
22
|
+
activatedAt?: number | null;
|
|
23
|
+
}
|
|
24
|
+
/** Result of {@link computeKeyExpiry}. */
|
|
25
|
+
interface KeyExpiryResult {
|
|
26
|
+
expired: boolean;
|
|
27
|
+
/** The resolved absolute expiry (epoch ms), when the key has one. */
|
|
28
|
+
effectiveExpiresAt?: number;
|
|
29
|
+
/**
|
|
30
|
+
* True when this is an activation-mode key that has NOT been activated yet, so
|
|
31
|
+
* the caller SHOULD stamp the activation (best-effort) on a successful verify.
|
|
32
|
+
*/
|
|
33
|
+
needsActivation?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolve whether a key is past its effective expiry (design D2).
|
|
37
|
+
* - `fixed`: expired when `expiresAt != null && now >= expiresAt`.
|
|
38
|
+
* - `activation`: while `activatedAt == null` the key is NOT expired (it
|
|
39
|
+
* activates on THIS use → `needsActivation`); once activated, expired when
|
|
40
|
+
* `now >= activatedAt + activationDays*DAY`. A null `activationDays` never
|
|
41
|
+
* expires.
|
|
42
|
+
* A key with no expiry configured never expires.
|
|
43
|
+
*/
|
|
44
|
+
declare function computeKeyExpiry(row: KeyExpiryInput, now: number): KeyExpiryResult;
|
|
45
|
+
/** Per-key USD cost limits carried on the verified key (absent scope ⇒ no cap). */
|
|
46
|
+
interface KeyCostLimits {
|
|
47
|
+
dailyUsd?: number;
|
|
48
|
+
totalUsd?: number;
|
|
49
|
+
weeklyUsd?: number;
|
|
50
|
+
}
|
|
51
|
+
/** In-memory per-key accumulated spend snapshot (see `keySpendTracker`). */
|
|
52
|
+
interface KeySpend {
|
|
53
|
+
dailyUsd: number;
|
|
54
|
+
/** Local-midnight boundary the `dailyUsd` window opened at (epoch ms). */
|
|
55
|
+
dailyWindowStart: number;
|
|
56
|
+
weeklyUsd: number;
|
|
57
|
+
/** Local week-start boundary the `weeklyUsd` window opened at (epoch ms). */
|
|
58
|
+
weeklyWindowStart: number;
|
|
59
|
+
totalUsd: number;
|
|
60
|
+
}
|
|
61
|
+
/** Decision returned by {@link checkKeyQuota}. */
|
|
62
|
+
type QuotaDecision = {
|
|
63
|
+
allowed: true;
|
|
64
|
+
} | {
|
|
65
|
+
allowed: false;
|
|
66
|
+
scope: 'daily' | 'weekly' | 'total';
|
|
67
|
+
limitUsd: number;
|
|
68
|
+
spentUsd: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Decide whether the key's accumulated spend already meets/exceeds any
|
|
72
|
+
* configured cost limit (design D4). `allowed:false` when a scope's PRIOR spend
|
|
73
|
+
* is `>= limit` (the triggering request's own cost is unknown pre-flight →
|
|
74
|
+
* bounded one-request overage, CRS-equivalent). An unconfigured scope is never
|
|
75
|
+
* gated; a `limits`-less key always passes.
|
|
76
|
+
*/
|
|
77
|
+
declare function checkKeyQuota(limits: KeyCostLimits | undefined, spend: KeySpend): QuotaDecision;
|
|
78
|
+
/**
|
|
79
|
+
* Per-key model restriction carried on the verified key (outbound-key-policy #6).
|
|
80
|
+
* Present ONLY when the key has `enableModelRestriction === true` — so the wire
|
|
81
|
+
* layer's presence check (`if (key.modelRestriction) …`) is the zero-regression
|
|
82
|
+
* gate.
|
|
83
|
+
*/
|
|
84
|
+
interface ModelRestriction {
|
|
85
|
+
mode: 'blacklist' | 'allowlist';
|
|
86
|
+
/** Bare modelIds the mode acts on. Empty allowlist denies every model. */
|
|
87
|
+
models: string[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { type KeyCostLimits as K, type ModelRestriction as M, type QuotaDecision as Q, type KeyExpiryInput as a, type KeyExpiryResult as b, type KeySpend as c, checkKeyQuota as d, computeKeyExpiry as e };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkE3UCVHLPcjs = require('../chunk-E3UCVHLP.cjs');
|
|
4
|
+
require('../chunk-FCR77GYM.cjs');
|
|
5
|
+
require('../chunk-AEOZIDEB.cjs');
|
|
6
|
+
require('../chunk-XSVNC2UD.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.beginAuditCapture = _chunkE3UCVHLPcjs.beginAuditCapture;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* auditCapture — the outbound server's post-response audit capture hook
|
|
5
|
+
* (request-audit-log, design D1/D3/D5).
|
|
6
|
+
*
|
|
7
|
+
* {@link beginAuditCapture} is called at the TOP of `handleOutboundRequest`. It
|
|
8
|
+
* reads the active capture config from the core slot; when audit is DISABLED it
|
|
9
|
+
* returns `null` immediately (one slot read — no assembly, no listener, zero
|
|
10
|
+
* regression). When enabled it:
|
|
11
|
+
* - registers a one-shot `res.on('close')` listener that, at response end,
|
|
12
|
+
* assembles the {@link AuditRecord} from the http `req` (IP via the socket, or
|
|
13
|
+
* a trusted `X-Forwarded-For` only when configured — LEAD OQ1 anti-spoof; UA;
|
|
14
|
+
* method; path with the query string DROPPED), the response `statusCode`, the
|
|
15
|
+
* elapsed ms, and the fields the handler fills in (keyId / model / provider /
|
|
16
|
+
* error / bodies) — then hands it to the fire-and-forget `recordAudit`;
|
|
17
|
+
* - when `captureBodies` is ALSO on, wraps `res.write`/`res.end` to accumulate a
|
|
18
|
+
* BOUNDED response body (metadata-only for a streaming `text/event-stream`
|
|
19
|
+
* response — a full stream is unbounded), and truncates+redacts both bodies.
|
|
20
|
+
*
|
|
21
|
+
* Request HEADERS are NEVER read into a record (Authorization / x-api-key live
|
|
22
|
+
* there). Every stored body passes through {@link redactAuditText}. The assembly
|
|
23
|
+
* is wrapped so a capture failure can never surface into the relay path.
|
|
24
|
+
*
|
|
25
|
+
* @module @omnicross/core/outbound-api/auditCapture
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The mutable context the request handler enriches as it progresses. `null` is
|
|
30
|
+
* returned by {@link beginAuditCapture} when audit is disabled — the handler
|
|
31
|
+
* guards every write with `if (audit)`.
|
|
32
|
+
*/
|
|
33
|
+
interface AuditCaptureContext {
|
|
34
|
+
/** Outbound key id (set after auth). NEVER the key material. */
|
|
35
|
+
keyId?: string | null;
|
|
36
|
+
/** Resolved upstream model (set after route resolution). */
|
|
37
|
+
model?: string;
|
|
38
|
+
/** Upstream provider id (set after route resolution). */
|
|
39
|
+
provider?: string;
|
|
40
|
+
/** Sanitized error message (set on a relay/dispatch failure). */
|
|
41
|
+
error?: string;
|
|
42
|
+
/** Stash the raw request body for capture (a no-op unless `captureBodies`). */
|
|
43
|
+
setRequestBody(raw: string): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Begin audit capture for one request. Returns a mutable context the handler
|
|
47
|
+
* enriches, or `null` when audit is disabled (zero-cost path). The record is
|
|
48
|
+
* emitted on response `close` via the fire-and-forget sink.
|
|
49
|
+
*/
|
|
50
|
+
declare function beginAuditCapture(req: http.IncomingMessage, res: http.ServerResponse, now: number): AuditCaptureContext | null;
|
|
51
|
+
|
|
52
|
+
export { type AuditCaptureContext, beginAuditCapture };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* auditCapture — the outbound server's post-response audit capture hook
|
|
5
|
+
* (request-audit-log, design D1/D3/D5).
|
|
6
|
+
*
|
|
7
|
+
* {@link beginAuditCapture} is called at the TOP of `handleOutboundRequest`. It
|
|
8
|
+
* reads the active capture config from the core slot; when audit is DISABLED it
|
|
9
|
+
* returns `null` immediately (one slot read — no assembly, no listener, zero
|
|
10
|
+
* regression). When enabled it:
|
|
11
|
+
* - registers a one-shot `res.on('close')` listener that, at response end,
|
|
12
|
+
* assembles the {@link AuditRecord} from the http `req` (IP via the socket, or
|
|
13
|
+
* a trusted `X-Forwarded-For` only when configured — LEAD OQ1 anti-spoof; UA;
|
|
14
|
+
* method; path with the query string DROPPED), the response `statusCode`, the
|
|
15
|
+
* elapsed ms, and the fields the handler fills in (keyId / model / provider /
|
|
16
|
+
* error / bodies) — then hands it to the fire-and-forget `recordAudit`;
|
|
17
|
+
* - when `captureBodies` is ALSO on, wraps `res.write`/`res.end` to accumulate a
|
|
18
|
+
* BOUNDED response body (metadata-only for a streaming `text/event-stream`
|
|
19
|
+
* response — a full stream is unbounded), and truncates+redacts both bodies.
|
|
20
|
+
*
|
|
21
|
+
* Request HEADERS are NEVER read into a record (Authorization / x-api-key live
|
|
22
|
+
* there). Every stored body passes through {@link redactAuditText}. The assembly
|
|
23
|
+
* is wrapped so a capture failure can never surface into the relay path.
|
|
24
|
+
*
|
|
25
|
+
* @module @omnicross/core/outbound-api/auditCapture
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The mutable context the request handler enriches as it progresses. `null` is
|
|
30
|
+
* returned by {@link beginAuditCapture} when audit is disabled — the handler
|
|
31
|
+
* guards every write with `if (audit)`.
|
|
32
|
+
*/
|
|
33
|
+
interface AuditCaptureContext {
|
|
34
|
+
/** Outbound key id (set after auth). NEVER the key material. */
|
|
35
|
+
keyId?: string | null;
|
|
36
|
+
/** Resolved upstream model (set after route resolution). */
|
|
37
|
+
model?: string;
|
|
38
|
+
/** Upstream provider id (set after route resolution). */
|
|
39
|
+
provider?: string;
|
|
40
|
+
/** Sanitized error message (set on a relay/dispatch failure). */
|
|
41
|
+
error?: string;
|
|
42
|
+
/** Stash the raw request body for capture (a no-op unless `captureBodies`). */
|
|
43
|
+
setRequestBody(raw: string): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Begin audit capture for one request. Returns a mutable context the handler
|
|
47
|
+
* enriches, or `null` when audit is disabled (zero-cost path). The record is
|
|
48
|
+
* emitted on response `close` via the fire-and-forget sink.
|
|
49
|
+
*/
|
|
50
|
+
declare function beginAuditCapture(req: http.IncomingMessage, res: http.ServerResponse, now: number): AuditCaptureContext | null;
|
|
51
|
+
|
|
52
|
+
export { type AuditCaptureContext, beginAuditCapture };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* auditRedact — the pure secret-redaction pass for captured audit bodies
|
|
3
|
+
* (request-audit-log, design D3/D7).
|
|
4
|
+
*
|
|
5
|
+
* Body capture is opt-in and inherently sensitive: a prompt or tool argument can
|
|
6
|
+
* embed a secret. {@link redactAuditText} is run over EVERY captured body (and
|
|
7
|
+
* any other free text stored in a record) BEFORE it is persisted — defense in
|
|
8
|
+
* depth on top of "request headers are NEVER captured" (so an Authorization /
|
|
9
|
+
* x-api-key HEADER value never enters a record in the first place).
|
|
10
|
+
*
|
|
11
|
+
* It masks the obvious, high-confidence secret shapes ONLY (frozen list) — never
|
|
12
|
+
* a broad heuristic that would gut a legitimate prompt:
|
|
13
|
+
* - `sk-…` API keys (covers `sk-ant-…`, `sk-omnicross-…`, `sk-proj-…`, OpenAI).
|
|
14
|
+
* - `Bearer <token>` authorization values.
|
|
15
|
+
* - `x-api-key` / `api-key` / `authorization` values written inline as text.
|
|
16
|
+
* - Google `AIza…` API keys.
|
|
17
|
+
*
|
|
18
|
+
* Pure + allocation-light + never throws.
|
|
19
|
+
*
|
|
20
|
+
* @module @omnicross/core/outbound-api/auditRedact
|
|
21
|
+
*/
|
|
22
|
+
/** The sentinel a masked secret is replaced with. */
|
|
23
|
+
declare const AUDIT_REDACTED = "***REDACTED***";
|
|
24
|
+
/**
|
|
25
|
+
* Mask obvious secrets in `text`. Pure; returns the input unchanged when it holds
|
|
26
|
+
* no recognized secret shape. Never throws (a bad input returns `''`).
|
|
27
|
+
*/
|
|
28
|
+
declare function redactAuditText(text: string): string;
|
|
29
|
+
|
|
30
|
+
export { AUDIT_REDACTED, redactAuditText };
|