@juspay/neurolink 12.9.4 → 12.9.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/CHANGELOG.md +2 -2
- package/dist/auth/codexOAuth.d.ts +1 -1
- package/dist/auth/codexOAuth.js +3 -1
- package/dist/browser/neurolink.min.js +335 -335
- package/dist/proxy/codexAccountUsage.js +22 -4
- package/dist/types/codex.d.ts +10 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { tokenStore } from "../auth/tokenStore.js";
|
|
10
10
|
import { normalizeAnthropicAccountKey } from "./accountSelection.js";
|
|
11
|
-
import {
|
|
11
|
+
import { CODEX_USAGE_URL, CODEX_USER_AGENT, decodeCodexAccessToken, resolveCodexAccountId, } from "../auth/codexOAuth.js";
|
|
12
12
|
import { logger } from "../utils/logger.js";
|
|
13
13
|
export const CODEX_ACCOUNT_PREFIX = "codex:";
|
|
14
14
|
/** Keep an account label in the Codex namespace used by its token store. */
|
|
@@ -71,6 +71,7 @@ function toFraction(percent) {
|
|
|
71
71
|
// Codex reports 0-100; clamp and normalise to 0-1.
|
|
72
72
|
return Math.min(1, Math.max(0, percent / 100));
|
|
73
73
|
}
|
|
74
|
+
/** Convert absolute or relative Codex window resets into epoch seconds. */
|
|
74
75
|
function windowResetEpochSeconds(window, nowSeconds) {
|
|
75
76
|
if (!window) {
|
|
76
77
|
return 0;
|
|
@@ -83,9 +84,18 @@ function windowResetEpochSeconds(window, nowSeconds) {
|
|
|
83
84
|
? Math.floor(window.resets_at / 1000)
|
|
84
85
|
: window.resets_at;
|
|
85
86
|
}
|
|
87
|
+
if (typeof window.reset_at === "number" &&
|
|
88
|
+
Number.isFinite(window.reset_at) &&
|
|
89
|
+
window.reset_at > 0) {
|
|
90
|
+
return window.reset_at > 4_102_444_800
|
|
91
|
+
? Math.floor(window.reset_at / 1000)
|
|
92
|
+
: window.reset_at;
|
|
93
|
+
}
|
|
86
94
|
const relative = typeof window.resets_in_seconds === "number"
|
|
87
95
|
? window.resets_in_seconds
|
|
88
|
-
: window.
|
|
96
|
+
: typeof window.reset_after_seconds === "number"
|
|
97
|
+
? window.reset_after_seconds
|
|
98
|
+
: window.reset_after;
|
|
89
99
|
if (typeof relative === "number" &&
|
|
90
100
|
Number.isFinite(relative) &&
|
|
91
101
|
relative > 0) {
|
|
@@ -177,7 +187,6 @@ export async function fetchCodexAccountUsage(account, options = {}) {
|
|
|
177
187
|
headers: {
|
|
178
188
|
Authorization: `Bearer ${account.token}`,
|
|
179
189
|
...(accountId ? { "chatgpt-account-id": accountId } : {}),
|
|
180
|
-
originator: CODEX_ORIGINATOR,
|
|
181
190
|
"User-Agent": CODEX_USER_AGENT,
|
|
182
191
|
Accept: "application/json",
|
|
183
192
|
},
|
|
@@ -186,11 +195,20 @@ export async function fetchCodexAccountUsage(account, options = {}) {
|
|
|
186
195
|
if (response.status === 401 || response.status === 403) {
|
|
187
196
|
return { ok: false, reason: "auth" };
|
|
188
197
|
}
|
|
198
|
+
if (response.status === 429) {
|
|
199
|
+
return { ok: false, reason: "rate_limited" };
|
|
200
|
+
}
|
|
189
201
|
if (!response.ok) {
|
|
190
202
|
return { ok: false, reason: "http" };
|
|
191
203
|
}
|
|
192
204
|
const usage = (await response.json());
|
|
193
|
-
|
|
205
|
+
const rateLimits = usage.rate_limit
|
|
206
|
+
? {
|
|
207
|
+
primary: usage.rate_limit.primary_window,
|
|
208
|
+
secondary: usage.rate_limit.secondary_window,
|
|
209
|
+
}
|
|
210
|
+
: usage.rate_limits;
|
|
211
|
+
return { ok: true, quota: codexRateLimitsToQuota(rateLimits) };
|
|
194
212
|
}
|
|
195
213
|
catch (error) {
|
|
196
214
|
logger.debug(`Codex usage fetch failed for ${account.label}: ${error instanceof Error ? error.message : String(error)}`);
|
package/dist/types/codex.d.ts
CHANGED
|
@@ -58,6 +58,9 @@ export type CodexRateLimitWindow = {
|
|
|
58
58
|
* instead of degrading to the transient ceiling. */
|
|
59
59
|
reset_after?: number | null;
|
|
60
60
|
resets_at?: number | null;
|
|
61
|
+
/** Current WHAM usage fields. */
|
|
62
|
+
reset_after_seconds?: number | null;
|
|
63
|
+
reset_at?: number | null;
|
|
61
64
|
};
|
|
62
65
|
/** Codex rate-limit block: a primary (short) and secondary (long) window. */
|
|
63
66
|
export type CodexRateLimits = {
|
|
@@ -66,7 +69,13 @@ export type CodexRateLimits = {
|
|
|
66
69
|
};
|
|
67
70
|
/** Loose shape of the Codex usage endpoint response. */
|
|
68
71
|
export type CodexUsageResponse = {
|
|
72
|
+
/** Legacy Codex usage payload. */
|
|
69
73
|
rate_limits?: CodexRateLimits | null;
|
|
74
|
+
/** Current ChatGPT WHAM account-usage payload. */
|
|
75
|
+
rate_limit?: {
|
|
76
|
+
primary_window?: CodexRateLimitWindow | null;
|
|
77
|
+
secondary_window?: CodexRateLimitWindow | null;
|
|
78
|
+
} | null;
|
|
70
79
|
plan_type?: string | null;
|
|
71
80
|
};
|
|
72
81
|
/** Result of a single Codex usage fetch. */
|
|
@@ -75,7 +84,7 @@ export type CodexUsageFetchResult = {
|
|
|
75
84
|
quota: AccountQuota;
|
|
76
85
|
} | {
|
|
77
86
|
ok: false;
|
|
78
|
-
reason: "not_oauth" | "auth" | "http" | "network" | "parse";
|
|
87
|
+
reason: "not_oauth" | "auth" | "rate_limited" | "http" | "network" | "parse";
|
|
79
88
|
};
|
|
80
89
|
/** A Codex account with its runtime cooldown/quota state hydrated from disk. */
|
|
81
90
|
export type CodexRuntimeAccount = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "12.9.
|
|
3
|
+
"version": "12.9.5",
|
|
4
4
|
"packageManager": "pnpm@10.15.1",
|
|
5
5
|
"description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
|
|
6
6
|
"author": {
|