(
chunk: StreamChunk,
options?: { resolveProcessing?: boolean },
)
| 459 | } |
| 460 | |
| 461 | private updateRunLifecycle( |
| 462 | chunk: StreamChunk, |
| 463 | options?: { resolveProcessing?: boolean }, |
| 464 | ): void { |
| 465 | if (chunk.type === 'RUN_STARTED') { |
| 466 | const chunkRunId = getChunkRunId(chunk) ?? chunk.runId |
| 467 | this.activeRunIds.add(chunkRunId) |
| 468 | this.persistor?.onRunStarted(chunkRunId) |
| 469 | this.setSessionGenerating(true) |
| 470 | return |
| 471 | } |
| 472 | |
| 473 | if (chunk.type !== 'RUN_FINISHED' && chunk.type !== 'RUN_ERROR') { |
| 474 | return |
| 475 | } |
| 476 | |
| 477 | const runId = getChunkRunId(chunk) |
| 478 | if (runId) { |
| 479 | this.activeRunIds.delete(runId) |
| 480 | this.persistor?.onRunSettled(runId) |
| 481 | } else if (chunk.type === 'RUN_ERROR') { |
| 482 | // RUN_ERROR without runId is a session-level error; clear all runs. |
| 483 | this.activeRunIds.clear() |
| 484 | this.persistor?.onSessionRunError() |
| 485 | } |
| 486 | this.setSessionGenerating(this.activeRunIds.size > 0) |
| 487 | if (options?.resolveProcessing !== false) { |
| 488 | this.resolveProcessing() |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | private generateUniqueId(prefix: string): string { |
| 493 | return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}` |
no test coverage detected