@nick3/copilot-api 1.3.3 → 1.3.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 +34 -24
- package/dist/account-DhQb2A6q.js +17 -0
- package/dist/account-DhQb2A6q.js.map +1 -0
- package/dist/{accounts-manager-H7YGTVk8.js → accounts-manager-BGBtDChT.js} +25 -573
- package/dist/accounts-manager-BGBtDChT.js.map +1 -0
- package/dist/accounts-registry-c7rs5Ed9.js +180 -0
- package/dist/accounts-registry-c7rs5Ed9.js.map +1 -0
- package/dist/admin/assets/index-BB9SaCFS.js +57 -0
- package/dist/admin/assets/{index-D-pIr-q0.css → index-CvffOmW7.css} +1 -1
- package/dist/admin/index.html +2 -2
- package/dist/auth-BvIHvhP9.js +241 -0
- package/dist/auth-BvIHvhP9.js.map +1 -0
- package/dist/check-usage-CiTcYDij.js +82 -0
- package/dist/check-usage-CiTcYDij.js.map +1 -0
- package/dist/debug-hQJWwXtC.js +82 -0
- package/dist/debug-hQJWwXtC.js.map +1 -0
- package/dist/get-copilot-token-CUT8hpgX.js +13 -0
- package/dist/get-copilot-token-CUT8hpgX.js.map +1 -0
- package/dist/main.js +25 -735
- package/dist/main.js.map +1 -1
- package/dist/paths-DoT4SZ8f.js +49 -0
- package/dist/paths-DoT4SZ8f.js.map +1 -0
- package/dist/poll-access-token-Dnd_xK36.js +52 -0
- package/dist/poll-access-token-Dnd_xK36.js.map +1 -0
- package/dist/{server-BZhJgGbw.js → server-COWbIpDR.js} +277 -23
- package/dist/server-COWbIpDR.js.map +1 -0
- package/dist/start-BbULwJ9B.js +306 -0
- package/dist/start-BbULwJ9B.js.map +1 -0
- package/dist/utils-BaoXuYkx.js +338 -0
- package/dist/utils-BaoXuYkx.js.map +1 -0
- package/package.json +1 -1
- package/dist/accounts-manager-H7YGTVk8.js.map +0 -1
- package/dist/admin/assets/index-C9gbhsHu.js +0 -56
- package/dist/server-BZhJgGbw.js.map +0 -1
package/README.md
CHANGED
|
@@ -52,9 +52,9 @@ Compared with routing everything through plain Chat Completions compatibility, t
|
|
|
52
52
|
- **Flexible Authentication**: Authenticate interactively or provide a GitHub token directly, suitable for CI/CD environments.
|
|
53
53
|
- **Support for Different Account Types**: Works with individual, business, and enterprise GitHub Copilot plans.
|
|
54
54
|
- **Multi-Account Support**: Use multiple GitHub Copilot accounts with automatic routing: premium models use accounts in order and fall back on quota exhaustion; free models are distributed round-robin across accounts by default (configurable in config.json).
|
|
55
|
-
- **Opencode OAuth Support**: Use opencode GitHub Copilot authentication by setting `COPILOT_API_OAUTH_APP=opencode` environment variable.
|
|
56
|
-
- **GitHub Enterprise Support**: Connect to GHE.com by setting `COPILOT_API_ENTERPRISE_URL` environment variable (e.g., `company.ghe.com`).
|
|
57
|
-
- **Custom Data Directory**: Change the default data directory (where tokens and config are stored) by setting `COPILOT_API_HOME` environment variable.
|
|
55
|
+
- **Opencode OAuth Support**: Use opencode GitHub Copilot authentication by setting `COPILOT_API_OAUTH_APP=opencode` environment variable or using `--oauth-app=opencode` command line option.
|
|
56
|
+
- **GitHub Enterprise Support**: Connect to GHE.com by setting `COPILOT_API_ENTERPRISE_URL` environment variable (e.g., `company.ghe.com`) or using `--enterprise-url=company.ghe.com` command line option.
|
|
57
|
+
- **Custom Data Directory**: Change the default data directory (where tokens and config are stored) by setting `COPILOT_API_HOME` environment variable or using `--api-home=/path/to/dir` command line option.
|
|
58
58
|
- **Multi-Provider Anthropic Proxy Routes**: Add global provider configs and call external Anthropic-compatible APIs via `/:provider/v1/messages` and `/:provider/v1/models`.
|
|
59
59
|
|
|
60
60
|
## Better Agent Semantics
|
|
@@ -237,6 +237,16 @@ Copilot API now uses a subcommand structure with these main commands:
|
|
|
237
237
|
|
|
238
238
|
## Command Line Options
|
|
239
239
|
|
|
240
|
+
### Global Options
|
|
241
|
+
|
|
242
|
+
The following options can be used with any subcommand. When passing them before the subcommand, use the `--key=value` form:
|
|
243
|
+
|
|
244
|
+
| Option | Description | Default | Alias |
|
|
245
|
+
| ----------------- | ------------------------------------------------------ | ------- | ----- |
|
|
246
|
+
| --api-home | Path to the API home directory (sets COPILOT_API_HOME) | none | none |
|
|
247
|
+
| --oauth-app | OAuth app identifier (sets COPILOT_API_OAUTH_APP) | none | none |
|
|
248
|
+
| --enterprise-url | Enterprise URL for GitHub (sets COPILOT_API_ENTERPRISE_URL) | none | none |
|
|
249
|
+
|
|
240
250
|
### Start Command Options
|
|
241
251
|
|
|
242
252
|
The following command line options are available for the `start` command:
|
|
@@ -297,25 +307,12 @@ The `<target>` can be either the account ID (GitHub username) or a 1-based index
|
|
|
297
307
|
"auth": {
|
|
298
308
|
"apiKeys": []
|
|
299
309
|
},
|
|
300
|
-
"providers": {
|
|
301
|
-
"custom": {
|
|
302
|
-
"type": "anthropic",
|
|
303
|
-
"enabled": true,
|
|
304
|
-
"baseUrl": "your-base-url",
|
|
305
|
-
"apiKey": "sk-your-provider-key",
|
|
306
|
-
"models": {
|
|
307
|
-
"kimi-k2.5": {
|
|
308
|
-
"temperature": 1,
|
|
309
|
-
"topP": 0.95
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
},
|
|
310
|
+
"providers": {},
|
|
314
311
|
"extraPrompts": {
|
|
315
312
|
"gpt-5-mini": "<built-in exploration prompt>",
|
|
316
313
|
"gpt-5.3-codex": "<built-in commentary prompt>",
|
|
314
|
+
"gpt-5.4-mini": "<built-in commentary prompt>",
|
|
317
315
|
"gpt-5.4": "<built-in commentary prompt>"
|
|
318
|
-
"useMessagesApi": true
|
|
319
316
|
},
|
|
320
317
|
"smallModel": "gpt-5-mini",
|
|
321
318
|
"freeModelLoadBalancing": true,
|
|
@@ -323,25 +320,24 @@ The `<target>` can be either the account ID (GitHub username) or a 1-based index
|
|
|
323
320
|
"modelReasoningEfforts": {
|
|
324
321
|
"gpt-5-mini": "low",
|
|
325
322
|
"gpt-5.3-codex": "xhigh",
|
|
323
|
+
"gpt-5.4-mini": "xhigh",
|
|
326
324
|
"gpt-5.4": "xhigh"
|
|
327
325
|
},
|
|
328
|
-
"modelAliases": {
|
|
329
|
-
"fast": { "target": "gpt-5-mini", "allowOriginal": false },
|
|
330
|
-
"draft": { "target": "gpt-5.1-codex-max" }
|
|
331
|
-
},
|
|
332
326
|
"allowOriginalModelNamesForAliases": false,
|
|
333
327
|
"useFunctionApplyPatch": true,
|
|
334
|
-
"forceAgent": false,
|
|
335
328
|
"compactUseSmallModel": true,
|
|
329
|
+
"messageStartInputTokensFallback": false,
|
|
330
|
+
"modelRefreshIntervalHours": 24,
|
|
336
331
|
"useMessagesApi": true
|
|
337
332
|
}
|
|
338
333
|
```
|
|
339
334
|
- **auth.apiKeys:** API keys used for request authentication. Supports multiple keys for rotation. Requests can authenticate with either `x-api-key: <key>` or `Authorization: Bearer <key>`. If empty or omitted, authentication is disabled.
|
|
340
|
-
- **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.
|
|
335
|
+
- **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`, `gpt-5.4-mini`, and `gpt-5.4` enable phase-aware commentary, which lets the model emit a short user-facing progress update before tools or deeper reasoning.
|
|
341
336
|
- **providers:** Global upstream provider map. Each provider key (for example `custom`) becomes a route prefix (`/custom/v1/messages`). Currently only `type: "anthropic"` is supported.
|
|
342
337
|
- `enabled` defaults to `true` if omitted.
|
|
343
338
|
- `baseUrl` should be provider API base URL without trailing `/v1/messages`.
|
|
344
339
|
- `apiKey` is used as upstream `x-api-key`.
|
|
340
|
+
- `adjustInputTokens` (optional): When `true`, the proxy will adjust the `input_tokens` in the usage response by subtracting `cache_read_input_tokens` and `cache_creation_input_tokens`.
|
|
345
341
|
- `models` (optional): Per-model configuration map. Each key is a model ID (matching the model name in requests), and the value is:
|
|
346
342
|
- `temperature` (optional): Default temperature value used when the request does not specify one.
|
|
347
343
|
- `topP` (optional): Default top_p value used when the request does not specify one.
|
|
@@ -356,6 +352,8 @@ The `<target>` can be either the account ID (GitHub username) or a 1-based index
|
|
|
356
352
|
- **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.
|
|
357
353
|
- **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.
|
|
358
354
|
- **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`.
|
|
355
|
+
- **messageStartInputTokensFallback:** When `true`, the Anthropic streaming translation layer estimates `message_start.input_tokens` when upstream stream events do not provide it. Defaults to `false`.
|
|
356
|
+
- **modelRefreshIntervalHours:** Interval for refreshing account model lists in the background. Set to `0` to disable refresh. Defaults to `24`.
|
|
359
357
|
- **useMessagesApi:** When `true` (default), Claude-family models that support Copilot's native `/v1/messages` endpoint may use the Messages API path. Set to `false` to skip the Messages API candidate and fall back to `/responses` (if supported) or `/chat/completions`.
|
|
360
358
|
|
|
361
359
|
Edit this file to customize prompts or swap in your own fast model. If you edit it manually, restart the server (or call `GET /api/admin/config`) so the cached config is refreshed. Changes made through the Admin UI/API are validated, written to disk, and applied immediately; unknown keys are rejected.
|
|
@@ -533,6 +531,18 @@ npx @nick3/copilot-api@latest start --proxy-env
|
|
|
533
531
|
|
|
534
532
|
# Use opencode GitHub Copilot authentication
|
|
535
533
|
COPILOT_API_OAUTH_APP=opencode npx @nick3/copilot-api@latest start
|
|
534
|
+
|
|
535
|
+
# Set custom API home directory via command line
|
|
536
|
+
npx @nick3/copilot-api@latest --api-home=/path/to/custom/dir start
|
|
537
|
+
|
|
538
|
+
# Use GitHub Enterprise via command line
|
|
539
|
+
npx @nick3/copilot-api@latest --enterprise-url=company.ghe.com start
|
|
540
|
+
|
|
541
|
+
# Use opencode OAuth via command line
|
|
542
|
+
npx @nick3/copilot-api@latest --oauth-app=opencode start
|
|
543
|
+
|
|
544
|
+
# Combine multiple global options
|
|
545
|
+
npx @nick3/copilot-api@latest --api-home=/custom/path --oauth-app=opencode --enterprise-url=company.ghe.com start
|
|
536
546
|
```
|
|
537
547
|
|
|
538
548
|
### Opencode OAuth Authentication
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/lib/types/account.ts
|
|
2
|
+
const ACCOUNT_TYPE_VALUES = [
|
|
3
|
+
"individual",
|
|
4
|
+
"business",
|
|
5
|
+
"enterprise"
|
|
6
|
+
];
|
|
7
|
+
function isAccountType(value) {
|
|
8
|
+
return typeof value === "string" && ACCOUNT_TYPE_VALUES.includes(value);
|
|
9
|
+
}
|
|
10
|
+
function parseAccountType(value) {
|
|
11
|
+
if (!isAccountType(value)) throw new Error(`Invalid account type: ${String(value)}. Valid values: ${ACCOUNT_TYPE_VALUES.join(", ")}`);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { parseAccountType };
|
|
17
|
+
//# sourceMappingURL=account-DhQb2A6q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-DhQb2A6q.js","names":["ACCOUNT_TYPE_VALUES: ReadonlyArray<AccountType>"],"sources":["../src/lib/types/account.ts"],"sourcesContent":["import type { ModelsResponse } from \"~/services/copilot/get-models\"\n\n/**\n * Account type for GitHub Copilot subscription.\n */\nexport type AccountType = \"individual\" | \"business\" | \"enterprise\"\n\nexport const ACCOUNT_TYPE_VALUES: ReadonlyArray<AccountType> = [\n \"individual\",\n \"business\",\n \"enterprise\",\n]\n\nexport function isAccountType(value: unknown): value is AccountType {\n return (\n typeof value === \"string\"\n && (ACCOUNT_TYPE_VALUES as ReadonlyArray<string>).includes(value)\n )\n}\n\nexport function parseAccountType(value: unknown): AccountType {\n if (!isAccountType(value)) {\n throw new Error(\n `Invalid account type: ${String(value)}. Valid values: ${ACCOUNT_TYPE_VALUES.join(\n \", \",\n )}`,\n )\n }\n return value\n}\n\n/**\n * Metadata for a registered account, stored in the registry file.\n */\nexport interface AccountMeta {\n /** GitHub login (username) */\n id: string\n /** Account subscription type */\n accountType: AccountType\n /** Timestamp when the account was added */\n addedAt: number\n}\n\n/**\n * Registry file structure for storing account metadata.\n */\nexport interface AccountRegistry {\n /** Schema version for future migrations */\n version: 1\n /** Ordered list of accounts (order = priority) */\n accounts: Array<AccountMeta>\n}\n\n/**\n * Runtime state for an account, including tokens and quota information.\n */\nexport interface AccountRuntime extends AccountMeta {\n /** GitHub personal access token */\n githubToken: string\n /** Copilot API token (obtained from GitHub) */\n copilotToken?: string\n /** VS Code version for API headers */\n vsCodeVersion?: string\n /** Cached available models for this account */\n models?: ModelsResponse\n /** Timestamp of last models fetch */\n lastModelsFetch?: number\n /** Whether models refresh is in progress */\n isRefreshingModels?: boolean\n /** Promise for an in-flight models refresh */\n modelsRefreshPromise?: Promise<void>\n /** Total premium interactions quota entitlement */\n premiumEntitlement?: number\n /** Remaining premium interactions quota */\n premiumRemaining?: number\n /** Reserved premium interaction units for in-flight requests */\n premiumReserved?: number\n /** Internal reservation map for idempotent release */\n premiumReservations?: Map<symbol, number>\n /** Whether this account has unlimited quota */\n unlimited?: boolean\n /** Whether this account allows overage billing (enterprise feature) */\n overagePermitted?: boolean\n /** Timestamp of last quota fetch */\n lastQuotaFetch?: number\n /** Token refresh timer reference */\n refreshTimer?: ReturnType<typeof setInterval>\n /** Whether this account has failed (e.g., 401 error) */\n failed?: boolean\n /** Failure reason if failed */\n failureReason?: string\n /** Whether quota refresh is in progress (prevents concurrent refreshes) */\n isRefreshingQuota?: boolean\n /** Promise for an in-flight quota refresh (allows concurrent callers to await the same refresh) */\n quotaRefreshPromise?: Promise<void>\n}\n\n/**\n * Context required for making API calls on behalf of an account.\n * This is a subset of AccountRuntime used by service functions.\n */\nexport interface AccountContext {\n /** GitHub personal access token */\n githubToken: string\n /** Copilot API token */\n copilotToken?: string\n /** Account subscription type */\n accountType: AccountType\n /** VS Code version for API headers */\n vsCodeVersion?: string\n}\n"],"mappings":";AAOA,MAAaA,sBAAkD;CAC7D;CACA;CACA;CACD;AAED,SAAgB,cAAc,OAAsC;AAClE,QACE,OAAO,UAAU,YACb,oBAA8C,SAAS,MAAM;;AAIrE,SAAgB,iBAAiB,OAA6B;AAC5D,KAAI,CAAC,cAAc,MAAM,CACvB,OAAM,IAAI,MACR,yBAAyB,OAAO,MAAM,CAAC,kBAAkB,oBAAoB,KAC3E,KACD,GACF;AAEH,QAAO"}
|