snow-flow 10.0.1-dev.399 → 10.0.1-dev.400

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.399",
3
+ "version": "10.0.1-dev.400",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -1102,34 +1102,72 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
1102
1102
  flowSysId = createdFlow.sys_id;
1103
1103
 
1104
1104
  // Create sys_hub_flow_version via Table API (critical for Flow Designer UI)
1105
+ // Strategy: INSERT as draft → UPDATE to published/compiled
1106
+ // The UPDATE triggers Business Rules that compile the flow and set latest_version
1105
1107
  try {
1106
- var versionData: any = {
1108
+ // Step 1: INSERT version as DRAFT (minimal fields)
1109
+ var versionInsertData: any = {
1107
1110
  flow: flowSysId,
1108
1111
  name: '1.0',
1109
1112
  version: '1.0',
1110
- state: shouldActivate ? 'published' : 'draft',
1111
- active: true,
1112
- compile_state: 'compiled',
1113
- is_current: true,
1114
- flow_definition: JSON.stringify(flowDefinition)
1113
+ state: 'draft',
1114
+ active: false,
1115
+ compile_state: 'draft',
1116
+ is_current: false,
1117
+ internal_name: sanitizeInternalName(flowName) + '_v1_0'
1115
1118
  };
1116
- if (shouldActivate) versionData.published_flow = flowSysId;
1117
- var versionResp = await client.post('/api/now/table/sys_hub_flow_version', versionData);
1119
+ var versionResp = await client.post('/api/now/table/sys_hub_flow_version', versionInsertData);
1118
1120
  var versionSysId = versionResp.data.result?.sys_id;
1121
+
1119
1122
  if (versionSysId) {
1123
+ // Step 2: UPDATE version → triggers compilation Business Rules
1124
+ var versionUpdateData: any = {
1125
+ state: shouldActivate ? 'published' : 'draft',
1126
+ active: true,
1127
+ compile_state: 'compiled',
1128
+ is_current: true,
1129
+ flow_definition: JSON.stringify(flowDefinition)
1130
+ };
1131
+ if (shouldActivate) versionUpdateData.published_flow = flowSysId;
1132
+ try {
1133
+ await client.patch('/api/now/table/sys_hub_flow_version/' + versionSysId, versionUpdateData);
1134
+ } catch (updateErr: any) {
1135
+ diagnostics.version_update_error = updateErr.message || 'unknown';
1136
+ }
1137
+
1120
1138
  versionCreated = true;
1121
1139
  diagnostics.version_created = true;
1122
- diagnostics.version_method = 'table_api';
1123
- diagnostics.version_fields_set = ['flow', 'name', 'version', 'state', 'active', 'compile_state', 'is_current', 'published_flow'];
1124
- // Link flow to its version
1140
+ diagnostics.version_method = 'table_api (draft→update)';
1141
+ diagnostics.version_fields_set = ['flow', 'name', 'version', 'state', 'active', 'compile_state', 'is_current', 'published_flow', 'internal_name'];
1142
+
1143
+ // Step 3: Check if BRs auto-set latest_version on the flow
1144
+ await new Promise(resolve => setTimeout(resolve, 1000));
1125
1145
  try {
1126
- await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, {
1127
- latest_version: versionSysId
1146
+ var flowCheck = await client.get('/api/now/table/sys_hub_flow/' + flowSysId, {
1147
+ params: { sysparm_fields: 'latest_version', sysparm_display_value: 'false' }
1128
1148
  });
1129
- } catch (linkError) {
1130
- // Version exists but link failed — still better than no version
1131
- factoryWarnings.push('Version created but latest_version link failed');
1132
- }
1149
+ var autoLinked = !!(flowCheck.data.result?.latest_version);
1150
+ diagnostics.latest_version_auto_set = autoLinked;
1151
+
1152
+ // Step 4: If BRs didn't set it, explicitly PATCH + verify
1153
+ if (!autoLinked) {
1154
+ try {
1155
+ var linkResp = await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, {
1156
+ latest_version: versionSysId,
1157
+ latest_published_version: shouldActivate ? versionSysId : undefined
1158
+ });
1159
+ diagnostics.latest_version_patch_status = linkResp.status;
1160
+ // Immediate readback
1161
+ var readback = await client.get('/api/now/table/sys_hub_flow/' + flowSysId, {
1162
+ params: { sysparm_fields: 'latest_version', sysparm_display_value: 'false' }
1163
+ });
1164
+ diagnostics.latest_version_after_patch = readback.data.result?.latest_version || 'null';
1165
+ } catch (linkError: any) {
1166
+ diagnostics.latest_version_patch_error = linkError.message || 'unknown';
1167
+ factoryWarnings.push('latest_version link failed: ' + (linkError.message || linkError));
1168
+ }
1169
+ }
1170
+ } catch (_) {}
1133
1171
  }
1134
1172
  } catch (verError: any) {
1135
1173
  factoryWarnings.push('sys_hub_flow_version creation failed: ' + (verError.message || verError));
@@ -1259,16 +1297,20 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
1259
1297
  if (flowSysId) {
1260
1298
  try {
1261
1299
  var verifyResp = await client.get('/api/now/table/sys_hub_flow/' + flowSysId, {
1262
- params: { sysparm_fields: 'sys_id,name,latest_version' }
1300
+ params: {
1301
+ sysparm_fields: 'sys_id,name,latest_version,latest_published_version,internal_name',
1302
+ sysparm_display_value: 'false'
1303
+ }
1263
1304
  });
1264
1305
  var verifyFlow = verifyResp.data.result;
1265
- var hasLatestVersion = !!(verifyFlow && verifyFlow.latest_version);
1306
+ var latestVersionVal = verifyFlow?.latest_version || null;
1307
+ var hasLatestVersion = !!latestVersionVal;
1266
1308
 
1267
- // Check if version record exists
1309
+ // Check version record details
1268
1310
  var verCheckResp = await client.get('/api/now/table/sys_hub_flow_version', {
1269
1311
  params: {
1270
1312
  sysparm_query: 'flow=' + flowSysId,
1271
- sysparm_fields: 'sys_id,name,state,compile_state,is_current',
1313
+ sysparm_fields: 'sys_id,name,state,compile_state,is_current,active,internal_name',
1272
1314
  sysparm_limit: 1
1273
1315
  }
1274
1316
  });
@@ -1277,44 +1319,35 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
1277
1319
 
1278
1320
  diagnostics.post_verify = {
1279
1321
  flow_exists: true,
1322
+ flow_internal_name: verifyFlow?.internal_name || 'not set',
1323
+ latest_version_value: latestVersionVal || 'null',
1324
+ latest_published_version: verifyFlow?.latest_published_version || 'null',
1280
1325
  has_latest_version_ref: hasLatestVersion,
1281
1326
  version_record_exists: hasVersionRecord,
1282
1327
  version_details: hasVersionRecord ? {
1283
1328
  sys_id: verRecords[0].sys_id,
1284
1329
  state: verRecords[0].state,
1285
1330
  compile_state: verRecords[0].compile_state,
1286
- is_current: verRecords[0].is_current
1331
+ is_current: verRecords[0].is_current,
1332
+ active: verRecords[0].active,
1333
+ internal_name: verRecords[0].internal_name || 'not set'
1287
1334
  } : null
1288
1335
  };
1289
1336
 
1290
- // If version record is missing, retry creation
1291
- if (!hasVersionRecord && !versionCreated) {
1337
+ // If latest_version still not set and version exists, try one more time
1338
+ if (!hasLatestVersion && hasVersionRecord) {
1292
1339
  try {
1293
- var retryVersionData: any = {
1294
- flow: flowSysId,
1295
- name: '1.0',
1296
- version: '1.0',
1297
- state: shouldActivate ? 'published' : 'draft',
1298
- active: true,
1299
- compile_state: 'compiled',
1300
- is_current: true,
1301
- flow_definition: JSON.stringify(flowDefinition)
1302
- };
1303
- if (shouldActivate) retryVersionData.published_flow = flowSysId;
1304
-
1305
- var retryVerResp = await client.post('/api/now/table/sys_hub_flow_version', retryVersionData);
1306
- var retryVerSysId = retryVerResp.data.result?.sys_id;
1307
- if (retryVerSysId) {
1308
- versionCreated = true;
1309
- diagnostics.version_created = true;
1310
- diagnostics.version_method = (diagnostics.version_method || 'table_api') + ' (retry)';
1311
- try {
1312
- await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, { latest_version: retryVerSysId });
1313
- } catch (_) {}
1314
- factoryWarnings.push('Version record was missing — created via post-verify retry');
1315
- }
1316
- } catch (retryErr: any) {
1317
- factoryWarnings.push('Post-verify version retry failed: ' + (retryErr.message || retryErr));
1340
+ await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, {
1341
+ latest_version: verRecords[0].sys_id,
1342
+ latest_published_version: shouldActivate ? verRecords[0].sys_id : undefined
1343
+ });
1344
+ // Readback
1345
+ var finalCheck = await client.get('/api/now/table/sys_hub_flow/' + flowSysId, {
1346
+ params: { sysparm_fields: 'latest_version', sysparm_display_value: 'false' }
1347
+ });
1348
+ diagnostics.post_verify.latest_version_final = finalCheck.data.result?.latest_version || 'still null';
1349
+ } catch (finalLinkErr: any) {
1350
+ diagnostics.post_verify.latest_version_final_error = finalLinkErr.message || 'unknown';
1318
1351
  }
1319
1352
  }
1320
1353
  } catch (verifyErr: any) {