@omnicross/core 0.1.3 → 0.1.5

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.
Files changed (141) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +57 -57
  3. package/README.md +15 -15
  4. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -5
  5. package/dist/auth/GeminiCodeAssistProjectResolver.js +6 -5
  6. package/dist/{chunk-2DCNB7DF.cjs → chunk-3Q6Z6JTO.cjs} +154 -26
  7. package/dist/chunk-3QFXFCHG.js +33 -0
  8. package/dist/chunk-3Z5BQZFM.cjs +52 -0
  9. package/dist/{chunk-4VAVYUZS.cjs → chunk-4XMYPW46.cjs} +9 -9
  10. package/dist/chunk-4YINUUKQ.cjs +33 -0
  11. package/dist/{chunk-S4WBV25P.js → chunk-6QZGDLL4.js} +106 -23
  12. package/dist/{chunk-C72S6TTV.cjs → chunk-7FEBOPJO.cjs} +5 -4
  13. package/dist/chunk-APYG5QD7.cjs +50 -0
  14. package/dist/{chunk-5HTVET6E.js → chunk-BODMAL6G.js} +143 -15
  15. package/dist/{chunk-CWM2ZDU5.js → chunk-BPKCU575.js} +3 -10
  16. package/dist/{chunk-2FMI2B6V.cjs → chunk-CGKLE6IW.cjs} +350 -461
  17. package/dist/{chunk-BO4RFWBR.js → chunk-D3TDKWRP.js} +84 -3
  18. package/dist/{chunk-RSJ3TWJQ.cjs → chunk-DDMRUL76.cjs} +5 -5
  19. package/dist/chunk-FCR77GYM.cjs +33 -0
  20. package/dist/{chunk-4DECIFU7.js → chunk-FH2P4OCD.js} +178 -289
  21. package/dist/{chunk-N5QFKSDO.js → chunk-HRRYG2AX.js} +2 -1
  22. package/dist/{chunk-KUU2RNG6.cjs → chunk-HYN75H6G.cjs} +3 -0
  23. package/dist/{chunk-Z7LUNECE.js → chunk-IB3FDI4O.js} +5 -4
  24. package/dist/chunk-IFXJ2BG7.js +109 -0
  25. package/dist/{chunk-JO5NLTLY.js → chunk-IK3KE3AU.js} +3 -0
  26. package/dist/{chunk-C7PSERMH.js → chunk-IWQAX3CS.js} +1 -1
  27. package/dist/{chunk-YGXJGRFI.cjs → chunk-JWVTXXPX.cjs} +106 -23
  28. package/dist/{chunk-7YN22L2H.cjs → chunk-K52THW2C.cjs} +5 -5
  29. package/dist/chunk-K5NM7VAH.js +33 -0
  30. package/dist/{chunk-Y6OM7EV7.cjs → chunk-KFI44N2R.cjs} +2 -1
  31. package/dist/{chunk-Z7Y2NPHY.js → chunk-MFZ5437A.js} +1 -1
  32. package/dist/chunk-OE6TDIWW.js +22 -0
  33. package/dist/{chunk-MQNDWYPN.js → chunk-OQWKZCXP.js} +13 -6
  34. package/dist/chunk-OZFM4X3S.js +18 -0
  35. package/dist/chunk-PG7PS2NN.cjs +170 -0
  36. package/dist/{chunk-3QOSDDNI.cjs → chunk-SNYBEXLB.cjs} +6 -13
  37. package/dist/chunk-SYQF7OIR.js +52 -0
  38. package/dist/{chunk-CZHZGRU7.js → chunk-UHGVBFU3.js} +2 -0
  39. package/dist/chunk-UIBD2YY5.cjs +22 -0
  40. package/dist/chunk-UNWKG6EI.cjs +109 -0
  41. package/dist/{chunk-SVXC36MU.cjs → chunk-VACWOIRE.cjs} +2 -0
  42. package/dist/chunk-WLYIIEAF.js +50 -0
  43. package/dist/chunk-XSVNC2UD.cjs +18 -0
  44. package/dist/{chunk-FFALUUZZ.cjs → chunk-ZCIQ3L3R.cjs} +18 -11
  45. package/dist/completion/CompletionService.cjs +26 -19
  46. package/dist/completion/CompletionService.js +25 -18
  47. package/dist/completion.cjs +28 -21
  48. package/dist/completion.js +27 -20
  49. package/dist/index.cjs +35 -25
  50. package/dist/index.d.cts +7 -3
  51. package/dist/index.d.ts +7 -3
  52. package/dist/index.js +44 -34
  53. package/dist/keyPolicy-Cp0FntZl.d.cts +90 -0
  54. package/dist/keyPolicy-Cp0FntZl.d.ts +90 -0
  55. package/dist/outbound-api/auditCapture.cjs +9 -0
  56. package/dist/outbound-api/auditCapture.d.cts +54 -0
  57. package/dist/outbound-api/auditCapture.d.ts +54 -0
  58. package/dist/outbound-api/auditCapture.js +9 -0
  59. package/dist/outbound-api/auditRedact.cjs +8 -0
  60. package/dist/outbound-api/auditRedact.d.cts +30 -0
  61. package/dist/outbound-api/auditRedact.d.ts +30 -0
  62. package/dist/outbound-api/auditRedact.js +8 -0
  63. package/dist/outbound-api/billingCapture.cjs +8 -0
  64. package/dist/outbound-api/billingCapture.d.cts +61 -0
  65. package/dist/outbound-api/billingCapture.d.ts +61 -0
  66. package/dist/outbound-api/billingCapture.js +8 -0
  67. package/dist/outbound-api/quotaWarn.cjs +12 -0
  68. package/dist/outbound-api/quotaWarn.d.cts +43 -0
  69. package/dist/outbound-api/quotaWarn.d.ts +43 -0
  70. package/dist/outbound-api/quotaWarn.js +12 -0
  71. package/dist/outbound-api/routeResolver.cjs +2 -2
  72. package/dist/outbound-api/routeResolver.d.cts +3 -2
  73. package/dist/outbound-api/routeResolver.d.ts +3 -2
  74. package/dist/outbound-api/routeResolver.js +1 -1
  75. package/dist/outbound-api/types.d.cts +2 -1
  76. package/dist/outbound-api/types.d.ts +2 -1
  77. package/dist/outbound-api.cjs +33 -23
  78. package/dist/outbound-api.d.cts +9 -140
  79. package/dist/outbound-api.d.ts +9 -140
  80. package/dist/outbound-api.js +32 -22
  81. package/dist/pipeline/AuthSource.d.cts +6 -0
  82. package/dist/pipeline/AuthSource.d.ts +6 -0
  83. package/dist/pipeline/SubscriptionAuthSource.cjs +2 -2
  84. package/dist/pipeline/SubscriptionAuthSource.js +1 -1
  85. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +6 -0
  86. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +6 -0
  87. package/dist/pipeline/auditUsageStash.cjs +10 -0
  88. package/dist/pipeline/auditUsageStash.d.cts +37 -0
  89. package/dist/pipeline/auditUsageStash.d.ts +37 -0
  90. package/dist/pipeline/auditUsageStash.js +10 -0
  91. package/dist/pipeline/executeProviderCall.cjs +2 -2
  92. package/dist/pipeline/executeProviderCall.js +1 -1
  93. package/dist/pipeline/upstreamFetch.cjs +15 -0
  94. package/dist/pipeline/upstreamFetch.d.cts +89 -0
  95. package/dist/pipeline/upstreamFetch.d.ts +89 -0
  96. package/dist/pipeline/upstreamFetch.js +15 -0
  97. package/dist/pipeline/upstreamTrace.cjs +14 -0
  98. package/dist/pipeline/upstreamTrace.d.cts +85 -0
  99. package/dist/pipeline/upstreamTrace.d.ts +85 -0
  100. package/dist/pipeline/upstreamTrace.js +14 -0
  101. package/dist/pipeline/webhookEmit.cjs +10 -0
  102. package/dist/pipeline/webhookEmit.d.cts +36 -0
  103. package/dist/pipeline/webhookEmit.d.ts +36 -0
  104. package/dist/pipeline/webhookEmit.js +10 -0
  105. package/dist/ports.d.cts +2 -1
  106. package/dist/ports.d.ts +2 -1
  107. package/dist/provider-proxy/ProviderProxy.cjs +26 -19
  108. package/dist/provider-proxy/ProviderProxy.js +25 -18
  109. package/dist/provider-proxy/ingress/providerProxyShared.cjs +28 -19
  110. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +17 -1
  111. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +17 -1
  112. package/dist/provider-proxy/ingress/providerProxyShared.js +27 -18
  113. package/dist/provider-proxy/types.d.cts +7 -0
  114. package/dist/provider-proxy/types.d.ts +7 -0
  115. package/dist/provider-proxy.cjs +26 -19
  116. package/dist/provider-proxy.js +25 -18
  117. package/dist/{routeResolver-B1NglTfe.d.ts → routeResolver-C4T7yClx.d.ts} +1 -1
  118. package/dist/{routeResolver-CbG5uBgm.d.cts → routeResolver-CB3tvJKy.d.cts} +1 -1
  119. package/dist/transformer/transformers/AnthropicTransformer.cjs +2 -2
  120. package/dist/transformer/transformers/AnthropicTransformer.js +1 -1
  121. package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
  122. package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
  123. package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
  124. package/dist/transformer/transformers/GeminiTransformer.js +2 -2
  125. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
  126. package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
  127. package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +2 -2
  128. package/dist/transformer/transformers/OpenCodeGoTransformer.js +1 -1
  129. package/dist/transformer/transformers.cjs +8 -8
  130. package/dist/transformer/transformers.js +7 -7
  131. package/dist/transformer.cjs +8 -8
  132. package/dist/transformer.js +7 -7
  133. package/dist/{types-aBFFXoBz.d.cts → types-B8Arpxn0.d.cts} +14 -90
  134. package/dist/{types-6OUY_xfA.d.ts → types-lgPYQuZS.d.ts} +14 -90
  135. package/dist/usage/usage-recorder.cjs +3 -2
  136. package/dist/usage/usage-recorder.js +2 -1
  137. package/dist/usage.cjs +3 -2
  138. package/dist/usage.js +2 -1
  139. package/package.json +64 -64
  140. package/dist/chunk-S6JGLF3G.cjs +0 -89
  141. package/dist/{chunk-FTQ7IQUC.js → chunk-C6OV7GCC.js} +8 -8
@@ -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 _chunkUNWKG6EIcjs = require('../chunk-UNWKG6EI.cjs');
4
+ require('../chunk-FCR77GYM.cjs');
5
+ require('../chunk-AEOZIDEB.cjs');
6
+ require('../chunk-XSVNC2UD.cjs');
7
+
8
+
9
+ exports.beginAuditCapture = _chunkUNWKG6EIcjs.beginAuditCapture;
@@ -0,0 +1,54 @@
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
18
+ * the response body. Bodies are captured IN FULL (no truncation) and a
19
+ * streaming `text/event-stream` response is captured too — the earlier
20
+ * metadata-only/bounded behavior made a codex (streaming) reply invisible,
21
+ * which defeated debugging. See `upstreamTrace.ts` for the upstream leg.
22
+ *
23
+ * Request HEADERS are NEVER read into a record (Authorization / x-api-key live
24
+ * there). Every stored body passes through {@link redactAuditText}. The assembly
25
+ * is wrapped so a capture failure can never surface into the relay path.
26
+ *
27
+ * @module @omnicross/core/outbound-api/auditCapture
28
+ */
29
+
30
+ /**
31
+ * The mutable context the request handler enriches as it progresses. `null` is
32
+ * returned by {@link beginAuditCapture} when audit is disabled — the handler
33
+ * guards every write with `if (audit)`.
34
+ */
35
+ interface AuditCaptureContext {
36
+ /** Outbound key id (set after auth). NEVER the key material. */
37
+ keyId?: string | null;
38
+ /** Resolved upstream model (set after route resolution). */
39
+ model?: string;
40
+ /** Upstream provider id (set after route resolution). */
41
+ provider?: string;
42
+ /** Sanitized error message (set on a relay/dispatch failure). */
43
+ error?: string;
44
+ /** Stash the raw request body for capture (a no-op unless `captureBodies`). */
45
+ setRequestBody(raw: string): void;
46
+ }
47
+ /**
48
+ * Begin audit capture for one request. Returns a mutable context the handler
49
+ * enriches, or `null` when audit is disabled (zero-cost path). The record is
50
+ * emitted on response `close` via the fire-and-forget sink.
51
+ */
52
+ declare function beginAuditCapture(req: http.IncomingMessage, res: http.ServerResponse, now: number): AuditCaptureContext | null;
53
+
54
+ export { type AuditCaptureContext, beginAuditCapture };
@@ -0,0 +1,54 @@
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
18
+ * the response body. Bodies are captured IN FULL (no truncation) and a
19
+ * streaming `text/event-stream` response is captured too — the earlier
20
+ * metadata-only/bounded behavior made a codex (streaming) reply invisible,
21
+ * which defeated debugging. See `upstreamTrace.ts` for the upstream leg.
22
+ *
23
+ * Request HEADERS are NEVER read into a record (Authorization / x-api-key live
24
+ * there). Every stored body passes through {@link redactAuditText}. The assembly
25
+ * is wrapped so a capture failure can never surface into the relay path.
26
+ *
27
+ * @module @omnicross/core/outbound-api/auditCapture
28
+ */
29
+
30
+ /**
31
+ * The mutable context the request handler enriches as it progresses. `null` is
32
+ * returned by {@link beginAuditCapture} when audit is disabled — the handler
33
+ * guards every write with `if (audit)`.
34
+ */
35
+ interface AuditCaptureContext {
36
+ /** Outbound key id (set after auth). NEVER the key material. */
37
+ keyId?: string | null;
38
+ /** Resolved upstream model (set after route resolution). */
39
+ model?: string;
40
+ /** Upstream provider id (set after route resolution). */
41
+ provider?: string;
42
+ /** Sanitized error message (set on a relay/dispatch failure). */
43
+ error?: string;
44
+ /** Stash the raw request body for capture (a no-op unless `captureBodies`). */
45
+ setRequestBody(raw: string): void;
46
+ }
47
+ /**
48
+ * Begin audit capture for one request. Returns a mutable context the handler
49
+ * enriches, or `null` when audit is disabled (zero-cost path). The record is
50
+ * emitted on response `close` via the fire-and-forget sink.
51
+ */
52
+ declare function beginAuditCapture(req: http.IncomingMessage, res: http.ServerResponse, now: number): AuditCaptureContext | null;
53
+
54
+ export { type AuditCaptureContext, beginAuditCapture };
@@ -0,0 +1,9 @@
1
+ import {
2
+ beginAuditCapture
3
+ } from "../chunk-IFXJ2BG7.js";
4
+ import "../chunk-K5NM7VAH.js";
5
+ import "../chunk-WNY4WMRF.js";
6
+ import "../chunk-OZFM4X3S.js";
7
+ export {
8
+ beginAuditCapture
9
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkFCR77GYMcjs = require('../chunk-FCR77GYM.cjs');
5
+
6
+
7
+
8
+ exports.AUDIT_REDACTED = _chunkFCR77GYMcjs.AUDIT_REDACTED; exports.redactAuditText = _chunkFCR77GYMcjs.redactAuditText;
@@ -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 };
@@ -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 };
@@ -0,0 +1,8 @@
1
+ import {
2
+ AUDIT_REDACTED,
3
+ redactAuditText
4
+ } from "../chunk-K5NM7VAH.js";
5
+ export {
6
+ AUDIT_REDACTED,
7
+ redactAuditText
8
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkAPYG5QD7cjs = require('../chunk-APYG5QD7.cjs');
4
+ require('../chunk-L74VDN4A.cjs');
5
+ require('../chunk-XSVNC2UD.cjs');
6
+
7
+
8
+ exports.beginBillingCapture = _chunkAPYG5QD7cjs.beginBillingCapture;
@@ -0,0 +1,61 @@
1
+ import http from 'node:http';
2
+
3
+ /**
4
+ * billingCapture — the outbound server's post-response billing capture hook
5
+ * (billing-event-stream, design D1/D4).
6
+ *
7
+ * {@link beginBillingCapture} is called at the TOP of `handleOutboundRequest`. It
8
+ * reads the active billing config from the core slot; when billing is DISABLED it
9
+ * returns `null` immediately (one slot read — no assembly, no listener, zero
10
+ * regression). When enabled it registers a one-shot `res.close` listener that
11
+ * assembles a {@link BillingEvent} from the handler-filled context (keyId / model
12
+ * / provider / authMode), the response `statusCode`, and this request's METERED
13
+ * FACTS (token counts + the ALREADY-COMPUTED cost) — then hands it to the
14
+ * no-throw {@link publishBillingEvent}.
15
+ *
16
+ * COST REUSE (design D3 — no double pricing): the metered facts are read from the
17
+ * per-request usage stash the usage tap populates ({@link readAuditUsage} — the
18
+ * SAME stash `usage-events.jsonl` correlation uses, populated UNCONDITIONALLY by
19
+ * the taps, independent of whether request-audit is enabled). Token counts are
20
+ * stashed SYNCHRONOUSLY at `record()`; the cost lands on the recorder's deferred
21
+ * pricing tick (scheduled BEFORE the response closes). So the assembly is deferred
22
+ * one macrotask past `close` — by then the earlier-scheduled pricing tick has run
23
+ * and stashed the computed cost we REUSE (we never re-price).
24
+ *
25
+ * BILLABLE-ONLY: an event is emitted ONLY when the request produced usage (an
26
+ * upstream call was billed). Auth failures / rate-limit / model-restriction
27
+ * rejections return before dispatch, stash no usage, and emit NO billing event.
28
+ *
29
+ * @module @omnicross/core/outbound-api/billingCapture
30
+ */
31
+
32
+ /**
33
+ * The mutable context the request handler enriches as it progresses. `null` is
34
+ * returned by {@link beginBillingCapture} when billing is disabled — the handler
35
+ * guards every write with `if (billing)`.
36
+ */
37
+ interface BillingCaptureContext {
38
+ /** Outbound key id (set after auth). NEVER the key material. */
39
+ keyId?: string | null;
40
+ /** Resolved upstream model (set after route resolution). */
41
+ model?: string;
42
+ /** Upstream provider id (set after route resolution). */
43
+ provider?: string;
44
+ /** Re-auth mode the request billed under (set after route resolution). */
45
+ authMode?: 'byo' | 'subscription';
46
+ }
47
+ /**
48
+ * Deferral used to schedule the event assembly one macrotask past `close`, so the
49
+ * usage tap's earlier-scheduled pricing tick has stashed the cost we reuse.
50
+ * Injectable ONLY for deterministic tests; production uses a zero-delay timer.
51
+ */
52
+ type BillingDefer = (fn: () => void) => void;
53
+ /**
54
+ * Begin billing capture for one request. Returns a mutable context the handler
55
+ * enriches, or `null` when billing is disabled (zero-cost path). The event is
56
+ * emitted on response `close` via the no-throw sink — but ONLY when the request
57
+ * produced usage (a billable request).
58
+ */
59
+ declare function beginBillingCapture(_req: http.IncomingMessage, res: http.ServerResponse, now: number, defer?: BillingDefer): BillingCaptureContext | null;
60
+
61
+ export { type BillingCaptureContext, type BillingDefer, beginBillingCapture };
@@ -0,0 +1,61 @@
1
+ import http from 'node:http';
2
+
3
+ /**
4
+ * billingCapture — the outbound server's post-response billing capture hook
5
+ * (billing-event-stream, design D1/D4).
6
+ *
7
+ * {@link beginBillingCapture} is called at the TOP of `handleOutboundRequest`. It
8
+ * reads the active billing config from the core slot; when billing is DISABLED it
9
+ * returns `null` immediately (one slot read — no assembly, no listener, zero
10
+ * regression). When enabled it registers a one-shot `res.close` listener that
11
+ * assembles a {@link BillingEvent} from the handler-filled context (keyId / model
12
+ * / provider / authMode), the response `statusCode`, and this request's METERED
13
+ * FACTS (token counts + the ALREADY-COMPUTED cost) — then hands it to the
14
+ * no-throw {@link publishBillingEvent}.
15
+ *
16
+ * COST REUSE (design D3 — no double pricing): the metered facts are read from the
17
+ * per-request usage stash the usage tap populates ({@link readAuditUsage} — the
18
+ * SAME stash `usage-events.jsonl` correlation uses, populated UNCONDITIONALLY by
19
+ * the taps, independent of whether request-audit is enabled). Token counts are
20
+ * stashed SYNCHRONOUSLY at `record()`; the cost lands on the recorder's deferred
21
+ * pricing tick (scheduled BEFORE the response closes). So the assembly is deferred
22
+ * one macrotask past `close` — by then the earlier-scheduled pricing tick has run
23
+ * and stashed the computed cost we REUSE (we never re-price).
24
+ *
25
+ * BILLABLE-ONLY: an event is emitted ONLY when the request produced usage (an
26
+ * upstream call was billed). Auth failures / rate-limit / model-restriction
27
+ * rejections return before dispatch, stash no usage, and emit NO billing event.
28
+ *
29
+ * @module @omnicross/core/outbound-api/billingCapture
30
+ */
31
+
32
+ /**
33
+ * The mutable context the request handler enriches as it progresses. `null` is
34
+ * returned by {@link beginBillingCapture} when billing is disabled — the handler
35
+ * guards every write with `if (billing)`.
36
+ */
37
+ interface BillingCaptureContext {
38
+ /** Outbound key id (set after auth). NEVER the key material. */
39
+ keyId?: string | null;
40
+ /** Resolved upstream model (set after route resolution). */
41
+ model?: string;
42
+ /** Upstream provider id (set after route resolution). */
43
+ provider?: string;
44
+ /** Re-auth mode the request billed under (set after route resolution). */
45
+ authMode?: 'byo' | 'subscription';
46
+ }
47
+ /**
48
+ * Deferral used to schedule the event assembly one macrotask past `close`, so the
49
+ * usage tap's earlier-scheduled pricing tick has stashed the cost we reuse.
50
+ * Injectable ONLY for deterministic tests; production uses a zero-delay timer.
51
+ */
52
+ type BillingDefer = (fn: () => void) => void;
53
+ /**
54
+ * Begin billing capture for one request. Returns a mutable context the handler
55
+ * enriches, or `null` when billing is disabled (zero-cost path). The event is
56
+ * emitted on response `close` via the no-throw sink — but ONLY when the request
57
+ * produced usage (a billable request).
58
+ */
59
+ declare function beginBillingCapture(_req: http.IncomingMessage, res: http.ServerResponse, now: number, defer?: BillingDefer): BillingCaptureContext | null;
60
+
61
+ export { type BillingCaptureContext, type BillingDefer, beginBillingCapture };
@@ -0,0 +1,8 @@
1
+ import {
2
+ beginBillingCapture
3
+ } from "../chunk-WLYIIEAF.js";
4
+ import "../chunk-TKJMZBAH.js";
5
+ import "../chunk-OZFM4X3S.js";
6
+ export {
7
+ beginBillingCapture
8
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunk4YINUUKQcjs = require('../chunk-4YINUUKQ.cjs');
7
+
8
+
9
+
10
+
11
+
12
+ exports.WEBHOOK_QUOTA_WARN_RATIO = _chunk4YINUUKQcjs.WEBHOOK_QUOTA_WARN_RATIO; exports.__resetQuotaWarnGuardForTests = _chunk4YINUUKQcjs.__resetQuotaWarnGuardForTests; exports.computeQuotaWarnings = _chunk4YINUUKQcjs.computeQuotaWarnings; exports.markQuotaWarnedOnce = _chunk4YINUUKQcjs.markQuotaWarnedOnce;
@@ -0,0 +1,43 @@
1
+ import { K as KeyCostLimits, c as KeySpend } from '../keyPolicy-Cp0FntZl.cjs';
2
+
3
+ /**
4
+ * quotaWarn — the key.quotaWarning threshold helper (webhook-notifications,
5
+ * design D3, Phase 2).
6
+ *
7
+ * A PURE crossing detector ({@link computeQuotaWarnings}) + a tiny module-level
8
+ * "already warned this window" guard ({@link markQuotaWarnedOnce}). The wire
9
+ * path (`outboundApiRouter`) computes warnings alongside the existing quota
10
+ * check and emits `key.quotaWarning` ONCE per window-crossing — so a key sitting
11
+ * above the warn ratio doesn't spam a webhook every request. The guard is keyed
12
+ * by `keyId + scope + windowStart`, so a NEW day/week window re-arms the warning
13
+ * naturally (its `windowStart` differs).
14
+ *
15
+ * @module @omnicross/core/outbound-api/quotaWarn
16
+ */
17
+
18
+ /** Warn when accumulated spend reaches this fraction of a scope's limit (design OQ2). */
19
+ declare const WEBHOOK_QUOTA_WARN_RATIO = 0.8;
20
+ /** A per-scope warning crossing (not-yet-exceeded, at/over the warn ratio). */
21
+ interface QuotaWarning {
22
+ scope: 'daily' | 'weekly' | 'total';
23
+ limitUsd: number;
24
+ spentUsd: number;
25
+ /** The window boundary (epoch ms; `0` for the window-less `total` scope). */
26
+ windowStart: number;
27
+ }
28
+ /**
29
+ * Detect which cost scopes have crossed the warn ratio but are NOT yet exceeded
30
+ * (an EXCEEDED scope is handled by `checkKeyQuota` → `key.quotaExceeded`, not a
31
+ * warning). Pure — the caller owns the emit + the dedupe guard.
32
+ */
33
+ declare function computeQuotaWarnings(limits: KeyCostLimits, spend: KeySpend, ratio?: number): QuotaWarning[];
34
+ /**
35
+ * Record a warning for `(keyId, scope, windowStart)` and return whether THIS is
36
+ * the first time (⇒ the caller should emit). Subsequent calls in the same window
37
+ * return `false` (deduped). A new window (different `windowStart`) re-arms.
38
+ */
39
+ declare function markQuotaWarnedOnce(keyId: string, scope: string, windowStart: number): boolean;
40
+ /** TEST SEAM — clear the dedupe guard between suites. */
41
+ declare function __resetQuotaWarnGuardForTests(): void;
42
+
43
+ export { type QuotaWarning, WEBHOOK_QUOTA_WARN_RATIO, __resetQuotaWarnGuardForTests, computeQuotaWarnings, markQuotaWarnedOnce };
@@ -0,0 +1,43 @@
1
+ import { K as KeyCostLimits, c as KeySpend } from '../keyPolicy-Cp0FntZl.js';
2
+
3
+ /**
4
+ * quotaWarn — the key.quotaWarning threshold helper (webhook-notifications,
5
+ * design D3, Phase 2).
6
+ *
7
+ * A PURE crossing detector ({@link computeQuotaWarnings}) + a tiny module-level
8
+ * "already warned this window" guard ({@link markQuotaWarnedOnce}). The wire
9
+ * path (`outboundApiRouter`) computes warnings alongside the existing quota
10
+ * check and emits `key.quotaWarning` ONCE per window-crossing — so a key sitting
11
+ * above the warn ratio doesn't spam a webhook every request. The guard is keyed
12
+ * by `keyId + scope + windowStart`, so a NEW day/week window re-arms the warning
13
+ * naturally (its `windowStart` differs).
14
+ *
15
+ * @module @omnicross/core/outbound-api/quotaWarn
16
+ */
17
+
18
+ /** Warn when accumulated spend reaches this fraction of a scope's limit (design OQ2). */
19
+ declare const WEBHOOK_QUOTA_WARN_RATIO = 0.8;
20
+ /** A per-scope warning crossing (not-yet-exceeded, at/over the warn ratio). */
21
+ interface QuotaWarning {
22
+ scope: 'daily' | 'weekly' | 'total';
23
+ limitUsd: number;
24
+ spentUsd: number;
25
+ /** The window boundary (epoch ms; `0` for the window-less `total` scope). */
26
+ windowStart: number;
27
+ }
28
+ /**
29
+ * Detect which cost scopes have crossed the warn ratio but are NOT yet exceeded
30
+ * (an EXCEEDED scope is handled by `checkKeyQuota` → `key.quotaExceeded`, not a
31
+ * warning). Pure — the caller owns the emit + the dedupe guard.
32
+ */
33
+ declare function computeQuotaWarnings(limits: KeyCostLimits, spend: KeySpend, ratio?: number): QuotaWarning[];
34
+ /**
35
+ * Record a warning for `(keyId, scope, windowStart)` and return whether THIS is
36
+ * the first time (⇒ the caller should emit). Subsequent calls in the same window
37
+ * return `false` (deduped). A new window (different `windowStart`) re-arms.
38
+ */
39
+ declare function markQuotaWarnedOnce(keyId: string, scope: string, windowStart: number): boolean;
40
+ /** TEST SEAM — clear the dedupe guard between suites. */
41
+ declare function __resetQuotaWarnGuardForTests(): void;
42
+
43
+ export { type QuotaWarning, WEBHOOK_QUOTA_WARN_RATIO, __resetQuotaWarnGuardForTests, computeQuotaWarnings, markQuotaWarnedOnce };
@@ -0,0 +1,12 @@
1
+ import {
2
+ WEBHOOK_QUOTA_WARN_RATIO,
3
+ __resetQuotaWarnGuardForTests,
4
+ computeQuotaWarnings,
5
+ markQuotaWarnedOnce
6
+ } from "../chunk-3QFXFCHG.js";
7
+ export {
8
+ WEBHOOK_QUOTA_WARN_RATIO,
9
+ __resetQuotaWarnGuardForTests,
10
+ computeQuotaWarnings,
11
+ markQuotaWarnedOnce
12
+ };
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkSVXC36MUcjs = require('../chunk-SVXC36MU.cjs');
6
+ var _chunkVACWOIREcjs = require('../chunk-VACWOIRE.cjs');
7
7
  require('../chunk-QBZJ7P2T.cjs');
8
8
  require('../chunk-4IH4EL7M.cjs');
9
9
 
@@ -11,4 +11,4 @@ require('../chunk-4IH4EL7M.cjs');
11
11
 
12
12
 
13
13
 
14
- exports.isSubscriptionProviderId = _chunkSVXC36MUcjs.isSubscriptionProviderId; exports.parseModelRef = _chunkSVXC36MUcjs.parseModelRef; exports.pickModelRefFromList = _chunkSVXC36MUcjs.pickModelRefFromList; exports.resolveRoute = _chunkSVXC36MUcjs.resolveRoute;
14
+ exports.isSubscriptionProviderId = _chunkVACWOIREcjs.isSubscriptionProviderId; exports.parseModelRef = _chunkVACWOIREcjs.parseModelRef; exports.pickModelRefFromList = _chunkVACWOIREcjs.pickModelRefFromList; exports.resolveRoute = _chunkVACWOIREcjs.resolveRoute;
@@ -1,7 +1,7 @@
1
1
  import '../ports/provider-config-source.cjs';
2
2
  import '../provider-proxy/types.cjs';
3
- import '../types-aBFFXoBz.cjs';
4
- export { R as RouteResolveError, b as RouteResolveResult, i as isSubscriptionProviderId, p as parseModelRef, a as pickModelRefFromList, r as resolveRoute } from '../routeResolver-CbG5uBgm.cjs';
3
+ import '../types-B8Arpxn0.cjs';
4
+ export { R as RouteResolveError, b as RouteResolveResult, i as isSubscriptionProviderId, p as parseModelRef, a as pickModelRefFromList, r as resolveRoute } from '../routeResolver-CB3tvJKy.cjs';
5
5
  import '@omnicross/contracts/llm-config';
6
6
  import '../transformer/types.cjs';
7
7
  import '../transformer/TransformerService.cjs';
@@ -23,3 +23,4 @@ import '@omnicross/contracts/health-logging-types';
23
23
  import '@omnicross/contracts/voucher-types';
24
24
  import '@omnicross/contracts/webhook-types';
25
25
  import '../ProviderProxy-CnMQYN59.cjs';
26
+ import '../keyPolicy-Cp0FntZl.cjs';
@@ -1,7 +1,7 @@
1
1
  import '../ports/provider-config-source.js';
2
2
  import '../provider-proxy/types.js';
3
- import '../types-6OUY_xfA.js';
4
- export { R as RouteResolveError, b as RouteResolveResult, i as isSubscriptionProviderId, p as parseModelRef, a as pickModelRefFromList, r as resolveRoute } from '../routeResolver-B1NglTfe.js';
3
+ import '../types-lgPYQuZS.js';
4
+ export { R as RouteResolveError, b as RouteResolveResult, i as isSubscriptionProviderId, p as parseModelRef, a as pickModelRefFromList, r as resolveRoute } from '../routeResolver-C4T7yClx.js';
5
5
  import '@omnicross/contracts/llm-config';
6
6
  import '../transformer/types.js';
7
7
  import '../transformer/TransformerService.js';
@@ -23,3 +23,4 @@ import '@omnicross/contracts/health-logging-types';
23
23
  import '@omnicross/contracts/voucher-types';
24
24
  import '@omnicross/contracts/webhook-types';
25
25
  import '../ProviderProxy-C-xqrkKi.js';
26
+ import '../keyPolicy-Cp0FntZl.js';
@@ -3,7 +3,7 @@ import {
3
3
  parseModelRef,
4
4
  pickModelRefFromList,
5
5
  resolveRoute
6
- } from "../chunk-CZHZGRU7.js";
6
+ } from "../chunk-UHGVBFU3.js";
7
7
  import "../chunk-AQ5TNQB7.js";
8
8
  import "../chunk-XEKD23J5.js";
9
9
  export {
@@ -8,7 +8,7 @@ import '../logger-4GvQNzhE.cjs';
8
8
  import '../ports/provider-config-source.cjs';
9
9
  import '../ProviderProxy-CnMQYN59.cjs';
10
10
  import '../provider-proxy/types.cjs';
11
- export { T as AccountHealthConfig, A as AccountProbeConfig, C as ChatDispatchMode, a as ConcurrencyQueueConfig, E as ENDPOINT_MODEL_KINDS, b as EndpointRoutingConfig, F as FingerprintConfig, i as KindMappedEndpoint, M as MessagesModelKind, j as ModelKind, k as ModelPrefixTargets, P as ModelRef, l as OutboundApiDeps, m as OutboundApiKeyCreated, n as OutboundApiKeyInfo, o as OutboundApiServerConfig, p as OutboundApiServerStatus, q as OutboundEndpoint, r as OutboundFormatUrls, s as OutboundKeyActivationMode, O as OutboundKeyDb, t as OutboundKeyDbRow, W as OutboundKeyModelRestrictionMode, u as OutboundKeyPolicy, v as OutboundProxyConfig, R as RequestRole, w as ResponsesModelKind, U as UserMessageQueueConfig } from '../types-aBFFXoBz.cjs';
11
+ export { H as AccountHealthConfig, A as AccountProbeConfig, C as ChatDispatchMode, a as ConcurrencyQueueConfig, E as ENDPOINT_MODEL_KINDS, b as EndpointRoutingConfig, F as FingerprintConfig, e as KindMappedEndpoint, M as MessagesModelKind, f as ModelKind, g as ModelPrefixTargets, G as ModelRef, h as OutboundApiDeps, i as OutboundApiKeyCreated, j as OutboundApiKeyInfo, k as OutboundApiServerConfig, l as OutboundApiServerStatus, m as OutboundEndpoint, n as OutboundFormatUrls, o as OutboundKeyActivationMode, O as OutboundKeyDb, p as OutboundKeyDbRow, I as OutboundKeyModelRestrictionMode, q as OutboundKeyPolicy, r as OutboundProxyConfig, R as RequestRole, s as ResponsesModelKind, U as UserMessageQueueConfig } from '../types-B8Arpxn0.cjs';
12
12
  import '@omnicross/contracts/llm-config';
13
13
  import '../transformer/types.cjs';
14
14
  import '../transformer/TransformerService.cjs';
@@ -22,3 +22,4 @@ import '../pipeline/SubscriptionAuthSource.cjs';
22
22
  import '../pipeline/SubscriptionAuthStrategy.cjs';
23
23
  import '../ports/web-search-backend.cjs';
24
24
  import '@omnicross/contracts/websearch-types';
25
+ import '../keyPolicy-Cp0FntZl.cjs';