@magpie-community/opencode-factory-auth 0.1.35 → 0.1.36
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 -4
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -403,10 +403,28 @@ async function reconcile(c) {
|
|
|
403
403
|
// "Requested active organization is not accessible by this user".
|
|
404
404
|
const orgRefused = (status, text) => status === 403 && text.toLowerCase().includes("active organization is not accessible")
|
|
405
405
|
|
|
406
|
+
// contentRefused is Factory's usage policy check refusing what the request
|
|
407
|
+
// says, not who sent it: a 403 with code "content_policy_rejected" (droid
|
|
408
|
+
// 0.245.0 tells it apart the same way, and only when Factory sent no
|
|
409
|
+
// x-factory-upstream-error header). Its check reads the whole conversation,
|
|
410
|
+
// so sending the request again, under any org, is refused again.
|
|
411
|
+
function contentRefused(status, text, headers) {
|
|
412
|
+
if (status !== 403 || headers?.get?.("x-factory-upstream-error")) return false
|
|
413
|
+
let v
|
|
414
|
+
try {
|
|
415
|
+
v = JSON.parse(text)
|
|
416
|
+
} catch {
|
|
417
|
+
return false
|
|
418
|
+
}
|
|
419
|
+
const err = v && typeof v === "object" && v.error && typeof v.error === "object" ? v.error : {}
|
|
420
|
+
return v?.code === "content_policy_rejected" || err.code === "content_policy_rejected"
|
|
421
|
+
}
|
|
422
|
+
|
|
406
423
|
// explain is what the user can do about a 403 Factory still answers once
|
|
407
424
|
// the request carries what droid sends.
|
|
408
|
-
function explain(status, text) {
|
|
425
|
+
function explain(status, text, headers) {
|
|
409
426
|
if (status !== 403) return ""
|
|
427
|
+
if (contentRefused(status, text, headers)) return "Factory's usage policy check reads the whole conversation, so this session's requests are refused again until the text that tripped it is gone: start a new session, or remove or reword what the conversation quotes (another agent's system prompt or instructions pasted in a message or a tool's output are the usual cause)"
|
|
410
428
|
if (orgRefused(status, text)) return "the Factory account's organization changed; remove the account in magpie and sign in to it again"
|
|
411
429
|
return "Factory refused the request. magpie adapts fixed client metadata on both OpenAI and Anthropic routes. Factory may still refuse unsupported fields or wrappers; check the upstream error, the organization's model policy, plan and regional provider availability, and compare the same model in Droid"
|
|
412
430
|
}
|
|
@@ -2020,12 +2038,12 @@ export const FactoryAuthPlugin = async ({ client }) => {
|
|
|
2020
2038
|
if (res.status === 413) return answer(await smaller(res))
|
|
2021
2039
|
if (res.status !== 403) return answer(res)
|
|
2022
2040
|
let text = await res.text()
|
|
2023
|
-
if (await mendOrg(res.status, text, onRenew).catch(() => false)) {
|
|
2041
|
+
if (!contentRefused(res.status, text, res.headers) && (await mendOrg(res.status, text, onRenew).catch(() => false))) {
|
|
2024
2042
|
res = await send(input, init, body, onRenew)
|
|
2025
2043
|
if (res.status !== 403) return answer(res)
|
|
2026
2044
|
text = await res.text()
|
|
2027
2045
|
}
|
|
2028
|
-
const why = explain(res.status, text)
|
|
2046
|
+
const why = explain(res.status, text, res.headers)
|
|
2029
2047
|
// the refusal, then what to do about it, as provider.Explain joins them
|
|
2030
2048
|
const ids = upstreamIds(text, res.headers)
|
|
2031
2049
|
const msg = `${vendorError(text, statusLine(res.status))}${ids.said} — ${why}`
|
|
@@ -2044,4 +2062,4 @@ export const FactoryAuthPlugin = async ({ client }) => {
|
|
|
2044
2062
|
}
|
|
2045
2063
|
|
|
2046
2064
|
// for tests
|
|
2047
|
-
export const _internal = { fastBody, FAST_BETA, limitWindows, windowEnd, dollars, vendorError, CORE, droidBody, DROID_LINE, geminiBody, leaveOutAttachments, LEFT_OUT, TOO_LARGE_HINT, MODELS, PROMOTIONS, rateOf, configModels, providerModel, providerModels }
|
|
2065
|
+
export const _internal = { contentRefused, explain, fastBody, FAST_BETA, limitWindows, windowEnd, dollars, vendorError, CORE, droidBody, DROID_LINE, geminiBody, leaveOutAttachments, LEFT_OUT, TOO_LARGE_HINT, MODELS, PROMOTIONS, rateOf, configModels, providerModel, providerModels }
|