@nick3/copilot-api 1.3.3 → 1.3.5
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 +25 -3
- package/dist/account-DhQb2A6q.js +17 -0
- package/dist/account-DhQb2A6q.js.map +1 -0
- package/dist/{accounts-manager-H7YGTVk8.js → accounts-manager-DjGzZIcp.js} +18 -569
- package/dist/accounts-manager-DjGzZIcp.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-CYJuRbDb.js +241 -0
- package/dist/auth-CYJuRbDb.js.map +1 -0
- package/dist/check-usage-CVF7i8yX.js +82 -0
- package/dist/check-usage-CVF7i8yX.js.map +1 -0
- package/dist/debug-hQJWwXtC.js +82 -0
- package/dist/debug-hQJWwXtC.js.map +1 -0
- package/dist/get-copilot-token-BwP_PxV5.js +13 -0
- package/dist/get-copilot-token-BwP_PxV5.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-CN92flJy.js +52 -0
- package/dist/poll-access-token-CN92flJy.js.map +1 -0
- package/dist/{server-BZhJgGbw.js → server-CM_0PrbK.js} +183 -7
- package/dist/server-CM_0PrbK.js.map +1 -0
- package/dist/start-KYMwXUvr.js +302 -0
- package/dist/start-KYMwXUvr.js.map +1 -0
- package/dist/utils-BUJfM1V2.js +335 -0
- package/dist/utils-BUJfM1V2.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:
|
|
@@ -533,6 +543,18 @@ npx @nick3/copilot-api@latest start --proxy-env
|
|
|
533
543
|
|
|
534
544
|
# Use opencode GitHub Copilot authentication
|
|
535
545
|
COPILOT_API_OAUTH_APP=opencode npx @nick3/copilot-api@latest start
|
|
546
|
+
|
|
547
|
+
# Set custom API home directory via command line
|
|
548
|
+
npx @nick3/copilot-api@latest --api-home=/path/to/custom/dir start
|
|
549
|
+
|
|
550
|
+
# Use GitHub Enterprise via command line
|
|
551
|
+
npx @nick3/copilot-api@latest --enterprise-url=company.ghe.com start
|
|
552
|
+
|
|
553
|
+
# Use opencode OAuth via command line
|
|
554
|
+
npx @nick3/copilot-api@latest --oauth-app=opencode start
|
|
555
|
+
|
|
556
|
+
# Combine multiple global options
|
|
557
|
+
npx @nick3/copilot-api@latest --api-home=/custom/path --oauth-app=opencode --enterprise-url=company.ghe.com start
|
|
536
558
|
```
|
|
537
559
|
|
|
538
560
|
### 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"}
|