@magpie-community/opencode-zcode-auth 0.1.3 → 0.1.4
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.
- package/index.mjs +17 -5
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -120,7 +120,9 @@ const jwtExpired = (jwt) => {
|
|
|
120
120
|
const t = jwtExpiry(jwt)
|
|
121
121
|
return t > 0 && Date.now() > t
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
// EXPIRED is the built-in's words (errZCodeExpired) for a Start Plan
|
|
124
|
+
// sign-in past its end.
|
|
125
|
+
const EXPIRED = "ZCode's sign-in has expired; sign in to ZCode again (or add the account again in magpie)"
|
|
124
126
|
|
|
125
127
|
const num = (v) => {
|
|
126
128
|
const n = typeof v === "string" ? parseFloat(v) : v
|
|
@@ -236,7 +238,7 @@ async function teamKey(s) {
|
|
|
236
238
|
teamKeys.set(id, { key, at: Date.now() })
|
|
237
239
|
return key
|
|
238
240
|
} catch (e) {
|
|
239
|
-
const err = new Error(`ZCode's team plan: ${e.message} — sign in again`)
|
|
241
|
+
const err = new Error(`ZCode's team plan: ${e.message} — sign in to ZCode again`)
|
|
240
242
|
teamKeys.set(id, { err, at: Date.now() })
|
|
241
243
|
throw err
|
|
242
244
|
}
|
|
@@ -1093,21 +1095,31 @@ export async function ZCodeAuthPlugin({ client }) {
|
|
|
1093
1095
|
h.delete("authorization")
|
|
1094
1096
|
h.set("x-api-key", key)
|
|
1095
1097
|
h.set("Authorization", "Bearer " + key)
|
|
1096
|
-
|
|
1098
|
+
const res = await fetch(url, { ...opts, headers: h })
|
|
1099
|
+
// the plan's answer goes on as it came, the account kept: the
|
|
1100
|
+
// built-in never marked a ZCode account lapsed nor cleared one
|
|
1101
|
+
const kept = new Headers(res.headers)
|
|
1102
|
+
kept.delete("content-length")
|
|
1103
|
+
kept.delete("content-encoding")
|
|
1104
|
+
kept.set("X-Magpie-Sign-In", "kept")
|
|
1105
|
+
return new Response(res.body, { status: res.status, statusText: res.statusText, headers: kept })
|
|
1097
1106
|
},
|
|
1098
1107
|
}
|
|
1099
1108
|
},
|
|
1100
|
-
// the plan's allowance, as magpie's built-in showed it
|
|
1109
|
+
// the plan's allowance, as magpie's built-in showed it. Each read
|
|
1110
|
+
// keeps the sign-in (signIn): the built-in's marked no account lapsed,
|
|
1111
|
+
// its expired Start Plan sign-in among them, and cleared none
|
|
1101
1112
|
async usage(getAuth, provider) {
|
|
1102
1113
|
const auth = await getAuth()
|
|
1103
1114
|
const s = stateOf(auth)
|
|
1104
|
-
if (!s) return { error: "not signed in" }
|
|
1115
|
+
if (!s) return { error: "not signed in", signIn: "kept" }
|
|
1105
1116
|
// every card starts from the plan the sign-in saved, as magpie's
|
|
1106
1117
|
// built-in did: a reply without a level, a team detail that
|
|
1107
1118
|
// failed or an error keeps it
|
|
1108
1119
|
const saved = (out) => {
|
|
1109
1120
|
const plan = s.plan || auth?.plan
|
|
1110
1121
|
if (plan && !out.plan) out.plan = plan
|
|
1122
|
+
out.signIn = "kept"
|
|
1111
1123
|
return out
|
|
1112
1124
|
}
|
|
1113
1125
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-zcode-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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",
|