* Run streaming text (agentic or one-shot depending on tools)
( options: TextActivityOptions<AnyTextAdapter, undefined, true, TContext>, )
| 2737 | * Run streaming text (agentic or one-shot depending on tools) |
| 2738 | */ |
| 2739 | async 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. |
no test coverage detected