@o-lang/olang 1.0.22 → 1.0.23
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 +1 -1
- package/src/runtime.js +33 -18
package/package.json
CHANGED
package/src/runtime.js
CHANGED
|
@@ -244,28 +244,43 @@ class RuntimeAPI {
|
|
|
244
244
|
this.allowedResolvers.add('builtInMathResolver');
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
// Handle different resolver input formats
|
|
248
|
+
let resolversToRun = [];
|
|
249
|
+
|
|
247
250
|
if (agentResolver && Array.isArray(agentResolver._chain)) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
251
|
+
// Resolver chain mode
|
|
252
|
+
resolversToRun = agentResolver._chain;
|
|
253
|
+
} else if (Array.isArray(agentResolver)) {
|
|
254
|
+
// Array of resolvers mode (what npx olang passes with -r flags)
|
|
255
|
+
resolversToRun = agentResolver;
|
|
256
|
+
} else if (agentResolver) {
|
|
257
|
+
// Single resolver mode
|
|
258
|
+
resolversToRun = [agentResolver];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// ✅ Return the FIRST resolver that returns a non-undefined result
|
|
262
|
+
for (let idx = 0; idx < resolversToRun.length; idx++) {
|
|
263
|
+
const resolver = resolversToRun[idx];
|
|
264
|
+
validateResolver(resolver);
|
|
265
|
+
|
|
266
|
+
try {
|
|
267
|
+
const out = await resolver(action, this.context);
|
|
268
|
+
outputs.push(out);
|
|
269
|
+
this.context[`__resolver_${idx}`] = out;
|
|
270
|
+
|
|
271
|
+
// ✅ If resolver handled the action (returned non-undefined), use it immediately
|
|
272
|
+
if (out !== undefined) {
|
|
273
|
+
return out;
|
|
259
274
|
}
|
|
275
|
+
} catch (e) {
|
|
276
|
+
this.addWarning(`Resolver ${resolver?.resolverName || resolver?.name || idx} failed for action "${action}": ${e.message}`);
|
|
277
|
+
outputs.push(null);
|
|
278
|
+
this.context[`__resolver_${idx}`] = null;
|
|
260
279
|
}
|
|
261
|
-
} else {
|
|
262
|
-
validateResolver(agentResolver);
|
|
263
|
-
const out = await agentResolver(action, this.context);
|
|
264
|
-
outputs.push(out);
|
|
265
|
-
this.context['__resolver_0'] = out;
|
|
266
280
|
}
|
|
267
281
|
|
|
268
|
-
|
|
282
|
+
// If no resolver handled the action, return undefined
|
|
283
|
+
return undefined;
|
|
269
284
|
};
|
|
270
285
|
|
|
271
286
|
switch (stepType) {
|
|
@@ -403,7 +418,7 @@ class RuntimeAPI {
|
|
|
403
418
|
const db = this.dbClient.client.db(process.env.DB_NAME || 'olang');
|
|
404
419
|
await db.collection(step.collection).insertOne({
|
|
405
420
|
workflow_name: this.context.workflow_name || 'unknown',
|
|
406
|
-
|
|
421
|
+
data: sourceValue,
|
|
407
422
|
created_at: new Date()
|
|
408
423
|
});
|
|
409
424
|
break;
|