diff --git a/changelog/unreleased/provider-client-alignment.md b/changelog/unreleased/provider-client-alignment.md new file mode 100644 index 00000000..942e55d9 --- /dev/null +++ b/changelog/unreleased/provider-client-alignment.md @@ -0,0 +1,11 @@ +### English + +- Aligned the in-process client identities with the current official builds: Qoder CLI `1.1.96` (Bun `1.4.4`, global inference on `api2.qoder.sh`), WorkBuddy desktop `5.11.3` CN / `5.11.4` Global with bundled CLI `2.176.0`, Trae CN `3.4.24` (AI extension `2.3.106768`, version code `20260212`), and QwenWork `2.1.0` build `26111906` with COSY `1.1.71`. +- WorkBuddy chat now sends the desktop `5.11.3`/`5.11.4` UA, `X-Client-*` identity and `X-Agent-Runtime: local-agent`, and drops the obsolete `X-Root-Request-ID`/`X-No-*` placeholders. Billing and check-in use the desktop AuthService shape (`axios/1.16.1`, a fresh `X-Request-ID`). +- WorkBuddy CN now uses the official primary entry `www.workbuddy.cn`; the old `copilot.tencent.com` host still resolves, but the client no longer sends there by default. + +### 中文 + +- 将进程内客户端身份对齐到当前官方客户端:Qoder CLI `1.1.96`(Bun `1.4.4`,国际版推理走 `api2.qoder.sh`)、WorkBuddy 国内桌面端 `5.11.3` / 国际版 `5.11.4`(内置 CLI `2.176.0`)、Trae 国内版 `3.4.24`(AI 扩展 `2.3.106768`,版本码 `20260212`)、千问办公 `2.1.0`(构建 `26111906`,COSY `1.1.71`)。 +- WorkBuddy 对话改用桌面端 `5.11.3` / `5.11.4` 的 UA、`X-Client-*` 身份和 `X-Agent-Runtime: local-agent`,去掉过时的 `X-Root-Request-ID` / `X-No-*` 占位头;积分与签到改用桌面 AuthService 的 `axios/1.16.1` 身份和每次新生成的 `X-Request-ID`。 +- WorkBuddy 国内版改用官方主入口 `www.workbuddy.cn`;旧的 `copilot.tencent.com` 仍能解析,但客户端默认不再请求。 diff --git a/docs/ARCHITECTURE_SUMMARY.md b/docs/ARCHITECTURE_SUMMARY.md index 24075d8f..7b15f1e3 100644 --- a/docs/ARCHITECTURE_SUMMARY.md +++ b/docs/ARCHITECTURE_SUMMARY.md @@ -6,7 +6,7 @@ status: canonical read-when: 需要快速理解后端分层、请求路径、运行时和 provider 扩展边界时 summary: 面向贡献者和 AI 的精简架构摘要;详细协议、里程碑和本地运维资料不在本文维护。 related: [AGENTS.md, CONTRIBUTING.md, docs/DESIGN.md, docs/REFACTORING.md, docs/NATIVE_PROTOCOL_REQUESTS.md] -last-updated: 2026-11-23 +last-updated: 2026-11-24 --- # CLI2API 架构摘要 @@ -74,7 +74,7 @@ cmd/server - Qoder Global 和 Qoder CN 是同一个 `provider=qoder`,通过 `region` 区分,不创建新的 provider family。 - 已存 PAT 的 Qoder 账号不启动 child process。旧 `qoder-native-v1` 账号仍使用独立 HOME 和独立 child process,不共享 WASM context;聊天不加载 CLI bundle。不得为每个请求启动完整 CLI agent。 - Qoder 的 CLI / worker 兼容性版本固定在 `worker/src/compat.mjs`,不兼容时应明确失败。 -- Qoder 聊天在 Go 进程内使用 COSY 客户端签名直连网关([`internal/providers/qoder/cosy.go`](../internal/providers/qoder/cosy.go))。协议版本只有一个来源:`cosy.go` 的 `COSYVersion` 取自 [`qauth.CosyVersion`](../internal/providers/qoder/qauth/fingerprint.go),改版本只改那里。支持中国区(`gateway.qoder.com.cn`)和全球区(`api1.qoder.sh`)双端点。 +- Qoder 聊天在 Go 进程内使用 COSY 客户端签名直连网关([`internal/providers/qoder/cosy.go`](../internal/providers/qoder/cosy.go))。协议版本只有一个来源:`cosy.go` 的 `COSYVersion` 取自 [`qauth.CosyVersion`](../internal/providers/qoder/qauth/fingerprint.go),改版本只改那里。支持中国区(`gateway.qoder.com.cn`)和全球区(`api2.qoder.sh`,登录仍走 `api1.qoder.sh`)双端点。 - 所有非 Qoder provider 使用进程内 adapter,不复制 Qoder worker 生命周期,也不得改为每请求启动上游 CLI。 - CodeArts 的 OAuth PKCE 只用于换取短期 STS 凭据,聊天直连 `snap-access.cn-north-4.myhuaweicloud.com` 的 OpenAI 兼容端点。 - provider 负责上游事实映射;executor 负责是否切号、冷却多久和是否 failover。 diff --git a/internal/providers/qoder/cosy.go b/internal/providers/qoder/cosy.go index 8442ffac..c1dc921d 100644 --- a/internal/providers/qoder/cosy.go +++ b/internal/providers/qoder/cosy.go @@ -164,30 +164,30 @@ func (s *Session) Sign(body, rawURL string, now time.Time) (headers map[string]s sum := md5.Sum([]byte(raw)) bearer := "Bearer COSY." + payload + "." + hex.EncodeToString(sum[:]) return map[string]string{ - "Accept": "text/event-stream", - "Authorization": bearer, - "Cache-Control": "no-cache", - "Content-Type": "application/json", - "Cosy-ClientType": "5", - "Cosy-Data-Policy": "agree", - "Cosy-Date": date, - "Cosy-Key": s.cosyKey, - "Cosy-MachineId": s.MachineID, - "Cosy-MachineToken": s.MachineToken, - "Cosy-MachineType": s.MachineType, - "Cosy-User": s.User.uid(), - "Cosy-Version": COSYVersion, - "Login-Version": "v2", - "Accept-Encoding": "identity", - "Cosy-Business-Product": "cli", - "Cosy-Business-Type": "agent", - "Cosy-Scene": "assistant", - "Cosy-Clientip": qauth.CosyClientIP, - // Inference SSE: undici UA + machine OS always; hostname SSE-only + "Accept": "text/event-stream", + "Authorization": bearer, + "Cache-Control": "no-cache", + "Content-Type": "application/json", + "Cosy-ClientType": "5", + "Cosy-Data-Policy": "agree", + "Cosy-Date": date, + "Cosy-Key": s.cosyKey, + "Cosy-MachineId": s.MachineID, + "Cosy-MachineToken": s.MachineToken, + "Cosy-MachineType": s.MachineType, + "Cosy-User": s.User.uid(), + "Cosy-Version": COSYVersion, + "Login-Version": "v2", + "Accept-Encoding": "identity", + "Cosy-Business-Product": "cli", + "Cosy-Business-Type": "agent", + "Cosy-Scene": "assistant", + "Cosy-Clientip": qauth.CosyClientIP, + // Inference SSE: Bun UA + machine OS always; hostname SSE-only // (applyClientFingerprint mirrors this on the bearer path). - "User-Agent": qauth.CosyUserAgent, - "Cosy-MachineOS": qauth.CosyMachineOS, - "Cosy-MachineHostname": qauth.MachineHostname(s.User.uid()), + "User-Agent": qauth.CosyUserAgent, + "Cosy-MachineOS": qauth.CosyMachineOS, + "Cosy-MachineHostname": qauth.MachineHostname(s.User.uid()), }, nil } @@ -251,7 +251,7 @@ func ChatEndpoint(region string) string { if strings.EqualFold(strings.TrimSpace(region), "cn") { return "https://gateway.qoder.com.cn/algo/api/v2/service/pro/sse/agent_chat_generation?FetchKeys=llm_model_result&AgentId=agent_common&Encode=1" } - return "https://api1.qoder.sh/algo/api/v2/service/pro/sse/agent_chat_generation?FetchKeys=llm_model_result&AgentId=agent_common&Encode=1" + return "https://api2.qoder.sh/algo/api/v2/service/pro/sse/agent_chat_generation?FetchKeys=llm_model_result&AgentId=agent_common&Encode=1" } func cosySignPath(rawURL string) string { diff --git a/internal/providers/qoder/cosy_test.go b/internal/providers/qoder/cosy_test.go index 1cc321dc..b85792c4 100644 --- a/internal/providers/qoder/cosy_test.go +++ b/internal/providers/qoder/cosy_test.go @@ -89,7 +89,7 @@ func TestSessionSignIsStableForMachineAndCoversBody(t *testing.T) { if left["Cosy-Version"] != COSYVersion || left["Cosy-User"] != "uid-9" { t.Fatalf("headers = %#v", left) } - if !strings.Contains(endpoint, "api1.qoder.sh") || !strings.Contains(ChatEndpoint("cn"), "gateway.qoder.com.cn") { + if !strings.Contains(endpoint, "api2.qoder.sh") || !strings.Contains(ChatEndpoint("cn"), "gateway.qoder.com.cn") { t.Fatalf("endpoints global=%s cn=%s", endpoint, ChatEndpoint("cn")) } } diff --git a/internal/providers/qoder/direct.go b/internal/providers/qoder/direct.go index 6b2d8872..f5ac340d 100644 --- a/internal/providers/qoder/direct.go +++ b/internal/providers/qoder/direct.go @@ -598,7 +598,7 @@ func BuildPlainChatBody(req translate.ChatRequest, now time.Time) map[string]any "product": "cli", "version": COSYVersion, "type": "agent", // model_key is what the gateway attributes the charge to. Without // it, models that have no model_config fallback (kmodel_latest and - // later) are billed as auto. qodercli 1.1.81 always sends it. + // later) are billed as auto. qodercli 1.1.96 always sends it. "model_key": modelKey, "id": newID(), "name": name, "begin_at": now.UnixMilli(), "stage": "start", }, diff --git a/internal/providers/qoder/qauth/fingerprint.go b/internal/providers/qoder/qauth/fingerprint.go index 13a7a326..c02904a0 100644 --- a/internal/providers/qoder/qauth/fingerprint.go +++ b/internal/providers/qoder/qauth/fingerprint.go @@ -11,20 +11,23 @@ import ( // CosyVersion is the single client/protocol version cli2api presents to // Qoder: the cosy-version header, the bearer payload's cosyVersion, the chat // body's business.version and the OpenAPI User-Agent all derive from it. -// 1.1.81 is the first qodercli that writes catalog-v7 and puts model_key on -// the business block the gateway attributes billing to. The published CLI is -// newer (1.1.89 as of 2026-11-13); this stays on the protocol floor rather -// than tracking every patch, and the desktop check-in version stays separate. -const CosyVersion = "1.1.81" +// 1.1.81 introduced catalog-v7 and model_key on the business block; the +// current official CLI is 1.1.96, whose COSY signing algorithm, headers and +// business endpoints are unchanged from 1.1.89. Keep this aligned with the +// published CLI rather than the older protocol floor. The desktop check-in +// version stays separate because campaign endpoints use their own identity. +const CosyVersion = "1.1.96" // DesktopCosyVersion is the Cosy-Version the official desktop app sends on // campaign / check-in requests (hub desktop 0.4.8). Distinct from CosyVersion // (CLI / reasoning). const DesktopCosyVersion = "0.4.8" -// CosyUserAgent is the User-Agent official qodercli leaves unset so the -// bundled undici fetch supplies its default ("undici"). -const CosyUserAgent = "undici" +// CosyUserAgent is the User-Agent the current official qodercli leaves on +// COSY requests. The CLI runs on Bun and lets its bundled fetch supply +// "Bun/1.4.4"; older npm/Node builds sent "undici". Keep the edition split +// out of this: both regions use the same runtime. +const CosyUserAgent = "Bun/1.4.4" // CosyMachineOS mirrors qodercli's `${arch}_${platform}` value for a Linux // x86_64 host, which is how cli2api is deployed. @@ -44,8 +47,8 @@ func applyCosyBusinessHeaders(h http.Header) { } // UserAgent returns the COSY reasoning User-Agent. Official qodercli does not -// set UA itself; undici supplies "undici". Edition no longer splits the UA. -// Region is accepted for call-site compatibility. +// set UA itself; its Bun fetch supplies "Bun/1.4.4". Edition no longer splits +// the UA. Region is accepted for call-site compatibility. func UserAgent(region *RegionConfig) string { _ = region return CosyUserAgent @@ -79,7 +82,7 @@ func MachineHostname(uid string) string { return "DESKTOP-" + strings.ToUpper(hex.EncodeToString(sum[:])[:7]) } -// applyClientFingerprint sets the undici User-Agent, always sends +// applyClientFingerprint sets the Bun User-Agent, always sends // cosy-machineos, and on inference SSE requests only also sends // cosy-machinehostname. func applyClientFingerprint(h http.Header, rawURL, uid string, inferSSE bool) { diff --git a/internal/providers/qoder/qauth/fingerprint_test.go b/internal/providers/qoder/qauth/fingerprint_test.go index a4e47a85..a9b2aaa5 100644 --- a/internal/providers/qoder/qauth/fingerprint_test.go +++ b/internal/providers/qoder/qauth/fingerprint_test.go @@ -9,22 +9,22 @@ import ( "testing" ) -func TestUserAgentIsUndici(t *testing.T) { +func TestUserAgentIsBun(t *testing.T) { if got := UserAgent(CN); got != CosyUserAgent { t.Fatalf("CN UA=%q want %q", got, CosyUserAgent) } if got := UserAgent(Global); got != CosyUserAgent { t.Fatalf("global UA=%q want %q", got, CosyUserAgent) } - if UserAgentForURL("https://api1.qoder.sh/algo/x") != CosyUserAgent || + if UserAgentForURL("https://api2.qoder.sh/algo/x") != CosyUserAgent || UserAgentForURL("https://gateway.qoder.com.cn/algo/x") != CosyUserAgent { - t.Fatal("URL UA must be undici for both editions") + t.Fatal("URL UA must be the Bun fingerprint for both editions") } if openAPIUserAgentVersion != CosyVersion { t.Fatal("OpenAPI UA version must follow CosyVersion") } - if CosyVersion != "1.1.81" { - t.Fatalf("CosyVersion=%q want 1.1.81", CosyVersion) + if CosyVersion != "1.1.96" { + t.Fatalf("CosyVersion=%q want 1.1.96", CosyVersion) } if DesktopCosyVersion != "0.4.8" { t.Fatalf("DesktopCosyVersion=%q want 0.4.8", DesktopCosyVersion) diff --git a/internal/providers/qoder/qauth/qauth.go b/internal/providers/qoder/qauth/qauth.go index 45c2fd72..1a98f721 100644 --- a/internal/providers/qoder/qauth/qauth.go +++ b/internal/providers/qoder/qauth/qauth.go @@ -67,13 +67,13 @@ var CN = &RegionConfig{ OpenAPIBase: "https://openapi.qoder.com.cn", } -// Global is the international Qoder region (qoder.sh). Chat/status go through -// api1.qoder.sh; quota/billing through openapi.qoder.sh and require a separate -// OpenAPI bearer token. +// Global is the international Qoder region (qoder.sh). Current qodercli +// routes inference through api2.qoder.sh; login stays on api1 and +// quota/billing go through openapi.qoder.sh with a separate OpenAPI bearer. var Global = &RegionConfig{ Name: "global", AuthBase: "https://api1.qoder.sh", - ChatBase: "https://api1.qoder.sh", + ChatBase: "https://api2.qoder.sh", OpenAPIBase: "https://openapi.qoder.sh", NeedsOpenAPIToken: true, } diff --git a/internal/providers/qwenwork/client_test.go b/internal/providers/qwenwork/client_test.go index b3aaadee..48af6397 100644 --- a/internal/providers/qwenwork/client_test.go +++ b/internal/providers/qwenwork/client_test.go @@ -230,7 +230,7 @@ func TestLoginPollPendingThenGrant(t *testing.T) { if r.URL.Query().Get("challenge_method") != "S256" { t.Errorf("challenge_method=%s", r.URL.Query().Get("challenge_method")) } - if r.Header.Get("User-Agent") != "qoderwork/1.0.4" { + if r.Header.Get("User-Agent") != "qoderwork/2.1.0" { t.Errorf("poll UA=%s", r.Header.Get("User-Agent")) } if atomic.LoadInt32(&polls) == 1 { @@ -520,7 +520,7 @@ func verifyCosySignature(t *testing.T, r *http.Request, body []byte, wantPath st if err := json.Unmarshal(decoded, &payload); err != nil { t.Fatalf("payload json: %v", err) } - if payload.CosyVersion != "1.1.18" || payload.Version != "v1" || payload.RequestID == "" || payload.Info == "" { + if payload.CosyVersion != "1.1.71" || payload.Version != "v1" || payload.RequestID == "" || payload.Info == "" { t.Fatalf("payload=%+v", payload) } } @@ -531,10 +531,10 @@ func TestChatSendsSignedRequestWithQwenWorkHeaders(t *testing.T) { client := newTestClient(t, store, chatHandlerFor(t, chatSSE, func(r *http.Request, body []byte) { verifyCosySignature(t, r, body, "/api/v2/service/pro/sse/agent_chat_generation") for header, want := range map[string]string{ - "User-Agent": "qoderwork/1.0.4", - "X-Qwenwork-Version": "1.0.4", - "X-Qwenwork-Release-Version": "1.0.4-26090501", - "X-Qwenwork-Build": "26090501", + "User-Agent": "qoderwork/2.1.0", + "X-Qwenwork-Version": "2.1.0", + "X-Qwenwork-Release-Version": "2.1.0-26111906", + "X-Qwenwork-Build": "26111906", "X-Qwenwork-Platform": "win32", "X-Qwenwork-Arch": "x64", "X-Qwenwork-Channel": "stable", @@ -580,8 +580,8 @@ func TestChatHeadersFollowRegion(t *testing.T) { build string defaultModel string }{ - {region: "global", userAgent: "qoderwork/1.0.4", version: "1.0.4", releaseVersion: "1.0.4-26090501", build: "26090501", defaultModel: "qwork-advanced"}, - {region: "cn", userAgent: "qoderwork/1.0.5", version: "1.0.5", releaseVersion: "1.0.5-26090901", build: "26090901", defaultModel: "pro"}, + {region: "global", userAgent: "qoderwork/2.1.0", version: "2.1.0", releaseVersion: "2.1.0-26111906", build: "26111906", defaultModel: "qwork-advanced"}, + {region: "cn", userAgent: "qoderwork/2.1.0", version: "2.1.0", releaseVersion: "2.1.0-26111906", build: "26111906", defaultModel: "pro"}, } for _, test := range tests { t.Run(test.region, func(t *testing.T) { @@ -785,7 +785,7 @@ func TestModelsParsesQworkKey(t *testing.T) { if r.URL.Path != pathModelList { t.Fatalf("path=%s", r.URL.Path) } - if r.Header.Get("X-Qwenwork-Version") != "1.0.4" { + if r.Header.Get("X-Qwenwork-Version") != "2.1.0" { t.Fatalf("models must carry site headers, got %+v", r.Header) } w.Header().Set("Content-Type", "application/json") diff --git a/internal/providers/qwenwork/credential.go b/internal/providers/qwenwork/credential.go index 9cf86ff5..d5c1ed14 100644 --- a/internal/providers/qwenwork/credential.go +++ b/internal/providers/qwenwork/credential.go @@ -27,7 +27,7 @@ const ( pathChatPath = "/algo/api/v2/service/pro/sse/agent_chat_generation" pathAccountContextPath = "/api/v1/adapter/user/account-context" - cosyVersion = "1.1.18" + cosyVersion = "1.1.71" clientType = "6" businessProduct = "qoder_work" businessType = "agent" @@ -40,8 +40,8 @@ const ( // site is the per-region desktop identity. Both regions share the device flow, // COSY key, paths, and scene; only the gateway, OAuth client, app version, -// and default model differ. Values come from the QwenWork desktop bundles -// (intl 1.0.4, CN 1.0.5). +// and default model differ. Values come from the current QwenWork desktop +// bundles (both editions 2.1.0, build 26111906). type site struct { Region string Gateway string @@ -58,8 +58,8 @@ var sites = map[string]site{ Gateway: "https://gateway.qwenwork.ai", ClientID: "cc65e5fc-05bd-4f5d-a4e8-0df19aa3d75a", RedirectURI: "qwenwork://", - AppVersion: "1.0.4", - Build: "26090501", + AppVersion: "2.1.0", + Build: "26111906", DefaultModel: "qwork-advanced", }, "cn": { @@ -67,8 +67,8 @@ var sites = map[string]site{ Gateway: "https://gateway.qwenwork.cn", ClientID: "e883ade2-e6e3-4d6d-adf7-f92ceff5fdcb", RedirectURI: "qwenwork-cn://", - AppVersion: "1.0.5", - Build: "26090901", + AppVersion: "2.1.0", + Build: "26111906", DefaultModel: "pro", }, } diff --git a/internal/providers/qwenwork/doc.go b/internal/providers/qwenwork/doc.go index 3771a14c..9ec162a8 100644 --- a/internal/providers/qwenwork/doc.go +++ b/internal/providers/qwenwork/doc.go @@ -9,7 +9,7 @@ // the COSY signing approach of internal/providers/qoder. The camelCase import // shape accepts that project's account export. // -// Daily free credits: the desktop bundles (global 1.0.4, CN 1.4.0) call +// Daily free credits: the current desktop bundles (both editions 2.1.0) call // GET /sash/api/v1/me/daily-check-in/status, POST .../claim, and // GET /sash/api/v1/me/{invitationRewards,invitationCode} for the growth card, // gated by the remote `operations/announcement:credits-growth-card` config. diff --git a/internal/providers/registry.go b/internal/providers/registry.go index 5c160f29..7f3c66e2 100644 --- a/internal/providers/registry.go +++ b/internal/providers/registry.go @@ -98,7 +98,7 @@ var Qoder = ProviderDescriptor{ }, Regions: []RegionDescriptor{ { - ID: "global", Label: "Global", ChatBase: "https://api1.qoder.sh", + ID: "global", Label: "Global", ChatBase: "https://api2.qoder.sh", BillingBase: "https://openapi.qoder.sh", AuthBase: "https://qoder.sh", DefaultDomain: "qoder.global", Checkin: &CheckinPolicy{Timezone: "Asia/Shanghai"}, @@ -128,8 +128,8 @@ var WorkBuddy = ProviderDescriptor{ }, Regions: []RegionDescriptor{ { - ID: "cn", Label: "CN", ChatBase: "https://copilot.tencent.com", - BillingBase: "https://www.codebuddy.cn", AuthBase: "https://copilot.tencent.com", + ID: "cn", Label: "CN", ChatBase: "https://www.workbuddy.cn", + BillingBase: "https://www.workbuddy.cn", AuthBase: "https://www.workbuddy.cn", DefaultDomain: "codebuddy.cn", Checkin: &CheckinPolicy{Timezone: "Local"}, }, diff --git a/internal/providers/trae/credential.go b/internal/providers/trae/credential.go index fc3aa9c9..4e708877 100644 --- a/internal/providers/trae/credential.go +++ b/internal/providers/trae/credential.go @@ -22,13 +22,13 @@ const ( ConsoleHost = "https://www.trae.cn" // Login uses the IDE product markers (PKCE authorization-code flow): - // client_id below, auth_from=trae, x_app_version=3.3.62. + // client_id below, auth_from=trae, x_app_version=3.4.24. ClientID = "ono9krqynydwx5" AuthFrom = "trae" AppID = "6eefa01c-1036-4c7e-9ca5-d891f63bfcd8" // IdeVersion is the x_app_version / IDEVersion sent on login + exchange. - IdeVersion = "3.3.62" - IdeVersionCode = "20260811" + IdeVersion = "3.4.24" + IdeVersionCode = "20260212" DeviceBrand = "83DG" OSVersion = "Windows 11 Pro" // Function is the fallback scene for a model that is in no fetched scene @@ -42,7 +42,7 @@ const ( // scene does not list (e.g. kimi-k2.6, kimi-k2.7-code upstream-hide from it). SecondaryScene = "solo_work_lite" DefaultModel = "glm-5.2" - PluginVersion = "2.3.62834" + PluginVersion = "2.3.106768" UserAgent = "Trae/" + IdeVersion QuotaUnit = "entitlement_pack" // LegacyClientID minted the refresh tokens of accounts created before the diff --git a/internal/providers/workbuddy/client_test.go b/internal/providers/workbuddy/client_test.go index d6aa164a..b5038a6e 100644 --- a/internal/providers/workbuddy/client_test.go +++ b/internal/providers/workbuddy/client_test.go @@ -1546,9 +1546,11 @@ func TestChatHeadersReuseConversationIDForOneSession(t *testing.T) { t.Fatalf("one session must reuse its conversation id: %s vs %s", first.Get("X-Conversation-ID"), second.Get("X-Conversation-ID")) } - if first.Get("X-Conversation-Request-ID") != first.Get("X-Conversation-ID") || - first.Get("X-Root-Request-ID") != first.Get("X-Conversation-ID") { - t.Fatalf("turn ids must follow the conversation id: %+v", first) + if first.Get("X-Conversation-Request-ID") != first.Get("X-Conversation-ID") { + t.Fatalf("turn id must follow the conversation id: %+v", first) + } + if first.Get("X-Root-Request-ID") != "" { + t.Fatalf("official chat no longer sends X-Root-Request-ID: %+v", first) } if first.Get("X-Request-ID") == second.Get("X-Request-ID") { t.Fatal("message id must be fresh per request") @@ -1583,15 +1585,16 @@ func dashedUUID(value string) bool { func TestChatHeadersStayRegionSpecificAndIncludeCLIChannel(t *testing.T) { cn := http.Header{} SetChatHeaders(cn, Credential{AccessToken: "at", UID: "u1", Domain: "www.codebuddy.cn"}, "") - if cn.Get("Origin") != "https://www.codebuddy.cn" || cn.Get("Referer") != "https://www.codebuddy.cn/" { - t.Fatalf("CN origin/referer mixed: %+v", cn) + if cn.Get("Origin") != "" || cn.Get("Referer") != "" { + t.Fatalf("official chat must not send origin/referer: %+v", cn) } if got := cn.Get("User-Agent"); got != UserAgent || !strings.Contains(got, CLIVersion) { t.Fatalf("CN UA=%q", got) } - if cn.Get("X-Product") != "SaaS" || cn.Get("X-IDE-Type") != "CLI" || cn.Get("X-IDE-Version") != CLIVersion || + if cn.Get("X-Product") != "SaaS" || cn.Get("X-IDE-Type") != "CLI" || cn.Get("X-IDE-Version") != DesktopVersionCN || cn.Get("X-Agent-Intent") != "craft" || cn.Get("X-Agent-Purpose") != "conversation" || - cn.Get("X-Agent-Runtime") != "other" || cn.Get("X-Agent-Type") != "main" || + cn.Get("X-Agent-Runtime") != "local-agent" || cn.Get("X-Agent-Type") != "main" || + cn.Get("X-Client-Version") != DesktopVersionCN || cn.Get("X-Client-Product") != "WorkBuddy" || cn.Get("X-Private-Data") != "false" || cn.Get("X-Request-ID") == "" { t.Fatalf("CN missing CLI channel headers: %+v", cn) } @@ -1603,7 +1606,7 @@ func TestChatHeadersStayRegionSpecificAndIncludeCLIChannel(t *testing.T) { cn.Get("X-Stainless-Timeout") != "1200" { t.Fatalf("CN missing CLI SDK fingerprint: %+v", cn) } - if cn.Get("X-Request-ID") == cn.Get("X-Conversation-ID") || cn.Get("X-Root-Request-ID") != cn.Get("X-Conversation-Request-ID") { + if cn.Get("X-Request-ID") == cn.Get("X-Conversation-ID") || cn.Get("X-Root-Request-ID") != "" { t.Fatalf("CLI request ids must split message and turn: %+v", cn) } if cn.Get("X-Request-ID") != cn.Get("X-Conversation-Message-ID") { @@ -1621,8 +1624,13 @@ func TestChatHeadersStayRegionSpecificAndIncludeCLIChannel(t *testing.T) { global := http.Header{} SetChatHeaders(global, Credential{AccessToken: "at", UID: "u2", Domain: "www.workbuddy.ai"}, "") - if global.Get("Origin") != "https://www.workbuddy.ai" || global.Get("Referer") != "https://www.workbuddy.ai/" { - t.Fatalf("Global origin/referer mixed: %+v", global) + if global.Get("Origin") != "" || global.Get("Referer") != "" { + t.Fatalf("official Global chat must not send origin/referer: %+v", global) + } + if global.Get("User-Agent") != DesktopUserAgentGlobal || + global.Get("X-Client-Version") != DesktopVersionGlobal || + global.Get("X-Client-Product") != "workbuddy-ai" { + t.Fatalf("Global chat identity=%+v", global) } if global.Get("X-IDE-Type") != "CLI" || global.Get("X-Product") != "SaaS" { t.Fatalf("Global missing CLI channel headers: %+v", global) diff --git a/internal/providers/workbuddy/credential.go b/internal/providers/workbuddy/credential.go index a4deb391..359445fc 100644 --- a/internal/providers/workbuddy/credential.go +++ b/internal/providers/workbuddy/credential.go @@ -17,18 +17,18 @@ const ( DomainCN = "codebuddy.cn" DomainGlobal = "workbuddy.ai" - ChatBaseCN = "https://copilot.tencent.com" + ChatBaseCN = "https://www.workbuddy.cn" ChatBaseGlobal = "https://www.workbuddy.ai" - BillingBaseCN = "https://www.codebuddy.cn" + BillingBaseCN = "https://www.workbuddy.cn" - // UserAgent matches official @tencent-ai/codebuddy-code in the dual-token - // form WorkBuddy chat still accepts. Origin/Referer stay region-specific + // UserAgent is the CN CLI/chat UA the current desktop sends: app token, + // edition token, then the bundled CLI. Origin/Referer stay region-specific // and must never mix CN with Global. All client versions live here. // CLIVersion is the unpacked @tencent-ai/codebuddy-code package version - // (hub identity audit, 2.168.2). Chat sends it as both UA segments and - // X-IDE-Version. - CLIVersion = "2.168.2" - UserAgent = "CLI/" + CLIVersion + " CodeBuddy/" + CLIVersion + // bundled in desktop 5.11.3 / 5.11.4 (2.176.0). The desktop app version, + // not the bundled CLI version, is the UA/version segment. + CLIVersion = "2.176.0" + UserAgent = "WorkBuddy/" + DesktopVersionCN + " WorkBuddy/" + DesktopVersionCN + " CLI/" + DesktopCLIVersionCN // OpenAI Node SDK fingerprint the official CLI attaches to chat. // Values are the SDK 6.25.0 defaults shipped with that CLI package. @@ -45,18 +45,20 @@ const ( // Desktop clients ship separately per edition. Their UA is three-part: // app token, edition token, then the CLI bundled inside that desktop - // build. Those bundled CLIs are not CLIVersion. International desktop - // 5.9.4 embeds 2.165.0; the CN desktop build was not re-verified and - // stays on its previous bundled CLI. - DesktopVersionGlobal = "5.9.4" - DesktopCLIVersionGlobal = "2.165.0" - DesktopVersionCN = "5.8.3" - DesktopCLIVersionCN = "2.161.0" + // build. The current official builds are CN 5.11.3 and Global 5.11.4; + // both bundle CLI 2.176.0. + DesktopVersionGlobal = "5.11.4" + DesktopCLIVersionGlobal = "2.176.0" + DesktopVersionCN = "5.11.3" + DesktopCLIVersionCN = "2.176.0" DesktopUserAgentGlobal = "WorkBuddy/" + DesktopVersionGlobal + " workbuddy-ai/" + DesktopVersionGlobal + " CLI/" + DesktopCLIVersionGlobal - DesktopUserAgentCN = "WorkBuddy/" + DesktopVersionCN + " WorkBuddy/" + DesktopVersionCN + " CLI/" + DesktopCLIVersionCN + DesktopUserAgentCN = UserAgent + // DaemonUserAgentGlobal is the background-service UA: the global edition's + // applicationName is used for both app segments. CN equals UserAgent. + DaemonUserAgentGlobal = "workbuddy-ai/" + DesktopVersionGlobal + " workbuddy-ai/" + DesktopVersionGlobal + " CLI/" + DesktopCLIVersionGlobal // IDEVersion is the CodeBuddy IDE plugin release, kept with the others. - IDEVersion = "2.168.2" + IDEVersion = "2.176.0" // DesktopVersion/DesktopUserAgent are for /v3/config only (Global). Live // A/B showed the same Global account returns the IDE dropdown (incl. @@ -68,7 +70,7 @@ const ( productTypeCLI = "CLI" agentIntentDefault = "craft" agentPurposeConversation = "conversation" - agentRuntimeOther = "other" + agentRuntimeOther = "local-agent" agentTypeMain = "main" pathAuthState = "/v2/plugin/auth/state" @@ -84,8 +86,8 @@ const ( pathModelsCN = "/console/enterprises/personal/models" pathModelsGlobal = "/v2/enterprises/personal/models" pathProductConfig = "/v3/config" - pathUserResource = "/v2/billing/meter/get-user-resource" - pathDailyCheckin = "/v2/billing/meter/daily-checkin" + pathUserResource = "/v2/billing/meter/get-user-resource" + pathDailyCheckin = "/v2/billing/meter/daily-checkin" sessionDeadCode = 12153 sessionDeadText = "Offline user session not found" @@ -244,10 +246,27 @@ func (c Credential) IsGlobal() bool { strings.Contains(domain, "workbuddy") } -// DesktopUserAgentFor returns the desktop UA for the account's edition. +// DesktopUserAgentFor returns the CLI/chat UA for the account's edition. func DesktopUserAgentFor(global bool) string { if global { return DesktopUserAgentGlobal } return DesktopUserAgentCN } + +// DaemonUserAgentFor returns the background-service UA for the account's edition. +func DaemonUserAgentFor(global bool) string { + if global { + return DaemonUserAgentGlobal + } + return UserAgent +} + +// DesktopVersionFor returns the desktop app version sent as X-IDE-Version and +// X-Client-Version. +func DesktopVersionFor(global bool) string { + if global { + return DesktopVersionGlobal + } + return DesktopVersionCN +} diff --git a/internal/providers/workbuddy/headers.go b/internal/providers/workbuddy/headers.go index 832f5a75..b1584e52 100644 --- a/internal/providers/workbuddy/headers.go +++ b/internal/providers/workbuddy/headers.go @@ -20,12 +20,14 @@ func setCommonHeaders(header http.Header, global bool) { header.Set("X-Requested-With", "XMLHttpRequest") header.Set("Origin", origin) header.Set("Referer", origin+"/") - header.Set("User-Agent", UserAgent) + header.Set("User-Agent", DaemonUserAgentFor(global)) + setDesktopClientHeaders(header, global) } // setCLIChannelHeaders is chat-only. Values come from the official // CodeBuddy CLI (craft / CLI / SaaS, plus the OpenAI Node SDK fingerprint -// that package sends). CN and Global share the names; Origin/host stay split. +// that package sends). CN and Global share the names; chat omits +// Origin/Referer, matching the desktop's OpenAI SDK request. // // The official CLI keeps X-Conversation-ID for the life of a session // (its session.id) and mints X-Request-ID fresh per request, equal to @@ -40,7 +42,6 @@ func setCLIChannelHeaders(header http.Header, credential Credential, conversatio header.Set("X-Request-ID", messageID) header.Set("X-Conversation-ID", conversationID) header.Set("X-Conversation-Request-ID", conversationID) - header.Set("X-Root-Request-ID", conversationID) header.Set("X-Conversation-Message-ID", messageID) header.Set("X-Agent-Type", agentTypeMain) header.Set("X-Agent-Intent", agentIntentDefault) @@ -48,7 +49,7 @@ func setCLIChannelHeaders(header http.Header, credential Credential, conversatio header.Set("X-Agent-Runtime", agentRuntimeOther) header.Set("X-IDE-Type", productTypeCLI) header.Set("X-IDE-Name", productTypeCLI) - header.Set("X-IDE-Version", CLIVersion) + header.Set("X-IDE-Version", DesktopVersionFor(credential.IsGlobal())) setCLIStainlessHeaders(header) if value, ok := privateDataHeader(identityCLI, privateDataModeFromEnv(), credential); ok { header.Set("X-Private-Data", value) @@ -176,25 +177,34 @@ func setIdentityHeaders(header http.Header, credential Credential) { setCommonHeaders(header, credential.IsGlobal()) if credential.AccessToken != "" { header.Set("Authorization", "Bearer "+credential.AccessToken) - } else { - header.Set("X-No-Authorization", "1") } if credential.UID != "" { header.Set("X-User-Id", credential.UID) - } else { - header.Set("X-No-User-Id", "1") } if credential.EnterpriseID != "" { header.Set("X-Enterprise-Id", credential.EnterpriseID) - } else { - header.Set("X-No-Enterprise-Id", "1") + header.Set("X-Tenant-Id", credential.EnterpriseID) } if credential.Domain != "" { header.Set("X-Domain", credential.Domain) - } else { - header.Set("X-No-Department-Info", "1") } header.Set("X-Product", "SaaS") + // Official chat always sends the department header, empty when the account + // has no department. Do not invent X-No-* placeholders. + header.Set("X-Department-Info", "") +} + +// setDesktopClientHeaders adds the identity the current desktop builds inject +// on first-party channels (5.11.3 CN / 5.11.4 Global), including chat and +// catalog through the bundled CLI's custom-header provider. +func setDesktopClientHeaders(header http.Header, global bool) { + version, product := DesktopVersionCN, "WorkBuddy" + if global { + version, product = DesktopVersionGlobal, "workbuddy-ai" + } + header.Set("X-Client-Version", version) + header.Set("X-Client-Platform", "macos") + header.Set("X-Client-Product", product) } // SetCatalogHeaders carries access identity for the product-config catalog @@ -217,6 +227,12 @@ func SetCatalogHeaders(header http.Header, credential Credential) { // id, since the official client does the same when it has no session. func SetChatHeaders(header http.Header, credential Credential, conversation string) { setIdentityHeaders(header, credential) + // The bundled CLI's chat path sends the desktop UA and the OpenAI SDK + // Accept, not the generic daemon shape. It also omits Origin/Referer. + header.Set("Accept", "application/json") + header.Set("User-Agent", DesktopUserAgentFor(credential.IsGlobal())) + header.Del("Origin") + header.Del("Referer") setCLIChannelHeaders(header, credential, conversation) } @@ -226,13 +242,22 @@ func SetRefreshHeaders(header http.Header, credential Credential) { header.Set("X-Refresh-Token", credential.RefreshToken) if credential.EnterpriseID != "" { header.Set("X-Enterprise-Id", credential.EnterpriseID) + header.Set("X-Tenant-Id", credential.EnterpriseID) } header.Set("X-Auth-Refresh-Source", "workbuddy") } -// SetBillingHeaders carries identity for the separate billing hosts. +// SetBillingHeaders carries identity for the separate billing hosts. Current +// desktop AuthService uses its own axios instance on meter, check-in and +// user-resource endpoints: application/json, axios/1.16.1, a fresh request id, +// and the desktop X-Client-* identity; it does not send Origin, Referer, +// X-Requested-With, X-Product or X-Department-Info. func SetBillingHeaders(header http.Header, credential Credential) { - setCommonHeaders(header, credential.IsGlobal()) + header.Set("Accept", "application/json") + header.Set("Content-Type", "application/json") + header.Set("X-Request-ID", newCLIMessageID()) + header.Set("User-Agent", "axios/1.16.1") + setDesktopClientHeaders(header, credential.IsGlobal()) if credential.AccessToken != "" { header.Set("Authorization", "Bearer "+credential.AccessToken) } diff --git a/internal/providers/workbuddy/versions_test.go b/internal/providers/workbuddy/versions_test.go index 3249f162..32661c3b 100644 --- a/internal/providers/workbuddy/versions_test.go +++ b/internal/providers/workbuddy/versions_test.go @@ -6,24 +6,30 @@ import ( ) func TestClientVersionsAndDesktopUserAgents(t *testing.T) { - if CLIVersion != "2.168.2" || IDEVersion != "2.168.2" { + if CLIVersion != "2.176.0" || IDEVersion != "2.176.0" { t.Fatalf("CLI=%q IDE=%q", CLIVersion, IDEVersion) } - if UserAgent != "CLI/2.168.2 CodeBuddy/2.168.2" { - t.Fatalf("CLI UA=%q", UserAgent) + if UserAgent != "WorkBuddy/5.11.3 WorkBuddy/5.11.3 CLI/2.176.0" { + t.Fatalf("CN desktop UA=%q", UserAgent) } if CLIStainlessPackageVersion != "6.25.0" || CLIStainlessRuntimeVersion != "v22.21.1" { t.Fatalf("SDK fingerprint package=%q runtime=%q", CLIStainlessPackageVersion, CLIStainlessRuntimeVersion) } - if DesktopVersionGlobal != "5.9.4" || DesktopCLIVersionGlobal != "2.165.0" { + if DesktopVersionGlobal != "5.11.4" || DesktopCLIVersionGlobal != "2.176.0" { t.Fatalf("global desktop=%q cli=%q", DesktopVersionGlobal, DesktopCLIVersionGlobal) } - if got := DesktopUserAgentFor(true); got != "WorkBuddy/5.9.4 workbuddy-ai/5.9.4 CLI/2.165.0" { + if got := DesktopUserAgentFor(true); got != "WorkBuddy/5.11.4 workbuddy-ai/5.11.4 CLI/2.176.0" { t.Fatalf("global desktop UA=%q", got) } - if got := DesktopUserAgentFor(false); got != "WorkBuddy/5.8.3 WorkBuddy/5.8.3 CLI/2.161.0" { + if got := DesktopUserAgentFor(false); got != UserAgent { t.Fatalf("CN desktop UA=%q", got) } + if got := DaemonUserAgentFor(true); got != "workbuddy-ai/5.11.4 workbuddy-ai/5.11.4 CLI/2.176.0" { + t.Fatalf("global daemon UA=%q", got) + } + if got := DaemonUserAgentFor(false); got != UserAgent { + t.Fatalf("CN daemon UA=%q", got) + } if DesktopUserAgent != DesktopUserAgentGlobal { t.Fatalf("DesktopUserAgent must alias the global UA") } @@ -32,4 +38,13 @@ func TestClientVersionsAndDesktopUserAgents(t *testing.T) { if h.Get("User-Agent") != DesktopUserAgentGlobal { t.Fatalf("global catalog UA=%q", h.Get("User-Agent")) } + billing := http.Header{} + SetBillingHeaders(billing, Credential{AccessToken: "at", UID: "u1", Domain: DomainCN}) + if billing.Get("User-Agent") != "axios/1.16.1" || + billing.Get("Accept") != "application/json" || + billing.Get("X-Client-Version") != DesktopVersionCN || + billing.Get("X-Client-Product") != "WorkBuddy" || + billing.Get("X-Request-ID") == "" { + t.Fatalf("CN billing identity=%+v", billing) + } }