@uipath/maestro-builder-sdk 6.81.0 → 6.82.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.
@@ -37,8 +37,10 @@ import { ruleShapeProblems } from './rule-options.js';
37
37
  import { CompileRefusal } from '../core/compile-refusal.js';
38
38
  import { implicitInArgBuiltTrigger, unboundInArgMessage } from './in-arg-binding.js';
39
39
  import { jsonClone } from '../core/json-clone.js';
40
+ import { savedDocumentExtractionData } from './document-extraction-saved.js';
40
41
  import { taskShapeProblems } from './task-shape.js';
41
42
  import { SCRIPT_INPUTS, scriptOutputMappings, scriptOutputs, storedScript } from './script.js';
43
+ import { DOCUMENT_EXTRACTION_NAME, DOCUMENT_EXTRACTION_RESOURCE, DOCUMENT_EXTRACTION_SERVICE_TYPE, DOCUMENT_EXTRACTION_VERSION, documentExtractionContext, documentExtractionInputs, documentExtractionOutputMappings, documentExtractionOutputs, documentExtractionRefusal, } from './document-extraction.js';
42
44
  import { HTTP_REQUEST_CONNECTION_NAME, HTTP_REQUEST_IMPLICIT_BINDING_ID, HTTP_REQUEST_IMPLICIT_CONNECTION, HTTP_REQUEST_SERVICE_TYPE, httpRequestBody, httpRequestContext, httpRequestInputs, httpRequestOutputMappings, httpRequestOutputs, httpRequestRefusal, writeHttpRequestMetadata, } from './http-request.js';
43
45
  import { connectorPlaceholderData, isConnectorPlaceholder } from './connector-placeholder.js';
44
46
  import { lowerTaskOutputRefs, planTaskOutputs, resolveInPlan, unresolvedTaskOutputRef } from './task-output-ref.js';
@@ -215,7 +217,9 @@ function serializeCase(built, opts) {
215
217
  offlineBindingIds: new Map(),
216
218
  varCompanions: new Map(),
217
219
  ownNameRows: new Map(),
218
- outputIds: new Set(),
220
+ // A carried task's saved output rows keep their ids: no other row takes one.
221
+ outputIds: new Set(savedOutputIds(caseJsonPreservation(built)?.documentExtractionData)),
222
+ savedDocumentExtractions: caseJsonPreservation(built)?.documentExtractionData ?? [],
219
223
  ownOutputVars: ownOutputVars(built),
220
224
  caseVarNames: new Set([...built.vars.map((v) => v.name), ...mappedFixedOutputVars(built)]),
221
225
  slaId: new Map(),
@@ -854,6 +858,7 @@ export function applyPreservation(result, preservation, options = {}) {
854
858
  // (preserve.ts `unreadBindings` / `readBindings` / `bindings`): a row the
855
859
  // original read nowhere stays, as Studio Web keeps it; any other stays while
856
860
  // something in the result still reads it, and goes with its last reader.
861
+ applySavedIxpBindings(result, preservation.readBindings);
857
862
  const carried = [...(preservation.unreadBindings ?? []), ...(preservation.readBindings ?? []), ...(preservation.bindings ?? [])];
858
863
  if (carried.length) {
859
864
  const rows = (result.bindings ??= []);
@@ -868,6 +873,51 @@ export function applyPreservation(result, preservation, options = {}) {
868
873
  }
869
874
  return result;
870
875
  }
876
+ /**
877
+ * Point each document-extraction task back at the `ixpDeployment` row it was
878
+ * saved with. Compile mints one row per deployment and key (`bIxp<n>`); the
879
+ * source's row for that deployment and key travels in `readBindings`, and it
880
+ * is written back under its own id, `context.name` with it, so a decompile ->
881
+ * compile (and a merge) keeps the Designer's binding. A fresh row no task
882
+ * reads any more is dropped. The carried-row pass below then appends the
883
+ * saved row, which the task now reads.
884
+ */
885
+ function applySavedIxpBindings(result, carried) {
886
+ const key = (row) => JSON.stringify([row.default, row.resourceKey ?? null]);
887
+ const saved = new Map();
888
+ for (const row of carried ?? [])
889
+ if (row.resource === DOCUMENT_EXTRACTION_RESOURCE && typeof row.id === 'string' && !saved.has(key(row)))
890
+ saved.set(key(row), row.id);
891
+ if (!saved.size)
892
+ return;
893
+ const rows = (result.bindings ?? []);
894
+ const written = new Set(rows.map((row) => row.id));
895
+ const renamed = new Map();
896
+ for (const row of rows) {
897
+ if (row.resource !== DOCUMENT_EXTRACTION_RESOURCE)
898
+ continue;
899
+ const id = saved.get(key(row));
900
+ if (id !== undefined && id !== row.id && !written.has(id))
901
+ renamed.set(row.id, id);
902
+ }
903
+ if (!renamed.size)
904
+ return;
905
+ for (const node of (result.nodes ?? [])) {
906
+ if (!String(node.type ?? '').endsWith('Stage'))
907
+ continue;
908
+ for (const task of (node.data?.tasks ?? []).flat()) {
909
+ if (task.type !== 'document-extraction')
910
+ continue;
911
+ for (const row of (task.data?.context ?? [])) {
912
+ const id = row.name === 'name' ? bindingRefId(row.value) : undefined;
913
+ if (id !== undefined && renamed.has(id))
914
+ row.value = `=bindings.${renamed.get(id)}`;
915
+ }
916
+ }
917
+ }
918
+ const reads = readBindingIds(result);
919
+ result.bindings = rows.filter((row) => !renamed.has(row.id) || reads.has(row.id));
920
+ }
871
921
  /**
872
922
  * Write each decompiled resource task's saved `=bindings.<id>` pair back over
873
923
  * the fresh one compile wrote (resource-wire.ts), while the task still names the
@@ -1113,6 +1163,7 @@ export function followRenames(result, preservation) {
1113
1163
  ...(preservation.connectorConfigurations ? { connectorConfigurations: preservation.connectorConfigurations.map(ref) } : {}),
1114
1164
  ...(preservation.httpRequestMetadata ? { httpRequestMetadata: preservation.httpRequestMetadata.map(ref) } : {}),
1115
1165
  ...(preservation.actionDataFields ? { actionDataFields: preservation.actionDataFields.map(ref) } : {}),
1166
+ ...(preservation.documentExtractionData ? { documentExtractionData: preservation.documentExtractionData.map(ref) } : {}),
1116
1167
  ...(preservation.omitTaskElementIds ? { omitTaskElementIds: preservation.omitTaskElementIds.map(ref) } : {}),
1117
1168
  ...(preservation.omitStagePositions ? { omitStagePositions: preservation.omitStagePositions.map(stageName) } : {}),
1118
1169
  ...(preservation.stageDataFields ? { stageDataFields: preservation.stageDataFields.map((entry) => ({ ...entry, stage: stageName(entry.stage) })) } : {}),
@@ -1934,7 +1985,9 @@ function emitTask(task, stageLabel, taskId, ids, resolver) {
1934
1985
  /** One task node (see {@link emitTask}). */
1935
1986
  function emitTaskNode(task, stageLabel, stageId, taskId, type, ids, resolver) {
1936
1987
  const node = { id: taskId, displayName: task.name, [CASE_FORMAT_PROFILE.nodeTypeField]: type };
1937
- node.data = taskData(task, resolver, taskId, stageId, ids);
1988
+ node.data = task.documentExtractionSaved
1989
+ ? savedDocumentExtractionData(`Document extraction task "${task.name}"`, resolver.savedDocumentExtractions, stageLabel, task.name, (task.outputs?.length ?? 0) > 0)
1990
+ : taskData(task, resolver, taskId, stageId, ids);
1938
1991
  // Every task carries `elementId: "<stageId>-<taskId>"`, the identity the
1939
1992
  // converter matches a task's io rows against:
1940
1993
  //
@@ -2065,6 +2118,9 @@ function taskData(task, resolver, taskId, stageId, ids) {
2065
2118
  : {};
2066
2119
  return withCustomOutputs(data, task, resolver);
2067
2120
  }
2121
+ case 'document-extraction':
2122
+ // Only `{ assign }` rows are written beside the two: a mapped row is one of them.
2123
+ return withCustomOutputs(documentExtractionTaskData(task, resolver, `${stageId}-${taskId}`), { ...task, outputs: task.outputs?.filter((o) => o.custom) }, resolver);
2068
2124
  case 'script':
2069
2125
  // Only `{ assign }` rows are written beside the two: a mapped row is one of them.
2070
2126
  return withCustomOutputs(scriptTaskData(task, resolver, `${stageId}-${taskId}`), { ...task, outputs: task.outputs?.filter((o) => o.custom) }, resolver);
@@ -2737,6 +2793,59 @@ function externalTaskData(kind, spec, resolver, elementId, where) {
2737
2793
  context.push(io('activityConfigurationVersion', 'string', { value: 'v2' }));
2738
2794
  return { ...data, serviceType: externalServiceType(kind, mode) };
2739
2795
  }
2796
+ /**
2797
+ * A document-extraction task (`case/document-extraction.ts`): the Designer's
2798
+ * context naming the IXP deployment through one `ixpDeployment` name binding
2799
+ * per deployment and key (as convert writes it), the two inputs, and the two
2800
+ * outputs, claimed like any task output's and kept off the case's variables.
2801
+ */
2802
+ function documentExtractionTaskData(task, resolver, elementId) {
2803
+ const where = `Document extraction task "${task.name}"`;
2804
+ const spec = task.documentExtraction;
2805
+ if (!spec)
2806
+ throw new Error(`internal SDK error: ${where} has no deployment.`);
2807
+ const refused = documentExtractionRefusal(where, spec);
2808
+ if (refused)
2809
+ throw new CompileRefusal(refused.code, refused.message, refused.suggestion);
2810
+ const mappings = documentExtractionOutputMappings(where, task.outputs);
2811
+ if (!(mappings instanceof Map))
2812
+ throw new CompileRefusal(mappings.code, mappings.message, mappings.suggestion);
2813
+ let nameRef = '';
2814
+ if (spec.deployment.trim() !== '') {
2815
+ const key = spec.deploymentKey;
2816
+ const rows = [...resolver.bindingSink.values()];
2817
+ const found = rows.find((row) => row.resource === DOCUMENT_EXTRACTION_RESOURCE && row.default === spec.deployment
2818
+ && row.resourceKey === key);
2819
+ let id = found?.id;
2820
+ if (id === undefined) {
2821
+ const ordinal = rows.filter((row) => row.resource === DOCUMENT_EXTRACTION_RESOURCE).length + 1;
2822
+ id = `bIxp${ordinal}`;
2823
+ for (let n = ordinal + 1; resolver.bindingSink.has(id); n++)
2824
+ id = `bIxp${n}`;
2825
+ resolver.bindingSink.set(id, {
2826
+ id, name: 'name', type: 'string', resource: DOCUMENT_EXTRACTION_RESOURCE,
2827
+ resourceKey: key, default: spec.deployment, propertyAttribute: 'name',
2828
+ });
2829
+ }
2830
+ nameRef = `=bindings.${id}`;
2831
+ }
2832
+ const claim = (base) => {
2833
+ let id = claimOutputId(resolver, base);
2834
+ while (resolver.caseVarNames.has(id))
2835
+ id = claimOutputId(resolver, base);
2836
+ return id;
2837
+ };
2838
+ registerMappedCompanions(resolver, mappings);
2839
+ return {
2840
+ name: DOCUMENT_EXTRACTION_NAME,
2841
+ serviceType: DOCUMENT_EXTRACTION_SERVICE_TYPE,
2842
+ context: documentExtractionContext(spec, nameRef),
2843
+ // The `v` ids follow `ioSlot`, every connector task's.
2844
+ inputs: documentExtractionInputs(spec, elementId, (name) => `v${name}`),
2845
+ outputs: documentExtractionOutputs(elementId, claim, mappings),
2846
+ version: DOCUMENT_EXTRACTION_VERSION,
2847
+ };
2848
+ }
2740
2849
  /**
2741
2850
  * A script task (`case/script.ts`): the body behind the Designer's leading `=`,
2742
2851
  * its two inputs, and its two outputs, each claimed like any task output's and
@@ -3145,12 +3254,19 @@ function isOwnNameOutput(o) {
3145
3254
  const field = o.source.replace(/^=/, '').split('.').pop() ?? '';
3146
3255
  return keepsOwnName(o.var, field);
3147
3256
  }
3257
+ /** The ids of the carried document-extraction tasks' saved output rows. */
3258
+ function savedOutputIds(entries) {
3259
+ return (entries ?? []).flatMap((entry) => (Array.isArray(entry.data.outputs) ? entry.data.outputs : [])
3260
+ .map((row) => row?.id).filter((id) => typeof id === 'string'));
3261
+ }
3148
3262
  /**
3149
3263
  * The task kinds whose output rows are fixed (the task writes its own rows and
3150
3264
  * a `.outputs()` mapping reassigns one to a case variable), so a mapped
3151
- * variable must be reserved before any row id is claimed.
3265
+ * variable must be reserved before any row id is claimed. A document
3266
+ * extraction carried in the older shape (`.savedDocumentExtraction()`) maps
3267
+ * none: its saved rows are reserved by id instead (`savedOutputIds`).
3152
3268
  */
3153
- const FIXED_OUTPUT_KINDS = new Set(['http-request', 'script']);
3269
+ const FIXED_OUTPUT_KINDS = new Set(['document-extraction', 'http-request', 'script']);
3154
3270
  /**
3155
3271
  * The case variables a fixed-output task's `.outputs()` maps, declared or not.
3156
3272
  * Collected before any task is emitted, so no task's own output row takes one
@@ -3163,7 +3279,7 @@ function mappedFixedOutputVars(built) {
3163
3279
  for (const stage of built.stages)
3164
3280
  for (const lane of stage.lanes)
3165
3281
  for (const task of lane)
3166
- if (FIXED_OUTPUT_KINDS.has(task.kind))
3282
+ if (FIXED_OUTPUT_KINDS.has(task.kind) && !task.documentExtractionSaved)
3167
3283
  for (const o of task.outputs ?? [])
3168
3284
  if (!o.custom)
3169
3285
  vars.add(o.var);
@@ -160,6 +160,15 @@ export declare const REFUSALS: {
160
160
  readonly CASE_IN_ARG_UNBOUND: "lowering";
161
161
  readonly CASE_LAYOUT_NODE_MATCH: "lowering";
162
162
  readonly CASE_LAYOUT_UNKNOWN_FIELD: "lowering";
163
+ readonly DOCUMENT_EXTRACTION_NO_MODEL: "lint";
164
+ readonly DOCUMENT_EXTRACTION_NO_DEPLOYMENT: "lint";
165
+ readonly DOCUMENT_EXTRACTION_NO_FOLDER_KEY: "lint";
166
+ readonly DOCUMENT_EXTRACTION_NO_FOLDER: "lint";
167
+ readonly DOCUMENT_EXTRACTION_NO_DEPLOYMENT_KEY: "lowering";
168
+ readonly DOCUMENT_EXTRACTION_NO_FILE: "lint";
169
+ readonly DOCUMENT_EXTRACTION_OUTPUT: "lowering";
170
+ readonly DOCUMENT_EXTRACTION_OLDER_SHAPE: "lint";
171
+ readonly DOCUMENT_EXTRACTION_SAVED_DATA: "lowering";
163
172
  readonly SCRIPT_BODY_SYNTAX: "lint";
164
173
  readonly SCRIPT_OUTPUT: "lowering";
165
174
  readonly HTTP_REQUEST_CONNECTOR: "lowering";
@@ -209,6 +209,23 @@ export const REFUSALS = {
209
209
  CASE_IN_ARG_UNBOUND: 'lowering',
210
210
  CASE_LAYOUT_NODE_MATCH: 'lowering',
211
211
  CASE_LAYOUT_UNKNOWN_FIELD: 'lowering',
212
+ // Case document-extraction task (case/document-extraction.ts). A missing
213
+ // model, folder key or file is written as authored (`lint`). A missing
214
+ // deployment key leaves the binding no resourceKey, which the platform
215
+ // rejects and decompile cannot read back, and an output other than the two
216
+ // has no row (`lowering`).
217
+ DOCUMENT_EXTRACTION_NO_MODEL: 'lint',
218
+ DOCUMENT_EXTRACTION_NO_DEPLOYMENT: 'lint',
219
+ DOCUMENT_EXTRACTION_NO_FOLDER_KEY: 'lint',
220
+ DOCUMENT_EXTRACTION_NO_FOLDER: 'lint',
221
+ DOCUMENT_EXTRACTION_NO_DEPLOYMENT_KEY: 'lowering',
222
+ DOCUMENT_EXTRACTION_NO_FILE: 'lint',
223
+ DOCUMENT_EXTRACTION_OUTPUT: 'lowering',
224
+ // The older, flat shape, carried as saved (case/document-extraction-saved.ts):
225
+ // check warns it is not editable (`lint`); compile refuses a carried task with
226
+ // no saved data, or with outputs it cannot add to the saved rows (`lowering`).
227
+ DOCUMENT_EXTRACTION_OLDER_SHAPE: 'lint',
228
+ DOCUMENT_EXTRACTION_SAVED_DATA: 'lowering',
212
229
  // Case script task (case/script.ts). A string body that does not parse is
213
230
  // written as authored (`lint`); an output other than the two has no row to
214
231
  // write it to (`lowering`).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.81.0",
3
+ "version": "6.82.1",
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": "f1f3a61ac051ab0738028776a78b2e564a15987f"
106
+ "gitref": "cd9e43c9e5505bd7691f83cf7cce2283a190ec7b"
107
107
  }