@nick3/copilot-api 1.10.4 → 1.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -8
- package/README.zh-CN.md +52 -7
- package/dist/admin/assets/{index-DG4TRVMu.js → index-BAh4eOwM.js} +36 -36
- package/dist/admin/index.html +1 -1
- package/dist/main.js +4 -2
- package/dist/main.js.map +1 -1
- package/dist/mcp-9Hgepkc5.js +37 -0
- package/dist/mcp-9Hgepkc5.js.map +1 -0
- package/dist/{proxy-BwmADhKh.js → proxy-_U-hgwIn.js} +1 -2
- package/dist/proxy-_U-hgwIn.js.map +1 -0
- package/dist/{server-DxQsi1x2.js → server-DulP9mYd.js} +251 -66
- package/dist/server-DulP9mYd.js.map +1 -0
- package/dist/{start-8QHzPrcg.js → start-CtEoE2gt.js} +3 -3
- package/dist/{start-8QHzPrcg.js.map → start-CtEoE2gt.js.map} +1 -1
- package/dist/tool-search-BrN7M0Dd.js +110 -0
- package/dist/tool-search-BrN7M0Dd.js.map +1 -0
- package/package.json +3 -6
- package/dist/proxy-BwmADhKh.js.map +0 -1
- package/dist/server-DxQsi1x2.js.map +0 -1
package/README.md
CHANGED
|
@@ -354,7 +354,6 @@ The `<target>` can be either the account ID (GitHub login) or a 1-based index.
|
|
|
354
354
|
"gpt-5.4": "xhigh"
|
|
355
355
|
},
|
|
356
356
|
"allowOriginalModelNamesForAliases": false,
|
|
357
|
-
"useFunctionApplyPatch": true,
|
|
358
357
|
"forceAgent": false,
|
|
359
358
|
"compactUseSmallModel": true,
|
|
360
359
|
"messageStartInputTokensFallback": false,
|
|
@@ -446,7 +445,6 @@ The `<target>` can be either the account ID (GitHub login) or a 1-based index.
|
|
|
446
445
|
- **apiKey (deprecated):** Legacy single-key field kept for migration compatibility. Prefer `auth.apiKeys`. When `auth.apiKeys` is empty, the server falls back to `COPILOT_API_KEY` and then `apiKey`.- **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.
|
|
447
446
|
- **modelAliases:** Map of `alias -> { target, allowOriginal? }` (legacy string values are still accepted). Alias keys are normalized (trim + lowercase) and must be non-empty; aliases cannot map to themselves (case-insensitive), and conflicting normalized aliases are rejected. `allowOriginal` overrides the global default per alias. If multiple aliases map to the same target, original names are allowed when any alias sets `allowOriginal: true` (allow-wins). Admin UI/API rejects blocked keys (`__proto__`, `constructor`, `prototype`). Aliases can be used in downstream requests, and targets may be configured `provider/model` aliases for top-level `/v1/messages` and `/v1/messages/count_tokens` routing.
|
|
448
447
|
- **allowOriginalModelNamesForAliases:** Global default for aliases that omit `allowOriginal`. When `false` (default), targets are blocked unless an alias explicitly allows them; when `true`, targets are allowed unless all aliases explicitly block them.
|
|
449
|
-
- **useFunctionApplyPatch:** When `true` (default), `POST /v1/responses` converts a `tools` entry with `{ "type": "custom", "name": "apply_patch" }` into an OpenAI-style `function` tool (with a parameter schema) for upstream compatibility. Set to `false` to leave custom tools untouched.
|
|
450
448
|
- **forceAgent:** When `true`, `POST /v1/responses` treats a request as agent-initiated if **any** input item has `role: "assistant"`. When `false` (default), only the **last** input item is checked.
|
|
451
449
|
- **compactUseSmallModel:** When `true`, detected "compact" requests (e.g., from Claude Code or opencode compact mode) will automatically use the configured `smallModel` to avoid consuming premium usage for short/background tasks. Defaults to `true`.
|
|
452
450
|
- **messageStartInputTokensFallback:** When `true`, the Anthropic streaming translation layer estimates `message_start.input_tokens` when upstream stream events do not provide it. Defaults to `false`.
|
|
@@ -730,6 +728,47 @@ You can find more options here: [Claude Code settings](https://docs.anthropic.co
|
|
|
730
728
|
|
|
731
729
|
You can also read more about IDE integration here: [Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
732
730
|
|
|
731
|
+
## GPT Tool Search
|
|
732
|
+
|
|
733
|
+
For GPT Responses models such as `gpt-5.4+`, this proxy can expose Responses `tool_search` through a small MCP bridge. The same bridge can be used by Claude Code and opencode, as long as the client loads MCP servers and sends Anthropic Messages traffic through this proxy.
|
|
734
|
+
|
|
735
|
+
Do not set Claude Code's native `ENABLE_TOOL_SEARCH` for GPT models. That flag enables Claude Code's own client-side tool search mode, and it may stop forwarding deferred tool definitions. This proxy needs the full tool definitions so it can keep the small always-loaded tool set eager and translate every other tool into Responses deferred namespaces.
|
|
736
|
+
|
|
737
|
+
If you install `tool-search@copilot-api-marketplace`, Claude Code receives this MCP bridge automatically and you can skip the manual Claude Code MCP setup below.
|
|
738
|
+
|
|
739
|
+
Add the tool search bridge to the MCP config used by Claude Code:
|
|
740
|
+
|
|
741
|
+
```json
|
|
742
|
+
{
|
|
743
|
+
"mcpServers": {
|
|
744
|
+
"tool_search": {
|
|
745
|
+
"type": "stdio",
|
|
746
|
+
"command": "npx",
|
|
747
|
+
"args": ["-y", "@nick3/copilot-api@latest", "mcp"]
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
Add the tool search bridge to the MCP config used by opencode:
|
|
754
|
+
|
|
755
|
+
```json
|
|
756
|
+
{
|
|
757
|
+
"mcp": {
|
|
758
|
+
"tool_search": {
|
|
759
|
+
"type": "local",
|
|
760
|
+
"command": ["npx", "-y", "@nick3/copilot-api@latest", "mcp"]
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
For local development, use `bun` as the command and `["run", "./src/main.ts", "mcp"]` as the args.
|
|
767
|
+
|
|
768
|
+
Internally, the proxy now configures OpenAI Responses `tool_search` in client-executed mode. Deferred tools are still exposed as searchable namespaces, but the model is explicitly asked to return the exact deferred tool names it wants to load next.
|
|
769
|
+
|
|
770
|
+
The bridge uses direct tool selection, not query search. Its tool input is `names`, a comma-separated list of exact deferred tool names, for example `TaskList,TaskGet,mcp__fetch__fetch`.
|
|
771
|
+
|
|
733
772
|
## Using with OpenCode
|
|
734
773
|
|
|
735
774
|
OpenCode already has a direct GitHub Copilot provider. Use this section when you want OpenCode to point at this proxy through `@ai-sdk/anthropic` and reuse the agent behaviors described earlier in this README.
|
|
@@ -891,10 +930,13 @@ Plugin integrations are available for Claude Code and opencode.
|
|
|
891
930
|
|
|
892
931
|
#### Claude Code plugin integration (marketplace-based)
|
|
893
932
|
|
|
894
|
-
The Claude Code integration is packaged as
|
|
933
|
+
The Claude Code integration is packaged as two plugins:
|
|
934
|
+
|
|
935
|
+
- `agent-inject` injects `__SUBAGENT_MARKER__...` on `SubagentStart`, so this proxy can infer `x-initiator: agent`.
|
|
936
|
+
- `tool-search` registers the `tool_search` MCP bridge used for GPT Responses deferred tool loading.
|
|
895
937
|
|
|
896
938
|
- Marketplace catalog in this repository: `.claude-plugin/marketplace.json`
|
|
897
|
-
- Plugin
|
|
939
|
+
- Plugin sources in this repository: `claude-plugin/agent-inject`, `claude-plugin/tool-search`
|
|
898
940
|
|
|
899
941
|
Add the marketplace remotely:
|
|
900
942
|
|
|
@@ -902,19 +944,22 @@ Add the marketplace remotely:
|
|
|
902
944
|
/plugin marketplace add https://github.com/nick3/copilot-api.git#all
|
|
903
945
|
```
|
|
904
946
|
|
|
905
|
-
Install the
|
|
947
|
+
Install the plugins from the marketplace:
|
|
906
948
|
|
|
907
949
|
```sh
|
|
908
|
-
/plugin install
|
|
950
|
+
/plugin install agent-inject@copilot-api-marketplace
|
|
951
|
+
/plugin install tool-search@copilot-api-marketplace
|
|
909
952
|
```
|
|
910
953
|
|
|
911
|
-
After installation,
|
|
954
|
+
After installation, `agent-inject` injects `__SUBAGENT_MARKER__...` on `SubagentStart`, and this proxy uses it to infer `x-initiator: agent`.
|
|
912
955
|
|
|
913
|
-
The plugin also registers a `UserPromptSubmit` hook that returns `{"continue": true}`, and it can inject `SessionStart` reminder rules through environment variables:
|
|
956
|
+
The `agent-inject` plugin also registers a `UserPromptSubmit` hook that returns `{"continue": true}`, and it can inject `SessionStart` reminder rules through environment variables:
|
|
914
957
|
|
|
915
958
|
- `CLAUDE_PLUGIN_ENABLE_QUESTION_RULES=1` enables the two reminders about using the `question` tool automatically for Claude Code. Alternatively, you can add the same reminders manually in `CLAUDE.md`; see [CLAUDE.md or AGENTS.md Recommended Content](#claudemd-or-agentsmd-recommended-content).
|
|
916
959
|
- `CLAUDE_PLUGIN_ENABLE_NO_BACKGROUND_AGENTS_RULE=1` enables the `run_in_background: true` avoidance reminder for agent hooks.
|
|
917
960
|
|
|
961
|
+
The `tool-search` plugin bundles the same MCP bridge described in [GPT Tool Search](#gpt-tool-search), so Claude Code users do not need to add the `tool_search` server manually when they install that plugin.
|
|
962
|
+
|
|
918
963
|
#### Opencode plugin
|
|
919
964
|
|
|
920
965
|
The subagent marker producer is packaged as an opencode plugin located at `.opencode/plugins/subagent-marker.js`.
|
package/README.zh-CN.md
CHANGED
|
@@ -363,7 +363,6 @@ Copilot API 现在使用子命令结构,主要命令包括:
|
|
|
363
363
|
"gpt-5.4": "xhigh"
|
|
364
364
|
},
|
|
365
365
|
"allowOriginalModelNamesForAliases": false,
|
|
366
|
-
"useFunctionApplyPatch": true,
|
|
367
366
|
"forceAgent": false,
|
|
368
367
|
"compactUseSmallModel": true,
|
|
369
368
|
"messageStartInputTokensFallback": false,
|
|
@@ -455,7 +454,6 @@ Copilot API 现在使用子命令结构,主要命令包括:
|
|
|
455
454
|
- **apiKey(已弃用):** 兼容迁移的旧单 key 字段。优先使用 `auth.apiKeys`。当 `auth.apiKeys` 为空时,服务端会回退到 `COPILOT_API_KEY`,再回退到 `apiKey`。- **modelReasoningEfforts:** 按模型配置发送到 Copilot Responses API 的 `reasoning.effort`。可选值包括 `none`、`minimal`、`low`、`medium`、`high` 和 `xhigh`。若某模型未配置,则默认使用 `high`。
|
|
456
455
|
- **modelAliases:** `alias -> { target, allowOriginal? }` 的映射(也仍然接受旧的字符串写法)。别名 key 会先做标准化(trim + lowercase),且不能为空;别名不能映射回自己(大小写不敏感),冲突的标准化别名会被拒绝。`allowOriginal` 可为单个别名覆盖全局默认值。如果多个别名映射到同一个 target,只要其中任意一个设置了 `allowOriginal: true`,原始模型名就会被允许(allow-wins)。Admin UI/API 会拒绝被屏蔽的键(`__proto__`、`constructor`、`prototype`)。下游请求可以直接使用这些别名,target 也可以是 `provider/model` 形式,用于顶层 `/v1/messages` 与 `/v1/messages/count_tokens` 路由。
|
|
457
456
|
- **allowOriginalModelNamesForAliases:** 对未显式设置 `allowOriginal` 的别名所采用的全局默认值。当其为 `false`(默认)时,target 原名默认被屏蔽,除非某个别名显式允许;当其为 `true` 时,target 原名默认可用,除非所有别名都显式阻止。
|
|
458
|
-
- **useFunctionApplyPatch:** 当为 `true`(默认)时,`POST /v1/responses` 会把 `tools` 中形如 `{ "type": "custom", "name": "apply_patch" }` 的条目转换为 OpenAI 风格的 `function` 工具(带参数 schema),以便与上游更好兼容。设为 `false` 则保留自定义工具原样。
|
|
459
457
|
- **forceAgent:** 当为 `true` 时,只要 `POST /v1/responses` 的任一 input item 带有 `role: "assistant"`,就会把请求视为由 agent 发起;当为 `false`(默认)时,只检查最后一个 input item。
|
|
460
458
|
- **compactUseSmallModel:** 当为 `true` 时,检测到的“compact”请求(例如 Claude Code 或 opencode 的 compact 模式)会自动改用配置中的 `smallModel`,以避免短后台任务消耗 premium 使用量。默认值为 `true`。
|
|
461
459
|
- **messageStartInputTokensFallback:** 当为 `true` 时,如果上游流式事件没有提供 `message_start.input_tokens`,Anthropic 流式翻译层会自行估算该值。默认值为 `false`。
|
|
@@ -742,6 +740,47 @@ npx @nick3/copilot-api@latest start --claude-code
|
|
|
742
740
|
|
|
743
741
|
也可以参考 IDE 集成说明:[Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
744
742
|
|
|
743
|
+
## GPT Tool Search
|
|
744
|
+
|
|
745
|
+
对于 `gpt-5.4+` 这类 GPT Responses 模型,本代理可以通过一个很小的 MCP bridge 暴露 Responses `tool_search`。Claude Code 和 opencode 都可以使用同一个 bridge,前提是客户端会加载 MCP server,并且 Anthropic Messages 流量会经过本代理。
|
|
746
|
+
|
|
747
|
+
GPT 模型不要设置 Claude Code 原生的 `ENABLE_TOOL_SEARCH`。这个开关启用的是 Claude Code 自己的客户端 tool search 模式,可能导致 deferred 工具定义不再转发给代理。本代理需要完整的工具定义,这样才能只保留那一小组常驻加载工具,其余工具统一转换为 Responses deferred namespace。
|
|
748
|
+
|
|
749
|
+
如果你安装了 `tool-search@copilot-api-marketplace`,Claude Code 会自动带上这个 MCP bridge,可以跳过下面这段 Claude Code MCP 手动配置。
|
|
750
|
+
|
|
751
|
+
请把 tool search bridge 加到 Claude Code 使用的 MCP 配置中:
|
|
752
|
+
|
|
753
|
+
```json
|
|
754
|
+
{
|
|
755
|
+
"mcpServers": {
|
|
756
|
+
"tool_search": {
|
|
757
|
+
"type": "stdio",
|
|
758
|
+
"command": "npx",
|
|
759
|
+
"args": ["-y", "@nick3/copilot-api@latest", "mcp"]
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
请把 tool search bridge 加到 opencode 使用的 MCP 配置中:
|
|
766
|
+
|
|
767
|
+
```json
|
|
768
|
+
{
|
|
769
|
+
"mcp": {
|
|
770
|
+
"tool_search": {
|
|
771
|
+
"type": "local",
|
|
772
|
+
"command": ["npx", "-y", "@nick3/copilot-api@latest", "mcp"]
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
本地开发时可以将命令换成 `bun`,参数换成 `["run", "./src/main.ts", "mcp"]`。
|
|
779
|
+
|
|
780
|
+
代理内部现在会把 OpenAI Responses `tool_search` 配置成 client-executed 模式。deferred tools 仍然会作为可搜索 namespace 暴露给模型,但会明确要求模型直接返回下一步要加载的精确工具名列表。
|
|
781
|
+
|
|
782
|
+
该 bridge 使用直接工具选择,不做 query 搜索。工具入参是 `names`,值为逗号分隔的精确 deferred 工具名,例如 `TaskList,TaskGet,mcp__fetch__fetch`。
|
|
783
|
+
|
|
745
784
|
## 与 OpenCode 一起使用
|
|
746
785
|
|
|
747
786
|
OpenCode 已经内置了 GitHub Copilot provider。本节适用于你希望让 OpenCode 通过 `@ai-sdk/anthropic` 指向这个代理,并复用本 README 前面提到的 agent 行为时。
|
|
@@ -905,10 +944,13 @@ UI 会把 token 保存在 `sessionStorage` 中,并通过 `x-admin-token` 请
|
|
|
905
944
|
|
|
906
945
|
#### Claude Code 插件集成(基于 marketplace)
|
|
907
946
|
|
|
908
|
-
Claude Code
|
|
947
|
+
Claude Code 集成现在拆分为两个插件:
|
|
948
|
+
|
|
949
|
+
- `agent-inject` 会在 `SubagentStart` 时注入 `__SUBAGENT_MARKER__...`,以便本代理推导 `x-initiator: agent`。
|
|
950
|
+
- `tool-search` 会注册用于 GPT Responses deferred tool loading 的 `tool_search` MCP bridge。
|
|
909
951
|
|
|
910
952
|
- 本仓库中的 marketplace catalog:`.claude-plugin/marketplace.json`
|
|
911
|
-
- 本仓库中的插件源码:`claude-plugin`
|
|
953
|
+
- 本仓库中的插件源码:`claude-plugin/agent-inject`、`claude-plugin/tool-search`
|
|
912
954
|
|
|
913
955
|
远程添加 marketplace:
|
|
914
956
|
|
|
@@ -919,16 +961,19 @@ Claude Code 集成被打包为名为 `claude-plugin` 的插件。
|
|
|
919
961
|
从 marketplace 安装插件:
|
|
920
962
|
|
|
921
963
|
```sh
|
|
922
|
-
/plugin install
|
|
964
|
+
/plugin install agent-inject@copilot-api-marketplace
|
|
965
|
+
/plugin install tool-search@copilot-api-marketplace
|
|
923
966
|
```
|
|
924
967
|
|
|
925
|
-
|
|
968
|
+
安装后,`agent-inject` 会在 `SubagentStart` 时注入 `__SUBAGENT_MARKER__...`,该代理会利用它推导 `x-initiator: agent`。
|
|
926
969
|
|
|
927
|
-
|
|
970
|
+
`agent-inject` 还会注册一个 `UserPromptSubmit` hook,并返回 `{"continue": true}`;同时它也可以通过环境变量注入 `SessionStart` reminder 规则:
|
|
928
971
|
|
|
929
972
|
- `CLAUDE_PLUGIN_ENABLE_QUESTION_RULES=1` 会自动为 Claude Code 启用两条关于使用 `question` 工具的提醒。你也可以把同样的提醒手动写进 `CLAUDE.md`;见 [CLAUDE.md 或 AGENTS.md 推荐内容](#claudemd-or-agentsmd-recommended-content)。
|
|
930
973
|
- `CLAUDE_PLUGIN_ENABLE_NO_BACKGROUND_AGENTS_RULE=1` 会启用关于避免在 agent hooks 中使用 `run_in_background: true` 的提醒。
|
|
931
974
|
|
|
975
|
+
`tool-search` 插件内置了 [GPT Tool Search](#gpt-tool-search) 一节描述的同一个 MCP bridge,因此安装该插件后,Claude Code 用户无需再手动配置 `tool_search` server。
|
|
976
|
+
|
|
932
977
|
#### Opencode 插件
|
|
933
978
|
|
|
934
979
|
subagent marker 生成器被打包为一个 opencode 插件,位于 `.opencode/plugins/subagent-marker.js`。
|