mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-18 21:22:28 +03:00
* feat(api): add provider quota telemetry, adaptive routing, and status inventory Adds a read-only OmniRoute status/inventory surface plus supporting resilience and usage-tracking infrastructure: - src/lib/quota/providerQuotaTelemetry.ts, providerCapabilities.ts: provider quota state and capability signals, sourced from configured metadata rather than invented values; unknown stays unknown. - src/lib/resilience/adaptiveCircuit.ts, failureClassification.ts: circuit state with lazy recovery and explicit failure classification. - src/lib/usage/usageLedger.ts, budgetGuard.ts, modelPricingRegistry.ts: internal usage tracking and budget allow/warn/deny decisions, kept separate from upstream-reported quota (never conflated). - src/lib/routing/adaptiveRouting.ts: excludes exhausted-quota and open-circuit candidates from routing, penalizes approaching-limit. - src/lib/omnirouteStatus.ts + src/app/api/omniroute/status, route/preview: read-only status endpoint; never issues a live upstream model request (asserted via liveRequestExecuted: false). - src/lib/db/quotaPools.ts: adds ensurePool() for idempotent pool management by automation/CLI callers, following the existing group-demo default-group convention. - scripts/omniroute-verify.mjs (+ omniroute:verify script): local verification against the running gateway. 9 new unit tests, all passing. typecheck:core clean relative to base (release/v3.8.50) -- the 2 pre-existing gateways.ts errors are tracked separately in #9985 and untouched by this change. * test(cli): align cli-machine-token assertions with HMAC-SHA256 64-char format The quota-telemetry feature hardens cliToken to HMAC-SHA256(machineId, SALT) (64-char hex, pristine machine id). Update the regression test to the new format and mirror the production derivation in the different-machine-id check. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: adevwithpurpose <adevwithpurpose@users.noreply.github.com> Co-authored-by: desamours-hub <desamours-hub@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
70 lines
2.4 KiB
JavaScript
70 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { CLI_TOKEN_HEADER, getCliToken } from "../../bin/cli/utils/cliToken.mjs";
|
|
|
|
const baseUrl = (process.env.OMNIROUTE_BASE_URL || "http://127.0.0.1:20128").replace(/\/$/, "");
|
|
const apiKey = process.env.OMNIROUTE_API_KEY || "";
|
|
const timeoutMs = 5000;
|
|
|
|
async function get(path) {
|
|
const controller = new AbortController();
|
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
let hardTimer;
|
|
const hardTimeout = new Promise((_, reject) => {
|
|
hardTimer = setTimeout(
|
|
() => reject(new Error(`request timeout after ${timeoutMs}ms`)),
|
|
timeoutMs + 100
|
|
);
|
|
});
|
|
try {
|
|
const response = await Promise.race([
|
|
fetch(`${baseUrl}${path}`, {
|
|
headers: {
|
|
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
[CLI_TOKEN_HEADER]: await getCliToken(),
|
|
},
|
|
signal: controller.signal,
|
|
}),
|
|
hardTimeout,
|
|
]);
|
|
const body = await response.json().catch(() => null);
|
|
return { ok: response.ok, status: response.status, body };
|
|
} finally {
|
|
clearTimeout(timer);
|
|
clearTimeout(hardTimer);
|
|
}
|
|
}
|
|
|
|
function check(label, passed, detail = "") {
|
|
console.log(`${label}: ${passed ? "PASS" : "FAIL"}${detail ? ` (${detail})` : ""}`);
|
|
return passed;
|
|
}
|
|
|
|
console.log("OmniRoute Verification");
|
|
console.log(`Gateway: ${baseUrl}`);
|
|
const results = [];
|
|
|
|
try {
|
|
const models = await get("/v1/models");
|
|
results.push(check("Gateway", models.ok, `HTTP ${models.status}`));
|
|
const modelCount = Array.isArray(models.body?.data) ? models.body.data.length : 0;
|
|
results.push(check("Catalog", modelCount > 0, `${modelCount} models`));
|
|
|
|
const pools = await get("/api/quota/pools");
|
|
const poolRows = Array.isArray(pools.body?.pools) ? pools.body.pools : [];
|
|
const allocations = poolRows.reduce((sum, pool) => sum + (pool.allocations?.length || 0), 0);
|
|
results.push(check("Pools", pools.ok, `${poolRows.length}`));
|
|
results.push(check("Allocations", pools.ok && allocations >= poolRows.length, `${allocations}`));
|
|
|
|
const status = await get("/api/omniroute/status");
|
|
results.push(check("Status API", status.ok, `HTTP ${status.status}`));
|
|
results.push(check("No live request", status.body?.liveRequestExecuted === false));
|
|
} catch (error) {
|
|
results.push(
|
|
check("Verification", false, error instanceof Error ? error.message : String(error))
|
|
);
|
|
}
|
|
|
|
console.log(`Live upstream requests: 0`);
|
|
if (results.some((passed) => !passed)) process.exitCode = 1;
|