Parity with magpie's built-ins: a failed sign-in says why, CLI-backed Command Code and Devin accounts follow the CLI's key, Factory's refused renewal is a 401 in the caller's API shape

- every {type:"failed"} carries an error reason magpie shows
- commandcode/devin: accounts taken from the CLI are marked metadata.cli and re-read its credentials on each request, usage and models
- factory: a refused refresh answers 401 authentication_error (Anthropic shape on /llm/a/, OpenAI's elsewhere) instead of throwing; the whoami back-off is per account; 403 hints name the account to sign in again
- versions: factory/devin/commandcode/cursor/kiro/mimo/zed/zcode 0.1.2, workbuddy 0.1.3
This commit is contained in:
yetone
2026-10-01 00:55:50 +08:00
parent bd9c0780cc
commit c8f4d448df
22 changed files with 228 additions and 75 deletions
+4 -4
View File
@@ -243,7 +243,7 @@ async function browserSignIn(site) {
const deadline = Date.now() + SIGN_IN_MS
const q = encodeURIComponent(state.state)
const token = await poll(site, `/v2/plugin/auth/token?state=${q}`, {}, [11217], deadline)
if (!token.accessToken) return { type: "failed" }
if (!token.accessToken) return { type: "failed", error: `${site.name} sent back no token` }
let a = merge({}, token)
const who = await poll(site, `/v2/plugin/login/account?state=${q}`, {
Authorization: "Bearer " + a.access,
@@ -253,8 +253,8 @@ async function browserSignIn(site) {
}, [12151], deadline)
a.uid = who.uid ?? ""
return success(site, a, who.nickname || who.phoneNumber || who.uid)
} catch {
return { type: "failed" }
} catch (e) {
return { type: "failed", error: e.message }
}
},
}
@@ -319,7 +319,7 @@ function desktopSignIn(site) {
method: "auto",
async callback() {
const d = readDesktop(site)
if (!d) return { type: "failed" }
if (!d) return { type: "failed", error: `${site.name} desktop isn't signed in` }
return { type: "success", refresh: "", access: "", expires: 0, source: "desktop", accountId: d.name || site.name, uid: d.uid }
},
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-workbuddy-auth",
"version": "0.1.2",
"version": "0.1.3",
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
"type": "module",
"main": "./index.mjs",
+7
View File
@@ -124,3 +124,10 @@ test("the desktop's sign-in is renewed in memory only", async () => {
await usageOf(WorkBuddyAuthPlugin, auth, client)
expect(calls.filter((c) => c.url.pathname.endsWith("/refresh")).length).toBe(1)
})
test("a desktop sign-in with the app signed out says why it failed", async () => {
const p = await WorkBuddyAIAuthPlugin({ client: {} })
const m = p.auth.methods.find((x) => x.label.endsWith("desktop's sign-in"))
const r = await (await m.authorize()).callback()
expect(r).toEqual({ type: "failed", error: "WorkBuddy AI desktop isn't signed in" })
})