mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 00:52:18 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
102 lines
3.5 KiB
JavaScript
102 lines
3.5 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* @file sync-alibaba-allowlist.mjs
|
|
* @description Build config/alibaba-free-tier-allowlist.json from Bailian console quota JSON exports.
|
|
*
|
|
* Usage:
|
|
* node --import tsx/esm scripts/ops/sync-alibaba-allowlist.mjs path/to/quota.json [...]
|
|
* node --import tsx/esm scripts/ops/sync-alibaba-allowlist.mjs --from-samples
|
|
*
|
|
* Writes:
|
|
* - config/alibaba-free-tier-allowlist.json (repo baseline)
|
|
* - ~/.omniroute/alibaba-free-tier-allowlist.json when DATA_DIR unset
|
|
*/
|
|
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import {
|
|
classifyAlibabaFreeTierQuotaEntries,
|
|
parseAlibabaFreeTierQuotaEntries,
|
|
} from "../../open-sse/services/alibabaFreeTierQuotaFetcher.ts";
|
|
import { isDashscopeTextModelId } from "../../open-sse/services/dashscopeTextModels.ts";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const repoRoot = path.resolve(__dirname, "../..");
|
|
|
|
const SAMPLE_FILES = [
|
|
"scripts/ops/alibabafreeaudio-quota.sample.json",
|
|
"scripts/ops/alibabafreemultimodal-quota.sample.json",
|
|
"scripts/ops/alibabafreevision-quota.sample.json",
|
|
].map((relativePath) => path.join(repoRoot, relativePath));
|
|
|
|
function readJsonFile(filePath) {
|
|
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
}
|
|
|
|
function collectInputs(argv) {
|
|
if (argv.includes("--from-samples")) {
|
|
return SAMPLE_FILES.filter((filePath) => fs.existsSync(filePath));
|
|
}
|
|
return argv.filter((arg) => !arg.startsWith("-"));
|
|
}
|
|
|
|
function classifyTextEntries(allEntries) {
|
|
const capable = new Set();
|
|
const noFreeTier = new Set();
|
|
|
|
for (const entry of allEntries) {
|
|
if (!isDashscopeTextModelId(entry.model)) continue;
|
|
const classified = classifyAlibabaFreeTierQuotaEntries([entry], { textOnly: true });
|
|
for (const modelId of classified.capableModels) capable.add(modelId);
|
|
for (const modelId of classified.noFreeTierModels) noFreeTier.add(modelId);
|
|
}
|
|
|
|
return {
|
|
capable: [...capable].sort(),
|
|
noFreeTier: [...noFreeTier].sort(),
|
|
};
|
|
}
|
|
|
|
function main() {
|
|
const inputs = collectInputs(process.argv.slice(2));
|
|
if (inputs.length === 0) {
|
|
console.error("Usage: sync-alibaba-allowlist.mjs <quota.json> [...] | --from-samples");
|
|
process.exit(1);
|
|
}
|
|
|
|
const allEntries = [];
|
|
for (const inputPath of inputs) {
|
|
const payload = readJsonFile(inputPath);
|
|
allEntries.push(...parseAlibabaFreeTierQuotaEntries(payload));
|
|
}
|
|
|
|
const { capable, noFreeTier } = classifyTextEntries(allEntries);
|
|
if (capable.length === 0) {
|
|
console.error("No text free-tier models found in input payloads.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const asOf = new Date().toISOString().slice(0, 10);
|
|
const validUntil = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10);
|
|
const pack = { asOf, validUntil, capable, noFreeTier };
|
|
const serialized = `${JSON.stringify(pack, null, 2)}\n`;
|
|
|
|
const configPath = path.join(repoRoot, "config", "alibaba-free-tier-allowlist.json");
|
|
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
fs.writeFileSync(configPath, serialized);
|
|
|
|
const dataDir = process.env.DATA_DIR?.trim() || path.join(os.homedir(), ".omniroute");
|
|
const runtimePath = path.join(dataDir, "alibaba-free-tier-allowlist.json");
|
|
fs.mkdirSync(dataDir, { recursive: true });
|
|
fs.writeFileSync(runtimePath, serialized);
|
|
|
|
console.log(`Wrote ${capable.length} capable + ${noFreeTier.length} blocked models`);
|
|
console.log(` config: ${configPath}`);
|
|
console.log(` runtime: ${runtimePath}`);
|
|
console.log(` validUntil: ${validUntil}`);
|
|
}
|
|
|
|
main();
|