@polka-codes/runner 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.
Files changed (2) hide show
  1. package/dist/index.js +61 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -37643,7 +37643,7 @@ var require_mimeScore = __commonJS((exports, module) => {
37643
37643
 
37644
37644
  // ../../node_modules/sql.js/dist/sql-wasm.js
37645
37645
  var require_sql_wasm = __commonJS((exports, module) => {
37646
- var __dirname = "/home/ubuntu/polka-codes/node_modules/sql.js/dist";
37646
+ var __dirname = "/Users/xiliangchen/projects/polka-codes/node_modules/sql.js/dist";
37647
37647
  var initSqlJsPromise = undefined;
37648
37648
  var initSqlJs = function(moduleConfig) {
37649
37649
  if (initSqlJsPromise) {
@@ -42783,7 +42783,7 @@ var {
42783
42783
  Help
42784
42784
  } = import__.default;
42785
42785
  // package.json
42786
- var version = "0.9.92";
42786
+ var version = "0.9.93";
42787
42787
 
42788
42788
  // src/runner.ts
42789
42789
  import { execSync } from "node:child_process";
@@ -57959,6 +57959,9 @@ class UsageMeter {
57959
57959
  let requestsWithCache = 0;
57960
57960
  for (const entry of entries) {
57961
57961
  const metadata = entry.metadata;
57962
+ if (typeof metadata !== "object" || metadata === null) {
57963
+ continue;
57964
+ }
57962
57965
  const cachedTokens = metadata.cachedPromptTokens ?? metadata.cacheReadTokens ?? metadata.prompt_cache_hit_tokens ?? 0;
57963
57966
  if (cachedTokens > 0) {
57964
57967
  totalCachedTokens += cachedTokens;
@@ -72848,17 +72851,65 @@ ${content}`;
72848
72851
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
72849
72852
  import { randomUUID } from "node:crypto";
72850
72853
  import { existsSync as existsSync2 } from "node:fs";
72851
- import { mkdir as mkdir2, readFile as readFile3, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
72852
- import { dirname as dirname2, resolve as resolve4 } from "node:path";
72854
+ import { mkdir as mkdir2, readdir, readFile as readFile3, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
72855
+ import { basename as basename2, dirname as dirname2, resolve as resolve4 } from "node:path";
72853
72856
  import { fileURLToPath } from "node:url";
72854
72857
  var import_sql = __toESM(require_sql_wasm(), 1);
72855
72858
 
72856
72859
  class FileLock {
72857
72860
  lockfilePath;
72858
72861
  static LOCK_TIMEOUT = 30000;
72862
+ static CLEANUP_AGE = 600000;
72863
+ static lastCleanupTime = 0;
72864
+ static CLEANUP_THROTTLE = 60000;
72859
72865
  constructor(dbPath) {
72860
72866
  this.lockfilePath = `${dbPath}.lock`;
72861
72867
  }
72868
+ static resetCleanupThrottle() {
72869
+ FileLock.lastCleanupTime = 0;
72870
+ }
72871
+ static async cleanupOldLockFiles(dbPath, maxAge = FileLock.CLEANUP_AGE, force = false) {
72872
+ const now = Date.now();
72873
+ if (!force && now - FileLock.lastCleanupTime < FileLock.CLEANUP_THROTTLE) {
72874
+ return;
72875
+ }
72876
+ FileLock.lastCleanupTime = now;
72877
+ try {
72878
+ const lockDir = dirname2(dbPath);
72879
+ const dbBaseName = basename2(dbPath);
72880
+ const files = await readdir(lockDir);
72881
+ const now2 = Date.now();
72882
+ let cleanedCount = 0;
72883
+ for (const file2 of files) {
72884
+ if (!file2.startsWith(`${dbBaseName}.lock.`)) {
72885
+ continue;
72886
+ }
72887
+ const match = file2.match(/\.lock\.(released|stale|invalid|corrupt)\.(\d+)$/);
72888
+ if (!match) {
72889
+ continue;
72890
+ }
72891
+ const filePath = resolve4(lockDir, file2);
72892
+ const timestamp = Number.parseInt(match[2], 10);
72893
+ const age = now2 - timestamp;
72894
+ if (age > maxAge) {
72895
+ try {
72896
+ await unlink2(filePath);
72897
+ cleanedCount++;
72898
+ } catch (error48) {
72899
+ const errorCode = error48?.code;
72900
+ if (errorCode !== "ENOENT") {
72901
+ console.warn(`[FileLock] Failed to delete old lock file ${file2}: ${error48 instanceof Error ? error48.message : String(error48)}`);
72902
+ }
72903
+ }
72904
+ }
72905
+ }
72906
+ if (cleanedCount > 0) {
72907
+ console.log(`[FileLock] Cleaned up ${cleanedCount} old lock file(s) (older than ${maxAge}ms)`);
72908
+ }
72909
+ } catch (error48) {
72910
+ console.debug(`[FileLock] Cleanup encountered an error: ${error48 instanceof Error ? error48.message : String(error48)}`);
72911
+ }
72912
+ }
72862
72913
  async acquire(retries = 10, delay2 = 100) {
72863
72914
  for (let i2 = 0;i2 < retries; i2++) {
72864
72915
  try {
@@ -72909,6 +72960,8 @@ class FileLock {
72909
72960
  async release() {
72910
72961
  try {
72911
72962
  await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
72963
+ const dbPath = this.lockfilePath.slice(0, -5);
72964
+ FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
72912
72965
  } catch (error48) {
72913
72966
  const errorCode = error48.code;
72914
72967
  if (errorCode !== "ENOENT") {
@@ -72991,6 +73044,9 @@ class SQLiteMemoryStore {
72991
73044
  inTransaction = false;
72992
73045
  transactionMutex = new ReentrantMutex;
72993
73046
  fileLock;
73047
+ static resetCleanupThrottle() {
73048
+ FileLock.resetCleanupThrottle();
73049
+ }
72994
73050
  getDbPath() {
72995
73051
  return this.config.path || DEFAULT_MEMORY_CONFIG.path;
72996
73052
  }
@@ -73027,6 +73083,7 @@ class SQLiteMemoryStore {
73027
73083
  if (!existsSync2(dir)) {
73028
73084
  await mkdir2(dir, { recursive: true, mode: 448 });
73029
73085
  }
73086
+ FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
73030
73087
  let dbData;
73031
73088
  if (existsSync2(dbPath)) {
73032
73089
  const lock = this.getFileLock();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
3
- "version": "0.9.92",
3
+ "version": "0.9.93",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",