snow-flow 2.6.0 → 2.6.2

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.
@@ -0,0 +1,655 @@
1
+ "use strict";
2
+ /**
3
+ * Intelligent Agent Detection System
4
+ * Dynamically determines which agents to spawn based on task analysis
5
+ *
6
+ * NOTE: This system now integrates with the Snow-Flow MCP task_categorize tool
7
+ * for dynamic AI-based categorization instead of static patterns.
8
+ */
9
+ var __assign = (this && this.__assign) || function () {
10
+ __assign = Object.assign || function(t) {
11
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
12
+ s = arguments[i];
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
14
+ t[p] = s[p];
15
+ }
16
+ return t;
17
+ };
18
+ return __assign.apply(this, arguments);
19
+ };
20
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
21
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
+ return new (P || (P = Promise))(function (resolve, reject) {
23
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
27
+ });
28
+ };
29
+ var __generator = (this && this.__generator) || function (thisArg, body) {
30
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
31
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
32
+ function verb(n) { return function (v) { return step([n, v]); }; }
33
+ function step(op) {
34
+ if (f) throw new TypeError("Generator is already executing.");
35
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
36
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
37
+ if (y = 0, t) op = [op[0] & 2, t.value];
38
+ switch (op[0]) {
39
+ case 0: case 1: t = op; break;
40
+ case 4: _.label++; return { value: op[1], done: false };
41
+ case 5: _.label++; y = op[1]; op = [0]; continue;
42
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
43
+ default:
44
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
45
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
46
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
47
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
48
+ if (t[2]) _.ops.pop();
49
+ _.trys.pop(); continue;
50
+ }
51
+ op = body.call(thisArg, _);
52
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
53
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
54
+ }
55
+ };
56
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
58
+ if (ar || !(i in from)) {
59
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
60
+ ar[i] = from[i];
61
+ }
62
+ }
63
+ return to.concat(ar || Array.prototype.slice.call(from));
64
+ };
65
+ Object.defineProperty(exports, "__esModule", { value: true });
66
+ exports.AgentDetector = void 0;
67
+ var AgentDetector = /** @class */ (function () {
68
+ function AgentDetector() {
69
+ }
70
+ /**
71
+ * Set the MCP client for dynamic categorization
72
+ */
73
+ AgentDetector.setMCPClient = function (client) {
74
+ this.mcpClient = client;
75
+ };
76
+ /**
77
+ * Analyze task using MCP dynamic categorization or fallback to static patterns
78
+ */
79
+ AgentDetector.analyzeTaskDynamic = function (objective, userMaxAgents) {
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ var response, result, error_1;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0:
85
+ if (!this.mcpClient) return [3 /*break*/, 4];
86
+ _a.label = 1;
87
+ case 1:
88
+ _a.trys.push([1, 3, , 4]);
89
+ return [4 /*yield*/, this.mcpClient.callTool({
90
+ name: 'task_categorize',
91
+ arguments: {
92
+ objective: objective,
93
+ context: {
94
+ language: 'auto',
95
+ maxAgents: userMaxAgents || 8,
96
+ environment: 'development',
97
+ },
98
+ },
99
+ })];
100
+ case 2:
101
+ response = _a.sent();
102
+ if (response && response.content && response.content[0]) {
103
+ result = JSON.parse(response.content[0].text);
104
+ // Map MCP response to TaskAnalysis interface
105
+ return [2 /*return*/, {
106
+ primaryAgent: result.categorization.primary_agent,
107
+ supportingAgents: result.categorization.supporting_agents,
108
+ complexity: result.categorization.complexity,
109
+ estimatedAgentCount: result.categorization.estimated_agent_count,
110
+ requiresUpdateSet: result.categorization.requires_update_set,
111
+ requiresApplication: result.categorization.requires_application,
112
+ taskType: result.categorization.task_type,
113
+ serviceNowArtifacts: result.categorization.service_now_artifacts,
114
+ confidence: result.categorization.confidence_score,
115
+ neuralConfidence: result.metadata.neural_confidence,
116
+ intentAnalysis: result.intent_analysis,
117
+ approach: {
118
+ recommendedStrategy: result.approach.recommended_strategy,
119
+ executionMode: result.approach.execution_mode,
120
+ parallelOpportunities: result.approach.parallel_opportunities,
121
+ riskFactors: result.approach.risk_factors,
122
+ optimizationHints: result.approach.optimization_hints,
123
+ },
124
+ }];
125
+ }
126
+ return [3 /*break*/, 4];
127
+ case 3:
128
+ error_1 = _a.sent();
129
+ console.warn('MCP task_categorize failed, falling back to static patterns:', error_1);
130
+ return [3 /*break*/, 4];
131
+ case 4:
132
+ // Fallback to static analysis
133
+ return [2 /*return*/, this.analyzeTask(objective, userMaxAgents)];
134
+ }
135
+ });
136
+ });
137
+ };
138
+ AgentDetector.analyzeTask = function (objective, userMaxAgents) {
139
+ var lowerObjective = objective.toLowerCase();
140
+ var words = lowerObjective.split(/\s+/);
141
+ // Check for data generation FIRST - before any other analysis
142
+ var dataGenerationPatterns = [
143
+ // Pattern for "create/make X incidents/changes" with flexible word order
144
+ /\b(create|generate|make|maak|genereer|aanmaken)\b.*\b\d+\b.*(incident|change|request|problem|task|record|item)/i,
145
+ // Pattern for "data set" with numbers anywhere
146
+ /\bdata\s*set\b.*\b\d{3,}/i, // data set with 3+ digit numbers
147
+ // Pattern for various test/mock/sample data keywords
148
+ /\b(test\s+data|mock\s+data|sample\s+data|training\s+data)\b/i,
149
+ // Pattern for populate/seed/fill operations
150
+ /\b(populate|seed|fill)\s+(with\s+)?(test|sample|random|mock)\s+(data|incident|change|record)/i,
151
+ // Pattern for seed database with numbers
152
+ /\b(seed|populate|fill)\s+(database|db|table)\s+with\s+\d+/i,
153
+ // Pattern for ML training data
154
+ /\b(ML|machine\s+learning|training)\b.*\bdata/i,
155
+ // Pattern for random/test with large numbers
156
+ /\b(random|test|mock|sample)\b.*\b\d{3,}\b.*(incident|change|request|problem)/i,
157
+ // Pattern for Dutch data set creation
158
+ /\bdata\s*set\s+(aan\s+)?van\s+\d+/i
159
+ ];
160
+ var isDataGeneration = dataGenerationPatterns.some(function (pattern) { return pattern.test(objective); });
161
+ if (isDataGeneration) {
162
+ return {
163
+ primaryAgent: 'script-writer',
164
+ supportingAgents: ['tester'], // Minimal support
165
+ complexity: 'simple',
166
+ estimatedAgentCount: 2,
167
+ requiresUpdateSet: false, // Usually no update set needed for data generation
168
+ requiresApplication: false,
169
+ taskType: 'data_generation',
170
+ serviceNowArtifacts: ['script']
171
+ };
172
+ }
173
+ // Check for simple operations
174
+ var simpleOperationPatterns = [
175
+ /\b(update|change|modify|delete|remove)\s+(the\s+)?(field|record|value|property)\b/i,
176
+ /\b(wijzig|verander|verwijder|pas\s+aan)\s+(het\s+)?(veld|record|waarde)\b/i
177
+ ];
178
+ var isSimpleOperation = simpleOperationPatterns.some(function (pattern) { return pattern.test(objective); });
179
+ if (isSimpleOperation) {
180
+ return {
181
+ primaryAgent: 'script-writer',
182
+ supportingAgents: ['tester'],
183
+ complexity: 'simple',
184
+ estimatedAgentCount: 2,
185
+ requiresUpdateSet: false,
186
+ requiresApplication: false,
187
+ taskType: 'simple_operation',
188
+ serviceNowArtifacts: ['script']
189
+ };
190
+ }
191
+ // Determine task type for other cases
192
+ var taskType = this.determineTaskType(lowerObjective, this.detectServiceNowArtifacts(lowerObjective));
193
+ // Detect agent capabilities
194
+ var agentCapabilities = this.detectAgentCapabilities(lowerObjective);
195
+ // Determine primary agent
196
+ var primaryAgent = this.determinePrimaryAgent(agentCapabilities);
197
+ // Determine supporting agents
198
+ var supportingAgents = this.determineSupportingAgents(agentCapabilities, primaryAgent, userMaxAgents);
199
+ // Assess complexity
200
+ var complexity = this.assessComplexity(objective, agentCapabilities);
201
+ // Determine ServiceNow artifacts
202
+ var serviceNowArtifacts = this.detectServiceNowArtifacts(lowerObjective);
203
+ // Determine if Update Set is required
204
+ var requiresUpdateSet = this.requiresUpdateSet(lowerObjective, serviceNowArtifacts);
205
+ // Determine if new Application is required
206
+ var requiresApplication = this.requiresApplication(lowerObjective, serviceNowArtifacts);
207
+ // 🚀 NEW: Accurate agent count for parallel system
208
+ var isDevelopmentTask = ['widget-creator', 'flow-builder', 'script-writer', 'app-architect'].includes(primaryAgent) ||
209
+ supportingAgents.some(function (agent) { return ['css-specialist', 'backend-specialist', 'frontend-specialist'].includes(agent); });
210
+ var estimatedAgentCount = isDevelopmentTask
211
+ ? Math.max(supportingAgents.length + 1, 6) // 6+ agents for development (1 primary + 5+ specialists)
212
+ : Math.min(Math.max(supportingAgents.length + 1, 2), 8); // Original logic for non-development
213
+ return {
214
+ primaryAgent: primaryAgent,
215
+ supportingAgents: supportingAgents,
216
+ complexity: complexity,
217
+ estimatedAgentCount: estimatedAgentCount,
218
+ requiresUpdateSet: requiresUpdateSet,
219
+ requiresApplication: requiresApplication,
220
+ taskType: taskType,
221
+ serviceNowArtifacts: serviceNowArtifacts
222
+ };
223
+ };
224
+ AgentDetector.detectAgentCapabilities = function (objective) {
225
+ var capabilities = [];
226
+ for (var _i = 0, _a = Object.entries(this.AGENT_PATTERNS); _i < _a.length; _i++) {
227
+ var _b = _a[_i], agentType = _b[0], config = _b[1];
228
+ var matchCount = 0;
229
+ var totalKeywords = config.keywords.length;
230
+ for (var _c = 0, _d = config.keywords; _c < _d.length; _c++) {
231
+ var keyword = _d[_c];
232
+ if (objective.includes(keyword)) {
233
+ matchCount++;
234
+ }
235
+ }
236
+ if (matchCount > 0) {
237
+ var confidence = (matchCount / totalKeywords) * config.confidence;
238
+ capabilities.push({
239
+ type: agentType,
240
+ confidence: confidence,
241
+ requiredFor: config.requiredFor,
242
+ description: config.description
243
+ });
244
+ }
245
+ }
246
+ return capabilities.sort(function (a, b) { return b.confidence - a.confidence; });
247
+ };
248
+ AgentDetector.determinePrimaryAgent = function (capabilities) {
249
+ if (capabilities.length === 0)
250
+ return 'queen-coordinator';
251
+ // Map detected types to new parallel agent types
252
+ var convertToParallelType = function (detectedType) {
253
+ var mapping = {
254
+ 'widget_builder': 'widget-creator',
255
+ 'flow_designer': 'flow-builder',
256
+ 'integration_specialist': 'integration-specialist',
257
+ 'database_expert': 'app-architect',
258
+ 'coder': 'script-writer',
259
+ 'architect': 'app-architect',
260
+ 'tester': 'tester',
261
+ 'data_generator': 'script-writer' // Data generation uses script-writer
262
+ };
263
+ return mapping[detectedType] || detectedType;
264
+ };
265
+ // Convert all capability types to parallel agent types
266
+ var parallelCapabilities = capabilities.map(function (c) { return (__assign(__assign({}, c), { type: convertToParallelType(c.type) })); });
267
+ // Special logic for ServiceNow-specific tasks - use new parallel agent types
268
+ var serviceNowAgents = parallelCapabilities.filter(function (c) {
269
+ return ['flow-builder', 'widget-creator', 'integration-specialist', 'app-architect'].includes(c.type);
270
+ });
271
+ if (serviceNowAgents.length > 0) {
272
+ return serviceNowAgents[0].type;
273
+ }
274
+ return parallelCapabilities[0].type;
275
+ };
276
+ AgentDetector.determineSupportingAgents = function (capabilities, primaryAgent, userMaxAgents) {
277
+ // 🚀 NEW: Parallel Agent System - Show 6+ specialized agents for development tasks
278
+ var isWidgetDevelopment = primaryAgent === 'widget-creator' || capabilities.some(function (c) { return c.type === 'widget-creator'; });
279
+ var isFlowDevelopment = primaryAgent === 'flow-builder' || capabilities.some(function (c) { return c.type === 'flow-builder'; });
280
+ var isDevelopmentTask = isWidgetDevelopment || isFlowDevelopment ||
281
+ capabilities.some(function (c) { return ['widget-creator', 'flow-builder', 'script-writer', 'app-architect'].includes(c.type); });
282
+ if (isDevelopmentTask) {
283
+ // 🚀 Widget development gets full specialized team (6+ agents)
284
+ if (isWidgetDevelopment) {
285
+ return ['css-specialist', 'backend-specialist', 'frontend-specialist', 'integration-specialist', 'performance-specialist', 'tester'];
286
+ }
287
+ // 🚀 Flow development gets flow-specific team
288
+ if (isFlowDevelopment) {
289
+ return ['trigger-specialist', 'action-specialist', 'approval-specialist', 'integration-specialist', 'error-handler', 'tester'];
290
+ }
291
+ // 🚀 General development gets adaptive specialized team
292
+ return ['script-writer', 'css-specialist', 'integration-specialist', 'security-specialist', 'performance-specialist', 'tester'];
293
+ }
294
+ // 🚀 For non-development tasks, use smart agent selection based on capabilities
295
+ var requestedSupportingCount = userMaxAgents ? Math.max(userMaxAgents - 1, 1) : 5;
296
+ // Start with high-confidence agents (confidence > 0.3)
297
+ var supportingAgents = capabilities
298
+ .filter(function (c) { return c.type !== primaryAgent && c.confidence > 0.3; })
299
+ .slice(0, requestedSupportingCount)
300
+ .map(function (c) { return c.type; });
301
+ // If we need more agents, add specialized agents based on task context
302
+ if (supportingAgents.length < requestedSupportingCount) {
303
+ var remainingSlots = requestedSupportingCount - supportingAgents.length;
304
+ var specializedAgents = ['integration-specialist', 'security-specialist', 'tester', 'performance-specialist']
305
+ .filter(function (agent) { return !supportingAgents.includes(agent); })
306
+ .slice(0, remainingSlots);
307
+ supportingAgents = __spreadArray(__spreadArray([], supportingAgents, true), specializedAgents, true);
308
+ }
309
+ // Ensure we don't exceed the requested count
310
+ if (userMaxAgents && supportingAgents.length > requestedSupportingCount) {
311
+ supportingAgents = supportingAgents.slice(0, requestedSupportingCount);
312
+ }
313
+ return supportingAgents;
314
+ };
315
+ AgentDetector.assessComplexity = function (objective, capabilities) {
316
+ var wordCount = objective.split(/\s+/).length;
317
+ var agentCount = capabilities.length;
318
+ // Complex indicators
319
+ var complexKeywords = ['integrate', 'multiple', 'complex', 'advanced', 'system', 'architecture', 'enterprise'];
320
+ var hasComplexKeywords = complexKeywords.some(function (keyword) { return objective.toLowerCase().includes(keyword); });
321
+ if (wordCount > 20 || agentCount > 4 || hasComplexKeywords) {
322
+ return 'complex';
323
+ }
324
+ else if (wordCount > 10 || agentCount > 2) {
325
+ return 'medium';
326
+ }
327
+ else {
328
+ return 'simple';
329
+ }
330
+ };
331
+ AgentDetector.detectServiceNowArtifacts = function (objective) {
332
+ var artifacts = [];
333
+ var lowerObjective = objective.toLowerCase();
334
+ // Enhanced artifact detection with Dutch support and context
335
+ var artifactPatterns = {
336
+ 'widget': [
337
+ 'widget', 'widgets',
338
+ 'service portal', 'portal component', 'dashboard component',
339
+ 'ui component', 'interface', 'display', 'homepage'
340
+ ],
341
+ 'flow': [
342
+ 'flow', 'flows', 'workflow', 'workflows',
343
+ 'process', 'processes', 'automation', 'automate',
344
+ 'approval', 'approvals', 'routing', 'trigger'
345
+ ],
346
+ 'application': [
347
+ 'application', 'applications', 'app', 'apps',
348
+ 'applicatie', 'applicaties', 'system', 'systeem',
349
+ 'complete', 'comprehensive', 'full solution'
350
+ ],
351
+ 'script': [
352
+ 'script', 'scripts', 'code', 'function', 'functions',
353
+ 'business rule', 'business rules', 'client script', 'server script',
354
+ 'script include', 'javascript', 'logic', 'programmeer'
355
+ ],
356
+ 'business_rule': [
357
+ 'business rule', 'business rules', 'business_rule',
358
+ 'rule', 'rules', 'validation', 'trigger logic',
359
+ 'bedrijfsregel', 'regel', 'regels'
360
+ ],
361
+ 'integration': [
362
+ 'integration', 'integrations', 'api', 'apis',
363
+ 'rest', 'soap', 'webhook', 'external', 'third party',
364
+ 'integratie', 'koppeling', 'verbinding'
365
+ ],
366
+ 'table': [
367
+ 'table', 'tables', 'database', 'data',
368
+ 'record', 'records', 'field', 'fields',
369
+ 'tabel', 'tabellen', 'gegevens'
370
+ ],
371
+ 'report': [
372
+ 'report', 'reports', 'reporting', 'analytics',
373
+ 'dashboard', 'chart', 'graph', 'metrics',
374
+ 'rapport', 'rapporten', 'rapportage'
375
+ ]
376
+ };
377
+ // Check each artifact type with enhanced patterns
378
+ for (var _i = 0, _a = Object.entries(artifactPatterns); _i < _a.length; _i++) {
379
+ var _b = _a[_i], artifactType = _b[0], patterns = _b[1];
380
+ for (var _c = 0, patterns_1 = patterns; _c < patterns_1.length; _c++) {
381
+ var pattern = patterns_1[_c];
382
+ if (lowerObjective.includes(pattern)) {
383
+ if (!artifacts.includes(artifactType)) {
384
+ artifacts.push(artifactType);
385
+ }
386
+ break; // Found one pattern for this type, move to next type
387
+ }
388
+ }
389
+ }
390
+ // Context-based detection for common development terms
391
+ var developmentContext = {
392
+ 'widget': ['voor', 'voor een', 'show', 'display', 'interface', 'homepage', 'portal'],
393
+ 'flow': ['goedkeuring', 'approval', 'proces', 'automatiseer', 'trigger', 'wanneer'],
394
+ 'script': ['implementeer', 'implement', 'schrijf', 'write', 'code', 'function'],
395
+ 'table': ['opslaan', 'save', 'store', 'data', 'informatie', 'gegevens'],
396
+ 'report': ['analyse', 'analyze', 'overview', 'overzicht', 'statistieken', 'metrics']
397
+ };
398
+ // Add context-based detection
399
+ for (var _d = 0, _e = Object.entries(developmentContext); _d < _e.length; _d++) {
400
+ var _f = _e[_d], artifactType = _f[0], contextWords = _f[1];
401
+ for (var _g = 0, contextWords_1 = contextWords; _g < contextWords_1.length; _g++) {
402
+ var contextWord = contextWords_1[_g];
403
+ if (lowerObjective.includes(contextWord) && !artifacts.includes(artifactType)) {
404
+ // Only add if we have creation/development intent
405
+ var creationWords = ['create', 'maak', 'bouw', 'build', 'develop', 'implementeer', 'schrijf', 'write'];
406
+ if (creationWords.some(function (word) { return lowerObjective.includes(word); })) {
407
+ artifacts.push(artifactType);
408
+ break;
409
+ }
410
+ }
411
+ }
412
+ }
413
+ // Remove duplicates and return
414
+ return Array.from(new Set(artifacts));
415
+ };
416
+ AgentDetector.requiresUpdateSet = function (objective, artifacts) {
417
+ var lowerObjective = objective.toLowerCase();
418
+ // Always require Update Set for development tasks
419
+ var developmentKeywords = [
420
+ 'create', 'build', 'implement', 'develop', 'make', 'generate', 'add',
421
+ 'bouw', 'maak', 'schrijf', 'write', 'update', 'modify', 'change',
422
+ 'implementeer', 'ontwikkel', 'codeer', 'programmeer', 'stel', 'wijzig',
423
+ 'business rule', 'script', 'flow', 'widget', 'workflow', 'client script',
424
+ 'ui action', 'scheduled job', 'transform', 'integration',
425
+ 'bedrijfsregel', 'proces', 'goedkeuring', 'automatisering'
426
+ ];
427
+ var hasDevelopmentKeywords = developmentKeywords.some(function (keyword) { return lowerObjective.includes(keyword); });
428
+ // Or if ServiceNow artifacts are involved
429
+ var hasServiceNowArtifacts = artifacts.length > 0;
430
+ // Or if task type indicates development
431
+ var developmentTaskTypes = [
432
+ 'widget_development', 'flow_development', 'script_development',
433
+ 'application_development', 'integration_development', 'database_development',
434
+ 'reporting_development', 'general_development'
435
+ ];
436
+ var taskType = this.determineTaskType(objective, artifacts);
437
+ var isDevelopmentTask = developmentTaskTypes.includes(taskType);
438
+ return hasDevelopmentKeywords || hasServiceNowArtifacts || isDevelopmentTask;
439
+ };
440
+ AgentDetector.requiresApplication = function (objective, artifacts) {
441
+ // Require new application for comprehensive systems
442
+ var applicationKeywords = [
443
+ 'application', 'app', 'system', 'complete', 'full', 'comprehensive',
444
+ 'applicatie', 'applicaties', 'systeem', 'volledig', 'compleet',
445
+ 'totaal', 'geheel', 'pakket', 'oplossing', 'solution'
446
+ ];
447
+ var hasApplicationKeywords = applicationKeywords.some(function (keyword) { return objective.toLowerCase().includes(keyword); });
448
+ // Or if multiple complex artifacts are involved
449
+ var hasMultipleArtifacts = artifacts.length >= 3;
450
+ return hasApplicationKeywords || hasMultipleArtifacts;
451
+ };
452
+ AgentDetector.determineTaskType = function (objective, artifacts) {
453
+ var lowerObjective = objective.toLowerCase();
454
+ // FIRST: Check for data generation requests
455
+ var dataGenerationPatterns = [
456
+ /\b(create|generate|make|maak)\s+\d+\s+(random\s+)?(incident|change|request|problem|task|record|item)/i,
457
+ /\b(genereer|aanmaken)\s+\d+\s+(willekeurige\s+)?(incident|change|request|problem|task|record|item)/i,
458
+ /\bdata\s*set\s*(van|of|with)\s*\d+/i,
459
+ /\b(test\s+data|mock\s+data|sample\s+data|training\s+data)\b/i,
460
+ /\b(populate|seed|fill)\s+(with\s+)?(test|sample|random)\s+data/i
461
+ ];
462
+ var isDataGeneration = dataGenerationPatterns.some(function (pattern) { return pattern.test(objective); });
463
+ if (isDataGeneration)
464
+ return 'data_generation';
465
+ // Check for simple operations (update, delete, modify single things)
466
+ var simpleOperationPatterns = [
467
+ /\b(update|change|modify|delete|remove)\s+(the\s+)?(field|record|value|property)\b/i,
468
+ /\b(wijzig|verander|verwijder|pas\s+aan)\s+(het\s+)?(veld|record|waarde)\b/i
469
+ ];
470
+ var isSimpleOperation = simpleOperationPatterns.some(function (pattern) { return pattern.test(objective); });
471
+ if (isSimpleOperation)
472
+ return 'simple_operation';
473
+ // Determine based on detected artifacts and keywords
474
+ // Check flow FIRST as it's often confused with widget when both are present
475
+ if (artifacts.includes('flow') || artifacts.includes('workflow'))
476
+ return 'flow_development';
477
+ if (artifacts.includes('widget'))
478
+ return 'widget_development';
479
+ if (artifacts.includes('application'))
480
+ return 'application_development';
481
+ if (artifacts.includes('script') || artifacts.includes('business_rule'))
482
+ return 'script_development';
483
+ if (artifacts.includes('integration') || artifacts.includes('api'))
484
+ return 'integration_development';
485
+ if (artifacts.includes('table') || artifacts.includes('database'))
486
+ return 'database_development';
487
+ if (artifacts.includes('report') || artifacts.includes('dashboard'))
488
+ return 'reporting_development';
489
+ // Fallback to general development
490
+ var developmentKeywords = [
491
+ 'create', 'build', 'implement', 'develop', 'make', 'generate',
492
+ 'bouw', 'maak', 'schrijf', 'implementeer', 'ontwikkel', 'codeer'
493
+ ];
494
+ var hasDevelopmentKeywords = developmentKeywords.some(function (keyword) { return lowerObjective.includes(keyword); });
495
+ if (hasDevelopmentKeywords)
496
+ return 'general_development';
497
+ // Research or _analysis tasks
498
+ var researchKeywords = [
499
+ 'research', 'analyze', 'investigate', 'study', 'explore',
500
+ 'onderzoek', 'analyseer', 'bestudeer', 'ontdek'
501
+ ];
502
+ var hasResearchKeywords = researchKeywords.some(function (keyword) { return lowerObjective.includes(keyword); });
503
+ if (hasResearchKeywords)
504
+ return 'research_task';
505
+ return 'orchestration_task';
506
+ };
507
+ AgentDetector.generateAgentPrompt = function (agentType, objective, _analysis) {
508
+ var agentConfig = this.AGENT_PATTERNS[agentType];
509
+ var basePrompt = "You are a specialized ".concat(agentType, " agent in a ServiceNow multi-agent development swarm.\n\n\uD83C\uDFAF **Your Role**: ").concat((agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.description) || 'Specialized agent', "\n\n\uD83D\uDD0D **Task Context**: ").concat(objective, "\n\n\uD83C\uDFD7\uFE0F **Project Setup**:\n").concat(_analysis.requiresUpdateSet ? '- ✅ Update Set will be automatically created' : '- ⚠️ No Update Set required', "\n").concat(_analysis.requiresApplication ? '- ✅ New Application will be automatically created' : '- ⚠️ Using existing application context', "\n\n\uD83E\uDD16 **ML Capabilities Available**:\n- \uD83E\uDDE0 Neural Networks: Incident classification, change risk prediction, anomaly detection\n- \uD83D\uDCCA Performance Analytics ML: KPI forecasting, trend analysis (when PA plugin active)\n- \uD83D\uDD2E Predictive Intelligence: Clustering, similarity matching (when PI plugin active)\n- \uD83C\uDFAF Hybrid ML: Combine ServiceNow native ML with custom TensorFlow models\n\n\uD83E\uDD16 **Team Coordination**:\n- Primary Agent: ").concat(_analysis.primaryAgent, "\n- Supporting Agents: ").concat(_analysis.supportingAgents.join(', '), "\n- Task Complexity: ").concat(_analysis.complexity, "\n- ServiceNow Artifacts: ").concat(_analysis.serviceNowArtifacts.join(', '), "\n\n\uD83D\uDCCB **Your Responsibilities**:");
510
+ // Add agent-specific responsibilities
511
+ switch (agentType) {
512
+ case 'architect':
513
+ return basePrompt + "\n- Design system architecture and data models\n- Define relationships between ServiceNow components\n- Create technical specifications\n- Ensure scalability and best practices\n- Coordinate with other agents on implementation approach";
514
+ case 'coder':
515
+ return basePrompt + "\n- Implement code based on architectural designs\n- Write ServiceNow scripts, business rules, and functions\n- Ensure code quality and maintainability\n- Follow ServiceNow development best practices\n- Collaborate with testers on code validation\n- Implement ML-powered features:\n * mcp__servicenow-machine-learning__ml_train_incident_classifier - Train classification models\n * mcp__servicenow-machine-learning__ml_classify_incident - Auto-classify incidents\n * mcp__servicenow-machine-learning__ml_predictive_intelligence - Add PI capabilities";
516
+ case 'flow_designer':
517
+ return basePrompt + "\n- Design and implement ServiceNow flows and workflows\n- Configure approval processes and routing logic\n- Set up triggers and conditions\n- Ensure proper integration with other system components\n- Test flow execution and error handling";
518
+ case 'widget_builder':
519
+ return basePrompt + "\n- Design and implement Service Portal widgets\n- Create HTML templates and CSS styling\n- Develop client-side and server-side scripts\n- Ensure responsive design and accessibility\n- Integrate with ServiceNow APIs and data sources";
520
+ case 'tester':
521
+ return basePrompt + "\n- Develop and execute test plans\n- Validate functionality and performance\n- Identify and report bugs and issues\n- Ensure quality standards are met\n- Coordinate with development agents on fixes";
522
+ case 'researcher':
523
+ return basePrompt + "\n- Research ServiceNow best practices and patterns\n- Analyze requirements and gather information\n- Provide insights and recommendations\n- Study existing implementations and solutions\n- Document findings and share knowledge\n- Use ML for data-driven insights:\n * mcp__servicenow-machine-learning__ml_forecast_incidents - Predict future trends\n * mcp__servicenow-machine-learning__ml_detect_anomalies - Find unusual patterns\n * mcp__servicenow-machine-learning__ml_performance_analytics - Analyze KPIs with ML";
524
+ case 'orchestrator':
525
+ return basePrompt + "\n- Coordinate activities between all agents\n- Manage task priorities and dependencies\n- Ensure project timeline and milestones\n- Facilitate communication and collaboration\n- Monitor progress and address blockers\n- Leverage ML for intelligent orchestration:\n * mcp__servicenow-machine-learning__ml_agent_intelligence - AI work assignment\n * mcp__servicenow-machine-learning__ml_process_optimization - Optimize workflows\n * mcp__servicenow-machine-learning__ml_hybrid_recommendation - Combined ML insights";
526
+ default:
527
+ return basePrompt + "\n- Provide specialized expertise in your domain\n- Collaborate effectively with other agents\n- Ensure quality and best practices\n- Contribute to overall project success";
528
+ }
529
+ };
530
+ // MCP integration for dynamic categorization
531
+ AgentDetector.mcpClient = null;
532
+ AgentDetector.AGENT_PATTERNS = {
533
+ // Development agents
534
+ architect: {
535
+ keywords: ['design', 'architecture', 'structure', 'database', 'schema', 'model', 'entity', 'relationship', 'system'],
536
+ confidence: 0.9,
537
+ description: 'System architecture and design',
538
+ requiredFor: ['applications', 'complex_systems', 'integrations']
539
+ },
540
+ coder: {
541
+ keywords: ['implement', 'code', 'script', 'function', 'api', 'endpoint', 'logic', 'algorithm', 'business_rule', 'schrijf', 'write', 'develop', 'programmeer', 'implementeer', 'maak', 'bouw', 'build', 'create', 'codeer'],
542
+ confidence: 0.8,
543
+ description: 'Code implementation and development',
544
+ requiredFor: ['scripts', 'functions', 'business_rules', 'apis']
545
+ },
546
+ researcher: {
547
+ keywords: ['research', 'analyze', 'investigate', 'study', 'explore', 'understand', 'learn', 'discover', 'onderzoek', 'analyseer', 'bestudeer', 'ontdek', 'begrijp'],
548
+ confidence: 0.7,
549
+ description: 'Research and _analysis',
550
+ requiredFor: ['requirements', 'best_practices', 'patterns']
551
+ },
552
+ tester: {
553
+ keywords: ['test', 'verify', 'validate', 'check', 'ensure', 'quality', 'bug', 'debug', 'controleer', 'valideer', 'kwaliteit', 'testen'],
554
+ confidence: 0.8,
555
+ description: 'Testing and quality assurance',
556
+ requiredFor: ['validation', 'quality_control', 'debugging']
557
+ },
558
+ reviewer: {
559
+ keywords: ['review', 'audit', 'examine', 'evaluate', 'assess', 'approve', 'feedback'],
560
+ confidence: 0.7,
561
+ description: 'Code and process review',
562
+ requiredFor: ['code_review', 'approval_process', 'quality_gates']
563
+ },
564
+ documenter: {
565
+ keywords: ['document', 'documentation', 'guide', 'manual', 'readme', 'help', 'instructions'],
566
+ confidence: 0.6,
567
+ description: 'Documentation and guides',
568
+ requiredFor: ['documentation', 'user_guides', 'api_docs']
569
+ },
570
+ orchestrator: {
571
+ keywords: ['coordinate', 'manage', 'orchestrate', 'organize', 'plan', 'schedule', 'oversee'],
572
+ confidence: 0.9,
573
+ description: 'Task coordination and management',
574
+ requiredFor: ['complex_tasks', 'multi_agent_coordination', 'project_management']
575
+ },
576
+ // ServiceNow specific agents
577
+ flow_designer: {
578
+ keywords: ['flow', 'workflow', 'process', 'automation', 'approval', 'routing', 'trigger', 'proces', 'goedkeuring', 'automatisering', 'automatiseer', 'doorloop', 'stroom'],
579
+ confidence: 0.9,
580
+ description: 'ServiceNow Flow Designer specialist',
581
+ requiredFor: ['flows', 'workflows', 'approvals', 'automation']
582
+ },
583
+ widget_builder: {
584
+ keywords: ['widget', 'portal', 'dashboard', 'ui', 'interface', 'frontend', 'display', 'weergave', 'scherm', 'component', 'homepage'],
585
+ confidence: 0.9,
586
+ description: 'Service Portal widget development',
587
+ requiredFor: ['widgets', 'portals', 'dashboards', 'ui_components']
588
+ },
589
+ integration_specialist: {
590
+ keywords: ['integration', 'api', 'rest', 'soap', 'webhook', 'external', 'third_party'],
591
+ confidence: 0.8,
592
+ description: 'System integration and APIs',
593
+ requiredFor: ['integrations', 'apis', 'webhooks', 'external_systems']
594
+ },
595
+ database_expert: {
596
+ keywords: ['database', 'table', 'field', 'record', 'data', 'schema', 'query', 'report'],
597
+ confidence: 0.8,
598
+ description: 'Database and data management',
599
+ requiredFor: ['tables', 'databases', 'reports', 'data_management']
600
+ }
601
+ };
602
+ // 🚀 ENHANCED: Updated to use new specialized agents for parallel execution (v1.1.92)
603
+ AgentDetector.SERVICENOW_ARTIFACTS = {
604
+ 'widget': [
605
+ 'widget-creator', // HTML structure specialist
606
+ 'css-specialist', // Styling and responsive design specialist
607
+ 'backend-specialist', // Server script specialist
608
+ 'frontend-specialist', // Client script specialist
609
+ 'integration-specialist', // API integration specialist
610
+ 'ui-ux-specialist', // User experience specialist
611
+ 'performance-specialist', // Performance optimization
612
+ 'tester' // Testing specialist
613
+ ],
614
+ 'flow': [
615
+ 'flow-builder', // Flow structure specialist
616
+ 'trigger-specialist', // Trigger configuration specialist
617
+ 'action-specialist', // Action development specialist
618
+ 'integration-specialist', // External system integration
619
+ 'approval-specialist', // Approval process specialist
620
+ 'notification-specialist', // Notification configuration
621
+ 'error-handler', // Error handling specialist
622
+ 'tester' // Flow testing specialist
623
+ ],
624
+ 'workflow': [
625
+ 'flow-builder', 'trigger-specialist', 'action-specialist', 'approval-specialist', 'tester'
626
+ ],
627
+ 'application': [
628
+ 'app-architect', // Application architecture
629
+ 'widget-creator', // UI components
630
+ 'css-specialist', // Styling specialist
631
+ 'flow-builder', // Business logic flows
632
+ 'script-writer', // Script includes and business rules
633
+ 'security-specialist', // Security implementation
634
+ 'integration-specialist', // System integration
635
+ 'performance-specialist', // Performance optimization
636
+ 'documentation-specialist' // Documentation
637
+ ],
638
+ 'script': ['script-writer', 'security-specialist', 'tester'],
639
+ 'business_rule': ['script-writer', 'security-specialist', 'tester'],
640
+ 'integration': [
641
+ 'integration-specialist', // API integration specialist
642
+ 'api-specialist', // API development specialist
643
+ 'transform-specialist', // Data transformation specialist
644
+ 'monitoring-specialist', // Integration monitoring
645
+ 'security-specialist', // Security implementation
646
+ 'tester' // Integration testing
647
+ ],
648
+ 'api': ['api-specialist', 'integration-specialist', 'security-specialist', 'tester'],
649
+ 'table': ['database_expert', 'architect', 'script-writer'],
650
+ 'report': ['database_expert', 'analyst', 'performance-specialist'],
651
+ 'dashboard': ['widget-creator', 'css-specialist', 'database_expert', 'performance-specialist']
652
+ };
653
+ return AgentDetector;
654
+ }());
655
+ exports.AgentDetector = AgentDetector;