Files
plugins/packages/system-prompt/cases.json
T
yetone d9236e976f 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

49 lines
2.9 KiB
JSON

[
{ "name": "Anthropic: none is given this one",
"options": { "system_prompt": "Be brief." },
"request": { "model": "m", "messages": [] },
"expect_request": { "model": "m", "messages": [], "system": "Be brief." } },
{ "name": "Anthropic: an agent's own stays without override",
"options": { "system_prompt": "Be brief." },
"request": { "model": "m", "system": "You code." } },
{ "name": "Anthropic: override appends a block after the cached ones",
"options": { "system_prompt": "Be brief.", "override": true },
"request": { "model": "m", "system": [{ "type": "text", "text": "You code.", "cache_control": { "type": "ephemeral" } }] },
"expect_request": { "model": "m", "system": [{ "type": "text", "text": "You code.", "cache_control": { "type": "ephemeral" } }, { "type": "text", "text": "Be brief." }] } },
{ "name": "Anthropic: override prepends to a string, New API's way",
"options": { "system_prompt": "Be brief.", "override": true, "position": "prepend" },
"request": { "model": "m", "system": "You code." },
"expect_request": { "model": "m", "system": "Be brief.\nYou code." } },
{ "name": "Chat: a system message first",
"ctx": { "protocol": "chat" },
"options": { "system_prompt": "Be brief." },
"request": { "model": "m", "messages": [{ "role": "user", "content": "hi" }] },
"expect_request": { "model": "m", "messages": [{ "role": "system", "content": "Be brief." }, { "role": "user", "content": "hi" }] } },
{ "name": "Chat: override on a developer message",
"ctx": { "protocol": "chat" },
"options": { "system_prompt": "Be brief.", "override": true },
"request": { "model": "m", "messages": [{ "role": "developer", "content": "You code." }, { "role": "user", "content": "hi" }] },
"expect_request": { "model": "m", "messages": [{ "role": "developer", "content": "You code.\nBe brief." }, { "role": "user", "content": "hi" }] } },
{ "name": "Responses: instructions",
"ctx": { "protocol": "responses" },
"options": { "system_prompt": "Be brief.", "override": true },
"request": { "model": "m", "instructions": "You code.", "input": [] },
"expect_request": { "model": "m", "instructions": "You code.\nBe brief.", "input": [] } },
{ "name": "Gemini: systemInstruction",
"ctx": { "protocol": "gemini" },
"options": { "system_prompt": "Be brief." },
"request": { "contents": [] },
"expect_request": { "contents": [], "systemInstruction": { "parts": [{ "text": "Be brief." }] } } },
{ "name": "only the agents named",
"ctx": { "agent": "codex" },
"options": { "system_prompt": "Be brief.", "agents": ["claude"] },
"request": { "model": "m" } },
{ "name": "only the models named",
"options": { "system_prompt": "Be brief.", "models": ["deepseek"] },
"request": { "model": "deepseek-chat" },
"expect_request": { "model": "deepseek-chat", "system": "Be brief." } },
{ "name": "no prompt, nothing done",
"options": {},
"request": { "model": "m" } }
]