Files
plugins/packages
yetone 3e18b1a20d catpaw 0.2.2: out of credits is a 402 with the purchase link, not an answer (#933)
Out of credits, 妙手's gateway answers the turn HTTP 200 with the
sentence "当前余额不足以完成本次操作。[去购买更多](https://credit.catpaw.meituan.com/#/plan),
即可继续使用全部功能。" as the assistant's text, in frames with no error
field and no model / modelDisplayName. The plugin only read `error`, so
the agent got the sentence as the model's answer (and with tools, the
forced-tool retry spent a second turn on it).

Now a frame that names no model and whose text, before anything was
streamed, starts with "当前余额不足以完成本次操作" is the credit gate:
the request fails 402 with {type: insufficient_quota, code:
insufficient_credits, help_url, upstream_message}, the message with the
markdown link spelled out as "去购买更多 (https://…)". magpie's gateway
reads a 402 as failCredit: the account rests for credit and the next
one is tried, not counted as broken. A head that could still grow into
the sentence ("当前", "当前余额") is held until it does or doesn't; a
model's answer quoting the sentence names its model and passes as text.
"余额不足" in a round's msg, an SSE error frame or a non-200 body is a
402 too.

Streaming requests now wait for the conversation's first event (up to
10s) before answering, so the 402, and a round or turn's bare 429 / 401,
go out as their own status instead of an error chunk inside a 200. A
slower turn streams as before. The bare 429 now says it is 妙手's rate
limit with Retry-After: 45 (the reporter saw a ~41s cool-down), the
bare 401 that the sign-in has expired; both keep the step and status.

The fixture (testdata/issue-933.json) is the reporter's frames as the
issue quotes them; the elided finishing frame is filled in, and the
model fields of a normal answer are made up (the issue doesn't quote
their values).

Run in WSL (magpie-desktop) via wsl-run at this tree:
- bun test packages/catpaw: 73 pass, 0 fail
- bun scripts/check.mjs: exit 0, catpaw ✓

Broken by hand, each red, then restored:
- no gate throw: 4 of the new tests red (both 402 paths, tools, split)
- gate without the no-model condition: the quoting test red
- plain stream not primed: 402-before-streaming, split and 429 red
- tool stream not primed: the tools 402 and the 401 test red
- held head never flushed: the held-head test red
- 429 not mapped: the 429 test red

Not tried: no real CatPaw account, so neither the gate nor the bare
429/401 was met against the real gateway; the 409/400 mapping the
issue suggests for "会话未在执行中" is not done.

Reported-by: LIEGU0317
2026-11-10 18:36:01 +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