@cortexkit/pi-anthropic-auth 2.4.5 → 2.4.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/stream.js +26 -16
- package/package.json +2 -2
package/dist/stream.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyClaudeCodeHeaders, applyCustomHeaders, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, CacheKeepSessionRegistry, createProviderErrorResponseScope, createSseFramer, createStickyNoRouteResponse, decideStickyQuotaFailure, decodeSseFrame, dumpDirectRequest, FAST_MODE_BETA, getCache1hPersistentMode, getClaudeCodeIdentityForVerifiedAccount, getDefaultCacheKeepRegistryDirectory, getFallbackReauthLabels, getQuotaCheckIntervalMs, getRequestGzipLatch, getRequestGzipLatchPath, getRoutingMode, getScopedQuotaWindowForModel, getThinkingPrefixMismatchBehavior, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isDumpPersistentlyEnabled, isFastModePersistentlyEnabled, isKillswitchEnabled, isNativeTransientAccountError, isOAuthAccount, isPermanentRefreshError, isValidApiBaseURL, killswitchPassesPolicy, logger, mergeAnthropicBetas, NativeAccountRefusal,
|
|
1
|
+
import { applyClaudeCodeHeaders, applyCustomHeaders, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, CacheKeepSessionRegistry, createNativeVaultNoRouteResponse, createProviderErrorResponseScope, createSseFramer, createStickyNoRouteResponse, decideStickyQuotaFailure, decodeSseFrame, dumpDirectRequest, FAST_MODE_BETA, getCache1hPersistentMode, getClaudeCodeIdentityForVerifiedAccount, getDefaultCacheKeepRegistryDirectory, getFallbackReauthLabels, getQuotaCheckIntervalMs, getRequestGzipLatch, getRequestGzipLatchPath, getRoutingMode, getScopedQuotaWindowForModel, getThinkingPrefixMismatchBehavior, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isDumpPersistentlyEnabled, isFastModePersistentlyEnabled, isKillswitchEnabled, isNativeTransientAccountError, isOAuthAccount, isPermanentRefreshError, isValidApiBaseURL, killswitchPassesPolicy, logger, mergeAnthropicBetas, NativeAccountRefusal, nativeAccountCanServe, parseSseFrame, QuotaManager, quotaBackoffActive, quotaExhaustionFromHeaders, quotaSnapshotHasStandardWindows, quotaSnapshotModelScopeIsExhausted, quotaSnapshotPassesModelScope, quotaSnapshotPassesPolicy, STICKY_ROUTING_MAIN_ACCOUNT_ID, StickySessionRouter, sendViaRelay, sendWithRequestGzip, setDumpEnabled, shouldFallbackStatus, stickyQuotaSnapshotIsFresh, stickyRetryAfterWithJitter, stickyRouteFamilyForModel, } from '@cortexkit/anthropic-auth-core';
|
|
2
2
|
import { calculateCost, createAssistantMessageEventStream, } from '@earendil-works/pi-ai';
|
|
3
3
|
import { buildAnthropicRequest, fromClaudeCodeToolName } from './convert.js';
|
|
4
4
|
import { getPiNativeRuntime, piAttemptAccessToken, } from './native.js';
|
|
@@ -1006,7 +1006,11 @@ async function executeWithFallback(options) {
|
|
|
1006
1006
|
}
|
|
1007
1007
|
if (!resolution) {
|
|
1008
1008
|
if (snapshot.mode === 'claustrum')
|
|
1009
|
-
|
|
1009
|
+
return createNativeVaultNoRouteResponse({
|
|
1010
|
+
snapshot: await native.view(),
|
|
1011
|
+
modelId: options.model.id,
|
|
1012
|
+
sticky: true,
|
|
1013
|
+
});
|
|
1010
1014
|
return createStickyNoRouteResponse({
|
|
1011
1015
|
mainRefreshError: storage?.refresh?.mainLastRefreshError,
|
|
1012
1016
|
fallbackReauthLabels: getFallbackReauthLabels(storage),
|
|
@@ -1051,23 +1055,26 @@ async function executeWithFallback(options) {
|
|
|
1051
1055
|
let migrate = (preflight instanceof Response && preflight.status === 403) ||
|
|
1052
1056
|
permanentAuthFailure;
|
|
1053
1057
|
if (primaryResponseAllowsApiFallback(preflight)) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1058
|
+
const responseHeaders = preflight instanceof Response ? preflight.headers : response.headers;
|
|
1059
|
+
let quota = quotaExhaustionFromHeaders(responseHeaders, options.model.id);
|
|
1060
|
+
// Do not extend the usage endpoint's own rate limit when the refusal
|
|
1061
|
+
// already confirms exhaustion.
|
|
1062
|
+
if (Object.keys(quota).length === 0) {
|
|
1063
|
+
try {
|
|
1064
|
+
quota =
|
|
1065
|
+
route.id === STICKY_ROUTING_MAIN_ACCOUNT_ID
|
|
1066
|
+
? await quotaManager.refreshMain(mainAccountId, '')
|
|
1067
|
+
: await quotaManager.refreshFallback(route.id, '', route.account);
|
|
1068
|
+
}
|
|
1069
|
+
catch {
|
|
1070
|
+
// Retain affinity when the quota probe itself is unavailable.
|
|
1071
|
+
quota = undefined;
|
|
1072
|
+
}
|
|
1064
1073
|
}
|
|
1065
1074
|
const decision = decideStickyQuotaFailure({
|
|
1066
1075
|
quota,
|
|
1067
1076
|
modelId: options.model.id,
|
|
1068
|
-
responseHeaders
|
|
1069
|
-
? preflight.headers
|
|
1070
|
-
: response.headers,
|
|
1077
|
+
responseHeaders,
|
|
1071
1078
|
});
|
|
1072
1079
|
if (decision.action === 'hold') {
|
|
1073
1080
|
const headers = new Headers(preflight instanceof Response
|
|
@@ -1161,7 +1168,10 @@ async function executeWithFallback(options) {
|
|
|
1161
1168
|
return fallback;
|
|
1162
1169
|
}
|
|
1163
1170
|
if (snapshot.mode === 'claustrum')
|
|
1164
|
-
|
|
1171
|
+
return createNativeVaultNoRouteResponse({
|
|
1172
|
+
snapshot: await native.view(),
|
|
1173
|
+
modelId: options.model.id,
|
|
1174
|
+
});
|
|
1165
1175
|
return createStickyNoRouteResponse({
|
|
1166
1176
|
routeQuotas: (storage?.accounts ?? [])
|
|
1167
1177
|
.filter(isOAuthAccount)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/pi-anthropic-auth",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prepublishOnly": "bun run build"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@cortexkit/anthropic-auth-core": "2.4.
|
|
39
|
+
"@cortexkit/anthropic-auth-core": "2.4.7"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@earendil-works/pi-ai": ">=0.86.1 <2",
|