zed 0.1.14: a Gemini model's effort variants are keyed lowercase, and its thinking level reaches Zed uppercase (#215)
Zed's cloud parses a Google request with its own serde enums (zed
crates/google_ai): ThinkingLevel is rename_all UPPERCASE (MINIMAL, LOW,
MEDIUM, HIGH) and FunctionCallingMode rename_all lowercase (auto, any,
none). A thinking budget reached it as thinkingLevel "low" and was
answered 400 "failed to parse Google AI request: unknown variant `low`,
expected one of `MINIMAL`, `LOW`, `MEDIUM`, `HIGH`" (iron-water, #215).
- The gemini wire in providerRequest() now goes through geminiEnums(),
from ump45nose's #587: the thinking level is uppercased (an empty one
left out) and the tool-calling mode lowercased, as 0.1.13 already did,
with VALIDATED, which Zed has no variant for, asked as auto.
- Zed's /models now lists a Gemini model's supported_effort_levels
uppercase (LOW/MEDIUM/HIGH; Yezike-yyy's Student-plan list on #215), so
the variants were keyed LOW and carried thinkingLevel "LOW". magpie's pi
profile, which maps efforts by key, matched none of them, and
@ai-sdk/google (thinkingLevel z.enum minimal/low/medium/high) refuses
an uppercase level. effortsOf() now lowercases the values whatever case
/models writes, once each, so a variant keeps the AI SDK's lowercase
spelling (the owner's review on #587) and only the wire is uppercase.
This covers every vendor's efforts, not only Google's.
- _internal exports model() so the test checks provider.models' variants.
Tests: gemini-enums.test.mjs builds its model list from the
supported_effort_levels Yezike-yyy pasted on #215, byte for byte, and its
fake /completions refuses both enums with Zed's error text.
Run on mote at f4e2ac3 plus this change: packages/zed `bun test` 61 pass,
0 fail; root `HOME=$(mktemp -d) bun test` 4545 pass, 0 fail; `bun
scripts/check.mjs` ok. (A root run with a HOME outside tmpdir gives the
same 20 devin/isolated-home reds on origin/main as with this change.)
Broken by hand:
- origin/main's index.mjs under the new test: 7 of 7 fail;
- effortsOf without the lowercase: 4 fail;
- the wire level not uppercased: 2 fail;
- VALIDATED not mapped to auto: 1 fail.
Not tried: a live request to cloud.zed.dev and OpenCode with the real
@ai-sdk/google (no Zed account here). Yezike-yyy reports the same two
changes, patched into 0.1.13, answered 200 for low/medium/high on
zed/gemini-4-argon through magpie on Windows with pi.
Thanks to Yezike-yyy for the uppercase /models finding and its check
through pi.
Co-authored-by: ump45nose <52391318+ump45nose@users.noreply.github.com>
This commit is contained in:
@@ -69,6 +69,10 @@ GitHub login.
|
||||
Every `tool_result` gets `is_error` (Zed's cloud refuses one without it).
|
||||
- xAI: `max_tokens` becomes `max_completion_tokens`.
|
||||
- Gemini: the model is named in the request as `models/<id>`.
|
||||
`thinkingConfig.thinkingLevel` is sent uppercase (`HIGH`) and
|
||||
`toolConfig.functionCallingConfig.mode` lowercase (`auto`), the only
|
||||
spellings Zed's cloud parses. A model's effort variants are keyed
|
||||
lowercase (`low`, `high`) whatever case Zed's model list uses.
|
||||
- **Replies:**
|
||||
- Zed's newline-delimited lines are sent back as each API's own
|
||||
server-sent events.
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
// Zed's cloud parses a Google request with its own serde enums (zed
|
||||
// crates/google_ai): ThinkingLevel UPPERCASE only, FunctionCallingMode
|
||||
// lowercase only. A thinking budget reached it as thinkingLevel "low" and was
|
||||
// answered 400 "failed to parse Google AI request: unknown variant `low`,
|
||||
// expected one of `MINIMAL`, `LOW`, `MEDIUM`, `HIGH`" (#215, iron-water).
|
||||
// Zed's /models then came to list a Gemini model's efforts uppercase, so its
|
||||
// variants were keyed LOW/MEDIUM/HIGH and hosts that map efforts by key found
|
||||
// none (#215, Yezike-yyy). A variant stays as @ai-sdk/google takes it
|
||||
// (lowercase); only the wire is uppercase (ump45nose, #587).
|
||||
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" }
|
||||
|
||||
// supported_effort_levels as Zed's /models lists them on a Student plan on
|
||||
// 2026-11-01, byte for byte from #215 (gemini-3.5-flash's list was cut off
|
||||
// after LOW there).
|
||||
const LISTED = {
|
||||
"gemini-4-argon": `[{"name":"Low","value":"LOW"},{"name":"Medium","value":"MEDIUM","is_default":true},{"name":"High","value":"HIGH"}]`,
|
||||
"gemini-3.1-pro-preview": `[{"name":"Low","value":"LOW"},{"name":"Medium","value":"MEDIUM"},{"name":"High","value":"HIGH","is_default":true}]`,
|
||||
"gemini-3.8-flash": `[{"name":"Low","value":"LOW"},{"name":"Medium","value":"MEDIUM","is_default":true},{"name":"High","value":"HIGH"}]`,
|
||||
"gemini-3.5-flash": `[{"name":"Minimal","value":"MINIMAL"},{"name":"Low","value":"LOW"}]`,
|
||||
}
|
||||
const listed = (id) => ({ provider: "google", id, supports_thinking: true, supported_effort_levels: JSON.parse(LISTED[id]) })
|
||||
|
||||
// @ai-sdk/google's providerOptions.google.thinkingLevel:
|
||||
// z.enum(['minimal','low','medium','high']) (google-language-model-options.ts)
|
||||
const AI_SDK_LEVELS = ["minimal", "low", "medium", "high"]
|
||||
|
||||
test("a Gemini model Zed lists with uppercase efforts declares lowercase variants", () => {
|
||||
for (const [id, want] of [
|
||||
["gemini-4-argon", ["low", "medium", "high"]],
|
||||
["gemini-3.1-pro-preview", ["low", "medium", "high"]],
|
||||
["gemini-3.8-flash", ["low", "medium", "high"]],
|
||||
["gemini-3.5-flash", ["minimal", "low"]],
|
||||
]) {
|
||||
const e = _internal.entry(listed(id))
|
||||
expect(e.reasoning).toBe(true)
|
||||
expect(Object.keys(e.variants)).toEqual(want)
|
||||
for (const k of want) {
|
||||
expect(e.variants[k]).toEqual({ thinkingConfig: { includeThoughts: true, thinkingLevel: k } })
|
||||
expect(AI_SDK_LEVELS).toContain(e.variants[k].thinkingConfig.thinkingLevel)
|
||||
}
|
||||
// OpenCode's provider.models hands on the same variants
|
||||
expect(Object.keys(_internal.model(listed(id)).variants)).toEqual(want)
|
||||
}
|
||||
})
|
||||
|
||||
test("lowercase efforts, as Zed listed them before, are unchanged; a doubled one is declared once", () => {
|
||||
const e = _internal.entry({ provider: "google", id: "gemini-3.8-flash", supports_thinking: true, supported_effort_levels: [{ value: "low" }, { value: "medium" }, { value: "high" }] })
|
||||
expect(Object.keys(e.variants)).toEqual(["low", "medium", "high"])
|
||||
expect(e.variants.high.thinkingConfig.thinkingLevel).toBe("high")
|
||||
const d = _internal.entry({ provider: "google", id: "g", supported_effort_levels: [{ value: "LOW" }, { value: "low" }, { value: "" }, {}, null] })
|
||||
expect(Object.keys(d.variants)).toEqual(["low"])
|
||||
})
|
||||
|
||||
test("another vendor's uppercase effort is keyed and given lowercase too", () => {
|
||||
const a = _internal.entry({ provider: "anthropic", id: "claude-sonnet-5", supported_effort_levels: [{ value: "HIGH" }] })
|
||||
expect(a.variants).toEqual({ high: { effort: "high" } })
|
||||
const o = _internal.entry({ provider: "open_ai", id: "gpt-5.5", supported_effort_levels: [{ value: "Low" }] })
|
||||
expect(o.variants).toEqual({ low: { reasoningEffort: "low" } })
|
||||
})
|
||||
|
||||
// sent is the provider_request the plugin hands Zed for a Gemini body, from
|
||||
// an upstream that parses both enums as Zed's cloud does.
|
||||
async function sent(body, model = "gemini-4-argon") {
|
||||
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 level = got.provider_request.generationConfig?.thinkingConfig?.thinkingLevel
|
||||
if (level !== undefined && !["MINIMAL", "LOW", "MEDIUM", "HIGH"].includes(level)) {
|
||||
return new Response(`failed to parse Google AI request: unknown variant \`${level}\`, expected one of \`MINIMAL\`, \`LOW\`, \`MEDIUM\`, \`HIGH\``, { status: 400 })
|
||||
}
|
||||
const mode = got.provider_request.toolConfig?.functionCallingConfig?.mode
|
||||
if (mode !== undefined && !["auto", "any", "none"].includes(mode)) {
|
||||
return new Response(`failed to parse Google AI request: unknown variant \`${mode}\`, expected one of \`auto\`, \`any\`, \`none\``, { status: 400 })
|
||||
}
|
||||
const ev = (e) => JSON.stringify({ event: e })
|
||||
return new Response(
|
||||
[
|
||||
ev({ candidates: [{ content: { role: "model", parts: [{ text: "Hi" }] }, finishReason: "STOP" }], usageMetadata: { promptTokenCount: 1, candidatesTokenCount: 1 } }),
|
||||
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/v1beta/models/${model}:streamGenerateContent?alt=sse`, { method: "POST", body: JSON.stringify(body) })
|
||||
return { req: got.provider_request, res, text: await res.text() }
|
||||
}
|
||||
|
||||
const tools = [{ functionDeclarations: [{ name: "Bash", description: "run a command", parameters: { type: "object", properties: { command: { type: "string" } }, required: ["command"] } }] }]
|
||||
const ask = (extra = {}) => ({ contents: [{ role: "user", parts: [{ text: "hi" }] }], generationConfig: { maxOutputTokens: 64, ...extra.generationConfig }, ...(extra.toolConfig && { tools, toolConfig: extra.toolConfig }) })
|
||||
|
||||
test("each declared variant, as the AI SDK writes it, reaches Zed uppercase and is answered", async () => {
|
||||
const e = _internal.entry(listed("gemini-4-argon"))
|
||||
for (const [k, want] of [["low", "LOW"], ["medium", "MEDIUM"], ["high", "HIGH"]]) {
|
||||
// @ai-sdk/google writes providerOptions.google.thinkingConfig into
|
||||
// generationConfig as given
|
||||
const { req, res, text } = await sent(ask({ generationConfig: { thinkingConfig: e.variants[k].thinkingConfig }, toolConfig: { functionCallingConfig: { mode: "AUTO" } } }))
|
||||
expect(text).not.toContain("unknown variant")
|
||||
expect(res.status).toBe(200)
|
||||
expect(req.model).toBe("models/gemini-4-argon")
|
||||
expect(req.generationConfig.thinkingConfig).toEqual({ includeThoughts: true, thinkingLevel: want })
|
||||
expect(req.toolConfig.functionCallingConfig.mode).toBe("auto")
|
||||
}
|
||||
})
|
||||
|
||||
test("a thinking level in any case goes to Zed uppercase", async () => {
|
||||
for (const [given, want] of [["minimal", "MINIMAL"], ["low", "LOW"], ["medium", "MEDIUM"], ["high", "HIGH"], ["HIGH", "HIGH"], ["High", "HIGH"]]) {
|
||||
const { req, res } = await sent(ask({ generationConfig: { thinkingConfig: { includeThoughts: true, thinkingLevel: given } } }))
|
||||
expect(res.status).toBe(200)
|
||||
expect(req.generationConfig.thinkingConfig).toEqual({ includeThoughts: true, thinkingLevel: want })
|
||||
}
|
||||
})
|
||||
|
||||
test("an empty thinking level is left out; a budget alone is sent as it was", async () => {
|
||||
let { req, res } = await sent(ask({ generationConfig: { thinkingConfig: { includeThoughts: true, thinkingLevel: "" } } }))
|
||||
expect(res.status).toBe(200)
|
||||
expect(req.generationConfig.thinkingConfig).toEqual({ includeThoughts: true })
|
||||
;({ req, res } = await sent(ask({ generationConfig: { thinkingConfig: { thinkingBudget: 2000 } } })))
|
||||
expect(res.status).toBe(200)
|
||||
expect(req.generationConfig.thinkingConfig).toEqual({ thinkingBudget: 2000 })
|
||||
})
|
||||
|
||||
test("VALIDATED, which Zed has no mode for, is asked as auto", async () => {
|
||||
const { req, res } = await sent(ask({ toolConfig: { functionCallingConfig: { mode: "VALIDATED", allowedFunctionNames: ["Bash"] } } }))
|
||||
expect(res.status).toBe(200)
|
||||
expect(req.toolConfig.functionCallingConfig).toEqual({ mode: "auto", allowedFunctionNames: ["Bash"] })
|
||||
})
|
||||
+36
-9
@@ -376,7 +376,15 @@ function variant(provider, effort) {
|
||||
return { reasoningEffort: effort }
|
||||
}
|
||||
|
||||
const effortsOf = (m) => (m.supported_effort_levels ?? []).map((e) => e?.value).filter(Boolean)
|
||||
// effortsOf is the efforts a model lists, lowercase whatever case /models
|
||||
// writes them in. Zed's /models came to list a Gemini model's levels
|
||||
// uppercase (LOW, MEDIUM, HIGH), so the variants were keyed LOW and carried
|
||||
// thinkingLevel "LOW": hosts that map efforts by key (magpie's pi profile)
|
||||
// matched none of them, and @ai-sdk/google, whose thinkingLevel is
|
||||
// minimal/low/medium/high, refuses an uppercase one (Yezike-yyy, #215). A
|
||||
// variant keeps the AI SDK's spelling; the gemini wire in providerRequest
|
||||
// uppercases the level for Zed.
|
||||
const effortsOf = (m) => [...new Set((m.supported_effort_levels ?? []).map((e) => e?.value).filter((v) => typeof v === "string" && v).map((v) => v.toLowerCase()))]
|
||||
|
||||
// entry is a model as OpenCode's config declares it.
|
||||
function entry(m) {
|
||||
@@ -614,6 +622,31 @@ function withoutSystemTurns(messages) {
|
||||
return out
|
||||
}
|
||||
|
||||
// Zed's cloud parses a Google request with its own serde enums (zed
|
||||
// crates/google_ai), which take fewer spellings than Google's API does:
|
||||
// ThinkingLevel is UPPERCASE only (MINIMAL, LOW, MEDIUM, HIGH) and
|
||||
// FunctionCallingMode lowercase only (auto, any, none).
|
||||
// - The tool-calling mode, as the AI SDK and magpie's Code Assist envelope
|
||||
// write it (AUTO, ANY, NONE), was answered 400 "failed to parse Google AI
|
||||
// request: unknown variant `AUTO`, expected one of `auto`, `any`, `none`",
|
||||
// so every turn that declared a tool failed (atticuskk, magpie#4657).
|
||||
// VALIDATED, which Zed has no variant for, is asked as auto.
|
||||
// - The thinking level, as the AI SDK and magpie's own translation write it
|
||||
// (high), was answered "unknown variant `high`, expected one of
|
||||
// `MINIMAL`, `LOW`, `MEDIUM`, `HIGH`" (#215). An empty one is left out.
|
||||
// geminiEnums spells both as Zed takes them (ump45nose, #587).
|
||||
const ZED_MODE = { AUTO: "auto", ANY: "any", NONE: "none", VALIDATED: "auto", MODE_UNSPECIFIED: "auto" }
|
||||
|
||||
function geminiEnums(req) {
|
||||
const tc = req.generationConfig?.thinkingConfig
|
||||
if (tc && typeof tc.thinkingLevel === "string") {
|
||||
if (tc.thinkingLevel) tc.thinkingLevel = tc.thinkingLevel.toUpperCase()
|
||||
else delete tc.thinkingLevel
|
||||
}
|
||||
const fc = req.toolConfig?.functionCallingConfig
|
||||
if (fc && typeof fc.mode === "string") fc.mode = ZED_MODE[fc.mode.toUpperCase()] ?? fc.mode.toLowerCase()
|
||||
}
|
||||
|
||||
// providerRequest is the request as Zed takes it for its provider's API,
|
||||
// and whether the caller asked for a stream (Zed always streams).
|
||||
function providerRequest(wire, req, model) {
|
||||
@@ -658,13 +691,7 @@ function providerRequest(wire, req, model) {
|
||||
delete req.session_id
|
||||
delete req.sessionId
|
||||
req.model = "models/" + model
|
||||
// Zed's cloud reads the tool-calling mode in lowercase (auto, any,
|
||||
// none); the Gemini API's proto enums, as the AI SDK and magpie's
|
||||
// Code Assist envelope write them (AUTO, ANY, NONE), are answered 400
|
||||
// "failed to parse Google AI request: unknown variant `AUTO`", so every
|
||||
// turn that declared a tool failed (atticuskk, magpie#4657)
|
||||
const fc = req.toolConfig?.functionCallingConfig
|
||||
if (fc && typeof fc.mode === "string") fc.mode = fc.mode.toLowerCase()
|
||||
geminiEnums(req)
|
||||
return { req }
|
||||
}
|
||||
}
|
||||
@@ -1263,4 +1290,4 @@ export async function ZedAuthPlugin({ client } = {}) {
|
||||
}
|
||||
|
||||
// for tests
|
||||
export const _internal = { said, eventError, stateOf, parseModels, entry, providerRequest, wireOf, refusal, failedStatus, decrypt, padded, signedInWith, complete, vendors, tokens, lists, orgOf, planOf, picked, who, planName, usage }
|
||||
export const _internal = { said, eventError, stateOf, parseModels, entry, model, providerRequest, wireOf, refusal, failedStatus, decrypt, padded, signedInWith, complete, vendors, tokens, lists, orgOf, planOf, picked, who, planName, usage }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-zed-auth",
|
||||
"version": "0.1.13",
|
||||
"version": "0.1.14",
|
||||
"description": "Sign in to a Zed subscription (Zed Pro, trial, student, business) from OpenCode or magpie",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
Reference in New Issue
Block a user