@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.
Files changed (184) 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 -1
  5. package/dist/auth/GeminiCodeAssistProjectResolver.js +6 -1
  6. package/dist/chunk-3QFXFCHG.js +33 -0
  7. package/dist/chunk-4IH4EL7M.cjs +9 -0
  8. package/dist/chunk-4YINUUKQ.cjs +33 -0
  9. package/dist/chunk-5ENKBSWO.js +311 -0
  10. package/dist/chunk-6RPZADX3.cjs +92 -0
  11. package/dist/chunk-7Y47UCF2.js +142 -0
  12. package/dist/chunk-AEOZIDEB.cjs +32 -0
  13. package/dist/chunk-APYG5QD7.cjs +50 -0
  14. package/dist/{chunk-MNYKI4CI.js → chunk-BPKCU575.js} +29 -0
  15. package/dist/{chunk-SN3YWBX7.cjs → chunk-DKPXN34V.cjs} +2108 -538
  16. package/dist/{chunk-4NBS6KPV.cjs → chunk-DQ5VAYZ6.cjs} +7 -8
  17. package/dist/chunk-E3UCVHLP.cjs +142 -0
  18. package/dist/chunk-FCR77GYM.cjs +33 -0
  19. package/dist/{chunk-74TMJA7Z.js → chunk-HRRYG2AX.js} +8 -4
  20. package/dist/chunk-HUZZZ3JL.js +32 -0
  21. package/dist/{chunk-KUU2RNG6.cjs → chunk-HYN75H6G.cjs} +3 -0
  22. package/dist/{chunk-QOCNX236.js → chunk-IAXWICZU.js} +24 -1
  23. package/dist/{chunk-JO5NLTLY.js → chunk-IK3KE3AU.js} +3 -0
  24. package/dist/{chunk-V5KPWNYX.cjs → chunk-JMJBSACD.cjs} +3 -3
  25. package/dist/chunk-K5NM7VAH.js +33 -0
  26. package/dist/{chunk-N3V2J5ZO.cjs → chunk-KFI44N2R.cjs} +8 -4
  27. package/dist/chunk-L74VDN4A.cjs +32 -0
  28. package/dist/chunk-OCEUVQHW.cjs +112 -0
  29. package/dist/chunk-OE6TDIWW.js +22 -0
  30. package/dist/chunk-OZFM4X3S.js +18 -0
  31. package/dist/{chunk-LKZJEL6E.cjs → chunk-Q27JY5RG.cjs} +6 -4
  32. package/dist/{chunk-SPVWWUHX.cjs → chunk-QWBWGODS.cjs} +24 -1
  33. package/dist/{chunk-2FEVTJWG.js → chunk-QYTT6GE3.js} +1929 -359
  34. package/dist/{chunk-UYPEN5XE.cjs → chunk-RGTR7CIO.cjs} +6 -6
  35. package/dist/chunk-RPII3E6Z.cjs +145 -0
  36. package/dist/{chunk-XBSYYZIY.cjs → chunk-SNYBEXLB.cjs} +31 -2
  37. package/dist/{chunk-2DCNB7DF.cjs → chunk-SU2GCLAC.cjs} +30 -10
  38. package/dist/{chunk-5HTVET6E.js → chunk-TIER4SUC.js} +24 -4
  39. package/dist/chunk-TKJMZBAH.js +32 -0
  40. package/dist/{chunk-ZSVQT3PW.js → chunk-UBWEBKRC.js} +5 -6
  41. package/dist/chunk-UHGVBFU3.js +385 -0
  42. package/dist/chunk-UIBD2YY5.cjs +22 -0
  43. package/dist/chunk-UNEFIWXI.cjs +32 -0
  44. package/dist/chunk-VACWOIRE.cjs +385 -0
  45. package/dist/{chunk-O466Y272.js → chunk-VPBAUQ2M.js} +7 -7
  46. package/dist/chunk-VQY5W4YW.cjs +311 -0
  47. package/dist/chunk-WLYIIEAF.js +50 -0
  48. package/dist/chunk-WNY4WMRF.js +32 -0
  49. package/dist/chunk-XEKD23J5.js +9 -0
  50. package/dist/chunk-XK5CIRMQ.js +112 -0
  51. package/dist/chunk-XSVNC2UD.cjs +18 -0
  52. package/dist/chunk-XTEI64OU.js +145 -0
  53. package/dist/chunk-XX6NQJMA.js +92 -0
  54. package/dist/{chunk-745DV5FL.js → chunk-Y7FO65VT.js} +3 -3
  55. package/dist/{chunk-PXUJF5HS.js → chunk-ZY6KU6P3.js} +4 -2
  56. package/dist/completion/CompletionService.cjs +30 -17
  57. package/dist/completion/CompletionService.js +29 -16
  58. package/dist/completion/NativeSearchInjector.cjs +3 -3
  59. package/dist/completion/NativeSearchInjector.js +2 -2
  60. package/dist/completion/openrouter-headers.cjs +3 -6
  61. package/dist/completion/openrouter-headers.d.cts +9 -12
  62. package/dist/completion/openrouter-headers.d.ts +9 -12
  63. package/dist/completion/openrouter-headers.js +2 -5
  64. package/dist/completion/openrouter-models.cjs +4 -3
  65. package/dist/completion/openrouter-models.js +2 -1
  66. package/dist/completion.cjs +30 -17
  67. package/dist/completion.js +29 -16
  68. package/dist/index.cjs +151 -20
  69. package/dist/index.d.cts +44 -10
  70. package/dist/index.d.ts +44 -10
  71. package/dist/index.js +160 -29
  72. package/dist/keyPolicy-Cp0FntZl.d.cts +90 -0
  73. package/dist/keyPolicy-Cp0FntZl.d.ts +90 -0
  74. package/dist/outbound-api/auditCapture.cjs +9 -0
  75. package/dist/outbound-api/auditCapture.d.cts +52 -0
  76. package/dist/outbound-api/auditCapture.d.ts +52 -0
  77. package/dist/outbound-api/auditCapture.js +9 -0
  78. package/dist/outbound-api/auditRedact.cjs +8 -0
  79. package/dist/outbound-api/auditRedact.d.cts +30 -0
  80. package/dist/outbound-api/auditRedact.d.ts +30 -0
  81. package/dist/outbound-api/auditRedact.js +8 -0
  82. package/dist/outbound-api/billingCapture.cjs +8 -0
  83. package/dist/outbound-api/billingCapture.d.cts +61 -0
  84. package/dist/outbound-api/billingCapture.d.ts +61 -0
  85. package/dist/outbound-api/billingCapture.js +8 -0
  86. package/dist/outbound-api/quotaWarn.cjs +12 -0
  87. package/dist/outbound-api/quotaWarn.d.cts +43 -0
  88. package/dist/outbound-api/quotaWarn.d.ts +43 -0
  89. package/dist/outbound-api/quotaWarn.js +12 -0
  90. package/dist/outbound-api/routeResolver.cjs +5 -2
  91. package/dist/outbound-api/routeResolver.d.cts +9 -2
  92. package/dist/outbound-api/routeResolver.d.ts +9 -2
  93. package/dist/outbound-api/routeResolver.js +4 -1
  94. package/dist/outbound-api/types.cjs +6 -1
  95. package/dist/outbound-api/types.d.cts +12 -144
  96. package/dist/outbound-api/types.d.ts +12 -144
  97. package/dist/outbound-api/types.js +6 -0
  98. package/dist/outbound-api.cjs +144 -17
  99. package/dist/outbound-api.d.cts +655 -25
  100. package/dist/outbound-api.d.ts +655 -25
  101. package/dist/outbound-api.js +148 -21
  102. package/dist/pipeline/AuthSource.d.cts +29 -1
  103. package/dist/pipeline/AuthSource.d.ts +29 -1
  104. package/dist/pipeline/LlmConfigProviderAuth.cjs +3 -3
  105. package/dist/pipeline/LlmConfigProviderAuth.js +2 -2
  106. package/dist/pipeline/SubscriptionAccountHealth.cjs +22 -0
  107. package/dist/pipeline/SubscriptionAccountHealth.d.cts +235 -0
  108. package/dist/pipeline/SubscriptionAccountHealth.d.ts +235 -0
  109. package/dist/pipeline/SubscriptionAccountHealth.js +22 -0
  110. package/dist/pipeline/SubscriptionAuthSource.cjs +2 -2
  111. package/dist/pipeline/SubscriptionAuthSource.d.cts +3 -2
  112. package/dist/pipeline/SubscriptionAuthSource.d.ts +3 -2
  113. package/dist/pipeline/SubscriptionAuthSource.js +1 -1
  114. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +30 -1
  115. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +30 -1
  116. package/dist/pipeline/auditSink.cjs +14 -0
  117. package/dist/pipeline/auditSink.d.cts +48 -0
  118. package/dist/pipeline/auditSink.d.ts +48 -0
  119. package/dist/pipeline/auditSink.js +14 -0
  120. package/dist/pipeline/auditUsageStash.cjs +10 -0
  121. package/dist/pipeline/auditUsageStash.d.cts +37 -0
  122. package/dist/pipeline/auditUsageStash.d.ts +37 -0
  123. package/dist/pipeline/auditUsageStash.js +10 -0
  124. package/dist/pipeline/billingEmit.cjs +14 -0
  125. package/dist/pipeline/billingEmit.d.cts +49 -0
  126. package/dist/pipeline/billingEmit.d.ts +49 -0
  127. package/dist/pipeline/billingEmit.js +14 -0
  128. package/dist/pipeline/executeProviderCall.cjs +2 -2
  129. package/dist/pipeline/executeProviderCall.js +1 -1
  130. package/dist/pipeline/upstreamFetch.cjs +14 -0
  131. package/dist/pipeline/upstreamFetch.d.cts +83 -0
  132. package/dist/pipeline/upstreamFetch.d.ts +83 -0
  133. package/dist/pipeline/upstreamFetch.js +14 -0
  134. package/dist/pipeline/webhookEmit.cjs +10 -0
  135. package/dist/pipeline/webhookEmit.d.cts +36 -0
  136. package/dist/pipeline/webhookEmit.d.ts +36 -0
  137. package/dist/pipeline/webhookEmit.js +10 -0
  138. package/dist/ports/usage-event-store.d.cts +26 -1
  139. package/dist/ports/usage-event-store.d.ts +26 -1
  140. package/dist/ports.d.cts +8 -1
  141. package/dist/ports.d.ts +8 -1
  142. package/dist/provider-proxy/ProviderProxy.cjs +30 -17
  143. package/dist/provider-proxy/ProviderProxy.js +29 -16
  144. package/dist/provider-proxy/identity/SubscriptionIdentityStore.cjs +15 -0
  145. package/dist/provider-proxy/identity/SubscriptionIdentityStore.d.cts +121 -0
  146. package/dist/provider-proxy/identity/SubscriptionIdentityStore.d.ts +121 -0
  147. package/dist/provider-proxy/identity/SubscriptionIdentityStore.js +15 -0
  148. package/dist/provider-proxy/identity/fingerprintHeaders.cjs +20 -0
  149. package/dist/provider-proxy/identity/fingerprintHeaders.d.cts +89 -0
  150. package/dist/provider-proxy/identity/fingerprintHeaders.d.ts +89 -0
  151. package/dist/provider-proxy/identity/fingerprintHeaders.js +20 -0
  152. package/dist/provider-proxy/ingress/providerProxyShared.cjs +30 -17
  153. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +11 -2
  154. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +11 -2
  155. package/dist/provider-proxy/ingress/providerProxyShared.js +29 -16
  156. package/dist/provider-proxy/matchText.cjs +4 -2
  157. package/dist/provider-proxy/matchText.d.cts +14 -1
  158. package/dist/provider-proxy/matchText.d.ts +14 -1
  159. package/dist/provider-proxy/matchText.js +3 -1
  160. package/dist/provider-proxy/types.d.cts +30 -0
  161. package/dist/provider-proxy/types.d.ts +30 -0
  162. package/dist/provider-proxy.cjs +30 -17
  163. package/dist/provider-proxy.js +29 -16
  164. package/dist/{routeResolver-HE-ZO0fO.d.ts → routeResolver-C4T7yClx.d.ts} +36 -10
  165. package/dist/{routeResolver-BrbK6ja9.d.cts → routeResolver-CB3tvJKy.d.cts} +36 -10
  166. package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
  167. package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
  168. package/dist/transformer/transformers.cjs +7 -7
  169. package/dist/transformer/transformers.js +8 -8
  170. package/dist/transformer.cjs +9 -9
  171. package/dist/transformer.js +8 -8
  172. package/dist/types-B8Arpxn0.d.cts +754 -0
  173. package/dist/types-lgPYQuZS.d.ts +754 -0
  174. package/dist/usage/usage-recorder.cjs +3 -2
  175. package/dist/usage/usage-recorder.d.cts +19 -1
  176. package/dist/usage/usage-recorder.d.ts +19 -1
  177. package/dist/usage/usage-recorder.js +2 -1
  178. package/dist/usage.cjs +3 -2
  179. package/dist/usage.js +2 -1
  180. package/package.json +64 -62
  181. package/dist/chunk-3MEACFK3.js +0 -193
  182. package/dist/chunk-6VIXXLMX.cjs +0 -14
  183. package/dist/chunk-E3WHL7CO.js +0 -14
  184. package/dist/chunk-G2FUJNA2.cjs +0 -193
@@ -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
+ };
@@ -2,10 +2,13 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkG2FUJNA2cjs = require('../chunk-G2FUJNA2.cjs');
5
+
6
+ var _chunkVACWOIREcjs = require('../chunk-VACWOIRE.cjs');
6
7
  require('../chunk-QBZJ7P2T.cjs');
8
+ require('../chunk-4IH4EL7M.cjs');
9
+
7
10
 
8
11
 
9
12
 
10
13
 
11
- exports.isSubscriptionProviderId = _chunkG2FUJNA2cjs.isSubscriptionProviderId; exports.parseModelRef = _chunkG2FUJNA2cjs.parseModelRef; exports.resolveRoute = _chunkG2FUJNA2cjs.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.cjs';
4
- export { R as RouteResolveError, a as RouteResolveResult, i as isSubscriptionProviderId, p as parseModelRef, r as resolveRoute } from '../routeResolver-BrbK6ja9.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';
@@ -16,4 +16,11 @@ import '../pipeline/SubscriptionAuthSource.cjs';
16
16
  import '../pipeline/SubscriptionAuthStrategy.cjs';
17
17
  import '../ports/web-search-backend.cjs';
18
18
  import '@omnicross/contracts/websearch-types';
19
+ import '@omnicross/contracts/account-tokens-types';
20
+ import '@omnicross/contracts/audit-types';
21
+ import '@omnicross/contracts/billing-types';
22
+ import '@omnicross/contracts/health-logging-types';
23
+ import '@omnicross/contracts/voucher-types';
24
+ import '@omnicross/contracts/webhook-types';
19
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.js';
4
- export { R as RouteResolveError, a as RouteResolveResult, i as isSubscriptionProviderId, p as parseModelRef, r as resolveRoute } from '../routeResolver-HE-ZO0fO.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';
@@ -16,4 +16,11 @@ import '../pipeline/SubscriptionAuthSource.js';
16
16
  import '../pipeline/SubscriptionAuthStrategy.js';
17
17
  import '../ports/web-search-backend.js';
18
18
  import '@omnicross/contracts/websearch-types';
19
+ import '@omnicross/contracts/account-tokens-types';
20
+ import '@omnicross/contracts/audit-types';
21
+ import '@omnicross/contracts/billing-types';
22
+ import '@omnicross/contracts/health-logging-types';
23
+ import '@omnicross/contracts/voucher-types';
24
+ import '@omnicross/contracts/webhook-types';
19
25
  import '../ProviderProxy-C-xqrkKi.js';
26
+ import '../keyPolicy-Cp0FntZl.js';
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  isSubscriptionProviderId,
3
3
  parseModelRef,
4
+ pickModelRefFromList,
4
5
  resolveRoute
5
- } from "../chunk-3MEACFK3.js";
6
+ } from "../chunk-UHGVBFU3.js";
6
7
  import "../chunk-AQ5TNQB7.js";
8
+ import "../chunk-XEKD23J5.js";
7
9
  export {
8
10
  isSubscriptionProviderId,
9
11
  parseModelRef,
12
+ pickModelRefFromList,
10
13
  resolveRoute
11
14
  };
@@ -1 +1,6 @@
1
- "use strict";
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk4IH4EL7Mcjs = require('../chunk-4IH4EL7M.cjs');
4
+
5
+
6
+ exports.ENDPOINT_MODEL_KINDS = _chunk4IH4EL7Mcjs.ENDPOINT_MODEL_KINDS;
@@ -1,6 +1,14 @@
1
- import { ProviderConfigSource } from '../ports/provider-config-source.cjs';
2
- import { P as ProviderProxy } from '../ProviderProxy-CnMQYN59.cjs';
3
- import { ProviderProxyDeps } from '../provider-proxy/types.cjs';
1
+ import '@omnicross/contracts/account-tokens-types';
2
+ import '@omnicross/contracts/audit-types';
3
+ import '@omnicross/contracts/billing-types';
4
+ import '@omnicross/contracts/health-logging-types';
5
+ import '@omnicross/contracts/voucher-types';
6
+ import '@omnicross/contracts/webhook-types';
7
+ import '../logger-4GvQNzhE.cjs';
8
+ import '../ports/provider-config-source.cjs';
9
+ import '../ProviderProxy-CnMQYN59.cjs';
10
+ import '../provider-proxy/types.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';
4
12
  import '@omnicross/contracts/llm-config';
5
13
  import '../transformer/types.cjs';
6
14
  import '../transformer/TransformerService.cjs';
@@ -9,149 +17,9 @@ import '@omnicross/contracts/completion-types';
9
17
  import '@omnicross/contracts/subscription-types';
10
18
  import '@omnicross/contracts/usage-types';
11
19
  import '../completion/ApiKeyPoolService.cjs';
12
- import '../logger-4GvQNzhE.cjs';
13
20
  import '../pipeline/AuthSource.cjs';
14
21
  import '../pipeline/SubscriptionAuthSource.cjs';
15
22
  import '../pipeline/SubscriptionAuthStrategy.cjs';
16
23
  import '../ports/web-search-backend.cjs';
17
24
  import '@omnicross/contracts/websearch-types';
18
-
19
- /**
20
- * Shared contract types for the outbound API server (`outbound-api-server`).
21
- *
22
- * The outbound server is a SEPARATE long-lived HTTP listener (distinct from the
23
- * resident loopback `ProviderProxy`) that authenticates external callers via
24
- * named API keys and routes their requests through the EXISTING `provider-proxy`
25
- * ingress parsers + transformer — there is exactly one conversion stack.
26
- *
27
- * These types are kept in their own module so the server, router, auth, rate
28
- * limiter, role detection, and route resolver can share shapes without circular
29
- * imports.
30
- *
31
- * @module outbound-api/types
32
- */
33
-
34
- /** The four endpoints, 1:1 with the four wire-format ingress parsers. */
35
- type OutboundEndpoint = 'chat' | 'responses' | 'messages' | 'gemini';
36
- /** A `"providerId,modelId"` model reference (mirrors `RouterConfig` vocab). */
37
- type ModelRef = string;
38
- /** The detected request role; precedence vision > background > default. */
39
- type RequestRole = 'vision' | 'background' | 'default';
40
- /**
41
- * Per-endpoint routing config. Persisted independently of the global
42
- * "默认模型" settings tab; survives restart.
43
- */
44
- interface EndpointRoutingConfig {
45
- /** Which of the four endpoints this block configures. */
46
- endpoint: OutboundEndpoint;
47
- /** REQUIRED — model for normal (non-vision, non-background) requests. */
48
- defaultModel: ModelRef;
49
- /** REQUIRED — model for background/probe/small-task requests. */
50
- backgroundModel: ModelRef;
51
- /** OPTIONAL — model for requests carrying image/vision content. */
52
- visionModel?: ModelRef;
53
- /** Gates subscription-vs-BYO provider selection. Default FALSE. */
54
- useSubscription: boolean;
55
- /**
56
- * OPTIONAL per-endpoint "background model id" override list (human decision
57
- * after the proposal). When set, an incoming requested model id appearing in
58
- * this list is classified as the BACKGROUND role; otherwise the registry
59
- * small/haiku-class signal is the baseline. Empty/unset → registry signal
60
- * only. Compared against the requested model id (bare or `providerId,modelId`).
61
- */
62
- backgroundModelIds?: string[];
63
- }
64
- /** The persisted server config. */
65
- interface OutboundApiServerConfig {
66
- /** When false the listener never binds (off by default). */
67
- enabled: boolean;
68
- /** When true the listener binds `0.0.0.0` (LAN) instead of `127.0.0.1`. */
69
- networkBinding: boolean;
70
- /** Per-endpoint routing config, one per endpoint (4 entries). */
71
- endpoints: EndpointRoutingConfig[];
72
- /** Persisted port (fixed default; falls back to ephemeral on EADDRINUSE). */
73
- port?: number;
74
- }
75
- /** A live status snapshot the Settings tab renders. */
76
- interface OutboundApiServerStatus {
77
- running: boolean;
78
- /** Actual bound port (0 when not running). */
79
- port: number;
80
- /** Loopback base URL (always present when running). */
81
- loopbackUrl: string | null;
82
- /** LAN base URL (present only when network binding is on). */
83
- lanUrl: string | null;
84
- /** The four format endpoint URLs (loopback). */
85
- formats: OutboundFormatUrls | null;
86
- /** The four format endpoint URLs over the LAN (only when network binding on). */
87
- lanFormats: OutboundFormatUrls | null;
88
- }
89
- /** The four format endpoint URLs for one base. */
90
- interface OutboundFormatUrls {
91
- chat: string;
92
- responses: string;
93
- messages: string;
94
- gemini: string;
95
- }
96
- /** A stored key DTO (never carries the plaintext secret). */
97
- interface OutboundApiKeyInfo {
98
- id: string;
99
- name: string;
100
- keyPrefix: string;
101
- enabled: boolean;
102
- createdAt: number;
103
- lastUsedAt: number | null;
104
- revoked: boolean;
105
- }
106
- /** The one-time create result; `plaintextOnce` is shown exactly once. */
107
- interface OutboundApiKeyCreated {
108
- id: string;
109
- name: string;
110
- keyPrefix: string;
111
- createdAt: number;
112
- plaintextOnce: string;
113
- }
114
- /**
115
- * Structural subset of the DB the outbound server needs — the named-key CRUD
116
- * surface. Kept structural so the server module does not depend on the full
117
- * `DbRpc`.
118
- */
119
- interface OutboundKeyDbRow {
120
- id: string;
121
- name: string;
122
- keyHash: string;
123
- keyPrefix: string;
124
- enabled: boolean;
125
- createdAt: number;
126
- lastUsedAt: number | null;
127
- revokedAt: number | null;
128
- }
129
- interface OutboundKeyDb {
130
- outboundApiKeysList(): Promise<OutboundKeyDbRow[]>;
131
- outboundApiKeysGetByHash(hash: string): Promise<OutboundKeyDbRow | null>;
132
- outboundApiKeysCreate(input: {
133
- id: string;
134
- name: string;
135
- keyHash: string;
136
- keyPrefix: string;
137
- createdAt?: number;
138
- }): Promise<OutboundKeyDbRow>;
139
- outboundApiKeysRevoke(id: string): Promise<boolean>;
140
- outboundApiKeysTouchLastUsed(id: string): Promise<boolean>;
141
- outboundApiKeysSetEnabled(id: string, enabled: boolean): Promise<boolean>;
142
- }
143
- /**
144
- * App-session-scoped dependencies the outbound server needs. The resident
145
- * `ProviderProxy` is shared so the new listener mints routes on the SAME route
146
- * map and reuses the SAME ingress parsers + transformer.
147
- */
148
- interface OutboundApiDeps {
149
- readonly db: OutboundKeyDb;
150
- readonly llmConfig: ProviderConfigSource;
151
- /** The resident proxy — shared for route minting + ingress dispatch. */
152
- readonly providerProxy: ProviderProxy;
153
- /** The proxy's app-session deps (reused verbatim for `routeRequest`). */
154
- readonly proxyDeps: ProviderProxyDeps;
155
- }
156
-
157
- export type { EndpointRoutingConfig, ModelRef, OutboundApiDeps, OutboundApiKeyCreated, OutboundApiKeyInfo, OutboundApiServerConfig, OutboundApiServerStatus, OutboundEndpoint, OutboundFormatUrls, OutboundKeyDb, OutboundKeyDbRow, RequestRole };
25
+ import '../keyPolicy-Cp0FntZl.cjs';