copilot-api-plus 1.0.57 → 1.0.58

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 CHANGED
@@ -5,9 +5,9 @@
5
5
 
6
6
  [English](README.en.md) | 简体中文
7
7
 
8
- > A proxy that converts GitHub Copilot, OpenCode Zen, and Google Antigravity into OpenAI & Anthropic compatible APIs. Works with Claude Code, opencode, and more.
8
+ > A proxy that converts GitHub Copilot into OpenAI & Anthropic compatible APIs. Works with Claude Code, opencode, and more.
9
9
 
10
- 将 GitHub Copilot、OpenCode Zen、Google Antigravity 等 AI 服务转换为 **OpenAI** 和 **Anthropic** 兼容 API,支持与 [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview)、[opencode](https://github.com/sst/opencode) 等工具无缝集成。
10
+ 将 GitHub Copilot 转换为 **OpenAI** 和 **Anthropic** 兼容 API,支持与 [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview)、[opencode](https://github.com/sst/opencode) 等工具无缝集成。
11
11
 
12
12
  ---
13
13
 
@@ -17,8 +17,6 @@
17
17
  - [快速开始](#-快速开始)
18
18
  - [详细使用指南](#-详细使用指南)
19
19
  - [GitHub Copilot 模式](#1-github-copilot-模式默认)
20
- - [OpenCode Zen 模式](#2-opencode-zen-模式)
21
- - [Google Antigravity 模式](#3-google-antigravity-模式)
22
20
  - [代理配置](#-代理配置)
23
21
  - [Claude Code 集成](#-claude-code-集成)
24
22
  - [opencode 集成](#-opencode-集成)
@@ -35,7 +33,6 @@
35
33
 
36
34
  | 功能 | 说明 |
37
35
  |------|------|
38
- | 🔌 **多后端支持** | GitHub Copilot、OpenCode Zen、Google Antigravity 三种后端可选 |
39
36
  | 🤖 **双协议兼容** | 同时支持 OpenAI Chat Completions API 和 Anthropic Messages API |
40
37
  | 💻 **Claude Code 集成** | 一键生成 Claude Code 启动命令 (`--claude-code`) |
41
38
  | 📊 **使用量监控** | Web 仪表盘实时查看 API 使用情况 |
@@ -46,7 +43,6 @@
46
43
  | 🔑 **API Key 认证** | 可选的 API Key 鉴权,保护公开部署的服务 |
47
44
  | ✂️ **上下文透传** | 全量透传上下文至上游 API,由客户端(如 Claude Code)自行管理压缩 |
48
45
  | 🔍 **智能模型匹配** | 自动处理模型名格式差异(日期后缀、dash/dot 版本号等) |
49
- | 🔁 **Antigravity 端点容错** | 熔断器状态机、加权账号调度、后台任务自动降级、双端点自动切换 |
50
46
 
51
47
  ---
52
48
 
@@ -68,12 +64,6 @@ npx copilot-api-plus@latest start
68
64
  # 启动服务器(默认使用 GitHub Copilot)
69
65
  npx copilot-api-plus@latest start
70
66
 
71
- # 使用 OpenCode Zen
72
- npx copilot-api-plus@latest start --zen
73
-
74
- # 使用 Google Antigravity
75
- npx copilot-api-plus@latest start --antigravity
76
-
77
67
  # 与 Claude Code 配合
78
68
  npx copilot-api-plus@latest start --claude-code
79
69
  ```
@@ -129,169 +119,6 @@ npx copilot-api-plus@latest start --account-type enterprise
129
119
 
130
120
  ---
131
121
 
132
- ### 2. OpenCode Zen 模式
133
-
134
- 使用 [OpenCode Zen](https://opencode.ai/zen) 的多模型 API 服务,支持 GPT-5、Claude、Gemini 等顶级编程模型。
135
-
136
- #### 前置要求
137
- 1. 访问 https://opencode.ai/zen
138
- 2. 注册账号并创建 API Key
139
-
140
- #### 启动步骤
141
-
142
- **方式一:交互式设置**
143
- ```bash
144
- npx copilot-api-plus@latest start --zen
145
- ```
146
- 首次运行会提示输入 API Key,保存后下次自动使用。
147
-
148
- **方式二:直接指定 API Key**
149
- ```bash
150
- npx copilot-api-plus@latest start --zen --zen-api-key YOUR_API_KEY
151
- ```
152
-
153
- #### 可用模型
154
-
155
- | 模型 | ID | 说明 |
156
- |------|-----|------|
157
- | GPT-5.2 | `gpt-5.2` | OpenAI 最新模型 |
158
- | GPT-5.1 Codex Max | `gpt-5.1-codex-max` | 代码优化版 |
159
- | GPT-5.1 Codex | `gpt-5.1-codex` | 代码专用 |
160
- | GPT-5 Codex | `gpt-5-codex` | OpenAI Responses API |
161
- | Claude Opus 4.5 | `claude-opus-4-5` | Anthropic Claude (200K) |
162
- | Claude Sonnet 4.5 | `claude-sonnet-4-5` | Anthropic Claude (200K) |
163
- | Claude Sonnet 4 | `claude-sonnet-4` | Anthropic Claude |
164
- | Gemini 3 Pro | `gemini-3-pro` | Google Gemini |
165
- | Qwen3 Coder | `qwen3-coder` | Alibaba Qwen |
166
- | Kimi K2 | `kimi-k2` | Moonshot |
167
- | Grok Code Fast 1 | `grok-code-fast-1` | xAI |
168
-
169
- 更多模型请访问 [opencode.ai/zen](https://opencode.ai/zen)
170
-
171
- #### API 端点
172
-
173
- Zen 模式支持以下 API 端点:
174
-
175
- | 端点 | 说明 |
176
- |------|------|
177
- | `/v1/chat/completions` | OpenAI 兼容 Chat API |
178
- | `/v1/messages` | Anthropic 兼容 Messages API |
179
- | `/v1/responses` | OpenAI Responses API (GPT-5 系列) |
180
- | `/v1/models` | 获取可用模型列表 |
181
-
182
- 专用端点(无需 `--zen` 标志也可访问):
183
- - `/zen/v1/chat/completions`
184
- - `/zen/v1/messages`
185
- - `/zen/v1/responses`
186
- - `/zen/v1/models`
187
-
188
- #### 管理 API Key
189
-
190
- ```bash
191
- # 查看/更换 API Key(清除后重新启动会提示输入)
192
- npx copilot-api-plus@latest logout --zen
193
- ```
194
-
195
- ---
196
-
197
- ### 3. Google Antigravity 模式
198
-
199
- 使用 Google Antigravity API 服务,支持 Gemini 和 Claude 模型。
200
-
201
- #### 前置要求
202
- - Google 账户
203
-
204
- #### 认证方式
205
-
206
- **方式一:API Key(推荐 - 最简单)**
207
-
208
- 1. 访问 https://aistudio.google.com/apikey 获取 API Key
209
- 2. 使用环境变量启动:
210
-
211
- ```bash
212
- # Linux/macOS
213
- GEMINI_API_KEY=your_api_key npx copilot-api-plus@latest start --antigravity
214
-
215
- # Windows PowerShell
216
- $env:GEMINI_API_KEY = "your_api_key"
217
- npx copilot-api-plus@latest start --antigravity
218
-
219
- # Windows CMD
220
- set GEMINI_API_KEY=your_api_key
221
- npx copilot-api-plus@latest start --antigravity
222
- ```
223
-
224
- **方式二:OAuth 网页登录(推荐)**
225
-
226
- ```bash
227
- npx copilot-api-plus@latest start --antigravity
228
- ```
229
-
230
- 首次运行会提示选择登录方式:
231
- - **Web(推荐)**:自动打开浏览器完成 Google 登录,授权后自动捕获回调
232
- - **Manual**:手动复制回调 URL 到终端
233
-
234
- **方式三:自定义 OAuth 凭证**
235
-
236
- 如果遇到 `invalid_client` 错误,可以创建自己的 OAuth 应用:
237
-
238
- 1. 访问 https://console.cloud.google.com/apis/credentials
239
- 2. 创建 OAuth 2.0 客户端 ID(选择"桌面应用"类型)
240
- 3. 添加重定向 URI:`http://localhost:8046/callback`
241
- 4. 使用环境变量或命令行参数:
242
-
243
- ```bash
244
- # 环境变量方式
245
- ANTIGRAVITY_CLIENT_ID=your_client_id ANTIGRAVITY_CLIENT_SECRET=your_secret \
246
- npx copilot-api-plus@latest start --antigravity
247
-
248
- # 命令行参数方式
249
- npx copilot-api-plus@latest start --antigravity \
250
- --antigravity-client-id your_client_id \
251
- --antigravity-client-secret your_secret
252
- ```
253
-
254
- #### 可用模型
255
-
256
- | 模型 | ID | 说明 |
257
- |------|-----|------|
258
- | Gemini 2.5 Pro | `gemini-2.5-pro-exp-03-25` | Google Gemini |
259
- | Gemini 2.5 Pro Preview | `gemini-2.5-pro-preview-05-06` | Google Gemini |
260
- | Gemini 2.0 Flash | `gemini-2.0-flash-exp` | 快速响应 |
261
- | Gemini 2.0 Flash Thinking | `gemini-2.0-flash-thinking-exp` | 支持思考链 |
262
- | Claude Opus 4.5 | `claude-opus-4-5` | Anthropic Claude |
263
- | Claude Sonnet 4.5 | `claude-sonnet-4-5` | Anthropic Claude |
264
-
265
- #### 特性
266
- - ✅ 自动 Token 刷新
267
- - ✅ 多账户支持,加权智能调度(配额健康度 60% + Token 新鲜度 20% + 可靠性 20%)
268
- - ✅ 配额用尽自动切换账户
269
- - ✅ 熔断器状态机(CLOSED → OPEN → HALF_OPEN → CLOSED)
270
- - ✅ 后台/Agent 请求多信号检测,可选模型降级节省配额
271
- - ✅ 支持 Thinking 模型(思考链输出)
272
-
273
- #### 多账户管理
274
-
275
- 可以添加多个 Google 账户,系统会在配额用尽时自动切换:
276
-
277
- ```bash
278
- # 添加新账户
279
- npx copilot-api-plus@latest antigravity add
280
-
281
- # 列出所有账户
282
- npx copilot-api-plus@latest antigravity list
283
-
284
- # 按索引删除账户
285
- npx copilot-api-plus@latest antigravity remove 0
286
-
287
- # 清除所有账户
288
- npx copilot-api-plus@latest antigravity clear
289
- # 或使用 logout 命令
290
- npx copilot-api-plus@latest logout --antigravity
291
- ```
292
-
293
- ---
294
-
295
122
  ## 🌐 代理配置
296
123
 
297
124
  如果你需要通过代理访问网络,有两种配置方式:
@@ -378,14 +205,7 @@ npx copilot-api-plus@latest start --proxy-env
378
205
  ### 自动配置(推荐)
379
206
 
380
207
  ```bash
381
- # 使用 GitHub Copilot 作为后端
382
208
  npx copilot-api-plus@latest start --claude-code
383
-
384
- # 使用 OpenCode Zen 作为后端
385
- npx copilot-api-plus@latest start --zen --claude-code
386
-
387
- # 使用 Google Antigravity 作为后端
388
- npx copilot-api-plus@latest start --antigravity --claude-code
389
209
  ```
390
210
 
391
211
  运行后:
@@ -499,13 +319,11 @@ npx opencode@latest
499
319
 
500
320
  ### 专用端点
501
321
 
502
- 各后端都有独立的专用路由,即使切换默认后端也能访问:
322
+ GitHub Copilot 有独立的专用路由:
503
323
 
504
324
  | 路由前缀 | 说明 |
505
325
  |----------|------|
506
326
  | `/copilot/v1/*` | GitHub Copilot 专用 |
507
- | `/zen/v1/*` | OpenCode Zen 专用 |
508
- | `/antigravity/v1/*` | Google Antigravity 专用 |
509
327
 
510
328
  ### 监控端点
511
329
 
@@ -548,7 +366,6 @@ curl http://localhost:4141/v1/messages \
548
366
  | `auth` | 仅执行 GitHub 认证流程 |
549
367
  | `logout` | 清除已保存的凭证 |
550
368
  | `proxy` | 配置代理设置 |
551
- | `antigravity` | 管理 Google Antigravity 账户 |
552
369
  | `check-usage` | 查看 Copilot 使用量 |
553
370
  | `debug` | 显示调试信息 |
554
371
 
@@ -560,11 +377,6 @@ curl http://localhost:4141/v1/messages \
560
377
  | `--verbose` | `-v` | false | 详细日志 |
561
378
  | `--account-type` | `-a` | individual | 账户类型 (individual/business/enterprise) |
562
379
  | `--claude-code` | `-c` | false | 生成 Claude Code 启动命令 |
563
- | `--zen` | `-z` | false | 启用 OpenCode Zen 模式 |
564
- | `--zen-api-key` | - | - | Zen API Key |
565
- | `--antigravity` | - | false | 启用 Google Antigravity 模式 |
566
- | `--antigravity-client-id` | - | - | Antigravity OAuth Client ID |
567
- | `--antigravity-client-secret` | - | - | Antigravity OAuth Client Secret |
568
380
  | `--rate-limit` | `-r` | - | 请求间隔(秒) |
569
381
  | `--wait` | `-w` | false | 达到限制时等待而非报错 |
570
382
  | `--manual` | - | false | 手动审批每个请求 |
@@ -591,31 +403,10 @@ curl http://localhost:4141/v1/messages \
591
403
  | 参数 | 别名 | 说明 |
592
404
  |------|------|------|
593
405
  | `--github` | `-g` | 仅清除 GitHub Copilot 凭证 |
594
- | `--zen` | `-z` | 仅清除 Zen 凭证 |
595
- | `--antigravity` | - | 仅清除 Antigravity 凭证 |
596
406
  | `--all` | `-a` | 清除所有凭证 |
597
407
 
598
408
  > **提示**:不带参数运行 `logout` 会显示交互式菜单供选择。
599
409
 
600
- ### antigravity 命令
601
-
602
- 管理 Google Antigravity 账户的子命令:
603
-
604
- | 子命令 | 说明 |
605
- |--------|------|
606
- | `add` | 添加新的 Antigravity 账户(OAuth 登录) |
607
- | `list` | 列出所有已配置的账户及其状态 |
608
- | `remove <index>` | 按索引删除指定账户 |
609
- | `clear` | 清除所有 Antigravity 账户(需确认) |
610
-
611
- ```bash
612
- # 示例
613
- npx copilot-api-plus@latest antigravity add # 添加账户
614
- npx copilot-api-plus@latest antigravity list # 列出账户
615
- npx copilot-api-plus@latest antigravity remove 0 # 删除索引为 0 的账户
616
- npx copilot-api-plus@latest antigravity clear # 清除所有账户
617
- ```
618
-
619
410
  ---
620
411
 
621
412
  ## 🔑 API Key 认证
@@ -672,35 +463,6 @@ Anthropic 格式的模型名(如 `claude-opus-4-6`)和 Copilot 的模型列
672
463
 
673
464
  对于 Anthropic 端点(`/v1/messages`),还会先通过 `translateModelName` 做格式转换(包括旧格式 `claude-3-5-sonnet` → `claude-sonnet-4.5` 的映射),再通过上述策略匹配。
674
465
 
675
- ### Antigravity 端点容错
676
-
677
- Google Antigravity 模式内置了多层可靠性保障:
678
-
679
- - **熔断器状态机**:按模型族(claude/gemini/other)独立管理,3 次失败后熔断(OPEN),30 秒后半开(HALF_OPEN)试探,连续 2 次成功则恢复(CLOSED)
680
- - **加权账号调度**:替代简单轮换,综合评分 `score = 配额健康度×0.6 + Token新鲜度×0.2 + 可靠性×0.2`,优先选用最健康的账号
681
- - **后台任务检测与降级**:多信号加权检测(tool_calls +0.5、tool 角色 +0.4、助手密度 +0.2、长对话 +0.1),得分 ≥ 0.6 判定为 Agent 请求,可自动降级高价模型(如 claude-sonnet-4-5 → gemini-2.5-flash)。通过 `ANTIGRAVITY_BACKGROUND_DOWNGRADE=1` 环境变量启用,默认关闭
682
- - **双端点自动切换**:daily sandbox 和 production 两个端点,一个失败自动切换到另一个
683
- - **指数退避重试**:429/503 等限流错误自动退避重试,短间隔走同端点,长间隔切换端点
684
-
685
- #### 后台降级环境变量
686
-
687
- | 变量 | 默认 | 说明 |
688
- |------|------|------|
689
- | `ANTIGRAVITY_BACKGROUND_DOWNGRADE` | `0` (关闭) | 设为 `1` 启用 Agent/后台请求自动模型降级 |
690
-
691
- 降级映射:
692
-
693
- | 原始模型 | 降级后 |
694
- |----------|--------|
695
- | `claude-sonnet-4-5` | `gemini-2.5-flash` |
696
- | `claude-sonnet-4-5-thinking` | `gemini-2.5-flash-thinking` |
697
- | `claude-opus-4-5-thinking` | `claude-sonnet-4-5-thinking` |
698
- | `gemini-2.5-pro` | `gemini-2.5-flash` |
699
- | `gemini-3-pro-high` | `gemini-3-flash` |
700
- | `gemini-3-pro-low` | `gemini-3-flash` |
701
-
702
- 客户端也可通过请求头 `X-Request-Type: background` 显式标记后台请求,无需检测直接生效。
703
-
704
466
  ### 请求日志
705
467
 
706
468
  每次 API 请求会输出一行日志,包含模型名、状态码和耗时:
@@ -780,8 +542,6 @@ docker run -p 4141:4141 \
780
542
  | 文件 | 说明 |
781
543
  |------|------|
782
544
  | `github_token` | GitHub Token |
783
- | `zen-auth.json` | Zen API Key |
784
- | `antigravity-accounts.json` | Antigravity 账户 |
785
545
  | `config.json` | 代理等配置 |
786
546
 
787
547
  ### 切换账户
@@ -795,12 +555,6 @@ npx copilot-api-plus@latest logout --github
795
555
  # 或简写
796
556
  npx copilot-api-plus@latest logout -g
797
557
 
798
- # 清除 Zen 凭证
799
- npx copilot-api-plus@latest logout --zen
800
-
801
- # 清除 Antigravity 凭证
802
- npx copilot-api-plus@latest logout --antigravity
803
-
804
558
  # 清除所有凭证
805
559
  npx copilot-api-plus@latest logout --all
806
560
  ```
@@ -0,0 +1,2 @@
1
+ import { t as HTTPError } from "./error-u36czEGD.js";
2
+ export { HTTPError };
@@ -42,4 +42,4 @@ async function forwardError(c, error) {
42
42
  //#endregion
43
43
  export { forwardError as n, HTTPError as t };
44
44
 
45
- //# sourceMappingURL=error-CvvAyU1E.js.map
45
+ //# sourceMappingURL=error-u36czEGD.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-CvvAyU1E.js","names":[],"sources":["../src/lib/error.ts"],"sourcesContent":["import type { Context } from \"hono\"\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\"\n\nimport consola from \"consola\"\n\nexport class HTTPError extends Error {\n response: Response\n\n constructor(message: string, response: Response) {\n super(message)\n this.response = response\n }\n}\n\nexport async function forwardError(c: Context, error: unknown) {\n if (error instanceof HTTPError) {\n // Try to read error body, but it may already be consumed by the caller\n let errorText: string\n try {\n errorText = await error.response.text()\n } catch {\n // Body already read — fall back to the error message\n errorText = error.message\n }\n\n // 400 errors: concise log, already detailed upstream\n if (error.response.status === 400) {\n // no extra logging, upstream already printed details\n } else {\n let errorJson: unknown\n try {\n errorJson = JSON.parse(errorText)\n } catch {\n errorJson = errorText\n }\n consola.error(\"Error occurred:\", error)\n consola.error(\"HTTP error:\", errorJson)\n }\n\n return c.json(\n {\n error: {\n message: errorText,\n type: \"error\",\n },\n },\n error.response.status as ContentfulStatusCode,\n )\n }\n\n // Network errors (fetch failed, TLS disconnect, etc.) — concise log\n const message = (error as Error).message || String(error)\n const cause = (error as { cause?: Error }).cause\n if (cause) {\n consola.error(`${message}: ${cause.message}`)\n } else {\n consola.error(message)\n }\n return c.json(\n {\n error: {\n message: (error as Error).message,\n type: \"error\",\n },\n },\n 500,\n )\n}\n"],"mappings":";;AAKA,IAAa,YAAb,cAA+B,MAAM;CACnC;CAEA,YAAY,SAAiB,UAAoB;AAC/C,QAAM,QAAQ;AACd,OAAK,WAAW;;;AAIpB,eAAsB,aAAa,GAAY,OAAgB;AAC7D,KAAI,iBAAiB,WAAW;EAE9B,IAAI;AACJ,MAAI;AACF,eAAY,MAAM,MAAM,SAAS,MAAM;UACjC;AAEN,eAAY,MAAM;;AAIpB,MAAI,MAAM,SAAS,WAAW,KAAK,QAE5B;GACL,IAAI;AACJ,OAAI;AACF,gBAAY,KAAK,MAAM,UAAU;WAC3B;AACN,gBAAY;;AAEd,WAAQ,MAAM,mBAAmB,MAAM;AACvC,WAAQ,MAAM,eAAe,UAAU;;AAGzC,SAAO,EAAE,KACP,EACE,OAAO;GACL,SAAS;GACT,MAAM;GACP,EACF,EACD,MAAM,SAAS,OAChB;;CAIH,MAAM,UAAW,MAAgB,WAAW,OAAO,MAAM;CACzD,MAAM,QAAS,MAA4B;AAC3C,KAAI,MACF,SAAQ,MAAM,GAAG,QAAQ,IAAI,MAAM,UAAU;KAE7C,SAAQ,MAAM,QAAQ;AAExB,QAAO,EAAE,KACP,EACE,OAAO;EACL,SAAU,MAAgB;EAC1B,MAAM;EACP,EACF,EACD,IACD"}
1
+ {"version":3,"file":"error-u36czEGD.js","names":[],"sources":["../src/lib/error.ts"],"sourcesContent":["import type { Context } from \"hono\"\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\"\n\nimport consola from \"consola\"\n\nexport class HTTPError extends Error {\n response: Response\n\n constructor(message: string, response: Response) {\n super(message)\n this.response = response\n }\n}\n\nexport async function forwardError(c: Context, error: unknown) {\n if (error instanceof HTTPError) {\n // Try to read error body, but it may already be consumed by the caller\n let errorText: string\n try {\n errorText = await error.response.text()\n } catch {\n // Body already read — fall back to the error message\n errorText = error.message\n }\n\n // 400 errors: concise log, already detailed upstream\n if (error.response.status === 400) {\n // no extra logging, upstream already printed details\n } else {\n let errorJson: unknown\n try {\n errorJson = JSON.parse(errorText)\n } catch {\n errorJson = errorText\n }\n consola.error(\"Error occurred:\", error)\n consola.error(\"HTTP error:\", errorJson)\n }\n\n return c.json(\n {\n error: {\n message: errorText,\n type: \"error\",\n },\n },\n error.response.status as ContentfulStatusCode,\n )\n }\n\n // Network errors (fetch failed, TLS disconnect, etc.) — concise log\n const message = (error as Error).message || String(error)\n const cause = (error as { cause?: Error }).cause\n if (cause) {\n consola.error(`${message}: ${cause.message}`)\n } else {\n consola.error(message)\n }\n return c.json(\n {\n error: {\n message: (error as Error).message,\n type: \"error\",\n },\n },\n 500,\n )\n}\n"],"mappings":";;AAKA,IAAa,YAAb,cAA+B,MAAM;CACnC;CAEA,YAAY,SAAiB,UAAoB;AAC/C,QAAM,QAAQ;AACd,OAAK,WAAW;;;AAIpB,eAAsB,aAAa,GAAY,OAAgB;AAC7D,KAAI,iBAAiB,WAAW;EAE9B,IAAI;AACJ,MAAI;AACF,eAAY,MAAM,MAAM,SAAS,MAAM;UACjC;AAEN,eAAY,MAAM;;AAIpB,MAAI,MAAM,SAAS,WAAW,KAAK,QAE5B;GACL,IAAI;AACJ,OAAI;AACF,gBAAY,KAAK,MAAM,UAAU;WAC3B;AACN,gBAAY;;AAEd,WAAQ,MAAM,mBAAmB,MAAM;AACvC,WAAQ,MAAM,eAAe,UAAU;;AAGzC,SAAO,EAAE,KACP,EACE,OAAO;GACL,SAAS;GACT,MAAM;GACP,EACF,EACD,MAAM,SAAS,OAChB;;CAIH,MAAM,UAAW,MAAgB,WAAW,OAAO,MAAM;CACzD,MAAM,QAAS,MAA4B;AAC3C,KAAI,MACF,SAAQ,MAAM,GAAG,QAAQ,IAAI,MAAM,UAAU;KAE7C,SAAQ,MAAM,QAAQ;AAExB,QAAO,EAAE,KACP,EACE,OAAO;EACL,SAAU,MAAgB;EAC1B,MAAM;EACP,EACF,EACD,IACD"}
@@ -1,6 +1,13 @@
1
- import { t as state } from "./state-CRpaW-qc.js";
2
- import { t as HTTPError } from "./error-CvvAyU1E.js";
1
+ import { t as HTTPError } from "./error-u36czEGD.js";
3
2
  import { randomUUID } from "node:crypto";
3
+ //#region src/lib/state.ts
4
+ const state = {
5
+ accountType: "individual",
6
+ manualApprove: false,
7
+ rateLimitWait: false,
8
+ showToken: false
9
+ };
10
+ //#endregion
4
11
  //#region src/lib/api-config.ts
5
12
  const standardHeaders = () => ({
6
13
  "content-type": "application/json",
@@ -54,6 +61,6 @@ async function getGitHubUser() {
54
61
  return await response.json();
55
62
  }
56
63
  //#endregion
57
- export { GITHUB_CLIENT_ID as a, githubHeaders as c, GITHUB_BASE_URL as i, standardHeaders as l, GITHUB_API_BASE_URL as n, copilotBaseUrl as o, GITHUB_APP_SCOPES as r, copilotHeaders as s, getGitHubUser as t };
64
+ export { GITHUB_CLIENT_ID as a, githubHeaders as c, GITHUB_BASE_URL as i, standardHeaders as l, GITHUB_API_BASE_URL as n, copilotBaseUrl as o, GITHUB_APP_SCOPES as r, copilotHeaders as s, getGitHubUser as t, state as u };
58
65
 
59
- //# sourceMappingURL=get-user-DOv07Myc.js.map
66
+ //# sourceMappingURL=get-user-BxebJZB6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-user-BxebJZB6.js","names":[],"sources":["../src/lib/state.ts","../src/lib/api-config.ts","../src/services/github/get-user.ts"],"sourcesContent":["import type { ModelsResponse } from \"~/services/copilot/get-models\"\n\nexport interface State {\n githubToken?: string\n copilotToken?: string\n copilotApiEndpoint?: string // API endpoint returned by token response\n\n accountType: string\n models?: ModelsResponse\n vsCodeVersion?: string\n\n manualApprove: boolean\n rateLimitWait: boolean\n showToken: boolean\n\n // Rate limiting configuration\n rateLimitSeconds?: number\n lastRequestTimestamp?: number\n\n // API key authentication\n apiKeys?: Array<string>\n}\n\nexport const state: State = {\n accountType: \"individual\",\n manualApprove: false,\n rateLimitWait: false,\n showToken: false,\n}\n","import { randomUUID } from \"node:crypto\"\n\nimport type { State } from \"./state\"\n\nexport const standardHeaders = () => ({\n \"content-type\": \"application/json\",\n accept: \"application/json\",\n})\n\nconst COPILOT_VERSION = \"0.26.7\"\nconst EDITOR_PLUGIN_VERSION = `copilot-chat/${COPILOT_VERSION}`\nconst USER_AGENT = `GitHubCopilotChat/${COPILOT_VERSION}`\n\n// Updated to match latest Zed implementation - 2025-05-01 returns Claude models\nconst API_VERSION = \"2025-05-01\"\n\n// Use the API endpoint from token response if available, otherwise fall back to default\nexport const copilotBaseUrl = (state: State) => {\n if (state.copilotApiEndpoint) {\n return state.copilotApiEndpoint\n }\n return state.accountType === \"individual\" ?\n \"https://api.githubcopilot.com\"\n : `https://api.${state.accountType}.githubcopilot.com`\n}\nexport const copilotHeaders = (state: State, vision: boolean = false) => {\n const headers: Record<string, string> = {\n Authorization: `Bearer ${state.copilotToken}`,\n \"content-type\": standardHeaders()[\"content-type\"],\n \"copilot-integration-id\": \"vscode-chat\",\n \"editor-version\": `vscode/${state.vsCodeVersion}`,\n \"editor-plugin-version\": EDITOR_PLUGIN_VERSION,\n \"user-agent\": USER_AGENT,\n \"openai-intent\": \"conversation-panel\",\n \"x-github-api-version\": API_VERSION,\n \"x-request-id\": randomUUID(),\n \"x-vscode-user-agent-library-version\": \"electron-fetch\",\n }\n\n if (vision) headers[\"copilot-vision-request\"] = \"true\"\n\n return headers\n}\n\nexport const GITHUB_API_BASE_URL = \"https://api.github.com\"\nexport const githubHeaders = (state: State) => ({\n ...standardHeaders(),\n authorization: `token ${state.githubToken}`,\n \"editor-version\": `vscode/${state.vsCodeVersion}`,\n \"editor-plugin-version\": EDITOR_PLUGIN_VERSION,\n \"user-agent\": USER_AGENT,\n \"x-github-api-version\": API_VERSION,\n \"x-vscode-user-agent-library-version\": \"electron-fetch\",\n})\n\nexport const GITHUB_BASE_URL = \"https://github.com\"\nexport const GITHUB_CLIENT_ID = \"Iv1.b507a08c87ecfe98\"\nexport const GITHUB_APP_SCOPES = [\"read:user\"].join(\" \")\n","import { GITHUB_API_BASE_URL, standardHeaders } from \"~/lib/api-config\"\nimport { HTTPError } from \"~/lib/error\"\nimport { state } from \"~/lib/state\"\n\nexport async function getGitHubUser() {\n const response = await fetch(`${GITHUB_API_BASE_URL}/user`, {\n headers: {\n authorization: `token ${state.githubToken}`,\n ...standardHeaders(),\n },\n })\n\n if (!response.ok) throw new HTTPError(\"Failed to get GitHub user\", response)\n\n return (await response.json()) as GithubUserResponse\n}\n\n// Trimmed for the sake of simplicity\ninterface GithubUserResponse {\n login: string\n}\n"],"mappings":";;;AAuBA,MAAa,QAAe;CAC1B,aAAa;CACb,eAAe;CACf,eAAe;CACf,WAAW;CACZ;;;ACxBD,MAAa,yBAAyB;CACpC,gBAAgB;CAChB,QAAQ;CACT;AAED,MAAM,kBAAkB;AACxB,MAAM,wBAAwB,gBAAgB;AAC9C,MAAM,aAAa,qBAAqB;AAGxC,MAAM,cAAc;AAGpB,MAAa,kBAAkB,UAAiB;AAC9C,KAAI,MAAM,mBACR,QAAO,MAAM;AAEf,QAAO,MAAM,gBAAgB,eACzB,kCACA,eAAe,MAAM,YAAY;;AAEvC,MAAa,kBAAkB,OAAc,SAAkB,UAAU;CACvE,MAAM,UAAkC;EACtC,eAAe,UAAU,MAAM;EAC/B,gBAAgB,iBAAiB,CAAC;EAClC,0BAA0B;EAC1B,kBAAkB,UAAU,MAAM;EAClC,yBAAyB;EACzB,cAAc;EACd,iBAAiB;EACjB,wBAAwB;EACxB,gBAAgB,YAAY;EAC5B,uCAAuC;EACxC;AAED,KAAI,OAAQ,SAAQ,4BAA4B;AAEhD,QAAO;;AAGT,MAAa,sBAAsB;AACnC,MAAa,iBAAiB,WAAkB;CAC9C,GAAG,iBAAiB;CACpB,eAAe,SAAS,MAAM;CAC9B,kBAAkB,UAAU,MAAM;CAClC,yBAAyB;CACzB,cAAc;CACd,wBAAwB;CACxB,uCAAuC;CACxC;AAED,MAAa,kBAAkB;AAC/B,MAAa,mBAAmB;AAChC,MAAa,oBAAoB,CAAC,YAAY,CAAC,KAAK,IAAI;;;ACrDxD,eAAsB,gBAAgB;CACpC,MAAM,WAAW,MAAM,MAAM,GAAG,oBAAoB,QAAQ,EAC1D,SAAS;EACP,eAAe,SAAS,MAAM;EAC9B,GAAG,iBAAiB;EACrB,EACF,CAAC;AAEF,KAAI,CAAC,SAAS,GAAI,OAAM,IAAI,UAAU,6BAA6B,SAAS;AAE5E,QAAQ,MAAM,SAAS,MAAM"}
@@ -0,0 +1,3 @@
1
+ import { t as getGitHubUser } from "./get-user-BxebJZB6.js";
2
+ import "./error-u36czEGD.js";
3
+ export { getGitHubUser };