@sparkleideas/ruv-swarm 1.0.18-patch.1
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/README.md +1565 -0
- package/bin/ruv-swarm-clean.js +1872 -0
- package/bin/ruv-swarm-memory.js +119 -0
- package/bin/ruv-swarm-secure-heartbeat.js +1549 -0
- package/bin/ruv-swarm-secure.js +1689 -0
- package/package.json +221 -0
- package/src/agent.ts +342 -0
- package/src/benchmark.js +267 -0
- package/src/claude-flow-enhanced.js +839 -0
- package/src/claude-integration/advanced-commands.js +561 -0
- package/src/claude-integration/core.js +112 -0
- package/src/claude-integration/docs.js +1548 -0
- package/src/claude-integration/env-template.js +39 -0
- package/src/claude-integration/index.js +209 -0
- package/src/claude-integration/remote.js +408 -0
- package/src/cli-diagnostics.js +364 -0
- package/src/cognitive-pattern-evolution.js +1317 -0
- package/src/daa-cognition.js +977 -0
- package/src/daa-service.d.ts +298 -0
- package/src/daa-service.js +1116 -0
- package/src/diagnostics.js +533 -0
- package/src/errors.js +528 -0
- package/src/github-coordinator/README.md +193 -0
- package/src/github-coordinator/claude-hooks.js +162 -0
- package/src/github-coordinator/gh-cli-coordinator.js +260 -0
- package/src/hooks/cli.js +82 -0
- package/src/hooks/index.js +1900 -0
- package/src/index-enhanced.d.ts +371 -0
- package/src/index-enhanced.js +734 -0
- package/src/index.d.ts +287 -0
- package/src/index.js +405 -0
- package/src/index.ts +457 -0
- package/src/logger.js +182 -0
- package/src/logging-config.js +179 -0
- package/src/mcp-daa-tools.js +735 -0
- package/src/mcp-tools-benchmarks.js +328 -0
- package/src/mcp-tools-enhanced.js +2863 -0
- package/src/memory-config.js +42 -0
- package/src/meta-learning-framework.js +1359 -0
- package/src/neural-agent.js +830 -0
- package/src/neural-coordination-protocol.js +1363 -0
- package/src/neural-models/README.md +118 -0
- package/src/neural-models/autoencoder.js +543 -0
- package/src/neural-models/base.js +269 -0
- package/src/neural-models/cnn.js +497 -0
- package/src/neural-models/gnn.js +447 -0
- package/src/neural-models/gru.js +536 -0
- package/src/neural-models/index.js +273 -0
- package/src/neural-models/lstm.js +551 -0
- package/src/neural-models/neural-presets-complete.js +1306 -0
- package/src/neural-models/presets/graph.js +392 -0
- package/src/neural-models/presets/index.js +279 -0
- package/src/neural-models/presets/nlp.js +328 -0
- package/src/neural-models/presets/timeseries.js +368 -0
- package/src/neural-models/presets/vision.js +387 -0
- package/src/neural-models/resnet.js +534 -0
- package/src/neural-models/transformer.js +515 -0
- package/src/neural-models/vae.js +489 -0
- package/src/neural-network-manager.js +1938 -0
- package/src/neural-network.ts +296 -0
- package/src/neural.js +574 -0
- package/src/performance-benchmarks.js +898 -0
- package/src/performance.js +458 -0
- package/src/persistence-pooled.js +695 -0
- package/src/persistence.js +480 -0
- package/src/schemas.js +864 -0
- package/src/security.js +218 -0
- package/src/singleton-container.js +183 -0
- package/src/sqlite-pool.js +587 -0
- package/src/sqlite-worker.js +141 -0
- package/src/types.ts +164 -0
- package/src/utils.ts +286 -0
- package/src/wasm-loader.js +601 -0
- package/src/wasm-loader2.js +404 -0
- package/src/wasm-memory-optimizer.js +783 -0
- package/src/wasm-types.d.ts +63 -0
- package/wasm/README.md +347 -0
- package/wasm/neuro-divergent.wasm +0 -0
- package/wasm/package.json +18 -0
- package/wasm/ruv-fann.wasm +0 -0
- package/wasm/ruv_swarm_simd.wasm +0 -0
- package/wasm/ruv_swarm_wasm.d.ts +391 -0
- package/wasm/ruv_swarm_wasm.js +2164 -0
- package/wasm/ruv_swarm_wasm_bg.wasm +0 -0
- package/wasm/ruv_swarm_wasm_bg.wasm.d.ts +123 -0
- package/wasm/wasm-bindings-loader.mjs +435 -0
- package/wasm/wasm-updates.md +684 -0
package/src/schemas.js
ADDED
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Validation Schemas for RUV-Swarm MCP Tools
|
|
3
|
+
* Provides comprehensive validation for all 25+ MCP tools
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ValidationError } from './errors.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base validator class
|
|
10
|
+
*/
|
|
11
|
+
class BaseValidator {
|
|
12
|
+
static validate(value, schema, fieldName = 'value') {
|
|
13
|
+
try {
|
|
14
|
+
return this.validateValue(value, schema, fieldName);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (error instanceof ValidationError) {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
throw new ValidationError(
|
|
20
|
+
`Validation failed for ${fieldName}: ${error.message}`,
|
|
21
|
+
fieldName,
|
|
22
|
+
value,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static validateValue(value, schema, fieldName) {
|
|
28
|
+
// Handle required fields
|
|
29
|
+
if (schema.required && (value === undefined || value === null)) {
|
|
30
|
+
throw new ValidationError(
|
|
31
|
+
`${fieldName} is required`,
|
|
32
|
+
fieldName,
|
|
33
|
+
value,
|
|
34
|
+
schema.type,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Handle optional fields
|
|
39
|
+
if (!schema.required && (value === undefined || value === null)) {
|
|
40
|
+
return schema.default;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Type validation
|
|
44
|
+
if (schema.type && !this.validateType(value, schema.type)) {
|
|
45
|
+
throw new ValidationError(
|
|
46
|
+
`${fieldName} must be of type ${schema.type}`,
|
|
47
|
+
fieldName,
|
|
48
|
+
value,
|
|
49
|
+
schema.type,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Range validation for numbers
|
|
54
|
+
if (schema.type === 'number') {
|
|
55
|
+
if (schema.min !== undefined && value < schema.min) {
|
|
56
|
+
throw new ValidationError(
|
|
57
|
+
`${fieldName} must be at least ${schema.min}`,
|
|
58
|
+
fieldName,
|
|
59
|
+
value,
|
|
60
|
+
schema.type,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (schema.max !== undefined && value > schema.max) {
|
|
64
|
+
throw new ValidationError(
|
|
65
|
+
`${fieldName} must be at most ${schema.max}`,
|
|
66
|
+
fieldName,
|
|
67
|
+
value,
|
|
68
|
+
schema.type,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (schema.integer && !Number.isInteger(value)) {
|
|
72
|
+
throw new ValidationError(
|
|
73
|
+
`${fieldName} must be an integer`,
|
|
74
|
+
fieldName,
|
|
75
|
+
value,
|
|
76
|
+
'integer',
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Length validation for strings and arrays
|
|
82
|
+
if (schema.type === 'string' || schema.type === 'array') {
|
|
83
|
+
const length = schema.type === 'string' ? value.length : value.length;
|
|
84
|
+
if (schema.minLength !== undefined && length < schema.minLength) {
|
|
85
|
+
throw new ValidationError(
|
|
86
|
+
`${fieldName} must be at least ${schema.minLength} characters/items long`,
|
|
87
|
+
fieldName,
|
|
88
|
+
value,
|
|
89
|
+
schema.type,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (schema.maxLength !== undefined && length > schema.maxLength) {
|
|
93
|
+
throw new ValidationError(
|
|
94
|
+
`${fieldName} must be at most ${schema.maxLength} characters/items long`,
|
|
95
|
+
fieldName,
|
|
96
|
+
value,
|
|
97
|
+
schema.type,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Enum validation
|
|
103
|
+
if (schema.enum && !schema.enum.includes(value)) {
|
|
104
|
+
throw new ValidationError(
|
|
105
|
+
`${fieldName} must be one of: ${schema.enum.join(', ')}`,
|
|
106
|
+
fieldName,
|
|
107
|
+
value,
|
|
108
|
+
`enum(${schema.enum.join('|')})`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Pattern validation for strings
|
|
113
|
+
if (schema.type === 'string' && schema.pattern) {
|
|
114
|
+
const regex = new RegExp(schema.pattern);
|
|
115
|
+
if (!regex.test(value)) {
|
|
116
|
+
throw new ValidationError(
|
|
117
|
+
`${fieldName} does not match the required pattern`,
|
|
118
|
+
fieldName,
|
|
119
|
+
value,
|
|
120
|
+
'string(pattern)',
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Object property validation
|
|
126
|
+
if (schema.type === 'object' && schema.properties) {
|
|
127
|
+
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
128
|
+
if (value[propName] !== undefined) {
|
|
129
|
+
value[propName] = this.validateValue(value[propName], propSchema, `${fieldName}.${propName}`);
|
|
130
|
+
} else if (propSchema.required) {
|
|
131
|
+
throw new ValidationError(
|
|
132
|
+
`${fieldName}.${propName} is required`,
|
|
133
|
+
`${fieldName}.${propName}`,
|
|
134
|
+
undefined,
|
|
135
|
+
propSchema.type,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Array item validation
|
|
142
|
+
if (schema.type === 'array' && schema.items) {
|
|
143
|
+
for (let i = 0; i < value.length; i++) {
|
|
144
|
+
value[i] = this.validateValue(value[i], schema.items, `${fieldName}[${i}]`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static validateType(value, expectedType) {
|
|
152
|
+
switch (expectedType) {
|
|
153
|
+
case 'string':
|
|
154
|
+
return typeof value === 'string';
|
|
155
|
+
case 'number':
|
|
156
|
+
return typeof value === 'number' && !isNaN(value) && isFinite(value);
|
|
157
|
+
case 'boolean':
|
|
158
|
+
return typeof value === 'boolean';
|
|
159
|
+
case 'array':
|
|
160
|
+
return Array.isArray(value);
|
|
161
|
+
case 'object':
|
|
162
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
163
|
+
case 'function':
|
|
164
|
+
return typeof value === 'function';
|
|
165
|
+
default:
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Schema definitions for all MCP tools
|
|
173
|
+
*/
|
|
174
|
+
const MCPSchemas = {
|
|
175
|
+
// Core Swarm Management
|
|
176
|
+
swarm_init: {
|
|
177
|
+
topology: {
|
|
178
|
+
type: 'string',
|
|
179
|
+
enum: ['mesh', 'hierarchical', 'ring', 'star'],
|
|
180
|
+
default: 'mesh',
|
|
181
|
+
},
|
|
182
|
+
maxAgents: {
|
|
183
|
+
type: 'number',
|
|
184
|
+
integer: true,
|
|
185
|
+
min: 1,
|
|
186
|
+
max: 100,
|
|
187
|
+
default: 5,
|
|
188
|
+
},
|
|
189
|
+
strategy: {
|
|
190
|
+
type: 'string',
|
|
191
|
+
enum: ['balanced', 'specialized', 'adaptive'],
|
|
192
|
+
default: 'balanced',
|
|
193
|
+
},
|
|
194
|
+
enableCognitiveDiversity: {
|
|
195
|
+
type: 'boolean',
|
|
196
|
+
default: true,
|
|
197
|
+
},
|
|
198
|
+
enableNeuralAgents: {
|
|
199
|
+
type: 'boolean',
|
|
200
|
+
default: true,
|
|
201
|
+
},
|
|
202
|
+
enableForecasting: {
|
|
203
|
+
type: 'boolean',
|
|
204
|
+
default: false,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
agent_spawn: {
|
|
209
|
+
type: {
|
|
210
|
+
type: 'string',
|
|
211
|
+
enum: ['researcher', 'coder', 'analyst', 'optimizer', 'coordinator', 'tester', 'reviewer', 'documenter'],
|
|
212
|
+
default: 'researcher',
|
|
213
|
+
},
|
|
214
|
+
name: {
|
|
215
|
+
type: 'string',
|
|
216
|
+
minLength: 1,
|
|
217
|
+
maxLength: 100,
|
|
218
|
+
required: false,
|
|
219
|
+
},
|
|
220
|
+
capabilities: {
|
|
221
|
+
type: 'array',
|
|
222
|
+
items: {
|
|
223
|
+
type: 'string',
|
|
224
|
+
minLength: 1,
|
|
225
|
+
},
|
|
226
|
+
required: false,
|
|
227
|
+
},
|
|
228
|
+
cognitivePattern: {
|
|
229
|
+
type: 'string',
|
|
230
|
+
enum: ['convergent', 'divergent', 'lateral', 'systems', 'critical', 'adaptive'],
|
|
231
|
+
required: false,
|
|
232
|
+
},
|
|
233
|
+
swarmId: {
|
|
234
|
+
type: 'string',
|
|
235
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
236
|
+
required: false,
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
task_orchestrate: {
|
|
241
|
+
task: {
|
|
242
|
+
type: 'string',
|
|
243
|
+
required: true,
|
|
244
|
+
minLength: 1,
|
|
245
|
+
maxLength: 1000,
|
|
246
|
+
},
|
|
247
|
+
priority: {
|
|
248
|
+
type: 'string',
|
|
249
|
+
enum: ['low', 'medium', 'high', 'critical'],
|
|
250
|
+
default: 'medium',
|
|
251
|
+
},
|
|
252
|
+
strategy: {
|
|
253
|
+
type: 'string',
|
|
254
|
+
enum: ['parallel', 'sequential', 'adaptive'],
|
|
255
|
+
default: 'adaptive',
|
|
256
|
+
},
|
|
257
|
+
maxAgents: {
|
|
258
|
+
type: 'number',
|
|
259
|
+
integer: true,
|
|
260
|
+
min: 1,
|
|
261
|
+
max: 50,
|
|
262
|
+
required: false,
|
|
263
|
+
},
|
|
264
|
+
swarmId: {
|
|
265
|
+
type: 'string',
|
|
266
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
267
|
+
required: false,
|
|
268
|
+
},
|
|
269
|
+
requiredCapabilities: {
|
|
270
|
+
type: 'array',
|
|
271
|
+
items: {
|
|
272
|
+
type: 'string',
|
|
273
|
+
minLength: 1,
|
|
274
|
+
},
|
|
275
|
+
required: false,
|
|
276
|
+
},
|
|
277
|
+
estimatedDuration: {
|
|
278
|
+
type: 'number',
|
|
279
|
+
min: 1000,
|
|
280
|
+
max: 3600000, // 1 hour max
|
|
281
|
+
required: false,
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
swarm_status: {
|
|
286
|
+
verbose: {
|
|
287
|
+
type: 'boolean',
|
|
288
|
+
default: false,
|
|
289
|
+
},
|
|
290
|
+
swarmId: {
|
|
291
|
+
type: 'string',
|
|
292
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
293
|
+
required: false,
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
task_status: {
|
|
298
|
+
taskId: {
|
|
299
|
+
type: 'string',
|
|
300
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
301
|
+
required: false,
|
|
302
|
+
},
|
|
303
|
+
detailed: {
|
|
304
|
+
type: 'boolean',
|
|
305
|
+
default: false,
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
task_results: {
|
|
310
|
+
taskId: {
|
|
311
|
+
type: 'string',
|
|
312
|
+
required: true,
|
|
313
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
314
|
+
},
|
|
315
|
+
format: {
|
|
316
|
+
type: 'string',
|
|
317
|
+
enum: ['summary', 'detailed', 'raw', 'performance'],
|
|
318
|
+
default: 'summary',
|
|
319
|
+
},
|
|
320
|
+
includeAgentResults: {
|
|
321
|
+
type: 'boolean',
|
|
322
|
+
default: true,
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
agent_list: {
|
|
327
|
+
filter: {
|
|
328
|
+
type: 'string',
|
|
329
|
+
enum: ['all', 'active', 'idle', 'busy'],
|
|
330
|
+
default: 'all',
|
|
331
|
+
},
|
|
332
|
+
swarmId: {
|
|
333
|
+
type: 'string',
|
|
334
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
335
|
+
required: false,
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
|
|
339
|
+
agent_metrics: {
|
|
340
|
+
agentId: {
|
|
341
|
+
type: 'string',
|
|
342
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
343
|
+
required: false,
|
|
344
|
+
},
|
|
345
|
+
swarmId: {
|
|
346
|
+
type: 'string',
|
|
347
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
348
|
+
required: false,
|
|
349
|
+
},
|
|
350
|
+
metric: {
|
|
351
|
+
type: 'string',
|
|
352
|
+
enum: ['all', 'cpu', 'memory', 'tasks', 'performance', 'neural'],
|
|
353
|
+
default: 'all',
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
benchmark_run: {
|
|
358
|
+
type: {
|
|
359
|
+
type: 'string',
|
|
360
|
+
enum: ['all', 'wasm', 'swarm', 'agent', 'task', 'neural'],
|
|
361
|
+
default: 'all',
|
|
362
|
+
},
|
|
363
|
+
iterations: {
|
|
364
|
+
type: 'number',
|
|
365
|
+
integer: true,
|
|
366
|
+
min: 1,
|
|
367
|
+
max: 100,
|
|
368
|
+
default: 10,
|
|
369
|
+
},
|
|
370
|
+
includeNeuralBenchmarks: {
|
|
371
|
+
type: 'boolean',
|
|
372
|
+
default: true,
|
|
373
|
+
},
|
|
374
|
+
includeSwarmBenchmarks: {
|
|
375
|
+
type: 'boolean',
|
|
376
|
+
default: true,
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
features_detect: {
|
|
381
|
+
category: {
|
|
382
|
+
type: 'string',
|
|
383
|
+
enum: ['all', 'wasm', 'simd', 'memory', 'platform', 'neural', 'forecasting'],
|
|
384
|
+
default: 'all',
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
|
|
388
|
+
memory_usage: {
|
|
389
|
+
detail: {
|
|
390
|
+
type: 'string',
|
|
391
|
+
enum: ['summary', 'detailed', 'by-agent'],
|
|
392
|
+
default: 'summary',
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
// Neural Network Tools
|
|
397
|
+
neural_status: {
|
|
398
|
+
agentId: {
|
|
399
|
+
type: 'string',
|
|
400
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
401
|
+
required: false,
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
|
|
405
|
+
neural_train: {
|
|
406
|
+
agentId: {
|
|
407
|
+
type: 'string',
|
|
408
|
+
required: true,
|
|
409
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
410
|
+
},
|
|
411
|
+
iterations: {
|
|
412
|
+
type: 'number',
|
|
413
|
+
integer: true,
|
|
414
|
+
min: 1,
|
|
415
|
+
max: 1000,
|
|
416
|
+
default: 10,
|
|
417
|
+
},
|
|
418
|
+
learningRate: {
|
|
419
|
+
type: 'number',
|
|
420
|
+
min: 0.00001,
|
|
421
|
+
max: 1.0,
|
|
422
|
+
default: 0.001,
|
|
423
|
+
},
|
|
424
|
+
modelType: {
|
|
425
|
+
type: 'string',
|
|
426
|
+
enum: ['feedforward', 'lstm', 'transformer', 'attention', 'cnn', 'rnn', 'gru'],
|
|
427
|
+
default: 'feedforward',
|
|
428
|
+
},
|
|
429
|
+
trainingData: {
|
|
430
|
+
type: 'object',
|
|
431
|
+
required: false,
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
neural_patterns: {
|
|
436
|
+
pattern: {
|
|
437
|
+
type: 'string',
|
|
438
|
+
enum: ['all', 'convergent', 'divergent', 'lateral', 'systems', 'critical', 'abstract', 'adaptive'],
|
|
439
|
+
default: 'all',
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
|
|
443
|
+
// DAA (Decentralized Autonomous Agents) Tools
|
|
444
|
+
daa_init: {
|
|
445
|
+
enableCoordination: {
|
|
446
|
+
type: 'boolean',
|
|
447
|
+
default: true,
|
|
448
|
+
},
|
|
449
|
+
enableLearning: {
|
|
450
|
+
type: 'boolean',
|
|
451
|
+
default: true,
|
|
452
|
+
},
|
|
453
|
+
persistenceMode: {
|
|
454
|
+
type: 'string',
|
|
455
|
+
enum: ['auto', 'memory', 'disk'],
|
|
456
|
+
default: 'auto',
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
|
|
460
|
+
daa_agent_create: {
|
|
461
|
+
id: {
|
|
462
|
+
type: 'string',
|
|
463
|
+
required: true,
|
|
464
|
+
minLength: 1,
|
|
465
|
+
maxLength: 100,
|
|
466
|
+
},
|
|
467
|
+
capabilities: {
|
|
468
|
+
type: 'array',
|
|
469
|
+
items: {
|
|
470
|
+
type: 'string',
|
|
471
|
+
minLength: 1,
|
|
472
|
+
},
|
|
473
|
+
required: false,
|
|
474
|
+
},
|
|
475
|
+
cognitivePattern: {
|
|
476
|
+
type: 'string',
|
|
477
|
+
enum: ['convergent', 'divergent', 'lateral', 'systems', 'critical', 'adaptive'],
|
|
478
|
+
required: false,
|
|
479
|
+
},
|
|
480
|
+
enableMemory: {
|
|
481
|
+
type: 'boolean',
|
|
482
|
+
default: true,
|
|
483
|
+
},
|
|
484
|
+
learningRate: {
|
|
485
|
+
type: 'number',
|
|
486
|
+
min: 0.001,
|
|
487
|
+
max: 1.0,
|
|
488
|
+
default: 0.1,
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
|
|
492
|
+
daa_agent_adapt: {
|
|
493
|
+
agentId: {
|
|
494
|
+
type: 'string',
|
|
495
|
+
required: true,
|
|
496
|
+
minLength: 1,
|
|
497
|
+
},
|
|
498
|
+
feedback: {
|
|
499
|
+
type: 'string',
|
|
500
|
+
minLength: 1,
|
|
501
|
+
maxLength: 1000,
|
|
502
|
+
required: false,
|
|
503
|
+
},
|
|
504
|
+
performanceScore: {
|
|
505
|
+
type: 'number',
|
|
506
|
+
min: 0,
|
|
507
|
+
max: 1,
|
|
508
|
+
required: false,
|
|
509
|
+
},
|
|
510
|
+
suggestions: {
|
|
511
|
+
type: 'array',
|
|
512
|
+
items: {
|
|
513
|
+
type: 'string',
|
|
514
|
+
minLength: 1,
|
|
515
|
+
},
|
|
516
|
+
required: false,
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
|
|
520
|
+
daa_workflow_create: {
|
|
521
|
+
id: {
|
|
522
|
+
type: 'string',
|
|
523
|
+
required: true,
|
|
524
|
+
minLength: 1,
|
|
525
|
+
maxLength: 100,
|
|
526
|
+
},
|
|
527
|
+
name: {
|
|
528
|
+
type: 'string',
|
|
529
|
+
required: true,
|
|
530
|
+
minLength: 1,
|
|
531
|
+
maxLength: 200,
|
|
532
|
+
},
|
|
533
|
+
steps: {
|
|
534
|
+
type: 'array',
|
|
535
|
+
items: {
|
|
536
|
+
type: 'object',
|
|
537
|
+
},
|
|
538
|
+
required: false,
|
|
539
|
+
},
|
|
540
|
+
dependencies: {
|
|
541
|
+
type: 'object',
|
|
542
|
+
required: false,
|
|
543
|
+
},
|
|
544
|
+
strategy: {
|
|
545
|
+
type: 'string',
|
|
546
|
+
enum: ['parallel', 'sequential', 'adaptive'],
|
|
547
|
+
default: 'adaptive',
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
|
|
551
|
+
daa_workflow_execute: {
|
|
552
|
+
workflowId: {
|
|
553
|
+
type: 'string',
|
|
554
|
+
required: true,
|
|
555
|
+
minLength: 1,
|
|
556
|
+
},
|
|
557
|
+
agentIds: {
|
|
558
|
+
type: 'array',
|
|
559
|
+
items: {
|
|
560
|
+
type: 'string',
|
|
561
|
+
minLength: 1,
|
|
562
|
+
},
|
|
563
|
+
required: false,
|
|
564
|
+
},
|
|
565
|
+
parallelExecution: {
|
|
566
|
+
type: 'boolean',
|
|
567
|
+
default: true,
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
|
|
571
|
+
daa_knowledge_share: {
|
|
572
|
+
sourceAgentId: {
|
|
573
|
+
type: 'string',
|
|
574
|
+
required: true,
|
|
575
|
+
minLength: 1,
|
|
576
|
+
},
|
|
577
|
+
targetAgentIds: {
|
|
578
|
+
type: 'array',
|
|
579
|
+
items: {
|
|
580
|
+
type: 'string',
|
|
581
|
+
minLength: 1,
|
|
582
|
+
},
|
|
583
|
+
required: true,
|
|
584
|
+
minLength: 1,
|
|
585
|
+
},
|
|
586
|
+
knowledgeDomain: {
|
|
587
|
+
type: 'string',
|
|
588
|
+
minLength: 1,
|
|
589
|
+
required: false,
|
|
590
|
+
},
|
|
591
|
+
knowledgeContent: {
|
|
592
|
+
type: 'object',
|
|
593
|
+
required: false,
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
|
|
597
|
+
daa_learning_status: {
|
|
598
|
+
agentId: {
|
|
599
|
+
type: 'string',
|
|
600
|
+
required: false,
|
|
601
|
+
},
|
|
602
|
+
detailed: {
|
|
603
|
+
type: 'boolean',
|
|
604
|
+
default: false,
|
|
605
|
+
},
|
|
606
|
+
},
|
|
607
|
+
|
|
608
|
+
daa_cognitive_pattern: {
|
|
609
|
+
agentId: {
|
|
610
|
+
type: 'string',
|
|
611
|
+
required: false,
|
|
612
|
+
},
|
|
613
|
+
pattern: {
|
|
614
|
+
type: 'string',
|
|
615
|
+
enum: ['convergent', 'divergent', 'lateral', 'systems', 'critical', 'adaptive'],
|
|
616
|
+
required: false,
|
|
617
|
+
},
|
|
618
|
+
analyze: {
|
|
619
|
+
type: 'boolean',
|
|
620
|
+
default: false,
|
|
621
|
+
},
|
|
622
|
+
},
|
|
623
|
+
|
|
624
|
+
daa_meta_learning: {
|
|
625
|
+
sourceDomain: {
|
|
626
|
+
type: 'string',
|
|
627
|
+
minLength: 1,
|
|
628
|
+
required: false,
|
|
629
|
+
},
|
|
630
|
+
targetDomain: {
|
|
631
|
+
type: 'string',
|
|
632
|
+
minLength: 1,
|
|
633
|
+
required: false,
|
|
634
|
+
},
|
|
635
|
+
transferMode: {
|
|
636
|
+
type: 'string',
|
|
637
|
+
enum: ['adaptive', 'direct', 'gradual'],
|
|
638
|
+
default: 'adaptive',
|
|
639
|
+
},
|
|
640
|
+
agentIds: {
|
|
641
|
+
type: 'array',
|
|
642
|
+
items: {
|
|
643
|
+
type: 'string',
|
|
644
|
+
minLength: 1,
|
|
645
|
+
},
|
|
646
|
+
required: false,
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
|
|
650
|
+
daa_performance_metrics: {
|
|
651
|
+
category: {
|
|
652
|
+
type: 'string',
|
|
653
|
+
enum: ['all', 'system', 'performance', 'efficiency', 'neural'],
|
|
654
|
+
default: 'all',
|
|
655
|
+
},
|
|
656
|
+
timeRange: {
|
|
657
|
+
type: 'string',
|
|
658
|
+
pattern: '^\\d+[hmd]$', // e.g., "1h", "24h", "7d"
|
|
659
|
+
required: false,
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
|
|
663
|
+
// Monitoring Tools
|
|
664
|
+
swarm_monitor: {
|
|
665
|
+
swarmId: {
|
|
666
|
+
type: 'string',
|
|
667
|
+
pattern: '^[a-fA-F0-9-]+$',
|
|
668
|
+
required: false,
|
|
669
|
+
},
|
|
670
|
+
duration: {
|
|
671
|
+
type: 'number',
|
|
672
|
+
integer: true,
|
|
673
|
+
min: 1,
|
|
674
|
+
max: 3600, // 1 hour max
|
|
675
|
+
default: 10,
|
|
676
|
+
},
|
|
677
|
+
interval: {
|
|
678
|
+
type: 'number',
|
|
679
|
+
integer: true,
|
|
680
|
+
min: 1,
|
|
681
|
+
max: 60,
|
|
682
|
+
default: 1,
|
|
683
|
+
},
|
|
684
|
+
includeAgents: {
|
|
685
|
+
type: 'boolean',
|
|
686
|
+
default: true,
|
|
687
|
+
},
|
|
688
|
+
includeTasks: {
|
|
689
|
+
type: 'boolean',
|
|
690
|
+
default: true,
|
|
691
|
+
},
|
|
692
|
+
includeMetrics: {
|
|
693
|
+
type: 'boolean',
|
|
694
|
+
default: true,
|
|
695
|
+
},
|
|
696
|
+
realTime: {
|
|
697
|
+
type: 'boolean',
|
|
698
|
+
default: false,
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Validation utilities
|
|
705
|
+
*/
|
|
706
|
+
class ValidationUtils {
|
|
707
|
+
/**
|
|
708
|
+
* Validate parameters against a schema
|
|
709
|
+
*/
|
|
710
|
+
static validateParams(params, toolName) {
|
|
711
|
+
const schema = MCPSchemas[toolName];
|
|
712
|
+
if (!schema) {
|
|
713
|
+
throw new ValidationError(
|
|
714
|
+
`No validation schema found for tool: ${toolName}`,
|
|
715
|
+
'toolName',
|
|
716
|
+
toolName,
|
|
717
|
+
'string',
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// Handle empty or null params
|
|
722
|
+
if (!params || typeof params !== 'object') {
|
|
723
|
+
params = {};
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const validatedParams = {};
|
|
727
|
+
|
|
728
|
+
// Validate each parameter
|
|
729
|
+
for (const [fieldName, fieldSchema] of Object.entries(schema)) {
|
|
730
|
+
try {
|
|
731
|
+
const value = params[fieldName];
|
|
732
|
+
validatedParams[fieldName] = BaseValidator.validate(value, fieldSchema, fieldName);
|
|
733
|
+
} catch (error) {
|
|
734
|
+
// Add tool context to error
|
|
735
|
+
if (error instanceof ValidationError) {
|
|
736
|
+
error.details.tool = toolName;
|
|
737
|
+
error.details.schema = fieldSchema;
|
|
738
|
+
}
|
|
739
|
+
throw error;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// Check for unexpected parameters
|
|
744
|
+
const allowedFields = Object.keys(schema);
|
|
745
|
+
const providedFields = Object.keys(params);
|
|
746
|
+
const unexpectedFields = providedFields.filter(field => !allowedFields.includes(field));
|
|
747
|
+
|
|
748
|
+
if (unexpectedFields.length > 0) {
|
|
749
|
+
console.warn(`Unexpected parameters for ${toolName}: ${unexpectedFields.join(', ')}`);
|
|
750
|
+
// Note: We don't throw here to maintain backward compatibility
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
return validatedParams;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Get schema documentation for a tool
|
|
758
|
+
*/
|
|
759
|
+
static getSchemaDoc(toolName) {
|
|
760
|
+
const schema = MCPSchemas[toolName];
|
|
761
|
+
if (!schema) {
|
|
762
|
+
return null;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
const doc = {
|
|
766
|
+
tool: toolName,
|
|
767
|
+
parameters: {},
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
for (const [fieldName, fieldSchema] of Object.entries(schema)) {
|
|
771
|
+
doc.parameters[fieldName] = {
|
|
772
|
+
type: fieldSchema.type,
|
|
773
|
+
required: fieldSchema.required || false,
|
|
774
|
+
default: fieldSchema.default,
|
|
775
|
+
description: this.generateFieldDescription(fieldName, fieldSchema),
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
if (fieldSchema.enum) {
|
|
779
|
+
doc.parameters[fieldName].allowedValues = fieldSchema.enum;
|
|
780
|
+
}
|
|
781
|
+
if (fieldSchema.min !== undefined || fieldSchema.max !== undefined) {
|
|
782
|
+
doc.parameters[fieldName].range = {
|
|
783
|
+
min: fieldSchema.min,
|
|
784
|
+
max: fieldSchema.max,
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
if (fieldSchema.minLength !== undefined || fieldSchema.maxLength !== undefined) {
|
|
788
|
+
doc.parameters[fieldName].length = {
|
|
789
|
+
min: fieldSchema.minLength,
|
|
790
|
+
max: fieldSchema.maxLength,
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return doc;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Generate human-readable description for a field
|
|
800
|
+
*/
|
|
801
|
+
static generateFieldDescription(fieldName, schema) {
|
|
802
|
+
let desc = `${fieldName} (${schema.type})`;
|
|
803
|
+
|
|
804
|
+
if (schema.required) {
|
|
805
|
+
desc += ' - Required';
|
|
806
|
+
} else {
|
|
807
|
+
desc += ' - Optional';
|
|
808
|
+
if (schema.default !== undefined) {
|
|
809
|
+
desc += `, default: ${schema.default}`;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (schema.enum) {
|
|
814
|
+
desc += `. Allowed values: ${schema.enum.join(', ')}`;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (schema.min !== undefined || schema.max !== undefined) {
|
|
818
|
+
desc += `. Range: ${schema.min || 'any'} to ${schema.max || 'any'}`;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
if (schema.minLength !== undefined || schema.maxLength !== undefined) {
|
|
822
|
+
desc += `. Length: ${schema.minLength || 0} to ${schema.maxLength || 'unlimited'}`;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return desc;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Get all available tool schemas
|
|
830
|
+
*/
|
|
831
|
+
static getAllSchemas() {
|
|
832
|
+
return Object.keys(MCPSchemas);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Validate a UUID string
|
|
837
|
+
*/
|
|
838
|
+
static isValidUUID(str) {
|
|
839
|
+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
840
|
+
return uuidRegex.test(str);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Sanitize input to prevent injection attacks
|
|
845
|
+
*/
|
|
846
|
+
static sanitizeInput(input) {
|
|
847
|
+
if (typeof input === 'string') {
|
|
848
|
+
// Remove potentially dangerous characters
|
|
849
|
+
return input.replace(/[<>"'&\x00-\x1f\x7f-\x9f]/g, '');
|
|
850
|
+
}
|
|
851
|
+
return input;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Export validation schemas and utilities
|
|
857
|
+
*/
|
|
858
|
+
export {
|
|
859
|
+
MCPSchemas,
|
|
860
|
+
BaseValidator,
|
|
861
|
+
ValidationUtils,
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
export default ValidationUtils;
|