@axiom-lattice/protocols 2.1.5 → 2.1.7

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.
@@ -0,0 +1,113 @@
1
+ /**
2
+ * AssistantStoreProtocol
3
+ *
4
+ * Assistant store protocol definitions for the Axiom Lattice framework
5
+ * Provides standardized interfaces for assistant management across all implementations
6
+ */
7
+
8
+ /**
9
+ * Assistant type definition
10
+ */
11
+ export interface Assistant {
12
+ /**
13
+ * Assistant identifier
14
+ */
15
+ id: string;
16
+
17
+ /**
18
+ * Assistant name
19
+ */
20
+ name: string;
21
+
22
+ /**
23
+ * Assistant description
24
+ */
25
+ description?: string;
26
+
27
+ /**
28
+ * Graph definition for the assistant
29
+ */
30
+ graphDefinition: any;
31
+
32
+ /**
33
+ * Assistant creation timestamp
34
+ */
35
+ createdAt: Date;
36
+
37
+ /**
38
+ * Assistant last update timestamp
39
+ */
40
+ updatedAt: Date;
41
+ }
42
+
43
+ /**
44
+ * Create assistant request type
45
+ */
46
+ export interface CreateAssistantRequest {
47
+ /**
48
+ * Assistant name
49
+ */
50
+ name: string;
51
+
52
+ /**
53
+ * Assistant description
54
+ */
55
+ description?: string;
56
+
57
+ /**
58
+ * Graph definition for the assistant
59
+ */
60
+ graphDefinition: any;
61
+ }
62
+
63
+ /**
64
+ * AssistantStore interface
65
+ * Provides CRUD operations for assistant data
66
+ */
67
+ export interface AssistantStore {
68
+ /**
69
+ * Get all assistants
70
+ * @returns Array of all assistants
71
+ */
72
+ getAllAssistants(): Promise<Assistant[]>;
73
+
74
+ /**
75
+ * Get assistant by ID
76
+ * @param id Assistant identifier
77
+ * @returns Assistant if found, undefined otherwise
78
+ */
79
+ getAssistantById(id: string): Promise<Assistant | null>;
80
+
81
+ /**
82
+ * Create a new assistant
83
+ * @param id Assistant identifier
84
+ * @param data Assistant creation data
85
+ * @returns Created assistant
86
+ */
87
+ createAssistant(id: string, data: CreateAssistantRequest): Promise<Assistant>;
88
+
89
+ /**
90
+ * Update an existing assistant
91
+ * @param id Assistant identifier
92
+ * @param updates Partial assistant data to update
93
+ * @returns Updated assistant if found, null otherwise
94
+ */
95
+ updateAssistant(
96
+ id: string,
97
+ updates: Partial<CreateAssistantRequest>
98
+ ): Promise<Assistant | null>;
99
+
100
+ /**
101
+ * Delete an assistant by ID
102
+ * @param id Assistant identifier
103
+ * @returns true if deleted, false otherwise
104
+ */
105
+ deleteAssistant(id: string): Promise<boolean>;
106
+
107
+ /**
108
+ * Check if assistant exists
109
+ * @param id Assistant identifier
110
+ * @returns true if assistant exists, false otherwise
111
+ */
112
+ hasAssistant(id: string): Promise<boolean>;
113
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * EmbeddingsLatticeProtocol
3
+ *
4
+ * Embeddings Lattice protocol for defining unified interface for embedding models
5
+ */
6
+
7
+ import { Embeddings } from "@langchain/core/embeddings";
8
+ import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
9
+
10
+ /**
11
+ * Embeddings configuration interface
12
+ */
13
+ export interface EmbeddingsConfig {
14
+ name: string; // Embeddings model name
15
+ description?: string; // Description of the embeddings model
16
+ dimensions?: number; // Embedding dimensions
17
+ maxChunkSize?: number; // Maximum chunk size for embedding
18
+ }
19
+
20
+ /**
21
+ * Embeddings Lattice protocol interface
22
+ */
23
+ export interface EmbeddingsLatticeProtocol
24
+ extends BaseLatticeProtocol<EmbeddingsConfig, Embeddings> {
25
+ // Embed documents into vectors
26
+ embedDocuments: (texts: string[]) => Promise<number[][]>;
27
+
28
+ // Embed a single query into a vector
29
+ embedQuery: (text: string) => Promise<number[]>;
30
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * ScheduleLatticeProtocol
3
+ *
4
+ * Schedule Lattice protocol for delayed task execution management
5
+ */
6
+
7
+ import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
8
+
9
+ /**
10
+ * Schedule service type enumeration
11
+ */
12
+ export enum ScheduleType {
13
+ MEMORY = "memory",
14
+ // Future implementations can add more types like REDIS, DATABASE, etc.
15
+ }
16
+
17
+ /**
18
+ * Schedule configuration interface
19
+ */
20
+ export interface ScheduleConfig {
21
+ name: string; // Schedule name
22
+ description: string; // Schedule description
23
+ type: ScheduleType; // Schedule service type
24
+ options?: Record<string, any>; // Additional options
25
+ }
26
+
27
+ /**
28
+ * Scheduled task information interface
29
+ */
30
+ export interface ScheduledTaskInfo {
31
+ taskId: string;
32
+ scheduledAt: number;
33
+ timeoutMs: number;
34
+ remainingMs: number;
35
+ }
36
+
37
+ /**
38
+ * Schedule client interface
39
+ */
40
+ export interface ScheduleClient {
41
+ /**
42
+ * Register a function to be executed after the specified timeout
43
+ * @param taskId - Unique identifier for the task
44
+ * @param callback - Function to execute when timeout expires
45
+ * @param timeoutMs - Delay in milliseconds before execution
46
+ * @returns true if registered successfully
47
+ */
48
+ register: (
49
+ taskId: string,
50
+ callback: () => void | Promise<void>,
51
+ timeoutMs: number
52
+ ) => boolean;
53
+
54
+ /**
55
+ * Cancel a scheduled task by its ID
56
+ * @param taskId - The task identifier to cancel
57
+ * @returns true if task was found and cancelled, false otherwise
58
+ */
59
+ cancel: (taskId: string) => boolean;
60
+
61
+ /**
62
+ * Check if a task is currently scheduled
63
+ * @param taskId - The task identifier to check
64
+ */
65
+ has: (taskId: string) => boolean;
66
+
67
+ /**
68
+ * Get the remaining time in milliseconds for a scheduled task
69
+ * @param taskId - The task identifier
70
+ * @returns Remaining time in ms, or -1 if task not found
71
+ */
72
+ getRemainingTime: (taskId: string) => number;
73
+
74
+ /**
75
+ * Get the count of currently scheduled tasks
76
+ */
77
+ getTaskCount: () => number;
78
+
79
+ /**
80
+ * Get all scheduled task IDs
81
+ */
82
+ getTaskIds: () => string[];
83
+
84
+ /**
85
+ * Cancel all scheduled tasks
86
+ */
87
+ cancelAll: () => void;
88
+
89
+ /**
90
+ * Get task information
91
+ * @param taskId - The task identifier
92
+ * @returns Task info or null if not found
93
+ */
94
+ getTaskInfo?: (taskId: string) => ScheduledTaskInfo | null;
95
+ }
96
+
97
+ /**
98
+ * Schedule Lattice protocol interface
99
+ */
100
+ export interface ScheduleLatticeProtocol
101
+ extends BaseLatticeProtocol<ScheduleConfig, ScheduleClient> {
102
+ // Schedule operations
103
+ register: (
104
+ taskId: string,
105
+ callback: () => void | Promise<void>,
106
+ timeoutMs: number
107
+ ) => boolean;
108
+ cancel: (taskId: string) => boolean;
109
+ has: (taskId: string) => boolean;
110
+ getRemainingTime: (taskId: string) => number;
111
+ getTaskCount: () => number;
112
+ getTaskIds: () => string[];
113
+ cancelAll: () => void;
114
+ getTaskInfo?: (taskId: string) => ScheduledTaskInfo | null;
115
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * ThreadStoreProtocol
3
+ *
4
+ * Thread store protocol definitions for the Axiom Lattice framework
5
+ * Provides standardized interfaces for thread management across all implementations
6
+ */
7
+
8
+ /**
9
+ * Thread type definition
10
+ */
11
+ export interface Thread {
12
+ /**
13
+ * Thread identifier
14
+ */
15
+ id: string;
16
+
17
+ /**
18
+ * Assistant identifier this thread belongs to
19
+ */
20
+ assistantId: string;
21
+
22
+ /**
23
+ * Thread metadata
24
+ */
25
+ metadata?: Record<string, any>;
26
+
27
+ /**
28
+ * Thread creation timestamp
29
+ */
30
+ createdAt: Date;
31
+
32
+ /**
33
+ * Thread last update timestamp
34
+ */
35
+ updatedAt: Date;
36
+ }
37
+
38
+ /**
39
+ * Create thread request type
40
+ */
41
+ export interface CreateThreadRequest {
42
+ /**
43
+ * Thread metadata
44
+ */
45
+ metadata?: Record<string, any>;
46
+ }
47
+
48
+ /**
49
+ * ThreadStore interface
50
+ * Provides CRUD operations for thread data
51
+ * All operations are scoped to an assistant ID
52
+ */
53
+ export interface ThreadStore {
54
+ /**
55
+ * Get all threads for a specific assistant
56
+ * @param assistantId Assistant identifier
57
+ * @returns Array of threads for the assistant
58
+ */
59
+ getThreadsByAssistantId(assistantId: string): Promise<Thread[]>;
60
+
61
+ /**
62
+ * Get a thread by ID for a specific assistant
63
+ * @param assistantId Assistant identifier
64
+ * @param threadId Thread identifier
65
+ * @returns Thread if found, undefined otherwise
66
+ */
67
+ getThreadById(
68
+ assistantId: string,
69
+ threadId: string
70
+ ): Promise<Thread | undefined>;
71
+
72
+ /**
73
+ * Create a new thread for an assistant
74
+ * @param assistantId Assistant identifier
75
+ * @param threadId Thread identifier
76
+ * @param data Thread creation data
77
+ * @returns Created thread
78
+ */
79
+ createThread(
80
+ assistantId: string,
81
+ threadId: string,
82
+ data: CreateThreadRequest
83
+ ): Promise<Thread>;
84
+
85
+ /**
86
+ * Update an existing thread
87
+ * @param assistantId Assistant identifier
88
+ * @param threadId Thread identifier
89
+ * @param updates Partial thread data to update
90
+ * @returns Updated thread if found, null otherwise
91
+ */
92
+ updateThread(
93
+ assistantId: string,
94
+ threadId: string,
95
+ updates: Partial<CreateThreadRequest>
96
+ ): Promise<Thread | null>;
97
+
98
+ /**
99
+ * Delete a thread by ID
100
+ * @param assistantId Assistant identifier
101
+ * @param threadId Thread identifier
102
+ * @returns true if deleted, false otherwise
103
+ */
104
+ deleteThread(assistantId: string, threadId: string): Promise<boolean>;
105
+
106
+ /**
107
+ * Check if thread exists
108
+ * @param assistantId Assistant identifier
109
+ * @param threadId Thread identifier
110
+ * @returns true if thread exists, false otherwise
111
+ */
112
+ hasThread(assistantId: string, threadId: string): Promise<boolean>;
113
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * VectorStoreLatticeProtocol
3
+ *
4
+ * VectorStore Lattice protocol for defining unified interface for vector store implementations
5
+ */
6
+
7
+ import { VectorStore } from "@langchain/core/vectorstores";
8
+ import { DocumentInterface } from "@langchain/core/documents";
9
+ import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
10
+
11
+ /**
12
+ * VectorStore configuration interface
13
+ */
14
+ export interface VectorStoreConfig {
15
+ name: string; // VectorStore name
16
+ description?: string; // Description of the vector store
17
+ type?: string; // Vector store type (e.g., "pinecone", "chroma", "pgvector")
18
+ config?: Record<string, any>; // Configuration for the vector store
19
+ }
20
+
21
+ /**
22
+ * VectorStore Lattice protocol interface
23
+ */
24
+ export interface VectorStoreLatticeProtocol
25
+ extends BaseLatticeProtocol<VectorStoreConfig, VectorStore> {
26
+ // Add precomputed vectors and documents
27
+ addVectors: (
28
+ vectors: number[][],
29
+ documents: DocumentInterface[],
30
+ options?: Record<string, any>
31
+ ) => Promise<string[] | void>;
32
+
33
+ // Add documents (will be embedded automatically)
34
+ addDocuments: (
35
+ documents: DocumentInterface[],
36
+ options?: Record<string, any>
37
+ ) => Promise<string[] | void>;
38
+
39
+ // Delete documents by parameters
40
+ delete: (params?: Record<string, any>) => Promise<void>;
41
+
42
+ // Similarity search with vector query
43
+ similaritySearchVectorWithScore: (
44
+ query: number[],
45
+ k: number,
46
+ filter?: VectorStore["FilterType"]
47
+ ) => Promise<[DocumentInterface, number][]>;
48
+
49
+ // Similarity search with text query
50
+ similaritySearch: (
51
+ query: string,
52
+ k?: number,
53
+ filter?: VectorStore["FilterType"]
54
+ ) => Promise<DocumentInterface[]>;
55
+
56
+ // Similarity search with text query and scores
57
+ similaritySearchWithScore: (
58
+ query: string,
59
+ k?: number,
60
+ filter?: VectorStore["FilterType"]
61
+ ) => Promise<[DocumentInterface, number][]>;
62
+
63
+ // Maximal marginal relevance search (optional)
64
+ maxMarginalRelevanceSearch?: (
65
+ query: string,
66
+ options: {
67
+ k: number;
68
+ fetchK?: number;
69
+ lambda?: number;
70
+ filter?: VectorStore["FilterType"];
71
+ }
72
+ ) => Promise<DocumentInterface[]>;
73
+ }
package/src/index.ts CHANGED
@@ -9,10 +9,14 @@ export * from "./ToolLatticeProtocol";
9
9
  export * from "./ModelLatticeProtocol";
10
10
  export * from "./AgentLatticeProtocol";
11
11
  export * from "./MemoryLatticeProtocol";
12
- export * from "./StorageLatticeProtocol";
13
12
  export * from "./UILatticeProtocol";
14
13
  export * from "./QueueLatticeProtocol";
14
+ export * from "./ScheduleLatticeProtocol";
15
+ export * from "./EmbeddingsLatticeProtocol";
16
+ export * from "./VectorStoreLatticeProtocol";
15
17
  export * from "./MessageProtocol";
18
+ export * from "./ThreadStoreProtocol";
19
+ export * from "./AssistantStoreProtocol";
16
20
 
17
21
  // 导出通用类型
18
22
  export * from "./types";
@@ -1,55 +0,0 @@
1
- /**
2
- * StorageLatticeProtocol
3
- *
4
- * 存储Lattice的协议,用于数据持久化和状态管理
5
- */
6
-
7
- import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
8
-
9
- /**
10
- * 存储类型枚举
11
- */
12
- export enum StorageType {
13
- MEMORY = "memory",
14
- LOCAL = "local",
15
- DATABASE = "database",
16
- CLOUD = "cloud",
17
- DISTRIBUTED = "distributed",
18
- }
19
-
20
- /**
21
- * 存储配置接口
22
- */
23
- export interface StorageConfig {
24
- name: string; // 名称
25
- description: string; // 描述
26
- type: StorageType; // 存储类型
27
- connectionString?: string; // 连接字符串
28
- options?: Record<string, any>; // 其他选项
29
- }
30
-
31
- /**
32
- * 存储客户端接口
33
- */
34
- export interface StorageClient {
35
- set: (key: string, value: any) => Promise<void>;
36
- get: (key: string) => Promise<any>;
37
- has: (key: string) => Promise<boolean>;
38
- delete: (key: string) => Promise<boolean>;
39
- clear: () => Promise<void>;
40
- transaction: <T>(operations: () => Promise<T>) => Promise<T>;
41
- }
42
-
43
- /**
44
- * 存储Lattice协议接口
45
- */
46
- export interface StorageLatticeProtocol
47
- extends BaseLatticeProtocol<StorageConfig, StorageClient> {
48
- // 存储操作方法
49
- set: (key: string, value: any) => Promise<void>;
50
- get: (key: string) => Promise<any>;
51
- has: (key: string) => Promise<boolean>;
52
- delete: (key: string) => Promise<boolean>;
53
- clear: () => Promise<void>;
54
- transaction: <T>(operations: () => Promise<T>) => Promise<T>;
55
- }