autoclaw 0.2.8: the credit balance is the card's balance, not a meter reading "剩余 100%" (#376)
moxuanchen: AutoClaw's credits are a bare balance with no limit and no
amount used, but usage() also sent them as a window with used: 0, so the
card read "500 积分 · 剩余 100%" whatever was left. The total, and the
wallets it breaks into, now go in balance only ("1234 积分(赠送积分 500 ·
会员积分 734)"). The daily check-in row stays a window.
Not changed here: magpie's card gives every window a share, so an aside
row that only carries text (the check-in row here, and the same pattern
in cline, cursor, factory and zcode) still shows "· 0% used / 100% left".
That is magpie's rendering, not this plugin's.
Run: HOME=<scratch> bun test packages/autoclaw, 38 pass; the new test is
red on 0.2.7. bun scripts/check.mjs autoclaw ok. Not tried against the
real API.
This commit is contained in:
@@ -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` 回执)→ 获取授权页 →
|
||||
|
||||
@@ -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: [] };
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user