snow-flow 10.0.1-dev.409 → 10.0.1-dev.411

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.409",
3
+ "version": "10.0.1-dev.411",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -280,37 +280,70 @@ async function createFlowViaScheduledJob(
280
280
  " }",
281
281
  " r.steps.variables = { success: true, created: varsCreated };",
282
282
  "",
283
- // ── Engine: PROBE ONLY do NOT call compile or publish ──
284
- // FlowAPI.publish() StackOverflowError (corrupts flow)
285
- // FlowAPI.compile() → "success" but doesn't set latest_version, may corrupt
286
- // Just probe what APIs exist for diagnostics.
287
- " r.steps.engine = { apis_found: [], mode: 'probe_only' };",
283
+ // ── Reference: query an existing published flow to see what it looks like ──
284
+ " r.steps.reference_flow = null;",
285
+ " try {",
286
+ " var refGr = new GlideRecord('sys_hub_flow');",
287
+ " refGr.addQuery('status', 'published');",
288
+ " refGr.addQuery('active', true);",
289
+ " refGr.setLimit(1); refGr.query();",
290
+ " if (refGr.next()) {",
291
+ " var refId = refGr.getUniqueValue();",
292
+ " var refFd = refGr.getValue('flow_definition') + '';",
293
+ " var refLs = refGr.getValue('latest_snapshot') + '';",
294
+ " var refLv = refGr.getValue('latest_version') + '';",
295
+ " r.steps.reference_flow = {",
296
+ " sys_id: refId,",
297
+ " name: refGr.getValue('name'),",
298
+ " has_flow_definition: refFd !== 'null' && refFd.length > 0,",
299
+ " flow_definition_length: refFd.length,",
300
+ " flow_definition_prefix: refFd.substring(0, 200),",
301
+ " has_latest_snapshot: refLs !== 'null' && refLs.length > 0,",
302
+ " latest_snapshot_length: refLs.length,",
303
+ " latest_version: refLv,",
304
+ " has_latest_version: refLv !== 'null' && refLv.length > 5",
305
+ " };",
306
+ // Also read the version record of the reference flow
307
+ " if (refLv !== 'null' && refLv.length > 5) {",
308
+ " var refVer = new GlideRecord('sys_hub_flow_version');",
309
+ " if (refVer.get(refLv)) {",
310
+ " var refVFd = refVer.getValue('flow_definition') + '';",
311
+ " r.steps.reference_flow.version_state = refVer.getValue('state');",
312
+ " r.steps.reference_flow.version_compile_state = refVer.getValue('compile_state');",
313
+ " r.steps.reference_flow.version_is_current = refVer.getValue('is_current');",
314
+ " r.steps.reference_flow.version_active = refVer.getValue('active');",
315
+ " r.steps.reference_flow.version_has_flow_def = refVFd !== 'null' && refVFd.length > 0;",
316
+ " r.steps.reference_flow.version_flow_def_length = refVFd.length;",
317
+ " r.steps.reference_flow.version_flow_def_prefix = refVFd.substring(0, 200);",
318
+ " }",
319
+ " }",
320
+ " }",
321
+ " } catch(refE) { r.steps.reference_flow = { error: refE + '' }; }",
322
+ "",
323
+ // ── Engine: try FlowAPI.compile() now that flow_definition is set ──
324
+ // DO NOT try publish (StackOverflowError). Only compile.
325
+ " r.steps.engine = { apis_found: [], mode: 'compile_with_flowdef' };",
288
326
  " try {",
289
327
  " if (typeof sn_fd !== 'undefined') {",
290
328
  " r.steps.engine.sn_fd = 'available';",
291
- " var probeNames = ['FlowDesigner', 'FlowCompiler', 'FlowAPI', 'FlowPublisher'];",
292
- " for (var pn = 0; pn < probeNames.length; pn++) {",
329
+ " if (sn_fd.FlowAPI && typeof sn_fd.FlowAPI.compile === 'function') {",
330
+ " r.steps.engine.apis_found.push('FlowAPI');",
293
331
  " try {",
294
- " if (sn_fd[probeNames[pn]]) {",
295
- " r.steps.engine.apis_found.push(probeNames[pn]);",
296
- " var methods = [];",
297
- " var pObj = sn_fd[probeNames[pn]];",
298
- " var checkMethods = ['createFlow','publishFlow','activateFlow','compileFlow','compile','publish','getFlow'];",
299
- " for (var cm = 0; cm < checkMethods.length; cm++) {",
300
- " if (typeof pObj[checkMethods[cm]] === 'function') methods.push(checkMethods[cm]);",
301
- " }",
302
- " if (methods.length > 0) r.steps.engine[probeNames[pn] + '_methods'] = methods;",
303
- " }",
304
- " } catch(e) {}",
332
+ " var compileResult = sn_fd.FlowAPI.compile(flowSysId);",
333
+ " r.steps.engine.compile = 'success';",
334
+ " r.steps.engine.compile_result = (compileResult + '').substring(0, 200);",
335
+ " } catch(ce) {",
336
+ " r.steps.engine.compile = 'error:' + (ce.getMessage ? ce.getMessage() : ce + '');",
337
+ " }",
338
+ // Check latest_version immediately after compile
339
+ " var postCompile = new GlideRecord('sys_hub_flow');",
340
+ " if (postCompile.get(flowSysId)) {",
341
+ " r.steps.engine.latest_version_after_compile = postCompile.getValue('latest_version') + '';",
342
+ " }",
305
343
  " }",
306
344
  " } else {",
307
345
  " r.steps.engine.sn_fd = 'unavailable';",
308
346
  " }",
309
- " try {",
310
- " if (typeof GlideFlowDesigner !== 'undefined') {",
311
- " r.steps.engine.apis_found.push('GlideFlowDesigner');",
312
- " }",
313
- " } catch(e) {}",
314
347
  " } catch(engineErr) {",
315
348
  " r.steps.engine.error = engineErr.getMessage ? engineErr.getMessage() : engineErr + '';",
316
349
  " }",
@@ -318,12 +351,17 @@ async function createFlowViaScheduledJob(
318
351
  "",
319
352
  " r.flow_sys_id = flowSysId ? flowSysId + '' : null;",
320
353
  " r.version_sys_id = verSysId ? verSysId + '' : null;",
321
- // ── Post-engine check: re-read latest_version ──
354
+ // ── Final check: re-read latest_version + compare our flow to reference ──
322
355
  " if (flowSysId) {",
323
356
  " var cf = new GlideRecord('sys_hub_flow');",
324
357
  " if (cf.get(flowSysId)) {",
325
358
  " r.latest_version_set = !cf.latest_version.nil();",
326
359
  " r.latest_version_value = cf.getValue('latest_version') + '';",
360
+ // Also read our flow_definition to verify it was stored
361
+ " var ourFd = cf.getValue('flow_definition') + '';",
362
+ " r.our_flow_definition_stored = ourFd !== 'null' && ourFd.length > 0;",
363
+ " r.our_flow_definition_length = ourFd.length;",
364
+ " r.our_flow_definition_prefix = ourFd.substring(0, 200);",
327
365
  " }",
328
366
  " }",
329
367
  " } catch(e) { r.success = false; r.error = e.getMessage ? e.getMessage() : e + ''; }",
@@ -1634,11 +1672,11 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
1634
1672
 
1635
1673
  }
1636
1674
 
1637
- // ── Register flow with Flow Designer engine (Table API only) ──
1638
- // For scheduled job path, engine registration is done server-side
1639
- // inside the job script (via sn_fd APIs). Only call the external
1640
- // REST-based registration for the Table API fallback path.
1641
- if (flowSysId && usedMethod.startsWith('table_api')) {
1675
+ // ── Register flow with Flow Designer engine ──
1676
+ // Call the REST API (publish/activate/checkout+checkin/snapshot) to
1677
+ // trigger engine compilation and set latest_version (computed field
1678
+ // that cannot be set via GlideRecord or Table API PATCH).
1679
+ if (flowSysId) {
1642
1680
  var engineResult = await registerFlowWithEngine(client, flowSysId, shouldActivate);
1643
1681
  diagnostics.engine_registration = {
1644
1682
  success: engineResult.success,