@cortexkit/opencode-openai-auth 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/dist/{index-9jpc8yct.js → index-02h7g5f9.js} +1 -1
- package/dist/index-2xppkvkx.js +2 -0
- package/dist/index-3w4vmckx.js +2 -0
- package/dist/{index-zxqb5ydj.js → index-507jh8bv.js} +1 -1
- package/dist/{index-zg1x8sty.js → index-944gsj1s.js} +1 -1
- package/dist/index-nshbgkz1.js +198 -0
- package/dist/{index-87145jkw.js → index-xyg86jgt.js} +1 -1
- package/dist/index.d.ts +381 -35
- package/dist/index.js +66 -161
- package/dist/protocol-Cv9ZmU0p.d.ts +24 -0
- package/dist/quota-normalize-wap0rne8.js +1 -0
- package/dist/rpc/port-file.d.ts +11 -9
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.d.ts +2 -21
- package/dist/rpc/rpc-client.d.ts +6 -4
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.d.ts +7 -5
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state.d.ts +84 -83
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-bvp0y166.js → token-jdvpwk60.js} +1 -1
- package/dist/token-util-zzm7paz9.js +1 -0
- package/dist/tui-preferences.d.ts +27 -26
- package/dist/tui-preferences.js +1 -1
- package/dist/tui.d.ts +18 -17
- package/package.json +7 -14
- package/src/tui/entry.mjs +2 -2
- package/src/tui-compiled/{core/account-paths.ts → raw/core-account-paths.ts} +29 -18
- package/src/tui-compiled/raw/logger.ts +53 -0
- package/src/tui-compiled/{rpc/port-file.ts → raw/rpc-port-file.ts} +1 -1
- package/src/tui-compiled/raw/rpc-protocol.ts +12 -0
- package/src/{rpc/rpc-client.ts → tui-compiled/raw/rpc-rpc-client.ts} +2 -2
- package/src/{sidebar-state.ts → tui-compiled/raw/sidebar-state.ts} +2 -2
- package/src/{tui/command-dialogs.tsx → tui-compiled/raw/tui-command-dialogs.tsx} +5 -5
- package/src/{tui.tsx → tui-compiled/raw/tui.tsx} +11 -10
- package/src/{core/account-paths.ts → tui-compiled/runtime/core-account-paths.ts} +29 -18
- package/src/tui-compiled/runtime/logger.ts +53 -0
- package/src/{rpc/port-file.ts → tui-compiled/runtime/rpc-port-file.ts} +1 -1
- package/src/tui-compiled/runtime/rpc-protocol.ts +12 -0
- package/src/tui-compiled/{rpc/rpc-client.ts → runtime/rpc-rpc-client.ts} +2 -2
- package/src/tui-compiled/{sidebar-state.ts → runtime/sidebar-state.ts} +2 -2
- package/src/tui-compiled/{tui/command-dialogs.tsx → runtime/tui-command-dialogs.tsx} +3 -4
- package/src/tui-compiled/{tui.tsx → runtime/tui.tsx} +10 -10
- package/src/tui-compiled/shared/internal.ts +6 -0
- package/src/{logger.ts → tui-compiled/shared/logger.ts} +82 -21
- package/src/tui-compiled/shared/paths.ts +33 -0
- package/src/{core → tui-compiled/shared}/refresh-file-lock.ts +7 -4
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -15
- package/dist/codex-http.d.ts +0 -3
- package/dist/commands.d.ts +0 -88
- package/dist/config.d.ts +0 -47
- package/dist/core/account-paths.d.ts +0 -25
- package/dist/core/accounts.d.ts +0 -330
- package/dist/core/atomic-write.d.ts +0 -1
- package/dist/core/background-quota-refresh.d.ts +0 -46
- package/dist/core/backoff.d.ts +0 -53
- package/dist/core/cachekeep.d.ts +0 -118
- package/dist/core/oauth.d.ts +0 -138
- package/dist/core/provider.d.ts +0 -70
- package/dist/core/quota-manager.d.ts +0 -192
- package/dist/core/refresh-all-quota.d.ts +0 -86
- package/dist/core/refresh-file-lock.d.ts +0 -12
- package/dist/core/reset-credits.d.ts +0 -116
- package/dist/core/sticky-routing.d.ts +0 -43
- package/dist/dump.d.ts +0 -20
- package/dist/hosted-web-search.d.ts +0 -5
- package/dist/index-8f1200qx.js +0 -6
- package/dist/index-cfjed1st.js +0 -89
- package/dist/index-nrvjr97q.js +0 -3
- package/dist/index-qaggaze1.js +0 -2
- package/dist/index-sdcpzbnk.js +0 -2
- package/dist/logger.d.ts +0 -22
- package/dist/model-costs.d.ts +0 -29
- package/dist/prompt-context.d.ts +0 -19
- package/dist/quota-normalize-dvwtmy7f.js +0 -1
- package/dist/quota-normalize.d.ts +0 -43
- package/dist/raw-ws-bun.d.ts +0 -40
- package/dist/raw-ws-node.d.ts +0 -37
- package/dist/raw-ws-upgrade.d.ts +0 -2
- package/dist/raw-ws.d.ts +0 -3
- package/dist/response-stream-error.d.ts +0 -12
- package/dist/rpc/notifications.d.ts +0 -5
- package/dist/rpc/rpc-server.d.ts +0 -17
- package/dist/token-util-jcj7k7pa.js +0 -1
- package/dist/tui/command-dialogs.d.ts +0 -21
- package/dist/util/error.d.ts +0 -1
- package/dist/util/open-url.d.ts +0 -6
- package/dist/util/proxy-env.d.ts +0 -4
- package/dist/util/record.d.ts +0 -1
- package/dist/util/stable-json.d.ts +0 -1
- package/dist/util/uuid-v7.d.ts +0 -1
- package/dist/version.d.ts +0 -1
- package/dist/ws-pool.d.ts +0 -57
- package/dist/ws.d.ts +0 -71
- package/src/rpc/notifications.ts +0 -54
- package/src/rpc/protocol.ts +0 -33
- package/src/rpc/rpc-server.ts +0 -172
- package/src/tui-compiled/core/refresh-file-lock.ts +0 -381
- package/src/tui-compiled/logger.ts +0 -196
- package/src/tui-compiled/rpc/protocol.ts +0 -33
- package/src/util/error.ts +0 -9
- package/src/util/open-url.ts +0 -30
- package/src/util/proxy-env.ts +0 -42
- package/src/util/record.ts +0 -3
- package/src/util/stable-json.ts +0 -15
- package/src/util/uuid-v7.ts +0 -18
- /package/src/{rpc/rpc-dir.ts → tui-compiled/raw/rpc-rpc-dir.ts} +0 -0
- /package/src/tui-compiled/{tui-preferences.ts → raw/tui-preferences.ts} +0 -0
- /package/src/tui-compiled/{rpc/rpc-dir.ts → runtime/rpc-rpc-dir.ts} +0 -0
- /package/src/{tui-preferences.ts → tui-compiled/runtime/tui-preferences.ts} +0 -0
- /package/src/tui-compiled/{util → shared/util}/error.ts +0 -0
- /package/src/tui-compiled/{util → shared/util}/open-url.ts +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,48 +1,393 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { SidebarMachineState, SidebarState } from "./sidebar-state.js";
|
|
2
|
+
import { Hooks, Plugin, PluginInput } from "@opencode-ai/plugin";
|
|
3
|
+
//#region ../core/dist/provider.d.ts
|
|
4
|
+
type QuotaWindowName = string;
|
|
5
|
+
type ProviderQuotaFn = (input: {
|
|
6
|
+
accessToken: string;
|
|
7
|
+
fetchImpl: typeof fetch;
|
|
8
|
+
now: () => number;
|
|
9
|
+
}) => Promise<OAuthQuotaSnapshot>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region ../core/dist/quota-manager.d.ts
|
|
12
|
+
type QuotaEntry = {
|
|
13
|
+
quota: OAuthQuotaSnapshot;
|
|
14
|
+
refreshAfter: number;
|
|
15
|
+
checkedAt: number;
|
|
16
|
+
accountId?: string;
|
|
17
|
+
};
|
|
18
|
+
type QuotaManagerOptions = {
|
|
19
|
+
storage: AccountStorage | null;
|
|
20
|
+
fetchImpl?: typeof fetch;
|
|
21
|
+
/**
|
|
22
|
+
* Account config file this manager's cross-process refresh locks are named
|
|
23
|
+
* after. Host-resolved and required, so two hosts pointing at different
|
|
24
|
+
* stores never contend on one another's lock.
|
|
25
|
+
*/
|
|
26
|
+
configPath: string;
|
|
27
|
+
now?: () => number;
|
|
28
|
+
/** Injected quota-fetch function — replaces the hard-imported Anthropic fetchOAuthQuotaSnapshot */
|
|
29
|
+
fetchQuotaFn?: ProviderQuotaFn;
|
|
30
|
+
onMainQuotaFetched?: (quota: OAuthQuotaSnapshot, checkedAt: number, fingerprint: string, fetchStartedAt: number) => void;
|
|
31
|
+
onApiError?: (error: AccountOperationError) => void;
|
|
32
|
+
};
|
|
33
|
+
declare class QuotaManager {
|
|
34
|
+
private main;
|
|
35
|
+
private mainTokenFp;
|
|
36
|
+
private mainQuotaAccountId;
|
|
37
|
+
private fallbacks;
|
|
38
|
+
private fallbackTokenFps;
|
|
39
|
+
private inflightMain;
|
|
40
|
+
private inflightMainFp;
|
|
41
|
+
private inflightFallbacks;
|
|
42
|
+
private mainLastApiError;
|
|
43
|
+
private fallbackApiErrors;
|
|
44
|
+
private fallbackErrorTokenFps;
|
|
45
|
+
private rateLimitedUntilMap;
|
|
46
|
+
private apiGate;
|
|
47
|
+
private lastApiCallAt;
|
|
48
|
+
private storage;
|
|
49
|
+
private readonly fetchImpl;
|
|
50
|
+
private readonly now;
|
|
51
|
+
private readonly fetchQuotaFn;
|
|
52
|
+
private readonly onMainQuotaFetched;
|
|
53
|
+
private readonly onApiError;
|
|
54
|
+
private readonly configPath;
|
|
55
|
+
constructor(opts: QuotaManagerOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Cached main quota entry. Pass the live access token to enforce token
|
|
58
|
+
* binding: if the cached entry was produced by a different token (main
|
|
59
|
+
* account switched), it is dropped and null is returned so the caller
|
|
60
|
+
* refetches for the current account. Called without a token (e.g. for
|
|
61
|
+
* display) it returns whatever is cached.
|
|
62
|
+
*/
|
|
63
|
+
getMain(accessToken?: string): QuotaEntry | null;
|
|
64
|
+
/**
|
|
65
|
+
* Cached fallback quota entry. Pass the live access token to enforce token
|
|
66
|
+
* binding: if the entry was produced by a different token (account re-login),
|
|
67
|
+
* it is dropped and null is returned so the caller refetches.
|
|
68
|
+
*/
|
|
69
|
+
getFallback(accountId: string, accessToken?: string): QuotaEntry | null;
|
|
70
|
+
getAllFallbacks(): Map<string, QuotaEntry>;
|
|
71
|
+
setMain(accessToken: string, entry: QuotaEntry, accountId?: string, completeSnapshot?: boolean): void;
|
|
72
|
+
/**
|
|
73
|
+
* Non-invalidating read of the cached main quota for POLICY decisions
|
|
74
|
+
* (killswitch). Unlike getMain(token), a token mismatch does NOT drop the
|
|
75
|
+
* cache — an access-token refresh is a same-account event and must not turn a
|
|
76
|
+
* known-exhausted account into "unknown" (which would fail open and spend).
|
|
77
|
+
*
|
|
78
|
+
* Pass the live ChatGPT accountId to still drop on a genuine account SWITCH:
|
|
79
|
+
* if the cached entry's account identity is known and differs, return null so
|
|
80
|
+
* the killswitch treats it as unknown rather than judging account A by account
|
|
81
|
+
* B's quota. When identity is unknown on either side, the cached snapshot is
|
|
82
|
+
* returned (best-effort) — the same fail-open-on-unknown stance as elsewhere.
|
|
83
|
+
*/
|
|
84
|
+
peekMainForPolicy(accountId?: string): QuotaEntry | null;
|
|
85
|
+
/**
|
|
86
|
+
* Non-invalidating read of a cached fallback quota for POLICY decisions
|
|
87
|
+
* (killswitch, admission). Keyed by the stable internal account id, so a
|
|
88
|
+
* token refresh for the same account does not drop it (getFallback(id, token)
|
|
89
|
+
* would).
|
|
90
|
+
*
|
|
91
|
+
* Pass the live ChatGPT identity to still drop on a genuine re-login: if the
|
|
92
|
+
* cached entry's identity is known and differs, return null so the previous
|
|
93
|
+
* identity's (possibly exhausted) quota is never judged against its
|
|
94
|
+
* replacement. Unknown on either side fails open, matching peekMainForPolicy.
|
|
95
|
+
*/
|
|
96
|
+
peekFallbackForPolicy(accountId: string, identity?: string): QuotaEntry | null;
|
|
97
|
+
setFallback(accountId: string, entry: QuotaEntry, accessToken?: string, completeSnapshot?: boolean, identity?: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Mark accountId ('main' or a fallback id) rate-limited until resetAtMs.
|
|
100
|
+
* Keeps the LATER reset: skips only when an existing mark is strictly
|
|
101
|
+
* later than resetAtMs, so an equal-reset re-mark still applies (idempotent)
|
|
102
|
+
* instead of being silently dropped by a stale `>=` comparison.
|
|
103
|
+
*/
|
|
104
|
+
markRateLimited(accountId: string, resetAtMs: number): void;
|
|
105
|
+
/** True iff accountId has a mark whose reset has not yet passed. */
|
|
106
|
+
isRateLimited(accountId: string): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Raw stored reset for accountId's mark, or undefined if none. Unlike
|
|
109
|
+
* isRateLimited, this does NOT apply read-time expiry — callers on the
|
|
110
|
+
* block path already know the mark is live (isRateLimited just returned
|
|
111
|
+
* true) and want its exact reset estimate for a Retry-After computation.
|
|
112
|
+
*/
|
|
113
|
+
rateLimitedUntil(accountId: string): number | undefined;
|
|
114
|
+
/** Explicit early clear — read-time expiry in isRateLimited is primary. */
|
|
115
|
+
clearRateLimited(accountId: string): void;
|
|
116
|
+
refreshMain(accessToken: string): Promise<OAuthQuotaSnapshot>;
|
|
117
|
+
refreshFallback(accountId: string, accessToken: string): Promise<OAuthQuotaSnapshot>;
|
|
118
|
+
refreshAllFallbacks(accounts: OAuthAccount[]): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Fire-and-forget refresh. Does not await, swallows errors.
|
|
121
|
+
*/
|
|
122
|
+
refreshMainInBackground(accessToken: string): void;
|
|
123
|
+
isMainStale(): boolean;
|
|
124
|
+
isFallbackStale(accountId: string, accessToken?: string): boolean;
|
|
125
|
+
shouldRefreshOnRequestCount(requestCount: number): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Combined check: should a refresh happen right now?
|
|
128
|
+
* True if main is stale by time OR triggered by request count.
|
|
129
|
+
*/
|
|
130
|
+
needsRefresh(requestCount: number): boolean;
|
|
131
|
+
updateStorage(storage: AccountStorage | null): void;
|
|
132
|
+
/**
|
|
133
|
+
* Seed/update the main quota cache from persisted state. This is deliberately
|
|
134
|
+
* callable after every disk load so another plugin process's fresh quota write
|
|
135
|
+
* can stop this process from showing "checking…" or making a redundant quota
|
|
136
|
+
* API call.
|
|
137
|
+
*/
|
|
138
|
+
seedMainFromStorage(storage: AccountStorage | null, accessToken?: string): void;
|
|
139
|
+
private seedMainBackoffFromStorage;
|
|
140
|
+
/**
|
|
141
|
+
* Seed fallback cache entries from persisted account.quota data.
|
|
142
|
+
* Updates older in-memory entries so a fresh quota write from another plugin
|
|
143
|
+
* process prevents redundant checks and stale sidebar writes.
|
|
144
|
+
*/
|
|
145
|
+
seedFallbacksFromAccounts(accounts: OAuthAccount[]): void;
|
|
146
|
+
/**
|
|
147
|
+
* Whether the MAIN quota API is currently in backoff. Scoped to the main
|
|
148
|
+
* account — a fallback account's 429 never reports here.
|
|
149
|
+
*/
|
|
150
|
+
isBackedOff(): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Whether a specific fallback account's quota API is in backoff.
|
|
153
|
+
*/
|
|
154
|
+
isFallbackBackedOff(accountId: string, accessToken?: string): boolean;
|
|
155
|
+
getLastApiError(): AccountOperationError | undefined;
|
|
156
|
+
/** Minimum gap between consecutive quota API calls (ms). */
|
|
157
|
+
private static readonly API_CALL_GAP_MS;
|
|
158
|
+
private static fallbackInflightKey;
|
|
159
|
+
private static quotaLockName;
|
|
160
|
+
/**
|
|
161
|
+
* Serialize API calls through a shared gate so only one
|
|
162
|
+
* quota API request runs at a time, with a minimum gap
|
|
163
|
+
* between calls. Prevents concurrent and rapid-fire calls
|
|
164
|
+
* from triggering rate limits.
|
|
165
|
+
*/
|
|
166
|
+
private _enqueueApiFetch;
|
|
167
|
+
private _fetchMain;
|
|
168
|
+
private _fetchFallback;
|
|
169
|
+
/** Route through injected fetchQuotaFn, or throw if unset. */
|
|
170
|
+
private _fetchQuota;
|
|
171
|
+
private static isAuthError;
|
|
172
|
+
/** Main quota failure: arms main-only backoff and persists via onApiError. */
|
|
173
|
+
private _handleMainFetchError;
|
|
174
|
+
/**
|
|
175
|
+
* Fallback quota failure: arms backoff for THIS account only. Never touches
|
|
176
|
+
* main backoff state and never calls onApiError (which persists the main
|
|
177
|
+
* quota error) — the per-account error is recorded by the caller via the
|
|
178
|
+
* account's lastQuotaRefreshError.
|
|
179
|
+
*/
|
|
180
|
+
private _handleFallbackFetchError;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region ../core/dist/paths.d.ts
|
|
184
|
+
/**
|
|
185
|
+
* The config file and the runtime-state file a store operation reads and writes.
|
|
186
|
+
*
|
|
187
|
+
* Both are required. A store function never derives one from the other, because
|
|
188
|
+
* a host may point its state file somewhere the derivation would not reach and
|
|
189
|
+
* a silently derived path would lock one file while writing another.
|
|
190
|
+
*/
|
|
191
|
+
interface AccountPaths {
|
|
192
|
+
configPath: string;
|
|
193
|
+
statePath: string;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region ../core/dist/accounts.d.ts
|
|
197
|
+
type AccountQuotaWindow = {
|
|
198
|
+
usedPercent: number;
|
|
199
|
+
remainingPercent: number;
|
|
200
|
+
resetsAt?: string;
|
|
201
|
+
checkedAt: number;
|
|
202
|
+
windowMinutes?: number;
|
|
203
|
+
};
|
|
204
|
+
interface OAuthQuotaSnapshot {
|
|
205
|
+
primary?: AccountQuotaWindow;
|
|
206
|
+
secondary?: AccountQuotaWindow;
|
|
207
|
+
resetCreditsAvailable?: number;
|
|
208
|
+
resetCreditsApplicable?: number;
|
|
209
|
+
}
|
|
210
|
+
type AccountBase = {
|
|
211
|
+
id: string;
|
|
212
|
+
label?: string;
|
|
213
|
+
enabled?: boolean;
|
|
214
|
+
addedAt?: number;
|
|
215
|
+
lastUsed?: number;
|
|
216
|
+
/** Stable ChatGPT account identifier extracted from the OAuth token claims. */
|
|
217
|
+
accountId?: string;
|
|
218
|
+
};
|
|
219
|
+
type AccountOperationError = {
|
|
220
|
+
message: string;
|
|
221
|
+
checkedAt: number;
|
|
222
|
+
nextRetryAt?: number;
|
|
223
|
+
retryCount?: number;
|
|
224
|
+
tokenHash?: string;
|
|
225
|
+
};
|
|
226
|
+
type OAuthAccount = AccountBase & {
|
|
227
|
+
type: 'oauth';
|
|
228
|
+
access?: string;
|
|
229
|
+
refresh: string;
|
|
230
|
+
expires?: number;
|
|
231
|
+
lastRefreshedAt?: number;
|
|
232
|
+
lastRefreshError?: AccountOperationError;
|
|
233
|
+
lastQuotaRefreshError?: AccountOperationError;
|
|
234
|
+
quota?: OAuthQuotaSnapshot;
|
|
235
|
+
};
|
|
236
|
+
type ApiKeyAccount = AccountBase & {
|
|
237
|
+
type: 'api';
|
|
238
|
+
apiKey?: string;
|
|
239
|
+
baseURL: string;
|
|
240
|
+
authHeader?: 'authorization-bearer' | 'x-api-key';
|
|
241
|
+
};
|
|
242
|
+
type FallbackAccount = OAuthAccount | ApiKeyAccount;
|
|
243
|
+
type RoutingMode = 'main-first' | 'fallback-first' | 'sticky-balanced';
|
|
244
|
+
type KillswitchThresholds = Partial<Record<QuotaWindowName | '5h' | '1w', number>>;
|
|
245
|
+
type KillswitchConfig = {
|
|
246
|
+
enabled?: boolean;
|
|
247
|
+
main?: KillswitchThresholds;
|
|
248
|
+
accounts?: Record<string, KillswitchThresholds>;
|
|
249
|
+
};
|
|
250
|
+
interface ResetInFlight {
|
|
251
|
+
redeemRequestId: string;
|
|
252
|
+
creditId: string;
|
|
253
|
+
startedAt: number;
|
|
254
|
+
}
|
|
255
|
+
interface ResetLastOutcome {
|
|
256
|
+
code: string;
|
|
257
|
+
at: number;
|
|
258
|
+
previousOutcome?: {
|
|
259
|
+
code: string;
|
|
260
|
+
at: number;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
interface ResetAccountState {
|
|
264
|
+
inFlight?: ResetInFlight | Record<string, unknown>;
|
|
265
|
+
lastOutcome?: ResetLastOutcome;
|
|
266
|
+
cooldownUntil?: number;
|
|
267
|
+
}
|
|
268
|
+
type ResetStateByAccount = Record<string, ResetAccountState>;
|
|
269
|
+
type AccountStorage = {
|
|
270
|
+
version: 1;
|
|
271
|
+
main?: {
|
|
272
|
+
type: 'opencode';
|
|
273
|
+
provider: 'openai';
|
|
274
|
+
};
|
|
275
|
+
routing?: {
|
|
276
|
+
mode?: RoutingMode;
|
|
277
|
+
};
|
|
278
|
+
fallbackOn?: number[];
|
|
279
|
+
refresh?: {
|
|
280
|
+
enabled?: boolean;
|
|
281
|
+
intervalMinutes?: number;
|
|
282
|
+
refreshBeforeExpiryMinutes?: number;
|
|
283
|
+
mainLastRefreshError?: AccountOperationError;
|
|
284
|
+
mainRefreshLeaseId?: string;
|
|
285
|
+
mainRefreshLeaseUntil?: number;
|
|
286
|
+
mainRefreshLeaseTokenHash?: string;
|
|
287
|
+
};
|
|
288
|
+
quota?: {
|
|
289
|
+
enabled?: boolean;
|
|
290
|
+
checkIntervalMinutes?: number;
|
|
291
|
+
refreshEveryNRequests?: number;
|
|
292
|
+
minimumRemaining?: Partial<Record<QuotaWindowName | '5h' | '1w', number>>;
|
|
293
|
+
failClosedOnUnknownQuota?: boolean;
|
|
294
|
+
showToasts?: boolean;
|
|
295
|
+
mainQuota?: OAuthQuotaSnapshot;
|
|
296
|
+
mainQuotaCheckedAt?: number;
|
|
297
|
+
mainQuotaToken?: string;
|
|
298
|
+
mainLastQuotaApiError?: AccountOperationError;
|
|
299
|
+
};
|
|
300
|
+
reset?: ResetStateByAccount;
|
|
301
|
+
dump?: {
|
|
302
|
+
enabled?: boolean;
|
|
303
|
+
};
|
|
304
|
+
costZeroing?: {
|
|
305
|
+
enabled?: boolean;
|
|
306
|
+
};
|
|
307
|
+
killswitch?: KillswitchConfig;
|
|
308
|
+
logging?: {
|
|
309
|
+
level?: string;
|
|
310
|
+
};
|
|
311
|
+
cachekeep?: {
|
|
312
|
+
enabled?: boolean;
|
|
313
|
+
subagents?: boolean;
|
|
314
|
+
sustain?: boolean;
|
|
315
|
+
/** Clock-hour window start (0-23, inclusive) — keeps cachekeep idle warming
|
|
316
|
+
* inside `[startHour, endHour)` local hours. Omit to warm unconditionally. */
|
|
317
|
+
startHour?: number;
|
|
318
|
+
/** Clock-hour window end (0-23, exclusive) — must differ from startHour
|
|
319
|
+
* to be honored; an unset or equal hour falls back to "always warm". */
|
|
320
|
+
endHour?: number;
|
|
321
|
+
};
|
|
322
|
+
/** Stable ChatGPT account identifier of the main account (extracted from OAuth token). */
|
|
323
|
+
mainAccountId?: string;
|
|
324
|
+
accounts: FallbackAccount[];
|
|
325
|
+
};
|
|
326
|
+
declare function loadAccounts(paths: AccountPaths): Promise<AccountStorage | null>;
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region ../core/dist/oauth.d.ts
|
|
329
|
+
interface IdTokenClaims {
|
|
330
|
+
chatgpt_account_id?: string;
|
|
331
|
+
email?: string;
|
|
332
|
+
organizations?: Array<{
|
|
333
|
+
id: string;
|
|
334
|
+
}>;
|
|
335
|
+
'https://api.openai.com/auth'?: {
|
|
336
|
+
chatgpt_account_id?: string;
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
export declare function parseJwtClaims(token: string): IdTokenClaims | undefined;
|
|
340
|
+
export declare function extractAccountIdFromClaims(claims: IdTokenClaims): string | undefined;
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region ../core/dist/commands.d.ts
|
|
343
|
+
interface ResetTargetIdentity {
|
|
344
|
+
accountKey: string;
|
|
345
|
+
label: string;
|
|
346
|
+
accessToken: string;
|
|
347
|
+
chatgptAccountId?: string;
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/index.d.ts
|
|
6
351
|
export declare const MAIN_REFRESH_LOCK_TTL_MS: number;
|
|
7
352
|
export declare const MAIN_REFRESH_LEASE_TTL_MS = 90000;
|
|
8
353
|
export declare class AuthPersistError extends Error {
|
|
9
|
-
|
|
10
|
-
|
|
354
|
+
readonly code = "OPENAI_AUTH_PERSIST_FAILED";
|
|
355
|
+
constructor(cause: unknown);
|
|
11
356
|
}
|
|
12
357
|
export type ResetTargetResolutionErrorKind = 'unknown_account' | 'disabled_account' | 'non_oauth_account' | 'token_unavailable';
|
|
13
358
|
export declare class ResetTargetResolutionError extends Error {
|
|
14
|
-
|
|
15
|
-
|
|
359
|
+
readonly code: ResetTargetResolutionErrorKind;
|
|
360
|
+
constructor(code: ResetTargetResolutionErrorKind, message: string);
|
|
16
361
|
}
|
|
17
362
|
interface ResetTargetResolverDeps {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
363
|
+
getAuth: () => Promise<{
|
|
364
|
+
type: string;
|
|
365
|
+
access?: string;
|
|
366
|
+
refresh?: string;
|
|
367
|
+
expires?: number;
|
|
368
|
+
}>;
|
|
369
|
+
refreshMainWithLease: () => Promise<{
|
|
370
|
+
access: string;
|
|
371
|
+
refresh: string;
|
|
372
|
+
expires: number;
|
|
373
|
+
}>;
|
|
374
|
+
refreshFallbackAccount: (account: OAuthAccount, storage: AccountStorage) => Promise<OAuthAccount>;
|
|
375
|
+
loadAccounts: typeof loadAccounts;
|
|
376
|
+
accountStoragePath: string;
|
|
377
|
+
accountStatePath: string;
|
|
378
|
+
now: () => number;
|
|
33
379
|
}
|
|
34
380
|
export declare function createResetTargetResolver(deps: ResetTargetResolverDeps): (accountKey: string) => Promise<ResetTargetIdentity>;
|
|
35
381
|
export declare function buildResetRedemptionDeps(): {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
382
|
+
fetchImpl: typeof fetch;
|
|
383
|
+
now: () => number;
|
|
384
|
+
randomUUID: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
39
385
|
};
|
|
40
|
-
export { extractAccountIdFromClaims, type IdTokenClaims, parseJwtClaims, } from './core/oauth';
|
|
41
386
|
interface CodexAuthPluginOptions {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
387
|
+
issuer?: string;
|
|
388
|
+
codexApiEndpoint?: string;
|
|
389
|
+
experimentalWebSockets?: boolean;
|
|
390
|
+
responsesLite?: boolean;
|
|
46
391
|
}
|
|
47
392
|
export declare function findCachekeepFallbackAccount(accounts: FallbackAccount[], accountId: string): OAuthAccount | undefined;
|
|
48
393
|
export declare function mergePushedQuotaMetadata(incoming: OAuthQuotaSnapshot, previous: OAuthQuotaSnapshot | undefined): OAuthQuotaSnapshot;
|
|
@@ -52,7 +397,8 @@ export declare function resolveSidebarSessionId(headers: Headers): string | unde
|
|
|
52
397
|
export declare function CodexAuthPlugin(input: PluginInput, options?: CodexAuthPluginOptions): Promise<Hooks>;
|
|
53
398
|
export declare const OpenAIAuthPlugin: Plugin;
|
|
54
399
|
declare const _default: {
|
|
55
|
-
|
|
56
|
-
|
|
400
|
+
id: string;
|
|
401
|
+
server: Plugin;
|
|
57
402
|
};
|
|
58
|
-
|
|
403
|
+
//#endregion
|
|
404
|
+
export { type IdTokenClaims, _default as default };
|