@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.
- package/dist/ApiConverter.cjs +799 -0
- package/dist/ApiConverter.d.cts +82 -0
- package/dist/ApiConverter.d.ts +82 -0
- package/dist/ApiConverter.js +763 -0
- package/dist/BuiltinToolExecutor-BluWyeob.d.ts +81 -0
- package/dist/BuiltinToolExecutor-CS2WpXhM.d.cts +81 -0
- package/dist/CompletionService-7fCmKAP3.d.ts +212 -0
- package/dist/CompletionService-DtOF_War.d.cts +212 -0
- package/dist/{ProviderProxy-f_8ziIhW.d.cts → ProviderProxy-C-xqrkKi.d.ts} +7 -2
- package/dist/{ProviderProxy-vjt8sQQk.d.ts → ProviderProxy-CnMQYN59.d.cts} +7 -2
- package/dist/completion/BuiltinToolExecutor.cjs +327 -0
- package/dist/completion/BuiltinToolExecutor.d.cts +4 -0
- package/dist/completion/BuiltinToolExecutor.d.ts +4 -0
- package/dist/completion/BuiltinToolExecutor.js +296 -0
- package/dist/completion/CompletionService.cjs +3487 -0
- package/dist/completion/CompletionService.d.cts +21 -0
- package/dist/completion/CompletionService.d.ts +21 -0
- package/dist/completion/CompletionService.js +3461 -0
- package/dist/completion/NativeSearchInjector.cjs +196 -0
- package/dist/completion/NativeSearchInjector.d.cts +42 -0
- package/dist/completion/NativeSearchInjector.d.ts +42 -0
- package/dist/completion/NativeSearchInjector.js +167 -0
- package/dist/completion/ProviderSearchInjector.cjs +87 -0
- package/dist/completion/ProviderSearchInjector.d.cts +47 -0
- package/dist/completion/ProviderSearchInjector.d.ts +47 -0
- package/dist/completion/ProviderSearchInjector.js +60 -0
- package/dist/completion/native-search-types.cjs +67 -0
- package/dist/completion/native-search-types.d.cts +3 -0
- package/dist/completion/native-search-types.d.ts +3 -0
- package/dist/completion/native-search-types.js +38 -0
- package/dist/completion/openrouter-headers.cjs +72 -0
- package/dist/completion/openrouter-headers.d.cts +44 -0
- package/dist/completion/openrouter-headers.d.ts +44 -0
- package/dist/completion/openrouter-headers.js +42 -0
- package/dist/completion/openrouter-models.cjs +86 -0
- package/dist/completion/openrouter-models.d.cts +27 -0
- package/dist/completion/openrouter-models.d.ts +27 -0
- package/dist/completion/openrouter-models.js +59 -0
- package/dist/completion/types.cjs +18 -0
- package/dist/completion/types.d.cts +3 -0
- package/dist/completion/types.d.ts +3 -0
- package/dist/completion/types.js +0 -0
- package/dist/completion/url-builder.cjs +138 -0
- package/dist/completion/url-builder.d.cts +87 -0
- package/dist/completion/url-builder.d.ts +87 -0
- package/dist/completion/url-builder.js +104 -0
- package/dist/completion.d.cts +148 -7
- package/dist/completion.d.ts +148 -7
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +27 -90
- package/dist/index.d.ts +27 -90
- package/dist/index.js +1 -0
- package/dist/outbound-api/routeResolver.cjs +221 -0
- package/dist/outbound-api/routeResolver.d.cts +18 -0
- package/dist/outbound-api/routeResolver.d.ts +18 -0
- package/dist/outbound-api/routeResolver.js +192 -0
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +5 -2
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +5 -2
- package/dist/outbound-api/types.cjs +18 -0
- package/dist/{types-CbCN2NQP.d.ts → outbound-api/types.d.cts} +17 -3
- package/dist/{types-CGGrKqC_.d.cts → outbound-api/types.d.ts} +17 -3
- package/dist/outbound-api/types.js +0 -0
- package/dist/outbound-api.cjs +1 -0
- package/dist/outbound-api.d.cts +14 -87
- package/dist/outbound-api.d.ts +14 -87
- package/dist/outbound-api.js +1 -0
- package/dist/pipeline/AuthSource.cjs +18 -0
- package/dist/pipeline/AuthSource.d.cts +101 -0
- package/dist/pipeline/AuthSource.d.ts +101 -0
- package/dist/pipeline/AuthSource.js +0 -0
- package/dist/pipeline/LlmConfigProviderAuth.cjs +169 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.cts +86 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.ts +86 -0
- package/dist/pipeline/LlmConfigProviderAuth.js +142 -0
- package/dist/pipeline/SubscriptionAuthSource.d.cts +165 -3
- package/dist/pipeline/SubscriptionAuthSource.d.ts +165 -3
- package/dist/pipeline/executeProviderCall.cjs +70 -0
- package/dist/pipeline/executeProviderCall.d.cts +149 -0
- package/dist/pipeline/executeProviderCall.d.ts +149 -0
- package/dist/pipeline/executeProviderCall.js +45 -0
- package/dist/pipeline/resolveProviderChain.cjs +47 -0
- package/dist/pipeline/resolveProviderChain.d.cts +58 -0
- package/dist/pipeline/resolveProviderChain.d.ts +58 -0
- package/dist/pipeline/resolveProviderChain.js +22 -0
- package/dist/pipeline/resolveSubscriptionChain.cjs +68 -0
- package/dist/pipeline/resolveSubscriptionChain.d.cts +68 -0
- package/dist/pipeline/resolveSubscriptionChain.d.ts +68 -0
- package/dist/pipeline/resolveSubscriptionChain.js +43 -0
- package/dist/ports/provider-config-source.cjs +18 -0
- package/dist/ports/provider-config-source.d.cts +51 -0
- package/dist/ports/provider-config-source.d.ts +51 -0
- package/dist/ports/provider-config-source.js +0 -0
- package/dist/ports/web-search-backend.cjs +18 -0
- package/dist/ports/web-search-backend.d.cts +29 -0
- package/dist/ports/web-search-backend.d.ts +29 -0
- package/dist/ports/web-search-backend.js +0 -0
- package/dist/ports.d.cts +10 -7
- package/dist/ports.d.ts +10 -7
- package/dist/provider-proxy/ProviderProxy.cjs +4643 -0
- package/dist/provider-proxy/ProviderProxy.d.cts +16 -0
- package/dist/provider-proxy/ProviderProxy.d.ts +16 -0
- package/dist/provider-proxy/ProviderProxy.js +4618 -0
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +5 -2
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +5 -2
- package/dist/provider-proxy/types.d.cts +406 -8
- package/dist/provider-proxy/types.d.ts +406 -8
- package/dist/provider-proxy.cjs +1 -0
- package/dist/provider-proxy.d.cts +8 -5
- package/dist/provider-proxy.d.ts +8 -5
- package/dist/provider-proxy.js +1 -0
- package/dist/routeResolver-BrbK6ja9.d.cts +88 -0
- package/dist/routeResolver-HE-ZO0fO.d.ts +88 -0
- package/dist/transformer/anthropicBetaInject.cjs +51 -0
- package/dist/transformer/anthropicBetaInject.d.cts +20 -0
- package/dist/transformer/anthropicBetaInject.d.ts +20 -0
- package/dist/transformer/anthropicBetaInject.js +25 -0
- package/dist/transformer/transformers/AnthropicTransformer.cjs +1017 -0
- package/dist/transformer/transformers/AnthropicTransformer.d.cts +148 -0
- package/dist/transformer/transformers/AnthropicTransformer.d.ts +148 -0
- package/dist/transformer/transformers/AnthropicTransformer.js +990 -0
- package/dist/transformer/transformers/ReasoningTransformer.cjs +273 -0
- package/dist/transformer/transformers/ReasoningTransformer.d.cts +47 -0
- package/dist/transformer/transformers/ReasoningTransformer.d.ts +47 -0
- package/dist/transformer/transformers/ReasoningTransformer.js +253 -0
- package/dist/transformer/transformers.cjs +3206 -0
- package/dist/transformer/transformers.d.cts +100 -0
- package/dist/transformer/transformers.d.ts +100 -0
- package/dist/transformer/transformers.js +3174 -0
- package/dist/transformer.d.cts +8 -31
- package/dist/transformer.d.ts +8 -31
- package/dist/types-BScIHmPr.d.cts +153 -0
- package/dist/types-BScIHmPr.d.ts +153 -0
- package/package.json +3 -3
- package/dist/SubscriptionAuthSource-Cr4fVEYY.d.cts +0 -264
- package/dist/SubscriptionAuthSource-D89zmiSS.d.ts +0 -264
- package/dist/index-BTSmc9Sm.d.ts +0 -645
- package/dist/index-DXazdTzZ.d.cts +0 -645
- package/dist/types-DCzHkhJt.d.ts +0 -467
- package/dist/types-DZIQbgp0.d.cts +0 -467
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/outbound-api/routeResolver.ts
|
|
21
|
+
var routeResolver_exports = {};
|
|
22
|
+
__export(routeResolver_exports, {
|
|
23
|
+
isSubscriptionProviderId: () => isSubscriptionProviderId,
|
|
24
|
+
parseModelRef: () => parseModelRef,
|
|
25
|
+
resolveRoute: () => resolveRoute
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(routeResolver_exports);
|
|
28
|
+
|
|
29
|
+
// src/outbound-api/subscriptionRegistryPort.ts
|
|
30
|
+
var _registry = null;
|
|
31
|
+
function getSubscriptionRegistryForOutbound() {
|
|
32
|
+
return _registry;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/outbound-api/subscriptionSupport.ts
|
|
36
|
+
var SUBSCRIPTION_PROVIDER_IDS = [
|
|
37
|
+
"claude",
|
|
38
|
+
"codex",
|
|
39
|
+
"gemini",
|
|
40
|
+
"opencodego"
|
|
41
|
+
];
|
|
42
|
+
var SUBSCRIPTION_ID_SET = new Set(SUBSCRIPTION_PROVIDER_IDS);
|
|
43
|
+
function isSubscriptionProviderId(providerId) {
|
|
44
|
+
if (SUBSCRIPTION_ID_SET.has(providerId)) return true;
|
|
45
|
+
const registry = getSubscriptionRegistryForOutbound();
|
|
46
|
+
return registry?.getProfile(providerId) != null;
|
|
47
|
+
}
|
|
48
|
+
var SUBSCRIPTION_SUPPORTED_ENDPOINTS = /* @__PURE__ */ new Set([
|
|
49
|
+
"messages",
|
|
50
|
+
"responses"
|
|
51
|
+
]);
|
|
52
|
+
function endpointSupportsSubscription(endpoint) {
|
|
53
|
+
return SUBSCRIPTION_SUPPORTED_ENDPOINTS.has(endpoint);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/outbound-api/routeResolver.ts
|
|
57
|
+
function parseModelRef(ref) {
|
|
58
|
+
if (!ref) return null;
|
|
59
|
+
const idx = ref.indexOf(",");
|
|
60
|
+
if (idx <= 0) return null;
|
|
61
|
+
const providerId = ref.slice(0, idx).trim();
|
|
62
|
+
const modelId = ref.slice(idx + 1).trim();
|
|
63
|
+
if (!providerId || !modelId) return null;
|
|
64
|
+
return { providerId, modelId };
|
|
65
|
+
}
|
|
66
|
+
function pickModelRefForRole(config, role) {
|
|
67
|
+
if (role === "vision") {
|
|
68
|
+
if (config.visionModel && config.visionModel.trim()) {
|
|
69
|
+
return { ref: config.visionModel, effectiveRole: "vision" };
|
|
70
|
+
}
|
|
71
|
+
return { ref: config.defaultModel, effectiveRole: "default" };
|
|
72
|
+
}
|
|
73
|
+
if (role === "background") {
|
|
74
|
+
return { ref: config.backgroundModel, effectiveRole: "background" };
|
|
75
|
+
}
|
|
76
|
+
return { ref: config.defaultModel, effectiveRole: "default" };
|
|
77
|
+
}
|
|
78
|
+
async function resolveRoute(args) {
|
|
79
|
+
const { config, role, ingressFormat, llmConfig } = args;
|
|
80
|
+
const sessionId = args.sessionId ?? null;
|
|
81
|
+
const { ref, effectiveRole } = pickModelRefForRole(config, role);
|
|
82
|
+
if (!ref || !ref.trim()) {
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
error: {
|
|
86
|
+
status: 503,
|
|
87
|
+
message: `endpoint '${config.endpoint}' has no ${effectiveRole} model configured`
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const parsed = parseModelRef(ref);
|
|
92
|
+
if (!parsed) {
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
error: {
|
|
96
|
+
status: 503,
|
|
97
|
+
message: `endpoint '${config.endpoint}' ${effectiveRole} model ref is malformed: '${ref}'`
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const { providerId, modelId } = parsed;
|
|
102
|
+
const provider = await llmConfig.getProvider(providerId);
|
|
103
|
+
if (!provider) {
|
|
104
|
+
if (isSubscriptionProviderId(providerId)) {
|
|
105
|
+
return await resolveSubscriptionRoute({
|
|
106
|
+
config,
|
|
107
|
+
providerId,
|
|
108
|
+
modelId,
|
|
109
|
+
ingressFormat,
|
|
110
|
+
sessionId,
|
|
111
|
+
effectiveRole
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
ok: false,
|
|
116
|
+
error: {
|
|
117
|
+
status: 503,
|
|
118
|
+
message: `provider '${providerId}' not found for endpoint '${config.endpoint}'`
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const isOfficialProvider = provider.isOfficial === true || provider.id === "anthropic";
|
|
123
|
+
const targetProviderFormat = isOfficialProvider ? "anthropic" : "transform";
|
|
124
|
+
let anthropicSdkHints = null;
|
|
125
|
+
if (ingressFormat === "anthropic-messages") {
|
|
126
|
+
anthropicSdkHints = {
|
|
127
|
+
apiKey: resolveApiKey(provider.api_key),
|
|
128
|
+
isOfficialProvider,
|
|
129
|
+
passThrough: false,
|
|
130
|
+
attribution: { sessionId, apiKeyId: null }
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const route = {
|
|
134
|
+
sessionId,
|
|
135
|
+
targetProviderFormat,
|
|
136
|
+
model: modelId,
|
|
137
|
+
ingressFormat,
|
|
138
|
+
authMode: "byo",
|
|
139
|
+
providerId,
|
|
140
|
+
anthropicSdkHints
|
|
141
|
+
};
|
|
142
|
+
return { ok: true, route, usedRole: effectiveRole };
|
|
143
|
+
}
|
|
144
|
+
async function resolveSubscriptionRoute(args) {
|
|
145
|
+
const { config, providerId, modelId, ingressFormat, sessionId, effectiveRole } = args;
|
|
146
|
+
if (!config.useSubscription) {
|
|
147
|
+
return {
|
|
148
|
+
ok: false,
|
|
149
|
+
error: {
|
|
150
|
+
status: 503,
|
|
151
|
+
message: `subscription routing disabled for endpoint '${config.endpoint}'`
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (!endpointSupportsSubscription(config.endpoint)) {
|
|
156
|
+
return {
|
|
157
|
+
ok: false,
|
|
158
|
+
error: {
|
|
159
|
+
status: 503,
|
|
160
|
+
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`
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const registry = getSubscriptionRegistryForOutbound();
|
|
165
|
+
const profile = registry?.getProfile(providerId) ?? null;
|
|
166
|
+
if (!profile) {
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
error: {
|
|
170
|
+
status: 503,
|
|
171
|
+
message: `subscription provider '${providerId}' is not available`
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const hints = {
|
|
176
|
+
apiKey: "",
|
|
177
|
+
isOfficialProvider: false,
|
|
178
|
+
passThrough: false,
|
|
179
|
+
subscriptionProfile: profile,
|
|
180
|
+
attribution: { sessionId, apiKeyId: null }
|
|
181
|
+
};
|
|
182
|
+
const subscriptionConfig = providerId === "opencodego" ? await registry?.getOpenCodeGoConfig?.() : void 0;
|
|
183
|
+
const route = {
|
|
184
|
+
sessionId,
|
|
185
|
+
targetProviderFormat: "transform",
|
|
186
|
+
model: modelId,
|
|
187
|
+
ingressFormat,
|
|
188
|
+
authMode: "subscription",
|
|
189
|
+
providerId,
|
|
190
|
+
// Anthropic delegation carries the dispatch profile inside
|
|
191
|
+
// `anthropicSdkHints.subscriptionProfile`. The Responses ingress reads the
|
|
192
|
+
// TOP-LEVEL `route.subscriptionProfile`, and so does the built-in
|
|
193
|
+
// (factory-absent) `/v1/messages` subscription path (RT2.1) — the registry's
|
|
194
|
+
// `SubscriptionDispatchProfile` structurally satisfies `SubscriptionAuthProfile`
|
|
195
|
+
// ({ authStrategy, resolveUpstreamUrl, providerTransformerNames }), so set it
|
|
196
|
+
// for BOTH. This is INERT when an Anthropic ingress factory is present: that
|
|
197
|
+
// delegation reads the hint-bundle field above (and uses a different
|
|
198
|
+
// route-minting path), never the top-level field. (chat/gemini never reach
|
|
199
|
+
// here — Gate 2 rejected them.)
|
|
200
|
+
subscriptionProfile: ingressFormat === "openai-responses" || ingressFormat === "anthropic-messages" ? profile : void 0,
|
|
201
|
+
// Opaque per-account config (opencodego-only; `undefined` otherwise). Read by
|
|
202
|
+
// the built-in `/v1/messages` plan builder; INERT for the factory-present
|
|
203
|
+
// delegation path + non-opencodego.
|
|
204
|
+
subscriptionConfig,
|
|
205
|
+
anthropicSdkHints: hints
|
|
206
|
+
};
|
|
207
|
+
return { ok: true, route, usedRole: effectiveRole };
|
|
208
|
+
}
|
|
209
|
+
function resolveApiKey(apiKey) {
|
|
210
|
+
if (!apiKey) return "";
|
|
211
|
+
if (apiKey.startsWith("$")) {
|
|
212
|
+
return process.env[apiKey.slice(1)] || "";
|
|
213
|
+
}
|
|
214
|
+
return apiKey;
|
|
215
|
+
}
|
|
216
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
+
0 && (module.exports = {
|
|
218
|
+
isSubscriptionProviderId,
|
|
219
|
+
parseModelRef,
|
|
220
|
+
resolveRoute
|
|
221
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import '../ports/provider-config-source.cjs';
|
|
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';
|
|
5
|
+
import '@omnicross/contracts/llm-config';
|
|
6
|
+
import '../transformer/types.cjs';
|
|
7
|
+
import '../transformer/TransformerService.cjs';
|
|
8
|
+
import 'node:http';
|
|
9
|
+
import '@omnicross/contracts/completion-types';
|
|
10
|
+
import '@omnicross/contracts/subscription-types';
|
|
11
|
+
import '@omnicross/contracts/usage-types';
|
|
12
|
+
import '../ApiKeyPoolService-BmMkau07.cjs';
|
|
13
|
+
import '../pipeline/AuthSource.cjs';
|
|
14
|
+
import '../pipeline/SubscriptionAuthSource.cjs';
|
|
15
|
+
import '../pipeline/SubscriptionAuthStrategy.cjs';
|
|
16
|
+
import '../ports/web-search-backend.cjs';
|
|
17
|
+
import '@omnicross/contracts/websearch-types';
|
|
18
|
+
import '../ProviderProxy-CnMQYN59.cjs';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import '../ports/provider-config-source.js';
|
|
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';
|
|
5
|
+
import '@omnicross/contracts/llm-config';
|
|
6
|
+
import '../transformer/types.js';
|
|
7
|
+
import '../transformer/TransformerService.js';
|
|
8
|
+
import 'node:http';
|
|
9
|
+
import '@omnicross/contracts/completion-types';
|
|
10
|
+
import '@omnicross/contracts/subscription-types';
|
|
11
|
+
import '@omnicross/contracts/usage-types';
|
|
12
|
+
import '../ApiKeyPoolService-BmMkau07.js';
|
|
13
|
+
import '../pipeline/AuthSource.js';
|
|
14
|
+
import '../pipeline/SubscriptionAuthSource.js';
|
|
15
|
+
import '../pipeline/SubscriptionAuthStrategy.js';
|
|
16
|
+
import '../ports/web-search-backend.js';
|
|
17
|
+
import '@omnicross/contracts/websearch-types';
|
|
18
|
+
import '../ProviderProxy-C-xqrkKi.js';
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// src/outbound-api/subscriptionRegistryPort.ts
|
|
2
|
+
var _registry = null;
|
|
3
|
+
function getSubscriptionRegistryForOutbound() {
|
|
4
|
+
return _registry;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// src/outbound-api/subscriptionSupport.ts
|
|
8
|
+
var SUBSCRIPTION_PROVIDER_IDS = [
|
|
9
|
+
"claude",
|
|
10
|
+
"codex",
|
|
11
|
+
"gemini",
|
|
12
|
+
"opencodego"
|
|
13
|
+
];
|
|
14
|
+
var SUBSCRIPTION_ID_SET = new Set(SUBSCRIPTION_PROVIDER_IDS);
|
|
15
|
+
function isSubscriptionProviderId(providerId) {
|
|
16
|
+
if (SUBSCRIPTION_ID_SET.has(providerId)) return true;
|
|
17
|
+
const registry = getSubscriptionRegistryForOutbound();
|
|
18
|
+
return registry?.getProfile(providerId) != null;
|
|
19
|
+
}
|
|
20
|
+
var SUBSCRIPTION_SUPPORTED_ENDPOINTS = /* @__PURE__ */ new Set([
|
|
21
|
+
"messages",
|
|
22
|
+
"responses"
|
|
23
|
+
]);
|
|
24
|
+
function endpointSupportsSubscription(endpoint) {
|
|
25
|
+
return SUBSCRIPTION_SUPPORTED_ENDPOINTS.has(endpoint);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/outbound-api/routeResolver.ts
|
|
29
|
+
function parseModelRef(ref) {
|
|
30
|
+
if (!ref) return null;
|
|
31
|
+
const idx = ref.indexOf(",");
|
|
32
|
+
if (idx <= 0) return null;
|
|
33
|
+
const providerId = ref.slice(0, idx).trim();
|
|
34
|
+
const modelId = ref.slice(idx + 1).trim();
|
|
35
|
+
if (!providerId || !modelId) return null;
|
|
36
|
+
return { providerId, modelId };
|
|
37
|
+
}
|
|
38
|
+
function pickModelRefForRole(config, role) {
|
|
39
|
+
if (role === "vision") {
|
|
40
|
+
if (config.visionModel && config.visionModel.trim()) {
|
|
41
|
+
return { ref: config.visionModel, effectiveRole: "vision" };
|
|
42
|
+
}
|
|
43
|
+
return { ref: config.defaultModel, effectiveRole: "default" };
|
|
44
|
+
}
|
|
45
|
+
if (role === "background") {
|
|
46
|
+
return { ref: config.backgroundModel, effectiveRole: "background" };
|
|
47
|
+
}
|
|
48
|
+
return { ref: config.defaultModel, effectiveRole: "default" };
|
|
49
|
+
}
|
|
50
|
+
async function resolveRoute(args) {
|
|
51
|
+
const { config, role, ingressFormat, llmConfig } = args;
|
|
52
|
+
const sessionId = args.sessionId ?? null;
|
|
53
|
+
const { ref, effectiveRole } = pickModelRefForRole(config, role);
|
|
54
|
+
if (!ref || !ref.trim()) {
|
|
55
|
+
return {
|
|
56
|
+
ok: false,
|
|
57
|
+
error: {
|
|
58
|
+
status: 503,
|
|
59
|
+
message: `endpoint '${config.endpoint}' has no ${effectiveRole} model configured`
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const parsed = parseModelRef(ref);
|
|
64
|
+
if (!parsed) {
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
error: {
|
|
68
|
+
status: 503,
|
|
69
|
+
message: `endpoint '${config.endpoint}' ${effectiveRole} model ref is malformed: '${ref}'`
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const { providerId, modelId } = parsed;
|
|
74
|
+
const provider = await llmConfig.getProvider(providerId);
|
|
75
|
+
if (!provider) {
|
|
76
|
+
if (isSubscriptionProviderId(providerId)) {
|
|
77
|
+
return await resolveSubscriptionRoute({
|
|
78
|
+
config,
|
|
79
|
+
providerId,
|
|
80
|
+
modelId,
|
|
81
|
+
ingressFormat,
|
|
82
|
+
sessionId,
|
|
83
|
+
effectiveRole
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
error: {
|
|
89
|
+
status: 503,
|
|
90
|
+
message: `provider '${providerId}' not found for endpoint '${config.endpoint}'`
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const isOfficialProvider = provider.isOfficial === true || provider.id === "anthropic";
|
|
95
|
+
const targetProviderFormat = isOfficialProvider ? "anthropic" : "transform";
|
|
96
|
+
let anthropicSdkHints = null;
|
|
97
|
+
if (ingressFormat === "anthropic-messages") {
|
|
98
|
+
anthropicSdkHints = {
|
|
99
|
+
apiKey: resolveApiKey(provider.api_key),
|
|
100
|
+
isOfficialProvider,
|
|
101
|
+
passThrough: false,
|
|
102
|
+
attribution: { sessionId, apiKeyId: null }
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const route = {
|
|
106
|
+
sessionId,
|
|
107
|
+
targetProviderFormat,
|
|
108
|
+
model: modelId,
|
|
109
|
+
ingressFormat,
|
|
110
|
+
authMode: "byo",
|
|
111
|
+
providerId,
|
|
112
|
+
anthropicSdkHints
|
|
113
|
+
};
|
|
114
|
+
return { ok: true, route, usedRole: effectiveRole };
|
|
115
|
+
}
|
|
116
|
+
async function resolveSubscriptionRoute(args) {
|
|
117
|
+
const { config, providerId, modelId, ingressFormat, sessionId, effectiveRole } = args;
|
|
118
|
+
if (!config.useSubscription) {
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
error: {
|
|
122
|
+
status: 503,
|
|
123
|
+
message: `subscription routing disabled for endpoint '${config.endpoint}'`
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (!endpointSupportsSubscription(config.endpoint)) {
|
|
128
|
+
return {
|
|
129
|
+
ok: false,
|
|
130
|
+
error: {
|
|
131
|
+
status: 503,
|
|
132
|
+
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`
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const registry = getSubscriptionRegistryForOutbound();
|
|
137
|
+
const profile = registry?.getProfile(providerId) ?? null;
|
|
138
|
+
if (!profile) {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
error: {
|
|
142
|
+
status: 503,
|
|
143
|
+
message: `subscription provider '${providerId}' is not available`
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const hints = {
|
|
148
|
+
apiKey: "",
|
|
149
|
+
isOfficialProvider: false,
|
|
150
|
+
passThrough: false,
|
|
151
|
+
subscriptionProfile: profile,
|
|
152
|
+
attribution: { sessionId, apiKeyId: null }
|
|
153
|
+
};
|
|
154
|
+
const subscriptionConfig = providerId === "opencodego" ? await registry?.getOpenCodeGoConfig?.() : void 0;
|
|
155
|
+
const route = {
|
|
156
|
+
sessionId,
|
|
157
|
+
targetProviderFormat: "transform",
|
|
158
|
+
model: modelId,
|
|
159
|
+
ingressFormat,
|
|
160
|
+
authMode: "subscription",
|
|
161
|
+
providerId,
|
|
162
|
+
// Anthropic delegation carries the dispatch profile inside
|
|
163
|
+
// `anthropicSdkHints.subscriptionProfile`. The Responses ingress reads the
|
|
164
|
+
// TOP-LEVEL `route.subscriptionProfile`, and so does the built-in
|
|
165
|
+
// (factory-absent) `/v1/messages` subscription path (RT2.1) — the registry's
|
|
166
|
+
// `SubscriptionDispatchProfile` structurally satisfies `SubscriptionAuthProfile`
|
|
167
|
+
// ({ authStrategy, resolveUpstreamUrl, providerTransformerNames }), so set it
|
|
168
|
+
// for BOTH. This is INERT when an Anthropic ingress factory is present: that
|
|
169
|
+
// delegation reads the hint-bundle field above (and uses a different
|
|
170
|
+
// route-minting path), never the top-level field. (chat/gemini never reach
|
|
171
|
+
// here — Gate 2 rejected them.)
|
|
172
|
+
subscriptionProfile: ingressFormat === "openai-responses" || ingressFormat === "anthropic-messages" ? profile : void 0,
|
|
173
|
+
// Opaque per-account config (opencodego-only; `undefined` otherwise). Read by
|
|
174
|
+
// the built-in `/v1/messages` plan builder; INERT for the factory-present
|
|
175
|
+
// delegation path + non-opencodego.
|
|
176
|
+
subscriptionConfig,
|
|
177
|
+
anthropicSdkHints: hints
|
|
178
|
+
};
|
|
179
|
+
return { ok: true, route, usedRole: effectiveRole };
|
|
180
|
+
}
|
|
181
|
+
function resolveApiKey(apiKey) {
|
|
182
|
+
if (!apiKey) return "";
|
|
183
|
+
if (apiKey.startsWith("$")) {
|
|
184
|
+
return process.env[apiKey.slice(1)] || "";
|
|
185
|
+
}
|
|
186
|
+
return apiKey;
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
isSubscriptionProviderId,
|
|
190
|
+
parseModelRef,
|
|
191
|
+
resolveRoute
|
|
192
|
+
};
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SubscriptionDispatchProfile } from '../provider-proxy/types.cjs';
|
|
2
2
|
import 'node:http';
|
|
3
3
|
import '@omnicross/contracts/completion-types';
|
|
4
4
|
import '@omnicross/contracts/subscription-types';
|
|
5
5
|
import '@omnicross/contracts/usage-types';
|
|
6
6
|
import '../ApiKeyPoolService-BmMkau07.cjs';
|
|
7
7
|
import '@omnicross/contracts/llm-config';
|
|
8
|
-
import '../
|
|
8
|
+
import '../pipeline/AuthSource.cjs';
|
|
9
|
+
import '../pipeline/SubscriptionAuthSource.cjs';
|
|
9
10
|
import '../pipeline/SubscriptionAuthStrategy.cjs';
|
|
11
|
+
import '../ports/provider-config-source.cjs';
|
|
10
12
|
import '../transformer/types.cjs';
|
|
11
13
|
import '../transformer/TransformerService.cjs';
|
|
14
|
+
import '../ports/web-search-backend.cjs';
|
|
12
15
|
import '@omnicross/contracts/websearch-types';
|
|
13
16
|
|
|
14
17
|
/**
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SubscriptionDispatchProfile } from '../provider-proxy/types.js';
|
|
2
2
|
import 'node:http';
|
|
3
3
|
import '@omnicross/contracts/completion-types';
|
|
4
4
|
import '@omnicross/contracts/subscription-types';
|
|
5
5
|
import '@omnicross/contracts/usage-types';
|
|
6
6
|
import '../ApiKeyPoolService-BmMkau07.js';
|
|
7
7
|
import '@omnicross/contracts/llm-config';
|
|
8
|
-
import '../
|
|
8
|
+
import '../pipeline/AuthSource.js';
|
|
9
|
+
import '../pipeline/SubscriptionAuthSource.js';
|
|
9
10
|
import '../pipeline/SubscriptionAuthStrategy.js';
|
|
11
|
+
import '../ports/provider-config-source.js';
|
|
10
12
|
import '../transformer/types.js';
|
|
11
13
|
import '../transformer/TransformerService.js';
|
|
14
|
+
import '../ports/web-search-backend.js';
|
|
12
15
|
import '@omnicross/contracts/websearch-types';
|
|
13
16
|
|
|
14
17
|
/**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/outbound-api/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { P as ProviderProxy } from '
|
|
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';
|
|
4
|
+
import '@omnicross/contracts/llm-config';
|
|
5
|
+
import '../transformer/types.cjs';
|
|
6
|
+
import '../transformer/TransformerService.cjs';
|
|
7
|
+
import 'node:http';
|
|
8
|
+
import '@omnicross/contracts/completion-types';
|
|
9
|
+
import '@omnicross/contracts/subscription-types';
|
|
10
|
+
import '@omnicross/contracts/usage-types';
|
|
11
|
+
import '../ApiKeyPoolService-BmMkau07.cjs';
|
|
12
|
+
import '../pipeline/AuthSource.cjs';
|
|
13
|
+
import '../pipeline/SubscriptionAuthSource.cjs';
|
|
14
|
+
import '../pipeline/SubscriptionAuthStrategy.cjs';
|
|
15
|
+
import '../ports/web-search-backend.cjs';
|
|
16
|
+
import '@omnicross/contracts/websearch-types';
|
|
3
17
|
|
|
4
18
|
/**
|
|
5
19
|
* Shared contract types for the outbound API server (`outbound-api-server`).
|
|
@@ -139,4 +153,4 @@ interface OutboundApiDeps {
|
|
|
139
153
|
readonly proxyDeps: ProviderProxyDeps;
|
|
140
154
|
}
|
|
141
155
|
|
|
142
|
-
export type { EndpointRoutingConfig
|
|
156
|
+
export type { EndpointRoutingConfig, ModelRef, OutboundApiDeps, OutboundApiKeyCreated, OutboundApiKeyInfo, OutboundApiServerConfig, OutboundApiServerStatus, OutboundEndpoint, OutboundFormatUrls, OutboundKeyDb, OutboundKeyDbRow, RequestRole };
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { P as ProviderProxy } from '
|
|
1
|
+
import { ProviderConfigSource } from '../ports/provider-config-source.js';
|
|
2
|
+
import { P as ProviderProxy } from '../ProviderProxy-C-xqrkKi.js';
|
|
3
|
+
import { ProviderProxyDeps } from '../provider-proxy/types.js';
|
|
4
|
+
import '@omnicross/contracts/llm-config';
|
|
5
|
+
import '../transformer/types.js';
|
|
6
|
+
import '../transformer/TransformerService.js';
|
|
7
|
+
import 'node:http';
|
|
8
|
+
import '@omnicross/contracts/completion-types';
|
|
9
|
+
import '@omnicross/contracts/subscription-types';
|
|
10
|
+
import '@omnicross/contracts/usage-types';
|
|
11
|
+
import '../ApiKeyPoolService-BmMkau07.js';
|
|
12
|
+
import '../pipeline/AuthSource.js';
|
|
13
|
+
import '../pipeline/SubscriptionAuthSource.js';
|
|
14
|
+
import '../pipeline/SubscriptionAuthStrategy.js';
|
|
15
|
+
import '../ports/web-search-backend.js';
|
|
16
|
+
import '@omnicross/contracts/websearch-types';
|
|
3
17
|
|
|
4
18
|
/**
|
|
5
19
|
* Shared contract types for the outbound API server (`outbound-api-server`).
|
|
@@ -139,4 +153,4 @@ interface OutboundApiDeps {
|
|
|
139
153
|
readonly proxyDeps: ProviderProxyDeps;
|
|
140
154
|
}
|
|
141
155
|
|
|
142
|
-
export type { EndpointRoutingConfig
|
|
156
|
+
export type { EndpointRoutingConfig, ModelRef, OutboundApiDeps, OutboundApiKeyCreated, OutboundApiKeyInfo, OutboundApiServerConfig, OutboundApiServerStatus, OutboundEndpoint, OutboundFormatUrls, OutboundKeyDb, OutboundKeyDbRow, RequestRole };
|
|
File without changes
|
package/dist/outbound-api.cjs
CHANGED
|
@@ -3836,6 +3836,7 @@ async function handleAnthropicMessagesRequest(req, res, route, deps) {
|
|
|
3836
3836
|
extendedContext: hints.extendedContext ?? null,
|
|
3837
3837
|
passThrough: hints.passThrough,
|
|
3838
3838
|
passThroughAuthToken: hints.passThroughAuthToken ?? null,
|
|
3839
|
+
resolvePassThroughAuthToken: hints.resolvePassThroughAuthToken ?? null,
|
|
3839
3840
|
subscriptionProfile: hints.subscriptionProfile ?? null,
|
|
3840
3841
|
maxConcurrency: hints.maxConcurrency,
|
|
3841
3842
|
webSearchService: hints.webSearchService ?? null,
|