@opengeni/config 0.10.0 → 0.10.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.
- package/dist/index.d.ts +112 -0
- package/dist/index.js +287 -11
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +335 -16
package/dist/index.js
CHANGED
|
@@ -292,6 +292,10 @@ var SettingsSchema = z.object({
|
|
|
292
292
|
openaiBaseUrl: z.string().optional(),
|
|
293
293
|
openaiModel: z.string().default("gpt-5.6-sol"),
|
|
294
294
|
openaiAllowedModels: z.string().default("gpt-5.6-sol,gpt-5.6-terra,gpt-5.6-luna"),
|
|
295
|
+
// OpenGeni-managed Vercel AI Gateway. When configured, the two reviewed
|
|
296
|
+
// Gateway models below are added to the managed-credit catalog. Workspace
|
|
297
|
+
// Gateway keys use the encrypted connection broker and never this secret.
|
|
298
|
+
vercelAiGatewayApiKey: z.string().optional(),
|
|
295
299
|
// Native composer voice input (browser MediaRecorder → API transcription).
|
|
296
300
|
// Provider credentials stay server-side; ClientConfig only projects availability
|
|
297
301
|
// and hard ceilings. Selection happens once before audio is sent — never retry
|
|
@@ -363,7 +367,7 @@ var SettingsSchema = z.object({
|
|
|
363
367
|
// match the UI danger flip (UsageBar danger at pct >= 90). OPENGENI_CODEX_ROTATION_NEAR_EXHAUSTION_PCT.
|
|
364
368
|
codexRotationNearExhaustionPct: z.coerce.number().int().min(1).max(100).default(90),
|
|
365
369
|
openaiReasoningEffort: ReasoningEffort.default("low"),
|
|
366
|
-
openaiAllowedReasoningEfforts: z.string().default("low,medium,high,xhigh"),
|
|
370
|
+
openaiAllowedReasoningEfforts: z.string().default("low,medium,high,xhigh,max"),
|
|
367
371
|
openaiResponsesTransport: z.enum(["http", "websocket"]).default("http"),
|
|
368
372
|
// Provider-assigned item ids (rs_/msg_/fc_…) in Responses API input are
|
|
369
373
|
// resolved against the provider's server-side response store. That store is
|
|
@@ -965,6 +969,9 @@ var ModelCapabilitiesV1Schema = z.object({
|
|
|
965
969
|
responsesWebSocket: CapabilityStateV1Schema,
|
|
966
970
|
realtimeAudio: CapabilityStateV1Schema
|
|
967
971
|
}),
|
|
972
|
+
promptCaching: CapabilityStateV1Schema.extend({
|
|
973
|
+
mode: z.enum(["implicit", "automatic", "none"])
|
|
974
|
+
}).optional(),
|
|
968
975
|
latencyModes: z.array(
|
|
969
976
|
z.object({
|
|
970
977
|
id: ModelLatencyModeV1,
|
|
@@ -1025,7 +1032,12 @@ var ModelCapabilitiesV1Schema = z.object({
|
|
|
1025
1032
|
}
|
|
1026
1033
|
});
|
|
1027
1034
|
var ModelProviderApi = z.enum(["responses", "chat"]);
|
|
1028
|
-
var RegistryProviderKind = z.enum([
|
|
1035
|
+
var RegistryProviderKind = z.enum([
|
|
1036
|
+
"api-key",
|
|
1037
|
+
"codex-subscription",
|
|
1038
|
+
"vercel-gateway-managed",
|
|
1039
|
+
"vercel-gateway-workspace"
|
|
1040
|
+
]);
|
|
1029
1041
|
var RegistryModelSchema = z.object({
|
|
1030
1042
|
id: z.string().min(1),
|
|
1031
1043
|
// canonical OpenGeni product id
|
|
@@ -1069,7 +1081,6 @@ var RegistryModelSchema = z.object({
|
|
|
1069
1081
|
});
|
|
1070
1082
|
var RegistryProviderSchema = z.object({
|
|
1071
1083
|
kind: RegistryProviderKind.default("api-key"),
|
|
1072
|
-
// "codex-subscription" => per-request token, no static key
|
|
1073
1084
|
id: z.string().min(1).regex(registryId),
|
|
1074
1085
|
// stable provider id, e.g. "fireworks"
|
|
1075
1086
|
label: z.string().min(1).optional(),
|
|
@@ -1094,6 +1105,68 @@ var IntegrationOAuthClientConfigSchema = z.object({
|
|
|
1094
1105
|
clientSecret: z.string().min(1).optional(),
|
|
1095
1106
|
tokenEndpointAuthMethod: z.enum(["none", "client_secret_post", "client_secret_basic"]).default("none")
|
|
1096
1107
|
});
|
|
1108
|
+
var VERCEL_AI_GATEWAY_BASE_URL = "https://ai-gateway.vercel.sh/v1";
|
|
1109
|
+
var VERCEL_AI_GATEWAY_AI_SDK_BASE_URL = "https://ai-gateway.vercel.sh/v4/ai";
|
|
1110
|
+
var OPENGENI_GATEWAY_PROVIDER_ID = "opengeni-gateway";
|
|
1111
|
+
var WORKSPACE_GATEWAY_PROVIDER_ID = "workspace-gateway";
|
|
1112
|
+
var WORKSPACE_GATEWAY_MODEL_ID_PREFIX = "workspace-gateway/";
|
|
1113
|
+
var VERCEL_AI_GATEWAY_CONNECTION_DOMAIN = "ai-gateway.vercel.sh";
|
|
1114
|
+
var VERCEL_AI_GATEWAY_CONNECTION_ROLE = "vercel_ai_gateway";
|
|
1115
|
+
var CODEX_REALTIME_MODEL_ID = "gpt-live-1-boulder-alpha";
|
|
1116
|
+
var OPENGENI_REALTIME_MODEL_ID_PREFIX = "opengeni-gateway/";
|
|
1117
|
+
var WORKSPACE_REALTIME_MODEL_ID_PREFIX = "workspace-gateway/";
|
|
1118
|
+
var AI_GATEWAY_REALTIME_MODELS = {
|
|
1119
|
+
openaiRealtime21: {
|
|
1120
|
+
upstreamModelId: "openai/gpt-realtime-2.1",
|
|
1121
|
+
managedModelId: `${OPENGENI_REALTIME_MODEL_ID_PREFIX}openai/gpt-realtime-2.1`,
|
|
1122
|
+
workspaceModelId: `${WORKSPACE_REALTIME_MODEL_ID_PREFIX}openai/gpt-realtime-2.1`,
|
|
1123
|
+
label: "GPT Realtime 2.1",
|
|
1124
|
+
description: "Best overall voice intelligence"
|
|
1125
|
+
},
|
|
1126
|
+
openaiRealtimeMini: {
|
|
1127
|
+
upstreamModelId: "openai/gpt-realtime-mini",
|
|
1128
|
+
managedModelId: `${OPENGENI_REALTIME_MODEL_ID_PREFIX}openai/gpt-realtime-mini`,
|
|
1129
|
+
workspaceModelId: `${WORKSPACE_REALTIME_MODEL_ID_PREFIX}openai/gpt-realtime-mini`,
|
|
1130
|
+
label: "GPT Realtime Mini",
|
|
1131
|
+
description: "Faster, lighter live voice"
|
|
1132
|
+
},
|
|
1133
|
+
grokVoiceThinkFast20: {
|
|
1134
|
+
upstreamModelId: "xai/grok-voice-think-fast-2.0",
|
|
1135
|
+
managedModelId: `${OPENGENI_REALTIME_MODEL_ID_PREFIX}xai/grok-voice-think-fast-2.0`,
|
|
1136
|
+
workspaceModelId: `${WORKSPACE_REALTIME_MODEL_ID_PREFIX}xai/grok-voice-think-fast-2.0`,
|
|
1137
|
+
label: "Grok Voice Think Fast 2.0",
|
|
1138
|
+
description: "Fast, natural xAI voice"
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
function resolveAiGatewayRealtimeModel(modelId) {
|
|
1142
|
+
for (const model of Object.values(AI_GATEWAY_REALTIME_MODELS)) {
|
|
1143
|
+
if (model.managedModelId === modelId) {
|
|
1144
|
+
return { source: "managed", upstreamModelId: model.upstreamModelId };
|
|
1145
|
+
}
|
|
1146
|
+
if (model.workspaceModelId === modelId) {
|
|
1147
|
+
return { source: "workspace", upstreamModelId: model.upstreamModelId };
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
return null;
|
|
1151
|
+
}
|
|
1152
|
+
var OPENGENI_GATEWAY_MODELS = {
|
|
1153
|
+
deepseek: {
|
|
1154
|
+
productId: "deepseek-v4-flash-0731",
|
|
1155
|
+
workspaceProductId: `${WORKSPACE_GATEWAY_MODEL_ID_PREFIX}deepseek-v4-flash-0731`,
|
|
1156
|
+
upstreamModelId: "deepseek/deepseek-v4-flash-0731",
|
|
1157
|
+
label: "DeepSeek V4 Flash 0731",
|
|
1158
|
+
providers: ["baseten", "novita", "deepinfra"],
|
|
1159
|
+
implicitCaching: true
|
|
1160
|
+
},
|
|
1161
|
+
kimi: {
|
|
1162
|
+
productId: "kimi-k3",
|
|
1163
|
+
workspaceProductId: `${WORKSPACE_GATEWAY_MODEL_ID_PREFIX}kimi-k3`,
|
|
1164
|
+
upstreamModelId: "moonshotai/kimi-k3",
|
|
1165
|
+
label: "Kimi K3",
|
|
1166
|
+
providers: ["baseten", "fireworks"],
|
|
1167
|
+
implicitCaching: true
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1097
1170
|
var defaultModelPricing = {
|
|
1098
1171
|
"gpt-5.6-sol": {
|
|
1099
1172
|
default: {
|
|
@@ -1153,6 +1226,27 @@ var defaultModelPricing = {
|
|
|
1153
1226
|
}
|
|
1154
1227
|
]
|
|
1155
1228
|
},
|
|
1229
|
+
// Conservative Vercel AI Gateway fallback prices. Normal managed Gateway
|
|
1230
|
+
// billing uses the exact response Gateway `cost` / `inferenceCost` and applies
|
|
1231
|
+
// the same margin. These token rates are used only if that
|
|
1232
|
+
// metadata is absent. DeepSeek therefore carries the highest approved route
|
|
1233
|
+
// (Novita); both approved Kimi routes have the same list price.
|
|
1234
|
+
[OPENGENI_GATEWAY_MODELS.deepseek.productId]: {
|
|
1235
|
+
default: {
|
|
1236
|
+
inputMicrosPerMillionTokens: 14e4,
|
|
1237
|
+
cachedInputMicrosPerMillionTokens: 28e3,
|
|
1238
|
+
outputMicrosPerMillionTokens: 28e4,
|
|
1239
|
+
marginBps: 2500
|
|
1240
|
+
}
|
|
1241
|
+
},
|
|
1242
|
+
[OPENGENI_GATEWAY_MODELS.kimi.productId]: {
|
|
1243
|
+
default: {
|
|
1244
|
+
inputMicrosPerMillionTokens: 3e6,
|
|
1245
|
+
cachedInputMicrosPerMillionTokens: 3e5,
|
|
1246
|
+
outputMicrosPerMillionTokens: 15e6,
|
|
1247
|
+
marginBps: 2500
|
|
1248
|
+
}
|
|
1249
|
+
},
|
|
1156
1250
|
// Fireworks AI / GLM 5.2 — the first shipped non-OpenAI registry model. A
|
|
1157
1251
|
// built-in default pricing entry makes managed billing work out of the box
|
|
1158
1252
|
// for hosts that expose this model via OPENGENI_MODEL_PROVIDERS_JSON without
|
|
@@ -1292,6 +1386,7 @@ function getSettings() {
|
|
|
1292
1386
|
openaiBaseUrl: optional("OPENGENI_OPENAI_BASE_URL") ?? optional("OPENAI_BASE_URL"),
|
|
1293
1387
|
openaiModel: optional("OPENGENI_OPENAI_MODEL"),
|
|
1294
1388
|
openaiAllowedModels: optional("OPENGENI_OPENAI_ALLOWED_MODELS"),
|
|
1389
|
+
vercelAiGatewayApiKey: optional("OPENGENI_VERCEL_AI_GATEWAY_API_KEY"),
|
|
1295
1390
|
voiceInputMaxDurationSeconds: optional("OPENGENI_VOICE_INPUT_MAX_DURATION_SECONDS"),
|
|
1296
1391
|
voiceInputMaxSizeBytes: optional("OPENGENI_VOICE_INPUT_MAX_SIZE_BYTES"),
|
|
1297
1392
|
voiceInputProviderOrder: optional("OPENGENI_VOICE_INPUT_PROVIDER_ORDER"),
|
|
@@ -1743,6 +1838,111 @@ function legacyModelCapabilities(settings, input) {
|
|
|
1743
1838
|
latencyModes: [{ id: "standard", upstream: "unknown", runnable: true }]
|
|
1744
1839
|
});
|
|
1745
1840
|
}
|
|
1841
|
+
function gatewayRequestPolicyForUpstreamModel(upstreamModelId) {
|
|
1842
|
+
const model = Object.values(OPENGENI_GATEWAY_MODELS).find(
|
|
1843
|
+
(candidate) => candidate.upstreamModelId === upstreamModelId
|
|
1844
|
+
);
|
|
1845
|
+
if (!model) {
|
|
1846
|
+
return void 0;
|
|
1847
|
+
}
|
|
1848
|
+
return {
|
|
1849
|
+
gateway: {
|
|
1850
|
+
only: [...model.providers],
|
|
1851
|
+
caching: model.implicitCaching ? "auto" : "none"
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
function gatewayModelCapabilities(settings, input) {
|
|
1856
|
+
const legacy = legacyModelCapabilities(settings, {
|
|
1857
|
+
reasoningEffort: true,
|
|
1858
|
+
hostedWebSearch: false
|
|
1859
|
+
});
|
|
1860
|
+
return normalizeCapabilities({
|
|
1861
|
+
...legacy,
|
|
1862
|
+
functionCalling: { upstream: "supported", runnable: true },
|
|
1863
|
+
inputModalities: input.vision ? ["text", "image"] : ["text"],
|
|
1864
|
+
transports: {
|
|
1865
|
+
...legacy.transports,
|
|
1866
|
+
sse: { upstream: "supported", runnable: true }
|
|
1867
|
+
},
|
|
1868
|
+
promptCaching: input.implicitCaching ? { upstream: "supported", runnable: true, mode: "implicit" } : { upstream: "unsupported", runnable: false, mode: "none" },
|
|
1869
|
+
// Both Gateway products expose one reviewed route policy and no separately
|
|
1870
|
+
// billed latency mode.
|
|
1871
|
+
latencyModes: [{ id: "standard", upstream: "supported", runnable: true }]
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1874
|
+
function gatewayRegistryProvider(settings, input) {
|
|
1875
|
+
const workspace = input.kind === "vercel-gateway-workspace";
|
|
1876
|
+
const models = [OPENGENI_GATEWAY_MODELS.deepseek, OPENGENI_GATEWAY_MODELS.kimi].map((model) => {
|
|
1877
|
+
const kimi = model === OPENGENI_GATEWAY_MODELS.kimi;
|
|
1878
|
+
return {
|
|
1879
|
+
id: workspace ? model.workspaceProductId : model.productId,
|
|
1880
|
+
upstreamModelId: model.upstreamModelId,
|
|
1881
|
+
label: model.label,
|
|
1882
|
+
capabilities: gatewayModelCapabilities(settings, {
|
|
1883
|
+
implicitCaching: model.implicitCaching,
|
|
1884
|
+
vision: kimi
|
|
1885
|
+
}),
|
|
1886
|
+
contextWindowTokens: 1e6,
|
|
1887
|
+
effectiveContextWindowTokens: 9e5,
|
|
1888
|
+
autoCompactTokenLimit: 85e4,
|
|
1889
|
+
toolOutputTruncationTokens: settings.modelToolOutputTruncationTokens
|
|
1890
|
+
};
|
|
1891
|
+
});
|
|
1892
|
+
return {
|
|
1893
|
+
kind: input.kind,
|
|
1894
|
+
id: workspace ? WORKSPACE_GATEWAY_PROVIDER_ID : OPENGENI_GATEWAY_PROVIDER_ID,
|
|
1895
|
+
label: workspace ? "Your Gateway" : "OpenGeni",
|
|
1896
|
+
// Responses preserves vision, reasoning items, and provider-native usage.
|
|
1897
|
+
// Model-specific compatibility stays at the reviewed request fence rather
|
|
1898
|
+
// than downgrading the whole provider wire.
|
|
1899
|
+
api: "responses",
|
|
1900
|
+
baseUrl: VERCEL_AI_GATEWAY_BASE_URL,
|
|
1901
|
+
...input.apiKey ? { apiKey: input.apiKey } : {},
|
|
1902
|
+
models
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
function configuredRegistryProviders(settings) {
|
|
1906
|
+
const providers = parseModelProvidersJson(settings.modelProvidersJson);
|
|
1907
|
+
if (!settings.vercelAiGatewayApiKey) {
|
|
1908
|
+
return providers;
|
|
1909
|
+
}
|
|
1910
|
+
if (providers.some((provider) => provider.id === OPENGENI_GATEWAY_PROVIDER_ID)) {
|
|
1911
|
+
throw new Error(
|
|
1912
|
+
`${OPENGENI_GATEWAY_PROVIDER_ID} is reserved for OPENGENI_VERCEL_AI_GATEWAY_API_KEY`
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1915
|
+
return [
|
|
1916
|
+
...providers,
|
|
1917
|
+
gatewayRegistryProvider(settings, {
|
|
1918
|
+
kind: "vercel-gateway-managed",
|
|
1919
|
+
apiKey: settings.vercelAiGatewayApiKey
|
|
1920
|
+
})
|
|
1921
|
+
];
|
|
1922
|
+
}
|
|
1923
|
+
function withWorkspaceGatewayCatalogProvider(settings) {
|
|
1924
|
+
const providers = parseModelProvidersJson(settings.modelProvidersJson);
|
|
1925
|
+
if (providers.some((provider) => provider.id === WORKSPACE_GATEWAY_PROVIDER_ID)) {
|
|
1926
|
+
return settings;
|
|
1927
|
+
}
|
|
1928
|
+
return {
|
|
1929
|
+
...settings,
|
|
1930
|
+
modelProvidersJson: JSON.stringify([
|
|
1931
|
+
...providers,
|
|
1932
|
+
gatewayRegistryProvider(settings, { kind: "vercel-gateway-workspace" })
|
|
1933
|
+
])
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
function withWorkspaceGatewayCredential(settings, apiKey) {
|
|
1937
|
+
if (!apiKey.trim()) {
|
|
1938
|
+
throw new Error("workspace AI Gateway credential is empty");
|
|
1939
|
+
}
|
|
1940
|
+
const catalogSettings = withWorkspaceGatewayCatalogProvider(settings);
|
|
1941
|
+
const providers = parseModelProvidersJson(catalogSettings.modelProvidersJson).map(
|
|
1942
|
+
(provider) => provider.id === WORKSPACE_GATEWAY_PROVIDER_ID ? { ...provider, apiKey } : provider
|
|
1943
|
+
);
|
|
1944
|
+
return { ...catalogSettings, modelProvidersJson: JSON.stringify(providers) };
|
|
1945
|
+
}
|
|
1746
1946
|
var GPT56_FAST_BILLING_MULTIPLIER_BPS = 2e4;
|
|
1747
1947
|
function productLabelForModelId(modelId) {
|
|
1748
1948
|
const slug = modelId.startsWith(CODEX_MODEL_ID_PREFIX) ? modelId.slice(CODEX_MODEL_ID_PREFIX.length) : modelId;
|
|
@@ -1772,6 +1972,10 @@ function builtinLatencyModesForModel(modelId) {
|
|
|
1772
1972
|
}
|
|
1773
1973
|
return [{ id: "standard", upstream: "unknown", runnable: true }];
|
|
1774
1974
|
}
|
|
1975
|
+
function builtinPromptCachingForModel(modelId) {
|
|
1976
|
+
const slug = modelId.startsWith(CODEX_MODEL_ID_PREFIX) ? modelId.slice(CODEX_MODEL_ID_PREFIX.length) : modelId;
|
|
1977
|
+
return slug.startsWith("gpt-5.6-") ? { upstream: "supported", runnable: true, mode: "implicit" } : void 0;
|
|
1978
|
+
}
|
|
1775
1979
|
function serviceTierForLatencyMode(providerId, latencyMode) {
|
|
1776
1980
|
if (latencyMode === "standard") {
|
|
1777
1981
|
return void 0;
|
|
@@ -1806,10 +2010,22 @@ function assertLatencyModeRunnable(settings, modelId, latencyMode) {
|
|
|
1806
2010
|
}
|
|
1807
2011
|
}
|
|
1808
2012
|
function registryCredentialSource(provider) {
|
|
1809
|
-
|
|
2013
|
+
if (provider.kind === "codex-subscription") {
|
|
2014
|
+
return { kind: "connected_subscription", provider: "codex" };
|
|
2015
|
+
}
|
|
2016
|
+
if (provider.kind === "vercel-gateway-workspace") {
|
|
2017
|
+
return { kind: "workspace_connection", mechanism: "api_key" };
|
|
2018
|
+
}
|
|
2019
|
+
return { kind: "deployment", mechanism: "api_key" };
|
|
1810
2020
|
}
|
|
1811
2021
|
function registryBilling(provider) {
|
|
1812
|
-
|
|
2022
|
+
if (provider.kind === "codex-subscription") {
|
|
2023
|
+
return { upstreamPayer: "connected_subscription", metering: "external" };
|
|
2024
|
+
}
|
|
2025
|
+
if (provider.kind === "vercel-gateway-workspace") {
|
|
2026
|
+
return { upstreamPayer: "workspace", metering: "external" };
|
|
2027
|
+
}
|
|
2028
|
+
return { upstreamPayer: "deployment", metering: "opengeni_credits" };
|
|
1813
2029
|
}
|
|
1814
2030
|
function builtinCredentialSource(settings) {
|
|
1815
2031
|
if (settings.openaiProvider === "azure" && !settings.azureOpenaiApiKey) {
|
|
@@ -1866,6 +2082,7 @@ function definitionVersionFor(model, provider) {
|
|
|
1866
2082
|
billing: model.billing,
|
|
1867
2083
|
executionLimits: model.executionLimits,
|
|
1868
2084
|
capabilities: model.capabilities,
|
|
2085
|
+
...model.requestPolicy ? { requestPolicy: model.requestPolicy } : {},
|
|
1869
2086
|
pricing: model.pricing ?? null
|
|
1870
2087
|
});
|
|
1871
2088
|
return `sha256:${createHash("sha256").update("opengeni:model-definition:v1\n", "utf8").update(digestInput, "utf8").digest("hex")}`;
|
|
@@ -1895,7 +2112,7 @@ function configuredProviders(settings) {
|
|
|
1895
2112
|
builtin.baseUrl = settings.openaiBaseUrl ? normalizeRegistryBaseUrl(settings.openaiBaseUrl, builtin.id) : void 0;
|
|
1896
2113
|
builtin.apiKey = settings.openaiApiKey;
|
|
1897
2114
|
}
|
|
1898
|
-
const registry =
|
|
2115
|
+
const registry = configuredRegistryProviders(settings).map(
|
|
1899
2116
|
(provider) => ({
|
|
1900
2117
|
id: provider.id,
|
|
1901
2118
|
label: provider.label ?? provider.id,
|
|
@@ -1931,6 +2148,9 @@ function withCodexCatalogProvider(settings) {
|
|
|
1931
2148
|
reasoningEffort: true,
|
|
1932
2149
|
hostedWebSearch: true
|
|
1933
2150
|
}),
|
|
2151
|
+
...builtinPromptCachingForModel(`${CODEX_MODEL_ID_PREFIX}${slug}`) ? {
|
|
2152
|
+
promptCaching: builtinPromptCachingForModel(`${CODEX_MODEL_ID_PREFIX}${slug}`)
|
|
2153
|
+
} : {},
|
|
1934
2154
|
latencyModes: builtinLatencyModesForModel(`${CODEX_MODEL_ID_PREFIX}${slug}`)
|
|
1935
2155
|
};
|
|
1936
2156
|
return {
|
|
@@ -1961,6 +2181,9 @@ function policyProviderIdForModel(settings, modelId) {
|
|
|
1961
2181
|
if (canonicalModelId.startsWith(CODEX_MODEL_ID_PREFIX)) {
|
|
1962
2182
|
return CODEX_PROVIDER_ID;
|
|
1963
2183
|
}
|
|
2184
|
+
if (canonicalModelId.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX)) {
|
|
2185
|
+
return WORKSPACE_GATEWAY_PROVIDER_ID;
|
|
2186
|
+
}
|
|
1964
2187
|
const configured = configuredModels(settings).find((model) => model.id === canonicalModelId);
|
|
1965
2188
|
return configured?.providerId ?? builtinProviderId(settings);
|
|
1966
2189
|
}
|
|
@@ -1973,9 +2196,11 @@ function resolvedExecutionLimits(settings, model) {
|
|
|
1973
2196
|
};
|
|
1974
2197
|
}
|
|
1975
2198
|
function finalizeConfiguredModel(settings, provider, input) {
|
|
2199
|
+
const requestPolicy = provider.kind === "vercel-gateway-managed" || provider.kind === "vercel-gateway-workspace" ? gatewayRequestPolicyForUpstreamModel(input.upstreamModelId) : void 0;
|
|
1976
2200
|
const modelWithoutVersion = {
|
|
1977
2201
|
schemaVersion: 1,
|
|
1978
2202
|
...input,
|
|
2203
|
+
...requestPolicy ? { requestPolicy } : {},
|
|
1979
2204
|
executionLimits: resolvedExecutionLimits(settings, input)
|
|
1980
2205
|
};
|
|
1981
2206
|
return {
|
|
@@ -2020,7 +2245,7 @@ function configuredModels(settings) {
|
|
|
2020
2245
|
const providers = configuredProviders(settings);
|
|
2021
2246
|
const providerById = new Map(providers.map((provider) => [provider.id, provider]));
|
|
2022
2247
|
const pricingSchedules = configuredModelPricingSchedules(settings);
|
|
2023
|
-
const parsedRegistry =
|
|
2248
|
+
const parsedRegistry = configuredRegistryProviders(settings);
|
|
2024
2249
|
const registryOwnedIds = new Set(
|
|
2025
2250
|
parsedRegistry.flatMap((provider) => provider.models.map((model) => model.id))
|
|
2026
2251
|
);
|
|
@@ -2041,6 +2266,7 @@ function configuredModels(settings) {
|
|
|
2041
2266
|
reasoningEffort: true,
|
|
2042
2267
|
hostedWebSearch: settings.webSearchEnabled
|
|
2043
2268
|
}),
|
|
2269
|
+
...builtinPromptCachingForModel(id) ? { promptCaching: builtinPromptCachingForModel(id) } : {},
|
|
2044
2270
|
latencyModes: builtinLatencyModesForModel(id)
|
|
2045
2271
|
};
|
|
2046
2272
|
return finalizeConfiguredModel(settings, builtinProvider, {
|
|
@@ -2129,7 +2355,13 @@ function resolveModelProvider(settings, modelId) {
|
|
|
2129
2355
|
return { provider, model };
|
|
2130
2356
|
}
|
|
2131
2357
|
function settingsForTurnExecutionPolicy(settings, modelId) {
|
|
2132
|
-
|
|
2358
|
+
if (settings.codexSubscriptionEnabled && modelId.startsWith(CODEX_MODEL_ID_PREFIX)) {
|
|
2359
|
+
return withCodexCatalogProvider(settings);
|
|
2360
|
+
}
|
|
2361
|
+
if (modelId.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX)) {
|
|
2362
|
+
return withWorkspaceGatewayCatalogProvider(settings);
|
|
2363
|
+
}
|
|
2364
|
+
return settings;
|
|
2133
2365
|
}
|
|
2134
2366
|
function resolveTurnExecutionPolicyV1(settings, input) {
|
|
2135
2367
|
const catalogSettings = settingsForTurnExecutionPolicy(settings, input.modelId);
|
|
@@ -2193,7 +2425,7 @@ function configuredModelPricingSchedules(settings) {
|
|
|
2193
2425
|
])
|
|
2194
2426
|
);
|
|
2195
2427
|
const registry = {};
|
|
2196
|
-
for (const provider of
|
|
2428
|
+
for (const provider of configuredRegistryProviders(settings)) {
|
|
2197
2429
|
for (const model of provider.models) {
|
|
2198
2430
|
if (model.pricing) {
|
|
2199
2431
|
registry[model.id] = normalizeModelPricingSchedule(model.pricing);
|
|
@@ -2307,6 +2539,28 @@ function calculateModelUsageCostMicros(settings, model, usage, options) {
|
|
|
2307
2539
|
}
|
|
2308
2540
|
return total;
|
|
2309
2541
|
}
|
|
2542
|
+
function calculateGatewayReportedCostMicros(settings, model, inferenceCostUsd, options) {
|
|
2543
|
+
const schedule = configuredModelPricingSchedules(settings)[model];
|
|
2544
|
+
if (!schedule) {
|
|
2545
|
+
throw new Error(`Missing model pricing for ${model}`);
|
|
2546
|
+
}
|
|
2547
|
+
const pricing = selectModelPricing(schedule, positiveInt(options?.inputTokens));
|
|
2548
|
+
const match = /^(0|[1-9]\d*)(?:\.(\d{1,18}))?$/.exec(inferenceCostUsd);
|
|
2549
|
+
if (!match) {
|
|
2550
|
+
throw new Error("Invalid AI Gateway inference cost");
|
|
2551
|
+
}
|
|
2552
|
+
const fraction = match[2] ?? "";
|
|
2553
|
+
const decimalDigits = BigInt(`${match[1]}${fraction}`);
|
|
2554
|
+
const decimalScale = 10n ** BigInt(fraction.length);
|
|
2555
|
+
const marginBps = BigInt(1e4 + (pricing.marginBps ?? 0));
|
|
2556
|
+
const numerator = decimalDigits * 1000000n * marginBps;
|
|
2557
|
+
const denominator = decimalScale * 10000n;
|
|
2558
|
+
const micros = (numerator + denominator - 1n) / denominator;
|
|
2559
|
+
if (micros > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
2560
|
+
throw new Error("AI Gateway inference cost exceeds the supported billing range");
|
|
2561
|
+
}
|
|
2562
|
+
return Number(micros);
|
|
2563
|
+
}
|
|
2310
2564
|
function configuredAllowedReasoningEfforts(settings) {
|
|
2311
2565
|
return uniqueValues([
|
|
2312
2566
|
settings.openaiReasoningEffort,
|
|
@@ -3132,6 +3386,11 @@ function validateSettings(settings) {
|
|
|
3132
3386
|
const builtinId = builtinProviderId(settings);
|
|
3133
3387
|
const providerIds = /* @__PURE__ */ new Set();
|
|
3134
3388
|
for (const provider of registryProviders) {
|
|
3389
|
+
if (provider.kind === "vercel-gateway-managed" || provider.kind === "vercel-gateway-workspace") {
|
|
3390
|
+
throw new Error(
|
|
3391
|
+
`OPENGENI_MODEL_PROVIDERS_JSON provider kind ${provider.kind} is reserved for the reviewed AI Gateway broker`
|
|
3392
|
+
);
|
|
3393
|
+
}
|
|
3135
3394
|
if (provider.id === builtinId) {
|
|
3136
3395
|
throw new Error(
|
|
3137
3396
|
`OPENGENI_MODEL_PROVIDERS_JSON provider id ${provider.id} collides with the built-in provider id`
|
|
@@ -3143,7 +3402,7 @@ function validateSettings(settings) {
|
|
|
3143
3402
|
);
|
|
3144
3403
|
}
|
|
3145
3404
|
providerIds.add(provider.id);
|
|
3146
|
-
if (!resolveProviderApiKey(provider)) {
|
|
3405
|
+
if (provider.kind !== "codex-subscription" && !resolveProviderApiKey(provider)) {
|
|
3147
3406
|
throw new Error(
|
|
3148
3407
|
`OPENGENI_MODEL_PROVIDERS_JSON provider ${provider.id} requires a resolvable API key (set apiKey or apiKeyEnv)`
|
|
3149
3408
|
);
|
|
@@ -3235,6 +3494,8 @@ function delay(ms) {
|
|
|
3235
3494
|
}
|
|
3236
3495
|
export {
|
|
3237
3496
|
AGENT_INSTRUCTIONS_CORE_PLACEHOLDER,
|
|
3497
|
+
AI_GATEWAY_REALTIME_MODELS,
|
|
3498
|
+
CODEX_REALTIME_MODEL_ID,
|
|
3238
3499
|
CapabilityStateV1Schema,
|
|
3239
3500
|
CapabilitySupportV1,
|
|
3240
3501
|
DEFAULT_AGENT_INSTRUCTIONS,
|
|
@@ -3242,12 +3503,23 @@ export {
|
|
|
3242
3503
|
McpServerConnectionRefSchema,
|
|
3243
3504
|
ModelCapabilitiesV1Schema,
|
|
3244
3505
|
ModelProviderApi,
|
|
3506
|
+
OPENGENI_GATEWAY_MODELS,
|
|
3507
|
+
OPENGENI_GATEWAY_PROVIDER_ID,
|
|
3508
|
+
OPENGENI_REALTIME_MODEL_ID_PREFIX,
|
|
3245
3509
|
RegistryProviderKind,
|
|
3246
3510
|
SANDBOX_REQUIRED_ENV,
|
|
3247
3511
|
SocialOAuthClientConfigSchema,
|
|
3512
|
+
VERCEL_AI_GATEWAY_AI_SDK_BASE_URL,
|
|
3513
|
+
VERCEL_AI_GATEWAY_BASE_URL,
|
|
3514
|
+
VERCEL_AI_GATEWAY_CONNECTION_DOMAIN,
|
|
3515
|
+
VERCEL_AI_GATEWAY_CONNECTION_ROLE,
|
|
3516
|
+
WORKSPACE_GATEWAY_MODEL_ID_PREFIX,
|
|
3517
|
+
WORKSPACE_GATEWAY_PROVIDER_ID,
|
|
3518
|
+
WORKSPACE_REALTIME_MODEL_ID_PREFIX,
|
|
3248
3519
|
applyGitAuthPointerEnvironment,
|
|
3249
3520
|
assertTurnExecutionPolicyMatchesConfigV1,
|
|
3250
3521
|
builtinProviderId,
|
|
3522
|
+
calculateGatewayReportedCostMicros,
|
|
3251
3523
|
calculateModelUsageCostMicros,
|
|
3252
3524
|
canonicalizeConfiguredModelId,
|
|
3253
3525
|
collectGitIdentityEnvironment,
|
|
@@ -3267,6 +3539,7 @@ export {
|
|
|
3267
3539
|
environmentsEncryptionKeyBytes,
|
|
3268
3540
|
firstPartyMcpBaseUrl,
|
|
3269
3541
|
firstPartyMcpWorkspaceUrl,
|
|
3542
|
+
gatewayRequestPolicyForUpstreamModel,
|
|
3270
3543
|
getSettings,
|
|
3271
3544
|
hasGitCredentialRepositorySelection,
|
|
3272
3545
|
hasGitHubRepositorySelection,
|
|
@@ -3283,6 +3556,7 @@ export {
|
|
|
3283
3556
|
policyProviderIdForModel,
|
|
3284
3557
|
productLabelForModelId,
|
|
3285
3558
|
requiredSandboxEnvForBackend,
|
|
3559
|
+
resolveAiGatewayRealtimeModel,
|
|
3286
3560
|
resolveEnrollmentSigningSecret,
|
|
3287
3561
|
resolveFirstPartyDelegationSecret,
|
|
3288
3562
|
resolveModelProvider,
|
|
@@ -3309,6 +3583,8 @@ export {
|
|
|
3309
3583
|
streamTokenDegraded,
|
|
3310
3584
|
temporalConnectionOptions,
|
|
3311
3585
|
voiceInputDeploymentConfigured,
|
|
3312
|
-
withCodexCatalogProvider
|
|
3586
|
+
withCodexCatalogProvider,
|
|
3587
|
+
withWorkspaceGatewayCatalogProvider,
|
|
3588
|
+
withWorkspaceGatewayCredential
|
|
3313
3589
|
};
|
|
3314
3590
|
//# sourceMappingURL=index.js.map
|