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.
114 lines
5.5 KiB
JavaScript
114 lines
5.5 KiB
JavaScript
// plugins#461 (jihuayu): a 45 MiB chat was parsed six times on its way to
|
|
// WorkBuddy, once by each step, and written out whole again even when no
|
|
// step changed it. prepared reads it once; what goes out is what the steps
|
|
// one by one made of it.
|
|
import { expect, test } from "bun:test"
|
|
import { WorkBuddyAuthPlugin, _internal } from "./index.mjs"
|
|
import { unz } from "./testdata/unz.mjs"
|
|
|
|
const { prepared, withSystem, fitted, normalizeToolChoice, withoutUnsigned } = _internal
|
|
|
|
const chats = [
|
|
{ model: "deepseek-v4.1-flash", messages: [{ role: "system", content: "Be brief." }, { role: "user", content: "hi" }] },
|
|
{ model: "m", messages: [{ role: "system", content: "s" }, { role: "user", content: "hi" }], tool_choice: "auto", tools: [{ type: "function", function: { name: "read", parameters: { type: "object" } } }] },
|
|
{ model: "m", messages: [{ role: "developer", content: "d" }, { role: "user", content: "x" }], max_completion_tokens: 9 },
|
|
{ model: "m", messages: [{ role: "user", content: "no system" }] },
|
|
{ model: "m", messages: [{ role: "system", content: "You are Claude Code, Anthropic's official CLI for Claude" }, { role: "user", content: "q" }] },
|
|
{ model: "m", messages: [{ role: "system", content: "s" }, { role: "user", content: "q" }, { role: "assistant", content: "a", reasoning_content: "thought" }, { role: "user", content: "q2" }] },
|
|
{ model: "m", messages: [{ role: "system", content: "s" }, { role: "user", content: "run" }], tools: [{ type: "function", function: { name: "fs.read", parameters: { type: "object", properties: { v: { type: ["string", "null"] } } } } }], tool_choice: { type: "function", function: { name: "fs.read" } } },
|
|
{ model: "m", messages: [{ role: "system", content: "s" }, { role: "user", content: "x" }], tools: [{ type: "function", function: { name: "a" } }], tool_choice: "none" },
|
|
{ model: "m", messages: [{ role: "system", content: "s" }, { role: "user", content: "x" }], tool_choice: { type: "required" } },
|
|
{ model: "m", messages: [{ role: "system", content: "s" }, { role: "user", content: "x" }], tool_choice: null },
|
|
{ model: "m", messages: [{ role: "system", content: "s" }, { role: "user", content: "x" }], tool_choice: { type: "other" } },
|
|
{ model: "m", messages: [] },
|
|
{ model: "m" },
|
|
[1, 2],
|
|
"a string",
|
|
42,
|
|
null,
|
|
]
|
|
|
|
const stepByStep = (body) => {
|
|
const fit = fitted(withSystem(body))
|
|
return { body: normalizeToolChoice(fit.body), names: fit.names }
|
|
}
|
|
const sent = (p) => (p.changed ? JSON.stringify(p.chat) : p.body)
|
|
const read = (s) => {
|
|
try {
|
|
return JSON.parse(s)
|
|
} catch {
|
|
return s
|
|
}
|
|
}
|
|
|
|
test("one parse makes what the steps one by one made", () => {
|
|
for (const c of chats) {
|
|
const body = JSON.stringify(c)
|
|
const old = stepByStep(body)
|
|
const p = prepared(body, false)
|
|
expect(read(sent(p))).toEqual(read(old.body))
|
|
expect([...p.names]).toEqual([...old.names])
|
|
}
|
|
for (const body of ["not json", "", "{", new TextEncoder().encode(JSON.stringify(chats[0]))]) {
|
|
const old = stepByStep(body)
|
|
expect(read(sent(prepared(body, false)))).toEqual(read(old.body))
|
|
}
|
|
})
|
|
|
|
test("a chat no step changes goes byte for byte, not written out again", () => {
|
|
// spaced as no JSON.stringify writes it: any rewrite would show
|
|
const body = `{"model": "m", "messages": [{"role": "system", "content": "s"}, {"role": "user", "content": "x"}], "tool_choice": "auto"}`
|
|
const p = prepared(body, false)
|
|
expect(p.changed).toBe(false)
|
|
expect(sent(p)).toBe(body)
|
|
})
|
|
|
|
test("a Messages body is read once too, its unsigned thinking dropped as before", () => {
|
|
const body = JSON.stringify({
|
|
model: "claude",
|
|
system: [{ type: "text", text: "s" }],
|
|
messages: [
|
|
{ role: "user", content: "q" },
|
|
{ role: "assistant", content: [{ type: "thinking", thinking: "t" }, { type: "text", text: "a" }] },
|
|
{ role: "user", content: "q2" },
|
|
],
|
|
})
|
|
expect(read(sent(prepared(body, true)))).toEqual(read(withoutUnsigned(body)))
|
|
const plain = JSON.stringify({ model: "claude", messages: [{ role: "user", content: "q" }] })
|
|
expect(sent(prepared(plain, true))).toBe(plain)
|
|
})
|
|
|
|
test("the loader parses a long chat once", async () => {
|
|
const realFetch = globalThis.fetch
|
|
const realParse = JSON.parse
|
|
let parses = 0
|
|
let out
|
|
JSON.parse = (s, ...a) => {
|
|
if (typeof s === "string" && s.length > 1 << 20) parses++
|
|
return realParse(s, ...a)
|
|
}
|
|
globalThis.fetch = async (_url, init) => {
|
|
out = unz(init.body)
|
|
return new Response('data: {"choices":[{"delta":{"content":"OK"}}]}\n\ndata: [DONE]\n\n', { headers: { "content-type": "text/event-stream" } })
|
|
}
|
|
try {
|
|
const hooks = await WorkBuddyAuthPlugin({ client: { auth: { set: async () => {} } }, magpie: { option: () => false } })
|
|
const auth = { type: "oauth", access: "test-only", refresh: "test-only", uid: "u", expires: Date.now() + 3600000 }
|
|
const loader = await hooks.auth.loader(async () => auth)
|
|
const body = JSON.stringify({
|
|
model: "deepseek-v4.1-flash",
|
|
stream: true,
|
|
tool_choice: "auto",
|
|
messages: [{ role: "system", content: "s" }, { role: "user", content: "x".repeat(2 << 20) }],
|
|
tools: [{ type: "function", function: { name: "test.tool.name", parameters: { type: "object" } } }],
|
|
})
|
|
const res = await loader.fetch("https://synthetic.invalid/v2/chat/completions", { method: "POST", body, headers: { "content-type": "application/json" } })
|
|
await res.text()
|
|
expect(parses).toBe(1)
|
|
expect(read(out)).toEqual(read(stepByStep(body).body))
|
|
} finally {
|
|
globalThis.fetch = realFetch
|
|
JSON.parse = realParse
|
|
}
|
|
})
|