@uipath/maestro-builder-sdk 6.108.0 → 6.110.0

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.
@@ -0,0 +1,253 @@
1
+ import { CompileRefusal } from '../../../core/compile-refusal.js';
2
+ import { nearestName } from '../../../core/edit-distance.js';
3
+ import { blank } from '../../../core/process-resource.js';
4
+ import { PROCESS_KIND, resolveRecordedResource, resourceLedgerKey, resourcePrepareCommand, resourceRowIsFresh, } from '../../../core/resource-resolution.js';
5
+ /** The vocabulary `returns` takes (`ReturnFieldType`). */
6
+ const RETURN_TYPES = new Set(['string', 'number', 'integer', 'boolean', 'object', 'array']);
7
+ /**
8
+ * The ledger reference a published process step names: kind `Process`, its
9
+ * `name`, and its `folderPath` as the folder. Undefined for an in-solution step,
10
+ * or one missing either, which has nothing to look up.
11
+ */
12
+ export function processRef(inputs) {
13
+ const s = (inputs ?? {});
14
+ // A step named by `project` is a sibling in the solution (#1978), read from its files.
15
+ if (s.location === 'in-solution' || s.project !== undefined)
16
+ return undefined;
17
+ if (typeof s.name !== 'string' || blank(s.name) || typeof s.folderPath !== 'string' || blank(s.folderPath))
18
+ return undefined;
19
+ return { kind: PROCESS_KIND, name: s.name, folder: s.folderPath };
20
+ }
21
+ /**
22
+ * The row `prepare` recorded for a published process step, however old:
23
+ * what the fill-in reads. A release key does not change while the process
24
+ * exists, so a source that leaves `key` out still compiles offline the next
25
+ * day, in CI or on another box; `check` warns that the row is old
26
+ * (`PROCESS_RECORD_STALE`) and stops validating against it.
27
+ */
28
+ function anyRecordedProcess(inputs, resources) {
29
+ const ref = processRef(inputs);
30
+ if (ref === undefined || resources === undefined)
31
+ return undefined;
32
+ const key = resourceLedgerKey(ref);
33
+ return Object.hasOwn(resources, key) ? resources[key] : undefined;
34
+ }
35
+ /** A JSON Schema's `properties`, or `{}`. */
36
+ function propertiesOf(schema) {
37
+ const p = schema?.properties;
38
+ return typeof p === 'object' && p !== null && !Array.isArray(p) ? p : {};
39
+ }
40
+ /** A property's JSON Schema types: `['integer']`, `['string', 'null']`; `[]` for an untyped one. */
41
+ function typesOf(property) {
42
+ const t = property?.type;
43
+ if (typeof t === 'string')
44
+ return [t];
45
+ return Array.isArray(t) ? t.filter((x) => typeof x === 'string') : [];
46
+ }
47
+ /** A recorded output property as a `returns` type: its first type `returns` can say, else `object`/`array` by shape, else `string`. */
48
+ function returnTypeOf(property) {
49
+ const known = typesOf(property).find((t) => RETURN_TYPES.has(t));
50
+ if (known !== undefined)
51
+ return known;
52
+ if (property?.properties !== undefined)
53
+ return 'object';
54
+ if (property?.items !== undefined)
55
+ return 'array';
56
+ return 'string';
57
+ }
58
+ /**
59
+ * The `returns` a recorded output schema declares, or undefined when it
60
+ * declares no field.
61
+ *
62
+ * @example
63
+ * recordedReturns({ type: 'object', properties: { EstimatedAge: { type: 'integer' } } }) // { EstimatedAge: 'integer' }
64
+ */
65
+ export function recordedReturns(output) {
66
+ const properties = propertiesOf(output);
67
+ const names = Object.keys(properties);
68
+ return names.length === 0 ? undefined : Object.fromEntries(names.map((n) => [n, returnTypeOf(properties[n])]));
69
+ }
70
+ /**
71
+ * The step's inputs with what `prepare` recorded filled in: a blank `key` from
72
+ * the row, and an omitted `returns` from its output schema when that side was
73
+ * recorded (not for a fire-and-forget dispatch, which publishes no output).
74
+ * Anything the author wrote is kept. A row of any age is used, so the same
75
+ * source and ledger compile the same `.flow`; without a row, the inputs as
76
+ * they are.
77
+ */
78
+ export function withRecordedProcess(inputs, resources) {
79
+ const row = anyRecordedProcess(inputs, resources);
80
+ if (row === undefined)
81
+ return inputs;
82
+ const s = inputs;
83
+ const key = blank(s.key) && row.key !== null ? row.key : undefined;
84
+ const returns = s.returns === undefined && s.completion !== 'fire-and-forget' && row.schema?.output !== undefined
85
+ ? recordedReturns(row.schema.output)
86
+ : undefined;
87
+ if (key === undefined && returns === undefined)
88
+ return inputs;
89
+ return { ...inputs, ...(key !== undefined ? { key } : {}), ...(returns !== undefined ? { returns } : {}) };
90
+ }
91
+ /**
92
+ * Why a published step with no key has none, naming the `prepare` command that
93
+ * records it — a missing row and an old one read differently
94
+ * (`resolveRecordedResource`'s wording). Undefined when the step names no
95
+ * process to look up (no name or folder, or in-solution), or its row is usable.
96
+ *
97
+ * @example
98
+ * unrecordedKeyReason({ name: 'NameToAgeFixed', folderPath: 'Shared' }, undefined)
99
+ * // 'process "NameToAgeFixed" in folder "Shared" is not resolved. … registry prepare --kind Process --name NameToAgeFixed --folder-path Shared'
100
+ */
101
+ export function unrecordedKeyReason(inputs, resources) {
102
+ const ref = processRef(inputs);
103
+ if (ref === undefined)
104
+ return undefined;
105
+ try {
106
+ resolveRecordedResource(ref, resources);
107
+ return undefined;
108
+ }
109
+ catch (error) {
110
+ if (error instanceof CompileRefusal)
111
+ return error.message;
112
+ throw error;
113
+ }
114
+ }
115
+ /**
116
+ * The sentence a `*_READ_WITHOUT_RETURNS` message ends with for a published
117
+ * step: the `prepare` command that records the output schema compile then
118
+ * writes. `''` when the step names no process to record.
119
+ */
120
+ export function returnsFromTenantHint(inputs) {
121
+ const ref = processRef(inputs);
122
+ return ref === undefined ? '' : ` Or record the process (\`${resourcePrepareCommand(ref)}\`) and leave \`returns\` out: compile writes the output schema when Orchestrator has one (it prints \`Outputs\`).`;
123
+ }
124
+ /** True for a value written as a plain JSON literal (not an expression or other object). */
125
+ function isLiteral(v) {
126
+ if (v === null || typeof v !== 'object')
127
+ return true;
128
+ if (Array.isArray(v))
129
+ return true;
130
+ return Object.getPrototypeOf(v) === Object.prototype;
131
+ }
132
+ /** Whether a literal fits a JSON Schema type list; an untyped property takes anything. */
133
+ function literalFits(v, types) {
134
+ if (types.length === 0 || v === null || v === undefined)
135
+ return true;
136
+ return types.some((t) => {
137
+ switch (t) {
138
+ case 'string': return typeof v === 'string';
139
+ case 'number': return typeof v === 'number';
140
+ case 'integer': return typeof v === 'number' && Number.isInteger(v);
141
+ case 'boolean': return typeof v === 'boolean';
142
+ case 'array': return Array.isArray(v);
143
+ case 'object': return typeof v === 'object' && !Array.isArray(v);
144
+ case 'null': return false;
145
+ default: return true; // a type this check does not know is not a mismatch
146
+ }
147
+ });
148
+ }
149
+ /** A literal's JSON type, for a message. */
150
+ function literalType(v) {
151
+ if (Array.isArray(v))
152
+ return 'array';
153
+ if (typeof v === 'number')
154
+ return Number.isInteger(v) ? 'integer' : 'number';
155
+ return typeof v;
156
+ }
157
+ /**
158
+ * Check a published process step against its recorded row: the key, the
159
+ * factory (`subType`, the binding subtype the step would be written with, is
160
+ * the `ProcessType` it starts), the inputs and the declared `returns`. A step
161
+ * with no fresh row is not checked here.
162
+ *
163
+ * @param inputs - The step's inputs as the author wrote them (not filled in).
164
+ * @param subType - The `resourceSubType` the step's definition carries, e.g. `'Api'`.
165
+ * @param label - How a message names the step's kind, e.g. `'API workflow'`.
166
+ */
167
+ export function checkRecordedProcess(inputs, ctx, subType, label) {
168
+ const any = anyRecordedProcess(inputs, ctx.options.resources);
169
+ if (any === undefined)
170
+ return;
171
+ const s = inputs;
172
+ const step = ctx.step;
173
+ const where = `${label} step "${step}" (process ${JSON.stringify(any.name)} in ${JSON.stringify(any.folderPath)})`;
174
+ if (!resourceRowIsFresh(any)) {
175
+ ctx.report('PROCESS_RECORD_STALE', `${where} was recorded ${any.resolvedAt !== undefined ? `at ${any.resolvedAt}, more than 24 hours ago` : 'with no resolvedAt'}. `
176
+ + 'Compile still takes the key and returns from it, but check no longer validates the step against it, '
177
+ + 'because the process may have been republished since. Record it again:\n'
178
+ + ` ${resourcePrepareCommand(processRef(inputs))}`);
179
+ return;
180
+ }
181
+ const row = any;
182
+ if (!blank(s.key) && row.key !== null && String(s.key).trim().toLowerCase() !== row.key.toLowerCase()) {
183
+ ctx.report('PROCESS_KEY_MISMATCH', `${where} has key ${JSON.stringify(s.key)}, but prepare recorded ${JSON.stringify(row.key)} for that name and folder. `
184
+ + `The node type would name a different release than the one the runtime starts by name. `
185
+ + `Use the recorded key, or leave \`key\` out and compile writes it.`, `key: '${row.key}'`);
186
+ }
187
+ if (row.processType !== undefined && row.processType !== subType) {
188
+ ctx.report('PROCESS_TYPE_MISMATCH', `${where} is a ${JSON.stringify(row.processType)} process on the tenant, but this factory starts a `
189
+ + `${JSON.stringify(subType)} one. The node would dispatch through the wrong service. Use the factory for a `
190
+ + `${row.processType} process (\`uip maestro flow registry search\` shows its node type).`);
191
+ }
192
+ const schema = row.schema;
193
+ if (schema === undefined)
194
+ return;
195
+ // Inputs: every name the process declares, the ones it requires, and each
196
+ // literal's type. A side Orchestrator left blank is unknown: nothing to check.
197
+ if (schema.input !== undefined)
198
+ checkInputs(s, schema.input, where, ctx);
199
+ if (schema.output !== undefined)
200
+ checkReturns(s, schema.output, where, ctx);
201
+ }
202
+ /** The step's inputs against a recorded input schema. */
203
+ function checkInputs(s, input, where, ctx) {
204
+ const declared = propertiesOf(input);
205
+ const names = Object.keys(declared);
206
+ const passed = typeof s.inputs === 'object' && s.inputs !== null && !Array.isArray(s.inputs) ? s.inputs : {};
207
+ const open = input.additionalProperties === true;
208
+ for (const [name, value] of Object.entries(passed)) {
209
+ const property = Object.hasOwn(declared, name) ? declared[name] : undefined;
210
+ if (property === undefined) {
211
+ if (open)
212
+ continue;
213
+ const near = names.find((n) => n.toLowerCase() === name.toLowerCase()) ?? nearestName(name, names);
214
+ ctx.report('PROCESS_INPUT_UNKNOWN', `${where} passes input ${JSON.stringify(name)}, which the process does not declare. `
215
+ + (names.length > 0 ? `Its input arguments: ${names.join(', ')}.` : 'It declares no input arguments.')
216
+ + ' The argument would not reach the process.', near !== undefined ? `inputs: { ${near}: … }` : undefined);
217
+ continue;
218
+ }
219
+ const types = typesOf(property);
220
+ if (isLiteral(value) && !literalFits(value, types)) {
221
+ ctx.report('PROCESS_INPUT_TYPE', `${where} passes ${JSON.stringify(value)} (${literalType(value)}) for input ${JSON.stringify(name)}, `
222
+ + `which the process declares as ${types.join(' | ')}. The job would start with an argument of the wrong type.`);
223
+ }
224
+ }
225
+ const required = Array.isArray(input.required) ? input.required.filter((r) => typeof r === 'string') : [];
226
+ const missing = required.filter((r) => !Object.hasOwn(passed, r));
227
+ if (missing.length > 0) {
228
+ ctx.report('PROCESS_INPUT_MISSING', `${where} does not pass the required input(s) ${missing.map((m) => JSON.stringify(m)).join(', ')}. `
229
+ + 'The process declares them required, so the job would start without them.', `inputs: { ${missing.map((m) => `${m}: …`).join(', ')} }`);
230
+ }
231
+ }
232
+ /** The step's declared `returns` against a recorded output schema. Omitted returns are filled in, so there is nothing to compare. */
233
+ function checkReturns(s, output, where, ctx) {
234
+ if (typeof s.returns !== 'object' || s.returns === null)
235
+ return;
236
+ const outputs = propertiesOf(output);
237
+ const outputNames = Object.keys(outputs);
238
+ for (const [field, type] of Object.entries(s.returns)) {
239
+ const property = Object.hasOwn(outputs, field) ? outputs[field] : undefined;
240
+ if (property === undefined) {
241
+ const near = outputNames.find((n) => n.toLowerCase() === field.toLowerCase()) ?? nearestName(field, outputNames);
242
+ ctx.report('PROCESS_RETURNS_UNKNOWN', `${where} declares output ${JSON.stringify(field)} in \`returns\`, which the process does not return. `
243
+ + (outputNames.length > 0 ? `Its output arguments: ${outputNames.join(', ')}.` : 'It declares no output arguments.')
244
+ + ' A read of it is undefined at run time. Fix the name, or leave `returns` out and compile writes the recorded ones.', near !== undefined ? `returns: { ${near}: '${returnTypeOf(outputs[near])}' }` : undefined);
245
+ continue;
246
+ }
247
+ const types = typesOf(property);
248
+ if (types.length > 0 && typeof type === 'string' && !types.includes(type)) {
249
+ ctx.report('PROCESS_RETURNS_TYPE', `${where} declares output ${JSON.stringify(field)} as ${JSON.stringify(type)}, but the process returns it as `
250
+ + `${types.join(' | ')}.`, `returns: { ${field}: '${returnTypeOf(property)}' }`);
251
+ }
252
+ }
253
+ }
@@ -18,7 +18,8 @@ import { ownEntry } from '../../../core/own-entry.js';
18
18
  import { resourceNodeSortOrder } from '../../../core/process-resource-sort-order.js';
19
19
  import { processResourceBindings, processResourceLocation } from '../../../core/process-resource.js';
20
20
  import { checkAgent, checkAgentRead, checkAgenticProcess, checkAgenticProcessRead, checkApiWorkflow, checkApiWorkflowRead, checkPublishedFunction, checkPublishedFunctionRead, checkRpaWorkflow, rpaWorkflowRead, } from './check.js';
21
- import { refuseLossyProcess } from './refusals.js';
21
+ import { checkRecordedProcess, withRecordedProcess } from './contract.js';
22
+ import { processLabel, refuseLossyProcess } from './refusals.js';
22
23
  import { refuseInSolution, resolveInSolution } from './in-solution.js';
23
24
  import { declareKeys } from '../../../core/option-keys.js';
24
25
  /** The RPA-workflow node type family. The process's release key is the suffix. */
@@ -644,13 +645,16 @@ export function processDefinition(spec) {
644
645
  * and in nothing else — the node body, the binding pair and the model-stripping
645
646
  * are identical, and the DATA paths that differ are all downstream in the engine.
646
647
  */
647
- function serializeProcess(spec, ctx) {
648
+ function serializeProcess(authored, ctx) {
649
+ // A published process named by name and folder takes what `prepare` recorded
650
+ // for it: the key, and the output schema when no `returns` is written (#1979).
651
+ const spec = recordedSpec(authored, ctx.resources);
648
652
  // A sibling the solution does not have, or one this factory cannot call:
649
653
  // refused before the generic rules, which would only say "no key" (#1978).
650
654
  refuseInSolution(spec.kind, spec.inputs, ctx.solution, ctx.step);
651
655
  // A missing key, a folder beside in-solution, a reserved `fireAndForget`
652
656
  // argument: each would be written wrong, so it is refused here (#1518).
653
- refuseLossyProcess(spec.kind, spec.inputs, ctx.step);
657
+ refuseLossyProcess(spec.kind, spec.inputs, ctx.step, ctx.resources);
654
658
  const s = spec.inputs;
655
659
  const fireAndForget = spec.kind === 'agenticProcess' && s.completion === 'fire-and-forget';
656
660
  const def = processDefinition(spec);
@@ -806,8 +810,17 @@ function printProcess(spec, ctx, factory) {
806
810
  ],
807
811
  };
808
812
  }
809
- /** What reading a process step's result yields: its `returns`, each kind's read rule. */
810
- function processOutput(spec) {
813
+ /** The spec with what `prepare` recorded for its process filled in (`withRecordedProcess`). */
814
+ function recordedSpec(spec, resources) {
815
+ const inputs = withRecordedProcess(spec.inputs, resources);
816
+ return inputs === spec.inputs ? spec : { ...spec, inputs };
817
+ }
818
+ /**
819
+ * What reading a process step's result yields: its `returns` — or, when none is
820
+ * written, the output schema `prepare` recorded — each kind's read rule.
821
+ */
822
+ function processOutput(authored, octx) {
823
+ const spec = recordedSpec(authored, octx?.resources);
811
824
  switch (spec.kind) {
812
825
  case 'rpaWorkflow': {
813
826
  const declared = Object.keys(spec.inputs?.returns ?? {});
@@ -827,7 +840,12 @@ function processOutput(spec) {
827
840
  return { kind: 'reader', read: (read, report) => checkAgentRead(read, spec.inputs, report) };
828
841
  }
829
842
  }
830
- function processCheck(spec, ctx) {
843
+ function processCheck(authored, ctx) {
844
+ const spec = recordedSpec(authored, ctx.options.resources);
845
+ // Against the tenant's record, when `prepare` made one: the key, the
846
+ // factory, the inputs and the declared returns, as the author wrote them. An
847
+ // in-solution step names no published process, and is not looked up.
848
+ checkRecordedProcess(authored.inputs, ctx, processDefinition(spec).model.bindings.resourceSubType, processLabel(spec.kind));
831
849
  switch (spec.kind) {
832
850
  case 'rpaWorkflow': return checkRpaWorkflow(spec.inputs, ctx);
833
851
  case 'apiWorkflow': return checkApiWorkflow(spec.inputs, ctx);
@@ -856,7 +874,7 @@ function processType(kind, prefix, factory, form) {
856
874
  check: (spec, ctx) => processCheck(spec, ctx),
857
875
  // check collected no expressions for a process step before the port; unchanged by it.
858
876
  expressions: () => [],
859
- output: processOutput,
877
+ output: (spec, octx) => processOutput(spec, octx),
860
878
  // An in-solution step named by `project` takes its key, project id, name and
861
879
  // returns from the sibling's files (#1978).
862
880
  withSolution: (spec, solution) => ({ ...spec, inputs: resolveInSolution(spec.kind, spec.inputs, solution) }),
@@ -1,8 +1,11 @@
1
1
  import { type ProcessKind } from '../../../core/process-resource.js';
2
+ import type { ResourceResolutions } from '../../../core/resource-resolution.js';
2
3
  /**
3
4
  * Throw the first condition of `inputs` the serializer would write wrong, as a
4
5
  * `CompileRefusal` on the step. For instance `rpaWorkflow({ name, folderPath })`
5
6
  * with no `key` throws `RPA_NO_KEY` instead of writing node type
6
7
  * `uipath.core.rpa-workflow.undefined`.
7
8
  */
8
- export declare function refuseLossyProcess(kind: ProcessKind, inputs: unknown, step: string): void;
9
+ export declare function refuseLossyProcess(kind: ProcessKind, inputs: unknown, step: string, resources?: ResourceResolutions): void;
10
+ /** How a message names a process kind's step: `RPA`, `API workflow`, `Agent`, … */
11
+ export declare function processLabel(kind: ProcessKind): string;
@@ -15,6 +15,7 @@
15
15
  import { CompileRefusal } from '../../../core/compile-refusal.js';
16
16
  import { ownEntry } from '../../../core/own-entry.js';
17
17
  import { blank, renamedFieldMessage } from '../../../core/process-resource.js';
18
+ import { unrecordedKeyReason } from './contract.js';
18
19
  /** Per kind: the codes, the label messages use, and the retired name of `key` (if any). */
19
20
  const KINDS = {
20
21
  rpaWorkflow: {
@@ -62,7 +63,7 @@ const KINDS = {
62
63
  * with no `key` throws `RPA_NO_KEY` instead of writing node type
63
64
  * `uipath.core.rpa-workflow.undefined`.
64
65
  */
65
- export function refuseLossyProcess(kind, inputs, step) {
66
+ export function refuseLossyProcess(kind, inputs, step, resources) {
66
67
  const k = ownEntry(KINDS, kind);
67
68
  const s = (inputs ?? {});
68
69
  // Every blank form is refused: omitted writes `<prefix>undefined`, and `''`
@@ -72,6 +73,13 @@ export function refuseLossyProcess(kind, inputs, step) {
72
73
  if (k.oldField !== undefined && !blank(old)) {
73
74
  throw new CompileRefusal(k.noKeyCode, renamedFieldMessage(k.label, step, k.oldField), `key: ${JSON.stringify(old)}`);
74
75
  }
76
+ // A published step that names its process by name and folder gets its key
77
+ // from `prepare`'s record (#1979); with no usable row, say which command records it.
78
+ const unrecorded = unrecordedKeyReason(inputs, resources);
79
+ if (unrecorded !== undefined) {
80
+ throw new CompileRefusal(k.noKeyCode, `${k.noKey(step)}\n Or leave it out and let prepare record the process: compile then writes the key, and check `
81
+ + `validates \`inputs\` and \`returns\` against the process's arguments. Its ${unrecorded}`, k.noKeySuggestion);
82
+ }
75
83
  throw new CompileRefusal(k.noKeyCode, k.noKey(step), k.noKeySuggestion);
76
84
  }
77
85
  if (k.localCode !== undefined && k.localLabel !== undefined && s.location === 'in-solution' && !blank(s.folderPath)) {
@@ -90,3 +98,7 @@ export function refuseLossyProcess(kind, inputs, step) {
90
98
  + `Rename the argument, or set \`completion: 'fire-and-forget'\` to start the process without waiting.`);
91
99
  }
92
100
  }
101
+ /** How a message names a process kind's step: `RPA`, `API workflow`, `Agent`, … */
102
+ export function processLabel(kind) {
103
+ return ownEntry(KINDS, kind).label;
104
+ }
@@ -19,6 +19,13 @@ export interface RpaWorkflowInputs {
19
19
  * it with `resource.key` from
20
20
  * `resources/solution_folder/process/process/<project>.json` — the suffix of the
21
21
  * node type `uip maestro flow registry list --local` shows.
22
+ *
23
+ * **Or leave it out** for a published one and run the `registry prepare`
24
+ * command `check` prints (`--kind Process --name <name> --folder-path <path>`).
25
+ * It records the key and the published argument schema; `compile` writes the
26
+ * key from that record, and `check` validates `inputs` and `returns` against it.
27
+ *
28
+ * @enforcedBy RPA_NO_KEY With no key, the process must be recorded by `prepare`.
22
29
  */
23
30
  key?: string;
24
31
  /** The process's name in Orchestrator — e.g. `'RPA Workflow'`. Filled from `project` for an in-solution sibling. */
@@ -87,6 +94,10 @@ export interface RpaWorkflowInputs {
87
94
  *
88
95
  * @enforcedBy RPA_READ_UNKNOWN_FIELD A read of the output must name a field declared here.
89
96
  * @enforcedBy RPA_READ_WITHOUT_RETURNS Reading a field off the result requires declaring it here.
97
+ *
98
+ * Leave it out once `registry prepare` has recorded the published process:
99
+ * compile then writes the recorded output schema, and `check` reads it.
100
+ * Declared, it is checked against that record (`PROCESS_RETURNS_UNKNOWN`).
90
101
  */
91
102
  returns?: Record<string, ReturnFieldType>;
92
103
  }
@@ -102,6 +113,13 @@ export interface ApiWorkflowInputs {
102
113
  * it with `resource.key` from
103
114
  * `resources/solution_folder/process/api/<project>.json`, the suffix of the
104
115
  * node type `uip maestro flow registry list --local` shows.
116
+ *
117
+ * **Or leave it out** for a published one and run the `registry prepare`
118
+ * command `check` prints (`--kind Process --name <name> --folder-path <path>`).
119
+ * It records the key and the published argument schema; `compile` writes the
120
+ * key from that record, and `check` validates `inputs` and `returns` against it.
121
+ *
122
+ * @enforcedBy APIWF_NO_KEY With no key, the process must be recorded by `prepare`.
105
123
  */
106
124
  key?: string;
107
125
  /** The workflow's name in Orchestrator — e.g. `'NameToAgeFixed'`. Filled from `project` for an in-solution sibling. */
@@ -167,6 +185,10 @@ export interface ApiWorkflowInputs {
167
185
  *
168
186
  * @enforcedBy APIWF_READ_WITHOUT_RETURNS Reading a field off the result requires
169
187
  * declaring it here.
188
+ *
189
+ * Leave it out once `registry prepare` has recorded the published process:
190
+ * compile then writes the recorded output schema, and `check` reads it.
191
+ * Declared, it is checked against that record (`PROCESS_RETURNS_UNKNOWN`).
170
192
  */
171
193
  returns?: Record<string, ReturnFieldType>;
172
194
  }
@@ -187,6 +209,13 @@ export interface PublishedFunctionInputs {
187
209
  * it with `resource.key` from
188
210
  * `resources/solution_folder/process/function/<project>.json` — the suffix of
189
211
  * the node type `uip maestro flow registry list --local` shows.
212
+ *
213
+ * **Or leave it out** for a published one and run the `registry prepare`
214
+ * command `check` prints (`--kind Process --name <name> --folder-path <path>`).
215
+ * It records the key and the published argument schema; `compile` writes the
216
+ * key from that record, and `check` validates `inputs` and `returns` against it.
217
+ *
218
+ * @enforcedBy FUNCTION_NO_KEY With no key, the process must be recorded by `prepare`.
190
219
  */
191
220
  key?: string;
192
221
  /** The function's name in Orchestrator, e.g. `'acme-echo'`. Filled from `project` for an in-solution sibling. */
@@ -249,6 +278,10 @@ export interface PublishedFunctionInputs {
249
278
  *
250
279
  * @enforcedBy FUNCTION_READ_WITHOUT_RETURNS Reading a field off the result
251
280
  * requires declaring it here.
281
+ *
282
+ * Leave it out once `registry prepare` has recorded the published process:
283
+ * compile then writes the recorded output schema, and `check` reads it.
284
+ * Declared, it is checked against that record (`PROCESS_RETURNS_UNKNOWN`).
252
285
  */
253
286
  returns?: Record<string, ReturnFieldType>;
254
287
  }
@@ -263,6 +296,13 @@ interface AgenticProcessInputsBase {
263
296
  * `--all-folders` PAGINATES at 50 rows and says so in `Pagination.HasMore` — pass
264
297
  * `--limit`/`--offset`, or scope the call with `--folder-path`, or a process that
265
298
  * exists will look as though it does not.
299
+ *
300
+ * **Or leave it out** for a published one and run the `registry prepare`
301
+ * command `check` prints (`--kind Process --name <name> --folder-path <path>`).
302
+ * It records the key and the published argument schema; `compile` writes the
303
+ * key from that record, and `check` validates `inputs` and `returns` against it.
304
+ *
305
+ * @enforcedBy AGENTIC_NO_KEY With no key, the process must be recorded by `prepare`.
266
306
  */
267
307
  key?: string;
268
308
  /** The process's name in Orchestrator — e.g. `'ProcurementProcess'`. Filled from `project` for an in-solution sibling. */
@@ -355,6 +395,10 @@ export type AgenticProcessCompletion = {
355
395
  *
356
396
  * @enforcedBy AGENTIC_READ_WITHOUT_RETURNS Reading a field off the result requires
357
397
  * declaring it here.
398
+ *
399
+ * Leave it out once `registry prepare` has recorded the published process:
400
+ * compile then writes the recorded output schema, and `check` reads it.
401
+ * Declared, it is checked against that record (`PROCESS_RETURNS_UNKNOWN`).
358
402
  */
359
403
  returns?: Record<string, ReturnFieldType>;
360
404
  } | {
@@ -393,6 +437,13 @@ export interface AgentInputs {
393
437
  *
394
438
  * Pass `--limit`: `--all-folders` returns 50 rows and reports the truncation
395
439
  * only in `Pagination.HasMore`, so an agent that exists can look absent.
440
+ *
441
+ * **Or leave it out** for a published one and run the `registry prepare`
442
+ * command `check` prints (`--kind Process --name <name> --folder-path <path>`).
443
+ * It records the key and the published argument schema; `compile` writes the
444
+ * key from that record, and `check` validates `inputs` and `returns` against it.
445
+ *
446
+ * @enforcedBy AGENT_NO_KEY With no key, the process must be recorded by `prepare`.
396
447
  */
397
448
  key?: string;
398
449
  /** The agent project name. Filled from `project` for an in-solution sibling. */
@@ -476,6 +527,10 @@ export interface AgentInputs {
476
527
  *
477
528
  * @enforcedBy AGENT_READ_WITHOUT_RETURNS Reading a field off the result requires
478
529
  * declaring it here.
530
+ *
531
+ * Leave it out once `registry prepare` has recorded the published process:
532
+ * compile then writes the recorded output schema, and `check` reads it.
533
+ * Declared, it is checked against that record (`PROCESS_RETURNS_UNKNOWN`).
479
534
  */
480
535
  returns?: Record<string, ReturnFieldType>;
481
536
  /**
@@ -0,0 +1,39 @@
1
+ /**
2
+ * `registry prepare --kind Process --name <name> --folder-path <path>`: after
3
+ * the catalogue names the published process, read its type and argument
4
+ * contract and record them on the row, so `check` can validate a step's
5
+ * `inputs` and `returns` and `compile` can fill in `key` and `returns` (#1979).
6
+ *
7
+ * The catalogue row (`uip solution resources list --kind Process`) carries the
8
+ * process's release `Key`; `uip or processes get <Key> --all-fields` carries
9
+ * `ProcessType` and `ArgumentsV2`, whose `Input` and `Output` are JSON Schemas
10
+ * written as escaped JSON strings. Read on the dev tenant 2026-11-13, for an API
11
+ * workflow:
12
+ *
13
+ * ```json
14
+ * { "Key": "ce857908-…", "Name": "NameToAgeFixed", "ProcessType": "Api",
15
+ * "ArgumentsV2": { "Input": "{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"}}}",
16
+ * "Output": "{\"type\":\"object\",\"properties\":{\"EstimatedAge\":{\"type\":\"integer\"}}}" } }
17
+ * ```
18
+ *
19
+ * Every process type the Flow process family starts has the same shape: RPA
20
+ * (`Process`), API workflow (`Api`), function (`Function`), agentic process
21
+ * (`ProcessOrchestration`, `Flow`, `CaseManagement`) and agent (`Agent`).
22
+ *
23
+ * A process authored in the solution (no remote twin) has no release yet, so
24
+ * nothing is read for it here; its contract lives in the solution's files.
25
+ */
26
+ import type { ResourceResolution } from "../../core/resource-resolution.js";
27
+ import type { UipClient } from "../uip/client.js";
28
+ /**
29
+ * The row with the published process's `processType` and `schema` added, read
30
+ * from `uip or processes get`. A row the solution authored, or one with no key,
31
+ * is returned as it is.
32
+ *
33
+ * @throws Refusal `PROCESS_SCHEMA_READ_FAILED` when the read fails or its
34
+ * `ArgumentsV2` is not JSON: "the process takes no arguments" and "the read
35
+ * failed" have opposite remedies, so nothing is recorded.
36
+ */
37
+ export declare function withProcessSchema(client: UipClient, row: ResourceResolution, cwd: string): Promise<ResourceResolution>;
38
+ /** The console lines for a recorded process's type and arguments; none for a row with neither. */
39
+ export declare function processSchemaLines(row: ResourceResolution): string[];
@@ -0,0 +1,90 @@
1
+ import { Refusal } from "../errors.js";
2
+ import { orProcessGet } from "../uip/commands.js";
3
+ import { failureReason, getCI, isSuccess, parseEnvelope } from "../uip/envelope.js";
4
+ /**
5
+ * One `ArgumentsV2` side as a JSON Schema object, `undefined` for a blank or
6
+ * missing side, or a refusal for text that is not one. Blank is "not
7
+ * extracted", not "no arguments": `GreetingApi` takes a string and answers
8
+ * `{"Input":"","Output":""}`, so reading it as empty would report every input
9
+ * the step passes as unknown.
10
+ */
11
+ function schemaSide(value, side, process, argv) {
12
+ if (value === undefined || value === null || (typeof value === "string" && value.trim() === ""))
13
+ return undefined;
14
+ let parsed = value;
15
+ if (typeof value === "string") {
16
+ try {
17
+ parsed = JSON.parse(value);
18
+ }
19
+ catch (error) {
20
+ throw new Refusal(`process ${JSON.stringify(process)}: ArgumentsV2.${side} is not JSON (${error instanceof Error ? error.message : String(error)}).\n` +
21
+ ` ${argv.join(" ")}`, "PROCESS_SCHEMA_READ_FAILED");
22
+ }
23
+ }
24
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
25
+ throw new Refusal(`process ${JSON.stringify(process)}: ArgumentsV2.${side} is not a JSON Schema object.\n ${argv.join(" ")}`, "PROCESS_SCHEMA_READ_FAILED");
26
+ }
27
+ return parsed;
28
+ }
29
+ /**
30
+ * The row with the published process's `processType` and `schema` added, read
31
+ * from `uip or processes get`. A row the solution authored, or one with no key,
32
+ * is returned as it is.
33
+ *
34
+ * @throws Refusal `PROCESS_SCHEMA_READ_FAILED` when the read fails or its
35
+ * `ArgumentsV2` is not JSON: "the process takes no arguments" and "the read
36
+ * failed" have opposite remedies, so nothing is recorded.
37
+ */
38
+ export async function withProcessSchema(client, row, cwd) {
39
+ if (row.source !== "remote" || row.key === null)
40
+ return row;
41
+ const argv = orProcessGet(row.key);
42
+ const result = await client.run(argv, { cwd });
43
+ const envelope = parseEnvelope(result.stdout);
44
+ if (result.code !== 0 || !isSuccess(envelope)) {
45
+ throw new Refusal(`could not read the arguments of process ${JSON.stringify(row.name)} (${failureReason(result)}).\n` +
46
+ ` ${argv.join(" ")}\n` +
47
+ "Check `uip login status`, then re-run. Nothing was recorded.", "PROCESS_SCHEMA_READ_FAILED");
48
+ }
49
+ const data = getCI(envelope, "Data");
50
+ const type = getCI(data, "ProcessType");
51
+ const args = getCI(data, "ArgumentsV2");
52
+ const sides = typeof args === "object" && args !== null && !Array.isArray(args)
53
+ ? { input: schemaSide(getCI(args, "Input"), "Input", row.name, argv), output: schemaSide(getCI(args, "Output"), "Output", row.name, argv) }
54
+ : {};
55
+ const schema = sides.input === undefined && sides.output === undefined
56
+ ? undefined
57
+ : { ...(sides.input !== undefined ? { input: sides.input } : {}), ...(sides.output !== undefined ? { output: sides.output } : {}) };
58
+ return {
59
+ ...row,
60
+ ...(typeof type === "string" && type !== "" ? { processType: type } : {}),
61
+ ...(schema !== undefined ? { schema } : {}),
62
+ };
63
+ }
64
+ /** A side's properties for the console: `name: string, id: integer (required)`; `(not recorded)` for an unknown side. */
65
+ function propertyLines(schema) {
66
+ if (schema === undefined)
67
+ return "(not recorded: Orchestrator left it blank, so check does not validate it)";
68
+ const properties = schema.properties;
69
+ if (typeof properties !== "object" || properties === null || Object.keys(properties).length === 0)
70
+ return "(none)";
71
+ const required = new Set(Array.isArray(schema.required) ? schema.required.filter((r) => typeof r === "string") : []);
72
+ return Object.entries(properties)
73
+ .map(([name, p]) => {
74
+ const t = p?.type;
75
+ return `${name}: ${Array.isArray(t) ? t.join("|") : typeof t === "string" ? t : "any"}${required.has(name) ? " (required)" : ""}`;
76
+ })
77
+ .join(", ");
78
+ }
79
+ /** The console lines for a recorded process's type and arguments; none for a row with neither. */
80
+ export function processSchemaLines(row) {
81
+ return [
82
+ ...(row.processType !== undefined ? [`Type ${row.processType}`] : []),
83
+ ...(row.schema !== undefined
84
+ ? [`Inputs ${propertyLines(row.schema.input)}`, `Outputs ${propertyLines(row.schema.output)}`]
85
+ : row.source === "remote" && row.key !== null
86
+ ? ["Arguments not recorded: Orchestrator left the process's ArgumentsV2 blank, so check cannot validate inputs or returns.",
87
+ "Declare `returns` for the fields the flow reads; compile writes the key from this record."]
88
+ : []),
89
+ ];
90
+ }
@@ -92,7 +92,8 @@ export interface ResolvedResource {
92
92
  * @param client - The `uip` client every call goes through.
93
93
  * @param request - The kind, the name, its folder path when the author gave one, and which listings to consult.
94
94
  * @returns The row to record, a note for the author when it was found without a folder, and how to read an entity's columns.
95
- * @throws Refusal `RESOURCE_AMBIGUOUS`, `RESOURCE_NOT_IN_FOLDER`, `RESOURCE_NOT_FOUND` or `RESOURCE_LISTING_FAILED`.
95
+ * @throws Refusal `RESOURCE_AMBIGUOUS`, `RESOURCE_NOT_IN_FOLDER`, `RESOURCE_NOT_FOUND` or `RESOURCE_LISTING_FAILED`; for a
96
+ * published process, `PROCESS_SCHEMA_READ_FAILED` when its arguments cannot be read.
96
97
  */
97
98
  export declare function resolveResource(client: UipClient, request: ResolveResourceRequest): Promise<ResolvedResource>;
98
99
  /** One line per recorded fact, for the console. */