@cortexkit/common-auth 0.45.0 → 0.46.0

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.
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { link, lstat, mkdir, open, readdir, readFile, rename, rm, stat, unlink, } from 'node:fs/promises';
3
3
  import { basename, dirname, join } from 'node:path';
4
+ import { createLogger } from '../logger/index.js';
4
5
  import { DisappearedLockRecordError, isWindowsAccessDeniedCreate, isWindowsAccessDeniedRead, readLockRecord, } from './lock-record.js';
5
6
  import { createPrivateBytes, createPrivateDirectoryExclusive, ensurePrivateDirectory, isWindowsSharingViolation, PrivateFileError, privateOperation, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from './private-files.js';
6
7
  import { LockOwnershipError, lockPathFor } from './with-lock.js';
@@ -1191,17 +1192,17 @@ export async function acquireRefreshFileLockWithClock(options) {
1191
1192
  removalConfirmed = true;
1192
1193
  }, deadline);
1193
1194
  changingRecordError = undefined;
1194
- if (markerAcquired) {
1195
- if (windowsPrivateFiles && !removalConfirmed)
1196
- throw new PrivateFileError(lockPath, 'release-not-confirmed', {
1197
- code: 'EIO',
1198
- });
1199
- releaseConfirmed = removalConfirmed;
1195
+ // Acquiring the marker does not confirm removal: stale-marker
1196
+ // recovery can take it away after the lease owner was checked.
1197
+ if (markerAcquired && removalConfirmed) {
1198
+ releaseConfirmed = true;
1200
1199
  return;
1201
1200
  }
1202
- if (signal?.aborted)
1203
- return;
1204
- await recoverStaleEvictionMarker(deadline);
1201
+ if (!markerAcquired) {
1202
+ if (signal?.aborted)
1203
+ return;
1204
+ await recoverStaleEvictionMarker(deadline);
1205
+ }
1205
1206
  }
1206
1207
  catch (error) {
1207
1208
  const changingRecord = windowsPrivateFiles &&
@@ -1242,6 +1243,9 @@ export async function acquireRefreshFileLockWithClock(options) {
1242
1243
  new PrivateFileError(lockPath, 'release-not-confirmed', {
1243
1244
  code: 'ETIMEDOUT',
1244
1245
  }));
1246
+ createLogger('fs').warn('File lock release deadline expired', {
1247
+ lockPath,
1248
+ });
1245
1249
  },
1246
1250
  };
1247
1251
  }
@@ -77,6 +77,23 @@ export type ReportRoutingInput = (RoutingReportIdentity & ({
77
77
  pool?: string;
78
78
  /** Optional reset time in epoch milliseconds. */
79
79
  resetsAt?: number;
80
+ } | {
81
+ /**
82
+ * A provider's typed refusal that condemns the API key until it is
83
+ * topped up, such as an exhausted prepaid balance. Never use for
84
+ * 401, 403 or short rate limits.
85
+ */
86
+ outcome: 'credential_refused';
87
+ credentialId: string;
88
+ /**
89
+ * What the provider actually sent: its own code from the structured
90
+ * error (OpenRouter's `openrouter_credits`). When the body carries
91
+ * no code, `http_<status>`, but only for a status the provider
92
+ * documents with a single balance meaning (DeepSeek's `http_402`).
93
+ * Never message text, and never a status with several meanings such
94
+ * as 403 or 429. Must match `^[a-z0-9._-]{1,64}$`.
95
+ */
96
+ providerCode: string;
80
97
  })) | {
81
98
  sessionId: string;
82
99
  kind: 'turn_notes_supported';
@@ -334,6 +334,19 @@ export function reportRouting(input) {
334
334
  };
335
335
  break;
336
336
  }
337
+ case 'credential_refused': {
338
+ const { credentialId, providerCode } = input;
339
+ if (!isNonEmptyString(credentialId) ||
340
+ typeof providerCode !== 'string' ||
341
+ !/^[a-z0-9._-]{1,64}$/.test(providerCode))
342
+ return;
343
+ payload = {
344
+ ...identity,
345
+ outcome: 'credential_refused',
346
+ provider_code: providerCode,
347
+ };
348
+ break;
349
+ }
337
350
  default:
338
351
  return;
339
352
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/common-auth",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
4
4
  "description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
5
5
  "license": "MIT",
6
6
  "repository": {