From 6de02a0ab3234e542efdd71ebeb20560a5893fde Mon Sep 17 00:00:00 2001 From: Akiiwa <115624916+akiiwa-games@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:08:24 +0800 Subject: [PATCH] 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. --- packages/agentcompass/package.json | 2 +- packages/agentcompass/src/catalog.js | 10 +++++++--- packages/agentcompass/test/router.test.mjs | 10 +++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/agentcompass/package.json b/packages/agentcompass/package.json index d757324..d7c506f 100644 --- a/packages/agentcompass/package.json +++ b/packages/agentcompass/package.json @@ -1,6 +1,6 @@ { "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.", "type": "module", "main": "./src/index.js", diff --git a/packages/agentcompass/src/catalog.js b/packages/agentcompass/src/catalog.js index e26fdc6..122983a 100644 --- a/packages/agentcompass/src/catalog.js +++ b/packages/agentcompass/src/catalog.js @@ -1506,9 +1506,13 @@ export function canonicalModel(rawModel, aliases = MODEL_ALIASES) { if (aliases[clean]) return aliases[clean]; const slashIdx = clean.indexOf("/"); const unprefixed = slashIdx >= 0 ? clean.slice(slashIdx + 1) : clean; - if (aliases[unprefixed]) return aliases[unprefixed]; - const lower = unprefixed.toLowerCase(); - if (aliases[lower]) return aliases[lower]; + // A multi-prefix id (`openrouter/openai/gpt-5-mini`) also resolves by its last segment, as AgentCompass's + // `resolve_canonical_model` does. An unknown id keeps only its first prefix stripped (`openrouter/qwen/foo` -> + // `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; } diff --git a/packages/agentcompass/test/router.test.mjs b/packages/agentcompass/test/router.test.mjs index 1a21eaf..d2d57b9 100644 --- a/packages/agentcompass/test/router.test.mjs +++ b/packages/agentcompass/test/router.test.mjs @@ -6,7 +6,7 @@ import test from "node:test"; import { fileURLToPath } from "node:url"; 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 { CACHE_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}` ); } + + // 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 () => {