@eddyskywalker/dsh-chatgpt-subscription 0.4.0 → 0.5.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/CHANGELOG.md +23 -0
- package/lib/client.js +703 -534
- package/lib/client.js.map +1 -1
- package/lib/index.js +5106 -3793
- package/lib/types/client/CodexSubscriptionSection.d.ts +1 -1
- package/lib/types/client/CodexSubscriptionSection.d.ts.map +1 -1
- package/lib/types/client/antigravity/AntigravitySection.d.ts.map +1 -1
- package/lib/types/client/antigravity/locales.d.ts +24 -192
- package/lib/types/client/antigravity/locales.d.ts.map +1 -1
- package/lib/types/client/api.d.ts +13 -1
- package/lib/types/client/api.d.ts.map +1 -1
- package/lib/types/client/command-code/CommandCodeSection.d.ts.map +1 -1
- package/lib/types/client/command-code/locales.d.ts +66 -201
- package/lib/types/client/command-code/locales.d.ts.map +1 -1
- package/lib/types/client/common/AccountPoolSection.d.ts +41 -0
- package/lib/types/client/common/AccountPoolSection.d.ts.map +1 -0
- package/lib/types/client/common/account-pool-labels.d.ts +43 -0
- package/lib/types/client/common/account-pool-labels.d.ts.map +1 -0
- package/lib/types/client/common/styles.d.ts +11 -0
- package/lib/types/client/common/styles.d.ts.map +1 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/kimi-code/KimiCodeSection.d.ts.map +1 -1
- package/lib/types/client/kimi-code/locales.d.ts +63 -336
- package/lib/types/client/kimi-code/locales.d.ts.map +1 -1
- package/lib/types/client/locales.d.ts +41 -1
- package/lib/types/client/locales.d.ts.map +1 -1
- package/lib/types/host/antigravity/account-pool.d.ts +15 -5
- package/lib/types/host/antigravity/account-pool.d.ts.map +1 -1
- package/lib/types/host/antigravity/routes.d.ts.map +1 -1
- package/lib/types/host/codex-account-pool.d.ts +64 -0
- package/lib/types/host/codex-account-pool.d.ts.map +1 -0
- package/lib/types/host/command-code/account-pool.d.ts +60 -0
- package/lib/types/host/command-code/account-pool.d.ts.map +1 -0
- package/lib/types/host/command-code/adapter.d.ts +11 -1
- package/lib/types/host/command-code/adapter.d.ts.map +1 -1
- package/lib/types/host/command-code/client.d.ts +17 -1
- package/lib/types/host/command-code/client.d.ts.map +1 -1
- package/lib/types/host/command-code/oauth.d.ts +4 -1
- package/lib/types/host/command-code/oauth.d.ts.map +1 -1
- package/lib/types/host/command-code/routes.d.ts +11 -2
- package/lib/types/host/command-code/routes.d.ts.map +1 -1
- package/lib/types/host/common/account-pool.d.ts +179 -0
- package/lib/types/host/common/account-pool.d.ts.map +1 -0
- package/lib/types/host/common/home.d.ts +8 -0
- package/lib/types/host/common/home.d.ts.map +1 -0
- package/lib/types/host/kimi-code/account-pool.d.ts +48 -0
- package/lib/types/host/kimi-code/account-pool.d.ts.map +1 -0
- package/lib/types/host/kimi-code/adapter.d.ts +10 -1
- package/lib/types/host/kimi-code/adapter.d.ts.map +1 -1
- package/lib/types/host/kimi-code/client.d.ts +16 -0
- package/lib/types/host/kimi-code/client.d.ts.map +1 -1
- package/lib/types/host/kimi-code/oauth.d.ts +2 -0
- package/lib/types/host/kimi-code/oauth.d.ts.map +1 -1
- package/lib/types/host/kimi-code/routes.d.ts +10 -2
- package/lib/types/host/kimi-code/routes.d.ts.map +1 -1
- package/lib/types/host/oauth-service.d.ts +41 -2
- package/lib/types/host/oauth-service.d.ts.map +1 -1
- package/lib/types/host/preset-sync.d.ts +7 -1
- package/lib/types/host/preset-sync.d.ts.map +1 -1
- package/lib/types/host/responses-client.d.ts +15 -0
- package/lib/types/host/responses-client.d.ts.map +1 -1
- package/lib/types/host/routes.d.ts +2 -1
- package/lib/types/host/routes.d.ts.map +1 -1
- package/lib/types/host/usage-service.d.ts +15 -0
- package/lib/types/host/usage-service.d.ts.map +1 -1
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/account-pool-contracts.d.ts +47 -0
- package/lib/types/shared/account-pool-contracts.d.ts.map +1 -0
- package/lib/types/shared/antigravity-contracts.d.ts +4 -10
- package/lib/types/shared/antigravity-contracts.d.ts.map +1 -1
- package/lib/types/shared/command-code-contracts.d.ts +14 -0
- package/lib/types/shared/command-code-contracts.d.ts.map +1 -1
- package/lib/types/shared/contracts.d.ts +6 -0
- package/lib/types/shared/contracts.d.ts.map +1 -1
- package/lib/types/shared/kimi-code-contracts.d.ts +14 -0
- package/lib/types/shared/kimi-code-contracts.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../../src/client/locales.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE,EAAG,0BAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../../src/client/locales.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE,EAAG,0BAAmC,CAAA;AAIrD,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkIL,CAAA;AAEV,eAAO,MAAM,EAAE,EAAE,MAAM,CAAC,MAAM,OAAO,EAAE,EAAE,MAAM,CAgI9C,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,EAAE,CAAA;AACvC,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAa,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CredentialStore } from '../token-store.ts';
|
|
2
2
|
import { FileCredentialStore, type AntigravityCredentials } from './token-store.ts';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AntigravityAccountSummaryDto, AccountRotationStrategy } from '../../shared/antigravity-contracts.ts';
|
|
4
4
|
export interface AntigravityPoolAccount {
|
|
5
5
|
id: string;
|
|
6
6
|
alias: string;
|
|
@@ -22,14 +22,20 @@ export interface AntigravityPoolData {
|
|
|
22
22
|
}
|
|
23
23
|
export declare function poolPath(): string;
|
|
24
24
|
export declare function parseAntigravityPoolData(value: unknown): AntigravityPoolData;
|
|
25
|
+
/**
|
|
26
|
+
* Antigravity's account pool.
|
|
27
|
+
*
|
|
28
|
+
* The storage, eligibility, rotation and cooldown rules live in the shared
|
|
29
|
+
* {@link AccountPoolCore}; this facade keeps the provider-shaped API the routes
|
|
30
|
+
* and the adapter were written against, including the credential projection
|
|
31
|
+
* (`token` / `projectId`) that predates the shared core.
|
|
32
|
+
*/
|
|
25
33
|
export declare class AccountPoolStore {
|
|
26
|
-
private readonly
|
|
27
|
-
private readonly backend;
|
|
34
|
+
private readonly core;
|
|
28
35
|
private readonly legacyStore;
|
|
29
36
|
constructor(filePath?: string, backend?: CredentialStore<AntigravityPoolData>, legacyStore?: FileCredentialStore);
|
|
37
|
+
/** Human description of where this pool's credentials live. */
|
|
30
38
|
path(): string;
|
|
31
|
-
private serialize;
|
|
32
|
-
private saveVerified;
|
|
33
39
|
read(): Promise<AntigravityPoolData>;
|
|
34
40
|
write(data: AntigravityPoolData): Promise<void>;
|
|
35
41
|
listAccounts(): Promise<AntigravityAccountSummaryDto[]>;
|
|
@@ -41,6 +47,10 @@ export declare class AccountPoolStore {
|
|
|
41
47
|
markCooldown(accountId: string, durationMs: number, reason: string): Promise<void>;
|
|
42
48
|
clearCooldown(accountId: string): Promise<void>;
|
|
43
49
|
hasAnotherAvailableAccount(triedAccountIds: ReadonlySet<string>): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Pick the account for the next request, with the credential projection the
|
|
52
|
+
* Antigravity adapter consumes.
|
|
53
|
+
*/
|
|
44
54
|
getEffectiveAccount(excludeIds?: ReadonlySet<string>, fetchFn?: typeof fetch): Promise<{
|
|
45
55
|
account: AntigravityPoolAccount;
|
|
46
56
|
token: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-pool.d.ts","sourceRoot":"","sources":["../../../../src/host/antigravity/account-pool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account-pool.d.ts","sourceRoot":"","sources":["../../../../src/host/antigravity/account-pool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAMxD,OAAO,EACL,mBAAmB,EAEnB,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EACV,4BAA4B,EAC5B,uBAAuB,EACxB,MAAM,uCAAuC,CAAA;AAE9C,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,sBAAsB,CAAA;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,CAAC,CAAA;IACV,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,uBAAuB,CAAA;IACzC,QAAQ,EAAE,sBAAsB,EAAE,CAAA;CACnC;AAED,wBAAgB,QAAQ,IAAI,MAAM,CAEjC;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAwC5E;AAmBD;;;;;;;GAOG;AACH,qBAA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AAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAOnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/antigravity/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,KAAK,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AAC/G,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAIpD,OAAO,KAAK,EAA0B,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AA+BzG,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,sBAAsB,EACrC,WAAW,CAAC,EAAE,0BAA0B,EACxC,WAAW,mBAAoD,GAC9D,OAAO,CAAC,oBAAoB,CAAC,CAoC/B;AAED,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,sBAAsB,EACrC,WAAW,CAAC,EAAE,0BAA0B,EACxC,OAAO,GAAE,OAAO,KAAa,EAC7B,WAAW,mBAAoD,GAC9D,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/antigravity/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,KAAK,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AAC/G,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAIpD,OAAO,KAAK,EAA0B,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AA+BzG,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,sBAAsB,EACrC,WAAW,CAAC,EAAE,0BAA0B,EACxC,WAAW,mBAAoD,GAC9D,OAAO,CAAC,oBAAoB,CAAC,CAoC/B;AAED,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,sBAAsB,EACrC,WAAW,CAAC,EAAE,0BAA0B,EACxC,OAAO,GAAE,OAAO,KAAa,EAC7B,WAAW,mBAAoD,GAC9D,MAAM,IAAI,CAmIZ"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AccountPoolCore, type PoolAccountShape, type PoolData } from './common/account-pool.ts';
|
|
2
|
+
import { type CredentialStore, type StoredOAuthCredentials, type TokenStore } from './token-store.ts';
|
|
3
|
+
import type { AccountRotationStrategy, PoolAccountSummaryDto } from '../shared/account-pool-contracts.ts';
|
|
4
|
+
/** One pooled ChatGPT account: the credential plus the facts the card renders. */
|
|
5
|
+
export interface CodexPoolAccount extends PoolAccountShape<StoredOAuthCredentials> {
|
|
6
|
+
email?: string;
|
|
7
|
+
planType?: string;
|
|
8
|
+
accountId?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Encrypted pool file the ChatGPT line owns; the single-credential store stays the mirror. */
|
|
11
|
+
export declare function codexPoolPath(): string;
|
|
12
|
+
/** Validate and normalize one whole pool document. */
|
|
13
|
+
export declare function parseCodexPoolData(value: unknown): PoolData<CodexPoolAccount>;
|
|
14
|
+
/** Token refresh the OAuth service lends the pool; refresh tokens rotate, so this must be the only writer. */
|
|
15
|
+
export interface CodexTokenRefresher {
|
|
16
|
+
/** Refresh one account with the service's own token-endpoint fetch. */
|
|
17
|
+
refreshAccount(credentials: StoredOAuthCredentials): Promise<StoredOAuthCredentials>;
|
|
18
|
+
}
|
|
19
|
+
export interface CodexAccountPoolOptions {
|
|
20
|
+
/** Single-credential store the pool mirrors its primary account into. */
|
|
21
|
+
store?: TokenStore;
|
|
22
|
+
/** Test seam; production builds the platform backend from the pool path. */
|
|
23
|
+
backend?: CredentialStore<PoolData<CodexPoolAccount>>;
|
|
24
|
+
/** Accounts this pool accepts; defaults to the core's limit. */
|
|
25
|
+
maxAccounts?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* ChatGPT's account pool.
|
|
29
|
+
*
|
|
30
|
+
* Thin wrapper over {@link AccountPoolCore}: it only supplies the credential
|
|
31
|
+
* shape, the identity a duplicate sign-in collapses onto, and the two provider
|
|
32
|
+
* hooks the core cannot know — how to refresh one account's tokens and which
|
|
33
|
+
* accounts a cached quota window already rules out.
|
|
34
|
+
*/
|
|
35
|
+
export declare class CodexAccountPool extends AccountPoolCore<StoredOAuthCredentials, CodexPoolAccount, PoolAccountSummaryDto> {
|
|
36
|
+
private readonly refresherRef;
|
|
37
|
+
private readonly store;
|
|
38
|
+
private quotaBlockedUntil?;
|
|
39
|
+
constructor(options?: CodexAccountPoolOptions);
|
|
40
|
+
/** Hand the pool the OAuth service's per-account refresh implementation. */
|
|
41
|
+
setRefresher(refresher: CodexTokenRefresher): void;
|
|
42
|
+
/**
|
|
43
|
+
* Wire in a cached-quota verdict.
|
|
44
|
+
*
|
|
45
|
+
* The return value is the time the account's Codex window reopens; a lookup
|
|
46
|
+
* returning undefined (or a past time) leaves the account routable. This is
|
|
47
|
+
* how an exhausted window is skipped before a request is even attempted,
|
|
48
|
+
* instead of discovering it from a 429.
|
|
49
|
+
*/
|
|
50
|
+
setQuotaBlockedUntil(lookup: (account: CodexPoolAccount, now: number) => number | undefined): void;
|
|
51
|
+
protected isEligible(account: CodexPoolAccount, now: number, triedAccountIds?: ReadonlySet<string>): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Force one account's token refresh and persist the rotated pair.
|
|
54
|
+
*
|
|
55
|
+
* Used after a 401: the core refreshes proactively when a token is close to
|
|
56
|
+
* expiry, but a server-side revocation is only discovered by the request.
|
|
57
|
+
*/
|
|
58
|
+
refreshAccountNow(accountId: string): Promise<StoredOAuthCredentials>;
|
|
59
|
+
/** The single-credential store this pool mirrors its primary account into. */
|
|
60
|
+
mirrorStore(): TokenStore;
|
|
61
|
+
/** Rotation strategy currently configured. */
|
|
62
|
+
strategy(): Promise<AccountRotationStrategy>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=codex-account-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-account-pool.d.ts","sourceRoot":"","sources":["../../../src/host/codex-account-pool.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,EAGf,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACd,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAEzG,kFAAkF;AAClF,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB,CAAC,sBAAsB,CAAC;IAChF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AASD,sDAAsD;AACtD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAsC7E;AAED,8GAA8G;AAC9G,MAAM,WAAW,mBAAmB;IAClC,uEAAuE;IACvE,cAAc,CAAC,WAAW,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAA;CACrF;AAED,MAAM,WAAW,uBAAuB;IACtC,yEAAyE;IACzE,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAA;IACrD,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;GAOG;AACH,qBAAa,gBAAiB,SAAQ,eAAe,CAAC,sBAAsB,EAAE,gBAAgB,EAAE,qBAAqB,CAAC;IACpH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmC;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,iBAAiB,CAAC,CAAgE;gBAE9E,OAAO,GAAE,uBAA4B;IAyEjD,4EAA4E;IAC5E,YAAY,CAAC,SAAS,EAAE,mBAAmB,GAAG,IAAI;IAIlD;;;;;;;OAOG;IACH,oBAAoB,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAAG,IAAI;cAI/E,UAAU,CAC3B,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,MAAM,EACX,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACpC,OAAO;IAMV;;;;;OAKG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAW3E,8EAA8E;IAC9E,WAAW,IAAI,UAAU;IAIzB,8CAA8C;IACxC,QAAQ,IAAI,OAAO,CAAC,uBAAuB,CAAC;CAGnD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AccountPoolCore, type PoolAccountShape, type PoolData } from '../common/account-pool.ts';
|
|
2
|
+
import type { CredentialStore } from '../token-store.ts';
|
|
3
|
+
import { FileCredentialStore, type CommandCodeCredentials } from './token-store.ts';
|
|
4
|
+
import type { CommandCodeAccountSummaryDto, CommandCodeApiEnv } from '../../shared/command-code-contracts.ts';
|
|
5
|
+
/** One pooled Command Code key: the bearer key plus the account facts the card renders. */
|
|
6
|
+
export interface CommandCodePoolAccount extends PoolAccountShape<CommandCodeCredentials> {
|
|
7
|
+
email?: string;
|
|
8
|
+
userName?: string;
|
|
9
|
+
keyName?: string;
|
|
10
|
+
organizationName?: string;
|
|
11
|
+
planLabel?: string;
|
|
12
|
+
planId?: string;
|
|
13
|
+
userId?: string;
|
|
14
|
+
}
|
|
15
|
+
export type { CommandCodeAccountSummaryDto };
|
|
16
|
+
/** Encrypted pool file this line owns; the pre-pool credential file stays the mirror. */
|
|
17
|
+
export declare function commandCodePoolPath(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Stable identity of one key.
|
|
20
|
+
*
|
|
21
|
+
* A user id plus the key name is what Command Code Studio itself shows, so two
|
|
22
|
+
* keys minted from the same account stay distinguishable; without a user id the
|
|
23
|
+
* key's digest is the identity. The digest is never written anywhere.
|
|
24
|
+
*/
|
|
25
|
+
export declare function commandCodeAccountKey(credentials: CommandCodeCredentials): string;
|
|
26
|
+
/** Validate and normalize one whole pool document. */
|
|
27
|
+
export declare function parseCommandCodePoolData(value: unknown): PoolData<CommandCodePoolAccount>;
|
|
28
|
+
export interface CommandCodeAccountPoolOptions {
|
|
29
|
+
/** Pre-pool credential file the pool mirrors its primary account into. */
|
|
30
|
+
store?: FileCredentialStore;
|
|
31
|
+
/** Test seam; production builds the platform backend from the pool path. */
|
|
32
|
+
backend?: CredentialStore<PoolData<CommandCodePoolAccount>>;
|
|
33
|
+
/** Accounts this pool accepts; defaults to the core's limit. */
|
|
34
|
+
maxAccounts?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Command Code's account pool.
|
|
38
|
+
*
|
|
39
|
+
* A Command Code credential is a long-lived bearer key with nothing to refresh,
|
|
40
|
+
* so this wrapper only supplies identity, display facts and the mirror of the
|
|
41
|
+
* single-credential file the plugin used before the pool existed.
|
|
42
|
+
*/
|
|
43
|
+
export declare class CommandCodeAccountPool extends AccountPoolCore<CommandCodeCredentials, CommandCodePoolAccount, CommandCodeAccountSummaryDto> {
|
|
44
|
+
private readonly store;
|
|
45
|
+
constructor(options?: CommandCodeAccountPoolOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Pick the key for the next request, with the API environment it belongs to.
|
|
48
|
+
*
|
|
49
|
+
* A key issued for one deployment must not be sent to another, so the
|
|
50
|
+
* environment travels with the credential rather than with the process.
|
|
51
|
+
*/
|
|
52
|
+
getEffectiveCredential(excludeIds?: ReadonlySet<string>, fetchFn?: typeof fetch): Promise<{
|
|
53
|
+
account: CommandCodePoolAccount;
|
|
54
|
+
credentials: CommandCodeCredentials;
|
|
55
|
+
apiEnv: CommandCodeApiEnv;
|
|
56
|
+
}>;
|
|
57
|
+
/** The pre-pool credential file this pool mirrors its primary account into. */
|
|
58
|
+
mirrorStore(): FileCredentialStore;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=account-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-pool.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/account-pool.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,EAGf,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACd,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EACL,mBAAmB,EAEnB,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAE7G,2FAA2F;AAC3F,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB,CAAC,sBAAsB,CAAC;IACtF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,YAAY,EAAE,4BAA4B,EAAE,CAAA;AAE5C,yFAAyF;AACzF,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,sBAAsB,GAAG,MAAM,CAKjF;AASD,sDAAsD;AACtD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAAC,sBAAsB,CAAC,CAsCzF;AAED,MAAM,WAAW,6BAA6B;IAC5C,0EAA0E;IAC1E,KAAK,CAAC,EAAE,mBAAmB,CAAA;IAC3B,4EAA4E;IAC5E,OAAO,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAA;IAC3D,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;GAMG;AACH,qBAAa,sBAAuB,SAAQ,eAAe,CACzD,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,CAC7B;IACC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;gBAE/B,OAAO,GAAE,6BAAkC;IAkFvD;;;;;OAKG;IACG,sBAAsB,CAC1B,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,OAAO,GAAE,OAAO,KAAa,GAC5B,OAAO,CAAC;QAAE,OAAO,EAAE,sBAAsB,CAAC;QAAC,WAAW,EAAE,sBAAsB,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,CAAC;IAK/G,+EAA+E;IAC/E,WAAW,IAAI,mBAAmB;CAGnC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LlmAdapter, ReasoningEffortId, type GenerateOptions, type LlmModelInfo, type LlmProviderInfo, type LlmResolvedModelInfo, type PreparedAdapterCall, type ResolvedRetryPolicy, type StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
2
2
|
import { FileCredentialStore, FileModelSettingsStore, type CommandCodeCatalogModel, type CommandCodePreferenceStore } from './token-store.ts';
|
|
3
|
+
import { CommandCodeAccountPool } from './account-pool.ts';
|
|
3
4
|
import { type AttachmentImageReader } from './mapper.ts';
|
|
4
5
|
/** Configured effort when the model supports it, else the adapter's preference order. */
|
|
5
6
|
export declare function resolveDefaultReasoningEffort(efforts: readonly string[], configuredEffort?: string | null): ReasoningEffortId | undefined;
|
|
@@ -14,7 +15,16 @@ export declare class CommandCodeAdapter extends LlmAdapter {
|
|
|
14
15
|
private readonly modelSettings;
|
|
15
16
|
private readonly preferences?;
|
|
16
17
|
private readonly options;
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Rotation pool, or null for the single stored key.
|
|
20
|
+
*
|
|
21
|
+
* The pool is only ever installed by the plugin entry, which owns its storage.
|
|
22
|
+
* An adapter built without one must keep reading the one credential file and
|
|
23
|
+
* must not create pool state on its own: that state outlives the process and
|
|
24
|
+
* would leak cooldowns between unrelated runs.
|
|
25
|
+
*/
|
|
26
|
+
private readonly accountPool;
|
|
27
|
+
constructor(store?: FileCredentialStore, modelSettings?: FileModelSettingsStore, preferences?: CommandCodePreferenceStore | undefined, options?: CommandCodeAdapterOptions, accountPool?: CommandCodeAccountPool);
|
|
18
28
|
providerInfo(provider: string): LlmProviderInfo;
|
|
19
29
|
providerRetryPolicy(): ResolvedRetryPolicy;
|
|
20
30
|
imageRequestPricing(): undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAEV,iBAAiB,EAEjB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,E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1C,mBAAmB,IAAI,SAAS;IAIhC,OAAO,CAAC,QAAQ;IAIhB;;;OAGG;YACW,OAAO;IAYrB,OAAO,CAAC,gBAAgB;IAUlB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,YAAY,EAAE,CAAC;IAgB/D,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA0BpG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO/F,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,aAAa,CAAC,WAAW,CAAC;YAgBpD,aAAa;CA0K7B"}
|
|
@@ -75,15 +75,31 @@ export declare function whoami(apiKey: string, options?: CommandCodeRequestOptio
|
|
|
75
75
|
* is never stored.
|
|
76
76
|
*/
|
|
77
77
|
export declare function verifyApiKey(apiKey: string, options?: CommandCodeRequestOptions): Promise<CommandCodeAccount>;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the quota snapshot for the most recently requested account.
|
|
80
|
+
* Kept with a no-argument signature for backward compatibility.
|
|
81
|
+
*/
|
|
78
82
|
export declare function getCachedQuota(): CommandCodeAccountQuota | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* The cached snapshot only when it belongs to this account.
|
|
85
|
+
*
|
|
86
|
+
* Passing no account keeps the pre-pool behavior of returning whatever was
|
|
87
|
+
* fetched last.
|
|
88
|
+
*/
|
|
89
|
+
export declare function getCachedQuotaFor(accountId?: string | null): CommandCodeAccountQuota | undefined;
|
|
79
90
|
export declare function clearCachedQuota(): void;
|
|
91
|
+
export interface FetchAccountQuotaOptions {
|
|
92
|
+
fetchFn?: typeof fetch;
|
|
93
|
+
force?: boolean;
|
|
94
|
+
accountId?: string;
|
|
95
|
+
}
|
|
80
96
|
/**
|
|
81
97
|
* Read credits, subscriptions, and usage, tolerating a service that answers
|
|
82
98
|
* only some of the three. Every failure is captured as a missing source rather
|
|
83
99
|
* than failing the whole snapshot, because a working credit balance is still
|
|
84
100
|
* worth showing when the usage route is down.
|
|
85
101
|
*/
|
|
86
|
-
export declare function fetchAccountQuota(store?: FileCredentialStore,
|
|
102
|
+
export declare function fetchAccountQuota(store?: Pick<FileCredentialStore, 'read'>, fetchFnOrOptions?: typeof fetch | FetchAccountQuotaOptions, force?: boolean, accountId?: string): Promise<CommandCodeAccountQuota>;
|
|
87
103
|
/** Catalog entry list with the exact defaults the settings card renders. */
|
|
88
104
|
export declare function buildModelOptions(catalog: readonly CommandCodeCatalogModel[], enabledModelIds: readonly string[], overrides: Record<string, number>): Array<{
|
|
89
105
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,WAAW,EAWZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,mBAAmB,EAAE,KAAK,uBAAuB,EAA+B,MAAM,kBAAkB,CAAA;AAEjH,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,wCAAwC,CAAA;AAI/C,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;IACtB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAC3B;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACjC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAcxB;AAqGD,qFAAqF;AACrF,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,Q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G,WAAW,CAAA;CAC7B,CAAC,CAgBD;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Server } from 'node:http';
|
|
2
|
-
import { FileCredentialStore } from './token-store.ts';
|
|
2
|
+
import { FileCredentialStore, type CommandCodeCredentials } from './token-store.ts';
|
|
3
3
|
import type { CommandCodeAccount } from '../../shared/command-code-contracts.ts';
|
|
4
4
|
export type CommandCodeLoginStatus = 'idle' | 'pending' | 'complete' | 'error';
|
|
5
5
|
export interface CommandCodeLoginFlowState {
|
|
@@ -74,6 +74,8 @@ export declare function beginWebLogin(store: FileCredentialStore, options?: {
|
|
|
74
74
|
fetchFn?: typeof fetch;
|
|
75
75
|
openBrowser?: (url: string) => void;
|
|
76
76
|
timeoutMs?: number;
|
|
77
|
+
/** Called with the validated credential so a pool can keep every sign-in. */
|
|
78
|
+
onSave?: (credentials: CommandCodeCredentials) => Promise<unknown>;
|
|
77
79
|
}): Promise<CommandCodeLoginFlowState>;
|
|
78
80
|
/**
|
|
79
81
|
* Persist a manually entered API key after proving it authenticates.
|
|
@@ -83,6 +85,7 @@ export declare function beginWebLogin(store: FileCredentialStore, options?: {
|
|
|
83
85
|
*/
|
|
84
86
|
export declare function saveApiKey(store: FileCredentialStore, apiKey: string, options?: {
|
|
85
87
|
fetchFn?: typeof fetch;
|
|
88
|
+
onSave?: (credentials: CommandCodeCredentials) => Promise<unknown>;
|
|
86
89
|
}): Promise<CommandCodeAccount>;
|
|
87
90
|
/** Stable per-attempt id the settings card can correlate; kept for symmetry with other routes. */
|
|
88
91
|
export declare function newLoginAttemptId(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/oauth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsC,KAAK,MAAM,EAAuB,MAAM,WAAW,CAAA;AAehG,OAAO,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,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ai/cordis';
|
|
2
2
|
import { PROVIDER_ID, PROVIDER_NAME } from './types.ts';
|
|
3
3
|
import { FileCredentialStore, FileModelSettingsStore, type CommandCodeCatalogModel, type CommandCodePreferenceStore } from './token-store.ts';
|
|
4
|
+
import { CommandCodeAccountPool } from './account-pool.ts';
|
|
4
5
|
import { getCachedCatalog } from './client.ts';
|
|
5
6
|
import type { CommandCodeApiEnv, CommandCodeWebStatus } from '../../shared/command-code-contracts.ts';
|
|
6
7
|
/**
|
|
@@ -18,10 +19,18 @@ export interface CommandCodeStatusOptions {
|
|
|
18
19
|
serving?: boolean | (() => boolean);
|
|
19
20
|
/** Diagnostic when another plugin owns the provider route; re-read on every status. */
|
|
20
21
|
conflict?: string | null | (() => string | null);
|
|
22
|
+
/**
|
|
23
|
+
* Account pool instance used for multi-account management.
|
|
24
|
+
*
|
|
25
|
+
* Only the plugin entry installs one, because it owns the pool's storage. A
|
|
26
|
+
* caller that passes none keeps the single-key behavior, and no code path
|
|
27
|
+
* invents pool state that would outlive the process.
|
|
28
|
+
*/
|
|
29
|
+
accountPool?: CommandCodeAccountPool;
|
|
21
30
|
}
|
|
22
31
|
/** Everything the settings card renders: account, quota, and the model catalog. */
|
|
23
|
-
export declare function getCommandCodeWebStatus(store: FileCredentialStore, modelSettings: FileModelSettingsStore, preferences?: CommandCodePreferenceStore, options?: CommandCodeStatusOptions): Promise<CommandCodeWebStatus>;
|
|
32
|
+
export declare function getCommandCodeWebStatus(store: FileCredentialStore, modelSettings: FileModelSettingsStore, preferences?: CommandCodePreferenceStore, options?: CommandCodeStatusOptions, accountPool?: CommandCodeAccountPool | undefined): Promise<CommandCodeWebStatus>;
|
|
24
33
|
/** Register the Command Code settings routes under `/command-code/api`. */
|
|
25
|
-
export declare function registerCommandCodeRoutes(ctx: Context, store: FileCredentialStore, modelSettings: FileModelSettingsStore, preferences?: CommandCodePreferenceStore, options?: CommandCodeStatusOptions): () => void;
|
|
34
|
+
export declare function registerCommandCodeRoutes(ctx: Context, store: FileCredentialStore, modelSettings: FileModelSettingsStore, preferences?: CommandCodePreferenceStore, options?: CommandCodeStatusOptions, accountPool?: CommandCodeAccountPool | undefined): () => void;
|
|
26
35
|
export { PROVIDER_ID, PROVIDER_NAME, type CommandCodeApiEnv, getCachedCatalog };
|
|
27
36
|
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,EAAmB,WAAW,EAAE,aAAa,EAAqC,MAAM,YAAY,CAAA;AAC3G,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,uBAAuB,EAE5B,KAAK,0BAA0B,EAChC,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAKL,gBAAgB,EAMjB,MAAM,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAA;AAkErG;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,EAAE,SAAS,uBAAuB,EAAE,EAC3C,OAAO,UAAO,GACb,MAAM,EAAE,CAUV;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;IACtB,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAA;IACnC,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AA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ACtC,WAAW,GAAE,sBAAsB,GAAG,SAA+B,GACpE,MAAM,IAAI,CAgOZ;AAED,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { CredentialStore } from '../token-store.ts';
|
|
2
|
+
import type { AccountAuthStatus, AccountRotationStrategy, PoolAccountSummaryDto } from '../../shared/account-pool-contracts.ts';
|
|
3
|
+
/** Refresh an access token this many milliseconds before it expires. */
|
|
4
|
+
export declare const POOL_REFRESH_MARGIN_MS = 60000;
|
|
5
|
+
/** Accounts a single pool may hold before `addAccount` refuses another one. */
|
|
6
|
+
export declare const DEFAULT_MAX_POOL_ACCOUNTS = 20;
|
|
7
|
+
/**
|
|
8
|
+
* The parts of a pooled account every provider line agrees on.
|
|
9
|
+
*
|
|
10
|
+
* A provider's own account type extends this with whatever non-secret display
|
|
11
|
+
* facts its card renders (project id, key name, region, plan …).
|
|
12
|
+
*/
|
|
13
|
+
export interface PoolAccountShape<TCredentials> {
|
|
14
|
+
id: string;
|
|
15
|
+
alias: string;
|
|
16
|
+
credentials: TCredentials;
|
|
17
|
+
addedAt: number;
|
|
18
|
+
lastUsedAt?: number;
|
|
19
|
+
isPrimary?: boolean;
|
|
20
|
+
cooldownUntil?: number;
|
|
21
|
+
cooldownReason?: string;
|
|
22
|
+
authStatus?: AccountAuthStatus;
|
|
23
|
+
authFailedReason?: string;
|
|
24
|
+
}
|
|
25
|
+
/** One provider's whole pool document, as it lives in encrypted storage. */
|
|
26
|
+
export interface PoolData<TAccount> {
|
|
27
|
+
version: 1;
|
|
28
|
+
activeAccountId?: string;
|
|
29
|
+
rotationStrategy: AccountRotationStrategy;
|
|
30
|
+
accounts: TAccount[];
|
|
31
|
+
}
|
|
32
|
+
/** Everything the core hands a provider hook that mints an account record. */
|
|
33
|
+
export interface PoolAccountInput<TCredentials, TAccount> {
|
|
34
|
+
id: string;
|
|
35
|
+
alias: string;
|
|
36
|
+
credentials: TCredentials;
|
|
37
|
+
addedAt: number;
|
|
38
|
+
isPrimary: boolean;
|
|
39
|
+
/** The account this one replaces, when the dedupe key already exists. */
|
|
40
|
+
existing?: TAccount;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Provider-specific behaviour of one account pool.
|
|
44
|
+
*
|
|
45
|
+
* The storage, serialization, eligibility, rotation and cooldown rules live in
|
|
46
|
+
* {@link AccountPoolCore}; only these hooks differ per provider line.
|
|
47
|
+
*/
|
|
48
|
+
export interface AccountPoolHooks<TCredentials, TAccount extends PoolAccountShape<TCredentials>, TSummary extends PoolAccountSummaryDto> {
|
|
49
|
+
/** Provider id used in storage descriptions and diagnostics. */
|
|
50
|
+
providerId: string;
|
|
51
|
+
/** Human label used in the messages the core raises. */
|
|
52
|
+
displayName: string;
|
|
53
|
+
/** Plaintext path of the pool file; the encrypted variants derive from it. */
|
|
54
|
+
poolFile: string;
|
|
55
|
+
/** Keychain / Secret Service service name on macOS and Linux. */
|
|
56
|
+
keychainService: string;
|
|
57
|
+
/** Validate and normalize one whole pool document. */
|
|
58
|
+
parsePoolData(value: unknown): PoolData<TAccount>;
|
|
59
|
+
/** Mint an account record; the core only decides id, alias and primary flag. */
|
|
60
|
+
createAccount(input: PoolAccountInput<TCredentials, TAccount>): TAccount;
|
|
61
|
+
/** Identity two credentials share when they are the same upstream account. */
|
|
62
|
+
dedupeKey?(credentials: TCredentials): string | undefined;
|
|
63
|
+
/** Alias for an account whose credentials name nothing the user would recognize. */
|
|
64
|
+
defaultAlias(credentials: TCredentials, position: number): string;
|
|
65
|
+
/** Unix milliseconds the access token expires; absent for a non-expiring key. */
|
|
66
|
+
expiresAt?(credentials: TCredentials): number | undefined;
|
|
67
|
+
/** Whether the credential must be refreshed before the next request. */
|
|
68
|
+
needsRefresh?(credentials: TCredentials, now: number): boolean;
|
|
69
|
+
/** Refresh one credential, returning the value to persist back into the pool. */
|
|
70
|
+
refresh?(credentials: TCredentials, fetchFn: typeof fetch): Promise<TCredentials>;
|
|
71
|
+
/**
|
|
72
|
+
* Classify a failed refresh.
|
|
73
|
+
*
|
|
74
|
+
* Returning a status takes that account out of rotation (it is kept, so a new
|
|
75
|
+
* sign-in restores it) and lets the next eligible account serve the request.
|
|
76
|
+
* Returning undefined lets the refresh error surface: a transient failure
|
|
77
|
+
* must not cost an account its place in the pool.
|
|
78
|
+
*/
|
|
79
|
+
refreshFailureStatus?(error: unknown): AccountAuthStatus | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Reason the stored credential is already known to be unusable (a rejected
|
|
82
|
+
* refresh token, for instance). Reported purely: nothing is written here.
|
|
83
|
+
*/
|
|
84
|
+
authRejectedReason?(credentials: TCredentials): string | undefined;
|
|
85
|
+
/** Pre-pool single credential, projected as the primary account on read. */
|
|
86
|
+
legacyAccount?(): Promise<TAccount | null>;
|
|
87
|
+
/** Mirror the primary account into the single-credential store; `null` clears it. */
|
|
88
|
+
mirrorPrimary?(credentials: TCredentials | null): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Add the provider's own display facts (project id, key name, region …) to
|
|
91
|
+
* the shared summary the core already filled in.
|
|
92
|
+
*/
|
|
93
|
+
extendSummary?(account: TAccount, base: PoolAccountSummaryDto, now: number): TSummary;
|
|
94
|
+
/** Message raised when the pool holds no account at all. */
|
|
95
|
+
emptyMessage?: string;
|
|
96
|
+
/** Message raised when every account is cooling down or unusable. */
|
|
97
|
+
allUnavailableMessage?(count: number, waitMinutes: number): string;
|
|
98
|
+
/** Accounts this pool accepts; defaults to {@link DEFAULT_MAX_POOL_ACCOUNTS}. */
|
|
99
|
+
maxAccounts?: number;
|
|
100
|
+
/** Test seam; production builds the platform backend from the paths above. */
|
|
101
|
+
backend?: CredentialStore<PoolData<TAccount>>;
|
|
102
|
+
}
|
|
103
|
+
/** Stable keychain account name for one pool file, isolated per `DSH_HOME`. */
|
|
104
|
+
/** Accept a stored rotation strategy, or fall back to sequential. */
|
|
105
|
+
export declare function normalizeRotationStrategy(value: unknown): AccountRotationStrategy;
|
|
106
|
+
export declare function poolCredentialAccount(filePath: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* The shared multi-account pool: encrypted storage, eligibility filtering,
|
|
109
|
+
* rotation strategy, 429 cooldowns and per-account auth failures.
|
|
110
|
+
*
|
|
111
|
+
* @typeParam TCredentials - the provider's stored credential shape.
|
|
112
|
+
* @typeParam TAccount - the provider's pooled account record.
|
|
113
|
+
* @typeParam TSummary - the public DTO the settings card renders.
|
|
114
|
+
*/
|
|
115
|
+
export declare class AccountPoolCore<TCredentials, TAccount extends PoolAccountShape<TCredentials>, TSummary extends PoolAccountSummaryDto> {
|
|
116
|
+
protected readonly hooks: AccountPoolHooks<TCredentials, TAccount, TSummary>;
|
|
117
|
+
private readonly filePath;
|
|
118
|
+
private readonly backend;
|
|
119
|
+
constructor(hooks: AccountPoolHooks<TCredentials, TAccount, TSummary>);
|
|
120
|
+
/** Human description of where this pool's credentials live. */
|
|
121
|
+
path(): string;
|
|
122
|
+
private serialize;
|
|
123
|
+
private saveVerified;
|
|
124
|
+
/**
|
|
125
|
+
* Read the pool.
|
|
126
|
+
*
|
|
127
|
+
* A pool that holds no account yet projects the pre-pool single credential as
|
|
128
|
+
* the primary account. That projection stays side-effect free on purpose:
|
|
129
|
+
* every caller that changes the pool writes it back immediately afterwards,
|
|
130
|
+
* so persisting it here only bought an extra encrypted round trip and made a
|
|
131
|
+
* getter write to disk.
|
|
132
|
+
*/
|
|
133
|
+
read(): Promise<PoolData<TAccount>>;
|
|
134
|
+
write(data: PoolData<TAccount>): Promise<void>;
|
|
135
|
+
/** Public summaries, with cooldowns that already expired reported as absent. */
|
|
136
|
+
listAccounts(): Promise<TSummary[]>;
|
|
137
|
+
protected summarize(account: TAccount, now: number): TSummary;
|
|
138
|
+
/** Add or re-authorize one account; an existing dedupe key updates in place. */
|
|
139
|
+
addAccount(credentials: TCredentials, alias?: string): Promise<TAccount>;
|
|
140
|
+
setPrimary(accountId: string): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Persist a refreshed credential for one account.
|
|
143
|
+
*
|
|
144
|
+
* Used by a forced refresh (a 401 mid-request) rather than by the rotating
|
|
145
|
+
* getEffectiveAccount path, which already writes back what it refreshed.
|
|
146
|
+
*/
|
|
147
|
+
updateAccountCredentials(accountId: string, credentials: TCredentials): Promise<TAccount | undefined>;
|
|
148
|
+
setAlias(accountId: string, alias: string): Promise<void>;
|
|
149
|
+
deleteAccount(accountId: string): Promise<void>;
|
|
150
|
+
setStrategy(strategy: AccountRotationStrategy): Promise<void>;
|
|
151
|
+
/** Cool one account down after an upstream 429. */
|
|
152
|
+
markCooldown(accountId: string, durationMs: number, reason: string): Promise<void>;
|
|
153
|
+
clearCooldown(accountId: string): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Record that an account can no longer authenticate.
|
|
156
|
+
*
|
|
157
|
+
* The account stays in the pool: signing in again is what restores it, and a
|
|
158
|
+
* deleted account would take the user's alias and ordering with it.
|
|
159
|
+
*/
|
|
160
|
+
markAuthFailed(accountId: string, reason: string, status?: AccountAuthStatus): Promise<void>;
|
|
161
|
+
clearAuthFailed(accountId: string): Promise<void>;
|
|
162
|
+
/** Whether an account may serve a request right now. */
|
|
163
|
+
protected isEligible(account: TAccount, now: number, triedAccountIds?: ReadonlySet<string>): boolean;
|
|
164
|
+
hasAnotherAvailableAccount(triedAccountIds: ReadonlySet<string>): Promise<boolean>;
|
|
165
|
+
/**
|
|
166
|
+
* Pick the account for the next request, refreshing its credential when it is
|
|
167
|
+
* about to expire.
|
|
168
|
+
*
|
|
169
|
+
* @param excludeIds - accounts already tried for this request, so a retry
|
|
170
|
+
* lands on a different account.
|
|
171
|
+
* @param fetchFn - fetch used by the provider's token refresh.
|
|
172
|
+
* @throws LlmError with `RATE_LIMIT` when every account is cooling down.
|
|
173
|
+
*/
|
|
174
|
+
getEffectiveAccount(excludeIds?: ReadonlySet<string>, fetchFn?: typeof fetch): Promise<{
|
|
175
|
+
account: TAccount;
|
|
176
|
+
credentials: TCredentials;
|
|
177
|
+
}>;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=account-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-pool.d.ts","sourceRoot":"","sources":["../../../../src/host/common/account-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAIxD,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,wCAAwC,CAAA;AAE/C,wEAAwE;AACxE,eAAO,MAAM,sBAAsB,QAAS,CAAA;AAK5C,+EAA+E;AAC/E,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB,CAAC,YAAY;IAC5C,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,YAAY,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,iBAAiB,CAAA;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,4EAA4E;AAC5E,MAAM,WAAW,QAAQ,CAAC,QAAQ;IAChC,OAAO,EAAE,CAAC,CAAA;IACV,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,uBAAuB,CAAA;IACzC,QAAQ,EAAE,QAAQ,EAAE,CAAA;CACrB;AAED,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB,CAAC,YAAY,EAAE,QAAQ;IACtD,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,YAAY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MAAM,GAAE,iBAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvG,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD,wDAAwD;IACxD,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO;IAQ9F,0BAA0B,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAMxF;;;;;;;;OAQG;IACG,mBAAmB,CACvB,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,OAAO,GAAE,OAAO,KAAa,GAC5B,OAAO,CAAC;QAAE,OAAO,EAAE,QAAQ,CAAC;QAAC,WAAW,EAAE,YAAY,CAAA;KAAE,CAAC;CAoF7D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The harness home directory every plugin store lives under.
|
|
3
|
+
*
|
|
4
|
+
* Shared by every provider line and by the pool core, so a single env override
|
|
5
|
+
* (`DSH_HOME`) redirects all of them at once.
|
|
6
|
+
*/
|
|
7
|
+
export declare function dshHomeDir(): string;
|
|
8
|
+
//# sourceMappingURL=home.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"home.d.ts","sourceRoot":"","sources":["../../../../src/host/common/home.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AccountPoolCore, type PoolAccountShape, type PoolData } from '../common/account-pool.ts';
|
|
2
|
+
import type { CredentialStore } from '../token-store.ts';
|
|
3
|
+
import { FileCredentialStore, type KimiCodeCredentials } from './token-store.ts';
|
|
4
|
+
import type { KimiCodeAccountSummaryDto, KimiCodeRegion } from '../../shared/kimi-code-contracts.ts';
|
|
5
|
+
/** One pooled Kimi Code account: the token pair plus the facts the card renders. */
|
|
6
|
+
export interface KimiCodePoolAccount extends PoolAccountShape<KimiCodeCredentials> {
|
|
7
|
+
email?: string;
|
|
8
|
+
nickname?: string;
|
|
9
|
+
userId?: string;
|
|
10
|
+
planName?: string;
|
|
11
|
+
region?: KimiCodeRegion;
|
|
12
|
+
}
|
|
13
|
+
/** Encrypted pool file this line owns; the pre-pool credential file stays the mirror. */
|
|
14
|
+
export declare function kimiCodePoolPath(): string;
|
|
15
|
+
/** Validate and normalize one whole pool document. */
|
|
16
|
+
export declare function parseKimiCodePoolData(value: unknown): PoolData<KimiCodePoolAccount>;
|
|
17
|
+
export interface KimiCodeAccountPoolOptions {
|
|
18
|
+
/** Pre-pool credential file the pool mirrors its primary account into. */
|
|
19
|
+
store?: FileCredentialStore;
|
|
20
|
+
/** Test seam; production builds the platform backend from the pool path. */
|
|
21
|
+
backend?: CredentialStore<PoolData<KimiCodePoolAccount>>;
|
|
22
|
+
/** Accounts this pool accepts; defaults to the core's limit. */
|
|
23
|
+
maxAccounts?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Kimi Code's account pool.
|
|
27
|
+
*
|
|
28
|
+
* The credential is an OAuth pair whose refresh token rotates, so the pool owns
|
|
29
|
+
* both the refresh and the write-back: two accounts must never be refreshed
|
|
30
|
+
* through the same single-credential file.
|
|
31
|
+
*/
|
|
32
|
+
export declare class KimiCodeAccountPool extends AccountPoolCore<KimiCodeCredentials, KimiCodePoolAccount, KimiCodeAccountSummaryDto> {
|
|
33
|
+
private readonly store;
|
|
34
|
+
constructor(options?: KimiCodeAccountPoolOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Pick the account for the next request.
|
|
37
|
+
*
|
|
38
|
+
* The returned credential carries its own region, OAuth host and base URL, so
|
|
39
|
+
* the caller must use those rather than the process-wide defaults.
|
|
40
|
+
*/
|
|
41
|
+
getEffectiveCredential(excludeIds?: ReadonlySet<string>, fetchFn?: typeof fetch): Promise<{
|
|
42
|
+
account: KimiCodePoolAccount;
|
|
43
|
+
credentials: KimiCodeCredentials;
|
|
44
|
+
}>;
|
|
45
|
+
/** The pre-pool credential file this pool mirrors its primary account into. */
|
|
46
|
+
mirrorStore(): FileCredentialStore;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=account-pool.d.ts.map
|