@magpie-community/opencode-zcode-auth 0.1.28 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +11 -5
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1001,6 +1001,10 @@ async function signedIn(site, token, jwt, device, onTeam = false) {
1001
1001
  // TEAM marks a team seat's account name beside the account's own.
1002
1002
  const TEAM = "team"
1003
1003
  const who = (u) => first(String(u?.email ?? "").replace(/@phone\.local$/, ""), u?.name, u?.user_id, "ZCode")
1004
+ // uidOf is the account's user id, kept beside its name: magpie tells two
1005
+ // accounts of one name apart by it, a name being no one's own (wakkana on
1006
+ // Discord, WorkBuddy's)
1007
+ const uidOf = (u) => (u?.user_id === undefined || u?.user_id === null ? "" : String(u.user_id).trim())
1004
1008
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
1005
1009
 
1006
1010
  // authorize opens ZCode's sign-in flow on site; its callback polls it.
@@ -1059,6 +1063,7 @@ async function authorize(site, log, onTeam = false) {
1059
1063
  // the key doesn't run out; ZCode's token, when it is all there is, does
1060
1064
  expires: s.key || isTeam(s) ? 0 : jwtExpiry(s.jwt),
1061
1065
  accountId: onTeam ? `${who(got.user)} (${TEAM})` : who(got.user),
1066
+ ...(uidOf(got.user) ? { uid: uidOf(got.user) } : {}),
1062
1067
  }
1063
1068
  }
1064
1069
  },
@@ -1220,7 +1225,7 @@ function ownSignIn() {
1220
1225
  } catch {}
1221
1226
  }
1222
1227
  }
1223
- return { ...s, user: who(info) }
1228
+ return { ...s, user: who(info), uid: uidOf(info) }
1224
1229
  }
1225
1230
 
1226
1231
  // asZCode is the sign-in "as ZCode": what it reads is ZCode's own.
@@ -1232,9 +1237,9 @@ function asZCode() {
1232
1237
  async callback() {
1233
1238
  const own = ownSignIn()
1234
1239
  if (!own) return { type: "failed", error: "ZCode isn't signed in on this computer; sign in to ZCode, or sign in to Z.ai or BigModel here" }
1235
- const { user, ...s } = own
1240
+ const { user, uid, ...s } = own
1236
1241
  const state = { source: "zcode", device: anyDevice, ...s }
1237
- return { type: "success", refresh: JSON.stringify(state), access: s.key || s.jwt || "", expires: 0, accountId: user }
1242
+ return { type: "success", refresh: JSON.stringify(state), access: s.key || s.jwt || "", expires: 0, accountId: user, ...(uid ? { uid } : {}) }
1238
1243
  },
1239
1244
  }
1240
1245
  }
@@ -1253,8 +1258,9 @@ function stateOf(auth) {
1253
1258
  // send this account's requests as that one, and an expired session
1254
1259
  // says sign in again (EXPIRED) rather than borrowing another's.
1255
1260
  const own = ownSignIn()
1256
- if (own && own.user === String(auth.accountId ?? "")) {
1257
- const { user, ...now } = own
1261
+ // (by user id where both have one: another account may share the name)
1262
+ if (own && own.user === String(auth.accountId ?? "") && (!own.uid || !auth.uid || own.uid === String(auth.uid))) {
1263
+ const { user, uid: _uid, ...now } = own
1258
1264
  s = { source: "zcode", device: s.device, plan: s.plan, ...now }
1259
1265
  }
1260
1266
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-zcode-auth",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",