@jeffreycao/copilot-api 1.9.15 → 1.10.0
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 +99 -82
- package/README.zh-CN.md +101 -84
- package/dist/{auth-DEUCqXMV.js → auth-D7YCTWpx.js} +3 -3
- package/dist/{auth-DEUCqXMV.js.map → auth-D7YCTWpx.js.map} +1 -1
- package/dist/{check-usage-OcW_3tEg.js → check-usage-Dgg0nNEw.js} +3 -3
- package/dist/{check-usage-OcW_3tEg.js.map → check-usage-Dgg0nNEw.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{config-DrfmMOO-.js → proxy-De0Po8kG.js} +62 -3
- package/dist/proxy-De0Po8kG.js.map +1 -0
- package/dist/{server-DkUKa2I6.js → server-BnKth1Jp.js} +402 -80
- package/dist/server-BnKth1Jp.js.map +1 -0
- package/dist/{start-DFJynp4A.js → start-1KA2mHVS.js} +5 -52
- package/dist/start-1KA2mHVS.js.map +1 -0
- package/dist/{token-BOwQe3TO.js → token-BQlDdqtI.js} +2 -2
- package/dist/{token-BOwQe3TO.js.map → token-BQlDdqtI.js.map} +1 -1
- package/dist/{utils-Cj-ToKA6.js → utils-C5ej0z8n.js} +47 -7
- package/dist/utils-C5ej0z8n.js.map +1 -0
- package/package.json +1 -1
- package/dist/config-DrfmMOO-.js.map +0 -1
- package/dist/server-DkUKa2I6.js.map +0 -1
- package/dist/start-DFJynp4A.js.map +0 -1
- package/dist/utils-Cj-ToKA6.js.map +0 -1
package/README.md
CHANGED
|
@@ -176,6 +176,15 @@ https://github.com/caozhiyuan/copilot-api/releases
|
|
|
176
176
|
|
|
177
177
|
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.
|
|
178
178
|
|
|
179
|
+
### Desktop App Screenshots
|
|
180
|
+
|
|
181
|
+
Main dashboard, token usage breakdown in the bundled Electron app:
|
|
182
|
+
|
|
183
|
+
<p align="center">
|
|
184
|
+
<img src="./docs/screenshots/desktop-dashboard.png" alt="Copilot API desktop app dashboard" width="49%" />
|
|
185
|
+
<img src="./docs/screenshots/desktop-token-usage.png" alt="Copilot API desktop app token usage view" width="49%" />
|
|
186
|
+
</p>
|
|
187
|
+
|
|
179
188
|
## Using with Docker
|
|
180
189
|
|
|
181
190
|
Build image
|
|
@@ -352,6 +361,7 @@ The following command line options are available for the `start` command:
|
|
|
352
361
|
},
|
|
353
362
|
"useFunctionApplyPatch": true,
|
|
354
363
|
"useMessagesApi": true,
|
|
364
|
+
"useResponsesApiWebSocket": true,
|
|
355
365
|
"useResponsesApiWebSearch": true
|
|
356
366
|
}
|
|
357
367
|
```
|
|
@@ -376,6 +386,7 @@ The following command line options are available for the `start` command:
|
|
|
376
386
|
- **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.
|
|
377
387
|
- **useFunctionApplyPatch:** When `true`, the server will convert any custom tool named `apply_patch` in Responses payloads into an OpenAI-style function tool (`type: "function"`) with a parameter schema so assistants can call it using function-calling semantics to edit files. Set to `false` to leave tools unchanged. Defaults to `true`.
|
|
378
388
|
- **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`.
|
|
389
|
+
- **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`.
|
|
379
390
|
- **useResponsesApiWebSearch:** When `true`, the server keeps Responses API tools with `type: "web_search"` and forwards them upstream. Set to `false` to strip those tools from `/responses` payloads. Defaults to `true`.
|
|
380
391
|
- **claudeTokenMultiplier:** Multiplier applied to the fallback GPT-tokenizer estimate for Claude `/v1/messages/count_tokens` requests. Defaults to `1.15`. Increase it if your client is still compacting too late. This setting is only used when the proxy is estimating Claude tokens locally; if `anthropicApiKey` is configured and Anthropic token counting succeeds, the exact Anthropic count is returned instead.
|
|
381
392
|
- **anthropicApiKey:** Anthropic API key used for accurate Claude token counting (see [Accurate Claude Token Counting](#accurate-claude-token-counting) below). Can also be set via the `ANTHROPIC_API_KEY` environment variable. If not set, token counting falls back to GPT tokenizer estimation.
|
|
@@ -500,6 +511,65 @@ npx @jeffreycao/copilot-api@latest --api-home=/custom/path --oauth-app=opencode
|
|
|
500
511
|
bunx --bun @jeffreycao/copilot-api@latest start
|
|
501
512
|
```
|
|
502
513
|
|
|
514
|
+
## Using with Claude Code
|
|
515
|
+
|
|
516
|
+
This proxy can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code), an experimental conversational AI assistant for developers from Anthropic.
|
|
517
|
+
|
|
518
|
+
There are two ways to configure Claude Code to use this proxy:
|
|
519
|
+
|
|
520
|
+
### Interactive Setup with `--claude-code` flag
|
|
521
|
+
|
|
522
|
+
To get started, run the `start` command with the `--claude-code` flag:
|
|
523
|
+
|
|
524
|
+
```sh
|
|
525
|
+
npx @jeffreycao/copilot-api@latest start --claude-code
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
You will be prompted to select a primary model and a "small, fast" model for background tasks. After selecting the models, a command will be copied to your clipboard. This command sets the necessary environment variables for Claude Code to use the proxy.
|
|
529
|
+
|
|
530
|
+
Paste and run this command in a new terminal to launch Claude Code.
|
|
531
|
+
|
|
532
|
+
### Manual Configuration with `settings.json`
|
|
533
|
+
|
|
534
|
+
Alternatively, you can configure Claude Code by creating a `.claude/settings.json` file in your project's root directory. This file should contain the environment variables needed by Claude Code. This way you don't need to run the interactive setup every time.
|
|
535
|
+
|
|
536
|
+
Here is an example `.claude/settings.json` file:
|
|
537
|
+
|
|
538
|
+
```json
|
|
539
|
+
{
|
|
540
|
+
"env": {
|
|
541
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
542
|
+
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
543
|
+
"ANTHROPIC_MODEL": "gpt-5.4",
|
|
544
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
|
|
545
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
|
|
546
|
+
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
547
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
548
|
+
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
549
|
+
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
550
|
+
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
551
|
+
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
552
|
+
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
553
|
+
},
|
|
554
|
+
"permissions": {
|
|
555
|
+
"deny": [
|
|
556
|
+
"WebSearch",
|
|
557
|
+
"mcp__ide__executeCode"
|
|
558
|
+
]
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
- Replace `ANTHROPIC_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_HAIKU_MODEL` according to your needs. After configuration, please install the claude code plugin [Plugin Integrations](#plugin-integrations). If configuring the claude model, it is recommended to set all model configurations the same, so as to remain consistent with github-copilot claude agent behavior.
|
|
564
|
+
- Setting CLAUDE_CODE_ATTRIBUTION_HEADER to 0 can prevent Claude code from adding billing and version information in system prompts, thereby avoiding prompt cache invalidation.
|
|
565
|
+
- Turning off CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION and CLAUDE_CODE_ENABLE_AWAY_SUMMARY can prevent quota from being consumed unnecessarily.
|
|
566
|
+
- Permissions deny WebSearch because the GitHub Copilot API does not support natie websearch (some gpt models support websearch, but the current project has not adapted websearch); it is recommended to install the mcp mcp_server_fetch tool or other search tools as alternatives..
|
|
567
|
+
- If using a non-Claude model, do not enable ENABLE_TOOL_SEARCH. If using the Claude model, can enable ENABLE_TOOL_SEARCH. The current Claude Code uses the client tool search mode. In this mode, loading defer tools requires an additional request each time.
|
|
568
|
+
|
|
569
|
+
You can find more options here: [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
570
|
+
|
|
571
|
+
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)
|
|
572
|
+
|
|
503
573
|
## Using with OpenCode
|
|
504
574
|
|
|
505
575
|
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.
|
|
@@ -590,88 +660,6 @@ Why these fields matter:
|
|
|
590
660
|
- `model`, `small_model`, and `agent.*.model` let you keep `gpt-5.4` for build/plan work while routing exploration and background work to `gpt-5-mini`.
|
|
591
661
|
- If you enable `auth.apiKeys` in this proxy, replace `dummy` with a real key. Otherwise any placeholder value is fine.
|
|
592
662
|
|
|
593
|
-
## Using the Usage Viewer
|
|
594
|
-
|
|
595
|
-
After starting the server, a URL to the Copilot Usage Dashboard will be displayed in your console. This dashboard is a web interface for monitoring your API usage.
|
|
596
|
-
|
|
597
|
-
1. Start the server. For example, using npx:
|
|
598
|
-
```sh
|
|
599
|
-
npx @jeffreycao/copilot-api@latest start
|
|
600
|
-
```
|
|
601
|
-
2. The server will output a URL to the usage viewer. Copy and paste this URL into your browser. It will look something like this:
|
|
602
|
-
`http://localhost:4141/usage-viewer?endpoint=http://localhost:4141/usage`
|
|
603
|
-
- If you use the `start.bat` script on Windows, this page will open automatically.
|
|
604
|
-
|
|
605
|
-
The dashboard provides a user-friendly interface to view your Copilot usage data:
|
|
606
|
-
|
|
607
|
-
> Token usage history requires Bun or Node.js >= 22.13.0. On Node.js < 22.13.0, the server runs normally but token usage storage is disabled.
|
|
608
|
-
|
|
609
|
-
- **API Endpoint URL**: The dashboard is pre-configured to fetch data from your local server endpoint via the URL query parameter. You can change this URL to point to any other compatible API endpoint.
|
|
610
|
-
- **Fetch Data**: Click the "Fetch" button to load or refresh the usage data. The dashboard will automatically fetch data on load.
|
|
611
|
-
- **Usage Quotas**: View a summary of your usage quotas for different services like Chat and Completions, displayed with progress bars for a quick overview.
|
|
612
|
-
- **Detailed Information**: See the full JSON response from the API for a detailed breakdown of all available usage statistics.
|
|
613
|
-
- **URL-based Configuration**: You can also specify the API endpoint directly in the URL using a query parameter. This is useful for bookmarks or sharing links. For example:
|
|
614
|
-
`http://localhost:4141/usage-viewer?endpoint=http://your-api-server/usage`
|
|
615
|
-
|
|
616
|
-
## Using with Claude Code
|
|
617
|
-
|
|
618
|
-
This proxy can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code), an experimental conversational AI assistant for developers from Anthropic.
|
|
619
|
-
|
|
620
|
-
There are two ways to configure Claude Code to use this proxy:
|
|
621
|
-
|
|
622
|
-
### Interactive Setup with `--claude-code` flag
|
|
623
|
-
|
|
624
|
-
To get started, run the `start` command with the `--claude-code` flag:
|
|
625
|
-
|
|
626
|
-
```sh
|
|
627
|
-
npx @jeffreycao/copilot-api@latest start --claude-code
|
|
628
|
-
```
|
|
629
|
-
|
|
630
|
-
You will be prompted to select a primary model and a "small, fast" model for background tasks. After selecting the models, a command will be copied to your clipboard. This command sets the necessary environment variables for Claude Code to use the proxy.
|
|
631
|
-
|
|
632
|
-
Paste and run this command in a new terminal to launch Claude Code.
|
|
633
|
-
|
|
634
|
-
### Manual Configuration with `settings.json`
|
|
635
|
-
|
|
636
|
-
Alternatively, you can configure Claude Code by creating a `.claude/settings.json` file in your project's root directory. This file should contain the environment variables needed by Claude Code. This way you don't need to run the interactive setup every time.
|
|
637
|
-
|
|
638
|
-
Here is an example `.claude/settings.json` file:
|
|
639
|
-
|
|
640
|
-
```json
|
|
641
|
-
{
|
|
642
|
-
"env": {
|
|
643
|
-
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
644
|
-
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
645
|
-
"ANTHROPIC_MODEL": "gpt-5.4",
|
|
646
|
-
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
|
|
647
|
-
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
|
|
648
|
-
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
649
|
-
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
650
|
-
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
651
|
-
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
652
|
-
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
653
|
-
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
654
|
-
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
655
|
-
},
|
|
656
|
-
"permissions": {
|
|
657
|
-
"deny": [
|
|
658
|
-
"WebSearch",
|
|
659
|
-
"mcp__ide__executeCode"
|
|
660
|
-
]
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
```
|
|
664
|
-
|
|
665
|
-
- Replace `ANTHROPIC_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_HAIKU_MODEL` according to your needs. After configuration, please install the claude code plugin [Plugin Integrations](#plugin-integrations). If configuring the claude model, it is recommended to set all model configurations the same, so as to remain consistent with github-copilot claude agent behavior.
|
|
666
|
-
- Setting CLAUDE_CODE_ATTRIBUTION_HEADER to 0 can prevent Claude code from adding billing and version information in system prompts, thereby avoiding prompt cache invalidation.
|
|
667
|
-
- Turning off CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION and CLAUDE_CODE_ENABLE_AWAY_SUMMARY can prevent quota from being consumed unnecessarily.
|
|
668
|
-
- Permissions deny WebSearch because the GitHub Copilot API does not support natie websearch (some gpt models support websearch, but the current project has not adapted websearch); it is recommended to install the mcp mcp_server_fetch tool or other search tools as alternatives..
|
|
669
|
-
- If using a non-Claude model, do not enable ENABLE_TOOL_SEARCH. If using the Claude model, can enable ENABLE_TOOL_SEARCH. The current Claude Code uses the client tool search mode. In this mode, loading defer tools requires an additional request each time.
|
|
670
|
-
|
|
671
|
-
You can find more options here: [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
672
|
-
|
|
673
|
-
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)
|
|
674
|
-
|
|
675
663
|
## Plugin Integrations
|
|
676
664
|
|
|
677
665
|
Plugin integrations are available for Claude Code and opencode.
|
|
@@ -726,6 +714,35 @@ Or manually create the file at `~/.config/opencode/plugins/subagent-marker.js` w
|
|
|
726
714
|
|
|
727
715
|
The plugin hooks into `session.created`, `session.deleted`, `chat.message`, and `chat.headers` events to provide seamless subagent marker functionality.
|
|
728
716
|
|
|
717
|
+
## Using the Usage Viewer
|
|
718
|
+
|
|
719
|
+
After starting the server, a URL to the Copilot Usage Dashboard will be displayed in your console. This dashboard is a web interface for monitoring your API usage.
|
|
720
|
+
|
|
721
|
+
1. Start the server. For example, using npx:
|
|
722
|
+
```sh
|
|
723
|
+
npx @jeffreycao/copilot-api@latest start
|
|
724
|
+
```
|
|
725
|
+
2. The server will output a URL to the usage viewer. Copy and paste this URL into your browser. It will look something like this:
|
|
726
|
+
`http://localhost:4141/usage-viewer?endpoint=http://localhost:4141/usage`
|
|
727
|
+
- If you use the `start.bat` script on Windows, this page will open automatically.
|
|
728
|
+
|
|
729
|
+
The dashboard provides a user-friendly interface to view your Copilot usage data:
|
|
730
|
+
|
|
731
|
+
> Token usage history requires Bun or Node.js >= 22.13.0. On Node.js < 22.13.0, the server runs normally but token usage storage is disabled.
|
|
732
|
+
|
|
733
|
+
- **API Endpoint URL**: The dashboard is pre-configured to fetch data from your local server endpoint via the URL query parameter. You can change this URL to point to any other compatible API endpoint.
|
|
734
|
+
- **Fetch Data**: Click the "Fetch" button to load or refresh the usage data. The dashboard will automatically fetch data on load.
|
|
735
|
+
- **Usage Quotas**: View a summary of your usage quotas for different services like Chat and Completions, displayed with progress bars for a quick overview.
|
|
736
|
+
- **Detailed Information**: See the full JSON response from the API for a detailed breakdown of all available usage statistics.
|
|
737
|
+
- **URL-based Configuration**: You can also specify the API endpoint directly in the URL using a query parameter. This is useful for bookmarks or sharing links. For example:
|
|
738
|
+
`http://localhost:4141/usage-viewer?endpoint=http://your-api-server/usage`
|
|
739
|
+
|
|
740
|
+
### Usage Viewer Screenshot
|
|
741
|
+
|
|
742
|
+
<p align="center">
|
|
743
|
+
<img src="./docs/screenshots/usage-viewer.png" alt="Copilot API usage viewer" width="900" />
|
|
744
|
+
</p>
|
|
745
|
+
|
|
729
746
|
## Running from Source
|
|
730
747
|
|
|
731
748
|
The project can be run from source in several ways:
|
package/README.zh-CN.md
CHANGED
|
@@ -178,6 +178,15 @@ https://github.com/caozhiyuan/copilot-api/releases
|
|
|
178
178
|
|
|
179
179
|
下载对应平台的安装包后,在应用内登录、选择端口并启动服务,再把你的客户端指向应用里显示的本地端点即可。发布版桌面应用使用随包内置的 Electron 运行时,正常使用不需要额外安装 Node.js;token usage 历史记录会在该内置运行时支持 SQLite 时启用。
|
|
180
180
|
|
|
181
|
+
### 桌面应用截图
|
|
182
|
+
|
|
183
|
+
下面展示了桌面应用中的首页、Token 用量统计页面:
|
|
184
|
+
|
|
185
|
+
<p align="center">
|
|
186
|
+
<img src="./docs/screenshots/desktop-dashboard.png" alt="Copilot API 桌面应用首页" width="49%" />
|
|
187
|
+
<img src="./docs/screenshots/desktop-token-usage.png" alt="Copilot API 桌面应用 Token 用量页" width="49%" />
|
|
188
|
+
</p>
|
|
189
|
+
|
|
181
190
|
## 配合 Docker 使用
|
|
182
191
|
|
|
183
192
|
构建镜像:
|
|
@@ -356,6 +365,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
|
|
|
356
365
|
},
|
|
357
366
|
"useFunctionApplyPatch": true,
|
|
358
367
|
"useMessagesApi": true,
|
|
368
|
+
"useResponsesApiWebSocket": true,
|
|
359
369
|
"useResponsesApiWebSearch": true
|
|
360
370
|
}
|
|
361
371
|
```
|
|
@@ -380,6 +390,7 @@ Copilot API 现在使用子命令结构,主要命令包括:
|
|
|
380
390
|
- **modelReasoningEfforts:** 按模型配置发送到 Copilot Responses API 的 `reasoning.effort`。可选值包括 `none`、`minimal`、`low`、`medium`、`high` 和 `xhigh`。若某模型未配置,则默认使用 `high`。
|
|
381
391
|
- **useFunctionApplyPatch:** 当为 `true` 时,服务端会把 Responses payload 中任何名为 `apply_patch` 的自定义工具转换为 OpenAI 风格的函数工具(`type: "function"`),并附带参数 schema,从而让 assistant 可以通过 function-calling 语义调用它来编辑文件。若设为 `false`,则保持工具原样。默认值为 `true`。
|
|
382
392
|
- **useMessagesApi:** 当为 `true` 时,支持 Copilot 原生 `/v1/messages` 的 Claude 系模型会走 Messages API;否则回退到 `/chat/completions`。设为 `false` 可禁用 Messages API 路由,始终使用 `/chat/completions`。默认值为 `true`。
|
|
393
|
+
- **useResponsesApiWebSocket:** 当为 `true` 时,Responses API 请求会优先对声明了 `ws:/responses` 的模型使用 Copilot websocket transport;仅声明 `/responses` 的模型仍走 HTTP。设为 `false` 可禁用 websocket 路由,并在模型支持 `/responses` 时使用 HTTP `/responses`。默认值为 `true`。
|
|
383
394
|
- **useResponsesApiWebSearch:** 当为 `true` 时,服务端会保留 Responses API 中 `type: "web_search"` 的工具并透传到上游。设为 `false` 则会从 `/responses` payload 中移除这些工具。默认值为 `true`。
|
|
384
395
|
- **claudeTokenMultiplier:** 用于 Claude `/v1/messages/count_tokens` 请求在本地走 GPT tokenizer 估算时的乘数。默认值为 `1.15`。如果你的客户端仍然过晚触发上下文压缩,可以适当调大。这个配置只会在代理本地估算 Claude token 时生效;如果已经配置 `anthropicApiKey` 且 Anthropic token counting 调用成功,则会直接返回 Anthropic 的精确计数,不会使用这个乘数。
|
|
385
396
|
- **anthropicApiKey:** 用于精确 Claude token 计数的 Anthropic API key(参见下方 [精确的 Claude Token 计数](#accurate-claude-token-counting))。也可通过环境变量 `ANTHROPIC_API_KEY` 设置。若未配置,则回退到 GPT tokenizer 估算。
|
|
@@ -504,6 +515,67 @@ npx @jeffreycao/copilot-api@latest --api-home=/custom/path --oauth-app=opencode
|
|
|
504
515
|
bunx --bun @jeffreycao/copilot-api@latest start
|
|
505
516
|
```
|
|
506
517
|
|
|
518
|
+
## 与 Claude Code 一起使用
|
|
519
|
+
|
|
520
|
+
这个代理可以为 [Claude Code](https://docs.anthropic.com/en/claude-code) 提供后端能力。Claude Code 是 Anthropic 提供的实验性面向开发者的对话式 AI 助手。
|
|
521
|
+
|
|
522
|
+
有两种方式可以把 Claude Code 配置为使用这个代理:
|
|
523
|
+
|
|
524
|
+
### 通过 `--claude-code` 标志进行交互式配置
|
|
525
|
+
|
|
526
|
+
执行带 `--claude-code` 的 `start` 命令开始:
|
|
527
|
+
|
|
528
|
+
```sh
|
|
529
|
+
npx @jeffreycao/copilot-api@latest start --claude-code
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
你会被提示选择一个主模型,以及一个用于后台任务的 “small, fast” 模型。选择完成后,会有一条命令被复制到剪贴板中。该命令会设置 Claude Code 使用该代理所需的环境变量。
|
|
533
|
+
|
|
534
|
+
在新的终端中粘贴并执行这条命令,即可启动 Claude Code。
|
|
535
|
+
|
|
536
|
+
<a id="manual-configuration-with-settingsjson"></a>
|
|
537
|
+
|
|
538
|
+
### 通过 `settings.json` 手动配置
|
|
539
|
+
|
|
540
|
+
另一种方式是在项目根目录中创建 `.claude/settings.json` 文件,并写入 Claude Code 所需的环境变量。这样你就不需要每次都运行交互式配置了。
|
|
541
|
+
|
|
542
|
+
下面是一个 `.claude/settings.json` 示例:
|
|
543
|
+
|
|
544
|
+
```json
|
|
545
|
+
{
|
|
546
|
+
"env": {
|
|
547
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
548
|
+
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
549
|
+
"ANTHROPIC_MODEL": "gpt-5.4",
|
|
550
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
|
|
551
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
|
|
552
|
+
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
553
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
554
|
+
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
555
|
+
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
556
|
+
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
557
|
+
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
558
|
+
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
559
|
+
},
|
|
560
|
+
"permissions": {
|
|
561
|
+
"deny": [
|
|
562
|
+
"WebSearch",
|
|
563
|
+
"mcp__ide__executeCode"
|
|
564
|
+
]
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
- 请根据需要替换 `ANTHROPIC_MODEL`、`ANTHROPIC_DEFAULT_OPUS_MODEL`、`ANTHROPIC_DEFAULT_SONNET_MODEL` 和 `ANTHROPIC_DEFAULT_HAIKU_MODEL`。配置完成后,请安装 claude code 插件,见 [插件集成](#plugin-integrations)。如果你配置的是 Claude 模型,建议把这些模型配置都设为相同,以保持与 github-copilot claude agent 行为一致。
|
|
570
|
+
- 将 `CLAUDE_CODE_ATTRIBUTION_HEADER` 设为 `0` 可以阻止 Claude Code 在 system prompt 中附加计费和版本信息,从而避免 prompt cache 失效。
|
|
571
|
+
- 关闭 `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION` 和 `CLAUDE_CODE_ENABLE_AWAY_SUMMARY` 可以避免不必要地消耗额度。
|
|
572
|
+
- `permissions` 中禁止 `WebSearch`,因为 GitHub Copilot API 不支持原生 web search(部分 gpt 模型支持 websearch,但本项目目前尚未适配);建议安装 mcp 的 `mcp_server_fetch` 工具或其他搜索工具作为替代。
|
|
573
|
+
- 如果使用的不是 Claude 模型,请不要启用 `ENABLE_TOOL_SEARCH`。如果使用的是 Claude 模型,则可以启用 `ENABLE_TOOL_SEARCH`。当前 Claude Code 使用的是客户端 tool search 模式,在该模式下每次加载 defer tools 都需要额外请求一次。
|
|
574
|
+
|
|
575
|
+
更多选项见:[Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
576
|
+
|
|
577
|
+
也可以参考 IDE 集成说明:[Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
578
|
+
|
|
507
579
|
## 与 OpenCode 一起使用
|
|
508
580
|
|
|
509
581
|
OpenCode 已经有直接的 GitHub Copilot provider。本节适用于你希望让 OpenCode 通过 `@ai-sdk/anthropic` 指向这个代理,并复用本 README 前面提到的 agent 行为时。
|
|
@@ -594,90 +666,6 @@ npx @jeffreycao/copilot-api@latest --oauth-app=opencode start
|
|
|
594
666
|
- `model`、`small_model` 与 `agent.*.model` 让你可以把 `gpt-5.4` 用于 build/plan,同时把探索和后台工作路由到 `gpt-5-mini`。
|
|
595
667
|
- 如果你在此代理中启用了 `auth.apiKeys`,请把 `dummy` 替换为真实 key;否则任意占位值都可以。
|
|
596
668
|
|
|
597
|
-
## 使用量查看器
|
|
598
|
-
|
|
599
|
-
服务启动后,控制台会输出一个 Copilot 使用量看板 URL。这个看板是一个用于监控 API 用量的 Web 界面。
|
|
600
|
-
|
|
601
|
-
1. 启动服务。例如使用 npx:
|
|
602
|
-
```sh
|
|
603
|
-
npx @jeffreycao/copilot-api@latest start
|
|
604
|
-
```
|
|
605
|
-
2. 服务会输出一个 usage viewer 的 URL。将它复制到浏览器中打开,形式大致如下:
|
|
606
|
-
`http://localhost:4141/usage-viewer?endpoint=http://localhost:4141/usage`
|
|
607
|
-
- 如果你在 Windows 上使用 `start.bat` 脚本,这个页面会自动打开。
|
|
608
|
-
|
|
609
|
-
看板提供了更易读的 Copilot 用量视图:
|
|
610
|
-
|
|
611
|
-
> token usage 历史记录需要 Bun 或 Node.js >= 22.13.0。Node.js < 22.13.0 时服务会正常运行,但 token usage 存储会被禁用。
|
|
612
|
-
|
|
613
|
-
- **API Endpoint URL**:看板会通过 URL 查询参数,默认从本地服务端点拉取数据。你也可以把这个 URL 改成任意其他兼容 API 端点。
|
|
614
|
-
- **Fetch Data**:点击 “Fetch” 按钮即可加载或刷新使用数据。页面首次加载时也会自动拉取。
|
|
615
|
-
- **Usage Quotas**:使用进度条汇总展示 Chat、Completions 等不同服务的额度使用情况。
|
|
616
|
-
- **Detailed Information**:可查看 API 返回的完整 JSON,以便深入分析所有可用统计信息。
|
|
617
|
-
- **URL-based Configuration**:你也可以直接通过 URL 查询参数指定 API 端点,便于收藏或分享。例如:
|
|
618
|
-
`http://localhost:4141/usage-viewer?endpoint=http://your-api-server/usage`
|
|
619
|
-
|
|
620
|
-
## 与 Claude Code 一起使用
|
|
621
|
-
|
|
622
|
-
这个代理可以为 [Claude Code](https://docs.anthropic.com/en/claude-code) 提供后端能力。Claude Code 是 Anthropic 提供的实验性面向开发者的对话式 AI 助手。
|
|
623
|
-
|
|
624
|
-
有两种方式可以把 Claude Code 配置为使用这个代理:
|
|
625
|
-
|
|
626
|
-
### 通过 `--claude-code` 标志进行交互式配置
|
|
627
|
-
|
|
628
|
-
执行带 `--claude-code` 的 `start` 命令开始:
|
|
629
|
-
|
|
630
|
-
```sh
|
|
631
|
-
npx @jeffreycao/copilot-api@latest start --claude-code
|
|
632
|
-
```
|
|
633
|
-
|
|
634
|
-
你会被提示选择一个主模型,以及一个用于后台任务的 “small, fast” 模型。选择完成后,会有一条命令被复制到剪贴板中。该命令会设置 Claude Code 使用该代理所需的环境变量。
|
|
635
|
-
|
|
636
|
-
在新的终端中粘贴并执行这条命令,即可启动 Claude Code。
|
|
637
|
-
|
|
638
|
-
<a id="manual-configuration-with-settingsjson"></a>
|
|
639
|
-
|
|
640
|
-
### 通过 `settings.json` 手动配置
|
|
641
|
-
|
|
642
|
-
另一种方式是在项目根目录中创建 `.claude/settings.json` 文件,并写入 Claude Code 所需的环境变量。这样你就不需要每次都运行交互式配置了。
|
|
643
|
-
|
|
644
|
-
下面是一个 `.claude/settings.json` 示例:
|
|
645
|
-
|
|
646
|
-
```json
|
|
647
|
-
{
|
|
648
|
-
"env": {
|
|
649
|
-
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
650
|
-
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
651
|
-
"ANTHROPIC_MODEL": "gpt-5.4",
|
|
652
|
-
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.4",
|
|
653
|
-
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
|
|
654
|
-
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
655
|
-
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
656
|
-
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
657
|
-
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
658
|
-
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
659
|
-
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
660
|
-
"CLAUDE_PLUGIN_ENABLE_QUESTION_RULES": "true"
|
|
661
|
-
},
|
|
662
|
-
"permissions": {
|
|
663
|
-
"deny": [
|
|
664
|
-
"WebSearch",
|
|
665
|
-
"mcp__ide__executeCode"
|
|
666
|
-
]
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
```
|
|
670
|
-
|
|
671
|
-
- 请根据需要替换 `ANTHROPIC_MODEL`、`ANTHROPIC_DEFAULT_OPUS_MODEL`、`ANTHROPIC_DEFAULT_SONNET_MODEL` 和 `ANTHROPIC_DEFAULT_HAIKU_MODEL`。配置完成后,请安装 claude code 插件,见 [插件集成](#plugin-integrations)。如果你配置的是 Claude 模型,建议把这些模型配置都设为相同,以保持与 github-copilot claude agent 行为一致。
|
|
672
|
-
- 将 `CLAUDE_CODE_ATTRIBUTION_HEADER` 设为 `0` 可以阻止 Claude Code 在 system prompt 中附加计费和版本信息,从而避免 prompt cache 失效。
|
|
673
|
-
- 关闭 `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION` 和 `CLAUDE_CODE_ENABLE_AWAY_SUMMARY` 可以避免不必要地消耗额度。
|
|
674
|
-
- `permissions` 中禁止 `WebSearch`,因为 GitHub Copilot API 不支持原生 web search(部分 gpt 模型支持 websearch,但本项目目前尚未适配);建议安装 mcp 的 `mcp_server_fetch` 工具或其他搜索工具作为替代。
|
|
675
|
-
- 如果使用的不是 Claude 模型,请不要启用 `ENABLE_TOOL_SEARCH`。如果使用的是 Claude 模型,则可以启用 `ENABLE_TOOL_SEARCH`。当前 Claude Code 使用的是客户端 tool search 模式,在该模式下每次加载 defer tools 都需要额外请求一次。
|
|
676
|
-
|
|
677
|
-
更多选项见:[Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
678
|
-
|
|
679
|
-
也可以参考 IDE 集成说明:[Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
680
|
-
|
|
681
669
|
<a id="plugin-integrations"></a>
|
|
682
670
|
|
|
683
671
|
## 插件集成
|
|
@@ -734,6 +722,35 @@ cp .opencode/plugins/subagent-marker.js ~/.config/opencode/plugins/
|
|
|
734
722
|
|
|
735
723
|
该插件会挂接到 `session.created`、`session.deleted`、`chat.message` 和 `chat.headers` 事件上,以无缝提供 subagent marker 能力。
|
|
736
724
|
|
|
725
|
+
## 使用量查看器
|
|
726
|
+
|
|
727
|
+
服务启动后,控制台会输出一个 Copilot 使用量看板 URL。这个看板是一个用于监控 API 用量的 Web 界面。
|
|
728
|
+
|
|
729
|
+
1. 启动服务。例如使用 npx:
|
|
730
|
+
```sh
|
|
731
|
+
npx @jeffreycao/copilot-api@latest start
|
|
732
|
+
```
|
|
733
|
+
2. 服务会输出一个 usage viewer 的 URL。将它复制到浏览器中打开,形式大致如下:
|
|
734
|
+
`http://localhost:4141/usage-viewer?endpoint=http://localhost:4141/usage`
|
|
735
|
+
- 如果你在 Windows 上使用 `start.bat` 脚本,这个页面会自动打开。
|
|
736
|
+
|
|
737
|
+
看板提供了更易读的 Copilot 用量视图:
|
|
738
|
+
|
|
739
|
+
> token usage 历史记录需要 Bun 或 Node.js >= 22.13.0。Node.js < 22.13.0 时服务会正常运行,但 token usage 存储会被禁用。
|
|
740
|
+
|
|
741
|
+
- **API Endpoint URL**:看板会通过 URL 查询参数,默认从本地服务端点拉取数据。你也可以把这个 URL 改成任意其他兼容 API 端点。
|
|
742
|
+
- **Fetch Data**:点击 “Fetch” 按钮即可加载或刷新使用数据。页面首次加载时也会自动拉取。
|
|
743
|
+
- **Usage Quotas**:使用进度条汇总展示 Chat、Completions 等不同服务的额度使用情况。
|
|
744
|
+
- **Detailed Information**:可查看 API 返回的完整 JSON,以便深入分析所有可用统计信息。
|
|
745
|
+
- **URL-based Configuration**:你也可以直接通过 URL 查询参数指定 API 端点,便于收藏或分享。例如:
|
|
746
|
+
`http://localhost:4141/usage-viewer?endpoint=http://your-api-server/usage`
|
|
747
|
+
|
|
748
|
+
### Usage Viewer 截图
|
|
749
|
+
|
|
750
|
+
<p align="center">
|
|
751
|
+
<img src="./docs/screenshots/usage-viewer.png" alt="Copilot API Usage Viewer 页面" width="900" />
|
|
752
|
+
</p>
|
|
753
|
+
|
|
737
754
|
## 从源码运行
|
|
738
755
|
|
|
739
756
|
本项目可以通过多种方式从源码运行:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as ensurePaths, t as PATHS } from "./paths-DC-mqCY3.js";
|
|
2
|
-
import {
|
|
3
|
-
import { r as setupGitHubToken } from "./token-
|
|
2
|
+
import { I as state } from "./utils-C5ej0z8n.js";
|
|
3
|
+
import { r as setupGitHubToken } from "./token-BQlDdqtI.js";
|
|
4
4
|
import { defineCommand } from "citty";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
//#region src/auth.ts
|
|
@@ -42,4 +42,4 @@ const auth = defineCommand({
|
|
|
42
42
|
//#endregion
|
|
43
43
|
export { auth };
|
|
44
44
|
|
|
45
|
-
//# sourceMappingURL=auth-
|
|
45
|
+
//# sourceMappingURL=auth-D7YCTWpx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-
|
|
1
|
+
{"version":3,"file":"auth-D7YCTWpx.js","names":[],"sources":["../src/auth.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { defineCommand } from \"citty\"\nimport consola from \"consola\"\n\nimport { PATHS, ensurePaths } from \"./lib/paths\"\nimport { state } from \"./lib/state\"\nimport { setupGitHubToken } from \"./lib/token\"\n\ninterface RunAuthOptions {\n verbose: boolean\n showToken: boolean\n}\n\nexport async function runAuth(options: RunAuthOptions): Promise<void> {\n if (options.verbose) {\n consola.level = 5\n consola.info(\"Verbose logging enabled\")\n }\n\n state.showToken = options.showToken\n\n await ensurePaths()\n await setupGitHubToken({ force: true })\n consola.success(\"GitHub token written to\", PATHS.GITHUB_TOKEN_PATH)\n}\n\nexport const auth = defineCommand({\n meta: {\n name: \"auth\",\n description: \"Run GitHub auth flow without running the server\",\n },\n args: {\n verbose: {\n alias: \"v\",\n type: \"boolean\",\n default: false,\n description: \"Enable verbose logging\",\n },\n \"show-token\": {\n type: \"boolean\",\n default: false,\n description: \"Show GitHub token on auth\",\n },\n },\n run({ args }) {\n return runAuth({\n verbose: args.verbose,\n showToken: args[\"show-token\"],\n })\n },\n})\n"],"mappings":";;;;;;AAcA,eAAsB,QAAQ,SAAwC;CACpE,IAAI,QAAQ,SAAS;EACnB,QAAQ,QAAQ;EAChB,QAAQ,KAAK,0BAA0B;;CAGzC,MAAM,YAAY,QAAQ;CAE1B,MAAM,aAAa;CACnB,MAAM,iBAAiB,EAAE,OAAO,MAAM,CAAC;CACvC,QAAQ,QAAQ,2BAA2B,MAAM,kBAAkB;;AAGrE,MAAa,OAAO,cAAc;CAChC,MAAM;EACJ,MAAM;EACN,aAAa;EACd;CACD,MAAM;EACJ,SAAS;GACP,OAAO;GACP,MAAM;GACN,SAAS;GACT,aAAa;GACd;EACD,cAAc;GACZ,MAAM;GACN,SAAS;GACT,aAAa;GACd;EACF;CACD,IAAI,EAAE,QAAQ;EACZ,OAAO,QAAQ;GACb,SAAS,KAAK;GACd,WAAW,KAAK;GACjB,CAAC;;CAEL,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as ensurePaths } from "./paths-DC-mqCY3.js";
|
|
2
|
-
import { f as getCopilotUsage } from "./utils-
|
|
3
|
-
import { r as setupGitHubToken } from "./token-
|
|
2
|
+
import { f as getCopilotUsage } from "./utils-C5ej0z8n.js";
|
|
3
|
+
import { r as setupGitHubToken } from "./token-BQlDdqtI.js";
|
|
4
4
|
import { defineCommand } from "citty";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
//#region src/check-usage.ts
|
|
@@ -40,4 +40,4 @@ const checkUsage = defineCommand({
|
|
|
40
40
|
//#endregion
|
|
41
41
|
export { checkUsage };
|
|
42
42
|
|
|
43
|
-
//# sourceMappingURL=check-usage-
|
|
43
|
+
//# sourceMappingURL=check-usage-Dgg0nNEw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-usage-
|
|
1
|
+
{"version":3,"file":"check-usage-Dgg0nNEw.js","names":[],"sources":["../src/check-usage.ts"],"sourcesContent":["import { defineCommand } from \"citty\"\nimport consola from \"consola\"\n\nimport { ensurePaths } from \"./lib/paths\"\nimport { setupGitHubToken } from \"./lib/token\"\nimport {\n getCopilotUsage,\n type QuotaDetail,\n} from \"./services/github/get-copilot-usage\"\n\nexport const checkUsage = defineCommand({\n meta: {\n name: \"check-usage\",\n description: \"Show current GitHub Copilot usage/quota information\",\n },\n async run() {\n await ensurePaths()\n await setupGitHubToken()\n try {\n const usage = await getCopilotUsage()\n const premium = usage.quota_snapshots.premium_interactions\n const premiumTotal = premium.entitlement\n const premiumUsed = premiumTotal - premium.remaining\n const premiumPercentUsed =\n premiumTotal > 0 ? (premiumUsed / premiumTotal) * 100 : 0\n const premiumPercentRemaining = premium.percent_remaining\n\n // Helper to summarize a quota snapshot\n function summarizeQuota(name: string, snap: QuotaDetail | undefined) {\n if (!snap) return `${name}: N/A`\n const total = snap.entitlement\n const used = total - snap.remaining\n const percentUsed = total > 0 ? (used / total) * 100 : 0\n const percentRemaining = snap.percent_remaining\n return `${name}: ${used}/${total} used (${percentUsed.toFixed(1)}% used, ${percentRemaining.toFixed(1)}% remaining)`\n }\n\n const premiumLine = `Premium: ${premiumUsed}/${premiumTotal} used (${premiumPercentUsed.toFixed(1)}% used, ${premiumPercentRemaining.toFixed(1)}% remaining)`\n const chatLine = summarizeQuota(\"Chat\", usage.quota_snapshots.chat)\n const completionsLine = summarizeQuota(\n \"Completions\",\n usage.quota_snapshots.completions,\n )\n\n consola.box(\n `Copilot Usage (plan: ${usage.copilot_plan})\\n`\n + `Quota resets: ${usage.quota_reset_date}\\n`\n + `\\nQuotas:\\n`\n + ` ${premiumLine}\\n`\n + ` ${chatLine}\\n`\n + ` ${completionsLine}`,\n )\n } catch (err) {\n consola.error(\"Failed to fetch Copilot usage:\", err)\n process.exit(1)\n }\n },\n})\n"],"mappings":";;;;;;AAUA,MAAa,aAAa,cAAc;CACtC,MAAM;EACJ,MAAM;EACN,aAAa;EACd;CACD,MAAM,MAAM;EACV,MAAM,aAAa;EACnB,MAAM,kBAAkB;EACxB,IAAI;GACF,MAAM,QAAQ,MAAM,iBAAiB;GACrC,MAAM,UAAU,MAAM,gBAAgB;GACtC,MAAM,eAAe,QAAQ;GAC7B,MAAM,cAAc,eAAe,QAAQ;GAC3C,MAAM,qBACJ,eAAe,IAAK,cAAc,eAAgB,MAAM;GAC1D,MAAM,0BAA0B,QAAQ;GAGxC,SAAS,eAAe,MAAc,MAA+B;IACnE,IAAI,CAAC,MAAM,OAAO,GAAG,KAAK;IAC1B,MAAM,QAAQ,KAAK;IACnB,MAAM,OAAO,QAAQ,KAAK;IAC1B,MAAM,cAAc,QAAQ,IAAK,OAAO,QAAS,MAAM;IACvD,MAAM,mBAAmB,KAAK;IAC9B,OAAO,GAAG,KAAK,IAAI,KAAK,GAAG,MAAM,SAAS,YAAY,QAAQ,EAAE,CAAC,UAAU,iBAAiB,QAAQ,EAAE,CAAC;;GAGzG,MAAM,cAAc,YAAY,YAAY,GAAG,aAAa,SAAS,mBAAmB,QAAQ,EAAE,CAAC,UAAU,wBAAwB,QAAQ,EAAE,CAAC;GAChJ,MAAM,WAAW,eAAe,QAAQ,MAAM,gBAAgB,KAAK;GACnE,MAAM,kBAAkB,eACtB,eACA,MAAM,gBAAgB,YACvB;GAED,QAAQ,IACN,wBAAwB,MAAM,aAAa,mBACtB,MAAM,iBAAiB,iBAEnC,YAAY,MACZ,SAAS,MACT,kBACV;WACM,KAAK;GACZ,QAAQ,MAAM,kCAAkC,IAAI;GACpD,QAAQ,KAAK,EAAE;;;CAGpB,CAAC"}
|
package/dist/main.js
CHANGED
|
@@ -39,10 +39,10 @@ if (typeof args["api-home"] === "string") process.env.COPILOT_API_HOME = args["a
|
|
|
39
39
|
if (typeof args["oauth-app"] === "string") process.env.COPILOT_API_OAUTH_APP = args["oauth-app"];
|
|
40
40
|
if (typeof args["enterprise-url"] === "string") process.env.COPILOT_API_ENTERPRISE_URL = args["enterprise-url"];
|
|
41
41
|
bindElectronFetch();
|
|
42
|
-
const { auth } = await import("./auth-
|
|
43
|
-
const { checkUsage } = await import("./check-usage-
|
|
42
|
+
const { auth } = await import("./auth-D7YCTWpx.js");
|
|
43
|
+
const { checkUsage } = await import("./check-usage-Dgg0nNEw.js");
|
|
44
44
|
const { debug } = await import("./debug-C_TBkyUw.js");
|
|
45
|
-
const { start } = await import("./start-
|
|
45
|
+
const { start } = await import("./start-1KA2mHVS.js");
|
|
46
46
|
await runMain(defineCommand({
|
|
47
47
|
meta: {
|
|
48
48
|
name: "copilot-api",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { t as PATHS } from "./paths-DC-mqCY3.js";
|
|
2
2
|
import consola from "consola";
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
+
import { Agent, ProxyAgent, setGlobalDispatcher } from "undici";
|
|
5
|
+
import { getProxyForUrl } from "proxy-from-env";
|
|
4
6
|
//#region src/lib/config.ts
|
|
5
7
|
const gpt5ExplorationPrompt = `## Exploration and reading files
|
|
6
8
|
- **Think first.** Before any tool call, decide ALL files/resources you will need.
|
|
@@ -48,6 +50,7 @@ const defaultConfig = {
|
|
|
48
50
|
},
|
|
49
51
|
useFunctionApplyPatch: true,
|
|
50
52
|
useMessagesApi: true,
|
|
53
|
+
useResponsesApiWebSocket: true,
|
|
51
54
|
useResponsesApiWebSearch: true
|
|
52
55
|
};
|
|
53
56
|
let cachedConfig = null;
|
|
@@ -117,7 +120,7 @@ function mergeConfigWithDefaults() {
|
|
|
117
120
|
return mergedConfig;
|
|
118
121
|
}
|
|
119
122
|
function getConfig() {
|
|
120
|
-
cachedConfig ??= readConfigFromDisk();
|
|
123
|
+
cachedConfig ??= mergeDefaultConfig(readConfigFromDisk()).mergedConfig;
|
|
121
124
|
return cachedConfig;
|
|
122
125
|
}
|
|
123
126
|
function getExtraPromptForModel(model) {
|
|
@@ -179,6 +182,9 @@ function getProviderConfig(name) {
|
|
|
179
182
|
function isMessagesApiEnabled() {
|
|
180
183
|
return getConfig().useMessagesApi ?? true;
|
|
181
184
|
}
|
|
185
|
+
function isResponsesApiWebSocketEnabled() {
|
|
186
|
+
return getConfig().useResponsesApiWebSocket ?? true;
|
|
187
|
+
}
|
|
182
188
|
function getAnthropicApiKey() {
|
|
183
189
|
return getConfig().anthropicApiKey ?? process.env.ANTHROPIC_API_KEY ?? void 0;
|
|
184
190
|
}
|
|
@@ -189,6 +195,59 @@ function getClaudeTokenMultiplier() {
|
|
|
189
195
|
return getConfig().claudeTokenMultiplier ?? 1.15;
|
|
190
196
|
}
|
|
191
197
|
//#endregion
|
|
192
|
-
|
|
198
|
+
//#region src/lib/proxy.ts
|
|
199
|
+
let proxyEnvDispatcher;
|
|
200
|
+
function getProxyEnvDispatcher() {
|
|
201
|
+
return proxyEnvDispatcher;
|
|
202
|
+
}
|
|
203
|
+
function initProxyFromEnv() {
|
|
204
|
+
try {
|
|
205
|
+
const direct = new Agent();
|
|
206
|
+
const proxies = /* @__PURE__ */ new Map();
|
|
207
|
+
proxyEnvDispatcher = {
|
|
208
|
+
dispatch(options, handler) {
|
|
209
|
+
try {
|
|
210
|
+
const origin = typeof options.origin === "string" ? new URL(options.origin) : options.origin;
|
|
211
|
+
const raw = getProxyForUrl(origin.toString());
|
|
212
|
+
const proxyUrl = raw && raw.length > 0 ? raw : void 0;
|
|
213
|
+
if (!proxyUrl) {
|
|
214
|
+
consola.debug(`HTTP proxy bypass: ${origin.hostname}`);
|
|
215
|
+
return direct.dispatch(options, handler);
|
|
216
|
+
}
|
|
217
|
+
let agent = proxies.get(proxyUrl);
|
|
218
|
+
if (!agent) {
|
|
219
|
+
agent = new ProxyAgent(proxyUrl);
|
|
220
|
+
proxies.set(proxyUrl, agent);
|
|
221
|
+
}
|
|
222
|
+
let label = proxyUrl;
|
|
223
|
+
try {
|
|
224
|
+
const u = new URL(proxyUrl);
|
|
225
|
+
label = `${u.protocol}//${u.host}`;
|
|
226
|
+
} catch {}
|
|
227
|
+
consola.debug(`HTTP proxy route: ${origin.hostname} via ${label}`);
|
|
228
|
+
return agent.dispatch(options, handler);
|
|
229
|
+
} catch {
|
|
230
|
+
return direct.dispatch(options, handler);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
close() {
|
|
234
|
+
return direct.close();
|
|
235
|
+
},
|
|
236
|
+
destroy() {
|
|
237
|
+
return direct.destroy();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
if (typeof Bun !== "undefined") {
|
|
241
|
+
consola.debug("WebSocket proxy configured from environment (per-URL)");
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
setGlobalDispatcher(proxyEnvDispatcher);
|
|
245
|
+
consola.debug("HTTP proxy configured from environment (per-URL)");
|
|
246
|
+
} catch (err) {
|
|
247
|
+
consola.debug("Proxy setup skipped:", err);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
export { getConfig as a, getReasoningEffortForModel as c, isResponsesApiContextManagementModel as d, isResponsesApiWebSearchEnabled as f, getClaudeTokenMultiplier as i, getSmallModel as l, mergeConfigWithDefaults as m, initProxyFromEnv as n, getExtraPromptForModel as o, isResponsesApiWebSocketEnabled as p, getAnthropicApiKey as r, getProviderConfig as s, getProxyEnvDispatcher as t, isMessagesApiEnabled as u };
|
|
193
252
|
|
|
194
|
-
//# sourceMappingURL=
|
|
253
|
+
//# sourceMappingURL=proxy-De0Po8kG.js.map
|