n8n
Version:
n8n Workflow Automation Tool
32 lines (31 loc) • 1.31 kB
TypeScript
import type { StreamChunk } from '@n8n/agents';
import type { Thread } from 'chat';
import type { Logger } from 'n8n-workflow';
import type { BridgeStatusHandle } from './agent-chat-integration';
type SuspendedChunk = Extract<StreamChunk, {
type: 'tool-call-suspended';
}>;
type MessageChunk = Extract<StreamChunk, {
type: 'message';
}>;
export type SuspensionHandlingResult = 'posted' | 'skipped' | 'failed';
interface AgentChatStreamConsumerOptions {
disableStreaming: boolean;
logger: Logger;
postErrorToThread: (thread: Thread<unknown, unknown> | null, error: unknown) => Promise<void>;
handleSuspension: (chunk: SuspendedChunk, thread: Thread<unknown, unknown>) => Promise<SuspensionHandlingResult>;
handleMessage: (chunk: MessageChunk, thread: Thread<unknown, unknown>) => Promise<boolean>;
}
interface ConsumeStreamOptions {
forceBuffered?: boolean;
statusHandle?: BridgeStatusHandle;
}
export declare class AgentChatStreamConsumer {
private readonly options;
constructor(options: AgentChatStreamConsumerOptions);
consume(stream: AsyncGenerator<StreamChunk>, thread: Thread<unknown, unknown>, options?: ConsumeStreamOptions): Promise<void>;
private createResponseLifecycle;
private postFallbackIfNeeded;
private consumeBuffered;
}
export {};