@juspay/neurolink 9.82.0 → 9.84.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.
- package/CHANGELOG.md +18 -0
- package/dist/agent/agent.d.ts +104 -0
- package/dist/agent/agent.js +401 -0
- package/dist/agent/agentNetwork.d.ts +87 -0
- package/dist/agent/agentNetwork.js +458 -0
- package/dist/agent/communication/index.d.ts +9 -0
- package/dist/agent/communication/index.js +9 -0
- package/dist/agent/communication/message-bus.d.ts +113 -0
- package/dist/agent/communication/message-bus.js +406 -0
- package/dist/agent/coordination/coordinator.d.ts +83 -0
- package/dist/agent/coordination/coordinator.js +598 -0
- package/dist/agent/coordination/index.d.ts +10 -0
- package/dist/agent/coordination/index.js +10 -0
- package/dist/agent/coordination/task-distributor.d.ts +113 -0
- package/dist/agent/coordination/task-distributor.js +585 -0
- package/dist/agent/index.d.ts +38 -0
- package/dist/agent/index.js +44 -0
- package/dist/agent/orchestration/index.d.ts +10 -0
- package/dist/agent/orchestration/index.js +10 -0
- package/dist/agent/orchestration/orchestrator.d.ts +114 -0
- package/dist/agent/orchestration/orchestrator.js +476 -0
- package/dist/agent/orchestration/topology.d.ts +164 -0
- package/dist/agent/orchestration/topology.js +520 -0
- package/dist/agent/prompts/routingPrompts.d.ts +63 -0
- package/dist/agent/prompts/routingPrompts.js +201 -0
- package/dist/browser/neurolink.min.js +377 -358
- package/dist/cli/commands/agent.d.ts +37 -0
- package/dist/cli/commands/agent.js +718 -0
- package/dist/cli/factories/commandFactory.d.ts +8 -0
- package/dist/cli/factories/commandFactory.js +116 -0
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/cli/parser.js +4 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +19 -0
- package/dist/lib/agent/agent.d.ts +104 -0
- package/dist/lib/agent/agent.js +402 -0
- package/dist/lib/agent/agentNetwork.d.ts +87 -0
- package/dist/lib/agent/agentNetwork.js +459 -0
- package/dist/lib/agent/communication/index.d.ts +9 -0
- package/dist/lib/agent/communication/index.js +10 -0
- package/dist/lib/agent/communication/message-bus.d.ts +113 -0
- package/dist/lib/agent/communication/message-bus.js +407 -0
- package/dist/lib/agent/coordination/coordinator.d.ts +83 -0
- package/dist/lib/agent/coordination/coordinator.js +599 -0
- package/dist/lib/agent/coordination/index.d.ts +10 -0
- package/dist/lib/agent/coordination/index.js +11 -0
- package/dist/lib/agent/coordination/task-distributor.d.ts +113 -0
- package/dist/lib/agent/coordination/task-distributor.js +586 -0
- package/dist/lib/agent/index.d.ts +38 -0
- package/dist/lib/agent/index.js +45 -0
- package/dist/lib/agent/orchestration/index.d.ts +10 -0
- package/dist/lib/agent/orchestration/index.js +11 -0
- package/dist/lib/agent/orchestration/orchestrator.d.ts +114 -0
- package/dist/lib/agent/orchestration/orchestrator.js +477 -0
- package/dist/lib/agent/orchestration/topology.d.ts +164 -0
- package/dist/lib/agent/orchestration/topology.js +521 -0
- package/dist/lib/agent/prompts/routingPrompts.d.ts +63 -0
- package/dist/lib/agent/prompts/routingPrompts.js +202 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.js +19 -0
- package/dist/lib/neurolink.d.ts +129 -0
- package/dist/lib/neurolink.js +276 -0
- package/dist/lib/processors/config/{fileTypes.js → fileExtensions.js} +1 -1
- package/dist/lib/processors/config/index.d.ts +2 -2
- package/dist/lib/processors/config/index.js +2 -2
- package/dist/lib/processors/config/{mimeTypes.js → mimeConstants.js} +1 -1
- package/dist/lib/processors/index.js +8 -0
- package/dist/lib/providers/googleAiStudio.js +28 -7
- package/dist/lib/providers/googleNativeGemini3.d.ts +18 -0
- package/dist/lib/providers/googleNativeGemini3.js +69 -3
- package/dist/lib/providers/googleVertex.js +33 -9
- package/dist/lib/types/agentNetwork.d.ts +1184 -0
- package/dist/lib/types/agentNetwork.js +8 -0
- package/dist/lib/types/cli.d.ts +66 -0
- package/dist/lib/types/common.d.ts +3 -0
- package/dist/lib/types/generate.d.ts +53 -0
- package/dist/lib/types/index.d.ts +2 -0
- package/dist/lib/types/index.js +3 -0
- package/dist/lib/types/ioProcessor.d.ts +119 -0
- package/dist/lib/types/ioProcessor.js +10 -0
- package/dist/lib/types/providers.d.ts +8 -0
- package/dist/lib/types/stream.d.ts +36 -0
- package/dist/lib/utils/piiDetector.d.ts +24 -0
- package/dist/lib/utils/piiDetector.js +221 -0
- package/dist/lib/utils/pricing.js +144 -26
- package/dist/lib/utils/responseValidator.d.ts +21 -0
- package/dist/lib/utils/responseValidator.js +354 -0
- package/dist/lib/utils/tokenUtils.d.ts +11 -0
- package/dist/lib/utils/tokenUtils.js +33 -2
- package/dist/lib/utils/tripwireEvaluator.d.ts +73 -0
- package/dist/lib/utils/tripwireEvaluator.js +285 -0
- package/dist/neurolink.d.ts +129 -0
- package/dist/neurolink.js +276 -0
- package/dist/processors/config/index.d.ts +2 -2
- package/dist/processors/config/index.js +2 -2
- package/dist/processors/index.js +8 -0
- package/dist/providers/googleAiStudio.js +28 -7
- package/dist/providers/googleNativeGemini3.d.ts +18 -0
- package/dist/providers/googleNativeGemini3.js +69 -3
- package/dist/providers/googleVertex.js +33 -9
- package/dist/types/agentNetwork.d.ts +1184 -0
- package/dist/types/agentNetwork.js +7 -0
- package/dist/types/cli.d.ts +66 -0
- package/dist/types/common.d.ts +3 -0
- package/dist/types/generate.d.ts +53 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +3 -0
- package/dist/types/ioProcessor.d.ts +119 -0
- package/dist/types/ioProcessor.js +9 -0
- package/dist/types/providers.d.ts +8 -0
- package/dist/types/stream.d.ts +36 -0
- package/dist/utils/piiDetector.d.ts +24 -0
- package/dist/utils/piiDetector.js +220 -0
- package/dist/utils/pricing.js +144 -26
- package/dist/utils/responseValidator.d.ts +21 -0
- package/dist/utils/responseValidator.js +353 -0
- package/dist/utils/tokenUtils.d.ts +11 -0
- package/dist/utils/tokenUtils.js +33 -2
- package/dist/utils/tripwireEvaluator.d.ts +73 -0
- package/dist/utils/tripwireEvaluator.js +284 -0
- package/package.json +1 -1
- /package/dist/lib/processors/config/{fileTypes.d.ts → fileExtensions.d.ts} +0 -0
- /package/dist/lib/processors/config/{mimeTypes.d.ts → mimeConstants.d.ts} +0 -0
- /package/dist/processors/config/{fileTypes.d.ts → fileExtensions.d.ts} +0 -0
- /package/dist/processors/config/{fileTypes.js → fileExtensions.js} +0 -0
- /package/dist/processors/config/{mimeTypes.d.ts → mimeConstants.d.ts} +0 -0
- /package/dist/processors/config/{mimeTypes.js → mimeConstants.js} +0 -0
|
@@ -0,0 +1,1184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Network Types for Multi-Agent Orchestration
|
|
3
|
+
*
|
|
4
|
+
* These types define the core abstractions for NeuroLink's multi-agent system,
|
|
5
|
+
* enabling intelligent routing, agent collaboration, and hierarchical networks.
|
|
6
|
+
*/
|
|
7
|
+
import type { z } from "zod";
|
|
8
|
+
import type { AIProviderName } from "../constants/enums.js";
|
|
9
|
+
import type { TokenUsage } from "./analytics.js";
|
|
10
|
+
/**
|
|
11
|
+
* Agent definition for creating agents in the network
|
|
12
|
+
*/
|
|
13
|
+
export type AgentDefinition = {
|
|
14
|
+
/** Unique identifier for the agent */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Human-readable name */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Description of the agent's capabilities (critical for routing) */
|
|
19
|
+
description: string;
|
|
20
|
+
/** System instructions for the agent */
|
|
21
|
+
instructions: string;
|
|
22
|
+
/** Provider to use for this agent */
|
|
23
|
+
provider?: AIProviderName | string;
|
|
24
|
+
/** Model to use for this agent */
|
|
25
|
+
model?: string;
|
|
26
|
+
/** Tools available to this agent (tool names) */
|
|
27
|
+
tools?: string[];
|
|
28
|
+
/** Input schema for structured agent input */
|
|
29
|
+
inputSchema?: z.ZodSchema;
|
|
30
|
+
/** Output schema for structured agent output */
|
|
31
|
+
outputSchema?: z.ZodSchema;
|
|
32
|
+
/** Maximum number of steps this agent can take (default: 10) */
|
|
33
|
+
maxSteps?: number;
|
|
34
|
+
/** Temperature for generation (default: 0.7) */
|
|
35
|
+
temperature?: number;
|
|
36
|
+
/** Whether this agent can delegate to other agents (default: false) */
|
|
37
|
+
canDelegate?: boolean;
|
|
38
|
+
/** Custom metadata for routing decisions */
|
|
39
|
+
metadata?: Record<string, unknown>;
|
|
40
|
+
/** Per-agent credentials override */
|
|
41
|
+
credentials?: Record<string, unknown>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Agent input - can be a string or structured data
|
|
45
|
+
*/
|
|
46
|
+
export type AgentInput = string | Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Result of agent execution
|
|
49
|
+
*/
|
|
50
|
+
export type AgentResult = {
|
|
51
|
+
/** Generated content */
|
|
52
|
+
content: string;
|
|
53
|
+
/** Structured output if schema was provided */
|
|
54
|
+
object?: unknown;
|
|
55
|
+
/** Token usage for this execution */
|
|
56
|
+
usage?: TokenUsage;
|
|
57
|
+
/** Tools used during execution */
|
|
58
|
+
toolsUsed?: string[];
|
|
59
|
+
/** Detailed tool execution info */
|
|
60
|
+
toolExecutions?: Array<{
|
|
61
|
+
name: string;
|
|
62
|
+
input: Record<string, unknown>;
|
|
63
|
+
output: unknown;
|
|
64
|
+
duration: number;
|
|
65
|
+
}>;
|
|
66
|
+
/** Execution duration in milliseconds */
|
|
67
|
+
duration: number;
|
|
68
|
+
/** Execution status */
|
|
69
|
+
status: "success" | "error";
|
|
70
|
+
/** Error message if status is error */
|
|
71
|
+
error?: string;
|
|
72
|
+
/** Agent ID that produced this result */
|
|
73
|
+
agentId: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Options for agent execution
|
|
77
|
+
*/
|
|
78
|
+
export type AgentExecutionOptions = {
|
|
79
|
+
/** Additional context for the agent */
|
|
80
|
+
context?: Record<string, unknown>;
|
|
81
|
+
/** Override max steps for this execution */
|
|
82
|
+
maxSteps?: number;
|
|
83
|
+
/** Trace ID for observability */
|
|
84
|
+
traceId?: string;
|
|
85
|
+
/** Parent span ID for nested tracing */
|
|
86
|
+
parentSpanId?: string;
|
|
87
|
+
/** Timeout in milliseconds */
|
|
88
|
+
timeout?: number;
|
|
89
|
+
/** Per-execution credentials override */
|
|
90
|
+
credentials?: Record<string, unknown>;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Agent status information
|
|
94
|
+
*/
|
|
95
|
+
export type AgentStatus = {
|
|
96
|
+
/** Agent ID */
|
|
97
|
+
id: string;
|
|
98
|
+
/** Agent name */
|
|
99
|
+
name: string;
|
|
100
|
+
/** Number of executions */
|
|
101
|
+
executionCount: number;
|
|
102
|
+
/** Last execution time in ms */
|
|
103
|
+
lastExecutionTime?: number;
|
|
104
|
+
/** Whether agent is available */
|
|
105
|
+
available: boolean;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Types of primitives that can be orchestrated in the network
|
|
109
|
+
*/
|
|
110
|
+
export type NetworkPrimitiveType = "agent" | "workflow" | "tool";
|
|
111
|
+
/**
|
|
112
|
+
* Base primitive type for all orchestrable components
|
|
113
|
+
*/
|
|
114
|
+
export type NetworkPrimitive = {
|
|
115
|
+
/** Unique identifier */
|
|
116
|
+
id: string;
|
|
117
|
+
/** Type of primitive */
|
|
118
|
+
type: NetworkPrimitiveType;
|
|
119
|
+
/** Human-readable name */
|
|
120
|
+
name: string;
|
|
121
|
+
/** Description for routing decisions */
|
|
122
|
+
description: string;
|
|
123
|
+
/** Input schema for validation */
|
|
124
|
+
inputSchema?: z.ZodSchema;
|
|
125
|
+
/** Output schema for validation */
|
|
126
|
+
outputSchema?: z.ZodSchema;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Agent as a network primitive
|
|
130
|
+
*/
|
|
131
|
+
export type AgentPrimitive = NetworkPrimitive & {
|
|
132
|
+
type: "agent";
|
|
133
|
+
/** The agent instance */
|
|
134
|
+
agent: AgentInstance;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Workflow definition for network integration
|
|
138
|
+
*/
|
|
139
|
+
export type NetworkWorkflow = {
|
|
140
|
+
/** Execute the workflow with given input */
|
|
141
|
+
execute(input: unknown): Promise<{
|
|
142
|
+
output: unknown;
|
|
143
|
+
}>;
|
|
144
|
+
/** Optional streaming support */
|
|
145
|
+
stream?(input: unknown): AsyncIterable<unknown>;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Workflow definition config
|
|
149
|
+
*/
|
|
150
|
+
export type NetworkWorkflowDefinition = {
|
|
151
|
+
id: string;
|
|
152
|
+
name: string;
|
|
153
|
+
description: string;
|
|
154
|
+
inputSchema?: z.ZodSchema;
|
|
155
|
+
outputSchema?: z.ZodSchema;
|
|
156
|
+
workflow: NetworkWorkflow;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Workflow as a network primitive
|
|
160
|
+
*/
|
|
161
|
+
export type WorkflowPrimitive = NetworkPrimitive & {
|
|
162
|
+
type: "workflow";
|
|
163
|
+
/** The workflow instance */
|
|
164
|
+
workflow: NetworkWorkflow;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Tool info for network integration
|
|
168
|
+
*/
|
|
169
|
+
export type NetworkToolInfo = {
|
|
170
|
+
name: string;
|
|
171
|
+
description?: string;
|
|
172
|
+
inputSchema?: unknown;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Tool as a network primitive
|
|
176
|
+
*/
|
|
177
|
+
export type ToolPrimitive = NetworkPrimitive & {
|
|
178
|
+
type: "tool";
|
|
179
|
+
/** Tool information */
|
|
180
|
+
tool: NetworkToolInfo;
|
|
181
|
+
/** Execute the tool */
|
|
182
|
+
execute: (args: unknown, context?: AgentExecutionContext) => Promise<unknown>;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Union type for all primitives
|
|
186
|
+
*/
|
|
187
|
+
export type Primitive = AgentPrimitive | WorkflowPrimitive | ToolPrimitive;
|
|
188
|
+
/**
|
|
189
|
+
* Configuration for creating an agent network
|
|
190
|
+
*/
|
|
191
|
+
export type AgentNetworkConfig = {
|
|
192
|
+
/** Unique identifier for the network (auto-generated if not provided) */
|
|
193
|
+
id?: string;
|
|
194
|
+
/** Human-readable name */
|
|
195
|
+
name: string;
|
|
196
|
+
/** Description of the network's purpose */
|
|
197
|
+
description?: string;
|
|
198
|
+
/** Agents in the network */
|
|
199
|
+
agents: AgentDefinition[];
|
|
200
|
+
/** Workflows available in the network */
|
|
201
|
+
workflows?: NetworkWorkflowDefinition[];
|
|
202
|
+
/** Additional tools available to all agents (tool names) */
|
|
203
|
+
tools?: string[];
|
|
204
|
+
/** Routing agent configuration */
|
|
205
|
+
router?: RouterConfig;
|
|
206
|
+
/** Default execution options */
|
|
207
|
+
defaults?: NetworkDefaults;
|
|
208
|
+
/** Memory configuration for the network */
|
|
209
|
+
memory?: NetworkMemoryConfig;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Router configuration
|
|
213
|
+
*/
|
|
214
|
+
export type RouterConfig = {
|
|
215
|
+
/** Provider for the routing agent */
|
|
216
|
+
provider?: AIProviderName | string;
|
|
217
|
+
/** Model for the routing agent */
|
|
218
|
+
model?: string;
|
|
219
|
+
/** Custom routing instructions */
|
|
220
|
+
instructions?: string;
|
|
221
|
+
/** Maximum routing attempts before fallback */
|
|
222
|
+
maxAttempts?: number;
|
|
223
|
+
/** Confidence threshold for routing (0-1) */
|
|
224
|
+
confidenceThreshold?: number;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Memory configuration for the network
|
|
228
|
+
*/
|
|
229
|
+
export type NetworkMemoryConfig = {
|
|
230
|
+
/** Enable shared memory across agents */
|
|
231
|
+
shared?: boolean;
|
|
232
|
+
/** Memory provider */
|
|
233
|
+
provider?: "in-memory" | "redis";
|
|
234
|
+
/** Memory TTL in seconds */
|
|
235
|
+
ttl?: number;
|
|
236
|
+
/** Maximum messages to retain */
|
|
237
|
+
maxMessages?: number;
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Default execution options for the network
|
|
241
|
+
*/
|
|
242
|
+
export type NetworkDefaults = {
|
|
243
|
+
/** Maximum steps per execution */
|
|
244
|
+
maxSteps?: number;
|
|
245
|
+
/** Timeout in milliseconds */
|
|
246
|
+
timeout?: number;
|
|
247
|
+
/** Default temperature */
|
|
248
|
+
temperature?: number;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Execution context passed to primitives
|
|
252
|
+
*/
|
|
253
|
+
export type AgentExecutionContext = {
|
|
254
|
+
/** Session ID for memory */
|
|
255
|
+
sessionId?: string;
|
|
256
|
+
/** Trace ID for observability */
|
|
257
|
+
traceId?: string;
|
|
258
|
+
/** Parent span ID */
|
|
259
|
+
parentSpanId?: string;
|
|
260
|
+
/** Additional context data */
|
|
261
|
+
[key: string]: unknown;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Input for network execution
|
|
265
|
+
*/
|
|
266
|
+
export type NetworkExecutionInput = {
|
|
267
|
+
/** The task or message to process */
|
|
268
|
+
message: string | CoreMessage[];
|
|
269
|
+
/** Thread ID for conversation context */
|
|
270
|
+
threadId?: string;
|
|
271
|
+
/** User/resource identifier */
|
|
272
|
+
resourceId?: string;
|
|
273
|
+
/** Additional context */
|
|
274
|
+
context?: Record<string, unknown>;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Core message format (simplified)
|
|
278
|
+
*/
|
|
279
|
+
export type CoreMessage = {
|
|
280
|
+
role: "user" | "assistant" | "system";
|
|
281
|
+
content: string;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Options for network execution
|
|
285
|
+
*/
|
|
286
|
+
export type NetworkExecutionOptions = {
|
|
287
|
+
/** Maximum execution steps across the network */
|
|
288
|
+
maxSteps?: number;
|
|
289
|
+
/** Timeout in milliseconds */
|
|
290
|
+
timeout?: number;
|
|
291
|
+
/** Enable streaming */
|
|
292
|
+
stream?: boolean;
|
|
293
|
+
/** Additional context */
|
|
294
|
+
context?: Record<string, unknown>;
|
|
295
|
+
/** Tracing configuration */
|
|
296
|
+
tracing?: {
|
|
297
|
+
enabled?: boolean;
|
|
298
|
+
traceId?: string;
|
|
299
|
+
parentSpanId?: string;
|
|
300
|
+
};
|
|
301
|
+
/** Model settings override */
|
|
302
|
+
modelSettings?: {
|
|
303
|
+
temperature?: number;
|
|
304
|
+
maxTokens?: number;
|
|
305
|
+
topP?: number;
|
|
306
|
+
};
|
|
307
|
+
/** Output schema for structured output */
|
|
308
|
+
outputSchema?: z.ZodSchema;
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Result of network execution
|
|
312
|
+
*/
|
|
313
|
+
export type NetworkExecutionResult = {
|
|
314
|
+
/** Final output content */
|
|
315
|
+
content: string;
|
|
316
|
+
/** Structured output if schema was provided */
|
|
317
|
+
object?: unknown;
|
|
318
|
+
/** Execution trace */
|
|
319
|
+
trace: NetworkExecutionTrace;
|
|
320
|
+
/** Token usage across all agents */
|
|
321
|
+
usage: NetworkTokenUsage;
|
|
322
|
+
/** Execution status */
|
|
323
|
+
status: NetworkExecutionStatus;
|
|
324
|
+
/** Time taken in milliseconds */
|
|
325
|
+
duration: number;
|
|
326
|
+
/** Error message if status is error */
|
|
327
|
+
error?: string;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* Execution trace for debugging and monitoring
|
|
331
|
+
*/
|
|
332
|
+
export type NetworkExecutionTrace = {
|
|
333
|
+
/** Unique trace ID */
|
|
334
|
+
traceId: string;
|
|
335
|
+
/** Steps taken during execution */
|
|
336
|
+
steps: NetworkExecutionStep[];
|
|
337
|
+
/** Routing decisions made */
|
|
338
|
+
routingDecisions: AgentRoutingDecision[];
|
|
339
|
+
/** Start timestamp */
|
|
340
|
+
startTime: number;
|
|
341
|
+
/** End timestamp */
|
|
342
|
+
endTime?: number;
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Single execution step in the trace
|
|
346
|
+
*/
|
|
347
|
+
export type NetworkExecutionStep = {
|
|
348
|
+
/** Step index */
|
|
349
|
+
index: number;
|
|
350
|
+
/** Primitive that was executed */
|
|
351
|
+
primitive: {
|
|
352
|
+
type: NetworkPrimitiveType;
|
|
353
|
+
id: string;
|
|
354
|
+
name: string;
|
|
355
|
+
};
|
|
356
|
+
/** Input to the primitive */
|
|
357
|
+
input: unknown;
|
|
358
|
+
/** Output from the primitive */
|
|
359
|
+
output?: unknown;
|
|
360
|
+
/** Error if step failed */
|
|
361
|
+
error?: string;
|
|
362
|
+
/** Duration in milliseconds */
|
|
363
|
+
duration: number;
|
|
364
|
+
/** Token usage for this step */
|
|
365
|
+
usage?: TokenUsage;
|
|
366
|
+
/** Timestamp */
|
|
367
|
+
timestamp: number;
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* Routing decision record
|
|
371
|
+
*/
|
|
372
|
+
export type AgentRoutingDecision = {
|
|
373
|
+
/** Step at which decision was made */
|
|
374
|
+
stepIndex: number;
|
|
375
|
+
/** Task description analyzed */
|
|
376
|
+
taskDescription: string;
|
|
377
|
+
/** Selected primitive */
|
|
378
|
+
selectedPrimitive: {
|
|
379
|
+
type: NetworkPrimitiveType;
|
|
380
|
+
id: string;
|
|
381
|
+
name: string;
|
|
382
|
+
};
|
|
383
|
+
/** Confidence score (0-1) */
|
|
384
|
+
confidence: number;
|
|
385
|
+
/** Reasoning for the decision */
|
|
386
|
+
reasoning: string;
|
|
387
|
+
/** Alternative primitives considered */
|
|
388
|
+
alternatives?: Array<{
|
|
389
|
+
type: NetworkPrimitiveType;
|
|
390
|
+
id: string;
|
|
391
|
+
confidence: number;
|
|
392
|
+
}>;
|
|
393
|
+
/** Formatted input for the selected primitive */
|
|
394
|
+
formattedInput?: string;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Token usage aggregated across the network
|
|
398
|
+
*/
|
|
399
|
+
export type NetworkTokenUsage = {
|
|
400
|
+
/** Total prompt tokens */
|
|
401
|
+
promptTokens: number;
|
|
402
|
+
/** Total completion tokens */
|
|
403
|
+
completionTokens: number;
|
|
404
|
+
/** Total tokens */
|
|
405
|
+
totalTokens: number;
|
|
406
|
+
/** Breakdown by agent */
|
|
407
|
+
byAgent?: Record<string, {
|
|
408
|
+
promptTokens: number;
|
|
409
|
+
completionTokens: number;
|
|
410
|
+
totalTokens: number;
|
|
411
|
+
}>;
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* Execution status enum
|
|
415
|
+
*/
|
|
416
|
+
export type NetworkExecutionStatus = "pending" | "running" | "completed" | "error" | "suspended";
|
|
417
|
+
/**
|
|
418
|
+
* Result from executing a primitive
|
|
419
|
+
*/
|
|
420
|
+
export type PrimitiveExecutionResult = {
|
|
421
|
+
/** Output from the primitive */
|
|
422
|
+
output: unknown;
|
|
423
|
+
/** Error message if execution failed */
|
|
424
|
+
error?: string;
|
|
425
|
+
/** Token usage */
|
|
426
|
+
usage?: TokenUsage;
|
|
427
|
+
/** Execution duration in ms */
|
|
428
|
+
duration?: number;
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* Interface for agent instances
|
|
432
|
+
*/
|
|
433
|
+
export type AgentInstance = {
|
|
434
|
+
/** Agent ID */
|
|
435
|
+
readonly id: string;
|
|
436
|
+
/** Agent name */
|
|
437
|
+
readonly name: string;
|
|
438
|
+
/** Agent description */
|
|
439
|
+
readonly description: string;
|
|
440
|
+
/** Agent instructions */
|
|
441
|
+
readonly instructions: string;
|
|
442
|
+
/** Execute the agent */
|
|
443
|
+
execute(input: AgentInput, options?: AgentExecutionOptions): Promise<AgentResult>;
|
|
444
|
+
/** Stream execution results */
|
|
445
|
+
stream(input: AgentInput, options?: AgentExecutionOptions): AsyncIterable<AgentStreamChunk>;
|
|
446
|
+
/** Get agent status */
|
|
447
|
+
getStatus(): AgentStatus;
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Agent-specific streaming chunk types
|
|
451
|
+
*/
|
|
452
|
+
export type AgentStreamChunkType = "agent-start" | "agent-thinking" | "agent-text" | "agent-tool-call" | "agent-tool-result" | "agent-complete" | "agent-error";
|
|
453
|
+
/**
|
|
454
|
+
* Agent stream chunk
|
|
455
|
+
*/
|
|
456
|
+
export type AgentStreamChunk = {
|
|
457
|
+
/** Chunk type */
|
|
458
|
+
type: AgentStreamChunkType;
|
|
459
|
+
/** Agent ID */
|
|
460
|
+
agentId: string;
|
|
461
|
+
/** Timestamp */
|
|
462
|
+
timestamp: number;
|
|
463
|
+
/** Trace ID */
|
|
464
|
+
traceId: string;
|
|
465
|
+
/** Content (for text chunks) */
|
|
466
|
+
content?: string;
|
|
467
|
+
/** Whether content is partial (for text chunks) */
|
|
468
|
+
isPartial?: boolean;
|
|
469
|
+
/** Token usage (for complete chunks) */
|
|
470
|
+
usage?: TokenUsage;
|
|
471
|
+
/** Duration in ms (for complete chunks) */
|
|
472
|
+
duration?: number;
|
|
473
|
+
/** Error message (for error chunks) */
|
|
474
|
+
error?: string;
|
|
475
|
+
/** Tool name (for tool chunks) */
|
|
476
|
+
toolName?: string;
|
|
477
|
+
/** Tool call ID (for tool chunks) */
|
|
478
|
+
toolCallId?: string;
|
|
479
|
+
/** Tool arguments (for tool call chunks) */
|
|
480
|
+
args?: unknown;
|
|
481
|
+
/** Tool result (for tool result chunks) */
|
|
482
|
+
result?: unknown;
|
|
483
|
+
/** Whether tool succeeded (for tool result chunks) */
|
|
484
|
+
success?: boolean;
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* Network streaming chunk types
|
|
488
|
+
*/
|
|
489
|
+
export type NetworkStreamChunkType = "network-start" | "routing-start" | "routing-decision" | "routing-end" | "primitive-start" | "primitive-progress" | "primitive-end" | "agent-thinking" | "agent-text" | "agent-tool-call" | "agent-tool-result" | "workflow-step" | "network-progress" | "network-complete" | "network-error";
|
|
490
|
+
/**
|
|
491
|
+
* Base streaming chunk with common fields
|
|
492
|
+
*/
|
|
493
|
+
export type NetworkStreamChunkBase = {
|
|
494
|
+
/** Chunk type */
|
|
495
|
+
type: NetworkStreamChunkType;
|
|
496
|
+
/** Timestamp */
|
|
497
|
+
timestamp: number;
|
|
498
|
+
/** Trace ID */
|
|
499
|
+
traceId: string;
|
|
500
|
+
/** Current step index */
|
|
501
|
+
stepIndex?: number;
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Network start event
|
|
505
|
+
*/
|
|
506
|
+
export type NetworkStartChunk = NetworkStreamChunkBase & {
|
|
507
|
+
type: "network-start";
|
|
508
|
+
networkId: string;
|
|
509
|
+
input: string;
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* Routing decision event
|
|
513
|
+
*/
|
|
514
|
+
export type RoutingDecisionChunk = NetworkStreamChunkBase & {
|
|
515
|
+
type: "routing-decision";
|
|
516
|
+
decision: AgentRoutingDecision;
|
|
517
|
+
};
|
|
518
|
+
/**
|
|
519
|
+
* Primitive start event
|
|
520
|
+
*/
|
|
521
|
+
export type PrimitiveStartChunk = NetworkStreamChunkBase & {
|
|
522
|
+
type: "primitive-start";
|
|
523
|
+
primitive: {
|
|
524
|
+
type: NetworkPrimitiveType;
|
|
525
|
+
id: string;
|
|
526
|
+
name: string;
|
|
527
|
+
};
|
|
528
|
+
input: unknown;
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* Primitive end event
|
|
532
|
+
*/
|
|
533
|
+
export type PrimitiveEndChunk = NetworkStreamChunkBase & {
|
|
534
|
+
type: "primitive-end";
|
|
535
|
+
primitive: {
|
|
536
|
+
type: NetworkPrimitiveType;
|
|
537
|
+
id: string;
|
|
538
|
+
name: string;
|
|
539
|
+
};
|
|
540
|
+
output: unknown;
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* Agent text generation event
|
|
544
|
+
*/
|
|
545
|
+
export type AgentTextChunk = NetworkStreamChunkBase & {
|
|
546
|
+
type: "agent-text";
|
|
547
|
+
agentId: string;
|
|
548
|
+
content: string;
|
|
549
|
+
isPartial: boolean;
|
|
550
|
+
};
|
|
551
|
+
/**
|
|
552
|
+
* Agent tool call event
|
|
553
|
+
*/
|
|
554
|
+
export type AgentToolCallChunk = NetworkStreamChunkBase & {
|
|
555
|
+
type: "agent-tool-call";
|
|
556
|
+
agentId: string;
|
|
557
|
+
toolName: string;
|
|
558
|
+
args: unknown;
|
|
559
|
+
toolCallId: string;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Agent tool result event
|
|
563
|
+
*/
|
|
564
|
+
export type AgentToolResultChunk = NetworkStreamChunkBase & {
|
|
565
|
+
type: "agent-tool-result";
|
|
566
|
+
agentId: string;
|
|
567
|
+
toolName: string;
|
|
568
|
+
toolCallId: string;
|
|
569
|
+
result: unknown;
|
|
570
|
+
success: boolean;
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* Network complete event
|
|
574
|
+
*/
|
|
575
|
+
export type NetworkCompleteChunk = NetworkStreamChunkBase & {
|
|
576
|
+
type: "network-complete";
|
|
577
|
+
result: NetworkExecutionResult;
|
|
578
|
+
};
|
|
579
|
+
/**
|
|
580
|
+
* Network error event
|
|
581
|
+
*/
|
|
582
|
+
export type NetworkErrorChunk = NetworkStreamChunkBase & {
|
|
583
|
+
type: "network-error";
|
|
584
|
+
error: string;
|
|
585
|
+
};
|
|
586
|
+
/**
|
|
587
|
+
* Union type for all streaming chunks
|
|
588
|
+
*/
|
|
589
|
+
export type NetworkStreamChunk = NetworkStartChunk | RoutingDecisionChunk | PrimitiveStartChunk | PrimitiveEndChunk | AgentTextChunk | AgentToolCallChunk | AgentToolResultChunk | NetworkCompleteChunk | NetworkErrorChunk;
|
|
590
|
+
/**
|
|
591
|
+
* Result of task analysis
|
|
592
|
+
*/
|
|
593
|
+
export type TaskAnalysis = {
|
|
594
|
+
/** Identified intent of the task */
|
|
595
|
+
intent: string;
|
|
596
|
+
/** Entities extracted from the task */
|
|
597
|
+
entities: Entity[];
|
|
598
|
+
/** Requirements for completing the task */
|
|
599
|
+
requirements: Requirement[];
|
|
600
|
+
/** Task complexity assessment */
|
|
601
|
+
complexity: "simple" | "moderate" | "complex";
|
|
602
|
+
/** Suggested primitives for handling */
|
|
603
|
+
suggestedPrimitives: string[];
|
|
604
|
+
};
|
|
605
|
+
/**
|
|
606
|
+
* Entity extracted from task
|
|
607
|
+
*/
|
|
608
|
+
export type Entity = {
|
|
609
|
+
/** Entity type */
|
|
610
|
+
type: string;
|
|
611
|
+
/** Entity value */
|
|
612
|
+
value: string;
|
|
613
|
+
/** Confidence score */
|
|
614
|
+
confidence: number;
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* Requirement for task completion
|
|
618
|
+
*/
|
|
619
|
+
export type Requirement = {
|
|
620
|
+
/** Requirement type */
|
|
621
|
+
type: "tool" | "capability" | "data";
|
|
622
|
+
/** Requirement description */
|
|
623
|
+
description: string;
|
|
624
|
+
/** Whether it's mandatory */
|
|
625
|
+
mandatory: boolean;
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* Context for routing decisions
|
|
629
|
+
*/
|
|
630
|
+
export type RoutingContext = {
|
|
631
|
+
/** Previous routing decisions */
|
|
632
|
+
previousDecisions?: AgentRoutingDecision[];
|
|
633
|
+
/** Conversation history */
|
|
634
|
+
conversationHistory?: CoreMessage[];
|
|
635
|
+
/** User preferences */
|
|
636
|
+
userPreferences?: Record<string, unknown>;
|
|
637
|
+
/** Session context */
|
|
638
|
+
sessionContext?: Record<string, unknown>;
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* Configuration for hierarchical networks
|
|
642
|
+
*/
|
|
643
|
+
export type HierarchicalNetworkConfig = AgentNetworkConfig & {
|
|
644
|
+
/** Maximum nesting depth */
|
|
645
|
+
maxDepth?: number;
|
|
646
|
+
/** Delegation rules for child networks */
|
|
647
|
+
delegationRules?: DelegationRule[];
|
|
648
|
+
/** Supervision mode */
|
|
649
|
+
supervisionMode?: "autonomous" | "supervised" | "collaborative";
|
|
650
|
+
};
|
|
651
|
+
/**
|
|
652
|
+
* Delegation rule for hierarchical networks
|
|
653
|
+
*/
|
|
654
|
+
export type DelegationRule = {
|
|
655
|
+
/** Rule condition */
|
|
656
|
+
condition: DelegationCondition;
|
|
657
|
+
/** Target network or agent */
|
|
658
|
+
targetNetwork: string;
|
|
659
|
+
/** Priority (higher = checked first) */
|
|
660
|
+
priority: number;
|
|
661
|
+
};
|
|
662
|
+
/**
|
|
663
|
+
* Delegation condition types
|
|
664
|
+
*/
|
|
665
|
+
export type DelegationCondition = {
|
|
666
|
+
type: "keyword";
|
|
667
|
+
keywords: string[];
|
|
668
|
+
} | {
|
|
669
|
+
type: "complexity";
|
|
670
|
+
threshold: "simple" | "moderate" | "complex";
|
|
671
|
+
} | {
|
|
672
|
+
type: "toolRequired";
|
|
673
|
+
tools: string[];
|
|
674
|
+
} | {
|
|
675
|
+
type: "custom";
|
|
676
|
+
evaluator: (task: string) => boolean;
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* Hierarchical execution trace
|
|
680
|
+
*/
|
|
681
|
+
export type HierarchicalExecutionTrace = NetworkExecutionTrace & {
|
|
682
|
+
/** Parent trace ID if this is a child network */
|
|
683
|
+
parentTraceId?: string;
|
|
684
|
+
/** Child traces */
|
|
685
|
+
childTraces?: HierarchicalExecutionTrace[];
|
|
686
|
+
/** Hierarchy level (0 = root) */
|
|
687
|
+
hierarchyLevel: number;
|
|
688
|
+
};
|
|
689
|
+
/**
|
|
690
|
+
* Supervisor agent definition
|
|
691
|
+
*/
|
|
692
|
+
export type SupervisorAgentDefinition = AgentDefinition & {
|
|
693
|
+
/** Supervision policy */
|
|
694
|
+
supervisionPolicy: SupervisionPolicy;
|
|
695
|
+
};
|
|
696
|
+
/**
|
|
697
|
+
* Supervision policy configuration
|
|
698
|
+
*/
|
|
699
|
+
export type SupervisionPolicy = {
|
|
700
|
+
/** Confidence below which to review */
|
|
701
|
+
reviewThreshold: number;
|
|
702
|
+
/** Severity above which to escalate */
|
|
703
|
+
escalationThreshold: number;
|
|
704
|
+
/** Maximum retries before escalation */
|
|
705
|
+
maxRetries: number;
|
|
706
|
+
/** Tool names requiring approval */
|
|
707
|
+
requireApprovalFor: string[];
|
|
708
|
+
};
|
|
709
|
+
/**
|
|
710
|
+
* Supervision options
|
|
711
|
+
*/
|
|
712
|
+
export type SupervisionOptions = {
|
|
713
|
+
/** Whether to enforce approval */
|
|
714
|
+
enforceApproval?: boolean;
|
|
715
|
+
/** Timeout for approval */
|
|
716
|
+
approvalTimeout?: number;
|
|
717
|
+
/** Fallback behavior on timeout */
|
|
718
|
+
timeoutBehavior?: "reject" | "approve" | "escalate";
|
|
719
|
+
};
|
|
720
|
+
/**
|
|
721
|
+
* Result of supervised execution
|
|
722
|
+
*/
|
|
723
|
+
export type SupervisedResult = AgentResult & {
|
|
724
|
+
/** Whether approval was required */
|
|
725
|
+
requiredApproval: boolean;
|
|
726
|
+
/** Approval decision */
|
|
727
|
+
approvalDecision?: ReviewDecision;
|
|
728
|
+
/** Escalation info if escalated */
|
|
729
|
+
escalation?: EscalationResult;
|
|
730
|
+
};
|
|
731
|
+
/**
|
|
732
|
+
* Review decision by supervisor
|
|
733
|
+
*/
|
|
734
|
+
export type ReviewDecision = {
|
|
735
|
+
/** Whether approved */
|
|
736
|
+
approved: boolean;
|
|
737
|
+
/** Reason for decision */
|
|
738
|
+
reason: string;
|
|
739
|
+
/** Modifications made */
|
|
740
|
+
modifications?: Record<string, unknown>;
|
|
741
|
+
/** Timestamp */
|
|
742
|
+
timestamp: number;
|
|
743
|
+
};
|
|
744
|
+
/**
|
|
745
|
+
* Result of escalation
|
|
746
|
+
*/
|
|
747
|
+
export type EscalationResult = {
|
|
748
|
+
/** Whether escalation was handled */
|
|
749
|
+
handled: boolean;
|
|
750
|
+
/** Handler that processed escalation */
|
|
751
|
+
handler?: string;
|
|
752
|
+
/** Resolution */
|
|
753
|
+
resolution?: string;
|
|
754
|
+
/** Timestamp */
|
|
755
|
+
timestamp: number;
|
|
756
|
+
};
|
|
757
|
+
/**
|
|
758
|
+
* Message types for agent communication
|
|
759
|
+
*/
|
|
760
|
+
export type MessageType = "request" | "response" | "broadcast" | "direct" | "event" | "command";
|
|
761
|
+
/**
|
|
762
|
+
* Message priority levels
|
|
763
|
+
*/
|
|
764
|
+
export type MessagePriority = "high" | "normal" | "low";
|
|
765
|
+
/**
|
|
766
|
+
* Message structure for agent communication
|
|
767
|
+
*/
|
|
768
|
+
export type AgentMessage = {
|
|
769
|
+
/** Unique message ID */
|
|
770
|
+
id: string;
|
|
771
|
+
/** Message type */
|
|
772
|
+
type: MessageType;
|
|
773
|
+
/** Topic/channel for the message */
|
|
774
|
+
topic: string;
|
|
775
|
+
/** Sender agent ID */
|
|
776
|
+
senderId: string;
|
|
777
|
+
/** Recipient agent ID (for direct messages) */
|
|
778
|
+
recipientId?: string;
|
|
779
|
+
/** Message payload */
|
|
780
|
+
payload: unknown;
|
|
781
|
+
/** Correlation ID (for request-response) */
|
|
782
|
+
correlationId?: string;
|
|
783
|
+
/** Reply-to topic (for request-response) */
|
|
784
|
+
replyTo?: string;
|
|
785
|
+
/** Message priority */
|
|
786
|
+
priority: MessagePriority;
|
|
787
|
+
/** Timestamp */
|
|
788
|
+
timestamp: number;
|
|
789
|
+
/** Time-to-live in ms (after which message expires) */
|
|
790
|
+
ttl?: number;
|
|
791
|
+
/** Message metadata */
|
|
792
|
+
metadata?: Record<string, unknown>;
|
|
793
|
+
};
|
|
794
|
+
/**
|
|
795
|
+
* Message handler function type
|
|
796
|
+
*/
|
|
797
|
+
export type MessageHandler = (message: AgentMessage) => void | Promise<void>;
|
|
798
|
+
/**
|
|
799
|
+
* Subscription options
|
|
800
|
+
*/
|
|
801
|
+
export type SubscriptionOptions = {
|
|
802
|
+
/** Filter messages by sender */
|
|
803
|
+
filterBySender?: string[];
|
|
804
|
+
/** Filter messages by type */
|
|
805
|
+
filterByType?: MessageType[];
|
|
806
|
+
/** Filter messages by priority */
|
|
807
|
+
filterByPriority?: MessagePriority[];
|
|
808
|
+
/** Custom filter function */
|
|
809
|
+
customFilter?: (message: AgentMessage) => boolean;
|
|
810
|
+
/** Maximum messages to receive (-1 for unlimited) */
|
|
811
|
+
maxMessages?: number;
|
|
812
|
+
};
|
|
813
|
+
/**
|
|
814
|
+
* Message bus configuration
|
|
815
|
+
*/
|
|
816
|
+
export type MessageBusConfig = {
|
|
817
|
+
/** Maximum messages to retain in history */
|
|
818
|
+
maxHistorySize?: number;
|
|
819
|
+
/** Default message TTL in ms */
|
|
820
|
+
defaultTtl?: number;
|
|
821
|
+
/** Enable message persistence */
|
|
822
|
+
enablePersistence?: boolean;
|
|
823
|
+
/** Dead letter queue for failed messages */
|
|
824
|
+
enableDeadLetterQueue?: boolean;
|
|
825
|
+
/** Request timeout for request-response pattern */
|
|
826
|
+
requestTimeout?: number;
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Protocol state
|
|
830
|
+
*/
|
|
831
|
+
export type ProtocolState = "initiated" | "pending" | "active" | "completed" | "failed" | "timeout";
|
|
832
|
+
/**
|
|
833
|
+
* Aggregation request payload
|
|
834
|
+
*/
|
|
835
|
+
export type AggregationRequest = {
|
|
836
|
+
/** Protocol session ID */
|
|
837
|
+
sessionId: string;
|
|
838
|
+
/** Protocol state */
|
|
839
|
+
state: ProtocolState;
|
|
840
|
+
/** Aggregation data */
|
|
841
|
+
data: {
|
|
842
|
+
results: Array<{
|
|
843
|
+
agentId: string;
|
|
844
|
+
result: unknown;
|
|
845
|
+
}>;
|
|
846
|
+
aggregationType: "merge" | "summarize" | "vote" | "custom";
|
|
847
|
+
customAggregator?: string;
|
|
848
|
+
};
|
|
849
|
+
};
|
|
850
|
+
/**
|
|
851
|
+
* Coordination strategy for multi-agent execution
|
|
852
|
+
*/
|
|
853
|
+
export type CoordinationStrategy = "sequential" | "parallel" | "pipeline" | "roundRobin" | "leastBusy" | "custom";
|
|
854
|
+
/**
|
|
855
|
+
* Configuration for the coordinator
|
|
856
|
+
*/
|
|
857
|
+
export type CoordinatorConfig = {
|
|
858
|
+
/** Coordination strategy to use */
|
|
859
|
+
strategy: CoordinationStrategy;
|
|
860
|
+
/** Maximum concurrent agent executions (for parallel strategy) */
|
|
861
|
+
maxConcurrency?: number;
|
|
862
|
+
/** Timeout for individual agent execution in ms */
|
|
863
|
+
agentTimeout?: number;
|
|
864
|
+
/** Whether to continue on agent failure */
|
|
865
|
+
continueOnFailure?: boolean;
|
|
866
|
+
/** Custom coordination logic (for custom strategy) */
|
|
867
|
+
customCoordinator?: (agents: AgentInstance[], task: string, context: CoordinationContext) => Promise<CoordinationResult>;
|
|
868
|
+
/** Retry configuration */
|
|
869
|
+
retry?: {
|
|
870
|
+
maxRetries: number;
|
|
871
|
+
retryDelay: number;
|
|
872
|
+
backoffMultiplier?: number;
|
|
873
|
+
};
|
|
874
|
+
};
|
|
875
|
+
/**
|
|
876
|
+
* Context passed during coordination
|
|
877
|
+
*/
|
|
878
|
+
export type CoordinationContext = AgentExecutionContext & {
|
|
879
|
+
/** Current execution step */
|
|
880
|
+
currentStep: number;
|
|
881
|
+
/** Total expected steps */
|
|
882
|
+
totalSteps?: number;
|
|
883
|
+
/** Results from previous agents */
|
|
884
|
+
previousResults: Map<string, AgentResult>;
|
|
885
|
+
/** Shared state across agents */
|
|
886
|
+
sharedState: Map<string, unknown>;
|
|
887
|
+
/** Coordination metadata */
|
|
888
|
+
metadata: {
|
|
889
|
+
startTime: number;
|
|
890
|
+
strategy: CoordinationStrategy;
|
|
891
|
+
executionId: string;
|
|
892
|
+
};
|
|
893
|
+
};
|
|
894
|
+
/**
|
|
895
|
+
* Result of a coordinated execution
|
|
896
|
+
*/
|
|
897
|
+
export type CoordinationResult = {
|
|
898
|
+
/** Whether coordination was successful */
|
|
899
|
+
success: boolean;
|
|
900
|
+
/** Results from all agents */
|
|
901
|
+
agentResults: Map<string, AgentResult>;
|
|
902
|
+
/** Execution steps taken */
|
|
903
|
+
steps: NetworkExecutionStep[];
|
|
904
|
+
/** Final combined output */
|
|
905
|
+
finalOutput?: string;
|
|
906
|
+
/** Any errors encountered */
|
|
907
|
+
errors: Array<{
|
|
908
|
+
agentId: string;
|
|
909
|
+
error: string;
|
|
910
|
+
}>;
|
|
911
|
+
/** Total duration in ms */
|
|
912
|
+
duration: number;
|
|
913
|
+
/** Execution metadata */
|
|
914
|
+
metadata: {
|
|
915
|
+
executionId: string;
|
|
916
|
+
strategy: CoordinationStrategy;
|
|
917
|
+
agentsExecuted: number;
|
|
918
|
+
agentsFailed: number;
|
|
919
|
+
};
|
|
920
|
+
};
|
|
921
|
+
/**
|
|
922
|
+
* Task assignment for an agent
|
|
923
|
+
*/
|
|
924
|
+
export type TaskAssignment = {
|
|
925
|
+
/** Agent to execute */
|
|
926
|
+
agent: AgentInstance;
|
|
927
|
+
/** Task input */
|
|
928
|
+
input: string;
|
|
929
|
+
/** Dependencies (agent IDs that must complete first) */
|
|
930
|
+
dependencies?: string[];
|
|
931
|
+
/** Priority (higher = executed first) */
|
|
932
|
+
priority?: number;
|
|
933
|
+
/** Timeout override */
|
|
934
|
+
timeout?: number;
|
|
935
|
+
};
|
|
936
|
+
/**
|
|
937
|
+
* Distribution strategy for tasks
|
|
938
|
+
*/
|
|
939
|
+
export type DistributionStrategy = "skillBased" | "loadBalanced" | "priority" | "affinity" | "broadcast";
|
|
940
|
+
/**
|
|
941
|
+
* Task priority levels
|
|
942
|
+
*/
|
|
943
|
+
export type TaskPriority = "critical" | "high" | "normal" | "low" | "background";
|
|
944
|
+
/**
|
|
945
|
+
* Task definition for distribution
|
|
946
|
+
*/
|
|
947
|
+
export type DistributableTask = {
|
|
948
|
+
/** Unique task ID */
|
|
949
|
+
id: string;
|
|
950
|
+
/** Task description/input */
|
|
951
|
+
input: string;
|
|
952
|
+
/** Task priority */
|
|
953
|
+
priority: TaskPriority;
|
|
954
|
+
/** Required skills/capabilities */
|
|
955
|
+
requiredSkills?: string[];
|
|
956
|
+
/** Preferred agent (for affinity) */
|
|
957
|
+
preferredAgent?: string;
|
|
958
|
+
/** Task metadata */
|
|
959
|
+
metadata?: Record<string, unknown>;
|
|
960
|
+
/** Deadline timestamp */
|
|
961
|
+
deadline?: number;
|
|
962
|
+
/** Parent task ID (for subtasks) */
|
|
963
|
+
parentTaskId?: string;
|
|
964
|
+
/** Dependencies (task IDs) */
|
|
965
|
+
dependencies?: string[];
|
|
966
|
+
};
|
|
967
|
+
/**
|
|
968
|
+
* Result of task distribution
|
|
969
|
+
*/
|
|
970
|
+
export type DistributionResult = {
|
|
971
|
+
/** Task ID */
|
|
972
|
+
taskId: string;
|
|
973
|
+
/** Assigned agent ID */
|
|
974
|
+
agentId: string;
|
|
975
|
+
/** Execution result */
|
|
976
|
+
result?: AgentResult;
|
|
977
|
+
/** Distribution timestamp */
|
|
978
|
+
distributedAt: number;
|
|
979
|
+
/** Completion timestamp */
|
|
980
|
+
completedAt?: number;
|
|
981
|
+
/** Status */
|
|
982
|
+
status: "pending" | "running" | "completed" | "failed";
|
|
983
|
+
/** Error if failed */
|
|
984
|
+
error?: string;
|
|
985
|
+
};
|
|
986
|
+
/**
|
|
987
|
+
* Agent capability description
|
|
988
|
+
*/
|
|
989
|
+
export type AgentCapability = {
|
|
990
|
+
/** Agent ID */
|
|
991
|
+
agentId: string;
|
|
992
|
+
/** Skills/capabilities */
|
|
993
|
+
skills: string[];
|
|
994
|
+
/** Current load (0-1) */
|
|
995
|
+
currentLoad: number;
|
|
996
|
+
/** Average response time in ms */
|
|
997
|
+
avgResponseTime: number;
|
|
998
|
+
/** Success rate (0-1) */
|
|
999
|
+
successRate: number;
|
|
1000
|
+
/** Affinity tags */
|
|
1001
|
+
affinityTags?: string[];
|
|
1002
|
+
};
|
|
1003
|
+
/**
|
|
1004
|
+
* Task Distributor configuration
|
|
1005
|
+
*/
|
|
1006
|
+
export type TaskDistributorConfig = {
|
|
1007
|
+
/** Distribution strategy */
|
|
1008
|
+
strategy: DistributionStrategy;
|
|
1009
|
+
/** Maximum queue size */
|
|
1010
|
+
maxQueueSize?: number;
|
|
1011
|
+
/** Maximum retries per task */
|
|
1012
|
+
maxRetries?: number;
|
|
1013
|
+
/** Retry delay in ms */
|
|
1014
|
+
retryDelay?: number;
|
|
1015
|
+
/** Task timeout in ms */
|
|
1016
|
+
taskTimeout?: number;
|
|
1017
|
+
/** Enable task decomposition */
|
|
1018
|
+
enableDecomposition?: boolean;
|
|
1019
|
+
/** Custom skill matcher */
|
|
1020
|
+
skillMatcher?: (task: DistributableTask, agent: AgentInstance) => number;
|
|
1021
|
+
};
|
|
1022
|
+
/**
|
|
1023
|
+
* Orchestration mode
|
|
1024
|
+
*/
|
|
1025
|
+
export type OrchestrationMode = "autonomous" | "supervised" | "collaborative" | "hierarchical";
|
|
1026
|
+
/**
|
|
1027
|
+
* Network state
|
|
1028
|
+
*/
|
|
1029
|
+
export type NetworkState = "idle" | "initializing" | "ready" | "executing" | "paused" | "error" | "shutdown";
|
|
1030
|
+
/**
|
|
1031
|
+
* Network info
|
|
1032
|
+
*/
|
|
1033
|
+
export type NetworkInfo = {
|
|
1034
|
+
id: string;
|
|
1035
|
+
name: string;
|
|
1036
|
+
state: NetworkState;
|
|
1037
|
+
agentCount: number;
|
|
1038
|
+
mode: OrchestrationMode;
|
|
1039
|
+
createdAt: number;
|
|
1040
|
+
lastExecutionAt?: number;
|
|
1041
|
+
executionCount: number;
|
|
1042
|
+
parentNetworkId?: string;
|
|
1043
|
+
childNetworkIds: string[];
|
|
1044
|
+
};
|
|
1045
|
+
/**
|
|
1046
|
+
* Orchestrator configuration
|
|
1047
|
+
*/
|
|
1048
|
+
export type OrchestratorConfig = {
|
|
1049
|
+
/** Default orchestration mode */
|
|
1050
|
+
defaultMode?: OrchestrationMode;
|
|
1051
|
+
/** Maximum concurrent network executions */
|
|
1052
|
+
maxConcurrentExecutions?: number;
|
|
1053
|
+
/** Default execution timeout */
|
|
1054
|
+
defaultTimeout?: number;
|
|
1055
|
+
/** Enable hierarchical networks */
|
|
1056
|
+
enableHierarchy?: boolean;
|
|
1057
|
+
/** Maximum hierarchy depth */
|
|
1058
|
+
maxHierarchyDepth?: number;
|
|
1059
|
+
/** Enable shared message bus */
|
|
1060
|
+
enableSharedMessageBus?: boolean;
|
|
1061
|
+
/** Resource limits */
|
|
1062
|
+
resourceLimits?: {
|
|
1063
|
+
maxNetworks?: number;
|
|
1064
|
+
maxAgentsPerNetwork?: number;
|
|
1065
|
+
maxTotalAgents?: number;
|
|
1066
|
+
};
|
|
1067
|
+
};
|
|
1068
|
+
/**
|
|
1069
|
+
* Execution request
|
|
1070
|
+
*/
|
|
1071
|
+
export type ExecutionRequest = {
|
|
1072
|
+
networkId: string;
|
|
1073
|
+
input: NetworkExecutionInput;
|
|
1074
|
+
options?: NetworkExecutionOptions;
|
|
1075
|
+
priority?: "high" | "normal" | "low";
|
|
1076
|
+
};
|
|
1077
|
+
/**
|
|
1078
|
+
* Topology type
|
|
1079
|
+
*/
|
|
1080
|
+
export type TopologyType = "star" | "mesh" | "hierarchical" | "ring" | "custom";
|
|
1081
|
+
/**
|
|
1082
|
+
* Node in the topology
|
|
1083
|
+
*/
|
|
1084
|
+
export type TopologyNode = {
|
|
1085
|
+
/** Unique node ID */
|
|
1086
|
+
id: string;
|
|
1087
|
+
/** Agent ID (maps to agent) */
|
|
1088
|
+
agentId: string;
|
|
1089
|
+
/** Agent name */
|
|
1090
|
+
agentName: string;
|
|
1091
|
+
/** Node role in topology */
|
|
1092
|
+
role: "coordinator" | "supervisor" | "worker" | "peer";
|
|
1093
|
+
/** Connected node IDs */
|
|
1094
|
+
connections: string[];
|
|
1095
|
+
/** Parent node ID (for hierarchical) */
|
|
1096
|
+
parentId?: string;
|
|
1097
|
+
/** Child node IDs (for hierarchical) */
|
|
1098
|
+
childIds: string[];
|
|
1099
|
+
/** Node metadata */
|
|
1100
|
+
metadata?: Record<string, unknown>;
|
|
1101
|
+
};
|
|
1102
|
+
/**
|
|
1103
|
+
* Edge in the topology
|
|
1104
|
+
*/
|
|
1105
|
+
export type TopologyEdge = {
|
|
1106
|
+
/** Unique edge ID */
|
|
1107
|
+
id: string;
|
|
1108
|
+
/** Source node ID */
|
|
1109
|
+
sourceId: string;
|
|
1110
|
+
/** Target node ID */
|
|
1111
|
+
targetId: string;
|
|
1112
|
+
/** Edge type */
|
|
1113
|
+
type: "bidirectional" | "unidirectional";
|
|
1114
|
+
/** Communication weight (for routing optimization) */
|
|
1115
|
+
weight: number;
|
|
1116
|
+
/** Edge metadata */
|
|
1117
|
+
metadata?: Record<string, unknown>;
|
|
1118
|
+
};
|
|
1119
|
+
/**
|
|
1120
|
+
* Topology configuration
|
|
1121
|
+
*/
|
|
1122
|
+
export type TopologyConfig = {
|
|
1123
|
+
/** Topology type */
|
|
1124
|
+
type: TopologyType;
|
|
1125
|
+
/** Coordinator agent ID (for star topology) */
|
|
1126
|
+
coordinatorId?: string;
|
|
1127
|
+
/** Root agent ID (for hierarchical topology) */
|
|
1128
|
+
rootId?: string;
|
|
1129
|
+
/** Maximum children per node (for hierarchical) */
|
|
1130
|
+
maxChildren?: number;
|
|
1131
|
+
/** Custom edges (for custom topology) */
|
|
1132
|
+
customEdges?: Array<{
|
|
1133
|
+
source: string;
|
|
1134
|
+
target: string;
|
|
1135
|
+
bidirectional?: boolean;
|
|
1136
|
+
}>;
|
|
1137
|
+
};
|
|
1138
|
+
/**
|
|
1139
|
+
* Topology statistics
|
|
1140
|
+
*/
|
|
1141
|
+
export type TopologyStats = {
|
|
1142
|
+
nodeCount: number;
|
|
1143
|
+
edgeCount: number;
|
|
1144
|
+
avgConnections: number;
|
|
1145
|
+
maxConnections: number;
|
|
1146
|
+
minConnections: number;
|
|
1147
|
+
diameter: number;
|
|
1148
|
+
density: number;
|
|
1149
|
+
};
|
|
1150
|
+
/**
|
|
1151
|
+
* Options for routing prompt generation
|
|
1152
|
+
*/
|
|
1153
|
+
export type RoutingPromptOptions = {
|
|
1154
|
+
/** Include alternative primitives in response */
|
|
1155
|
+
includeAlternatives?: boolean;
|
|
1156
|
+
/** Maximum primitives to include in prompt */
|
|
1157
|
+
maxPrimitivesToShow?: number;
|
|
1158
|
+
/** Additional context for routing */
|
|
1159
|
+
additionalContext?: string;
|
|
1160
|
+
/** Conversation history for context */
|
|
1161
|
+
conversationHistory?: Array<{
|
|
1162
|
+
role: string;
|
|
1163
|
+
content: string;
|
|
1164
|
+
}>;
|
|
1165
|
+
};
|
|
1166
|
+
/**
|
|
1167
|
+
* MessageBus subscription record
|
|
1168
|
+
*/
|
|
1169
|
+
export type MessageBusSubscription = {
|
|
1170
|
+
id: string;
|
|
1171
|
+
topic: string;
|
|
1172
|
+
handler: MessageHandler;
|
|
1173
|
+
options: SubscriptionOptions;
|
|
1174
|
+
messageCount: number;
|
|
1175
|
+
subscriberId: string;
|
|
1176
|
+
};
|
|
1177
|
+
/**
|
|
1178
|
+
* Task distributor queue item
|
|
1179
|
+
*/
|
|
1180
|
+
export type TaskQueueItem = {
|
|
1181
|
+
task: DistributableTask;
|
|
1182
|
+
addedAt: number;
|
|
1183
|
+
attempts: number;
|
|
1184
|
+
};
|