astudio 0.1.4: check-in sends the desktop's clientType and studioVersion, and reads a pending daily reward popup as done (jinyue806, #721)

The account requests to agent.xfyun.cn/xingchen-studio now carry the
desktop client's identity headers, clientType and studioVersion. Without
clientType the server refuses client-popups/pending with 11001001. The
values are AStudio's own: the 3.5.5 desktop bundle
(AStudio-3.5.5-arm64.dmg, sha512 matching the vendor's
client/releases/latest, apps/desktop/dist-electron/main.js and
apps/server/dist/index.mjs, packages/shared/src/astronStudioHttp.ts)
sends "21" on win32, "22" on darwin, and studioVersion = its package
version (3.5.5).

auth.checkin, after a balance read that shows no rise, reads
client-popups/pending (GET only, as the desktop's
listPendingAstronClientPopups does; it never calls client-popups/complete,
so the desktop's own notice is left alone). A DAILY_REWARD_DIALOG there is
the server's record of a grant not yet shown: the check-in reports done,
with payload.points as credit only when it is a positive number. No
popup still reports inactive (#658). A refused popup read reports failed.
astudio 0.1.3 -> 0.1.4 (jinyue806).

Run at 6d2919dce on mote (mote-run): packages/astudio node --test, 38/38
pass; bun scripts/check.mjs astudio: registry.json and astudio ok.
Broken by hand: without the clientType header, the identity test fails;
with the popup branch disabled, the two popup done tests fail (3 red).
The new tests use fake fetches only.

Not tried: a real AStudio account (the author's live run is in the PR).
Linux sends clientType 21 where the desktop sends none (it ships for
mac and Windows only). studioVersion is fixed at 3.5.5; the desktop
sends its own version. Whether a DAILY_REWARD_DIALOG left pending
past its day (desktop closed before showing it) would read as done the
next day was not checked; the desktop completes it as soon as it shows.
This commit is contained in:
Pursuit806
2026-11-04 17:42:23 +08:00
committed by GitHub
parent d4eeba4493
commit f9b7a1ab24
4 changed files with 93 additions and 11 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ AStudio 在 registry 里有两个入口,都保留([#614](https://github.com/
| 登录 | 读取本机 AStudio 桌面端的登录态,或粘贴 `modelBearerToken`;不需要再输手机号或密码 | 本机打开一个登录页:手机验证码、账号密码或微信扫码(含极验验证),不依赖桌面端 |
| 适合 | 装了 AStudio 桌面端的用户(数据目录按 `ASTUDIO_HOME`、Windows 注册表、`~/.acode` 查找;其他情况粘贴凭据) | 任何平台,没装桌面端也行 |
| 模型端点 | `…/model-gateway/v1/responses`(OpenAI Responses,与桌面端一致) | `…/model-gateway/v1/chat/completions` |
| 每日积分 | 做一次会话活跃,按前后余额差记录,不调用领取接口 | 调用 `client-popups` 领取每日奖励和新人礼包弹窗 |
| 每日积分 | 做一次会话活跃,按前后余额差与 `client-popups/pending` 待通知弹窗记录,不调用领取接口 | 调用 `client-popups` 领取每日奖励和新人礼包弹窗 |
两者用同一个 AStudio 账号时,读的是同一个 `points/balance`,模型调用也扣同一份积分:**每日登录积分是一个池子,装两个不会多一份。** 同一账号两边都登录只会重复显示同一笔余额。
@@ -52,7 +52,7 @@ same daily points balance.
## 每日签到(每日登录积分)
AStudio 有「每日登录积分」:服务端在当天账号会话首次活跃时发放(体验版 100 分/天,标准版 200,高级/畅享 400;活动期 31 天有效),客户端弹窗只做通知、没有领取接口。插件为此提供 magpie 的 `auth.checkin`:每天替账号做一次会话活跃(只读请求)并观测前后余额差——涨了记为已领取;没涨**不谎称已签**,如实报「未观测到新发放」(发放可能挂靠桌面端登录)。签到需要账号带网页会话(桌面端登录态方式默认有)。
AStudio 有「每日登录积分」:服务端在当天账号会话首次活跃时发放(体验版 100 分/天,标准版 200,高级/畅享 400;活动期 31 天有效),客户端弹窗只做通知、没有领取接口。插件为此提供 magpie 的 `auth.checkin`:每天替账号做一次会话活跃(只读请求,带桌面端 `clientType` / `studioVersion` 身份头;缺 `clientType` 会被服务端以 `11001001` 拒绝),再观测前后余额差与 `client-popups/pending` 的 `DAILY_REWARD_DIALOG` 待通知弹窗——涨了记为已领取,见到弹窗记为今日已发放,两者都没有则如实报「未观测到新发放」,**不谎称已签**。发放由服务端按账号会话判定,插件不能代替桌面端登录,也不保证某天一定有积分到账。签到需要账号带网页会话(桌面端登录态方式默认有)。
## 用量
@@ -62,7 +62,7 @@ AStudio 有「每日登录积分」:服务端在当天账号会话首次活跃
- 模型调用:`POST https://astronstudio-api-volces-prod.xf-yun.com/model-gateway/v1/responses`(OpenAI Responses,`Authorization: Bearer`)——与 AStudio 桌面端写进 acode 内核的 `base_url` / `wire_api` 完全一致。
- 模型目录:`GET https://astronstudio-api-volces-prod.xf-yun.com/api/v1/model-manager/models`。
- 账号面:`https://agent.xfyun.cn/xingchen-studio/`(`points/balance`、`membership/me`、`membership/plan-config`,Cookie 会话鉴权)。
- 账号面:`https://agent.xfyun.cn/xingchen-studio/`(`points/balance`、`membership/me`、`membership/plan-config`、`points/summary`、`client-popups/pending`,Cookie 会话鉴权 + `clientType` / `studioVersion` 身份头)。
## 风险提示
+25 -5
View File
@@ -31,6 +31,10 @@ const ID = "astudio"
const MODEL_GATEWAY_BASE = "https://astronstudio-api-volces-prod.xf-yun.com/model-gateway/v1"
const MODEL_MANAGER_URL = "https://astronstudio-api-volces-prod.xf-yun.com/api/v1/model-manager/models"
const STUDIO_API_BASE = "https://agent.xfyun.cn/xingchen-studio/"
// agent.xfyun.cn 的账号面接口要求桌面端身份:只带 Cookie 会被拒(code 11001001)。
// clientType 是必需头且校验合法枚举(21/22 通过、99/缺失被拒);studioVersion 桌面端也带,实测值不参与校验。
const CLIENT_TYPE = process.platform === "darwin" ? "22" : "21"
const STUDIO_VERSION = "3.5.5"
// 读取桌面端登录态失败时展示的跳转页:AStudio 官网(含桌面端下载)。
const OFFICIAL_SITE = "https://agent.xfyun.cn/"
@@ -258,6 +262,8 @@ async function studioJson(path, { session, fetchImpl, method = "GET", body, oper
method,
headers: {
accept: "application/json",
clientType: CLIENT_TYPE,
studioVersion: STUDIO_VERSION,
...(body !== undefined ? { "content-type": "application/json" } : {}),
cookie: buildCookieHeader(session),
},
@@ -527,8 +533,8 @@ function createPlugin({ fetchImpl = globalThis.fetch, env = process.env, homedir
}
},
// 「每日登录积分」:服务端在当天账号会话首次活跃时发放,客户端没有领取
// 接口(弹窗只做通知)。这里以一组账号面请求代表当天的会话活跃,并用
// 发放前后的余额差观测结果:涨了是 claimed,没涨是 done。
// 接口(DAILY_REWARD_DIALOG 弹窗只做通知)。这里以一组账号面请求代表
// 当天的会话活跃,再用余额差与待通知弹窗观测结果,不谎称已领取。
async checkin(getAuth) {
const auth = await getAuth()
if (auth?.type !== "api" || !auth.key) return {}
@@ -569,9 +575,22 @@ function createPlugin({ fetchImpl = globalThis.fetch, env = process.env, homedir
}
const delta = after.totalBalance - before.totalBalance
if (delta > 0) return { outcome: "claimed", credit: delta, message: `每日登录积分 +${delta}` }
// 余额没涨 ≠ 已发放:无领取接口,发放可能挂靠桌面端登录,本次未观测到。
// 不能报 done(宿主渲染成「今日已签到」,是没发生的断言);inactive 是
// 静默结算态,message 仍会把实情带给用户。
// 服务端把已发放但还没通知的每日奖励挂成待通知弹窗;见到它才算「今日已签到」。
let popups
try {
popups = await studioJson("client-popups/pending", { session, fetchImpl, operation: "每日奖励弹窗" })
} catch (error) {
if (error?.signIn === "expired") throw error
return { outcome: "failed", message: error?.message ?? "每日奖励弹窗读取失败" }
}
const daily = Array.isArray(popups) && popups.find((item) => item?.componentType === "DAILY_REWARD_DIALOG")
if (daily) {
const rawPoints = Number(daily.payload?.points)
const credit = Number.isFinite(rawPoints) && rawPoints >= 0 ? rawPoints : 0
return { outcome: "done", ...(credit > 0 ? { credit } : {}), message: "每日登录积分已发放(服务端待通知弹窗)" }
}
// 余额没涨、也没有待通知弹窗:发放可能挂靠桌面端登录,本次未观测到。
// done 会渲染成「今日已签到」,是没发生的断言,故记 inactive。
return { outcome: "inactive", message: "未观测到新发放:余额无变化(发放可能挂靠桌面端登录)" }
},
},
@@ -634,6 +653,7 @@ export const _internal = {
MODEL_GATEWAY_BASE,
MODEL_MANAGER_URL,
STUDIO_API_BASE,
STUDIO_VERSION,
OFFICIAL_SITE,
DESKTOP_WAIT_MS,
BOOTSTRAP,
+64 -2
View File
@@ -15,6 +15,7 @@ const {
MODEL_GATEWAY_BASE,
MODEL_MANAGER_URL,
STUDIO_API_BASE,
STUDIO_VERSION,
OFFICIAL_SITE,
DESKTOP_WAIT_MS,
ID,
@@ -490,10 +491,11 @@ test("studioJson via usage: balance and membership map to quota windows", async
assert.deepEqual(out.windows[1], { name: "星火积分", balance: 35000, aside: false })
})
const checkinFetch = (balanceSequence) => {
const checkinFetch = (balanceSequence, { popups = [], identityAssert, popupFails = false } = {}) => {
let balanceCalls = 0
return async (input) => {
return async (input, init) => {
const url = String(input)
if (identityAssert) identityAssert(init.headers)
if (url.includes("membership/plan-config")) {
return jsonRes({ flag: true, code: 0, data: { dailyLoginEnabled: true, dailyLoginValidDays: 31, plans: [{ planCode: "TRIAL", dailyLoginPoints: 100 }] } })
}
@@ -502,6 +504,10 @@ const checkinFetch = (balanceSequence) => {
const total = balanceSequence[Math.min(balanceCalls - 1, balanceSequence.length - 1)]
return jsonRes({ flag: true, code: 0, data: { totalBalance: total, activityBalance: total } })
}
if (url.includes("client-popups/pending")) {
if (popupFails) return jsonRes({ flag: false, code: 11001001, desc: "客户端平台、版本或构建号无效", data: null })
return jsonRes({ flag: true, code: 0, data: popups })
}
if (url.includes("membership/me") || url.includes("points/summary")) {
return jsonRes({ flag: true, code: 0, data: {} })
}
@@ -509,6 +515,11 @@ const checkinFetch = (balanceSequence) => {
}
}
const dailyRewardPopup = [{
popupId: 1, popupCode: "DAILY_LOGIN", popupType: "BANNER", componentType: "DAILY_REWARD_DIALOG",
priority: 100, instanceKey: "2026-11-04", payload: { points: "100" },
}]
const checkinAuth = { type: "api", key: "k", metadata: { session: { token: "T", ssoSessionId: "S", accountId: "A" } } }
test("check-in observes the balance delta around the session touch", async () => {
@@ -536,6 +547,57 @@ test("check-in reports ineligible without a session and inactive without the cam
assert.equal(out2.outcome, "inactive")
})
test("check-in sends the desktop client identity on account requests", async () => {
const seen = []
const plugin = createPlugin({
fetchImpl: checkinFetch([7900, 7900], {
identityAssert: (headers) => seen.push(headers),
}),
sleepImpl: async () => {},
})
await plugin.auth.checkin(async () => checkinAuth)
assert.equal(seen.length, 6)
for (const headers of seen) {
assert.equal(headers.clientType, process.platform === "darwin" ? "22" : "21")
assert.equal(headers.studioVersion, STUDIO_VERSION)
}
})
test("check-in reports done when the server has a pending daily reward popup", async () => {
const plugin = createPlugin({ fetchImpl: checkinFetch([7900, 7900], { popups: dailyRewardPopup }), sleepImpl: async () => {} })
const out = await plugin.auth.checkin(async () => checkinAuth)
assert.deepEqual(out, { outcome: "done", credit: 100, message: "每日登录积分已发放(服务端待通知弹窗)" })
})
test("check-in omits credit when the daily reward popup has no usable points", async () => {
for (const payload of [{}, { points: "0" }, { points: "n/a" }]) {
const plugin = createPlugin({
fetchImpl: checkinFetch([7900, 7900], { popups: [{ ...dailyRewardPopup[0], payload }] }),
sleepImpl: async () => {},
})
const out = await plugin.auth.checkin(async () => checkinAuth)
assert.deepEqual(out, { outcome: "done", message: "每日登录积分已发放(服务端待通知弹窗)" })
}
})
test("check-in ignores other popup types", async () => {
const plugin = createPlugin({
fetchImpl: checkinFetch([7900, 7900], {
popups: [{ ...dailyRewardPopup[0], componentType: "NEW_USER_DIALOG" }],
}),
sleepImpl: async () => {},
})
const out = await plugin.auth.checkin(async () => checkinAuth)
assert.equal(out.outcome, "inactive")
})
test("check-in reports failed when the popup query is rejected", async () => {
const plugin = createPlugin({ fetchImpl: checkinFetch([7900, 7900], { popupFails: true }), sleepImpl: async () => {} })
const out = await plugin.auth.checkin(async () => checkinAuth)
assert.equal(out.outcome, "failed")
assert.match(out.message, /11001001|平台|版本/)
})
test("check-in propagates dead sessions as signIn expired", async () => {
const dead = createPlugin({
fetchImpl: async () => jsonRes({ flag: false, code: 80000, desc: "登录异常,请重新登录" }, 200),
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-astudio-auth",
"version": "0.1.3",
"version": "0.1.4",
"description": "AStudio (iFLYTEK Astron Studio) desktop sign-in as an OpenCode/magpie provider: Responses model gateway with live model catalog",
"type": "module",
"main": "./opencode.mjs",