@cortexkit/opencode-anthropic-auth 1.1.2 → 1.1.3
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/README.md +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.js +15 -3
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { authorize, buildClaudeQuotaSummary, buildFallbackQuotaSummaries, buildRefreshOperationError, CACHE_1H_COMMAND_NAME, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, CLAUDE_CACHE_KEEP_COMMAND_NAME, CLAUDE_DUMP_COMMAND_NAME, CLAUDE_FAST_COMMAND_NAME, CLAUDE_QUOTAS_COMMAND_NAME, ClaudeOAuthRefreshError, exchange, executeCache1hCommand, executeCacheKeepCommand, executeDumpCommand, executeFastModeCommand, FallbackAccountManager, fetchOAuthQuotaSnapshot, formatRefreshBackoffMessage, getCache1hMode, getCache1hPersistentMode, getCacheKeepWindow, getQuotaCheckIntervalMs, getQuotaNextRefreshAt, getRelayConfig, hashRefreshToken, isCache1hEnabled, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isCacheKeepPersistentlyEnabled, isDumpPersistentlyEnabled, isFastModeEnabled, isFastModePersistentlyEnabled, isFastModeSupportedModel, loadAccounts, log, mergeAnthropicBetas, parseCache1hCommandAction, parseCacheKeepCommandAction, parseDumpCommandAction, parseFastModeCommandAction, quotaSnapshotPassesPolicy, refreshBackoffActive, refreshClaudeOAuthToken, resolveClaudeCodeIdentity, saveAccounts, sendViaRelay, setCache1hPersistentEnabled, setCache1hPersistentMode, setCache1hState, setCacheKeepPersistentEnabled, setCacheKeepPersistentWindow, setDumpEnabled, setDumpPersistentEnabled, setFastModeEnabled, setFastModePersistentEnabled, shouldFallbackStatus, } from '@cortexkit/anthropic-auth-core';
|
|
2
|
+
import { acquireRefreshFileLock, authorize, buildClaudeQuotaSummary, buildFallbackQuotaSummaries, buildRefreshOperationError, CACHE_1H_COMMAND_NAME, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, CLAUDE_CACHE_KEEP_COMMAND_NAME, CLAUDE_DUMP_COMMAND_NAME, CLAUDE_FAST_COMMAND_NAME, CLAUDE_QUOTAS_COMMAND_NAME, ClaudeOAuthRefreshError, exchange, executeCache1hCommand, executeCacheKeepCommand, executeDumpCommand, executeFastModeCommand, FallbackAccountManager, fetchOAuthQuotaSnapshot, formatRefreshBackoffMessage, getCache1hMode, getCache1hPersistentMode, getCacheKeepWindow, getQuotaCheckIntervalMs, getQuotaNextRefreshAt, getRelayConfig, hashRefreshToken, isCache1hEnabled, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isCacheKeepPersistentlyEnabled, isDumpPersistentlyEnabled, isFastModeEnabled, isFastModePersistentlyEnabled, isFastModeSupportedModel, loadAccounts, log, mergeAnthropicBetas, parseCache1hCommandAction, parseCacheKeepCommandAction, parseDumpCommandAction, parseFastModeCommandAction, quotaSnapshotPassesPolicy, refreshBackoffActive, refreshClaudeOAuthToken, resolveClaudeCodeIdentity, saveAccounts, sendViaRelay, setCache1hPersistentEnabled, setCache1hPersistentMode, setCache1hState, setCacheKeepPersistentEnabled, setCacheKeepPersistentWindow, setDumpEnabled, setDumpPersistentEnabled, setFastModeEnabled, setFastModePersistentEnabled, shouldFallbackStatus, } from '@cortexkit/anthropic-auth-core';
|
|
3
3
|
import { resolvePromptContext } from "./prompt-context.js";
|
|
4
4
|
import { addFastModeBetaHeader, createStrippedStream, isInsecure, mergeHeaders, rewriteRequestBody, rewriteUrl, setOAuthHeaders, } from "./transform.js";
|
|
5
5
|
const HANDLED_SENTINEL = '__OPENCODE_ANTHROPIC_AUTH_COMMAND_HANDLED__';
|
|
6
6
|
const MAIN_AUTH_REFRESH_TICK_MS = 60_000;
|
|
7
|
-
const
|
|
7
|
+
const MIN_MAIN_REFRESH_BEFORE_EXPIRY_MINUTES = 240;
|
|
8
|
+
const DEFAULT_MAIN_REFRESH_BEFORE_EXPIRY_MINUTES = MIN_MAIN_REFRESH_BEFORE_EXPIRY_MINUTES;
|
|
8
9
|
let nextPerfRequestId = 1;
|
|
9
10
|
let eventLoopLagMonitorStarted = false;
|
|
10
11
|
function perfLoggingEnabled() {
|
|
@@ -163,7 +164,7 @@ export const AnthropicAuthPlugin = async (ctx) => {
|
|
|
163
164
|
function mainRefreshBeforeExpiryMs(storage) {
|
|
164
165
|
const minutes = storage?.refresh?.refreshBeforeExpiryMinutes ??
|
|
165
166
|
DEFAULT_MAIN_REFRESH_BEFORE_EXPIRY_MINUTES;
|
|
166
|
-
return Math.max(
|
|
167
|
+
return Math.max(MIN_MAIN_REFRESH_BEFORE_EXPIRY_MINUTES, minutes) * 60_000;
|
|
167
168
|
}
|
|
168
169
|
function mainRefreshEnabled(storage) {
|
|
169
170
|
return storage?.refresh?.enabled !== false;
|
|
@@ -374,6 +375,7 @@ export const AnthropicAuthPlugin = async (ctx) => {
|
|
|
374
375
|
const baseDelayMs = 500;
|
|
375
376
|
let leaseId = null;
|
|
376
377
|
let leaseTokenHash = null;
|
|
378
|
+
let releaseFileLock = null;
|
|
377
379
|
async function updateMainRefreshState(update) {
|
|
378
380
|
const storage = (await loadAccounts()) ?? {
|
|
379
381
|
version: 1,
|
|
@@ -430,6 +432,15 @@ export const AnthropicAuthPlugin = async (ctx) => {
|
|
|
430
432
|
});
|
|
431
433
|
throw new Error('Claude OAuth refresh is already in progress');
|
|
432
434
|
}
|
|
435
|
+
const fileLock = await acquireRefreshFileLock({
|
|
436
|
+
name: 'opencode-main-oauth-refresh',
|
|
437
|
+
ttlMs: 2 * 60_000,
|
|
438
|
+
});
|
|
439
|
+
if (!fileLock) {
|
|
440
|
+
log('[refresh] opencode main oauth refresh skipped file lock');
|
|
441
|
+
throw new Error('Claude OAuth refresh is already in progress');
|
|
442
|
+
}
|
|
443
|
+
releaseFileLock = fileLock.release;
|
|
433
444
|
leaseId = randomUUID();
|
|
434
445
|
leaseTokenHash = refreshTokenHash;
|
|
435
446
|
await updateMainRefreshState((nextStorage) => {
|
|
@@ -536,6 +547,7 @@ export const AnthropicAuthPlugin = async (ctx) => {
|
|
|
536
547
|
}
|
|
537
548
|
}).catch(() => { });
|
|
538
549
|
}
|
|
550
|
+
await releaseFileLock?.().catch(() => { });
|
|
539
551
|
}
|
|
540
552
|
}
|
|
541
553
|
// Unreachable — each iteration either returns or throws.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/opencode-anthropic-auth",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"@opencode-ai/plugin": "*"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@cortexkit/anthropic-auth-core": "1.1.
|
|
43
|
+
"@cortexkit/anthropic-auth-core": "1.1.3"
|
|
44
44
|
}
|
|
45
45
|
}
|