MCPcopy
hub / github.com/TanStack/ai / updateRunLifecycle

Method updateRunLifecycle

packages/ai-client/src/chat-client.ts:461–490  ·  view source on GitHub ↗
(
    chunk: StreamChunk,
    options?: { resolveProcessing?: boolean },
  )

Source from the content-addressed store, hash-verified

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)}`

Callers 1

consumeSubscriptionMethod · 0.95

Calls 8

setSessionGeneratingMethod · 0.95
resolveProcessingMethod · 0.95
getChunkRunIdFunction · 0.90
onRunStartedMethod · 0.80
onRunSettledMethod · 0.80
onSessionRunErrorMethod · 0.80
deleteMethod · 0.65
clearMethod · 0.65

Tested by

no test coverage detected