agentic-flow 1.8.11 → 1.8.14
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 +58 -0
- package/dist/agents/claudeAgentDirect.js +168 -0
- package/dist/cli/federation-cli.d.ts +53 -0
- package/dist/cli/federation-cli.js +431 -0
- package/dist/cli-proxy.js +32 -4
- package/dist/federation/EphemeralAgent.js +258 -0
- package/dist/federation/FederationHub.js +283 -0
- package/dist/federation/FederationHubClient.js +212 -0
- package/dist/federation/FederationHubServer.js +436 -0
- package/dist/federation/SecurityManager.js +191 -0
- package/dist/federation/debug/agent-debug-stream.js +474 -0
- package/dist/federation/debug/debug-stream.js +419 -0
- package/dist/federation/index.js +12 -0
- package/dist/federation/integrations/realtime-federation.js +404 -0
- package/dist/federation/integrations/supabase-adapter-debug.js +400 -0
- package/dist/federation/integrations/supabase-adapter.js +258 -0
- package/dist/utils/cli.js +5 -0
- package/docs/architecture/FEDERATION-DATA-LIFECYCLE.md +520 -0
- package/docs/federation/AGENT-DEBUG-STREAMING.md +403 -0
- package/docs/federation/DEBUG-STREAMING-COMPLETE.md +432 -0
- package/docs/federation/DEBUG-STREAMING.md +537 -0
- package/docs/federation/DEPLOYMENT-VALIDATION-SUCCESS.md +394 -0
- package/docs/federation/DOCKER-FEDERATION-DEEP-REVIEW.md +478 -0
- package/docs/issues/ISSUE-SUPABASE-INTEGRATION.md +536 -0
- package/docs/releases/RELEASE-v1.8.13.md +426 -0
- package/docs/supabase/IMPLEMENTATION-SUMMARY.md +498 -0
- package/docs/supabase/INDEX.md +358 -0
- package/docs/supabase/QUICKSTART.md +365 -0
- package/docs/supabase/README.md +318 -0
- package/docs/supabase/SUPABASE-REALTIME-FEDERATION.md +575 -0
- package/docs/supabase/TEST-REPORT.md +446 -0
- package/docs/supabase/migrations/001_create_federation_tables.sql +339 -0
- package/docs/validation/reports/REGRESSION-TEST-V1.8.11.md +456 -0
- package/package.json +4 -1
- package/wasm/reasoningbank/reasoningbank_wasm_bg.js +2 -2
- package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm +0 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug Streaming System for Federation
|
|
3
|
+
*
|
|
4
|
+
* Provides detailed, real-time visibility into agent operations
|
|
5
|
+
* with multiple verbosity levels and customizable output formats.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Multiple debug levels (SILENT, BASIC, DETAILED, VERBOSE, TRACE)
|
|
9
|
+
* - Real-time event streaming
|
|
10
|
+
* - Performance metrics and timing
|
|
11
|
+
* - Stack traces and context
|
|
12
|
+
* - Customizable formatters
|
|
13
|
+
* - File and console output
|
|
14
|
+
* - JSON and human-readable formats
|
|
15
|
+
*/
|
|
16
|
+
import { EventEmitter } from 'events';
|
|
17
|
+
import { createWriteStream } from 'fs';
|
|
18
|
+
export var DebugLevel;
|
|
19
|
+
(function (DebugLevel) {
|
|
20
|
+
DebugLevel[DebugLevel["SILENT"] = 0] = "SILENT";
|
|
21
|
+
DebugLevel[DebugLevel["BASIC"] = 1] = "BASIC";
|
|
22
|
+
DebugLevel[DebugLevel["DETAILED"] = 2] = "DETAILED";
|
|
23
|
+
DebugLevel[DebugLevel["VERBOSE"] = 3] = "VERBOSE";
|
|
24
|
+
DebugLevel[DebugLevel["TRACE"] = 4] = "TRACE";
|
|
25
|
+
})(DebugLevel || (DebugLevel = {}));
|
|
26
|
+
export class DebugStream extends EventEmitter {
|
|
27
|
+
config;
|
|
28
|
+
fileStream;
|
|
29
|
+
eventBuffer = [];
|
|
30
|
+
metrics = new Map();
|
|
31
|
+
constructor(config = {}) {
|
|
32
|
+
super();
|
|
33
|
+
this.config = {
|
|
34
|
+
level: config.level ?? DebugLevel.BASIC,
|
|
35
|
+
output: config.output ?? 'console',
|
|
36
|
+
format: config.format ?? 'human',
|
|
37
|
+
includeTimestamps: config.includeTimestamps ?? true,
|
|
38
|
+
includeStackTraces: config.includeStackTraces ?? false,
|
|
39
|
+
includeMetadata: config.includeMetadata ?? true,
|
|
40
|
+
colorize: config.colorize ?? true,
|
|
41
|
+
filterCategories: config.filterCategories,
|
|
42
|
+
filterAgents: config.filterAgents,
|
|
43
|
+
outputFile: config.outputFile,
|
|
44
|
+
customStream: config.customStream,
|
|
45
|
+
};
|
|
46
|
+
if (this.config.outputFile && (this.config.output === 'file' || this.config.output === 'both')) {
|
|
47
|
+
this.fileStream = createWriteStream(this.config.outputFile, { flags: 'a' });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Log a debug event
|
|
52
|
+
*/
|
|
53
|
+
log(event) {
|
|
54
|
+
// Check if event should be logged based on level
|
|
55
|
+
if (event.level > this.config.level) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// Apply filters
|
|
59
|
+
if (this.config.filterCategories && !this.config.filterCategories.includes(event.category)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (this.config.filterAgents && event.agentId && !this.config.filterAgents.includes(event.agentId)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const fullEvent = {
|
|
66
|
+
...event,
|
|
67
|
+
timestamp: new Date().toISOString(),
|
|
68
|
+
stackTrace: this.config.includeStackTraces ? this.captureStackTrace() : undefined,
|
|
69
|
+
};
|
|
70
|
+
// Buffer event
|
|
71
|
+
this.eventBuffer.push(fullEvent);
|
|
72
|
+
// Update metrics
|
|
73
|
+
if (event.duration !== undefined) {
|
|
74
|
+
const key = `${event.category}:${event.operation}`;
|
|
75
|
+
const existing = this.metrics.get(key) || { count: 0, totalDuration: 0 };
|
|
76
|
+
this.metrics.set(key, {
|
|
77
|
+
count: existing.count + 1,
|
|
78
|
+
totalDuration: existing.totalDuration + event.duration,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// Output event
|
|
82
|
+
this.outputEvent(fullEvent);
|
|
83
|
+
// Emit for external listeners
|
|
84
|
+
this.emit('event', fullEvent);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Log connection events
|
|
88
|
+
*/
|
|
89
|
+
logConnection(operation, data, error) {
|
|
90
|
+
this.log({
|
|
91
|
+
level: DebugLevel.BASIC,
|
|
92
|
+
category: 'connection',
|
|
93
|
+
operation,
|
|
94
|
+
data,
|
|
95
|
+
error,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Log database operations
|
|
100
|
+
*/
|
|
101
|
+
logDatabase(operation, data, duration, error) {
|
|
102
|
+
this.log({
|
|
103
|
+
level: DebugLevel.DETAILED,
|
|
104
|
+
category: 'database',
|
|
105
|
+
operation,
|
|
106
|
+
data,
|
|
107
|
+
duration,
|
|
108
|
+
error,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Log realtime events
|
|
113
|
+
*/
|
|
114
|
+
logRealtime(operation, agentId, data, duration) {
|
|
115
|
+
this.log({
|
|
116
|
+
level: DebugLevel.VERBOSE,
|
|
117
|
+
category: 'realtime',
|
|
118
|
+
operation,
|
|
119
|
+
agentId,
|
|
120
|
+
data,
|
|
121
|
+
duration,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Log memory operations
|
|
126
|
+
*/
|
|
127
|
+
logMemory(operation, agentId, tenantId, data, duration) {
|
|
128
|
+
this.log({
|
|
129
|
+
level: DebugLevel.DETAILED,
|
|
130
|
+
category: 'memory',
|
|
131
|
+
operation,
|
|
132
|
+
agentId,
|
|
133
|
+
tenantId,
|
|
134
|
+
data,
|
|
135
|
+
duration,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Log task operations
|
|
140
|
+
*/
|
|
141
|
+
logTask(operation, agentId, tenantId, data, duration) {
|
|
142
|
+
this.log({
|
|
143
|
+
level: DebugLevel.VERBOSE,
|
|
144
|
+
category: 'task',
|
|
145
|
+
operation,
|
|
146
|
+
agentId,
|
|
147
|
+
tenantId,
|
|
148
|
+
data,
|
|
149
|
+
duration,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Log internal state changes
|
|
154
|
+
*/
|
|
155
|
+
logTrace(operation, data) {
|
|
156
|
+
this.log({
|
|
157
|
+
level: DebugLevel.TRACE,
|
|
158
|
+
category: 'trace',
|
|
159
|
+
operation,
|
|
160
|
+
data,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Output event to configured destinations
|
|
165
|
+
*/
|
|
166
|
+
outputEvent(event) {
|
|
167
|
+
const formatted = this.formatEvent(event);
|
|
168
|
+
if (this.config.output === 'console' || this.config.output === 'both') {
|
|
169
|
+
console.log(formatted);
|
|
170
|
+
}
|
|
171
|
+
if (this.config.output === 'file' || this.config.output === 'both') {
|
|
172
|
+
if (this.fileStream) {
|
|
173
|
+
this.fileStream.write(formatted + '\n');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (this.config.output === 'stream' && this.config.customStream) {
|
|
177
|
+
this.config.customStream.write(formatted + '\n');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Format event for output
|
|
182
|
+
*/
|
|
183
|
+
formatEvent(event) {
|
|
184
|
+
if (this.config.format === 'json') {
|
|
185
|
+
return JSON.stringify(event);
|
|
186
|
+
}
|
|
187
|
+
if (this.config.format === 'compact') {
|
|
188
|
+
return this.formatCompact(event);
|
|
189
|
+
}
|
|
190
|
+
return this.formatHuman(event);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Format event in human-readable format
|
|
194
|
+
*/
|
|
195
|
+
formatHuman(event) {
|
|
196
|
+
const parts = [];
|
|
197
|
+
// Timestamp
|
|
198
|
+
if (this.config.includeTimestamps) {
|
|
199
|
+
const timestamp = this.colorize(event.timestamp, 'gray');
|
|
200
|
+
parts.push(`[${timestamp}]`);
|
|
201
|
+
}
|
|
202
|
+
// Level
|
|
203
|
+
const levelStr = this.getLevelString(event.level);
|
|
204
|
+
parts.push(this.colorize(levelStr, this.getLevelColor(event.level)));
|
|
205
|
+
// Category
|
|
206
|
+
parts.push(this.colorize(event.category.toUpperCase(), 'cyan'));
|
|
207
|
+
// Agent/Tenant
|
|
208
|
+
if (event.agentId) {
|
|
209
|
+
parts.push(this.colorize(`agent=${event.agentId}`, 'blue'));
|
|
210
|
+
}
|
|
211
|
+
if (event.tenantId) {
|
|
212
|
+
parts.push(this.colorize(`tenant=${event.tenantId}`, 'blue'));
|
|
213
|
+
}
|
|
214
|
+
// Operation
|
|
215
|
+
parts.push(this.colorize(event.operation, 'white'));
|
|
216
|
+
// Duration
|
|
217
|
+
if (event.duration !== undefined) {
|
|
218
|
+
const durationStr = `${event.duration.toFixed(2)}ms`;
|
|
219
|
+
parts.push(this.colorize(durationStr, 'yellow'));
|
|
220
|
+
}
|
|
221
|
+
let output = parts.join(' ');
|
|
222
|
+
// Data
|
|
223
|
+
if (event.data && this.config.includeMetadata) {
|
|
224
|
+
const dataStr = typeof event.data === 'string'
|
|
225
|
+
? event.data
|
|
226
|
+
: JSON.stringify(event.data, null, 2);
|
|
227
|
+
output += '\n ' + this.colorize('Data:', 'gray') + ' ' + dataStr;
|
|
228
|
+
}
|
|
229
|
+
// Metadata
|
|
230
|
+
if (event.metadata && this.config.includeMetadata) {
|
|
231
|
+
output += '\n ' + this.colorize('Metadata:', 'gray') + ' ' + JSON.stringify(event.metadata);
|
|
232
|
+
}
|
|
233
|
+
// Error
|
|
234
|
+
if (event.error) {
|
|
235
|
+
output += '\n ' + this.colorize('Error:', 'red') + ' ' + event.error.message;
|
|
236
|
+
if (event.error.stack) {
|
|
237
|
+
output += '\n ' + this.colorize('Stack:', 'red') + '\n' + event.error.stack
|
|
238
|
+
.split('\n')
|
|
239
|
+
.map(line => ' ' + line)
|
|
240
|
+
.join('\n');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// Stack trace
|
|
244
|
+
if (event.stackTrace && this.config.includeStackTraces) {
|
|
245
|
+
output += '\n ' + this.colorize('Trace:', 'gray') + '\n' + event.stackTrace
|
|
246
|
+
.split('\n')
|
|
247
|
+
.slice(0, 5)
|
|
248
|
+
.map(line => ' ' + line)
|
|
249
|
+
.join('\n');
|
|
250
|
+
}
|
|
251
|
+
return output;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Format event in compact format
|
|
255
|
+
*/
|
|
256
|
+
formatCompact(event) {
|
|
257
|
+
const parts = [];
|
|
258
|
+
if (this.config.includeTimestamps) {
|
|
259
|
+
parts.push(event.timestamp);
|
|
260
|
+
}
|
|
261
|
+
parts.push(this.getLevelString(event.level));
|
|
262
|
+
parts.push(event.category);
|
|
263
|
+
if (event.agentId)
|
|
264
|
+
parts.push(`a=${event.agentId}`);
|
|
265
|
+
if (event.tenantId)
|
|
266
|
+
parts.push(`t=${event.tenantId}`);
|
|
267
|
+
parts.push(event.operation);
|
|
268
|
+
if (event.duration !== undefined) {
|
|
269
|
+
parts.push(`${event.duration.toFixed(0)}ms`);
|
|
270
|
+
}
|
|
271
|
+
if (event.error) {
|
|
272
|
+
parts.push(`ERROR: ${event.error.message}`);
|
|
273
|
+
}
|
|
274
|
+
return parts.join(' | ');
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Get level string
|
|
278
|
+
*/
|
|
279
|
+
getLevelString(level) {
|
|
280
|
+
switch (level) {
|
|
281
|
+
case DebugLevel.SILENT: return 'SILENT';
|
|
282
|
+
case DebugLevel.BASIC: return 'BASIC ';
|
|
283
|
+
case DebugLevel.DETAILED: return 'DETAIL';
|
|
284
|
+
case DebugLevel.VERBOSE: return 'VERBOS';
|
|
285
|
+
case DebugLevel.TRACE: return 'TRACE ';
|
|
286
|
+
default: return 'UNKNOWN';
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get color for level
|
|
291
|
+
*/
|
|
292
|
+
getLevelColor(level) {
|
|
293
|
+
switch (level) {
|
|
294
|
+
case DebugLevel.BASIC: return 'green';
|
|
295
|
+
case DebugLevel.DETAILED: return 'blue';
|
|
296
|
+
case DebugLevel.VERBOSE: return 'magenta';
|
|
297
|
+
case DebugLevel.TRACE: return 'gray';
|
|
298
|
+
default: return 'white';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Colorize text
|
|
303
|
+
*/
|
|
304
|
+
colorize(text, color) {
|
|
305
|
+
if (!this.config.colorize)
|
|
306
|
+
return text;
|
|
307
|
+
const colors = {
|
|
308
|
+
gray: '\x1b[90m',
|
|
309
|
+
red: '\x1b[31m',
|
|
310
|
+
green: '\x1b[32m',
|
|
311
|
+
yellow: '\x1b[33m',
|
|
312
|
+
blue: '\x1b[34m',
|
|
313
|
+
magenta: '\x1b[35m',
|
|
314
|
+
cyan: '\x1b[36m',
|
|
315
|
+
white: '\x1b[37m',
|
|
316
|
+
};
|
|
317
|
+
const reset = '\x1b[0m';
|
|
318
|
+
return (colors[color] || '') + text + reset;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Capture stack trace
|
|
322
|
+
*/
|
|
323
|
+
captureStackTrace() {
|
|
324
|
+
const stack = new Error().stack || '';
|
|
325
|
+
return stack
|
|
326
|
+
.split('\n')
|
|
327
|
+
.slice(3) // Skip DebugStream internal frames
|
|
328
|
+
.join('\n');
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get metrics summary
|
|
332
|
+
*/
|
|
333
|
+
getMetrics() {
|
|
334
|
+
const summary = {};
|
|
335
|
+
for (const [key, value] of this.metrics.entries()) {
|
|
336
|
+
summary[key] = {
|
|
337
|
+
count: value.count,
|
|
338
|
+
avgDuration: value.totalDuration / value.count,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
return summary;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Print metrics summary
|
|
345
|
+
*/
|
|
346
|
+
printMetrics() {
|
|
347
|
+
console.log('\n' + this.colorize('='.repeat(60), 'cyan'));
|
|
348
|
+
console.log(this.colorize('Performance Metrics Summary', 'cyan'));
|
|
349
|
+
console.log(this.colorize('='.repeat(60), 'cyan') + '\n');
|
|
350
|
+
const metrics = this.getMetrics();
|
|
351
|
+
const sorted = Object.entries(metrics).sort((a, b) => b[1].count - a[1].count);
|
|
352
|
+
console.log(this.colorize('Operation'.padEnd(40) + 'Count'.padEnd(10) + 'Avg Duration', 'white'));
|
|
353
|
+
console.log(this.colorize('-'.repeat(60), 'gray'));
|
|
354
|
+
for (const [key, value] of sorted) {
|
|
355
|
+
const countStr = value.count.toString().padEnd(10);
|
|
356
|
+
const durationStr = value.avgDuration.toFixed(2) + 'ms';
|
|
357
|
+
console.log(key.padEnd(40) +
|
|
358
|
+
this.colorize(countStr, 'yellow') +
|
|
359
|
+
this.colorize(durationStr, 'green'));
|
|
360
|
+
}
|
|
361
|
+
console.log('\n' + this.colorize('='.repeat(60), 'cyan') + '\n');
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Get event buffer
|
|
365
|
+
*/
|
|
366
|
+
getEvents(filter) {
|
|
367
|
+
let events = [...this.eventBuffer];
|
|
368
|
+
if (filter?.category) {
|
|
369
|
+
events = events.filter(e => e.category === filter.category);
|
|
370
|
+
}
|
|
371
|
+
if (filter?.agentId) {
|
|
372
|
+
events = events.filter(e => e.agentId === filter.agentId);
|
|
373
|
+
}
|
|
374
|
+
if (filter?.since) {
|
|
375
|
+
events = events.filter(e => new Date(e.timestamp) >= filter.since);
|
|
376
|
+
}
|
|
377
|
+
return events;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Clear event buffer
|
|
381
|
+
*/
|
|
382
|
+
clearEvents() {
|
|
383
|
+
this.eventBuffer = [];
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Clear metrics
|
|
387
|
+
*/
|
|
388
|
+
clearMetrics() {
|
|
389
|
+
this.metrics.clear();
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Close file stream
|
|
393
|
+
*/
|
|
394
|
+
close() {
|
|
395
|
+
if (this.fileStream) {
|
|
396
|
+
this.fileStream.end();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Create debug stream with sensible defaults
|
|
402
|
+
*/
|
|
403
|
+
export function createDebugStream(config) {
|
|
404
|
+
return new DebugStream(config);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Get debug level from environment variable
|
|
408
|
+
*/
|
|
409
|
+
export function getDebugLevelFromEnv() {
|
|
410
|
+
const level = process.env.DEBUG_LEVEL?.toUpperCase();
|
|
411
|
+
switch (level) {
|
|
412
|
+
case 'SILENT': return DebugLevel.SILENT;
|
|
413
|
+
case 'BASIC': return DebugLevel.BASIC;
|
|
414
|
+
case 'DETAILED': return DebugLevel.DETAILED;
|
|
415
|
+
case 'VERBOSE': return DebugLevel.VERBOSE;
|
|
416
|
+
case 'TRACE': return DebugLevel.TRACE;
|
|
417
|
+
default: return DebugLevel.BASIC;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Federated AgentDB - Main exports
|
|
3
|
+
*
|
|
4
|
+
* Provides secure federated memory for ephemeral agents with:
|
|
5
|
+
* - QUIC-based synchronization
|
|
6
|
+
* - Zero-trust security (mTLS + JWT + AES-256)
|
|
7
|
+
* - Tenant isolation
|
|
8
|
+
* - Vector clock conflict resolution
|
|
9
|
+
*/
|
|
10
|
+
export { EphemeralAgent } from './EphemeralAgent.js';
|
|
11
|
+
export { FederationHub } from './FederationHub.js';
|
|
12
|
+
export { SecurityManager } from './SecurityManager.js';
|