From 23a580b6aa2e524a4edcc982fe04848366f5b95d Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 1 Oct 2026 03:21:02 +0800 Subject: [PATCH] =?UTF-8?q?factory=200.1.3:=20a=20refusal=20says=20what=20?= =?UTF-8?q?to=20do=20after=20an=20em=20dash=20("=20?= =?UTF-8?q?=E2=80=94=20Factory=20refused=20this=20account=E2=80=A6"),=20as?= =?UTF-8?q?=20the=20built-in's=20Provider.Explain=20joins=20them,=20where?= =?UTF-8?q?=20it=20used=20":=20";=20an=20empty=20403=20reads=20"403=20Forb?= =?UTF-8?q?idden",=20the=20status=20Go=20falls=20back=20to?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/factory/index.mjs | 3 ++- packages/factory/lapsed.test.mjs | 13 +++++++++++++ packages/factory/package.json | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/factory/index.mjs b/packages/factory/index.mjs index 8364664..be1a406 100644 --- a/packages/factory/index.mjs +++ b/packages/factory/index.mjs @@ -681,7 +681,8 @@ export const FactoryAuthPlugin = async ({ client }) => { text = await res.text() } const why = explain(res.status, text) - const msg = `${apiError(text, "Forbidden")}: ${why}` + // the refusal, then what to do about it, as provider.Explain joins them + const msg = `${apiError(text, "403 Forbidden")} — ${why}` return errorReply(url, res.status, "permission_error", msg, new Headers(res.headers)) }, } diff --git a/packages/factory/lapsed.test.mjs b/packages/factory/lapsed.test.mjs index 5e2f884..1ced49b 100644 --- a/packages/factory/lapsed.test.mjs +++ b/packages/factory/lapsed.test.mjs @@ -52,3 +52,16 @@ test("and OpenAI's on /llm/o/", async () => { expect(b.error.code).toBe(null) expect(b.type).toBeUndefined() }) + +test("a refusal says what to do after an em dash, as the built-in's Explain joins it", async () => { + globalThis.fetch = async () => new Response(JSON.stringify({ error: { message: "model not allowed" } }), { status: 403 }) + const auth = { ...expired, access: "tok", expires: Date.now() + 3_600_000 } + const hooks = await FactoryAuthPlugin({ client: { auth: { set: async () => {} } } }) + const l = await hooks.auth.loader(async () => auth) + let res = await l.fetch("https://api.factory.ai/api/llm/o/v1/responses", { method: "POST", body: JSON.stringify({ model: "gpt-x" }) }) + expect(res.status).toBe(403) + expect((await res.json()).error.message).toMatch(/^model not allowed — Factory refused this account the request; check that `droid`/) + globalThis.fetch = async () => new Response("", { status: 403 }) + res = await l.fetch("https://api.factory.ai/api/llm/o/v1/responses", { method: "POST", body: JSON.stringify({ model: "gpt-x" }) }) + expect((await res.json()).error.message).toMatch(/^403 Forbidden — Factory refused/) +}) diff --git a/packages/factory/package.json b/packages/factory/package.json index 6f48de5..3711076 100644 --- a/packages/factory/package.json +++ b/packages/factory/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-factory-auth", - "version": "0.1.2", + "version": "0.1.3", "description": "Sign in to a Factory (Droid) subscription from OpenCode or magpie", "type": "module", "main": "./index.mjs",