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
Reported by 1007cordon-ux in #605: every chat with 0.1.0 failed at the
round step with "妙手 round 失败:HTTP 200 code=400 msg=source 不存在或未启用:
CatPawCLI". The 10-09 capture the package was built from was the CatPaw
CLI's (source CatPawCLI, mode CLI, m-appkey com.sankuai.mcopilot.cli); the
gateway no longer serves that source. The reporter changed both bodies to
source CatX / mode CATX_APP, kept the headers, and got a normal completion
from catpaw/glm-5.3-flashx through a real gateway request. That is the
combination the package README documented from the start, and the same
author's magpie-catpaw-auth 0.2.3 on npm sends it with these same headers.
- index.mjs: one frozen BODY_IDENTITY ({source: "CatX", mode: "CATX_APP"})
spread into both the round and the turn body, so they can't differ.
Headers unchanged (m-appkey com.sankuai.mcopilot.cli, x-agent-version
1.2.0-beta.6, axios UA).
- fake.mjs: answers a disabled source (CatPawCLI) with HTTP 200
{code: 400, msg: "source 不存在或未启用: <source>"}, the body behind the
report, and refuses a turn whose source/mode differ from its round's.
- testdata/issue-605.json holds the reporter's line verbatim; a test checks
that the fake's refusal, put through the plugin's round error format, is
that line byte for byte.
- README: the protocol note says why the body isn't the capture's.
Not confirmed: whether the official CatX desktop app sends a different
m-appkey or x-agent-version. No official client is on npm, and the
CatPaw sites offer no download without signing in, so the headers stay the
captured CLI's (the reporter's verified combination).
Run on mote at this tree (mote-run -C the worktree):
- bun test packages/catpaw: 28 pass, 0 fail
- HOME=$(mktemp -d) bun test (root): 4550 pass, 9 skip, 0 fail, 352 files
- bun scripts/check.mjs: exit 0 (catpaw ✓)
Broken by hand, then restored:
- BODY_IDENTITY back to CatPawCLI/CLI: 9 fail, each chat error the
reporter's exact text ("妙手 round 失败:HTTP 200 code=400
msg=source 不存在或未启用: CatPawCLI").
- only the turn body back to CatPawCLI/CLI: 5 fail.
Not tried: a real CatPaw account (none available); the fix rests on the
reporter's real request.
Adds packages/catpaw (Meituan CatPaw): sign-in, paste-token sign-in, models, chat and usage. Hosts: ai.catpaw.meituan.com and catx.nocode.cn only; no dependencies or scripts; captures redacted.
Answers the 10-17 review: the request body's source/mode is CatPawCLI/CLI, matching the captured CLI round (testdata/captured-round.json, captured-turn.json) and enforced by the fake; the non-stream usage block that wasn't in the capture is gone; a no-credit error keeps the sign-in; the paste method returns a callback as the host calls it.
Run at 475979a (PR head 71f36ce with origin/main merged, loomy #175 included; registry.json conflict resolved keeping both entries), on mote with a sandbox HOME:
- bun test packages/catpaw: 24 pass, 0 fail
- bun scripts/check.mjs: exit 0 (catpaw ✓); bun test scripts: 3 pass, 0 fail
- Broken by hand, then restored: identity reverted to CatX/CATX_APP (8 fail), paste callback reverted (1 fail). The no-credit signIn:"kept" has no test (removing it stays green).
Not tried: a real CatPaw account. Not on npm yet: served from the dist branch until the first version is published by hand.