snow-flow 10.0.1-dev.421 → 10.0.1-dev.422

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.421",
3
+ "version": "10.0.1-dev.422",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -411,39 +411,94 @@ async function createFlowViaScheduledJob(
411
411
  " }",
412
412
  " } catch(refE) { r.steps.reference_flow = { error: refE + '' }; }",
413
413
  "",
414
- // ── Engine: try FlowAPI.compile on snapshot and flow ──
415
- " r.steps.engine = { mode: 'compile', sn_fd: typeof sn_fd !== 'undefined' ? 'available' : 'unavailable' };",
414
+ // ── Engine: enumerate FlowAPI methods + try create/save/compile ──
415
+ " r.steps.engine = { mode: 'discover_and_create', sn_fd: typeof sn_fd !== 'undefined' ? 'available' : 'unavailable' };",
416
416
  " if (typeof sn_fd !== 'undefined' && sn_fd.FlowAPI) {",
417
417
  " r.steps.engine.FlowAPI = 'available';",
418
- // Try compile on snapshot first (snapshot extends sys_hub_flow_block)
419
- " if (snapId) {",
420
- " try {",
421
- " var snapCompResult = sn_fd.FlowAPI.compile(snapId);",
422
- " r.steps.engine.compile_snapshot = snapCompResult ? (snapCompResult + '').substring(0, 200) : 'success (null return)';",
423
- " } catch(sce) { r.steps.engine.compile_snapshot = 'error: ' + (sce.getMessage ? sce.getMessage() : sce + ''); }",
418
+ "",
419
+ // Enumerate ALL methods on FlowAPI
420
+ " var apiMethods = [];",
421
+ " try {",
422
+ " for (var mk in sn_fd.FlowAPI) {",
423
+ " if (typeof sn_fd.FlowAPI[mk] === 'function') apiMethods.push(mk);",
424
+ " }",
425
+ " } catch(e) {}",
426
+ // Also try prototype methods
427
+ " try {",
428
+ " var proto = Object.getPrototypeOf ? Object.getPrototypeOf(sn_fd.FlowAPI) : sn_fd.FlowAPI.__proto__;",
429
+ " if (proto) {",
430
+ " for (var pk in proto) {",
431
+ " if (typeof proto[pk] === 'function' && apiMethods.indexOf(pk) === -1) apiMethods.push(pk + '(proto)');",
432
+ " }",
433
+ " }",
434
+ " } catch(e) {}",
435
+ // Try known method names that might exist
436
+ " var knownMethods = ['createFlow', 'createSubflow', 'saveFlow', 'save', 'newFlow', 'designFlow',",
437
+ " 'checkout', 'checkin', 'publish', 'activate', 'deactivate', 'compile', 'getFlow', 'getFlowById',",
438
+ " 'getDesignerModel', 'getDesignerStructure', 'openFlow', 'importFlow', 'createDraftFlow',",
439
+ " 'createVersion', 'publishFlow', 'activateFlow', 'compileFlow', 'getFlowStructure'];",
440
+ " for (var km = 0; km < knownMethods.length; km++) {",
441
+ " if (typeof sn_fd.FlowAPI[knownMethods[km]] === 'function' && apiMethods.indexOf(knownMethods[km]) === -1) {",
442
+ " apiMethods.push(knownMethods[km]);",
443
+ " }",
424
444
  " }",
425
- // Then compile the flow record itself
445
+ " r.steps.engine.all_methods = apiMethods;",
446
+ "",
447
+ // Try createFlow / createSubflow / createDraftFlow if they exist
448
+ " var createMethods = ['createFlow', 'createSubflow', 'createDraftFlow', 'newFlow'];",
449
+ " for (var cm = 0; cm < createMethods.length; cm++) {",
450
+ " if (typeof sn_fd.FlowAPI[createMethods[cm]] === 'function') {",
451
+ " try {",
452
+ " var createResult = sn_fd.FlowAPI[createMethods[cm]](flowName, flowDesc);",
453
+ " var crStr = createResult ? JSON.stringify(createResult).substring(0, 300) : 'null';",
454
+ " r.steps.engine['try_' + createMethods[cm]] = crStr;",
455
+ // If it returned a sys_id, use it as the real flow
456
+ " if (createResult && typeof createResult === 'string' && createResult.length === 32) {",
457
+ " r.steps.engine.engine_created_flow = createResult;",
458
+ " } else if (createResult && createResult.sys_id) {",
459
+ " r.steps.engine.engine_created_flow = createResult.sys_id + '';",
460
+ " }",
461
+ " } catch(cme) { r.steps.engine['try_' + createMethods[cm]] = 'error: ' + (cme.getMessage ? cme.getMessage() : cme + ''); }",
462
+ " }",
463
+ " }",
464
+ "",
465
+ // Try save/checkout/checkin on existing flow
466
+ " if (flowSysId) {",
467
+ " var saveMethods = ['save', 'saveFlow', 'checkout', 'checkin'];",
468
+ " for (var sm = 0; sm < saveMethods.length; sm++) {",
469
+ " if (typeof sn_fd.FlowAPI[saveMethods[sm]] === 'function') {",
470
+ " try {",
471
+ " var saveRes = sn_fd.FlowAPI[saveMethods[sm]](flowSysId);",
472
+ " r.steps.engine['try_' + saveMethods[sm]] = saveRes ? (saveRes + '').substring(0, 200) : 'success (null)';",
473
+ " } catch(se) { r.steps.engine['try_' + saveMethods[sm]] = 'error: ' + (se.getMessage ? se.getMessage() : se + ''); }",
474
+ " }",
475
+ " }",
476
+ " }",
477
+ "",
478
+ // Still try compile on flow (for diagnostics)
426
479
  " if (flowSysId) {",
427
480
  " try {",
428
481
  " var flowCompResult = sn_fd.FlowAPI.compile(flowSysId);",
429
- " r.steps.engine.compile_flow = flowCompResult ? (flowCompResult + '').substring(0, 200) : 'success (null return)';",
482
+ " r.steps.engine.compile_flow = flowCompResult ? (flowCompResult + '').substring(0, 200) : 'success (null)';",
430
483
  " } catch(fce) { r.steps.engine.compile_flow = 'error: ' + (fce.getMessage ? fce.getMessage() : fce + ''); }",
431
484
  " }",
432
- // After compile, re-read snapshot to check if label_cache was populated
433
- " if (snapId) {",
485
+ "",
486
+ // Enumerate other sn_fd top-level objects
487
+ " var snfdKeys = [];",
488
+ " try {",
489
+ " for (var sk in sn_fd) {",
490
+ " snfdKeys.push(sk + ':' + typeof sn_fd[sk]);",
491
+ " }",
492
+ " } catch(e) {}",
493
+ " r.steps.engine.sn_fd_keys = snfdKeys;",
494
+ "",
495
+ // Also check for global FlowDesigner-related objects
496
+ " var globalApis = ['GlideFlowDesigner', 'FlowDesignerService', 'FlowDesignerUtil', 'FlowEngine'];",
497
+ " r.steps.engine.global_apis = {};",
498
+ " for (var ga = 0; ga < globalApis.length; ga++) {",
434
499
  " try {",
435
- " var postSnap = new GlideRecord('sys_hub_flow_snapshot');",
436
- " if (postSnap.get(snapId)) {",
437
- " var lc = postSnap.getValue('label_cache') + '';",
438
- " r.steps.engine.label_cache_after_compile = lc.length > 5 ? lc.substring(0, 100) + '...(len:' + lc.length + ')' : lc;",
439
- " }",
440
- " } catch(e) {}",
441
- " }",
442
- // Try other known APIs
443
- " var otherApis = ['FlowDesigner', 'FlowPublisher', 'FlowCompiler'];",
444
- " r.steps.engine.other_apis = {};",
445
- " for (var oa = 0; oa < otherApis.length; oa++) {",
446
- " r.steps.engine.other_apis[otherApis[oa]] = typeof sn_fd[otherApis[oa]] !== 'undefined' ? 'available' : 'unavailable';",
500
+ " r.steps.engine.global_apis[globalApis[ga]] = eval('typeof ' + globalApis[ga]) !== 'undefined' ? 'available' : 'unavailable';",
501
+ " } catch(e) { r.steps.engine.global_apis[globalApis[ga]] = 'unavailable'; }",
447
502
  " }",
448
503
  " } else {",
449
504
  " r.steps.engine.FlowAPI = 'unavailable';",
@@ -1879,17 +1934,28 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
1879
1934
  createSummary.indented('Version created: ' + diagnostics.version_created + (diagnostics.version_method ? ' (' + diagnostics.version_method + ')' : ''));
1880
1935
  if (diagnostics.engine_registration) {
1881
1936
  var eng = diagnostics.engine_registration;
1882
- if (eng.mode === 'compile') {
1883
- // New compile mode (scheduled job path)
1937
+ if (eng.mode === 'discover_and_create') {
1938
+ // Discovery mode show all FlowAPI methods found
1939
+ createSummary.indented('Engine (discover): sn_fd=' + eng.sn_fd + ', FlowAPI=' + (eng.FlowAPI || 'unknown'));
1940
+ if (eng.all_methods) createSummary.indented(' FlowAPI methods: [' + eng.all_methods.join(', ') + ']');
1941
+ if (eng.sn_fd_keys) createSummary.indented(' sn_fd keys: [' + eng.sn_fd_keys.join(', ') + ']');
1942
+ // Show any create/save attempts
1943
+ var tryKeys = Object.keys(eng).filter(function(k: string) { return k.indexOf('try_') === 0; });
1944
+ for (var tk = 0; tk < tryKeys.length; tk++) {
1945
+ createSummary.indented(' ' + tryKeys[tk] + ': ' + eng[tryKeys[tk]]);
1946
+ }
1947
+ if (eng.engine_created_flow) createSummary.indented(' ENGINE CREATED FLOW: ' + eng.engine_created_flow);
1948
+ if (eng.compile_flow) createSummary.indented(' compile(flow): ' + eng.compile_flow);
1949
+ if (eng.global_apis) {
1950
+ var gaList = Object.keys(eng.global_apis).map(function(k: string) { return k + '=' + eng.global_apis[k]; }).join(', ');
1951
+ createSummary.indented(' Global APIs: ' + gaList);
1952
+ }
1953
+ } else if (eng.mode === 'compile') {
1884
1954
  var engineLabel = 'sn_fd=' + eng.sn_fd + ', FlowAPI=' + (eng.FlowAPI || 'unknown');
1885
1955
  if (eng.compile_snapshot) engineLabel += ', compile(snapshot)=' + eng.compile_snapshot;
1886
1956
  if (eng.compile_flow) engineLabel += ', compile(flow)=' + eng.compile_flow;
1887
1957
  if (eng.label_cache_after_compile) engineLabel += ', label_cache=' + eng.label_cache_after_compile;
1888
1958
  createSummary.indented('Engine (compile): ' + engineLabel);
1889
- if (eng.other_apis) {
1890
- var apiList = Object.keys(eng.other_apis).map(function(k: string) { return k + '=' + eng.other_apis[k]; }).join(', ');
1891
- createSummary.indented(' Other APIs: ' + apiList);
1892
- }
1893
1959
  } else if (eng.sn_fd) {
1894
1960
  // Legacy probe-only mode (from scheduled job)
1895
1961
  var legacyLabel = 'sn_fd=' + eng.sn_fd;