@magpie-community/opencode-factory-auth 0.1.39 → 0.1.40

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.
Files changed (2) hide show
  1. package/index.mjs +14 -2
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -785,12 +785,15 @@ function tooLarge(text, left) {
785
785
 
786
786
  // errorReply is an error as the API the request was for words one:
787
787
  // Anthropic's on /llm/a/, OpenAI's on the others.
788
- function errorReply(url, status, type, message, headers = new Headers(), requestId) {
788
+ // code is the vendor's error code, kept on the error: magpie and OpenCode
789
+ // tell a refusal of the request apart by it (content_policy_rejected).
790
+ function errorReply(url, status, type, message, headers = new Headers(), requestId, code) {
789
791
  headers.set("content-type", "application/json")
790
792
  headers.delete("content-length")
791
793
  headers.delete("content-encoding")
792
794
  const anthropic = new URL(url).pathname.includes("/llm/a/")
793
- const body = anthropic ? { type: "error", error: { type, message } } : { error: { message, type, code: null } }
795
+ const body = anthropic ? { type: "error", error: { type, message } } : { error: { message, type, code: code ?? null } }
796
+ if (anthropic && code) body.error.code = code
794
797
  // Anthropic's error body carries the request id beside the error
795
798
  if (anthropic && requestId) body.request_id = requestId
796
799
  return new Response(JSON.stringify(body), { status, headers })
@@ -2088,6 +2091,15 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
2088
2091
  // the refusal, then what to do about it, as provider.Explain joins them
2089
2092
  const ids = upstreamIds(text, res.headers)
2090
2093
  const msg = `${vendorError(text, statusLine(res.status))}${ids.said} — ${why}`
2094
+ if (contentRefused(res.status, text, res.headers)) {
2095
+ // the usage policy check refused what the request says, not
2096
+ // the account: a 400 invalid_request_error with Factory's
2097
+ // code, as OpenAI words a content refusal. Its 403
2098
+ // permission_error read to agents as a failed sign-in
2099
+ // (yetone/magpie, sweanng: ZCode's "Provider
2100
+ // authentication failed", reason=auth_failed status=403)
2101
+ return answer(errorReply(url, 400, "invalid_request_error", msg, new Headers(res.headers), ids.id, "content_policy_rejected"))
2102
+ }
2091
2103
  return answer(errorReply(url, res.status, "permission_error", msg, new Headers(res.headers), ids.id))
2092
2104
  } catch (e) {
2093
2105
  // Factory refused to renew the sign-in: the built-in failed the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-factory-auth",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "description": "Sign in to a Factory (Droid) subscription from OpenCode or magpie",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",