/** * Gateway/Bot Module for PraisonAI TypeScript SDK * * Python parity with praisonaiagents gateway/bot types * * Provides: * - Bot protocols and interfaces * - Gateway protocols and interfaces * - Message types */ /** * Bot configuration. * Python parity: praisonaiagents/bots */ export interface BotConfig { name: string; token?: string; prefix?: string; channels?: string[]; allowedUsers?: string[]; metadata?: Record; } /** * Bot user. * Python parity: praisonaiagents/bots */ export interface BotUser { id: string; name: string; displayName?: string; isBot?: boolean; metadata?: Record; } /** * Bot channel. * Python parity: praisonaiagents/bots */ export interface BotChannel { id: string; name: string; type: 'text' | 'voice' | 'dm' | 'group'; metadata?: Record; } /** * Bot message. * Python parity: praisonaiagents/bots */ export interface BotMessage { id: string; content: string; author: BotUser; channel: BotChannel; timestamp: Date; attachments?: Array<{ url: string; type: string; name?: string; }>; metadata?: Record; } /** * Bot protocol interface. * Python parity: praisonaiagents/bots */ export interface BotProtocol { name: string; config: BotConfig; connect(): Promise; disconnect(): Promise; sendMessage(channel: string, content: string): Promise; onMessage(handler: (message: BotMessage) => void | Promise): void; getUser(userId: string): Promise; getChannel(channelId: string): Promise; } /** * Gateway configuration. * Python parity: praisonaiagents/gateway */ export interface GatewayConfig { url: string; apiKey?: string; timeout?: number; retryAttempts?: number; retryDelay?: number; metadata?: Record; } /** * Gateway event. * Python parity: praisonaiagents/gateway */ export interface GatewayEvent { type: string; data: any; timestamp: Date; source?: string; metadata?: Record; } /** * Standard gateway event types. * Python parity: `EventType(str, Enum)` in praisonaiagents/gateway/protocols.py, * exported from the package as `GatewayEventType`. Kept in lockstep by * praisonai-agents/tests/unit/test_gateway_ts_event_type_lockstep.py. */ export declare enum GatewayEventType { CONNECT = "connect", DISCONNECT = "disconnect", RECONNECT = "reconnect", SESSION_START = "session_start", SESSION_END = "session_end", SESSION_UPDATE = "session_update", AGENT_REGISTER = "agent_register", AGENT_UNREGISTER = "agent_unregister", AGENT_STATUS = "agent_status", MESSAGE = "message", MESSAGE_ACK = "message_ack", MESSAGE_ABORT = "message_abort", TYPING = "typing", TOKEN_STREAM = "token_stream", TOOL_CALL_STREAM = "tool_call_stream", REASONING_STREAM = "reasoning_stream", TOOL_PROGRESS_STREAM = "tool_progress_stream", STREAM_ERROR = "stream_error", STREAM_END = "stream_end", MODEL_FALLBACK_STREAM = "model_fallback_stream", RETRY_STREAM = "retry_stream", TODO_STREAM = "todo_stream", TOOL_RESULT_STREAM = "tool_result_stream", HEALTH = "health", ERROR = "error", BROADCAST = "broadcast", PING = "ping", PONG = "pong", CHANNEL_SUBSCRIBE = "channel_subscribe", CHANNEL_UNSUBSCRIBE = "channel_unsubscribe", CHANNEL_MESSAGE = "channel_message", CHANNEL_CREATED = "channel_created", CHANNEL_DELETED = "channel_deleted", PRESENCE_JOIN = "presence_join", PRESENCE_LEAVE = "presence_leave", PRESENCE_UPDATE = "presence_update", MESSAGE_NACK = "message_nack", DELIVERY_RETRY = "delivery_retry", POLL_REQUEST = "poll_request", POLL_RESPONSE = "poll_response", HELLO = "hello", HELLO_OK = "hello_ok", HELLO_ERROR = "hello_error" } /** * Gateway message. * Python parity: praisonaiagents/gateway */ export interface GatewayMessage { id: string; type: 'request' | 'response' | 'event' | 'error'; payload: any; timestamp: Date; correlationId?: string; metadata?: Record; } /** * Gateway protocol interface. * Python parity: praisonaiagents/gateway */ export interface GatewayProtocol { config: GatewayConfig; connect(): Promise; disconnect(): Promise; isConnected(): boolean; send(message: GatewayMessage): Promise; receive(): Promise; onEvent(handler: (event: GatewayEvent) => void | Promise): void; onError(handler: (error: Error) => void): void; } /** * Gateway client protocol. * Python parity: praisonaiagents/gateway */ export interface GatewayClientProtocol extends GatewayProtocol { request(payload: any, timeout?: number): Promise; subscribe(eventType: string, handler: (event: GatewayEvent) => void): () => void; } /** * Gateway session protocol. * Python parity: praisonaiagents/gateway */ export interface GatewaySessionProtocol { sessionId: string; userId?: string; startTime: Date; metadata?: Record; isActive(): boolean; extend(duration: number): void; terminate(): void; } /** * Immutable view of a single agent run/turn within a session. * Python parity: `RunView` in praisonaiagents/gateway/session_projection.py */ export interface RunView { runId: string; text: string; done: boolean; finalMessageId?: string; } /** * A transcript entry tracked by the projection. * Loosely mirrors Python's `GatewayMessage`. */ export interface ProjectionEntry { messageId: string; content: any; senderId?: string; requestId?: string; metadata?: Record; } /** * Immutable, de-duplicated, bounded view of a session. * Python parity: `SessionProjectionState`. */ export interface SessionProjectionState { entries: ProjectionEntry[]; runs: Record; hasTransportGap: boolean; } /** * A snapshot to seed the projection. */ export interface SessionSnapshot { messages?: ProjectionEntry[]; entries?: ProjectionEntry[]; cursor?: number; sequence?: number; } /** * Pure, dependency-free session-projection reducer. * * Folds an initial snapshot plus a stream of {@link GatewayEvent}s into a * consistent, de-duplicated, memory-bounded view — so every gateway client * stops re-implementing snapshot+event reconciliation, final-message * de-duplication, optimistic echo reconciliation, gap healing and bounded * retention. * * Python parity: `SessionProjection` in * praisonaiagents/gateway/session_projection.py (Issue #5324). */ export declare class SessionProjection { private readonly maxTrackedRuns; private entries; private byMessageId; private byRequestId; private runs; private expectedSequence; private hasGap; constructor(options?: { maxTrackedRuns?: number; }); get state(): SessionProjectionState; applySnapshot(snapshot: SessionSnapshot): SessionProjectionState; apply(event: GatewayEvent): SessionProjectionState; private trackSequence; private applyMessage; private upsertMessage; private reindex; private runIdOf; private applyDelta; private applyStreamEnd; private evictRuns; } /** * Provider status. * Python parity: praisonaiagents/gateway */ export interface ProviderStatus { name: string; status: 'online' | 'offline' | 'degraded' | 'unknown'; latency?: number; lastCheck: Date; errorCount?: number; metadata?: Record; } /** * Failover configuration. * Python parity: praisonaiagents/gateway */ export interface FailoverConfig { providers: string[]; strategy: 'round-robin' | 'priority' | 'random' | 'least-latency'; maxRetries?: number; retryDelay?: number; healthCheckInterval?: number; } /** * Failover manager. * Python parity: praisonaiagents/gateway */ export declare class FailoverManager { private config; private providerStatuses; private currentIndex; constructor(config: FailoverConfig); /** * Get the next provider based on strategy. */ getNextProvider(): string | null; /** * Update provider status. */ updateStatus(provider: string, status: Partial): void; /** * Mark provider as failed. */ markFailed(provider: string): void; /** * Mark provider as healthy. */ markHealthy(provider: string, latency?: number): void; /** * Get all provider statuses. */ getStatuses(): ProviderStatus[]; } /** * Auth profile. * Python parity: praisonaiagents/auth */ export interface AuthProfile { userId: string; username?: string; email?: string; roles?: string[]; permissions?: string[]; token?: string; expiresAt?: Date; metadata?: Record; } /** * Resource limits. * Python parity: praisonaiagents/limits */ export interface ResourceLimits { maxTokens?: number; maxRequests?: number; maxConcurrent?: number; rateLimitPerMinute?: number; rateLimitPerHour?: number; maxMemoryMB?: number; maxExecutionTimeMs?: number; } /** * Sandbox status. * Python parity: praisonaiagents/sandbox */ export declare enum SandboxStatus { IDLE = "idle", RUNNING = "running", COMPLETED = "completed", FAILED = "failed", TIMEOUT = "timeout" } /** * Sandbox result. * Python parity: praisonaiagents/sandbox */ export interface SandboxResult { status: SandboxStatus; output?: string; error?: string; exitCode?: number; duration?: number; metadata?: Record; } /** * Sandbox protocol. * Python parity: praisonaiagents/sandbox */ export interface SandboxProtocol { execute(code: string, language?: string): Promise; executeFile(filePath: string): Promise; terminate(): Promise; getStatus(): SandboxStatus; } /** * Autonomy level. * Python parity: praisonaiagents/autonomy */ export declare enum AutonomyLevel { NONE = "none", SUGGEST = "suggest", AUTO_APPROVE = "auto_approve", FULL_AUTO = "full_auto" } /** * Reflection output. * Python parity: praisonaiagents/reflection */ export interface ReflectionOutput { originalOutput: string; reflectedOutput: string; iterations: number; improvements: string[]; score?: number; metadata?: Record; } /** * RAG retrieval policy. * Python parity: praisonaiagents/rag */ export declare enum RagRetrievalPolicy { SIMILARITY = "similarity", MMR = "mmr", HYBRID = "hybrid", RERANK = "rerank" } /** * Auto RAG configuration. * Python parity: praisonaiagents/knowledge */ export interface AutoRagConfig { sources: string[]; chunkSize?: number; chunkOverlap?: number; topK?: number; rerank?: boolean; retrievalPolicy?: RagRetrievalPolicy; }