@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.d.cts CHANGED
@@ -832,6 +832,7 @@ declare class StreamerServer {
832
832
  private pendingQuestionKey;
833
833
  private pendingPermission;
834
834
  private scanner;
835
+ private scannerPersistenceDisabled;
835
836
  private allScanners;
836
837
  private scannerReady;
837
838
  private scannerStale;
@@ -911,6 +912,7 @@ declare class StreamerServer {
911
912
  private handleGetPopularProjects;
912
913
  private buildStatCache;
913
914
  private codexScanOpts;
915
+ private newScanner;
914
916
  private getScanner;
915
917
  private getFreshScanner;
916
918
  private findJsonlPath;
package/dist/index.d.ts CHANGED
@@ -832,6 +832,7 @@ declare class StreamerServer {
832
832
  private pendingQuestionKey;
833
833
  private pendingPermission;
834
834
  private scanner;
835
+ private scannerPersistenceDisabled;
835
836
  private allScanners;
836
837
  private scannerReady;
837
838
  private scannerStale;
@@ -911,6 +912,7 @@ declare class StreamerServer {
911
912
  private handleGetPopularProjects;
912
913
  private buildStatCache;
913
914
  private codexScanOpts;
915
+ private newScanner;
914
916
  private getScanner;
915
917
  private getFreshScanner;
916
918
  private findJsonlPath;
package/dist/index.js CHANGED
@@ -4788,6 +4788,11 @@ var StreamerServer = class {
4788
4788
  // /input { keys }. Cleared when the gate closes.
4789
4789
  pendingPermission = /* @__PURE__ */ new Map();
4790
4790
  scanner = null;
4791
+ // Set when better-sqlite3 is unusable (e.g. node ABI mismatch made
4792
+ // ConversationCache.open throw). All scanners are then built with
4793
+ // persistent: false so requests serve from disk instead of 500ing on
4794
+ // every touch of the scanner's own SQLite index.
4795
+ scannerPersistenceDisabled = false;
4791
4796
  // Tracks every ConversationScanner ever created so close() can shut them all
4792
4797
  // down and release SQLite handles (open handles block temp-dir deletion on Windows).
4793
4798
  allScanners = /* @__PURE__ */ new Set();
@@ -5287,11 +5292,12 @@ var StreamerServer = class {
5287
5292
  const message = err instanceof Error ? err.message : String(err);
5288
5293
  const abiMismatch = message.includes("NODE_MODULE_VERSION") || message.includes("was compiled against a different Node.js version");
5289
5294
  this.log.error(
5290
- `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})`,
5295
+ `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})`,
5291
5296
  { error: message, abiMismatch, event: "cache.open_failed" }
5292
5297
  );
5298
+ this.scannerPersistenceDisabled = true;
5293
5299
  }
5294
- const warmupScanner = new ConversationScanner();
5300
+ const warmupScanner = this.newScanner();
5295
5301
  this.allScanners.add(warmupScanner);
5296
5302
  const warmupStatCache = this.buildStatCache(null);
5297
5303
  const shouldEmitProgress = createScanProgressThrottle();
@@ -5308,6 +5314,10 @@ var StreamerServer = class {
5308
5314
  }
5309
5315
  }
5310
5316
  }).then(async () => {
5317
+ if (!this.scannerReady && !this.scanner) {
5318
+ this.scanner = warmupScanner;
5319
+ this.scannerReady = Promise.resolve();
5320
+ }
5311
5321
  if (!this.cache) return;
5312
5322
  const metas = [...warmupScanner.getMetadataCache().values()];
5313
5323
  const upsertedIds = new Set(this.cache.upsertFromScannerMeta(metas));
@@ -5356,10 +5366,6 @@ var StreamerServer = class {
5356
5366
  event: "cache.warmup_failed"
5357
5367
  });
5358
5368
  }).finally(() => {
5359
- if (!this.scannerReady && !this.scanner) {
5360
- this.scanner = warmupScanner;
5361
- this.scannerReady = Promise.resolve();
5362
- }
5363
5369
  this.cacheReady = true;
5364
5370
  this.wsHub.broadcast({ type: "cache_ready" });
5365
5371
  resolveWarm();
@@ -5742,6 +5748,11 @@ var StreamerServer = class {
5742
5748
  // this — its per-file refreshFile (in findConversationByUuid) already
5743
5749
  // reconciles the one conversation being requested, so paying a full-tree
5744
5750
  // rescan just because some OTHER file changed is the stall this avoids.
5751
+ newScanner() {
5752
+ return new ConversationScanner(
5753
+ this.scannerPersistenceDisabled ? { persistent: false } : void 0
5754
+ );
5755
+ }
5745
5756
  async getScanner(skipStaleRescan = false) {
5746
5757
  if (this.scannerReady) {
5747
5758
  await this.scannerReady;
@@ -5758,14 +5769,20 @@ var StreamerServer = class {
5758
5769
  }
5759
5770
  this.scannerStale = false;
5760
5771
  const statCache = this.buildStatCache(this.scanner);
5761
- this.scanner = new ConversationScanner();
5772
+ this.scanner = this.newScanner();
5762
5773
  this.allScanners.add(this.scanner);
5763
5774
  this.scannerReady = this.scanner.scan({
5764
5775
  ...this.scanProfiles ? { profiles: this.scanProfiles } : {},
5765
5776
  ...this.codexScanOpts(),
5766
5777
  ...statCache ? { statCache } : {}
5767
5778
  });
5768
- await this.scannerReady;
5779
+ try {
5780
+ await this.scannerReady;
5781
+ } catch (err) {
5782
+ this.scanner = null;
5783
+ this.scannerReady = null;
5784
+ throw err;
5785
+ }
5769
5786
  const scanner = this.scanner;
5770
5787
  if (!scanner) return this.getScanner();
5771
5788
  return scanner;
@@ -5820,7 +5837,7 @@ var StreamerServer = class {
5820
5837
  const filePath2 = this.findJsonlPath(uuid);
5821
5838
  if (filePath2) {
5822
5839
  const account = this.cache?.getMetaById(uuid)?.account ?? void 0;
5823
- const coldScanner = this.scanner ?? new ConversationScanner();
5840
+ const coldScanner = this.scanner ?? this.newScanner();
5824
5841
  const page = await coldScanner.parseSingleFilePage(filePath2, account, {
5825
5842
  limit: Number.MAX_SAFE_INTEGER
5826
5843
  });