astudio: Spark points count only the Spark models, so 0 of them no longer stops the account (#990)
AStudio has two pools: 通用积分 (general) and 星火积分 (Spark). Both
windows were sent as balances with aside: false and no model scope, and
magpie reads a balance window at <= 0 as used up for every model it
counts (allowanceOf on magpie main). So a Spark balance of 0 marked the
whole account used=100, and pace/smart never picked it, though
DeepSeek-V4-Flash and the other non-Spark models bill general points.
Change: the 星火积分 window now carries `models`, the Spark-series ids,
so magpie judges only those models on it (Limit.applies). Spark-series
means a catalog id starting with spark- (BOOTSTRAP's spark-x2.6,
spark-x2.6-4b, spark-x2.5, and the README's table): taken from the
account's live catalog (usage's provider.models) and, for ids that
catalog doesn't list, from BOOTSTRAP. A model the catalog marks free
(Spark-X2.6-Lite, 限免) is left out, since it spends no points; with no
model left the window is shown only (aside: true) rather than sent
unscoped. 通用积分 stays unscoped and still stops the account at 0.
Version 0.2.2.
Ran (wsl-run, magpie-desktop, HOME=$(mktemp -d)):
- bun test packages/astudio: 82 pass, 0 fail
- bun scripts/check.mjs: ok
- root bun test at base 017cd73e: 8211 pass, 19 skip, 0 fail (581 files)
Broken by hand: sending the Spark window without `models` (aside false
as before) turns 3 tests red, among them the reporter's case (general
1500, Spark 0: xopdsv4flash0731in judged not used up, spark-x2.6 still
used up on Spark).
Not tried: a real AStudio account or API call; magpie's own routing over
the new windows (the tests mirror allowanceOf/applies, read from magpie
main). Not known: whether a Spark model falls back to general points
when Spark is 0, so 通用积分 is left gating Spark models too, as before.
Reported-by: noblechang
This commit is contained in:
@@ -64,7 +64,7 @@ AStudio 有「每日登录积分」:账号面 `client-popups/pending` 里的 `
|
||||
|
||||
## 用量
|
||||
|
||||
有网页会话时显示真实数据:会员档(体验版/标准版/高级版/畅享版)、通用积分余额(含最近到期批次与时间)、星火积分余额与最早到期时间(`runsOutAt` / `runsOut`:60 天流水里未过期批次按到期日聚合,翻页读取,金额按余额封顶)。星火积分 7 天内到期时,签到消息会追加提醒。所有读取均不计费;模型调用本身才消耗账号额度。401/403/登录异常会把账号标记为需要重新登录。
|
||||
有网页会话时显示真实数据:会员档(体验版/标准版/高级版/畅享版)、通用积分余额(含最近到期批次与时间)、星火积分余额与最早到期时间(`runsOutAt` / `runsOut`:60 天流水里未过期批次按到期日聚合,翻页读取,金额按余额封顶)。两个池子分开算:星火积分只圈 `spark-` 开头的星火模型(限免的不算),用光只挡它们;其它模型扣通用积分,照常路由。星火积分 7 天内到期时,签到消息会追加提醒。所有读取均不计费;模型调用本身才消耗账号额度。401/403/登录异常会把账号标记为需要重新登录。
|
||||
|
||||
## 协议与上游
|
||||
|
||||
|
||||
@@ -81,6 +81,29 @@ const BOOTSTRAP = [
|
||||
{ id: "xopdsv4flash0731in", name: "DeepSeek-V4-Flash", context: 1048576, output: 32768 },
|
||||
]
|
||||
|
||||
// 星火系列模型:目录 id 以 spark- 打头(启动表 Spark-X2.6 / Spark-X2.6-Lite /
|
||||
// Spark-X2.5,实时目录同名)。只有它们扣星火积分,其它模型(DeepSeek、GLM、
|
||||
// Auto)扣通用积分(plugins#990)。
|
||||
const SPARK_MODEL = /^spark-/i
|
||||
|
||||
// sparkModelIds 是星火积分窗口要圈住的模型:账号实时目录里的星火模型(有目录时
|
||||
// 以目录为准,限免标记也以目录为准),再并上启动表里目录没列的星火模型。限免
|
||||
// 模型不扣积分,不圈进去——星火积分用光不该挡住它。
|
||||
function sparkModelIds(models) {
|
||||
const ids = new Set()
|
||||
const listed = new Set()
|
||||
for (const [key, m] of Object.entries(models && typeof models === "object" ? models : {})) {
|
||||
const id = typeof m?.id === "string" && m.id ? m.id : key
|
||||
if (!SPARK_MODEL.test(id)) continue
|
||||
listed.add(id)
|
||||
if (m?.free !== true) ids.add(id)
|
||||
}
|
||||
for (const m of BOOTSTRAP) {
|
||||
if (SPARK_MODEL.test(m.id) && !listed.has(m.id) && !m.free) ids.add(m.id)
|
||||
}
|
||||
return [...ids].sort()
|
||||
}
|
||||
|
||||
function join(...parts) {
|
||||
return parts.join("/")
|
||||
}
|
||||
@@ -693,7 +716,7 @@ function createPlugin({ fetchImpl = globalThis.fetch, env = process.env, homedir
|
||||
},
|
||||
// 有 Cookie 会话时显示真实积分余额与会员档;只有模型凭据时退回目录
|
||||
// 连通性检查。读取均不计费。
|
||||
async usage(getAuth) {
|
||||
async usage(getAuth, provider) {
|
||||
const auth = await getAuth()
|
||||
if (auth?.type !== "api" || !auth.key) return {}
|
||||
const session = auth.metadata?.session
|
||||
@@ -746,10 +769,14 @@ function createPlugin({ fetchImpl = globalThis.fetch, env = process.env, homedir
|
||||
// 星火积分的到期时间 balance 接口不给,从入账流水推(失败不塌方);
|
||||
// 流水是发放额,到期提示按余额封顶。
|
||||
const sparkExpiry = await readSparkExpiry(session, balance.sparkTotalBalance).catch(() => null)
|
||||
// 两个池子各管各的:星火积分只圈星火模型(models),用光只挡它们,
|
||||
// 不把整个账号判成用光;DeepSeek 等照扣通用积分照常路由(plugins#990)。
|
||||
// 圈不出模型时(全是限免)它挡不了谁,只显示。
|
||||
const sparkModels = sparkModelIds(provider?.models)
|
||||
windows.push({
|
||||
name: "星火积分",
|
||||
balance: balance.sparkTotalBalance,
|
||||
aside: false,
|
||||
...(sparkModels.length ? { aside: false, models: sparkModels } : { aside: true }),
|
||||
...(sparkExpiry && balance.sparkTotalBalance > 0 ? sparkExpiry : {}),
|
||||
})
|
||||
}
|
||||
@@ -933,5 +960,6 @@ export const _internal = {
|
||||
DESKTOP_WAIT_MS,
|
||||
WEB_SIGNIN_WAIT_MS,
|
||||
BOOTSTRAP,
|
||||
sparkModelIds,
|
||||
ID,
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ const {
|
||||
STUDIO_WEB_URL,
|
||||
OFFICIAL_SITE,
|
||||
DESKTOP_WAIT_MS,
|
||||
BOOTSTRAP,
|
||||
sparkModelIds,
|
||||
ID,
|
||||
} = _internal
|
||||
|
||||
@@ -519,7 +521,7 @@ test("studioJson via usage: balance and membership map to quota windows", async
|
||||
assert.equal(out.user, "18800000000")
|
||||
assert.deepEqual(out.windows[0], { name: "通用积分", balance: 7900, aside: false, runsOutAt: "2026-11-03T06:11:12", runsOut: 7900 })
|
||||
// 星火到期从入账流水推(balance 接口不给星火到期时间)。
|
||||
assert.deepEqual(out.windows[1], { name: "星火积分", balance: 35000, aside: false, runsOutAt: "2026-11-22T13:34:30.000Z", runsOut: 35000 })
|
||||
assert.deepEqual(out.windows[1], { name: "星火积分", balance: 35000, aside: false, models: ["spark-x2.5", "spark-x2.6"], runsOutAt: "2026-11-22T13:34:30.000Z", runsOut: 35000 })
|
||||
})
|
||||
|
||||
test("usage spark window omits expiry when the ledger query fails", async () => {
|
||||
@@ -541,7 +543,7 @@ test("usage spark window omits expiry when the ledger query fails", async () =>
|
||||
})
|
||||
const out = await plugin.auth.usage(async () => ({ type: "api", key: "k", metadata: { session } }))
|
||||
// 到期推算失败不塌方:星火窗口退回无 runsOut 形态。
|
||||
assert.deepEqual(out.windows[1], { name: "星火积分", balance: 35000, aside: false })
|
||||
assert.deepEqual(out.windows[1], { name: "星火积分", balance: 35000, aside: false, models: ["spark-x2.5", "spark-x2.6"] })
|
||||
})
|
||||
|
||||
const checkinFetch = (balanceSequence, { popups = [], identityAssert, popupFails = false, onComplete, completeFails = false, ledger, ledgerSequence, ledgerFails = false, sparkLedger, sparkPages } = {}) => {
|
||||
@@ -1493,3 +1495,66 @@ test("web login maps a code 80000 from the exchange to sign-in expired", async (
|
||||
assert.match(result.error, /会话已失效/)
|
||||
assert.equal(exchangeCalls, 1)
|
||||
})
|
||||
|
||||
// magpie 怎么读窗口(internal/provider/routing.go allowanceOf / Limit.applies):
|
||||
// aside 的窗口不挡账号;列了 models 的窗口只算这些模型;balance ≤ 0 即用光。
|
||||
const gating = (windows, model) =>
|
||||
windows.filter((w) => !w.aside && (!w.models || w.models.map((m) => m.toLowerCase()).includes(model.toLowerCase())))
|
||||
const exhaustedFor = (windows, model) => gating(windows, model).some((w) => typeof w.balance === "number" && w.balance <= 0)
|
||||
|
||||
const poolsFetch = (totalBalance, sparkTotalBalance) => async (input) => {
|
||||
const url = String(input)
|
||||
if (url.includes("points/balance")) return jsonRes({ flag: true, code: 0, data: { totalBalance, activityBalance: 0, sparkTotalBalance } })
|
||||
if (url.includes("membership/me")) return jsonRes({ flag: true, code: 0, data: { uid: 1, planName: "体验版" } })
|
||||
if (url.includes("points/details")) return jsonRes({ flag: true, code: 0, data: { items: [] } })
|
||||
throw new Error(`unexpected ${url}`)
|
||||
}
|
||||
|
||||
test("Spark points at 0 leave the general-points models routable (plugins#990)", async () => {
|
||||
// 报告者的账号:通用积分 1500,星火积分 0。
|
||||
const plugin = createPlugin({ fetchImpl: poolsFetch(1500, 0) })
|
||||
const out = await plugin.auth.usage(async () => ({ type: "api", key: "k", metadata: { session: { token: "T", accountId: "A" } } }), { models: bootstrapRows() })
|
||||
const spark = out.windows.find((w) => w.name === "星火积分")
|
||||
assert.equal(spark.balance, 0)
|
||||
assert.deepEqual(spark.models, ["spark-x2.5", "spark-x2.6"])
|
||||
for (const model of ["xopdsv4flash0731in", "xopdeepseekv4pro0813", "xopglm52", "astronclaw-auto"]) {
|
||||
assert.equal(exhaustedFor(out.windows, model), false, `${model} 扣通用积分,不该被星火积分挡住`)
|
||||
}
|
||||
// 星火模型仍按星火积分判:0 就是用光。限免的 Lite 不扣积分,不挡。
|
||||
assert.equal(exhaustedFor(out.windows, "spark-x2.6"), true)
|
||||
assert.equal(exhaustedFor(out.windows, "spark-x2.5"), true)
|
||||
assert.equal(exhaustedFor(out.windows, "spark-x2.6-4b"), false)
|
||||
})
|
||||
|
||||
test("general points at 0 still stop the account", async () => {
|
||||
const plugin = createPlugin({ fetchImpl: poolsFetch(0, 35000) })
|
||||
const out = await plugin.auth.usage(async () => ({ type: "api", key: "k", metadata: { session: { token: "T", accountId: "A" } } }), { models: bootstrapRows() })
|
||||
assert.equal(exhaustedFor(out.windows, "xopdsv4flash0731in"), true)
|
||||
assert.equal(out.windows.find((w) => w.name === "通用积分").models, undefined)
|
||||
})
|
||||
|
||||
test("the Spark window follows the account's live catalog", () => {
|
||||
// 目录新增星火模型就圈进去;目录说限免的不圈;目录把 Lite 的限免撤了就圈。
|
||||
assert.deepEqual(
|
||||
sparkModelIds({
|
||||
"spark-x3": { id: "spark-x3" },
|
||||
"spark-x2.6-4b": { id: "spark-x2.6-4b" },
|
||||
"spark-x2.6": { id: "spark-x2.6", free: true },
|
||||
xopglm52: { id: "xopglm52" },
|
||||
}),
|
||||
["spark-x2.5", "spark-x2.6-4b", "spark-x3"],
|
||||
)
|
||||
// 没有目录(usage 没拿到 provider)时退回启动表。
|
||||
const fromBootstrap = BOOTSTRAP.filter((m) => /^spark-/.test(m.id) && !m.free).map((m) => m.id).sort()
|
||||
assert.deepEqual(sparkModelIds(undefined), fromBootstrap)
|
||||
})
|
||||
|
||||
test("a Spark window with no model to count is shown only", async () => {
|
||||
const all = Object.fromEntries(BOOTSTRAP.filter((m) => /^spark-/.test(m.id)).map((m) => [m.id, { id: m.id, free: true }]))
|
||||
const plugin = createPlugin({ fetchImpl: poolsFetch(1500, 0) })
|
||||
const out = await plugin.auth.usage(async () => ({ type: "api", key: "k", metadata: { session: { token: "T", accountId: "A" } } }), { models: all })
|
||||
const spark = out.windows.find((w) => w.name === "星火积分")
|
||||
assert.equal(spark.aside, true)
|
||||
assert.equal(spark.models, undefined)
|
||||
assert.equal(exhaustedFor(out.windows, "xopdsv4flash0731in"), false)
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-astudio-auth",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"description": "AStudio (iFLYTEK Astron Studio) sign-in as an OpenCode/magpie provider: browser sign-in with one account-pool slot per account, or the desktop sign-in, over the Responses model gateway with live model catalog",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
Reference in New Issue
Block a user