fix(dashboard): re-qualify no-think playground model ids correctly

This commit is contained in:
Will Gordon
2026-07-30 15:04:26 -04:00
parent 8394b87402
commit 499a75f5df
2 changed files with 46 additions and 0 deletions

View File

@@ -35,6 +35,10 @@ function resolvePlaygroundKeyId(
return keys.find((k) => k.key === selectedMaskedKey)?.id ?? null;
}
// Mirrors NO_THINKING_PREFIX in open-sse/utils/noThinkingAlias.ts — kept as a local literal
// (not imported) to avoid pulling server-side catalog modules into the client bundle.
const NO_THINKING_PREFIX = "no-think/";
/**
* Qualify a provider-scoped playground model with its routing prefix so
* OmniRoute can resolve it unambiguously. The previous heuristic only prefixed
@@ -52,6 +56,14 @@ export function qualifyPlaygroundModel(
): string {
const m = (model ?? "").trim();
if (!m || !routingPrefix) return m;
// A no-think id's real wire form is `no-think/<provider>/<model>` — the provider segment
// sits AFTER the prefix, not at the front, so it needs its own qualification branch instead
// of the generic leading-prefix check below.
if (m.startsWith(NO_THINKING_PREFIX)) {
const inner = m.slice(NO_THINKING_PREFIX.length);
const alreadyQualified = inner === routingPrefix || inner.startsWith(`${routingPrefix}/`);
return alreadyQualified ? m : `${NO_THINKING_PREFIX}${routingPrefix}/${inner}`;
}
return m === routingPrefix || m.startsWith(`${routingPrefix}/`) ? m : `${routingPrefix}/${m}`;
}

View File

@@ -37,3 +37,37 @@ test("OpenCode Free playground uses its routing alias instead of the reserved pr
assert.equal(getProviderAlias("opencode"), "oc");
assert.equal(qualifyPlaygroundModel("big-pickle", getProviderAlias("opencode")), "oc/big-pickle");
});
test("qualifyPlaygroundModel inserts the provider after the no-think prefix, not before it", () => {
assert.equal(
qualifyPlaygroundModel("no-think/claude-sonnet-5", "vertex"),
"no-think/vertex/claude-sonnet-5"
);
});
test("qualifyPlaygroundModel does not double-qualify an already-qualified no-think id", () => {
assert.equal(
qualifyPlaygroundModel("no-think/vertex/claude-sonnet-5", "vertex"),
"no-think/vertex/claude-sonnet-5"
);
});
test("qualifyPlaygroundModel does not mistake a provider-name-prefix collision for already-qualified", () => {
// routingPrefix "vertex" must not match "vertex-eu/..." as already-qualified just because
// it starts with the same characters — the check requires an exact "vertex/" segment
// boundary. A naive `inner.startsWith(routingPrefix)` (no slash) would wrongly skip
// qualification here and leave the provider segment un-inserted.
assert.equal(
qualifyPlaygroundModel("no-think/vertex-eu/claude-sonnet-5", "vertex"),
"no-think/vertex/vertex-eu/claude-sonnet-5"
);
});
test("LlmChatCard's local NO_THINKING_PREFIX literal matches the canonical constant", async () => {
// Drift guard: LlmChatCard.tsx deliberately hardcodes "no-think/" as a literal instead
// of importing NO_THINKING_PREFIX from open-sse/utils/noThinkingAlias.ts (avoids pulling
// server-side catalog modules into the client bundle — see Step 1). This test file is not
// client-bundled, so it can safely import the real constant and assert they never drift.
const { NO_THINKING_PREFIX } = await import("../../open-sse/utils/noThinkingAlias.ts");
assert.equal(NO_THINKING_PREFIX, "no-think/");
});