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

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.438",
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,56 @@ 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' },
70
- };
71
-
72
- const config = triggerMap[triggerType] || triggerMap['record_create_or_update'];
73
-
74
- // Trigger definitions live in sys_hub_trigger_definition, keyed by `type` field
65
+ // Dynamically look up trigger definition in sys_hub_trigger_definition
75
66
  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
67
+ let trigName = '';
68
+ let trigType = triggerType;
69
+ let trigCategory = '';
70
+ // Try exact match on type first, then name
71
+ for (const field of ['type', 'name']) {
72
+ if (trigDefId) break;
73
+ try {
74
+ const resp = await client.get('/api/now/table/sys_hub_trigger_definition', {
75
+ params: {
76
+ sysparm_query: field + '=' + triggerType,
77
+ sysparm_fields: 'sys_id,type,name,category',
78
+ sysparm_display_value: 'true',
79
+ sysparm_limit: 1
80
+ }
81
+ });
82
+ const found = resp.data.result?.[0];
83
+ if (found?.sys_id) {
84
+ trigDefId = found.sys_id;
85
+ trigName = found.name || triggerType;
86
+ trigType = found.type || triggerType;
87
+ trigCategory = found.category || '';
88
+ steps.def_lookup = { id: found.sys_id, type: found.type, name: found.name, category: found.category, matched: field + '=' + triggerType };
89
+ }
90
+ } catch (_) {}
91
+ }
92
+ // Fallback: LIKE search on both fields
84
93
  if (!trigDefId) {
85
94
  try {
86
95
  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 }
96
+ params: {
97
+ sysparm_query: 'typeLIKE' + triggerType + '^ORnameLIKE' + triggerType,
98
+ sysparm_fields: 'sys_id,type,name,category',
99
+ sysparm_display_value: 'true',
100
+ sysparm_limit: 5
101
+ }
88
102
  });
89
- trigDefId = resp.data.result?.[0]?.sys_id || null;
90
- steps.def_lookup_fallback = resp.data.result?.[0] || null;
103
+ const results = resp.data.result || [];
104
+ steps.def_lookup_fallback_candidates = results.map((r: any) => ({ sys_id: r.sys_id, type: r.type, name: r.name, category: r.category }));
105
+ if (results[0]?.sys_id) {
106
+ trigDefId = results[0].sys_id;
107
+ trigName = results[0].name || triggerType;
108
+ trigType = results[0].type || triggerType;
109
+ trigCategory = results[0].category || '';
110
+ steps.def_lookup = { id: results[0].sys_id, type: results[0].type, name: results[0].name, category: results[0].category, matched: 'LIKE ' + triggerType };
111
+ }
91
112
  } catch (_) {}
92
113
  }
93
114
  if (!trigDefId) return { success: false, error: 'Trigger definition not found for: ' + triggerType, steps };
94
- steps.def_lookup = { id: trigDefId };
95
115
 
96
116
  const triggerResponseFields = 'triggerInstances { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }';
97
117
  try {
@@ -100,10 +120,10 @@ async function addTriggerViaGraphQL(
100
120
  triggerInstances: {
101
121
  insert: [{
102
122
  flowSysId: flowId,
103
- name: config.name,
104
- triggerType: config.triggerType,
123
+ name: trigName,
124
+ triggerType: trigCategory,
105
125
  triggerDefinitionId: trigDefId,
106
- type: config.type,
126
+ type: trigType,
107
127
  hasDynamicOutputs: false,
108
128
  metadata: '{"predicates":[]}',
109
129
  inputs: [],
@@ -157,35 +177,26 @@ async function addActionViaGraphQL(
157
177
  ): Promise<{ success: boolean; actionId?: string; steps?: any; error?: string }> {
158
178
  const steps: any = {};
159
179
 
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
-
180
+ // Dynamically look up action definition in sys_hub_action_type_snapshot
171
181
  let actionDefId: string | null = null;
172
- const candidates = actionTypeNames[actionType] || [];
173
- for (const name of candidates) {
182
+ // Try exact match on internal_name first, then name
183
+ for (const field of ['internal_name', 'name']) {
184
+ if (actionDefId) break;
174
185
  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 }
186
+ const resp = await client.get('/api/now/table/sys_hub_action_type_snapshot', {
187
+ params: { sysparm_query: field + '=' + actionType, sysparm_fields: 'sys_id,internal_name,name', sysparm_limit: 1 }
177
188
  });
178
189
  const found = resp.data.result?.[0];
179
190
  if (found?.sys_id) {
180
191
  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;
192
+ steps.def_lookup = { id: found.sys_id, internal_name: found.internal_name, name: found.name, matched: field + '=' + actionType };
183
193
  }
184
194
  } catch (_) {}
185
195
  }
196
+ // Fallback: LIKE search on both fields
186
197
  if (!actionDefId) {
187
198
  try {
188
- const resp = await client.get('/api/now/table/sys_hub_action_type_definition', {
199
+ const resp = await client.get('/api/now/table/sys_hub_action_type_snapshot', {
189
200
  params: {
190
201
  sysparm_query: 'internal_nameLIKE' + actionType + '^ORnameLIKE' + actionType,
191
202
  sysparm_fields: 'sys_id,internal_name,name', sysparm_limit: 5
@@ -193,8 +204,10 @@ async function addActionViaGraphQL(
193
204
  });
194
205
  const results = resp.data.result || [];
195
206
  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 };
207
+ if (results[0]?.sys_id) {
208
+ actionDefId = results[0].sys_id;
209
+ steps.def_lookup = { id: results[0].sys_id, internal_name: results[0].internal_name, name: results[0].name, matched: 'LIKE ' + actionType };
210
+ }
198
211
  } catch (_) {}
199
212
  }
200
213
  if (!actionDefId) return { success: false, error: 'Action definition not found for: ' + actionType, steps };