@axiom-lattice/protocols 2.1.8 → 2.1.10
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.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +292 -19
- package/dist/index.d.ts +292 -19
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AgentLatticeProtocol.ts +4 -19
- package/src/LoggerLatticeProtocol.ts +81 -0
- package/src/SkillLatticeProtocol.ts +66 -0
- package/src/SkillStoreProtocol.ts +193 -0
- package/src/index.ts +3 -0
package/dist/index.mjs.map
CHANGED
|
@@ -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 * 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"],"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;","names":["AgentType","MemoryType","UIComponentType","QueueType","ScheduleType","ScheduleExecutionType","ScheduledTaskStatus"]}
|
|
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\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 skillCategories?: string[];\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\n/**\n * Agent configuration union type\n * Different agent types have different configuration options\n */\nexport type AgentConfig =\n | ReactAgentConfig\n | DeepAgentConfig\n\n\n/**\n * Agent configuration with tools property\n */\nexport type AgentConfigWithTools =\n | ReactAgentConfig\n | DeepAgentConfig\n\n/**\n * Type guard to check if config has tools property\n */\nexport function hasTools(config: AgentConfig): config is AgentConfigWithTools {\n return true\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;AAFH,SAAAA;AAAA,GAAA;AA0EL,SAAS,SAAS,QAAqD;AAC5E,SAAO;AACT;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;;;AC3GO,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
|
@@ -14,8 +14,7 @@ import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
|
|
|
14
14
|
export enum AgentType {
|
|
15
15
|
REACT = "react",
|
|
16
16
|
DEEP_AGENT = "deep_agent",
|
|
17
|
-
|
|
18
|
-
SEQUENTIAL = "sequential",
|
|
17
|
+
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
/**
|
|
@@ -44,6 +43,7 @@ interface BaseAgentConfig {
|
|
|
44
43
|
* Will be available in tools via config.configurable.runConfig
|
|
45
44
|
*/
|
|
46
45
|
runConfig?: AgentRunConfig;
|
|
46
|
+
skillCategories?: string[];
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
@@ -64,20 +64,7 @@ export interface DeepAgentConfig extends BaseAgentConfig {
|
|
|
64
64
|
internalSubAgents?: AgentConfig[]; // Internal sub-agent list (unique to DEEP_AGENT)
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/**
|
|
68
|
-
* PLAN_EXECUTE agent configuration
|
|
69
|
-
*/
|
|
70
|
-
export interface PlanExecuteAgentConfig extends BaseAgentConfig {
|
|
71
|
-
type: AgentType.PLAN_EXECUTE;
|
|
72
|
-
tools?: string[]; // Tool list
|
|
73
|
-
}
|
|
74
67
|
|
|
75
|
-
/**
|
|
76
|
-
* SEQUENTIAL agent configuration
|
|
77
|
-
*/
|
|
78
|
-
export interface SequentialAgentConfig extends BaseAgentConfig {
|
|
79
|
-
type: AgentType.SEQUENTIAL;
|
|
80
|
-
}
|
|
81
68
|
|
|
82
69
|
/**
|
|
83
70
|
* Agent configuration union type
|
|
@@ -86,8 +73,7 @@ export interface SequentialAgentConfig extends BaseAgentConfig {
|
|
|
86
73
|
export type AgentConfig =
|
|
87
74
|
| ReactAgentConfig
|
|
88
75
|
| DeepAgentConfig
|
|
89
|
-
|
|
90
|
-
| SequentialAgentConfig;
|
|
76
|
+
|
|
91
77
|
|
|
92
78
|
/**
|
|
93
79
|
* Agent configuration with tools property
|
|
@@ -95,13 +81,12 @@ export type AgentConfig =
|
|
|
95
81
|
export type AgentConfigWithTools =
|
|
96
82
|
| ReactAgentConfig
|
|
97
83
|
| DeepAgentConfig
|
|
98
|
-
| PlanExecuteAgentConfig;
|
|
99
84
|
|
|
100
85
|
/**
|
|
101
86
|
* Type guard to check if config has tools property
|
|
102
87
|
*/
|
|
103
88
|
export function hasTools(config: AgentConfig): config is AgentConfigWithTools {
|
|
104
|
-
return
|
|
89
|
+
return true
|
|
105
90
|
}
|
|
106
91
|
|
|
107
92
|
/**
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillLatticeProtocol
|
|
3
|
+
*
|
|
4
|
+
* Skill Lattice protocol for defining reusable skill components
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
|
|
8
|
+
import { SkillStore } from "./SkillStoreProtocol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Skill configuration interface
|
|
12
|
+
*/
|
|
13
|
+
export interface SkillConfig {
|
|
14
|
+
/** Skill name (required) */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Skill description (required) */
|
|
17
|
+
description: string;
|
|
18
|
+
/** License information (optional) */
|
|
19
|
+
license?: string;
|
|
20
|
+
/** Compatibility information (optional) */
|
|
21
|
+
compatibility?: string;
|
|
22
|
+
/** Additional metadata as string-to-string map (optional) */
|
|
23
|
+
metadata?: Record<string, string>;
|
|
24
|
+
/** Skill detailed content description (optional) */
|
|
25
|
+
content?: string;
|
|
26
|
+
/** Sub-skills (optional) - Array of skill names that are sub-skills of this skill */
|
|
27
|
+
subSkills?: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Skill client interface
|
|
32
|
+
* Clients can optionally implement setStore to receive store access
|
|
33
|
+
* Supports both interface implementation and any type for backward compatibility
|
|
34
|
+
*/
|
|
35
|
+
export interface SkillClient {
|
|
36
|
+
/**
|
|
37
|
+
* Optional method to set the store instance
|
|
38
|
+
* Called by SkillLatticeManager when registering a skill
|
|
39
|
+
*/
|
|
40
|
+
setStore?: (store: SkillStore) => void;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Optional store property
|
|
44
|
+
* Can be set directly or via setStore method
|
|
45
|
+
*/
|
|
46
|
+
store?: SkillStore;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Additional client-specific properties and methods
|
|
50
|
+
*/
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Skill client type (supports both interface and any for backward compatibility)
|
|
56
|
+
*/
|
|
57
|
+
export type SkillClientType = SkillClient | any;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Skill Lattice protocol interface
|
|
61
|
+
*/
|
|
62
|
+
export interface SkillLatticeProtocol
|
|
63
|
+
extends BaseLatticeProtocol<SkillConfig, SkillClientType> {
|
|
64
|
+
// Skill execution function
|
|
65
|
+
execute?: (input: any, config?: any) => Promise<any>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillStoreProtocol
|
|
3
|
+
*
|
|
4
|
+
* Skill store protocol definitions for the Axiom Lattice framework
|
|
5
|
+
* Provides standardized interfaces for skill management across all implementations
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { SkillConfig } from "./SkillLatticeProtocol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Skill type definition
|
|
12
|
+
*/
|
|
13
|
+
export interface Skill {
|
|
14
|
+
/**
|
|
15
|
+
* Skill identifier (key)
|
|
16
|
+
*/
|
|
17
|
+
id: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Skill name
|
|
21
|
+
*/
|
|
22
|
+
name: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Skill description
|
|
26
|
+
*/
|
|
27
|
+
description: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* License information (optional)
|
|
31
|
+
*/
|
|
32
|
+
license?: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Compatibility information (optional)
|
|
36
|
+
*/
|
|
37
|
+
compatibility?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Additional metadata as string-to-string map (optional)
|
|
41
|
+
*/
|
|
42
|
+
metadata?: Record<string, string>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Skill detailed content description (optional)
|
|
46
|
+
* This is the markdown body content after the frontmatter
|
|
47
|
+
*/
|
|
48
|
+
content?: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Sub-skills (optional)
|
|
52
|
+
* Array of skill names that are sub-skills of this skill
|
|
53
|
+
* Creates a hierarchical tree structure for organizing skills
|
|
54
|
+
*/
|
|
55
|
+
subSkills?: string[];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Skill creation timestamp
|
|
59
|
+
*/
|
|
60
|
+
createdAt: Date;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Skill last update timestamp
|
|
64
|
+
*/
|
|
65
|
+
updatedAt: Date;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Create skill request type
|
|
70
|
+
*/
|
|
71
|
+
export interface CreateSkillRequest {
|
|
72
|
+
/**
|
|
73
|
+
* Skill name
|
|
74
|
+
*/
|
|
75
|
+
name: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Skill description
|
|
79
|
+
*/
|
|
80
|
+
description: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* License information (optional)
|
|
84
|
+
*/
|
|
85
|
+
license?: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Compatibility information (optional)
|
|
89
|
+
*/
|
|
90
|
+
compatibility?: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Additional metadata as string-to-string map (optional)
|
|
94
|
+
*/
|
|
95
|
+
metadata?: Record<string, string>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Skill detailed content description (optional)
|
|
99
|
+
* This is the markdown body content after the frontmatter
|
|
100
|
+
*/
|
|
101
|
+
content?: string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Sub-skills (optional)
|
|
105
|
+
* Array of skill names that are sub-skills of this skill
|
|
106
|
+
* Creates a hierarchical tree structure for organizing skills
|
|
107
|
+
*/
|
|
108
|
+
subSkills?: string[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* SkillStore interface
|
|
113
|
+
* Provides CRUD operations for skill data
|
|
114
|
+
*/
|
|
115
|
+
export interface SkillStore {
|
|
116
|
+
/**
|
|
117
|
+
* Get all skills
|
|
118
|
+
* @returns Array of all skills
|
|
119
|
+
*/
|
|
120
|
+
getAllSkills(): Promise<Skill[]>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get skill by ID
|
|
124
|
+
* @param id Skill identifier
|
|
125
|
+
* @returns Skill if found, null otherwise
|
|
126
|
+
*/
|
|
127
|
+
getSkillById(id: string): Promise<Skill | null>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Create a new skill
|
|
131
|
+
* @param id Skill identifier
|
|
132
|
+
* @param data Skill creation data
|
|
133
|
+
* @returns Created skill
|
|
134
|
+
*/
|
|
135
|
+
createSkill(id: string, data: CreateSkillRequest): Promise<Skill>;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Update an existing skill
|
|
139
|
+
* @param id Skill identifier
|
|
140
|
+
* @param updates Partial skill data to update
|
|
141
|
+
* @returns Updated skill if found, null otherwise
|
|
142
|
+
*/
|
|
143
|
+
updateSkill(
|
|
144
|
+
id: string,
|
|
145
|
+
updates: Partial<CreateSkillRequest>
|
|
146
|
+
): Promise<Skill | null>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Delete a skill by ID
|
|
150
|
+
* @param id Skill identifier
|
|
151
|
+
* @returns true if deleted, false otherwise
|
|
152
|
+
*/
|
|
153
|
+
deleteSkill(id: string): Promise<boolean>;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Check if skill exists
|
|
157
|
+
* @param id Skill identifier
|
|
158
|
+
* @returns true if skill exists, false otherwise
|
|
159
|
+
*/
|
|
160
|
+
hasSkill(id: string): Promise<boolean>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Search skills by metadata
|
|
164
|
+
* @param metadataKey Metadata key to search for
|
|
165
|
+
* @param metadataValue Metadata value to match
|
|
166
|
+
* @returns Array of matching skills
|
|
167
|
+
*/
|
|
168
|
+
searchByMetadata(
|
|
169
|
+
metadataKey: string,
|
|
170
|
+
metadataValue: string
|
|
171
|
+
): Promise<Skill[]>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Filter skills by compatibility
|
|
175
|
+
* @param compatibility Compatibility string to filter by
|
|
176
|
+
* @returns Array of matching skills
|
|
177
|
+
*/
|
|
178
|
+
filterByCompatibility(compatibility: string): Promise<Skill[]>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Filter skills by license
|
|
182
|
+
* @param license License string to filter by
|
|
183
|
+
* @returns Array of matching skills
|
|
184
|
+
*/
|
|
185
|
+
filterByLicense(license: string): Promise<Skill[]>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Get sub-skills of a parent skill
|
|
189
|
+
* @param parentSkillName Parent skill name
|
|
190
|
+
* @returns Array of sub-skills if found, empty array otherwise
|
|
191
|
+
*/
|
|
192
|
+
getSubSkills(parentSkillName: string): Promise<Skill[]>;
|
|
193
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -14,9 +14,12 @@ 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";
|
|
21
|
+
export * from "./SkillLatticeProtocol";
|
|
22
|
+
export * from "./SkillStoreProtocol";
|
|
20
23
|
|
|
21
24
|
// 导出通用类型
|
|
22
25
|
export * from "./types";
|