Skip to content

Commit ee240fa

Browse files
committed
Integrate upstream Responses context and subagent changes
Merge czy-all into dev after preserving local Responses session, logging, header-forwarding, and image retry behavior while accepting upstream context management, model mapping, and Codex subagent support. Constraint: best-of-both-worlds workflow requires dev-side conflict resolution with user-approved hunks Rejected: resolving conflicts on czy-all | would pollute the upstream buffer branch Confidence: high Scope-risk: moderate Directive: keep future czy-all updates as pure caozhiyuan/dev synchronization only Tested: bun run lint:all --fix; bun run build; bun test; bun run typecheck Not-tested: live Copilot upstream behavior
2 parents ebcf911 + a06e033 commit ee240fa

16 files changed

Lines changed: 534 additions & 178 deletions

README.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ English | [简体中文](./README.zh-CN.md)
1616
>
1717
> 3. **Built-in `codex` provider:** Run `npx @jeffreycao/copilot-api@latest auth login --provider codex` once and the gateway will persist and refresh Codex OAuth credentials automatically.
1818
>
19-
> 4. **Disable multi agent when using codex:** If you're using codex via GitHub Copilot, disable multi agent. Copilot currently charges codex traffic based on whether the last message is a user role, and that billing logic has not been adjusted.
20-
>
21-
> 5. **Note:** See [GitHub Copilot Security Notice](./NOTICE.md#github-copilot-security-notice) for the warning removed from the README header.
19+
> 4. **Note:** See [GitHub Copilot Security Notice](./NOTICE.md#github-copilot-security-notice) for the warning removed from the README header.
2220
2321
---
2422
@@ -94,7 +92,7 @@ https://github.com/caozhiyuan/copilot-api/releases
9492

9593
Download the installer for your platform, sign in inside the app, choose a port, start the server, then point your client at the local endpoint shown in the app. Packaged desktop builds use the bundled Electron runtime, so normal desktop usage does not require installing Node.js separately. Token usage history is enabled when that bundled runtime supports SQLite.
9694

97-
The desktop app's Advanced Config page reads and writes model mappings through `GET/POST /admin/config/model-mappings`. It uses `auth.adminApiKey` instead of the regular `auth.apiKeys`, and the app reads that key directly from `config.json` after the server has generated it on startup.
95+
The desktop app's Advanced Config page reads and writes the shared model mappings through `GET/POST /admin/config/model-mappings`. The same mappings apply across `POST /v1/messages`, `POST /v1/messages/count_tokens`, `POST /v1/responses`, and `POST /v1/chat/completions` instead of being split per interface. It uses `auth.adminApiKey` instead of the regular `auth.apiKeys`, and the app reads that key directly from `config.json` after the server has generated it on startup.
9896

9997
### Desktop App Screenshots
10098

@@ -195,14 +193,7 @@ The following command line options are available for the `start` command:
195193
"enabled": true,
196194
"baseUrl": "your-base-url",
197195
"apiKey": "sk-your-provider-key",
198-
"authType": "x-api-key",
199-
"adjustInputTokens": false,
200-
"models": {
201-
"kimi-k2.5": {
202-
"temperature": 1,
203-
"topP": 0.95
204-
}
205-
}
196+
"authType": "x-api-key"
206197
},
207198
"dashscope": {
208199
"type": "openai-compatible",
@@ -216,8 +207,7 @@ The following command line options are available for the `start` command:
216207
"topK": 20,
217208
"extraBody": {
218209
"preserve_thinking": true
219-
},
220-
"contextCache": true
210+
}
221211
},
222212
"glm-5.1": {
223213
"temperature": 0.7,
@@ -238,7 +228,7 @@ The following command line options are available for the `start` command:
238228
"gpt-5.4": "<built-in commentary prompt>"
239229
},
240230
"smallModel": "gpt-5-mini",
241-
"responsesApiContextManagementModels": [],
231+
"useResponsesApiContextManagement": true,
242232
"modelReasoningEfforts": {
243233
"gpt-5-mini": "low",
244234
"gpt-5.3-codex": "xhigh",
@@ -252,7 +242,7 @@ The following command line options are available for the `start` command:
252242
```
253243
- **auth.apiKeys:** API keys used for request authentication on non-admin routes. Supports multiple keys for rotation. Requests can authenticate with either `x-api-key: <key>` or `Authorization: Bearer <key>`. If empty or omitted, authentication for non-admin routes is disabled.
254244
- **auth.adminApiKey:** Single admin key used only for `/admin/*` routes. If missing, the server generates a random key at startup and writes it back to `config.json`. Requests use the same `x-api-key` or `Authorization: Bearer` headers, but regular `auth.apiKeys` never grant access to `/admin/*`.
255-
- **modelMappings:** Exact `sourceModel -> targetModel` rewrites for top-level `POST /v1/messages` and `POST /v1/messages/count_tokens` requests. Omit it or leave it as `{}` to disable rewrites. Both the source and target must be non-empty strings. Targets can be regular model IDs or `provider/model` aliases such as `dashscope/qwen3.6-plus`, and the rewrite happens before provider alias parsing. The admin endpoints `GET/POST /admin/config/model-mappings` read and update only this field.
245+
- **modelMappings:** Exact `sourceModel -> targetModel` rewrites shared by top-level `POST /v1/messages`, `POST /v1/messages/count_tokens`, `POST /v1/responses`, and `POST /v1/chat/completions` requests. Omit it or leave it as `{}` to disable rewrites. Both the source and target must be non-empty strings. Targets can be regular model IDs or `provider/model` aliases such as `dashscope/qwen3.6-plus`, and the rewrite happens before provider alias parsing. These mappings are not split per interface. The admin endpoints `GET/POST /admin/config/model-mappings` read and update only this field.
256246
- **extraPrompts:** Map of `model -> prompt` appended to the first system prompt when translating Anthropic-style requests to Copilot. Use this to inject guardrails or guidance per model. Missing default entries are auto-added without overwriting your custom prompts. The built-in prompts for `gpt-5.3-codex` and `gpt-5.4` enable phase-aware commentary, which lets the model emit a short user-facing progress update before tools or deeper reasoning.
257247
- **providers:** Global upstream provider map. Each provider key (for example `dashscope`) becomes a route prefix (`/dashscope/v1/messages`). Supports `type: "anthropic"`, `type: "openai-compatible"`, and `type: "openai-responses"`. Top-level clients can also use `model: "dashscope/model-id"` with `/v1/messages`, `/v1/messages/count_tokens`, and `/v1/responses`; the gateway strips the `dashscope/` prefix before forwarding upstream. `GET /v1/models` does not aggregate provider models; use `GET /dashscope/v1/models` for provider model lists.
258248
- `enabled` defaults to `true` if omitted.
@@ -269,7 +259,7 @@ The following command line options are available for the `start` command:
269259
- `supportPdf` (optional): Controls whether the model supports PDF/document content. Defaults to `false`; unsupported PDFs are converted to a text notice. Set it to `true` to send PDF/document blocks as OpenAI Chat Completions file parts.
270260
- `toolContentSupportType` (optional): Tool result content capabilities for that model, as an array of `array`, `image`, and `pdf`. Provider routes default to string-only tool content when omitted. If `supportPdf` is `true` but this list does not include `pdf`, file parts in tool results are moved to user role messages. This provider default does not change the Copilot main flow, which continues to support array + image and not PDF.
271261
- **smallModel:** Fallback model used for tool-less warmup messages (e.g., Claude Code probe requests); defaults to gpt-5-mini.
272-
- **responsesApiContextManagementModels:** List of GPT model IDs that should receive Responses API `context_management` compaction instructions. This defaults to `[]`, so you need to opt in explicitly. A good starting point is `["gpt-5-mini", "gpt-5.3-codex", "gpt-5.4-mini", "gpt-5.4"]`. When enabled, the request includes `context_management` in the body and keeps only the latest compaction carrier on follow-up turns. The actual compaction is handled server-side and appears to begin when usage approaches roughly 90% of the model's `maxPromptTokens`, which makes it especially useful for long-running tasks. In practice, the effective `compact_threshold` also appears to be fixed on the server side, so changing it in this project does not currently alter compaction behavior. At the moment, this optimization is intended for GPT-family models only.
262+
- **useResponsesApiContextManagement:** When `true`, the proxy adds Responses API `context_management` compaction instructions. Defaults to `true`. Set it to `false` to disable this globally. When enabled, the request includes `context_management` in the body and keeps only the latest compaction carrier on follow-up turns. This is especially useful for long-running tasks.
273263
- **modelReasoningEfforts:** Per-model `reasoning.effort` sent to the Copilot Responses API. Allowed values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`. If a model isn’t listed, `high` is used by default.
274264
- **useMessagesApi:** When `true`, Claude-family models that support Copilot's native `/v1/messages` endpoint will use the Messages API; otherwise they fall back to `/chat/completions`. Set to `false` to disable Messages API routing and always use `/chat/completions`. Defaults to `true`.
275265
- **useResponsesApiWebSocket:** When `true`, Responses API requests use Copilot's websocket transport for models that advertise `ws:/responses`; models that only advertise `/responses` continue to use HTTP. Set to `false` to disable websocket routing and use HTTP `/responses` whenever the selected model supports it. Defaults to `true`.
@@ -520,14 +510,14 @@ Example `~/.config/opencode/opencode.json`:
520510
"output": ["text"]
521511
},
522512
"limit": {
523-
"context": 272000,
513+
"context": 300000,
524514
"output": 128000
525515
}
526516
},
527517
"gpt-5-mini": {
528518
"name": "gpt-5-mini",
529519
"limit": {
530-
"context": 128000,
520+
"context": 200000,
531521
"output": 64000
532522
}
533523
},
@@ -539,7 +529,7 @@ Example `~/.config/opencode/opencode.json`:
539529
"output": ["text"]
540530
},
541531
"limit": {
542-
"context": 128000,
532+
"context": 200000,
543533
"output": 32000
544534
},
545535
"options": {

README.zh-CN.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
>
1717
> 3. **内置 `codex` provider:** 执行一次 `npx @jeffreycao/copilot-api@latest auth login --provider codex` 后,AI gateway 会自动持久化并刷新 Codex OAuth 凭据。
1818
>
19-
> 4. **通过 codex 使用时请关闭 multi agent:** 如果你是通过 GitHub Copilot 使用 codex,请关闭 multi agent。当前 Copilot 会按最后一条消息是否为 user role 对 codex 流量计费,而这部分逻辑尚未调整。
20-
>
21-
> 5. **注意事项:** README 顶部移除的 GitHub Copilot warning 见 [GitHub Copilot 安全提示](./NOTICE.md#github-copilot-security-notice)。
19+
> 4. **注意事项:** README 顶部移除的 GitHub Copilot warning 见 [GitHub Copilot 安全提示](./NOTICE.md#github-copilot-security-notice)。
2220
2321
---
2422
@@ -94,7 +92,7 @@ https://github.com/caozhiyuan/copilot-api/releases
9492

9593
下载对应平台的安装包后,在应用内登录、选择端口并启动服务,再把你的客户端指向应用里显示的本地端点即可。发布版桌面应用使用随包内置的 Electron 运行时,正常使用不需要额外安装 Node.js;token usage 历史记录会在该内置运行时支持 SQLite 时启用。
9694

97-
桌面应用里的高级配置页会通过 `GET/POST /admin/config/model-mappings` 读写模型映射。它使用的是 `auth.adminApiKey`,不是普通的 `auth.apiKeys`;应用会在服务启动并自动生成该 key 后,直接从 `config.json` 读取它来发起请求。
95+
桌面应用里的高级配置页会通过 `GET/POST /admin/config/model-mappings` 读写这份共享的模型映射。同一份映射会统一作用于 `POST /v1/messages``POST /v1/messages/count_tokens``POST /v1/responses``POST /v1/chat/completions`,不再按接口区分。它使用的是 `auth.adminApiKey`,不是普通的 `auth.apiKeys`;应用会在服务启动并自动生成该 key 后,直接从 `config.json` 读取它来发起请求。
9896

9997
### 桌面应用截图
10098

@@ -197,14 +195,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
197195
"enabled": true,
198196
"baseUrl": "your-base-url",
199197
"apiKey": "sk-your-provider-key",
200-
"authType": "x-api-key",
201-
"adjustInputTokens": false,
202-
"models": {
203-
"kimi-k2.5": {
204-
"temperature": 1,
205-
"topP": 0.95
206-
}
207-
}
198+
"authType": "x-api-key"
208199
},
209200
"dashscope": {
210201
"type": "openai-compatible",
@@ -218,8 +209,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
218209
"topK": 20,
219210
"extraBody": {
220211
"preserve_thinking": true
221-
},
222-
"contextCache": true
212+
}
223213
},
224214
"glm-5.1": {
225215
"temperature": 0.7,
@@ -240,7 +230,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
240230
"gpt-5.4": "<built-in commentary prompt>"
241231
},
242232
"smallModel": "gpt-5-mini",
243-
"responsesApiContextManagementModels": [],
233+
"useResponsesApiContextManagement": true,
244234
"modelReasoningEfforts": {
245235
"gpt-5-mini": "low",
246236
"gpt-5.3-codex": "xhigh",
@@ -254,7 +244,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
254244
```
255245
- **auth.apiKeys:** 用于普通非 admin 路由的 API key。支持多个 key 轮换使用。请求可通过 `x-api-key: <key>``Authorization: Bearer <key>` 进行认证。若为空或省略,则普通路由的认证会被禁用。
256246
- **auth.adminApiKey:** 仅用于 `/admin/*` 路由的单个 admin key。若未配置,服务会在启动时自动生成一个随机 key,并回写到 `config.json`。它同样使用 `x-api-key``Authorization: Bearer` 这两种头,但普通 `auth.apiKeys` 不能访问 `/admin/*`
257-
- **modelMappings:** 用于顶层 `POST /v1/messages` `POST /v1/messages/count_tokens` 请求的精确 `sourceModel -> targetModel` 重写映射。省略该字段或保留为 `{}` 时,不会做模型重写。`source``target` 都必须是非空字符串。`target` 可以是普通模型 ID,也可以是 `provider/model` 形式的别名,例如 `dashscope/qwen3.6-plus`;重写发生在 provider alias 解析之前。`GET/POST /admin/config/model-mappings` 管理接口读写的也只有这个字段。
247+
- **modelMappings:** 用于顶层 `POST /v1/messages``POST /v1/messages/count_tokens``POST /v1/responses` `POST /v1/chat/completions` 请求的精确 `sourceModel -> targetModel` 重写映射,这几类接口共用同一份规则。省略该字段或保留为 `{}` 时,不会做模型重写。`source``target` 都必须是非空字符串。`target` 可以是普通模型 ID,也可以是 `provider/model` 形式的别名,例如 `dashscope/qwen3.6-plus`;重写发生在 provider alias 解析之前。这些映射不再按接口区分`GET/POST /admin/config/model-mappings` 管理接口读写的也只有这个字段。
258248
- **extraPrompts:** `model -> prompt` 的映射。把 Anthropic 风格请求翻译给 Copilot 时,会将其附加到第一条 system prompt 后面。你可以借此为不同模型注入护栏或指引。缺失的默认项会自动补齐,但不会覆盖你自定义的 prompt。内置的 `gpt-5.3-codex``gpt-5.4` prompt 会启用带阶段感知的 commentary,让模型在工具调用或更深层推理前先发出简短的用户可见进度说明。
259249
- **providers:** 全局上游 provider 映射。每个 provider key(例如 `dashscope`)都会变成一个路由前缀(`/dashscope/v1/messages`)。支持 `type: "anthropic"``type: "openai-compatible"``type: "openai-responses"`。顶层客户端也可以在 `/v1/messages``/v1/messages/count_tokens``/v1/responses` 中使用 `model: "dashscope/model-id"`;AI gateway 会在转发上游前移除 `dashscope/` 前缀。`GET /v1/models` 不聚合 provider 模型;provider 模型列表请使用 `GET /dashscope/v1/models`
260250
- `enabled`:可选,若省略则默认为 `true`
@@ -271,7 +261,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
271261
- `supportPdf`:可选,控制该模型是否支持 PDF/document content。默认 `false`,不支持时会把 PDF 转成提示文本;设为 `true` 时会把 PDF/document 转成 OpenAI Chat Completions 的 file part。
272262
- `toolContentSupportType`:可选,配置该模型的 tool result content 支持能力,值为 `array``image``pdf` 的数组。provider 侧未配置时默认只发送 string tool content。若 `supportPdf``true` 但这里不包含 `pdf`,tool result 里的 file part 会被转成 user role 消息。Copilot 主链路不使用这个 provider 默认,仍按 array + image 且不支持 PDF 的能力处理。
273263
- **smallModel:** 无工具预热消息的回退模型(例如 Claude Code 的探测请求);默认是 `gpt-5-mini`
274-
- **responsesApiContextManagementModels** 需要启用 Responses API `context_management` 压缩指令的 GPT 模型 ID 列表。默认是 `[]`,需要你显式开启。一个不错的起点是 `["gpt-5-mini", "gpt-5.3-codex", "gpt-5.4-mini", "gpt-5.4"]`。启用后,请求体会带上 `context_management`,并在后续轮次中仅保留最新的压缩承载内容。实际压缩由服务端完成,看起来会在 usage 接近模型 `maxPromptTokens` 的约 90% 时开始,因此特别适合长任务场景。实践中 `compact_threshold` 似乎也是服务端固定的,所以在本项目中修改它目前不会改变压缩行为。当前该优化仅面向 GPT 系模型
264+
- **useResponsesApiContextManagement** 当为 `true` 时,代理会为 Responses API 附加 `context_management` 压缩指令。默认值为 `true`。如需全局关闭,可设为 `false`。启用后,请求体会带上 `context_management`,并在后续轮次中仅保留最新的压缩承载内容因此特别适合长任务场景。
275265
- **modelReasoningEfforts:** 按模型配置发送到 Copilot Responses API 的 `reasoning.effort`。可选值包括 `none``minimal``low``medium``high``xhigh`。若某模型未配置,则默认使用 `high`
276266
- **useMessagesApi:** 当为 `true` 时,支持 Copilot 原生 `/v1/messages` 的 Claude 系模型会走 Messages API;否则回退到 `/chat/completions`。设为 `false` 可禁用 Messages API 路由,始终使用 `/chat/completions`。默认值为 `true`
277267
- **useResponsesApiWebSocket:** 当为 `true` 时,Responses API 请求会优先对声明了 `ws:/responses` 的模型使用 Copilot websocket transport;仅声明 `/responses` 的模型仍走 HTTP。设为 `false` 可禁用 websocket 路由,并在模型支持 `/responses` 时使用 HTTP `/responses`。默认值为 `true`
@@ -524,14 +514,14 @@ npx @jeffreycao/copilot-api@latest --oauth-app=opencode start
524514
"output": ["text"]
525515
},
526516
"limit": {
527-
"context": 272000,
517+
"context": 300000,
528518
"output": 128000
529519
}
530520
},
531521
"gpt-5-mini": {
532522
"name": "gpt-5-mini",
533523
"limit": {
534-
"context": 128000,
524+
"context": 200000,
535525
"output": 64000
536526
}
537527
},
@@ -543,7 +533,7 @@ npx @jeffreycao/copilot-api@latest --oauth-app=opencode start
543533
"output": ["text"]
544534
},
545535
"limit": {
546-
"context": 128000,
536+
"context": 200000,
547537
"output": 32000
548538
},
549539
"options": {

desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "copilot-api-desktop",
3-
"version": "1.10.22",
3+
"version": "1.10.25",
44
"description": "Copilot API Desktop App",
55
"main": "out/main/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)