From aa44cc3edb49b9a0b0c113609ac2903cdb3edba7 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 4 Nov 2026 14:45:23 +0800 Subject: [PATCH] zed 0.1.17: an Anthropic thinking.display Zed has no variant for is left out (#708) gogoing1024 (#708): claude-sonnet-5-5 from Claude Code at max effort was answered 400 "Zed: failed to parse Anthropic request: unknown variant `updates`, expected `omitted` or `summarized`". Claude Code asks its newest models for thinking.display "updates"; Zed's cloud parses display into an enum with only omitted and summarized. providerRequest now sends "highlights" as summarized (the thinking still shown) and leaves any other value beyond omitted/summarized out, the same rule magpie's gateway applies to relays (withDisplay in internal/gateway/anthropic_shapes.go). Adaptive and budgeted thinking alike; summarized and omitted go as written. Run at this head (mote, via mote-run): - bun test in packages/zed: 71 pass, 0 fail (11 files) - bun scripts/check.mjs: exit 0 Broken by hand: thinking-display.test.mjs against the old index.mjs, 3 of 5 red (updates, highlights, budgeted updates). Not tried: a real Zed account; the fix is from the reporter's 400 text and the request shape Claude Code writes. --- packages/zed/index.mjs | 11 ++++ packages/zed/package.json | 2 +- packages/zed/thinking-display.test.mjs | 78 ++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 packages/zed/thinking-display.test.mjs diff --git a/packages/zed/index.mjs b/packages/zed/index.mjs index ddaef50..afa6f24 100644 --- a/packages/zed/index.mjs +++ b/packages/zed/index.mjs @@ -665,6 +665,17 @@ function providerRequest(wire, req, model) { if (edits.length) req.context_management = { ...cm, edits } else delete req.context_management } + // Zed's cloud parses thinking.display into its own enum too, which has + // only omitted and summarized: Claude Code's "updates" was answered 400 + // "unknown variant `updates`, expected `omitted` or `summarized`" + // (gogoing1024, #708). "highlights" goes as summarized, the thinking + // still shown; "updates" or any other is left out, as Claude Code + // itself sends it again after Anthropic's API refuses one. + const th = req.thinking + if (th && typeof th === "object" && "display" in th && th.display !== "omitted" && th.display !== "summarized") { + if (th.display === "highlights") th.display = "summarized" + else delete th.display + } // Zed's Anthropic request has no stream field: the cloud always streams delete req.stream // Zed's cloud refuses a tool result without is_error ("missing field diff --git a/packages/zed/package.json b/packages/zed/package.json index 0e106ba..efb23fc 100644 --- a/packages/zed/package.json +++ b/packages/zed/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-zed-auth", - "version": "0.1.16", + "version": "0.1.17", "description": "Sign in to a Zed subscription (Zed Pro, trial, student, business) from OpenCode or magpie", "type": "module", "main": "./opencode.mjs", diff --git a/packages/zed/thinking-display.test.mjs b/packages/zed/thinking-display.test.mjs new file mode 100644 index 0000000..56f7144 --- /dev/null +++ b/packages/zed/thinking-display.test.mjs @@ -0,0 +1,78 @@ +// Zed's cloud parses an Anthropic request's thinking.display into its own +// enum, which has only omitted and summarized. Claude Code asks +// claude-sonnet-5-5 for display "updates", which Zed answered 400 "failed to +// parse Anthropic request: unknown variant `updates`, expected `omitted` or +// `summarized`" (gogoing1024, #708). The plugin sends "highlights" as +// summarized, leaves any other unknown value out, and passes the two Zed +// knows as written. +import { afterEach, expect, test } from "bun:test" +import { _internal } from "./index.mjs" + +const real = globalThis.fetch +afterEach(() => { + globalThis.fetch = real + _internal.tokens.clear() +}) + +const s = { userId: "4242", access: "plain-access", systemId: "", org: "org-me", plan: "zed_pro", who: "octo" } + +// sent is the provider_request the plugin hands Zed for an Anthropic body. +async function sent(body) { + let got + globalThis.fetch = async (url, init) => { + const path = new URL(String(url)).pathname + if (path === "/client/llm_tokens") return Response.json({ token: "llm-token" }) + if (path === "/completions") { + got = JSON.parse(init.body) + const ev = (e) => JSON.stringify({ event: e }) + return new Response( + [ + ev({ type: "message_start", message: { id: "m1", type: "message", role: "assistant", model: "claude-sonnet-5-5", content: [], usage: { input_tokens: 1, output_tokens: 0 } } }), + ev({ type: "message_delta", delta: { stop_reason: "end_turn" }, usage: { output_tokens: 1 } }), + ev({ type: "message_stop" }), + JSON.stringify({ status: "stream_ended" }), + ].join("\n") + "\n", + { headers: { "x-zed-server-supports-status-messages": "true" } }, + ) + } + return new Response("", { status: 404 }) + } + const res = await _internal.complete(s, "https://cloud.zed.dev/v1/messages", { method: "POST", body: JSON.stringify(body) }) + expect(res.status).toBe(200) + await res.text() + return got.provider_request +} + +// body is a request as Claude Code writes it for claude-sonnet-5-5 at max effort. +const body = (thinking) => ({ + model: "claude-sonnet-5-5", + stream: true, + max_tokens: 64000, + thinking, + output_config: { effort: "max" }, + messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }], +}) + +test("Claude Code's display updates is left out, the adaptive thinking kept", async () => { + const pr = await sent(body({ type: "adaptive", display: "updates" })) + expect(pr.thinking).toEqual({ type: "adaptive" }) + expect(pr.output_config).toEqual({ effort: "max" }) +}) + +test("display highlights goes as summarized", async () => { + expect((await sent(body({ type: "adaptive", display: "highlights" }))).thinking).toEqual({ type: "adaptive", display: "summarized" }) +}) + +test("a budgeted thinking's unknown display is left out too", async () => { + expect((await sent(body({ type: "enabled", budget_tokens: 2048, display: "updates" }))).thinking).toEqual({ type: "enabled", budget_tokens: 2048 }) +}) + +test("summarized and omitted go as written", async () => { + expect((await sent(body({ type: "adaptive", display: "summarized" }))).thinking).toEqual({ type: "adaptive", display: "summarized" }) + expect((await sent(body({ type: "adaptive", display: "omitted" }))).thinking).toEqual({ type: "adaptive", display: "omitted" }) +}) + +test("a request without display is unchanged", async () => { + expect((await sent(body({ type: "adaptive" }))).thinking).toEqual({ type: "adaptive" }) + expect("thinking" in (await sent({ ...body(undefined), thinking: undefined }))).toBe(false) +})