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

Method setResult

packages/ai-client/src/generation-client.ts:384–415  ·  view source on GitHub ↗
(rawResult: TResult | null)

Source from the content-addressed store, hash-verified

382 // ===========================
383
384 private setResult(rawResult: TResult | null): void {
385 if (rawResult === null) {
386 this.result = null
387 this.callbacksRef.onResultChange?.(null)
388 this.devtoolsBridge.recordResultChange()
389 return
390 }
391
392 if (this.callbacksRef.onResult) {
393 const transformed = this.callbacksRef.onResult(rawResult)
394 if (transformed === null) {
395 // null return → keep previous result unchanged, just re-emit
396 this.devtoolsBridge.emitState()
397 return
398 }
399 if (transformed !== undefined) {
400 // Non-null, non-undefined → use transformed value
401 this.result = transformed
402 this.callbacksRef.onResultChange?.(this.result)
403 this.devtoolsBridge.recordResultChange()
404 return
405 }
406 }
407
408 // No onResult callback, or callback returned void → use raw value as
409 // TOutput. When the caller did not supply an onResult transform,
410 // `TOutput` defaults to `TResult`, so the runtime cast is sound.
411 // eslint-disable-next-line no-restricted-syntax -- TOutput defaults to TResult when no onResult transform is supplied
412 this.result = rawResult as unknown as TOutput
413 this.callbacksRef.onResultChange?.(this.result)
414 this.devtoolsBridge.recordResultChange()
415 }
416
417 private setIsLoading(isLoading: boolean): void {
418 this.isLoading = isLoading

Callers 3

generateMethod · 0.95
processStreamMethod · 0.95
resetMethod · 0.95

Calls 2

recordResultChangeMethod · 0.45
emitStateMethod · 0.45

Tested by

no test coverage detected