Files
plugins/packages/loomy
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-loomy-auth

OpenCode / magpie provider 插件:Loomy(讯飞,loomyad.xunfei.cn)——登录、模型清单、聊天转发、双积分钱包与每日赠送积分刷新(签到)。

请求形态移植自 aimod-cc/agent2api(MIT)的 providers/loomy,按 magpie 插件 API 重写。

安装

magpie plugin add @magpie-community/opencode-loomy-auth
magpie plugin login loomy     # 选「短信验证码登录」或「手动粘贴 session」

能力

  • 登录:短信验证码登录(发码 → 输入 6 位码完成,session 14 天)或 手动粘贴 session。
  • 无续期接口:session 过期(业务码 020002/100002)需重新登录(短信或粘贴)。
  • 聊天:POST {modelBase}/chat/completions,OpenAI 形态基本透传,两处适配(参照实现 reasoning_patch / images.rs):思考档折进 low/medium/high(超档删除)、DeepSeek 系模型的 data-URI 图片转 <image_base64> 标记;SSE;请求头必须带 charset=utf-8(上游对无 charset 的 body 按 GBK 解码)。
  • 画图:POST {modelBase}/images/generations(doubao-seedream-5-lite / qwen-image-3.0-pro / Hy-Image-3.5-preview),body 按 magpie 写的原样透传,Accept: application/json(不是 SSE),回答是普通 JSON(data[].url、points_consumed)。401/403 报登录失效。/images/edits(改图)暂不转发:magpie 发给插件的改图是 multipart,Loomy 网关收不收这种改图没有实测过(#609)。
  • 模型:登录前给静态表(2026-10-16 实抓 /api/v1/models 的 chat 模型:DeepSeek-V4.1-Flash / deepseek-v4-flash-0731 / MiniMax-M3 / Kimi-k2.6 / qwen-3.8-max / GLM-5.3-Flash / qwen3.8-flash / spark-x / mimo-v2.5 / auto),登录后以 GET /api/v1/models 的实时目录为准(能力位读 capabilities;展示名尾部倍率 (x3.0) 拆为 rate 字段)。
  • 余额(usage):GET /api/v2/points/records?... → 永久积分 + 每日赠送积分两个窗口;每日窗口用厂商自己的 dailyLimitPoints/dailyRemainingPoints 报「已用/剩余/上限」,厂商未带这一对时按无上限的余额展示(不编造上限)。响应缺余额字段时报 error("未知"不冒充 0)。
  • 签到判定:first-login 接口对"当天首登"与"重复调用"都返回成功,插件用调用前后的每日余额差判定——涨了 = claimed(今日首登奖励),没涨 = done(已领过/无每日钱包)。
  • 每日签到(checkin):POST /api/v1/points/first-login(body {})——服务端按"当天是否第一次"把每日赠送刷回;按天幂等,重复调=成功。这是厂商客户端自己就会发的那个单请求(判定见上)。

账号域签名说明

登录两步(POST https://account.xfinfr.com/login/phone/{sendMsgCode,checkCode})带 HMAC-SHA1 签名头(9 段待签串,AK/SK 为客户端内置常量),插件按参照实现同款实现(见 index.mjs 的 signHeaders)。

环境变量(测试 / 镜像用,与 agent2api 同名)

变量 默认
LOOMY_XFYUN_BASE_URL https://account.xfinfr.com(登录域,HMAC 签名;来自客户端安装包 app.asar 内解密的 .env.prod 的 VITE_XFYUN_BASE_URL,是讯飞账号域 CAccount 自己的 host)
LOOMY_POINTS_BASE_URL https://loomyad.xunfei.cn(积分/签到/模型网关)

测试

bun test packages/loomy

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

许可

MIT。请求逻辑移植自 aimod-cc/agent2api(MIT)。