Files
plugins/packages
yetone ff9d3a6446 system-prompt 0.1.1: models matches a model's own name, and a routing group's try on it
@liucl on X (11-09): a prompt only for gemini-3.8-flash. `models` was
checked with String(body.model ?? ctx.model).startsWith(m), but an agent
wired to magpie names its model magpie's way, provider first
(google/gemini-3.8-flash, openrouter/google/gemini-3.8-flash), or names a
routing group (group/...). So "models": ["gemini-3.8-flash"] never
matched, though the README said "models whose names begin with one of
these prefixes".

A prefix now matches the whole id or the part after any "/" of it, case
aside; full-id prefixes (google/, deepseek) work as before. magpie's
middleware gets the agent's body at onRequest (ctx.model is modelOf(body),
serveAgent in internal/gateway/middleware.go), so a group request names
the group there. The member is known on each try: onProvider gets
ctx.provider {id, model} and can change that try's body
(docs/subsystems/gateway-middleware.md, triedOn). A request onRequest
didn't match is matched there against the member's model (and id/model),
so only the tries on gemini-3.8-flash get the prompt. ctx.state.given
keeps a try from adding it a second time after onRequest did.

Run on mote: packages/system-prompt bun test, 24 pass 0 fail (13 new
cases); bun scripts/check.mjs, all ok. In magpie's own engine: a
throwaway test in a detached magpie worktree at origin/main (removed, not
committed) loaded this module through internal/middleware's Begin,
Request and Tried in moejs: google/ and openrouter/google/gemini-3.8-flash
got it once, gemini-3.8-pro none, group/fast got it on the google
gemini-3.8-flash try and not on a deepseek try, no failures counted.
Broken by hand: with the old startsWith in onRequest, the 4 name cases go
red; with onProvider not exported, the 2 group-try cases; without
ctx.state.given, the "not given it twice" case.
Not tried: a real agent through a real magpie gateway and Gemini account.
Without override, an agent's own system prompt is kept and none is
added, as before; the README's example sets override.
2026-11-09 14:54:54 +08:00
..
middleware: param-override, model-map, system-prompt, word-guard and think-tags — gateway middleware that magpie runs on every agent's requests and replies, mostly New API's channel settings with the same JSON (the owner) — magpie can now run a plugin as gateway middleware (onRequest, onEvent, onResponse, in-process on moejs), and these are the first ones: param-override is New API's param_override (both forms, operations with gjson paths and conditions, return_error); model-map is model_mapping (chains, /regex/ keys with $1) and puts the asked-for name back into replies; system-prompt adds a prompt in each API's own place, keeping an agent's own unless override (New API's semantics), by agent or model; word-guard is the sensitive-word filter (reject or mask the user's text, optionally replies); think-tags strips a leading <think>…</think> from replies across stream chunks, or puts Chat reasoning_content into the text (thinking_to_content). Each is one file with no imports, named @magpie-community/middleware-<name>, with magpie.options as the example the app's editor starts from; registry.json lists them with "kind": "middleware" and no providers; check.mjs skips middleware-only packages. scripts/middleware.mjs calls the hooks as the gateway does (events split, [DONE] passed by) and runs each package's cases.json. Tested with a real DeepSeek account and real Claude Code through magpie's gateway: a mapped model named back in message_start, max_tokens capped, a system prompt appended for claude only, a word turned away as a 400 in Anthropic's shape, return_error as a 403 in Chat's, <think> stripped from Chat and Responses streams and an Anthropic whole reply, reasoning_content moved into the text. bun test (61 for these five) and bun scripts/check.mjs pass; packages/devin's two image tests fail on this machine only, as on main. Their first npm version has to be published by hand (trusted publishing can't create a package); until then magpie shows them as Coming soon.
2026-10-05 20:49:42 +08:00