@uipath/maestro-builder-sdk 6.86.22 → 6.86.24

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.
@@ -68,18 +68,54 @@ export declare function connectionResources(flow: unknown): BindingsV2Resource[]
68
68
  * "Folder"` and no `SolutionsSupport`.
69
69
  */
70
70
  export declare function entityResources(flow: unknown): BindingsV2Resource[];
71
+ /**
72
+ * The connection and `Entity` rows of the flows a Flow project declares in
73
+ * `bindings_v2.json` — the union over `flows`, in the order given.
74
+ *
75
+ * The sidecar is one file per project, written by whichever compile ran last,
76
+ * so it is derived from the project's flows as they stand on disk — normally
77
+ * just the main one, the flow pack deploys — and not from the compiled flow
78
+ * alone (#1381). Each `.flow` is read the way pack derives a package's rows
79
+ * from it.
80
+ *
81
+ * A connection two flows use is one row, the first flow's (the key is compared
82
+ * case-insensitively, as `uip agent refresh` does). A flow whose rows cannot be
83
+ * derived — the file does not parse, or two of its nodes type one connection
84
+ * differently — is listed in `unreadable` and contributes nothing; the caller
85
+ * must then keep the rows already on disk, since some of them may be its.
86
+ *
87
+ * @param flows - The flows to declare, in a stable order.
88
+ * @returns The rows, and the files whose rows could not be derived.
89
+ */
90
+ export declare function projectBindingRows(flows: ReadonlyArray<{
91
+ file: string;
92
+ flow: unknown;
93
+ }>): {
94
+ connections: BindingsV2Resource[];
95
+ entities: BindingsV2Resource[];
96
+ unreadable: string[];
97
+ };
71
98
  /**
72
99
  * Fold freshly derived connection and entity rows into whatever the project
73
100
  * already has.
74
101
  *
75
- * Connection and `Entity` rows are replaced wholesale — they are re-derived from the flow that
76
- * was just compiled, so the compile is the newer truth. Every other row is
102
+ * Connection and `Entity` rows are replaced wholesale — they are re-derived from
103
+ * the project's flows ({@link projectBindingRows}), so the compile is the newer
104
+ * truth, and a row no declared flow uses is dropped. Every other row is
77
105
  * carried through in its original order, because this module does not derive
78
106
  * those kinds and dropping them would silently delete a `TimeTrigger` (or
79
107
  * anything a future generator adds) that `node configure` or an earlier `pack`
80
108
  * had put there.
109
+ *
110
+ * `keepUnderived` is for a project where some flow's rows could not be derived
111
+ * (`unreadable` above): the existing connection and `Entity` rows that were not
112
+ * re-derived are then kept too, in place, because they may be that flow's. A
113
+ * stale row only declares a connection nothing uses; a lost one leaves a flow's
114
+ * connection undeclared.
81
115
  */
82
- export declare function mergeBindingsV2(existing: unknown, connections: BindingsV2Resource[], entities?: BindingsV2Resource[]): BindingsV2Document;
116
+ export declare function mergeBindingsV2(existing: unknown, connections: BindingsV2Resource[], entities?: BindingsV2Resource[], options?: {
117
+ keepUnderived?: boolean;
118
+ }): BindingsV2Document;
83
119
  /** The files of one inline agent, as `uip agent refresh` reads them. */
84
120
  export interface InlineAgentFiles {
85
121
  /** `<agent>/agent.json`. */
@@ -127,7 +163,7 @@ export declare function mergeInlineAgentResources(existing: BindingsV2Resource[]
127
163
  * declared and a deploy could still fail on it. They are generated by the same
128
164
  * function, so they match exactly, and a row a remaining resource still
129
165
  * declares is kept. Connection rows are not touched here: compile re-derives
130
- * them from the flow ({@link connectionResources}).
166
+ * them from the project's flows ({@link projectBindingRows}).
131
167
  *
132
168
  * @param resources - The project's current rows.
133
169
  * @param agents - Every inline agent's files, as they now stand.
@@ -34,8 +34,10 @@
34
34
  *
35
35
  * Two kinds of row, each copied from the generator that owns it:
36
36
  *
37
- * - `connection` rows for the flow's own connector steps — what pack derives,
38
- * and what #689 is about ({@link connectionResources}).
37
+ * - `connection` rows for the connector steps of the project's main flow —
38
+ * what pack derives, and what #689 is about ({@link connectionResources}).
39
+ * The file is one per project, whichever `.flow` was compiled
40
+ * ({@link projectBindingRows}, #1381).
39
41
  * - `Entity` rows for the flow's folder-scoped Data Fabric steps, which
40
42
  * `uip solution resources refresh` turns into the solution's entity
41
43
  * resource ({@link entityResources}, #1463).
@@ -311,22 +313,79 @@ export function entityResources(flow) {
311
313
  }
312
314
  return resources;
313
315
  }
316
+ /**
317
+ * The connection and `Entity` rows of the flows a Flow project declares in
318
+ * `bindings_v2.json` — the union over `flows`, in the order given.
319
+ *
320
+ * The sidecar is one file per project, written by whichever compile ran last,
321
+ * so it is derived from the project's flows as they stand on disk — normally
322
+ * just the main one, the flow pack deploys — and not from the compiled flow
323
+ * alone (#1381). Each `.flow` is read the way pack derives a package's rows
324
+ * from it.
325
+ *
326
+ * A connection two flows use is one row, the first flow's (the key is compared
327
+ * case-insensitively, as `uip agent refresh` does). A flow whose rows cannot be
328
+ * derived — the file does not parse, or two of its nodes type one connection
329
+ * differently — is listed in `unreadable` and contributes nothing; the caller
330
+ * must then keep the rows already on disk, since some of them may be its.
331
+ *
332
+ * @param flows - The flows to declare, in a stable order.
333
+ * @returns The rows, and the files whose rows could not be derived.
334
+ */
335
+ export function projectBindingRows(flows) {
336
+ const connections = [];
337
+ const entities = [];
338
+ const unreadable = [];
339
+ const seen = new Set();
340
+ for (const { file, flow } of flows) {
341
+ let rows;
342
+ try {
343
+ if (!isRecord(flow))
344
+ throw new Error('not a flow');
345
+ rows = [...connectionResources(flow), ...entityResources(flow)];
346
+ }
347
+ catch {
348
+ unreadable.push(file);
349
+ continue;
350
+ }
351
+ for (const row of rows) {
352
+ const id = mergeIdentity(row);
353
+ if (seen.has(id))
354
+ continue;
355
+ seen.add(id);
356
+ (isConnection(row.resource) ? connections : entities).push(row);
357
+ }
358
+ }
359
+ return { connections, entities, unreadable };
360
+ }
314
361
  /**
315
362
  * Fold freshly derived connection and entity rows into whatever the project
316
363
  * already has.
317
364
  *
318
- * Connection and `Entity` rows are replaced wholesale — they are re-derived from the flow that
319
- * was just compiled, so the compile is the newer truth. Every other row is
365
+ * Connection and `Entity` rows are replaced wholesale — they are re-derived from
366
+ * the project's flows ({@link projectBindingRows}), so the compile is the newer
367
+ * truth, and a row no declared flow uses is dropped. Every other row is
320
368
  * carried through in its original order, because this module does not derive
321
369
  * those kinds and dropping them would silently delete a `TimeTrigger` (or
322
370
  * anything a future generator adds) that `node configure` or an earlier `pack`
323
371
  * had put there.
372
+ *
373
+ * `keepUnderived` is for a project where some flow's rows could not be derived
374
+ * (`unreadable` above): the existing connection and `Entity` rows that were not
375
+ * re-derived are then kept too, in place, because they may be that flow's. A
376
+ * stale row only declares a connection nothing uses; a lost one leaves a flow's
377
+ * connection undeclared.
324
378
  */
325
- export function mergeBindingsV2(existing, connections, entities = []) {
379
+ export function mergeBindingsV2(existing, connections, entities = [], options = {}) {
326
380
  const previous = isRecord(existing) && Array.isArray(existing.resources)
327
381
  ? existing.resources.filter(isRecord)
328
382
  : [];
329
- const preserved = previous.filter((r) => !isConnection(r.resource) && !isEntity(r.resource));
383
+ const derived = new Set([...connections, ...entities].map(mergeIdentity));
384
+ const preserved = previous.filter((r) => {
385
+ if (!isConnection(r.resource) && !isEntity(r.resource))
386
+ return true;
387
+ return options.keepUnderived === true && !derived.has(mergeIdentity(r));
388
+ });
330
389
  const version = (isRecord(existing) && nonEmptyString(existing.version)) || DOCUMENT_VERSION;
331
390
  return { version, resources: [...connections, ...entities, ...preserved] };
332
391
  }
@@ -580,7 +639,7 @@ export function mergeInlineAgentResources(existing, fresh) {
580
639
  * declared and a deploy could still fail on it. They are generated by the same
581
640
  * function, so they match exactly, and a row a remaining resource still
582
641
  * declares is kept. Connection rows are not touched here: compile re-derives
583
- * them from the flow ({@link connectionResources}).
642
+ * them from the project's flows ({@link projectBindingRows}).
584
643
  *
585
644
  * @param resources - The project's current rows.
586
645
  * @param agents - Every inline agent's files, as they now stand.
@@ -33,6 +33,7 @@ import { flagValue, runWhenInvokedDirectly } from '../cli-run.js';
33
33
  import { ensureTypeScriptRuntime } from '../node-runtime.js';
34
34
  import { CASE_FORMAT_PROFILE } from './format-profile.js';
35
35
  import { deriveCaseBindingsV2 } from './bindings-v2.js';
36
+ import { orphanWarnings } from './orphaned-resources.js';
36
37
  import { BINDINGS_V2_DOCUMENT_VERSION } from '../core/bindings-v2-resource.js';
37
38
  import { sha256Uuid } from '../core/stable-id.js';
38
39
  export async function run(argv) {
@@ -88,6 +89,8 @@ export async function run(argv) {
88
89
  // (`reportCompileRefusal`, shared with Flow and BPMN).
89
90
  return reportCompileRefusal(error, { before: warnings });
90
91
  }
92
+ // Solution declarations no project binds once this derivation lands.
93
+ warnings.push(...orphanWarnings(caseplan, out));
91
94
  for (const w of warnings)
92
95
  console.error(` ${diagnosticLine(w)}`);
93
96
  // Reported before the first write, so a write that throws still carries it.
@@ -0,0 +1,3 @@
1
+ import type { Diagnostic } from './check.js';
2
+ /** Warnings for the solution declarations of `outPath`'s solution that no project binds. */
3
+ export declare function orphanWarnings(caseplan: Record<string, unknown>, outPath: string): Diagnostic[];
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Solution declarations no project binds any more (ORPHANED_SOLUTION_RESOURCE).
3
+ *
4
+ * `case compile` rewrites the project's `bindings_v2.json` from the source, so
5
+ * a resource-bound task removed from the source drops its row. Its declaration
6
+ * under `<solution>/resources/solution_folder/` stays: `uip solution resources
7
+ * refresh` only adds, `uip maestro case validate` reads neither file, and
8
+ * Studio Web provisioning fails on the unreferenced resource. Compile is the
9
+ * authoring step that runs after every edit, so it reports what is left.
10
+ *
11
+ * The orphans are derived from the solution as it is, not from the rows this
12
+ * compile dropped, so a recompile keeps reporting a declaration until it is
13
+ * removed. A declaration is reported when all of these hold:
14
+ * - its kind is one a sidecar binds (`process`, `app`); queues, assets and the
15
+ * rest never appear in `bindings_v2.json`, so their absence there means nothing;
16
+ * - it is not a project's own declaration (it carries no `projectKey`);
17
+ * - it is not a package (removing the process or app removes its package);
18
+ * - no project of the solution binds its kind and name (this Case's new
19
+ * derivation, or another project's `bindings_v2.json`), and no bound
20
+ * declaration depends on it: refresh imports an Action App's `webApp`
21
+ * process as a dependency of the app, and the sidecar names only the app.
22
+ *
23
+ * Identity is kind + name. A declaration's `folders` is the solution folder,
24
+ * not the tenant folder the binding names, so the tenant folder cannot be
25
+ * compared; the solution itself keys declarations by kind and name.
26
+ */
27
+ import { readFileSync, readdirSync, existsSync } from 'node:fs';
28
+ import { join, dirname, resolve } from 'node:path';
29
+ import { deriveCaseBindingsV2 } from './bindings-v2.js';
30
+ import { solutionRoot } from '../registry/prepare/resources.js';
31
+ const BOUND_KINDS = new Set(['process', 'app']);
32
+ const identity = (kind, name) => typeof kind === 'string' && typeof name === 'string' ? `${kind.toLowerCase()}\u0000${name}` : undefined;
33
+ /** Warnings for the solution declarations of `outPath`'s solution that no project binds. */
34
+ export function orphanWarnings(caseplan, outPath) {
35
+ const projectDir = dirname(resolve(outPath));
36
+ const solutionDir = solutionRoot(projectDir);
37
+ if (!solutionDir)
38
+ return [];
39
+ const declarations = solutionDeclarations(join(solutionDir, 'resources', 'solution_folder'));
40
+ if (declarations.length === 0)
41
+ return [];
42
+ const bound = new Set();
43
+ for (const r of deriveCaseBindingsV2(caseplan)) {
44
+ const id = identity(r?.resource, r?.value?.name?.defaultValue);
45
+ if (id)
46
+ bound.add(id);
47
+ }
48
+ for (const other of otherProjectDirs(solutionDir, projectDir)) {
49
+ const path = join(other, 'bindings_v2.json');
50
+ if (!existsSync(path))
51
+ continue;
52
+ const rows = readSidecar(path);
53
+ if (typeof rows === 'string') {
54
+ return [{
55
+ level: 'warning',
56
+ code: 'ORPHANED_SOLUTION_RESOURCE',
57
+ message: `cannot read ${path} (${rows}); orphaned solution declarations were not checked.`,
58
+ }];
59
+ }
60
+ for (const r of rows) {
61
+ const id = identity(r?.resource, r?.value?.name?.defaultValue);
62
+ if (id)
63
+ bound.add(id);
64
+ }
65
+ }
66
+ // Whatever a bound declaration depends on, transitively, is bound too.
67
+ const byId = new Map(declarations.map((d) => [identity(d.kind, d.name), d]));
68
+ const queue = [...bound];
69
+ while (queue.length > 0) {
70
+ for (const dep of byId.get(queue.pop())?.dependsOn ?? []) {
71
+ if (!bound.has(dep)) {
72
+ bound.add(dep);
73
+ queue.push(dep);
74
+ }
75
+ }
76
+ }
77
+ const quoted = JSON.stringify(solutionDir);
78
+ return declarations
79
+ .filter((d) => BOUND_KINDS.has(d.kind.toLowerCase()) && !d.own && !bound.has(identity(d.kind, d.name)))
80
+ .map((d) => ({
81
+ level: 'warning',
82
+ code: 'ORPHANED_SOLUTION_RESOURCE',
83
+ message: `${d.kind.toLowerCase()} "${d.name}" is declared in ${d.path}, but no project of the solution binds it. ` +
84
+ `resources refresh only adds and validate does not read it, so it would ship and fail Studio Web provisioning.`,
85
+ suggestion: `uip solution resources remove ${d.key} --solution-folder ${quoted} --output json ` +
86
+ `(removes its package declaration too), then uip solution resources refresh --solution-folder ${quoted} --output json`,
87
+ }));
88
+ }
89
+ /** The sidecar's rows, or the reason it cannot be read. */
90
+ function readSidecar(path) {
91
+ try {
92
+ const doc = JSON.parse(readFileSync(path, 'utf8'));
93
+ return Array.isArray(doc?.resources) ? doc.resources : [];
94
+ }
95
+ catch (error) {
96
+ return error instanceof Error ? error.message : String(error);
97
+ }
98
+ }
99
+ /** The other projects the solution manifest registers. */
100
+ function otherProjectDirs(solutionDir, projectDir) {
101
+ const dirs = [];
102
+ for (const name of readdirSync(solutionDir).filter((n) => n.endsWith('.uipx'))) {
103
+ try {
104
+ const manifest = JSON.parse(readFileSync(join(solutionDir, name), 'utf8'));
105
+ for (const p of Array.isArray(manifest?.Projects) ? manifest.Projects : []) {
106
+ if (typeof p?.ProjectRelativePath !== 'string')
107
+ continue;
108
+ const dir = resolve(solutionDir, dirname(p.ProjectRelativePath));
109
+ if (dir !== projectDir)
110
+ dirs.push(dir);
111
+ }
112
+ }
113
+ catch {
114
+ // An unreadable manifest names no other project.
115
+ }
116
+ }
117
+ return dirs;
118
+ }
119
+ /** Every non-package declaration under `resources/solution_folder/`, with its dependency edges. */
120
+ function solutionDeclarations(root) {
121
+ const found = [];
122
+ const walk = (dir) => {
123
+ let entries;
124
+ try {
125
+ entries = readdirSync(dir, { withFileTypes: true });
126
+ }
127
+ catch {
128
+ return;
129
+ }
130
+ for (const e of entries) {
131
+ const path = join(dir, e.name);
132
+ if (e.isDirectory()) {
133
+ if (dir === root && e.name.toLowerCase() === 'package')
134
+ continue;
135
+ walk(path);
136
+ }
137
+ else if (e.name.endsWith('.json')) {
138
+ try {
139
+ const r = JSON.parse(readFileSync(path, 'utf8'))?.resource ?? {};
140
+ // `resources remove` takes the solution key, `resource.key` (a GUID), not the sidecar key.
141
+ if (typeof r.kind !== 'string' || typeof r.name !== 'string' || typeof r.key !== 'string')
142
+ continue;
143
+ const dependsOn = (Array.isArray(r.dependencies) ? r.dependencies : [])
144
+ .map((d) => identity(d?.kind, d?.name))
145
+ .filter((id) => id !== undefined);
146
+ found.push({ kind: r.kind, name: r.name, key: r.key, path, own: r.projectKey !== undefined, dependsOn });
147
+ }
148
+ catch {
149
+ // Not a declaration.
150
+ }
151
+ }
152
+ }
153
+ };
154
+ walk(root);
155
+ return found.sort((a, b) => a.path.localeCompare(b.path));
156
+ }
@@ -32,13 +32,13 @@ import { compileOwnsResource } from './core/agent-tool-resources.js';
32
32
  import { openCliLibrary } from './cli-library.js';
33
33
  import { Bindings } from './bindings.js';
34
34
  import { flagValue, runWhenInvokedDirectly } from './cli-run.js';
35
- import { connectionResources, entityResources, inlineAgentResources, mergeBindingsV2, refreshInlineAgentRows } from './bindings-v2.js';
35
+ import { connectionResources, inlineAgentResources, mergeBindingsV2, projectBindingRows, refreshInlineAgentRows } from './bindings-v2.js';
36
36
  import { readBindingsV2, readInlineAgentFiles } from './bindings-v2-files.js';
37
37
  import { ensureTypeScriptRuntime } from './node-runtime.js';
38
38
  import { defaultBindingsFile, defaultResourcesFile } from './workdir.js';
39
39
  import { readCliResources } from './registry/prepare/resources.js';
40
40
  import { isWithin, physicalPath } from './path-within.js';
41
- import { flowSources, resourceSourcesOfOtherFlows } from './project-resource-users.js';
41
+ import { flowSources, projectMainFlow, resourceSourcesOfOtherFlows } from './project-resource-users.js';
42
42
  import { fnv1aX4Uuid } from './core/stable-id.js';
43
43
  import { cliSpelling } from './core/cli-spelling.js';
44
44
  /** An agent folder name: a uuid, any case. */
@@ -296,25 +296,71 @@ export async function run(argv) {
296
296
  // with a resource declaration nothing reads would be worse than not writing it.
297
297
  if (existsSync(join(outDir, 'project.uiproj'))) {
298
298
  const sidecarPath = join(outDir, 'bindings_v2.json');
299
- const connections = connectionResources(flowJson);
300
- // The folder-scoped Data Fabric entities, from the two `Entity` bindings each
301
- // step carries — what declares the entity in the solution (#1463).
302
- const entityRows = entityResources(flowJson);
299
+ // A connection two of this flow's nodes type differently is refused here,
300
+ // whichever flow the sidecar declares.
301
+ connectionResources(flowJson);
302
+ // The sidecar is one per PROJECT and declares the flow the project runs:
303
+ // the one `uip` packs, debugs and refreshes resources from
304
+ // (`projectMainFlow`). Any other `.flow` in the project is never deployed,
305
+ // so its connections are not declared, and compiling it leaves the main
306
+ // flow's rows as they are (#1381). Only when the project holds several
307
+ // `.flow` files and none is the main one is every one of them declared:
308
+ // pack would take whichever the file system lists first.
309
+ const self = resolve(out);
310
+ const ownFile = basename(self);
311
+ const main = projectMainFlow(outDir);
312
+ const flowAt = (path) => ({
313
+ file: relative(outDir, path),
314
+ flow: resolve(path) === self ? flowJson : readJsonOrUndefined(path),
315
+ });
316
+ const rowFlows = main.file !== undefined
317
+ ? [flowAt(main.file)]
318
+ : main.ambiguous.length > 0 ? main.ambiguous.map(flowAt) : [{ file: ownFile, flow: flowJson }];
319
+ if (main.file !== undefined && resolve(main.file) !== self) {
320
+ console.log(`compile: ${ownFile} is not this project's main flow (${rowFlows[0].file}, the one pack deploys); `
321
+ + `bindings_v2.json declares ${rowFlows[0].file}'s connections, not ${ownFile}'s`);
322
+ }
323
+ else if (main.ambiguous.length > 1) {
324
+ console.error(`compile: this project holds several .flow files and none is its main one (${rowFlows.map((f) => f.file).join(', ')}); `
325
+ + 'bindings_v2.json declares the connections of all of them. Set "MainFile" in project.uiproj, '
326
+ + 'or keep only the flow you deploy in the project, so pack and refresh read the flow you mean.');
327
+ }
328
+ // Connections, and the folder-scoped Data Fabric entities from the two
329
+ // `Entity` bindings each step carries — what declares the entity in the
330
+ // solution (#1463).
331
+ const { connections, entities: entityRows, unreadable } = projectBindingRows(rowFlows);
332
+ for (const file of unreadable) {
333
+ console.error(`compile: could not read the connections of ${file}; keeping the bindings_v2.json rows this compile does not derive, `
334
+ + 'since some may be its. Fix or recompile that flow to re-derive them.');
335
+ }
303
336
  const existing = readBindingsV2(sidecarPath);
304
337
  // Each inline agent's own rows (process, index, app, … — #962), derived from
305
338
  // the agent directory as it now stands on disk, the way `uip agent refresh
306
339
  // --inline-in-flow` derives them. `uip agent validate --inline-in-flow`
307
340
  // requires every one of them, so leaving them to a refresh the SDK route
308
341
  // never runs made every agent with a deployed-resource tool, a context index
309
- // or an app escalation fail validate with `AgentValidationDrift`.
310
- const agentFiles = agentDirs
342
+ // or an app escalation fail validate with `AgentValidationDrift`. The
343
+ // agents of the flows declared above are re-derived too, since the merge
344
+ // below re-derives every connection row, their agents' included (#1381).
345
+ // This flow's own agents are kept as well: pack ships every agent folder
346
+ // in the project (`processAgents`), not only the main flow's.
347
+ const declaresSelf = rowFlows.some((f) => resolve(outDir, f.file) === self);
348
+ const projectAgentDirs = [...new Set([
349
+ ...rowFlows.flatMap((f) => (resolve(outDir, f.file) === self
350
+ ? agentDirs
351
+ : flowSources(f.flow)
352
+ .map((src) => resolve(outDir, src))
353
+ .filter((dir) => isWithin(outDir, dir) && existsSync(join(dir, 'agent.json'))))),
354
+ ...(declaresSelf ? [] : agentDirs),
355
+ ])];
356
+ const agentFiles = projectAgentDirs
311
357
  .map((dir) => readInlineAgentFiles(dir))
312
358
  .filter((files) => files !== undefined);
313
359
  const agentRows = agentFiles.map((files) => inlineAgentResources(files));
314
360
  // Nothing to declare and nothing already declared — do not create an empty
315
361
  // file for a flow that has no resources at all.
316
362
  if (connections.length > 0 || entityRows.length > 0 || existing !== undefined || agentRows.some((rows) => rows.length > 0)) {
317
- const merged = mergeBindingsV2(existing, connections, entityRows);
363
+ const merged = mergeBindingsV2(existing, connections, entityRows, { keepUnderived: unreadable.length > 0 });
318
364
  merged.resources = refreshInlineAgentRows(merged.resources, agentFiles, removedResources);
319
365
  writeJsonFile(sidecarPath, merged);
320
366
  const derived = new Set([...connections, ...entityRows, ...agentRows.flat()].map((r) => `${r.resource}\u0000${r.key}`));
@@ -555,6 +555,7 @@ export declare const REFUSALS: {
555
555
  readonly NO_START: "lint";
556
556
  readonly OBJECT_UNPREPARED: "lint";
557
557
  readonly ONERROR_NO_ERROR_PORT: "lowering";
558
+ readonly ORPHANED_SOLUTION_RESOURCE: "lint";
558
559
  readonly OUTPUT_BACKING_COLLISION: "lowering";
559
560
  readonly OUTPUT_FORWARD_READ: "lint";
560
561
  readonly OUTPUT_ROWS_FIXED: "lint";
@@ -628,6 +628,7 @@ export const REFUSALS = {
628
628
  NO_START: 'lint',
629
629
  OBJECT_UNPREPARED: 'lint',
630
630
  ONERROR_NO_ERROR_PORT: 'lowering',
631
+ ORPHANED_SOLUTION_RESOURCE: 'lint',
631
632
  OUTPUT_BACKING_COLLISION: 'lowering',
632
633
  OUTPUT_FORWARD_READ: 'lint',
633
634
  OUTPUT_ROWS_FIXED: 'lint',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The `inputs.source` uuids the OTHER `.flow` files in `dir` reference, each
3
- * mapped to the first file that does. `dir` is the namespace sidecar paths are
3
+ * mapped to the first file (by name) that does. `dir` is the namespace sidecar paths are
4
4
  * relative to, so these are the agent resources another flow still uses. The
5
5
  * flow being written (`self`) is left out: what it no longer references is what
6
6
  * pruning is for. Subflow bodies are included; an unreadable file contributes
@@ -15,3 +15,22 @@ export declare function resourceSourcesOfOtherFlows(dir: string, self: string):
15
15
  * two cannot disagree on where a node keeps its source.
16
16
  */
17
17
  export declare function flowSources(flow: unknown): string[];
18
+ /**
19
+ * The `.flow` a Flow project runs, picked the way `uip` picks it for pack,
20
+ * debug, validate and `uip solution resources refresh` (`scanProjectFlowFile`
21
+ * in the CLI's packager-tool-flow `flow-io.ts`): `project.uiproj`'s `MainFile`
22
+ * when it names an existing `.flow` inside the project, else `<Name>.flow`
23
+ * (the name with every character outside `[A-Za-z0-9_-]` made `_`, compared
24
+ * case-insensitively) in the root, `content/` or `flow_files/`, else the
25
+ * first folder of those three that holds a `.flow`, when it holds just one. Only that one file is packed and deployed; any other
26
+ * `.flow` in the project is never run.
27
+ *
28
+ * When that folder holds several and none is the main one, the CLI takes the
29
+ * first in directory order, which is not stable. That case answers
30
+ * `{ file: undefined, ambiguous: [...] }` (absolute paths, sorted) instead of
31
+ * guessing; no `.flow` at all answers `{ file: undefined, ambiguous: [] }`.
32
+ */
33
+ export declare function projectMainFlow(dir: string): {
34
+ file: string | undefined;
35
+ ambiguous: string[];
36
+ };
@@ -3,12 +3,15 @@
3
3
  * use a sidecar directory. Compile's prune and merge's resource removal both
4
4
  * must leave such a directory alone: a decompiled canvas agent keeps its
5
5
  * `source` directory, so two flows in one project can share it (#1151, #1184).
6
+ * Compile's `bindings_v2.json` write reads the same files: the sidecar is one
7
+ * per project, so it declares the project's main flow ({@link projectMainFlow}),
8
+ * whichever `.flow` was compiled (#1381).
6
9
  */
7
- import { readdirSync, readFileSync } from 'node:fs';
8
- import { join, resolve } from 'node:path';
10
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
11
+ import { isAbsolute, join, relative, resolve } from 'node:path';
9
12
  /**
10
13
  * The `inputs.source` uuids the OTHER `.flow` files in `dir` reference, each
11
- * mapped to the first file that does. `dir` is the namespace sidecar paths are
14
+ * mapped to the first file (by name) that does. `dir` is the namespace sidecar paths are
12
15
  * relative to, so these are the agent resources another flow still uses. The
13
16
  * flow being written (`self`) is left out: what it no longer references is what
14
17
  * pruning is for. Subflow bodies are included; an unreadable file contributes
@@ -16,26 +19,36 @@ import { join, resolve } from 'node:path';
16
19
  */
17
20
  export function resourceSourcesOfOtherFlows(dir, self) {
18
21
  const users = new Map();
22
+ for (const { file, flow } of otherFlows(dir, self)) {
23
+ for (const src of flowSources(flow))
24
+ if (!users.has(src))
25
+ users.set(src, file);
26
+ }
27
+ return users;
28
+ }
29
+ /**
30
+ * The OTHER `.flow` files in `dir`, sorted by name so every reader sees them in
31
+ * the same order whatever order the file system lists them in. `self` (an
32
+ * absolute path) is left out. A file that cannot be read or parsed is listed
33
+ * with `flow: undefined`, so a caller that must not lose another flow's state
34
+ * can tell "this flow declares nothing" from "this flow could not be read".
35
+ */
36
+ function otherFlows(dir, self) {
19
37
  let entries;
20
38
  try {
21
- entries = readdirSync(dir).filter((f) => f.endsWith('.flow') && resolve(dir, f) !== self);
39
+ entries = readdirSync(dir).filter((f) => f.endsWith('.flow') && resolve(dir, f) !== self).sort();
22
40
  }
23
41
  catch {
24
- return users;
42
+ return [];
25
43
  }
26
- for (const f of entries) {
27
- let flow;
44
+ return entries.map((file) => {
28
45
  try {
29
- flow = JSON.parse(readFileSync(join(dir, f), 'utf8'));
46
+ return { file, flow: JSON.parse(readFileSync(join(dir, file), 'utf8')) };
30
47
  }
31
48
  catch {
32
- continue;
49
+ return { file, flow: undefined };
33
50
  }
34
- for (const src of flowSources(flow))
35
- if (!users.has(src))
36
- users.set(src, f);
37
- }
38
- return users;
51
+ });
39
52
  }
40
53
  /**
41
54
  * Every `inputs.source` string a flow's nodes name — agent folders and agent
@@ -59,3 +72,63 @@ export function flowSources(flow) {
59
72
  walk(flow);
60
73
  return ids;
61
74
  }
75
+ /**
76
+ * The `.flow` a Flow project runs, picked the way `uip` picks it for pack,
77
+ * debug, validate and `uip solution resources refresh` (`scanProjectFlowFile`
78
+ * in the CLI's packager-tool-flow `flow-io.ts`): `project.uiproj`'s `MainFile`
79
+ * when it names an existing `.flow` inside the project, else `<Name>.flow`
80
+ * (the name with every character outside `[A-Za-z0-9_-]` made `_`, compared
81
+ * case-insensitively) in the root, `content/` or `flow_files/`, else the
82
+ * first folder of those three that holds a `.flow`, when it holds just one. Only that one file is packed and deployed; any other
83
+ * `.flow` in the project is never run.
84
+ *
85
+ * When that folder holds several and none is the main one, the CLI takes the
86
+ * first in directory order, which is not stable. That case answers
87
+ * `{ file: undefined, ambiguous: [...] }` (absolute paths, sorted) instead of
88
+ * guessing; no `.flow` at all answers `{ file: undefined, ambiguous: [] }`.
89
+ */
90
+ export function projectMainFlow(dir) {
91
+ let uiproj;
92
+ try {
93
+ uiproj = JSON.parse(readFileSync(join(dir, 'project.uiproj'), 'utf8'));
94
+ }
95
+ catch {
96
+ uiproj = undefined;
97
+ }
98
+ const mainFile = typeof uiproj?.MainFile === 'string' ? uiproj.MainFile : undefined;
99
+ if (mainFile?.endsWith('.flow')) {
100
+ const path = resolve(dir, mainFile);
101
+ const rel = relative(dir, path);
102
+ if (rel !== '' && !/^\.\.(?:[\\/]|$)/.test(rel) && !isAbsolute(rel) && existsSync(path)) {
103
+ return { file: path, ambiguous: [] };
104
+ }
105
+ }
106
+ const preferred = typeof uiproj?.Name === 'string' && uiproj.Name !== ''
107
+ ? `${uiproj.Name.replace(/[^a-zA-Z0-9_-]/g, '_')}.flow`.toLowerCase()
108
+ : undefined;
109
+ const candidates = [];
110
+ let firstFolder;
111
+ for (const sub of ['', 'content', 'flow_files']) {
112
+ const d = join(dir, sub);
113
+ let entries;
114
+ try {
115
+ if (!statSync(d).isDirectory())
116
+ continue;
117
+ entries = readdirSync(d).filter((f) => f.endsWith('.flow')).sort();
118
+ }
119
+ catch {
120
+ continue;
121
+ }
122
+ const named = preferred && entries.find((f) => f.toLowerCase() === preferred);
123
+ if (named)
124
+ return { file: join(d, named), ambiguous: [] };
125
+ if (entries.length > 0)
126
+ firstFolder ??= entries.map((f) => join(d, f));
127
+ candidates.push(...entries.map((f) => join(d, f)));
128
+ }
129
+ // The CLI's fallback is the first `.flow` of the first folder holding one:
130
+ // a fixed answer only when that folder holds exactly one.
131
+ if (firstFolder?.length === 1)
132
+ return { file: firstFolder[0], ambiguous: [] };
133
+ return { file: undefined, ambiguous: candidates };
134
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.86.22",
3
+ "version": "6.86.24",
4
4
  "description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.uipath.com/maestro",
@@ -103,5 +103,5 @@
103
103
  "@types/node": "^22.7.0",
104
104
  "esbuild": "^0.28.1"
105
105
  },
106
- "gitref": "5f41a8dcaad179d995dfe163d6b72120b35a2690"
106
+ "gitref": "d3ec19ada01dd0065c935cda8901d1e142137140"
107
107
  }