mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 00:52:18 +03:00
* feat(db): cc discovery alias gate storage + EXPOSE_CC_DISCOVERY_ALIASES flag
Adds the gate for claude/<provider>/<model> discovery-alias mirror ids on
the /v1/models catalog: a new runtime feature flag (env forces on and wins
over the dashboard DB override), per-provider and per-model "on"/"off"/null
overrides stored in key_value under the ccDiscoveryAliases namespace, and a
pure precedence resolver (model > provider > global). Catalog wiring is a
separate follow-up task; this only lands the gate + storage.
* feat(sse): synthesize claude/ discovery aliases for the model catalog
* feat(api): advertise cc discovery aliases on /v1/models behind the 3-level gate
* feat(sse): resolve claude/ discovery aliases on the request path
* fix(sse): import getComboByName from db/combos, not the localDb barrel
* fix(sse): cover custom-node prefixes and the Codex WS bridge in cc discovery alias resolution
* feat(dashboard): cc discovery alias toggles + flag-screen env warning
Adds the operator-facing UI/API layer for the Claude Code discovery-alias
gate (claude/<provider>/<model> mirror ids on /v1/models): REST endpoint
for provider/model overrides, a provider-detail card with 3-state
(inherit/on/off) toggles, an info button on the Claude Code tool card
linking to Feature Flags, and an env-source warning on the
EXPOSE_CC_DISCOVERY_ALIASES flag card when it's forced on via env.
* feat(api): cc discovery usage metrics
* fix(api): record cc alias metric in the production wrapper + atomic counter upsert
* docs: document cc discovery aliases (Claude Code guide + feature flag catalog)
* fix(sse): don't mirror built-in auto/* combos as discovery aliases (advertised-but-unroutable)
* i18n(vi): translate the discovery-alias strings instead of shipping placeholders
vi is the one locale with a strict "no internal missing markers" test, so the 17
__MISSING__ entries this branch added (the provider ccAlias panel, the info
button, the feature-flag description and the env warning) would have turned that
test red the moment the base itself was repaired. Translated, keeping every ICU
placeholder ({modelId}, {error}) and the literal claude/<provider>/<model> id
shape intact.
* chore(quality): raise the frozen caps this feature legitimately grows
catalog.ts 1615 -> 1639: the alias synthesis is wired into the catalog builder,
which is where the per-key-filtered list is assembled — the only place the mirror
entries can be appended after model hiding has been applied.
localDb.ts 808 -> 810: two re-export lines for the new ccDiscoveryAliases db
module, which is exactly what the "Adding a New DB Module" recipe prescribes.
* refactor(dashboard,api): keep the complexity ratchets flat
The feature added four cyclomatic violations and one cognitive one, which the
ratchets reject — the baseline only moves when a metric improves. Split the new
code instead:
- appendCcDiscoveryAliases: the four skip-guards become isMirrorableId().
- resolveCcDiscoveryAliasStripWith: alias parsing and gate resolution become
parseCcAliasTarget() and resolveGateFor(), replacing a chain of ternaries that
each re-tested isComboAlias.
- FeatureFlagCard: the env-precedence warning becomes its own component instead
of a conditional branch inside an already-large render.
- ProviderCcAliasSection: the loader moves to useCcAliasData(), and the override
list and add-row become ModelOverrideList / AddOverrideRow, bringing both
oversized functions back under the 80-line rule.
Behavior unchanged — the 74 discovery-alias tests pass untouched. Both ratchets
now sit exactly at baseline (2188 / 971).
76 lines
2.5 KiB
TypeScript
76 lines
2.5 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-cc-discovery-metrics-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
|
|
test.beforeEach(() => {
|
|
core.resetDbInstance();
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
});
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
try {
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
} catch {
|
|
// best-effort cleanup
|
|
}
|
|
});
|
|
|
|
test("getCcDiscoveryMetrics starts at zero", async () => {
|
|
const { getCcDiscoveryMetrics } = await import("../../src/lib/db/ccDiscoveryMetrics.ts");
|
|
const metrics = getCcDiscoveryMetrics();
|
|
assert.deepEqual(metrics, { aliasRequests: 0, discoveryHits: 0, byModel: {} });
|
|
});
|
|
|
|
test("incrementCcAliasRequestCount bumps total and per-model counters", async () => {
|
|
const { incrementCcAliasRequestCount, getCcDiscoveryMetrics } =
|
|
await import("../../src/lib/db/ccDiscoveryMetrics.ts");
|
|
|
|
incrementCcAliasRequestCount("kimi/kimi-k2.6");
|
|
incrementCcAliasRequestCount("kimi/kimi-k2.6");
|
|
incrementCcAliasRequestCount("openai/gpt-5.2");
|
|
|
|
const metrics = getCcDiscoveryMetrics();
|
|
assert.equal(metrics.aliasRequests, 3);
|
|
assert.deepEqual(metrics.byModel, {
|
|
"kimi/kimi-k2.6": 2,
|
|
"openai/gpt-5.2": 1,
|
|
});
|
|
});
|
|
|
|
test("incrementCcDiscoveryHitCount bumps the discovery-hit counter", async () => {
|
|
const { incrementCcDiscoveryHitCount, getCcDiscoveryMetrics } =
|
|
await import("../../src/lib/db/ccDiscoveryMetrics.ts");
|
|
|
|
incrementCcDiscoveryHitCount();
|
|
incrementCcDiscoveryHitCount();
|
|
incrementCcDiscoveryHitCount();
|
|
|
|
const metrics = getCcDiscoveryMetrics();
|
|
assert.equal(metrics.discoveryHits, 3);
|
|
});
|
|
|
|
test("getCcDiscoveryMetrics aggregates both counters together and repeated increments sum", async () => {
|
|
const { incrementCcAliasRequestCount, incrementCcDiscoveryHitCount, getCcDiscoveryMetrics } =
|
|
await import("../../src/lib/db/ccDiscoveryMetrics.ts");
|
|
|
|
const before = getCcDiscoveryMetrics();
|
|
|
|
incrementCcAliasRequestCount("combo/my-combo");
|
|
incrementCcAliasRequestCount("combo/my-combo");
|
|
incrementCcAliasRequestCount("combo/my-combo");
|
|
incrementCcDiscoveryHitCount();
|
|
|
|
const after = getCcDiscoveryMetrics();
|
|
assert.equal(after.aliasRequests - before.aliasRequests, 3);
|
|
assert.equal(after.discoveryHits - before.discoveryHits, 1);
|
|
assert.equal(after.byModel["combo/my-combo"], 3);
|
|
});
|