agentcompass 0.1.4: canonicalModel resolves a multi-prefix model id by its last segment (#751)
agentcompass 0.1.4: canonicalModel tries the id with its first prefix removed, then its lowercase, then the last path segment and its lowercase, so a multi-prefix id such as openrouter/minimax/MiniMax-M3 resolves to its alias (minimax-m3). An id no alias knows keeps its old key. Reviewed at 2adb5439 on mote (Bun 1.4.2, Node 22.22.0, fresh HOME): agentcompass bun test and node --test 44/44; bun scripts/check.mjs (package and whole repo) exit 0; repo root bun test 6244 pass, 0 fail. The old code and three of the four new lookups, each broken by hand, turned test 9.7 red; dropping the lowercase of the prefix-stripped id, which was already on main, stayed green. PR CI green on attempt 1. Not tried: a real routed request through a live gateway.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@magpie-community/gateway-agentcompass",
|
"name": "@magpie-community/gateway-agentcompass",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"description": "Intent, multi-dimensional capability, Model DNA, subscription quota opportunity-cost, and session-affinity routing plugin for Magpie, powered by AgentCompass.",
|
"description": "Intent, multi-dimensional capability, Model DNA, subscription quota opportunity-cost, and session-affinity routing plugin for Magpie, powered by AgentCompass.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
|
|||||||
@@ -1506,9 +1506,13 @@ export function canonicalModel(rawModel, aliases = MODEL_ALIASES) {
|
|||||||
if (aliases[clean]) return aliases[clean];
|
if (aliases[clean]) return aliases[clean];
|
||||||
const slashIdx = clean.indexOf("/");
|
const slashIdx = clean.indexOf("/");
|
||||||
const unprefixed = slashIdx >= 0 ? clean.slice(slashIdx + 1) : clean;
|
const unprefixed = slashIdx >= 0 ? clean.slice(slashIdx + 1) : clean;
|
||||||
if (aliases[unprefixed]) return aliases[unprefixed];
|
// A multi-prefix id (`openrouter/openai/gpt-5-mini`) also resolves by its last segment, as AgentCompass's
|
||||||
const lower = unprefixed.toLowerCase();
|
// `resolve_canonical_model` does. An unknown id keeps only its first prefix stripped (`openrouter/qwen/foo` ->
|
||||||
if (aliases[lower]) return aliases[lower];
|
// `qwen/foo`), the key quota.js and continuity.js already match on.
|
||||||
|
const last = clean.slice(clean.lastIndexOf("/") + 1);
|
||||||
|
for (const name of [unprefixed, unprefixed.toLowerCase(), last, last.toLowerCase()]) {
|
||||||
|
if (aliases[name]) return aliases[name];
|
||||||
|
}
|
||||||
return unprefixed;
|
return unprefixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import test from "node:test";
|
|||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
import { burnScale, effortValue, namedRoute, rankCandidates, selectBestRoute } from "../src/allocator.js";
|
import { burnScale, effortValue, namedRoute, rankCandidates, selectBestRoute } from "../src/allocator.js";
|
||||||
import { CANONICAL_ROUTES, DEFAULT_SCORING_POLICY, EFFORT_CURVES } from "../src/catalog.js";
|
import { CANONICAL_ROUTES, DEFAULT_SCORING_POLICY, EFFORT_CURVES, canonicalModel } from "../src/catalog.js";
|
||||||
import {
|
import {
|
||||||
CACHE_COLD_MS,
|
CACHE_COLD_MS,
|
||||||
CHATGPT_CODEX_COLD_MS,
|
CHATGPT_CODEX_COLD_MS,
|
||||||
@@ -2181,6 +2181,14 @@ test("9.7 PR #670 Round 2 Guard: Mainstream real model IDs & trivial single-vari
|
|||||||
`Expected claude-opus-4-6:(high|xhigh|max) for permutation [${candidateModels.join(", ")}], got ${auditOut.model}`
|
`Expected claude-opus-4-6:(high|xhigh|max) for permutation [${candidateModels.join(", ")}], got ${auditOut.model}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A multi-prefix id resolves by its last segment; an unknown one keeps only its first prefix stripped
|
||||||
|
assert.equal(canonicalModel("openrouter/openai/gpt-5-mini"), "gpt-6-luna");
|
||||||
|
assert.equal(canonicalModel("OpenRouter/OpenAI/GPT-5-Mini"), "gpt-6-luna");
|
||||||
|
// Alias keys with capitals (`MiniMax-M3`) need the exact-case last-segment lookup
|
||||||
|
assert.equal(canonicalModel("openrouter/minimax/MiniMax-M3"), "minimax-m3");
|
||||||
|
assert.equal(canonicalModel("openrouter/qwen/foo"), "qwen/foo");
|
||||||
|
assert.equal(canonicalModel("qwen/foo"), "foo");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("9.8 PR #670 Round 2 Guard: `options.fetch` alone never enables external scorer unless `allowExternalScorer === true`", async () => {
|
test("9.8 PR #670 Round 2 Guard: `options.fetch` alone never enables external scorer unless `allowExternalScorer === true`", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user