jeopi-ai 16.6.26 → 16.6.27
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
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [16.6.27] - 2026-11-17
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Shared cross-runtime OAuth 429 cooldown synchronization via mode-`0600` `~/.agents/auth-pool/cooldowns.json` (`shared-cooldown-bridge.ts`, wired into `AuthStorage`), with stat-gated in-memory caching for zero-copy repeat lookups and hermetic test isolation.
|
|
10
|
+
|
|
5
11
|
## [16.6.25] - 2026-11-14
|
|
6
12
|
|
|
7
13
|
### Fixed
|
|
@@ -392,6 +392,8 @@ export type AuthStorageOptions = {
|
|
|
392
392
|
* AuthStorage caller surfaces that to its own consumer unchanged.
|
|
393
393
|
*/
|
|
394
394
|
fetchUsageReports?: (signal?: AbortSignal) => Promise<UsageReport[] | null>;
|
|
395
|
+
/** Enable cross-runtime 429 cooldown synchronization via ~/.agents/auth-pool/cooldowns.json. */
|
|
396
|
+
sharedCooldown?: boolean;
|
|
395
397
|
};
|
|
396
398
|
export { isDefinitiveOAuthFailure } from "./error/auth-classify";
|
|
397
399
|
/**
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface SharedCooldownRecord {
|
|
2
|
+
blockedUntil: number;
|
|
3
|
+
reason?: string;
|
|
4
|
+
source: "jeo-code" | "jeopi";
|
|
5
|
+
}
|
|
6
|
+
export declare function canonicalSharedProvider(provider: string): string;
|
|
7
|
+
export declare function resolveSharedCooldownPath(): string;
|
|
8
|
+
export declare function shouldEnableSharedCooldown(dbPath?: string): boolean;
|
|
9
|
+
export declare function sharedCredentialIdentityKey(cred: {
|
|
10
|
+
type?: string;
|
|
11
|
+
email?: unknown;
|
|
12
|
+
accountId?: unknown;
|
|
13
|
+
refresh?: unknown;
|
|
14
|
+
access?: unknown;
|
|
15
|
+
}): string | null;
|
|
16
|
+
export declare function lookupSharedCredentialCooldown(provider: string, cred: {
|
|
17
|
+
type?: string;
|
|
18
|
+
email?: unknown;
|
|
19
|
+
accountId?: unknown;
|
|
20
|
+
refresh?: unknown;
|
|
21
|
+
access?: unknown;
|
|
22
|
+
} | undefined): number | undefined;
|
|
23
|
+
export declare function recordSharedCredentialCooldown(provider: string, cred: {
|
|
24
|
+
type?: string;
|
|
25
|
+
email?: unknown;
|
|
26
|
+
accountId?: unknown;
|
|
27
|
+
refresh?: unknown;
|
|
28
|
+
access?: unknown;
|
|
29
|
+
} | undefined, blockedUntil: number, reason?: string): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "jeopi-ai",
|
|
4
|
-
"version": "16.6.
|
|
4
|
+
"version": "16.6.27",
|
|
5
5
|
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
6
6
|
"homepage": "https://github.com/akillness/jeopi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@bufbuild/protobuf": "^2.12.0",
|
|
41
|
-
"jeopi-catalog": "16.6.
|
|
42
|
-
"jeopi-utils": "16.6.
|
|
43
|
-
"jeopi-wire": "16.6.
|
|
41
|
+
"jeopi-catalog": "16.6.27",
|
|
42
|
+
"jeopi-utils": "16.6.27",
|
|
43
|
+
"jeopi-wire": "16.6.27",
|
|
44
44
|
"arktype": "2.2.3",
|
|
45
45
|
"zod": "^4"
|
|
46
46
|
},
|
package/src/auth-storage.ts
CHANGED
|
@@ -17,6 +17,11 @@ import { isUsageLimitOutcome } from "./error/rate-limit";
|
|
|
17
17
|
import { getProviderDefinition, PASTE_CODE_LOGIN_PROVIDERS } from "./registry";
|
|
18
18
|
import { getOAuthApiKey, getOAuthProvider, refreshOAuthToken } from "./registry/oauth";
|
|
19
19
|
import type { OAuthController, OAuthCredentials, OAuthProvider, OAuthProviderId } from "./registry/oauth/types";
|
|
20
|
+
import {
|
|
21
|
+
lookupSharedCredentialCooldown,
|
|
22
|
+
recordSharedCredentialCooldown,
|
|
23
|
+
shouldEnableSharedCooldown,
|
|
24
|
+
} from "./shared-cooldown-bridge";
|
|
20
25
|
import { getEnvApiKey, getEnvApiKeyName } from "./stream";
|
|
21
26
|
import type { Provider } from "./types";
|
|
22
27
|
import type {
|
|
@@ -478,6 +483,8 @@ export type AuthStorageOptions = {
|
|
|
478
483
|
* AuthStorage caller surfaces that to its own consumer unchanged.
|
|
479
484
|
*/
|
|
480
485
|
fetchUsageReports?: (signal?: AbortSignal) => Promise<UsageReport[] | null>;
|
|
486
|
+
/** Enable cross-runtime 429 cooldown synchronization via ~/.agents/auth-pool/cooldowns.json. */
|
|
487
|
+
sharedCooldown?: boolean;
|
|
481
488
|
};
|
|
482
489
|
|
|
483
490
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -987,10 +994,12 @@ export class AuthStorage {
|
|
|
987
994
|
#generationListeners: Set<(generation: number) => void> = new Set();
|
|
988
995
|
#oauthRefreshInFlight: Map<number, Promise<AuthCredentialSnapshotEntry>> = new Map();
|
|
989
996
|
#oauthCredentialRefreshInFlight: Map<number, Promise<OAuthCredentials>> = new Map();
|
|
997
|
+
#sharedCooldownEnabled = false;
|
|
990
998
|
#closed = false;
|
|
991
999
|
|
|
992
1000
|
constructor(store: AuthCredentialStore, options: AuthStorageOptions = {}) {
|
|
993
1001
|
this.#store = store;
|
|
1002
|
+
this.#sharedCooldownEnabled = options.sharedCooldown ?? shouldEnableSharedCooldown();
|
|
994
1003
|
this.#configValueResolver = options.configValueResolver ?? defaultConfigValueResolver;
|
|
995
1004
|
this.#usageProviderResolver = options.usageProviderResolver ?? resolveDefaultUsageProvider;
|
|
996
1005
|
this.#rankingStrategyResolver = options.rankingStrategyResolver ?? resolveDefaultRankingStrategy;
|
|
@@ -1028,7 +1037,10 @@ export class AuthStorage {
|
|
|
1028
1037
|
*/
|
|
1029
1038
|
static async create(dbPath: string, options: AuthStorageOptions = {}): Promise<AuthStorage> {
|
|
1030
1039
|
const store = await SqliteAuthCredentialStore.open(dbPath);
|
|
1031
|
-
return new AuthStorage(store,
|
|
1040
|
+
return new AuthStorage(store, {
|
|
1041
|
+
...options,
|
|
1042
|
+
sharedCooldown: options.sharedCooldown ?? shouldEnableSharedCooldown(dbPath),
|
|
1043
|
+
});
|
|
1032
1044
|
}
|
|
1033
1045
|
|
|
1034
1046
|
/**
|
|
@@ -1337,15 +1349,24 @@ export class AuthStorage {
|
|
|
1337
1349
|
return blockedUntil;
|
|
1338
1350
|
}
|
|
1339
1351
|
|
|
1340
|
-
/** Returns block expiry timestamp for a credential, checking global
|
|
1352
|
+
/** Returns block expiry timestamp for a credential, checking global, scoped, and shared pool blocks. */
|
|
1341
1353
|
#getCredentialBlockedUntil(
|
|
1342
1354
|
providerKey: string,
|
|
1343
1355
|
credentialIndex: number,
|
|
1344
1356
|
blockScope: string | undefined = undefined,
|
|
1345
1357
|
): number | undefined {
|
|
1346
1358
|
const globalBlockedUntil = this.#getCredentialBlockedUntilForKey(providerKey, credentialIndex);
|
|
1347
|
-
|
|
1348
|
-
|
|
1359
|
+
const localUntil =
|
|
1360
|
+
globalBlockedUntil !== undefined || !blockScope
|
|
1361
|
+
? globalBlockedUntil
|
|
1362
|
+
: this.#getCredentialBlockedUntilForKey(this.#toScopedBackoffKey(providerKey, blockScope), credentialIndex);
|
|
1363
|
+
if (!this.#sharedCooldownEnabled) return localUntil;
|
|
1364
|
+
const colonIdx = providerKey.lastIndexOf(":");
|
|
1365
|
+
const provider = colonIdx > 0 ? providerKey.slice(0, colonIdx) : providerKey;
|
|
1366
|
+
const cred = this.#getCredentialsForProvider(provider)[credentialIndex];
|
|
1367
|
+
const sharedUntil = lookupSharedCredentialCooldown(provider, cred);
|
|
1368
|
+
if (localUntil !== undefined && sharedUntil !== undefined) return Math.max(localUntil, sharedUntil);
|
|
1369
|
+
return localUntil ?? sharedUntil;
|
|
1349
1370
|
}
|
|
1350
1371
|
|
|
1351
1372
|
/** Checks if a credential is temporarily blocked due to usage limits. */
|
|
@@ -1369,6 +1390,17 @@ export class AuthStorage {
|
|
|
1369
1390
|
const existing = backoffMap.get(credentialIndex) ?? 0;
|
|
1370
1391
|
backoffMap.set(credentialIndex, Math.max(existing, blockedUntilMs));
|
|
1371
1392
|
this.#credentialBackoff.set(backoffKey, backoffMap);
|
|
1393
|
+
if (this.#sharedCooldownEnabled) {
|
|
1394
|
+
const colonIdx = providerKey.lastIndexOf(":");
|
|
1395
|
+
const provider = colonIdx > 0 ? providerKey.slice(0, colonIdx) : providerKey;
|
|
1396
|
+
const cred = this.#getCredentialsForProvider(provider)[credentialIndex];
|
|
1397
|
+
recordSharedCredentialCooldown(
|
|
1398
|
+
provider,
|
|
1399
|
+
cred,
|
|
1400
|
+
blockedUntilMs,
|
|
1401
|
+
blockScope ? `usage_limit:${blockScope}` : "usage_limit",
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1372
1404
|
}
|
|
1373
1405
|
|
|
1374
1406
|
/** Records which credential was used for a session (for rate-limit switching). */
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
|
|
6
|
+
export interface SharedCooldownRecord {
|
|
7
|
+
blockedUntil: number;
|
|
8
|
+
reason?: string;
|
|
9
|
+
source: "jeo-code" | "jeopi";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface SharedCooldownFile {
|
|
13
|
+
version: 1;
|
|
14
|
+
updatedAt: number;
|
|
15
|
+
cooldowns: Record<string, SharedCooldownRecord>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const CANONICAL_PROVIDER_MAP: Record<string, string> = {
|
|
19
|
+
anthropic: "anthropic",
|
|
20
|
+
openai: "openai",
|
|
21
|
+
"openai-codex": "openai",
|
|
22
|
+
antigravity: "antigravity",
|
|
23
|
+
"google-antigravity": "antigravity",
|
|
24
|
+
gemini: "gemini",
|
|
25
|
+
"google-gemini-cli": "gemini",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function canonicalSharedProvider(provider: string): string {
|
|
29
|
+
return CANONICAL_PROVIDER_MAP[provider.toLowerCase()] ?? provider.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function resolveSharedCooldownPath(): string {
|
|
33
|
+
return (
|
|
34
|
+
process.env.JEO_SHARED_AUTH_POOL_PATH?.trim() || path.join(os.homedir(), ".agents", "auth-pool", "cooldowns.json")
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function shouldEnableSharedCooldown(dbPath?: string): boolean {
|
|
39
|
+
if (process.env.JEO_SHARED_AUTH_POOL_PATH?.trim()) return true;
|
|
40
|
+
if (!dbPath || dbPath === ":memory:") return false;
|
|
41
|
+
const resolved = path.resolve(dbPath);
|
|
42
|
+
const jeopiRoot = path.resolve(path.join(os.homedir(), ".jeopi"));
|
|
43
|
+
return resolved === jeopiRoot || resolved.startsWith(`${jeopiRoot}${path.sep}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function hashToken(value: string): string {
|
|
47
|
+
return createHash("sha256").update(value.trim()).digest("hex").slice(0, 16);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function sharedCredentialIdentityKey(cred: {
|
|
51
|
+
type?: string;
|
|
52
|
+
email?: unknown;
|
|
53
|
+
accountId?: unknown;
|
|
54
|
+
refresh?: unknown;
|
|
55
|
+
access?: unknown;
|
|
56
|
+
}): string | null {
|
|
57
|
+
if (cred.type !== "oauth") return null;
|
|
58
|
+
if (typeof cred.email === "string" && cred.email.trim()) {
|
|
59
|
+
return `email:${cred.email.trim().toLowerCase()}`;
|
|
60
|
+
}
|
|
61
|
+
if (typeof cred.accountId === "string" && cred.accountId.trim()) {
|
|
62
|
+
return `account:${cred.accountId.trim().toLowerCase()}`;
|
|
63
|
+
}
|
|
64
|
+
if (typeof cred.refresh === "string" && cred.refresh.trim()) {
|
|
65
|
+
return `tok:${hashToken(cred.refresh)}`;
|
|
66
|
+
}
|
|
67
|
+
if (typeof cred.access === "string" && cred.access.trim()) {
|
|
68
|
+
return `tok:${hashToken(cred.access)}`;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let cachedSharedFile: {
|
|
74
|
+
filePath: string;
|
|
75
|
+
mtimeNs: bigint;
|
|
76
|
+
size: bigint;
|
|
77
|
+
ino: bigint;
|
|
78
|
+
data: SharedCooldownFile;
|
|
79
|
+
} | null = null;
|
|
80
|
+
|
|
81
|
+
function pruneActiveCooldowns(raw: SharedCooldownFile): SharedCooldownFile {
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
const active: Record<string, SharedCooldownRecord> = {};
|
|
84
|
+
for (const [k, rec] of Object.entries(raw.cooldowns)) {
|
|
85
|
+
if (rec.blockedUntil > now) active[k] = rec;
|
|
86
|
+
}
|
|
87
|
+
return { version: 1, updatedAt: raw.updatedAt, cooldowns: active };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function readSharedFile(): SharedCooldownFile {
|
|
91
|
+
const filePath = resolveSharedCooldownPath();
|
|
92
|
+
try {
|
|
93
|
+
const st = fs.statSync(filePath, { bigint: true });
|
|
94
|
+
if (
|
|
95
|
+
cachedSharedFile &&
|
|
96
|
+
cachedSharedFile.filePath === filePath &&
|
|
97
|
+
cachedSharedFile.mtimeNs === st.mtimeNs &&
|
|
98
|
+
cachedSharedFile.size === st.size &&
|
|
99
|
+
cachedSharedFile.ino === st.ino
|
|
100
|
+
) {
|
|
101
|
+
return pruneActiveCooldowns(cachedSharedFile.data);
|
|
102
|
+
}
|
|
103
|
+
const raw = fs.readFileSync(filePath, "utf8");
|
|
104
|
+
const parsed = JSON.parse(raw) as Partial<SharedCooldownFile>;
|
|
105
|
+
if (parsed && parsed.version === 1 && parsed.cooldowns && typeof parsed.cooldowns === "object") {
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
const active: Record<string, SharedCooldownRecord> = {};
|
|
108
|
+
for (const [k, rec] of Object.entries(parsed.cooldowns)) {
|
|
109
|
+
if (
|
|
110
|
+
rec &&
|
|
111
|
+
typeof rec.blockedUntil === "number" &&
|
|
112
|
+
Number.isFinite(rec.blockedUntil) &&
|
|
113
|
+
rec.blockedUntil > now
|
|
114
|
+
) {
|
|
115
|
+
active[k] = {
|
|
116
|
+
blockedUntil: rec.blockedUntil,
|
|
117
|
+
...(typeof rec.reason === "string" ? { reason: rec.reason } : {}),
|
|
118
|
+
source: rec.source === "jeo-code" ? "jeo-code" : "jeopi",
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const data: SharedCooldownFile = { version: 1, updatedAt: parsed.updatedAt ?? now, cooldowns: active };
|
|
123
|
+
cachedSharedFile = { filePath, mtimeNs: st.mtimeNs, size: st.size, ino: st.ino, data };
|
|
124
|
+
return data;
|
|
125
|
+
}
|
|
126
|
+
} catch {
|
|
127
|
+
cachedSharedFile = null;
|
|
128
|
+
}
|
|
129
|
+
return { version: 1, updatedAt: Date.now(), cooldowns: {} };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function writeSharedFile(data: SharedCooldownFile): void {
|
|
133
|
+
const filePath = resolveSharedCooldownPath();
|
|
134
|
+
const dir = path.dirname(filePath);
|
|
135
|
+
const tmpPath = `${filePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
136
|
+
cachedSharedFile = null;
|
|
137
|
+
try {
|
|
138
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
139
|
+
fs.writeFileSync(tmpPath, JSON.stringify(data, null, 2), { encoding: "utf8", mode: 0o600 });
|
|
140
|
+
try {
|
|
141
|
+
fs.chmodSync(tmpPath, 0o600);
|
|
142
|
+
} catch {}
|
|
143
|
+
fs.renameSync(tmpPath, filePath);
|
|
144
|
+
} catch {
|
|
145
|
+
try {
|
|
146
|
+
fs.unlinkSync(tmpPath);
|
|
147
|
+
} catch {}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function lookupSharedCredentialCooldown(
|
|
152
|
+
provider: string,
|
|
153
|
+
cred: { type?: string; email?: unknown; accountId?: unknown; refresh?: unknown; access?: unknown } | undefined,
|
|
154
|
+
): number | undefined {
|
|
155
|
+
if (!cred) return undefined;
|
|
156
|
+
const ident = sharedCredentialIdentityKey(cred);
|
|
157
|
+
if (!ident) return undefined;
|
|
158
|
+
const key = `${canonicalSharedProvider(provider)}:${ident}`;
|
|
159
|
+
const rec = readSharedFile().cooldowns[key];
|
|
160
|
+
if (!rec || rec.blockedUntil <= Date.now()) return undefined;
|
|
161
|
+
return rec.blockedUntil;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function recordSharedCredentialCooldown(
|
|
165
|
+
provider: string,
|
|
166
|
+
cred: { type?: string; email?: unknown; accountId?: unknown; refresh?: unknown; access?: unknown } | undefined,
|
|
167
|
+
blockedUntil: number,
|
|
168
|
+
reason?: string,
|
|
169
|
+
): void {
|
|
170
|
+
if (!cred || !Number.isFinite(blockedUntil) || blockedUntil <= Date.now()) return;
|
|
171
|
+
const ident = sharedCredentialIdentityKey(cred);
|
|
172
|
+
if (!ident) return;
|
|
173
|
+
const key = `${canonicalSharedProvider(provider)}:${ident}`;
|
|
174
|
+
const data = readSharedFile();
|
|
175
|
+
const existing = data.cooldowns[key];
|
|
176
|
+
const mergedUntil = existing ? Math.max(existing.blockedUntil, blockedUntil) : blockedUntil;
|
|
177
|
+
data.cooldowns[key] = {
|
|
178
|
+
blockedUntil: mergedUntil,
|
|
179
|
+
...(reason ? { reason } : existing?.reason ? { reason: existing.reason } : {}),
|
|
180
|
+
source: "jeopi",
|
|
181
|
+
};
|
|
182
|
+
data.updatedAt = Date.now();
|
|
183
|
+
writeSharedFile(data);
|
|
184
|
+
}
|