confused-ai-core 0.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.
- package/FEATURES.md +169 -0
- package/package.json +119 -0
- package/src/agent.ts +187 -0
- package/src/agentic/index.ts +87 -0
- package/src/agentic/runner.ts +386 -0
- package/src/agentic/types.ts +91 -0
- package/src/artifacts/artifact.ts +417 -0
- package/src/artifacts/index.ts +42 -0
- package/src/artifacts/media.ts +304 -0
- package/src/cli/index.ts +122 -0
- package/src/core/base-agent.ts +151 -0
- package/src/core/context-builder.ts +106 -0
- package/src/core/index.ts +8 -0
- package/src/core/schemas.ts +17 -0
- package/src/core/types.ts +158 -0
- package/src/create-agent.ts +309 -0
- package/src/debug-logger.ts +188 -0
- package/src/dx/agent.ts +88 -0
- package/src/dx/define-agent.ts +183 -0
- package/src/dx/dev-logger.ts +57 -0
- package/src/dx/index.ts +11 -0
- package/src/errors.ts +175 -0
- package/src/execution/engine.ts +522 -0
- package/src/execution/graph-builder.ts +362 -0
- package/src/execution/index.ts +8 -0
- package/src/execution/types.ts +257 -0
- package/src/execution/worker-pool.ts +308 -0
- package/src/extensions/index.ts +123 -0
- package/src/guardrails/allowlist.ts +155 -0
- package/src/guardrails/index.ts +17 -0
- package/src/guardrails/types.ts +159 -0
- package/src/guardrails/validator.ts +265 -0
- package/src/index.ts +74 -0
- package/src/knowledge/index.ts +5 -0
- package/src/knowledge/types.ts +52 -0
- package/src/learning/in-memory-store.ts +72 -0
- package/src/learning/index.ts +6 -0
- package/src/learning/types.ts +42 -0
- package/src/llm/cache.ts +300 -0
- package/src/llm/index.ts +22 -0
- package/src/llm/model-resolver.ts +81 -0
- package/src/llm/openai-provider.ts +313 -0
- package/src/llm/openrouter-provider.ts +29 -0
- package/src/llm/types.ts +131 -0
- package/src/memory/in-memory-store.ts +255 -0
- package/src/memory/index.ts +7 -0
- package/src/memory/types.ts +193 -0
- package/src/memory/vector-store.ts +251 -0
- package/src/observability/console-logger.ts +123 -0
- package/src/observability/index.ts +12 -0
- package/src/observability/metrics.ts +85 -0
- package/src/observability/otlp-exporter.ts +417 -0
- package/src/observability/tracer.ts +105 -0
- package/src/observability/types.ts +341 -0
- package/src/orchestration/agent-adapter.ts +33 -0
- package/src/orchestration/index.ts +34 -0
- package/src/orchestration/load-balancer.ts +151 -0
- package/src/orchestration/mcp-types.ts +59 -0
- package/src/orchestration/message-bus.ts +192 -0
- package/src/orchestration/orchestrator.ts +349 -0
- package/src/orchestration/pipeline.ts +66 -0
- package/src/orchestration/supervisor.ts +107 -0
- package/src/orchestration/swarm.ts +1099 -0
- package/src/orchestration/toolkit.ts +47 -0
- package/src/orchestration/types.ts +339 -0
- package/src/planner/classical-planner.ts +383 -0
- package/src/planner/index.ts +8 -0
- package/src/planner/llm-planner.ts +353 -0
- package/src/planner/types.ts +227 -0
- package/src/planner/validator.ts +297 -0
- package/src/production/circuit-breaker.ts +290 -0
- package/src/production/graceful-shutdown.ts +251 -0
- package/src/production/health.ts +333 -0
- package/src/production/index.ts +57 -0
- package/src/production/latency-eval.ts +62 -0
- package/src/production/rate-limiter.ts +287 -0
- package/src/production/resumable-stream.ts +289 -0
- package/src/production/types.ts +81 -0
- package/src/sdk/index.ts +374 -0
- package/src/session/db-driver.ts +50 -0
- package/src/session/in-memory-store.ts +235 -0
- package/src/session/index.ts +12 -0
- package/src/session/sql-store.ts +315 -0
- package/src/session/sqlite-store.ts +61 -0
- package/src/session/types.ts +153 -0
- package/src/tools/base-tool.ts +223 -0
- package/src/tools/browser-tool.ts +123 -0
- package/src/tools/calculator-tool.ts +265 -0
- package/src/tools/file-tools.ts +394 -0
- package/src/tools/github-tool.ts +432 -0
- package/src/tools/hackernews-tool.ts +187 -0
- package/src/tools/http-tool.ts +118 -0
- package/src/tools/index.ts +99 -0
- package/src/tools/jira-tool.ts +373 -0
- package/src/tools/notion-tool.ts +322 -0
- package/src/tools/openai-tool.ts +236 -0
- package/src/tools/registry.ts +131 -0
- package/src/tools/serpapi-tool.ts +234 -0
- package/src/tools/shell-tool.ts +118 -0
- package/src/tools/slack-tool.ts +327 -0
- package/src/tools/telegram-tool.ts +127 -0
- package/src/tools/types.ts +229 -0
- package/src/tools/websearch-tool.ts +335 -0
- package/src/tools/wikipedia-tool.ts +177 -0
- package/src/tools/yfinance-tool.ts +33 -0
- package/src/voice/index.ts +17 -0
- package/src/voice/voice-provider.ts +228 -0
- package/tests/artifact.test.ts +241 -0
- package/tests/circuit-breaker.test.ts +171 -0
- package/tests/health.test.ts +192 -0
- package/tests/llm-cache.test.ts +186 -0
- package/tests/rate-limiter.test.ts +161 -0
- package/tsconfig.json +29 -0
- package/vitest.config.ts +47 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toolkit: named set of tools (100+ built-in style).
|
|
3
|
+
* Bundle tools for reuse across agents; compatible with MCP/A2A.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Tool } from '../tools/types.js';
|
|
7
|
+
import type { ToolRegistry } from '../tools/types.js';
|
|
8
|
+
import { ToolRegistryImpl } from '../tools/registry.js';
|
|
9
|
+
|
|
10
|
+
export interface Toolkit {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly description: string;
|
|
14
|
+
readonly version?: string;
|
|
15
|
+
/** Tools in this toolkit */
|
|
16
|
+
readonly tools: Tool[];
|
|
17
|
+
/** Optional: get tools lazily (e.g. from MCP server) */
|
|
18
|
+
getTools?(): Tool[] | Promise<Tool[]>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Create a toolkit from a list of tools */
|
|
22
|
+
export function createToolkit(
|
|
23
|
+
name: string,
|
|
24
|
+
tools: Tool[],
|
|
25
|
+
options?: { id?: string; description?: string; version?: string }
|
|
26
|
+
): Toolkit {
|
|
27
|
+
return {
|
|
28
|
+
id: options?.id ?? `toolkit-${name.toLowerCase().replace(/\s+/g, '-')}`,
|
|
29
|
+
name,
|
|
30
|
+
description: options?.description ?? `${name} tools`,
|
|
31
|
+
version: options?.version,
|
|
32
|
+
tools,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Flatten one or more toolkits (and/or Tool[]) into a single ToolRegistry */
|
|
37
|
+
export function toolkitsToRegistry(input: (Toolkit | Tool)[]): ToolRegistry {
|
|
38
|
+
const reg = new ToolRegistryImpl();
|
|
39
|
+
for (const item of input) {
|
|
40
|
+
if ('tools' in item && Array.isArray(item.tools)) {
|
|
41
|
+
for (const t of item.tools) reg.register(t);
|
|
42
|
+
} else if ('execute' in item && 'validate' in item) {
|
|
43
|
+
reg.register(item as Tool);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return reg;
|
|
47
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-agent orchestration types and interfaces
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { EntityId } from '../core/types.js';
|
|
6
|
+
import type { Agent, AgentInput, AgentOutput } from '../core/types.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Agent role definition
|
|
10
|
+
*/
|
|
11
|
+
export interface AgentRole {
|
|
12
|
+
readonly id: EntityId;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly description: string;
|
|
15
|
+
readonly responsibilities: string[];
|
|
16
|
+
readonly permissions: RolePermissions;
|
|
17
|
+
readonly canDelegate: boolean;
|
|
18
|
+
readonly canCommunicateWith: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Role permissions
|
|
23
|
+
*/
|
|
24
|
+
export interface RolePermissions {
|
|
25
|
+
readonly canExecuteTools: boolean;
|
|
26
|
+
readonly canAccessMemory: boolean;
|
|
27
|
+
readonly canCreateSubAgents: boolean;
|
|
28
|
+
readonly canModifyPlan: boolean;
|
|
29
|
+
readonly allowedTools?: string[];
|
|
30
|
+
readonly restrictedTools?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Agent registration in the orchestrator
|
|
35
|
+
*/
|
|
36
|
+
export interface AgentRegistration {
|
|
37
|
+
readonly agent: Agent;
|
|
38
|
+
readonly role: AgentRole;
|
|
39
|
+
readonly capabilities: string[];
|
|
40
|
+
readonly metadata: AgentMetadata;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Agent metadata
|
|
45
|
+
*/
|
|
46
|
+
export interface AgentMetadata {
|
|
47
|
+
readonly registeredAt: Date;
|
|
48
|
+
readonly lastActiveAt?: Date;
|
|
49
|
+
readonly totalTasksCompleted: number;
|
|
50
|
+
readonly totalTasksFailed: number;
|
|
51
|
+
readonly averageExecutionTimeMs: number;
|
|
52
|
+
readonly currentLoad: number;
|
|
53
|
+
readonly maxConcurrentTasks: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Message for inter-agent communication
|
|
58
|
+
*/
|
|
59
|
+
export interface AgentMessage {
|
|
60
|
+
readonly id: EntityId;
|
|
61
|
+
readonly from: EntityId;
|
|
62
|
+
readonly to: EntityId | 'broadcast';
|
|
63
|
+
readonly type: MessageType;
|
|
64
|
+
readonly payload: unknown;
|
|
65
|
+
readonly timestamp: Date;
|
|
66
|
+
readonly correlationId?: EntityId;
|
|
67
|
+
readonly priority: MessagePriority;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Message types
|
|
72
|
+
*/
|
|
73
|
+
export enum MessageType {
|
|
74
|
+
TASK_REQUEST = 'task_request',
|
|
75
|
+
TASK_RESPONSE = 'task_response',
|
|
76
|
+
DELEGATION = 'delegation',
|
|
77
|
+
NOTIFICATION = 'notification',
|
|
78
|
+
QUERY = 'query',
|
|
79
|
+
COMMAND = 'command',
|
|
80
|
+
EVENT = 'event',
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Message priority
|
|
85
|
+
*/
|
|
86
|
+
export enum MessagePriority {
|
|
87
|
+
CRITICAL = 0,
|
|
88
|
+
HIGH = 1,
|
|
89
|
+
NORMAL = 2,
|
|
90
|
+
LOW = 3,
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Message bus for agent communication
|
|
95
|
+
*/
|
|
96
|
+
export interface MessageBus {
|
|
97
|
+
/**
|
|
98
|
+
* Send a message to an agent or broadcast
|
|
99
|
+
*/
|
|
100
|
+
send(message: Omit<AgentMessage, 'id' | 'timestamp'>): Promise<AgentMessage>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Subscribe to messages
|
|
104
|
+
*/
|
|
105
|
+
subscribe(
|
|
106
|
+
subscriberId: EntityId,
|
|
107
|
+
filter: MessageFilter,
|
|
108
|
+
handler: MessageHandler
|
|
109
|
+
): Subscription;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Unsubscribe from messages
|
|
113
|
+
*/
|
|
114
|
+
unsubscribe(subscription: Subscription): void;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Request-response pattern
|
|
118
|
+
*/
|
|
119
|
+
request<T>(to: EntityId, payload: unknown, timeoutMs?: number): Promise<T>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Message filter
|
|
124
|
+
*/
|
|
125
|
+
export interface MessageFilter {
|
|
126
|
+
readonly from?: EntityId;
|
|
127
|
+
readonly types?: MessageType[];
|
|
128
|
+
readonly correlationId?: EntityId;
|
|
129
|
+
readonly minPriority?: MessagePriority;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Message handler
|
|
134
|
+
*/
|
|
135
|
+
export type MessageHandler = (message: AgentMessage) => void | Promise<void>;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Subscription handle
|
|
139
|
+
*/
|
|
140
|
+
export interface Subscription {
|
|
141
|
+
readonly id: EntityId;
|
|
142
|
+
readonly subscriberId: EntityId;
|
|
143
|
+
readonly unsubscribe: () => void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Multi-agent orchestrator
|
|
148
|
+
*/
|
|
149
|
+
export interface Orchestrator {
|
|
150
|
+
/**
|
|
151
|
+
* Register an agent with a role
|
|
152
|
+
*/
|
|
153
|
+
registerAgent(agent: Agent, role: AgentRole): Promise<void>;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Unregister an agent
|
|
157
|
+
*/
|
|
158
|
+
unregisterAgent(agentId: EntityId): Promise<void>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get a registered agent
|
|
162
|
+
*/
|
|
163
|
+
getAgent(agentId: EntityId): AgentRegistration | undefined;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* List all registered agents
|
|
167
|
+
*/
|
|
168
|
+
listAgents(): AgentRegistration[];
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Find agents by role
|
|
172
|
+
*/
|
|
173
|
+
findAgentsByRole(roleName: string): AgentRegistration[];
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Find agents by capability
|
|
177
|
+
*/
|
|
178
|
+
findAgentsByCapability(capability: string): AgentRegistration[];
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Delegate a task to the best available agent
|
|
182
|
+
*/
|
|
183
|
+
delegateTask(task: DelegationTask, options?: DelegationOptions): Promise<DelegationResult>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Broadcast a message to all agents
|
|
187
|
+
*/
|
|
188
|
+
broadcast(payload: unknown, type?: MessageType): Promise<void>;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Get the message bus
|
|
192
|
+
*/
|
|
193
|
+
getMessageBus(): MessageBus;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Start the orchestrator
|
|
197
|
+
*/
|
|
198
|
+
start(): Promise<void>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Stop the orchestrator
|
|
202
|
+
*/
|
|
203
|
+
stop(): Promise<void>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Task delegation request
|
|
208
|
+
*/
|
|
209
|
+
export interface DelegationTask {
|
|
210
|
+
readonly id: EntityId;
|
|
211
|
+
readonly description: string;
|
|
212
|
+
readonly requiredCapabilities: string[];
|
|
213
|
+
readonly preferredRole?: string;
|
|
214
|
+
readonly input: AgentInput;
|
|
215
|
+
readonly priority: DelegationPriority;
|
|
216
|
+
readonly deadline?: Date;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Task priority for delegation
|
|
221
|
+
*/
|
|
222
|
+
export enum DelegationPriority {
|
|
223
|
+
CRITICAL = 'critical',
|
|
224
|
+
HIGH = 'high',
|
|
225
|
+
NORMAL = 'normal',
|
|
226
|
+
LOW = 'low',
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Delegation options
|
|
231
|
+
*/
|
|
232
|
+
export interface DelegationOptions {
|
|
233
|
+
readonly timeoutMs?: number;
|
|
234
|
+
readonly retryCount?: number;
|
|
235
|
+
readonly requireAcknowledgment?: boolean;
|
|
236
|
+
readonly loadBalance?: boolean;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Delegation result
|
|
241
|
+
*/
|
|
242
|
+
export interface DelegationResult {
|
|
243
|
+
readonly taskId: EntityId;
|
|
244
|
+
readonly assignedAgentId: EntityId;
|
|
245
|
+
readonly status: DelegationStatus;
|
|
246
|
+
readonly output?: AgentOutput;
|
|
247
|
+
readonly error?: string;
|
|
248
|
+
readonly executionTimeMs: number;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Delegation status
|
|
253
|
+
*/
|
|
254
|
+
export enum DelegationStatus {
|
|
255
|
+
ASSIGNED = 'assigned',
|
|
256
|
+
COMPLETED = 'completed',
|
|
257
|
+
FAILED = 'failed',
|
|
258
|
+
TIMEOUT = 'timeout',
|
|
259
|
+
REJECTED = 'rejected',
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Load balancer for task distribution
|
|
264
|
+
*/
|
|
265
|
+
export interface LoadBalancer {
|
|
266
|
+
/**
|
|
267
|
+
* Select the best agent for a task
|
|
268
|
+
*/
|
|
269
|
+
selectAgent(
|
|
270
|
+
candidates: AgentRegistration[],
|
|
271
|
+
task: DelegationTask
|
|
272
|
+
): AgentRegistration | undefined;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Update agent metrics after task completion
|
|
276
|
+
*/
|
|
277
|
+
updateMetrics(agentId: EntityId, executionTimeMs: number, success: boolean): void;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Coordination strategy
|
|
282
|
+
*/
|
|
283
|
+
export interface CoordinationStrategy {
|
|
284
|
+
/**
|
|
285
|
+
* Coordinate multiple agents for a complex task
|
|
286
|
+
*/
|
|
287
|
+
coordinate(agents: AgentRegistration[], task: CoordinationTask): Promise<CoordinationResult>;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Coordination task
|
|
292
|
+
*/
|
|
293
|
+
export interface CoordinationTask {
|
|
294
|
+
readonly id: EntityId;
|
|
295
|
+
readonly description: string;
|
|
296
|
+
readonly subtasks: SubTask[];
|
|
297
|
+
readonly coordinationType: CoordinationType;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Coordination type
|
|
302
|
+
*/
|
|
303
|
+
export enum CoordinationType {
|
|
304
|
+
SEQUENTIAL = 'sequential',
|
|
305
|
+
PARALLEL = 'parallel',
|
|
306
|
+
PIPELINE = 'pipeline',
|
|
307
|
+
HIERARCHICAL = 'hierarchical',
|
|
308
|
+
CONSENSUS = 'consensus',
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Subtask in a coordination
|
|
313
|
+
*/
|
|
314
|
+
export interface SubTask {
|
|
315
|
+
readonly id: EntityId;
|
|
316
|
+
readonly description: string;
|
|
317
|
+
readonly requiredCapabilities: string[];
|
|
318
|
+
readonly dependencies: EntityId[];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Coordination result
|
|
323
|
+
*/
|
|
324
|
+
export interface CoordinationResult {
|
|
325
|
+
readonly taskId: EntityId;
|
|
326
|
+
readonly status: CoordinationStatus;
|
|
327
|
+
readonly results: Map<EntityId, AgentOutput>;
|
|
328
|
+
readonly aggregatedOutput?: unknown;
|
|
329
|
+
readonly executionTimeMs: number;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Coordination status
|
|
334
|
+
*/
|
|
335
|
+
export enum CoordinationStatus {
|
|
336
|
+
SUCCESS = 'success',
|
|
337
|
+
PARTIAL = 'partial',
|
|
338
|
+
FAILED = 'failed',
|
|
339
|
+
}
|