@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.
package/dist/index.d.ts CHANGED
@@ -126,6 +126,16 @@ declare enum AgentType {
126
126
  PLAN_EXECUTE = "plan_execute",
127
127
  SEQUENTIAL = "sequential"
128
128
  }
129
+ /**
130
+ * Runtime configuration that will be injected into LangGraphRunnableConfig.configurable
131
+ * Tools can access these values via config.configurable.runConfig
132
+ */
133
+ interface AgentRunConfig {
134
+ /** Database key for SQL tools (registered via sqlDatabaseManager) */
135
+ databaseKey?: string;
136
+ /** Any additional runtime configuration */
137
+ [key: string]: any;
138
+ }
129
139
  /**
130
140
  * Base agent configuration shared by all agent types
131
141
  */
@@ -136,6 +146,11 @@ interface BaseAgentConfig {
136
146
  prompt: string;
137
147
  schema?: ZodObject<any, any, any, any, any>;
138
148
  modelKey?: string;
149
+ /**
150
+ * Runtime configuration to inject into tool execution context
151
+ * Will be available in tools via config.configurable.runConfig
152
+ */
153
+ runConfig?: AgentRunConfig;
139
154
  }
140
155
  /**
141
156
  * REACT agent configuration
@@ -367,14 +382,36 @@ interface QueueLatticeProtocol extends BaseLatticeProtocol<QueueConfig, QueueCli
367
382
  /**
368
383
  * ScheduleLatticeProtocol
369
384
  *
370
- * Schedule Lattice protocol for delayed task execution management
385
+ * Schedule Lattice protocol for delayed and recurring task execution management
386
+ * Supports persistence and recovery after service restart
387
+ * Supports both one-time delayed tasks and cron-style recurring tasks
371
388
  */
372
389
 
373
390
  /**
374
391
  * Schedule service type enumeration
375
392
  */
376
393
  declare enum ScheduleType {
377
- MEMORY = "memory"
394
+ MEMORY = "memory",
395
+ POSTGRES = "postgres",
396
+ REDIS = "redis"
397
+ }
398
+ /**
399
+ * Schedule execution type - one-time or recurring
400
+ */
401
+ declare enum ScheduleExecutionType {
402
+ ONCE = "once",// Execute once at specified time
403
+ CRON = "cron"
404
+ }
405
+ /**
406
+ * Task status enumeration
407
+ */
408
+ declare enum ScheduledTaskStatus {
409
+ PENDING = "pending",// Waiting to be executed
410
+ RUNNING = "running",// Currently executing
411
+ COMPLETED = "completed",// Successfully completed (for ONCE type)
412
+ FAILED = "failed",// Execution failed
413
+ CANCELLED = "cancelled",// Manually cancelled
414
+ PAUSED = "paused"
378
415
  }
379
416
  /**
380
417
  * Schedule configuration interface
@@ -383,77 +420,248 @@ interface ScheduleConfig {
383
420
  name: string;
384
421
  description: string;
385
422
  type: ScheduleType;
423
+ storage?: ScheduleStorage;
386
424
  options?: Record<string, any>;
387
425
  }
388
426
  /**
389
- * Scheduled task information interface
427
+ * Scheduled task definition - fully serializable
428
+ * Supports both one-time and cron-style recurring tasks
390
429
  */
391
- interface ScheduledTaskInfo {
430
+ interface ScheduledTaskDefinition {
392
431
  taskId: string;
393
- scheduledAt: number;
394
- timeoutMs: number;
395
- remainingMs: number;
432
+ taskType: string;
433
+ payload: Record<string, any>;
434
+ assistantId?: string;
435
+ threadId?: string;
436
+ executionType: ScheduleExecutionType;
437
+ executeAt?: number;
438
+ delayMs?: number;
439
+ cronExpression?: string;
440
+ timezone?: string;
441
+ nextRunAt?: number;
442
+ lastRunAt?: number;
443
+ status: ScheduledTaskStatus;
444
+ runCount: number;
445
+ maxRuns?: number;
446
+ retryCount: number;
447
+ maxRetries: number;
448
+ lastError?: string;
449
+ createdAt: number;
450
+ updatedAt: number;
451
+ expiresAt?: number;
452
+ metadata?: Record<string, any>;
453
+ }
454
+ /**
455
+ * Task handler function type
456
+ */
457
+ type TaskHandler = (payload: Record<string, any>, taskInfo: ScheduledTaskDefinition) => void | Promise<void>;
458
+ /**
459
+ * Options for scheduling a one-time task
460
+ */
461
+ interface ScheduleOnceOptions {
462
+ executeAt?: number;
463
+ delayMs?: number;
464
+ maxRetries?: number;
465
+ assistantId?: string;
466
+ threadId?: string;
467
+ metadata?: Record<string, any>;
468
+ }
469
+ /**
470
+ * Options for scheduling a cron task
471
+ */
472
+ interface ScheduleCronOptions {
473
+ cronExpression: string;
474
+ timezone?: string;
475
+ maxRuns?: number;
476
+ expiresAt?: number;
477
+ maxRetries?: number;
478
+ assistantId?: string;
479
+ threadId?: string;
480
+ metadata?: Record<string, any>;
481
+ }
482
+ /**
483
+ * Schedule storage interface for persistence
484
+ */
485
+ interface ScheduleStorage {
486
+ /**
487
+ * Save a new task
488
+ */
489
+ save(task: ScheduledTaskDefinition): Promise<void>;
490
+ /**
491
+ * Get task by ID
492
+ */
493
+ get(taskId: string): Promise<ScheduledTaskDefinition | null>;
494
+ /**
495
+ * Update task
496
+ */
497
+ update(taskId: string, updates: Partial<ScheduledTaskDefinition>): Promise<void>;
498
+ /**
499
+ * Delete task
500
+ */
501
+ delete(taskId: string): Promise<void>;
502
+ /**
503
+ * Get all pending/active tasks (for recovery)
504
+ * Returns tasks with status: PENDING or PAUSED
505
+ */
506
+ getActiveTasks(): Promise<ScheduledTaskDefinition[]>;
507
+ /**
508
+ * Get tasks by type
509
+ */
510
+ getTasksByType(taskType: string): Promise<ScheduledTaskDefinition[]>;
511
+ /**
512
+ * Get tasks by status
513
+ */
514
+ getTasksByStatus(status: ScheduledTaskStatus): Promise<ScheduledTaskDefinition[]>;
515
+ /**
516
+ * Get tasks by execution type
517
+ */
518
+ getTasksByExecutionType(executionType: ScheduleExecutionType): Promise<ScheduledTaskDefinition[]>;
519
+ /**
520
+ * Get tasks by assistant ID
521
+ */
522
+ getTasksByAssistantId(assistantId: string): Promise<ScheduledTaskDefinition[]>;
523
+ /**
524
+ * Get tasks by thread ID
525
+ */
526
+ getTasksByThreadId(threadId: string): Promise<ScheduledTaskDefinition[]>;
527
+ /**
528
+ * Get all tasks (with optional filters)
529
+ */
530
+ getAllTasks(filters?: {
531
+ status?: ScheduledTaskStatus;
532
+ executionType?: ScheduleExecutionType;
533
+ taskType?: string;
534
+ assistantId?: string;
535
+ threadId?: string;
536
+ limit?: number;
537
+ offset?: number;
538
+ }): Promise<ScheduledTaskDefinition[]>;
539
+ /**
540
+ * Count tasks (with optional filters)
541
+ */
542
+ countTasks(filters?: {
543
+ status?: ScheduledTaskStatus;
544
+ executionType?: ScheduleExecutionType;
545
+ taskType?: string;
546
+ assistantId?: string;
547
+ threadId?: string;
548
+ }): Promise<number>;
549
+ /**
550
+ * Delete completed/cancelled tasks older than specified time
551
+ * Useful for cleanup
552
+ */
553
+ deleteOldTasks(olderThanMs: number): Promise<number>;
396
554
  }
397
555
  /**
398
556
  * Schedule client interface
399
557
  */
400
558
  interface ScheduleClient {
401
559
  /**
402
- * Register a function to be executed after the specified timeout
403
- * @param taskId - Unique identifier for the task
404
- * @param callback - Function to execute when timeout expires
405
- * @param timeoutMs - Delay in milliseconds before execution
406
- * @returns true if registered successfully
560
+ * Register a handler for a task type
561
+ * Must be called before scheduling tasks of this type
407
562
  */
408
- register: (taskId: string, callback: () => void | Promise<void>, timeoutMs: number) => boolean;
563
+ registerHandler(taskType: string, handler: TaskHandler): void;
409
564
  /**
410
- * Cancel a scheduled task by its ID
411
- * @param taskId - The task identifier to cancel
412
- * @returns true if task was found and cancelled, false otherwise
565
+ * Unregister a handler
413
566
  */
414
- cancel: (taskId: string) => boolean;
567
+ unregisterHandler(taskType: string): boolean;
415
568
  /**
416
- * Check if a task is currently scheduled
417
- * @param taskId - The task identifier to check
569
+ * Check if a handler is registered
418
570
  */
419
- has: (taskId: string) => boolean;
571
+ hasHandler(taskType: string): boolean;
420
572
  /**
421
- * Get the remaining time in milliseconds for a scheduled task
422
- * @param taskId - The task identifier
423
- * @returns Remaining time in ms, or -1 if task not found
573
+ * Get all registered handler types
424
574
  */
425
- getRemainingTime: (taskId: string) => number;
575
+ getHandlerTypes(): string[];
426
576
  /**
427
- * Get the count of currently scheduled tasks
577
+ * Schedule a one-time task
578
+ * @param taskId - Unique identifier for the task
579
+ * @param taskType - Type of task (must have a registered handler)
580
+ * @param payload - Data to pass to the handler (must be JSON-serializable)
581
+ * @param options - Execution options (executeAt or delayMs required)
582
+ */
583
+ scheduleOnce(taskId: string, taskType: string, payload: Record<string, any>, options: ScheduleOnceOptions): Promise<boolean>;
584
+ /**
585
+ * Schedule a recurring cron task
586
+ * @param taskId - Unique identifier for the task
587
+ * @param taskType - Type of task (must have a registered handler)
588
+ * @param payload - Data to pass to the handler (must be JSON-serializable)
589
+ * @param options - Cron options (cronExpression required)
428
590
  */
429
- getTaskCount: () => number;
591
+ scheduleCron(taskId: string, taskType: string, payload: Record<string, any>, options: ScheduleCronOptions): Promise<boolean>;
430
592
  /**
431
- * Get all scheduled task IDs
593
+ * Cancel a scheduled task
432
594
  */
433
- getTaskIds: () => string[];
595
+ cancel(taskId: string): Promise<boolean>;
434
596
  /**
435
- * Cancel all scheduled tasks
597
+ * Pause a cron task (only for CRON type)
436
598
  */
437
- cancelAll: () => void;
599
+ pause(taskId: string): Promise<boolean>;
600
+ /**
601
+ * Resume a paused cron task (only for CRON type)
602
+ */
603
+ resume(taskId: string): Promise<boolean>;
604
+ /**
605
+ * Check if a task exists
606
+ */
607
+ has(taskId: string): Promise<boolean>;
438
608
  /**
439
609
  * Get task information
440
- * @param taskId - The task identifier
441
- * @returns Task info or null if not found
442
610
  */
443
- getTaskInfo?: (taskId: string) => ScheduledTaskInfo | null;
611
+ getTask(taskId: string): Promise<ScheduledTaskDefinition | null>;
612
+ /**
613
+ * Get remaining time until next execution
614
+ * Returns -1 if task not found or already executed
615
+ */
616
+ getRemainingTime(taskId: string): Promise<number>;
617
+ /**
618
+ * Get count of active tasks (pending + paused)
619
+ */
620
+ getActiveTaskCount(): Promise<number>;
621
+ /**
622
+ * Get all active task IDs
623
+ */
624
+ getActiveTaskIds(): Promise<string[]>;
625
+ /**
626
+ * Cancel all active tasks
627
+ */
628
+ cancelAll(): Promise<void>;
629
+ /**
630
+ * Restore active tasks from storage (call on service startup)
631
+ * Re-schedules all pending tasks with their remaining time
632
+ * Re-schedules all cron tasks for their next run
633
+ * @returns Number of tasks restored
634
+ */
635
+ restore(): Promise<number>;
636
+ /**
637
+ * Set the storage backend
638
+ */
639
+ setStorage(storage: ScheduleStorage): void;
640
+ /**
641
+ * Get current storage backend
642
+ */
643
+ getStorage(): ScheduleStorage | null;
444
644
  }
445
645
  /**
446
646
  * Schedule Lattice protocol interface
447
647
  */
448
648
  interface ScheduleLatticeProtocol extends BaseLatticeProtocol<ScheduleConfig, ScheduleClient> {
449
- register: (taskId: string, callback: () => void | Promise<void>, timeoutMs: number) => boolean;
450
- cancel: (taskId: string) => boolean;
451
- has: (taskId: string) => boolean;
452
- getRemainingTime: (taskId: string) => number;
453
- getTaskCount: () => number;
454
- getTaskIds: () => string[];
455
- cancelAll: () => void;
456
- getTaskInfo?: (taskId: string) => ScheduledTaskInfo | null;
649
+ registerHandler: (taskType: string, handler: TaskHandler) => void;
650
+ unregisterHandler: (taskType: string) => boolean;
651
+ hasHandler: (taskType: string) => boolean;
652
+ getHandlerTypes: () => string[];
653
+ scheduleOnce: (taskId: string, taskType: string, payload: Record<string, any>, options: ScheduleOnceOptions) => Promise<boolean>;
654
+ scheduleCron: (taskId: string, taskType: string, payload: Record<string, any>, options: ScheduleCronOptions) => Promise<boolean>;
655
+ cancel: (taskId: string) => Promise<boolean>;
656
+ pause: (taskId: string) => Promise<boolean>;
657
+ resume: (taskId: string) => Promise<boolean>;
658
+ has: (taskId: string) => Promise<boolean>;
659
+ getTask: (taskId: string) => Promise<ScheduledTaskDefinition | null>;
660
+ getRemainingTime: (taskId: string) => Promise<number>;
661
+ getActiveTaskCount: () => Promise<number>;
662
+ getActiveTaskIds: () => Promise<string[]>;
663
+ cancelAll: () => Promise<void>;
664
+ restore: () => Promise<number>;
457
665
  }
458
666
 
459
667
  /**
@@ -512,6 +720,77 @@ interface VectorStoreLatticeProtocol extends BaseLatticeProtocol<VectorStoreConf
512
720
  }) => Promise<DocumentInterface[]>;
513
721
  }
514
722
 
723
+ /**
724
+ * LoggerLatticeProtocol
725
+ *
726
+ * Logger Lattice protocol for logging management
727
+ */
728
+
729
+ /**
730
+ * Logger service type enumeration
731
+ */
732
+ declare enum LoggerType {
733
+ PINO = "pino",
734
+ CONSOLE = "console",
735
+ CUSTOM = "custom"
736
+ }
737
+ /**
738
+ * Logger context interface
739
+ */
740
+ interface LoggerContext {
741
+ "x-user-id"?: string;
742
+ "x-tenant-id"?: string;
743
+ "x-request-id"?: string;
744
+ "x-task-id"?: string;
745
+ "x-thread-id"?: string;
746
+ [key: string]: any;
747
+ }
748
+ /**
749
+ * Pino logger file transport options
750
+ */
751
+ interface PinoFileOptions {
752
+ file?: string;
753
+ frequency?: "daily" | "hourly" | "minutely" | string;
754
+ mkdir?: boolean;
755
+ size?: string;
756
+ maxFiles?: number;
757
+ }
758
+ /**
759
+ * Logger configuration interface
760
+ */
761
+ interface LoggerConfig {
762
+ name: string;
763
+ description?: string;
764
+ type: LoggerType;
765
+ serviceName?: string;
766
+ loggerName?: string;
767
+ context?: LoggerContext;
768
+ file?: string | PinoFileOptions;
769
+ options?: Record<string, any>;
770
+ }
771
+ /**
772
+ * Logger client interface
773
+ */
774
+ interface LoggerClient {
775
+ info: (msg: string, obj?: object) => void;
776
+ error: (msg: string, obj?: object | Error) => void;
777
+ warn: (msg: string, obj?: object) => void;
778
+ debug: (msg: string, obj?: object) => void;
779
+ updateContext?: (context: Partial<LoggerContext>) => void;
780
+ child?: (options: Partial<LoggerConfig>) => LoggerClient;
781
+ }
782
+ /**
783
+ * Logger Lattice protocol interface
784
+ */
785
+ interface LoggerLatticeProtocol extends BaseLatticeProtocol<LoggerConfig, LoggerClient> {
786
+ info: (msg: string, obj?: object) => void;
787
+ error: (msg: string, obj?: object | Error) => void;
788
+ warn: (msg: string, obj?: object) => void;
789
+ debug: (msg: string, obj?: object) => void;
790
+ updateContext?: (context: Partial<LoggerContext>) => void;
791
+ child?: (options: Partial<LoggerConfig>) => LoggerClient;
792
+ }
793
+
515
794
  /**
516
795
  * MessageProtocol
517
796
  *
@@ -865,4 +1144,4 @@ type Timestamp = number;
865
1144
  */
866
1145
  type Callback<T = any, R = void> = (data: T) => R | Promise<R>;
867
1146
 
868
- export { type AgentClient, type AgentConfig, type AgentConfigWithTools, type AgentLatticeProtocol, AgentType, type Assistant, type AssistantMessage, type AssistantStore, type BaseLatticeProtocol, type BaseMessage, type Callback, type CreateAssistantRequest, type CreateThreadRequest, type DeepAgentConfig, type DeveloperMessage, type EmbeddingsConfig, type EmbeddingsLatticeProtocol, type FilterCondition, type GraphBuildOptions, type ID, type InterruptMessage, type LLMConfig, type LatticeError, type LatticeEventBus, type LatticeMessage, type MemoryClient, type MemoryConfig, type MemoryLatticeProtocol, MemoryType, type Message, type MessageChunk, type ModelLatticeProtocol, type PaginatedResult, type PaginationParams, type PlanExecuteAgentConfig, type QueryParams, type QueueClient, type QueueConfig, type QueueLatticeProtocol, type QueueResult, QueueType, type ReactAgentConfig, type Result, type ScheduleClient, type ScheduleConfig, type ScheduleLatticeProtocol, ScheduleType, type ScheduledTaskInfo, type SequentialAgentConfig, type SystemMessage, type Thread, type ThreadStore, type Timestamp, type ToolCall, type ToolConfig, type ToolExecutor, type ToolLatticeProtocol, type ToolMessage, type UIComponent, UIComponentType, type UIConfig, type UILatticeProtocol, type UserMessage, type VectorStoreConfig, type VectorStoreLatticeProtocol, getSubAgentsFromConfig, getToolsFromConfig, hasTools, isDeepAgentConfig };
1147
+ export { type AgentClient, type AgentConfig, type AgentConfigWithTools, type AgentLatticeProtocol, type AgentRunConfig, AgentType, type Assistant, type AssistantMessage, type AssistantStore, type BaseLatticeProtocol, type BaseMessage, type Callback, type CreateAssistantRequest, type CreateThreadRequest, type DeepAgentConfig, type DeveloperMessage, type EmbeddingsConfig, type EmbeddingsLatticeProtocol, type FilterCondition, type GraphBuildOptions, type ID, type InterruptMessage, type LLMConfig, type LatticeError, type LatticeEventBus, type LatticeMessage, type LoggerClient, type LoggerConfig, type LoggerContext, type LoggerLatticeProtocol, LoggerType, type MemoryClient, type MemoryConfig, type MemoryLatticeProtocol, MemoryType, type Message, type MessageChunk, type ModelLatticeProtocol, type PaginatedResult, type PaginationParams, type PinoFileOptions, type PlanExecuteAgentConfig, type QueryParams, type QueueClient, type QueueConfig, type QueueLatticeProtocol, type QueueResult, QueueType, type ReactAgentConfig, type Result, type ScheduleClient, type ScheduleConfig, type ScheduleCronOptions, ScheduleExecutionType, type ScheduleLatticeProtocol, type ScheduleOnceOptions, type ScheduleStorage, ScheduleType, type ScheduledTaskDefinition, ScheduledTaskStatus, type SequentialAgentConfig, type SystemMessage, type TaskHandler, type Thread, type ThreadStore, type Timestamp, type ToolCall, type ToolConfig, type ToolExecutor, type ToolLatticeProtocol, type ToolMessage, type UIComponent, UIComponentType, type UIConfig, type UILatticeProtocol, type UserMessage, type VectorStoreConfig, type VectorStoreLatticeProtocol, getSubAgentsFromConfig, getToolsFromConfig, hasTools, isDeepAgentConfig };
package/dist/index.js CHANGED
@@ -21,9 +21,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AgentType: () => AgentType,
24
+ LoggerType: () => LoggerType,
24
25
  MemoryType: () => MemoryType,
25
26
  QueueType: () => QueueType,
27
+ ScheduleExecutionType: () => ScheduleExecutionType,
26
28
  ScheduleType: () => ScheduleType,
29
+ ScheduledTaskStatus: () => ScheduledTaskStatus,
27
30
  UIComponentType: () => UIComponentType,
28
31
  getSubAgentsFromConfig: () => getSubAgentsFromConfig,
29
32
  getToolsFromConfig: () => getToolsFromConfig,
@@ -94,14 +97,41 @@ var QueueType = /* @__PURE__ */ ((QueueType2) => {
94
97
  // src/ScheduleLatticeProtocol.ts
95
98
  var ScheduleType = /* @__PURE__ */ ((ScheduleType2) => {
96
99
  ScheduleType2["MEMORY"] = "memory";
100
+ ScheduleType2["POSTGRES"] = "postgres";
101
+ ScheduleType2["REDIS"] = "redis";
97
102
  return ScheduleType2;
98
103
  })(ScheduleType || {});
104
+ var ScheduleExecutionType = /* @__PURE__ */ ((ScheduleExecutionType2) => {
105
+ ScheduleExecutionType2["ONCE"] = "once";
106
+ ScheduleExecutionType2["CRON"] = "cron";
107
+ return ScheduleExecutionType2;
108
+ })(ScheduleExecutionType || {});
109
+ var ScheduledTaskStatus = /* @__PURE__ */ ((ScheduledTaskStatus2) => {
110
+ ScheduledTaskStatus2["PENDING"] = "pending";
111
+ ScheduledTaskStatus2["RUNNING"] = "running";
112
+ ScheduledTaskStatus2["COMPLETED"] = "completed";
113
+ ScheduledTaskStatus2["FAILED"] = "failed";
114
+ ScheduledTaskStatus2["CANCELLED"] = "cancelled";
115
+ ScheduledTaskStatus2["PAUSED"] = "paused";
116
+ return ScheduledTaskStatus2;
117
+ })(ScheduledTaskStatus || {});
118
+
119
+ // src/LoggerLatticeProtocol.ts
120
+ var LoggerType = /* @__PURE__ */ ((LoggerType2) => {
121
+ LoggerType2["PINO"] = "pino";
122
+ LoggerType2["CONSOLE"] = "console";
123
+ LoggerType2["CUSTOM"] = "custom";
124
+ return LoggerType2;
125
+ })(LoggerType || {});
99
126
  // Annotate the CommonJS export names for ESM import in node:
100
127
  0 && (module.exports = {
101
128
  AgentType,
129
+ LoggerType,
102
130
  MemoryType,
103
131
  QueueType,
132
+ ScheduleExecutionType,
104
133
  ScheduleType,
134
+ ScheduledTaskStatus,
105
135
  UIComponentType,
106
136
  getSubAgentsFromConfig,
107
137
  getToolsFromConfig,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/AgentLatticeProtocol.ts","../src/MemoryLatticeProtocol.ts","../src/UILatticeProtocol.ts","../src/QueueLatticeProtocol.ts","../src/ScheduleLatticeProtocol.ts"],"sourcesContent":["/**\n * Protocols\n *\n * 导出所有Lattice协议接口,为整个系统提供统一的接口规范\n */\n\nexport * from \"./BaseLatticeProtocol\";\nexport * from \"./ToolLatticeProtocol\";\nexport * from \"./ModelLatticeProtocol\";\nexport * from \"./AgentLatticeProtocol\";\nexport * from \"./MemoryLatticeProtocol\";\nexport * from \"./UILatticeProtocol\";\nexport * from \"./QueueLatticeProtocol\";\nexport * from \"./ScheduleLatticeProtocol\";\nexport * from \"./EmbeddingsLatticeProtocol\";\nexport * from \"./VectorStoreLatticeProtocol\";\nexport * from \"./MessageProtocol\";\nexport * from \"./ThreadStoreProtocol\";\nexport * from \"./AssistantStoreProtocol\";\n\n// 导出通用类型\nexport * from \"./types\";\n","/**\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,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/index.ts","../src/AgentLatticeProtocol.ts","../src/MemoryLatticeProtocol.ts","../src/UILatticeProtocol.ts","../src/QueueLatticeProtocol.ts","../src/ScheduleLatticeProtocol.ts","../src/LoggerLatticeProtocol.ts"],"sourcesContent":["/**\n * Protocols\n *\n * 导出所有Lattice协议接口,为整个系统提供统一的接口规范\n */\n\nexport * from \"./BaseLatticeProtocol\";\nexport * from \"./ToolLatticeProtocol\";\nexport * from \"./ModelLatticeProtocol\";\nexport * from \"./AgentLatticeProtocol\";\nexport * from \"./MemoryLatticeProtocol\";\nexport * from \"./UILatticeProtocol\";\nexport * from \"./QueueLatticeProtocol\";\nexport * from \"./ScheduleLatticeProtocol\";\nexport * from \"./EmbeddingsLatticeProtocol\";\nexport * from \"./VectorStoreLatticeProtocol\";\nexport * from \"./LoggerLatticeProtocol\";\nexport * from \"./MessageProtocol\";\nexport * from \"./ThreadStoreProtocol\";\nexport * from \"./AssistantStoreProtocol\";\n\n// 导出通用类型\nexport * from \"./types\";\n","/**\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,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/dist/index.mjs CHANGED
@@ -60,13 +60,40 @@ var QueueType = /* @__PURE__ */ ((QueueType2) => {
60
60
  // src/ScheduleLatticeProtocol.ts
61
61
  var ScheduleType = /* @__PURE__ */ ((ScheduleType2) => {
62
62
  ScheduleType2["MEMORY"] = "memory";
63
+ ScheduleType2["POSTGRES"] = "postgres";
64
+ ScheduleType2["REDIS"] = "redis";
63
65
  return ScheduleType2;
64
66
  })(ScheduleType || {});
67
+ var ScheduleExecutionType = /* @__PURE__ */ ((ScheduleExecutionType2) => {
68
+ ScheduleExecutionType2["ONCE"] = "once";
69
+ ScheduleExecutionType2["CRON"] = "cron";
70
+ return ScheduleExecutionType2;
71
+ })(ScheduleExecutionType || {});
72
+ var ScheduledTaskStatus = /* @__PURE__ */ ((ScheduledTaskStatus2) => {
73
+ ScheduledTaskStatus2["PENDING"] = "pending";
74
+ ScheduledTaskStatus2["RUNNING"] = "running";
75
+ ScheduledTaskStatus2["COMPLETED"] = "completed";
76
+ ScheduledTaskStatus2["FAILED"] = "failed";
77
+ ScheduledTaskStatus2["CANCELLED"] = "cancelled";
78
+ ScheduledTaskStatus2["PAUSED"] = "paused";
79
+ return ScheduledTaskStatus2;
80
+ })(ScheduledTaskStatus || {});
81
+
82
+ // src/LoggerLatticeProtocol.ts
83
+ var LoggerType = /* @__PURE__ */ ((LoggerType2) => {
84
+ LoggerType2["PINO"] = "pino";
85
+ LoggerType2["CONSOLE"] = "console";
86
+ LoggerType2["CUSTOM"] = "custom";
87
+ return LoggerType2;
88
+ })(LoggerType || {});
65
89
  export {
66
90
  AgentType,
91
+ LoggerType,
67
92
  MemoryType,
68
93
  QueueType,
94
+ ScheduleExecutionType,
69
95
  ScheduleType,
96
+ ScheduledTaskStatus,
70
97
  UIComponentType,
71
98
  getSubAgentsFromConfig,
72
99
  getToolsFromConfig,