mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-23 15:42:12 +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).
98 lines
3.7 KiB
TypeScript
98 lines
3.7 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { stripCcDiscoveryAlias } from "../../open-sse/handlers/chatCore/ccDiscoveryAliasStrip.ts";
|
|
|
|
const alwaysFalse = () => false;
|
|
const alwaysTrue = () => true;
|
|
|
|
test("non-'claude/' model id passes through untouched", () => {
|
|
const result = stripCcDiscoveryAlias("kimi/kimi-k2.6", {
|
|
isClaudeProviderModel: alwaysFalse,
|
|
isKnownProviderPrefix: alwaysTrue,
|
|
hasCombo: alwaysTrue,
|
|
aliasEnabledFor: alwaysTrue,
|
|
});
|
|
assert.deepEqual(result, { model: "kimi/kimi-k2.6", stripped: false });
|
|
});
|
|
|
|
test("legitimate claude provider model (e.g. claude/claude-fable-5) is left intact", () => {
|
|
const result = stripCcDiscoveryAlias("claude/claude-fable-5", {
|
|
isClaudeProviderModel: (rest) => rest === "claude-fable-5",
|
|
isKnownProviderPrefix: alwaysTrue,
|
|
hasCombo: alwaysTrue,
|
|
aliasEnabledFor: alwaysTrue,
|
|
});
|
|
assert.deepEqual(result, { model: "claude/claude-fable-5", stripped: false });
|
|
});
|
|
|
|
test("claude/<provider>/<model> with known provider + gate on strips to the real id", () => {
|
|
const result = stripCcDiscoveryAlias("claude/kimi/kimi-k2.6", {
|
|
isClaudeProviderModel: alwaysFalse,
|
|
isKnownProviderPrefix: (prefix) => prefix === "kimi",
|
|
hasCombo: alwaysFalse,
|
|
aliasEnabledFor: alwaysTrue,
|
|
});
|
|
assert.deepEqual(result, { model: "kimi/kimi-k2.6", stripped: true });
|
|
});
|
|
|
|
test("claude/combo/<name> with existing combo + gate on strips to the combo name", () => {
|
|
const result = stripCcDiscoveryAlias("claude/combo/custo-otimizado", {
|
|
isClaudeProviderModel: alwaysFalse,
|
|
isKnownProviderPrefix: alwaysFalse,
|
|
hasCombo: (name) => name === "custo-otimizado",
|
|
aliasEnabledFor: alwaysTrue,
|
|
});
|
|
assert.deepEqual(result, { model: "custo-otimizado", stripped: true });
|
|
});
|
|
|
|
test("claude/<unknown-provider>/x is left intact (unknown model flows through normally)", () => {
|
|
const result = stripCcDiscoveryAlias("claude/desconhecido/x", {
|
|
isClaudeProviderModel: alwaysFalse,
|
|
isKnownProviderPrefix: alwaysFalse,
|
|
hasCombo: alwaysFalse,
|
|
aliasEnabledFor: alwaysTrue,
|
|
});
|
|
assert.deepEqual(result, { model: "claude/desconhecido/x", stripped: false });
|
|
});
|
|
|
|
test("gate off leaves a known-provider alias intact even though the provider is known", () => {
|
|
const result = stripCcDiscoveryAlias("claude/kimi/kimi-k2.6", {
|
|
isClaudeProviderModel: alwaysFalse,
|
|
isKnownProviderPrefix: (prefix) => prefix === "kimi",
|
|
hasCombo: alwaysFalse,
|
|
aliasEnabledFor: alwaysFalse,
|
|
});
|
|
assert.deepEqual(result, { model: "claude/kimi/kimi-k2.6", stripped: false });
|
|
});
|
|
|
|
test("gate off leaves a combo alias intact even though the combo exists", () => {
|
|
const result = stripCcDiscoveryAlias("claude/combo/custo-otimizado", {
|
|
isClaudeProviderModel: alwaysFalse,
|
|
isKnownProviderPrefix: alwaysFalse,
|
|
hasCombo: (name) => name === "custo-otimizado",
|
|
aliasEnabledFor: alwaysFalse,
|
|
});
|
|
assert.deepEqual(result, { model: "claude/combo/custo-otimizado", stripped: false });
|
|
});
|
|
|
|
test("non-string model input is a no-op", () => {
|
|
const result = stripCcDiscoveryAlias(undefined as unknown as string, {
|
|
isClaudeProviderModel: alwaysFalse,
|
|
isKnownProviderPrefix: alwaysTrue,
|
|
hasCombo: alwaysTrue,
|
|
aliasEnabledFor: alwaysTrue,
|
|
});
|
|
assert.deepEqual(result, { model: undefined, stripped: false });
|
|
});
|
|
|
|
test("bare 'claude/' with nothing after the prefix is left intact (empty rest, no slash)", () => {
|
|
const result = stripCcDiscoveryAlias("claude/", {
|
|
isClaudeProviderModel: alwaysFalse,
|
|
isKnownProviderPrefix: alwaysTrue,
|
|
hasCombo: alwaysTrue,
|
|
aliasEnabledFor: alwaysTrue,
|
|
});
|
|
assert.deepEqual(result, { model: "claude/", stripped: false });
|
|
});
|