Files
R227BOUT 735e83e621 raccoon 0.1.13: the daily pool is its own window (#1178)
The raccoon card shows the daily pool (`daily_points`: 300 credits a day, each lasting 7 days) as its own "Daily pool" window, read as used / limit with a limit of max(2,100, daily_points, the unexpired daily grants in bills), along with its next expiry. When the pool is shown, routing weighs it and the aggregate Credits window becomes display-only (`aside`). The `setting_info` fallback and accounts with a daily pool of 0 keep Credits as the only weighted window. Version 0.1.13.

Run at 7d2bbf94 on mote (rebased on d123d540):
- `bun test packages/raccoon`: 58 pass, 0 fail.
- `bun scripts/check.mjs raccoon`: ok.

Broken by hand: with main's index.mjs under the PR's tests, 3 fail (the daily pool's used / limit, a daily_points over 2,100, and Credits when the bills cover every grant). The other 47 pass.

Not tried: a real Raccoon account. The window values come from the author's account data.

Co-authored-by: R227BOUT <235274933+R227BOUT@users.noreply.github.com>
2026-11-15 22:43:54 +08:00

7.5 KiB
Raw Permalink Blame History

@magpie-community/opencode-raccoon-auth

OpenCode & Magpie provider plugin for SenseTime Raccoon (商汤小浣熊, xiaohuanxiong.com).

Features

  • Sign-in methods:
    1. Browser OAuth with automatic loopback return: confirm authorization in the browser; no desktop client or pasted code is needed.
    2. Manual callback URL / token fallback (paste office-raccoon://auth/callback?code=..., or raw JWT access_token / JSON token pair).
    3. Raccoon desktop live session reuse (strictly read-only, reading the auth.json the desktop app keeps — <profile>/agent/config/auth.json in current builds, where the profile is ~/Library/Application Support/office-raccoon on macOS and %USERPROFILE%\.office-raccoon on Windows, and ~/.box-agent/config/auth.json in older ones — without writing or spending desktop refresh tokens). A desktop seat keeps the token it was signed in with on its own record, so it is never answered with, and never reports, another account's credentials or credits; once its own token is refused or runs out it asks to be signed in again. The app's own refresh token is still never spent.
  • Token renewal: single-flight proactive refresh 5 minutes before expiration for browser logins.
  • Dynamic model catalog & credit rates: real-time synchronization from /api/web/llm/v2/model_catalog with context window, output limit, vision/reasoning tags, credit multipliers, and limited-free markers.
  • Usage & allowances: reports available credits, unexpired grant bills, daily expiration timestamps, and Pro/Free subscription plans. The Daily pool window (daily_points: 300 credits granted per day, each slice lasting 7 days, so 2,100 at most) reads used / limit like every other window (144 / 2,100) and carries the next expiry date. It is the only balance that lapses, so it is what routing weighs; the aggregate Credits window beside it is display-only (aside). When /points/v1/balance answers 403 and the balance comes from setting_info, there is no daily_points there: the card then shows Credits alone, still carrying the routing weight.
  • Daily check-in & desktop onboarding grant: supports Magpie automatic daily check-in (+300 credits/day) and one-time desktop onboarding grant (+3000 credits).
  • SSE model rewrite: transparently rewrites internal upstream model names back to requested downstream models for client compatibility.
  • The card's name: the account's own phone number (138****8000), read once per token from /api/web/auth/v1/user_info with the JWT the sign-in holds. accountId stays the account's identity (the JWT's Raccoon-pu-<uuid>, or the desktop app's name) — magpie keys the user's own name for the account, its proxy, model picks and a gateway key's list by it, so it never changes. The card shows usage's user, which is the phone once a sign-in or renewal has read it. A failed read changes nothing and never costs a sign-in.

中文

商汤小浣熊(SenseTime Raccoon / xiaohuanxiong.com)OpenCode & Magpie 提供商插件。

功能特性

  • 多种登录方式:
    1. 浏览器 OAuth 授权登录:确认授权后自动返回,无需安装官方桌面客户端,也无需输入短信验证码或粘贴网页地址。
    2. 手动回调 / Token 备用入口:粘贴 office-raccoon://auth/callback?code=... 完整回调链接,或 access_token / JSON;普通授权网页地址和单独授权码不能代替完整回调。
    3. 直接只读复用本机商汤小浣熊客户端实时登录态(客户端保存的 auth.json:新版在客户端配置目录下的 agent/config/auth.json(macOS 为 ~/Library/Application Support/office-raccoon,Windows 为 %USERPROFILE%\.office-raccoon),旧版在 ~/.box-agent/config/auth.json)。桌面端席位会把登录时读到的 token 保存在自己的账号记录里,因此它不会拿到、也不会上报另一个账号的凭据或积分;一旦自己的 token 被拒或用尽,就提示重新登录(客户端自身的 refresh token 依旧不会被动用)。
  • Token 自动续期:浏览器登录账号过期前 5 分钟自动单飞刷新。
  • 动态模型目录与积分倍率:实时同步 /api/web/llm/v2/model_catalog,展示模型上下文、最大输出、视觉/思考能力、积分倍率与限免(Free)标识。
  • 积分余额与套餐查询:展示可用积分、未过期发放额度、每日积分过期时间与 Pro/Free 套餐状态。每日池(Daily pool 窗口,daily_points,每天 300 分、每份存 7 天,上限 2,100)与其余窗口同向显示「已用 / 上限」(144 / 2100)并附最近一次过期时间。它是唯一会作废的余额,所以由它承担路由权重;旁边的聚合 Credits 窗口标 aside 只显示不参与路由。积分余额接口 /api/web/points/v1/balance 拒绝时(403),改从 /api/web/office/v3/setting_info 读可用积分——这里读不到 daily_points,此时卡片只显示 Credits 且照常参与路由。套餐接口读不到时不显示套餐,而不是当作 Free。余额比账单里未过期的发放额度略多时(10% 以内),以这批发放下见过的最高余额作总额,之后用掉的积分记为已用;有新的发放或发放过期时重新计。
  • 每日签到与桌面端登录奖励:支持 Magpie 每日自动签到(+300 积分/天)及首次桌面端 +3000 积分登录奖励领取。
  • SSE 模型名重写:将上游响应中的内部模型名重写为下游请求的 model,确保 Claude Code / Codex / OpenCode 等客户端兼容。

Browser callback lifecycle

The browser flow uses the authorize page's desktop_callback=loopback contract, a random 64-character hex state and http://127.0.0.1:<port>/auth/callback. The listener accepts only the matching host, GET path and state. Invalid callbacks leave the pending login intact; success, authorization refusal, exchange failure or the ten-minute deadline close it. A browser page says success only after the code exchange succeeds; response pages contain no code or token and disable caching. Closing/cancelling the host UI does not notify this plugin through the OpenCode callback contract, so an abandoned listener expires at that deadline. When a remote browser cannot reach that machine's loopback, Magpie can forward a pasted final callback URL; the separate manual method remains available as well.

Desktop seats

The desktop app is signed in to one account at a time and keeps only that account's JWT in auth.json. A desktop seat therefore saves the token it was signed in with on its own record and uses it for every request, reading the app only to pick up a newer token for that same account. A seat whose account the app no longer holds is never answered with the app's current token: it keeps using its own until that token is refused, and then asks to be signed in again, rather than being billed to an account it does not name. Adding a seat takes only the account the app holds at that moment.

Note that signing in to a second account in the desktop app revokes the first account's session on the vendor's side, so the first seat's token stops being accepted then — its exp notwithstanding — and is answered 401 {"code":200003} by the credits and check-in endpoints, with every refresh endpoint answering 404 for it (#166, measured on a real pair of accounts). Two desktop seats are therefore one live account plus one seat waiting to be signed in again, never two working seats. For two accounts that both work, sign in twice through the browser method.