@magpie-community/opencode-workbuddy-auth 0.1.16 → 0.1.17
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 +20 -7
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1350,6 +1350,18 @@ const REFUSED_HINT =
|
|
|
1350
1350
|
"WorkBuddy refuses chats from Codex and Claude Code (their system prompt); use it from Hermes, OpenCode or Pi, or add another provider to this group"
|
|
1351
1351
|
const REFUSED = /unapproved channel|illegal api invocation/i
|
|
1352
1352
|
|
|
1353
|
+
// RESTRICTED_HINT is what the user can do about WorkBuddy's 403 code 11140
|
|
1354
|
+
// "request illegal", whose displayMsg says "Your account has been restricted
|
|
1355
|
+
// due to unusual activity" (magpie #1849): the account is out until WorkBuddy
|
|
1356
|
+
// lifts the restriction, which an appeal asks for. It ends the error's
|
|
1357
|
+
// message as magpie's built-in puts it (provider.WBRestrictedHint), word for
|
|
1358
|
+
// word, so magpie rests the account for hours rather than minutes.
|
|
1359
|
+
const RESTRICTED_HINT =
|
|
1360
|
+
"WorkBuddy restricted this account for unusual activity; it stays out until WorkBuddy lifts that, which an appeal (Submit feedback in WorkBuddy) asks for"
|
|
1361
|
+
const RESTRICTED_CODE = 11140
|
|
1362
|
+
// The code is matched whole, as with 14018: 111400 is another error.
|
|
1363
|
+
const RESTRICTED_TEXT = /account has been restricted due to unusual activity|账号存在异常行为|帳號存在異常行為|["']code["']\s*:\s*["']?11140(?![\d.])/i
|
|
1364
|
+
|
|
1353
1365
|
// EXHAUSTED_HINT explains WorkBuddy's requirement of an active package
|
|
1354
1366
|
// even for 0-rate / free models. When an account has no packages or 0 credits,
|
|
1355
1367
|
// WorkBuddy returns code 14018 ("Credits exhausted...").
|
|
@@ -1367,7 +1379,7 @@ function kept(res) {
|
|
|
1367
1379
|
return new Response(res.body, { status: res.status, statusText: res.statusText, headers })
|
|
1368
1380
|
}
|
|
1369
1381
|
|
|
1370
|
-
// explained is res with REFUSED_HINT or EXHAUSTED_HINT added to that refusal's message.
|
|
1382
|
+
// explained is res with REFUSED_HINT, RESTRICTED_HINT or EXHAUSTED_HINT added to that refusal's message.
|
|
1371
1383
|
// Each refusal says the sign-in is kept: the built-in passed WorkBuddy's
|
|
1372
1384
|
// 401 on and never marked a WorkBuddy account lapsed.
|
|
1373
1385
|
async function explained(res) {
|
|
@@ -1386,8 +1398,9 @@ async function explained(res) {
|
|
|
1386
1398
|
const at = v?.error && typeof v.error === "object" ? v.error : v && typeof v === "object" ? v : null
|
|
1387
1399
|
const code = at?.data?.code ?? at?.code ?? v?.code ?? v?.data?.code
|
|
1388
1400
|
const isRefused = REFUSED.test(text)
|
|
1389
|
-
const
|
|
1390
|
-
|
|
1401
|
+
const isRestricted = !isRefused && (Number(code) === RESTRICTED_CODE || RESTRICTED_TEXT.test(text))
|
|
1402
|
+
const isExhausted = !isRestricted && (code === 14018 || Number(code) === 14018 || EXHAUSTED_TEXT.test(text))
|
|
1403
|
+
if (!isRefused && !isRestricted && !isExhausted) return again(text)
|
|
1391
1404
|
|
|
1392
1405
|
let msg = text.trim()
|
|
1393
1406
|
if (at && typeof at.message === "string") msg = at.message
|
|
@@ -1396,9 +1409,9 @@ async function explained(res) {
|
|
|
1396
1409
|
else if (typeof v?.msg === "string" && v.msg) msg = v.msg // WorkBuddy's own {"code", "msg"}
|
|
1397
1410
|
else if (typeof v?.data?.msg === "string") msg = v.data.msg
|
|
1398
1411
|
|
|
1399
|
-
const hint = isRefused ? REFUSED_HINT : EXHAUSTED_HINT
|
|
1400
|
-
const type = isRefused ? "permission_error" : "insufficient_quota"
|
|
1401
|
-
const errCode = isRefused ? null : 14018
|
|
1412
|
+
const hint = isRefused ? REFUSED_HINT : isRestricted ? RESTRICTED_HINT : EXHAUSTED_HINT
|
|
1413
|
+
const type = isRefused || isRestricted ? "permission_error" : "insufficient_quota"
|
|
1414
|
+
const errCode = isRefused ? null : isRestricted ? RESTRICTED_CODE : 14018
|
|
1402
1415
|
msg = `${msg} — ${hint}`
|
|
1403
1416
|
const headers = new Headers(res.headers)
|
|
1404
1417
|
headers.set("content-type", "application/json")
|
|
@@ -1412,4 +1425,4 @@ export const WorkBuddyAuthPlugin = makePlugin(SITES.workbuddy)
|
|
|
1412
1425
|
export const WorkBuddyAIAuthPlugin = makePlugin(SITES["workbuddy-ai"])
|
|
1413
1426
|
|
|
1414
1427
|
// for tests
|
|
1415
|
-
export const _internal = { textOnly, runsOutOf, packagesOf, endOf, enterpriseHeaders, enterpriseOf, liveModels, browserSignIn, withSystem, normalizeToolChoice, fitTools, fitted, renamed, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, EXHAUSTED_HINT, freeCredits, creditsOf, fresh, SITES, renewing, renewed, SESSION, attend, turnKey, conversationKey, signatureOf }
|
|
1428
|
+
export const _internal = { textOnly, runsOutOf, packagesOf, endOf, enterpriseHeaders, enterpriseOf, liveModels, browserSignIn, withSystem, normalizeToolChoice, fitTools, fitted, renamed, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, RESTRICTED_HINT, EXHAUSTED_HINT, freeCredits, creditsOf, fresh, SITES, renewing, renewed, SESSION, attend, turnKey, conversationKey, signatureOf }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-workbuddy-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|