@threadbase-sh/streamer 1.15.0 → 1.15.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
@@ -766,6 +766,7 @@ declare class StreamerServer {
766
766
  private handleListSessions;
767
767
  private handleGetSession;
768
768
  private handleResume;
769
+ private enrichResumedSessionAsync;
769
770
  private handleSendInput;
770
771
  private handleUploadFile;
771
772
  private handleGetOutput;
package/dist/index.d.ts CHANGED
@@ -766,6 +766,7 @@ declare class StreamerServer {
766
766
  private handleListSessions;
767
767
  private handleGetSession;
768
768
  private handleResume;
769
+ private enrichResumedSessionAsync;
769
770
  private handleSendInput;
770
771
  private handleUploadFile;
771
772
  private handleGetOutput;
package/dist/index.js CHANGED
@@ -5063,28 +5063,37 @@ var StreamerServer = class {
5063
5063
  projectName: body.projectName,
5064
5064
  branch: body.branch
5065
5065
  });
5066
- if (conv) {
5067
- session.sessionName = conv.sessionName ?? void 0;
5068
- session.messageCount = conv.messageCount ?? 0;
5069
- session.account = conv.account ?? void 0;
5070
- session.filePath = conv.filePath ?? void 0;
5071
- const scanner = await this.getScanner();
5072
- const meta = conv.filePath ? scanner.getMetadataCache().get(conv.filePath) : void 0;
5073
- if (meta) {
5074
- session.model = meta.model ?? void 0;
5075
- session.preview = meta.preview ?? void 0;
5076
- session.firstMessageText = meta.firstMessage?.text ?? void 0;
5077
- session.firstMessageAt = meta.firstMessage?.timestamp ? new Date(meta.firstMessage.timestamp) : void 0;
5078
- session.lastMessageText = meta.lastMessage?.text ?? void 0;
5079
- session.lastMessageAt = meta.lastMessage?.timestamp ? new Date(meta.lastMessage.timestamp) : void 0;
5066
+ this.sessionStore.addManaged(session);
5067
+ void this.watchConversationFile(sessionId);
5068
+ const resp = this.sessionStore.get(session.id, this.ptyAttachedIds());
5069
+ this.broadcastOrUnicastSessionList(req);
5070
+ json(res, 201, resp ?? session);
5071
+ this.enrichResumedSessionAsync(sessionId, projectPath, conv);
5072
+ }
5073
+ enrichResumedSessionAsync(sessionId, projectPath, conv) {
5074
+ try {
5075
+ const session = this.sessionStore.get(sessionId, this.ptyAttachedIds());
5076
+ if (!session) return;
5077
+ if (conv) {
5078
+ session.sessionName = conv.sessionName ?? void 0;
5079
+ session.messageCount = conv.messageCount ?? 0;
5080
+ session.account = conv.account ?? void 0;
5081
+ session.filePath = conv.filePath ?? void 0;
5080
5082
  }
5081
- }
5082
- if (this.cache && this.projectsRepo && this.conversationsRepo) {
5083
- let resolvedProjectId = null;
5084
- const cachedConv = this.cache.getMetaById(sessionId);
5085
- if (cachedConv?.projectId) {
5086
- resolvedProjectId = cachedConv.projectId;
5087
- } else {
5083
+ if (!this.cache || !this.projectsRepo || !this.conversationsRepo) return;
5084
+ const cached2 = this.cache.getMetaById(sessionId);
5085
+ if (cached2) {
5086
+ session.model = cached2.model ?? void 0;
5087
+ session.preview = cached2.preview ?? void 0;
5088
+ const first = cached2.firstMessage ? JSON.parse(cached2.firstMessage) : null;
5089
+ const last = cached2.lastMessage ? JSON.parse(cached2.lastMessage) : null;
5090
+ session.firstMessageText = first?.text ?? void 0;
5091
+ session.firstMessageAt = first?.timestamp ? new Date(first.timestamp).toISOString() : void 0;
5092
+ session.lastMessageText = last?.text ?? void 0;
5093
+ session.lastMessageAt = last?.timestamp ? new Date(last.timestamp).toISOString() : void 0;
5094
+ }
5095
+ let resolvedProjectId = cached2?.projectId ?? null;
5096
+ if (!resolvedProjectId) {
5088
5097
  const project = this.projectsRepo.upsertProjectByPath(projectPath);
5089
5098
  resolvedProjectId = project.id;
5090
5099
  this.conversationsRepo.updateConversationProjectId({
@@ -5096,12 +5105,9 @@ var StreamerServer = class {
5096
5105
  session.projectId = resolvedProjectId;
5097
5106
  session.resumedFromConversationId = sessionId;
5098
5107
  }
5108
+ } catch (err) {
5109
+ console.error(`[enrichResumedSessionAsync] ${sessionId}:`, err);
5099
5110
  }
5100
- this.sessionStore.addManaged(session);
5101
- void this.watchConversationFile(sessionId);
5102
- const resp = this.sessionStore.get(session.id, this.ptyAttachedIds());
5103
- this.broadcastOrUnicastSessionList(req);
5104
- json(res, 201, resp ?? session);
5105
5111
  }
5106
5112
  async handleSendInput(sessionId, req, res) {
5107
5113
  if (this.agentConfig.enabled) {
@@ -5404,20 +5410,29 @@ var StreamerServer = class {
5404
5410
  cleanup();
5405
5411
  return;
5406
5412
  }
5407
- if (!existsSync6(filePath)) return;
5413
+ let resolvedFilePath = existsSync6(filePath) ? filePath : null;
5414
+ if (!resolvedFilePath && existsSync6(projectsDir)) {
5415
+ try {
5416
+ const now = Date.now();
5417
+ const recent = readdirSync3(projectsDir).filter((f) => f.endsWith(".jsonl")).map((f) => ({ f, mtime: statSync5(join12(projectsDir, f)).mtimeMs })).filter(({ mtime }) => now - mtime < 5e3).sort((a, b) => b.mtime - a.mtime)[0];
5418
+ if (recent) resolvedFilePath = join12(projectsDir, recent.f);
5419
+ } catch {
5420
+ }
5421
+ }
5422
+ if (!resolvedFilePath) return;
5408
5423
  cleanup();
5409
- this.sessionFileMap.set(sessionId, filePath);
5410
- this.fileWatcher.watch(filePath);
5424
+ this.sessionFileMap.set(sessionId, resolvedFilePath);
5425
+ this.fileWatcher.watch(resolvedFilePath);
5411
5426
  if (this.scannerReady) {
5412
5427
  this.scannerStale = true;
5413
5428
  } else {
5414
5429
  this.scanner = null;
5415
5430
  }
5416
- this.linkSessionToProject(sessionId, projectPath, filePath);
5431
+ this.linkSessionToProject(sessionId, projectPath, resolvedFilePath);
5417
5432
  this.cache?.markAsStreamer(sessionId);
5418
5433
  this.log.info(
5419
5434
  `[startFresh] wired JSONL for ${sessionId}`,
5420
- { event: "session.jsonl_wired", sessionId, filePath },
5435
+ { event: "session.jsonl_wired", sessionId, filePath: resolvedFilePath },
5421
5436
  "pino"
5422
5437
  );
5423
5438
  };