@polka-codes/cli-shared 0.9.92 → 0.9.93
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 +60 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35106,7 +35106,7 @@ var require_mimeScore = __commonJS((exports, module) => {
|
|
|
35106
35106
|
|
|
35107
35107
|
// ../../node_modules/sql.js/dist/sql-wasm.js
|
|
35108
35108
|
var require_sql_wasm = __commonJS((exports, module) => {
|
|
35109
|
-
var __dirname = "/
|
|
35109
|
+
var __dirname = "/Users/xiliangchen/projects/polka-codes/node_modules/sql.js/dist";
|
|
35110
35110
|
var initSqlJsPromise = undefined;
|
|
35111
35111
|
var initSqlJs = function(moduleConfig) {
|
|
35112
35112
|
if (initSqlJsPromise) {
|
|
@@ -52477,6 +52477,9 @@ class UsageMeter {
|
|
|
52477
52477
|
let requestsWithCache = 0;
|
|
52478
52478
|
for (const entry of entries) {
|
|
52479
52479
|
const metadata = entry.metadata;
|
|
52480
|
+
if (typeof metadata !== "object" || metadata === null) {
|
|
52481
|
+
continue;
|
|
52482
|
+
}
|
|
52480
52483
|
const cachedTokens = metadata.cachedPromptTokens ?? metadata.cacheReadTokens ?? metadata.prompt_cache_hit_tokens ?? 0;
|
|
52481
52484
|
if (cachedTokens > 0) {
|
|
52482
52485
|
totalCachedTokens += cachedTokens;
|
|
@@ -67474,17 +67477,65 @@ ${content}`;
|
|
|
67474
67477
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
67475
67478
|
import { randomUUID } from "node:crypto";
|
|
67476
67479
|
import { existsSync as existsSync3 } from "node:fs";
|
|
67477
|
-
import { mkdir as mkdir2, readFile as readFile3, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
|
|
67478
|
-
import { dirname as dirname3, resolve as resolve5 } from "node:path";
|
|
67480
|
+
import { mkdir as mkdir2, readdir, readFile as readFile3, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
|
|
67481
|
+
import { basename as basename2, dirname as dirname3, resolve as resolve5 } from "node:path";
|
|
67479
67482
|
import { fileURLToPath } from "node:url";
|
|
67480
67483
|
var import_sql = __toESM(require_sql_wasm(), 1);
|
|
67481
67484
|
|
|
67482
67485
|
class FileLock {
|
|
67483
67486
|
lockfilePath;
|
|
67484
67487
|
static LOCK_TIMEOUT = 30000;
|
|
67488
|
+
static CLEANUP_AGE = 600000;
|
|
67489
|
+
static lastCleanupTime = 0;
|
|
67490
|
+
static CLEANUP_THROTTLE = 60000;
|
|
67485
67491
|
constructor(dbPath) {
|
|
67486
67492
|
this.lockfilePath = `${dbPath}.lock`;
|
|
67487
67493
|
}
|
|
67494
|
+
static resetCleanupThrottle() {
|
|
67495
|
+
FileLock.lastCleanupTime = 0;
|
|
67496
|
+
}
|
|
67497
|
+
static async cleanupOldLockFiles(dbPath, maxAge = FileLock.CLEANUP_AGE, force = false) {
|
|
67498
|
+
const now = Date.now();
|
|
67499
|
+
if (!force && now - FileLock.lastCleanupTime < FileLock.CLEANUP_THROTTLE) {
|
|
67500
|
+
return;
|
|
67501
|
+
}
|
|
67502
|
+
FileLock.lastCleanupTime = now;
|
|
67503
|
+
try {
|
|
67504
|
+
const lockDir = dirname3(dbPath);
|
|
67505
|
+
const dbBaseName = basename2(dbPath);
|
|
67506
|
+
const files = await readdir(lockDir);
|
|
67507
|
+
const now2 = Date.now();
|
|
67508
|
+
let cleanedCount = 0;
|
|
67509
|
+
for (const file2 of files) {
|
|
67510
|
+
if (!file2.startsWith(`${dbBaseName}.lock.`)) {
|
|
67511
|
+
continue;
|
|
67512
|
+
}
|
|
67513
|
+
const match = file2.match(/\.lock\.(released|stale|invalid|corrupt)\.(\d+)$/);
|
|
67514
|
+
if (!match) {
|
|
67515
|
+
continue;
|
|
67516
|
+
}
|
|
67517
|
+
const filePath = resolve5(lockDir, file2);
|
|
67518
|
+
const timestamp = Number.parseInt(match[2], 10);
|
|
67519
|
+
const age = now2 - timestamp;
|
|
67520
|
+
if (age > maxAge) {
|
|
67521
|
+
try {
|
|
67522
|
+
await unlink2(filePath);
|
|
67523
|
+
cleanedCount++;
|
|
67524
|
+
} catch (error48) {
|
|
67525
|
+
const errorCode = error48?.code;
|
|
67526
|
+
if (errorCode !== "ENOENT") {
|
|
67527
|
+
console.warn(`[FileLock] Failed to delete old lock file ${file2}: ${error48 instanceof Error ? error48.message : String(error48)}`);
|
|
67528
|
+
}
|
|
67529
|
+
}
|
|
67530
|
+
}
|
|
67531
|
+
}
|
|
67532
|
+
if (cleanedCount > 0) {
|
|
67533
|
+
console.log(`[FileLock] Cleaned up ${cleanedCount} old lock file(s) (older than ${maxAge}ms)`);
|
|
67534
|
+
}
|
|
67535
|
+
} catch (error48) {
|
|
67536
|
+
console.debug(`[FileLock] Cleanup encountered an error: ${error48 instanceof Error ? error48.message : String(error48)}`);
|
|
67537
|
+
}
|
|
67538
|
+
}
|
|
67488
67539
|
async acquire(retries = 10, delay2 = 100) {
|
|
67489
67540
|
for (let i2 = 0;i2 < retries; i2++) {
|
|
67490
67541
|
try {
|
|
@@ -67535,6 +67586,8 @@ class FileLock {
|
|
|
67535
67586
|
async release() {
|
|
67536
67587
|
try {
|
|
67537
67588
|
await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
|
|
67589
|
+
const dbPath = this.lockfilePath.slice(0, -5);
|
|
67590
|
+
FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
|
|
67538
67591
|
} catch (error48) {
|
|
67539
67592
|
const errorCode = error48.code;
|
|
67540
67593
|
if (errorCode !== "ENOENT") {
|
|
@@ -67617,6 +67670,9 @@ class SQLiteMemoryStore {
|
|
|
67617
67670
|
inTransaction = false;
|
|
67618
67671
|
transactionMutex = new ReentrantMutex;
|
|
67619
67672
|
fileLock;
|
|
67673
|
+
static resetCleanupThrottle() {
|
|
67674
|
+
FileLock.resetCleanupThrottle();
|
|
67675
|
+
}
|
|
67620
67676
|
getDbPath() {
|
|
67621
67677
|
return this.config.path || DEFAULT_MEMORY_CONFIG.path;
|
|
67622
67678
|
}
|
|
@@ -67653,6 +67709,7 @@ class SQLiteMemoryStore {
|
|
|
67653
67709
|
if (!existsSync3(dir)) {
|
|
67654
67710
|
await mkdir2(dir, { recursive: true, mode: 448 });
|
|
67655
67711
|
}
|
|
67712
|
+
FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
|
|
67656
67713
|
let dbData;
|
|
67657
67714
|
if (existsSync3(dbPath)) {
|
|
67658
67715
|
const lock = this.getFileLock();
|