MCPcopy Index your code
hub / github.com/TanStack/ai / observeChunk

Method observeChunk

packages/ai-client/src/devtools.ts:809–829  ·  view source on GitHub ↗
(chunk: StreamChunk)

Source from the content-addressed store, hash-verified

807 }
808
809 observeChunk(chunk: StreamChunk): void {
810 if (chunk.type === 'RUN_STARTED') {
811 this.beginRun(chunk.runId, chunk.threadId)
812 return
813 }
814
815 if (chunk.type === 'RUN_FINISHED' || chunk.type === 'RUN_ERROR') {
816 const runId =
817 chunk.type === 'RUN_FINISHED'
818 ? chunk.runId
819 : (chunk as { runId?: string }).runId
820 if (!runId || runId === this.currentRunId) {
821 const context = this.getCurrentRunEventContext()
822 if (context) {
823 this.lastRunEventContext = context
824 }
825 this.currentRunId = null
826 this.currentRunThreadId = null
827 }
828 }
829 }
830
831 getCurrentRunEventContext(): ChatClientRunEventContext | undefined {
832 if (!this.currentRunId) return undefined

Callers 1

consumeSubscriptionMethod · 0.45

Calls 2

beginRunMethod · 0.95

Tested by

no test coverage detected