@weave_protocol/domere 1.0.18 → 1.2.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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/orchestration/index.d.ts +125 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +258 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/registry.d.ts +156 -0
- package/dist/orchestration/registry.d.ts.map +1 -0
- package/dist/orchestration/registry.js +411 -0
- package/dist/orchestration/registry.js.map +1 -0
- package/dist/orchestration/scheduler.d.ts +192 -0
- package/dist/orchestration/scheduler.d.ts.map +1 -0
- package/dist/orchestration/scheduler.js +544 -0
- package/dist/orchestration/scheduler.js.map +1 -0
- package/dist/orchestration/state.d.ts +258 -0
- package/dist/orchestration/state.d.ts.map +1 -0
- package/dist/orchestration/state.js +665 -0
- package/dist/orchestration/state.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/orchestration/index.ts +341 -0
- package/src/orchestration/registry.ts +568 -0
- package/src/orchestration/scheduler.ts +748 -0
- package/src/orchestration/state.ts +894 -0
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA2BnE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC;AAC3C,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA2BnE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC;AAC3C,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEnG,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACjG,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;AACxC,MAAM,WAAW,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;AAEnD,MAAM,CAAC,iBAAiB,CAAC,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
*
|
|
4
|
+
* Multi-agent coordination infrastructure for AI systems.
|
|
5
|
+
* Provides task scheduling, agent registry, and shared state management.
|
|
6
|
+
*/
|
|
7
|
+
export * from './scheduler.js';
|
|
8
|
+
export * from './registry.js';
|
|
9
|
+
export * from './state.js';
|
|
10
|
+
import { TaskScheduler, Task } from './scheduler.js';
|
|
11
|
+
import { AgentRegistry, Agent } from './registry.js';
|
|
12
|
+
import { StateManager } from './state.js';
|
|
13
|
+
export interface OrchestratorConfig {
|
|
14
|
+
max_agents?: number;
|
|
15
|
+
default_task_timeout_ms?: number;
|
|
16
|
+
heartbeat_interval_ms?: number;
|
|
17
|
+
state_conflict_resolution?: 'last-write-wins' | 'first-write-wins' | 'merge' | 'manual';
|
|
18
|
+
auto_reassign_on_failure?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface OrchestratorStats {
|
|
21
|
+
agents: {
|
|
22
|
+
total: number;
|
|
23
|
+
ready: number;
|
|
24
|
+
busy: number;
|
|
25
|
+
offline: number;
|
|
26
|
+
};
|
|
27
|
+
tasks: {
|
|
28
|
+
total: number;
|
|
29
|
+
queued: number;
|
|
30
|
+
running: number;
|
|
31
|
+
completed: number;
|
|
32
|
+
failed: number;
|
|
33
|
+
};
|
|
34
|
+
state: {
|
|
35
|
+
keys: number;
|
|
36
|
+
branches: number;
|
|
37
|
+
locks: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Unified orchestrator combining scheduler, registry, and state
|
|
42
|
+
*/
|
|
43
|
+
export declare class Orchestrator {
|
|
44
|
+
readonly scheduler: TaskScheduler;
|
|
45
|
+
readonly registry: AgentRegistry;
|
|
46
|
+
readonly state: StateManager;
|
|
47
|
+
private config;
|
|
48
|
+
private running;
|
|
49
|
+
constructor(config?: OrchestratorConfig);
|
|
50
|
+
/**
|
|
51
|
+
* Start the orchestrator
|
|
52
|
+
*/
|
|
53
|
+
start(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Stop the orchestrator
|
|
56
|
+
*/
|
|
57
|
+
stop(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Register an agent
|
|
60
|
+
*/
|
|
61
|
+
registerAgent(params: {
|
|
62
|
+
id?: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
capabilities: string[];
|
|
65
|
+
max_concurrent_tasks?: number;
|
|
66
|
+
}): Promise<Agent>;
|
|
67
|
+
/**
|
|
68
|
+
* Submit a task
|
|
69
|
+
*/
|
|
70
|
+
submitTask(params: {
|
|
71
|
+
intent: string;
|
|
72
|
+
priority?: 'critical' | 'high' | 'normal' | 'low' | 'background';
|
|
73
|
+
dependencies?: string[];
|
|
74
|
+
required_capabilities?: string[];
|
|
75
|
+
timeout_ms?: number;
|
|
76
|
+
}): Promise<Task>;
|
|
77
|
+
/**
|
|
78
|
+
* Get orchestrator statistics
|
|
79
|
+
*/
|
|
80
|
+
getStats(): OrchestratorStats;
|
|
81
|
+
/**
|
|
82
|
+
* Agent heartbeat (call from agent)
|
|
83
|
+
*/
|
|
84
|
+
heartbeat(agentId: string, currentTasks: string[]): Promise<{
|
|
85
|
+
ok: boolean;
|
|
86
|
+
tasks_to_run?: Task[];
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Report task started (call from agent)
|
|
90
|
+
*/
|
|
91
|
+
taskStarted(agentId: string, taskId: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Report task progress (call from agent)
|
|
94
|
+
*/
|
|
95
|
+
taskProgress(agentId: string, taskId: string, percent: number, message?: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Report task completed (call from agent)
|
|
98
|
+
*/
|
|
99
|
+
taskCompleted(agentId: string, taskId: string, result?: any): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Report task failed (call from agent)
|
|
102
|
+
*/
|
|
103
|
+
taskFailed(agentId: string, taskId: string, error: string): Promise<void>;
|
|
104
|
+
private setupEventHandlers;
|
|
105
|
+
/**
|
|
106
|
+
* Get shared state value
|
|
107
|
+
*/
|
|
108
|
+
getState(key: string): Promise<any>;
|
|
109
|
+
/**
|
|
110
|
+
* Set shared state value (with optional lock)
|
|
111
|
+
*/
|
|
112
|
+
setState(key: string, value: any, agentId: string, options?: {
|
|
113
|
+
lock?: boolean;
|
|
114
|
+
}): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Lock state key
|
|
117
|
+
*/
|
|
118
|
+
lockState(key: string, agentId: string, durationMs?: number): Promise<boolean>;
|
|
119
|
+
/**
|
|
120
|
+
* Unlock state key
|
|
121
|
+
*/
|
|
122
|
+
unlockState(key: string, agentId: string): Promise<boolean>;
|
|
123
|
+
}
|
|
124
|
+
export default Orchestrator;
|
|
125
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/orchestration/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,IAAI,EAA8B,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,KAAK,EAAc,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,YAAY,EAAe,MAAM,YAAY,CAAC;AAMvD,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,yBAAyB,CAAC,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,OAAO,GAAG,QAAQ,CAAC;IACxF,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EA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AAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAGlE;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dōmere - Orchestration Module
|
|
3
|
+
*
|
|
4
|
+
* Multi-agent coordination infrastructure for AI systems.
|
|
5
|
+
* Provides task scheduling, agent registry, and shared state management.
|
|
6
|
+
*/
|
|
7
|
+
export * from './scheduler.js';
|
|
8
|
+
export * from './registry.js';
|
|
9
|
+
export * from './state.js';
|
|
10
|
+
import { TaskScheduler } from './scheduler.js';
|
|
11
|
+
import { AgentRegistry } from './registry.js';
|
|
12
|
+
import { StateManager } from './state.js';
|
|
13
|
+
/**
|
|
14
|
+
* Unified orchestrator combining scheduler, registry, and state
|
|
15
|
+
*/
|
|
16
|
+
export class Orchestrator {
|
|
17
|
+
scheduler;
|
|
18
|
+
registry;
|
|
19
|
+
state;
|
|
20
|
+
config;
|
|
21
|
+
running = false;
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.config = {
|
|
24
|
+
max_agents: 16,
|
|
25
|
+
default_task_timeout_ms: 300000,
|
|
26
|
+
heartbeat_interval_ms: 5000,
|
|
27
|
+
state_conflict_resolution: 'last-write-wins',
|
|
28
|
+
auto_reassign_on_failure: true,
|
|
29
|
+
...config,
|
|
30
|
+
};
|
|
31
|
+
// Initialize components
|
|
32
|
+
this.registry = new AgentRegistry({
|
|
33
|
+
heartbeat_interval_ms: this.config.heartbeat_interval_ms,
|
|
34
|
+
heartbeat_timeout_ms: this.config.heartbeat_interval_ms * 3,
|
|
35
|
+
});
|
|
36
|
+
this.scheduler = new TaskScheduler({
|
|
37
|
+
agentGetter: async () => {
|
|
38
|
+
const agents = this.registry.getAllAgents();
|
|
39
|
+
return agents.map(a => ({
|
|
40
|
+
id: a.id,
|
|
41
|
+
available: a.status === 'ready' || a.status === 'busy',
|
|
42
|
+
capabilities: a.capabilities,
|
|
43
|
+
current_load: a.metrics.current_load,
|
|
44
|
+
}));
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
this.state = new StateManager({
|
|
48
|
+
conflict_resolution: this.config.state_conflict_resolution,
|
|
49
|
+
});
|
|
50
|
+
// Wire up event handlers
|
|
51
|
+
this.setupEventHandlers();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Start the orchestrator
|
|
55
|
+
*/
|
|
56
|
+
async start() {
|
|
57
|
+
this.running = true;
|
|
58
|
+
console.log('[Orchestrator] Started');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Stop the orchestrator
|
|
62
|
+
*/
|
|
63
|
+
async stop() {
|
|
64
|
+
this.running = false;
|
|
65
|
+
// Drain all agents
|
|
66
|
+
const agents = this.registry.getAllAgents();
|
|
67
|
+
for (const agent of agents) {
|
|
68
|
+
await this.registry.drain(agent.id);
|
|
69
|
+
}
|
|
70
|
+
console.log('[Orchestrator] Stopped');
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Register an agent
|
|
74
|
+
*/
|
|
75
|
+
async registerAgent(params) {
|
|
76
|
+
const agents = this.registry.getAllAgents();
|
|
77
|
+
if (agents.length >= this.config.max_agents) {
|
|
78
|
+
throw new Error(`Maximum agents (${this.config.max_agents}) reached`);
|
|
79
|
+
}
|
|
80
|
+
const agent = await this.registry.register({
|
|
81
|
+
agent_id: params.id,
|
|
82
|
+
name: params.name,
|
|
83
|
+
capabilities: params.capabilities,
|
|
84
|
+
max_concurrent_tasks: params.max_concurrent_tasks,
|
|
85
|
+
heartbeat_interval_ms: this.config.heartbeat_interval_ms,
|
|
86
|
+
});
|
|
87
|
+
return agent;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Submit a task
|
|
91
|
+
*/
|
|
92
|
+
async submitTask(params) {
|
|
93
|
+
const task = await this.scheduler.createTask({
|
|
94
|
+
intent: params.intent,
|
|
95
|
+
priority: params.priority,
|
|
96
|
+
dependencies: params.dependencies,
|
|
97
|
+
constraints: {
|
|
98
|
+
required_capabilities: params.required_capabilities,
|
|
99
|
+
max_duration_ms: params.timeout_ms || this.config.default_task_timeout_ms,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
// Try to assign immediately if agents available
|
|
103
|
+
try {
|
|
104
|
+
const queued = this.scheduler.getTasksByStatus('queued');
|
|
105
|
+
if (queued.find(t => t.id === task.id)) {
|
|
106
|
+
await this.scheduler.assignTask(task.id);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
// No available agent, will be assigned later
|
|
111
|
+
}
|
|
112
|
+
return task;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get orchestrator statistics
|
|
116
|
+
*/
|
|
117
|
+
getStats() {
|
|
118
|
+
const agentStats = this.registry.getStats();
|
|
119
|
+
const taskStats = this.scheduler.getStats();
|
|
120
|
+
const stateStats = this.state.getStats();
|
|
121
|
+
return {
|
|
122
|
+
agents: {
|
|
123
|
+
total: agentStats.total_agents,
|
|
124
|
+
ready: agentStats.by_status.ready,
|
|
125
|
+
busy: agentStats.by_status.busy,
|
|
126
|
+
offline: agentStats.by_status.offline + agentStats.by_status.failed,
|
|
127
|
+
},
|
|
128
|
+
tasks: {
|
|
129
|
+
total: taskStats.total_tasks,
|
|
130
|
+
queued: taskStats.by_status.queued,
|
|
131
|
+
running: taskStats.by_status.running,
|
|
132
|
+
completed: taskStats.by_status.completed,
|
|
133
|
+
failed: taskStats.by_status.failed,
|
|
134
|
+
},
|
|
135
|
+
state: {
|
|
136
|
+
keys: stateStats.total_keys,
|
|
137
|
+
branches: stateStats.branches,
|
|
138
|
+
locks: stateStats.active_locks,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Agent heartbeat (call from agent)
|
|
144
|
+
*/
|
|
145
|
+
async heartbeat(agentId, currentTasks) {
|
|
146
|
+
const result = await this.registry.heartbeat({
|
|
147
|
+
agent_id: agentId,
|
|
148
|
+
current_tasks: currentTasks,
|
|
149
|
+
});
|
|
150
|
+
if (!result.acknowledged) {
|
|
151
|
+
return { ok: false };
|
|
152
|
+
}
|
|
153
|
+
// Check for new tasks to assign
|
|
154
|
+
const agent = this.registry.getAgent(agentId);
|
|
155
|
+
if (!agent)
|
|
156
|
+
return { ok: false };
|
|
157
|
+
const availableSlots = agent.max_concurrent_tasks - agent.current_tasks.length;
|
|
158
|
+
const tasksToRun = [];
|
|
159
|
+
for (let i = 0; i < availableSlots; i++) {
|
|
160
|
+
const task = await this.scheduler.getNextTask(agentId, agent.capabilities);
|
|
161
|
+
if (task) {
|
|
162
|
+
await this.scheduler.assignTask(task.id, agentId);
|
|
163
|
+
await this.registry.assignTask(agentId, task.id);
|
|
164
|
+
tasksToRun.push(task);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { ok: true, tasks_to_run: tasksToRun.length > 0 ? tasksToRun : undefined };
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Report task started (call from agent)
|
|
174
|
+
*/
|
|
175
|
+
async taskStarted(agentId, taskId) {
|
|
176
|
+
await this.scheduler.startTask(taskId, agentId);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Report task progress (call from agent)
|
|
180
|
+
*/
|
|
181
|
+
async taskProgress(agentId, taskId, percent, message) {
|
|
182
|
+
await this.scheduler.reportProgress(taskId, agentId, percent, undefined, message);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Report task completed (call from agent)
|
|
186
|
+
*/
|
|
187
|
+
async taskCompleted(agentId, taskId, result) {
|
|
188
|
+
const taskResult = await this.scheduler.completeTask(taskId, agentId, result);
|
|
189
|
+
await this.registry.completeTask(agentId, taskId, true, taskResult.duration_ms);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Report task failed (call from agent)
|
|
193
|
+
*/
|
|
194
|
+
async taskFailed(agentId, taskId, error) {
|
|
195
|
+
const taskResult = await this.scheduler.failTask(taskId, agentId, error);
|
|
196
|
+
await this.registry.completeTask(agentId, taskId, false, taskResult.duration_ms);
|
|
197
|
+
}
|
|
198
|
+
// ===========================================================================
|
|
199
|
+
// Event Handlers
|
|
200
|
+
// ===========================================================================
|
|
201
|
+
setupEventHandlers() {
|
|
202
|
+
// Handle agent going offline
|
|
203
|
+
this.registry.onAgentDown(async (agent, activeTasks) => {
|
|
204
|
+
console.log(`[Orchestrator] Agent ${agent.id} went down with ${activeTasks.length} active tasks`);
|
|
205
|
+
if (this.config.auto_reassign_on_failure) {
|
|
206
|
+
// Release all locks held by agent
|
|
207
|
+
await this.state.releaseAllLocks(agent.id);
|
|
208
|
+
// Reassign tasks
|
|
209
|
+
const reassignments = await this.scheduler.reassignFromAgent(agent.id);
|
|
210
|
+
console.log(`[Orchestrator] Reassigned ${reassignments.length} tasks from failed agent`);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
// Log task completions
|
|
214
|
+
this.scheduler.onAnyTaskComplete((result) => {
|
|
215
|
+
console.log(`[Orchestrator] Task ${result.task_id} ${result.status} in ${result.duration_ms}ms`);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
// ===========================================================================
|
|
219
|
+
// Convenience Methods for State
|
|
220
|
+
// ===========================================================================
|
|
221
|
+
/**
|
|
222
|
+
* Get shared state value
|
|
223
|
+
*/
|
|
224
|
+
async getState(key) {
|
|
225
|
+
return this.state.get(key);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Set shared state value (with optional lock)
|
|
229
|
+
*/
|
|
230
|
+
async setState(key, value, agentId, options) {
|
|
231
|
+
if (options?.lock) {
|
|
232
|
+
const lockResult = await this.state.acquireLock({ key, holder: agentId });
|
|
233
|
+
if (!lockResult.acquired) {
|
|
234
|
+
throw new Error(`Could not acquire lock on ${key}: ${lockResult.reason}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
await this.state.set(key, value, { agent_id: agentId });
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Lock state key
|
|
241
|
+
*/
|
|
242
|
+
async lockState(key, agentId, durationMs) {
|
|
243
|
+
const result = await this.state.acquireLock({
|
|
244
|
+
key,
|
|
245
|
+
holder: agentId,
|
|
246
|
+
duration_ms: durationMs,
|
|
247
|
+
});
|
|
248
|
+
return result.acquired;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Unlock state key
|
|
252
|
+
*/
|
|
253
|
+
async unlockState(key, agentId) {
|
|
254
|
+
return this.state.releaseLock(key, agentId);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
export default Orchestrator;
|
|
258
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/orchestration/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAoC,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,aAAa,EAAqB,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,YAAY,EAAe,MAAM,YAAY,CAAC;AAmCvD;;GAEG;AACH,MAAM,OAAO,YAAY;IACP,SAAS,CAAgB;IACzB,QAAQ,CAAgB;IACxB,KAAK,CAAe;IAE5B,MAAM,CAAqB;IAC3B,OAAO,GAAY,KAAK,CAAC;IAEjC,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG;YACZ,UAAU,EAAE,EAAE;YACd,uBAAuB,EAAE,MAAM;YAC/B,qBAAqB,EAAE,IAAI;YAC3B,yBAAyB,EAAE,iBAAiB;YAC5C,wBAAwB,EAAE,IAAI;YAC9B,GAAG,MAAM;SACV,CAAC;QAEF,wBAAwB;QACxB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E,CAAC;QACH,CAAC;QAED,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,OAAe,EAAE,UAAmB;QAC/D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;YAC1C,GAAG;YACH,MAAM,EAAE,OAAO;YACf,WAAW,EAAE,UAAU;SACxB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,GAAW,EAAE,OAAe;QAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dōmere - Agent Registry
|
|
3
|
+
*
|
|
4
|
+
* Agent lifecycle management, health monitoring, and capability tracking
|
|
5
|
+
* for multi-agent AI orchestration systems.
|
|
6
|
+
*/
|
|
7
|
+
export type AgentStatus = 'initializing' | 'ready' | 'busy' | 'overloaded' | 'draining' | 'offline' | 'failed';
|
|
8
|
+
export interface Agent {
|
|
9
|
+
id: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
status: AgentStatus;
|
|
12
|
+
registered_at: Date;
|
|
13
|
+
last_heartbeat: Date;
|
|
14
|
+
capabilities: string[];
|
|
15
|
+
max_concurrent_tasks: number;
|
|
16
|
+
current_tasks: string[];
|
|
17
|
+
metrics: AgentMetrics;
|
|
18
|
+
config: AgentConfig;
|
|
19
|
+
metadata: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentConfig {
|
|
22
|
+
heartbeat_interval_ms: number;
|
|
23
|
+
heartbeat_timeout_ms: number;
|
|
24
|
+
drain_timeout_ms: number;
|
|
25
|
+
auto_recover: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface AgentMetrics {
|
|
28
|
+
tasks_completed: number;
|
|
29
|
+
tasks_failed: number;
|
|
30
|
+
total_duration_ms: number;
|
|
31
|
+
avg_duration_ms: number;
|
|
32
|
+
success_rate: number;
|
|
33
|
+
current_load: number;
|
|
34
|
+
uptime_ms: number;
|
|
35
|
+
last_task_completed_at?: Date;
|
|
36
|
+
}
|
|
37
|
+
export interface AgentRegistration {
|
|
38
|
+
agent_id?: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
capabilities: string[];
|
|
41
|
+
max_concurrent_tasks?: number;
|
|
42
|
+
heartbeat_interval_ms?: number;
|
|
43
|
+
metadata?: Record<string, any>;
|
|
44
|
+
}
|
|
45
|
+
export interface HeartbeatPayload {
|
|
46
|
+
agent_id: string;
|
|
47
|
+
status?: AgentStatus;
|
|
48
|
+
current_tasks?: string[];
|
|
49
|
+
metrics_update?: Partial<AgentMetrics>;
|
|
50
|
+
metadata_update?: Record<string, any>;
|
|
51
|
+
}
|
|
52
|
+
export interface AgentQuery {
|
|
53
|
+
capabilities?: string[];
|
|
54
|
+
status?: AgentStatus[];
|
|
55
|
+
min_available_slots?: number;
|
|
56
|
+
max_load?: number;
|
|
57
|
+
exclude?: string[];
|
|
58
|
+
}
|
|
59
|
+
export interface AgentEvent {
|
|
60
|
+
type: 'registered' | 'ready' | 'busy' | 'overloaded' | 'draining' | 'offline' | 'failed' | 'recovered' | 'deregistered';
|
|
61
|
+
agent_id: string;
|
|
62
|
+
timestamp: Date;
|
|
63
|
+
details?: Record<string, any>;
|
|
64
|
+
}
|
|
65
|
+
export declare class AgentRegistry {
|
|
66
|
+
private agents;
|
|
67
|
+
private heartbeatTimers;
|
|
68
|
+
private eventCallbacks;
|
|
69
|
+
private globalEventCallbacks;
|
|
70
|
+
private defaultConfig;
|
|
71
|
+
constructor(defaultConfig?: Partial<AgentConfig>);
|
|
72
|
+
/**
|
|
73
|
+
* Register a new agent
|
|
74
|
+
*/
|
|
75
|
+
register(params: AgentRegistration): Promise<Agent>;
|
|
76
|
+
/**
|
|
77
|
+
* Mark agent as ready
|
|
78
|
+
*/
|
|
79
|
+
setReady(agentId: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Process heartbeat from agent
|
|
82
|
+
*/
|
|
83
|
+
heartbeat(payload: HeartbeatPayload): Promise<{
|
|
84
|
+
acknowledged: boolean;
|
|
85
|
+
instructions?: string[];
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Get agent by ID
|
|
89
|
+
*/
|
|
90
|
+
getAgent(agentId: string): Agent | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Get all agents
|
|
93
|
+
*/
|
|
94
|
+
getAllAgents(): Agent[];
|
|
95
|
+
/**
|
|
96
|
+
* Find agents matching criteria
|
|
97
|
+
*/
|
|
98
|
+
findAgents(query: AgentQuery): Agent[];
|
|
99
|
+
/**
|
|
100
|
+
* Get best agent for a task
|
|
101
|
+
*/
|
|
102
|
+
getBestAgent(query: AgentQuery & {
|
|
103
|
+
prefer_lowest_load?: boolean;
|
|
104
|
+
prefer_highest_success?: boolean;
|
|
105
|
+
}): Agent | null;
|
|
106
|
+
/**
|
|
107
|
+
* Assign task to agent
|
|
108
|
+
*/
|
|
109
|
+
assignTask(agentId: string, taskId: string): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Complete task for agent
|
|
112
|
+
*/
|
|
113
|
+
completeTask(agentId: string, taskId: string, success: boolean, durationMs: number): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Start draining agent (stop accepting new tasks)
|
|
116
|
+
*/
|
|
117
|
+
drain(agentId: string): Promise<{
|
|
118
|
+
drained: boolean;
|
|
119
|
+
remaining_tasks: number;
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* Deregister agent
|
|
123
|
+
*/
|
|
124
|
+
deregister(agentId: string, force?: boolean): Promise<{
|
|
125
|
+
success: boolean;
|
|
126
|
+
orphaned_tasks: string[];
|
|
127
|
+
}>;
|
|
128
|
+
/**
|
|
129
|
+
* Get agent statistics
|
|
130
|
+
*/
|
|
131
|
+
getStats(): {
|
|
132
|
+
total_agents: number;
|
|
133
|
+
by_status: Record<AgentStatus, number>;
|
|
134
|
+
total_capacity: number;
|
|
135
|
+
total_load: number;
|
|
136
|
+
avg_success_rate: number;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Subscribe to agent events
|
|
140
|
+
*/
|
|
141
|
+
onAgentEvent(agentId: string, callback: (event: AgentEvent) => void): () => void;
|
|
142
|
+
/**
|
|
143
|
+
* Subscribe to all agent events
|
|
144
|
+
*/
|
|
145
|
+
onAnyAgentEvent(callback: (event: AgentEvent) => void): () => void;
|
|
146
|
+
/**
|
|
147
|
+
* Subscribe to agent going offline/failed
|
|
148
|
+
*/
|
|
149
|
+
onAgentDown(callback: (agent: Agent, activeTasks: string[]) => void): () => void;
|
|
150
|
+
private startHeartbeatMonitor;
|
|
151
|
+
private resetHeartbeatTimer;
|
|
152
|
+
private handleHeartbeatTimeout;
|
|
153
|
+
private emitEvent;
|
|
154
|
+
}
|
|
155
|
+
export default AgentRegistry;
|
|
156
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/orchestration/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE/G,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,MAAM,EAAE,WAAW,CAAC;IACpB,aAAa,EAAE,IAAI,CAAC;IACpB,cAAc,EAAE,IAAI,CAAC;IAG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