@cortexkit/anthropic-auth-core 2.2.6 → 2.2.7
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/dist/index.js +36 -23
- package/dist/sticky-routing.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24193,27 +24193,30 @@ function decideStickyQuotaFailure(input) {
|
|
|
24193
24193
|
const quota2 = knownQuota(input.quota);
|
|
24194
24194
|
if (!quota2)
|
|
24195
24195
|
return { action: "retain", reason: "unknown" };
|
|
24196
|
-
|
|
24197
|
-
|
|
24198
|
-
|
|
24199
|
-
|
|
24200
|
-
|
|
24201
|
-
|
|
24202
|
-
|
|
24203
|
-
|
|
24204
|
-
|
|
24205
|
-
|
|
24206
|
-
|
|
24207
|
-
if (
|
|
24208
|
-
|
|
24209
|
-
|
|
24210
|
-
|
|
24211
|
-
|
|
24212
|
-
|
|
24213
|
-
|
|
24214
|
-
|
|
24196
|
+
let blocking;
|
|
24197
|
+
for (const [reason, window2] of [
|
|
24198
|
+
["model-scoped", getScopedQuotaWindowForModel(quota2, input.modelId)],
|
|
24199
|
+
["seven-day", quota2.seven_day],
|
|
24200
|
+
["five-hour", quota2.five_hour]
|
|
24201
|
+
]) {
|
|
24202
|
+
if (!window2 || !Number.isFinite(window2.remainingPercent) || window2.remainingPercent > 0)
|
|
24203
|
+
continue;
|
|
24204
|
+
const resetAt = window2.resetsAt ? Date.parse(window2.resetsAt) : NaN;
|
|
24205
|
+
if (!Number.isFinite(resetAt) || resetAt <= now)
|
|
24206
|
+
return { action: "migrate", reason };
|
|
24207
|
+
if (!blocking || resetAt > blocking.resetAt)
|
|
24208
|
+
blocking = { resetAt, reason };
|
|
24209
|
+
}
|
|
24210
|
+
if (!blocking)
|
|
24211
|
+
return { action: "retain", reason: "not-exhausted" };
|
|
24212
|
+
if (blocking.resetAt - now <= STICKY_ROUTING_SHORT_RESET_GRACE_MS) {
|
|
24213
|
+
return {
|
|
24214
|
+
action: "hold",
|
|
24215
|
+
reason: `${blocking.reason}-short-reset`,
|
|
24216
|
+
retryAfterSeconds: Math.max(1, Math.ceil((blocking.resetAt - now) / 1000))
|
|
24217
|
+
};
|
|
24215
24218
|
}
|
|
24216
|
-
return { action: "
|
|
24219
|
+
return { action: "migrate", reason: blocking.reason };
|
|
24217
24220
|
}
|
|
24218
24221
|
function getStickyRoutingStatePath(accountStoragePath) {
|
|
24219
24222
|
const name = basename6(accountStoragePath);
|
|
@@ -25864,6 +25867,11 @@ async function sendViaRelay(options) {
|
|
|
25864
25867
|
responseMode ??= requestResponseMode(bodyText);
|
|
25865
25868
|
return responseMode;
|
|
25866
25869
|
};
|
|
25870
|
+
let directFallbackStarted = false;
|
|
25871
|
+
const directFallback = () => {
|
|
25872
|
+
directFallbackStarted = true;
|
|
25873
|
+
return fallback();
|
|
25874
|
+
};
|
|
25867
25875
|
try {
|
|
25868
25876
|
let result;
|
|
25869
25877
|
const sendStart = perfNowMs();
|
|
@@ -25884,7 +25892,7 @@ async function sendViaRelay(options) {
|
|
|
25884
25892
|
payload,
|
|
25885
25893
|
bodyText,
|
|
25886
25894
|
requestMode,
|
|
25887
|
-
fallback,
|
|
25895
|
+
fallback: directFallback,
|
|
25888
25896
|
signal: init?.signal,
|
|
25889
25897
|
authorizeAttempt
|
|
25890
25898
|
});
|
|
@@ -25895,7 +25903,7 @@ async function sendViaRelay(options) {
|
|
|
25895
25903
|
payload,
|
|
25896
25904
|
bodyText,
|
|
25897
25905
|
requestMode,
|
|
25898
|
-
fallback,
|
|
25906
|
+
fallback: directFallback,
|
|
25899
25907
|
signal: init?.signal,
|
|
25900
25908
|
authorizeAttempt
|
|
25901
25909
|
});
|
|
@@ -25955,6 +25963,10 @@ async function sendViaRelay(options) {
|
|
|
25955
25963
|
throw error.failure;
|
|
25956
25964
|
if (error instanceof RelayResponseMetadataError)
|
|
25957
25965
|
throw error;
|
|
25966
|
+
if (directFallbackStarted) {
|
|
25967
|
+
relayLog(`direct fallback failed session=${shortAffinity2(affinity)}; not sending it again code=relay_transport_error`);
|
|
25968
|
+
throw error;
|
|
25969
|
+
}
|
|
25958
25970
|
if (!config.fallbackToDirect) {
|
|
25959
25971
|
relayLog(`relay failed session=${shortAffinity2(affinity)} and fallbackToDirect=false code=relay_transport_error`);
|
|
25960
25972
|
throw error;
|
|
@@ -26997,11 +27009,12 @@ function createNativeAccountRuntime(options) {
|
|
|
26997
27009
|
} catch {
|
|
26998
27010
|
throw new Error("Claude account identity could not be verified; retry sign-in. No account changes were saved.");
|
|
26999
27011
|
}
|
|
27012
|
+
const { access, refresh, expires } = input.credential;
|
|
27000
27013
|
return runtime2.putAccount({
|
|
27001
27014
|
...input,
|
|
27002
27015
|
accountIdentity,
|
|
27003
27016
|
replace: input.replace ?? true,
|
|
27004
|
-
credential: { type: "oauth",
|
|
27017
|
+
credential: { type: "oauth", access, refresh, expires }
|
|
27005
27018
|
});
|
|
27006
27019
|
},
|
|
27007
27020
|
async putAccount(input) {
|
package/dist/sticky-routing.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export type StickyQuotaFailureDecision = {
|
|
|
45
45
|
reason: 'not-exhausted' | 'unknown';
|
|
46
46
|
} | {
|
|
47
47
|
action: 'hold';
|
|
48
|
-
reason: 'five-hour-short-reset';
|
|
48
|
+
reason: 'five-hour-short-reset' | 'seven-day-short-reset' | 'model-scoped-short-reset';
|
|
49
49
|
retryAfterSeconds: number;
|
|
50
50
|
} | {
|
|
51
51
|
action: 'migrate';
|