/** * Message Processing Pipeline * * Three-stage pipeline: * - Preflight: Filter empty messages, self-messages, detect commands * - Process: Transform format, extract metadata * - Delivery: Send to Agent */ import type { AgentResponse } from './plugin-types.js'; export type { AgentResponse } from './plugin-types.js'; export interface PipelineMessageContext { /** Channel identifier */ channel: string; /** Account ID */ accountId: string; /** Chat ID */ chatId: string; /** Sender ID */ senderId: string; /** Message content */ content: string; /** Original message metadata */ metadata: Record; /** Is group chat */ isGroup: boolean; /** Is direct message */ isDm: boolean; /** Thread ID (optional) */ threadId?: string; /** Message ID (optional) */ messageId?: string; } export interface PipelineMediaRef { type: 'photo' | 'video' | 'audio' | 'document' | 'voice'; fileId: string; mimeType?: string; fileName?: string; url?: string; } export interface PreflightHandler { /** Handler name */ name: string; /** Preflight - return null to skip message */ preflight?(ctx: PipelineMessageContext): Promise; } export interface ProcessHandler { /** Handler name */ name: string; /** Process message - transform and extract */ process(ctx: PipelineMessageContext): Promise; } export interface DeliveryHandler { /** Handler name */ name: string; /** Deliver message to Agent */ deliver(ctx: PipelineMessageContext, response: AgentResponse): Promise; } export interface PipelineOptions { /** Channel name */ channel: string; /** Preflight handlers */ preflightHandlers?: PreflightHandler[]; /** Process handlers */ processHandlers?: ProcessHandler[]; /** Delivery handlers */ deliveryHandlers?: DeliveryHandler[]; /** Agent callback */ agentInvoke?: (ctx: PipelineMessageContext) => Promise; /** Error handler */ onError?: (err: unknown, ctx: PipelineMessageContext) => void; } export declare class MessagePipeline { private channel; private preflightHandlers; private processHandlers; private deliveryHandlers; private agentInvoke?; private onError?; constructor(options: PipelineOptions); /** * Handle inbound message */ handleMessage(ctx: PipelineMessageContext): Promise; private runPreflight; private runProcess; private runDelivery; } /** * Create filter-self handler */ export declare function createFilterSelfHandler(currentBotId: string): PreflightHandler; /** * Create filter-empty handler */ export declare function createFilterEmptyHandler(): PreflightHandler; /** * Create filter-commands handler */ export declare function createFilterCommandsHandler(commands: string[]): PreflightHandler; /** * Create standard preflight handlers */ export declare function standardPreflightHandlers(botId: string): PreflightHandler[]; /** * Prepends a per-turn `[YYYY-MM-DD HH:MM TZ]` prefix to inbound text so the model has * a stable "now" without changing the system prompt (prompt-cache friendly). */ export declare function createEnvelopeTimestampHandler(timezone?: string): ProcessHandler; /** * Create standard process handlers */ export declare function standardProcessHandlers(timezone?: string): ProcessHandler[]; export interface CreatePipelineParams { channel: string; botId: string; agentInvoke: PipelineOptions['agentInvoke']; onError?: PipelineOptions['onError']; /** IANA timezone — matches userTimezone from config or global user profile */ timezone?: string; } /** * Create message processing pipeline */ export declare function createPipeline(params: CreatePipelineParams): MessagePipeline;