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

Function runStreamingText

packages/ai/src/activities/chat/index.ts:2739–2773  ·  view source on GitHub ↗

* Run streaming text (agentic or one-shot depending on tools)

(
  options: TextActivityOptions<AnyTextAdapter, undefined, true, TContext>,
)

Source from the content-addressed store, hash-verified

2737 * Run streaming text (agentic or one-shot depending on tools)
2738 */
2739async function* runStreamingText<TContext = unknown>(
2740 options: TextActivityOptions<AnyTextAdapter, undefined, true, TContext>,
2741): AsyncIterable<StreamChunk> {
2742 const { adapter, middleware, context, debug, mcp, ...textOptions } = options
2743 const model = adapter.model
2744 const logger = resolveDebugOption(debug)
2745
2746 const mcpManager = MCPManager.from(mcp)
2747 const mcpTools = await mcpManager.discover()
2748 if (mcpTools.length > 0) {
2749 textOptions.tools = [...(textOptions.tools ?? []), ...mcpTools]
2750 }
2751
2752 const engine = new TextEngine(
2753 {
2754 adapter,
2755 params: { ...textOptions, model, logger } as TextOptions<
2756 Record<string, any>,
2757 Record<string, any>,
2758 TContext
2759 >,
2760 middleware,
2761 context,
2762 },
2763 logger,
2764 )
2765
2766 try {
2767 for await (const chunk of engine.run()) {
2768 yield chunk
2769 }
2770 } finally {
2771 await mcpManager.dispose()
2772 }
2773}
2774
2775/**
2776 * Run non-streaming text - collects all content and returns as a string.

Callers 2

chatFunction · 0.85
runNonStreamingTextFunction · 0.85

Calls 5

runMethod · 0.95
resolveDebugOptionFunction · 0.90
fromMethod · 0.80
discoverMethod · 0.80
disposeMethod · 0.45

Tested by

no test coverage detected