@axiom-lattice/protocols 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
 
2
- > @axiom-lattice/protocols@2.0.0 build /home/runner/work/agentic/agentic/packages/protocols
2
+ > @axiom-lattice/protocols@2.1.0 build /home/runner/work/agentic/agentic/packages/protocols
3
3
  > tsup src/index.ts --format cjs,esm --dts --sourcemap
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,13 +8,13 @@
8
8
  CLI Target: es2020
9
9
  CJS Build start
10
10
  ESM Build start
11
- CJS dist/index.js 2.67 KB
12
- CJS dist/index.js.map 6.50 KB
13
- CJS ⚡️ Build success in 40ms
14
- ESM dist/index.mjs 1.56 KB
15
- ESM dist/index.mjs.map 5.98 KB
16
- ESM ⚡️ Build success in 41ms
11
+ CJS dist/index.js 3.34 KB
12
+ CJS dist/index.js.map 8.90 KB
13
+ CJS ⚡️ Build success in 38ms
14
+ ESM dist/index.mjs 2.06 KB
15
+ ESM dist/index.mjs.map 8.37 KB
16
+ ESM ⚡️ Build success in 39ms
17
17
  DTS Build start
18
- DTS ⚡️ Build success in 2454ms
19
- DTS dist/index.d.ts 10.37 KB
20
- DTS dist/index.d.mts 10.37 KB
18
+ DTS ⚡️ Build success in 2277ms
19
+ DTS dist/index.d.ts 12.11 KB
20
+ DTS dist/index.d.mts 12.11 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @axiom-lattice/protocols
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a6ec6b6: enhance deepagent and ui
8
+
9
+ ## 2.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 31df9b6: enhance deep agent
14
+
3
15
  ## 2.0.0
4
16
 
5
17
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { StructuredTool } from '@langchain/core/tools';
2
- import z, { ZodSchema } from 'zod';
2
+ import { ZodSchema, ZodObject } from 'zod';
3
3
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
4
4
  import { BaseMessage as BaseMessage$1 } from '@langchain/core/messages';
5
5
  import { ChatResult } from '@langchain/core/outputs';
@@ -123,19 +123,70 @@ declare enum AgentType {
123
123
  SEQUENTIAL = "sequential"
124
124
  }
125
125
  /**
126
- * 智能体配置接口
126
+ * Base agent configuration shared by all agent types
127
127
  */
128
- interface AgentConfig {
128
+ interface BaseAgentConfig {
129
129
  key: string;
130
130
  name: string;
131
131
  description: string;
132
- type: AgentType;
133
- tools?: string[];
134
- subAgents?: string[];
135
132
  prompt: string;
136
- schema?: z.ZodObject<any, any, any, any, any>;
133
+ schema?: ZodObject<any, any, any, any, any>;
137
134
  modelKey?: string;
138
135
  }
136
+ /**
137
+ * REACT agent configuration
138
+ */
139
+ interface ReactAgentConfig extends BaseAgentConfig {
140
+ type: AgentType.REACT;
141
+ tools?: string[];
142
+ }
143
+ /**
144
+ * DEEP_AGENT configuration - only this type supports subAgents
145
+ */
146
+ interface DeepAgentConfig extends BaseAgentConfig {
147
+ type: AgentType.DEEP_AGENT;
148
+ tools?: string[];
149
+ subAgents?: string[];
150
+ internalSubAgents?: AgentConfig[];
151
+ }
152
+ /**
153
+ * PLAN_EXECUTE agent configuration
154
+ */
155
+ interface PlanExecuteAgentConfig extends BaseAgentConfig {
156
+ type: AgentType.PLAN_EXECUTE;
157
+ tools?: string[];
158
+ }
159
+ /**
160
+ * SEQUENTIAL agent configuration
161
+ */
162
+ interface SequentialAgentConfig extends BaseAgentConfig {
163
+ type: AgentType.SEQUENTIAL;
164
+ }
165
+ /**
166
+ * Agent configuration union type
167
+ * Different agent types have different configuration options
168
+ */
169
+ type AgentConfig = ReactAgentConfig | DeepAgentConfig | PlanExecuteAgentConfig | SequentialAgentConfig;
170
+ /**
171
+ * Agent configuration with tools property
172
+ */
173
+ type AgentConfigWithTools = ReactAgentConfig | DeepAgentConfig | PlanExecuteAgentConfig;
174
+ /**
175
+ * Type guard to check if config has tools property
176
+ */
177
+ declare function hasTools(config: AgentConfig): config is AgentConfigWithTools;
178
+ /**
179
+ * Type guard to check if config is DeepAgentConfig (has subAgents)
180
+ */
181
+ declare function isDeepAgentConfig(config: AgentConfig): config is DeepAgentConfig;
182
+ /**
183
+ * Get tools from config safely
184
+ */
185
+ declare function getToolsFromConfig(config: AgentConfig): string[];
186
+ /**
187
+ * Get subAgents from config safely (only DeepAgentConfig has subAgents)
188
+ */
189
+ declare function getSubAgentsFromConfig(config: AgentConfig): string[];
139
190
  /**
140
191
  * 智能体客户端类型
141
192
  */
@@ -465,4 +516,4 @@ type Timestamp = number;
465
516
  */
466
517
  type Callback<T = any, R = void> = (data: T) => R | Promise<R>;
467
518
 
468
- export { type AgentClient, type AgentConfig, type AgentLatticeProtocol, AgentType, type AssistantMessage, type BaseLatticeProtocol, type BaseMessage, type Callback, type DeveloperMessage, type FilterCondition, type GraphBuildOptions, type ID, 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 QueryParams, type Result, type StorageClient, type StorageConfig, type StorageLatticeProtocol, StorageType, type SystemMessage, type Timestamp, type ToolCall, type ToolConfig, type ToolExecutor, type ToolLatticeProtocol, type ToolMessage, type UIComponent, UIComponentType, type UIConfig, type UILatticeProtocol, type UserMessage };
519
+ export { type AgentClient, type AgentConfig, type AgentConfigWithTools, type AgentLatticeProtocol, AgentType, type AssistantMessage, type BaseLatticeProtocol, type BaseMessage, type Callback, type DeepAgentConfig, type DeveloperMessage, type FilterCondition, type GraphBuildOptions, type ID, 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 ReactAgentConfig, type Result, type SequentialAgentConfig, type StorageClient, type StorageConfig, type StorageLatticeProtocol, StorageType, type SystemMessage, type Timestamp, type ToolCall, type ToolConfig, type ToolExecutor, type ToolLatticeProtocol, type ToolMessage, type UIComponent, UIComponentType, type UIConfig, type UILatticeProtocol, type UserMessage, getSubAgentsFromConfig, getToolsFromConfig, hasTools, isDeepAgentConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { StructuredTool } from '@langchain/core/tools';
2
- import z, { ZodSchema } from 'zod';
2
+ import { ZodSchema, ZodObject } from 'zod';
3
3
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
4
4
  import { BaseMessage as BaseMessage$1 } from '@langchain/core/messages';
5
5
  import { ChatResult } from '@langchain/core/outputs';
@@ -123,19 +123,70 @@ declare enum AgentType {
123
123
  SEQUENTIAL = "sequential"
124
124
  }
125
125
  /**
126
- * 智能体配置接口
126
+ * Base agent configuration shared by all agent types
127
127
  */
128
- interface AgentConfig {
128
+ interface BaseAgentConfig {
129
129
  key: string;
130
130
  name: string;
131
131
  description: string;
132
- type: AgentType;
133
- tools?: string[];
134
- subAgents?: string[];
135
132
  prompt: string;
136
- schema?: z.ZodObject<any, any, any, any, any>;
133
+ schema?: ZodObject<any, any, any, any, any>;
137
134
  modelKey?: string;
138
135
  }
136
+ /**
137
+ * REACT agent configuration
138
+ */
139
+ interface ReactAgentConfig extends BaseAgentConfig {
140
+ type: AgentType.REACT;
141
+ tools?: string[];
142
+ }
143
+ /**
144
+ * DEEP_AGENT configuration - only this type supports subAgents
145
+ */
146
+ interface DeepAgentConfig extends BaseAgentConfig {
147
+ type: AgentType.DEEP_AGENT;
148
+ tools?: string[];
149
+ subAgents?: string[];
150
+ internalSubAgents?: AgentConfig[];
151
+ }
152
+ /**
153
+ * PLAN_EXECUTE agent configuration
154
+ */
155
+ interface PlanExecuteAgentConfig extends BaseAgentConfig {
156
+ type: AgentType.PLAN_EXECUTE;
157
+ tools?: string[];
158
+ }
159
+ /**
160
+ * SEQUENTIAL agent configuration
161
+ */
162
+ interface SequentialAgentConfig extends BaseAgentConfig {
163
+ type: AgentType.SEQUENTIAL;
164
+ }
165
+ /**
166
+ * Agent configuration union type
167
+ * Different agent types have different configuration options
168
+ */
169
+ type AgentConfig = ReactAgentConfig | DeepAgentConfig | PlanExecuteAgentConfig | SequentialAgentConfig;
170
+ /**
171
+ * Agent configuration with tools property
172
+ */
173
+ type AgentConfigWithTools = ReactAgentConfig | DeepAgentConfig | PlanExecuteAgentConfig;
174
+ /**
175
+ * Type guard to check if config has tools property
176
+ */
177
+ declare function hasTools(config: AgentConfig): config is AgentConfigWithTools;
178
+ /**
179
+ * Type guard to check if config is DeepAgentConfig (has subAgents)
180
+ */
181
+ declare function isDeepAgentConfig(config: AgentConfig): config is DeepAgentConfig;
182
+ /**
183
+ * Get tools from config safely
184
+ */
185
+ declare function getToolsFromConfig(config: AgentConfig): string[];
186
+ /**
187
+ * Get subAgents from config safely (only DeepAgentConfig has subAgents)
188
+ */
189
+ declare function getSubAgentsFromConfig(config: AgentConfig): string[];
139
190
  /**
140
191
  * 智能体客户端类型
141
192
  */
@@ -465,4 +516,4 @@ type Timestamp = number;
465
516
  */
466
517
  type Callback<T = any, R = void> = (data: T) => R | Promise<R>;
467
518
 
468
- export { type AgentClient, type AgentConfig, type AgentLatticeProtocol, AgentType, type AssistantMessage, type BaseLatticeProtocol, type BaseMessage, type Callback, type DeveloperMessage, type FilterCondition, type GraphBuildOptions, type ID, 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 QueryParams, type Result, type StorageClient, type StorageConfig, type StorageLatticeProtocol, StorageType, type SystemMessage, type Timestamp, type ToolCall, type ToolConfig, type ToolExecutor, type ToolLatticeProtocol, type ToolMessage, type UIComponent, UIComponentType, type UIConfig, type UILatticeProtocol, type UserMessage };
519
+ export { type AgentClient, type AgentConfig, type AgentConfigWithTools, type AgentLatticeProtocol, AgentType, type AssistantMessage, type BaseLatticeProtocol, type BaseMessage, type Callback, type DeepAgentConfig, type DeveloperMessage, type FilterCondition, type GraphBuildOptions, type ID, 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 ReactAgentConfig, type Result, type SequentialAgentConfig, type StorageClient, type StorageConfig, type StorageLatticeProtocol, StorageType, type SystemMessage, type Timestamp, type ToolCall, type ToolConfig, type ToolExecutor, type ToolLatticeProtocol, type ToolMessage, type UIComponent, UIComponentType, type UIConfig, type UILatticeProtocol, type UserMessage, getSubAgentsFromConfig, getToolsFromConfig, hasTools, isDeepAgentConfig };
package/dist/index.js CHANGED
@@ -23,7 +23,11 @@ __export(index_exports, {
23
23
  AgentType: () => AgentType,
24
24
  MemoryType: () => MemoryType,
25
25
  StorageType: () => StorageType,
26
- UIComponentType: () => UIComponentType
26
+ UIComponentType: () => UIComponentType,
27
+ getSubAgentsFromConfig: () => getSubAgentsFromConfig,
28
+ getToolsFromConfig: () => getToolsFromConfig,
29
+ hasTools: () => hasTools,
30
+ isDeepAgentConfig: () => isDeepAgentConfig
27
31
  });
28
32
  module.exports = __toCommonJS(index_exports);
29
33
 
@@ -35,6 +39,24 @@ var AgentType = /* @__PURE__ */ ((AgentType2) => {
35
39
  AgentType2["SEQUENTIAL"] = "sequential";
36
40
  return AgentType2;
37
41
  })(AgentType || {});
42
+ function hasTools(config) {
43
+ return config.type !== "sequential" /* SEQUENTIAL */;
44
+ }
45
+ function isDeepAgentConfig(config) {
46
+ return config.type === "deep_agent" /* DEEP_AGENT */;
47
+ }
48
+ function getToolsFromConfig(config) {
49
+ if (hasTools(config)) {
50
+ return config.tools || [];
51
+ }
52
+ return [];
53
+ }
54
+ function getSubAgentsFromConfig(config) {
55
+ if (isDeepAgentConfig(config)) {
56
+ return config.subAgents || [];
57
+ }
58
+ return [];
59
+ }
38
60
 
39
61
  // src/MemoryLatticeProtocol.ts
40
62
  var MemoryType = /* @__PURE__ */ ((MemoryType2) => {
@@ -75,6 +97,10 @@ var UIComponentType = /* @__PURE__ */ ((UIComponentType2) => {
75
97
  AgentType,
76
98
  MemoryType,
77
99
  StorageType,
78
- UIComponentType
100
+ UIComponentType,
101
+ getSubAgentsFromConfig,
102
+ getToolsFromConfig,
103
+ hasTools,
104
+ isDeepAgentConfig
79
105
  });
80
106
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/AgentLatticeProtocol.ts","../src/MemoryLatticeProtocol.ts","../src/StorageLatticeProtocol.ts","../src/UILatticeProtocol.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 \"./StorageLatticeProtocol\";\nexport * from \"./UILatticeProtocol\";\nexport * from \"./MessageProtocol\";\n\n// 导出通用类型\nexport * from \"./types\";\n","/**\n * AgentLatticeProtocol\n *\n * 智能体Lattice的协议,定义了智能体的行为和组合方式\n */\n\nimport { CompiledStateGraph } from \"@langchain/langgraph\";\nimport z, { 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 * 智能体配置接口\n */\nexport interface AgentConfig {\n key: string; // 唯一键\n name: string; // 名称\n description: string; // 描述\n type: AgentType; // 智能体类型\n tools?: string[]; // 使用的工具列表\n subAgents?: string[]; // 子智能体列表\n prompt: string; // 提示词\n schema?: z.ZodObject<any, any, any, any, any>; // 输入验证模式\n modelKey?: string; // 使用的模型键\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 * StorageLatticeProtocol\n *\n * 存储Lattice的协议,用于数据持久化和状态管理\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 存储类型枚举\n */\nexport enum StorageType {\n MEMORY = \"memory\",\n LOCAL = \"local\",\n DATABASE = \"database\",\n CLOUD = \"cloud\",\n DISTRIBUTED = \"distributed\",\n}\n\n/**\n * 存储配置接口\n */\nexport interface StorageConfig {\n name: string; // 名称\n description: string; // 描述\n type: StorageType; // 存储类型\n connectionString?: string; // 连接字符串\n options?: Record<string, any>; // 其他选项\n}\n\n/**\n * 存储客户端接口\n */\nexport interface StorageClient {\n set: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n has: (key: string) => Promise<boolean>;\n delete: (key: string) => Promise<boolean>;\n clear: () => Promise<void>;\n transaction: <T>(operations: () => Promise<T>) => Promise<T>;\n}\n\n/**\n * 存储Lattice协议接口\n */\nexport interface StorageLatticeProtocol\n extends BaseLatticeProtocol<StorageConfig, StorageClient> {\n // 存储操作方法\n set: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n has: (key: string) => Promise<boolean>;\n delete: (key: string) => Promise<boolean>;\n clear: () => Promise<void>;\n transaction: <T>(operations: () => Promise<T>) => Promise<T>;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;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;;;ACFL,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,cAAL,kBAAKC,iBAAL;AACL,EAAAA,aAAA,YAAS;AACT,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,cAAW;AACX,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,iBAAc;AALJ,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;","names":["AgentType","MemoryType","StorageType","UIComponentType"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/AgentLatticeProtocol.ts","../src/MemoryLatticeProtocol.ts","../src/StorageLatticeProtocol.ts","../src/UILatticeProtocol.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 \"./StorageLatticeProtocol\";\nexport * from \"./UILatticeProtocol\";\nexport * from \"./MessageProtocol\";\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 * StorageLatticeProtocol\n *\n * 存储Lattice的协议,用于数据持久化和状态管理\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 存储类型枚举\n */\nexport enum StorageType {\n MEMORY = \"memory\",\n LOCAL = \"local\",\n DATABASE = \"database\",\n CLOUD = \"cloud\",\n DISTRIBUTED = \"distributed\",\n}\n\n/**\n * 存储配置接口\n */\nexport interface StorageConfig {\n name: string; // 名称\n description: string; // 描述\n type: StorageType; // 存储类型\n connectionString?: string; // 连接字符串\n options?: Record<string, any>; // 其他选项\n}\n\n/**\n * 存储客户端接口\n */\nexport interface StorageClient {\n set: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n has: (key: string) => Promise<boolean>;\n delete: (key: string) => Promise<boolean>;\n clear: () => Promise<void>;\n transaction: <T>(operations: () => Promise<T>) => Promise<T>;\n}\n\n/**\n * 存储Lattice协议接口\n */\nexport interface StorageLatticeProtocol\n extends BaseLatticeProtocol<StorageConfig, StorageClient> {\n // 存储操作方法\n set: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n has: (key: string) => Promise<boolean>;\n delete: (key: string) => Promise<boolean>;\n clear: () => Promise<void>;\n transaction: <T>(operations: () => Promise<T>) => Promise<T>;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;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,cAAL,kBAAKC,iBAAL;AACL,EAAAA,aAAA,YAAS;AACT,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,cAAW;AACX,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,iBAAc;AALJ,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;","names":["AgentType","MemoryType","StorageType","UIComponentType"]}
package/dist/index.mjs CHANGED
@@ -6,6 +6,24 @@ var AgentType = /* @__PURE__ */ ((AgentType2) => {
6
6
  AgentType2["SEQUENTIAL"] = "sequential";
7
7
  return AgentType2;
8
8
  })(AgentType || {});
9
+ function hasTools(config) {
10
+ return config.type !== "sequential" /* SEQUENTIAL */;
11
+ }
12
+ function isDeepAgentConfig(config) {
13
+ return config.type === "deep_agent" /* DEEP_AGENT */;
14
+ }
15
+ function getToolsFromConfig(config) {
16
+ if (hasTools(config)) {
17
+ return config.tools || [];
18
+ }
19
+ return [];
20
+ }
21
+ function getSubAgentsFromConfig(config) {
22
+ if (isDeepAgentConfig(config)) {
23
+ return config.subAgents || [];
24
+ }
25
+ return [];
26
+ }
9
27
 
10
28
  // src/MemoryLatticeProtocol.ts
11
29
  var MemoryType = /* @__PURE__ */ ((MemoryType2) => {
@@ -45,6 +63,10 @@ export {
45
63
  AgentType,
46
64
  MemoryType,
47
65
  StorageType,
48
- UIComponentType
66
+ UIComponentType,
67
+ getSubAgentsFromConfig,
68
+ getToolsFromConfig,
69
+ hasTools,
70
+ isDeepAgentConfig
49
71
  };
50
72
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/AgentLatticeProtocol.ts","../src/MemoryLatticeProtocol.ts","../src/StorageLatticeProtocol.ts","../src/UILatticeProtocol.ts"],"sourcesContent":["/**\n * AgentLatticeProtocol\n *\n * 智能体Lattice的协议,定义了智能体的行为和组合方式\n */\n\nimport { CompiledStateGraph } from \"@langchain/langgraph\";\nimport z, { 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 * 智能体配置接口\n */\nexport interface AgentConfig {\n key: string; // 唯一键\n name: string; // 名称\n description: string; // 描述\n type: AgentType; // 智能体类型\n tools?: string[]; // 使用的工具列表\n subAgents?: string[]; // 子智能体列表\n prompt: string; // 提示词\n schema?: z.ZodObject<any, any, any, any, any>; // 输入验证模式\n modelKey?: string; // 使用的模型键\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 * StorageLatticeProtocol\n *\n * 存储Lattice的协议,用于数据持久化和状态管理\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 存储类型枚举\n */\nexport enum StorageType {\n MEMORY = \"memory\",\n LOCAL = \"local\",\n DATABASE = \"database\",\n CLOUD = \"cloud\",\n DISTRIBUTED = \"distributed\",\n}\n\n/**\n * 存储配置接口\n */\nexport interface StorageConfig {\n name: string; // 名称\n description: string; // 描述\n type: StorageType; // 存储类型\n connectionString?: string; // 连接字符串\n options?: Record<string, any>; // 其他选项\n}\n\n/**\n * 存储客户端接口\n */\nexport interface StorageClient {\n set: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n has: (key: string) => Promise<boolean>;\n delete: (key: string) => Promise<boolean>;\n clear: () => Promise<void>;\n transaction: <T>(operations: () => Promise<T>) => Promise<T>;\n}\n\n/**\n * 存储Lattice协议接口\n */\nexport interface StorageLatticeProtocol\n extends BaseLatticeProtocol<StorageConfig, StorageClient> {\n // 存储操作方法\n set: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n has: (key: string) => Promise<boolean>;\n delete: (key: string) => Promise<boolean>;\n clear: () => Promise<void>;\n transaction: <T>(operations: () => Promise<T>) => Promise<T>;\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"],"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;;;ACFL,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,cAAL,kBAAKC,iBAAL;AACL,EAAAA,aAAA,YAAS;AACT,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,cAAW;AACX,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,iBAAc;AALJ,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;","names":["AgentType","MemoryType","StorageType","UIComponentType"]}
1
+ {"version":3,"sources":["../src/AgentLatticeProtocol.ts","../src/MemoryLatticeProtocol.ts","../src/StorageLatticeProtocol.ts","../src/UILatticeProtocol.ts"],"sourcesContent":["/**\n * AgentLatticeProtocol\n *\n * 智能体Lattice的协议,定义了智能体的行为和组合方式\n */\n\nimport { CompiledStateGraph } from \"@langchain/langgraph\";\nimport z, { ZodObject, ZodSchema } from \"zod\";\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 智能体类型枚举\n */\nexport enum AgentType {\n REACT = \"react\",\n DEEP_AGENT = \"deep_agent\",\n PLAN_EXECUTE = \"plan_execute\",\n SEQUENTIAL = \"sequential\",\n}\n\n/**\n * Base agent configuration shared by all agent types\n */\ninterface BaseAgentConfig {\n key: string; // Unique key\n name: string; // Name\n description: string; // Description\n prompt: string; // Prompt\n schema?: ZodObject<any, any, any, any, any>; // Input validation schema\n modelKey?: string; // Model key to use\n}\n\n/**\n * REACT agent configuration\n */\nexport interface ReactAgentConfig extends BaseAgentConfig {\n type: AgentType.REACT;\n tools?: string[]; // Tool list\n}\n\n/**\n * DEEP_AGENT configuration - only this type supports subAgents\n */\nexport interface DeepAgentConfig extends BaseAgentConfig {\n type: AgentType.DEEP_AGENT;\n tools?: string[]; // Tool list\n subAgents?: string[]; // Sub-agent list (unique to DEEP_AGENT)\n internalSubAgents?: AgentConfig[]; // Internal sub-agent list (unique to DEEP_AGENT)\n}\n\n/**\n * PLAN_EXECUTE agent configuration\n */\nexport interface PlanExecuteAgentConfig extends BaseAgentConfig {\n type: AgentType.PLAN_EXECUTE;\n tools?: string[]; // Tool list\n}\n\n/**\n * SEQUENTIAL agent configuration\n */\nexport interface SequentialAgentConfig extends BaseAgentConfig {\n type: AgentType.SEQUENTIAL;\n}\n\n/**\n * Agent configuration union type\n * Different agent types have different configuration options\n */\nexport type AgentConfig =\n | ReactAgentConfig\n | DeepAgentConfig\n | PlanExecuteAgentConfig\n | SequentialAgentConfig;\n\n/**\n * Agent configuration with tools property\n */\nexport type AgentConfigWithTools =\n | ReactAgentConfig\n | DeepAgentConfig\n | PlanExecuteAgentConfig;\n\n/**\n * Type guard to check if config has tools property\n */\nexport function hasTools(config: AgentConfig): config is AgentConfigWithTools {\n return config.type !== AgentType.SEQUENTIAL;\n}\n\n/**\n * Type guard to check if config is DeepAgentConfig (has subAgents)\n */\nexport function isDeepAgentConfig(\n config: AgentConfig\n): config is DeepAgentConfig {\n return config.type === AgentType.DEEP_AGENT;\n}\n\n/**\n * Get tools from config safely\n */\nexport function getToolsFromConfig(config: AgentConfig): string[] {\n if (hasTools(config)) {\n return config.tools || [];\n }\n return [];\n}\n\n/**\n * Get subAgents from config safely (only DeepAgentConfig has subAgents)\n */\nexport function getSubAgentsFromConfig(config: AgentConfig): string[] {\n if (isDeepAgentConfig(config)) {\n return config.subAgents || [];\n }\n return [];\n}\n\n/**\n * 智能体客户端类型\n */\nexport type AgentClient = CompiledStateGraph<any, any, any, any, any>;\n\n/**\n * Graph构建选项\n */\nexport interface GraphBuildOptions {\n overrideTools?: string[];\n overrideModel?: string;\n metadata?: Record<string, any>;\n}\n\n/**\n * 智能体Lattice协议接口\n */\nexport interface AgentLatticeProtocol\n extends BaseLatticeProtocol<AgentConfig, AgentClient> {\n // 智能体执行函数\n invoke: (input: any, options?: any) => Promise<any>;\n\n // 构建智能体图\n buildGraph: (options?: GraphBuildOptions) => Promise<AgentClient>;\n}\n","/**\n * MemoryLatticeProtocol\n *\n * 记忆Lattice的协议,用于管理智能体的上下文和记忆\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 记忆类型枚举\n */\nexport enum MemoryType {\n SHORT_TERM = \"short_term\",\n LONG_TERM = \"long_term\",\n EPISODIC = \"episodic\",\n SEMANTIC = \"semantic\",\n WORKING = \"working\",\n}\n\n/**\n * 记忆配置接口\n */\nexport interface MemoryConfig {\n name: string; // 名称\n description: string; // 描述\n type: MemoryType; // 记忆类型\n ttl?: number; // 生存时间\n capacity?: number; // 容量限制\n}\n\n/**\n * 记忆客户端接口\n */\nexport interface MemoryClient {\n add: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n update: (key: string, value: any) => Promise<void>;\n delete: (key: string) => Promise<void>;\n search: (query: string, options?: any) => Promise<any[]>;\n clear: () => Promise<void>;\n}\n\n/**\n * 记忆Lattice协议接口\n */\nexport interface MemoryLatticeProtocol\n extends BaseLatticeProtocol<MemoryConfig, MemoryClient> {\n // 记忆操作方法\n add: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n update: (key: string, value: any) => Promise<void>;\n delete: (key: string) => Promise<void>;\n search: (query: string, options?: any) => Promise<any[]>;\n clear: () => Promise<void>;\n}\n","/**\n * StorageLatticeProtocol\n *\n * 存储Lattice的协议,用于数据持久化和状态管理\n */\n\nimport { BaseLatticeProtocol } from \"./BaseLatticeProtocol\";\n\n/**\n * 存储类型枚举\n */\nexport enum StorageType {\n MEMORY = \"memory\",\n LOCAL = \"local\",\n DATABASE = \"database\",\n CLOUD = \"cloud\",\n DISTRIBUTED = \"distributed\",\n}\n\n/**\n * 存储配置接口\n */\nexport interface StorageConfig {\n name: string; // 名称\n description: string; // 描述\n type: StorageType; // 存储类型\n connectionString?: string; // 连接字符串\n options?: Record<string, any>; // 其他选项\n}\n\n/**\n * 存储客户端接口\n */\nexport interface StorageClient {\n set: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n has: (key: string) => Promise<boolean>;\n delete: (key: string) => Promise<boolean>;\n clear: () => Promise<void>;\n transaction: <T>(operations: () => Promise<T>) => Promise<T>;\n}\n\n/**\n * 存储Lattice协议接口\n */\nexport interface StorageLatticeProtocol\n extends BaseLatticeProtocol<StorageConfig, StorageClient> {\n // 存储操作方法\n set: (key: string, value: any) => Promise<void>;\n get: (key: string) => Promise<any>;\n has: (key: string) => Promise<boolean>;\n delete: (key: string) => Promise<boolean>;\n clear: () => Promise<void>;\n transaction: <T>(operations: () => Promise<T>) => Promise<T>;\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"],"mappings":";AAaO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,gBAAa;AACb,EAAAA,WAAA,kBAAe;AACf,EAAAA,WAAA,gBAAa;AAJH,SAAAA;AAAA,GAAA;AAyEL,SAAS,SAAS,QAAqD;AAC5E,SAAO,OAAO,SAAS;AACzB;AAKO,SAAS,kBACd,QAC2B;AAC3B,SAAO,OAAO,SAAS;AACzB;AAKO,SAAS,mBAAmB,QAA+B;AAChE,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO,OAAO,SAAS,CAAC;AAAA,EAC1B;AACA,SAAO,CAAC;AACV;AAKO,SAAS,uBAAuB,QAA+B;AACpE,MAAI,kBAAkB,MAAM,GAAG;AAC7B,WAAO,OAAO,aAAa,CAAC;AAAA,EAC9B;AACA,SAAO,CAAC;AACV;;;AC1GO,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,eAAY;AACZ,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,aAAU;AALA,SAAAA;AAAA,GAAA;;;ACAL,IAAK,cAAL,kBAAKC,iBAAL;AACL,EAAAA,aAAA,YAAS;AACT,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,cAAW;AACX,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,iBAAc;AALJ,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;","names":["AgentType","MemoryType","StorageType","UIComponentType"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiom-lattice/protocols",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Unified protocol type definitions for Axiom Lattice framework",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -21,9 +21,9 @@
21
21
  "author": "",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@langchain/core": "^0.3.72",
25
- "@langchain/langgraph": "^0.4.6",
26
- "zod": "^3.24.2"
24
+ "@langchain/core": "1.1.4",
25
+ "@langchain/langgraph": "1.0.4",
26
+ "zod": "3.25.76"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/jest": "^29.5.12",
@@ -34,9 +34,9 @@
34
34
  "typescript": "^5.4.2"
35
35
  },
36
36
  "peerDependencies": {
37
- "@langchain/core": "^0.3.72",
38
- "@langchain/langgraph": "^0.4.6",
39
- "zod": "^3.24.2"
37
+ "@langchain/core": "1.1.4",
38
+ "@langchain/langgraph": "1.0.4",
39
+ "zod": "3.25.76"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsup src/index.ts --format cjs,esm --dts --sourcemap",
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { CompiledStateGraph } from "@langchain/langgraph";
8
- import z, { ZodSchema } from "zod";
8
+ import z, { ZodObject, ZodSchema } from "zod";
9
9
  import { BaseLatticeProtocol } from "./BaseLatticeProtocol";
10
10
 
11
11
  /**
@@ -19,18 +19,102 @@ export enum AgentType {
19
19
  }
20
20
 
21
21
  /**
22
- * 智能体配置接口
22
+ * Base agent configuration shared by all agent types
23
23
  */
24
- export interface AgentConfig {
25
- key: string; // 唯一键
26
- name: string; // 名称
27
- description: string; // 描述
28
- type: AgentType; // 智能体类型
29
- tools?: string[]; // 使用的工具列表
30
- subAgents?: string[]; // 子智能体列表
31
- prompt: string; // 提示词
32
- schema?: z.ZodObject<any, any, any, any, any>; // 输入验证模式
33
- modelKey?: string; // 使用的模型键
24
+ interface BaseAgentConfig {
25
+ key: string; // Unique key
26
+ name: string; // Name
27
+ description: string; // Description
28
+ prompt: string; // Prompt
29
+ schema?: ZodObject<any, any, any, any, any>; // Input validation schema
30
+ modelKey?: string; // Model key to use
31
+ }
32
+
33
+ /**
34
+ * REACT agent configuration
35
+ */
36
+ export interface ReactAgentConfig extends BaseAgentConfig {
37
+ type: AgentType.REACT;
38
+ tools?: string[]; // Tool list
39
+ }
40
+
41
+ /**
42
+ * DEEP_AGENT configuration - only this type supports subAgents
43
+ */
44
+ export interface DeepAgentConfig extends BaseAgentConfig {
45
+ type: AgentType.DEEP_AGENT;
46
+ tools?: string[]; // Tool list
47
+ subAgents?: string[]; // Sub-agent list (unique to DEEP_AGENT)
48
+ internalSubAgents?: AgentConfig[]; // Internal sub-agent list (unique to DEEP_AGENT)
49
+ }
50
+
51
+ /**
52
+ * PLAN_EXECUTE agent configuration
53
+ */
54
+ export interface PlanExecuteAgentConfig extends BaseAgentConfig {
55
+ type: AgentType.PLAN_EXECUTE;
56
+ tools?: string[]; // Tool list
57
+ }
58
+
59
+ /**
60
+ * SEQUENTIAL agent configuration
61
+ */
62
+ export interface SequentialAgentConfig extends BaseAgentConfig {
63
+ type: AgentType.SEQUENTIAL;
64
+ }
65
+
66
+ /**
67
+ * Agent configuration union type
68
+ * Different agent types have different configuration options
69
+ */
70
+ export type AgentConfig =
71
+ | ReactAgentConfig
72
+ | DeepAgentConfig
73
+ | PlanExecuteAgentConfig
74
+ | SequentialAgentConfig;
75
+
76
+ /**
77
+ * Agent configuration with tools property
78
+ */
79
+ export type AgentConfigWithTools =
80
+ | ReactAgentConfig
81
+ | DeepAgentConfig
82
+ | PlanExecuteAgentConfig;
83
+
84
+ /**
85
+ * Type guard to check if config has tools property
86
+ */
87
+ export function hasTools(config: AgentConfig): config is AgentConfigWithTools {
88
+ return config.type !== AgentType.SEQUENTIAL;
89
+ }
90
+
91
+ /**
92
+ * Type guard to check if config is DeepAgentConfig (has subAgents)
93
+ */
94
+ export function isDeepAgentConfig(
95
+ config: AgentConfig
96
+ ): config is DeepAgentConfig {
97
+ return config.type === AgentType.DEEP_AGENT;
98
+ }
99
+
100
+ /**
101
+ * Get tools from config safely
102
+ */
103
+ export function getToolsFromConfig(config: AgentConfig): string[] {
104
+ if (hasTools(config)) {
105
+ return config.tools || [];
106
+ }
107
+ return [];
108
+ }
109
+
110
+ /**
111
+ * Get subAgents from config safely (only DeepAgentConfig has subAgents)
112
+ */
113
+ export function getSubAgentsFromConfig(config: AgentConfig): string[] {
114
+ if (isDeepAgentConfig(config)) {
115
+ return config.subAgents || [];
116
+ }
117
+ return [];
34
118
  }
35
119
 
36
120
  /**
@@ -1,183 +0,0 @@
1
- /**
2
- * MessageProtocol Example
3
- *
4
- * Demonstrates how to use MessageProtocol for message interaction
5
- */
6
-
7
- import {
8
- Message,
9
- UserMessage,
10
- AssistantMessage,
11
- SystemMessage,
12
- ToolMessage,
13
- ToolCall,
14
- MessageEventType,
15
- MessagesSnapshotEvent,
16
- } from "../MessageProtocol";
17
-
18
- // Example 1: Basic message interaction
19
- function basicMessageExample() {
20
- // Create a simple conversation
21
- const conversation: Message[] = [
22
- // System message
23
- {
24
- id: "sys_1",
25
- role: "system",
26
- content: "You are a helpful AI assistant.",
27
- },
28
-
29
- // User message
30
- {
31
- id: "user_1",
32
- role: "user",
33
- content: "Can you help me check the weather in New York?",
34
- },
35
-
36
- // Assistant message (with tool call)
37
- {
38
- id: "asst_1",
39
- role: "assistant",
40
- content: "Let me check the weather for you.",
41
- toolCalls: [
42
- {
43
- id: "tool_call_1",
44
- type: "function",
45
- function: {
46
- name: "get_weather",
47
- arguments: '{"location": "New York", "unit": "celsius"}',
48
- },
49
- },
50
- ],
51
- },
52
-
53
- // Tool message (tool execution result)
54
- {
55
- id: "tool_1",
56
- role: "tool",
57
- content:
58
- '{"temperature": 22, "condition": "Partly Cloudy", "humidity": 65}',
59
- toolCallId: "tool_call_1",
60
- },
61
-
62
- // Assistant final response
63
- {
64
- id: "asst_2",
65
- role: "assistant",
66
- content:
67
- "The weather in New York is partly cloudy with a temperature of 22°C and 65% humidity.",
68
- },
69
- ];
70
-
71
- return conversation;
72
- }
73
-
74
- // Example 2: Message conversion (vendor neutrality)
75
- function vendorNeutralityExample() {
76
- const agUiMessages = basicMessageExample();
77
-
78
- // Convert to OpenAI format
79
- const openaiMessages = agUiMessages
80
- .filter((msg) => ["user", "system", "assistant"].includes(msg.role))
81
- .map((msg) => ({
82
- role: msg.role as "user" | "system" | "assistant",
83
- content: msg.content || "",
84
- // Map tool calls if present
85
- ...(msg.role === "assistant" && (msg as AssistantMessage).toolCalls
86
- ? {
87
- tool_calls: (msg as AssistantMessage).toolCalls?.map((tc) => ({
88
- id: tc.id,
89
- type: tc.type,
90
- function: {
91
- name: tc.function.name,
92
- arguments: tc.function.arguments,
93
- },
94
- })),
95
- }
96
- : {}),
97
- }));
98
-
99
- return { agUiMessages, openaiMessages };
100
- }
101
-
102
- // Example 3: Message event handling
103
- function messageEventsExample() {
104
- // Message snapshot event
105
- const snapshotEvent: MessagesSnapshotEvent = {
106
- type: MessageEventType.MESSAGES_SNAPSHOT,
107
- messages: basicMessageExample(),
108
- };
109
-
110
- // Handle events
111
- function handleEvent(event: any) {
112
- switch (event.type) {
113
- case MessageEventType.MESSAGES_SNAPSHOT:
114
- console.log(
115
- "Received message snapshot with",
116
- event.messages.length,
117
- "messages"
118
- );
119
- break;
120
- case MessageEventType.TEXT_MESSAGE_START:
121
- console.log(
122
- "New message started:",
123
- event.messageId,
124
- "role:",
125
- event.role
126
- );
127
- break;
128
- case MessageEventType.TEXT_MESSAGE_CONTENT:
129
- console.log("Message content:", event.messageId, "delta:", event.delta);
130
- break;
131
- case MessageEventType.TEXT_MESSAGE_END:
132
- console.log("Message ended:", event.messageId);
133
- break;
134
- // Other event handling...
135
- }
136
- }
137
-
138
- // Simulate event handling
139
- handleEvent(snapshotEvent);
140
- }
141
-
142
- // Example 4: Streaming message handling
143
- function streamingMessageExample() {
144
- // Simulate streaming message processing
145
- const messageId = "stream_msg_1";
146
- const chunks = [
147
- "Hello",
148
- ", I am ",
149
- "an AI assistant",
150
- ". How ",
151
- "can I help ",
152
- "you today?",
153
- ];
154
-
155
- // Start message
156
- console.log({
157
- type: MessageEventType.TEXT_MESSAGE_START,
158
- messageId,
159
- role: "assistant",
160
- });
161
-
162
- // Stream content
163
- chunks.forEach((chunk) => {
164
- console.log({
165
- type: MessageEventType.TEXT_MESSAGE_CONTENT,
166
- messageId,
167
- delta: chunk,
168
- });
169
- });
170
-
171
- // End message
172
- console.log({
173
- type: MessageEventType.TEXT_MESSAGE_END,
174
- messageId,
175
- });
176
- }
177
-
178
- export {
179
- basicMessageExample,
180
- vendorNeutralityExample,
181
- messageEventsExample,
182
- streamingMessageExample,
183
- };