snow-flow 10.0.1-dev.441 → 10.0.1-dev.443
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/package.json
CHANGED
|
@@ -406,7 +406,7 @@ async function resolveFlowId(client: any, flowId: string): Promise<string> {
|
|
|
406
406
|
|
|
407
407
|
export const toolDefinition: MCPToolDefinition = {
|
|
408
408
|
name: 'snow_manage_flow',
|
|
409
|
-
description: 'Complete Flow Designer lifecycle: create flows/subflows, list, get details, update, activate, deactivate, delete and publish',
|
|
409
|
+
description: 'Complete Flow Designer lifecycle: create flows/subflows, add/update triggers and actions, list, get details, update, activate, deactivate, delete and publish. Use update_trigger to change an existing trigger (e.g. switch from record_created to record_create_or_update) without deleting the flow.',
|
|
410
410
|
category: 'automation',
|
|
411
411
|
subcategory: 'flow-designer',
|
|
412
412
|
use_cases: ['flow-designer', 'automation', 'flow-management', 'subflow'],
|
|
@@ -419,8 +419,8 @@ export const toolDefinition: MCPToolDefinition = {
|
|
|
419
419
|
properties: {
|
|
420
420
|
action: {
|
|
421
421
|
type: 'string',
|
|
422
|
-
enum: ['create', 'create_subflow', 'list', 'get', 'update', 'activate', 'deactivate', 'delete', 'publish', 'add_trigger', 'add_action'],
|
|
423
|
-
description: 'Action to perform'
|
|
422
|
+
enum: ['create', 'create_subflow', 'list', 'get', 'update', 'activate', 'deactivate', 'delete', 'publish', 'add_trigger', 'update_trigger', 'add_action'],
|
|
423
|
+
description: 'Action to perform. Use add_trigger/add_action to add new elements, update_trigger to change an existing trigger type/table/condition.'
|
|
424
424
|
},
|
|
425
425
|
|
|
426
426
|
flow_id: {
|
|
@@ -438,8 +438,7 @@ export const toolDefinition: MCPToolDefinition = {
|
|
|
438
438
|
},
|
|
439
439
|
trigger_type: {
|
|
440
440
|
type: 'string',
|
|
441
|
-
|
|
442
|
-
description: 'Trigger type (create only, default: manual)',
|
|
441
|
+
description: 'Trigger type - looked up dynamically in sys_hub_trigger_definition. Common values: record_create, record_update, record_create_or_update, scheduled, manual (default: manual)',
|
|
443
442
|
default: 'manual'
|
|
444
443
|
},
|
|
445
444
|
table: {
|
|
@@ -470,8 +469,7 @@ export const toolDefinition: MCPToolDefinition = {
|
|
|
470
469
|
name: { type: 'string', description: 'Step name' },
|
|
471
470
|
type: {
|
|
472
471
|
type: 'string',
|
|
473
|
-
|
|
474
|
-
description: 'Action type'
|
|
472
|
+
description: 'Action type - looked up dynamically in sys_hub_action_type_snapshot by internal_name or name. Common values: log, create_record, update_record, send_notification, script, field_update, wait, create_approval'
|
|
475
473
|
},
|
|
476
474
|
inputs: { type: 'object', description: 'Step-specific input values' }
|
|
477
475
|
}
|
|
@@ -1352,6 +1350,69 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
|
|
|
1352
1350
|
: createErrorResult(addTrigResult.error || 'Failed to add trigger');
|
|
1353
1351
|
}
|
|
1354
1352
|
|
|
1353
|
+
// ────────────────────────────────────────────────────────────────
|
|
1354
|
+
// UPDATE_TRIGGER — replace existing trigger(s) with a new one
|
|
1355
|
+
// ────────────────────────────────────────────────────────────────
|
|
1356
|
+
case 'update_trigger': {
|
|
1357
|
+
if (!args.flow_id) {
|
|
1358
|
+
throw new SnowFlowError(ErrorType.VALIDATION_ERROR, 'flow_id is required for update_trigger');
|
|
1359
|
+
}
|
|
1360
|
+
var updTrigFlowId = await resolveFlowId(client, args.flow_id);
|
|
1361
|
+
var updTrigType = args.trigger_type || 'record_create_or_update';
|
|
1362
|
+
var updTrigTable = args.table || '';
|
|
1363
|
+
var updTrigCondition = args.trigger_condition || '';
|
|
1364
|
+
var updTrigSteps: any = {};
|
|
1365
|
+
|
|
1366
|
+
// Step 1: Find existing trigger instances on this flow
|
|
1367
|
+
try {
|
|
1368
|
+
var existingTriggers = await client.get('/api/now/table/sys_hub_trigger_instance', {
|
|
1369
|
+
params: {
|
|
1370
|
+
sysparm_query: 'flow=' + updTrigFlowId,
|
|
1371
|
+
sysparm_fields: 'sys_id,name,type',
|
|
1372
|
+
sysparm_limit: 10
|
|
1373
|
+
}
|
|
1374
|
+
});
|
|
1375
|
+
var trigInstances = existingTriggers.data.result || [];
|
|
1376
|
+
updTrigSteps.existing_triggers = trigInstances.map((t: any) => ({ sys_id: t.sys_id, name: t.name, type: t.type }));
|
|
1377
|
+
|
|
1378
|
+
// Step 2: Delete existing triggers via GraphQL
|
|
1379
|
+
if (trigInstances.length > 0) {
|
|
1380
|
+
var deleteIds = trigInstances.map((t: any) => t.sys_id);
|
|
1381
|
+
try {
|
|
1382
|
+
await executeFlowPatchMutation(client, {
|
|
1383
|
+
flowId: updTrigFlowId,
|
|
1384
|
+
triggerInstances: { delete: deleteIds }
|
|
1385
|
+
}, 'triggerInstances { deletes __typename }');
|
|
1386
|
+
updTrigSteps.deleted = deleteIds;
|
|
1387
|
+
} catch (e: any) {
|
|
1388
|
+
updTrigSteps.delete_error = e.message;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
} catch (_) {
|
|
1392
|
+
updTrigSteps.lookup_error = 'Could not query existing triggers';
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
// Step 3: Add the new trigger
|
|
1396
|
+
var updTrigResult = await addTriggerViaGraphQL(client, updTrigFlowId, updTrigType, updTrigTable, updTrigCondition);
|
|
1397
|
+
updTrigSteps.new_trigger = updTrigResult;
|
|
1398
|
+
|
|
1399
|
+
var updTrigSummary = summary();
|
|
1400
|
+
if (updTrigResult.success) {
|
|
1401
|
+
updTrigSummary
|
|
1402
|
+
.success('Trigger updated via GraphQL')
|
|
1403
|
+
.field('Flow', updTrigFlowId)
|
|
1404
|
+
.field('New Type', updTrigType)
|
|
1405
|
+
.field('Trigger ID', updTrigResult.triggerId || 'unknown');
|
|
1406
|
+
if (updTrigTable) updTrigSummary.field('Table', updTrigTable);
|
|
1407
|
+
} else {
|
|
1408
|
+
updTrigSummary.error('Failed to update trigger: ' + (updTrigResult.error || 'unknown'));
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
return updTrigResult.success
|
|
1412
|
+
? createSuccessResult({ action: 'update_trigger', steps: updTrigSteps }, {}, updTrigSummary.build())
|
|
1413
|
+
: createErrorResult(updTrigResult.error || 'Failed to update trigger');
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1355
1416
|
// ────────────────────────────────────────────────────────────────
|
|
1356
1417
|
// ADD_ACTION
|
|
1357
1418
|
// ────────────────────────────────────────────────────────────────
|