@omnicross/core 0.1.0 → 0.1.1

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 (139) hide show
  1. package/dist/ApiConverter.cjs +799 -0
  2. package/dist/ApiConverter.d.cts +82 -0
  3. package/dist/ApiConverter.d.ts +82 -0
  4. package/dist/ApiConverter.js +763 -0
  5. package/dist/BuiltinToolExecutor-BluWyeob.d.ts +81 -0
  6. package/dist/BuiltinToolExecutor-CS2WpXhM.d.cts +81 -0
  7. package/dist/CompletionService-7fCmKAP3.d.ts +212 -0
  8. package/dist/CompletionService-DtOF_War.d.cts +212 -0
  9. package/dist/{ProviderProxy-f_8ziIhW.d.cts → ProviderProxy-C-xqrkKi.d.ts} +7 -2
  10. package/dist/{ProviderProxy-vjt8sQQk.d.ts → ProviderProxy-CnMQYN59.d.cts} +7 -2
  11. package/dist/completion/BuiltinToolExecutor.cjs +327 -0
  12. package/dist/completion/BuiltinToolExecutor.d.cts +4 -0
  13. package/dist/completion/BuiltinToolExecutor.d.ts +4 -0
  14. package/dist/completion/BuiltinToolExecutor.js +296 -0
  15. package/dist/completion/CompletionService.cjs +3487 -0
  16. package/dist/completion/CompletionService.d.cts +21 -0
  17. package/dist/completion/CompletionService.d.ts +21 -0
  18. package/dist/completion/CompletionService.js +3461 -0
  19. package/dist/completion/NativeSearchInjector.cjs +196 -0
  20. package/dist/completion/NativeSearchInjector.d.cts +42 -0
  21. package/dist/completion/NativeSearchInjector.d.ts +42 -0
  22. package/dist/completion/NativeSearchInjector.js +167 -0
  23. package/dist/completion/ProviderSearchInjector.cjs +87 -0
  24. package/dist/completion/ProviderSearchInjector.d.cts +47 -0
  25. package/dist/completion/ProviderSearchInjector.d.ts +47 -0
  26. package/dist/completion/ProviderSearchInjector.js +60 -0
  27. package/dist/completion/native-search-types.cjs +67 -0
  28. package/dist/completion/native-search-types.d.cts +3 -0
  29. package/dist/completion/native-search-types.d.ts +3 -0
  30. package/dist/completion/native-search-types.js +38 -0
  31. package/dist/completion/openrouter-headers.cjs +72 -0
  32. package/dist/completion/openrouter-headers.d.cts +44 -0
  33. package/dist/completion/openrouter-headers.d.ts +44 -0
  34. package/dist/completion/openrouter-headers.js +42 -0
  35. package/dist/completion/openrouter-models.cjs +86 -0
  36. package/dist/completion/openrouter-models.d.cts +27 -0
  37. package/dist/completion/openrouter-models.d.ts +27 -0
  38. package/dist/completion/openrouter-models.js +59 -0
  39. package/dist/completion/types.cjs +18 -0
  40. package/dist/completion/types.d.cts +3 -0
  41. package/dist/completion/types.d.ts +3 -0
  42. package/dist/completion/types.js +0 -0
  43. package/dist/completion/url-builder.cjs +138 -0
  44. package/dist/completion/url-builder.d.cts +87 -0
  45. package/dist/completion/url-builder.d.ts +87 -0
  46. package/dist/completion/url-builder.js +104 -0
  47. package/dist/completion.d.cts +148 -7
  48. package/dist/completion.d.ts +148 -7
  49. package/dist/index.cjs +1 -0
  50. package/dist/index.d.cts +27 -90
  51. package/dist/index.d.ts +27 -90
  52. package/dist/index.js +1 -0
  53. package/dist/outbound-api/routeResolver.cjs +221 -0
  54. package/dist/outbound-api/routeResolver.d.cts +18 -0
  55. package/dist/outbound-api/routeResolver.d.ts +18 -0
  56. package/dist/outbound-api/routeResolver.js +192 -0
  57. package/dist/outbound-api/subscriptionRegistryPort.d.cts +5 -2
  58. package/dist/outbound-api/subscriptionRegistryPort.d.ts +5 -2
  59. package/dist/outbound-api/types.cjs +18 -0
  60. package/dist/{types-CbCN2NQP.d.ts → outbound-api/types.d.cts} +17 -3
  61. package/dist/{types-CGGrKqC_.d.cts → outbound-api/types.d.ts} +17 -3
  62. package/dist/outbound-api/types.js +0 -0
  63. package/dist/outbound-api.cjs +1 -0
  64. package/dist/outbound-api.d.cts +14 -87
  65. package/dist/outbound-api.d.ts +14 -87
  66. package/dist/outbound-api.js +1 -0
  67. package/dist/pipeline/AuthSource.cjs +18 -0
  68. package/dist/pipeline/AuthSource.d.cts +101 -0
  69. package/dist/pipeline/AuthSource.d.ts +101 -0
  70. package/dist/pipeline/AuthSource.js +0 -0
  71. package/dist/pipeline/LlmConfigProviderAuth.cjs +169 -0
  72. package/dist/pipeline/LlmConfigProviderAuth.d.cts +86 -0
  73. package/dist/pipeline/LlmConfigProviderAuth.d.ts +86 -0
  74. package/dist/pipeline/LlmConfigProviderAuth.js +142 -0
  75. package/dist/pipeline/SubscriptionAuthSource.d.cts +165 -3
  76. package/dist/pipeline/SubscriptionAuthSource.d.ts +165 -3
  77. package/dist/pipeline/executeProviderCall.cjs +70 -0
  78. package/dist/pipeline/executeProviderCall.d.cts +149 -0
  79. package/dist/pipeline/executeProviderCall.d.ts +149 -0
  80. package/dist/pipeline/executeProviderCall.js +45 -0
  81. package/dist/pipeline/resolveProviderChain.cjs +47 -0
  82. package/dist/pipeline/resolveProviderChain.d.cts +58 -0
  83. package/dist/pipeline/resolveProviderChain.d.ts +58 -0
  84. package/dist/pipeline/resolveProviderChain.js +22 -0
  85. package/dist/pipeline/resolveSubscriptionChain.cjs +68 -0
  86. package/dist/pipeline/resolveSubscriptionChain.d.cts +68 -0
  87. package/dist/pipeline/resolveSubscriptionChain.d.ts +68 -0
  88. package/dist/pipeline/resolveSubscriptionChain.js +43 -0
  89. package/dist/ports/provider-config-source.cjs +18 -0
  90. package/dist/ports/provider-config-source.d.cts +51 -0
  91. package/dist/ports/provider-config-source.d.ts +51 -0
  92. package/dist/ports/provider-config-source.js +0 -0
  93. package/dist/ports/web-search-backend.cjs +18 -0
  94. package/dist/ports/web-search-backend.d.cts +29 -0
  95. package/dist/ports/web-search-backend.d.ts +29 -0
  96. package/dist/ports/web-search-backend.js +0 -0
  97. package/dist/ports.d.cts +10 -7
  98. package/dist/ports.d.ts +10 -7
  99. package/dist/provider-proxy/ProviderProxy.cjs +4643 -0
  100. package/dist/provider-proxy/ProviderProxy.d.cts +16 -0
  101. package/dist/provider-proxy/ProviderProxy.d.ts +16 -0
  102. package/dist/provider-proxy/ProviderProxy.js +4618 -0
  103. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +5 -2
  104. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +5 -2
  105. package/dist/provider-proxy/types.d.cts +406 -8
  106. package/dist/provider-proxy/types.d.ts +406 -8
  107. package/dist/provider-proxy.cjs +1 -0
  108. package/dist/provider-proxy.d.cts +8 -5
  109. package/dist/provider-proxy.d.ts +8 -5
  110. package/dist/provider-proxy.js +1 -0
  111. package/dist/routeResolver-BrbK6ja9.d.cts +88 -0
  112. package/dist/routeResolver-HE-ZO0fO.d.ts +88 -0
  113. package/dist/transformer/anthropicBetaInject.cjs +51 -0
  114. package/dist/transformer/anthropicBetaInject.d.cts +20 -0
  115. package/dist/transformer/anthropicBetaInject.d.ts +20 -0
  116. package/dist/transformer/anthropicBetaInject.js +25 -0
  117. package/dist/transformer/transformers/AnthropicTransformer.cjs +1017 -0
  118. package/dist/transformer/transformers/AnthropicTransformer.d.cts +148 -0
  119. package/dist/transformer/transformers/AnthropicTransformer.d.ts +148 -0
  120. package/dist/transformer/transformers/AnthropicTransformer.js +990 -0
  121. package/dist/transformer/transformers/ReasoningTransformer.cjs +273 -0
  122. package/dist/transformer/transformers/ReasoningTransformer.d.cts +47 -0
  123. package/dist/transformer/transformers/ReasoningTransformer.d.ts +47 -0
  124. package/dist/transformer/transformers/ReasoningTransformer.js +253 -0
  125. package/dist/transformer/transformers.cjs +3206 -0
  126. package/dist/transformer/transformers.d.cts +100 -0
  127. package/dist/transformer/transformers.d.ts +100 -0
  128. package/dist/transformer/transformers.js +3174 -0
  129. package/dist/transformer.d.cts +8 -31
  130. package/dist/transformer.d.ts +8 -31
  131. package/dist/types-BScIHmPr.d.cts +153 -0
  132. package/dist/types-BScIHmPr.d.ts +153 -0
  133. package/package.json +3 -3
  134. package/dist/SubscriptionAuthSource-Cr4fVEYY.d.cts +0 -264
  135. package/dist/SubscriptionAuthSource-D89zmiSS.d.ts +0 -264
  136. package/dist/index-BTSmc9Sm.d.ts +0 -645
  137. package/dist/index-DXazdTzZ.d.cts +0 -645
  138. package/dist/types-DCzHkhJt.d.ts +0 -467
  139. package/dist/types-DZIQbgp0.d.cts +0 -467
@@ -1,12 +1,410 @@
1
- import 'node:http';
2
- import '@omnicross/contracts/completion-types';
3
- import '@omnicross/contracts/subscription-types';
4
- import '@omnicross/contracts/usage-types';
5
- import '../ApiKeyPoolService-BmMkau07.js';
6
- import '../SubscriptionAuthSource-D89zmiSS.js';
7
- import '../pipeline/SubscriptionAuthStrategy.js';
8
- export { A as AnthropicIngressHandler, b as AnthropicIngressHandlerFactory, c as AnthropicRouteHandlerParams, d as AnthropicSdkHints, E as ExtendedContextHint, I as IngressFormat, a as ProviderProxyDeps, e as ProxyAttribution, R as RetryCallback, f as RouteAuthMode, g as RouteContext, h as StreamEventCallback, S as SubscriptionDispatchProfile, i as SubscriptionRequestSummary, T as TargetProviderFormat, j as UsageRecordImportInput, U as UsageRecorderImport } from '../types-DCzHkhJt.js';
1
+ import http from 'node:http';
2
+ import { ThinkLevel } from '@omnicross/contracts/completion-types';
3
+ import { SubscriptionProviderId, OpenCodeGoTokenConfig, OpenCodeGoScenario, OpenCodeGoModelEntry } from '@omnicross/contracts/subscription-types';
4
+ import { UsageEngineOrigin, UsageTokens } from '@omnicross/contracts/usage-types';
5
+ import { A as ApiKeyPoolService } from '../ApiKeyPoolService-BmMkau07.js';
6
+ import { AuthSource } from '../pipeline/AuthSource.js';
7
+ import { SubscriptionAuthProfile } from '../pipeline/SubscriptionAuthSource.js';
8
+ import { AuthStrategy } from '../pipeline/SubscriptionAuthStrategy.js';
9
+ import { ProviderConfigSource } from '../ports/provider-config-source.js';
10
+ import { WebSearchBackend } from '../ports/web-search-backend.js';
9
11
  import '@omnicross/contracts/llm-config';
10
12
  import '../transformer/types.js';
11
13
  import '../transformer/TransformerService.js';
12
14
  import '@omnicross/contracts/websearch-types';
15
+
16
+ /**
17
+ * Shared contract types for the resident `ProviderProxy`.
18
+ *
19
+ * The `ProviderProxy` (OpenSpec `engine-provider-decouple`, design D0/D3/D7/D9)
20
+ * is the single resident `127.0.0.1` listener that subsumes both of the
21
+ * host's per-session proxies (Anthropic Messages ingress and OpenAI Responses
22
+ * ingress). Per-run state lives in a `Map<token, RouteContext>`
23
+ * minted at run start and reaped at run end / on idle TTL.
24
+ *
25
+ * These types are kept in their own module so the server, route map, router,
26
+ * and the two ingress parsers can share shapes without importing one another
27
+ * for type-only purposes.
28
+ *
29
+ * @module provider-proxy/types
30
+ */
31
+
32
+ /** Callback for retry events (client toast). */
33
+ type RetryCallback = (info: {
34
+ attempt: number;
35
+ maxAttempts: number;
36
+ delayMs: number;
37
+ statusCode: number;
38
+ error?: string;
39
+ }) => void;
40
+ /** Callback for real-time SSE streaming events (content_block_delta, content_block_start, etc.) */
41
+ type StreamEventCallback = (event: Record<string, unknown>) => void;
42
+ /**
43
+ * Routing attribution carried alongside usage records — `messageId` is per-request
44
+ * and unknown at this layer, so only the persistent `sessionId` + `apiKeyId` flow
45
+ * through.
46
+ */
47
+ interface ProxyAttribution {
48
+ sessionId?: string | null;
49
+ apiKeyId?: string | null;
50
+ }
51
+ /**
52
+ * 1M-context opt-in for outbound Anthropic requests. Populated by
53
+ * the host's Claude-SDK engine from the active session's `cliBackend` /
54
+ * `useExtendedContext` schema fields. When `enabled` is true and `model`
55
+ * is in the 1M-capable allowlist, `injectExtendedContextBeta` adds
56
+ * `'context-1m-2025-08-07'` to the request's `anthropic-beta` header
57
+ * before transport.
58
+ */
59
+ interface ExtendedContextHint {
60
+ enabled: boolean;
61
+ model: string;
62
+ }
63
+ /** Lightweight summary derived from the inbound Anthropic request body —
64
+ * consumed by `modelMapper` (scenario routing) without full body access. */
65
+ interface SubscriptionRequestSummary {
66
+ messageCount: number;
67
+ /** cl100k_base-estimated token count of system + messages (no tools). */
68
+ estimatedInputTokens: number;
69
+ /**
70
+ * OPTIONAL bounded per-message text slice (system prompt + the most recent
71
+ * user/system messages, each per-message-capped) consumed ONLY by the
72
+ * OpenCodeGo keyword matcher in `@omnicross/subscriptions`
73
+ * (`resolveOpenCodeGoScenario`). Core only WRITES this `string[]`; it never
74
+ * reads it and never names the matcher — keeping the cross-layer litmus at 0
75
+ * (no `@omnicross/core` → `@omnicross/subscriptions` edge). Optional so callers
76
+ * that omit it (legacy/tests) compile and degrade to the token-threshold +
77
+ * `default` routing.
78
+ */
79
+ matchText?: string[];
80
+ }
81
+ interface SubscriptionDispatchProfile {
82
+ readonly providerId: SubscriptionProviderId;
83
+ readonly displayName: string;
84
+ readonly authStrategy: AuthStrategy;
85
+ /** Pass-through providers (Claude) skip the transformer chain entirely.
86
+ * Transformer providers use the chain below + the proxy's existing
87
+ * `AnthropicTransformer` endpoint reverse-decoder. */
88
+ readonly mode: 'pass-through' | 'transformer';
89
+ /** Resolve the upstream URL for a given resolved model id. Required for
90
+ * `mode === 'transformer'`; unused for pass-through (proxy hard-codes
91
+ * `api.anthropic.com`). The OPTIONAL 2nd `config` arg lets the opencodego
92
+ * profile honor a per-account `baseUrl` override (D1) — additive, so existing
93
+ * one-arg callers compile unchanged. */
94
+ readonly resolveUpstreamUrl?: (resolvedModel: string, config?: OpenCodeGoTokenConfig) => string;
95
+ /** Names of transformers (registered in `TransformerService`) to run on the
96
+ * provider chain. The proxy adds `AnthropicTransformer` as the endpoint
97
+ * reverse-decoder. */
98
+ readonly providerTransformerNames?: readonly string[];
99
+ readonly modelTransformerNames?: readonly string[];
100
+ /**
101
+ * OPTIONAL shape-aware provider transformer-name resolver (opencodego zen).
102
+ * Parallel to `resolveUpstreamUrl(model, config)`: lets a profile vary its
103
+ * provider chain by the RESOLVED model's wire shape (e.g. zen `responses` ⇒
104
+ * `['openai-response']`, `gemini` ⇒ `['gemini']`). `config` is `unknown` on the
105
+ * core side (opaque-config discipline — core never names
106
+ * `OpenCodeGoTokenConfig` from `@omnicross/subscriptions`); the subscriptions
107
+ * implementation narrows it. When ABSENT, both ingress paths fall back to the
108
+ * static `providerTransformerNames` — BYTE-IDENTICAL for claude / codex / gemini
109
+ * (which leave this unset). Purely additive (optional).
110
+ */
111
+ readonly resolveProviderTransformerNames?: (model: string, config?: unknown) => readonly string[];
112
+ /** Optional model placeholder rewriter — only set for OpenCodeGo. */
113
+ readonly modelMapper?: (sdkModel: string, summary: SubscriptionRequestSummary, config: OpenCodeGoTokenConfig | undefined) => {
114
+ resolvedModel: string;
115
+ scenario: OpenCodeGoScenario;
116
+ };
117
+ /** Optional fallback resolver — for OpenCodeGo, picks the next model after
118
+ * an unrecoverable error. Returns `null` when exhausted. Cap = 3. The
119
+ * opencodego implementation ALSO consults the circuit breaker (D5): it skips
120
+ * models whose circuit is open. */
121
+ readonly nextFallback?: (scenario: OpenCodeGoScenario, attempted: readonly string[], config: OpenCodeGoTokenConfig | undefined) => OpenCodeGoModelEntry | null;
122
+ /** Optional circuit-breaker admission gate for the PRIMARY (mapped) model
123
+ * (D5 primary-gating). Only set for OpenCodeGo. Returns whether `modelId`'s
124
+ * circuit currently admits a request (side-effecting: flips an `open` model
125
+ * to `half-open` once its window elapses, exactly like `nextFallback`'s
126
+ * internal consult). `nextFallback` covers the FALLBACKS; this covers the
127
+ * primary the loop already holds. Absent/undefined ⇒ the loop treats the
128
+ * primary as always admitted (claude / codex / gemini have no breaker). */
129
+ readonly allowModel?: (modelId: string) => boolean;
130
+ /** Optional record-outcome callback (D5 record seam). Only set for OpenCodeGo.
131
+ * Both fallback loops invoke it after each attempt: `ok: true` on a `2xx`,
132
+ * `ok: false` on a thrown/network error / `5xx` / `429`; a non-429 `4xx` is
133
+ * NEUTRAL and the loops MUST NOT call it. Drives the per-model breaker.
134
+ * Absent/undefined for claude / codex / gemini ⇒ a no-op (no breaker). */
135
+ readonly recordModelOutcome?: (modelId: string, ok: boolean) => void;
136
+ }
137
+ /** The single-entry handler the Anthropic ingress drives per request. */
138
+ interface AnthropicIngressHandler {
139
+ handle(req: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
140
+ }
141
+ /**
142
+ * Per-run inputs the resident proxy threads into the ingress handler factory.
143
+ * Structural mirror of the host's `RouteHandlerParams` — kept here so the
144
+ * ingress + `ProviderProxyDeps` do not import upward. The host's
145
+ * `RouteHandlerParams` re-exports / aligns to this shape (so its
146
+ * request-handler factory is assignable to the factory type below).
147
+ */
148
+ interface AnthropicRouteHandlerParams {
149
+ readonly llmConfig: ProviderConfigSource;
150
+ readonly providerId: string;
151
+ readonly model: string;
152
+ readonly apiKey: string;
153
+ readonly backgroundTaskModel?: string;
154
+ readonly isOfficialProvider: boolean;
155
+ readonly thinkingLevel?: ThinkLevel;
156
+ readonly extendedContext?: ExtendedContextHint | null;
157
+ readonly passThrough: boolean;
158
+ /** Upstream Bearer for the pass-through path (resident-proxy route token swap). */
159
+ readonly passThroughAuthToken?: string | null;
160
+ /** Lazy per-request resolver for the pass-through Bearer (takes precedence over the static one). */
161
+ readonly resolvePassThroughAuthToken?: (() => Promise<string | null>) | null;
162
+ readonly subscriptionProfile?: SubscriptionDispatchProfile | null;
163
+ readonly maxConcurrency?: number;
164
+ /** Instance-level web-search backend; falls back to the proxy-global one. */
165
+ readonly webSearchService?: WebSearchBackend | null;
166
+ readonly onRetry?: RetryCallback;
167
+ readonly onStreamEvent?: StreamEventCallback;
168
+ readonly usageRecorder?: UsageRecorderImport | null;
169
+ readonly attribution?: ProxyAttribution | null;
170
+ }
171
+ /** Factory that builds a per-request Anthropic ingress handler. */
172
+ type AnthropicIngressHandlerFactory = (params: AnthropicRouteHandlerParams) => AnthropicIngressHandler;
173
+ /**
174
+ * Wire format the proxy ingests for a given route. Phase 1 landed the two
175
+ * already-sound parsers (`anthropic-messages`, `openai-responses`);
176
+ * `provider-proxy-transformer-matrix` adds `openai-chat` (qwen / copilot /
177
+ * opencode) and `gemini-generatecontent` (gemini-CLI api-key/relay) — completing
178
+ * the resident proxy's 4-ingress-parser matrix.
179
+ */
180
+ type IngressFormat = 'anthropic-messages' | 'openai-responses' | 'openai-chat' | 'gemini-generatecontent';
181
+ /**
182
+ * The target Provider's wire format. The proxy's internal pass-through-vs-
183
+ * transform decision is keyed on `(ingressFormat, targetProviderFormat)`:
184
+ * when they MATCH the request is passed through + re-authed; otherwise it is
185
+ * transformed through the Unified chain (design D3).
186
+ *
187
+ * NOTE: `'anthropic'` here is the FORMAT family, not a provider id. An official
188
+ * or third-party Anthropic Messages provider is `'anthropic'`; an
189
+ * OpenAI-compatible / Responses provider is `'openai-responses'`.
190
+ */
191
+ type TargetProviderFormat = 'anthropic' | 'openai-responses' | 'transform';
192
+ /**
193
+ * How the proxy re-authenticates a route upstream. `'byo'` resolves the key
194
+ * from an LLM-config provider row (with optional `ApiKeyPool` failover);
195
+ * `'subscription'` re-auths via a subscription `AuthStrategy` (OAuth bearer +
196
+ * 401 refresh). The forwarded route-token sentinel is ALWAYS discarded — the
197
+ * proxy never trusts the CLI/SDK-carried key.
198
+ */
199
+ type RouteAuthMode = 'byo' | 'subscription';
200
+ /**
201
+ * The Anthropic SDK-hint bundle carried on a `RouteContext` for routes whose
202
+ * ingress is `'anthropic-messages'`. The Anthropic path is NOT re-implemented
203
+ * inside the resident proxy — it is DELEGATED wholesale to the host's existing
204
+ * per-request proxy handler (engine-provider-decouple task 2.10, "delegate for
205
+ * parity"). That handler keeps owning its own upstream fetch + all the SDK
206
+ * quirks (probe-mock, local web-search interception, thinkingLevel / 1M-context
207
+ * beta injection, subscription dispatch, and the 5h/7d window header taps) — so
208
+ * everything the host proxy used to receive per session is threaded here per
209
+ * run and fed straight into the per-request handler factory.
210
+ *
211
+ * D7 conversion-SSOT is ALREADY MET: the delegated host handler runs
212
+ * its Anthropic⇄Unified⇄provider conversion through the SAME shared pipeline
213
+ * SSOT (`executeProviderCall` + `AnthropicTransformer`) that the Responses /
214
+ * OpenAI-Chat / Gemini ingresses use — there is no second conversion stack. The
215
+ * SDK quirks listed above (probe / web-search / thinking / window-tap) are
216
+ * INGRESS concerns and deliberately stay at the ingress under the design's
217
+ * ingress-vs-core split; they are NOT folded into the shared core.
218
+ */
219
+ interface AnthropicSdkHints {
220
+ /** Real provider key (resolved at run start) for `getProviderHeaders`. */
221
+ readonly apiKey: string;
222
+ /** Official-Anthropic provider → skip probe caching + transformer pipeline. */
223
+ readonly isOfficialProvider: boolean;
224
+ /** claude-code OAuth pass-through (forward to api.anthropic.com verbatim). */
225
+ readonly passThrough: boolean;
226
+ /**
227
+ * Host-managed OAuth Bearer token for the pass-through path. With the
228
+ * resident proxy the SDK forwards the route TOKEN as its `Authorization`
229
+ * header (used only for route lookup, then discarded), so the real upstream
230
+ * Bearer can no longer ride the SDK header — it is carried here and
231
+ * re-applied by the pass-through forwarder. `null`/absent → fall back to the
232
+ * SDK's own forwarded credential (system `~/.claude/.credentials.json`).
233
+ */
234
+ readonly passThroughAuthToken?: string | null;
235
+ /**
236
+ * OPTIONAL lazy resolver for the pass-through upstream Bearer, evaluated at
237
+ * REQUEST time rather than route-build time. When present it takes precedence
238
+ * over the static `passThroughAuthToken`, so a long-lived route always forwards
239
+ * a freshly auto-refreshed token (the host re-reads its OAuth store / system
240
+ * credentials per request) instead of the one captured when the route was
241
+ * built — that capture is what makes a session outlive its token and 401
242
+ * mid-run. Returns `null` (or throws) to fall back to the static token.
243
+ */
244
+ readonly resolvePassThroughAuthToken?: (() => Promise<string | null>) | null;
245
+ /** User thinking-budget preference (Anthropic-direct + reasoning chain). */
246
+ readonly thinkingLevel?: ThinkLevel;
247
+ /** 1M-context opt-in (injects `context-1m-2025-08-07` into anthropic_beta). */
248
+ readonly extendedContext?: ExtendedContextHint | null;
249
+ /** Subscription dispatch profile (Codex/Gemini/OpenCodeGo over the SDK wire). */
250
+ readonly subscriptionProfile?: SubscriptionDispatchProfile | null;
251
+ /** Per-request max-concurrency cap for the error-handler semaphore. */
252
+ readonly maxConcurrency?: number;
253
+ /** Instance-level web-search backend (falls back to the proxy-global one). */
254
+ readonly webSearchService?: WebSearchBackend | null;
255
+ /** Retry-event callback (client toast). */
256
+ readonly onRetry?: RetryCallback;
257
+ /** Real-time SSE event callback (client live-display). */
258
+ readonly onStreamEvent?: StreamEventCallback;
259
+ /** Usage attribution (sessionId + apiKeyId) for recorded usage rows. */
260
+ readonly attribution?: ProxyAttribution | null;
261
+ /**
262
+ * The usage recorder (`UsageRecorderImport` port) for the delegated
263
+ * stream-manager taps (stream + non-stream + 5h/7d window). Per-run
264
+ * because `buildProviderEnvWithProxy` resolves it from the explicit arg ??
265
+ * the module-level recorder, exactly as the host proxy received it. The
266
+ * host injects its concrete usage-recorder service, which satisfies the port.
267
+ */
268
+ readonly usageRecorder?: UsageRecorderImport | null;
269
+ }
270
+ /**
271
+ * Per-run routing context, looked up by the crypto route token carried in the
272
+ * forwarded `Authorization` sentinel. Shaped to exactly what the pipeline call
273
+ * (`executeProviderCall` + the `endpointTransformer` seam) needs to re-auth and
274
+ * route a single run's traffic. There is NO fallback: a token miss or an
275
+ * expired entry is rejected (design D9).
276
+ */
277
+ interface RouteContext {
278
+ /** Owning chat session id — usage attribution + ApiKeyPool affinity. */
279
+ readonly sessionId: string | null;
280
+ /**
281
+ * Target Provider's wire format. Drives the internal pass-through-vs-transform
282
+ * decision against the route's `ingressFormat`.
283
+ */
284
+ readonly targetProviderFormat: TargetProviderFormat;
285
+ /** Resolved provider model the upstream request targets. */
286
+ readonly model: string;
287
+ /** Wire format this route's ingress decodes. */
288
+ readonly ingressFormat: IngressFormat;
289
+ /** Re-auth mode (BYO key vs subscription OAuth). */
290
+ readonly authMode: RouteAuthMode;
291
+ /**
292
+ * LLM-config provider row id whose key/headers authenticate a BYO call.
293
+ * Required for `authMode === 'byo'`; ignored for subscription routes.
294
+ */
295
+ readonly providerId?: string;
296
+ /**
297
+ * Background-task model (the SDK's haiku probes map to this). Optional —
298
+ * falls back to `model` when omitted. Anthropic ingress quirk only.
299
+ */
300
+ readonly backgroundTaskModel?: string;
301
+ /**
302
+ * Pre-built `AuthSource` for this route, when the caller resolved it at run
303
+ * start (subscription routes supply this). When omitted for BYO routes the
304
+ * proxy builds an `LlmConfigProviderAuth` from `providerId` at request time.
305
+ */
306
+ readonly auth?: AuthSource;
307
+ /**
308
+ * Subscription profile (structural `SubscriptionAuthProfile` subset — the
309
+ * registry's full `SubscriptionDispatchProfile` satisfies it). REQUIRED when
310
+ * `authMode === 'subscription'`. The route resolver populates it for BOTH the
311
+ * OpenAI-Responses ingress and the built-in (factory-absent) Anthropic
312
+ * `/v1/messages` ingress (RT2.1). The Responses ingress consumes only
313
+ * `authStrategy` / `resolveUpstreamUrl` / `providerTransformerNames`; the
314
+ * built-in messages subscription path additionally reads the OPTIONAL `mode`
315
+ * + `modelMapper` fields (present on the registry profile passed here). The
316
+ * factory-present Anthropic delegation carries its OWN profile inside
317
+ * `anthropicSdkHints.subscriptionProfile` and ignores this field.
318
+ */
319
+ readonly subscriptionProfile?: SubscriptionAuthProfile | null;
320
+ /**
321
+ * OPAQUE per-account subscription config (opencodego-only). Populated by the
322
+ * route resolver from the subscription registry's `getOpenCodeGoConfig()`
323
+ * getter; passed BACK INTO the profile closures (`modelMapper` /
324
+ * `nextFallback` / `resolveUpstreamUrl`) by the built-in (factory-absent)
325
+ * `/v1/messages` plan builder so user `baseUrl` / `modelMap` / `fallbacks`
326
+ * overrides apply on that path.
327
+ *
328
+ * Typed `unknown` ON PURPOSE: core MUST NOT name the concrete
329
+ * `OpenCodeGoTokenConfig` type from `@omnicross/subscriptions` (cross-layer
330
+ * litmus = 0). The plan builder narrows it to the contract type
331
+ * (`@omnicross/contracts`) at the single profile-call boundary.
332
+ *
333
+ * INERT when an Anthropic ingress factory is injected (the built-in plan
334
+ * builder is then unreachable) and for non-opencodego routes (claude /
335
+ * codex / gemini leave it `undefined`).
336
+ */
337
+ readonly subscriptionConfig?: unknown;
338
+ /**
339
+ * The Anthropic SDK-hint bundle. REQUIRED when
340
+ * `ingressFormat === 'anthropic-messages'` (the resident proxy delegates that
341
+ * ingress to the host's existing per-request handler, which needs the full bundle).
342
+ * Ignored for the OpenAI Responses ingress.
343
+ */
344
+ readonly anthropicSdkHints?: AnthropicSdkHints | null;
345
+ }
346
+ /**
347
+ * App-session-scoped dependencies the resident proxy needs to service ALL
348
+ * routes. Unlike the per-run proxies these are wired ONCE at startup; per-run
349
+ * state lives in the route map.
350
+ */
351
+ interface ProviderProxyDeps {
352
+ readonly llmConfig: ProviderConfigSource;
353
+ /**
354
+ * Session-affine key selection + 429/529/401/403 failover. Centralized here
355
+ * (task 2.8) so the next-batch cutover removes the per-proxy taps. Optional —
356
+ * BYO single-key routes work without it.
357
+ */
358
+ readonly apiKeyPool?: ApiKeyPoolService | null;
359
+ /**
360
+ * The single usage tap (task 2.8). When set, both ingress relays
361
+ * record their non-stream usage through it. Optional.
362
+ */
363
+ readonly usageRecorder?: UsageRecorderImport | null;
364
+ /**
365
+ * Factory for the per-request Anthropic `/v1/messages` ingress handler
366
+ * (E1 de-inversion). The ingress builds its delegated request handler
367
+ * through THIS injected factory instead of importing the host's factory
368
+ * directly. Bootstrap supplies the host implementation.
369
+ *
370
+ * Optional so unit-test constructors that never drive the Anthropic ingress
371
+ * (env-wiring smoke, pool failover, etc.) compile unchanged; when a route
372
+ * with `ingressFormat: 'anthropic-messages'` IS served without it wired, the
373
+ * ingress responds 502 (the factory is a hard dependency of THAT path only).
374
+ */
375
+ readonly anthropicIngressHandlerFactory?: AnthropicIngressHandlerFactory | null;
376
+ }
377
+ /**
378
+ * Structural port for the usage recorder — only the `record` method.
379
+ *
380
+ * Kept structural so the serving core does not depend on the host's concrete
381
+ * usage-recorder class. The host injects that concrete service at
382
+ * bootstrap; it satisfies this port. Both the proxy taps (narrow literal-null
383
+ * payloads) and the CompletionService / TransformerHandler completion path
384
+ * (rich payloads with `messageId` / `apiKeyId` / `'completion'` origin) call
385
+ * through this single `record()`, so the accepted input is the full structural
386
+ * mirror of the host's `UsageRecordInput`.
387
+ */
388
+ interface UsageRecorderImport {
389
+ record(input: UsageRecordImportInput): void;
390
+ }
391
+ /**
392
+ * The usage payload accepted by the recorder port — structural mirror of the
393
+ * host's `UsageRecordInput` (type-only; no host import). Covers both the proxy
394
+ * taps and the completion path.
395
+ */
396
+ interface UsageRecordImportInput {
397
+ messageId?: string | null;
398
+ parentMessageId?: string | null;
399
+ sessionId?: string | null;
400
+ providerId: string;
401
+ model: string;
402
+ apiKeyId?: string | null;
403
+ engineOrigin: UsageEngineOrigin;
404
+ usage: UsageTokens;
405
+ rawUsage?: unknown;
406
+ runId?: string | null;
407
+ eventId?: string | null;
408
+ }
409
+
410
+ export type { AnthropicIngressHandler, AnthropicIngressHandlerFactory, AnthropicRouteHandlerParams, AnthropicSdkHints, ExtendedContextHint, IngressFormat, ProviderProxyDeps, ProxyAttribution, RetryCallback, RouteAuthMode, RouteContext, StreamEventCallback, SubscriptionDispatchProfile, SubscriptionRequestSummary, TargetProviderFormat, UsageRecordImportInput, UsageRecorderImport };
@@ -3912,6 +3912,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
3912
3912
  extendedContext: hints.extendedContext ?? null,
3913
3913
  passThrough: hints.passThrough,
3914
3914
  passThroughAuthToken: hints.passThroughAuthToken ?? null,
3915
+ resolvePassThroughAuthToken: hints.resolvePassThroughAuthToken ?? null,
3915
3916
  subscriptionProfile: hints.subscriptionProfile ?? null,
3916
3917
  maxConcurrency: hints.maxConcurrency,
3917
3918
  webSearchService: hints.webSearchService ?? null,
@@ -1,17 +1,20 @@
1
- import { P as ProviderProxy } from './ProviderProxy-f_8ziIhW.cjs';
2
- export { D as DEFAULT_ROUTE_IDLE_MS, a as ProviderProxyRouteMap } from './ProviderProxy-f_8ziIhW.cjs';
3
- import { a as ProviderProxyDeps } from './types-DZIQbgp0.cjs';
4
- export { A as AnthropicIngressHandler, b as AnthropicIngressHandlerFactory, c as AnthropicRouteHandlerParams, d as AnthropicSdkHints, E as ExtendedContextHint, I as IngressFormat, e as ProxyAttribution, R as RetryCallback, f as RouteAuthMode, g as RouteContext, h as StreamEventCallback, S as SubscriptionDispatchProfile, i as SubscriptionRequestSummary, T as TargetProviderFormat } from './types-DZIQbgp0.cjs';
1
+ import { P as ProviderProxy } from './ProviderProxy-CnMQYN59.cjs';
2
+ export { D as DEFAULT_ROUTE_IDLE_MS, a as ProviderProxyRouteMap } from './ProviderProxy-CnMQYN59.cjs';
3
+ import { ProviderProxyDeps } from './provider-proxy/types.cjs';
4
+ export { AnthropicIngressHandler, AnthropicIngressHandlerFactory, AnthropicRouteHandlerParams, AnthropicSdkHints, ExtendedContextHint, IngressFormat, ProxyAttribution, RetryCallback, RouteAuthMode, RouteContext, StreamEventCallback, SubscriptionDispatchProfile, SubscriptionRequestSummary, TargetProviderFormat } from './provider-proxy/types.cjs';
5
5
  import 'node:http';
6
6
  import '@omnicross/contracts/completion-types';
7
7
  import '@omnicross/contracts/subscription-types';
8
8
  import '@omnicross/contracts/usage-types';
9
9
  import './ApiKeyPoolService-BmMkau07.cjs';
10
10
  import '@omnicross/contracts/llm-config';
11
- import './SubscriptionAuthSource-Cr4fVEYY.cjs';
11
+ import './pipeline/AuthSource.cjs';
12
+ import './pipeline/SubscriptionAuthSource.cjs';
12
13
  import './pipeline/SubscriptionAuthStrategy.cjs';
14
+ import './ports/provider-config-source.cjs';
13
15
  import './transformer/types.cjs';
14
16
  import './transformer/TransformerService.cjs';
17
+ import './ports/web-search-backend.cjs';
15
18
  import '@omnicross/contracts/websearch-types';
16
19
 
17
20
  /**
@@ -1,17 +1,20 @@
1
- import { P as ProviderProxy } from './ProviderProxy-vjt8sQQk.js';
2
- export { D as DEFAULT_ROUTE_IDLE_MS, a as ProviderProxyRouteMap } from './ProviderProxy-vjt8sQQk.js';
3
- import { a as ProviderProxyDeps } from './types-DCzHkhJt.js';
4
- export { A as AnthropicIngressHandler, b as AnthropicIngressHandlerFactory, c as AnthropicRouteHandlerParams, d as AnthropicSdkHints, E as ExtendedContextHint, I as IngressFormat, e as ProxyAttribution, R as RetryCallback, f as RouteAuthMode, g as RouteContext, h as StreamEventCallback, S as SubscriptionDispatchProfile, i as SubscriptionRequestSummary, T as TargetProviderFormat } from './types-DCzHkhJt.js';
1
+ import { P as ProviderProxy } from './ProviderProxy-C-xqrkKi.js';
2
+ export { D as DEFAULT_ROUTE_IDLE_MS, a as ProviderProxyRouteMap } from './ProviderProxy-C-xqrkKi.js';
3
+ import { ProviderProxyDeps } from './provider-proxy/types.js';
4
+ export { AnthropicIngressHandler, AnthropicIngressHandlerFactory, AnthropicRouteHandlerParams, AnthropicSdkHints, ExtendedContextHint, IngressFormat, ProxyAttribution, RetryCallback, RouteAuthMode, RouteContext, StreamEventCallback, SubscriptionDispatchProfile, SubscriptionRequestSummary, TargetProviderFormat } from './provider-proxy/types.js';
5
5
  import 'node:http';
6
6
  import '@omnicross/contracts/completion-types';
7
7
  import '@omnicross/contracts/subscription-types';
8
8
  import '@omnicross/contracts/usage-types';
9
9
  import './ApiKeyPoolService-BmMkau07.js';
10
10
  import '@omnicross/contracts/llm-config';
11
- import './SubscriptionAuthSource-D89zmiSS.js';
11
+ import './pipeline/AuthSource.js';
12
+ import './pipeline/SubscriptionAuthSource.js';
12
13
  import './pipeline/SubscriptionAuthStrategy.js';
14
+ import './ports/provider-config-source.js';
13
15
  import './transformer/types.js';
14
16
  import './transformer/TransformerService.js';
17
+ import './ports/web-search-backend.js';
15
18
  import '@omnicross/contracts/websearch-types';
16
19
 
17
20
  /**
@@ -3882,6 +3882,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
3882
3882
  extendedContext: hints.extendedContext ?? null,
3883
3883
  passThrough: hints.passThrough,
3884
3884
  passThroughAuthToken: hints.passThroughAuthToken ?? null,
3885
+ resolvePassThroughAuthToken: hints.resolvePassThroughAuthToken ?? null,
3885
3886
  subscriptionProfile: hints.subscriptionProfile ?? null,
3886
3887
  maxConcurrency: hints.maxConcurrency,
3887
3888
  webSearchService: hints.webSearchService ?? null,
@@ -0,0 +1,88 @@
1
+ import { ProviderConfigSource } from './ports/provider-config-source.cjs';
2
+ import { IngressFormat, RouteContext } from './provider-proxy/types.cjs';
3
+ import { OutboundEndpoint, EndpointRoutingConfig, RequestRole } from './outbound-api/types.cjs';
4
+ import { SubscriptionProviderId } from '@omnicross/contracts/subscription-types';
5
+
6
+ /**
7
+ * subscriptionSupport — single source of truth for (a) which provider ids are
8
+ * subscription-backed and (b) which outbound endpoints can soundly serve a
9
+ * subscription route (`outbound-api-server`, design D2 + review M1/m1).
10
+ *
11
+ * The subscription-id catalog mirrors `SubscriptionProviderRegistry`'s ids; the
12
+ * static fast-path is backstopped at runtime by a live registry lookup (see
13
+ * `isSubscriptionProviderId`) so it degrades gracefully if it drifts. Both
14
+ * `routeResolver` and `apiServerHandlers` import from here — no duplicated set.
15
+ *
16
+ * @module outbound-api/subscriptionSupport
17
+ */
18
+
19
+ /**
20
+ * The registry-aligned subscription provider ids — the outbound layer's SSOT
21
+ * fast-path. NOTE: `SubscriptionProviderId` is currently a `z.string()` alias,
22
+ * so this `readonly SubscriptionProviderId[]` typing does NOT compile-enforce
23
+ * alignment with the registry; drift is instead tolerated at runtime by
24
+ * `isSubscriptionProviderId`'s live `registry.getProfile` fallback.
25
+ */
26
+ declare const SUBSCRIPTION_PROVIDER_IDS: readonly SubscriptionProviderId[];
27
+ /**
28
+ * True when a provider id refers to a subscription-backed provider. Checks the
29
+ * registry-aligned static catalog first, then falls back to a live registry
30
+ * lookup (so a registry addition is honored even before this list is updated).
31
+ *
32
+ * NOTE (review m2): this classifies by id string. The resolver MUST confirm the
33
+ * id does not resolve to a real BYO provider row before treating it as
34
+ * subscription-backed — see `routeResolver` (BYO rows win).
35
+ */
36
+ declare function isSubscriptionProviderId(providerId: string): boolean;
37
+ /** True when the endpoint's ingress can soundly serve a subscription route. */
38
+ declare function endpointSupportsSubscription(endpoint: OutboundEndpoint): boolean;
39
+
40
+ /**
41
+ * routeResolver — turn an endpoint's `EndpointRoutingConfig` + the detected
42
+ * request role into a `RouteContext` for the shared `provider-proxy` dispatch
43
+ * (`outbound-api-server`, design D2).
44
+ *
45
+ * Steps:
46
+ * 1. Pick the model for the role (vision → default fallback when `visionModel`
47
+ * is unset; vision is optional).
48
+ * 2. Parse the chosen `"providerId,modelId"` ref.
49
+ * 3. Gate by `useSubscription`: OFF → only BYO-key providers are eligible
50
+ * (subscription-backed providers excluded); ON → subscription-backed
51
+ * providers are eligible.
52
+ * 4. Resolve the provider (BYO via the `ProviderConfigSource`; subscription via the
53
+ * subscription registry) and build the `RouteContext` exactly as the
54
+ * internal callers do.
55
+ * 5. Return a clear `503`-style error when the role's required model is unset,
56
+ * the provider is unavailable, or the subscription gate excludes it.
57
+ *
58
+ * @module outbound-api/routeResolver
59
+ */
60
+
61
+ /** A 503-style resolution failure. */
62
+ interface RouteResolveError {
63
+ status: number;
64
+ message: string;
65
+ }
66
+ type RouteResolveResult = {
67
+ ok: true;
68
+ route: RouteContext;
69
+ usedRole: RequestRole;
70
+ } | {
71
+ ok: false;
72
+ error: RouteResolveError;
73
+ };
74
+ /** Parse a `"providerId,modelId"` ref. Returns null on a malformed/empty ref. */
75
+ declare function parseModelRef(ref: string | undefined): {
76
+ providerId: string;
77
+ modelId: string;
78
+ } | null;
79
+ /** Resolve a route for one authenticated outbound request. */
80
+ declare function resolveRoute(args: {
81
+ config: EndpointRoutingConfig;
82
+ role: RequestRole;
83
+ ingressFormat: IngressFormat;
84
+ llmConfig: ProviderConfigSource;
85
+ sessionId?: string | null;
86
+ }): Promise<RouteResolveResult>;
87
+
88
+ export { type RouteResolveError as R, SUBSCRIPTION_PROVIDER_IDS as S, type RouteResolveResult as a, endpointSupportsSubscription as e, isSubscriptionProviderId as i, parseModelRef as p, resolveRoute as r };