@threadbase-sh/streamer 1.24.1 → 1.24.2

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.cjs CHANGED
@@ -4827,6 +4827,11 @@ var StreamerServer = class {
4827
4827
  // /input { keys }. Cleared when the gate closes.
4828
4828
  pendingPermission = /* @__PURE__ */ new Map();
4829
4829
  scanner = null;
4830
+ // Set when better-sqlite3 is unusable (e.g. node ABI mismatch made
4831
+ // ConversationCache.open throw). All scanners are then built with
4832
+ // persistent: false so requests serve from disk instead of 500ing on
4833
+ // every touch of the scanner's own SQLite index.
4834
+ scannerPersistenceDisabled = false;
4830
4835
  // Tracks every ConversationScanner ever created so close() can shut them all
4831
4836
  // down and release SQLite handles (open handles block temp-dir deletion on Windows).
4832
4837
  allScanners = /* @__PURE__ */ new Set();
@@ -5326,11 +5331,12 @@ var StreamerServer = class {
5326
5331
  const message = err instanceof Error ? err.message : String(err);
5327
5332
  const abiMismatch = message.includes("NODE_MODULE_VERSION") || message.includes("was compiled against a different Node.js version");
5328
5333
  this.log.error(
5329
- `ConversationCache failed to open \u2014 running WITHOUT cache; /api/conversations, /api/conversations/count and /project-chats will 500.` + (abiMismatch ? ` Fix: npm rebuild better-sqlite3` : "") + ` (${message})`,
5334
+ `ConversationCache failed to open \u2014 running WITHOUT cache; /api/conversations, /api/conversations/count and /project-chats serve from disk (degraded).` + (abiMismatch ? ` Fix: npm rebuild better-sqlite3` : "") + ` (${message})`,
5330
5335
  { error: message, abiMismatch, event: "cache.open_failed" }
5331
5336
  );
5337
+ this.scannerPersistenceDisabled = true;
5332
5338
  }
5333
- const warmupScanner = new import_scanner2.ConversationScanner();
5339
+ const warmupScanner = this.newScanner();
5334
5340
  this.allScanners.add(warmupScanner);
5335
5341
  const warmupStatCache = this.buildStatCache(null);
5336
5342
  const shouldEmitProgress = createScanProgressThrottle();
@@ -5347,6 +5353,10 @@ var StreamerServer = class {
5347
5353
  }
5348
5354
  }
5349
5355
  }).then(async () => {
5356
+ if (!this.scannerReady && !this.scanner) {
5357
+ this.scanner = warmupScanner;
5358
+ this.scannerReady = Promise.resolve();
5359
+ }
5350
5360
  if (!this.cache) return;
5351
5361
  const metas = [...warmupScanner.getMetadataCache().values()];
5352
5362
  const upsertedIds = new Set(this.cache.upsertFromScannerMeta(metas));
@@ -5395,10 +5405,6 @@ var StreamerServer = class {
5395
5405
  event: "cache.warmup_failed"
5396
5406
  });
5397
5407
  }).finally(() => {
5398
- if (!this.scannerReady && !this.scanner) {
5399
- this.scanner = warmupScanner;
5400
- this.scannerReady = Promise.resolve();
5401
- }
5402
5408
  this.cacheReady = true;
5403
5409
  this.wsHub.broadcast({ type: "cache_ready" });
5404
5410
  resolveWarm();
@@ -5781,6 +5787,11 @@ var StreamerServer = class {
5781
5787
  // this — its per-file refreshFile (in findConversationByUuid) already
5782
5788
  // reconciles the one conversation being requested, so paying a full-tree
5783
5789
  // rescan just because some OTHER file changed is the stall this avoids.
5790
+ newScanner() {
5791
+ return new import_scanner2.ConversationScanner(
5792
+ this.scannerPersistenceDisabled ? { persistent: false } : void 0
5793
+ );
5794
+ }
5784
5795
  async getScanner(skipStaleRescan = false) {
5785
5796
  if (this.scannerReady) {
5786
5797
  await this.scannerReady;
@@ -5797,14 +5808,20 @@ var StreamerServer = class {
5797
5808
  }
5798
5809
  this.scannerStale = false;
5799
5810
  const statCache = this.buildStatCache(this.scanner);
5800
- this.scanner = new import_scanner2.ConversationScanner();
5811
+ this.scanner = this.newScanner();
5801
5812
  this.allScanners.add(this.scanner);
5802
5813
  this.scannerReady = this.scanner.scan({
5803
5814
  ...this.scanProfiles ? { profiles: this.scanProfiles } : {},
5804
5815
  ...this.codexScanOpts(),
5805
5816
  ...statCache ? { statCache } : {}
5806
5817
  });
5807
- await this.scannerReady;
5818
+ try {
5819
+ await this.scannerReady;
5820
+ } catch (err) {
5821
+ this.scanner = null;
5822
+ this.scannerReady = null;
5823
+ throw err;
5824
+ }
5808
5825
  const scanner = this.scanner;
5809
5826
  if (!scanner) return this.getScanner();
5810
5827
  return scanner;
@@ -5859,7 +5876,7 @@ var StreamerServer = class {
5859
5876
  const filePath2 = this.findJsonlPath(uuid);
5860
5877
  if (filePath2) {
5861
5878
  const account = this.cache?.getMetaById(uuid)?.account ?? void 0;
5862
- const coldScanner = this.scanner ?? new import_scanner2.ConversationScanner();
5879
+ const coldScanner = this.scanner ?? this.newScanner();
5863
5880
  const page = await coldScanner.parseSingleFilePage(filePath2, account, {
5864
5881
  limit: Number.MAX_SAFE_INTEGER
5865
5882
  });