@uipath/maestro-builder-sdk 6.120.17 → 6.120.19

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.
@@ -20,6 +20,10 @@
20
20
  * are all readable downstream. `nodeDeclaredVars` supplies them; being stricter
21
21
  * than the platform here would reject working processes.
22
22
  *
23
+ * A declared name is not always a readable one: a process input is scoped to its start
24
+ * event and an output to its end event, and a read of either from another element is
25
+ * `EXPR_ARGUMENT_REF` (#2138, `BpmnRoots.args`).
26
+ *
23
27
  * A loop's item binds `iterator.<itemVar>`, and a script output writes `=result.…`
24
28
  * — different namespaces, left alone (only `vars.` is the author's to get wrong).
25
29
  * Variables are SCOPED: a sub-process sees the enclosing variables plus its own.
@@ -20,13 +20,19 @@
20
20
  * are all readable downstream. `nodeDeclaredVars` supplies them; being stricter
21
21
  * than the platform here would reject working processes.
22
22
  *
23
+ * A declared name is not always a readable one: a process input is scoped to its start
24
+ * event and an output to its end event, and a read of either from another element is
25
+ * `EXPR_ARGUMENT_REF` (#2138, `BpmnRoots.args`).
26
+ *
23
27
  * A loop's item binds `iterator.<itemVar>`, and a script output writes `=result.…`
24
28
  * — different namespaces, left alone (only `vars.` is the author's to get wrong).
25
29
  * Variables are SCOPED: a sub-process sees the enclosing variables plus its own.
26
30
  */
27
- import { checkExpression } from '../core/expr-check.js';
28
- import { nodeDeclaredVars } from './declared-vars.js';
31
+ import { checkExpression, extractRefs } from '../core/expr-check.js';
32
+ import { nodeDeclaredVars, publicDeclarationScope } from './declared-vars.js';
29
33
  import { CompileRefusal } from '../core/compile-refusal.js';
34
+ import { tsLiteral } from '../core/ts-literal.js';
35
+ import { isExpressionValue } from './expression-value.js';
30
36
  const NOUN = 'variable';
31
37
  const NAMESPACE = 'vars';
32
38
  const BINDING_NOUN = 'binding';
@@ -36,6 +42,7 @@ function checkExpr(expr, where, roots, out) {
36
42
  return;
37
43
  for (const d of checkExpression(expr, { roots: roots.vars, noun: NOUN, namespace: NAMESPACE }))
38
44
  out.push({ ...d, where });
45
+ argumentReads(expr, where, roots, out);
39
46
  for (const d of checkExpression(expr, { roots: roots.bindings, noun: BINDING_NOUN, namespace: BINDING_NAMESPACE }))
40
47
  out.push({ ...d, where });
41
48
  // A process variable is always read through the `vars` namespace. The bare
@@ -56,7 +63,55 @@ function checkExpr(expr, where, roots, out) {
56
63
  }
57
64
  }
58
65
  /**
59
- * Check every `=`-expression VALUE of a `field → expression` map (keys are targets).
66
+ * Report each read of a process argument — see {@link BpmnRoots.args}. One finding
67
+ * per argument per expression, naming the form that IS readable: the start-event
68
+ * mapping into a process variable for an input, the variable the end event maps from
69
+ * for an output.
70
+ */
71
+ function argumentReads(expr, where, roots, out) {
72
+ if (!roots.args.size)
73
+ return;
74
+ const seen = new Set();
75
+ for (const ref of extractRefs(expr, NAMESPACE)) {
76
+ const arg = roots.args.get(ref.root);
77
+ if (!arg || seen.has(arg.decl.id))
78
+ continue;
79
+ seen.add(arg.decl.id);
80
+ out.push({ level: 'error', code: 'EXPR_ARGUMENT_REF', message: argumentMessage(ref.root, arg), where });
81
+ }
82
+ }
83
+ function argumentMessage(root, { decl, scope }) {
84
+ const type = typeof decl.type === 'string' ? decl.type : 'string';
85
+ if (decl.direction === 'output') {
86
+ return (`\`vars.${root}\` reads process output \`${decl.id}\`, which is scoped to \`${scope}\` and only ` +
87
+ `written by its mapping: Studio Web reports "A variable is unresolved" on a read of it, and ` +
88
+ `\`validate\` reports VARIABLE_DOES_NOT_EXIST. Compute the value into a \`.var()\`, read that variable here, ` +
89
+ `and map it onto \`${decl.id}\` in \`${scope}\`'s payload.`);
90
+ }
91
+ const local = `${decl.id}In`;
92
+ return (`\`vars.${root}\` reads process input \`${decl.id}\`, which is scoped to \`${scope}\`: Studio Web ` +
93
+ `reports "A variable is unresolved" on a read of it from any other element, and \`validate\` reports ` +
94
+ `VARIABLE_NOT_SET (the engine runs it; the designer does not accept it). Map it, as the canvas ` +
95
+ `does, into a variable scoped to that start event and read the variable: ` +
96
+ `\`.var(${tsLiteral(local)}, ${tsLiteral(type)}, { elementId: ${tsLiteral(scope)} })\` and ` +
97
+ `\`.startEvent(${tsLiteral(scope)}, { payload: { type: ` +
98
+ `'BPMN.Variables', outputRows: [{ name: ${tsLiteral(decl.name)}, type: ${tsLiteral(type)}, ` +
99
+ `source: ${tsLiteral(`=vars.${decl.id}`)}, var: ${tsLiteral(local)} }] } })\`, then read \`=vars.${local}\`.`);
100
+ }
101
+ /** What a field's string values are, which decides which of them `checkExprValues` checks. */
102
+ var FieldValues;
103
+ (function (FieldValues) {
104
+ /** Every string is an expression and is checked: a script task's `outputs`, expressions against the result. */
105
+ FieldValues[FieldValues["Expressions"] = 0] = "Expressions";
106
+ /**
107
+ * A string is an expression only when `isExpressionValue` says so, the same rule
108
+ * `serialize` applies; literal text is not a read. `.task({ set })` and a script task's
109
+ * `inputs`: `set: { label: 'vars.amount' }` assigns the text "vars.amount".
110
+ */
111
+ FieldValues[FieldValues["LiteralOrExpression"] = 1] = "LiteralOrExpression";
112
+ })(FieldValues || (FieldValues = {}));
113
+ /**
114
+ * Check every expression VALUE of a `field → value` map (keys are targets), as `kind` says.
60
115
  *
61
116
  * A value need not be a string. A script task's `inputs` are the keys of its `args`
62
117
  * JSON body, and the designer nests objects there (`{"args":{"name":"=vars.x"}}`), so
@@ -64,10 +119,12 @@ function checkExpr(expr, where, roots, out) {
64
119
  * Handing it to `checkExpr` as if it were a string is what crashed `build()` with
65
120
  * `expr.replace is not a function` on six deployed processes.
66
121
  */
67
- function checkExprValues(rec, where, roots, out) {
122
+ function checkExprValues(rec, where, roots, out, kind) {
68
123
  for (const v of Object.values(rec ?? {})) {
69
- if (typeof v === 'string')
70
- checkExpr(v, where, roots, out);
124
+ if (typeof v === 'string') {
125
+ if (kind === FieldValues.Expressions || isExpressionValue(v))
126
+ checkExpr(v, where, roots, out);
127
+ }
71
128
  else
72
129
  deepExprStrings(v, where, roots, out);
73
130
  }
@@ -75,7 +132,7 @@ function checkExprValues(rec, where, roots, out) {
75
132
  /** Reach `=`-expression strings anywhere in a connector's (possibly nested) inputs. */
76
133
  function deepExprStrings(val, where, roots, out) {
77
134
  if (typeof val === 'string') {
78
- if (val.startsWith('='))
135
+ if (isExpressionValue(val))
79
136
  checkExpr(val, where, roots, out);
80
137
  return;
81
138
  }
@@ -96,10 +153,13 @@ function walk(nodes, flows, rootsIn, out) {
96
153
  // script task's output, a variable task's assignment target. Collect them for
97
154
  // the WHOLE scope before walking: a flow condition is checked first but may
98
155
  // read a node declared later in authoring order.
99
- const roots = { vars: new Set(rootsIn.vars), varIds: rootsIn.varIds, bindings: rootsIn.bindings };
156
+ const roots = { ...rootsIn, vars: new Set(rootsIn.vars), args: new Map(rootsIn.args) };
100
157
  for (const n of nodes)
101
- for (const name of nodeDeclaredVars(n))
158
+ for (const name of nodeDeclaredVars(n)) {
102
159
  roots.vars.add(name);
160
+ // A node writing that name makes it readable, whatever else declares it.
161
+ roots.args.delete(name);
162
+ }
103
163
  for (const f of flows) {
104
164
  const found = [];
105
165
  checkExpr(f.condition, `flow "${f.id}" condition`, roots, found);
@@ -142,7 +202,7 @@ function walkNode(n, roots, located) {
142
202
  // `error` joins `vars` (so `vars.error` resolves) but NOT `varIds`: it is a
143
203
  // scoped runtime binding, not a declared variable, so `=error` is not a bare
144
204
  // spelling of one.
145
- const errRoots = { vars: new Set(roots.vars).add('error'), varIds: roots.varIds, bindings: roots.bindings };
205
+ const errRoots = { ...roots, vars: new Set(roots.vars).add('error') };
146
206
  for (const row of ('errorMapping' in n ? n.errorMapping : undefined) ?? []) {
147
207
  checkExpr(row.condition, `${at} errorMapping "${row.code}" condition`, errRoots, out);
148
208
  }
@@ -156,19 +216,15 @@ function walkNode(n, roots, located) {
156
216
  checkExpr(n.loop.collection, `${at} loop collection`, roots, out);
157
217
  // The iterator bindings (`iterator.item`, `iterator.<itemVar>`) are the loop's
158
218
  // own, not author declarations, so a completion condition may read them.
159
- const loopRoots = {
160
- vars: new Set(roots.vars).add('iterator'),
161
- varIds: roots.varIds,
162
- bindings: roots.bindings,
163
- };
219
+ const loopRoots = { ...roots, vars: new Set(roots.vars).add('iterator') };
164
220
  checkExpr(n.loop.completion, `${at} loop completion`, loopRoots, out);
165
221
  }
166
222
  if (n.kind === 'scriptTask') {
167
- checkExprValues(n.inputs, `${at} input`, roots, out);
168
- checkExprValues(n.outputs, `${at} output`, roots, out);
223
+ checkExprValues(n.inputs, `${at} input`, roots, out, FieldValues.LiteralOrExpression);
224
+ checkExprValues(n.outputs, `${at} output`, roots, out, FieldValues.Expressions);
169
225
  }
170
226
  else if (n.kind === 'task') {
171
- checkExprValues(n.set, `${at} assignment`, roots, out);
227
+ checkExprValues(n.set, `${at} assignment`, roots, out, FieldValues.LiteralOrExpression);
172
228
  }
173
229
  else if (n.kind === 'connector') {
174
230
  deepExprStrings(n.inputs, `${at} input`, roots, out);
@@ -178,7 +234,9 @@ function walkNode(n, roots, located) {
178
234
  // plus the ones it declares. The loop COLLECTION is evaluated in the
179
235
  // enclosing scope (before entry); the body and completion see the sub-scope.
180
236
  checkExpr(n.loop?.collection, `${at} loop collection`, roots, out);
181
- const subRoots = { vars: new Set(roots.vars), varIds: new Set(roots.varIds), bindings: roots.bindings };
237
+ // Only the process's own arguments are reported: a sub-process's declarations,
238
+ // whatever their direction, are left to the platform's own scoping.
239
+ const subRoots = { ...roots, vars: new Set(roots.vars), varIds: new Set(roots.varIds), args: new Map(roots.args) };
182
240
  // By ID as well as display name, exactly as the root scope below: an expression
183
241
  // reads `vars.<id>`. This added the name alone, so a sub-process variable whose
184
242
  // display name differed from its id — every `errorVar`, displayed as `Error` —
@@ -187,6 +245,8 @@ function walkNode(n, roots, located) {
187
245
  subRoots.vars.add(v.id);
188
246
  subRoots.vars.add(v.name);
189
247
  subRoots.varIds.add(v.id);
248
+ subRoots.args.delete(v.id);
249
+ subRoots.args.delete(v.name);
190
250
  }
191
251
  checkExpr(n.loop?.completion, `${at} loop completion`, subRoots, out);
192
252
  flush();
@@ -220,11 +280,41 @@ export function checkBpmnExpressions(built) {
220
280
  // connector turns into bindings at serialize time — the author's own spelling
221
281
  // is what they would reference, so both are legitimate roots.
222
282
  bindings: new Set([...built.bindings.map((b) => b.id), ...connectorBindingNames(built.nodes)]),
283
+ args: processArguments(built),
223
284
  };
224
285
  const out = [];
225
286
  walk(built.nodes, built.flows, roots, out);
226
287
  return out;
227
288
  }
289
+ /**
290
+ * The top-level arguments no expression may read — see {@link BpmnRoots.args}.
291
+ *
292
+ * An argument is one only where it is SCOPED TO AN ELEMENT: its `elementId`, or the
293
+ * element `publicDeclarationScope` writes for it (the manual start event for an input,
294
+ * the end event that writes an output). One scoped to the process itself is root state
295
+ * to `validate`, which counts every declaration whose `elementId` is the process as
296
+ * available everywhere, so it is left alone, as is one written with no `elementId` at
297
+ * all (`null`, a legacy import), which `validate` already reports as missing.
298
+ *
299
+ * Keyed by id and by display name, as `vars` is. A spelling an internal variable
300
+ * shares is left out: the canvas resolves the reference to that variable.
301
+ */
302
+ function processArguments(built) {
303
+ const scopeOf = publicDeclarationScope(built.nodes, built.id);
304
+ const readable = new Set(built.variables.filter((v) => v.direction === 'inputOutput').flatMap((v) => [v.id, v.name]));
305
+ const args = new Map();
306
+ for (const v of built.variables) {
307
+ if (v.direction === 'inputOutput' || v.elementId === null)
308
+ continue;
309
+ const scope = v.elementId ?? scopeOf(v);
310
+ if (scope === built.id)
311
+ continue;
312
+ for (const key of [v.id, v.name])
313
+ if (!readable.has(key) && !args.has(key))
314
+ args.set(key, { decl: v, scope });
315
+ }
316
+ return args;
317
+ }
228
318
  /** Every symbolic connection/folder name in a graph, at any nesting depth. */
229
319
  function connectorBindingNames(nodes) {
230
320
  const out = [];
@@ -1541,34 +1541,51 @@ export interface HumanTaskCommonOpts extends ActivityOpts {
1541
1541
  /**
1542
1542
  * Options for `.humanTask()` backed by an Action App — an `Actions.HITL` action-app task.
1543
1543
  *
1544
- * `app` is the Action App's id and the registry marks it the type's primary key,
1545
- * so it comes from the tenant (`RequiresDiscovery: Yes`). Nothing offline can
1546
- * resolve it: pass the id, or a `=bindings.<id>` reference so it is configurable
1547
- * per environment. With no app on the tenant, use {@link HumanTaskFormOpts} instead.
1544
+ * The app is addressed by its NAME and FOLDER PATH, the way Studio Web saves the task:
1545
+ * `uipath:type version="v2"`, `name` and `folderPath` context inputs that are
1546
+ * `=bindings.<id>` references, and two `resource="app"` bindings (`propertyAttribute`
1547
+ * `name` and `folderPath`) keyed `<folder>.<app>`. The SDK declares the bindings for you
1548
+ * from the two plain values, so each is overridable per environment at deploy time.
1549
+ *
1550
+ * Both come from the tenant (`RequiresDiscovery: Yes`): the app as Action Center lists
1551
+ * it, and the Orchestrator folder it is deployed to. With no app on the tenant, use
1552
+ * {@link HumanTaskFormOpts} instead.
1553
+ *
1554
+ * @remarks
1555
+ * **Not an app id.** Before UiPath/builder-sdk#2144 `app` was the app's id and the task
1556
+ * was written at `version="v1"` with an `appId` context input. The V2 engine never reads
1557
+ * `appId`: it resolves the app only from `name`/`folderPath` at v2, and fails a v1 task
1558
+ * with 170000. `folder` is required so a program written against the old meaning is
1559
+ * refused (`BPMN_HUMAN_TASK_APP_NO_FOLDER`) rather than compiled into a task that looks
1560
+ * up an app NAMED like the id.
1548
1561
  */
1549
1562
  export interface HumanTaskAppOpts extends HumanTaskCommonOpts {
1550
- /** The Action App's id (`appId`). Tenant-specific — see the remarks above. */
1563
+ /**
1564
+ * The Action App's name, e.g. `'InvoiceApproval'` — the context's `name`. Or an
1565
+ * `=bindings.<id>` reference to an `app` / `name` binding you declared.
1566
+ */
1551
1567
  app: string;
1552
- /** Not on this variant — see {@link HumanTaskFormOpts}. */
1553
- form?: never;
1554
- /** The app version (`appVersion`). */
1555
- appVersion?: number;
1556
1568
  /**
1557
- * The outcomes a human can pick, e.g. `['approve', 'reject']`.
1558
- *
1559
- * Joined with commas. The registry types this field as a bare `string` and says
1560
- * nothing about its encoding, and `uip maestro bpmn validate` accepts a
1561
- * comma-joined list, a JSON array, a single word and an empty string alike — so
1562
- * this is the plausible reading, not a verified one. If a LIVE run mis-reads the
1563
- * outcomes, this is the first thing to compare against a Studio Web export.
1569
+ * The Orchestrator folder path the app is deployed to, e.g. `'Shared'` or
1570
+ * `'Finance/Invoices'` — the context's `folderPath`. Or an `=bindings.<id>` reference
1571
+ * to an `app` / `folderPath` binding you declared.
1564
1572
  */
1565
- actions?: string[];
1566
- /** An existing task key, when resuming rather than creating (`key`). */
1567
- key?: string;
1573
+ folder: string;
1574
+ /** Not on this variant — see {@link HumanTaskFormOpts}. */
1575
+ form?: never;
1568
1576
  /** Data the task shows the human — the node's `HitlTaskArguments`. */
1569
1577
  input?: Record<string, unknown>;
1570
1578
  /** Variable the whole typed response lands in. Defaults to `<id>_processResponse`. */
1571
1579
  outputVar?: string;
1580
+ /**
1581
+ * Removed (#2144): a v1 `appId`-task field the V2 engine never reads. The app defines
1582
+ * its own outcomes; read the one picked with `outputs: { decision: '=Action' }`.
1583
+ */
1584
+ actions?: never;
1585
+ /** Removed (#2144): a v1 `appId`-task field the V2 engine never reads. */
1586
+ appVersion?: never;
1587
+ /** Removed (#2144): a v1 `appId`-task field the V2 engine never reads. */
1588
+ key?: never;
1572
1589
  }
1573
1590
  /**
1574
1591
  * Options for `.humanTask()` with an INLINE form — the quick-form `Actions.HITL` task,
@@ -1589,6 +1606,8 @@ export interface HumanTaskFormOpts extends HumanTaskCommonOpts {
1589
1606
  form: HumanTaskForm;
1590
1607
  /** Not on this variant — the form replaces the app. */
1591
1608
  app?: never;
1609
+ /** Not on this variant — there is no app to look up in a folder. */
1610
+ folder?: never;
1592
1611
  /** Action Center priority, e.g. `'Medium'` (`priority`). */
1593
1612
  priority?: string;
1594
1613
  /** Action Center labels, comma-separated (`labels`). */
@@ -1919,9 +1938,13 @@ export interface VarOpts {
1919
1938
  * the process's manual START event and a top-level `.output()` to the END event
1920
1939
  * whose mapping writes it (or the only end event): that is how every Studio Web
1921
1940
  * export and converter output declares a process's public contract, and what the
1922
- * canvas, the entry-point derivation and the graders read it from. The engine itself
1923
- * resolves `vars.<id>` by id whatever the scope, so a script may read an input
1924
- * directly with no start-event bridge. `uip maestro bpmn validate` (1.203+) requires
1941
+ * canvas, the entry-point derivation and the graders read it from. It also decides
1942
+ * who may READ it: an input scoped to the start event is readable only by that start
1943
+ * event's own mapping, and an output by nobody. The engine resolves `vars.<id>` by id
1944
+ * whatever the scope, so a direct read runs, but Studio Web shows "A variable is
1945
+ * unresolved" on it and `validate` reports `VARIABLE_NOT_SET`; `check` reports it as
1946
+ * `EXPR_ARGUMENT_REF`. Map an input, on the start event, into a `.var()` scoped to that
1947
+ * start event and read the variable, as the canvas does (see `.input()`). `uip maestro bpmn validate` (1.203+) requires
1925
1948
  * SOME `elementId`: a declaration with none is `ROOT_VARIABLE_MISSING_ELEMENT_ID`,
1926
1949
  * and every `vars.<id>` read of it fails `VARIABLE_DOES_NOT_EXIST`. Name an element
1927
1950
  * to scope the variable to it explicitly (the node whose output fills it, a specific
@@ -2970,9 +2993,10 @@ declare abstract class ScopeBuilder {
2970
2993
  * @remarks
2971
2994
  * **Pick the variant by whether an app is named.** With no deployed Action App named,
2972
2995
  * use `form: { fields, outcomes }` ({@link HumanTaskFormOpts}): the form travels in the
2973
- * `.bpmn` and nothing on the tenant has to exist. Use `app` ({@link HumanTaskAppOpts})
2974
- * only when the request names a deployed app — an app id that is not on the tenant fails
2975
- * `uip maestro bpmn validate` with `MISSING_BINDING` / `MISSING_RESOURCE`.
2996
+ * `.bpmn` and nothing on the tenant has to exist. Use `app` and `folder`
2997
+ * ({@link HumanTaskAppOpts}) only when the request names a deployed app: the app's name
2998
+ * and the folder path it is deployed to. The SDK writes them as the two `app` bindings
2999
+ * Studio Web saves, so a deploy can point the task at another environment's app.
2976
3000
  *
2977
3001
  * The offline runtime can stand in for the human — `--hitl-response` injects an
2978
3002
  * outcome — so an approval gate's branches are testable with no tenant and no
@@ -2993,9 +3017,9 @@ declare abstract class ScopeBuilder {
2993
3017
  * .var('outcome', 'string', { default: 'none' })
2994
3018
  * .startEvent('start')
2995
3019
  * .humanTask('approve', {
2996
- * app: 'app-123',
3020
+ * app: 'InvoiceApproval',
3021
+ * folder: 'Shared',
2997
3022
  * title: 'Approve the invoice',
2998
- * actions: ['approve', 'reject'],
2999
3023
  * input: { amount: 100 },
3000
3024
  * outputs: { decision: '=Action' },
3001
3025
  * })
@@ -3475,7 +3499,26 @@ declare abstract class ScopeBuilder {
3475
3499
  */
3476
3500
  var(id: string, type: BpmnVarType, opts?: VarOpts): this;
3477
3501
  /**
3478
- * A read-only entry input (`uipath:input`).
3502
+ * A read-only entry input (`uipath:input`), scoped to the manual start event.
3503
+ *
3504
+ * Only the start event's own mapping reads it. Every other element reads the variable
3505
+ * that mapping copies it into, scoped to the start event — which is what Studio Web
3506
+ * writes when an input is added on the canvas: a
3507
+ * `vars.<input>` read anywhere else is "A variable is unresolved" on the canvas, and
3508
+ * `check` reports it as `EXPR_ARGUMENT_REF`.
3509
+ *
3510
+ * ```ts
3511
+ * bpmn('approve')
3512
+ * .input('amount', 'number')
3513
+ * .var('amountIn', 'number', { elementId: 'start' })
3514
+ * .startEvent('start', {
3515
+ * payload: {
3516
+ * type: 'BPMN.Variables',
3517
+ * outputRows: [{ name: 'amount', type: 'number', source: '=vars.amount', var: 'amountIn' }],
3518
+ * },
3519
+ * })
3520
+ * // downstream: '=vars.amountIn > 1000', never '=vars.amount > 1000'
3521
+ * ```
3479
3522
  *
3480
3523
  * @param id - The input's name.
3481
3524
  * @param type - A `types.*` descriptor, or another product spelling ({@link BpmnVarType}).
@@ -3674,7 +3717,7 @@ export declare class PathBuilder extends ScopeBuilder {
3674
3717
  * bpmn('approval')
3675
3718
  * .var('reminded', 'string')
3676
3719
  * .startEvent('start')
3677
- * .humanTask('approve', { app: 'InvoiceApproval', actions: ['Approve', 'Reject'] }, (t) => {
3720
+ * .humanTask('approve', { app: 'InvoiceApproval', folder: 'Shared' }, (t) => {
3678
3721
  * t.onTimer('PT1H', { interrupting: false }, (b) =>
3679
3722
  * b.task('remind', { set: { reminded: 'true' } }).endEvent('reminded'));
3680
3723
  * t.onError((b) => b.endEvent('failed', { name: 'Approval failed' }));
@@ -14,6 +14,19 @@ export { connectorOutputVars, nodeDeclaredVars, typedNodeDeclaredVars } from './
14
14
  function normTimer(t) {
15
15
  return typeof t === 'string' ? { duration: t } : t;
16
16
  }
17
+ /**
18
+ * The `uipath:type` version of an app-backed `.humanTask()`. PO.BpmnEngine
19
+ * (`AppTasksCreateArgs`) reads the app from `name`/`folderPath` only on `v2`; on `v1` it
20
+ * reads no app at all and the AppTasks request fails with 170000 (UiPath/cli#5940).
21
+ */
22
+ const HITL_APP_TYPE_VERSION = 'v2';
23
+ /**
24
+ * How an app-backed `.humanTask()` keys its `app` binding pair: `<folderPath>.<name>`,
25
+ * Studio Web's fallback when the task carries no tenant key (`useAddTaskInfoToBindings`),
26
+ * e.g. `Shared.InvoiceApproval`. The registry's own pattern, `${metadata.key}`, names the
27
+ * app's tenant key, which nothing offline has.
28
+ */
29
+ const HITL_APP_RESOURCE_KEY_PATTERN = '${metadata.folderPath}.${metadata.name}';
17
30
  /** Every {@link PlainTaskElement}, for the run-time check in `.plainTask()`. */
18
31
  const PLAIN_TASK_ELEMENTS = new Set([
19
32
  'bpmn:callActivity', 'bpmn:task', 'bpmn:userTask', 'bpmn:serviceTask', 'bpmn:sendTask', 'bpmn:manualTask', 'bpmn:businessRuleTask', 'bpmn:receiveTask',
@@ -1283,7 +1296,9 @@ class ScopeBuilder {
1283
1296
  * right. An author who passes an `=`-expression already knows what they want and
1284
1297
  * is left alone.
1285
1298
  */
1286
- bindRequiredContext(id, type, context) {
1299
+ bindRequiredContext(id, type, context,
1300
+ /** A key pattern to use in place of the registry's, for a type whose own one names nothing an author has. */
1301
+ keyPattern) {
1287
1302
  const out = { ...context };
1288
1303
  for (const field of bindingRequiredFields(type)) {
1289
1304
  const value = out[field.name];
@@ -1297,7 +1312,7 @@ class ScopeBuilder {
1297
1312
  // (`${metadata.key}`, the live registry's pattern on a job start, whose context
1298
1313
  // has no `key`) leaves the key to the value, as before. This snapshot carries no
1299
1314
  // pattern for the job starts at all; `resource-key-pattern.ts` is tested on both.
1300
- const keyed = this.resourceKeyFromPattern(id, type, field, context);
1315
+ const keyed = this.resourceKeyFromPattern(id, type, field, context, keyPattern);
1301
1316
  this._bindingRegistry.declare({
1302
1317
  id: bindingId,
1303
1318
  name: field.displayName ?? field.name,
@@ -1339,8 +1354,8 @@ class ScopeBuilder {
1339
1354
  * `.binding()` before this node declares with a value: that key would otherwise be
1340
1355
  * built, so the author is told what to declare rather than given a wrong pair.
1341
1356
  */
1342
- resourceKeyFromPattern(id, type, field, context) {
1343
- const pattern = field.bindingInfo?.resourceKeyPattern;
1357
+ resourceKeyFromPattern(id, type, field, context, keyPattern) {
1358
+ const pattern = keyPattern ?? field.bindingInfo?.resourceKeyPattern;
1344
1359
  const byId = (bindingId) => this._bindingRegistry.bindings.find((b) => b.id === bindingId);
1345
1360
  const resolved = resolveResourceKeyPattern(pattern, context, byId);
1346
1361
  if (resolved === undefined)
@@ -1611,9 +1626,10 @@ class ScopeBuilder {
1611
1626
  * @remarks
1612
1627
  * **Pick the variant by whether an app is named.** With no deployed Action App named,
1613
1628
  * use `form: { fields, outcomes }` ({@link HumanTaskFormOpts}): the form travels in the
1614
- * `.bpmn` and nothing on the tenant has to exist. Use `app` ({@link HumanTaskAppOpts})
1615
- * only when the request names a deployed app — an app id that is not on the tenant fails
1616
- * `uip maestro bpmn validate` with `MISSING_BINDING` / `MISSING_RESOURCE`.
1629
+ * `.bpmn` and nothing on the tenant has to exist. Use `app` and `folder`
1630
+ * ({@link HumanTaskAppOpts}) only when the request names a deployed app: the app's name
1631
+ * and the folder path it is deployed to. The SDK writes them as the two `app` bindings
1632
+ * Studio Web saves, so a deploy can point the task at another environment's app.
1617
1633
  *
1618
1634
  * The offline runtime can stand in for the human — `--hitl-response` injects an
1619
1635
  * outcome — so an approval gate's branches are testable with no tenant and no
@@ -1634,9 +1650,9 @@ class ScopeBuilder {
1634
1650
  * .var('outcome', 'string', { default: 'none' })
1635
1651
  * .startEvent('start')
1636
1652
  * .humanTask('approve', {
1637
- * app: 'app-123',
1653
+ * app: 'InvoiceApproval',
1654
+ * folder: 'Shared',
1638
1655
  * title: 'Approve the invoice',
1639
- * actions: ['approve', 'reject'],
1640
1656
  * input: { amount: 100 },
1641
1657
  * outputs: { decision: '=Action' },
1642
1658
  * })
@@ -1688,20 +1704,30 @@ class ScopeBuilder {
1688
1704
  * @returns This builder, so calls chain.
1689
1705
  */
1690
1706
  humanTask(id, opts, body) {
1691
- const hasApp = opts.app !== undefined;
1692
- const hasForm = opts.form !== undefined;
1707
+ const given = opts;
1708
+ const hasApp = given.app !== undefined;
1709
+ const hasForm = given.form !== undefined;
1693
1710
  if (hasApp === hasForm) {
1694
1711
  throw new CompileRefusal('BPMN_HUMAN_TASK_APP_XOR_FORM', `humanTask "${id}": pass exactly one of app (a deployed Action App) or form ({ fields, outcomes }, an inline form that needs no app).`);
1695
1712
  }
1713
+ // The v1 app task's own fields (UiPath/builder-sdk#2144). The V2 engine reads none of
1714
+ // them on either variant: an app's outcomes are the app's, a form's are form.outcomes.
1715
+ const v1Fields = ['appVersion', 'actions', 'key'].filter((k) => given[k] !== undefined);
1716
+ if (v1Fields.length) {
1717
+ throw new CompileRefusal('BPMN_HUMAN_TASK_APP_V1_FIELDS', `humanTask "${id}": ${v1Fields.join(', ')} belong to the retired v1 app task (addressed by appId), which the V2 engine never reads. ` +
1718
+ (hasForm
1719
+ ? 'On an inline form, put the outcomes in form.outcomes and what the human sees in form.fields.'
1720
+ : 'Drop them: the app defines its own outcomes, and outputs: { decision: \'=Action\' } reads the one the human picked.'));
1721
+ }
1696
1722
  if (hasForm) {
1697
1723
  const o = opts;
1698
- // The app variant's fields have no meaning on an inline form: the form IS the
1699
- // outcomes (`actions`) and what the human sees (`input`).
1724
+ // The app variant's fields have no meaning on an inline form: the form IS what the
1725
+ // human sees (`input`), and there is no app to look up (`folder`).
1700
1726
  // Nor does `outputVar`: the app task's whole-response row has no source, which a
1701
- // quick form never fills (UiPath/builder-sdk#2139), so there is nothing to name.
1702
- const appOnly = ['appVersion', 'actions', 'key', 'input', 'outputVar'].filter((k) => opts[k] !== undefined);
1727
+ // quick form never fills, so there is nothing to name.
1728
+ const appOnly = ['folder', 'input', 'outputVar'].filter((k) => given[k] !== undefined);
1703
1729
  if (appOnly.length) {
1704
- throw new CompileRefusal('BPMN_HUMAN_TASK_APP_FIELDS_ON_FORM', `humanTask "${id}": ${appOnly.join(', ')} belong to an app-backed task. On an inline form, put the outcomes in form.outcomes and what the human sees in form.fields` +
1730
+ throw new CompileRefusal('BPMN_HUMAN_TASK_APP_FIELDS_ON_FORM', `humanTask "${id}": ${appOnly.join(', ')} belong to an app-backed task. On an inline form, put what the human sees in form.fields` +
1705
1731
  (appOnly.includes('outputVar')
1706
1732
  ? '; an inline form has no whole-response variable, so each answer lands in its field\'s variable and the outcome in an outputs mapping, e.g. outputs: { decision: \'=Action\' }.'
1707
1733
  : '.'));
@@ -1727,27 +1753,36 @@ class ScopeBuilder {
1727
1753
  loop: o.loop,
1728
1754
  }, body);
1729
1755
  }
1730
- opts = opts;
1756
+ const o = opts;
1757
+ if (typeof o.folder !== 'string' || o.folder === '') {
1758
+ throw new CompileRefusal('BPMN_HUMAN_TASK_APP_NO_FOLDER', `humanTask "${id}": an Action App is addressed by its name and the folder it is deployed to — pass both, e.g. ` +
1759
+ `{ app: 'InvoiceApproval', folder: 'Shared' } (or =bindings.<id> references to app bindings). ` +
1760
+ `app is the app's NAME, not its id: the V2 engine never reads an appId and fails such a task with 170000 (UiPath/builder-sdk#2144).`);
1761
+ }
1762
+ // Studio Web's app task (`useActionsProperties` / `useAddTaskInfoToBindings`): v2,
1763
+ // `name` and `folderPath` as `=bindings.<id>` references to a `resource="app"` pair.
1764
+ // The registry keys that pair `${metadata.key}`, the app's tenant key, which an author
1765
+ // offline does not have; Studio Web falls back to `<folderPath>.<name>` when the task
1766
+ // carries no key, and every app binding it saves is keyed that way.
1731
1767
  return this.pushActivity({
1732
1768
  kind: 'typed',
1733
1769
  id,
1734
- name: opts.name,
1770
+ name: o.name,
1735
1771
  type: 'Actions.HITL',
1736
- context: {
1737
- appId: opts.app,
1738
- ...(opts.appVersion !== undefined ? { appVersion: opts.appVersion } : {}),
1739
- ...(opts.actions !== undefined ? { actions: opts.actions.join(',') } : {}),
1740
- ...(opts.title !== undefined ? { taskTitle: opts.title } : {}),
1741
- ...(opts.key !== undefined ? { key: opts.key } : {}),
1742
- },
1743
- inputs: opts.input ?? {},
1744
- outputVar: opts.outputVar,
1745
- outputs: opts.outputs,
1746
- skipCondition: opts.skipCondition,
1747
- tags: opts.tags,
1748
- retry: opts.retry,
1749
- errorMapping: opts.errorMapping,
1750
- loop: opts.loop,
1772
+ typeVersion: HITL_APP_TYPE_VERSION,
1773
+ context: this.bindRequiredContext(id, 'Actions.HITL', {
1774
+ name: o.app,
1775
+ folderPath: o.folder,
1776
+ ...(o.title !== undefined ? { taskTitle: o.title } : {}),
1777
+ }, HITL_APP_RESOURCE_KEY_PATTERN),
1778
+ inputs: o.input ?? {},
1779
+ outputVar: o.outputVar,
1780
+ outputs: o.outputs,
1781
+ skipCondition: o.skipCondition,
1782
+ tags: o.tags,
1783
+ retry: o.retry,
1784
+ errorMapping: o.errorMapping,
1785
+ loop: o.loop,
1751
1786
  }, body);
1752
1787
  }
1753
1788
  /**
@@ -2433,7 +2468,26 @@ class ScopeBuilder {
2433
2468
  return this.declareVar(id, type, 'inputOutput', opts);
2434
2469
  }
2435
2470
  /**
2436
- * A read-only entry input (`uipath:input`).
2471
+ * A read-only entry input (`uipath:input`), scoped to the manual start event.
2472
+ *
2473
+ * Only the start event's own mapping reads it. Every other element reads the variable
2474
+ * that mapping copies it into, scoped to the start event — which is what Studio Web
2475
+ * writes when an input is added on the canvas: a
2476
+ * `vars.<input>` read anywhere else is "A variable is unresolved" on the canvas, and
2477
+ * `check` reports it as `EXPR_ARGUMENT_REF`.
2478
+ *
2479
+ * ```ts
2480
+ * bpmn('approve')
2481
+ * .input('amount', 'number')
2482
+ * .var('amountIn', 'number', { elementId: 'start' })
2483
+ * .startEvent('start', {
2484
+ * payload: {
2485
+ * type: 'BPMN.Variables',
2486
+ * outputRows: [{ name: 'amount', type: 'number', source: '=vars.amount', var: 'amountIn' }],
2487
+ * },
2488
+ * })
2489
+ * // downstream: '=vars.amountIn > 1000', never '=vars.amount > 1000'
2490
+ * ```
2437
2491
  *
2438
2492
  * @param id - The input's name.
2439
2493
  * @param type - A `types.*` descriptor, or another product spelling ({@link BpmnVarType}).
@@ -2705,7 +2759,7 @@ export class PathBuilder extends ScopeBuilder {
2705
2759
  * bpmn('approval')
2706
2760
  * .var('reminded', 'string')
2707
2761
  * .startEvent('start')
2708
- * .humanTask('approve', { app: 'InvoiceApproval', actions: ['Approve', 'Reject'] }, (t) => {
2762
+ * .humanTask('approve', { app: 'InvoiceApproval', folder: 'Shared' }, (t) => {
2709
2763
  * t.onTimer('PT1H', { interrupting: false }, (b) =>
2710
2764
  * b.task('remind', { set: { reminded: 'true' } }).endEvent('reminded'));
2711
2765
  * t.onError((b) => b.endEvent('failed', { name: 'Approval failed' }));