@uipath/maestro-builder-sdk 6.107.0 → 6.109.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.
Files changed (35) hide show
  1. package/dist/api-index.md +10 -10
  2. package/dist/api-members.md +50 -45
  3. package/dist/check-cli.js +8 -3
  4. package/dist/check.d.ts +8 -0
  5. package/dist/check.js +10 -6
  6. package/dist/compile-cli.js +5 -0
  7. package/dist/core/nodes/node-type.d.ts +12 -2
  8. package/dist/core/refusals.d.ts +13 -0
  9. package/dist/core/refusals.js +13 -0
  10. package/dist/core/resource-resolution.d.ts +32 -0
  11. package/dist/core/resource-resolution.js +2 -0
  12. package/dist/core/solution-projects.d.ts +63 -0
  13. package/dist/core/solution-projects.js +37 -0
  14. package/dist/flow-node-type.d.ts +17 -0
  15. package/dist/merge-cli.js +8 -3
  16. package/dist/nodes/process/flow/check.js +36 -20
  17. package/dist/nodes/process/flow/contract.d.ts +81 -0
  18. package/dist/nodes/process/flow/contract.js +253 -0
  19. package/dist/nodes/process/flow/in-solution.d.ts +32 -0
  20. package/dist/nodes/process/flow/in-solution.js +169 -0
  21. package/dist/nodes/process/flow/node-type.js +37 -12
  22. package/dist/nodes/process/flow/refusals.d.ts +4 -1
  23. package/dist/nodes/process/flow/refusals.js +13 -1
  24. package/dist/nodes/process/flow/spec.d.ts +175 -20
  25. package/dist/registry/prepare/process-schema.d.ts +39 -0
  26. package/dist/registry/prepare/process-schema.js +90 -0
  27. package/dist/registry/prepare/resources.d.ts +2 -1
  28. package/dist/registry/prepare/resources.js +24 -3
  29. package/dist/registry/uip/commands.d.ts +8 -0
  30. package/dist/registry/uip/commands.js +10 -0
  31. package/dist/serialize.d.ts +9 -0
  32. package/dist/serialize.js +4 -2
  33. package/dist/solution-projects-files.d.ts +6 -0
  34. package/dist/solution-projects-files.js +163 -0
  35. package/package.json +2 -2
@@ -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
+ }
@@ -0,0 +1,32 @@
1
+ import { type ProcessKind } from '../../../core/process-resource.js';
2
+ import { type SolutionProject, type SolutionProjects } from '../../../core/solution-projects.js';
3
+ /** The factory call a sibling takes: its kind, and for an agentic process its form. */
4
+ interface Builder {
5
+ kind: ProcessKind;
6
+ form?: 'bpmn' | 'flow' | 'case';
7
+ /** The builder, for messages: `rpaWorkflow`, `agenticProcess` with form 'flow'. */
8
+ label: string;
9
+ /** How the call opens, for a suggestion: `agenticProcess({ form: 'flow', `. */
10
+ open: string;
11
+ }
12
+ /**
13
+ * The factory that calls `project`. The entry point's own type wins over the
14
+ * folder: `uip solution projects add` files a coded agent with no `ProjectType`
15
+ * under `process/function/`, while its `entry-points.json` still says `agent`.
16
+ */
17
+ export declare function builderOf(project: SolutionProject): Builder | undefined;
18
+ /**
19
+ * `inputs` with what the solution says about the sibling it names filled in.
20
+ * Only an in-solution step named by `project`, whose sibling is found and is
21
+ * this factory's, is filled; a field the author wrote is kept (a wrong one is
22
+ * `refuseInSolution`'s). Anything else is returned unchanged.
23
+ */
24
+ export declare function resolveInSolution(kind: ProcessKind, inputs: unknown, solution: SolutionProjects | undefined): unknown;
25
+ /**
26
+ * Throw what the serializer cannot write correctly about an in-solution step,
27
+ * knowing the solution. For instance `publishedFunction({ location:
28
+ * 'in-solution', project: 'Summarizer' })` on a project whose entry point is an
29
+ * agent throws `IN_SOLUTION_WRONG_BUILDER`, naming `agent(`.
30
+ */
31
+ export declare function refuseInSolution(kind: ProcessKind, inputs: unknown, solution: SolutionProjects | undefined, step: string): void;
32
+ export {};
@@ -0,0 +1,169 @@
1
+ /**
2
+ * An in-solution process step resolved against the solution on disk (#1978).
3
+ *
4
+ * The author names the sibling by project:
5
+ *
6
+ * rpaWorkflow({ location: 'in-solution', project: 'CalculatePay', inputs: { hours: 40 } })
7
+ *
8
+ * and `resolveInSolution` fills what the sibling's resource file and entry points
9
+ * say: `key` (`resource.key`), `projectId` (`resource.projectKey`), `name` (the
10
+ * project's name) and, when the step declares none, `returns` (the entry point's
11
+ * output fields). The serializer and `check` both run it (`withSolution` on the
12
+ * node type), so the read rules see the filled `returns` and the two rungs agree.
13
+ *
14
+ * `refuseInSolution` is the serializer's half: what it cannot write correctly once
15
+ * it knows the solution. A `project` it cannot find, a sibling the factory cannot
16
+ * call (a coded agent under `process/function/` called with `publishedFunction()`
17
+ * "validates and dispatches nothing"), and a `key` or `projectId` that names no
18
+ * sibling of this solution. Without a solution (a library call, or a flow outside
19
+ * any `.uipx` folder) an explicit `key` is not judged, and a `project` is refused:
20
+ * nothing can say what it names.
21
+ */
22
+ import { CompileRefusal } from '../../../core/compile-refusal.js';
23
+ import { nearestName } from '../../../core/edit-distance.js';
24
+ import { blank } from '../../../core/process-resource.js';
25
+ import { sameGuid, solutionProjectByKey, solutionProjectByName, } from '../../../core/solution-projects.js';
26
+ /**
27
+ * The factory that calls `project`. The entry point's own type wins over the
28
+ * folder: `uip solution projects add` files a coded agent with no `ProjectType`
29
+ * under `process/function/`, while its `entry-points.json` still says `agent`.
30
+ */
31
+ export function builderOf(project) {
32
+ const entry = project.entryPointType?.toLowerCase();
33
+ if (entry === 'agent')
34
+ return { kind: 'agent', label: 'agent', open: 'agent({ ' };
35
+ if (entry === 'function')
36
+ return { kind: 'publishedFunction', label: 'publishedFunction', open: 'publishedFunction({ ' };
37
+ switch (project.resourceType.toLowerCase()) {
38
+ case 'process': return { kind: 'rpaWorkflow', label: 'rpaWorkflow', open: 'rpaWorkflow({ ' };
39
+ case 'api': return { kind: 'apiWorkflow', label: 'apiWorkflow', open: 'apiWorkflow({ ' };
40
+ case 'function': return { kind: 'publishedFunction', label: 'publishedFunction', open: 'publishedFunction({ ' };
41
+ case 'agent': return { kind: 'agent', label: 'agent', open: 'agent({ ' };
42
+ case 'flow': return { kind: 'agenticProcess', form: 'flow', label: "agenticProcess with form 'flow'", open: "agenticProcess({ form: 'flow', " };
43
+ case 'processorchestration': return { kind: 'agenticProcess', form: 'bpmn', label: "agenticProcess with form 'bpmn'", open: "agenticProcess({ form: 'bpmn', " };
44
+ case 'casemanagement': return { kind: 'agenticProcess', form: 'case', label: "agenticProcess with form 'case'", open: "agenticProcess({ form: 'case', " };
45
+ default: return undefined;
46
+ }
47
+ }
48
+ /** Whether a `kind` step (with `form`, for an agentic process) is the call `builder` names. */
49
+ function fits(builder, kind, form) {
50
+ if (builder === undefined || builder.kind !== kind)
51
+ return false;
52
+ return kind !== 'agenticProcess' || (form ?? 'bpmn') === builder.form;
53
+ }
54
+ /** A JSON schema type as a `returns` type; anything else (a union, `null`) reads as `object`. */
55
+ function returnType(type) {
56
+ return type === 'string' || type === 'number' || type === 'integer' || type === 'boolean' || type === 'array'
57
+ ? type
58
+ : 'object';
59
+ }
60
+ /** The project a step names: by `project`, else by its `key`. */
61
+ function namedProject(s, solution) {
62
+ if (!blank(s.project))
63
+ return solutionProjectByName(solution, String(s.project).trim());
64
+ return !blank(s.key) ? solutionProjectByKey(solution, String(s.key)) : undefined;
65
+ }
66
+ /**
67
+ * `inputs` with what the solution says about the sibling it names filled in.
68
+ * Only an in-solution step named by `project`, whose sibling is found and is
69
+ * this factory's, is filled; a field the author wrote is kept (a wrong one is
70
+ * `refuseInSolution`'s). Anything else is returned unchanged.
71
+ */
72
+ export function resolveInSolution(kind, inputs, solution) {
73
+ const authored = (inputs ?? {});
74
+ // `project` names a sibling, so it implies the location; beside 'published' it is refused.
75
+ if (blank(authored.project) || (authored.location !== undefined && authored.location !== 'in-solution'))
76
+ return inputs;
77
+ const s = { ...authored, location: 'in-solution' };
78
+ const project = String(s.project).trim();
79
+ // The name is the project's either way, so an unresolved one is not also "has no name".
80
+ const found = solution !== undefined ? solutionProjectByName(solution, project) : undefined;
81
+ if (found === undefined || !fits(builderOf(found), kind, s.form)) {
82
+ return blank(s.name) ? { ...s, name: project } : s;
83
+ }
84
+ const outputs = found.outputs !== undefined && Object.keys(found.outputs).length > 0 ? found.outputs : undefined;
85
+ const fillReturns = s.returns === undefined && s.completion !== 'fire-and-forget' && outputs !== undefined;
86
+ return {
87
+ ...s,
88
+ key: blank(s.key) ? found.key : s.key,
89
+ name: blank(s.name) ? found.name : s.name,
90
+ projectId: blank(s.projectId) ? found.projectId : s.projectId,
91
+ ...(fillReturns ? { returns: Object.fromEntries(Object.entries(outputs).map(([f, t]) => [f, returnType(t)])) } : {}),
92
+ };
93
+ }
94
+ /** ` The solution's projects: "CalculatePay" (rpaWorkflow, resources/…/CalculatePay.json); …` */
95
+ function siblingList(solution) {
96
+ if (solution.projects.length === 0)
97
+ return '';
98
+ return ` The solution's projects: ${solution.projects
99
+ .map((p) => `"${p.name}" (${builderOf(p)?.label ?? p.resourceType}, ${p.file})`)
100
+ .join('; ')}.`;
101
+ }
102
+ /**
103
+ * Throw what the serializer cannot write correctly about an in-solution step,
104
+ * knowing the solution. For instance `publishedFunction({ location:
105
+ * 'in-solution', project: 'Summarizer' })` on a project whose entry point is an
106
+ * agent throws `IN_SOLUTION_WRONG_BUILDER`, naming `agent(`.
107
+ */
108
+ export function refuseInSolution(kind, inputs, solution, step) {
109
+ const s = (inputs ?? {});
110
+ const byProject = !blank(s.project);
111
+ if (byProject && s.location !== undefined && s.location !== 'in-solution') {
112
+ throw new CompileRefusal('IN_SOLUTION_PROJECT_PUBLISHED', `Step "${step}" names project ${JSON.stringify(s.project)} with \`location: ${JSON.stringify(s.location)}\`. `
113
+ + `\`project\` names a sibling of this solution; a published process is named by \`key\`, \`name\` and `
114
+ + `\`folderPath\`. Drop \`location\` (or set 'in-solution') to call the sibling, or drop \`project\`.`, `location: 'in-solution'`);
115
+ }
116
+ if (s.location !== 'in-solution')
117
+ return;
118
+ if (solution === undefined) {
119
+ if (!byProject)
120
+ return;
121
+ throw new CompileRefusal('IN_SOLUTION_NO_SOLUTION', `Step "${step}" calls in-solution project ${JSON.stringify(s.project)}, but this compile was given no `
122
+ + `solution to look it up in. \`flow compile\`, \`flow check\` and \`flow merge\` read it from the nearest folder `
123
+ + `at or above the flow that holds a \`.uipx\`, and found none; a library call to \`serialize()\` or \`check()\` `
124
+ + `passes it as the \`solution\` option. Run the command from inside the solution (\`<Solution>/<FlowProject>/\`), `
125
+ + `or write the sibling's \`key\` and \`projectId\` instead of \`project\`.`, `key: '<resource.key>', projectId: '<resource.projectKey>'`);
126
+ }
127
+ // Nothing to check an explicit key against: the solution was never refreshed,
128
+ // so the step's key cannot be judged here (`flow validate` sees it).
129
+ if (!byProject && solution.projects.length === 0)
130
+ return;
131
+ const project = namedProject(s, solution);
132
+ if (project === undefined) {
133
+ const refresh = solution.projects.length === 0
134
+ ? ` The solution has no project resource files yet: run \`uip solution resources refresh\` in ${solution.dir} `
135
+ + `after \`uip solution projects add\`, then compile again.`
136
+ : '';
137
+ if (byProject) {
138
+ const near = nearestName(String(s.project), solution.projects.map((p) => p.name));
139
+ throw new CompileRefusal('IN_SOLUTION_PROJECT_NOT_FOUND', `Step "${step}" calls in-solution project ${JSON.stringify(s.project)}, but the solution has no project of that `
140
+ + `name under resources/solution_folder/process/.${siblingList(solution)}${refresh}`, near !== undefined ? `project: '${near}'` : undefined);
141
+ }
142
+ const byName = !blank(s.name) ? solutionProjectByName(solution, String(s.name).trim()) : undefined;
143
+ if (byName !== undefined) {
144
+ throw new CompileRefusal('IN_SOLUTION_KEY_MISMATCH', `In-solution step "${step}" has \`key\` ${JSON.stringify(s.key)}, but project "${byName.name}" has resource key `
145
+ + `"${byName.key}" (${byName.file}). A key that names no sibling is a node the platform cannot resolve. `
146
+ + `Write \`project: '${byName.name}'\` and drop \`key\` and \`projectId\`, so compile reads them.`, `project: '${byName.name}'`);
147
+ }
148
+ throw new CompileRefusal('IN_SOLUTION_PROJECT_NOT_FOUND', `In-solution step "${step}" has \`key\` ${JSON.stringify(s.key)}, which is no project's resource key in this `
149
+ + `solution.${siblingList(solution)} Name the sibling with \`project: '<name>'\` and drop \`key\` and \`projectId\`.`);
150
+ }
151
+ const builder = builderOf(project);
152
+ if (!fits(builder, kind, s.form)) {
153
+ const why = project.entryPointType !== undefined
154
+ ? `its entry point is of type "${project.entryPointType}" and its resource is in ${project.file}`
155
+ : `its resource is in ${project.file}`;
156
+ throw new CompileRefusal('IN_SOLUTION_WRONG_BUILDER', `Step "${step}" calls project "${project.name}" with the wrong builder: ${why}, so it is called with `
157
+ + `${builder !== undefined ? builder.label : 'no process builder'}. The wrong builder writes a node `
158
+ + `that validates and starts nothing.`, builder !== undefined ? `${builder.open}location: 'in-solution', project: '${project.name}', … })` : undefined);
159
+ }
160
+ if (!blank(s.key) && !sameGuid(String(s.key), project.key)) {
161
+ throw new CompileRefusal('IN_SOLUTION_KEY_MISMATCH', `In-solution step "${step}" has \`key\` ${JSON.stringify(s.key)}, but project "${project.name}" has resource key `
162
+ + `"${project.key}" (${project.file}). Drop \`key\` and let compile read it from \`project\`.`, `key: '${project.key}'`);
163
+ }
164
+ if (!blank(s.projectId) && !sameGuid(String(s.projectId), project.projectId)) {
165
+ throw new CompileRefusal('IN_SOLUTION_KEY_MISMATCH', `In-solution step "${step}" has \`projectId\` ${JSON.stringify(s.projectId)}, but project "${project.name}" has `
166
+ + `\`resource.projectKey\` "${project.projectId}" (${project.file}). Drop \`projectId\` and let compile read it `
167
+ + `from \`project\`.`, `projectId: '${project.projectId}'`);
168
+ }
169
+ }
@@ -18,7 +18,9 @@ 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';
23
+ import { refuseInSolution, resolveInSolution } from './in-solution.js';
22
24
  import { declareKeys } from '../../../core/option-keys.js';
23
25
  /** The RPA-workflow node type family. The process's release key is the suffix. */
24
26
  const RPA_WORKFLOW_PREFIX = 'uipath.core.rpa-workflow.';
@@ -643,10 +645,16 @@ export function processDefinition(spec) {
643
645
  * and in nothing else — the node body, the binding pair and the model-stripping
644
646
  * are identical, and the DATA paths that differ are all downstream in the engine.
645
647
  */
646
- 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);
652
+ // A sibling the solution does not have, or one this factory cannot call:
653
+ // refused before the generic rules, which would only say "no key" (#1978).
654
+ refuseInSolution(spec.kind, spec.inputs, ctx.solution, ctx.step);
647
655
  // A missing key, a folder beside in-solution, a reserved `fireAndForget`
648
656
  // argument: each would be written wrong, so it is refused here (#1518).
649
- refuseLossyProcess(spec.kind, spec.inputs, ctx.step);
657
+ refuseLossyProcess(spec.kind, spec.inputs, ctx.step, ctx.resources);
650
658
  const s = spec.inputs;
651
659
  const fireAndForget = spec.kind === 'agenticProcess' && s.completion === 'fire-and-forget';
652
660
  const def = processDefinition(spec);
@@ -802,8 +810,17 @@ function printProcess(spec, ctx, factory) {
802
810
  ],
803
811
  };
804
812
  }
805
- /** What reading a process step's result yields: its `returns`, each kind's read rule. */
806
- 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);
807
824
  switch (spec.kind) {
808
825
  case 'rpaWorkflow': {
809
826
  const declared = Object.keys(spec.inputs?.returns ?? {});
@@ -823,7 +840,12 @@ function processOutput(spec) {
823
840
  return { kind: 'reader', read: (read, report) => checkAgentRead(read, spec.inputs, report) };
824
841
  }
825
842
  }
826
- 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));
827
849
  switch (spec.kind) {
828
850
  case 'rpaWorkflow': return checkRpaWorkflow(spec.inputs, ctx);
829
851
  case 'apiWorkflow': return checkApiWorkflow(spec.inputs, ctx);
@@ -834,11 +856,11 @@ function processCheck(spec, ctx) {
834
856
  }
835
857
  /** Every key of each factory's options (builder-sdk#1990), by kind; `tsc` holds each list to its type. */
836
858
  const PROCESS_OPTIONS = {
837
- rpaWorkflow: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
838
- apiWorkflow: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
839
- publishedFunction: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
840
- agenticProcess: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, form: true, completion: true, returns: true }) },
841
- agent: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, returns: true, flavour: true }) },
859
+ rpaWorkflow: { inputs: declareKeys({ key: true, name: true, location: true, project: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
860
+ apiWorkflow: { inputs: declareKeys({ key: true, name: true, location: true, project: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
861
+ publishedFunction: { inputs: declareKeys({ key: true, name: true, location: true, project: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
862
+ agenticProcess: { inputs: declareKeys({ key: true, name: true, location: true, project: true, folderPath: true, projectId: true, inputs: true, form: true, completion: true, returns: true }) },
863
+ agent: { inputs: declareKeys({ key: true, name: true, location: true, project: true, folderPath: true, projectId: true, inputs: true, returns: true, flavour: true }) },
842
864
  };
843
865
  function processType(kind, prefix, factory, form) {
844
866
  const impl = {
@@ -852,7 +874,10 @@ function processType(kind, prefix, factory, form) {
852
874
  check: (spec, ctx) => processCheck(spec, ctx),
853
875
  // check collected no expressions for a process step before the port; unchanged by it.
854
876
  expressions: () => [],
855
- output: processOutput,
877
+ output: (spec, octx) => processOutput(spec, octx),
878
+ // An in-solution step named by `project` takes its key, project id, name and
879
+ // returns from the sibling's files (#1978).
880
+ withSolution: (spec, solution) => ({ ...spec, inputs: resolveInSolution(spec.kind, spec.inputs, solution) }),
856
881
  ...(kind === 'agenticProcess' ? {
857
882
  fireAndForget: ({ inputs }) => inputs?.completion === 'fire-and-forget'
858
883
  ? { fix: "completion: 'wait'" }
@@ -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
+ }