onRequest returned early for ctx.protocol === "gemini", on the grounds that a
Gemini request names its model in the URL and not in the body. magpie puts it
in the body before the middleware runs (gateway.go, serveAgent is called with
withFields(body, {"model": model, "stream": stream})), and reads it from there
to route, so the mapping applied to every API but Gemini: a Gemini client
asking for a mapped name got "magpie knows no model" as a 404.
onEvent and onResponse also never looked at modelVersion, where a Gemini reply
names its model (internal/gateway/member.go lists exactly that path), so the
name a Gemini client read back was the upstream's even when the mapping did
apply.
cases.json's "Gemini's body has no model to map" asserted the old assumption
with a body carrying no model — a body the gateway never sends. It is replaced
by one that carries the model the gateway fills, covering the request, the
stream and a whole reply; a second case keeps the no-model body passing as it
is. The new case fails on 0.1.0 and passes here.
Co-authored-by: TryWorld2026 <tryworld@users.noreply.github.com>
15 lines
725 B
JSON
15 lines
725 B
JSON
{
|
|
"name": "@magpie-community/middleware-model-map",
|
|
"version": "0.1.1",
|
|
"description": "New API's model_mapping (模型重定向) as magpie gateway middleware: send the model an agent asks for as another, and keep the asked name in replies",
|
|
"type": "module",
|
|
"files": ["model-map.middleware.js", "README.md"],
|
|
"keywords": ["magpie", "magpie-middleware", "new-api", "model-mapping", "llm-gateway"],
|
|
"license": "MIT",
|
|
"repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/model-map" },
|
|
"magpie": {
|
|
"middleware": "./model-map.middleware.js",
|
|
"options": { "mapping": { "fast": "deepseek-chat", "/^gpt-4o(-.*)?$/": "deepseek-chat" } }
|
|
}
|
|
}
|