@omnicross/core 0.1.2 → 0.1.3

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 (131) hide show
  1. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -1
  2. package/dist/auth/GeminiCodeAssistProjectResolver.js +6 -1
  3. package/dist/{chunk-SN3YWBX7.cjs → chunk-2FMI2B6V.cjs} +2329 -533
  4. package/dist/{chunk-XBSYYZIY.cjs → chunk-3QOSDDNI.cjs} +39 -3
  5. package/dist/{chunk-2FEVTJWG.js → chunk-4DECIFU7.js} +2162 -366
  6. package/dist/chunk-4IH4EL7M.cjs +9 -0
  7. package/dist/chunk-5ENKBSWO.js +311 -0
  8. package/dist/chunk-6RPZADX3.cjs +92 -0
  9. package/dist/chunk-AEOZIDEB.cjs +32 -0
  10. package/dist/chunk-BO4RFWBR.js +89 -0
  11. package/dist/{chunk-MNYKI4CI.js → chunk-CWM2ZDU5.js} +36 -0
  12. package/dist/chunk-CZHZGRU7.js +383 -0
  13. package/dist/{chunk-4NBS6KPV.cjs → chunk-DQ5VAYZ6.cjs} +7 -8
  14. package/dist/chunk-HUZZZ3JL.js +32 -0
  15. package/dist/{chunk-QOCNX236.js → chunk-IAXWICZU.js} +24 -1
  16. package/dist/{chunk-V5KPWNYX.cjs → chunk-JMJBSACD.cjs} +3 -3
  17. package/dist/chunk-L74VDN4A.cjs +32 -0
  18. package/dist/{chunk-74TMJA7Z.js → chunk-N5QFKSDO.js} +7 -4
  19. package/dist/{chunk-LKZJEL6E.cjs → chunk-Q27JY5RG.cjs} +6 -4
  20. package/dist/{chunk-SPVWWUHX.cjs → chunk-QWBWGODS.cjs} +24 -1
  21. package/dist/chunk-RPII3E6Z.cjs +145 -0
  22. package/dist/chunk-S6JGLF3G.cjs +89 -0
  23. package/dist/chunk-SVXC36MU.cjs +383 -0
  24. package/dist/chunk-TKJMZBAH.js +32 -0
  25. package/dist/{chunk-ZSVQT3PW.js → chunk-UBWEBKRC.js} +5 -6
  26. package/dist/chunk-UNEFIWXI.cjs +32 -0
  27. package/dist/chunk-VQY5W4YW.cjs +311 -0
  28. package/dist/chunk-WNY4WMRF.js +32 -0
  29. package/dist/chunk-XEKD23J5.js +9 -0
  30. package/dist/chunk-XTEI64OU.js +145 -0
  31. package/dist/chunk-XX6NQJMA.js +92 -0
  32. package/dist/{chunk-N3V2J5ZO.cjs → chunk-Y6OM7EV7.cjs} +7 -4
  33. package/dist/{chunk-745DV5FL.js → chunk-Y7FO65VT.js} +3 -3
  34. package/dist/{chunk-PXUJF5HS.js → chunk-ZY6KU6P3.js} +4 -2
  35. package/dist/completion/CompletionService.cjs +22 -15
  36. package/dist/completion/CompletionService.js +21 -14
  37. package/dist/completion/NativeSearchInjector.cjs +3 -3
  38. package/dist/completion/NativeSearchInjector.js +2 -2
  39. package/dist/completion/openrouter-headers.cjs +3 -6
  40. package/dist/completion/openrouter-headers.d.cts +9 -12
  41. package/dist/completion/openrouter-headers.d.ts +9 -12
  42. package/dist/completion/openrouter-headers.js +2 -5
  43. package/dist/completion/openrouter-models.cjs +4 -3
  44. package/dist/completion/openrouter-models.js +2 -1
  45. package/dist/completion.cjs +22 -15
  46. package/dist/completion.js +21 -14
  47. package/dist/index.cjs +139 -17
  48. package/dist/index.d.cts +40 -10
  49. package/dist/index.d.ts +40 -10
  50. package/dist/index.js +146 -24
  51. package/dist/outbound-api/routeResolver.cjs +5 -2
  52. package/dist/outbound-api/routeResolver.d.cts +8 -2
  53. package/dist/outbound-api/routeResolver.d.ts +8 -2
  54. package/dist/outbound-api/routeResolver.js +4 -1
  55. package/dist/outbound-api/types.cjs +6 -1
  56. package/dist/outbound-api/types.d.cts +11 -144
  57. package/dist/outbound-api/types.d.ts +11 -144
  58. package/dist/outbound-api/types.js +6 -0
  59. package/dist/outbound-api.cjs +133 -15
  60. package/dist/outbound-api.d.cts +786 -25
  61. package/dist/outbound-api.d.ts +786 -25
  62. package/dist/outbound-api.js +137 -19
  63. package/dist/pipeline/AuthSource.d.cts +23 -1
  64. package/dist/pipeline/AuthSource.d.ts +23 -1
  65. package/dist/pipeline/LlmConfigProviderAuth.cjs +3 -3
  66. package/dist/pipeline/LlmConfigProviderAuth.js +2 -2
  67. package/dist/pipeline/SubscriptionAccountHealth.cjs +22 -0
  68. package/dist/pipeline/SubscriptionAccountHealth.d.cts +235 -0
  69. package/dist/pipeline/SubscriptionAccountHealth.d.ts +235 -0
  70. package/dist/pipeline/SubscriptionAccountHealth.js +22 -0
  71. package/dist/pipeline/SubscriptionAuthSource.cjs +2 -2
  72. package/dist/pipeline/SubscriptionAuthSource.d.cts +3 -2
  73. package/dist/pipeline/SubscriptionAuthSource.d.ts +3 -2
  74. package/dist/pipeline/SubscriptionAuthSource.js +1 -1
  75. package/dist/pipeline/SubscriptionAuthStrategy.d.cts +24 -1
  76. package/dist/pipeline/SubscriptionAuthStrategy.d.ts +24 -1
  77. package/dist/pipeline/auditSink.cjs +14 -0
  78. package/dist/pipeline/auditSink.d.cts +48 -0
  79. package/dist/pipeline/auditSink.d.ts +48 -0
  80. package/dist/pipeline/auditSink.js +14 -0
  81. package/dist/pipeline/billingEmit.cjs +14 -0
  82. package/dist/pipeline/billingEmit.d.cts +49 -0
  83. package/dist/pipeline/billingEmit.d.ts +49 -0
  84. package/dist/pipeline/billingEmit.js +14 -0
  85. package/dist/ports/usage-event-store.d.cts +26 -1
  86. package/dist/ports/usage-event-store.d.ts +26 -1
  87. package/dist/ports.d.cts +7 -1
  88. package/dist/ports.d.ts +7 -1
  89. package/dist/provider-proxy/ProviderProxy.cjs +22 -15
  90. package/dist/provider-proxy/ProviderProxy.js +21 -14
  91. package/dist/provider-proxy/identity/SubscriptionIdentityStore.cjs +15 -0
  92. package/dist/provider-proxy/identity/SubscriptionIdentityStore.d.cts +121 -0
  93. package/dist/provider-proxy/identity/SubscriptionIdentityStore.d.ts +121 -0
  94. package/dist/provider-proxy/identity/SubscriptionIdentityStore.js +15 -0
  95. package/dist/provider-proxy/identity/fingerprintHeaders.cjs +20 -0
  96. package/dist/provider-proxy/identity/fingerprintHeaders.d.cts +89 -0
  97. package/dist/provider-proxy/identity/fingerprintHeaders.d.ts +89 -0
  98. package/dist/provider-proxy/identity/fingerprintHeaders.js +20 -0
  99. package/dist/provider-proxy/ingress/providerProxyShared.cjs +22 -15
  100. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +11 -2
  101. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +11 -2
  102. package/dist/provider-proxy/ingress/providerProxyShared.js +21 -14
  103. package/dist/provider-proxy/matchText.cjs +4 -2
  104. package/dist/provider-proxy/matchText.d.cts +14 -1
  105. package/dist/provider-proxy/matchText.d.ts +14 -1
  106. package/dist/provider-proxy/matchText.js +3 -1
  107. package/dist/provider-proxy/types.d.cts +23 -0
  108. package/dist/provider-proxy/types.d.ts +23 -0
  109. package/dist/provider-proxy.cjs +22 -15
  110. package/dist/provider-proxy.js +21 -14
  111. package/dist/{routeResolver-HE-ZO0fO.d.ts → routeResolver-B1NglTfe.d.ts} +36 -10
  112. package/dist/{routeResolver-BrbK6ja9.d.cts → routeResolver-CbG5uBgm.d.cts} +36 -10
  113. package/dist/transformer/transformers.cjs +7 -7
  114. package/dist/transformer/transformers.js +7 -7
  115. package/dist/transformer.cjs +5 -5
  116. package/dist/transformer.js +4 -4
  117. package/dist/types-6OUY_xfA.d.ts +830 -0
  118. package/dist/types-aBFFXoBz.d.cts +830 -0
  119. package/dist/usage/usage-recorder.cjs +2 -2
  120. package/dist/usage/usage-recorder.d.cts +19 -1
  121. package/dist/usage/usage-recorder.d.ts +19 -1
  122. package/dist/usage/usage-recorder.js +1 -1
  123. package/dist/usage.cjs +2 -2
  124. package/dist/usage.js +1 -1
  125. package/package.json +4 -2
  126. package/dist/chunk-3MEACFK3.js +0 -193
  127. package/dist/chunk-6VIXXLMX.cjs +0 -14
  128. package/dist/chunk-E3WHL7CO.js +0 -14
  129. package/dist/chunk-G2FUJNA2.cjs +0 -193
  130. package/dist/{chunk-UYPEN5XE.cjs → chunk-FFALUUZZ.cjs} +5 -5
  131. package/dist/{chunk-O466Y272.js → chunk-MQNDWYPN.js} +6 -6
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkXBSYYZIYcjs = require('../chunk-XBSYYZIY.cjs');
3
+ var _chunk3QOSDDNIcjs = require('../chunk-3QOSDDNI.cjs');
4
4
 
5
5
 
6
- exports.UsageRecorder = _chunkXBSYYZIYcjs.UsageRecorder;
6
+ exports.UsageRecorder = _chunk3QOSDDNIcjs.UsageRecorder;
@@ -1,5 +1,5 @@
1
1
  import { PricingEngine } from './pricing-engine.cjs';
2
- import { UsageDateRange, UsageTotals, ModelUsageRow, ApiKeyUsageRow, MessageUsageRow, SessionCacheStats } from '@omnicross/contracts/usage-stats-types';
2
+ import { UsageDateRange, UsageTotals, ModelUsageRow, ApiKeyUsageRow, UsageTimeBucket, UsageTimeSeriesBucket, MessageUsageRow, SessionCacheStats } from '@omnicross/contracts/usage-stats-types';
3
3
  import { UsageEngineOrigin, UsageTokens } from '@omnicross/contracts/usage-types';
4
4
  import { L as Logger } from '../logger-4GvQNzhE.cjs';
5
5
  import { UsageEventStore } from '../ports/usage-event-store.cjs';
@@ -34,6 +34,15 @@ interface UsageRecordInput {
34
34
  runId?: string | null;
35
35
  /** Host event-correlation id for this call. Optional / additive. */
36
36
  eventId?: string | null;
37
+ /**
38
+ * OPTIONAL per-request audit correlation key (request-audit-log). When the
39
+ * OUTBOUND relay taps set this to the request's `http.ServerResponse`, the
40
+ * recorder stashes this request's token counts (synchronously) + cost (on the
41
+ * deferred pricing tick) keyed by it, so the audit capture can enrich its
42
+ * record. Any other caller leaves it unset ⇒ the audit stash is never touched
43
+ * (byte-identical zero regression). Opaque object; NEVER inspected/serialized.
44
+ */
45
+ auditResponse?: object;
37
46
  }
38
47
  /** Optional knobs (mostly for hosts/tests). */
39
48
  interface UsageRecorderOptions {
@@ -43,12 +52,20 @@ interface UsageRecorderOptions {
43
52
  * `setImmediate` to preserve their exact scheduling.
44
53
  */
45
54
  defer?: (fn: () => void) => void;
55
+ /**
56
+ * OPTIONAL per-request hook (outbound-key-policy). Called synchronously after
57
+ * cost is computed for each recorded request that carries an `apiKeyId`, so a
58
+ * host can keep a live per-key spend aggregate WITHOUT re-scanning the store.
59
+ * Absent ⇒ no-op (byte-identical for hosts/tests that do not wire it).
60
+ */
61
+ onRecord?: (apiKeyId: string, costUsd: number, now: number) => void;
46
62
  }
47
63
  declare class UsageRecorder {
48
64
  private store;
49
65
  private pricing;
50
66
  private logger;
51
67
  private defer;
68
+ private onRecord?;
52
69
  constructor(store: UsageEventStore, pricing: PricingEngine, logger: Logger, options?: UsageRecorderOptions);
53
70
  /**
54
71
  * Record one LLM request. Returns immediately — the actual store insert is
@@ -65,6 +82,7 @@ declare class UsageRecorder {
65
82
  getTotals(range: UsageDateRange): Promise<UsageTotals>;
66
83
  getByModel(range: UsageDateRange): Promise<ModelUsageRow[]>;
67
84
  getByApiKey(range: UsageDateRange): Promise<ApiKeyUsageRow[]>;
85
+ getTimeSeries(range: UsageDateRange, bucket: UsageTimeBucket): Promise<UsageTimeSeriesBucket[]>;
68
86
  getMessagesForSession(sessionId: string): Promise<MessageUsageRow[]>;
69
87
  /** Cumulative cache hit/miss stats for one session. */
70
88
  getSessionCacheStats(sessionId: string): Promise<SessionCacheStats>;
@@ -1,5 +1,5 @@
1
1
  import { PricingEngine } from './pricing-engine.js';
2
- import { UsageDateRange, UsageTotals, ModelUsageRow, ApiKeyUsageRow, MessageUsageRow, SessionCacheStats } from '@omnicross/contracts/usage-stats-types';
2
+ import { UsageDateRange, UsageTotals, ModelUsageRow, ApiKeyUsageRow, UsageTimeBucket, UsageTimeSeriesBucket, MessageUsageRow, SessionCacheStats } from '@omnicross/contracts/usage-stats-types';
3
3
  import { UsageEngineOrigin, UsageTokens } from '@omnicross/contracts/usage-types';
4
4
  import { L as Logger } from '../logger-4GvQNzhE.js';
5
5
  import { UsageEventStore } from '../ports/usage-event-store.js';
@@ -34,6 +34,15 @@ interface UsageRecordInput {
34
34
  runId?: string | null;
35
35
  /** Host event-correlation id for this call. Optional / additive. */
36
36
  eventId?: string | null;
37
+ /**
38
+ * OPTIONAL per-request audit correlation key (request-audit-log). When the
39
+ * OUTBOUND relay taps set this to the request's `http.ServerResponse`, the
40
+ * recorder stashes this request's token counts (synchronously) + cost (on the
41
+ * deferred pricing tick) keyed by it, so the audit capture can enrich its
42
+ * record. Any other caller leaves it unset ⇒ the audit stash is never touched
43
+ * (byte-identical zero regression). Opaque object; NEVER inspected/serialized.
44
+ */
45
+ auditResponse?: object;
37
46
  }
38
47
  /** Optional knobs (mostly for hosts/tests). */
39
48
  interface UsageRecorderOptions {
@@ -43,12 +52,20 @@ interface UsageRecorderOptions {
43
52
  * `setImmediate` to preserve their exact scheduling.
44
53
  */
45
54
  defer?: (fn: () => void) => void;
55
+ /**
56
+ * OPTIONAL per-request hook (outbound-key-policy). Called synchronously after
57
+ * cost is computed for each recorded request that carries an `apiKeyId`, so a
58
+ * host can keep a live per-key spend aggregate WITHOUT re-scanning the store.
59
+ * Absent ⇒ no-op (byte-identical for hosts/tests that do not wire it).
60
+ */
61
+ onRecord?: (apiKeyId: string, costUsd: number, now: number) => void;
46
62
  }
47
63
  declare class UsageRecorder {
48
64
  private store;
49
65
  private pricing;
50
66
  private logger;
51
67
  private defer;
68
+ private onRecord?;
52
69
  constructor(store: UsageEventStore, pricing: PricingEngine, logger: Logger, options?: UsageRecorderOptions);
53
70
  /**
54
71
  * Record one LLM request. Returns immediately — the actual store insert is
@@ -65,6 +82,7 @@ declare class UsageRecorder {
65
82
  getTotals(range: UsageDateRange): Promise<UsageTotals>;
66
83
  getByModel(range: UsageDateRange): Promise<ModelUsageRow[]>;
67
84
  getByApiKey(range: UsageDateRange): Promise<ApiKeyUsageRow[]>;
85
+ getTimeSeries(range: UsageDateRange, bucket: UsageTimeBucket): Promise<UsageTimeSeriesBucket[]>;
68
86
  getMessagesForSession(sessionId: string): Promise<MessageUsageRow[]>;
69
87
  /** Cumulative cache hit/miss stats for one session. */
70
88
  getSessionCacheStats(sessionId: string): Promise<SessionCacheStats>;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  UsageRecorder
3
- } from "../chunk-MNYKI4CI.js";
3
+ } from "../chunk-CWM2ZDU5.js";
4
4
  export {
5
5
  UsageRecorder
6
6
  };
package/dist/usage.cjs CHANGED
@@ -4,8 +4,8 @@
4
4
  var _chunkYMFAJFQTcjs = require('./chunk-YMFAJFQT.cjs');
5
5
 
6
6
 
7
- var _chunkXBSYYZIYcjs = require('./chunk-XBSYYZIY.cjs');
7
+ var _chunk3QOSDDNIcjs = require('./chunk-3QOSDDNI.cjs');
8
8
 
9
9
 
10
10
 
11
- exports.PricingEngine = _chunkYMFAJFQTcjs.PricingEngine; exports.UsageRecorder = _chunkXBSYYZIYcjs.UsageRecorder;
11
+ exports.PricingEngine = _chunkYMFAJFQTcjs.PricingEngine; exports.UsageRecorder = _chunk3QOSDDNIcjs.UsageRecorder;
package/dist/usage.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-ZLX3KGXX.js";
5
5
  import {
6
6
  UsageRecorder
7
- } from "./chunk-MNYKI4CI.js";
7
+ } from "./chunk-CWM2ZDU5.js";
8
8
  export {
9
9
  PricingEngine,
10
10
  UsageRecorder
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnicross/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Omnicross LLM serving core — provider dispatch, completion pipeline, transformers, and the provider proxy.",
5
5
  "license": "MIT",
6
6
  "author": "Sayo (https://github.com/Dumoedss)",
@@ -57,6 +57,8 @@
57
57
  "@mozilla/readability": "^0.6.0",
58
58
  "@omnicross/contracts": "^0.1.0",
59
59
  "jsdom": "^24.1.3",
60
- "turndown": "^7.2.2"
60
+ "socks": "^2.8.3",
61
+ "turndown": "^7.2.2",
62
+ "undici": "^6.21.1"
61
63
  }
62
64
  }
@@ -1,193 +0,0 @@
1
- import {
2
- getSubscriptionRegistryForOutbound
3
- } from "./chunk-AQ5TNQB7.js";
4
-
5
- // src/outbound-api/subscriptionSupport.ts
6
- var SUBSCRIPTION_PROVIDER_IDS = [
7
- "claude",
8
- "codex",
9
- "gemini",
10
- "opencodego"
11
- ];
12
- var SUBSCRIPTION_ID_SET = new Set(SUBSCRIPTION_PROVIDER_IDS);
13
- function isSubscriptionProviderId(providerId) {
14
- if (SUBSCRIPTION_ID_SET.has(providerId)) return true;
15
- const registry = getSubscriptionRegistryForOutbound();
16
- return registry?.getProfile(providerId) != null;
17
- }
18
- var SUBSCRIPTION_SUPPORTED_ENDPOINTS = /* @__PURE__ */ new Set([
19
- "messages",
20
- "responses"
21
- ]);
22
- function endpointSupportsSubscription(endpoint) {
23
- return SUBSCRIPTION_SUPPORTED_ENDPOINTS.has(endpoint);
24
- }
25
-
26
- // src/outbound-api/routeResolver.ts
27
- function parseModelRef(ref) {
28
- if (!ref) return null;
29
- const idx = ref.indexOf(",");
30
- if (idx <= 0) return null;
31
- const providerId = ref.slice(0, idx).trim();
32
- const modelId = ref.slice(idx + 1).trim();
33
- if (!providerId || !modelId) return null;
34
- return { providerId, modelId };
35
- }
36
- function pickModelRefForRole(config, role) {
37
- if (role === "vision") {
38
- if (config.visionModel && config.visionModel.trim()) {
39
- return { ref: config.visionModel, effectiveRole: "vision" };
40
- }
41
- return { ref: config.defaultModel, effectiveRole: "default" };
42
- }
43
- if (role === "background") {
44
- return { ref: config.backgroundModel, effectiveRole: "background" };
45
- }
46
- return { ref: config.defaultModel, effectiveRole: "default" };
47
- }
48
- async function resolveRoute(args) {
49
- const { config, role, ingressFormat, llmConfig } = args;
50
- const sessionId = args.sessionId ?? null;
51
- const { ref, effectiveRole } = pickModelRefForRole(config, role);
52
- if (!ref || !ref.trim()) {
53
- return {
54
- ok: false,
55
- error: {
56
- status: 503,
57
- message: `endpoint '${config.endpoint}' has no ${effectiveRole} model configured`
58
- }
59
- };
60
- }
61
- const parsed = parseModelRef(ref);
62
- if (!parsed) {
63
- return {
64
- ok: false,
65
- error: {
66
- status: 503,
67
- message: `endpoint '${config.endpoint}' ${effectiveRole} model ref is malformed: '${ref}'`
68
- }
69
- };
70
- }
71
- const { providerId, modelId } = parsed;
72
- const provider = await llmConfig.getProvider(providerId);
73
- if (!provider) {
74
- if (isSubscriptionProviderId(providerId)) {
75
- return await resolveSubscriptionRoute({
76
- config,
77
- providerId,
78
- modelId,
79
- ingressFormat,
80
- sessionId,
81
- effectiveRole
82
- });
83
- }
84
- return {
85
- ok: false,
86
- error: {
87
- status: 503,
88
- message: `provider '${providerId}' not found for endpoint '${config.endpoint}'`
89
- }
90
- };
91
- }
92
- const isOfficialProvider = provider.isOfficial === true || provider.id === "anthropic";
93
- const targetProviderFormat = isOfficialProvider ? "anthropic" : "transform";
94
- let anthropicSdkHints = null;
95
- if (ingressFormat === "anthropic-messages") {
96
- anthropicSdkHints = {
97
- apiKey: resolveApiKey(provider.api_key),
98
- isOfficialProvider,
99
- passThrough: false,
100
- attribution: { sessionId, apiKeyId: null }
101
- };
102
- }
103
- const route = {
104
- sessionId,
105
- targetProviderFormat,
106
- model: modelId,
107
- ingressFormat,
108
- authMode: "byo",
109
- providerId,
110
- anthropicSdkHints
111
- };
112
- return { ok: true, route, usedRole: effectiveRole };
113
- }
114
- async function resolveSubscriptionRoute(args) {
115
- const { config, providerId, modelId, ingressFormat, sessionId, effectiveRole } = args;
116
- if (!config.useSubscription) {
117
- return {
118
- ok: false,
119
- error: {
120
- status: 503,
121
- message: `subscription routing disabled for endpoint '${config.endpoint}'`
122
- }
123
- };
124
- }
125
- if (!endpointSupportsSubscription(config.endpoint)) {
126
- return {
127
- ok: false,
128
- error: {
129
- status: 503,
130
- message: `subscription routing is not supported on the '${config.endpoint}' endpoint; use a BYO API-key provider, or the /v1/messages or /v1/responses endpoint`
131
- }
132
- };
133
- }
134
- const registry = getSubscriptionRegistryForOutbound();
135
- const profile = registry?.getProfile(providerId) ?? null;
136
- if (!profile) {
137
- return {
138
- ok: false,
139
- error: {
140
- status: 503,
141
- message: `subscription provider '${providerId}' is not available`
142
- }
143
- };
144
- }
145
- const hints = {
146
- apiKey: "",
147
- isOfficialProvider: false,
148
- passThrough: false,
149
- subscriptionProfile: profile,
150
- attribution: { sessionId, apiKeyId: null }
151
- };
152
- const subscriptionConfig = providerId === "opencodego" ? await registry?.getOpenCodeGoConfig?.() : void 0;
153
- const route = {
154
- sessionId,
155
- targetProviderFormat: "transform",
156
- model: modelId,
157
- ingressFormat,
158
- authMode: "subscription",
159
- providerId,
160
- // Anthropic delegation carries the dispatch profile inside
161
- // `anthropicSdkHints.subscriptionProfile`. The Responses ingress reads the
162
- // TOP-LEVEL `route.subscriptionProfile`, and so does the built-in
163
- // (factory-absent) `/v1/messages` subscription path (RT2.1) — the registry's
164
- // `SubscriptionDispatchProfile` structurally satisfies `SubscriptionAuthProfile`
165
- // ({ authStrategy, resolveUpstreamUrl, providerTransformerNames }), so set it
166
- // for BOTH. This is INERT when an Anthropic ingress factory is present: that
167
- // delegation reads the hint-bundle field above (and uses a different
168
- // route-minting path), never the top-level field. (chat/gemini never reach
169
- // here — Gate 2 rejected them.)
170
- subscriptionProfile: ingressFormat === "openai-responses" || ingressFormat === "anthropic-messages" ? profile : void 0,
171
- // Opaque per-account config (opencodego-only; `undefined` otherwise). Read by
172
- // the built-in `/v1/messages` plan builder; INERT for the factory-present
173
- // delegation path + non-opencodego.
174
- subscriptionConfig,
175
- anthropicSdkHints: hints
176
- };
177
- return { ok: true, route, usedRole: effectiveRole };
178
- }
179
- function resolveApiKey(apiKey) {
180
- if (!apiKey) return "";
181
- if (apiKey.startsWith("$")) {
182
- return process.env[apiKey.slice(1)] || "";
183
- }
184
- return apiKey;
185
- }
186
-
187
- export {
188
- SUBSCRIPTION_PROVIDER_IDS,
189
- isSubscriptionProviderId,
190
- endpointSupportsSubscription,
191
- parseModelRef,
192
- resolveRoute
193
- };
@@ -1,14 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/openrouter.ts
2
- function isOpenRouterProvider(provider) {
3
- const baseUrl = (provider.api_base_url || "").toLowerCase();
4
- return baseUrl.includes("openrouter.ai");
5
- }
6
- var OPENROUTER_APP_HEADERS = {
7
- "HTTP-Referer": "https://omnicross.dev",
8
- "X-Title": "omnicross"
9
- };
10
-
11
-
12
-
13
-
14
- exports.isOpenRouterProvider = isOpenRouterProvider; exports.OPENROUTER_APP_HEADERS = OPENROUTER_APP_HEADERS;
@@ -1,14 +0,0 @@
1
- // src/openrouter.ts
2
- function isOpenRouterProvider(provider) {
3
- const baseUrl = (provider.api_base_url || "").toLowerCase();
4
- return baseUrl.includes("openrouter.ai");
5
- }
6
- var OPENROUTER_APP_HEADERS = {
7
- "HTTP-Referer": "https://omnicross.dev",
8
- "X-Title": "omnicross"
9
- };
10
-
11
- export {
12
- isOpenRouterProvider,
13
- OPENROUTER_APP_HEADERS
14
- };
@@ -1,193 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunkQBZJ7P2Tcjs = require('./chunk-QBZJ7P2T.cjs');
4
-
5
- // src/outbound-api/subscriptionSupport.ts
6
- var SUBSCRIPTION_PROVIDER_IDS = [
7
- "claude",
8
- "codex",
9
- "gemini",
10
- "opencodego"
11
- ];
12
- var SUBSCRIPTION_ID_SET = new Set(SUBSCRIPTION_PROVIDER_IDS);
13
- function isSubscriptionProviderId(providerId) {
14
- if (SUBSCRIPTION_ID_SET.has(providerId)) return true;
15
- const registry = _chunkQBZJ7P2Tcjs.getSubscriptionRegistryForOutbound.call(void 0, );
16
- return _optionalChain([registry, 'optionalAccess', _ => _.getProfile, 'call', _2 => _2(providerId)]) != null;
17
- }
18
- var SUBSCRIPTION_SUPPORTED_ENDPOINTS = /* @__PURE__ */ new Set([
19
- "messages",
20
- "responses"
21
- ]);
22
- function endpointSupportsSubscription(endpoint) {
23
- return SUBSCRIPTION_SUPPORTED_ENDPOINTS.has(endpoint);
24
- }
25
-
26
- // src/outbound-api/routeResolver.ts
27
- function parseModelRef(ref) {
28
- if (!ref) return null;
29
- const idx = ref.indexOf(",");
30
- if (idx <= 0) return null;
31
- const providerId = ref.slice(0, idx).trim();
32
- const modelId = ref.slice(idx + 1).trim();
33
- if (!providerId || !modelId) return null;
34
- return { providerId, modelId };
35
- }
36
- function pickModelRefForRole(config, role) {
37
- if (role === "vision") {
38
- if (config.visionModel && config.visionModel.trim()) {
39
- return { ref: config.visionModel, effectiveRole: "vision" };
40
- }
41
- return { ref: config.defaultModel, effectiveRole: "default" };
42
- }
43
- if (role === "background") {
44
- return { ref: config.backgroundModel, effectiveRole: "background" };
45
- }
46
- return { ref: config.defaultModel, effectiveRole: "default" };
47
- }
48
- async function resolveRoute(args) {
49
- const { config, role, ingressFormat, llmConfig } = args;
50
- const sessionId = _nullishCoalesce(args.sessionId, () => ( null));
51
- const { ref, effectiveRole } = pickModelRefForRole(config, role);
52
- if (!ref || !ref.trim()) {
53
- return {
54
- ok: false,
55
- error: {
56
- status: 503,
57
- message: `endpoint '${config.endpoint}' has no ${effectiveRole} model configured`
58
- }
59
- };
60
- }
61
- const parsed = parseModelRef(ref);
62
- if (!parsed) {
63
- return {
64
- ok: false,
65
- error: {
66
- status: 503,
67
- message: `endpoint '${config.endpoint}' ${effectiveRole} model ref is malformed: '${ref}'`
68
- }
69
- };
70
- }
71
- const { providerId, modelId } = parsed;
72
- const provider = await llmConfig.getProvider(providerId);
73
- if (!provider) {
74
- if (isSubscriptionProviderId(providerId)) {
75
- return await resolveSubscriptionRoute({
76
- config,
77
- providerId,
78
- modelId,
79
- ingressFormat,
80
- sessionId,
81
- effectiveRole
82
- });
83
- }
84
- return {
85
- ok: false,
86
- error: {
87
- status: 503,
88
- message: `provider '${providerId}' not found for endpoint '${config.endpoint}'`
89
- }
90
- };
91
- }
92
- const isOfficialProvider = provider.isOfficial === true || provider.id === "anthropic";
93
- const targetProviderFormat = isOfficialProvider ? "anthropic" : "transform";
94
- let anthropicSdkHints = null;
95
- if (ingressFormat === "anthropic-messages") {
96
- anthropicSdkHints = {
97
- apiKey: resolveApiKey(provider.api_key),
98
- isOfficialProvider,
99
- passThrough: false,
100
- attribution: { sessionId, apiKeyId: null }
101
- };
102
- }
103
- const route = {
104
- sessionId,
105
- targetProviderFormat,
106
- model: modelId,
107
- ingressFormat,
108
- authMode: "byo",
109
- providerId,
110
- anthropicSdkHints
111
- };
112
- return { ok: true, route, usedRole: effectiveRole };
113
- }
114
- async function resolveSubscriptionRoute(args) {
115
- const { config, providerId, modelId, ingressFormat, sessionId, effectiveRole } = args;
116
- if (!config.useSubscription) {
117
- return {
118
- ok: false,
119
- error: {
120
- status: 503,
121
- message: `subscription routing disabled for endpoint '${config.endpoint}'`
122
- }
123
- };
124
- }
125
- if (!endpointSupportsSubscription(config.endpoint)) {
126
- return {
127
- ok: false,
128
- error: {
129
- status: 503,
130
- message: `subscription routing is not supported on the '${config.endpoint}' endpoint; use a BYO API-key provider, or the /v1/messages or /v1/responses endpoint`
131
- }
132
- };
133
- }
134
- const registry = _chunkQBZJ7P2Tcjs.getSubscriptionRegistryForOutbound.call(void 0, );
135
- const profile = _nullishCoalesce(_optionalChain([registry, 'optionalAccess', _3 => _3.getProfile, 'call', _4 => _4(providerId)]), () => ( null));
136
- if (!profile) {
137
- return {
138
- ok: false,
139
- error: {
140
- status: 503,
141
- message: `subscription provider '${providerId}' is not available`
142
- }
143
- };
144
- }
145
- const hints = {
146
- apiKey: "",
147
- isOfficialProvider: false,
148
- passThrough: false,
149
- subscriptionProfile: profile,
150
- attribution: { sessionId, apiKeyId: null }
151
- };
152
- const subscriptionConfig = providerId === "opencodego" ? await _optionalChain([registry, 'optionalAccess', _5 => _5.getOpenCodeGoConfig, 'optionalCall', _6 => _6()]) : void 0;
153
- const route = {
154
- sessionId,
155
- targetProviderFormat: "transform",
156
- model: modelId,
157
- ingressFormat,
158
- authMode: "subscription",
159
- providerId,
160
- // Anthropic delegation carries the dispatch profile inside
161
- // `anthropicSdkHints.subscriptionProfile`. The Responses ingress reads the
162
- // TOP-LEVEL `route.subscriptionProfile`, and so does the built-in
163
- // (factory-absent) `/v1/messages` subscription path (RT2.1) — the registry's
164
- // `SubscriptionDispatchProfile` structurally satisfies `SubscriptionAuthProfile`
165
- // ({ authStrategy, resolveUpstreamUrl, providerTransformerNames }), so set it
166
- // for BOTH. This is INERT when an Anthropic ingress factory is present: that
167
- // delegation reads the hint-bundle field above (and uses a different
168
- // route-minting path), never the top-level field. (chat/gemini never reach
169
- // here — Gate 2 rejected them.)
170
- subscriptionProfile: ingressFormat === "openai-responses" || ingressFormat === "anthropic-messages" ? profile : void 0,
171
- // Opaque per-account config (opencodego-only; `undefined` otherwise). Read by
172
- // the built-in `/v1/messages` plan builder; INERT for the factory-present
173
- // delegation path + non-opencodego.
174
- subscriptionConfig,
175
- anthropicSdkHints: hints
176
- };
177
- return { ok: true, route, usedRole: effectiveRole };
178
- }
179
- function resolveApiKey(apiKey) {
180
- if (!apiKey) return "";
181
- if (apiKey.startsWith("$")) {
182
- return process.env[apiKey.slice(1)] || "";
183
- }
184
- return apiKey;
185
- }
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
- exports.SUBSCRIPTION_PROVIDER_IDS = SUBSCRIPTION_PROVIDER_IDS; exports.isSubscriptionProviderId = isSubscriptionProviderId; exports.endpointSupportsSubscription = endpointSupportsSubscription; exports.parseModelRef = parseModelRef; exports.resolveRoute = resolveRoute;
@@ -1,18 +1,18 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
2
 
3
- var _chunk7YN22L2Hcjs = require('./chunk-7YN22L2H.cjs');
3
+ var _chunkC72S6TTVcjs = require('./chunk-C72S6TTV.cjs');
4
4
 
5
5
 
6
- var _chunk2DCNB7DFcjs = require('./chunk-2DCNB7DF.cjs');
6
+ var _chunkDWKQZ2SKcjs = require('./chunk-DWKQZ2SK.cjs');
7
7
 
8
8
 
9
- var _chunkC72S6TTVcjs = require('./chunk-C72S6TTV.cjs');
9
+ var _chunk4VAVYUZScjs = require('./chunk-4VAVYUZS.cjs');
10
10
 
11
11
 
12
- var _chunkDWKQZ2SKcjs = require('./chunk-DWKQZ2SK.cjs');
12
+ var _chunk7YN22L2Hcjs = require('./chunk-7YN22L2H.cjs');
13
13
 
14
14
 
15
- var _chunk4VAVYUZScjs = require('./chunk-4VAVYUZS.cjs');
15
+ var _chunk2DCNB7DFcjs = require('./chunk-2DCNB7DF.cjs');
16
16
 
17
17
 
18
18
  var _chunkRSJ3TWJQcjs = require('./chunk-RSJ3TWJQ.cjs');
@@ -1,9 +1,3 @@
1
- import {
2
- GeminiTransformer
3
- } from "./chunk-C7PSERMH.js";
4
- import {
5
- OpenAIResponseTransformer
6
- } from "./chunk-5HTVET6E.js";
7
1
  import {
8
2
  OpenCodeGoTransformer
9
3
  } from "./chunk-Z7LUNECE.js";
@@ -13,6 +7,12 @@ import {
13
7
  import {
14
8
  AnthropicTransformer
15
9
  } from "./chunk-FTQ7IQUC.js";
10
+ import {
11
+ GeminiTransformer
12
+ } from "./chunk-C7PSERMH.js";
13
+ import {
14
+ OpenAIResponseTransformer
15
+ } from "./chunk-5HTVET6E.js";
16
16
  import {
17
17
  GeminiCodeAssistTransformer
18
18
  } from "./chunk-Z7Y2NPHY.js";