@cortexkit/pi-anthropic-auth 2.4.9 → 2.4.11
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/native.d.ts +3 -0
- package/dist/native.js +19 -2
- package/dist/stream.js +3 -3
- package/package.json +2 -2
package/dist/native.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export interface PiVaultPollOptions {
|
|
|
27
27
|
clearInterval?: typeof globalThis.clearInterval;
|
|
28
28
|
}
|
|
29
29
|
export declare class PiNativeRuntime {
|
|
30
|
+
private readonly pendingReports;
|
|
31
|
+
/** Join started failure reports, never model sends waiting for headers. */
|
|
32
|
+
drainReports(): Promise<void>;
|
|
30
33
|
private readonly paths;
|
|
31
34
|
private readonly holderRegistration;
|
|
32
35
|
private readonly initialization;
|
package/dist/native.js
CHANGED
|
@@ -71,6 +71,12 @@ export function isNativeMigrationRequired(error) {
|
|
|
71
71
|
/** How often Pi asks the vault for account changes, matching OpenCode's default. Model requests no longer rediscover a healthy roster, so this poll is how Pi notices a re-login or a newly added account. */
|
|
72
72
|
export const PI_VAULT_POLL_INTERVAL_MS = 2000;
|
|
73
73
|
export class PiNativeRuntime {
|
|
74
|
+
pendingReports = new Set();
|
|
75
|
+
/** Join started failure reports, never model sends waiting for headers. */
|
|
76
|
+
async drainReports() {
|
|
77
|
+
while (this.pendingReports.size)
|
|
78
|
+
await Promise.allSettled([...this.pendingReports]);
|
|
79
|
+
}
|
|
74
80
|
paths;
|
|
75
81
|
holderRegistration;
|
|
76
82
|
initialization;
|
|
@@ -328,8 +334,18 @@ export class PiNativeRuntime {
|
|
|
328
334
|
};
|
|
329
335
|
}
|
|
330
336
|
async report(served, status, source) {
|
|
331
|
-
if (served.source === 'vault' && status === 401)
|
|
332
|
-
|
|
337
|
+
if (served.source === 'vault' && status === 401) {
|
|
338
|
+
// An already-served receipt can be reported while shutdown drains it.
|
|
339
|
+
// Do not re-enter service admission after close has blocked new sends.
|
|
340
|
+
const pending = this.initialization.then((runtime) => runtime.vault.reportFailure(served.receipt, status, source));
|
|
341
|
+
this.pendingReports.add(pending);
|
|
342
|
+
try {
|
|
343
|
+
await pending;
|
|
344
|
+
}
|
|
345
|
+
finally {
|
|
346
|
+
this.pendingReports.delete(pending);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
333
349
|
}
|
|
334
350
|
async markUsed(served, servingRuntime) {
|
|
335
351
|
const runtime = servingRuntime ?? (await this.service());
|
|
@@ -350,6 +366,7 @@ export class PiNativeRuntime {
|
|
|
350
366
|
await this.initialization.then(async (runtime) => {
|
|
351
367
|
await runtime.drainQuotaPublications();
|
|
352
368
|
await runtime.drainRoutingPublications();
|
|
369
|
+
await this.drainReports();
|
|
353
370
|
await runtime.close();
|
|
354
371
|
}, () => { });
|
|
355
372
|
})();
|
package/dist/stream.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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, runWithRequestSignal, 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';
|
|
@@ -1242,7 +1242,7 @@ export function streamCortexKitAnthropic(model, context, options, effortTransiti
|
|
|
1242
1242
|
buildPiOAuthMessagesUrl(model.baseUrl);
|
|
1243
1243
|
const storagePath = getPiAccountStoragePath();
|
|
1244
1244
|
let hostTools = [];
|
|
1245
|
-
const response = await executeWithFallback({
|
|
1245
|
+
const response = await runWithRequestSignal(options?.signal, () => executeWithFallback({
|
|
1246
1246
|
model,
|
|
1247
1247
|
context,
|
|
1248
1248
|
streamOptions: options,
|
|
@@ -1251,7 +1251,7 @@ export function streamCortexKitAnthropic(model, context, options, effortTransiti
|
|
|
1251
1251
|
onResolvedTools: (tools) => {
|
|
1252
1252
|
hostTools = tools;
|
|
1253
1253
|
},
|
|
1254
|
-
});
|
|
1254
|
+
}));
|
|
1255
1255
|
if (!response.ok) {
|
|
1256
1256
|
throw new Error(`Anthropic request failed: HTTP ${response.status} ${await response.text()}`);
|
|
1257
1257
|
}
|
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.11",
|
|
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.11"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@earendil-works/pi-ai": ">=0.86.1 <2",
|