diff --git a/packages/autoclaw/README.md b/packages/autoclaw/README.md index 169f0d1..d345b2c 100644 --- a/packages/autoclaw/README.md +++ b/packages/autoclaw/README.md @@ -35,7 +35,7 @@ OpenCode 同样可加载(`opencode auth login`)。登录信息保存在 magp - 对话走 `POST {host}/autoclaw-proxy/proxy/autoclaw/v1/chat/completions`(`X-Authorization` 鉴权); - token 过期前自动轮换(refresh token 一次一换,`auth.refresh` 钩子交给 magpie 串行化,不会双花); -- 积分余额通过 `auth.usage` 显示(纯积分制,无总量上限,`aside` 窗口展示余额); +- 积分余额通过 `auth.usage` 的 `balance` 显示(纯积分制,无总量上限,不做成额度窗口,细分钱包写在括号里); - **国际版登录是完整本地实现**:插件在 127.0.0.1 上取官方 TokenServer 端口池中的一个端口 (18432/19654/19723/53699,OAuth client 回调白名单;被占自动顺延)起临时服务器,内嵌引导页完成 阿里滑块验证(`AliyunCaptcha` SDK,`ali_captcha_verify_param` 回执)→ 获取授权页 → diff --git a/packages/autoclaw/index.mjs b/packages/autoclaw/index.mjs index e1d74d0..99bfd16 100644 --- a/packages/autoclaw/index.mjs +++ b/packages/autoclaw/index.mjs @@ -822,13 +822,13 @@ function makeAutoclawPlugin({ providerId, providerName, homeHost, loginMethod }) }] : []; + // 积分是纯余额,没有总量也没有已用量:只放在 balance 里。做成 + // used: 0 的窗口,卡片会给它配上「剩余 100%」(#376)。细分钱包 + // 一并写进 balance。 + const parts = named.map((w) => `${w.name} ${Math.round(w.balance)}`); return { - balance: `${Math.round(total)} 积分`, - windows: [ - { name: "积分余额", used: 0, display: `${Math.round(total)} 积分`, aside: true }, - ...signinWindow, - ...named.map((w) => ({ name: w.name, used: 0, display: `${Math.round(w.balance)}`, aside: true })), - ], + balance: `${Math.round(total)} 积分${parts.length ? `(${parts.join(" · ")})` : ""}`, + windows: signinWindow, }; } catch (e) { if (e?.banned) return { error: e.message, signIn: "kept", windows: [] }; diff --git a/packages/autoclaw/index.test.mjs b/packages/autoclaw/index.test.mjs index 0fd4753..7cc2c36 100644 --- a/packages/autoclaw/index.test.mjs +++ b/packages/autoclaw/index.test.mjs @@ -612,6 +612,27 @@ test("signinOnUsage signs every account, also two with the same name", async () } }) +// #376 (moxuanchen): the credits are a bare balance, with no limit and no +// amount used; as a used: 0 window the card read "500 积分 · 剩余 100%" +test("usage: the credit balance and its wallets are the balance, never a window with a share", async () => { + const realFetch = globalThis.fetch + globalThis.fetch = async (input) => { + const u = String(input) + if (u.includes("wallets")) return Response.json({ code: 0, data: { total_balance: 1234.4, wallets: [ + { display_name: "赠送积分", balance: 500 }, { display_name: "会员积分", balance: 734.4 }, { display_name: "空", balance: 0 }, + ] } }) + return Response.json({ code: 0, data: null }) + } + try { + const hooks = await AutoclawAuthPlugin({ client: { auth: { set: async () => {} } } }) + const u = await hooks.auth.usage(async () => ({ type: "oauth", access: "a1" })) + expect(u.balance).toBe("1234 积分(赠送积分 500 · 会员积分 734)") + expect(u.windows.filter((w) => w.name !== "每日签到")).toEqual([]) + } finally { + globalThis.fetch = realFetch + } +}) + // #367 (menhouran): the overseas gateway answers X-Tm "linux" with // 403 {"message":"forbidden"} for a valid token; the official Linux client // sends "linux-x64", which it takes diff --git a/packages/autoclaw/package.json b/packages/autoclaw/package.json index 194f699..53c9030 100644 --- a/packages/autoclaw/package.json +++ b/packages/autoclaw/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-autoclaw-auth", - "version": "0.2.7", + "version": "0.2.8", "description": "OpenCode provider plugin for AutoClaw (Zhipu OpenClaw): oversea web sign-in (Google/z.ai) and CN phone SMS, multi-account pool, credit balance and daily check-in", "type": "module", "main": "./index.mjs",