snow-flow 10.0.1-dev.435 → 10.0.1-dev.439

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.435",
3
+ "version": "10.0.1-dev.439",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -62,36 +62,63 @@ async function addTriggerViaGraphQL(
62
62
  ): Promise<{ success: boolean; triggerId?: string; steps?: any; error?: string }> {
63
63
  const steps: any = {};
64
64
 
65
- const triggerMap: Record<string, { type: string; name: string; triggerType: string }> = {
66
- 'record_created': { type: 'record_create', name: 'Created', triggerType: 'Record' },
67
- 'record_updated': { type: 'record_update', name: 'Updated', triggerType: 'Record' },
68
- 'record_create_or_update': { type: 'record_create_or_update', name: 'Created or Updated', triggerType: 'Record' },
69
- 'scheduled': { type: 'scheduled', name: 'Scheduled', triggerType: 'Scheduled' },
65
+ // Dynamically look up trigger definition in sys_hub_trigger_definition
66
+ let trigDefId: string | null = null;
67
+ let trigName = '';
68
+ let trigType = triggerType;
69
+ let trigCategory = '';
70
+
71
+ // Build search variations: record_updated → also try record_update, and vice versa
72
+ const variations = [triggerType];
73
+ if (triggerType.endsWith('ed')) variations.push(triggerType.slice(0, -1), triggerType.slice(0, -2));
74
+ else if (triggerType.endsWith('e')) variations.push(triggerType + 'd');
75
+ else variations.push(triggerType + 'ed', triggerType + 'd');
76
+
77
+ const assignFound = (found: any, matched: string) => {
78
+ trigDefId = found.sys_id;
79
+ trigName = found.name || triggerType;
80
+ trigType = found.type || triggerType;
81
+ trigCategory = found.category || '';
82
+ steps.def_lookup = { id: found.sys_id, type: found.type, name: found.name, category: found.category, matched };
70
83
  };
71
84
 
72
- const config = triggerMap[triggerType] || triggerMap['record_create_or_update'];
73
-
74
- // Trigger definitions live in sys_hub_trigger_definition, keyed by `type` field
75
- let trigDefId: string | null = null;
76
- try {
77
- const resp = await client.get('/api/now/table/sys_hub_trigger_definition', {
78
- params: { sysparm_query: 'type=' + config.type, sysparm_fields: 'sys_id,type,name', sysparm_limit: 1 }
79
- });
80
- trigDefId = resp.data.result?.[0]?.sys_id || null;
81
- steps.def_lookup_primary = resp.data.result?.[0] || null;
82
- } catch (_) {}
83
- // Fallback: search by name
85
+ // Try exact match on type and name for each variation
86
+ for (const variant of variations) {
87
+ if (trigDefId) break;
88
+ for (const field of ['type', 'name']) {
89
+ if (trigDefId) break;
90
+ try {
91
+ const resp = await client.get('/api/now/table/sys_hub_trigger_definition', {
92
+ params: {
93
+ sysparm_query: field + '=' + variant,
94
+ sysparm_fields: 'sys_id,type,name,category',
95
+ sysparm_display_value: 'true',
96
+ sysparm_limit: 1
97
+ }
98
+ });
99
+ const found = resp.data.result?.[0];
100
+ if (found?.sys_id) assignFound(found, field + '=' + variant);
101
+ } catch (_) {}
102
+ }
103
+ }
104
+ // Fallback: LIKE search using shortest variation (most likely to match)
84
105
  if (!trigDefId) {
106
+ const shortest = variations.reduce((a, b) => a.length <= b.length ? a : b);
85
107
  try {
86
108
  const resp = await client.get('/api/now/table/sys_hub_trigger_definition', {
87
- params: { sysparm_query: 'name=' + config.name, sysparm_fields: 'sys_id,type,name', sysparm_limit: 1 }
109
+ params: {
110
+ sysparm_query: 'typeLIKE' + shortest + '^ORnameLIKE' + shortest,
111
+ sysparm_fields: 'sys_id,type,name,category',
112
+ sysparm_display_value: 'true',
113
+ sysparm_limit: 5
114
+ }
88
115
  });
89
- trigDefId = resp.data.result?.[0]?.sys_id || null;
90
- steps.def_lookup_fallback = resp.data.result?.[0] || null;
116
+ const results = resp.data.result || [];
117
+ steps.def_lookup_fallback_candidates = results.map((r: any) => ({ sys_id: r.sys_id, type: r.type, name: r.name, category: r.category }));
118
+ if (results[0]?.sys_id) assignFound(results[0], 'LIKE ' + shortest);
91
119
  } catch (_) {}
92
120
  }
93
121
  if (!trigDefId) return { success: false, error: 'Trigger definition not found for: ' + triggerType, steps };
94
- steps.def_lookup = { id: trigDefId };
95
122
 
96
123
  const triggerResponseFields = 'triggerInstances { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }';
97
124
  try {
@@ -100,10 +127,10 @@ async function addTriggerViaGraphQL(
100
127
  triggerInstances: {
101
128
  insert: [{
102
129
  flowSysId: flowId,
103
- name: config.name,
104
- triggerType: config.triggerType,
130
+ name: trigName,
131
+ triggerType: trigCategory,
105
132
  triggerDefinitionId: trigDefId,
106
- type: config.type,
133
+ type: trigType,
107
134
  hasDynamicOutputs: false,
108
135
  metadata: '{"predicates":[]}',
109
136
  inputs: [],
@@ -157,35 +184,26 @@ async function addActionViaGraphQL(
157
184
  ): Promise<{ success: boolean; actionId?: string; steps?: any; error?: string }> {
158
185
  const steps: any = {};
159
186
 
160
- const actionTypeNames: Record<string, string[]> = {
161
- 'log': ['sn_fd.action.log', 'global.sn_fd.action.log', 'global.log'],
162
- 'create_record': ['sn_fd.action.create_record', 'global.sn_fd.action.create_record'],
163
- 'update_record': ['sn_fd.action.update_record', 'global.sn_fd.action.update_record'],
164
- 'notification': ['sn_fd.action.send_notification', 'global.sn_fd.action.send_notification'],
165
- 'script': ['sn_fd.action.script', 'global.sn_fd.action.script', 'global.script_action'],
166
- 'field_update': ['sn_fd.action.field_update', 'global.sn_fd.action.field_update'],
167
- 'wait': ['sn_fd.action.wait', 'global.sn_fd.action.wait'],
168
- 'approval': ['sn_fd.action.create_approval', 'global.sn_fd.action.create_approval'],
169
- };
170
-
187
+ // Dynamically look up action definition in sys_hub_action_type_snapshot
171
188
  let actionDefId: string | null = null;
172
- const candidates = actionTypeNames[actionType] || [];
173
- for (const name of candidates) {
189
+ // Try exact match on internal_name first, then name
190
+ for (const field of ['internal_name', 'name']) {
191
+ if (actionDefId) break;
174
192
  try {
175
- const resp = await client.get('/api/now/table/sys_hub_action_type_definition', {
176
- params: { sysparm_query: 'internal_name=' + name, sysparm_fields: 'sys_id,internal_name,name', sysparm_limit: 1 }
193
+ const resp = await client.get('/api/now/table/sys_hub_action_type_snapshot', {
194
+ params: { sysparm_query: field + '=' + actionType, sysparm_fields: 'sys_id,internal_name,name', sysparm_limit: 1 }
177
195
  });
178
196
  const found = resp.data.result?.[0];
179
197
  if (found?.sys_id) {
180
198
  actionDefId = found.sys_id;
181
- steps.def_lookup = { id: found.sys_id, internal_name: found.internal_name, name: found.name, matched_query: name };
182
- break;
199
+ steps.def_lookup = { id: found.sys_id, internal_name: found.internal_name, name: found.name, matched: field + '=' + actionType };
183
200
  }
184
201
  } catch (_) {}
185
202
  }
203
+ // Fallback: LIKE search on both fields
186
204
  if (!actionDefId) {
187
205
  try {
188
- const resp = await client.get('/api/now/table/sys_hub_action_type_definition', {
206
+ const resp = await client.get('/api/now/table/sys_hub_action_type_snapshot', {
189
207
  params: {
190
208
  sysparm_query: 'internal_nameLIKE' + actionType + '^ORnameLIKE' + actionType,
191
209
  sysparm_fields: 'sys_id,internal_name,name', sysparm_limit: 5
@@ -193,8 +211,10 @@ async function addActionViaGraphQL(
193
211
  });
194
212
  const results = resp.data.result || [];
195
213
  steps.def_lookup_fallback_candidates = results.map((r: any) => ({ sys_id: r.sys_id, internal_name: r.internal_name, name: r.name }));
196
- actionDefId = results[0]?.sys_id || null;
197
- if (actionDefId) steps.def_lookup = { id: actionDefId, internal_name: results[0].internal_name, name: results[0].name, matched_query: 'LIKE ' + actionType };
214
+ if (results[0]?.sys_id) {
215
+ actionDefId = results[0].sys_id;
216
+ steps.def_lookup = { id: results[0].sys_id, internal_name: results[0].internal_name, name: results[0].name, matched: 'LIKE ' + actionType };
217
+ }
198
218
  } catch (_) {}
199
219
  }
200
220
  if (!actionDefId) return { success: false, error: 'Action definition not found for: ' + actionType, steps };