snow-flow 10.0.1-dev.404 → 10.0.1-dev.405

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.404",
3
+ "version": "10.0.1-dev.405",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -165,7 +165,7 @@ async function createFlowViaScheduledJob(
165
165
  "",
166
166
  // ── Trigger, action, variable creation (runs for any tier) ──
167
167
  " if (flowSysId) {",
168
- // Trigger — search broadly for trigger definition (internal_name varies per instance)
168
+ // Trigger — search broadly (no type filter, internal_name varies per instance)
169
169
  " if (!isSubflow && trigType !== 'manual') {",
170
170
  " try {",
171
171
  " var trigSearchTerms = {",
@@ -177,21 +177,55 @@ async function createFlowViaScheduledJob(
177
177
  " var trigDef = null;",
178
178
  " var trigDefId = null;",
179
179
  " var trigSearchLog = [];",
180
+ // Search 1: CONTAINS on internal_name (NO type filter — 'type' column values vary)
180
181
  " for (var ts = 0; ts < terms.length; ts++) {",
181
182
  " var tg = new GlideRecord('sys_hub_action_type_definition');",
182
183
  " tg.addQuery('internal_name', 'CONTAINS', terms[ts]);",
183
- " tg.addQuery('type', 'trigger');",
184
- " tg.setLimit(1); tg.query();",
185
- " if (tg.next()) { trigDef = tg; trigDefId = tg.getUniqueValue(); trigSearchLog.push(terms[ts] + ':found'); break; }",
186
- " trigSearchLog.push(terms[ts] + ':not_found');",
184
+ " tg.setLimit(5); tg.query();",
185
+ " while (tg.next()) {",
186
+ " var tgType = tg.getValue('type') + '';",
187
+ " var tgName = tg.getValue('internal_name') + '';",
188
+ " trigSearchLog.push(terms[ts] + ':' + tgName + '(type=' + tgType + ')');",
189
+ " if (!trigDefId) { trigDef = tg; trigDefId = tg.getUniqueValue(); }",
190
+ " }",
191
+ " if (trigDefId) break;",
187
192
  " }",
193
+ // Search 2: by display name (no type filter)
188
194
  " if (!trigDefId) {",
189
195
  " var tg2 = new GlideRecord('sys_hub_action_type_definition');",
190
196
  " tg2.addQuery('name', 'CONTAINS', trigType.replace('_', ' '));",
191
- " tg2.addQuery('type', 'trigger');",
192
- " tg2.setLimit(1); tg2.query();",
193
- " if (tg2.next()) { trigDef = tg2; trigDefId = tg2.getUniqueValue(); trigSearchLog.push('name_search:found'); }",
194
- " else { trigSearchLog.push('name_search:not_found'); }",
197
+ " tg2.setLimit(5); tg2.query();",
198
+ " while (tg2.next()) {",
199
+ " var tg2Type = tg2.getValue('type') + '';",
200
+ " var tg2Name = tg2.getValue('internal_name') + '';",
201
+ " trigSearchLog.push('name:' + tg2Name + '(type=' + tg2Type + ')');",
202
+ " if (!trigDefId) { trigDef = tg2; trigDefId = tg2.getUniqueValue(); }",
203
+ " }",
204
+ " }",
205
+ // Search 3: sys_hub_trigger_definition table (alternative on some instances)
206
+ " if (!trigDefId) {",
207
+ " try {",
208
+ " var tg3 = new GlideRecord('sys_hub_trigger_definition');",
209
+ " if (tg3.isValid()) {",
210
+ " tg3.addQuery('internal_name', 'CONTAINS', terms[0]);",
211
+ " tg3.setLimit(3); tg3.query();",
212
+ " while (tg3.next()) {",
213
+ " trigSearchLog.push('trig_def_table:' + tg3.getValue('internal_name'));",
214
+ " if (!trigDefId) { trigDef = tg3; trigDefId = tg3.getUniqueValue(); }",
215
+ " }",
216
+ " } else { trigSearchLog.push('trig_def_table:invalid'); }",
217
+ " } catch(e3) { trigSearchLog.push('trig_def_table:error'); }",
218
+ " }",
219
+ // Discovery: log what type values exist (helps debug trigger issues)
220
+ " if (!trigDefId) {",
221
+ " try {",
222
+ " var disc = new GlideAggregate('sys_hub_action_type_definition');",
223
+ " disc.addAggregate('COUNT', 'type');",
224
+ " disc.groupBy('type'); disc.query();",
225
+ " var typeValues = [];",
226
+ " while (disc.next()) { typeValues.push(disc.getValue('type') + ':' + disc.getAggregate('COUNT', 'type')); }",
227
+ " trigSearchLog.push('type_values:[' + typeValues.join(',') + ']');",
228
+ " } catch(de) { trigSearchLog.push('discovery:error'); }",
195
229
  " }",
196
230
  " if (trigDefId) {",
197
231
  " var trigInst = new GlideRecord('sys_hub_trigger_instance');",
@@ -201,9 +235,9 @@ async function createFlowViaScheduledJob(
201
235
  " if (trigTable) trigInst.setValue('table', trigTable);",
202
236
  " if (trigCondition) trigInst.setValue('condition', trigCondition);",
203
237
  " var trigId = trigInst.insert();",
204
- " r.steps.trigger = { success: !!trigId, sys_id: trigId + '', def_name: trigDef.getValue('name'), search: trigSearchLog };",
238
+ " r.steps.trigger = { success: !!trigId, sys_id: trigId + '', def_name: trigDef.getValue('name'), def_internal: trigDef.getValue('internal_name'), search: trigSearchLog };",
205
239
  " } else {",
206
- " r.steps.trigger = { success: false, error: 'No trigger def found', search: trigSearchLog };",
240
+ " r.steps.trigger = { success: false, error: 'No trigger def found after broad search', search: trigSearchLog };",
207
241
  " }",
208
242
  " } catch(te) { r.steps.trigger = { success: false, error: te.getMessage ? te.getMessage() : te + '' }; }",
209
243
  " }",
@@ -245,11 +279,11 @@ async function createFlowViaScheduledJob(
245
279
  " }",
246
280
  " r.steps.variables = { success: true, created: varsCreated };",
247
281
  "",
248
- // ── Engine probe (discovery only do NOT call publish/compile) ──
249
- // Previous versions called FlowAPI.publish() which caused StackOverflowError
250
- // and corrupted the flow. Now we only probe which APIs exist for diagnostics.
251
- // The flow is left as a clean draft; user publishes via Flow Designer UI.
252
- " r.steps.engine = { apis_found: [], mode: 'probe_only' };",
282
+ // ── Engine: probe APIs + try compile (NOT publish — that StackOverflowed) ──
283
+ // FlowAPI.publish() caused StackOverflowError and corrupted the flow.
284
+ // FlowAPI.compile() should be safer it registers the flow with the
285
+ // engine and sets latest_version without the publish side effects.
286
+ " r.steps.engine = { apis_found: [], mode: 'probe_and_compile' };",
253
287
  " try {",
254
288
  " if (typeof sn_fd !== 'undefined') {",
255
289
  " r.steps.engine.sn_fd = 'available';",
@@ -268,6 +302,24 @@ async function createFlowViaScheduledJob(
268
302
  " }",
269
303
  " } catch(e) {}",
270
304
  " }",
305
+ // Try compile (safe) — DO NOT try publish (StackOverflowError)
306
+ " var compiled = false;",
307
+ // Priority 1: FlowDesigner.compileFlow (most specific)
308
+ " if (!compiled && sn_fd.FlowDesigner && typeof sn_fd.FlowDesigner.compileFlow === 'function') {",
309
+ " try { sn_fd.FlowDesigner.compileFlow(flowSysId); r.steps.engine.compile = 'FlowDesigner.compileFlow:success'; compiled = true; }",
310
+ " catch(e) { r.steps.engine.compile = 'FlowDesigner.compileFlow:' + (e.getMessage ? e.getMessage() : e + ''); }",
311
+ " }",
312
+ // Priority 2: FlowCompiler.compile
313
+ " if (!compiled && sn_fd.FlowCompiler && typeof sn_fd.FlowCompiler.compile === 'function') {",
314
+ " try { sn_fd.FlowCompiler.compile(flowSysId); r.steps.engine.compile = 'FlowCompiler.compile:success'; compiled = true; }",
315
+ " catch(e) { r.steps.engine.compile = 'FlowCompiler.compile:' + (e.getMessage ? e.getMessage() : e + ''); }",
316
+ " }",
317
+ // Priority 3: FlowAPI.compile (available on this instance per diagnostics)
318
+ " if (!compiled && sn_fd.FlowAPI && typeof sn_fd.FlowAPI.compile === 'function') {",
319
+ " try { sn_fd.FlowAPI.compile(flowSysId); r.steps.engine.compile = 'FlowAPI.compile:success'; compiled = true; }",
320
+ " catch(e) { r.steps.engine.compile = 'FlowAPI.compile:' + (e.getMessage ? e.getMessage() : e + ''); }",
321
+ " }",
322
+ " r.steps.engine.compiled = compiled;",
271
323
  " } else {",
272
324
  " r.steps.engine.sn_fd = 'unavailable';",
273
325
  " }",