network-ai 3.2.11 → 3.3.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 +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/compliance-monitor.d.ts +129 -0
- package/dist/lib/compliance-monitor.d.ts.map +1 -0
- package/dist/lib/compliance-monitor.js +261 -0
- package/dist/lib/compliance-monitor.js.map +1 -0
- package/dist/lib/fsm-journey.d.ts +238 -0
- package/dist/lib/fsm-journey.d.ts.map +1 -0
- package/dist/lib/fsm-journey.js +476 -0
- package/dist/lib/fsm-journey.js.map +1 -0
- package/dist/lib/mcp-blackboard-tools.d.ts +126 -0
- package/dist/lib/mcp-blackboard-tools.d.ts.map +1 -0
- package/dist/lib/mcp-blackboard-tools.js +298 -0
- package/dist/lib/mcp-blackboard-tools.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* FSM Journey Layer — Phase 4: Behavioral Control Plane
|
|
4
|
+
*
|
|
5
|
+
* Implements state machine–based workflow authorization. Agents can only act
|
|
6
|
+
* in their designated states, and tools can only be called when the current
|
|
7
|
+
* workflow state permits it.
|
|
8
|
+
*
|
|
9
|
+
* @module fsm-journey
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ComplianceViolationError = exports.ComplianceMiddleware = exports.JourneyFSM = exports.ToolAuthorizationMatrix = exports.WORKFLOW_STATES = void 0;
|
|
13
|
+
exports.createDeliveryPipelineFSM = createDeliveryPipelineFSM;
|
|
14
|
+
/** Built-in canonical workflow states for common agent pipelines. */
|
|
15
|
+
exports.WORKFLOW_STATES = {
|
|
16
|
+
INTAKE: 'INTAKE',
|
|
17
|
+
VALIDATE: 'VALIDATE',
|
|
18
|
+
RESEARCH: 'RESEARCH',
|
|
19
|
+
PLAN: 'PLAN',
|
|
20
|
+
EXECUTE: 'EXECUTE',
|
|
21
|
+
REVIEW: 'REVIEW',
|
|
22
|
+
DELIVER: 'DELIVER',
|
|
23
|
+
COMPLETE: 'COMPLETE',
|
|
24
|
+
ERROR: 'ERROR',
|
|
25
|
+
};
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// TOOL AUTHORIZATION MATRIX
|
|
28
|
+
// ============================================================================
|
|
29
|
+
/**
|
|
30
|
+
* Standalone tool authorization matrix.
|
|
31
|
+
*
|
|
32
|
+
* Maps `agentId -> state -> allowedTools[]`.
|
|
33
|
+
* The FSM embeds one automatically, but you can also use this independently.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const matrix = new ToolAuthorizationMatrix();
|
|
38
|
+
* matrix.allow('data_analyst', 'RESEARCH', ['search_web', 'query_db']);
|
|
39
|
+
* matrix.allow('*', 'REVIEW', ['read_blackboard']);
|
|
40
|
+
* matrix.isAllowed('data_analyst', 'RESEARCH', 'query_db'); // true
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class ToolAuthorizationMatrix {
|
|
44
|
+
// agentId -> state -> Set<toolName>
|
|
45
|
+
rules = new Map();
|
|
46
|
+
/**
|
|
47
|
+
* Grant an agent permission to use a list of tools in a given state.
|
|
48
|
+
* Use `'*'` for agentId or toolNames to mean "all".
|
|
49
|
+
*/
|
|
50
|
+
allow(agentId, state, tools) {
|
|
51
|
+
if (!this.rules.has(agentId))
|
|
52
|
+
this.rules.set(agentId, new Map());
|
|
53
|
+
const agentRules = this.rules.get(agentId);
|
|
54
|
+
if (!agentRules.has(state))
|
|
55
|
+
agentRules.set(state, new Set());
|
|
56
|
+
const toolSet = agentRules.get(state);
|
|
57
|
+
for (const t of tools)
|
|
58
|
+
toolSet.add(t);
|
|
59
|
+
}
|
|
60
|
+
/** Revoke a specific tool permission. */
|
|
61
|
+
revoke(agentId, state, tool) {
|
|
62
|
+
this.rules.get(agentId)?.get(state)?.delete(tool);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if an agent is allowed to use a tool in a given state.
|
|
66
|
+
* Checks exact agentId first, then falls back to '*' wildcard.
|
|
67
|
+
*/
|
|
68
|
+
isAllowed(agentId, state, tool) {
|
|
69
|
+
return (this._check(agentId, state, tool) ||
|
|
70
|
+
this._check('*', state, tool) ||
|
|
71
|
+
this._check(agentId, '*', tool) ||
|
|
72
|
+
this._check('*', '*', tool));
|
|
73
|
+
}
|
|
74
|
+
_check(agentId, state, tool) {
|
|
75
|
+
const tools = this.rules.get(agentId)?.get(state);
|
|
76
|
+
if (!tools)
|
|
77
|
+
return false;
|
|
78
|
+
return tools.has(tool) || tools.has('*');
|
|
79
|
+
}
|
|
80
|
+
/** Dump current rules for debugging/audit. */
|
|
81
|
+
dump() {
|
|
82
|
+
const out = {};
|
|
83
|
+
for (const [agent, states] of this.rules) {
|
|
84
|
+
out[agent] = {};
|
|
85
|
+
for (const [state, tools] of states) {
|
|
86
|
+
out[agent][state] = Array.from(tools);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.ToolAuthorizationMatrix = ToolAuthorizationMatrix;
|
|
93
|
+
// ============================================================================
|
|
94
|
+
// JOURNEY FSM
|
|
95
|
+
// ============================================================================
|
|
96
|
+
/**
|
|
97
|
+
* Finite-state machine for workflow authorization.
|
|
98
|
+
*
|
|
99
|
+
* Governs which agents can act (and with which tools) based on the current
|
|
100
|
+
* workflow state. Integrates an inline `ComplianceMiddleware` and a
|
|
101
|
+
* `ToolAuthorizationMatrix`.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { JourneyFSM, WORKFLOW_STATES } from 'network-ai';
|
|
106
|
+
*
|
|
107
|
+
* const fsm = new JourneyFSM({
|
|
108
|
+
* states: [
|
|
109
|
+
* { name: 'INTAKE', authorizedAgents: ['orchestrator'], authorizedTools: { orchestrator: ['read_intake'] } },
|
|
110
|
+
* { name: 'RESEARCH', authorizedAgents: ['data_analyst'], authorizedTools: { data_analyst: ['query_db', 'search_web'] } },
|
|
111
|
+
* { name: 'DELIVER', authorizedAgents: ['orchestrator'], authorizedTools: { '*': ['write_blackboard'] } },
|
|
112
|
+
* ],
|
|
113
|
+
* transitions: [
|
|
114
|
+
* { from: 'INTAKE', event: 'start_research', to: 'RESEARCH', allowedBy: 'orchestrator' },
|
|
115
|
+
* { from: 'RESEARCH', event: 'research_done', to: 'DELIVER', allowedBy: '*' },
|
|
116
|
+
* ],
|
|
117
|
+
* initialState: 'INTAKE',
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* fsm.transition('start_research', 'orchestrator'); // moves to RESEARCH
|
|
121
|
+
* fsm.canAgentAct('data_analyst'); // true — we're now in RESEARCH
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
class JourneyFSM {
|
|
125
|
+
currentState;
|
|
126
|
+
stateMap = new Map();
|
|
127
|
+
transitions;
|
|
128
|
+
options;
|
|
129
|
+
stateEnteredAt = Date.now();
|
|
130
|
+
history = [];
|
|
131
|
+
/** Embedded tool authorization matrix (populated from state definitions). */
|
|
132
|
+
toolMatrix;
|
|
133
|
+
constructor(options) {
|
|
134
|
+
this.options = options;
|
|
135
|
+
this.transitions = options.transitions;
|
|
136
|
+
this.toolMatrix = new ToolAuthorizationMatrix();
|
|
137
|
+
// Index states
|
|
138
|
+
for (const s of options.states) {
|
|
139
|
+
this.stateMap.set(s.name, s);
|
|
140
|
+
// Populate the tool matrix from state definitions
|
|
141
|
+
if (s.authorizedTools) {
|
|
142
|
+
for (const [agentId, tools] of Object.entries(s.authorizedTools)) {
|
|
143
|
+
this.toolMatrix.allow(agentId, s.name, tools);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!this.stateMap.has(options.initialState)) {
|
|
148
|
+
throw new Error(`Initial state "${options.initialState}" is not defined in states list`);
|
|
149
|
+
}
|
|
150
|
+
this.currentState = options.initialState;
|
|
151
|
+
this.history.push({ state: this.currentState, enteredAt: Date.now() });
|
|
152
|
+
}
|
|
153
|
+
// --------------------------------------------------------------------------
|
|
154
|
+
// State accessors
|
|
155
|
+
// --------------------------------------------------------------------------
|
|
156
|
+
/** Current workflow state name. */
|
|
157
|
+
get state() {
|
|
158
|
+
return this.currentState;
|
|
159
|
+
}
|
|
160
|
+
/** Full definition of the current state. */
|
|
161
|
+
get stateDefinition() {
|
|
162
|
+
return this.stateMap.get(this.currentState);
|
|
163
|
+
}
|
|
164
|
+
/** How long (ms) the FSM has been in the current state. */
|
|
165
|
+
get timeInCurrentState() {
|
|
166
|
+
return Date.now() - this.stateEnteredAt;
|
|
167
|
+
}
|
|
168
|
+
/** Whether the current state has timed out. */
|
|
169
|
+
get isTimedOut() {
|
|
170
|
+
const def = this.stateDefinition;
|
|
171
|
+
if (!def.timeoutMs)
|
|
172
|
+
return false;
|
|
173
|
+
return this.timeInCurrentState > def.timeoutMs;
|
|
174
|
+
}
|
|
175
|
+
/** Full transition history. */
|
|
176
|
+
get transitionHistory() {
|
|
177
|
+
return this.history;
|
|
178
|
+
}
|
|
179
|
+
// --------------------------------------------------------------------------
|
|
180
|
+
// Authorization checks
|
|
181
|
+
// --------------------------------------------------------------------------
|
|
182
|
+
/**
|
|
183
|
+
* Check if an agent is authorized to perform any action in the current state.
|
|
184
|
+
*/
|
|
185
|
+
canAgentAct(agentId) {
|
|
186
|
+
const def = this.stateDefinition;
|
|
187
|
+
return def.authorizedAgents.includes('*') || def.authorizedAgents.includes(agentId);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Check if an agent is authorized to use a specific tool in the current state.
|
|
191
|
+
* Checks both the tool matrix AND agent authorization.
|
|
192
|
+
*/
|
|
193
|
+
canAgentUseTool(agentId, tool) {
|
|
194
|
+
if (!this.canAgentAct(agentId))
|
|
195
|
+
return false;
|
|
196
|
+
return this.toolMatrix.isAllowed(agentId, this.currentState, tool);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Inline compliance check — call this BEFORE executing any agent action.
|
|
200
|
+
* Returns `{ allowed: true }` or `{ allowed: false, reason }`.
|
|
201
|
+
*/
|
|
202
|
+
checkCompliance(agentId, tool) {
|
|
203
|
+
const canAct = this.canAgentAct(agentId);
|
|
204
|
+
if (!canAct) {
|
|
205
|
+
const result = {
|
|
206
|
+
allowed: false,
|
|
207
|
+
reason: `Agent "${agentId}" is not authorized in state "${this.currentState}". ` +
|
|
208
|
+
`Authorized agents: [${this.stateDefinition.authorizedAgents.join(', ')}]`,
|
|
209
|
+
currentState: this.currentState,
|
|
210
|
+
agentId,
|
|
211
|
+
tool,
|
|
212
|
+
};
|
|
213
|
+
this.options.onViolation?.(result);
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
if (tool) {
|
|
217
|
+
const canUseTool = this.canAgentUseTool(agentId, tool);
|
|
218
|
+
if (!canUseTool) {
|
|
219
|
+
const result = {
|
|
220
|
+
allowed: false,
|
|
221
|
+
reason: `Agent "${agentId}" is not authorized to use tool "${tool}" in state "${this.currentState}"`,
|
|
222
|
+
currentState: this.currentState,
|
|
223
|
+
agentId,
|
|
224
|
+
tool,
|
|
225
|
+
};
|
|
226
|
+
this.options.onViolation?.(result);
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return { allowed: true, currentState: this.currentState, agentId, tool };
|
|
231
|
+
}
|
|
232
|
+
// --------------------------------------------------------------------------
|
|
233
|
+
// Transitions
|
|
234
|
+
// --------------------------------------------------------------------------
|
|
235
|
+
/**
|
|
236
|
+
* Fire a named event to transition the FSM to the next state.
|
|
237
|
+
* Returns a `TransitionResult` describing what happened.
|
|
238
|
+
*/
|
|
239
|
+
transition(event, agentId) {
|
|
240
|
+
const match = this.transitions.find(t => t.from === this.currentState && t.event === event);
|
|
241
|
+
if (!match) {
|
|
242
|
+
const result = {
|
|
243
|
+
success: false,
|
|
244
|
+
previousState: this.currentState,
|
|
245
|
+
currentState: this.currentState,
|
|
246
|
+
reason: `No transition "${event}" defined from state "${this.currentState}"`,
|
|
247
|
+
};
|
|
248
|
+
this.options.onTransition?.(result, agentId);
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
// Check if this agent is allowed to fire this transition
|
|
252
|
+
if (match.allowedBy && match.allowedBy !== '*' && match.allowedBy !== agentId) {
|
|
253
|
+
const result = {
|
|
254
|
+
success: false,
|
|
255
|
+
previousState: this.currentState,
|
|
256
|
+
currentState: this.currentState,
|
|
257
|
+
reason: `Agent "${agentId}" cannot fire event "${event}" (only "${match.allowedBy}" can)`,
|
|
258
|
+
};
|
|
259
|
+
this.options.onTransition?.(result, agentId);
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
if (!this.stateMap.has(match.to)) {
|
|
263
|
+
const result = {
|
|
264
|
+
success: false,
|
|
265
|
+
previousState: this.currentState,
|
|
266
|
+
currentState: this.currentState,
|
|
267
|
+
reason: `Target state "${match.to}" is not defined`,
|
|
268
|
+
};
|
|
269
|
+
this.options.onTransition?.(result, agentId);
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
const previous = this.currentState;
|
|
273
|
+
// Mark exit time on current history entry
|
|
274
|
+
this.history[this.history.length - 1].exitedAt = Date.now();
|
|
275
|
+
this.history[this.history.length - 1].triggeredBy = agentId;
|
|
276
|
+
this.currentState = match.to;
|
|
277
|
+
this.stateEnteredAt = Date.now();
|
|
278
|
+
this.history.push({ state: this.currentState, enteredAt: this.stateEnteredAt });
|
|
279
|
+
const result = {
|
|
280
|
+
success: true,
|
|
281
|
+
previousState: previous,
|
|
282
|
+
currentState: this.currentState,
|
|
283
|
+
};
|
|
284
|
+
this.options.onTransition?.(result, agentId);
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Returns all events available from the current state.
|
|
289
|
+
*/
|
|
290
|
+
availableEvents() {
|
|
291
|
+
return this.transitions
|
|
292
|
+
.filter(t => t.from === this.currentState)
|
|
293
|
+
.map(t => t.event);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Returns which agents are authorized in a given state (defaults to current).
|
|
297
|
+
*/
|
|
298
|
+
getAuthorizedAgents(stateName) {
|
|
299
|
+
return this.stateMap.get(stateName ?? this.currentState)?.authorizedAgents ?? [];
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Reset the FSM to its initial state.
|
|
303
|
+
*/
|
|
304
|
+
reset() {
|
|
305
|
+
this.history[this.history.length - 1].exitedAt = Date.now();
|
|
306
|
+
this.currentState = this.options.initialState;
|
|
307
|
+
this.stateEnteredAt = Date.now();
|
|
308
|
+
this.history.push({ state: this.currentState, enteredAt: this.stateEnteredAt });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
exports.JourneyFSM = JourneyFSM;
|
|
312
|
+
// ============================================================================
|
|
313
|
+
// COMPLIANCE MIDDLEWARE
|
|
314
|
+
// ============================================================================
|
|
315
|
+
/**
|
|
316
|
+
* Wraps an async action and blocks its execution if the FSM denies it.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* const middleware = new ComplianceMiddleware(fsm);
|
|
321
|
+
*
|
|
322
|
+
* const result = await middleware.enforce('data_analyst', 'query_db', async () => {
|
|
323
|
+
* return await db.query('SELECT * FROM invoices');
|
|
324
|
+
* });
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
class ComplianceMiddleware {
|
|
328
|
+
fsm;
|
|
329
|
+
constructor(fsm) {
|
|
330
|
+
this.fsm = fsm;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Enforce compliance before running `action`.
|
|
334
|
+
* Throws if not authorized; returns the action's result if allowed.
|
|
335
|
+
*/
|
|
336
|
+
async enforce(agentId, tool, action) {
|
|
337
|
+
const check = this.fsm.checkCompliance(agentId, tool);
|
|
338
|
+
if (!check.allowed) {
|
|
339
|
+
throw new ComplianceViolationError(check.reason ?? 'Compliance check failed', check);
|
|
340
|
+
}
|
|
341
|
+
return action();
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Synchronous version — use when the action is not async.
|
|
345
|
+
*/
|
|
346
|
+
enforceSync(agentId, tool, action) {
|
|
347
|
+
const check = this.fsm.checkCompliance(agentId, tool);
|
|
348
|
+
if (!check.allowed) {
|
|
349
|
+
throw new ComplianceViolationError(check.reason ?? 'Compliance check failed', check);
|
|
350
|
+
}
|
|
351
|
+
return action();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
exports.ComplianceMiddleware = ComplianceMiddleware;
|
|
355
|
+
// ============================================================================
|
|
356
|
+
// ERRORS
|
|
357
|
+
// ============================================================================
|
|
358
|
+
/** Thrown when ComplianceMiddleware blocks an action. */
|
|
359
|
+
class ComplianceViolationError extends Error {
|
|
360
|
+
check;
|
|
361
|
+
constructor(message, check) {
|
|
362
|
+
super(message);
|
|
363
|
+
this.name = 'ComplianceViolationError';
|
|
364
|
+
this.check = check;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
exports.ComplianceViolationError = ComplianceViolationError;
|
|
368
|
+
// ============================================================================
|
|
369
|
+
// FACTORY
|
|
370
|
+
// ============================================================================
|
|
371
|
+
/**
|
|
372
|
+
* Build a standard delivery pipeline FSM with sensible defaults.
|
|
373
|
+
* States: INTAKE → VALIDATE → RESEARCH → PLAN → EXECUTE → REVIEW → DELIVER → COMPLETE
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* const fsm = createDeliveryPipelineFSM({
|
|
378
|
+
* orchestratorId: 'orchestrator',
|
|
379
|
+
* researchAgentId: 'data_analyst',
|
|
380
|
+
* executorId: 'code_writer',
|
|
381
|
+
* });
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
function createDeliveryPipelineFSM(options) {
|
|
385
|
+
const orch = options.orchestratorId ?? 'orchestrator';
|
|
386
|
+
const analyst = options.researchAgentId ?? 'data_analyst';
|
|
387
|
+
const exec = options.executorId ?? 'code_writer';
|
|
388
|
+
const reviewer = options.reviewerId ?? 'reviewer';
|
|
389
|
+
return new JourneyFSM({
|
|
390
|
+
states: [
|
|
391
|
+
{
|
|
392
|
+
name: exports.WORKFLOW_STATES.INTAKE,
|
|
393
|
+
description: 'Receive and parse the incoming task',
|
|
394
|
+
authorizedAgents: [orch],
|
|
395
|
+
authorizedTools: { [orch]: ['read_intake', 'write_blackboard', 'parse_task'] },
|
|
396
|
+
timeoutMs: 30_000,
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
name: exports.WORKFLOW_STATES.VALIDATE,
|
|
400
|
+
description: 'Validate task feasibility and permissions',
|
|
401
|
+
authorizedAgents: [orch],
|
|
402
|
+
authorizedTools: { [orch]: ['check_permission', 'validate_schema', 'write_blackboard'] },
|
|
403
|
+
timeoutMs: 60_000,
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
name: exports.WORKFLOW_STATES.RESEARCH,
|
|
407
|
+
description: 'Gather information required for the task',
|
|
408
|
+
authorizedAgents: [analyst],
|
|
409
|
+
authorizedTools: { [analyst]: ['query_db', 'search_web', 'read_blackboard', 'write_blackboard'] },
|
|
410
|
+
timeoutMs: 120_000,
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
name: exports.WORKFLOW_STATES.PLAN,
|
|
414
|
+
description: 'Build execution plan from research results',
|
|
415
|
+
authorizedAgents: [orch],
|
|
416
|
+
authorizedTools: { [orch]: ['read_blackboard', 'write_blackboard', 'decompose_task'] },
|
|
417
|
+
timeoutMs: 60_000,
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
name: exports.WORKFLOW_STATES.EXECUTE,
|
|
421
|
+
description: 'Execute the planned steps',
|
|
422
|
+
authorizedAgents: [exec],
|
|
423
|
+
authorizedTools: { [exec]: ['run_code', 'call_api', 'write_blackboard', 'read_blackboard'] },
|
|
424
|
+
timeoutMs: 300_000,
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: exports.WORKFLOW_STATES.REVIEW,
|
|
428
|
+
description: 'Review execution output for quality',
|
|
429
|
+
authorizedAgents: [reviewer, orch],
|
|
430
|
+
authorizedTools: {
|
|
431
|
+
[reviewer]: ['read_blackboard', 'quality_gate', 'write_review'],
|
|
432
|
+
[orch]: ['read_blackboard', 'quality_gate'],
|
|
433
|
+
},
|
|
434
|
+
timeoutMs: 120_000,
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: exports.WORKFLOW_STATES.DELIVER,
|
|
438
|
+
description: 'Deliver results to requesting system',
|
|
439
|
+
authorizedAgents: [orch],
|
|
440
|
+
authorizedTools: { [orch]: ['write_output', 'notify', 'write_blackboard'] },
|
|
441
|
+
timeoutMs: 30_000,
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
name: exports.WORKFLOW_STATES.COMPLETE,
|
|
445
|
+
description: 'Terminal state — workflow complete',
|
|
446
|
+
authorizedAgents: ['*'],
|
|
447
|
+
authorizedTools: { '*': ['read_blackboard'] },
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
name: exports.WORKFLOW_STATES.ERROR,
|
|
451
|
+
description: 'Error recovery state',
|
|
452
|
+
authorizedAgents: [orch, '*'],
|
|
453
|
+
authorizedTools: { '*': ['read_blackboard', 'write_blackboard'] },
|
|
454
|
+
},
|
|
455
|
+
],
|
|
456
|
+
transitions: [
|
|
457
|
+
{ from: exports.WORKFLOW_STATES.INTAKE, event: 'validate', to: exports.WORKFLOW_STATES.VALIDATE, allowedBy: orch },
|
|
458
|
+
{ from: exports.WORKFLOW_STATES.VALIDATE, event: 'start_research', to: exports.WORKFLOW_STATES.RESEARCH, allowedBy: orch },
|
|
459
|
+
{ from: exports.WORKFLOW_STATES.VALIDATE, event: 'validation_fail', to: exports.WORKFLOW_STATES.ERROR, allowedBy: orch },
|
|
460
|
+
{ from: exports.WORKFLOW_STATES.RESEARCH, event: 'research_done', to: exports.WORKFLOW_STATES.PLAN, allowedBy: analyst },
|
|
461
|
+
{ from: exports.WORKFLOW_STATES.RESEARCH, event: 'research_fail', to: exports.WORKFLOW_STATES.ERROR, allowedBy: analyst },
|
|
462
|
+
{ from: exports.WORKFLOW_STATES.PLAN, event: 'execute', to: exports.WORKFLOW_STATES.EXECUTE, allowedBy: orch },
|
|
463
|
+
{ from: exports.WORKFLOW_STATES.EXECUTE, event: 'execution_done', to: exports.WORKFLOW_STATES.REVIEW, allowedBy: exec },
|
|
464
|
+
{ from: exports.WORKFLOW_STATES.EXECUTE, event: 'execution_fail', to: exports.WORKFLOW_STATES.ERROR, allowedBy: exec },
|
|
465
|
+
{ from: exports.WORKFLOW_STATES.REVIEW, event: 'approved', to: exports.WORKFLOW_STATES.DELIVER, allowedBy: '*' },
|
|
466
|
+
{ from: exports.WORKFLOW_STATES.REVIEW, event: 'rejected', to: exports.WORKFLOW_STATES.EXECUTE, allowedBy: '*' },
|
|
467
|
+
{ from: exports.WORKFLOW_STATES.DELIVER, event: 'delivered', to: exports.WORKFLOW_STATES.COMPLETE, allowedBy: orch },
|
|
468
|
+
{ from: exports.WORKFLOW_STATES.ERROR, event: 'retry', to: exports.WORKFLOW_STATES.INTAKE, allowedBy: orch },
|
|
469
|
+
{ from: exports.WORKFLOW_STATES.ERROR, event: 'abort', to: exports.WORKFLOW_STATES.COMPLETE, allowedBy: orch },
|
|
470
|
+
],
|
|
471
|
+
initialState: exports.WORKFLOW_STATES.INTAKE,
|
|
472
|
+
onTransition: options.onTransition,
|
|
473
|
+
onViolation: options.onViolation,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
//# sourceMappingURL=fsm-journey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsm-journey.js","sourceRoot":"","sources":["../../lib/fsm-journey.ts"],"names":[],"mappings":";AA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AAC;AACL,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Blackboard Tool Bindings — Phase 4: Behavioral Control Plane
|
|
3
|
+
*
|
|
4
|
+
* Exposes the shared blackboard as MCP-compatible tool definitions so any
|
|
5
|
+
* LLM agent can interact with shared state via standard tool calls.
|
|
6
|
+
*
|
|
7
|
+
* Tools exposed:
|
|
8
|
+
* - blackboard_read — read a single entry by key
|
|
9
|
+
* - blackboard_write — write a value to the blackboard
|
|
10
|
+
* - blackboard_list — list all keys (optionally filtered by prefix)
|
|
11
|
+
* - blackboard_delete — delete an entry by key
|
|
12
|
+
* - blackboard_exists — check whether a key is present and not expired
|
|
13
|
+
*
|
|
14
|
+
* @module mcp-blackboard-tools
|
|
15
|
+
*/
|
|
16
|
+
/** JSON Schema subset sufficient for MCP tool descriptors. */
|
|
17
|
+
export interface MCPJsonSchema {
|
|
18
|
+
type: 'object';
|
|
19
|
+
properties: Record<string, {
|
|
20
|
+
type: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
enum?: string[];
|
|
23
|
+
}>;
|
|
24
|
+
required?: string[];
|
|
25
|
+
}
|
|
26
|
+
/** MCP tool definition (matches Model Context Protocol spec). */
|
|
27
|
+
export interface MCPToolDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
inputSchema: MCPJsonSchema;
|
|
31
|
+
}
|
|
32
|
+
/** Normalised result returned by every blackboard tool call. */
|
|
33
|
+
export interface BlackboardToolResult {
|
|
34
|
+
ok: boolean;
|
|
35
|
+
tool: string;
|
|
36
|
+
data?: unknown;
|
|
37
|
+
error?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Minimal interface required by the tool bindings. */
|
|
40
|
+
export interface IBlackboard {
|
|
41
|
+
read(key: string): {
|
|
42
|
+
key: string;
|
|
43
|
+
value: unknown;
|
|
44
|
+
sourceAgent: string;
|
|
45
|
+
timestamp: string;
|
|
46
|
+
ttl: number | null;
|
|
47
|
+
} | null;
|
|
48
|
+
write(key: string, value: unknown, sourceAgent: string, ttl?: number, agentToken?: string): {
|
|
49
|
+
key: string;
|
|
50
|
+
value: unknown;
|
|
51
|
+
sourceAgent: string;
|
|
52
|
+
timestamp: string;
|
|
53
|
+
ttl: number | null;
|
|
54
|
+
};
|
|
55
|
+
exists(key: string): boolean;
|
|
56
|
+
getSnapshot(): Record<string, {
|
|
57
|
+
key: string;
|
|
58
|
+
value: unknown;
|
|
59
|
+
sourceAgent: string;
|
|
60
|
+
timestamp: string;
|
|
61
|
+
ttl: number | null;
|
|
62
|
+
}>;
|
|
63
|
+
delete?: (key: string) => void;
|
|
64
|
+
getScopedSnapshot?: (agentId: string) => Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
/** MCP tool definitions for all five blackboard operations. */
|
|
67
|
+
export declare const BLACKBOARD_TOOL_DEFINITIONS: MCPToolDefinition[];
|
|
68
|
+
/**
|
|
69
|
+
* MCP-compatible tool handler wrapping a {@link IBlackboard} instance.
|
|
70
|
+
*
|
|
71
|
+
* Register it with any MCP adapter to expose shared blackboard operations
|
|
72
|
+
* as callable tools for LLM agents.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { BlackboardMCPTools } from 'network-ai';
|
|
77
|
+
*
|
|
78
|
+
* const tools = new BlackboardMCPTools(orchestrator.blackboard);
|
|
79
|
+
*
|
|
80
|
+
* // Register with the MCP adapter
|
|
81
|
+
* for (const def of tools.getDefinitions()) {
|
|
82
|
+
* mcpAdapter.registerTool(def.name, (args) => tools.call(def.name, args), def);
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* // Or call directly for testing
|
|
86
|
+
* const result = await tools.call('blackboard_read', {
|
|
87
|
+
* key: 'task:q3_analysis',
|
|
88
|
+
* agent_id: 'data_analyst',
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare class BlackboardMCPTools {
|
|
93
|
+
private readonly blackboard;
|
|
94
|
+
constructor(blackboard: IBlackboard);
|
|
95
|
+
/** Returns all MCP tool definitions for this blackboard instance. */
|
|
96
|
+
getDefinitions(): MCPToolDefinition[];
|
|
97
|
+
/**
|
|
98
|
+
* Dispatch a tool call by name. `args` should match the tool's inputSchema.
|
|
99
|
+
* All errors are caught and returned as `{ ok: false, error }`.
|
|
100
|
+
*/
|
|
101
|
+
call(toolName: string, args: Record<string, unknown>): Promise<BlackboardToolResult>;
|
|
102
|
+
private _read;
|
|
103
|
+
private _write;
|
|
104
|
+
private _list;
|
|
105
|
+
private _delete;
|
|
106
|
+
private _exists;
|
|
107
|
+
private _requireString;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Convenience factory: create a `BlackboardMCPTools` instance and register
|
|
111
|
+
* all tools on an MCPAdapter in one call.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* import { registerBlackboardTools } from 'network-ai';
|
|
116
|
+
*
|
|
117
|
+
* registerBlackboardTools(mcpAdapter, orchestrator.getBlackboard());
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function registerBlackboardTools(mcpAdapter: {
|
|
121
|
+
registerTool(name: string, handler: (args: Record<string, unknown>) => Promise<unknown>, metadata?: {
|
|
122
|
+
description?: string;
|
|
123
|
+
inputSchema?: Record<string, unknown>;
|
|
124
|
+
}): void;
|
|
125
|
+
}, blackboard: IBlackboard): BlackboardMCPTools;
|
|
126
|
+
//# sourceMappingURL=mcp-blackboard-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-blackboard-tools.d.ts","sourceRoot":"","sources":["../../lib/mcp-blackboard-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAA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