@threadbase-sh/streamer 1.15.1 → 1.15.3

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
@@ -5451,20 +5451,39 @@ var StreamerServer = class {
5451
5451
  cleanup();
5452
5452
  return;
5453
5453
  }
5454
- if (!(0, import_fs11.existsSync)(filePath)) return;
5454
+ let resolvedFilePath = (0, import_fs11.existsSync)(filePath) ? filePath : null;
5455
+ if (!resolvedFilePath && (0, import_fs11.existsSync)(projectsDir)) {
5456
+ try {
5457
+ const now = Date.now();
5458
+ const recent = (0, import_fs11.readdirSync)(projectsDir).filter((f) => f.endsWith(".jsonl")).map((f) => ({ f, mtime: (0, import_fs11.statSync)((0, import_path11.join)(projectsDir, f)).mtimeMs })).filter(({ mtime }) => now - mtime < 5e3).sort((a, b) => b.mtime - a.mtime)[0];
5459
+ if (recent) resolvedFilePath = (0, import_path11.join)(projectsDir, recent.f);
5460
+ } catch {
5461
+ }
5462
+ }
5463
+ if (!resolvedFilePath) return;
5455
5464
  cleanup();
5456
- this.sessionFileMap.set(sessionId, filePath);
5457
- this.fileWatcher.watch(filePath);
5465
+ this.sessionFileMap.set(sessionId, resolvedFilePath);
5466
+ this.fileWatcher.watch(resolvedFilePath);
5467
+ try {
5468
+ const existing = (0, import_fs11.readFileSync)(resolvedFilePath, "utf8").split("\n").filter(Boolean);
5469
+ if (existing.length > 0) {
5470
+ this.wsHub.broadcast({ type: "conversation_events", sessionId, lines: existing });
5471
+ for (const line of existing) {
5472
+ this.wsHub.broadcast({ type: "conversation_event", sessionId, line });
5473
+ }
5474
+ }
5475
+ } catch {
5476
+ }
5458
5477
  if (this.scannerReady) {
5459
5478
  this.scannerStale = true;
5460
5479
  } else {
5461
5480
  this.scanner = null;
5462
5481
  }
5463
- this.linkSessionToProject(sessionId, projectPath, filePath);
5482
+ this.linkSessionToProject(sessionId, projectPath, resolvedFilePath);
5464
5483
  this.cache?.markAsStreamer(sessionId);
5465
5484
  this.log.info(
5466
5485
  `[startFresh] wired JSONL for ${sessionId}`,
5467
- { event: "session.jsonl_wired", sessionId, filePath },
5486
+ { event: "session.jsonl_wired", sessionId, filePath: resolvedFilePath },
5468
5487
  "pino"
5469
5488
  );
5470
5489
  };