snow-flow 10.0.1-dev.431 → 10.0.1-dev.433

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.431",
3
+ "version": "10.0.1-dev.433",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -53,103 +53,6 @@ async function executeFlowPatchMutation(
53
53
  return resp.data?.data?.global?.snFlowDesigner?.flow || resp.data;
54
54
  }
55
55
 
56
- async function lookupDefinitionParams(client: any, defSysId: string): Promise<any[]> {
57
- const queries = [
58
- { table: 'sys_hub_action_type_param', query: 'action_type=' + defSysId },
59
- { table: 'sys_hub_action_type_param', query: 'model=' + defSysId },
60
- { table: 'sys_hub_action_input_param', query: 'action_type=' + defSysId },
61
- { table: 'sys_hub_action_input_param', query: 'model=' + defSysId },
62
- ];
63
- const fields = 'sys_id,name,element,label,internal_type,type,type_label,order,mandatory,readonly,maxsize,data_structure,reference,reference_display,ref_qual,choice_option,column_name,default_value,use_dependent,dependent_on,internal_link,attributes,sys_class_name';
64
- for (const q of queries) {
65
- try {
66
- const resp = await client.get('/api/now/table/' + q.table, {
67
- params: { sysparm_query: q.query, sysparm_fields: fields, sysparm_display_value: 'false', sysparm_limit: 50 }
68
- });
69
- const raw = resp.data.result || [];
70
- if (raw.length === 0) continue;
71
- const seen = new Set<string>();
72
- const unique: any[] = [];
73
- for (const r of raw) {
74
- const id = r.sys_id || '';
75
- if (id === defSysId) continue;
76
- if (id && seen.has(id)) continue;
77
- const name = r.name || r.element || '';
78
- if (!name) continue;
79
- seen.add(id);
80
- unique.push(r);
81
- }
82
- if (unique.length > 0) return unique;
83
- } catch (_) {}
84
- }
85
- return [];
86
- }
87
-
88
- function str(v: any): string {
89
- if (!v) return '';
90
- if (typeof v === 'string') return v;
91
- if (typeof v === 'object' && v.value !== undefined) return String(v.value);
92
- return String(v);
93
- }
94
-
95
- function buildGraphQLInput(p: any, defaultValue?: any, forTrigger?: boolean): any {
96
- const name = str(p.name) || str(p.element) || '';
97
- const type = str(p.internal_type) || str(p.type) || 'string';
98
- const isMandatory = p.mandatory === 'true' || p.mandatory === true;
99
- const order = parseInt(str(p.order)) || 100;
100
- const defVal = defaultValue !== undefined ? defaultValue : (str(p.default_value) || '');
101
- const valueObj = type === 'conditions'
102
- ? { schemaless: false, schemalessValue: '', value: '^EQ' }
103
- : defVal
104
- ? { schemaless: false, schemalessValue: '', value: String(defVal) }
105
- : { value: '' };
106
- const parameter: any = {
107
- id: str(p.sys_id) || '',
108
- label: str(p.label) || name,
109
- name,
110
- type,
111
- type_label: str(p.type_label) || '',
112
- hint: '',
113
- order,
114
- extended: false,
115
- mandatory: isMandatory,
116
- readonly: p.readonly === 'true' || p.readonly === true,
117
- maxsize: parseInt(str(p.maxsize)) || 80,
118
- data_structure: str(p.data_structure) || '',
119
- reference: str(p.reference) || '',
120
- reference_display: str(p.reference_display) || '',
121
- ref_qual: str(p.ref_qual) || '',
122
- choiceOption: str(p.choice_option) || '',
123
- table: '',
124
- columnName: str(p.column_name) || '',
125
- defaultValue: str(p.default_value) || '',
126
- use_dependent: p.use_dependent === 'true' || p.use_dependent === true,
127
- dependent_on: str(p.dependent_on) || '',
128
- show_ref_finder: false,
129
- local: false,
130
- attributes: str(p.attributes) || '',
131
- sys_class_name: str(p.sys_class_name) || '',
132
- children: []
133
- };
134
- if (!forTrigger) {
135
- parameter.dynamic = null;
136
- } else {
137
- parameter.internal_link = p.internal_link || '';
138
- }
139
-
140
- if (forTrigger) {
141
- return {
142
- name, label: str(p.label) || name, internalType: type, mandatory: isMandatory,
143
- order, valueSysId: '', field_name: name, type,
144
- children: [], displayValue: { value: '' }, value: valueObj, parameter
145
- };
146
- }
147
- return {
148
- id: str(p.sys_id) || '', name,
149
- children: [], displayValue: { value: '' }, value: valueObj, parameter
150
- };
151
- }
152
-
153
56
  async function addTriggerViaGraphQL(
154
57
  client: any,
155
58
  flowId: string,
@@ -192,31 +95,35 @@ async function addTriggerViaGraphQL(
192
95
  try {
193
96
  const resp = await client.get('/api/now/table/' + defTable, {
194
97
  params: {
195
- sysparm_query: 'internal_nameLIKE' + config.type + '^ORnameLIKE' + config.name,
196
- sysparm_fields: 'sys_id,internal_name', sysparm_limit: 10
98
+ sysparm_query: 'internal_nameLIKEsn_fd.trigger.' + config.type,
99
+ sysparm_fields: 'sys_id,internal_name,name', sysparm_limit: 10
197
100
  }
198
101
  });
199
102
  for (const r of (resp.data.result || [])) {
200
- if ((r.internal_name || '').indexOf(config.type) > -1) { trigDefId = r.sys_id; break; }
103
+ const iname = r.internal_name || '';
104
+ if (iname.indexOf('trigger') > -1 && iname.indexOf(config.type) > -1) { trigDefId = r.sys_id; break; }
201
105
  }
202
106
  } catch (_) {}
203
107
  }
204
108
  }
109
+ if (!trigDefId) {
110
+ try {
111
+ const resp = await client.get('/api/now/table/sys_hub_action_type_definition', {
112
+ params: {
113
+ sysparm_query: 'internal_nameLIKEtrigger^internal_nameLIKE' + config.type,
114
+ sysparm_fields: 'sys_id,internal_name,name', sysparm_limit: 10
115
+ }
116
+ });
117
+ steps.fallback_candidates = (resp.data.result || []).map((r: any) => ({ sys_id: r.sys_id, internal_name: r.internal_name, name: r.name }));
118
+ for (const r of (resp.data.result || [])) {
119
+ const iname = r.internal_name || '';
120
+ if (iname.indexOf(config.type) > -1) { trigDefId = r.sys_id; break; }
121
+ }
122
+ } catch (_) {}
123
+ }
205
124
  if (!trigDefId) return { success: false, error: 'Trigger definition not found for: ' + triggerType, steps };
206
125
  steps.def_lookup = { id: trigDefId };
207
126
 
208
- const params = await lookupDefinitionParams(client, trigDefId);
209
- steps.params_found = params.length;
210
-
211
- const gqlInputs = params.map((p: any) => buildGraphQLInput(p, undefined, true));
212
-
213
- if (gqlInputs.length === 0 && config.triggerType === 'Record') {
214
- gqlInputs.push(
215
- buildGraphQLInput({ name: 'table', label: 'Table', internal_type: 'table_name', mandatory: 'true', order: '1' }, undefined, true),
216
- buildGraphQLInput({ name: 'condition', label: 'Condition', internal_type: 'conditions', mandatory: 'false', order: '100', use_dependent: 'true', dependent_on: 'table' }, undefined, true)
217
- );
218
- }
219
-
220
127
  const triggerResponseFields = 'triggerInstances { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }';
221
128
  try {
222
129
  const insertResult = await executeFlowPatchMutation(client, {
@@ -230,7 +137,7 @@ async function addTriggerViaGraphQL(
230
137
  type: config.type,
231
138
  hasDynamicOutputs: false,
232
139
  metadata: '{"predicates":[]}',
233
- inputs: gqlInputs,
140
+ inputs: [],
234
141
  outputs: []
235
142
  }]
236
143
  }
@@ -317,16 +224,6 @@ async function addActionViaGraphQL(
317
224
  if (!actionDefId) return { success: false, error: 'Action definition not found for: ' + actionType, steps };
318
225
  steps.def_lookup = { id: actionDefId };
319
226
 
320
- const params = await lookupDefinitionParams(client, actionDefId);
321
- steps.params_found = params.length;
322
- steps.params_detail = params.map((p: any) => ({ sys_id: p.sys_id, name: p.name || p.element, type: str(p.internal_type) || str(p.type) }));
323
-
324
- const gqlInputs = params.map((p: any) => {
325
- const pName = p.name || p.element || '';
326
- const providedValue = inputs?.[pName];
327
- return buildGraphQLInput(p, providedValue);
328
- });
329
-
330
227
  const uuid = generateUUID();
331
228
  const actionResponseFields = 'actions { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }';
332
229
  try {
@@ -343,7 +240,7 @@ async function addActionViaGraphQL(
343
240
  uiUniqueIdentifier: uuid,
344
241
  type: 'action',
345
242
  parentUiId: '',
346
- inputs: gqlInputs
243
+ inputs: []
347
244
  }]
348
245
  }
349
246
  }, actionResponseFields);