snow-flow 2.0.2 → 2.0.3
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/{.claude/mcp-config.json → .mcp.json} +13 -12
- package/.releaserc.json +47 -0
- package/README.md +6 -0
- package/package.json +1 -1
- package/.claude/claude-settings.json +0 -15
- package/.claude/commands/analysis/README.md +0 -9
- package/.claude/commands/automation/README.md +0 -9
- package/.claude/commands/github/README.md +0 -11
- package/.claude/commands/helpers/standard-checkpoint-hooks.sh +0 -179
- package/.claude/commands/hooks/README.md +0 -11
- package/.claude/commands/monitoring/README.md +0 -9
- package/.claude/commands/optimization/README.md +0 -9
- package/.claude/commands/training/README.md +0 -9
- package/.claude/commands/workflows/README.md +0 -9
- package/.claude/config.json +0 -36
- package/.claude/helpers/github-setup.sh +0 -28
- package/.claude/helpers/quick-start.sh +0 -19
- package/.claude/helpers/setup-mcp.sh +0 -18
- package/.claude/settings.json +0 -114
- package/.claude/settings.local.json +0 -33
- package/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude-flow/metrics/performance.json +0 -9
- package/.claude-flow/metrics/system-metrics.json +0 -15986
- package/.claude-flow/metrics/task-metrics.json +0 -10
- package/.roo/README.md +0 -402
- package/.roo/mcp-list.txt +0 -257
- package/.roo/mcp.json +0 -32
- package/.roo/workflows/basic-tdd.json +0 -32
- package/.roomodes +0 -201
- package/CLAUDE.md +0 -393
- package/bin/snow-flow.js +0 -3
- package/dist/cli.js.bak +0 -2052
- package/dist/config/snow-flow-config.d.ts +0 -1492
- package/dist/config/snow-flow-config.js +0 -938
- package/scripts/create-env.js +0 -91
- package/scripts/postinstall.js +0 -30
- package/scripts/register-mcp-servers.js +0 -210
- package/scripts/reset-mcp-servers.js +0 -246
- package/scripts/setup-mcp.js +0 -106
- package/scripts/update-version.js +0 -31
- package/src/agents/README.md +0 -192
- package/src/agents/base-agent.ts +0 -251
- package/src/agents/coordinator.ts +0 -971
- package/src/agents/index.ts +0 -18
- package/src/agents/queen-403-handler.ts +0 -230
- package/src/agents/queen-agent.ts +0 -1399
- package/src/agents/script-writer-agent.ts +0 -769
- package/src/agents/security-agent.ts +0 -726
- package/src/agents/widget-creator-agent.ts +0 -568
- package/src/api/error-handling.ts +0 -1758
- package/src/api/natural-language-mapper.ts +0 -630
- package/src/api/performance-optimizer.ts +0 -891
- package/src/api/transaction-manager.ts +0 -754
- package/src/cli/deploy-artifact.ts +0 -304
- package/src/cli/snow-flow-cli-integration.ts +0 -434
- package/src/cli.ts +0 -4455
- package/src/cli.ts.bak +0 -5616
- package/src/compliance/advanced-compliance-system.ts +0 -1268
- package/src/compliance/index.ts +0 -19
- package/src/config/snow-flow-config.ts +0 -1019
- package/src/documentation/index.ts +0 -16
- package/src/documentation/self-documenting-system.ts +0 -1421
- package/src/dynamic-version.ts +0 -44
- package/src/healing/index.ts +0 -20
- package/src/healing/self-healing-system.ts +0 -1435
- package/src/health/README.md +0 -161
- package/src/health/system-health.ts +0 -995
- package/src/index.ts +0 -60
- package/src/intelligence/acl-analyzer.ts +0 -377
- package/src/intelligence/auto-resolution-engine.ts +0 -643
- package/src/intelligence/gap-analysis-engine.ts +0 -488
- package/src/intelligence/manual-instructions-generator.ts +0 -744
- package/src/intelligence/mcp-coverage-analyzer.ts +0 -708
- package/src/intelligence/multi-pass-requirements-analyzer.ts +0 -603
- package/src/intelligence/performance-recommendations-engine.ts +0 -1223
- package/src/intelligence/requirements-analyzer.ts +0 -1148
- package/src/intelligence/task-analyzer.ts +0 -628
- package/src/managers/scope-manager.ts +0 -555
- package/src/mcp/advanced/servicenow-advanced-features-mcp.ts +0 -16110
- package/src/mcp/base-mcp-server.ts +0 -660
- package/src/mcp/http-transport-wrapper.ts +0 -426
- package/src/mcp/service-discovery-client.ts +0 -312
- package/src/mcp/servicenow-automation-mcp-refactored.ts +0 -678
- package/src/mcp/servicenow-automation-mcp.ts +0 -838
- package/src/mcp/servicenow-deployment-mcp-refactored.ts +0 -1292
- package/src/mcp/servicenow-deployment-mcp.ts +0 -7244
- package/src/mcp/servicenow-graph-memory-mcp-refactored.ts +0 -721
- package/src/mcp/servicenow-graph-memory-mcp.ts +0 -832
- package/src/mcp/servicenow-integration-mcp-refactored.ts +0 -655
- package/src/mcp/servicenow-integration-mcp.ts +0 -819
- package/src/mcp/servicenow-intelligent-mcp-refactored.ts +0 -977
- package/src/mcp/servicenow-intelligent-mcp.ts +0 -4638
- package/src/mcp/servicenow-mcp-server.ts +0 -728
- package/src/mcp/servicenow-memory-mcp.ts +0 -474
- package/src/mcp/servicenow-operations-mcp-refactored.ts +0 -1995
- package/src/mcp/servicenow-operations-mcp.ts +0 -3384
- package/src/mcp/servicenow-platform-development-mcp-refactored.ts +0 -611
- package/src/mcp/servicenow-platform-development-mcp.ts +0 -970
- package/src/mcp/servicenow-progressive-indexer.ts +0 -370
- package/src/mcp/servicenow-reporting-analytics-mcp-refactored.ts +0 -695
- package/src/mcp/servicenow-reporting-analytics-mcp.ts +0 -1123
- package/src/mcp/servicenow-security-compliance-mcp-refactored.ts +0 -642
- package/src/mcp/servicenow-security-compliance-mcp.ts +0 -1157
- package/src/mcp/servicenow-update-set-mcp-refactored.ts +0 -751
- package/src/mcp/servicenow-update-set-mcp.ts +0 -811
- package/src/mcp/shared/agent-context-provider.ts +0 -365
- package/src/mcp/shared/base-mcp-server.ts +0 -2463
- package/src/mcp/shared/mcp-memory-manager.ts +0 -540
- package/src/mcp/shared/mcp-resource-manager.ts +0 -367
- package/src/mcp/snow-flow-mcp.ts +0 -911
- package/src/mcp/start-all-mcp-servers.ts +0 -102
- package/src/mcp/start-servicenow-mcp.ts +0 -67
- package/src/monitoring/enhanced-monitoring-system.ts +0 -1345
- package/src/monitoring/performance-tracker.ts +0 -777
- package/src/optimization/cost-optimization-engine.ts +0 -1125
- package/src/optimization/index.ts +0 -10
- package/src/queen/README.md +0 -403
- package/src/queen/agent-factory.ts +0 -574
- package/src/queen/index.ts +0 -94
- package/src/queen/mcp-execution-bridge.ts +0 -681
- package/src/queen/neural-learning.ts +0 -319
- package/src/queen/parallel-agent-engine.ts +0 -848
- package/src/queen/queen-memory-system.ts +0 -490
- package/src/queen/queen-memory.ts +0 -456
- package/src/queen/servicenow-queen.ts +0 -1029
- package/src/queen/types.ts +0 -87
- package/src/rollback/smart-rollback-system.ts +0 -866
- package/src/schemas/deployment.schema.json +0 -58
- package/src/schemas/flow.schema.json +0 -79
- package/src/schemas/widget.schema.json +0 -72
- package/src/snow-flow-system.ts +0 -541
- package/src/sparc/sparc-help.ts +0 -49
- package/src/sparc/team-sparc.ts +0 -88
- package/src/strategies/global-scope-strategy.ts +0 -736
- package/src/templates/base/application.template.json +0 -45
- package/src/templates/base/business_rule.template.json +0 -33
- package/src/templates/base/script_include.template.json +0 -18
- package/src/templates/base/table.template.json +0 -64
- package/src/templates/base/widget.template.json +0 -25
- package/src/templates/patterns/composite.incident-management.template.json +0 -140
- package/src/templates/patterns/widget.dashboard.template.json +0 -238
- package/src/templates/patterns/widget.datatable.template.json +0 -292
- package/src/testing/integration-test-suite.ts +0 -1276
- package/src/types/index.ts +0 -183
- package/src/types/neo4j-driver.d.ts +0 -23
- package/src/types/servicenow.types.ts +0 -307
- package/src/types/snow-flow.types.ts +0 -186
- package/src/types/todo.types.ts +0 -70
- package/src/utils/action-type-cache.ts +0 -286
- package/src/utils/agent-detector.ts +0 -573
- package/src/utils/artifact-tracker.ts +0 -379
- package/src/utils/dependency-detector.ts +0 -233
- package/src/utils/deployment-metadata-handler.ts +0 -518
- package/src/utils/error-recovery.ts +0 -680
- package/src/utils/logger.ts +0 -60
- package/src/utils/mcp-auth-middleware.ts +0 -262
- package/src/utils/mcp-config-manager.ts +0 -270
- package/src/utils/mcp-server-manager.ts +0 -446
- package/src/utils/mcp-tool-registry.ts +0 -298
- package/src/utils/migrate-snow-flow.ts +0 -98
- package/src/utils/oauth-html-templates.ts +0 -188
- package/src/utils/scope-utils.ts +0 -443
- package/src/utils/servicenow-client.ts +0 -3321
- package/src/utils/servicenow-id-generator.ts +0 -181
- package/src/utils/snow-memory-manager.ts +0 -605
- package/src/utils/snow-oauth.ts +0 -797
- package/src/utils/template-engine.ts +0 -463
- package/src/utils/theme-manager.ts +0 -295
- package/src/utils/unified-auth-store.ts +0 -222
- package/src/utils/update-set-importer.ts +0 -422
- package/src/utils/update-set-xml-packager.ts +0 -371
- package/src/utils/widget-template-generator.ts +0 -1744
- package/src/version.ts +0 -1950
|
@@ -1,630 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Natural Language to ServiceNow Action Type Mapper
|
|
3
|
-
* Intelligent mapping from natural language descriptions to ServiceNow action types
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Flow API Discovery removed in v1.4.0
|
|
7
|
-
import { Logger } from '../utils/logger.js';
|
|
8
|
-
|
|
9
|
-
// Flow types removed in v1.4.0
|
|
10
|
-
export interface NLPMappingResult {
|
|
11
|
-
action_type: string; // was FlowActionType
|
|
12
|
-
confidence: number;
|
|
13
|
-
reasoning: string;
|
|
14
|
-
suggested_inputs: Record<string, any>;
|
|
15
|
-
alternative_actions: string[]; // was FlowActionType[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ActionIntent {
|
|
19
|
-
verb: string;
|
|
20
|
-
object: string;
|
|
21
|
-
context: string[];
|
|
22
|
-
modifiers: string[];
|
|
23
|
-
conditions: string[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface MappingContext {
|
|
27
|
-
previous_actions: string[];
|
|
28
|
-
target_table: string;
|
|
29
|
-
flow_purpose: string;
|
|
30
|
-
available_data: Record<string, any>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class NaturalLanguageMapper {
|
|
34
|
-
// private discovery: FlowAPIDiscovery; // removed in v1.4.0
|
|
35
|
-
private logger: Logger;
|
|
36
|
-
private verbMappings: Map<string, string[]> = new Map();
|
|
37
|
-
private objectMappings: Map<string, string[]> = new Map();
|
|
38
|
-
private contextMappings: Map<string, string[]> = new Map();
|
|
39
|
-
|
|
40
|
-
constructor() { // discovery: FlowAPIDiscovery removed in v1.4.0
|
|
41
|
-
// this.discovery = discovery; // removed in v1.4.0
|
|
42
|
-
this.logger = new Logger('NaturalLanguageMapper');
|
|
43
|
-
this.initializeMappings();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Map natural language description to ServiceNow action type
|
|
48
|
-
*/
|
|
49
|
-
async mapToActionType(description: string, context?: MappingContext): Promise<NLPMappingResult> {
|
|
50
|
-
this.logger.info('Mapping natural language to action type', { description });
|
|
51
|
-
|
|
52
|
-
// 1. Parse the natural language description
|
|
53
|
-
const intent = this.parseIntent(description);
|
|
54
|
-
|
|
55
|
-
// 2. Generate search terms
|
|
56
|
-
const searchTerms = this.generateSearchTerms(intent);
|
|
57
|
-
|
|
58
|
-
// 3. Search for matching action types
|
|
59
|
-
const searchResults = await this.searchActionTypes(searchTerms);
|
|
60
|
-
|
|
61
|
-
// 4. Score and rank results
|
|
62
|
-
const rankedResults = this.rankResults(searchResults, intent, context);
|
|
63
|
-
|
|
64
|
-
// 5. Generate suggested inputs
|
|
65
|
-
const suggestedInputs = await this.generateSuggestedInputs(
|
|
66
|
-
rankedResults.best_match,
|
|
67
|
-
intent,
|
|
68
|
-
context
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
action_type: rankedResults.best_match,
|
|
73
|
-
confidence: rankedResults.confidence,
|
|
74
|
-
reasoning: rankedResults.reasoning,
|
|
75
|
-
suggested_inputs: suggestedInputs,
|
|
76
|
-
alternative_actions: rankedResults.alternatives
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Parse natural language description into structured intent
|
|
82
|
-
*/
|
|
83
|
-
private parseIntent(description: string): ActionIntent {
|
|
84
|
-
const lowerDesc = description.toLowerCase();
|
|
85
|
-
const words = lowerDesc.split(/\s+/);
|
|
86
|
-
|
|
87
|
-
// Extract verb (action)
|
|
88
|
-
const verb = this.extractVerb(words);
|
|
89
|
-
|
|
90
|
-
// Extract object (what the action is performed on)
|
|
91
|
-
const object = this.extractObject(words);
|
|
92
|
-
|
|
93
|
-
// Extract context (additional information)
|
|
94
|
-
const context = this.extractContext(words);
|
|
95
|
-
|
|
96
|
-
// Extract modifiers (how the action is performed)
|
|
97
|
-
const modifiers = this.extractModifiers(words);
|
|
98
|
-
|
|
99
|
-
// Extract conditions (when the action is performed)
|
|
100
|
-
const conditions = this.extractConditions(words);
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
verb,
|
|
104
|
-
object,
|
|
105
|
-
context,
|
|
106
|
-
modifiers,
|
|
107
|
-
conditions
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Extract the primary verb from the description
|
|
113
|
-
*/
|
|
114
|
-
private extractVerb(words: string[]): string {
|
|
115
|
-
const actionVerbs = [
|
|
116
|
-
'send', 'create', 'update', 'delete', 'notify', 'email', 'call', 'execute',
|
|
117
|
-
'run', 'start', 'stop', 'wait', 'delay', 'check', 'validate', 'approve',
|
|
118
|
-
'reject', 'assign', 'escalate', 'close', 'open', 'set', 'get', 'fetch',
|
|
119
|
-
'save', 'load', 'transform', 'convert', 'parse', 'format', 'log', 'audit',
|
|
120
|
-
'track', 'monitor', 'alert', 'trigger', 'schedule', 'cancel', 'retry'
|
|
121
|
-
];
|
|
122
|
-
|
|
123
|
-
for (const word of words) {
|
|
124
|
-
if (actionVerbs.includes(word)) {
|
|
125
|
-
return word;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// If no direct verb found, try to infer from context
|
|
130
|
-
if (words.includes('notification') || words.includes('message')) {
|
|
131
|
-
return 'send';
|
|
132
|
-
}
|
|
133
|
-
if (words.includes('record') || words.includes('entry')) {
|
|
134
|
-
return 'create';
|
|
135
|
-
}
|
|
136
|
-
if (words.includes('field') || words.includes('value')) {
|
|
137
|
-
return 'update';
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return 'execute'; // Default fallback
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Extract the object being acted upon
|
|
145
|
-
*/
|
|
146
|
-
private extractObject(words: string[]): string {
|
|
147
|
-
const objectNouns = [
|
|
148
|
-
'email', 'notification', 'message', 'record', 'field', 'value', 'task',
|
|
149
|
-
'ticket', 'incident', 'request', 'approval', 'user', 'group', 'table',
|
|
150
|
-
'script', 'workflow', 'process', 'data', 'file', 'document', 'report',
|
|
151
|
-
'log', 'audit', 'event', 'alert', 'condition', 'rule', 'policy'
|
|
152
|
-
];
|
|
153
|
-
|
|
154
|
-
for (const word of words) {
|
|
155
|
-
if (objectNouns.includes(word)) {
|
|
156
|
-
return word;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return 'record'; // Default fallback
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Extract context information
|
|
165
|
-
*/
|
|
166
|
-
private extractContext(words: string[]): string[] {
|
|
167
|
-
const contextWords = [
|
|
168
|
-
'manager', 'admin', 'user', 'requester', 'approver', 'assignee',
|
|
169
|
-
'high', 'medium', 'low', 'critical', 'urgent', 'normal',
|
|
170
|
-
'active', 'inactive', 'pending', 'completed', 'cancelled',
|
|
171
|
-
'business', 'technical', 'operational', 'security', 'compliance'
|
|
172
|
-
];
|
|
173
|
-
|
|
174
|
-
return words.filter(word => contextWords.includes(word));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Extract modifiers (how the action is performed)
|
|
179
|
-
*/
|
|
180
|
-
private extractModifiers(words: string[]): string[] {
|
|
181
|
-
const modifiers = [
|
|
182
|
-
'automatically', 'manually', 'immediately', 'delayed', 'scheduled',
|
|
183
|
-
'conditionally', 'recursively', 'asynchronously', 'synchronously',
|
|
184
|
-
'securely', 'encrypted', 'logged', 'audited', 'tracked'
|
|
185
|
-
];
|
|
186
|
-
|
|
187
|
-
return words.filter(word => modifiers.includes(word));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Extract conditions (when the action is performed)
|
|
192
|
-
*/
|
|
193
|
-
private extractConditions(words: string[]): string[] {
|
|
194
|
-
const conditions = [];
|
|
195
|
-
const conditionMarkers = ['when', 'if', 'unless', 'after', 'before', 'during', 'while'];
|
|
196
|
-
|
|
197
|
-
for (let i = 0; i < words.length; i++) {
|
|
198
|
-
if (conditionMarkers.includes(words[i])) {
|
|
199
|
-
// Extract the condition phrase
|
|
200
|
-
const conditionStart = i + 1;
|
|
201
|
-
const conditionEnd = words.findIndex((word, index) =>
|
|
202
|
-
index > conditionStart && ['then', 'and', 'or', 'but'].includes(word)
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
const condition = words.slice(conditionStart, conditionEnd > -1 ? conditionEnd : words.length).join(' ');
|
|
206
|
-
if (condition) {
|
|
207
|
-
conditions.push(condition);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return conditions;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Generate search terms for action type discovery
|
|
217
|
-
*/
|
|
218
|
-
private generateSearchTerms(intent: ActionIntent): string[] {
|
|
219
|
-
const searchTerms: string[] = [];
|
|
220
|
-
|
|
221
|
-
// Primary search term: verb + object
|
|
222
|
-
searchTerms.push(`${intent.verb} ${intent.object}`);
|
|
223
|
-
|
|
224
|
-
// Add verb mappings
|
|
225
|
-
const verbMappings = this.verbMappings.get(intent.verb) || [];
|
|
226
|
-
verbMappings.forEach(mapping => {
|
|
227
|
-
searchTerms.push(mapping);
|
|
228
|
-
searchTerms.push(`${mapping} ${intent.object}`);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// Add object mappings
|
|
232
|
-
const objectMappings = this.objectMappings.get(intent.object) || [];
|
|
233
|
-
objectMappings.forEach(mapping => {
|
|
234
|
-
searchTerms.push(`${intent.verb} ${mapping}`);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
// Add context-based search terms
|
|
238
|
-
intent.context.forEach(ctx => {
|
|
239
|
-
const contextMappings = this.contextMappings.get(ctx) || [];
|
|
240
|
-
contextMappings.forEach(mapping => {
|
|
241
|
-
searchTerms.push(mapping);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// Add modifier-based search terms
|
|
246
|
-
intent.modifiers.forEach(modifier => {
|
|
247
|
-
if (modifier === 'automatically') {
|
|
248
|
-
searchTerms.push('automated');
|
|
249
|
-
} else if (modifier === 'scheduled') {
|
|
250
|
-
searchTerms.push('timer', 'schedule');
|
|
251
|
-
} else if (modifier === 'conditionally') {
|
|
252
|
-
searchTerms.push('condition', 'if');
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
return [...new Set(searchTerms)]; // Remove duplicates
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Search for action types using multiple search terms
|
|
261
|
-
*/
|
|
262
|
-
private async searchActionTypes(searchTerms: string[]): Promise<any[]> {
|
|
263
|
-
const allResults: any[] = [];
|
|
264
|
-
|
|
265
|
-
for (const term of searchTerms) {
|
|
266
|
-
try {
|
|
267
|
-
// Flow discovery removed in v1.4.0 - using fallback logic
|
|
268
|
-
const result = { exact_matches: [], partial_matches: [], suggested_matches: [] };
|
|
269
|
-
allResults.push(result);
|
|
270
|
-
} catch (error) {
|
|
271
|
-
this.logger.warn(`Search failed for term: ${term}`, error);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return allResults;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Rank and score search results
|
|
280
|
-
*/
|
|
281
|
-
private rankResults(
|
|
282
|
-
searchResults: any[],
|
|
283
|
-
intent: ActionIntent,
|
|
284
|
-
context?: MappingContext
|
|
285
|
-
): {
|
|
286
|
-
best_match: string;
|
|
287
|
-
confidence: number;
|
|
288
|
-
reasoning: string;
|
|
289
|
-
alternatives: string[];
|
|
290
|
-
} {
|
|
291
|
-
const actionScores = new Map<string, number>();
|
|
292
|
-
const actionReasons = new Map<string, string[]>();
|
|
293
|
-
const allActions = new Set<string>();
|
|
294
|
-
|
|
295
|
-
// Score actions from all search results
|
|
296
|
-
for (const result of searchResults) {
|
|
297
|
-
// Score exact matches highest
|
|
298
|
-
result.exact_matches.forEach(action => {
|
|
299
|
-
this.addScore(actionScores, action.sys_id, 1.0);
|
|
300
|
-
this.addReason(actionReasons, action.sys_id, 'Exact match');
|
|
301
|
-
allActions.add(action);
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
// Score partial matches medium
|
|
305
|
-
result.partial_matches.forEach(action => {
|
|
306
|
-
this.addScore(actionScores, action.sys_id, 0.7);
|
|
307
|
-
this.addReason(actionReasons, action.sys_id, 'Partial match');
|
|
308
|
-
allActions.add(action);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
// Score semantic matches lower
|
|
312
|
-
result.semantic_matches.forEach(action => {
|
|
313
|
-
this.addScore(actionScores, action.sys_id, 0.4);
|
|
314
|
-
this.addReason(actionReasons, action.sys_id, 'Semantic match');
|
|
315
|
-
allActions.add(action);
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Apply context-based scoring
|
|
320
|
-
if (context) {
|
|
321
|
-
for (const action of allActions) {
|
|
322
|
-
const contextScore = this.scoreByContext(action, context);
|
|
323
|
-
this.addScore(actionScores, action, contextScore);
|
|
324
|
-
if (contextScore > 0) {
|
|
325
|
-
this.addReason(actionReasons, action, 'Context match');
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Find best match
|
|
331
|
-
const sortedActions = Array.from(allActions).sort((a, b) => {
|
|
332
|
-
const scoreA = actionScores.get(a) || 0;
|
|
333
|
-
const scoreB = actionScores.get(b) || 0;
|
|
334
|
-
return scoreB - scoreA;
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
const bestMatch = sortedActions[0];
|
|
338
|
-
const bestMatchId = typeof bestMatch === 'string' ? bestMatch : (bestMatch as any)?.sys_id || bestMatch;
|
|
339
|
-
const confidence = actionScores.get(bestMatchId) || 0;
|
|
340
|
-
const reasoning = actionReasons.get(bestMatchId)?.join(', ') || 'No specific reasoning';
|
|
341
|
-
const alternatives = sortedActions.slice(1, 4); // Top 3 alternatives
|
|
342
|
-
|
|
343
|
-
return {
|
|
344
|
-
best_match: bestMatch,
|
|
345
|
-
confidence: Math.min(confidence, 1.0), // Cap at 1.0
|
|
346
|
-
reasoning,
|
|
347
|
-
alternatives
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Generate suggested inputs for an action type
|
|
353
|
-
*/
|
|
354
|
-
private async generateSuggestedInputs(
|
|
355
|
-
actionType: string,
|
|
356
|
-
intent: ActionIntent,
|
|
357
|
-
context?: MappingContext
|
|
358
|
-
): Promise<Record<string, any>> {
|
|
359
|
-
const suggestedInputs: Record<string, any> = {};
|
|
360
|
-
|
|
361
|
-
// Get action type details to understand inputs
|
|
362
|
-
// Flow discovery removed in v1.4.0 - using fallback
|
|
363
|
-
const actionDetails = null;
|
|
364
|
-
if (!actionDetails) {
|
|
365
|
-
return suggestedInputs;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// Generate inputs based on action type and intent
|
|
369
|
-
for (const input of actionDetails.inputs) {
|
|
370
|
-
let suggestedValue: any = input.default_value;
|
|
371
|
-
|
|
372
|
-
// Generate contextual values based on input name and intent
|
|
373
|
-
switch (input.name.toLowerCase()) {
|
|
374
|
-
case 'to':
|
|
375
|
-
case 'recipient':
|
|
376
|
-
case 'email_to':
|
|
377
|
-
suggestedValue = this.suggestRecipient(intent, context);
|
|
378
|
-
break;
|
|
379
|
-
|
|
380
|
-
case 'subject':
|
|
381
|
-
case 'email_subject':
|
|
382
|
-
suggestedValue = this.suggestSubject(intent, context);
|
|
383
|
-
break;
|
|
384
|
-
|
|
385
|
-
case 'message':
|
|
386
|
-
case 'body':
|
|
387
|
-
case 'email_body':
|
|
388
|
-
suggestedValue = this.suggestMessage(intent, context);
|
|
389
|
-
break;
|
|
390
|
-
|
|
391
|
-
case 'table':
|
|
392
|
-
case 'target_table':
|
|
393
|
-
suggestedValue = context?.target_table || 'incident';
|
|
394
|
-
break;
|
|
395
|
-
|
|
396
|
-
case 'field':
|
|
397
|
-
case 'field_name':
|
|
398
|
-
suggestedValue = this.suggestField(intent, context);
|
|
399
|
-
break;
|
|
400
|
-
|
|
401
|
-
case 'value':
|
|
402
|
-
case 'field_value':
|
|
403
|
-
suggestedValue = this.suggestValue(intent, context);
|
|
404
|
-
break;
|
|
405
|
-
|
|
406
|
-
case 'condition':
|
|
407
|
-
suggestedValue = this.suggestCondition(intent, context);
|
|
408
|
-
break;
|
|
409
|
-
|
|
410
|
-
case 'duration':
|
|
411
|
-
case 'delay':
|
|
412
|
-
suggestedValue = this.suggestDuration(intent);
|
|
413
|
-
break;
|
|
414
|
-
|
|
415
|
-
case 'script':
|
|
416
|
-
suggestedValue = this.suggestScript(intent, context);
|
|
417
|
-
break;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (suggestedValue !== undefined) {
|
|
421
|
-
suggestedInputs[input.name] = suggestedValue;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
return suggestedInputs;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Suggest recipient based on intent
|
|
430
|
-
*/
|
|
431
|
-
private suggestRecipient(intent: ActionIntent, context?: MappingContext): string {
|
|
432
|
-
if (intent.context.includes('manager')) {
|
|
433
|
-
return '${trigger.record.assigned_to.manager.email}';
|
|
434
|
-
}
|
|
435
|
-
if (intent.context.includes('admin')) {
|
|
436
|
-
return '${trigger.record.assignment_group.manager.email}';
|
|
437
|
-
}
|
|
438
|
-
if (intent.context.includes('requester')) {
|
|
439
|
-
return '${trigger.record.requested_for.email}';
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
return '${trigger.record.assigned_to.email}';
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Suggest subject based on intent
|
|
447
|
-
*/
|
|
448
|
-
private suggestSubject(intent: ActionIntent, context?: MappingContext): string {
|
|
449
|
-
const action = intent.verb.charAt(0).toUpperCase() + intent.verb.slice(1);
|
|
450
|
-
const object = intent.object.charAt(0).toUpperCase() + intent.object.slice(1);
|
|
451
|
-
|
|
452
|
-
return `${action} ${object}: \${trigger.record.number}`;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Suggest message based on intent
|
|
457
|
-
*/
|
|
458
|
-
private suggestMessage(intent: ActionIntent, context?: MappingContext): string {
|
|
459
|
-
const templates = {
|
|
460
|
-
'send notification': 'A notification has been triggered for ${trigger.record.number}.',
|
|
461
|
-
'send email': 'Please review ${trigger.record.number}: ${trigger.record.short_description}',
|
|
462
|
-
'create task': 'A new task has been created: ${trigger.record.short_description}',
|
|
463
|
-
'update field': 'Field ${field} has been updated to ${value}',
|
|
464
|
-
'approve request': 'Your approval is required for ${trigger.record.number}'
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
const key = `${intent.verb} ${intent.object}`;
|
|
468
|
-
return templates[key] || `Flow action executed: ${key}`;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* Suggest field based on intent
|
|
473
|
-
*/
|
|
474
|
-
private suggestField(intent: ActionIntent, context?: MappingContext): string {
|
|
475
|
-
if (intent.context.includes('high') || intent.context.includes('critical')) {
|
|
476
|
-
return 'priority';
|
|
477
|
-
}
|
|
478
|
-
if (intent.context.includes('active') || intent.context.includes('inactive')) {
|
|
479
|
-
return 'active';
|
|
480
|
-
}
|
|
481
|
-
if (intent.context.includes('pending') || intent.context.includes('completed')) {
|
|
482
|
-
return 'state';
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
return 'state';
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Suggest value based on intent
|
|
490
|
-
*/
|
|
491
|
-
private suggestValue(intent: ActionIntent, context?: MappingContext): string {
|
|
492
|
-
if (intent.context.includes('high')) {
|
|
493
|
-
return '1';
|
|
494
|
-
}
|
|
495
|
-
if (intent.context.includes('medium')) {
|
|
496
|
-
return '2';
|
|
497
|
-
}
|
|
498
|
-
if (intent.context.includes('low')) {
|
|
499
|
-
return '3';
|
|
500
|
-
}
|
|
501
|
-
if (intent.context.includes('active')) {
|
|
502
|
-
return 'true';
|
|
503
|
-
}
|
|
504
|
-
if (intent.context.includes('inactive')) {
|
|
505
|
-
return 'false';
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
return '${trigger.record.value}';
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Suggest condition based on intent
|
|
513
|
-
*/
|
|
514
|
-
private suggestCondition(intent: ActionIntent, context?: MappingContext): string {
|
|
515
|
-
if (intent.conditions.length > 0) {
|
|
516
|
-
return intent.conditions[0];
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
return 'state=1';
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Suggest duration based on intent
|
|
524
|
-
*/
|
|
525
|
-
private suggestDuration(intent: ActionIntent): number {
|
|
526
|
-
if (intent.modifiers.includes('immediately')) {
|
|
527
|
-
return 0;
|
|
528
|
-
}
|
|
529
|
-
if (intent.context.includes('minutes')) {
|
|
530
|
-
return 300; // 5 minutes
|
|
531
|
-
}
|
|
532
|
-
if (intent.context.includes('hours')) {
|
|
533
|
-
return 3600; // 1 hour
|
|
534
|
-
}
|
|
535
|
-
if (intent.context.includes('days')) {
|
|
536
|
-
return 86400; // 1 day
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
return 300; // Default 5 minutes
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Suggest script based on intent
|
|
544
|
-
*/
|
|
545
|
-
private suggestScript(intent: ActionIntent, context?: MappingContext): string {
|
|
546
|
-
const templates = {
|
|
547
|
-
'log': 'gs.log("Flow action executed: ${trigger.record.number}");',
|
|
548
|
-
'audit': 'gs.audit("Flow action", "${trigger.record.number}");',
|
|
549
|
-
'validate': 'if (current.isValid()) { gs.log("Valid"); } else { gs.log("Invalid"); }',
|
|
550
|
-
'calculate': 'var result = current.field1 + current.field2; current.result = result;'
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
return templates[intent.verb] || '// Custom script for ${trigger.record.number}';
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* Add score to an action
|
|
558
|
-
*/
|
|
559
|
-
private addScore(scores: Map<string, number>, actionId: string, score: number): void {
|
|
560
|
-
const currentScore = scores.get(actionId) || 0;
|
|
561
|
-
scores.set(actionId, currentScore + score);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Add reason to an action
|
|
566
|
-
*/
|
|
567
|
-
private addReason(reasons: Map<string, string[]>, actionId: string, reason: string): void {
|
|
568
|
-
const currentReasons = reasons.get(actionId) || [];
|
|
569
|
-
currentReasons.push(reason);
|
|
570
|
-
reasons.set(actionId, currentReasons);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* Score action by context
|
|
575
|
-
*/
|
|
576
|
-
private scoreByContext(action: string, context: MappingContext): number {
|
|
577
|
-
let score = 0;
|
|
578
|
-
|
|
579
|
-
// Score based on action name matching context
|
|
580
|
-
if (action && context.flow_purpose) {
|
|
581
|
-
const actionLower = action.toLowerCase();
|
|
582
|
-
const purposeLower = context.flow_purpose.toLowerCase();
|
|
583
|
-
|
|
584
|
-
if (actionLower.includes(purposeLower) || purposeLower.includes(actionLower)) {
|
|
585
|
-
score += 0.3;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// Score based on action requirements (if available)
|
|
590
|
-
if (action && (context as any).action_requirements) {
|
|
591
|
-
const matches = (context as any).action_requirements.filter((req: string) =>
|
|
592
|
-
action.toLowerCase().includes(req.toLowerCase())
|
|
593
|
-
);
|
|
594
|
-
score += matches.length * 0.1;
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
return score;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Initialize mapping tables
|
|
602
|
-
*/
|
|
603
|
-
private initializeMappings(): void {
|
|
604
|
-
// Verb mappings
|
|
605
|
-
this.verbMappings.set('send', ['notify', 'email', 'message', 'alert']);
|
|
606
|
-
this.verbMappings.set('create', ['add', 'insert', 'new', 'generate']);
|
|
607
|
-
this.verbMappings.set('update', ['modify', 'change', 'edit', 'set']);
|
|
608
|
-
this.verbMappings.set('delete', ['remove', 'destroy', 'erase']);
|
|
609
|
-
this.verbMappings.set('notify', ['send', 'alert', 'email']);
|
|
610
|
-
this.verbMappings.set('approve', ['authorization', 'review']);
|
|
611
|
-
this.verbMappings.set('wait', ['delay', 'pause', 'timer']);
|
|
612
|
-
this.verbMappings.set('execute', ['run', 'script', 'custom']);
|
|
613
|
-
this.verbMappings.set('log', ['audit', 'track', 'record']);
|
|
614
|
-
this.verbMappings.set('check', ['validate', 'test', 'condition']);
|
|
615
|
-
|
|
616
|
-
// Object mappings
|
|
617
|
-
this.objectMappings.set('email', ['notification', 'message', 'mail']);
|
|
618
|
-
this.objectMappings.set('record', ['entry', 'row', 'item']);
|
|
619
|
-
this.objectMappings.set('task', ['job', 'work', 'activity']);
|
|
620
|
-
this.objectMappings.set('field', ['column', 'attribute', 'property']);
|
|
621
|
-
this.objectMappings.set('user', ['person', 'individual', 'account']);
|
|
622
|
-
this.objectMappings.set('approval', ['authorization', 'permission']);
|
|
623
|
-
|
|
624
|
-
// Context mappings
|
|
625
|
-
this.contextMappings.set('manager', ['supervisor', 'lead', 'director']);
|
|
626
|
-
this.contextMappings.set('admin', ['administrator', 'sysadmin', 'system']);
|
|
627
|
-
this.contextMappings.set('high', ['critical', 'urgent', 'important']);
|
|
628
|
-
this.contextMappings.set('low', ['minor', 'trivial', 'routine']);
|
|
629
|
-
}
|
|
630
|
-
}
|