catpaw 0.1.1: round and turn send source CatX / mode CATX_APP; the gateway turned CatPawCLI off (#605)

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.
This commit is contained in:
yetone
2026-11-02 00:10:44 +08:00
parent 25a50db0fa
commit 8db0a0576a
6 changed files with 94 additions and 16 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ magpie plugin login catpaw # 选「网页登录」/「妙手桌面端登录
## 协议细节
- 请求头(客户端抓包原样):`m-appkey: com.sankuai.mcopilot.cli`、`m-debug: true`、`User-Agent: axios/1.19.0`、`m-traceid`/`x-request-id`/`x-trace-id` 每请求随机、`x-agent-version: 1.2.0-beta.6`、`Cookie: X-Passport-Token=...`(聊天网关 `ai.catpaw.meituan.com`);抓包里的 `m-host` 是客户端本机局域网 IP,插件不发这个头。
- 请求体(客户端抓包原样):`source: CatX`、`mode: CATX_APP`、`permissionMode: "unsafeBypassPermissions"`、`toolVersion: 2.0.2`。
- 请求体:`source: CatX`、`mode: CATX_APP`(round 与 turn 同一份)、`permissionMode: "unsafeBypassPermissions"`、`toolVersion: 2.0.2`。2026-10-09 抓包里的 `CatPawCLI` / `CLI` 已被网关停用(返回 `code=400 msg=source 不存在或未启用: CatPawCLI`,plugins#605),0.1.1 起改回 `CatX` / `CATX_APP`,请求头不变。
- **注意**:上表是**聊天网关**的头;**余额接口**(`catx.nocode.cn`)改用 `X-Auth-Token`(见上)。
- turn SSE 总超时:15 分钟(带工具循环的长回答全程在推流,更短会把长回答掐断)。
+11 -1
View File
@@ -11,6 +11,11 @@ export function fakeCatPaw() {
events: 0,
turns: 0,
turnError: null, // "sse-error" makes the turn stream send an error frame
// sources the gateway has turned off: it answers them HTTP 200 with
// {code: 400, msg: "source 不存在或未启用: <source>"}, the body behind
// plugins#605. CatPawCLI was turned off by 2026-11-01.
disabledSources: new Set(["CatPawCLI"]),
turnBodies: [],
balanceCalls: 0,
// the web sign-in: sids awaiting their token, like the real vendor
webSids: new Map(), // sid -> token to hand out
@@ -23,6 +28,8 @@ export function fakeCatPaw() {
state.events = 0
state.turns = 0
state.turnError = null
state.disabledSources = new Set(["CatPawCLI"])
state.turnBodies = []
state.balanceCalls = 0
state.webSids = new Map()
state.webTokens = new Set()
@@ -83,7 +90,8 @@ export function fakeCatPaw() {
if (url.pathname === "/api/agent/conversation/round") {
state.rounds++
if (body.source !== "CatPawCLI" || body.mode !== "CLI") return json(400, { code: 400, msg: `source/mode wrong: ${body.source}/${body.mode}` })
if (state.disabledSources.has(body.source)) return json(200, { code: 400, msg: `source 不存在或未启用: ${body.source}` })
if (body.source !== "CatX" || body.mode !== "CATX_APP") return json(400, { code: 400, msg: `source/mode wrong: ${body.source}/${body.mode}` })
state.conversations.push({ id: body.conversationId, modelType: body.modelType, prompt: body.message?.content?.[0]?.text ?? "", token: (req.headers.get("cookie") ?? "").match(/X-Passport-Token=([^;]+)/)?.[1] ?? "", permissionMode: body.permissionMode, source: body.source, mode: body.mode })
return json(200, { code: 0, data: { conversationId: body.conversationId } })
}
@@ -96,7 +104,9 @@ export function fakeCatPaw() {
if (url.pathname === "/api/agent/conversation/turn") {
state.turns++
state.turnBodies.push(body)
const conv = state.conversations.at(-1)
if (body.source !== conv?.source || body.mode !== conv?.mode) return json(400, { code: 400, msg: `turn source/mode ${body.source}/${body.mode} differ from the round's` })
if (body.conversationId !== conv?.id) return json(400, { code: 400, msg: "turn for unknown conversation" })
if (state.turnError === "sse-error")
return new Response(`data: ${JSON.stringify({ error: { code: 500, message: "vendor broke" } })}\n\n`, { headers: { "content-type": "text/event-stream" } })
+15 -9
View File
@@ -132,6 +132,16 @@ function gatewayHeaders(token, extra = {}) {
}
}
// BODY_IDENTITY is the source/mode the round and turn bodies carry. The
// 2026-10-09 capture (testdata/captured-*.json) had the CLI's CatPawCLI/CLI,
// but by 2026-11-01 the gateway answered that source with HTTP 200
// {code: 400, msg: "source 不存在或未启用: CatPawCLI"} on every round
// (plugins#605). CatX/CATX_APP is the desktop app's source; the reporter
// verified a real request with it and these unchanged headers, and the
// package README has documented it from the start. Both bodies spread this
// one object, so they can never name different sources.
const BODY_IDENTITY = Object.freeze({ source: "CatX", mode: "CATX_APP" })
async function gatewayPost(pathname, body, token, extraHeaders, signal) {
const res = await fetch(ORIGIN + pathname, {
method: "POST",
@@ -186,11 +196,8 @@ async function* runConversation(token, chat, signal) {
conversationId: convId,
message: { type: "user", messageId: msgId, content: [{ type: "text", text: prompt }], finished: true },
modelType,
// the client's own round body (testdata/captured-round.json): CLI
// identity end to end — these source/mode values ride the same
// captured request as the CLI headers gatewayHeaders sends
source: "CatPawCLI",
mode: "CLI",
// see BODY_IDENTITY: the source the gateway still serves
...BODY_IDENTITY,
// the client's own round/turn bodies carry this exact value (captured
// 2026-10-09, both requests) — the client's default, not ours
permissionMode: "unsafeBypassPermissions",
@@ -222,9 +229,8 @@ async function* runConversation(token, chat, signal) {
turnRequestId: turnId,
message: { type: "user", messageId: msgId, content: [{ type: "text", text: prompt }], finished: true },
modelType,
// the client's own turn body (testdata/captured-turn.json): CLI identity
source: "CatPawCLI",
mode: "CLI",
// see BODY_IDENTITY: round and turn always name the same source
...BODY_IDENTITY,
// the client's own round/turn bodies carry this exact value (captured
// 2026-10-09, both requests) — the client's default, not ours
permissionMode: "unsafeBypassPermissions",
@@ -628,4 +634,4 @@ export async function CatPawAuthPlugin({ client } = {}) {
}
// for tests
export const _internal = { ID, NAME, MODELS, modelTypeOf, buildPrompt, gatewayHeaders, gatewayHeadersForTest: gatewayHeaders, readAuth, authPath, configModel }
export const _internal = { ID, BODY_IDENTITY, NAME, MODELS, modelTypeOf, buildPrompt, gatewayHeaders, gatewayHeadersForTest: gatewayHeaders, readAuth, authPath, configModel }
+59 -4
View File
@@ -7,6 +7,7 @@ import { CatPawAuthPlugin, _internal } from "./index.mjs"
import { fakeCatPaw } from "./fake.mjs"
import capturedRound from "./testdata/captured-round.json"
import capturedTurn from "./testdata/captured-turn.json"
import issue605 from "./testdata/issue-605.json"
// every test runs against the fake upstream in fake.mjs: no network, no real
// token ever leaves this process. The upstream base is monkey-patched because
@@ -399,10 +400,10 @@ describe("captured protocol", () => {
})
const sent = fake.state.conversations[0]
expect(sent.permissionMode).toBe(capturedRound.bodyProtocol.permissionMode)
// one client identity end to end: the body's source/mode are the same
// captured request's values as the headers are
expect(sent.source).toBe(capturedRound.bodyProtocol.source)
expect(sent.mode).toBe(capturedRound.bodyProtocol.mode)
// source/mode are not the capture's any more: the gateway turned the
// captured CatPawCLI off (plugins#605), see the "source" tests below
expect(sent.source).toBe(issue605.served.source)
expect(sent.mode).toBe(issue605.served.mode)
})
test("the captured turn request carries the same permissionMode", () => {
@@ -411,6 +412,60 @@ describe("captured protocol", () => {
})
})
describe("source (plugins#605)", () => {
const chat = async (stream) => {
const loader = await plugin.auth.loader(getAuth)
const res = await loader.fetch("https://ai.catpaw.meituan.com/v1/chat/completions", {
method: "POST",
body: JSON.stringify({ model: "glm-5.3-flashx", stream, messages: [{ role: "user", content: "hi" }] }),
})
return { status: res.status, text: await res.text() }
}
test("the fake refuses CatPawCLI with the reporter's exact bytes", async () => {
// the fake's refusal, fed through the plugin's own round error format,
// is the reporter's line word for word (minus magpie's "妙手 CatPaw: ")
const res = await fetch("https://ai.catpaw.meituan.com/api/agent/conversation/round", {
method: "POST",
headers: _internal.gatewayHeaders(fake.state.token),
body: JSON.stringify({ conversationId: "c", source: "CatPawCLI", mode: "CLI" }),
})
const body = await res.json()
expect(res.status).toBe(issue605.upstreamStatus)
expect(body).toEqual(issue605.upstream)
expect(`妙手 CatPaw: 妙手 round 失败:HTTP ${res.status} code=${body.code} msg=${body.msg}`).toBe(issue605.reported)
})
test("a chat no longer meets the reporter's refusal: round and turn both name CatX/CATX_APP", async () => {
for (const stream of [true, false]) {
fake.state.reset()
const { status, text } = await chat(stream)
expect(text).not.toContain(issue605.upstream.msg)
expect(status).toBe(200)
expect(text).toContain("收到")
expect(fake.state.conversations[0].source).toBe("CatX")
expect(fake.state.conversations[0].mode).toBe("CATX_APP")
expect(fake.state.turnBodies).toHaveLength(1)
expect(fake.state.turnBodies[0].source).toBe("CatX")
expect(fake.state.turnBodies[0].mode).toBe("CATX_APP")
}
})
test("the headers stay the captured client's: only the body's source changed", () => {
const ours = _internal.gatewayHeaders("t")
expect(ours["m-appkey"]).toBe(capturedRound.headers["m-appkey"])
expect(ours["x-agent-version"]).toBe(capturedTurn.headers["x-agent-version"])
expect(ours["User-Agent"]).toBe(capturedRound.headers["user-agent"])
})
test("if the gateway turns the source off again, the user reads its words", async () => {
fake.state.disabledSources.add(_internal.BODY_IDENTITY.source)
const { text } = await chat(true)
expect(text).toContain(`妙手 round 失败:HTTP 200 code=400 msg=source 不存在或未启用: ${_internal.BODY_IDENTITY.source}`)
expect(fake.state.turns).toBe(0)
})
})
describe("helpers", () => {
test("model type mapping", () => {
expect(_internal.modelTypeOf("longcat-2.0")).toBe(77)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-catpaw-auth",
"version": "0.1.0",
"version": "0.1.1",
"description": "OpenCode & Magpie provider plugin for Meituan's 妙手 CatPaw (ai.catpaw.meituan.com): web sign-in or the desktop client's saved credentials, chat through the round/event/turn protocol, models and credit balance",
"type": "module",
"main": "./index.mjs",
+7
View File
@@ -0,0 +1,7 @@
{
"note": "plugins#605 (1007cordon-ux, 2026-11-01): what magpie showed for every chat with plugin 0.1.0, verbatim. The plugin formats a refused round as `妙手 round 失败:HTTP <status> code=<code> msg=<msg>`, so the gateway answered HTTP 200 with the body under `upstream`. The reporter verified that source CatX / mode CATX_APP, with the same headers, gets a normal completion.",
"reported": "妙手 CatPaw: 妙手 round 失败:HTTP 200 code=400 msg=source 不存在或未启用: CatPawCLI",
"upstreamStatus": 200,
"upstream": { "code": 400, "msg": "source 不存在或未启用: CatPawCLI" },
"served": { "source": "CatX", "mode": "CATX_APP" }
}