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

Function chat

packages/ai/src/activities/chat/index.ts:2666–2734  ·  view source on GitHub ↗
(
  options: TextActivityOptionsWithContext<
    TAdapter,
    TSchema,
    TStream,
    TTools,
    TMiddleware
  >,
)

Source from the content-addressed store, hash-verified

2664 * ```
2665 */
2666export function chat<
2667 TAdapter extends AnyTextAdapter,
2668 TSchema extends SchemaInput | undefined = undefined,
2669 TStream extends boolean = boolean,
2670 const TTools extends TextActivityOptions<
2671 TAdapter,
2672 TSchema,
2673 TStream,
2674 any
2675 >['tools'] = TextActivityOptions<TAdapter, TSchema, TStream, any>['tools'],
2676 const TMiddleware extends TextActivityOptions<
2677 TAdapter,
2678 TSchema,
2679 TStream,
2680 any
2681 >['middleware'] = TextActivityOptions<
2682 TAdapter,
2683 TSchema,
2684 TStream,
2685 any
2686 >['middleware'],
2687>(
2688 options: TextActivityOptionsWithContext<
2689 TAdapter,
2690 TSchema,
2691 TStream,
2692 TTools,
2693 TMiddleware
2694 >,
2695): TextActivityResult<TSchema, TStream> {
2696 validateCapabilities(options.middleware ?? [], options.adapter)
2697
2698 const { outputSchema, stream } = options
2699
2700 // outputSchema + stream:true is the only branch that streams structured
2701 // output. Without an explicit `stream: true`, schema-bearing calls run the
2702 // agent loop and resolve to a typed Promise<InferSchemaType<TSchema>>.
2703 if (outputSchema && stream === true) {
2704 return runStreamingStructuredOutput({
2705 ...options,
2706 outputSchema,
2707 stream,
2708 }) as TextActivityResult<TSchema, TStream>
2709 }
2710
2711 // If outputSchema is provided, run agentic structured output (Promise<T>)
2712 if (outputSchema) {
2713 return runAgenticStructuredOutput({
2714 ...options,
2715 outputSchema,
2716 }) as TextActivityResult<TSchema, TStream>
2717 }
2718
2719 // If stream is explicitly false, run non-streaming text
2720 if (stream === false) {
2721 return runNonStreamingText({
2722 ...options,
2723 outputSchema: undefined,

Callers 15

mainFunction · 0.90
judgeReportsFunction · 0.90
buildRunStreamFunction · 0.90
runAgentFunction · 0.90
runLiveTestFunction · 0.90
runStructuredOutputTestFunction · 0.90
runSimulatedTestFunction · 0.90
runRegistryTestFunction · 0.90
selectRelevantSkillsFunction · 0.90
middleware.test.tsFile · 0.90
runChatWithMiddlewareFunction · 0.90

Calls 5

validateCapabilitiesFunction · 0.90
runNonStreamingTextFunction · 0.85
runStreamingTextFunction · 0.85

Tested by 5

runChatWithMiddlewareFunction · 0.72
runWithToolAndCaptureFunction · 0.72
captureSerializedToolFunction · 0.72
runFinishedFunction · 0.72
captureSerializedToolsFunction · 0.72