Files
plugins/packages/catpaw
yetone 17e5ef7457 all: load on OpenCode 2.x through a default {id, setup} (#657)
nbczw8750 (#657): trae 0.2.26 on OpenCode 2.2.5 fails with "Plugin
must export a default definition with an id and an effect or setup
function. (cause: SchemaError(Missing key at ["default"]))". 2.x
imports a package's exports["."] (a plugin dir and an npm install
alike) and has no V1 path at all, so every package here that serves
models failed the same way, not only trae.

Every one of the 32 model packages now has:
- opencode2.mjs, exports["."]: a copy of scripts/opencode2.mjs, an
  adapter that runs the package's V1 plugins inside 2.x's promise
  API. Config providers become 2.x providers (package pinned so the
  aisdk sdk hook runs), V1 auth methods become integration methods
  (oauth auto/code with forms; api without authorize as a key method),
  V1 credentials are kept in metadata.v1, the loader's baseURL,
  apiKey, headers and fetch are applied through the sdk hook, an
  auth.set renewal is stored per credential, and credential.switched
  /updated reload the account's own model list.
- opencode.mjs, main: re-exports the V1 plugin functions only.
  OpenCode 1.x and magpie's host.js take main. On 1.x, trae 0.2.26's
  main exported a non-plugin (_internal) and 1.19.5 refused it ("Plugin
  export is not a function"); the new main fixes that too.
- both files in "files"; patch version bumped. devin already had 2.x
  and is unchanged.

scripts/check.mjs fails a model package whose 2.x entry has no default
{id, setup}, whose opencode2.mjs differs from the canonical one, whose
entry is missing from files, or whose main exports a non-plugin.

Run at this head (mote):
- HOME=$(mktemp -d) bun test, as CI runs it: 4900 pass, 0 fail
  (4914 tests, 374 files). A first run set globalThis.fetch for the
  whole process from opencode2.test and failed 528 tests in other
  packages; the block is now set and put back around that file's tests.
- bun scripts/check.mjs: every package passes. With the network
  blocked cloudflare-workers-ai fails on its fetched catalog, the same
  on origin/main.
- Real OpenCode 2.2.5 (npm opencode-ai), sandbox HOME, packed trae
  0.2.27: loads with no error; /api/integration lists trae-cn "Trae CN"
  and trae-global "Trae Global" with their browser sign-ins; `auth
  login` starts the trae.cn authorization and waits (cancelled there);
  with a fake credential POSTed to /api/credential, `opencode models`
  lists trae-cn's six models.
- Real 2.2.5 with a fake V1 key plugin through the same adapter
  against a local fake server: `auth login` with a key, `models`,
  `opencode run` reached /real/v1/chat/completions with the loader's
  "Bearer loader-sk-fake" and header, and printed the fake's reply;
  with @ai-sdk/anthropic it reached /real/v1/messages with x-api-key
  from the loader. This run found the key method missing after 2.x's
  second integration transform (a once-only flag outside the
  transform); fixed, and opencode2.test checks a rebuild.
- Real OpenCode 1.19.5, sandbox HOME, trae 0.2.27: `opencode models`
  lists trae-cn and trae-global models; 0.2.26 failed there.

Broken by hand (scratch copy, bun test scripts/ and check.mjs):
- trae's exports back to "./index.mjs": the trae 2.x test fails
  (default.id undefined), check fails trae with "OpenCode 2.x:
  ./index.mjs has no default {id, setup} (plugins#657)".
- zed's opencode2.mjs changed: the copies test fails, check fails zed
  "differs from scripts/opencode2.mjs".
- the key flag back outside the transform: the 1.x plugin test fails
  on the rebuilt sign-ins (key missing).

Not tried: a real sign-in with a real account on 2.x; Windows (the
reporter's OS); chat.headers, chat.params, usage and tool hooks, which
the adapter doesn't carry to 2.x; the tools/pages packages (calc,
goanyapi, layerfs, search1api, aelios, agent-console, chat,
fingerprint, nowledge-mem, kimi-desktop), which still load only on 1.x.
2026-11-03 13:54:26 +08:00
..

@magpie-community/opencode-catpaw-auth

OpenCode / magpie provider 插件:妙手(CatPaw,美团 ai.catpaw.meituan.com)——登录、模型清单、聊天转发、余额查询。

请求形态按妙手桌面客户端 2026-10-09 的真实抓包移植(round → event(running) → turn(SSE) 简化链路,无跨请求会话复用):请求头、permissionMode 均为客户端原样取值,脱敏抓包存于 testdata/captured-*.json,测试逐键比对。

安装

magpie plugin add @magpie-community/opencode-catpaw-auth
magpie plugin login catpaw     # 选「网页登录」/「妙手桌面端登录态」/「手动粘贴 token」

能力

  • 登录:
    • 网页登录:插件问 login-config 取官方登录页,浏览器完成登录后,插件按官方客户端同款 poll-token 通道每秒轮询 ?sid 直接拿 token——服务端对服务端,无监听端口、不受浏览器私有网络检查(PNA)影响;再问一次 current-user 补 uid/昵称(失败不影响登录)。
    • 妙手桌面端登录态:每次请求前实时读 ~/.meituan-catpaw/auth.json(mtime 缓存 5 分钟内;重开妙手即自动刷新)。
    • 手动粘贴 token。
  • 无续期接口:token 过期后 401,网页登录重新发起一次即可;桌面端登录态则在妙手里重新登录(下一请求自动读新 token)。
  • 聊天:round → event → turn 三步会话机;上游 SSE 帧为累积式,插件做差分转 OpenAI delta(content + reasoning_content),流式与非流式都支持。
  • 模型:妙手桌面端的 9 个模型(longcat-2.0 / glm-5.3 系列 / deepseek-v4 系列 / minimax-m3 / kimi-k3 / auto),静态表(无远程目录接口)。不声明各模型的上下文/输出窗口(客户端未公布,不编造数字),也不声明图片输入(见下)。
  • 工具与图片:会话协议只收一段扁平文本 prompt,工具定义、工具结果与图片都无法送达——带这些的请求以 400 明确拒绝(而不是悄悄丢掉后答错)。
  • 余额(usage):GET https://catx.nocode.cn/api/gateway/credit/balance,鉴权头是 X-Auth-Token: <accessToken>。
    • ⚠️ 这个接口与聊天网关不是同一个鉴权头:它只认 X-Auth-Token,把聊天用的 Cookie: X-Passport-Token 发到这里会稳定 401(body code 4010)。magpie 把 usage 的 401 当作「登录态失效」,所以鉴权头必须分开核对。
    • 读成功后不带 signIn 字段:magpie 以此把「已退出登录」的标记撤掉。
  • 无签到: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(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 分钟(带工具循环的长回答全程在推流,更短会把长回答掐断)。

环境变量(测试 / 镜像用)

变量 默认
CATPAW_AUTH_PATH ~/.meituan-catpaw/auth.json(妙手桌面端登录态)
CATPAW_BALANCE_URL https://catx.nocode.cn/api/gateway/credit/balance(余额接口,测试用)
CATPAW_PASSPORT_BASE https://catx.nocode.cn(网页登录的 passport 域,测试用)

测试

bun test packages/catpaw

测试打到本地假上游(fake.mjs),不触网、不使用真实 token。

许可

MIT。