@polka-codes/runner 0.9.92 → 0.9.94

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 +65 -6
  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.94";
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;
@@ -68903,9 +68906,11 @@ ${error48}`);
68903
68906
  const config3 = readConfig(path);
68904
68907
  configs.push(config3);
68905
68908
  } catch (error48) {
68906
- console.error(`Error loading config file: ${path}
68909
+ if (error48 instanceof ZodError) {
68910
+ console.error(`Error in config file: ${path}
68907
68911
  ${error48}`);
68908
- throw error48;
68912
+ throw error48;
68913
+ }
68909
68914
  }
68910
68915
  }
68911
68916
  } else {
@@ -72848,17 +72853,65 @@ ${content}`;
72848
72853
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
72849
72854
  import { randomUUID } from "node:crypto";
72850
72855
  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";
72856
+ import { mkdir as mkdir2, readdir, readFile as readFile3, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
72857
+ import { basename as basename2, dirname as dirname2, resolve as resolve4 } from "node:path";
72853
72858
  import { fileURLToPath } from "node:url";
72854
72859
  var import_sql = __toESM(require_sql_wasm(), 1);
72855
72860
 
72856
72861
  class FileLock {
72857
72862
  lockfilePath;
72858
72863
  static LOCK_TIMEOUT = 30000;
72864
+ static CLEANUP_AGE = 600000;
72865
+ static lastCleanupTime = 0;
72866
+ static CLEANUP_THROTTLE = 60000;
72859
72867
  constructor(dbPath) {
72860
72868
  this.lockfilePath = `${dbPath}.lock`;
72861
72869
  }
72870
+ static resetCleanupThrottle() {
72871
+ FileLock.lastCleanupTime = 0;
72872
+ }
72873
+ static async cleanupOldLockFiles(dbPath, maxAge = FileLock.CLEANUP_AGE, force = false) {
72874
+ const now = Date.now();
72875
+ if (!force && now - FileLock.lastCleanupTime < FileLock.CLEANUP_THROTTLE) {
72876
+ return;
72877
+ }
72878
+ FileLock.lastCleanupTime = now;
72879
+ try {
72880
+ const lockDir = dirname2(dbPath);
72881
+ const dbBaseName = basename2(dbPath);
72882
+ const files = await readdir(lockDir);
72883
+ const now2 = Date.now();
72884
+ let cleanedCount = 0;
72885
+ for (const file2 of files) {
72886
+ if (!file2.startsWith(`${dbBaseName}.lock.`)) {
72887
+ continue;
72888
+ }
72889
+ const match = file2.match(/\.lock\.(released|stale|invalid|corrupt)\.(\d+)$/);
72890
+ if (!match) {
72891
+ continue;
72892
+ }
72893
+ const filePath = resolve4(lockDir, file2);
72894
+ const timestamp = Number.parseInt(match[2], 10);
72895
+ const age = now2 - timestamp;
72896
+ if (age > maxAge) {
72897
+ try {
72898
+ await unlink2(filePath);
72899
+ cleanedCount++;
72900
+ } catch (error48) {
72901
+ const errorCode = error48?.code;
72902
+ if (errorCode !== "ENOENT") {
72903
+ console.warn(`[FileLock] Failed to delete old lock file ${file2}: ${error48 instanceof Error ? error48.message : String(error48)}`);
72904
+ }
72905
+ }
72906
+ }
72907
+ }
72908
+ if (cleanedCount > 0) {
72909
+ console.log(`[FileLock] Cleaned up ${cleanedCount} old lock file(s) (older than ${maxAge}ms)`);
72910
+ }
72911
+ } catch (error48) {
72912
+ console.debug(`[FileLock] Cleanup encountered an error: ${error48 instanceof Error ? error48.message : String(error48)}`);
72913
+ }
72914
+ }
72862
72915
  async acquire(retries = 10, delay2 = 100) {
72863
72916
  for (let i2 = 0;i2 < retries; i2++) {
72864
72917
  try {
@@ -72909,6 +72962,8 @@ class FileLock {
72909
72962
  async release() {
72910
72963
  try {
72911
72964
  await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
72965
+ const dbPath = this.lockfilePath.slice(0, -5);
72966
+ FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
72912
72967
  } catch (error48) {
72913
72968
  const errorCode = error48.code;
72914
72969
  if (errorCode !== "ENOENT") {
@@ -72991,6 +73046,9 @@ class SQLiteMemoryStore {
72991
73046
  inTransaction = false;
72992
73047
  transactionMutex = new ReentrantMutex;
72993
73048
  fileLock;
73049
+ static resetCleanupThrottle() {
73050
+ FileLock.resetCleanupThrottle();
73051
+ }
72994
73052
  getDbPath() {
72995
73053
  return this.config.path || DEFAULT_MEMORY_CONFIG.path;
72996
73054
  }
@@ -73027,6 +73085,7 @@ class SQLiteMemoryStore {
73027
73085
  if (!existsSync2(dir)) {
73028
73086
  await mkdir2(dir, { recursive: true, mode: 448 });
73029
73087
  }
73088
+ FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
73030
73089
  let dbData;
73031
73090
  if (existsSync2(dbPath)) {
73032
73091
  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.94",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",