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

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.407",
3
+ "version": "10.0.1-dev.409",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -123,7 +123,10 @@ async function createFlowViaScheduledJob(
123
123
  " }",
124
124
  " } catch(t1e) { r.steps.tier1 = { success: false, error: t1e.getMessage ? t1e.getMessage() : t1e + '' }; }",
125
125
  "",
126
- // ── TIER 2: GlideRecord with flow_definition ──
126
+ // ── TIER 2: GlideRecord ──
127
+ // Set flow_definition + latest_snapshot on flow record.
128
+ // Set flow_definition on version record.
129
+ // Force-set latest_version with setWorkflow(false) to bypass BRs.
127
130
  " if (!flowSysId) {",
128
131
  " try {",
129
132
  " var f = new GlideRecord('sys_hub_flow');",
@@ -135,7 +138,7 @@ async function createFlowViaScheduledJob(
135
138
  " f.setValue('type', isSubflow ? 'subflow' : 'flow');",
136
139
  " if (flowDefStr) { f.setValue('flow_definition', flowDefStr); f.setValue('latest_snapshot', flowDefStr); }",
137
140
  " flowSysId = f.insert();",
138
- " r.steps.flow_insert = { success: !!flowSysId, sys_id: flowSysId + '' };",
141
+ " r.steps.flow_insert = { success: !!flowSysId, sys_id: flowSysId + '', flow_def_set: !!flowDefStr };",
139
142
  " if (flowSysId) {",
140
143
  " var v = new GlideRecord('sys_hub_flow_version');",
141
144
  " v.initialize();",
@@ -143,19 +146,29 @@ async function createFlowViaScheduledJob(
143
146
  " v.setValue('version', '1.0'); v.setValue('state', 'draft');",
144
147
  " v.setValue('active', true); v.setValue('compile_state', 'draft');",
145
148
  " v.setValue('is_current', true);",
146
- " if (flowDefStr) v.setValue('flow_definition', flowDefStr);",
149
+ " v.setValue('internal_name', intName + '_v1_0');",
150
+ " if (flowDefStr) { v.setValue('flow_definition', flowDefStr); }",
147
151
  " verSysId = v.insert();",
148
- " r.steps.version_insert = { success: !!verSysId, sys_id: verSysId + '' };",
152
+ " r.steps.version_insert = { success: !!verSysId, sys_id: verSysId + '', has_flow_def: !!flowDefStr };",
153
+ "",
154
+ // Force-set latest_version — bypass BRs with setWorkflow(false)
149
155
  " if (verSysId) {",
150
- " var lk = new GlideRecord('sys_hub_flow');",
151
- " if (lk.get(flowSysId)) { lk.setValue('latest_version', verSysId); lk.update(); }",
152
- " }",
153
- " if (activate) {",
154
- " var fp = new GlideRecord('sys_hub_flow');",
155
- " if (fp.get(flowSysId)) { fp.setValue('status', 'published'); fp.setValue('active', true); fp.update(); }",
156
- " if (verSysId) {",
157
- " var vp = new GlideRecord('sys_hub_flow_version');",
158
- " if (vp.get(verSysId)) { vp.setValue('state', 'published'); vp.setValue('compile_state', 'compiled'); vp.setValue('published_flow', flowSysId); vp.update(); }",
156
+ " try {",
157
+ " var flowUpd = new GlideRecord('sys_hub_flow');",
158
+ " flowUpd.setWorkflow(false);",
159
+ " flowUpd.autoSysFields(false);",
160
+ " if (flowUpd.get(flowSysId)) {",
161
+ " flowUpd.setValue('latest_version', verSysId);",
162
+ " flowUpd.update();",
163
+ " r.steps.latest_version_force = 'attempted';",
164
+ " }",
165
+ " } catch(lvE) { r.steps.latest_version_force = 'error:' + (lvE.getMessage ? lvE.getMessage() : lvE + ''); }",
166
+ // Verify latest_version was set
167
+ " var lvCheck = new GlideRecord('sys_hub_flow');",
168
+ " if (lvCheck.get(flowSysId)) {",
169
+ " var lvVal = lvCheck.getValue('latest_version');",
170
+ " r.steps.latest_version_after_force = lvVal + '';",
171
+ " r.steps.latest_version_success = (lvVal === verSysId + '');",
159
172
  " }",
160
173
  " }",
161
174
  " r.tier_used = 'gliderecord_scheduled'; r.success = true;",
@@ -206,23 +219,10 @@ async function createFlowViaScheduledJob(
206
219
  " trigSearchLog.push('prefix_sn_fd.trigger:[' + prefixMatches.join(',') + ']');",
207
220
  " }",
208
221
  "",
209
- // Search 3: sys_hub_trigger_definition table
210
- " if (!trigDefId) {",
211
- " try {",
212
- " var tg3 = new GlideRecord('sys_hub_trigger_definition');",
213
- " if (tg3.isValid()) {",
214
- " tg3.addQuery('internal_name', 'CONTAINS', trigType);",
215
- " tg3.setLimit(5); tg3.query();",
216
- " while (tg3.next()) {",
217
- " var t3n = tg3.getValue('internal_name') + '';",
218
- " trigSearchLog.push('trigger_def:' + t3n);",
219
- " if (!trigDefId) { trigDefId = tg3.getUniqueValue(); trigDefName = tg3.getValue('name'); }",
220
- " }",
221
- " } else { trigSearchLog.push('trigger_def_table:not_valid'); }",
222
- " } catch(e3) { trigSearchLog.push('trigger_def_table:' + e3); }",
223
- " }",
222
+ // Search 3 removed — sys_hub_trigger_definition returned wrong defs (Proactive Analytics, DevOps)
223
+ " if (!trigDefId) { trigSearchLog.push('no_exact_trigger_def_found'); }",
224
224
  "",
225
- // Create trigger instance
225
+ // Create trigger instance — only set action_type if exact sn_fd.trigger.* match found
226
226
  " var trigInst = new GlideRecord('sys_hub_trigger_instance');",
227
227
  " trigInst.initialize();",
228
228
  " trigInst.setValue('flow', flowSysId);",
@@ -280,11 +280,11 @@ async function createFlowViaScheduledJob(
280
280
  " }",
281
281
  " r.steps.variables = { success: true, created: varsCreated };",
282
282
  "",
283
- // ── Engine: probe APIs + try compile (NOT publish that StackOverflowed) ──
284
- // FlowAPI.publish() caused StackOverflowError and corrupted the flow.
285
- // FlowAPI.compile() should be safer it registers the flow with the
286
- // engine and sets latest_version without the publish side effects.
287
- " r.steps.engine = { apis_found: [], mode: 'probe_and_compile' };",
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' };",
288
288
  " try {",
289
289
  " if (typeof sn_fd !== 'undefined') {",
290
290
  " r.steps.engine.sn_fd = 'available';",
@@ -303,24 +303,6 @@ async function createFlowViaScheduledJob(
303
303
  " }",
304
304
  " } catch(e) {}",
305
305
  " }",
306
- // Try compile (safe) — DO NOT try publish (StackOverflowError)
307
- " var compiled = false;",
308
- // Priority 1: FlowDesigner.compileFlow (most specific)
309
- " if (!compiled && sn_fd.FlowDesigner && typeof sn_fd.FlowDesigner.compileFlow === 'function') {",
310
- " try { sn_fd.FlowDesigner.compileFlow(flowSysId); r.steps.engine.compile = 'FlowDesigner.compileFlow:success'; compiled = true; }",
311
- " catch(e) { r.steps.engine.compile = 'FlowDesigner.compileFlow:' + (e.getMessage ? e.getMessage() : e + ''); }",
312
- " }",
313
- // Priority 2: FlowCompiler.compile
314
- " if (!compiled && sn_fd.FlowCompiler && typeof sn_fd.FlowCompiler.compile === 'function') {",
315
- " try { sn_fd.FlowCompiler.compile(flowSysId); r.steps.engine.compile = 'FlowCompiler.compile:success'; compiled = true; }",
316
- " catch(e) { r.steps.engine.compile = 'FlowCompiler.compile:' + (e.getMessage ? e.getMessage() : e + ''); }",
317
- " }",
318
- // Priority 3: FlowAPI.compile (available on this instance per diagnostics)
319
- " if (!compiled && sn_fd.FlowAPI && typeof sn_fd.FlowAPI.compile === 'function') {",
320
- " try { sn_fd.FlowAPI.compile(flowSysId); r.steps.engine.compile = 'FlowAPI.compile:success'; compiled = true; }",
321
- " catch(e) { r.steps.engine.compile = 'FlowAPI.compile:' + (e.getMessage ? e.getMessage() : e + ''); }",
322
- " }",
323
- " r.steps.engine.compiled = compiled;",
324
306
  " } else {",
325
307
  " r.steps.engine.sn_fd = 'unavailable';",
326
308
  " }",