From b2fe48ea2e8bf6c5beda207e169f2eecdc308b5c Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 28 Oct 2026 03:20:46 +0800 Subject: [PATCH] workbuddy 0.1.40: chats carry the current desktop client's headers WorkBuddy accounts are being restricted, and a report says WorkBuddy now checks request-header fingerprints. Diffed the plugin's chat request against each build's current desktop app, read (never run) from the update feeds on 2026-10-28: - China: WorkBuddy 5.9.3.42398134 (copilot.tencent.com/v2/update), bundled @genie/agent-cli 2.165.0. - WorkBuddy AI: 5.8.4.41366630 (www.workbuddy.ai/v2/update), CLI 2.161.0. The chat is the CLI's OpenAI client (openai 6.25.0) through axiosToFetchAdapter, with UserAgentHttpInterceptor and the desktop's CLIENT_INFO_* env (sidecar-manager getCachedBaseEnv). What differed, and now matches: - User-Agent: was WorkBuddy/5.5.6; the client sends "WorkBuddy/ / CLI/": WorkBuddy/5.9.3 WorkBuddy/5.9.3 CLI/2.165.0 (China), WorkBuddy/5.8.4 workbuddy-ai/5.8.4 CLI/2.161.0 (AI). The /v3/config models call (was CLI/2.0.0 WorkBuddy/5.5.6) takes the same one, as the CLI's CloudProductProvider sends it through the same interceptor. - X-IDE-Version: was 5.5.6; now the app's version. - X-Agent-Type: main was sent on WorkBuddy AI only; the adapter sets it on every model call on both builds. - X-Agent-Runtime: local-agent, new in 5.9 (the desktop's local transport puts agentRuntime local-agent in the prompt meta); China build only, 5.8.4 has no such header. - Accept: application/json and the OpenAI SDK's X-Stainless-* (Lang js, Package-Version 6.25.0, OS/Arch of this machine, Runtime node, Runtime-Version v22.21.1 = Electron 37.10.3's Node, Retry-Count 0, Timeout 1200); the adapter strips them only in its skip-auth mode. - The desktop's own calls (billing, plugin API) send WorkBuddy/; they now send the current app version instead of 5.5.6. Not matched: X-Device-Token (TuringShield native SDK, sent since at least 5.6.2), traceparent (only while server-side tracing is enabled), and transport-level differences (Bun's fetch vs axios on Node: header order, Accept-Encoding). Run: HOME=$(mktemp -d) bun test packages/workbuddy: 184 pass, 0 fail. With the old index.mjs the 4 changed tests fail (UA, IDE version, config UA, the new per-build header test). Not tried: a real account's chat or /v3/config with the new User-Agent (unauthenticated /v3/config answers the same for old and new). No text added names magpie or WorkBuddy's limits. --- packages/workbuddy/README.md | 16 +++++- packages/workbuddy/apikey.test.mjs | 2 + packages/workbuddy/conversation.test.mjs | 33 +++++++++++- packages/workbuddy/index.mjs | 68 +++++++++++++++++++++--- packages/workbuddy/package.json | 2 +- packages/workbuddy/usage.test.mjs | 2 +- 6 files changed, 109 insertions(+), 14 deletions(-) diff --git a/packages/workbuddy/README.md b/packages/workbuddy/README.md index e9c3ad9..28e1099 100644 --- a/packages/workbuddy/README.md +++ b/packages/workbuddy/README.md @@ -124,7 +124,11 @@ estimate. Each chat carries WorkBuddy's headers: - `Authorization`, `X-User-Id`, `X-Domain`, `X-Product: SaaS`, `X-IDE-Type: WorkBuddy`; -- `User-Agent: WorkBuddy/5.5.6`. Without it, WorkBuddy answers error 10085; +- the desktop CLI's `User-Agent`, `WorkBuddy/ / CLI/`: + `WorkBuddy/5.9.3 WorkBuddy/5.9.3 CLI/2.165.0` on the China build and + `WorkBuddy/5.8.4 workbuddy-ai/5.8.4 CLI/2.161.0` on WorkBuddy AI, each + build's current app on 2026-10-28; `X-IDE-Version` is the app's version. + A User-Agent not starting `WorkBuddy/` is answered error 10085; - the client's, which WorkBuddy's usage list shows as the client that asked (使用端): `X-Agent-Purpose: conversation`, `X-IDE-Name: WorkBuddy`, `X-IDE-Version`, `X-Agent-Intent: craft`, `X-Requested-With`. Both builds @@ -139,7 +143,15 @@ Each chat carries WorkBuddy's headers: else the chat's first user message; nothing is made up when neither names one, a made-up conversation of the request's own being what splits one conversation into many in the usage detail; -- WorkBuddy AI also takes `X-Agent-Type: main`. +- what the CLI adds to a model request alone: `X-Agent-Type: main` on both + builds, `X-Agent-Runtime: local-agent` on the China build (new in 5.9), + `Accept: application/json`, and the `X-Stainless-*` headers of the OpenAI + SDK it sends through (openai 6.25.0 on Electron 37's Node v22.21.1, a + 1200s timeout, no retries). + +Not sent: `X-Device-Token`, which the desktop app gets from Tencent's +native device SDK before each prompt, and a `traceparent`, which the CLI +adds only while its server-side tracing is on. A chat that doesn't open with a system message is given WorkBuddy's default one, as the app does. diff --git a/packages/workbuddy/apikey.test.mjs b/packages/workbuddy/apikey.test.mjs index 7544804..1c10414 100644 --- a/packages/workbuddy/apikey.test.mjs +++ b/packages/workbuddy/apikey.test.mjs @@ -119,6 +119,8 @@ test("models: a ck_ key asks /v3/config with the key's headers, another key asks expect(sent[0].url).toBe("https://copilot.tencent.com/v3/config") expect(sent[0].headers.get("x-api-key")).toBe(KEY) expect(sent[0].headers.get("authorization")).toBe("Bearer " + KEY) + // the CLI asks it with its own User-Agent (CLI/ in it picks the cli list) + expect(sent[0].headers.get("user-agent")).toBe("WorkBuddy/5.9.3 WorkBuddy/5.9.3 CLI/2.165.0") expect(Object.keys(got)).toEqual(["glm-9"]) const other = await hooks.provider.models(provider, { auth: { type: "api", key: "sk-something-else" } }) diff --git a/packages/workbuddy/conversation.test.mjs b/packages/workbuddy/conversation.test.mjs index 0e1bae4..257557f 100644 --- a/packages/workbuddy/conversation.test.mjs +++ b/packages/workbuddy/conversation.test.mjs @@ -116,7 +116,37 @@ test("WorkBuddy AI takes the ids too, with its client's headers", async () => { expect(turn(ai)).toMatch(HEX32) expect(conv(ai)).toMatch(HEX32) expect(ai.get("x-ide-name")).toBe("WorkBuddy") - expect(ai.get("user-agent")).toBe("WorkBuddy/5.5.6") + expect(ai.get("user-agent")).toBe("WorkBuddy/5.8.4 workbuddy-ai/5.8.4 CLI/2.161.0") +}) + +// What WorkBuddy's desktop CLI sends with a chat, read from each build's +// current app (China 5.9.3 with CLI 2.165.0, WorkBuddy AI 5.8.4 with CLI +// 2.161.0): UserAgentHttpInterceptor's User-Agent, the app's version as +// the IDE's, X-Agent-Type on both builds, 5.9's X-Agent-Runtime, and the +// OpenAI SDK's headers its fetch passes on. +test("each build's chat carries its desktop client's headers", async () => { + const sdk = { + accept: "application/json", + "x-agent-type": "main", + "x-stainless-lang": "js", + "x-stainless-package-version": "6.25.0", + "x-stainless-runtime": "node", + "x-stainless-runtime-version": "v22.21.1", + "x-stainless-retry-count": "0", + "x-stainless-timeout": "1200", + } + const want = { + workbuddy: [WorkBuddyAuthPlugin, { ...sdk, "user-agent": "WorkBuddy/5.9.3 WorkBuddy/5.9.3 CLI/2.165.0", "x-ide-version": "5.9.3", "x-agent-runtime": "local-agent" }], + "workbuddy-ai": [WorkBuddyAIAuthPlugin, { ...sdk, "user-agent": "WorkBuddy/5.8.4 workbuddy-ai/5.8.4 CLI/2.161.0", "x-ide-version": "5.8.4", "x-agent-runtime": null }], + } + for (const [provider, [plugin, heads]] of Object.entries(want)) { + const h = await ask(send("hi"), { provider, plugin, headers: { "x-agent-runtime": "cloud-agent" } }) + for (const [name, v] of Object.entries(heads)) expect([provider, name, h.get(name)]).toEqual([provider, name, v]) + expect(h.get("x-stainless-os")).toMatch(/^(MacOS|Windows|Linux|FreeBSD|OpenBSD|Android|Other:.+)$/) + expect(h.get("x-stainless-arch")).toMatch(/^(x64|arm64|arm|x32|other:.+)$/) + // nothing in what is sent names magpie or a tool other than WorkBuddy's + for (const [k, v] of h) expect([k, v.toLowerCase()].join(" ")).not.toMatch(/magpie|opencode/) + } }) test("both builds carry what the usage list shows as the client (使用端)", async () => { @@ -126,7 +156,6 @@ test("both builds carry what the usage list shows as the client (使用端)", as "x-agent-purpose": "conversation", "x-ide-name": "WorkBuddy", "x-ide-type": "WorkBuddy", - "x-ide-version": "5.5.6", "x-product": "SaaS", "x-agent-intent": "craft", "x-requested-with": "XMLHttpRequest", diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index 2fa3e9c..797083e 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -6,7 +6,8 @@ // the token as WorkBuddy's desktop app does) or is taken from WorkBuddy // desktop's own sign-in. Its chats are chat completions at /v2, // streamed only, with WorkBuddy's headers: a request whose User-Agent isn't -// WorkBuddy/ is refused (error 10085). +// WorkBuddy/ is refused (error 10085). Each build's headers are +// those of its current desktop app (see SITES' app, cli and appName). import { createHash, randomBytes } from "node:crypto" import { readFileSync } from "node:fs" @@ -14,7 +15,6 @@ import { homedir } from "node:os" import { join } from "node:path" const APP_VERSION = "2.0.0" // the version WorkBuddy's sign-in page is opened with -const UA_VERSION = "5.5.6" // WorkBuddy/ is the User-Agent the API takes const POLL_MS = 1000 const SIGN_IN_MS = 5 * 60 * 1000 const EARLY_MS = 60 * 1000 // a token this close to its end is refreshed before a request @@ -67,6 +67,16 @@ const SITES = { authID: "workbuddy-desktop", platform: "workbuddy", ai: false, + // the desktop app the requests are WorkBuddy's own client's of: its + // version, its bundled CLI's (@genie/agent-cli), and the CLI's + // product.json applicationName. Read from WorkBuddy 5.9.3.42398134, + // the update feed's current build on 2026-10-28. + app: "5.9.3", + cli: "2.165.0", + appName: "WorkBuddy", + // 5.9's CLI says on each chat where the agent runs; the desktop's own + // is "local-agent" (X-Agent-Runtime, absent in 5.8) + runtime: "local-agent", // where this build's API keys are made (see keyAccount) keys: "https://www.workbuddy.cn/profile/keys", models: CN_MODELS, @@ -81,6 +91,11 @@ const SITES = { authID: "workbuddy-desktop-ai", platform: "workbuddy-ai", ai: true, + // WorkBuddy AI 5.8.4.41366630, its update feed's current build on + // 2026-10-28 (see the China build's) + app: "5.8.4", + cli: "2.161.0", + appName: "workbuddy-ai", keys: "https://www.workbuddy.ai/profile/keys", models: AI_MODELS, // models whose images WorkBuddy AI drops though its config says they @@ -155,7 +170,7 @@ async function call(site, method, path, headers = {}, body) { headers: { "Content-Type": "application/json", Accept: "application/json", - "User-Agent": "WorkBuddy/" + UA_VERSION, + "User-Agent": "WorkBuddy/" + site.app, ...headers, }, body: body === undefined ? undefined : JSON.stringify(body), @@ -312,15 +327,51 @@ function sign(site, a, headers) { } headers.set("X-Product", "SaaS") headers.set("X-IDE-Type", "WorkBuddy") - headers.set("User-Agent", "WorkBuddy/" + UA_VERSION) + headers.set("User-Agent", cliAgent(site)) headers.set("X-Requested-With", "XMLHttpRequest") headers.set("X-Agent-Intent", "craft") headers.set("X-Agent-Purpose", "conversation") headers.set("X-IDE-Name", "WorkBuddy") - headers.set("X-IDE-Version", UA_VERSION) + headers.set("X-IDE-Version", site.app) for (const [k, v] of Object.entries(enterpriseHeaders(a))) headers.set(k, v) - if (!site.ai) return +} + +// cliAgent is the User-Agent WorkBuddy's desktop CLI sends its API calls +// (a chat, the product config) with: UserAgentHttpInterceptor's +// buildUserAgent puts the platform (CLIENT_INFO_PLATFORM "WorkBuddy", at +// the app's version) first, then the CLI's applicationName at the same +// version, then CLIENT_INFO_USER_AGENT_EXTENSION, "CLI/". +function cliAgent(site) { + return `WorkBuddy/${site.app} ${site.appName}/${site.app} CLI/${site.cli}` +} + +// OPENAI_SDK and NODE are what the CLI's chats go out through: the OpenAI +// SDK it bundles (openai 6.25.0) and the Node its Electron runs it on +// (Electron 37.10.3, ELECTRON_RUN_AS_NODE). +const OPENAI_SDK = "6.25.0" +const NODE = "v22.21.1" +const SDK_OS = { darwin: "MacOS", win32: "Windows", linux: "Linux", freebsd: "FreeBSD", openbsd: "OpenBSD", android: "Android" } +const SDK_ARCH = { x64: "x64", arm64: "arm64", arm: "arm", ia32: "x32", x32: "x32" } + +// chatHeaders sets on a chat what WorkBuddy's CLI adds to its model +// requests alone (axiosToFetchAdapter, both builds): the agent type +// (resolveModelCallAgentType, "main" for the conversation's own agent), +// the runtime where a build sends one, and the OpenAI SDK's own headers, +// which the CLI's fetch passes on. Its client has a 1200s timeout and +// no retries of its own. +function chatHeaders(site, headers) { headers.set("X-Agent-Type", "main") + if (site.runtime) headers.set("X-Agent-Runtime", site.runtime) + else headers.delete("X-Agent-Runtime") + headers.set("Accept", "application/json") + headers.set("X-Stainless-Retry-Count", "0") + headers.set("X-Stainless-Timeout", "1200") + headers.set("X-Stainless-Lang", "js") + headers.set("X-Stainless-Package-Version", OPENAI_SDK) + headers.set("X-Stainless-OS", SDK_OS[process.platform] ?? (process.platform ? `Other:${process.platform}` : "Unknown")) + headers.set("X-Stainless-Arch", SDK_ARCH[process.arch] ?? (process.arch ? `other:${process.arch}` : "unknown")) + headers.set("X-Stainless-Runtime", "node") + headers.set("X-Stainless-Runtime-Version", NODE) } // keyAccount is the account an API key (OpenCode's {type: "api", key}) is @@ -1459,7 +1510,7 @@ const statusText = (n) => STATUS_TEXT[n] || `HTTP ${n}` function meterAsked(site, a, path, body = {}, signal = AbortSignal.timeout(20000)) { return fetch(site.endpoint + path, { method: "POST", - headers: { "Content-Type": "application/json", Accept: "application/json", "User-Agent": "WorkBuddy/" + UA_VERSION, + headers: { "Content-Type": "application/json", Accept: "application/json", "User-Agent": "WorkBuddy/" + site.app, Authorization: "Bearer " + a.access, "X-User-Id": a.uid ?? "", "X-Domain": domainOf(site, a), "X-Product": "SaaS", "X-IDE-Type": "WorkBuddy", ...enterpriseHeaders(a) }, body: JSON.stringify(body), @@ -1992,7 +2043,7 @@ function effortsOf(d, site, id) { async function liveModels(site, a) { const headers = new Headers() sign(site, a, headers) - headers.set("User-Agent", `CLI/${APP_VERSION} WorkBuddy/${UA_VERSION}`) + headers.set("User-Agent", cliAgent(site)) headers.set("X-Requested-With", "XMLHttpRequest") headers.set("Accept", "application/json") const res = await fetch(site.endpoint + "/v3/config", { headers, signal: AbortSignal.timeout(15000) }) @@ -2242,6 +2293,7 @@ function makePlugin(site) { } else { body = withoutUnsigned(body) } + chatHeaders(site, headers) attend(headers, body, session) const post = (b) => fetch(req ? req.url : input, { ...init, method: init?.method ?? req?.method, headers, body: b }).catch((e) => unanswered(site, a, b, e, init?.signal)) diff --git a/packages/workbuddy/package.json b/packages/workbuddy/package.json index 83f19a7..990e4eb 100644 --- a/packages/workbuddy/package.json +++ b/packages/workbuddy/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-workbuddy-auth", - "version": "0.1.39", + "version": "0.1.40", "description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)", "type": "module", "main": "./index.mjs", diff --git a/packages/workbuddy/usage.test.mjs b/packages/workbuddy/usage.test.mjs index 3cc08d1..1bb5195 100644 --- a/packages/workbuddy/usage.test.mjs +++ b/packages/workbuddy/usage.test.mjs @@ -57,7 +57,7 @@ test("a paid WorkBuddy account's credits", async () => { expect(c.init.body).toBe("{}") expect(Object.fromEntries(["authorization", "x-user-id", "x-domain", "x-product", "x-ide-type", "user-agent"].map((h) => [h, c.headers.get(h)]))) .toEqual({ authorization: "Bearer two-access", "x-user-id": "u2", "x-domain": "copilot.tencent.com", "x-product": "SaaS", - "x-ide-type": "WorkBuddy", "user-agent": "WorkBuddy/5.5.6" }) + "x-ide-type": "WorkBuddy", "user-agent": "WorkBuddy/5.9.3" }) }) test("a free WorkBuddy AI account, at its own site and domain", async () => {