diff --git a/packages/codearts/README.md b/packages/codearts/README.md index 50d9725..f8eec39 100644 --- a/packages/codearts/README.md +++ b/packages/codearts/README.md @@ -73,6 +73,10 @@ signing in, a short built-in catalog stands in. `mcp__plugin_android-emulator_android-emulator__android_discover_project`) goes as its first 55 characters, `_` and 8 hex of its SHA-256, and the tool calls in the answer, streamed or not, carry the agent's own name again. +- Every model is listed as text only (`modalities.input: ["text"]`, `image: false`): CodeArts + answers an image with `InferHub.001001020.406` "The request model is not multimodal". Since + 0.2.4 magpie is told so, and describes an image for the model or leaves it out. That refusal, + inside a `200` or with any status, comes back as a `400`, not a `502` an agent would ask again. ## Usage and check-in @@ -130,6 +134,8 @@ magpie 里使用其 GLM、DeepSeek、openPangu 等模型。provider id:`codear 只对流式回答计量积分),调用方要非流式时折叠回 JSON;默认注入 `thinking: { type: "enabled" }`,思考与 正文分开;200 里内嵌的错误换算为 `429` / `400` / `502` 并带厂商原话;码道只接受不超过 64 个字符的工具名, 更长的(如 MCP 工具名)发出时缩为前 55 个字符 + `_` + 8 位 SHA-256,回答(流式与非流式)里的工具调用再换回原名。 + 0.2.4 起所有模型都声明为只收文本(码道对图片回 `InferHub.001001020.406`「The request model is not multimodal」), + magpie 会替模型描述图片或把图片略去;这个拒绝不论放在 200 里还是带别的状态码,都换算为 `400`,而不是让智能体反复重试的 `502`。 - **用量与签到**:总积分决定账号是否可用,其余积分桶只做明细;另有每日免费额度窗口。各批积分的到期 时间读自码道控制台同一批接口,读不到时退回插件的签到账本 `~/.config/magpie/codearts-checkins.json` (这部分仍在用更多账号验证,请以控制台为准)。`auth.checkin` 与客户端「限时福利 → 每日领取」一致 diff --git a/packages/codearts/index.mjs b/packages/codearts/index.mjs index a84bfc8..6fa9f85 100644 --- a/packages/codearts/index.mjs +++ b/packages/codearts/index.mjs @@ -221,6 +221,14 @@ const CATALOG = [ { id: "deepseek-v4.1-flash", name: "DeepSeek V4.1 Flash" }, ] +// Every model listed takes text alone: the vision ones (`-vl`) are left out +// (parseModelInfo), and the rest answer an image with +// `InferHub.001001020.406` "The request model is not multimodal". Said in so +// many words (`image: false`, not left out, which magpie reads as unknown), +// so magpie describes an image for the model or leaves it out, and an agent +// is told it takes none. +const TEXT_ONLY = { input: { text: true, image: false, audio: false, video: false, pdf: false } } + // ---- small helpers --------------------------------------------------------- const firstOf = (...vs) => vs.find((v) => typeof v === "string" && v.trim())?.trim() ?? "" @@ -1076,9 +1084,19 @@ function isRateLimitCode(code) { function embeddedErrorStatus(code) { if (isRateLimitCode(code)) return 429 if (/(^|\.)40[0-4](\.|$)|InferHub\.400[0-9]\./.test(String(code ?? ""))) return 400 + if (isNotMultimodal(code)) return 400 return 502 } +/** + * An image sent to a text-only model (`InferHub.001001020.406` "The request + * model is not multimodal"): the request's content, which no retry and no + * other account changes. + */ +function isNotMultimodal(codeOrText) { + return /InferHub\.001001020\.406|not multimodal/i.test(String(codeOrText ?? "")) +} + /** Does this event carry part of an answer (not only a role or a keepalive)? */ function eventHasContent(event) { const choice = Array.isArray(event?.choices) ? event.choices[0] : undefined @@ -1234,7 +1252,8 @@ async function foldAnswer(res, head, names = null) { const body = names ? JSON.stringify(restoreToolNames(whole, names)) : text return new Response(body, { status: res.status, statusText: res.statusText, headers }) } - return errorResponse(502, errorCodeOf(text), firstOf(errorMessageOf(text), "the gateway returned an empty answer")) + const code = errorCodeOf(text) + return errorResponse(code ? embeddedErrorStatus(code) : 502, code, firstOf(errorMessageOf(text), "the gateway returned an empty answer")) } /** An OpenAI-shaped error carrying the vendor's code and words (magpie adds the provider name). */ @@ -1632,6 +1651,9 @@ async function signedFetch(cred, input, init, context) { } return errorResponse(429, SESSION_LIMIT_ERROR, firstOf(errorMessageOf(text), "并发会话数已达上限,请稍后再试")) } + // an image the model can't take is the request's fault, whatever + // status it came with + if (!res.ok && isNotMultimodal(code || text)) return errorResponse(400, code, firstOf(errorMessageOf(text), "the model takes no images")) if (!res.ok) return rebuildResponse(res, text) return errorResponse(embeddedErrorStatus(code), code, firstOf(errorMessageOf(text), "the gateway answered with an error")) } @@ -2341,14 +2363,19 @@ export const CodeArtsAuthPlugin = async ({ client } = {}, options = {}) => { // Declared so a caller never sends its own, larger default. limit: { context: m.context ?? 0, output: MAX_OUTPUT_TOKENS }, tool_call: true, + // Text only (TEXT_ONLY): said, not left out, so an agent sends no image. + attachment: false, + modalities: { input: ["text"], output: ["text"] }, }) const modelOf = (provider, live, state) => { const base = provider.models?.[live.id] ?? {} const capabilities = { - temperature: true, toolcall: true, attachment: false, input: { text: true }, output: { text: true }, + temperature: true, toolcall: true, output: { text: true }, attachment: false, ...(base.capabilities ?? {}), ...(live.reasoning ? { reasoning: true } : {}), + // what the user's own config says of a kind stands; the rest is text only + input: { ...TEXT_ONLY.input, ...(base.capabilities?.input ?? {}) }, } // magpie's own fields: `free` (from the free daily pool, the same answer // the signed `maas_type: benefit` header follows, so a model never shows @@ -2648,7 +2675,7 @@ export const _internal = { PACKAGE_CREDIT_PAGE_URL, OPS_CREDIT_OVERVIEW_URL, OPS_CREDIT_CAMPAIGN_URL, toBytes, isBenefitModel, prepareChatBody, signedFetch, signedGet, TOOL_NAME_LIMIT, cutToolName, shortenToolNames, restoreToolNames, restoreToolNamesInStream, - parseSseEvents, errorCodeOf, errorMessageOf, isStaleCredential, isRateLimitCode, embeddedErrorStatus, classifyHead, + parseSseEvents, errorCodeOf, errorMessageOf, isStaleCredential, isRateLimitCode, embeddedErrorStatus, isNotMultimodal, classifyHead, peekAnswer, completionFromChunks, createConcurrencyGate, delay, retryDelayMs, isRegularModel, queueInfoOf, waitInQueue, TRACE_QUEUE_URL, SESSION_HEADER, snapRequest, dailyCheckin, diff --git a/packages/codearts/index.test.mjs b/packages/codearts/index.test.mjs index d800e1f..8246367 100644 --- a/packages/codearts/index.test.mjs +++ b/packages/codearts/index.test.mjs @@ -943,6 +943,62 @@ test("the free model's TPM limit inside a 200 is a 429 magpie fails over on, not } }) +// star21321321124 (Discord, 10-28): an agent sent DeepSeek V4.1 Flash an +// image, and the "502: you can retry" had it ask again and again. +const notMultimodal = { error_code: "InferHub.001001020.406", error_msg: "The request model is not multimodal" } + +test("an image a text-only model turns away is a 400, not a 502 to retry, on every path", async () => { + const cred = await makeCred() + let answer = () => sseResponse(sse(notMultimodal)) + const plugin = await CodeArtsAuthPlugin({ client: {} }, { fetch: async () => answer() }) + const loaded = await plugin.auth.loader(async () => makeAuth(cred)) + const ask = (stream) => loaded.fetch(CHAT_URL, chatInit({ model: "deepseek-v4.1-flash", messages: [{ role: "user", content: "看图" }], stream })) + const cases = [ + ["inside a 200", () => sseResponse(sse(notMultimodal))], + ["as a 502", () => new Response(JSON.stringify(notMultimodal), { status: 502, headers: { "content-type": "application/json" } })], + ["as a 406", () => new Response(JSON.stringify(notMultimodal), { status: 406, headers: { "content-type": "application/json" } })], + ] + for (const [how, make] of cases) { + answer = make + for (const stream of [true, false]) { + const res = await ask(stream) + assert.equal(res.status, 400, `${how}, stream ${stream}`) + const body = await res.json() + assert.equal(body.error.code, "InferHub.001001020.406", how) + assert.match(body.error.message, /not multimodal/, how) + } + } +}) + +test("every model says it takes text alone, so an agent sends it no image", async () => { + const plugin = await CodeArtsAuthPlugin({ client: {} }, {}) + const config = {} + await plugin.config(config) + for (const [id, m] of Object.entries(config.provider.codearts.models)) { + assert.deepEqual(m.modalities, { input: ["text"], output: ["text"] }, id) + assert.equal(m.attachment, false, id) + } + + const cred = await makeCred() + const listed = await CodeArtsAuthPlugin({ client: {} }, { fetch: modelsFetcher([], { agents: agentList, detail: agentDetail }) }) + // the host's entry for a config model, and one the user said sees + const provider = { + models: { + "GLM-5.2": { capabilities: { input: { text: true, image: false } } }, + "glm-5.3-flash": { capabilities: { input: { text: true, image: true } } }, + }, + } + const models = await listed.provider.models(provider, { auth: makeAuth(cred) }) + // glm-5.3 only the agent lists, deepseek-v4-flash-0731 has no entry of its own + for (const id of ["GLM-5.2", "glm-5.3", "deepseek-v4-flash-0731"]) { + assert.equal(models[id].capabilities.input.image, false, id) + assert.equal(models[id].capabilities.input.text, true, id) + assert.equal(models[id].capabilities.attachment, false, id) + } + // what the user's own config says stands + assert.equal(models["glm-5.3-flash"].capabilities.input.image, true) +}) + test("embeddedErrorStatus sorts the gateway's codes into what magpie acts on", () => { assert.equal(x.embeddedErrorStatus("InferHub.4291.200"), 429) assert.equal(x.embeddedErrorStatus("81114.429"), 429) @@ -950,6 +1006,7 @@ test("embeddedErrorStatus sorts the gateway's codes into what magpie acts on", ( assert.equal(x.embeddedErrorStatus("ModelArts.81009.404"), 400) assert.equal(x.embeddedErrorStatus("InferHub.001001005.400"), 400) assert.equal(x.embeddedErrorStatus("InferHub.5000.500"), 502) + assert.equal(x.embeddedErrorStatus("InferHub.001001020.406"), 400) }) test("every chat carries the agent's session headers: one session, a fresh trace", async () => { diff --git a/packages/codearts/package.json b/packages/codearts/package.json index fb945af..f9d087a 100644 --- a/packages/codearts/package.json +++ b/packages/codearts/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-codearts-auth", - "version": "0.2.3", + "version": "0.2.4", "description": "Huawei Cloud CodeArts (码道) in OpenCode and magpie: its models through Huawei Cloud OAuth sign-in, signed requests, credit usage and the daily check-in (unofficial)", "type": "module", "main": "./index.mjs",