@formio/uag-sdk 2.0.0-rc.8 → 2.0.0-rc.9

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.
Files changed (3) hide show
  1. package/loader.d.ts +12 -0
  2. package/loader.js +47 -1
  3. package/package.json +1 -1
package/loader.d.ts CHANGED
@@ -53,3 +53,15 @@ export declare function createEngine(definition: EngineTypeDefinition, options:
53
53
 
54
54
  /** Resolve, configure and create each instance. Any problem stops loading, with the instance named. */
55
55
  export declare function loadEngines(instances: EngineInstanceSpec[], options?: LoadOptions): Promise<LoadedEngine[]>;
56
+
57
+ /** One instance planned but not created: what creating it takes, and how a failure to start reads. */
58
+ export type PlannedEngine = Omit<LoadedEngine, 'engine'> & {
59
+ name: string;
60
+ kinds: ('decision' | 'agent')[];
61
+ definition: EngineTypeDefinition;
62
+ args: { name: string; settings: Record<string, any>; options: Record<string, any>; config: Record<string, any>; requireSetting(key: string): any };
63
+ failure(err: unknown): string;
64
+ };
65
+
66
+ /** Resolve and configure each instance without creating it, for a host that creates engines elsewhere. */
67
+ export declare function planEngines(instances: EngineInstanceSpec[], options?: LoadOptions): PlannedEngine[];
package/loader.js CHANGED
@@ -223,4 +223,50 @@ async function loadEngines(instances, { types = {}, paths = [], env = process.en
223
223
  return loaded;
224
224
  }
225
225
 
226
- module.exports = { enginePaths, packageCandidates, resolveType, createEngine, loadEngines };
226
+ /**
227
+ * Plan the given instances without creating them: resolve each type and its
228
+ * settings, and describe how each is created and how a failure to start reads
229
+ * (with secrets left out). For a host that has engines created elsewhere, such
230
+ * as Agentic Formflow's `startEngines`, which creates and wraps them.
231
+ */
232
+ function planEngines(instances, { types = {}, paths = [], env = process.env, config = {}, apiVersion = ENGINE_API_VERSION } = {}) {
233
+ const resolved = instances.map((instance) => {
234
+ const found = resolveType(instance.type, { types, paths, apiVersion });
235
+ const name = instance.name || found.definition.name;
236
+ checkName(name);
237
+ return { ...found, name, options: instance.options || {} };
238
+ });
239
+ checkUnique(resolved);
240
+ checkVariables(resolved);
241
+ return resolved.map(({ definition, name, options, package: pkg, version }) => {
242
+ const label = `The "${name}" engine (type "${definition.name}")`;
243
+ const settings = resolveSettings(definition, name, options, env);
244
+ const secrets = secretValues(definition, settings, options);
245
+ return {
246
+ name,
247
+ type: definition.name,
248
+ title: definition.title,
249
+ kinds: [...definition.kinds],
250
+ ...(definition.version && { typeVersion: definition.version }),
251
+ ...(pkg && { package: pkg }),
252
+ ...(version && { version }),
253
+ definition,
254
+ args: {
255
+ name,
256
+ settings,
257
+ options,
258
+ config,
259
+ requireSetting: (key) => {
260
+ if (settings[key] === undefined) throw missingSetting(definition, name, key);
261
+ return settings[key];
262
+ },
263
+ },
264
+ failure: (err) => {
265
+ const message = redact(errorText(err), secrets);
266
+ return err instanceof EngineConfigError || (err && err.name === 'EngineConfigError') ? message : `${label} failed to start: ${message}`;
267
+ },
268
+ };
269
+ });
270
+ }
271
+
272
+ module.exports = { enginePaths, packageCandidates, resolveType, createEngine, loadEngines, planEngines };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/uag-sdk",
3
- "version": "2.0.0-rc.8",
3
+ "version": "2.0.0-rc.9",
4
4
  "description": "Build engine packages for the Form.io Universal Agent Gateway (UAG): the engine contract, defineEngine, settings and instance resolution, the engine loader, and a conformance check.",
5
5
  "keywords": [
6
6
  "formio",