@axiom-lattice/protocols 2.1.7 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/AgentLatticeProtocol.ts","../src/MemoryLatticeProtocol.ts","../src/UILatticeProtocol.ts","../src/QueueLatticeProtocol.ts","../src/ScheduleLatticeProtocol.ts"],"sourcesContent":["/**\n * AgentLatticeProtocol\n *\n * 智能体Lattice的协议,定义了智能体的行为和组合方式\n */\n\nimport { CompiledStateGraph } from \"@langchain/langgraph\";\nimport z, { ZodObject, ZodSchema } from \"zod\";\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 智能体类型枚举\n */\nexport enum AgentType {\n REACT = \"react\",\n DEEP_AGENT = \"deep_agent\",\n PLAN_EXECUTE = \"plan_execute\",\n SEQUENTIAL = \"sequential\",\n}\n\n/**\n * Base agent configuration shared by all agent types\n */\ninterface BaseAgentConfig {\n key: string; // Unique key\n name: string; // Name\n description: string; // Description\n prompt: string; // Prompt\n schema?: ZodObject<any, any, any, any, any>; // Input validation schema\n modelKey?: string; // Model key to use\n}\n\n/**\n * REACT agent configuration\n */\nexport interface ReactAgentConfig extends BaseAgentConfig {\n type: AgentType.REACT;\n tools?: string[]; // Tool list\n}\n\n/**\n * DEEP_AGENT configuration - only this type supports subAgents\n */\nexport interface DeepAgentConfig extends BaseAgentConfig {\n type: AgentType.DEEP_AGENT;\n tools?: string[]; // Tool list\n subAgents?: string[]; // Sub-agent list (unique to DEEP_AGENT)\n internalSubAgents?: AgentConfig[]; // Internal sub-agent list (unique to DEEP_AGENT)\n}\n\n/**\n * PLAN_EXECUTE agent configuration\n */\nexport interface PlanExecuteAgentConfig extends BaseAgentConfig {\n type: AgentType.PLAN_EXECUTE;\n tools?: string[]; // Tool list\n}\n\n/**\n * SEQUENTIAL agent configuration\n */\nexport interface SequentialAgentConfig extends BaseAgentConfig {\n type: AgentType.SEQUENTIAL;\n}\n\n/**\n * Agent configuration union type\n * Different agent types have different configuration options\n */\nexport type AgentConfig =\n | ReactAgentConfig\n | DeepAgentConfig\n | PlanExecuteAgentConfig\n | SequentialAgentConfig;\n\n/**\n * Agent configuration with tools property\n */\nexport type AgentConfigWithTools =\n | ReactAgentConfig\n | DeepAgentConfig\n | PlanExecuteAgentConfig;\n\n/**\n * Type guard to check if config has tools property\n */\nexport function hasTools(config: AgentConfig): config is AgentConfigWithTools {\n return config.type !== AgentType.SEQUENTIAL;\n}\n\n/**\n * Type guard to check if config is DeepAgentConfig (has subAgents)\n */\nexport function isDeepAgentConfig(\n config: AgentConfig\n): config is DeepAgentConfig {\n return config.type === AgentType.DEEP_AGENT;\n}\n\n/**\n * Get tools from config safely\n */\nexport function getToolsFromConfig(config: AgentConfig): string[] {\n if (hasTools(config)) {\n return config.tools || [];\n }\n return [];\n}\n\n/**\n * Get subAgents from config safely (only DeepAgentConfig has subAgents)\n */\nexport function getSubAgentsFromConfig(config: AgentConfig): string[] {\n if (isDeepAgentConfig(config)) {\n return config.subAgents || [];\n }\n return [];\n}\n\n/**\n * 智能体客户端类型\n */\nexport type AgentClient = CompiledStateGraph<any, any, any, any, any>;\n\n/**\n * Graph构建选项\n */\nexport interface GraphBuildOptions {\n overrideTools?: string[];\n overrideModel?: string;\n metadata?: Record<string, any>;\n}\n\n/**\n * 智能体Lattice协议接口\n */\nexport interface AgentLatticeProtocol\n extends BaseLatticeProtocol<AgentConfig, AgentClient> {\n // 智能体执行函数\n invoke: (input: any, options?: any) => Promise<any>;\n\n // 构建智能体图\n buildGraph: (options?: GraphBuildOptions) => Promise<AgentClient>;\n}\n","/**\n * MemoryLatticeProtocol\n *\n * 记忆Lattice的协议,用于管理智能体的上下文和记忆\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 记忆类型枚举\n */\nexport enum MemoryType {\n SHORT_TERM = \"short_term\",\n LONG_TERM = \"long_term\",\n EPISODIC = \"episodic\",\n SEMANTIC = \"semantic\",\n WORKING = \"working\",\n}\n\n/**\n * 记忆配置接口\n */\nexport interface MemoryConfig {\n name: string; // 名称\n description: string; // 描述\n type: MemoryType; // 记忆类型\n ttl?: number; // 生存时间\n capacity?: number; // 容量限制\n}\n\n/**\n * 记忆客户端接口\n */\nexport interface MemoryClient {\n add: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n update: (key: string, value: any) => Promise<void>;\n delete: (key: string) => Promise<void>;\n search: (query: string, options?: any) => Promise<any[]>;\n clear: () => Promise<void>;\n}\n\n/**\n * 记忆Lattice协议接口\n */\nexport interface MemoryLatticeProtocol\n extends BaseLatticeProtocol<MemoryConfig, MemoryClient> {\n // 记忆操作方法\n add: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n update: (key: string, value: any) => Promise<void>;\n delete: (key: string) => Promise<void>;\n search: (query: string, options?: any) => Promise<any[]>;\n clear: () => Promise<void>;\n}\n","/**\n * UILatticeProtocol\n *\n * UI Lattice的协议,用于定义用户界面组件\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * UI组件类型枚举\n */\nexport enum UIComponentType {\n CONTAINER = \"container\",\n INPUT = \"input\",\n BUTTON = \"button\",\n LIST = \"list\",\n TABLE = \"table\",\n CHART = \"chart\",\n FORM = \"form\",\n CARD = \"card\",\n MODAL = \"modal\",\n CUSTOM = \"custom\",\n}\n\n/**\n * UI配置接口\n */\nexport interface UIConfig {\n name: string; // 组件名称\n description: string; // 组件描述\n type: UIComponentType; // 组件类型\n props?: Record<string, any>; // 组件属性\n children?: string[]; // 子组件列表\n}\n\n/**\n * UI组件接口\n * 使用泛型以适应不同的UI框架(React, Vue等)\n */\nexport interface UIComponent<T = any> {\n render: (props?: any) => T;\n addEventListener: (event: string, handler: Function) => void;\n removeEventListener: (event: string, handler: Function) => void;\n}\n\n/**\n * UI Lattice协议接口\n */\nexport interface UILatticeProtocol<T = any>\n extends BaseLatticeProtocol<UIConfig, UIComponent<T>> {\n // UI渲染方法\n render: (props?: any) => T;\n\n // 事件处理\n addEventListener: (event: string, handler: Function) => void;\n removeEventListener: (event: string, handler: Function) => void;\n}\n","/**\n * QueueLatticeProtocol\n *\n * Queue Lattice protocol for task queue management\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * Queue service type enumeration\n */\nexport enum QueueType {\n MEMORY = \"memory\",\n REDIS = \"redis\",\n}\n\n/**\n * Queue configuration interface\n */\nexport interface QueueConfig {\n name: string; // Queue name\n description: string; // Queue description\n type: QueueType; // Queue service type\n queueName?: string; // Specific queue name (e.g., \"tasks\")\n options?: Record<string, any>; // Additional options (e.g., Redis connection options)\n}\n\n/**\n * Queue operation result interface\n */\nexport interface QueueResult<T = any> {\n data: T | null;\n error: any | null;\n}\n\n/**\n * Queue client interface\n */\nexport interface QueueClient {\n push: (item: any) => Promise<QueueResult<number>>;\n pop: () => Promise<QueueResult<any>>;\n createQueue?: () => Promise<{ success: boolean; queue_name?: string; error?: any }>;\n}\n\n/**\n * Queue Lattice protocol interface\n */\nexport interface QueueLatticeProtocol\n extends BaseLatticeProtocol<QueueConfig, QueueClient> {\n // Queue operations\n push: (item: any) => Promise<QueueResult<number>>;\n pop: () => Promise<QueueResult<any>>;\n createQueue?: () => Promise<{ success: boolean; queue_name?: string; error?: any }>;\n}\n\n\n\n","/**\n * ScheduleLatticeProtocol\n *\n * Schedule Lattice protocol for delayed task execution management\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * Schedule service type enumeration\n */\nexport enum ScheduleType {\n MEMORY = \"memory\",\n // Future implementations can add more types like REDIS, DATABASE, etc.\n}\n\n/**\n * Schedule configuration interface\n */\nexport interface ScheduleConfig {\n name: string; // Schedule name\n description: string; // Schedule description\n type: ScheduleType; // Schedule service type\n options?: Record<string, any>; // Additional options\n}\n\n/**\n * Scheduled task information interface\n */\nexport interface ScheduledTaskInfo {\n taskId: string;\n scheduledAt: number;\n timeoutMs: number;\n remainingMs: number;\n}\n\n/**\n * Schedule client interface\n */\nexport interface ScheduleClient {\n /**\n * Register a function to be executed after the specified timeout\n * @param taskId - Unique identifier for the task\n * @param callback - Function to execute when timeout expires\n * @param timeoutMs - Delay in milliseconds before execution\n * @returns true if registered successfully\n */\n register: (\n taskId: string,\n callback: () => void | Promise<void>,\n timeoutMs: number\n ) => boolean;\n\n /**\n * Cancel a scheduled task by its ID\n * @param taskId - The task identifier to cancel\n * @returns true if task was found and cancelled, false otherwise\n */\n cancel: (taskId: string) => boolean;\n\n /**\n * Check if a task is currently scheduled\n * @param taskId - The task identifier to check\n */\n has: (taskId: string) => boolean;\n\n /**\n * Get the remaining time in milliseconds for a scheduled task\n * @param taskId - The task identifier\n * @returns Remaining time in ms, or -1 if task not found\n */\n getRemainingTime: (taskId: string) => number;\n\n /**\n * Get the count of currently scheduled tasks\n */\n getTaskCount: () => number;\n\n /**\n * Get all scheduled task IDs\n */\n getTaskIds: () => string[];\n\n /**\n * Cancel all scheduled tasks\n */\n cancelAll: () => void;\n\n /**\n * Get task information\n * @param taskId - The task identifier\n * @returns Task info or null if not found\n */\n getTaskInfo?: (taskId: string) => ScheduledTaskInfo | null;\n}\n\n/**\n * Schedule Lattice protocol interface\n */\nexport interface ScheduleLatticeProtocol\n extends BaseLatticeProtocol<ScheduleConfig, ScheduleClient> {\n // Schedule operations\n register: (\n taskId: string,\n callback: () => void | Promise<void>,\n timeoutMs: number\n ) => boolean;\n cancel: (taskId: string) => boolean;\n has: (taskId: string) => boolean;\n getRemainingTime: (taskId: string) => number;\n getTaskCount: () => number;\n getTaskIds: () => string[];\n cancelAll: () => void;\n getTaskInfo?: (taskId: string) => ScheduledTaskInfo | null;\n}\n"],"mappings":";AAaO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,gBAAa;AACb,EAAAA,WAAA,kBAAe;AACf,EAAAA,WAAA,gBAAa;AAJH,SAAAA;AAAA,GAAA;AAyEL,SAAS,SAAS,QAAqD;AAC5E,SAAO,OAAO,SAAS;AACzB;AAKO,SAAS,kBACd,QAC2B;AAC3B,SAAO,OAAO,SAAS;AACzB;AAKO,SAAS,mBAAmB,QAA+B;AAChE,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO,OAAO,SAAS,CAAC;AAAA,EAC1B;AACA,SAAO,CAAC;AACV;AAKO,SAAS,uBAAuB,QAA+B;AACpE,MAAI,kBAAkB,MAAM,GAAG;AAC7B,WAAO,OAAO,aAAa,CAAC;AAAA,EAC9B;AACA,SAAO,CAAC;AACV;;;AC1GO,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,eAAY;AACZ,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,aAAU;AALA,SAAAA;AAAA,GAAA;;;ACAL,IAAK,kBAAL,kBAAKC,qBAAL;AACL,EAAAA,iBAAA,eAAY;AACZ,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,YAAS;AACT,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,YAAS;AAVC,SAAAA;AAAA,GAAA;;;ACAL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;;;ACAL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,YAAS;AADC,SAAAA;AAAA,GAAA;","names":["AgentType","MemoryType","UIComponentType","QueueType","ScheduleType"]}
1
+ {"version":3,"sources":["../src/AgentLatticeProtocol.ts","../src/MemoryLatticeProtocol.ts","../src/UILatticeProtocol.ts","../src/QueueLatticeProtocol.ts","../src/ScheduleLatticeProtocol.ts","../src/LoggerLatticeProtocol.ts"],"sourcesContent":["/**\n * AgentLatticeProtocol\n *\n * 智能体Lattice的协议,定义了智能体的行为和组合方式\n */\n\nimport { CompiledStateGraph } from \"@langchain/langgraph\";\nimport z, { ZodObject, ZodSchema } from \"zod\";\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 智能体类型枚举\n */\nexport enum AgentType {\n REACT = \"react\",\n DEEP_AGENT = \"deep_agent\",\n PLAN_EXECUTE = \"plan_execute\",\n SEQUENTIAL = \"sequential\",\n}\n\n/**\n * Runtime configuration that will be injected into LangGraphRunnableConfig.configurable\n * Tools can access these values via config.configurable.runConfig\n */\nexport interface AgentRunConfig {\n /** Database key for SQL tools (registered via sqlDatabaseManager) */\n databaseKey?: string;\n /** Any additional runtime configuration */\n [key: string]: any;\n}\n\n/**\n * Base agent configuration shared by all agent types\n */\ninterface BaseAgentConfig {\n key: string; // Unique key\n name: string; // Name\n description: string; // Description\n prompt: string; // Prompt\n schema?: ZodObject<any, any, any, any, any>; // Input validation schema\n modelKey?: string; // Model key to use\n /**\n * Runtime configuration to inject into tool execution context\n * Will be available in tools via config.configurable.runConfig\n */\n runConfig?: AgentRunConfig;\n}\n\n/**\n * REACT agent configuration\n */\nexport interface ReactAgentConfig extends BaseAgentConfig {\n type: AgentType.REACT;\n tools?: string[]; // Tool list\n}\n\n/**\n * DEEP_AGENT configuration - only this type supports subAgents\n */\nexport interface DeepAgentConfig extends BaseAgentConfig {\n type: AgentType.DEEP_AGENT;\n tools?: string[]; // Tool list\n subAgents?: string[]; // Sub-agent list (unique to DEEP_AGENT)\n internalSubAgents?: AgentConfig[]; // Internal sub-agent list (unique to DEEP_AGENT)\n}\n\n/**\n * PLAN_EXECUTE agent configuration\n */\nexport interface PlanExecuteAgentConfig extends BaseAgentConfig {\n type: AgentType.PLAN_EXECUTE;\n tools?: string[]; // Tool list\n}\n\n/**\n * SEQUENTIAL agent configuration\n */\nexport interface SequentialAgentConfig extends BaseAgentConfig {\n type: AgentType.SEQUENTIAL;\n}\n\n/**\n * Agent configuration union type\n * Different agent types have different configuration options\n */\nexport type AgentConfig =\n | ReactAgentConfig\n | DeepAgentConfig\n | PlanExecuteAgentConfig\n | SequentialAgentConfig;\n\n/**\n * Agent configuration with tools property\n */\nexport type AgentConfigWithTools =\n | ReactAgentConfig\n | DeepAgentConfig\n | PlanExecuteAgentConfig;\n\n/**\n * Type guard to check if config has tools property\n */\nexport function hasTools(config: AgentConfig): config is AgentConfigWithTools {\n return config.type !== AgentType.SEQUENTIAL;\n}\n\n/**\n * Type guard to check if config is DeepAgentConfig (has subAgents)\n */\nexport function isDeepAgentConfig(\n config: AgentConfig\n): config is DeepAgentConfig {\n return config.type === AgentType.DEEP_AGENT;\n}\n\n/**\n * Get tools from config safely\n */\nexport function getToolsFromConfig(config: AgentConfig): string[] {\n if (hasTools(config)) {\n return config.tools || [];\n }\n return [];\n}\n\n/**\n * Get subAgents from config safely (only DeepAgentConfig has subAgents)\n */\nexport function getSubAgentsFromConfig(config: AgentConfig): string[] {\n if (isDeepAgentConfig(config)) {\n return config.subAgents || [];\n }\n return [];\n}\n\n/**\n * 智能体客户端类型\n */\nexport type AgentClient = CompiledStateGraph<any, any, any, any, any>;\n\n/**\n * Graph构建选项\n */\nexport interface GraphBuildOptions {\n overrideTools?: string[];\n overrideModel?: string;\n metadata?: Record<string, any>;\n}\n\n/**\n * 智能体Lattice协议接口\n */\nexport interface AgentLatticeProtocol\n extends BaseLatticeProtocol<AgentConfig, AgentClient> {\n // 智能体执行函数\n invoke: (input: any, options?: any) => Promise<any>;\n\n // 构建智能体图\n buildGraph: (options?: GraphBuildOptions) => Promise<AgentClient>;\n}\n","/**\n * MemoryLatticeProtocol\n *\n * 记忆Lattice的协议,用于管理智能体的上下文和记忆\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 记忆类型枚举\n */\nexport enum MemoryType {\n SHORT_TERM = \"short_term\",\n LONG_TERM = \"long_term\",\n EPISODIC = \"episodic\",\n SEMANTIC = \"semantic\",\n WORKING = \"working\",\n}\n\n/**\n * 记忆配置接口\n */\nexport interface MemoryConfig {\n name: string; // 名称\n description: string; // 描述\n type: MemoryType; // 记忆类型\n ttl?: number; // 生存时间\n capacity?: number; // 容量限制\n}\n\n/**\n * 记忆客户端接口\n */\nexport interface MemoryClient {\n add: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n update: (key: string, value: any) => Promise<void>;\n delete: (key: string) => Promise<void>;\n search: (query: string, options?: any) => Promise<any[]>;\n clear: () => Promise<void>;\n}\n\n/**\n * 记忆Lattice协议接口\n */\nexport interface MemoryLatticeProtocol\n extends BaseLatticeProtocol<MemoryConfig, MemoryClient> {\n // 记忆操作方法\n add: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n update: (key: string, value: any) => Promise<void>;\n delete: (key: string) => Promise<void>;\n search: (query: string, options?: any) => Promise<any[]>;\n clear: () => Promise<void>;\n}\n","/**\n * UILatticeProtocol\n *\n * UI Lattice的协议,用于定义用户界面组件\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * UI组件类型枚举\n */\nexport enum UIComponentType {\n CONTAINER = \"container\",\n INPUT = \"input\",\n BUTTON = \"button\",\n LIST = \"list\",\n TABLE = \"table\",\n CHART = \"chart\",\n FORM = \"form\",\n CARD = \"card\",\n MODAL = \"modal\",\n CUSTOM = \"custom\",\n}\n\n/**\n * UI配置接口\n */\nexport interface UIConfig {\n name: string; // 组件名称\n description: string; // 组件描述\n type: UIComponentType; // 组件类型\n props?: Record<string, any>; // 组件属性\n children?: string[]; // 子组件列表\n}\n\n/**\n * UI组件接口\n * 使用泛型以适应不同的UI框架(React, Vue等)\n */\nexport interface UIComponent<T = any> {\n render: (props?: any) => T;\n addEventListener: (event: string, handler: Function) => void;\n removeEventListener: (event: string, handler: Function) => void;\n}\n\n/**\n * UI Lattice协议接口\n */\nexport interface UILatticeProtocol<T = any>\n extends BaseLatticeProtocol<UIConfig, UIComponent<T>> {\n // UI渲染方法\n render: (props?: any) => T;\n\n // 事件处理\n addEventListener: (event: string, handler: Function) => void;\n removeEventListener: (event: string, handler: Function) => void;\n}\n","/**\n * QueueLatticeProtocol\n *\n * Queue Lattice protocol for task queue management\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * Queue service type enumeration\n */\nexport enum QueueType {\n MEMORY = \"memory\",\n REDIS = \"redis\",\n}\n\n/**\n * Queue configuration interface\n */\nexport interface QueueConfig {\n name: string; // Queue name\n description: string; // Queue description\n type: QueueType; // Queue service type\n queueName?: string; // Specific queue name (e.g., \"tasks\")\n options?: Record<string, any>; // Additional options (e.g., Redis connection options)\n}\n\n/**\n * Queue operation result interface\n */\nexport interface QueueResult<T = any> {\n data: T | null;\n error: any | null;\n}\n\n/**\n * Queue client interface\n */\nexport interface QueueClient {\n push: (item: any) => Promise<QueueResult<number>>;\n pop: () => Promise<QueueResult<any>>;\n createQueue?: () => Promise<{ success: boolean; queue_name?: string; error?: any }>;\n}\n\n/**\n * Queue Lattice protocol interface\n */\nexport interface QueueLatticeProtocol\n extends BaseLatticeProtocol<QueueConfig, QueueClient> {\n // Queue operations\n push: (item: any) => Promise<QueueResult<number>>;\n pop: () => Promise<QueueResult<any>>;\n createQueue?: () => Promise<{ success: boolean; queue_name?: string; error?: any }>;\n}\n\n\n\n","/**\n * ScheduleLatticeProtocol\n *\n * Schedule Lattice protocol for delayed and recurring task execution management\n * Supports persistence and recovery after service restart\n * Supports both one-time delayed tasks and cron-style recurring tasks\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * Schedule service type enumeration\n */\nexport enum ScheduleType {\n MEMORY = \"memory\",\n POSTGRES = \"postgres\",\n REDIS = \"redis\",\n}\n\n/**\n * Schedule execution type - one-time or recurring\n */\nexport enum ScheduleExecutionType {\n ONCE = \"once\", // Execute once at specified time\n CRON = \"cron\", // Recurring based on cron expression\n}\n\n/**\n * Task status enumeration\n */\nexport enum ScheduledTaskStatus {\n PENDING = \"pending\", // Waiting to be executed\n RUNNING = \"running\", // Currently executing\n COMPLETED = \"completed\", // Successfully completed (for ONCE type)\n FAILED = \"failed\", // Execution failed\n CANCELLED = \"cancelled\", // Manually cancelled\n PAUSED = \"paused\", // Paused (for CRON type)\n}\n\n/**\n * Schedule configuration interface\n */\nexport interface ScheduleConfig {\n name: string;\n description: string;\n type: ScheduleType;\n storage?: ScheduleStorage; // Optional storage for persistence\n options?: Record<string, any>;\n}\n\n/**\n * Scheduled task definition - fully serializable\n * Supports both one-time and cron-style recurring tasks\n */\nexport interface ScheduledTaskDefinition {\n taskId: string;\n taskType: string; // Maps to a registered handler\n payload: Record<string, any>; // JSON-serializable data passed to handler\n\n // Context fields for querying\n assistantId?: string; // Which assistant created/owns this task\n threadId?: string; // Which thread this task belongs to\n\n // Execution configuration\n executionType: ScheduleExecutionType;\n\n // For ONCE type - execute at specific time or after delay\n executeAt?: number; // Timestamp when to execute\n delayMs?: number; // Original delay in milliseconds (for reference)\n\n // For CRON type - recurring schedule\n cronExpression?: string; // Cron format: \"0 9 * * *\" (min hour day month weekday)\n timezone?: string; // Timezone: \"Asia/Shanghai\", defaults to system timezone\n nextRunAt?: number; // Next calculated execution time\n lastRunAt?: number; // Last execution time\n\n // Execution tracking\n status: ScheduledTaskStatus;\n runCount: number; // How many times executed\n maxRuns?: number; // Max executions (null/undefined = infinite for cron, 1 for once)\n\n // Error handling\n retryCount: number; // Current retry count\n maxRetries: number; // Maximum retry attempts\n lastError?: string; // Last error message if failed\n\n // Timestamps\n createdAt: number;\n updatedAt: number;\n expiresAt?: number; // When to stop (for cron, optional)\n\n metadata?: Record<string, any>; // Additional metadata\n}\n\n/**\n * Task handler function type\n */\nexport type TaskHandler = (\n payload: Record<string, any>,\n taskInfo: ScheduledTaskDefinition\n) => void | Promise<void>;\n\n/**\n * Options for scheduling a one-time task\n */\nexport interface ScheduleOnceOptions {\n executeAt?: number; // Absolute timestamp to execute\n delayMs?: number; // OR relative delay from now\n maxRetries?: number; // Max retry attempts (default: 0)\n assistantId?: string; // Which assistant created/owns this task\n threadId?: string; // Which thread this task belongs to\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for scheduling a cron task\n */\nexport interface ScheduleCronOptions {\n cronExpression: string; // Cron expression: \"0 9 * * *\"\n timezone?: string; // Timezone: \"Asia/Shanghai\"\n maxRuns?: number; // Max executions (undefined = infinite)\n expiresAt?: number; // Stop after this timestamp\n maxRetries?: number; // Max retry attempts per run (default: 0)\n assistantId?: string; // Which assistant created/owns this task\n threadId?: string; // Which thread this task belongs to\n metadata?: Record<string, any>;\n}\n\n/**\n * Schedule storage interface for persistence\n */\nexport interface ScheduleStorage {\n /**\n * Save a new task\n */\n save(task: ScheduledTaskDefinition): Promise<void>;\n\n /**\n * Get task by ID\n */\n get(taskId: string): Promise<ScheduledTaskDefinition | null>;\n\n /**\n * Update task\n */\n update(\n taskId: string,\n updates: Partial<ScheduledTaskDefinition>\n ): Promise<void>;\n\n /**\n * Delete task\n */\n delete(taskId: string): Promise<void>;\n\n /**\n * Get all pending/active tasks (for recovery)\n * Returns tasks with status: PENDING or PAUSED\n */\n getActiveTasks(): Promise<ScheduledTaskDefinition[]>;\n\n /**\n * Get tasks by type\n */\n getTasksByType(taskType: string): Promise<ScheduledTaskDefinition[]>;\n\n /**\n * Get tasks by status\n */\n getTasksByStatus(\n status: ScheduledTaskStatus\n ): Promise<ScheduledTaskDefinition[]>;\n\n /**\n * Get tasks by execution type\n */\n getTasksByExecutionType(\n executionType: ScheduleExecutionType\n ): Promise<ScheduledTaskDefinition[]>;\n\n /**\n * Get tasks by assistant ID\n */\n getTasksByAssistantId(\n assistantId: string\n ): Promise<ScheduledTaskDefinition[]>;\n\n /**\n * Get tasks by thread ID\n */\n getTasksByThreadId(threadId: string): Promise<ScheduledTaskDefinition[]>;\n\n /**\n * Get all tasks (with optional filters)\n */\n getAllTasks(filters?: {\n status?: ScheduledTaskStatus;\n executionType?: ScheduleExecutionType;\n taskType?: string;\n assistantId?: string;\n threadId?: string;\n limit?: number;\n offset?: number;\n }): Promise<ScheduledTaskDefinition[]>;\n\n /**\n * Count tasks (with optional filters)\n */\n countTasks(filters?: {\n status?: ScheduledTaskStatus;\n executionType?: ScheduleExecutionType;\n taskType?: string;\n assistantId?: string;\n threadId?: string;\n }): Promise<number>;\n\n /**\n * Delete completed/cancelled tasks older than specified time\n * Useful for cleanup\n */\n deleteOldTasks(olderThanMs: number): Promise<number>;\n}\n\n/**\n * Schedule client interface\n */\nexport interface ScheduleClient {\n // ===== Handler Registration =====\n\n /**\n * Register a handler for a task type\n * Must be called before scheduling tasks of this type\n */\n registerHandler(taskType: string, handler: TaskHandler): void;\n\n /**\n * Unregister a handler\n */\n unregisterHandler(taskType: string): boolean;\n\n /**\n * Check if a handler is registered\n */\n hasHandler(taskType: string): boolean;\n\n /**\n * Get all registered handler types\n */\n getHandlerTypes(): string[];\n\n // ===== One-time Task Scheduling =====\n\n /**\n * Schedule a one-time task\n * @param taskId - Unique identifier for the task\n * @param taskType - Type of task (must have a registered handler)\n * @param payload - Data to pass to the handler (must be JSON-serializable)\n * @param options - Execution options (executeAt or delayMs required)\n */\n scheduleOnce(\n taskId: string,\n taskType: string,\n payload: Record<string, any>,\n options: ScheduleOnceOptions\n ): Promise<boolean>;\n\n // ===== Cron Task Scheduling =====\n\n /**\n * Schedule a recurring cron task\n * @param taskId - Unique identifier for the task\n * @param taskType - Type of task (must have a registered handler)\n * @param payload - Data to pass to the handler (must be JSON-serializable)\n * @param options - Cron options (cronExpression required)\n */\n scheduleCron(\n taskId: string,\n taskType: string,\n payload: Record<string, any>,\n options: ScheduleCronOptions\n ): Promise<boolean>;\n\n // ===== Task Management =====\n\n /**\n * Cancel a scheduled task\n */\n cancel(taskId: string): Promise<boolean>;\n\n /**\n * Pause a cron task (only for CRON type)\n */\n pause(taskId: string): Promise<boolean>;\n\n /**\n * Resume a paused cron task (only for CRON type)\n */\n resume(taskId: string): Promise<boolean>;\n\n /**\n * Check if a task exists\n */\n has(taskId: string): Promise<boolean>;\n\n /**\n * Get task information\n */\n getTask(taskId: string): Promise<ScheduledTaskDefinition | null>;\n\n /**\n * Get remaining time until next execution\n * Returns -1 if task not found or already executed\n */\n getRemainingTime(taskId: string): Promise<number>;\n\n /**\n * Get count of active tasks (pending + paused)\n */\n getActiveTaskCount(): Promise<number>;\n\n /**\n * Get all active task IDs\n */\n getActiveTaskIds(): Promise<string[]>;\n\n /**\n * Cancel all active tasks\n */\n cancelAll(): Promise<void>;\n\n // ===== Recovery =====\n\n /**\n * Restore active tasks from storage (call on service startup)\n * Re-schedules all pending tasks with their remaining time\n * Re-schedules all cron tasks for their next run\n * @returns Number of tasks restored\n */\n restore(): Promise<number>;\n\n // ===== Storage =====\n\n /**\n * Set the storage backend\n */\n setStorage(storage: ScheduleStorage): void;\n\n /**\n * Get current storage backend\n */\n getStorage(): ScheduleStorage | null;\n}\n\n/**\n * Schedule Lattice protocol interface\n */\nexport interface ScheduleLatticeProtocol\n extends BaseLatticeProtocol<ScheduleConfig, ScheduleClient> {\n // Handler registration\n registerHandler: (taskType: string, handler: TaskHandler) => void;\n unregisterHandler: (taskType: string) => boolean;\n hasHandler: (taskType: string) => boolean;\n getHandlerTypes: () => string[];\n\n // One-time task scheduling\n scheduleOnce: (\n taskId: string,\n taskType: string,\n payload: Record<string, any>,\n options: ScheduleOnceOptions\n ) => Promise<boolean>;\n\n // Cron task scheduling\n scheduleCron: (\n taskId: string,\n taskType: string,\n payload: Record<string, any>,\n options: ScheduleCronOptions\n ) => Promise<boolean>;\n\n // Task management\n cancel: (taskId: string) => Promise<boolean>;\n pause: (taskId: string) => Promise<boolean>;\n resume: (taskId: string) => Promise<boolean>;\n has: (taskId: string) => Promise<boolean>;\n getTask: (taskId: string) => Promise<ScheduledTaskDefinition | null>;\n getRemainingTime: (taskId: string) => Promise<number>;\n getActiveTaskCount: () => Promise<number>;\n getActiveTaskIds: () => Promise<string[]>;\n cancelAll: () => Promise<void>;\n\n // Recovery\n restore: () => Promise<number>;\n}\n","/**\n * LoggerLatticeProtocol\n *\n * Logger Lattice protocol for logging management\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * Logger service type enumeration\n */\nexport enum LoggerType {\n PINO = \"pino\",\n CONSOLE = \"console\",\n CUSTOM = \"custom\",\n}\n\n/**\n * Logger context interface\n */\nexport interface LoggerContext {\n \"x-user-id\"?: string;\n \"x-tenant-id\"?: string;\n \"x-request-id\"?: string;\n \"x-task-id\"?: string;\n \"x-thread-id\"?: string;\n [key: string]: any;\n}\n\n/**\n * Pino logger file transport options\n */\nexport interface PinoFileOptions {\n file?: string; // Log file path (e.g., \"./logs/app.log\" or \"./logs/app\")\n frequency?: \"daily\" | \"hourly\" | \"minutely\" | string; // Log rotation frequency\n mkdir?: boolean; // Create directory if not exists\n size?: string; // Max file size (e.g., \"10M\", \"100K\")\n maxFiles?: number; // Maximum number of log files to keep\n}\n\n/**\n * Logger configuration interface\n */\nexport interface LoggerConfig {\n name: string; // Logger name\n description?: string; // Logger description\n type: LoggerType; // Logger service type\n serviceName?: string; // Service name (e.g., \"lattice-gateway\")\n loggerName?: string; // Logger instance name (e.g., \"fastify-server\")\n context?: LoggerContext; // Initial context\n // File logging options (for PINO type)\n file?: string | PinoFileOptions; // Log file path or detailed file options\n // Additional options (e.g., pino config, custom logger settings)\n options?: Record<string, any>;\n}\n\n/**\n * Logger client interface\n */\nexport interface LoggerClient {\n info: (msg: string, obj?: object) => void;\n error: (msg: string, obj?: object | Error) => void;\n warn: (msg: string, obj?: object) => void;\n debug: (msg: string, obj?: object) => void;\n updateContext?: (context: Partial<LoggerContext>) => void;\n child?: (options: Partial<LoggerConfig>) => LoggerClient;\n}\n\n/**\n * Logger Lattice protocol interface\n */\nexport interface LoggerLatticeProtocol\n extends BaseLatticeProtocol<LoggerConfig, LoggerClient> {\n // Logger operations\n info: (msg: string, obj?: object) => void;\n error: (msg: string, obj?: object | Error) => void;\n warn: (msg: string, obj?: object) => void;\n debug: (msg: string, obj?: object) => void;\n updateContext?: (context: Partial<LoggerContext>) => void;\n child?: (options: Partial<LoggerConfig>) => LoggerClient;\n}\n"],"mappings":";AAaO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,gBAAa;AACb,EAAAA,WAAA,kBAAe;AACf,EAAAA,WAAA,gBAAa;AAJH,SAAAA;AAAA,GAAA;AAyFL,SAAS,SAAS,QAAqD;AAC5E,SAAO,OAAO,SAAS;AACzB;AAKO,SAAS,kBACd,QAC2B;AAC3B,SAAO,OAAO,SAAS;AACzB;AAKO,SAAS,mBAAmB,QAA+B;AAChE,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO,OAAO,SAAS,CAAC;AAAA,EAC1B;AACA,SAAO,CAAC;AACV;AAKO,SAAS,uBAAuB,QAA+B;AACpE,MAAI,kBAAkB,MAAM,GAAG;AAC7B,WAAO,OAAO,aAAa,CAAC;AAAA,EAC9B;AACA,SAAO,CAAC;AACV;;;AC1HO,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,eAAY;AACZ,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,aAAU;AALA,SAAAA;AAAA,GAAA;;;ACAL,IAAK,kBAAL,kBAAKC,qBAAL;AACL,EAAAA,iBAAA,eAAY;AACZ,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,YAAS;AACT,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,YAAS;AAVC,SAAAA;AAAA,GAAA;;;ACAL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,YAAS;AACT,EAAAA,WAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;;;ACEL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,YAAS;AACT,EAAAA,cAAA,cAAW;AACX,EAAAA,cAAA,WAAQ;AAHE,SAAAA;AAAA,GAAA;AASL,IAAK,wBAAL,kBAAKC,2BAAL;AACL,EAAAA,uBAAA,UAAO;AACP,EAAAA,uBAAA,UAAO;AAFG,SAAAA;AAAA,GAAA;AAQL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,aAAU;AACV,EAAAA,qBAAA,aAAU;AACV,EAAAA,qBAAA,eAAY;AACZ,EAAAA,qBAAA,YAAS;AACT,EAAAA,qBAAA,eAAY;AACZ,EAAAA,qBAAA,YAAS;AANC,SAAAA;AAAA,GAAA;;;ACnBL,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,YAAS;AAHC,SAAAA;AAAA,GAAA;","names":["AgentType","MemoryType","UIComponentType","QueueType","ScheduleType","ScheduleExecutionType","ScheduledTaskStatus","LoggerType"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiom-lattice/protocols",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "description": "Unified protocol type definitions for Axiom Lattice framework",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -18,6 +18,17 @@ export enum AgentType {
18
18
  SEQUENTIAL = "sequential",
19
19
  }
20
20
 
21
+ /**
22
+ * Runtime configuration that will be injected into LangGraphRunnableConfig.configurable
23
+ * Tools can access these values via config.configurable.runConfig
24
+ */
25
+ export interface AgentRunConfig {
26
+ /** Database key for SQL tools (registered via sqlDatabaseManager) */
27
+ databaseKey?: string;
28
+ /** Any additional runtime configuration */
29
+ [key: string]: any;
30
+ }
31
+
21
32
  /**
22
33
  * Base agent configuration shared by all agent types
23
34
  */
@@ -28,6 +39,11 @@ interface BaseAgentConfig {
28
39
  prompt: string; // Prompt
29
40
  schema?: ZodObject<any, any, any, any, any>; // Input validation schema
30
41
  modelKey?: string; // Model key to use
42
+ /**
43
+ * Runtime configuration to inject into tool execution context
44
+ * Will be available in tools via config.configurable.runConfig
45
+ */
46
+ runConfig?: AgentRunConfig;
31
47
  }
32
48
 
33
49
  /**
@@ -0,0 +1,81 @@
1
+ /**
2
+ * LoggerLatticeProtocol
3
+ *
4
+ * Logger Lattice protocol for logging management
5
+ */
6
+
7
+ import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
8
+
9
+ /**
10
+ * Logger service type enumeration
11
+ */
12
+ export enum LoggerType {
13
+ PINO = "pino",
14
+ CONSOLE = "console",
15
+ CUSTOM = "custom",
16
+ }
17
+
18
+ /**
19
+ * Logger context interface
20
+ */
21
+ export interface LoggerContext {
22
+ "x-user-id"?: string;
23
+ "x-tenant-id"?: string;
24
+ "x-request-id"?: string;
25
+ "x-task-id"?: string;
26
+ "x-thread-id"?: string;
27
+ [key: string]: any;
28
+ }
29
+
30
+ /**
31
+ * Pino logger file transport options
32
+ */
33
+ export interface PinoFileOptions {
34
+ file?: string; // Log file path (e.g., "./logs/app.log" or "./logs/app")
35
+ frequency?: "daily" | "hourly" | "minutely" | string; // Log rotation frequency
36
+ mkdir?: boolean; // Create directory if not exists
37
+ size?: string; // Max file size (e.g., "10M", "100K")
38
+ maxFiles?: number; // Maximum number of log files to keep
39
+ }
40
+
41
+ /**
42
+ * Logger configuration interface
43
+ */
44
+ export interface LoggerConfig {
45
+ name: string; // Logger name
46
+ description?: string; // Logger description
47
+ type: LoggerType; // Logger service type
48
+ serviceName?: string; // Service name (e.g., "lattice-gateway")
49
+ loggerName?: string; // Logger instance name (e.g., "fastify-server")
50
+ context?: LoggerContext; // Initial context
51
+ // File logging options (for PINO type)
52
+ file?: string | PinoFileOptions; // Log file path or detailed file options
53
+ // Additional options (e.g., pino config, custom logger settings)
54
+ options?: Record<string, any>;
55
+ }
56
+
57
+ /**
58
+ * Logger client interface
59
+ */
60
+ export interface LoggerClient {
61
+ info: (msg: string, obj?: object) => void;
62
+ error: (msg: string, obj?: object | Error) => void;
63
+ warn: (msg: string, obj?: object) => void;
64
+ debug: (msg: string, obj?: object) => void;
65
+ updateContext?: (context: Partial<LoggerContext>) => void;
66
+ child?: (options: Partial<LoggerConfig>) => LoggerClient;
67
+ }
68
+
69
+ /**
70
+ * Logger Lattice protocol interface
71
+ */
72
+ export interface LoggerLatticeProtocol
73
+ extends BaseLatticeProtocol<LoggerConfig, LoggerClient> {
74
+ // Logger operations
75
+ info: (msg: string, obj?: object) => void;
76
+ error: (msg: string, obj?: object | Error) => void;
77
+ warn: (msg: string, obj?: object) => void;
78
+ debug: (msg: string, obj?: object) => void;
79
+ updateContext?: (context: Partial<LoggerContext>) => void;
80
+ child?: (options: Partial<LoggerConfig>) => LoggerClient;
81
+ }
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * ScheduleLatticeProtocol
3
3
  *
4
- * Schedule Lattice protocol for delayed task execution management
4
+ * Schedule Lattice protocol for delayed and recurring task execution management
5
+ * Supports persistence and recovery after service restart
6
+ * Supports both one-time delayed tasks and cron-style recurring tasks
5
7
  */
6
8
 
7
9
  import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
@@ -11,87 +13,342 @@ import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
11
13
  */
12
14
  export enum ScheduleType {
13
15
  MEMORY = "memory",
14
- // Future implementations can add more types like REDIS, DATABASE, etc.
16
+ POSTGRES = "postgres",
17
+ REDIS = "redis",
18
+ }
19
+
20
+ /**
21
+ * Schedule execution type - one-time or recurring
22
+ */
23
+ export enum ScheduleExecutionType {
24
+ ONCE = "once", // Execute once at specified time
25
+ CRON = "cron", // Recurring based on cron expression
26
+ }
27
+
28
+ /**
29
+ * Task status enumeration
30
+ */
31
+ export enum ScheduledTaskStatus {
32
+ PENDING = "pending", // Waiting to be executed
33
+ RUNNING = "running", // Currently executing
34
+ COMPLETED = "completed", // Successfully completed (for ONCE type)
35
+ FAILED = "failed", // Execution failed
36
+ CANCELLED = "cancelled", // Manually cancelled
37
+ PAUSED = "paused", // Paused (for CRON type)
15
38
  }
16
39
 
17
40
  /**
18
41
  * Schedule configuration interface
19
42
  */
20
43
  export interface ScheduleConfig {
21
- name: string; // Schedule name
22
- description: string; // Schedule description
23
- type: ScheduleType; // Schedule service type
24
- options?: Record<string, any>; // Additional options
44
+ name: string;
45
+ description: string;
46
+ type: ScheduleType;
47
+ storage?: ScheduleStorage; // Optional storage for persistence
48
+ options?: Record<string, any>;
25
49
  }
26
50
 
27
51
  /**
28
- * Scheduled task information interface
52
+ * Scheduled task definition - fully serializable
53
+ * Supports both one-time and cron-style recurring tasks
29
54
  */
30
- export interface ScheduledTaskInfo {
55
+ export interface ScheduledTaskDefinition {
31
56
  taskId: string;
32
- scheduledAt: number;
33
- timeoutMs: number;
34
- remainingMs: number;
57
+ taskType: string; // Maps to a registered handler
58
+ payload: Record<string, any>; // JSON-serializable data passed to handler
59
+
60
+ // Context fields for querying
61
+ assistantId?: string; // Which assistant created/owns this task
62
+ threadId?: string; // Which thread this task belongs to
63
+
64
+ // Execution configuration
65
+ executionType: ScheduleExecutionType;
66
+
67
+ // For ONCE type - execute at specific time or after delay
68
+ executeAt?: number; // Timestamp when to execute
69
+ delayMs?: number; // Original delay in milliseconds (for reference)
70
+
71
+ // For CRON type - recurring schedule
72
+ cronExpression?: string; // Cron format: "0 9 * * *" (min hour day month weekday)
73
+ timezone?: string; // Timezone: "Asia/Shanghai", defaults to system timezone
74
+ nextRunAt?: number; // Next calculated execution time
75
+ lastRunAt?: number; // Last execution time
76
+
77
+ // Execution tracking
78
+ status: ScheduledTaskStatus;
79
+ runCount: number; // How many times executed
80
+ maxRuns?: number; // Max executions (null/undefined = infinite for cron, 1 for once)
81
+
82
+ // Error handling
83
+ retryCount: number; // Current retry count
84
+ maxRetries: number; // Maximum retry attempts
85
+ lastError?: string; // Last error message if failed
86
+
87
+ // Timestamps
88
+ createdAt: number;
89
+ updatedAt: number;
90
+ expiresAt?: number; // When to stop (for cron, optional)
91
+
92
+ metadata?: Record<string, any>; // Additional metadata
93
+ }
94
+
95
+ /**
96
+ * Task handler function type
97
+ */
98
+ export type TaskHandler = (
99
+ payload: Record<string, any>,
100
+ taskInfo: ScheduledTaskDefinition
101
+ ) => void | Promise<void>;
102
+
103
+ /**
104
+ * Options for scheduling a one-time task
105
+ */
106
+ export interface ScheduleOnceOptions {
107
+ executeAt?: number; // Absolute timestamp to execute
108
+ delayMs?: number; // OR relative delay from now
109
+ maxRetries?: number; // Max retry attempts (default: 0)
110
+ assistantId?: string; // Which assistant created/owns this task
111
+ threadId?: string; // Which thread this task belongs to
112
+ metadata?: Record<string, any>;
113
+ }
114
+
115
+ /**
116
+ * Options for scheduling a cron task
117
+ */
118
+ export interface ScheduleCronOptions {
119
+ cronExpression: string; // Cron expression: "0 9 * * *"
120
+ timezone?: string; // Timezone: "Asia/Shanghai"
121
+ maxRuns?: number; // Max executions (undefined = infinite)
122
+ expiresAt?: number; // Stop after this timestamp
123
+ maxRetries?: number; // Max retry attempts per run (default: 0)
124
+ assistantId?: string; // Which assistant created/owns this task
125
+ threadId?: string; // Which thread this task belongs to
126
+ metadata?: Record<string, any>;
127
+ }
128
+
129
+ /**
130
+ * Schedule storage interface for persistence
131
+ */
132
+ export interface ScheduleStorage {
133
+ /**
134
+ * Save a new task
135
+ */
136
+ save(task: ScheduledTaskDefinition): Promise<void>;
137
+
138
+ /**
139
+ * Get task by ID
140
+ */
141
+ get(taskId: string): Promise<ScheduledTaskDefinition | null>;
142
+
143
+ /**
144
+ * Update task
145
+ */
146
+ update(
147
+ taskId: string,
148
+ updates: Partial<ScheduledTaskDefinition>
149
+ ): Promise<void>;
150
+
151
+ /**
152
+ * Delete task
153
+ */
154
+ delete(taskId: string): Promise<void>;
155
+
156
+ /**
157
+ * Get all pending/active tasks (for recovery)
158
+ * Returns tasks with status: PENDING or PAUSED
159
+ */
160
+ getActiveTasks(): Promise<ScheduledTaskDefinition[]>;
161
+
162
+ /**
163
+ * Get tasks by type
164
+ */
165
+ getTasksByType(taskType: string): Promise<ScheduledTaskDefinition[]>;
166
+
167
+ /**
168
+ * Get tasks by status
169
+ */
170
+ getTasksByStatus(
171
+ status: ScheduledTaskStatus
172
+ ): Promise<ScheduledTaskDefinition[]>;
173
+
174
+ /**
175
+ * Get tasks by execution type
176
+ */
177
+ getTasksByExecutionType(
178
+ executionType: ScheduleExecutionType
179
+ ): Promise<ScheduledTaskDefinition[]>;
180
+
181
+ /**
182
+ * Get tasks by assistant ID
183
+ */
184
+ getTasksByAssistantId(
185
+ assistantId: string
186
+ ): Promise<ScheduledTaskDefinition[]>;
187
+
188
+ /**
189
+ * Get tasks by thread ID
190
+ */
191
+ getTasksByThreadId(threadId: string): Promise<ScheduledTaskDefinition[]>;
192
+
193
+ /**
194
+ * Get all tasks (with optional filters)
195
+ */
196
+ getAllTasks(filters?: {
197
+ status?: ScheduledTaskStatus;
198
+ executionType?: ScheduleExecutionType;
199
+ taskType?: string;
200
+ assistantId?: string;
201
+ threadId?: string;
202
+ limit?: number;
203
+ offset?: number;
204
+ }): Promise<ScheduledTaskDefinition[]>;
205
+
206
+ /**
207
+ * Count tasks (with optional filters)
208
+ */
209
+ countTasks(filters?: {
210
+ status?: ScheduledTaskStatus;
211
+ executionType?: ScheduleExecutionType;
212
+ taskType?: string;
213
+ assistantId?: string;
214
+ threadId?: string;
215
+ }): Promise<number>;
216
+
217
+ /**
218
+ * Delete completed/cancelled tasks older than specified time
219
+ * Useful for cleanup
220
+ */
221
+ deleteOldTasks(olderThanMs: number): Promise<number>;
35
222
  }
36
223
 
37
224
  /**
38
225
  * Schedule client interface
39
226
  */
40
227
  export interface ScheduleClient {
228
+ // ===== Handler Registration =====
229
+
41
230
  /**
42
- * Register a function to be executed after the specified timeout
231
+ * Register a handler for a task type
232
+ * Must be called before scheduling tasks of this type
233
+ */
234
+ registerHandler(taskType: string, handler: TaskHandler): void;
235
+
236
+ /**
237
+ * Unregister a handler
238
+ */
239
+ unregisterHandler(taskType: string): boolean;
240
+
241
+ /**
242
+ * Check if a handler is registered
243
+ */
244
+ hasHandler(taskType: string): boolean;
245
+
246
+ /**
247
+ * Get all registered handler types
248
+ */
249
+ getHandlerTypes(): string[];
250
+
251
+ // ===== One-time Task Scheduling =====
252
+
253
+ /**
254
+ * Schedule a one-time task
43
255
  * @param taskId - Unique identifier for the task
44
- * @param callback - Function to execute when timeout expires
45
- * @param timeoutMs - Delay in milliseconds before execution
46
- * @returns true if registered successfully
256
+ * @param taskType - Type of task (must have a registered handler)
257
+ * @param payload - Data to pass to the handler (must be JSON-serializable)
258
+ * @param options - Execution options (executeAt or delayMs required)
47
259
  */
48
- register: (
260
+ scheduleOnce(
49
261
  taskId: string,
50
- callback: () => void | Promise<void>,
51
- timeoutMs: number
52
- ) => boolean;
262
+ taskType: string,
263
+ payload: Record<string, any>,
264
+ options: ScheduleOnceOptions
265
+ ): Promise<boolean>;
266
+
267
+ // ===== Cron Task Scheduling =====
53
268
 
54
269
  /**
55
- * Cancel a scheduled task by its ID
56
- * @param taskId - The task identifier to cancel
57
- * @returns true if task was found and cancelled, false otherwise
270
+ * Schedule a recurring cron task
271
+ * @param taskId - Unique identifier for the task
272
+ * @param taskType - Type of task (must have a registered handler)
273
+ * @param payload - Data to pass to the handler (must be JSON-serializable)
274
+ * @param options - Cron options (cronExpression required)
58
275
  */
59
- cancel: (taskId: string) => boolean;
276
+ scheduleCron(
277
+ taskId: string,
278
+ taskType: string,
279
+ payload: Record<string, any>,
280
+ options: ScheduleCronOptions
281
+ ): Promise<boolean>;
282
+
283
+ // ===== Task Management =====
60
284
 
61
285
  /**
62
- * Check if a task is currently scheduled
63
- * @param taskId - The task identifier to check
286
+ * Cancel a scheduled task
64
287
  */
65
- has: (taskId: string) => boolean;
288
+ cancel(taskId: string): Promise<boolean>;
66
289
 
67
290
  /**
68
- * Get the remaining time in milliseconds for a scheduled task
69
- * @param taskId - The task identifier
70
- * @returns Remaining time in ms, or -1 if task not found
291
+ * Pause a cron task (only for CRON type)
71
292
  */
72
- getRemainingTime: (taskId: string) => number;
293
+ pause(taskId: string): Promise<boolean>;
73
294
 
74
295
  /**
75
- * Get the count of currently scheduled tasks
296
+ * Resume a paused cron task (only for CRON type)
76
297
  */
77
- getTaskCount: () => number;
298
+ resume(taskId: string): Promise<boolean>;
78
299
 
79
300
  /**
80
- * Get all scheduled task IDs
301
+ * Check if a task exists
81
302
  */
82
- getTaskIds: () => string[];
303
+ has(taskId: string): Promise<boolean>;
83
304
 
84
305
  /**
85
- * Cancel all scheduled tasks
306
+ * Get task information
86
307
  */
87
- cancelAll: () => void;
308
+ getTask(taskId: string): Promise<ScheduledTaskDefinition | null>;
88
309
 
89
310
  /**
90
- * Get task information
91
- * @param taskId - The task identifier
92
- * @returns Task info or null if not found
311
+ * Get remaining time until next execution
312
+ * Returns -1 if task not found or already executed
313
+ */
314
+ getRemainingTime(taskId: string): Promise<number>;
315
+
316
+ /**
317
+ * Get count of active tasks (pending + paused)
318
+ */
319
+ getActiveTaskCount(): Promise<number>;
320
+
321
+ /**
322
+ * Get all active task IDs
323
+ */
324
+ getActiveTaskIds(): Promise<string[]>;
325
+
326
+ /**
327
+ * Cancel all active tasks
328
+ */
329
+ cancelAll(): Promise<void>;
330
+
331
+ // ===== Recovery =====
332
+
333
+ /**
334
+ * Restore active tasks from storage (call on service startup)
335
+ * Re-schedules all pending tasks with their remaining time
336
+ * Re-schedules all cron tasks for their next run
337
+ * @returns Number of tasks restored
338
+ */
339
+ restore(): Promise<number>;
340
+
341
+ // ===== Storage =====
342
+
343
+ /**
344
+ * Set the storage backend
345
+ */
346
+ setStorage(storage: ScheduleStorage): void;
347
+
348
+ /**
349
+ * Get current storage backend
93
350
  */
94
- getTaskInfo?: (taskId: string) => ScheduledTaskInfo | null;
351
+ getStorage(): ScheduleStorage | null;
95
352
  }
96
353
 
97
354
  /**
@@ -99,17 +356,39 @@ export interface ScheduleClient {
99
356
  */
100
357
  export interface ScheduleLatticeProtocol
101
358
  extends BaseLatticeProtocol<ScheduleConfig, ScheduleClient> {
102
- // Schedule operations
103
- register: (
359
+ // Handler registration
360
+ registerHandler: (taskType: string, handler: TaskHandler) => void;
361
+ unregisterHandler: (taskType: string) => boolean;
362
+ hasHandler: (taskType: string) => boolean;
363
+ getHandlerTypes: () => string[];
364
+
365
+ // One-time task scheduling
366
+ scheduleOnce: (
104
367
  taskId: string,
105
- callback: () => void | Promise<void>,
106
- timeoutMs: number
107
- ) => boolean;
108
- cancel: (taskId: string) => boolean;
109
- has: (taskId: string) => boolean;
110
- getRemainingTime: (taskId: string) => number;
111
- getTaskCount: () => number;
112
- getTaskIds: () => string[];
113
- cancelAll: () => void;
114
- getTaskInfo?: (taskId: string) => ScheduledTaskInfo | null;
368
+ taskType: string,
369
+ payload: Record<string, any>,
370
+ options: ScheduleOnceOptions
371
+ ) => Promise<boolean>;
372
+
373
+ // Cron task scheduling
374
+ scheduleCron: (
375
+ taskId: string,
376
+ taskType: string,
377
+ payload: Record<string, any>,
378
+ options: ScheduleCronOptions
379
+ ) => Promise<boolean>;
380
+
381
+ // Task management
382
+ cancel: (taskId: string) => Promise<boolean>;
383
+ pause: (taskId: string) => Promise<boolean>;
384
+ resume: (taskId: string) => Promise<boolean>;
385
+ has: (taskId: string) => Promise<boolean>;
386
+ getTask: (taskId: string) => Promise<ScheduledTaskDefinition | null>;
387
+ getRemainingTime: (taskId: string) => Promise<number>;
388
+ getActiveTaskCount: () => Promise<number>;
389
+ getActiveTaskIds: () => Promise<string[]>;
390
+ cancelAll: () => Promise<void>;
391
+
392
+ // Recovery
393
+ restore: () => Promise<number>;
115
394
  }
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ export * from "./QueueLatticeProtocol";
14
14
  export * from "./ScheduleLatticeProtocol";
15
15
  export * from "./EmbeddingsLatticeProtocol";
16
16
  export * from "./VectorStoreLatticeProtocol";
17
+ export * from "./LoggerLatticeProtocol";
17
18
  export * from "./MessageProtocol";
18
19
  export * from "./ThreadStoreProtocol";
19
20
  export * from "./AssistantStoreProtocol";