@llmops/gateway 0.2.7-beta.2 → 0.2.7
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.cjs +10 -232
- package/dist/index.d.cts +1 -33
- package/dist/index.d.mts +1 -33
- package/dist/index.mjs +10 -228
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4304,57 +4304,8 @@ function _instanceof(cls, params = {}) {
|
|
|
4304
4304
|
return inst;
|
|
4305
4305
|
}
|
|
4306
4306
|
|
|
4307
|
-
//#endregion
|
|
4308
|
-
//#region src/providers/providerIdMapping.ts
|
|
4309
|
-
/**
|
|
4310
|
-
* Provider ID mapping between models.dev and Portkey gateway.
|
|
4311
|
-
*
|
|
4312
|
-
* models.dev uses different provider IDs than Portkey for some providers.
|
|
4313
|
-
* This mapping allows converting from models.dev IDs to Portkey gateway IDs.
|
|
4314
|
-
*
|
|
4315
|
-
* Key: models.dev provider ID
|
|
4316
|
-
* Value: Portkey gateway provider ID
|
|
4317
|
-
*/
|
|
4318
|
-
const MODELS_DEV_TO_PORTKEY_PROVIDER_MAP = {
|
|
4319
|
-
"azure-cognitive-services": "azure-ai",
|
|
4320
|
-
azure: "azure-openai"
|
|
4321
|
-
};
|
|
4322
|
-
/**
|
|
4323
|
-
* Reverse mapping from Portkey to models.dev
|
|
4324
|
-
*/
|
|
4325
|
-
const PORTKEY_TO_MODELS_DEV_PROVIDER_MAP = Object.fromEntries(Object.entries(MODELS_DEV_TO_PORTKEY_PROVIDER_MAP).map(([k, v]) => [v, k]));
|
|
4326
|
-
/**
|
|
4327
|
-
* Get the Portkey gateway provider ID for a given models.dev provider ID.
|
|
4328
|
-
* Returns the original ID if no mapping exists.
|
|
4329
|
-
*
|
|
4330
|
-
* @param modelsDevProviderId - The provider ID from models.dev
|
|
4331
|
-
* @returns The corresponding Portkey gateway provider ID
|
|
4332
|
-
*/
|
|
4333
|
-
function getPortkeyProviderId(modelsDevProviderId) {
|
|
4334
|
-
return MODELS_DEV_TO_PORTKEY_PROVIDER_MAP[modelsDevProviderId] ?? modelsDevProviderId;
|
|
4335
|
-
}
|
|
4336
|
-
/**
|
|
4337
|
-
* Get the models.dev provider ID for a given Portkey gateway provider ID.
|
|
4338
|
-
* Returns the original ID if no mapping exists.
|
|
4339
|
-
*
|
|
4340
|
-
* @param portkeyProviderId - The provider ID from Portkey gateway
|
|
4341
|
-
* @returns The corresponding models.dev provider ID
|
|
4342
|
-
*/
|
|
4343
|
-
function getModelsDevProviderId(portkeyProviderId) {
|
|
4344
|
-
return PORTKEY_TO_MODELS_DEV_PROVIDER_MAP[portkeyProviderId] ?? portkeyProviderId;
|
|
4345
|
-
}
|
|
4346
|
-
|
|
4347
4307
|
//#endregion
|
|
4348
4308
|
//#region src/middlewares/requestValidator/schema/config.ts
|
|
4349
|
-
/**
|
|
4350
|
-
* Check if a provider ID is valid.
|
|
4351
|
-
* Accepts both Portkey provider IDs and models.dev provider IDs that can be mapped.
|
|
4352
|
-
*/
|
|
4353
|
-
function isValidProvider$1(value) {
|
|
4354
|
-
if (VALID_PROVIDERS.includes(value)) return true;
|
|
4355
|
-
const mappedId = getPortkeyProviderId(value);
|
|
4356
|
-
return VALID_PROVIDERS.includes(mappedId);
|
|
4357
|
-
}
|
|
4358
4309
|
const configSchema = object({
|
|
4359
4310
|
strategy: object({
|
|
4360
4311
|
mode: string().refine((value) => [
|
|
@@ -4370,7 +4321,7 @@ const configSchema = object({
|
|
|
4370
4321
|
})).optional(),
|
|
4371
4322
|
default: string().optional()
|
|
4372
4323
|
}).optional(),
|
|
4373
|
-
provider: string().refine((value) =>
|
|
4324
|
+
provider: string().refine((value) => VALID_PROVIDERS.includes(value), { message: `Invalid 'provider' value. Must be one of: ${VALID_PROVIDERS.join(", ")}` }).optional(),
|
|
4374
4325
|
api_key: string().optional(),
|
|
4375
4326
|
aws_secret_access_key: string().optional(),
|
|
4376
4327
|
aws_access_key_id: string().optional(),
|
|
@@ -4400,17 +4351,8 @@ const configSchema = object({
|
|
|
4400
4351
|
vertex_service_account_json: object({}).catchall(string()).optional(),
|
|
4401
4352
|
openai_project: string().optional(),
|
|
4402
4353
|
openai_organization: string().optional(),
|
|
4403
|
-
azure_resource_name: string().optional(),
|
|
4404
|
-
azure_deployment_id: string().optional(),
|
|
4405
|
-
azure_api_version: string().optional(),
|
|
4406
4354
|
azure_model_name: string().optional(),
|
|
4407
4355
|
azure_auth_mode: string().optional(),
|
|
4408
|
-
azure_ad_token: string().optional(),
|
|
4409
|
-
azure_managed_client_id: string().optional(),
|
|
4410
|
-
azure_workload_client_id: string().optional(),
|
|
4411
|
-
azure_entra_client_id: string().optional(),
|
|
4412
|
-
azure_entra_client_secret: string().optional(),
|
|
4413
|
-
azure_entra_tenant_id: string().optional(),
|
|
4414
4356
|
strict_open_ai_compliance: boolean().optional()
|
|
4415
4357
|
}).refine((value) => {
|
|
4416
4358
|
const hasProviderApiKey = value.provider !== void 0 && value.api_key !== void 0;
|
|
@@ -4505,15 +4447,6 @@ const Environment = (c) => {
|
|
|
4505
4447
|
|
|
4506
4448
|
//#endregion
|
|
4507
4449
|
//#region src/middlewares/requestValidator/index.ts
|
|
4508
|
-
/**
|
|
4509
|
-
* Check if a provider ID is valid.
|
|
4510
|
-
* Accepts both Portkey provider IDs and models.dev provider IDs that can be mapped.
|
|
4511
|
-
*/
|
|
4512
|
-
function isValidProvider(value) {
|
|
4513
|
-
if (VALID_PROVIDERS.includes(value)) return true;
|
|
4514
|
-
const mappedId = getPortkeyProviderId(value);
|
|
4515
|
-
return VALID_PROVIDERS.includes(mappedId);
|
|
4516
|
-
}
|
|
4517
4450
|
const VALIDATION_PATTERNS = {
|
|
4518
4451
|
CONTROL_CHARS: /[\x00-\x1F\x7F]/,
|
|
4519
4452
|
SUSPICIOUS_CHARS: /[\s<>{}|\\^`]/,
|
|
@@ -4619,7 +4552,7 @@ const requestValidator = (c, next) => {
|
|
|
4619
4552
|
status: 400,
|
|
4620
4553
|
headers: { "content-type": "application/json" }
|
|
4621
4554
|
});
|
|
4622
|
-
if (requestHeaders[`x-${POWERED_BY}-provider`] && !
|
|
4555
|
+
if (requestHeaders[`x-${POWERED_BY}-provider`] && !VALID_PROVIDERS.includes(requestHeaders[`x-${POWERED_BY}-provider`])) return new Response(JSON.stringify({
|
|
4623
4556
|
status: "failure",
|
|
4624
4557
|
message: `Invalid provider passed`
|
|
4625
4558
|
}), {
|
|
@@ -10112,140 +10045,8 @@ function convertKeysToCamelCase(obj, parentKeysToPreserve = []) {
|
|
|
10112
10045
|
}
|
|
10113
10046
|
}
|
|
10114
10047
|
|
|
10115
|
-
//#endregion
|
|
10116
|
-
//#region src/shared/utils/logger.ts
|
|
10117
|
-
/**
|
|
10118
|
-
* @file src/utils/logger.ts
|
|
10119
|
-
* Configurable logger utility for MCP Gateway
|
|
10120
|
-
*/
|
|
10121
|
-
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
10122
|
-
LogLevel$1[LogLevel$1["ERROR"] = 0] = "ERROR";
|
|
10123
|
-
LogLevel$1[LogLevel$1["CRITICAL"] = 1] = "CRITICAL";
|
|
10124
|
-
LogLevel$1[LogLevel$1["WARN"] = 2] = "WARN";
|
|
10125
|
-
LogLevel$1[LogLevel$1["INFO"] = 3] = "INFO";
|
|
10126
|
-
LogLevel$1[LogLevel$1["DEBUG"] = 4] = "DEBUG";
|
|
10127
|
-
return LogLevel$1;
|
|
10128
|
-
}({});
|
|
10129
|
-
var Logger = class Logger {
|
|
10130
|
-
config;
|
|
10131
|
-
colors = {
|
|
10132
|
-
error: "\x1B[31m",
|
|
10133
|
-
critical: "\x1B[35m",
|
|
10134
|
-
warn: "\x1B[33m",
|
|
10135
|
-
info: "\x1B[36m",
|
|
10136
|
-
debug: "\x1B[37m",
|
|
10137
|
-
reset: "\x1B[0m"
|
|
10138
|
-
};
|
|
10139
|
-
constructor(config$1) {
|
|
10140
|
-
this.config = {
|
|
10141
|
-
timestamp: true,
|
|
10142
|
-
colors: true,
|
|
10143
|
-
...config$1
|
|
10144
|
-
};
|
|
10145
|
-
}
|
|
10146
|
-
formatMessage(level, message) {
|
|
10147
|
-
const parts = [];
|
|
10148
|
-
if (this.config.timestamp) parts.push(`[${(/* @__PURE__ */ new Date()).toISOString()}]`);
|
|
10149
|
-
if (this.config.prefix) parts.push(`[${this.config.prefix}]`);
|
|
10150
|
-
parts.push(`[${level.toUpperCase()}]`);
|
|
10151
|
-
parts.push(message);
|
|
10152
|
-
return parts.join(" ");
|
|
10153
|
-
}
|
|
10154
|
-
log(level, levelName, message, data) {
|
|
10155
|
-
if (level > this.config.level) return;
|
|
10156
|
-
const formattedMessage = this.formatMessage(levelName, message);
|
|
10157
|
-
const color = this.config.colors ? this.colors[levelName] : "";
|
|
10158
|
-
const reset = this.config.colors ? this.colors.reset : "";
|
|
10159
|
-
if (data !== void 0) console.log(`${color}${formattedMessage}${reset}`, data);
|
|
10160
|
-
else console.log(`${color}${formattedMessage}${reset}`);
|
|
10161
|
-
}
|
|
10162
|
-
error(message, error) {
|
|
10163
|
-
if (error instanceof Error) {
|
|
10164
|
-
this.log(LogLevel.ERROR, "error", `${message}: ${error.message}`);
|
|
10165
|
-
if (this.config.level >= LogLevel.DEBUG) console.error(error.stack);
|
|
10166
|
-
} else if (error) this.log(LogLevel.ERROR, "error", message, error);
|
|
10167
|
-
else this.log(LogLevel.ERROR, "error", message);
|
|
10168
|
-
}
|
|
10169
|
-
critical(message, data) {
|
|
10170
|
-
this.log(LogLevel.CRITICAL, "critical", message, data);
|
|
10171
|
-
}
|
|
10172
|
-
warn(message, data) {
|
|
10173
|
-
this.log(LogLevel.WARN, "warn", message, data);
|
|
10174
|
-
}
|
|
10175
|
-
info(message, data) {
|
|
10176
|
-
this.log(LogLevel.INFO, "info", message, data);
|
|
10177
|
-
}
|
|
10178
|
-
debug(message, data) {
|
|
10179
|
-
this.log(LogLevel.DEBUG, "debug", message, data);
|
|
10180
|
-
}
|
|
10181
|
-
createChild(prefix) {
|
|
10182
|
-
return new Logger({
|
|
10183
|
-
...this.config,
|
|
10184
|
-
prefix: this.config.prefix ? `${this.config.prefix}:${prefix}` : prefix
|
|
10185
|
-
});
|
|
10186
|
-
}
|
|
10187
|
-
};
|
|
10188
|
-
const defaultConfig = {
|
|
10189
|
-
level: process.env.LOG_LEVEL ? LogLevel[process.env.LOG_LEVEL.toUpperCase()] || LogLevel.ERROR : process.env.NODE_ENV === "production" ? LogLevel.ERROR : LogLevel.INFO,
|
|
10190
|
-
timestamp: process.env.LOG_TIMESTAMP !== "false",
|
|
10191
|
-
colors: process.env.LOG_COLORS !== "false" && process.env.NODE_ENV !== "production"
|
|
10192
|
-
};
|
|
10193
|
-
const logger$7 = new Logger(defaultConfig);
|
|
10194
|
-
function createLogger(prefix) {
|
|
10195
|
-
return logger$7.createChild(prefix);
|
|
10196
|
-
}
|
|
10197
|
-
|
|
10198
10048
|
//#endregion
|
|
10199
10049
|
//#region src/handlers/retryHandler.ts
|
|
10200
|
-
const logger$6 = createLogger("ProviderRequest");
|
|
10201
|
-
/**
|
|
10202
|
-
* Sanitizes headers by masking sensitive values like API keys and tokens
|
|
10203
|
-
*/
|
|
10204
|
-
function sanitizeHeaders(headers) {
|
|
10205
|
-
if (!headers) return {};
|
|
10206
|
-
const sanitized = {};
|
|
10207
|
-
const sensitivePatterns = /^(authorization|x-api-key|api-key|x-.*-key|x-.*-token|x-.*-secret|bearer)$/i;
|
|
10208
|
-
const headersObj = headers instanceof Headers ? Object.fromEntries([...headers]) : Array.isArray(headers) ? Object.fromEntries(headers) : headers;
|
|
10209
|
-
for (const [key, value] of Object.entries(headersObj)) if (sensitivePatterns.test(key)) sanitized[key] = value.length > 12 ? `${value.substring(0, 8)}...****` : "****";
|
|
10210
|
-
else sanitized[key] = value;
|
|
10211
|
-
return sanitized;
|
|
10212
|
-
}
|
|
10213
|
-
/**
|
|
10214
|
-
* Logs the outgoing request to the provider
|
|
10215
|
-
*/
|
|
10216
|
-
function logProviderRequest(url, options, attempt) {
|
|
10217
|
-
const sanitizedHeaders = sanitizeHeaders(options.headers);
|
|
10218
|
-
let bodyPreview;
|
|
10219
|
-
if (options.body) if (typeof options.body === "string") try {
|
|
10220
|
-
const parsed = JSON.parse(options.body);
|
|
10221
|
-
const bodyStr = JSON.stringify(parsed, null, 2);
|
|
10222
|
-
bodyPreview = bodyStr.length > 2e3 ? `${bodyStr.substring(0, 2e3)}...` : bodyStr;
|
|
10223
|
-
} catch {
|
|
10224
|
-
bodyPreview = options.body.length > 500 ? `${options.body.substring(0, 500)}...` : options.body;
|
|
10225
|
-
}
|
|
10226
|
-
else if (options.body instanceof FormData) bodyPreview = "[FormData]";
|
|
10227
|
-
else if (options.body instanceof ArrayBuffer) bodyPreview = `[ArrayBuffer: ${options.body.byteLength} bytes]`;
|
|
10228
|
-
else if (options.body instanceof ReadableStream) bodyPreview = "[ReadableStream]";
|
|
10229
|
-
else bodyPreview = "[Unknown body type]";
|
|
10230
|
-
logger$6.debug(`Provider Request (attempt ${attempt})`, {
|
|
10231
|
-
url,
|
|
10232
|
-
method: options.method || "GET",
|
|
10233
|
-
headers: sanitizedHeaders,
|
|
10234
|
-
body: bodyPreview
|
|
10235
|
-
});
|
|
10236
|
-
}
|
|
10237
|
-
/**
|
|
10238
|
-
* Logs the provider response
|
|
10239
|
-
*/
|
|
10240
|
-
function logProviderResponse(url, response, attempt, durationMs) {
|
|
10241
|
-
logger$6.debug(`Provider Response (attempt ${attempt})`, {
|
|
10242
|
-
url,
|
|
10243
|
-
status: response.status,
|
|
10244
|
-
statusText: response.statusText,
|
|
10245
|
-
durationMs,
|
|
10246
|
-
headers: Object.fromEntries([...response.headers])
|
|
10247
|
-
});
|
|
10248
|
-
}
|
|
10249
10050
|
async function fetchWithTimeout(url, options, timeout, requestHandler) {
|
|
10250
10051
|
const controller = new AbortController();
|
|
10251
10052
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
@@ -10294,14 +10095,10 @@ const retryRequest = async (url, options, retryCount, statusCodesToRetry, timeou
|
|
|
10294
10095
|
try {
|
|
10295
10096
|
await (0, async_retry.default)(async (bail, attempt, rateLimiter) => {
|
|
10296
10097
|
try {
|
|
10297
|
-
logProviderRequest(url, options, attempt);
|
|
10298
|
-
const fetchStartTime = Date.now();
|
|
10299
10098
|
let response;
|
|
10300
10099
|
if (timeout) response = await fetchWithTimeout(url, options, timeout, requestHandler);
|
|
10301
10100
|
else if (requestHandler) response = await requestHandler();
|
|
10302
10101
|
else response = await fetch(url, options);
|
|
10303
|
-
const fetchDuration = Date.now() - fetchStartTime;
|
|
10304
|
-
logProviderResponse(url, response, attempt, fetchDuration);
|
|
10305
10102
|
if (statusCodesToRetry.includes(response.status)) {
|
|
10306
10103
|
const errorObj = new Error(await response.text());
|
|
10307
10104
|
errorObj.status = response.status;
|
|
@@ -10375,7 +10172,7 @@ const retryRequest = async (url, options, retryCount, statusCodesToRetry, timeou
|
|
|
10375
10172
|
|
|
10376
10173
|
//#endregion
|
|
10377
10174
|
//#region package.json
|
|
10378
|
-
var version = "0.2.7
|
|
10175
|
+
var version = "0.2.7";
|
|
10379
10176
|
|
|
10380
10177
|
//#endregion
|
|
10381
10178
|
//#region src/providers/bytez/api.ts
|
|
@@ -17293,7 +17090,7 @@ const transformToProviderRequest = (provider, params, requestBody, fn, requestHe
|
|
|
17293
17090
|
if (fn === "createFinetune" && [AZURE_OPEN_AI, FIREWORKS_AI].includes(provider)) return transformToProviderRequestBody(provider, requestBody, requestHeaders, providerOptions, fn);
|
|
17294
17091
|
if (requestBody instanceof FormData || requestBody instanceof ArrayBuffer) return requestBody;
|
|
17295
17092
|
if (fn === "proxy") return params;
|
|
17296
|
-
const providerAPIConfig = providers_default[
|
|
17093
|
+
const providerAPIConfig = providers_default[provider].api;
|
|
17297
17094
|
if (providerAPIConfig.transformToFormData && providerAPIConfig.transformToFormData({ gatewayRequestBody: params })) return transformToProviderRequestFormData(provider, params, fn, providerOptions);
|
|
17298
17095
|
return transformToProviderRequestJSON(provider, params, fn, providerOptions);
|
|
17299
17096
|
};
|
|
@@ -30254,7 +30051,7 @@ async function responseHandler(c, response, streamingMode, providerOptions, resp
|
|
|
30254
30051
|
let responseTransformerFunction;
|
|
30255
30052
|
const responseContentType = response.headers?.get("content-type");
|
|
30256
30053
|
const isSuccessStatusCode = [200, 246].includes(response.status);
|
|
30257
|
-
const provider =
|
|
30054
|
+
const provider = providerOptions.provider;
|
|
30258
30055
|
const providerConfig = providers_default[provider];
|
|
30259
30056
|
let providerTransformers = providers_default[provider]?.responseTransforms;
|
|
30260
30057
|
if (providerConfig?.getConfig) providerTransformers = providerConfig.getConfig({
|
|
@@ -30856,8 +30653,7 @@ var PreRequestValidatorService = class {
|
|
|
30856
30653
|
var ProviderContext = class {
|
|
30857
30654
|
constructor(provider) {
|
|
30858
30655
|
this.provider = provider;
|
|
30859
|
-
|
|
30860
|
-
if (!providers_default[this.provider]) throw new GatewayError(`Provider ${provider} not found`);
|
|
30656
|
+
if (!providers_default[provider]) throw new GatewayError(`Provider ${provider} not found`);
|
|
30861
30657
|
}
|
|
30862
30658
|
get providerConfig() {
|
|
30863
30659
|
return providers_default[this.provider];
|
|
@@ -31129,20 +30925,6 @@ var ResponseService = class {
|
|
|
31129
30925
|
|
|
31130
30926
|
//#endregion
|
|
31131
30927
|
//#region src/handlers/handlerUtils.ts
|
|
31132
|
-
/**
|
|
31133
|
-
* Normalizes Azure OpenAI config fields from JSON config format to provider format.
|
|
31134
|
-
* JSON config uses `azure_*` prefix (e.g., `azure_resource_name`) which converts to `azureResourceName`,
|
|
31135
|
-
* but the provider expects `resourceName`, `deploymentId`, etc.
|
|
31136
|
-
* This function recursively normalizes nested targets as well.
|
|
31137
|
-
*/
|
|
31138
|
-
function normalizeAzureConfig(config$1) {
|
|
31139
|
-
const normalized = { ...config$1 };
|
|
31140
|
-
if (normalized.azureResourceName && !normalized.resourceName) normalized.resourceName = normalized.azureResourceName;
|
|
31141
|
-
if (normalized.azureDeploymentId && !normalized.deploymentId) normalized.deploymentId = normalized.azureDeploymentId;
|
|
31142
|
-
if (normalized.azureApiVersion && !normalized.apiVersion) normalized.apiVersion = normalized.azureApiVersion;
|
|
31143
|
-
if (Array.isArray(normalized.targets)) normalized.targets = normalized.targets.map((target) => normalizeAzureConfig(target));
|
|
31144
|
-
return normalized;
|
|
31145
|
-
}
|
|
31146
30928
|
function constructRequestBody(requestContext, providerHeaders) {
|
|
31147
30929
|
const headerContentType = providerHeaders[HEADER_KEYS.CONTENT_TYPE];
|
|
31148
30930
|
const requestContentType = requestContext.getHeader(HEADER_KEYS.CONTENT_TYPE);
|
|
@@ -31656,7 +31438,7 @@ function constructConfigFromRequestHeaders(requestHeaders) {
|
|
|
31656
31438
|
...oracleConfig
|
|
31657
31439
|
};
|
|
31658
31440
|
}
|
|
31659
|
-
return
|
|
31441
|
+
return convertKeysToCamelCase(parsedConfigJson, [
|
|
31660
31442
|
"override_params",
|
|
31661
31443
|
"params",
|
|
31662
31444
|
"checks",
|
|
@@ -31671,7 +31453,7 @@ function constructConfigFromRequestHeaders(requestHeaders) {
|
|
|
31671
31453
|
"integrationDetails",
|
|
31672
31454
|
"virtualKeyDetails",
|
|
31673
31455
|
"cb_config"
|
|
31674
|
-
])
|
|
31456
|
+
]);
|
|
31675
31457
|
}
|
|
31676
31458
|
return {
|
|
31677
31459
|
provider: requestHeaders[`x-${POWERED_BY}-provider`],
|
|
@@ -32259,7 +32041,7 @@ async function realTimeHandler(c) {
|
|
|
32259
32041
|
try {
|
|
32260
32042
|
const requestHeaders = Object.fromEntries(c.req.raw.headers);
|
|
32261
32043
|
const providerOptions = constructConfigFromRequestHeaders(requestHeaders);
|
|
32262
|
-
const apiConfig = providers_default[
|
|
32044
|
+
const apiConfig = providers_default[providerOptions.provider ?? ""].api;
|
|
32263
32045
|
const url = getURLForOutgoingConnection(apiConfig, providerOptions, c.req.url, c);
|
|
32264
32046
|
const options = await getOptionsForOutgoingConnection(apiConfig, providerOptions, url, c);
|
|
32265
32047
|
const sessionOptions = {
|
|
@@ -33554,9 +33336,5 @@ app.delete("/v1/*", requestValidator, proxyHandler);
|
|
|
33554
33336
|
var src_default = app;
|
|
33555
33337
|
|
|
33556
33338
|
//#endregion
|
|
33557
|
-
exports.MODELS_DEV_TO_PORTKEY_PROVIDER_MAP = MODELS_DEV_TO_PORTKEY_PROVIDER_MAP;
|
|
33558
|
-
exports.PORTKEY_TO_MODELS_DEV_PROVIDER_MAP = PORTKEY_TO_MODELS_DEV_PROVIDER_MAP;
|
|
33559
33339
|
exports.Providers = providers_default;
|
|
33560
|
-
exports.default = src_default;
|
|
33561
|
-
exports.getModelsDevProviderId = getModelsDevProviderId;
|
|
33562
|
-
exports.getPortkeyProviderId = getPortkeyProviderId;
|
|
33340
|
+
exports.default = src_default;
|
package/dist/index.d.cts
CHANGED
|
@@ -423,38 +423,6 @@ interface ProviderConfigs {
|
|
|
423
423
|
}) => any;
|
|
424
424
|
}
|
|
425
425
|
//#endregion
|
|
426
|
-
//#region src/providers/providerIdMapping.d.ts
|
|
427
|
-
/**
|
|
428
|
-
* Provider ID mapping between models.dev and Portkey gateway.
|
|
429
|
-
*
|
|
430
|
-
* models.dev uses different provider IDs than Portkey for some providers.
|
|
431
|
-
* This mapping allows converting from models.dev IDs to Portkey gateway IDs.
|
|
432
|
-
*
|
|
433
|
-
* Key: models.dev provider ID
|
|
434
|
-
* Value: Portkey gateway provider ID
|
|
435
|
-
*/
|
|
436
|
-
declare const MODELS_DEV_TO_PORTKEY_PROVIDER_MAP: Record<string, string>;
|
|
437
|
-
/**
|
|
438
|
-
* Reverse mapping from Portkey to models.dev
|
|
439
|
-
*/
|
|
440
|
-
declare const PORTKEY_TO_MODELS_DEV_PROVIDER_MAP: Record<string, string>;
|
|
441
|
-
/**
|
|
442
|
-
* Get the Portkey gateway provider ID for a given models.dev provider ID.
|
|
443
|
-
* Returns the original ID if no mapping exists.
|
|
444
|
-
*
|
|
445
|
-
* @param modelsDevProviderId - The provider ID from models.dev
|
|
446
|
-
* @returns The corresponding Portkey gateway provider ID
|
|
447
|
-
*/
|
|
448
|
-
declare function getPortkeyProviderId(modelsDevProviderId: string): string;
|
|
449
|
-
/**
|
|
450
|
-
* Get the models.dev provider ID for a given Portkey gateway provider ID.
|
|
451
|
-
* Returns the original ID if no mapping exists.
|
|
452
|
-
*
|
|
453
|
-
* @param portkeyProviderId - The provider ID from Portkey gateway
|
|
454
|
-
* @returns The corresponding models.dev provider ID
|
|
455
|
-
*/
|
|
456
|
-
declare function getModelsDevProviderId(portkeyProviderId: string): string;
|
|
457
|
-
//#endregion
|
|
458
426
|
//#region src/providers/index.d.ts
|
|
459
427
|
declare const Providers: {
|
|
460
428
|
[key: string]: ProviderConfigs;
|
|
@@ -463,4 +431,4 @@ declare const Providers: {
|
|
|
463
431
|
//#region src/index.d.ts
|
|
464
432
|
declare const app: Hono<hono_types0.BlankEnv, hono_types0.BlankSchema, "/">;
|
|
465
433
|
//#endregion
|
|
466
|
-
export {
|
|
434
|
+
export { Providers, app as default };
|
package/dist/index.d.mts
CHANGED
|
@@ -423,38 +423,6 @@ interface ProviderConfigs {
|
|
|
423
423
|
}) => any;
|
|
424
424
|
}
|
|
425
425
|
//#endregion
|
|
426
|
-
//#region src/providers/providerIdMapping.d.ts
|
|
427
|
-
/**
|
|
428
|
-
* Provider ID mapping between models.dev and Portkey gateway.
|
|
429
|
-
*
|
|
430
|
-
* models.dev uses different provider IDs than Portkey for some providers.
|
|
431
|
-
* This mapping allows converting from models.dev IDs to Portkey gateway IDs.
|
|
432
|
-
*
|
|
433
|
-
* Key: models.dev provider ID
|
|
434
|
-
* Value: Portkey gateway provider ID
|
|
435
|
-
*/
|
|
436
|
-
declare const MODELS_DEV_TO_PORTKEY_PROVIDER_MAP: Record<string, string>;
|
|
437
|
-
/**
|
|
438
|
-
* Reverse mapping from Portkey to models.dev
|
|
439
|
-
*/
|
|
440
|
-
declare const PORTKEY_TO_MODELS_DEV_PROVIDER_MAP: Record<string, string>;
|
|
441
|
-
/**
|
|
442
|
-
* Get the Portkey gateway provider ID for a given models.dev provider ID.
|
|
443
|
-
* Returns the original ID if no mapping exists.
|
|
444
|
-
*
|
|
445
|
-
* @param modelsDevProviderId - The provider ID from models.dev
|
|
446
|
-
* @returns The corresponding Portkey gateway provider ID
|
|
447
|
-
*/
|
|
448
|
-
declare function getPortkeyProviderId(modelsDevProviderId: string): string;
|
|
449
|
-
/**
|
|
450
|
-
* Get the models.dev provider ID for a given Portkey gateway provider ID.
|
|
451
|
-
* Returns the original ID if no mapping exists.
|
|
452
|
-
*
|
|
453
|
-
* @param portkeyProviderId - The provider ID from Portkey gateway
|
|
454
|
-
* @returns The corresponding models.dev provider ID
|
|
455
|
-
*/
|
|
456
|
-
declare function getModelsDevProviderId(portkeyProviderId: string): string;
|
|
457
|
-
//#endregion
|
|
458
426
|
//#region src/providers/index.d.ts
|
|
459
427
|
declare const Providers: {
|
|
460
428
|
[key: string]: ProviderConfigs;
|
|
@@ -463,4 +431,4 @@ declare const Providers: {
|
|
|
463
431
|
//#region src/index.d.ts
|
|
464
432
|
declare const app: Hono<hono_types0.BlankEnv, hono_types0.BlankSchema, "/">;
|
|
465
433
|
//#endregion
|
|
466
|
-
export {
|
|
434
|
+
export { Providers, app as default };
|
package/dist/index.mjs
CHANGED
|
@@ -4277,57 +4277,8 @@ function _instanceof(cls, params = {}) {
|
|
|
4277
4277
|
return inst;
|
|
4278
4278
|
}
|
|
4279
4279
|
|
|
4280
|
-
//#endregion
|
|
4281
|
-
//#region src/providers/providerIdMapping.ts
|
|
4282
|
-
/**
|
|
4283
|
-
* Provider ID mapping between models.dev and Portkey gateway.
|
|
4284
|
-
*
|
|
4285
|
-
* models.dev uses different provider IDs than Portkey for some providers.
|
|
4286
|
-
* This mapping allows converting from models.dev IDs to Portkey gateway IDs.
|
|
4287
|
-
*
|
|
4288
|
-
* Key: models.dev provider ID
|
|
4289
|
-
* Value: Portkey gateway provider ID
|
|
4290
|
-
*/
|
|
4291
|
-
const MODELS_DEV_TO_PORTKEY_PROVIDER_MAP = {
|
|
4292
|
-
"azure-cognitive-services": "azure-ai",
|
|
4293
|
-
azure: "azure-openai"
|
|
4294
|
-
};
|
|
4295
|
-
/**
|
|
4296
|
-
* Reverse mapping from Portkey to models.dev
|
|
4297
|
-
*/
|
|
4298
|
-
const PORTKEY_TO_MODELS_DEV_PROVIDER_MAP = Object.fromEntries(Object.entries(MODELS_DEV_TO_PORTKEY_PROVIDER_MAP).map(([k, v]) => [v, k]));
|
|
4299
|
-
/**
|
|
4300
|
-
* Get the Portkey gateway provider ID for a given models.dev provider ID.
|
|
4301
|
-
* Returns the original ID if no mapping exists.
|
|
4302
|
-
*
|
|
4303
|
-
* @param modelsDevProviderId - The provider ID from models.dev
|
|
4304
|
-
* @returns The corresponding Portkey gateway provider ID
|
|
4305
|
-
*/
|
|
4306
|
-
function getPortkeyProviderId(modelsDevProviderId) {
|
|
4307
|
-
return MODELS_DEV_TO_PORTKEY_PROVIDER_MAP[modelsDevProviderId] ?? modelsDevProviderId;
|
|
4308
|
-
}
|
|
4309
|
-
/**
|
|
4310
|
-
* Get the models.dev provider ID for a given Portkey gateway provider ID.
|
|
4311
|
-
* Returns the original ID if no mapping exists.
|
|
4312
|
-
*
|
|
4313
|
-
* @param portkeyProviderId - The provider ID from Portkey gateway
|
|
4314
|
-
* @returns The corresponding models.dev provider ID
|
|
4315
|
-
*/
|
|
4316
|
-
function getModelsDevProviderId(portkeyProviderId) {
|
|
4317
|
-
return PORTKEY_TO_MODELS_DEV_PROVIDER_MAP[portkeyProviderId] ?? portkeyProviderId;
|
|
4318
|
-
}
|
|
4319
|
-
|
|
4320
4280
|
//#endregion
|
|
4321
4281
|
//#region src/middlewares/requestValidator/schema/config.ts
|
|
4322
|
-
/**
|
|
4323
|
-
* Check if a provider ID is valid.
|
|
4324
|
-
* Accepts both Portkey provider IDs and models.dev provider IDs that can be mapped.
|
|
4325
|
-
*/
|
|
4326
|
-
function isValidProvider$1(value) {
|
|
4327
|
-
if (VALID_PROVIDERS.includes(value)) return true;
|
|
4328
|
-
const mappedId = getPortkeyProviderId(value);
|
|
4329
|
-
return VALID_PROVIDERS.includes(mappedId);
|
|
4330
|
-
}
|
|
4331
4282
|
const configSchema = object({
|
|
4332
4283
|
strategy: object({
|
|
4333
4284
|
mode: string().refine((value) => [
|
|
@@ -4343,7 +4294,7 @@ const configSchema = object({
|
|
|
4343
4294
|
})).optional(),
|
|
4344
4295
|
default: string().optional()
|
|
4345
4296
|
}).optional(),
|
|
4346
|
-
provider: string().refine((value) =>
|
|
4297
|
+
provider: string().refine((value) => VALID_PROVIDERS.includes(value), { message: `Invalid 'provider' value. Must be one of: ${VALID_PROVIDERS.join(", ")}` }).optional(),
|
|
4347
4298
|
api_key: string().optional(),
|
|
4348
4299
|
aws_secret_access_key: string().optional(),
|
|
4349
4300
|
aws_access_key_id: string().optional(),
|
|
@@ -4373,17 +4324,8 @@ const configSchema = object({
|
|
|
4373
4324
|
vertex_service_account_json: object({}).catchall(string()).optional(),
|
|
4374
4325
|
openai_project: string().optional(),
|
|
4375
4326
|
openai_organization: string().optional(),
|
|
4376
|
-
azure_resource_name: string().optional(),
|
|
4377
|
-
azure_deployment_id: string().optional(),
|
|
4378
|
-
azure_api_version: string().optional(),
|
|
4379
4327
|
azure_model_name: string().optional(),
|
|
4380
4328
|
azure_auth_mode: string().optional(),
|
|
4381
|
-
azure_ad_token: string().optional(),
|
|
4382
|
-
azure_managed_client_id: string().optional(),
|
|
4383
|
-
azure_workload_client_id: string().optional(),
|
|
4384
|
-
azure_entra_client_id: string().optional(),
|
|
4385
|
-
azure_entra_client_secret: string().optional(),
|
|
4386
|
-
azure_entra_tenant_id: string().optional(),
|
|
4387
4329
|
strict_open_ai_compliance: boolean().optional()
|
|
4388
4330
|
}).refine((value) => {
|
|
4389
4331
|
const hasProviderApiKey = value.provider !== void 0 && value.api_key !== void 0;
|
|
@@ -4478,15 +4420,6 @@ const Environment = (c) => {
|
|
|
4478
4420
|
|
|
4479
4421
|
//#endregion
|
|
4480
4422
|
//#region src/middlewares/requestValidator/index.ts
|
|
4481
|
-
/**
|
|
4482
|
-
* Check if a provider ID is valid.
|
|
4483
|
-
* Accepts both Portkey provider IDs and models.dev provider IDs that can be mapped.
|
|
4484
|
-
*/
|
|
4485
|
-
function isValidProvider(value) {
|
|
4486
|
-
if (VALID_PROVIDERS.includes(value)) return true;
|
|
4487
|
-
const mappedId = getPortkeyProviderId(value);
|
|
4488
|
-
return VALID_PROVIDERS.includes(mappedId);
|
|
4489
|
-
}
|
|
4490
4423
|
const VALIDATION_PATTERNS = {
|
|
4491
4424
|
CONTROL_CHARS: /[\x00-\x1F\x7F]/,
|
|
4492
4425
|
SUSPICIOUS_CHARS: /[\s<>{}|\\^`]/,
|
|
@@ -4592,7 +4525,7 @@ const requestValidator = (c, next) => {
|
|
|
4592
4525
|
status: 400,
|
|
4593
4526
|
headers: { "content-type": "application/json" }
|
|
4594
4527
|
});
|
|
4595
|
-
if (requestHeaders[`x-${POWERED_BY}-provider`] && !
|
|
4528
|
+
if (requestHeaders[`x-${POWERED_BY}-provider`] && !VALID_PROVIDERS.includes(requestHeaders[`x-${POWERED_BY}-provider`])) return new Response(JSON.stringify({
|
|
4596
4529
|
status: "failure",
|
|
4597
4530
|
message: `Invalid provider passed`
|
|
4598
4531
|
}), {
|
|
@@ -10085,140 +10018,8 @@ function convertKeysToCamelCase(obj, parentKeysToPreserve = []) {
|
|
|
10085
10018
|
}
|
|
10086
10019
|
}
|
|
10087
10020
|
|
|
10088
|
-
//#endregion
|
|
10089
|
-
//#region src/shared/utils/logger.ts
|
|
10090
|
-
/**
|
|
10091
|
-
* @file src/utils/logger.ts
|
|
10092
|
-
* Configurable logger utility for MCP Gateway
|
|
10093
|
-
*/
|
|
10094
|
-
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
10095
|
-
LogLevel$1[LogLevel$1["ERROR"] = 0] = "ERROR";
|
|
10096
|
-
LogLevel$1[LogLevel$1["CRITICAL"] = 1] = "CRITICAL";
|
|
10097
|
-
LogLevel$1[LogLevel$1["WARN"] = 2] = "WARN";
|
|
10098
|
-
LogLevel$1[LogLevel$1["INFO"] = 3] = "INFO";
|
|
10099
|
-
LogLevel$1[LogLevel$1["DEBUG"] = 4] = "DEBUG";
|
|
10100
|
-
return LogLevel$1;
|
|
10101
|
-
}({});
|
|
10102
|
-
var Logger = class Logger {
|
|
10103
|
-
config;
|
|
10104
|
-
colors = {
|
|
10105
|
-
error: "\x1B[31m",
|
|
10106
|
-
critical: "\x1B[35m",
|
|
10107
|
-
warn: "\x1B[33m",
|
|
10108
|
-
info: "\x1B[36m",
|
|
10109
|
-
debug: "\x1B[37m",
|
|
10110
|
-
reset: "\x1B[0m"
|
|
10111
|
-
};
|
|
10112
|
-
constructor(config$1) {
|
|
10113
|
-
this.config = {
|
|
10114
|
-
timestamp: true,
|
|
10115
|
-
colors: true,
|
|
10116
|
-
...config$1
|
|
10117
|
-
};
|
|
10118
|
-
}
|
|
10119
|
-
formatMessage(level, message) {
|
|
10120
|
-
const parts = [];
|
|
10121
|
-
if (this.config.timestamp) parts.push(`[${(/* @__PURE__ */ new Date()).toISOString()}]`);
|
|
10122
|
-
if (this.config.prefix) parts.push(`[${this.config.prefix}]`);
|
|
10123
|
-
parts.push(`[${level.toUpperCase()}]`);
|
|
10124
|
-
parts.push(message);
|
|
10125
|
-
return parts.join(" ");
|
|
10126
|
-
}
|
|
10127
|
-
log(level, levelName, message, data) {
|
|
10128
|
-
if (level > this.config.level) return;
|
|
10129
|
-
const formattedMessage = this.formatMessage(levelName, message);
|
|
10130
|
-
const color = this.config.colors ? this.colors[levelName] : "";
|
|
10131
|
-
const reset = this.config.colors ? this.colors.reset : "";
|
|
10132
|
-
if (data !== void 0) console.log(`${color}${formattedMessage}${reset}`, data);
|
|
10133
|
-
else console.log(`${color}${formattedMessage}${reset}`);
|
|
10134
|
-
}
|
|
10135
|
-
error(message, error) {
|
|
10136
|
-
if (error instanceof Error) {
|
|
10137
|
-
this.log(LogLevel.ERROR, "error", `${message}: ${error.message}`);
|
|
10138
|
-
if (this.config.level >= LogLevel.DEBUG) console.error(error.stack);
|
|
10139
|
-
} else if (error) this.log(LogLevel.ERROR, "error", message, error);
|
|
10140
|
-
else this.log(LogLevel.ERROR, "error", message);
|
|
10141
|
-
}
|
|
10142
|
-
critical(message, data) {
|
|
10143
|
-
this.log(LogLevel.CRITICAL, "critical", message, data);
|
|
10144
|
-
}
|
|
10145
|
-
warn(message, data) {
|
|
10146
|
-
this.log(LogLevel.WARN, "warn", message, data);
|
|
10147
|
-
}
|
|
10148
|
-
info(message, data) {
|
|
10149
|
-
this.log(LogLevel.INFO, "info", message, data);
|
|
10150
|
-
}
|
|
10151
|
-
debug(message, data) {
|
|
10152
|
-
this.log(LogLevel.DEBUG, "debug", message, data);
|
|
10153
|
-
}
|
|
10154
|
-
createChild(prefix) {
|
|
10155
|
-
return new Logger({
|
|
10156
|
-
...this.config,
|
|
10157
|
-
prefix: this.config.prefix ? `${this.config.prefix}:${prefix}` : prefix
|
|
10158
|
-
});
|
|
10159
|
-
}
|
|
10160
|
-
};
|
|
10161
|
-
const defaultConfig = {
|
|
10162
|
-
level: process.env.LOG_LEVEL ? LogLevel[process.env.LOG_LEVEL.toUpperCase()] || LogLevel.ERROR : process.env.NODE_ENV === "production" ? LogLevel.ERROR : LogLevel.INFO,
|
|
10163
|
-
timestamp: process.env.LOG_TIMESTAMP !== "false",
|
|
10164
|
-
colors: process.env.LOG_COLORS !== "false" && process.env.NODE_ENV !== "production"
|
|
10165
|
-
};
|
|
10166
|
-
const logger$7 = new Logger(defaultConfig);
|
|
10167
|
-
function createLogger(prefix) {
|
|
10168
|
-
return logger$7.createChild(prefix);
|
|
10169
|
-
}
|
|
10170
|
-
|
|
10171
10021
|
//#endregion
|
|
10172
10022
|
//#region src/handlers/retryHandler.ts
|
|
10173
|
-
const logger$6 = createLogger("ProviderRequest");
|
|
10174
|
-
/**
|
|
10175
|
-
* Sanitizes headers by masking sensitive values like API keys and tokens
|
|
10176
|
-
*/
|
|
10177
|
-
function sanitizeHeaders(headers) {
|
|
10178
|
-
if (!headers) return {};
|
|
10179
|
-
const sanitized = {};
|
|
10180
|
-
const sensitivePatterns = /^(authorization|x-api-key|api-key|x-.*-key|x-.*-token|x-.*-secret|bearer)$/i;
|
|
10181
|
-
const headersObj = headers instanceof Headers ? Object.fromEntries([...headers]) : Array.isArray(headers) ? Object.fromEntries(headers) : headers;
|
|
10182
|
-
for (const [key, value] of Object.entries(headersObj)) if (sensitivePatterns.test(key)) sanitized[key] = value.length > 12 ? `${value.substring(0, 8)}...****` : "****";
|
|
10183
|
-
else sanitized[key] = value;
|
|
10184
|
-
return sanitized;
|
|
10185
|
-
}
|
|
10186
|
-
/**
|
|
10187
|
-
* Logs the outgoing request to the provider
|
|
10188
|
-
*/
|
|
10189
|
-
function logProviderRequest(url, options, attempt) {
|
|
10190
|
-
const sanitizedHeaders = sanitizeHeaders(options.headers);
|
|
10191
|
-
let bodyPreview;
|
|
10192
|
-
if (options.body) if (typeof options.body === "string") try {
|
|
10193
|
-
const parsed = JSON.parse(options.body);
|
|
10194
|
-
const bodyStr = JSON.stringify(parsed, null, 2);
|
|
10195
|
-
bodyPreview = bodyStr.length > 2e3 ? `${bodyStr.substring(0, 2e3)}...` : bodyStr;
|
|
10196
|
-
} catch {
|
|
10197
|
-
bodyPreview = options.body.length > 500 ? `${options.body.substring(0, 500)}...` : options.body;
|
|
10198
|
-
}
|
|
10199
|
-
else if (options.body instanceof FormData) bodyPreview = "[FormData]";
|
|
10200
|
-
else if (options.body instanceof ArrayBuffer) bodyPreview = `[ArrayBuffer: ${options.body.byteLength} bytes]`;
|
|
10201
|
-
else if (options.body instanceof ReadableStream) bodyPreview = "[ReadableStream]";
|
|
10202
|
-
else bodyPreview = "[Unknown body type]";
|
|
10203
|
-
logger$6.debug(`Provider Request (attempt ${attempt})`, {
|
|
10204
|
-
url,
|
|
10205
|
-
method: options.method || "GET",
|
|
10206
|
-
headers: sanitizedHeaders,
|
|
10207
|
-
body: bodyPreview
|
|
10208
|
-
});
|
|
10209
|
-
}
|
|
10210
|
-
/**
|
|
10211
|
-
* Logs the provider response
|
|
10212
|
-
*/
|
|
10213
|
-
function logProviderResponse(url, response, attempt, durationMs) {
|
|
10214
|
-
logger$6.debug(`Provider Response (attempt ${attempt})`, {
|
|
10215
|
-
url,
|
|
10216
|
-
status: response.status,
|
|
10217
|
-
statusText: response.statusText,
|
|
10218
|
-
durationMs,
|
|
10219
|
-
headers: Object.fromEntries([...response.headers])
|
|
10220
|
-
});
|
|
10221
|
-
}
|
|
10222
10023
|
async function fetchWithTimeout(url, options, timeout, requestHandler) {
|
|
10223
10024
|
const controller = new AbortController();
|
|
10224
10025
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
@@ -10267,14 +10068,10 @@ const retryRequest = async (url, options, retryCount, statusCodesToRetry, timeou
|
|
|
10267
10068
|
try {
|
|
10268
10069
|
await retry(async (bail, attempt, rateLimiter) => {
|
|
10269
10070
|
try {
|
|
10270
|
-
logProviderRequest(url, options, attempt);
|
|
10271
|
-
const fetchStartTime = Date.now();
|
|
10272
10071
|
let response;
|
|
10273
10072
|
if (timeout) response = await fetchWithTimeout(url, options, timeout, requestHandler);
|
|
10274
10073
|
else if (requestHandler) response = await requestHandler();
|
|
10275
10074
|
else response = await fetch(url, options);
|
|
10276
|
-
const fetchDuration = Date.now() - fetchStartTime;
|
|
10277
|
-
logProviderResponse(url, response, attempt, fetchDuration);
|
|
10278
10075
|
if (statusCodesToRetry.includes(response.status)) {
|
|
10279
10076
|
const errorObj = new Error(await response.text());
|
|
10280
10077
|
errorObj.status = response.status;
|
|
@@ -10348,7 +10145,7 @@ const retryRequest = async (url, options, retryCount, statusCodesToRetry, timeou
|
|
|
10348
10145
|
|
|
10349
10146
|
//#endregion
|
|
10350
10147
|
//#region package.json
|
|
10351
|
-
var version = "0.2.7
|
|
10148
|
+
var version = "0.2.7";
|
|
10352
10149
|
|
|
10353
10150
|
//#endregion
|
|
10354
10151
|
//#region src/providers/bytez/api.ts
|
|
@@ -17266,7 +17063,7 @@ const transformToProviderRequest = (provider, params, requestBody, fn, requestHe
|
|
|
17266
17063
|
if (fn === "createFinetune" && [AZURE_OPEN_AI, FIREWORKS_AI].includes(provider)) return transformToProviderRequestBody(provider, requestBody, requestHeaders, providerOptions, fn);
|
|
17267
17064
|
if (requestBody instanceof FormData || requestBody instanceof ArrayBuffer) return requestBody;
|
|
17268
17065
|
if (fn === "proxy") return params;
|
|
17269
|
-
const providerAPIConfig = providers_default[
|
|
17066
|
+
const providerAPIConfig = providers_default[provider].api;
|
|
17270
17067
|
if (providerAPIConfig.transformToFormData && providerAPIConfig.transformToFormData({ gatewayRequestBody: params })) return transformToProviderRequestFormData(provider, params, fn, providerOptions);
|
|
17271
17068
|
return transformToProviderRequestJSON(provider, params, fn, providerOptions);
|
|
17272
17069
|
};
|
|
@@ -30227,7 +30024,7 @@ async function responseHandler(c, response, streamingMode, providerOptions, resp
|
|
|
30227
30024
|
let responseTransformerFunction;
|
|
30228
30025
|
const responseContentType = response.headers?.get("content-type");
|
|
30229
30026
|
const isSuccessStatusCode = [200, 246].includes(response.status);
|
|
30230
|
-
const provider =
|
|
30027
|
+
const provider = providerOptions.provider;
|
|
30231
30028
|
const providerConfig = providers_default[provider];
|
|
30232
30029
|
let providerTransformers = providers_default[provider]?.responseTransforms;
|
|
30233
30030
|
if (providerConfig?.getConfig) providerTransformers = providerConfig.getConfig({
|
|
@@ -30829,8 +30626,7 @@ var PreRequestValidatorService = class {
|
|
|
30829
30626
|
var ProviderContext = class {
|
|
30830
30627
|
constructor(provider) {
|
|
30831
30628
|
this.provider = provider;
|
|
30832
|
-
|
|
30833
|
-
if (!providers_default[this.provider]) throw new GatewayError(`Provider ${provider} not found`);
|
|
30629
|
+
if (!providers_default[provider]) throw new GatewayError(`Provider ${provider} not found`);
|
|
30834
30630
|
}
|
|
30835
30631
|
get providerConfig() {
|
|
30836
30632
|
return providers_default[this.provider];
|
|
@@ -31102,20 +30898,6 @@ var ResponseService = class {
|
|
|
31102
30898
|
|
|
31103
30899
|
//#endregion
|
|
31104
30900
|
//#region src/handlers/handlerUtils.ts
|
|
31105
|
-
/**
|
|
31106
|
-
* Normalizes Azure OpenAI config fields from JSON config format to provider format.
|
|
31107
|
-
* JSON config uses `azure_*` prefix (e.g., `azure_resource_name`) which converts to `azureResourceName`,
|
|
31108
|
-
* but the provider expects `resourceName`, `deploymentId`, etc.
|
|
31109
|
-
* This function recursively normalizes nested targets as well.
|
|
31110
|
-
*/
|
|
31111
|
-
function normalizeAzureConfig(config$1) {
|
|
31112
|
-
const normalized = { ...config$1 };
|
|
31113
|
-
if (normalized.azureResourceName && !normalized.resourceName) normalized.resourceName = normalized.azureResourceName;
|
|
31114
|
-
if (normalized.azureDeploymentId && !normalized.deploymentId) normalized.deploymentId = normalized.azureDeploymentId;
|
|
31115
|
-
if (normalized.azureApiVersion && !normalized.apiVersion) normalized.apiVersion = normalized.azureApiVersion;
|
|
31116
|
-
if (Array.isArray(normalized.targets)) normalized.targets = normalized.targets.map((target) => normalizeAzureConfig(target));
|
|
31117
|
-
return normalized;
|
|
31118
|
-
}
|
|
31119
30901
|
function constructRequestBody(requestContext, providerHeaders) {
|
|
31120
30902
|
const headerContentType = providerHeaders[HEADER_KEYS.CONTENT_TYPE];
|
|
31121
30903
|
const requestContentType = requestContext.getHeader(HEADER_KEYS.CONTENT_TYPE);
|
|
@@ -31629,7 +31411,7 @@ function constructConfigFromRequestHeaders(requestHeaders) {
|
|
|
31629
31411
|
...oracleConfig
|
|
31630
31412
|
};
|
|
31631
31413
|
}
|
|
31632
|
-
return
|
|
31414
|
+
return convertKeysToCamelCase(parsedConfigJson, [
|
|
31633
31415
|
"override_params",
|
|
31634
31416
|
"params",
|
|
31635
31417
|
"checks",
|
|
@@ -31644,7 +31426,7 @@ function constructConfigFromRequestHeaders(requestHeaders) {
|
|
|
31644
31426
|
"integrationDetails",
|
|
31645
31427
|
"virtualKeyDetails",
|
|
31646
31428
|
"cb_config"
|
|
31647
|
-
])
|
|
31429
|
+
]);
|
|
31648
31430
|
}
|
|
31649
31431
|
return {
|
|
31650
31432
|
provider: requestHeaders[`x-${POWERED_BY}-provider`],
|
|
@@ -32232,7 +32014,7 @@ async function realTimeHandler(c) {
|
|
|
32232
32014
|
try {
|
|
32233
32015
|
const requestHeaders = Object.fromEntries(c.req.raw.headers);
|
|
32234
32016
|
const providerOptions = constructConfigFromRequestHeaders(requestHeaders);
|
|
32235
|
-
const apiConfig = providers_default[
|
|
32017
|
+
const apiConfig = providers_default[providerOptions.provider ?? ""].api;
|
|
32236
32018
|
const url = getURLForOutgoingConnection(apiConfig, providerOptions, c.req.url, c);
|
|
32237
32019
|
const options = await getOptionsForOutgoingConnection(apiConfig, providerOptions, url, c);
|
|
32238
32020
|
const sessionOptions = {
|
|
@@ -33527,4 +33309,4 @@ app.delete("/v1/*", requestValidator, proxyHandler);
|
|
|
33527
33309
|
var src_default = app;
|
|
33528
33310
|
|
|
33529
33311
|
//#endregion
|
|
33530
|
-
export {
|
|
33312
|
+
export { providers_default as Providers, src_default as default };
|