workbuddy 0.1.39: an earlier turn's reasoning_content goes as reasoning, as WorkBuddy's own client sends it
uk.jent on Discord: Grok Build's chat.completions history lost its thinking on WorkBuddy. Grok Build 1.0.67 sends an earlier assistant turn's thinking as reasoning_content; magpie and this plugin pass it on byte for byte, and WorkBuddy drops it. WorkBuddy's own client (CodeBuddy's agents converter, applyPendingReasoning) sets `reasoning` on the assistant message and skips its reasoning_content backfill for WorkBuddy's own hosts. The chat path now does the same: reasoning_content, or reasoning_details' text, becomes `reasoning` (one the client set is kept) and the original fields are left out. Nothing is folded into content as <think>, since WorkBuddy's client doesn't send it that way. The Messages route (Claude on the China build) is unchanged. Run: packages/workbuddy `bun test` with a temp HOME (183 pass); `bun scripts/check.mjs` all green. Live on www.workbuddy.ai (a real WorkBuddy AI account, access token only, refresh left out), a codeword in the earlier turn's thinking, asked for after the tool result: before, reasoning_content reached no model (0 of ~15 across kimi-k2.6, kimi-k3, glm-5.3, deepseek-v4.1-flash, minimax-m3) while `reasoning` did on kimi-k2.6 and minimax-m3; through 0.1.39 a reasoning_content history reached kimi-k2.6 2 of 8 and minimax-m3 4 of 9, with the no-thinking control 0 every time. glm-5.3, kimi-k3 and deepseek-v4.1-flash never quoted it in either spelling. Broken by hand: index.mjs from origin/main: reasoning.test.mjs 4 of 4 red; with the asReasoning call commented out, its two end-to-end tests red. Not tried: the China build (copilot.tencent.com; its desktop sign-in answered 401), and Grok Build end to end through WorkBuddy (its request was captured against a fake server). The "thinking loop" the report names wasn't reproduced; the plugin doesn't touch the reply stream.
This commit is contained in:
@@ -164,8 +164,12 @@ refusal rests the account.
|
||||
|
||||
The loader also translates OpenAI-compatible request spellings WorkBuddy
|
||||
doesn't take: `max_completion_tokens` becomes `max_tokens`, `developer`
|
||||
messages become `system`, and an object `tool_choice` becomes WorkBuddy's
|
||||
string form.
|
||||
messages become `system`, an object `tool_choice` becomes WorkBuddy's
|
||||
string form, and an earlier assistant turn's `reasoning_content` (or
|
||||
`reasoning_details` text) goes as `reasoning`, the field WorkBuddy's own
|
||||
client sends. WorkBuddy drops `reasoning_content`, so a client such as Grok
|
||||
Build that sends it lost its earlier thinking; nothing is folded into the
|
||||
message's content.
|
||||
|
||||
A chat's tools are given shapes WorkBuddy's models take. Without them
|
||||
WorkBuddy AI answers 400 "Invalid request parameters" (11133), DeepSeek's
|
||||
|
||||
@@ -705,6 +705,36 @@ function unflag(messages) {
|
||||
// OpenAI-compatible client normally uses max_completion_tokens and may call a
|
||||
// reasoning prompt developer; WorkBuddy's endpoint takes max_tokens and
|
||||
// system instead.
|
||||
// An earlier turn's thinking goes back as `reasoning`, the field WorkBuddy's
|
||||
// own client (CodeBuddy's agents converter) sets on an assistant message.
|
||||
// WorkBuddy drops `reasoning_content`, which Grok Build, DeepSeek-style
|
||||
// clients and magpie's own replies use: measured 2026-10-27 on
|
||||
// www.workbuddy.ai, a codeword in reasoning_content reached none of
|
||||
// kimi-k2.6, kimi-k3, glm-5.3, deepseek-v4.1-flash and minimax-m3, while
|
||||
// the same words as `reasoning` reached kimi-k2.6 and minimax-m3.
|
||||
// OpenRouter-style reasoning_details are read for their text the same way.
|
||||
function reasoningOf(m) {
|
||||
if (typeof m.reasoning_content === "string" && m.reasoning_content) return m.reasoning_content
|
||||
if (Array.isArray(m.reasoning_details)) {
|
||||
const text = m.reasoning_details.map((d) => (typeof d?.text === "string" ? d.text : typeof d?.summary === "string" ? d.summary : "")).join("")
|
||||
if (text) return text
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
function asReasoning(messages) {
|
||||
let changed = false
|
||||
for (const m of messages) {
|
||||
if (m?.role !== "assistant" || (m.reasoning_content === undefined && m.reasoning_details === undefined)) continue
|
||||
const text = reasoningOf(m)
|
||||
if (text && !(typeof m.reasoning === "string" && m.reasoning)) m.reasoning = text
|
||||
delete m.reasoning_content
|
||||
delete m.reasoning_details
|
||||
changed = true
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
function withSystem(body) {
|
||||
// a body magpie or OpenCode hands over as bytes is read as the text it is
|
||||
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) body = new TextDecoder().decode(body)
|
||||
@@ -723,6 +753,7 @@ function withSystem(body) {
|
||||
m.role = "system"
|
||||
changed = true
|
||||
}
|
||||
if (asReasoning(b.messages)) changed = true
|
||||
if (b.messages[0]?.role !== "system") {
|
||||
b.messages.unshift({ role: "system", content: "You are a helpful assistant." })
|
||||
changed = true
|
||||
@@ -2492,4 +2523,4 @@ export const WorkBuddyAuthPlugin = makePlugin(SITES.workbuddy)
|
||||
export const WorkBuddyAIAuthPlugin = makePlugin(SITES["workbuddy-ai"])
|
||||
|
||||
// for tests
|
||||
export const _internal = { FREE_ONLY, PRICE_TTL, keyAccount, remoteConfig, cycleOf, typeUnions, systemAsUser, systemKey, DEFAULT_SYSTEM, EDGE_READS, fitShape, replyAfterTools, AFTER_TOOLS_REFUSED, enterpriseUsageOf, notDesktop, textOnly, runsOutOf, packagesOf, endOf, enterpriseHeaders, enterpriseOf, liveModels, browserSignIn, withSystem, normalizeToolChoice, fitTools, fitted, renamed, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, RESTRICTED_HINT, EXHAUSTED_HINT, freeCredits, creditsOf, priceOf, fresh, SITES, renewing, renewed, SESSION, attend, turnKey, conversationKey, signatureOf, isMessages, withoutUnsigned, withoutSignedThinking, answeredBefore, nativeOf, modelOf, configModels, API_MESSAGES: NPM_MESSAGES, API_CHAT: NPM }
|
||||
export const _internal = { FREE_ONLY, PRICE_TTL, keyAccount, remoteConfig, cycleOf, typeUnions, systemAsUser, systemKey, DEFAULT_SYSTEM, EDGE_READS, fitShape, replyAfterTools, AFTER_TOOLS_REFUSED, enterpriseUsageOf, notDesktop, textOnly, runsOutOf, packagesOf, endOf, enterpriseHeaders, enterpriseOf, liveModels, browserSignIn, withSystem, asReasoning, normalizeToolChoice, fitTools, fitted, renamed, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, RESTRICTED_HINT, EXHAUSTED_HINT, freeCredits, creditsOf, priceOf, fresh, SITES, renewing, renewed, SESSION, attend, turnKey, conversationKey, signatureOf, isMessages, withoutUnsigned, withoutSignedThinking, answeredBefore, nativeOf, modelOf, configModels, API_MESSAGES: NPM_MESSAGES, API_CHAT: NPM }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-workbuddy-auth",
|
||||
"version": "0.1.38",
|
||||
"version": "0.1.39",
|
||||
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// WorkBuddy drops an assistant message's reasoning_content and reads its own
|
||||
// client's `reasoning` (uk.jent on Discord, 2026-10-27: Grok Build's
|
||||
// chat.completions history lost its thinking on WorkBuddy). The history is
|
||||
// the one Grok Build 1.0.67 sends after a tool call.
|
||||
import { expect, test } from "bun:test"
|
||||
import { WorkBuddyAIAuthPlugin, _internal } from "./index.mjs"
|
||||
|
||||
const { asReasoning } = _internal
|
||||
|
||||
const thought = "The user wants the files. Codeword ZEBRA-42."
|
||||
const history = (assistant) => [
|
||||
{ role: "system", content: "You are Grok." },
|
||||
{ role: "user", content: "List the files here." },
|
||||
{ role: "assistant", content: "", tool_calls: [{ id: "call_1", type: "function", function: { name: "list_files", arguments: "{}" } }], ...assistant },
|
||||
{ role: "tool", tool_call_id: "call_1", content: "a.txt\nb.txt" },
|
||||
{ role: "user", content: "And now?" },
|
||||
]
|
||||
|
||||
async function upstream(messages) {
|
||||
const realFetch = globalThis.fetch
|
||||
const sent = []
|
||||
globalThis.fetch = async (url, init) => {
|
||||
if (String(url).includes("/chat/completions")) sent.push(JSON.parse(init.body))
|
||||
return new Response("data: [DONE]\n\n", { headers: { "content-type": "text/event-stream" } })
|
||||
}
|
||||
try {
|
||||
const hooks = await WorkBuddyAIAuthPlugin({ client: {} })
|
||||
const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: "access", uid: "uid", expires: Date.now() + 3600_000 }))
|
||||
const res = await loader.fetch("https://www.workbuddy.ai/v2/chat/completions", { method: "POST", body: JSON.stringify({ model: "kimi-k2.6", stream: true, messages }) })
|
||||
expect(res.status).toBe(200)
|
||||
} finally {
|
||||
globalThis.fetch = realFetch
|
||||
}
|
||||
expect(sent.length).toBe(1)
|
||||
return sent[0].messages
|
||||
}
|
||||
|
||||
test("an earlier turn's reasoning_content goes as reasoning, as WorkBuddy's own client sends it", async () => {
|
||||
const m = await upstream(history({ reasoning_content: thought, model_id: "kimi-k2.6" }))
|
||||
expect(m[2].reasoning).toBe(thought)
|
||||
expect(m[2].reasoning_content).toBeUndefined()
|
||||
expect(m[2].tool_calls[0].id).toBe("call_1")
|
||||
// nothing is folded into what the model said
|
||||
expect(m[2].content).toBe("")
|
||||
expect(m[4]).toEqual({ role: "user", content: "And now?" })
|
||||
})
|
||||
|
||||
test("reasoning_details' text goes as reasoning too", async () => {
|
||||
const m = await upstream(history({ reasoning_details: [{ type: "reasoning.text", text: "The user wants " }, { type: "reasoning.text", text: "the files." }] }))
|
||||
expect(m[2].reasoning).toBe("The user wants the files.")
|
||||
expect(m[2].reasoning_details).toBeUndefined()
|
||||
})
|
||||
|
||||
test("a reasoning the client set already is kept", () => {
|
||||
const messages = history({ reasoning: "own words", reasoning_content: thought })
|
||||
expect(asReasoning(messages)).toBe(true)
|
||||
expect(messages[2].reasoning).toBe("own words")
|
||||
expect(messages[2].reasoning_content).toBeUndefined()
|
||||
})
|
||||
|
||||
test("a history without reasoning fields is left as sent", () => {
|
||||
const messages = history({ reasoning: "own words" })
|
||||
const before = JSON.stringify(messages)
|
||||
expect(asReasoning(messages)).toBe(false)
|
||||
expect(JSON.stringify(messages)).toBe(before)
|
||||
})
|
||||
Reference in New Issue
Block a user