@uipath/maestro-builder-sdk 6.117.4 → 6.118.1

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.
@@ -575,6 +575,20 @@ export interface FlowNodeType<Spec> extends NodeType<Spec, FlowNodeContribution,
575
575
  * (`core/carried-connector-operation.ts`). Absent: never.
576
576
  */
577
577
  carriesFromFile?(node: unknown, library: NonNullable<SerializeOpts['library']>): boolean;
578
+ /**
579
+ * Whether `outputs` is an output declaration an earlier SDK wrote for this
580
+ * type at this version, and the SDK's bundle has since corrected. `outputs` is
581
+ * a saved node's `outputs` or its `definitions[]` entry's `outputDefinition`;
582
+ * the two have one shape (`{ output: { schema, ... }, ... }`).
583
+ *
584
+ * Compile derives both from the definition, so the author never writes them.
585
+ * When the original file holds a superseded one, merge writes the edited
586
+ * compile's node `outputs`, `variables.nodes` entries and definition instead
587
+ * of keeping the original's (merge-superseded-outputs.ts). Otherwise the merged
588
+ * file declares an output the node does not publish, and `flow validate` refuses
589
+ * the corrected reads of it. Omitted: never.
590
+ */
591
+ supersededOutputs?(outputs: unknown): boolean;
578
592
  /**
579
593
  * The node-level `model` every node of this type carries, whichever path emits
580
594
  * it — this type's `serialize`, or a `rawNode` of its definition. `'omit'`: none
@@ -0,0 +1,21 @@
1
+ /** What {@link provisionIdpProcessors} did, for compile to report. */
2
+ export interface IdpProcessorProvisioning {
3
+ /** Solution-relative paths of the resource files created or updated. */
4
+ written: string[];
5
+ /** Why no file was written although a node authors a processor (the project is not in a solution). */
6
+ pending?: string;
7
+ /** Processors whose file was not written, and why (a resource folder that resolves outside the solution). */
8
+ skipped: string[];
9
+ /** The processor display names by key, as the solution's files hold them, for `bindings_v2.json`. */
10
+ namesByKey: Map<string, string>;
11
+ }
12
+ /**
13
+ * Give each processor the flow's Extract document nodes author its resource
14
+ * file, and each such node the processor's name (`inputs.processorName`) —
15
+ * MUTATES `flow`, so call it before the `.flow` is written. `projectDir` is the
16
+ * Flow project (the folder holding `project.uiproj`) the flow is the main flow of.
17
+ */
18
+ export declare function provisionIdpProcessors(flow: {
19
+ nodes?: unknown;
20
+ subflows?: unknown;
21
+ }, projectDir: string): IdpProcessorProvisioning;
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Writing each Extract document node's IDP processor resource file, for
3
+ * `compile-cli` (builder-sdk#1984). The rules are the document family's
4
+ * (`nodes/document/flow/idp-processor.ts`, pure, so the flow core loads no
5
+ * `node:fs` — FB015); this module only reads and writes the files.
6
+ *
7
+ * What it does, as `uip maestro flow nodes create` / `nodes provision` and
8
+ * `uip solution pack` do it: find the solution whose `.uipx` lists the
9
+ * project; read its `idpProcessor` resources, matched by `kind` and `key`
10
+ * (never by path); merge each authored processor's spec into its file, or
11
+ * create the file under a de-duplicated name.
12
+ *
13
+ * Confinement: every path read or written resolves inside the solution. The
14
+ * walk follows only canonical paths, a new file's folder is checked through
15
+ * its nearest existing ancestor, and a new file is created exclusively (it
16
+ * fails on anything already at the path, a dangling link included). A link at
17
+ * a candidate path is never read through or reused.
18
+ *
19
+ * A file is only written when its content changes, and never deleted: a
20
+ * resource outlives its node, as pack leaves it.
21
+ */
22
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
23
+ import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
24
+ import { writeJsonFile } from './core/json-file.js';
25
+ import { buildIdpProcessorSpec, collectWorkflowNodes, DEFAULT_IDP_PROCESSOR_NAME, deriveIdpProcessorName, idpProcessorResourcePath, isIdpProcessorResource, isPublishedIdpProcessorLink, readAuthoringProcessorKey, readIdpProcessorName, readNodeLabel, updateIdpProcessorResource, wrapIdpProcessorSpec, } from './nodes/document/flow/family.js';
26
+ function readJson(path) {
27
+ try {
28
+ return JSON.parse(readFileSync(path, 'utf8'));
29
+ }
30
+ catch {
31
+ return undefined;
32
+ }
33
+ }
34
+ function canonical(path) {
35
+ try {
36
+ return realpathSync(path);
37
+ }
38
+ catch {
39
+ return undefined;
40
+ }
41
+ }
42
+ function contains(root, target) {
43
+ const rel = relative(root, target);
44
+ return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
45
+ }
46
+ /** The Flow project folders a solution's `.uipx` lists (the CLI's `readFlowProjectDirs`). */
47
+ function flowProjectDirs(solutionDir) {
48
+ let entries;
49
+ try {
50
+ entries = readdirSync(solutionDir);
51
+ }
52
+ catch {
53
+ return [];
54
+ }
55
+ const uipx = entries.find((e) => e.endsWith('.uipx'));
56
+ if (uipx === undefined)
57
+ return [];
58
+ const manifest = readJson(join(solutionDir, uipx));
59
+ const root = resolve(solutionDir);
60
+ const dirs = [];
61
+ for (const project of Array.isArray(manifest?.Projects) ? manifest.Projects : []) {
62
+ if (project?.Type !== 'Flow' || typeof project.ProjectRelativePath !== 'string')
63
+ continue;
64
+ const target = resolve(root, ...project.ProjectRelativePath.replace(/\\/g, '/').split('/'));
65
+ const dir = target.endsWith('.uiproj') ? dirname(target) : target;
66
+ if (contains(root, dir))
67
+ dirs.push(dir);
68
+ }
69
+ return dirs;
70
+ }
71
+ /** The nearest folder at or above `projectDir` whose `.uipx` lists it (the CLI's `findEnclosingSolutionDir`). */
72
+ function enclosingSolution(projectDir) {
73
+ const project = resolve(projectDir);
74
+ let dir = project;
75
+ for (;;) {
76
+ let entries = [];
77
+ try {
78
+ entries = readdirSync(dir);
79
+ }
80
+ catch {
81
+ // An unreadable folder is not a solution; keep walking up.
82
+ }
83
+ if (entries.some((e) => e.endsWith('.uipx')) && flowProjectDirs(dir).includes(project))
84
+ return dir;
85
+ const parent = dirname(dir);
86
+ if (parent === dir)
87
+ return undefined;
88
+ dir = parent;
89
+ }
90
+ }
91
+ /**
92
+ * Every processor resource under `<solution>/resources/`, walked through
93
+ * canonical paths so a link cannot carry a write out of the solution, each
94
+ * folder visited once.
95
+ */
96
+ function readResources(solutionDir) {
97
+ const root = canonical(solutionDir);
98
+ const entries = [];
99
+ if (root === undefined)
100
+ return entries;
101
+ const visited = new Set();
102
+ const walk = (dir) => {
103
+ const at = canonical(dir);
104
+ if (at === undefined || !contains(root, at) || visited.has(at))
105
+ return;
106
+ visited.add(at);
107
+ let names;
108
+ try {
109
+ names = readdirSync(at).sort();
110
+ }
111
+ catch {
112
+ return;
113
+ }
114
+ for (const name of names) {
115
+ const child = canonical(join(at, name));
116
+ if (child === undefined || !contains(root, child))
117
+ continue;
118
+ const stat = statSync(child);
119
+ if (stat.isDirectory())
120
+ walk(child);
121
+ else if (stat.isFile() && name.endsWith('.json')) {
122
+ const parsed = readJson(child);
123
+ if (!isIdpProcessorResource(parsed))
124
+ continue;
125
+ const resource = parsed.resource;
126
+ entries.push({
127
+ filePath: child,
128
+ key: typeof resource.key === 'string' ? resource.key : '',
129
+ name: typeof resource.name === 'string' ? resource.name : '',
130
+ file: parsed,
131
+ });
132
+ }
133
+ }
134
+ };
135
+ walk(join(root, 'resources'));
136
+ return entries;
137
+ }
138
+ /** What is at a candidate path, without following a link there. */
139
+ function occupant(path) {
140
+ try {
141
+ return lstatSync(path).isSymbolicLink() ? 'link' : 'file';
142
+ }
143
+ catch {
144
+ return 'free';
145
+ }
146
+ }
147
+ /**
148
+ * `path`, or the first `<name>_<N>.json` that is free or already holds this
149
+ * processor's own file. A link is never followed, read or reused: its path is skipped.
150
+ */
151
+ function freeResourcePath(path, key) {
152
+ const base = path.slice(0, -'.json'.length);
153
+ for (let suffix = 1, candidate = path;; candidate = `${base}_${suffix++}.json`) {
154
+ const at = occupant(candidate);
155
+ if (at === 'free')
156
+ return { path: candidate, own: false };
157
+ if (at === 'link')
158
+ continue;
159
+ const parsed = readJson(candidate);
160
+ if (parsed?.resource?.key === key)
161
+ return { path: candidate, own: true };
162
+ }
163
+ }
164
+ /** The deterministic bytes the CLI writes a resource file with. */
165
+ function serialized(value) {
166
+ return `${JSON.stringify(value, null, 2)}\n`;
167
+ }
168
+ /**
169
+ * Give each processor the flow's Extract document nodes author its resource
170
+ * file, and each such node the processor's name (`inputs.processorName`) —
171
+ * MUTATES `flow`, so call it before the `.flow` is written. `projectDir` is the
172
+ * Flow project (the folder holding `project.uiproj`) the flow is the main flow of.
173
+ */
174
+ export function provisionIdpProcessors(flow, projectDir) {
175
+ const authors = collectWorkflowNodes(flow).filter((node) => {
176
+ const key = readAuthoringProcessorKey(node);
177
+ return key !== undefined && !isPublishedIdpProcessorLink(node.inputs);
178
+ });
179
+ const namesByKey = new Map();
180
+ if (authors.length === 0)
181
+ return { written: [], namesByKey, skipped: [] };
182
+ const solutionDir = enclosingSolution(projectDir);
183
+ if (solutionDir === undefined) {
184
+ return {
185
+ written: [],
186
+ namesByKey,
187
+ skipped: [],
188
+ pending: 'the flow project is not inside a solution, so each Extract document step\'s idpProcessor resource file '
189
+ + 'is created when the project is packed inside one (uip solution pack)',
190
+ };
191
+ }
192
+ const resources = readResources(solutionDir);
193
+ for (const entry of resources)
194
+ if (entry.key !== '' && entry.name !== '')
195
+ namesByKey.set(entry.key, entry.name);
196
+ const taken = new Set(resources.map((r) => r.name.toLowerCase()).filter((n) => n.length > 0));
197
+ const written = [];
198
+ const skipped = [];
199
+ const done = new Map();
200
+ for (const node of authors) {
201
+ const key = readAuthoringProcessorKey(node);
202
+ const inputs = node.inputs;
203
+ // Nodes sharing a key share its processor: the first one writes it.
204
+ const named = done.get(key);
205
+ if (named !== undefined) {
206
+ inputs.processorName = named;
207
+ continue;
208
+ }
209
+ const spec = buildIdpProcessorSpec(node);
210
+ const existing = resources.find((r) => r.key === key);
211
+ if (existing !== undefined) {
212
+ // The resource owns the name once created.
213
+ if (existing.name.length > 0)
214
+ inputs.processorName = existing.name;
215
+ const merged = updateIdpProcessorResource(existing.file, spec);
216
+ if (serialized(merged) !== serialized(existing.file)) {
217
+ writeJsonFile(existing.filePath, merged);
218
+ written.push(relative(solutionDir, existing.filePath));
219
+ }
220
+ done.set(key, existing.name.length > 0 ? existing.name : String(inputs.processorName ?? ''));
221
+ continue;
222
+ }
223
+ const base = readIdpProcessorName(inputs) ?? readNodeLabel(node) ?? DEFAULT_IDP_PROCESSOR_NAME;
224
+ const name = deriveIdpProcessorName(base, taken) ?? DEFAULT_IDP_PROCESSOR_NAME;
225
+ taken.add(name.toLowerCase());
226
+ inputs.processorName = name;
227
+ namesByKey.set(key, name);
228
+ const found = freeResourcePath(join(solutionDir, ...idpProcessorResourcePath(name).split('/')), key);
229
+ const target = found.path;
230
+ // Nearest existing ancestor first: mkdir would follow a link anywhere above
231
+ // the leaf and carry the new folders out of the solution.
232
+ let probe = dirname(target);
233
+ while (!existsSync(probe) && dirname(probe) !== probe)
234
+ probe = dirname(probe);
235
+ const realProbe = canonical(probe);
236
+ const realRoot = canonical(solutionDir);
237
+ if (realProbe === undefined || realRoot === undefined || !contains(realRoot, realProbe)) {
238
+ skipped.push(`${name} (${key}): ${relative(solutionDir, dirname(target))} resolves outside the solution`);
239
+ done.set(key, name);
240
+ continue;
241
+ }
242
+ mkdirSync(dirname(target), { recursive: true });
243
+ // Its own file (a regular file, checked above) is rewritten in place; a
244
+ // new one is created exclusively, so nothing that appears at the path in
245
+ // between, a link included, is written through.
246
+ writeJsonFile(target, wrapIdpProcessorSpec({ key, name, spec }), { exclusive: !found.own });
247
+ written.push(relative(solutionDir, target));
248
+ done.set(key, name);
249
+ }
250
+ return { written, namesByKey, skipped };
251
+ }
@@ -33,13 +33,14 @@ interface RtFlow {
33
33
  /** One difference, or one inconsistency in the merged file. */
34
34
  export interface MergeFinding {
35
35
  /** Which comparison found it. */
36
- kind: 'node-removed' | 'node-added' | 'node-type' | 'implicit-end' | 'edge-handle-renamed' | 'edge-rewired' | 'edge-removed' | 'edge-added' | 'handle-ids' | 'binding-removed' | 'binding-added' | 'variable-added' | 'variable-changed' | 'undeclared-handle' | 'duplicate-binding' | 'agent-sidecar' | 'agent-storage' | 'agent-prompt-input' | 'agent-embedded-edit';
36
+ kind: 'node-removed' | 'node-added' | 'node-type' | 'implicit-end' | 'edge-handle-renamed' | 'edge-rewired' | 'edge-removed' | 'edge-added' | 'handle-ids' | 'binding-removed' | 'binding-added' | 'variable-added' | 'variable-changed' | 'undeclared-handle' | 'duplicate-binding' | 'agent-sidecar' | 'agent-storage' | 'agent-prompt-input' | 'agent-embedded-edit' | 'outputs-superseded';
37
37
  /** The finding, phrased for the author, naming the node, edge or row. */
38
38
  message: string;
39
39
  /**
40
40
  * Whether `strict` refuses the merge over it. False for `implicit-end` and
41
41
  * `binding-removed`, which leave the merged file doing what the original does,
42
- * and for `agent-embedded-edit`, which reports what merge did not carry.
42
+ * for `agent-embedded-edit`, which reports what merge did not carry, and for
43
+ * `outputs-superseded`, which reports a declaration merge corrected.
43
44
  */
44
45
  refuses: boolean;
45
46
  }
@@ -57,7 +58,11 @@ export interface MergeFinding {
57
58
  * @param merged - The merged file, before it is written.
58
59
  * @returns One finding per difference, in a stable order.
59
60
  */
60
- export declare function roundTripFindings(original: RtFlow, baseline: RtFlow, merged: RtFlow): MergeFinding[];
61
+ /**
62
+ * `correctedVariables` are root `variables.nodes` ids merge rewrote on purpose
63
+ * (merge-superseded-outputs.ts), so they are not reported as a rewrite here.
64
+ */
65
+ export declare function roundTripFindings(original: RtFlow, baseline: RtFlow, merged: RtFlow, correctedVariables?: ReadonlySet<string>): MergeFinding[];
61
66
  /**
62
67
  * Inconsistencies in the merged file that come from mixing its sources: a root
63
68
  * edge leaving a handle its source node does not declare, and two binding rows
@@ -110,7 +110,11 @@ function bindingText(b) {
110
110
  * @param merged - The merged file, before it is written.
111
111
  * @returns One finding per difference, in a stable order.
112
112
  */
113
- export function roundTripFindings(original, baseline, merged) {
113
+ /**
114
+ * `correctedVariables` are root `variables.nodes` ids merge rewrote on purpose
115
+ * (merge-superseded-outputs.ts), so they are not reported as a rewrite here.
116
+ */
117
+ export function roundTripFindings(original, baseline, merged, correctedVariables = new Set()) {
114
118
  const out = [];
115
119
  const origDefs = defsOf(original);
116
120
  const baseDefs = defsOf(baseline);
@@ -299,6 +303,8 @@ export function roundTripFindings(original, baseline, merged) {
299
303
  const ov = o.get(id);
300
304
  if (mv === undefined || stableJson(mv) !== stableJson(bv) || (ov !== undefined && stableJson(ov) === stableJson(bv)))
301
305
  continue;
306
+ if (section === 'nodes' && correctedVariables.has(id))
307
+ continue;
302
308
  if (ov === undefined) {
303
309
  out.push({ kind: 'variable-added', refuses, message: `the round trip adds variables.${section} "${id}"; merge will write it${tail}.` });
304
310
  continue;
@@ -0,0 +1,12 @@
1
+ import type { MergeFinding } from './merge-roundtrip.js';
2
+ import { type AnyFlow } from './edit-scope.js';
3
+ /**
4
+ * Replace, in `merged` (mutated), each superseded node output declaration and
5
+ * definition with the edited compile's. Returns the findings and the ids of the
6
+ * ROOT `variables.nodes` entries it rewrote, which the round-trip check must not
7
+ * report as a rewrite the author did not make.
8
+ */
9
+ export declare function replaceSupersededOutputs(merged: AnyFlow, edited: AnyFlow): {
10
+ findings: MergeFinding[];
11
+ rootVariables: Set<string>;
12
+ };
@@ -0,0 +1,111 @@
1
+ /**
2
+ * merge-superseded-outputs — write the corrected output declaration of a node
3
+ * whose original an older SDK compiled with a wrong one.
4
+ *
5
+ * A node's `outputs`, its `variables.nodes` entries and its `definitions[]`
6
+ * entry are derived: compile writes all three from the node type's definition,
7
+ * and the author never writes them. So merge normally keeps the original's
8
+ * (withEdits and merge-variables.ts keep a field the author did not change;
9
+ * the original's definition wins on conflict, as the tenant-resolved authority).
10
+ *
11
+ * That is wrong when the SDK's own bundle was wrong when the original was
12
+ * compiled and has since been corrected. For instance, before #1987 the bundle
13
+ * declared Extract document's output as `ExtractionResult` and `Taxonomy`, while
14
+ * the node publishes a processed document (`result.output.<group>.<field>`, ...).
15
+ * An author fixes the read `$vars.extract.output.ExtractionResult` to
16
+ * `$vars.extract.output.result.output.Invoice.Total` and merges. Keeping the
17
+ * original's declaration, the merged file says the output has no `result`, and
18
+ * `flow validate` warns `Property 'result' does not exist on type 'Extract_Output'`,
19
+ * while a fresh compile of the same source validates clean.
20
+ *
21
+ * A node type names the declarations it superseded (`FlowNodeType.supersededOutputs`).
22
+ * For a merged node whose `outputs` is one of them, merge takes the edited
23
+ * compile's `outputs` and the scope's `variables.nodes` entries bound to the
24
+ * node; for a merged definition whose `outputDefinition` is one, the edited
25
+ * compile's definition of the same `(nodeType, version)`. Only an edited node or
26
+ * definition at the same type and version, whose own declaration is not
27
+ * superseded, is taken. Each replacement is reported, never refused: the merged
28
+ * file then declares what the node publishes.
29
+ */
30
+ import { jsonClone } from './core/json-clone.js';
31
+ import { isRecord } from './core/node-envelope.js';
32
+ import { FLOW_NODE_TYPES } from './flow-node-registry.js';
33
+ import { byId } from './edit-scope.js';
34
+ /** The registered type's `supersededOutputs` at exactly this version, if it declares one. */
35
+ function supersededRule(type, version) {
36
+ if (typeof type !== 'string' || typeof version !== 'string')
37
+ return undefined;
38
+ const entry = FLOW_NODE_TYPES.byTypeName(type);
39
+ if (!entry || !Object.hasOwn(entry.type.versions, version))
40
+ return undefined;
41
+ return entry.type.versions[version].supersededOutputs;
42
+ }
43
+ function nodeEntries(variables) {
44
+ const list = isRecord(variables) ? variables.nodes : undefined;
45
+ return Array.isArray(list) ? list : undefined;
46
+ }
47
+ const boundTo = (entry, nodeId) => isRecord(entry) && isRecord(entry.binding) && entry.binding.nodeId === nodeId;
48
+ /**
49
+ * Replace, in `merged` (mutated), each superseded node output declaration and
50
+ * definition with the edited compile's. Returns the findings and the ids of the
51
+ * ROOT `variables.nodes` entries it rewrote, which the round-trip check must not
52
+ * report as a rewrite the author did not make.
53
+ */
54
+ export function replaceSupersededOutputs(merged, edited) {
55
+ const findings = [];
56
+ const rootVariables = new Set();
57
+ const scopes = [
58
+ ['', merged, edited],
59
+ ...Object.keys(merged.subflows ?? {}).map((key) => [key, merged.subflows[key], edited.subflows?.[key]]),
60
+ ];
61
+ for (const [key, into, from] of scopes) {
62
+ if (!into?.nodes || !from)
63
+ continue;
64
+ const editedNodes = byId(from.nodes);
65
+ for (const node of into.nodes) {
66
+ const superseded = supersededRule(node.type, node.typeVersion);
67
+ const e = editedNodes.get(node.id);
68
+ if (!superseded || !superseded(node.outputs) || !e || e.type !== node.type || e.typeVersion !== node.typeVersion)
69
+ continue;
70
+ if (e.outputs === undefined || superseded(e.outputs))
71
+ continue;
72
+ node.outputs = jsonClone(e.outputs);
73
+ const entries = nodeEntries(into.variables);
74
+ const editedEntries = new Map((nodeEntries(from.variables) ?? []).filter((v) => boundTo(v, node.id)).map((v) => [v.id, v]));
75
+ if (entries) {
76
+ into.variables.nodes = entries.map((v) => {
77
+ const replacement = boundTo(v, node.id) ? editedEntries.get(v.id) : undefined;
78
+ if (replacement === undefined)
79
+ return v;
80
+ if (key === '')
81
+ rootVariables.add(v.id);
82
+ return jsonClone(replacement);
83
+ });
84
+ }
85
+ const where = key === '' ? '' : ` in subflow "${key}"`;
86
+ findings.push({
87
+ kind: 'outputs-superseded',
88
+ refuses: false,
89
+ message: `node "${node.id}"${where} (${node.type}@${node.typeVersion}) declared an output an earlier SDK wrote wrongly; `
90
+ + 'merge wrote the edited compile\'s outputs and variables.nodes entries, which declare what the node publishes.',
91
+ });
92
+ }
93
+ }
94
+ const editedDefs = new Map((edited.definitions ?? []).map((d) => [`${String(d.nodeType)}@${String(d.version)}`, d]));
95
+ merged.definitions = merged.definitions?.map((d) => {
96
+ const superseded = supersededRule(d.nodeType, d.version);
97
+ if (!superseded?.(d.outputDefinition))
98
+ return d;
99
+ const e = editedDefs.get(`${String(d.nodeType)}@${String(d.version)}`);
100
+ if (e === undefined || superseded(e.outputDefinition))
101
+ return d;
102
+ findings.push({
103
+ kind: 'outputs-superseded',
104
+ refuses: false,
105
+ message: `the original's definition of ${String(d.nodeType)}@${String(d.version)} declares an output an earlier SDK wrote wrongly; `
106
+ + 'merge wrote the edited compile\'s definition.',
107
+ });
108
+ return jsonClone(e);
109
+ });
110
+ return { findings, rootVariables };
111
+ }
package/dist/merge.d.ts CHANGED
@@ -82,6 +82,13 @@
82
82
  * checked for an edge that leaves a handle its kept source node does not
83
83
  * declare. See merge-roundtrip.ts.
84
84
  *
85
+ * ## A superseded output declaration is replaced
86
+ *
87
+ * A node's `outputs`, `variables.nodes` entries and definition are derived from
88
+ * its type's definition, so merge keeps the original's. Where an older SDK
89
+ * wrote them wrongly and the node type says so (`supersededOutputs`), merge
90
+ * writes the edited compile's instead. See merge-superseded-outputs.ts.
91
+ *
85
92
  * ## An embedded agent stays embedded
86
93
  *
87
94
  * An agent node whose original carries its prompts and model on the node is
@@ -114,6 +121,9 @@ export interface MergeOptions {
114
121
  * the same id, because the edit took the SDK's version;
115
122
  * - a merged edge whose `sourcePort` is not a handle its source node declares,
116
123
  * and two merged binding rows for the same resource property;
124
+ * - a node output declaration or definition an older SDK wrote wrongly, which
125
+ * merge replaced with the edited compile's (merge-superseded-outputs.ts);
126
+ * never refused;
117
127
  * - an edited agent whose original carries its prompts and model on the node
118
128
  * (embedded): merge keeps them and applies only the node change, so a prompt
119
129
  * or model edit in the source is not carried. Under `strict` it refuses a
package/dist/merge.js CHANGED
@@ -82,6 +82,13 @@
82
82
  * checked for an edge that leaves a handle its kept source node does not
83
83
  * declare. See merge-roundtrip.ts.
84
84
  *
85
+ * ## A superseded output declaration is replaced
86
+ *
87
+ * A node's `outputs`, `variables.nodes` entries and definition are derived from
88
+ * its type's definition, so merge keeps the original's. Where an older SDK
89
+ * wrote them wrongly and the node type says so (`supersededOutputs`), merge
90
+ * writes the edited compile's instead. See merge-superseded-outputs.ts.
91
+ *
85
92
  * ## An embedded agent stays embedded
86
93
  *
87
94
  * An agent node whose original carries its prompts and model on the node is
@@ -97,6 +104,7 @@ import { placeAddedNodes, stripPlaceholderFlag, unplacedRule } from './node-plac
97
104
  import { mergeAgentSidecars } from './merge-sidecars.js';
98
105
  import { embeddedAgentFindings, isEmbeddedAgent, mergeEmbeddedAgentNode } from './merge-embedded-agent.js';
99
106
  import { mergeObject, mergeVariables, stableJson } from './merge-variables.js';
107
+ import { replaceSupersededOutputs } from './merge-superseded-outputs.js';
100
108
  import { byId, isKept, nodeUnchanged, subflowsTakenFromEdited } from './edit-scope.js';
101
109
  export { MergeRefusedError } from './merge-roundtrip.js';
102
110
  /**
@@ -624,10 +632,14 @@ function mergeFlowFindings(original, edited, options) {
624
632
  if (options.baseline && edited.version !== undefined && edited.version !== options.baseline.version) {
625
633
  result.version = edited.version;
626
634
  }
635
+ // ── Output declarations an older SDK wrote wrongly: the edited compile's,
636
+ // not the original's (merge-superseded-outputs.ts). ──
637
+ const superseded = replaceSupersededOutputs(result, edited);
627
638
  // ── What the no-edit round trip changed, and what mixing sources broke. ──
628
639
  // The caller warns them, or refuses under strict (`reportOrRefuse`).
629
640
  const findings = [
630
- ...(options.baseline ? roundTripFindings(original, options.baseline, result) : []),
641
+ ...superseded.findings,
642
+ ...(options.baseline ? roundTripFindings(original, options.baseline, result, superseded.rootVariables) : []),
631
643
  ...mergedFileFindings(result, original),
632
644
  ];
633
645
  const agentFindings = (authored) => embeddedAgentFindings(!!options.baseline, [
@@ -0,0 +1,61 @@
1
+ /**
2
+ * What the Extract document node (`uipath.ixp.extract-document-builder`,
3
+ * `dynamicExtract()`) publishes, and the rule that checks a read of it.
4
+ *
5
+ * The output is a processed document, the shape flow-core's IxP mapper
6
+ * declares (`buildExtractDocumentBuilderNode`):
7
+ *
8
+ * ```
9
+ * $vars.extract.output
10
+ * .version, .type the contract version and 'Extraction'
11
+ * .result.output.<group>.<field> the extracted values, shaped like the taxonomy
12
+ * .result.attribution['/<pointer>'] where each value was read on the page
13
+ * .result.traceContext.{traceId, spanId, folderKey}
14
+ * .taxonomy the schema the run extracted against
15
+ * .metadata.{pipelineRunId, folderKey, traceId, spanId, modelConfig}
16
+ * ```
17
+ *
18
+ * The rule checks the fixed keys only. The group and field names under
19
+ * `result.output` come from the author's taxonomy and are not checked.
20
+ */
21
+ import type { OutputPathRead } from '../../../core/nodes/node-type.js';
22
+ /**
23
+ * One level of the output, as a read sees it: `leaf` is a scalar, `open` is an
24
+ * object the definition gives no closed key list for (any key may be read), and
25
+ * an object lists the keys that exist.
26
+ */
27
+ export type ReadShape = 'leaf' | 'open' | {
28
+ readonly [key: string]: ReadShape;
29
+ };
30
+ /**
31
+ * The processed document's keys, level by level. An object schema with
32
+ * `properties` is a closed level; one without (`result.output`, `taxonomy`, and
33
+ * `result.attribution`, keyed by JSON Pointer such as `'/Net pay'`) is open.
34
+ * One level is open although its schema lists properties: `metadata.modelConfig`
35
+ * "grows with the processor: read the keys you know and tolerate the rest" (its
36
+ * own description). `tests/document-processing.test.ts` derives this table from
37
+ * the bundled `outputDefinition` by the same rule and holds the two equal, so
38
+ * they cannot drift apart.
39
+ */
40
+ export declare const EXTRACT_OUTPUT_SHAPE: {
41
+ readonly [key: string]: ReadShape;
42
+ };
43
+ /**
44
+ * Whether `outputs` (a node's `outputs`, or its definition's `outputDefinition`)
45
+ * is the declaration the SDK bundled for this node before #1987: the
46
+ * published-project extractor's `ExtractionResult` and `Taxonomy`. A file an
47
+ * older SDK compiled carries it in three places: the node's `outputs`, its
48
+ * `variables.nodes` entry and its `definitions[]` entry. The processed document
49
+ * has no `ExtractionResult` key, so the test cannot match a current declaration.
50
+ * Merge replaces it (`supersededOutputs`, merge-superseded-outputs.ts).
51
+ */
52
+ export declare function isLegacyExtractOutputs(outputs: unknown): boolean;
53
+ /**
54
+ * A read of a `dynamicExtract()` step's output: `out('<step>', '<path>')`.
55
+ *
56
+ * Only `output` (and the `error` envelope, which `check` handles before this
57
+ * rule) exists on the step. Under `output`, each segment of the path must name
58
+ * a key of {@link EXTRACT_OUTPUT_SHAPE} until it reaches an open level or a
59
+ * scalar; past that nothing is checked. A miss is undefined at run time.
60
+ */
61
+ export declare function checkExtractRead({ node: name, field, rest, reader: step }: OutputPathRead, report: (code: string, message: string, suggestion?: string) => void): void;