import type { Adapter, Thread } from 'chat'; import type { IMastraLogger } from '../logger/logger.js'; import type { AgentChunkType } from '../stream/types.js'; import type { PendingApprovalRecord } from './stream-helpers.js'; import type { ToolDisplayFn } from './types.js'; export interface StreamingDriverArgs { stream: AsyncIterable>; chatThread: Thread; adapter: Adapter; /** * Resolved tool display mode. `'timeline'`/`'grouped'`/`'hidden'` render * inside the streaming `Plan` widget; `'cards'`/`'text'` render as * discrete `chatThread.post`/`edit` calls — the driver closes the active * session, posts the per-tool message, and reopens on the next chunk. */ toolDisplay: 'cards' | 'text' | 'timeline' | 'grouped' | 'hidden'; /** * Optional function-form `toolDisplay` callback. When set, the built-in * renderers are bypassed and this is called once per tool lifecycle event. * A `{ kind: 'post' }` return triggers the close/post/reopen lifecycle * (same as `'cards'`/`'text'`); a `{ kind: 'stream' }` return pushes the * chunk into the active streaming session. */ toolDisplayFn?: ToolDisplayFn; streamingOptions?: { updateIntervalMs?: number; }; channelToolNames: Set; logger?: IMastraLogger; /** * Called when an approval card is posted so the outer channels instance * can resume the correct run on click. The driver doesn't know how the * click handler looks up the runId — it just stashes the record. */ onApprovalPosted: (toolCallId: string, record: PendingApprovalRecord) => void; /** * Read access to the approval-card stash so a `tool-result` that arrives * via the resumed run's subscription (skipping the original `tool-call`) * can still find the original card's `messageId` to edit. */ getPendingApproval: (toolCallId: string) => PendingApprovalRecord | undefined; /** * Pop the stash entry for `toolCallId` — used by terminal chunks * (`tool-result`, `tool-error`) so the stash doesn't leak across runs. */ takePendingApproval: (toolCallId: string) => PendingApprovalRecord | undefined; /** * Shared mutable flag the typing-status wrapper reads. The driver flips * `active = true` while a `StreamingPlan` post is in flight so the wrapper * skips `startTyping` (Slack's `assistant.threads.setStatus` doesn't * auto-clear on `chat.stopStream`, only on `chat.postMessage`, so a status * set during streaming would stick after the run ends). */ typingGate: { active: boolean; }; /** Optional adapter-supplied formatter for `error` chunks; defaults to a plain prefix. */ formatError?: (error: Error) => unknown; } /** * Streaming driver: consumes `AgentChunkType` chunks and renders them * through one or more chat-SDK `StreamingPlan` posts. Handles `timeline`, * `grouped`, and `hidden` tool-display modes (all of which require * `streaming: true`). Out-of-band chunks (approval, file, tripwire, error) * close the current session, post separately, then optionally reopen on the * next text/tool chunk. */ export declare function runStreamingDriver({ stream, chatThread, adapter, toolDisplay, toolDisplayFn, streamingOptions, channelToolNames, logger, onApprovalPosted, getPendingApproval, takePendingApproval, typingGate, formatError, }: StreamingDriverArgs): Promise; //# sourceMappingURL=chat-driver-streaming.d.ts.map