Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changelog/unreleased/provider-client-alignment.md
Original file line number Diff line number Diff line change
@@ -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` 仍能解析,但客户端默认不再请求。
4 changes: 2 additions & 2 deletions docs/ARCHITECTURE_SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 架构摘要
Expand Down Expand Up @@ -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。
Expand Down
48 changes: 24 additions & 24 deletions internal/providers/qoder/cosy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/qoder/cosy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/qoder/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
25 changes: 14 additions & 11 deletions internal/providers/qoder/qauth/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions internal/providers/qoder/qauth/fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions internal/providers/qoder/qauth/qauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
18 changes: 9 additions & 9 deletions internal/providers/qwenwork/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions internal/providers/qwenwork/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -58,17 +58,17 @@ 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": {
Region: "cn",
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",
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/qwenwork/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions internal/providers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/providers/trae/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading
Loading