@axiom-lattice/protocols 2.1.9 → 2.1.11

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,260 @@
1
+ /**
2
+ * McpLatticeProtocol
3
+ *
4
+ * Model Context Protocol (MCP) lattice protocol for integrating MCP servers
5
+ * with the Lattice framework. Provides standardized interfaces for MCP
6
+ * client connections, tool discovery, and remote execution.
7
+ */
8
+
9
+ import { BaseLatticeProtocol, LatticeMessage } from "./BaseLatticeProtocol";
10
+
11
+ /**
12
+ * MCP transport type
13
+ */
14
+ export type McpTransportType = "stdio" | "streamable_http" | "sse";
15
+
16
+ /**
17
+ * MCP server configuration
18
+ */
19
+ export interface McpServerConfig {
20
+ /** Server name */
21
+ name: string;
22
+ /** Server version */
23
+ version: string;
24
+ /** Transport type */
25
+ transport: McpTransportType;
26
+ /** Command for stdio transport (e.g., "npx", "python") */
27
+ command?: string;
28
+ /** Arguments for stdio transport */
29
+ args?: string[];
30
+ /** URL for HTTP/SSE transport */
31
+ url?: string;
32
+ /** Environment variables */
33
+ env?: Record<string, string>;
34
+ /** Connection timeout in milliseconds */
35
+ timeout?: number;
36
+ /** Retry attempts on connection failure */
37
+ retryAttempts?: number;
38
+ }
39
+
40
+ /**
41
+ * MCP tool definition
42
+ */
43
+ export interface McpTool {
44
+ /** Tool name */
45
+ name: string;
46
+ /** Tool description */
47
+ description: string;
48
+ /** Input schema */
49
+ inputSchema: {
50
+ type: "object";
51
+ properties: Record<string, any>;
52
+ required?: string[];
53
+ };
54
+ /** Tool metadata */
55
+ metadata?: Record<string, any>;
56
+ }
57
+
58
+ /**
59
+ * MCP tool call result
60
+ */
61
+ export interface McpToolResult {
62
+ /** Whether the call was successful */
63
+ success: boolean;
64
+ /** Result content */
65
+ content: Array<{
66
+ type: "text" | "image" | "audio" | "resource";
67
+ data: any;
68
+ mimeType?: string;
69
+ }>;
70
+ /** Error message if failed */
71
+ error?: string;
72
+ /** Execution metadata */
73
+ metadata?: {
74
+ duration: number;
75
+ tokens?: number;
76
+ model?: string;
77
+ };
78
+ }
79
+
80
+ /**
81
+ * MCP client interface
82
+ */
83
+ export interface McpClient {
84
+ /** Client name */
85
+ name: string;
86
+ /** Client version */
87
+ version: string;
88
+ /** Server configuration */
89
+ serverConfig: McpServerConfig;
90
+
91
+ /**
92
+ * Connect to MCP server
93
+ */
94
+ connect(): Promise<void>;
95
+
96
+ /**
97
+ * Disconnect from MCP server
98
+ */
99
+ disconnect(): Promise<void>;
100
+
101
+ /**
102
+ * Check if connected
103
+ */
104
+ isConnected(): boolean;
105
+
106
+ /**
107
+ * List available tools
108
+ */
109
+ listTools(): Promise<McpTool[]>;
110
+
111
+ /**
112
+ * Call a tool
113
+ */
114
+ callTool(name: string, arguments_: Record<string, any>): Promise<McpToolResult>;
115
+
116
+ /**
117
+ * Subscribe to server notifications
118
+ */
119
+ subscribe(topic: string, handler: (data: any) => void): void;
120
+
121
+ /**
122
+ * Unsubscribe from server notifications
123
+ */
124
+ unsubscribe(topic: string): void;
125
+
126
+ /**
127
+ * Get client statistics
128
+ */
129
+ getStats(): McpStats;
130
+
131
+ /**
132
+ * Get connection status
133
+ */
134
+ getStatus(): McpConnectionStatus;
135
+ }
136
+
137
+ /**
138
+ * MCP client options
139
+ */
140
+ export interface McpClientOptions {
141
+ /** Client name */
142
+ name: string;
143
+ /** Client version */
144
+ version: string;
145
+ /** Server configuration */
146
+ serverConfig: McpServerConfig;
147
+ /** Auto-connect on initialization */
148
+ autoConnect?: boolean;
149
+ /** Error handler */
150
+ onError?: (error: Error) => void;
151
+ /** Connection status handler */
152
+ onStatusChange?: (status: McpConnectionStatus) => void;
153
+ }
154
+
155
+ /**
156
+ * MCP Lattice protocol interface
157
+ */
158
+ export interface McpLatticeProtocol
159
+ extends BaseLatticeProtocol<McpServerConfig, McpClient> {
160
+ /**
161
+ * Server configuration
162
+ */
163
+ config: McpServerConfig;
164
+
165
+ /**
166
+ * MCP client instance
167
+ */
168
+ client: McpClient;
169
+
170
+ /**
171
+ * Connect to MCP server
172
+ */
173
+ connect(): Promise<void>;
174
+
175
+ /**
176
+ * Disconnect from MCP server
177
+ */
178
+ disconnect(): Promise<void>;
179
+
180
+ /**
181
+ * Get available tools
182
+ */
183
+ getTools(): Promise<McpTool[]>;
184
+
185
+ /**
186
+ * Execute a tool
187
+ */
188
+ executeTool(
189
+ name: string,
190
+ arguments_: Record<string, any>
191
+ ): Promise<McpToolResult>;
192
+
193
+ /**
194
+ * Execute with automatic retries
195
+ */
196
+ executeToolWithRetry(
197
+ name: string,
198
+ arguments_: Record<string, any>,
199
+ maxRetries?: number
200
+ ): Promise<McpToolResult>;
201
+
202
+ /**
203
+ * Get protocol version
204
+ */
205
+ getProtocolVersion(): string;
206
+
207
+ /**
208
+ * Health check
209
+ */
210
+ healthCheck(): Promise<boolean>;
211
+ }
212
+
213
+ /**
214
+ * MCP message types
215
+ */
216
+ export enum McpMessageType {
217
+ CONNECT = "mcp:connect",
218
+ DISCONNECT = "mcp:disconnect",
219
+ LIST_TOOLS = "mcp:list_tools",
220
+ CALL_TOOL = "mcp:call_tool",
221
+ TOOL_RESULT = "mcp:tool_result",
222
+ NOTIFICATION = "mcp:notification",
223
+ ERROR = "mcp:error",
224
+ HEALTH_CHECK = "mcp:health_check",
225
+ }
226
+
227
+ /**
228
+ * MCP Lattice message
229
+ */
230
+ export interface McpLatticeMessage extends LatticeMessage {
231
+ type: McpMessageType;
232
+ payload: {
233
+ toolName?: string;
234
+ arguments?: Record<string, any>;
235
+ result?: McpToolResult;
236
+ tools?: McpTool[];
237
+ error?: string;
238
+ };
239
+ }
240
+
241
+ /**
242
+ * MCP connection status
243
+ */
244
+ export type McpConnectionStatus =
245
+ | "disconnected"
246
+ | "connecting"
247
+ | "connected"
248
+ | "reconnecting"
249
+ | "error";
250
+
251
+ /**
252
+ * MCP statistics
253
+ */
254
+ export interface McpStats {
255
+ totalCalls: number;
256
+ successfulCalls: number;
257
+ failedCalls: number;
258
+ averageLatency: number;
259
+ lastCallTimestamp: number;
260
+ }
@@ -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
@@ -18,6 +18,9 @@ export * from "./LoggerLatticeProtocol";
18
18
  export * from "./MessageProtocol";
19
19
  export * from "./ThreadStoreProtocol";
20
20
  export * from "./AssistantStoreProtocol";
21
+ export * from "./SkillLatticeProtocol";
22
+ export * from "./SkillStoreProtocol";
23
+ export * from "./McpLatticeProtocol";
21
24
 
22
25
  // 导出通用类型
23
26
  export * from "./types";