@mupt-ai/dari-gateway 1.0.359 → 1.0.360
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/self_host/config.js
CHANGED
|
@@ -95,7 +95,21 @@ function parseProvider(id, raw) {
|
|
|
95
95
|
if (raw.apiKeyEnv !== undefined && (typeof raw.apiKeyEnv !== "string" || !raw.apiKeyEnv.trim())) {
|
|
96
96
|
throw new Error(`providers.${id}.apiKeyEnv must name an environment variable.`);
|
|
97
97
|
}
|
|
98
|
+
const limits = {};
|
|
99
|
+
for (const field of ["contextWindow", "maxOutputTokens"]) {
|
|
100
|
+
const n = raw[field];
|
|
101
|
+
if (n === undefined)
|
|
102
|
+
continue;
|
|
103
|
+
if (typeof n !== "number" || !Number.isSafeInteger(n) || n < 1) {
|
|
104
|
+
throw new Error(`providers.${id}.${field} must be a positive token count.`);
|
|
105
|
+
}
|
|
106
|
+
limits[field] = n;
|
|
107
|
+
}
|
|
108
|
+
if (limits.contextWindow && limits.maxOutputTokens && limits.maxOutputTokens > limits.contextWindow) {
|
|
109
|
+
throw new Error(`providers.${id}.maxOutputTokens exceeds the context window.`);
|
|
110
|
+
}
|
|
98
111
|
return {
|
|
112
|
+
...limits,
|
|
99
113
|
baseUrl: raw.baseUrl.replace(/\/+$/, ""),
|
|
100
114
|
api: typeof raw.api === "string" ? raw.api.trim() : "openai-completions",
|
|
101
115
|
...(typeof raw.apiKeyEnv === "string" ? { apiKeyEnv: raw.apiKeyEnv.trim() } : {}),
|
package/dist/self_host/main.js
CHANGED
|
@@ -207,6 +207,8 @@ export async function startSelfHostedGateway(env = process.env) {
|
|
|
207
207
|
auto_routing: autoRoutingKey ? "dari" : "priority",
|
|
208
208
|
...(hosted === null ? {} : { connected: { hosted_url: hosted.url, gateway_id: hosted.gatewayId } }),
|
|
209
209
|
}));
|
|
210
|
+
if (env.DARI_SESSION_PORT_FILE)
|
|
211
|
+
await Bun.write(env.DARI_SESSION_PORT_FILE, String(server.port));
|
|
210
212
|
sync?.start();
|
|
211
213
|
const idleUsage = sync === null ? null : setInterval(() => {
|
|
212
214
|
void refreshStaleUsage(subscriptions, { fetch, baseUrls });
|
|
@@ -325,9 +325,14 @@ function candidateConfig(deps, modelId, candidate) {
|
|
|
325
325
|
}
|
|
326
326
|
const served = providerModel(modelId, provider);
|
|
327
327
|
const endpoint = deps.config.providers[provider];
|
|
328
|
+
const limits = {
|
|
329
|
+
...(endpoint?.contextWindow !== undefined ? { context_window: endpoint.contextWindow } : {}),
|
|
330
|
+
...(endpoint?.maxOutputTokens !== undefined ? { max_output_tokens: endpoint.maxOutputTokens } : {}),
|
|
331
|
+
};
|
|
328
332
|
if (served !== undefined) {
|
|
329
333
|
return {
|
|
330
334
|
provider,
|
|
335
|
+
...limits,
|
|
331
336
|
native_model_id: served.native_model_id,
|
|
332
337
|
api: endpoint?.api ?? served.api,
|
|
333
338
|
base_url: endpoint?.baseUrl ?? served.base_url,
|
|
@@ -338,6 +343,7 @@ function candidateConfig(deps, modelId, candidate) {
|
|
|
338
343
|
return undefined;
|
|
339
344
|
return {
|
|
340
345
|
provider,
|
|
346
|
+
...limits,
|
|
341
347
|
native_model_id: nativeModelId(modelId),
|
|
342
348
|
api: endpoint.api,
|
|
343
349
|
base_url: endpoint.baseUrl,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mupt-ai/dari-gateway",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.360",
|
|
4
4
|
"description": "Self-hostable LLM gateway for coding agents and APIs: one endpoint for Anthropic Messages, OpenAI Chat Completions, and OpenAI Responses, with subscription pooling, failover, and prompt-cache-aware routing.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@aws-sdk/client-sts": "3.1063.0",
|
|
55
|
-
"@mupt-ai/dari-router": "1.0.
|
|
55
|
+
"@mupt-ai/dari-router": "1.0.360",
|
|
56
56
|
"@mupt-ai/pi-ai": "1.5.2-mupt.3"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
package/src/self_host/config.ts
CHANGED
|
@@ -74,6 +74,8 @@ export type ProviderEndpointConfig = {
|
|
|
74
74
|
api: string;
|
|
75
75
|
// Environment variable holding the endpoint's API key; absent sends none.
|
|
76
76
|
apiKeyEnv?: string;
|
|
77
|
+
contextWindow?: number;
|
|
78
|
+
maxOutputTokens?: number;
|
|
77
79
|
};
|
|
78
80
|
|
|
79
81
|
export type RouterConfig = {
|
|
@@ -205,7 +207,20 @@ function parseProvider(id: string, raw: unknown): ProviderEndpointConfig {
|
|
|
205
207
|
if (raw.apiKeyEnv !== undefined && (typeof raw.apiKeyEnv !== "string" || !raw.apiKeyEnv.trim())) {
|
|
206
208
|
throw new Error(`providers.${id}.apiKeyEnv must name an environment variable.`);
|
|
207
209
|
}
|
|
210
|
+
const limits: Pick<ProviderEndpointConfig, "contextWindow" | "maxOutputTokens"> = {};
|
|
211
|
+
for (const field of ["contextWindow", "maxOutputTokens"] as const) {
|
|
212
|
+
const n = raw[field];
|
|
213
|
+
if (n === undefined) continue;
|
|
214
|
+
if (typeof n !== "number" || !Number.isSafeInteger(n) || n < 1) {
|
|
215
|
+
throw new Error(`providers.${id}.${field} must be a positive token count.`);
|
|
216
|
+
}
|
|
217
|
+
limits[field] = n;
|
|
218
|
+
}
|
|
219
|
+
if (limits.contextWindow && limits.maxOutputTokens && limits.maxOutputTokens > limits.contextWindow) {
|
|
220
|
+
throw new Error(`providers.${id}.maxOutputTokens exceeds the context window.`);
|
|
221
|
+
}
|
|
208
222
|
return {
|
|
223
|
+
...limits,
|
|
209
224
|
baseUrl: raw.baseUrl.replace(/\/+$/, ""),
|
|
210
225
|
api: typeof raw.api === "string" ? raw.api.trim() : "openai-completions",
|
|
211
226
|
...(typeof raw.apiKeyEnv === "string" ? { apiKeyEnv: raw.apiKeyEnv.trim() } : {}),
|
package/src/self_host/main.ts
CHANGED
|
@@ -234,6 +234,7 @@ export async function startSelfHostedGateway(env: Record<string, string> = proce
|
|
|
234
234
|
...(hosted === null ? {} : { connected: { hosted_url: hosted.url, gateway_id: hosted.gatewayId } }),
|
|
235
235
|
}),
|
|
236
236
|
);
|
|
237
|
+
if (env.DARI_SESSION_PORT_FILE) await Bun.write(env.DARI_SESSION_PORT_FILE, String(server.port));
|
|
237
238
|
sync?.start();
|
|
238
239
|
const idleUsage = sync === null ? null : setInterval(() => {
|
|
239
240
|
void refreshStaleUsage(subscriptions, { fetch, baseUrls });
|
package/src/self_host/resolve.ts
CHANGED
|
@@ -400,9 +400,14 @@ function candidateConfig(
|
|
|
400
400
|
}
|
|
401
401
|
const served = providerModel(modelId, provider);
|
|
402
402
|
const endpoint = deps.config.providers[provider];
|
|
403
|
+
const limits = {
|
|
404
|
+
...(endpoint?.contextWindow !== undefined ? { context_window: endpoint.contextWindow } : {}),
|
|
405
|
+
...(endpoint?.maxOutputTokens !== undefined ? { max_output_tokens: endpoint.maxOutputTokens } : {}),
|
|
406
|
+
};
|
|
403
407
|
if (served !== undefined) {
|
|
404
408
|
return {
|
|
405
409
|
provider,
|
|
410
|
+
...limits,
|
|
406
411
|
native_model_id: served.native_model_id,
|
|
407
412
|
api: endpoint?.api ?? served.api,
|
|
408
413
|
base_url: endpoint?.baseUrl ?? served.base_url,
|
|
@@ -412,6 +417,7 @@ function candidateConfig(
|
|
|
412
417
|
if (endpoint === undefined) return undefined;
|
|
413
418
|
return {
|
|
414
419
|
provider,
|
|
420
|
+
...limits,
|
|
415
421
|
native_model_id: nativeModelId(modelId),
|
|
416
422
|
api: endpoint.api,
|
|
417
423
|
base_url: endpoint.baseUrl,
|