@magpie-community/opencode-qoder-auth 0.2.10 → 0.2.12
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 +15 -6
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -708,8 +708,13 @@ function failure(status, text) {
|
|
|
708
708
|
} catch {}
|
|
709
709
|
msg ||= STATUS_CODES[status] ?? `HTTP ${status}`
|
|
710
710
|
// a refused chat is the built-in's 401, which never marked the account
|
|
711
|
-
// lapsed: only a refused refresh did (errorResponse says kept)
|
|
712
|
-
|
|
711
|
+
// lapsed: only a refused refresh did (errorResponse says kept). Qoder's
|
|
712
|
+
// own words go with it: a 401 right after signing in isn't a lapsed
|
|
713
|
+
// sign-in, and its reason is what says what is (Yayoi_no_yume on X).
|
|
714
|
+
if (status === 401 || status === 403) {
|
|
715
|
+
const said = msg && msg !== STATUS_CODES[status] ? ` (Qoder said ${status}: ${msg.slice(0, 300)})` : ""
|
|
716
|
+
return { status: 401, message: "the sign-in lapsed — sign in again" + said }
|
|
717
|
+
}
|
|
713
718
|
if (status === 429 || msg.toLowerCase().includes("quota")) return { status: 429, message: "usage limit reached: " + msg }
|
|
714
719
|
return { status, message: msg }
|
|
715
720
|
}
|
|
@@ -1314,6 +1319,9 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
1314
1319
|
}
|
|
1315
1320
|
// each account's listing, the model configs a request carries
|
|
1316
1321
|
const listings = new Map()
|
|
1322
|
+
// A public and a VPC account can name the same uid but have different
|
|
1323
|
+
// catalogs. Keep each deployment's listing apart.
|
|
1324
|
+
const listingKey = (cred) => `${cred.vpc ?? ""}\0${cred.uid}`
|
|
1317
1325
|
// the accounts fresh renewed: the built-in took the lapse mark off on a
|
|
1318
1326
|
// renewed job token (qoderPersist), whatever the request then met
|
|
1319
1327
|
const renewals = new WeakSet()
|
|
@@ -1322,7 +1330,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
1322
1330
|
// says "renewed" for it
|
|
1323
1331
|
const unsaid = new Set()
|
|
1324
1332
|
const renewed = (cred) => {
|
|
1325
|
-
const was = unsaid.delete(cred
|
|
1333
|
+
const was = unsaid.delete(listingKey(cred))
|
|
1326
1334
|
return renewals.has(cred) || was
|
|
1327
1335
|
}
|
|
1328
1336
|
|
|
@@ -1343,10 +1351,11 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
1343
1351
|
})
|
|
1344
1352
|
|
|
1345
1353
|
const models = async (cred, again = false) => {
|
|
1346
|
-
|
|
1354
|
+
const key = listingKey(cred)
|
|
1355
|
+
let l = listings.get(key)
|
|
1347
1356
|
if (!l || again) {
|
|
1348
1357
|
l = modelInfos(await fetchListing(siteOf(site, cred), cred))
|
|
1349
|
-
listings.set(
|
|
1358
|
+
listings.set(key, l)
|
|
1350
1359
|
}
|
|
1351
1360
|
return l
|
|
1352
1361
|
}
|
|
@@ -1559,7 +1568,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
1559
1568
|
if (e?.expired) throw Object.assign(new Error(e.message), { signIn: "expired" })
|
|
1560
1569
|
return provider.models
|
|
1561
1570
|
}
|
|
1562
|
-
if (renewals.has(cred)) unsaid.add(cred
|
|
1571
|
+
if (renewals.has(cred)) unsaid.add(listingKey(cred))
|
|
1563
1572
|
try {
|
|
1564
1573
|
const ms = await models(cred, true)
|
|
1565
1574
|
if (!ms.length) return provider.models
|
package/package.json
CHANGED