troilus1011 on X: WorkBuddy's DeepSeek in OpenCode through magpie thought at low and high, never at the default. OpenCode's default variant names no reasoning_effort, and WorkBuddy doesn't think without one: measured on www.workbuddy.ai with 0.1.42, deepseek-v4.1-flash gave 0 reasoning tokens with no effort (2 of 2), 0 at none, 16/37 at low, 34/56 at high. WorkBuddy's own client (CLI 2.165.0 in WorkBuddy 5.9.3, configureThinkingSettings) sends the session's effort, else the reasoningEffort setting, else the model's reasoning.defaultEffort from /v3/config, which is "high" for this model on both builds. A chat that names no effort now gets the model's own defaultEffort when its listed levels hold it, read from the same cached /v3/config list (one read per minute; a failed read leaves the chat as it came and is not retried on every chat). An effort the client names, none included, is untouched and the list isn't read for it. Models with no reasoning config get nothing. runmiNeverstop on X: 2.89 GB up to copilot.tencent.com through magpie. WorkBuddy's client gzips a model request's body (GzipRequestProcessor, on with productFeatures.RequestBodyGzip, true in both builds' product.json and not turned off by the remote config); the plugin sent it as plain JSON. Agent chat JSON (the whole history each turn, tool schemas) compresses several-fold, so the upload was several times what the official client sends for the same turns. A chat-completions body now goes gzipped with Content-Encoding: gzip on both builds; unanswered() weighs the gzipped size against the front door's 2 MiB. Claude's Messages route goes as it came (not tried gzipped live). Run (on mote, HOME=$(mktemp -d) bun test in packages/workbuddy): 197 pass, 0 fail. bun scripts/check.mjs: exit 0. Fakes that parse the sent body gunzip it (testdata/unz.mjs); reset.test.mjs's 2 MiB bodies are random base64 so they stay over 2 MiB on the wire. Live (www.workbuddy.ai, a real account in a sandbox HOME): with 0.1.43 the default sent reasoning_effort high gzipped and thought (34 and 51 reasoning tokens), none stayed 0, low and high as before, all 200. A gzipped chat answered 200 the same as a plain one. Broken by hand: origin/main's index.mjs with the new default-effort.test.mjs: 5 of 8 red (default effort, failed-read reuse, both gzip tests, defaultEffortOf); the 3 that pass guard what must not change (named efforts, models without a default, Messages). Not tried: a live chat on the China build (copilot.tencent.com answered 401 to every token available here, its /v3/config read fine); Messages gzipped; the reporters' own OpenCode sessions end to end.
152 lines
7.7 KiB
JavaScript
152 lines
7.7 KiB
JavaScript
// troilus1011 on X: WorkBuddy's DeepSeek in OpenCode thought at low and
|
|
// high, never at the default. OpenCode's default variant names no effort,
|
|
// and WorkBuddy doesn't think without one; WorkBuddy's own client sends the
|
|
// config's reasoning.defaultEffort (configureThinkingSettings). The config
|
|
// below is the China build's own for deepseek-v4.1-flash (2026-10-28), with
|
|
// models beside it that take no effort or another default.
|
|
//
|
|
// runmiNeverstop on X: 2.89 GB up to copilot.tencent.com. WorkBuddy's own
|
|
// client gzips a model request's body (GzipRequestProcessor); the plugin
|
|
// sent it as plain JSON. Every fetch here is a fake.
|
|
import { afterEach, expect, test } from "bun:test"
|
|
import { WorkBuddyAuthPlugin, WorkBuddyAIAuthPlugin, _internal } from "./index.mjs"
|
|
import { unz } from "./testdata/unz.mjs"
|
|
|
|
const real = globalThis.fetch
|
|
afterEach(() => (globalThis.fetch = real))
|
|
|
|
const CONFIG = {
|
|
code: 0,
|
|
data: {
|
|
agents: [{ name: "cli", models: ["deepseek-v4.1-flash", "glm-5.2", "auto", "odd-default", "claude-opus-5.5"] }],
|
|
models: [
|
|
{ id: "deepseek-v4.1-flash", name: "Deepseek-V4.1-Flash", supportsReasoning: true, onlyReasoning: true,
|
|
reasoning: { canDisableThinking: true, defaultEffort: "high", summary: "auto", supportedEfforts: ["low", "high", "max"] } },
|
|
{ id: "glm-5.2", name: "GLM-5.2", supportsReasoning: true,
|
|
reasoning: { canDisableThinking: true, defaultEffort: "xhigh", summary: "auto", supportedEfforts: ["high", "xhigh"] } },
|
|
{ id: "auto", name: "Auto" },
|
|
// a default its own levels don't hold: WorkBuddy's client clamps it,
|
|
// the plugin leaves it to the server
|
|
{ id: "odd-default", name: "Odd", supportsReasoning: true, reasoning: { defaultEffort: "medium", supportedEfforts: ["low", "high"] } },
|
|
{ id: "claude-opus-5.5", name: "Claude-Opus-5.5", supportsReasoning: true, reasoning: { defaultEffort: "high", supportedEfforts: ["low", "high", "xhigh"] } },
|
|
],
|
|
},
|
|
}
|
|
|
|
const OK = () => new Response("data: [DONE]\n\n", { headers: { "content-type": "text/event-stream" } })
|
|
|
|
// serve answers /v3/config with config() and anything else with OK, and
|
|
// keeps each request: its URL, headers, the body on the wire and as text
|
|
function serve(config = () => Response.json(CONFIG)) {
|
|
const sent = []
|
|
globalThis.fetch = async (url, init) => {
|
|
const u = String(url)
|
|
sent.push({ url: u, headers: new Headers(init?.headers), wire: init?.body, text: unz(init?.body) })
|
|
if (u.endsWith("/v3/config")) return config()
|
|
return OK()
|
|
}
|
|
return sent
|
|
}
|
|
|
|
const AUTH = { type: "oauth", access: "tok", refresh: "r", uid: "u1", expires: Date.now() + 3600_000 }
|
|
const CN_CHAT = "https://copilot.tencent.com/v2/chat/completions"
|
|
const chatsOf = (sent) => sent.filter((s) => !s.url.endsWith("/v3/config"))
|
|
|
|
async function loader(plugin = WorkBuddyAuthPlugin) {
|
|
const h = await plugin({ client: {} })
|
|
return h.auth.loader(async () => AUTH)
|
|
}
|
|
|
|
const ask = (opts, model, extra = {}, url = CN_CHAT) =>
|
|
opts.fetch(url, { method: "POST", body: JSON.stringify({ model, stream: true, messages: [{ role: "user", content: "hi" }], ...extra }) })
|
|
|
|
test("a DeepSeek chat that names no effort goes at the config's default, as WorkBuddy's client asks it", async () => {
|
|
const sent = serve()
|
|
const opts = await loader()
|
|
expect((await ask(opts, "deepseek-v4.1-flash")).status).toBe(200)
|
|
const [c] = chatsOf(sent)
|
|
expect(JSON.parse(c.text).reasoning_effort).toBe("high")
|
|
// another model's default is its own
|
|
await ask(opts, "glm-5.2")
|
|
expect(JSON.parse(chatsOf(sent)[1].text).reasoning_effort).toBe("xhigh")
|
|
// the list was read once for both
|
|
expect(sent.filter((s) => s.url.endsWith("/v3/config"))).toHaveLength(1)
|
|
})
|
|
|
|
test("an effort the client named goes as it came, none too, and the list isn't read for it", async () => {
|
|
const sent = serve()
|
|
const opts = await loader()
|
|
for (const e of ["none", "low", "max"]) await ask(opts, "deepseek-v4.1-flash", { reasoning_effort: e })
|
|
await ask(opts, "deepseek-v4.1-flash", { reasoning: { effort: "low" } })
|
|
const chats = chatsOf(sent).map((c) => JSON.parse(c.text))
|
|
expect(chats.map((c) => c.reasoning_effort)).toEqual(["none", "low", "max", undefined])
|
|
expect(chats[3].reasoning).toEqual({ effort: "low" })
|
|
expect(sent.filter((s) => s.url.endsWith("/v3/config"))).toHaveLength(0)
|
|
})
|
|
|
|
test("a model that takes no effort, or whose default its levels don't hold, gets none", async () => {
|
|
const sent = serve()
|
|
const opts = await loader()
|
|
await ask(opts, "auto")
|
|
await ask(opts, "odd-default")
|
|
await ask(opts, "not-listed")
|
|
for (const c of chatsOf(sent)) expect(JSON.parse(c.text).reasoning_effort).toBeUndefined()
|
|
})
|
|
|
|
test("a config that can't be read leaves the chat as it came, and is tried again a minute later, not on each chat", async () => {
|
|
const sent = serve(() => new Response("down", { status: 502 }))
|
|
const opts = await loader()
|
|
expect((await ask(opts, "deepseek-v4.1-flash")).status).toBe(200)
|
|
expect((await ask(opts, "deepseek-v4.1-flash")).status).toBe(200)
|
|
for (const c of chatsOf(sent)) expect(JSON.parse(c.text).reasoning_effort).toBeUndefined()
|
|
expect(sent.filter((s) => s.url.endsWith("/v3/config"))).toHaveLength(1)
|
|
})
|
|
|
|
test("a chat goes gzipped, as WorkBuddy's client sends it, on both builds", async () => {
|
|
for (const [plugin, url] of [
|
|
[WorkBuddyAuthPlugin, CN_CHAT],
|
|
[WorkBuddyAIAuthPlugin, "https://www.workbuddy.ai/v2/chat/completions"],
|
|
]) {
|
|
const sent = serve()
|
|
const opts = await loader(plugin)
|
|
const history = Array.from({ length: 200 }, (_, i) => ({ role: i % 2 ? "assistant" : "user", content: `step ${i}: read src/file${i}.ts and run the tests again` }))
|
|
const body = JSON.stringify({ model: "deepseek-v4.1-flash", reasoning_effort: "high", stream: true, messages: [{ role: "system", content: "You are an agent." }, ...history] })
|
|
await opts.fetch(url, { method: "POST", body })
|
|
const [c] = chatsOf(sent)
|
|
expect(c.url).toBe(url)
|
|
expect(c.headers.get("content-encoding")).toBe("gzip")
|
|
expect(c.headers.has("content-length")).toBe(false)
|
|
expect(typeof c.wire).not.toBe("string")
|
|
expect(JSON.parse(c.text)).toEqual(JSON.parse(body))
|
|
expect(c.wire.byteLength * 5).toBeLessThan(Buffer.byteLength(body))
|
|
}
|
|
})
|
|
|
|
test("a body handed over as bytes goes gzipped too", async () => {
|
|
const sent = serve()
|
|
const opts = await loader()
|
|
const body = JSON.stringify({ model: "glm-5.2", reasoning_effort: "high", stream: true, messages: [{ role: "system", content: "You are an agent." }, { role: "user", content: "hi" }] })
|
|
await opts.fetch(CN_CHAT, { method: "POST", body: new TextEncoder().encode(body) })
|
|
const [c] = chatsOf(sent)
|
|
expect(c.headers.get("content-encoding")).toBe("gzip")
|
|
expect(JSON.parse(c.text)).toEqual(JSON.parse(body))
|
|
})
|
|
|
|
test("a Claude request on Messages goes as it came: neither gzipped nor given an effort", async () => {
|
|
const sent = serve()
|
|
const opts = await loader()
|
|
const body = JSON.stringify({ model: "claude-opus-5.5", max_tokens: 100, stream: true, messages: [{ role: "user", content: "hi" }] })
|
|
await opts.fetch("https://copilot.tencent.com/v1/messages", { method: "POST", body })
|
|
const [c] = chatsOf(sent)
|
|
expect(c.headers.has("content-encoding")).toBe(false)
|
|
expect(c.wire).toBe(body)
|
|
})
|
|
|
|
test("defaultEffortOf reads defaultEffort, else effort, held to the model's levels", () => {
|
|
const { defaultEffortOf } = _internal
|
|
expect(defaultEffortOf({ reasoning: { defaultEffort: "high" } }, ["low", "high"])).toBe("high")
|
|
expect(defaultEffortOf({ reasoning: { effort: "medium" } }, ["low", "medium", "high", "max"])).toBe("medium")
|
|
expect(defaultEffortOf({ reasoning: { defaultEffort: "medium" } }, ["low", "high"])).toBeUndefined()
|
|
expect(defaultEffortOf({}, ["low"])).toBeUndefined()
|
|
})
|