/** * March Agent SDK - Shared Types * Port of Python march_agent types */ import { z } from 'zod' // ============================================================================ // Kafka Message Types // ============================================================================ export interface KafkaMessage { topic: string partition: number offset: number key: string headers: Record body: Record timestamp: number } export interface KafkaHeaders { conversationId?: string userId?: string from_?: string to_?: string messageMetadata?: string messageSchema?: string attachment?: string [key: string]: string | undefined } // ============================================================================ // Agent Registration Types // ============================================================================ export interface AgentRegistrationData { id: string name: string about: string document: string representationName?: string baseUrl?: string metadata?: Record relatedPages?: RelatedPage[] } export interface RelatedPage { name: string endpoint: string } export interface RegisterOptions { name: string about: string document: string representationName?: string baseUrl?: string metadata?: Record relatedPages?: RelatedPage[] } // ============================================================================ // Message Types // ============================================================================ // Forward reference - actual Message class is imported where needed // Using 'any' here to avoid circular dependency, but consumers should use Message type export interface MessageHandler { // eslint-disable-next-line @typescript-eslint/no-explicit-any (message: any, sender: string): void | Promise } export interface SenderFilterOptions { senders?: string[] } // ============================================================================ // Streamer Types // ============================================================================ export interface StreamOptions { persist?: boolean eventType?: string } export interface StreamerOptions { awaiting?: boolean sendTo?: string } // ============================================================================ // Attachment Types // ============================================================================ export const AttachmentInfoSchema = z.object({ url: z.string(), filename: z.string(), contentType: z.string(), size: z.number().optional(), fileType: z.string().optional(), }) export type AttachmentInfo = z.infer export function isImageAttachment(attachment: AttachmentInfo): boolean { return attachment.contentType?.startsWith('image/') || false } export function isPdfAttachment(attachment: AttachmentInfo): boolean { return attachment.contentType === 'application/pdf' } // ============================================================================ // Conversation Message Types // ============================================================================ export interface ConversationMessageData { id: string conversationId: string role: 'user' | 'assistant' | 'system' content: string from?: string to?: string createdAt: string metadata?: Record } // ============================================================================ // Gateway Client Types // ============================================================================ export interface ProduceAck { topic: string partition: number offset: number correlationId?: string } // ============================================================================ // Reconnection Types // ============================================================================ /** * Configuration options for automatic reconnection behavior. */ export interface ReconnectionOptions { /** Maximum number of reconnection attempts before giving up. Default: 10 */ maxRetries?: number /** Initial delay in milliseconds before first retry. Default: 1000 */ initialDelayMs?: number /** Maximum delay in milliseconds between retries. Default: 30000 */ maxDelayMs?: number /** Multiplier for exponential backoff. Default: 2 */ backoffMultiplier?: number /** Whether to automatically reconnect on disconnect. Default: true */ autoReconnect?: boolean } /** * Connection state for the gateway client. */ export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' /** * Listener callback for connection state changes. */ export interface ConnectionStateListener { (state: ConnectionState, error?: Error): void } /** * Default reconnection options. */ export const DEFAULT_RECONNECTION_OPTIONS: Required = { maxRetries: 10, initialDelayMs: 1000, maxDelayMs: 30000, backoffMultiplier: 2, autoReconnect: true, } // ============================================================================ // App Configuration Types // ============================================================================ export interface AppOptions { gatewayUrl: string apiKey: string heartbeatInterval?: number maxConcurrentTasks?: number errorMessageTemplate?: string secure?: boolean /** Reconnection options for the gateway connection */ reconnection?: ReconnectionOptions } // ============================================================================ // HTTP Response Types // ============================================================================ export interface ConversationData { id: string userId: string agentId?: string awaitingRoute?: string pendingResponseSchema?: Record createdAt: string updatedAt: string metadata?: Record } export interface GetMessagesOptions { role?: string from?: string to?: string limit?: number offset?: number } // ============================================================================ // Memory Types // ============================================================================ /** * A message for memory ingestion (simplified format). */ export interface MemoryMessage { role: 'user' | 'assistant' content: string timestamp?: string } /** * A stored message from ai-memory (full format). */ export interface StoredMemoryMessage { id: string role: 'user' | 'assistant' content: string tenantId?: string userId?: string conversationId?: string metadata?: Record timestamp?: string sequenceNumber?: number } /** * A memory search result with similarity score and optional context. */ export interface MemorySearchResult { message: StoredMemoryMessage score: number context?: StoredMemoryMessage[] } /** * User conversation summary. */ export interface UserSummary { userId: string text: string lastUpdated: string messageCount: number version: number }