snow-flow 10.0.1-dev.401 → 10.0.1-dev.402

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "10.0.1-dev.401",
3
+ "version": "10.0.1-dev.402",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -59,6 +59,12 @@ async function createFlowViaScheduledJob(
59
59
  category: string;
60
60
  runAs: string;
61
61
  shouldActivate: boolean;
62
+ triggerType?: string;
63
+ triggerTable?: string;
64
+ triggerCondition?: string;
65
+ activities?: Array<{ name: string; type?: string; inputs?: any }>;
66
+ inputs?: Array<{ name: string; label?: string; type?: string; mandatory?: boolean; default_value?: string }>;
67
+ outputs?: Array<{ name: string; label?: string; type?: string }>;
62
68
  }
63
69
  ): Promise<{
64
70
  success: boolean;
@@ -85,6 +91,15 @@ async function createFlowViaScheduledJob(
85
91
  " var flowCat = '" + escForScript(params.category) + "';",
86
92
  " var runAs = '" + escForScript(params.runAs) + "';",
87
93
  " var activate = " + (params.shouldActivate ? "true" : "false") + ";",
94
+ " var trigType = '" + escForScript(params.triggerType || 'manual') + "';",
95
+ " var trigTable = '" + escForScript(params.triggerTable || '') + "';",
96
+ " var trigCondition = '" + escForScript(params.triggerCondition || '') + "';",
97
+ " var activitiesJson = '" + escForScript(JSON.stringify(params.activities || [])) + "';",
98
+ " var inputsJson = '" + escForScript(JSON.stringify(params.inputs || [])) + "';",
99
+ " var outputsJson = '" + escForScript(JSON.stringify(params.outputs || [])) + "';",
100
+ " var activities = []; try { activities = JSON.parse(activitiesJson); } catch(e) {}",
101
+ " var inputs = []; try { inputs = JSON.parse(inputsJson); } catch(e) {}",
102
+ " var outputs = []; try { outputs = JSON.parse(outputsJson); } catch(e) {}",
88
103
  " var flowSysId = null;",
89
104
  " var verSysId = null;",
90
105
  "",
@@ -141,6 +156,68 @@ async function createFlowViaScheduledJob(
141
156
  " } catch(t2e) { r.steps.tier2 = { success: false, error: t2e.getMessage ? t2e.getMessage() : t2e + '' }; }",
142
157
  " }",
143
158
  "",
159
+ // ── Trigger, action, variable creation (runs for any tier) ──
160
+ " if (flowSysId) {",
161
+ // Trigger
162
+ " if (!isSubflow && trigType !== 'manual') {",
163
+ " try {",
164
+ " var triggerMap = { 'record_created': 'sn_fd.trigger.record_created', 'record_updated': 'sn_fd.trigger.record_updated', 'scheduled': 'sn_fd.trigger.scheduled' };",
165
+ " var trigIntName = triggerMap[trigType] || '';",
166
+ " if (trigIntName) {",
167
+ " var trigDef = new GlideRecord('sys_hub_action_type_definition');",
168
+ " trigDef.addQuery('internal_name', trigIntName); trigDef.query();",
169
+ " if (trigDef.next()) {",
170
+ " var trigInst = new GlideRecord('sys_hub_trigger_instance');",
171
+ " trigInst.initialize();",
172
+ " trigInst.setValue('flow', flowSysId); trigInst.setValue('action_type', trigDef.getUniqueValue());",
173
+ " trigInst.setValue('name', trigType); trigInst.setValue('order', 0); trigInst.setValue('active', true);",
174
+ " if (trigTable) trigInst.setValue('table', trigTable);",
175
+ " if (trigCondition) trigInst.setValue('condition', trigCondition);",
176
+ " var trigId = trigInst.insert();",
177
+ " r.steps.trigger = { success: !!trigId, sys_id: trigId + '' };",
178
+ " } else { r.steps.trigger = { success: false, error: 'Trigger def not found: ' + trigIntName }; }",
179
+ " }",
180
+ " } catch(te) { r.steps.trigger = { success: false, error: te.getMessage ? te.getMessage() : te + '' }; }",
181
+ " }",
182
+ // Actions
183
+ " var actionsCreated = 0;",
184
+ " for (var ai = 0; ai < activities.length; ai++) {",
185
+ " try {",
186
+ " var act = activities[ai];",
187
+ " var actDef = new GlideRecord('sys_hub_action_type_definition');",
188
+ " actDef.addQuery('internal_name', 'CONTAINS', act.type || 'script');",
189
+ " actDef.addOrCondition('name', 'CONTAINS', act.type || 'script'); actDef.query();",
190
+ " var actInst = new GlideRecord('sys_hub_action_instance');",
191
+ " actInst.initialize();",
192
+ " actInst.setValue('flow', flowSysId); actInst.setValue('name', act.name || 'Action ' + (ai + 1));",
193
+ " actInst.setValue('order', (ai + 1) * 100); actInst.setValue('active', true);",
194
+ " if (actDef.next()) actInst.setValue('action_type', actDef.getUniqueValue());",
195
+ " if (actInst.insert()) actionsCreated++;",
196
+ " } catch(ae) {}",
197
+ " }",
198
+ " r.steps.actions = { success: true, created: actionsCreated, requested: activities.length };",
199
+ // Variables (subflows)
200
+ " var varsCreated = 0;",
201
+ " if (isSubflow) {",
202
+ " for (var vi = 0; vi < inputs.length; vi++) {",
203
+ " try { var inp = inputs[vi]; var fv = new GlideRecord('sys_hub_flow_variable'); fv.initialize();",
204
+ " fv.setValue('flow', flowSysId); fv.setValue('name', inp.name); fv.setValue('label', inp.label || inp.name);",
205
+ " fv.setValue('type', inp.type || 'string'); fv.setValue('mandatory', inp.mandatory || false);",
206
+ " fv.setValue('default_value', inp.default_value || ''); fv.setValue('variable_type', 'input');",
207
+ " if (fv.insert()) varsCreated++;",
208
+ " } catch(ve) {}",
209
+ " }",
210
+ " for (var vo = 0; vo < outputs.length; vo++) {",
211
+ " try { var ot = outputs[vo]; var ov = new GlideRecord('sys_hub_flow_variable'); ov.initialize();",
212
+ " ov.setValue('flow', flowSysId); ov.setValue('name', ot.name); ov.setValue('label', ot.label || ot.name);",
213
+ " ov.setValue('type', ot.type || 'string'); ov.setValue('variable_type', 'output');",
214
+ " if (ov.insert()) varsCreated++;",
215
+ " } catch(ve) {}",
216
+ " }",
217
+ " }",
218
+ " r.steps.variables = { success: true, created: varsCreated };",
219
+ " }",
220
+ "",
144
221
  " r.flow_sys_id = flowSysId ? flowSysId + '' : null;",
145
222
  " r.version_sys_id = verSysId ? verSysId + '' : null;",
146
223
  " if (flowSysId) {",
@@ -1284,7 +1361,15 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
1284
1361
  isSubflow: isSubflow,
1285
1362
  category: flowCategory,
1286
1363
  runAs: flowRunAs,
1287
- shouldActivate: shouldActivate
1364
+ shouldActivate: shouldActivate,
1365
+ triggerType: triggerType,
1366
+ triggerTable: flowTable,
1367
+ triggerCondition: triggerCondition,
1368
+ activities: activitiesArg.map(function (act: any, idx: number) {
1369
+ return { name: act.name, type: act.type || 'script', inputs: act.inputs || {} };
1370
+ }),
1371
+ inputs: inputsArg,
1372
+ outputs: outputsArg
1288
1373
  });
1289
1374
  diagnostics.scheduled_job = {
1290
1375
  success: scheduledResult.success,
@@ -1301,6 +1386,19 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
1301
1386
  diagnostics.version_created = versionCreated;
1302
1387
  diagnostics.version_method = 'scheduled_job';
1303
1388
  diagnostics.latest_version_auto_set = scheduledResult.latestVersionSet;
1389
+ // Extract trigger/action/variable results from scheduled job
1390
+ if (scheduledResult.steps?.trigger) {
1391
+ triggerCreated = !!scheduledResult.steps.trigger.success;
1392
+ if (!scheduledResult.steps.trigger.success && scheduledResult.steps.trigger.error) {
1393
+ factoryWarnings.push('Trigger: ' + scheduledResult.steps.trigger.error);
1394
+ }
1395
+ }
1396
+ if (scheduledResult.steps?.actions) {
1397
+ actionsCreated = scheduledResult.steps.actions.created || 0;
1398
+ }
1399
+ if (scheduledResult.steps?.variables) {
1400
+ varsCreated = scheduledResult.steps.variables.created || 0;
1401
+ }
1304
1402
  }
1305
1403
  } catch (schedErr: any) {
1306
1404
  diagnostics.scheduled_job = { error: schedErr.message || 'unknown' };