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",