@magpie-community/opencode-qoder-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 +22 -5
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -232,9 +232,9 @@ async function refreshJob(refresh, user) {
|
|
|
232
232
|
const r = await openapi("/api/v1/jobToken/refresh", { method: "POST", body: { refresh_token: refresh } })
|
|
233
233
|
if (r.status === 401 || r.status === 403)
|
|
234
234
|
throw new SignInGone(`${user}'s Qoder sign-in has expired — sign in again (qoder job token refresh: status ${r.status})`, true)
|
|
235
|
-
if (r.status !== 200) throw new Error(`
|
|
235
|
+
if (r.status !== 200) throw new Error(`qoder job token refresh: status ${r.status}`)
|
|
236
236
|
if (!String(r.json?.token ?? "").trim() || !String(r.json?.refresh_token ?? "").trim())
|
|
237
|
-
throw new Error("
|
|
237
|
+
throw new Error("qoder job token refresh: incomplete token pair")
|
|
238
238
|
return r.json
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -894,6 +894,14 @@ export async function QoderAuthPlugin({ client }) {
|
|
|
894
894
|
// the accounts fresh renewed: the built-in took the lapse mark off on a
|
|
895
895
|
// renewed job token (qoderPersist), whatever the request then met
|
|
896
896
|
const renewals = new WeakSet()
|
|
897
|
+
// the accounts the models hook renewed: that hook has no way to say so
|
|
898
|
+
// and still answer the list, so the account's next usage read or answer
|
|
899
|
+
// says "renewed" for it
|
|
900
|
+
const unsaid = new Set()
|
|
901
|
+
const renewed = (cred) => {
|
|
902
|
+
const was = unsaid.delete(cred.uid)
|
|
903
|
+
return renewals.has(cred) || was
|
|
904
|
+
}
|
|
897
905
|
|
|
898
906
|
// fresh is the account with a live job token, refreshed and saved near
|
|
899
907
|
// its end.
|
|
@@ -937,7 +945,7 @@ export async function QoderAuthPlugin({ client }) {
|
|
|
937
945
|
let signIn = "kept"
|
|
938
946
|
try {
|
|
939
947
|
const cred = await fresh(getAuth)
|
|
940
|
-
if (
|
|
948
|
+
if (renewed(cred)) signIn = "renewed"
|
|
941
949
|
let env
|
|
942
950
|
try {
|
|
943
951
|
env = await fetchUsage(cred.deviceToken)
|
|
@@ -1013,7 +1021,7 @@ export async function QoderAuthPlugin({ client }) {
|
|
|
1013
1021
|
} catch (e) {
|
|
1014
1022
|
return signedInError(e)
|
|
1015
1023
|
}
|
|
1016
|
-
return signed(await ask(chat, cred, init),
|
|
1024
|
+
return signed(await ask(chat, cred, init), renewed(cred))
|
|
1017
1025
|
},
|
|
1018
1026
|
}
|
|
1019
1027
|
},
|
|
@@ -1036,8 +1044,17 @@ export async function QoderAuthPlugin({ client }) {
|
|
|
1036
1044
|
id: ID,
|
|
1037
1045
|
async models(provider, { auth } = {}) {
|
|
1038
1046
|
if (auth?.type !== "oauth") return provider.models
|
|
1047
|
+
let cred
|
|
1048
|
+
try {
|
|
1049
|
+
cred = await fresh(async () => auth)
|
|
1050
|
+
} catch (e) {
|
|
1051
|
+
// the built-in listed through QoderCredentialOf: a refused job
|
|
1052
|
+
// refresh marked the account there; anything else marked nothing
|
|
1053
|
+
if (e?.expired) throw Object.assign(new Error(e.message), { signIn: "expired" })
|
|
1054
|
+
return provider.models
|
|
1055
|
+
}
|
|
1056
|
+
if (renewals.has(cred)) unsaid.add(cred.uid)
|
|
1039
1057
|
try {
|
|
1040
|
-
const cred = await fresh(async () => auth)
|
|
1041
1058
|
const ms = await models(cred, true)
|
|
1042
1059
|
if (!ms.length) return provider.models
|
|
1043
1060
|
return Object.fromEntries(
|