@uipath/maestro-builder-sdk 6.118.1 → 6.119.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api-index.md CHANGED
@@ -135,7 +135,7 @@ could hand you spans for a version you do not have.
135
135
  | `DocumentClassifyInputs` | interface | `dist/nodes/document/flow/spec.d.ts:10-39` | Option shapes | What `documentClassify()` takes: the document, and how to split and classify it. |
136
136
  | `DocValidationInputs` | interface | `dist/nodes/hitl/flow/spec.d.ts:76-99` | Option shapes | The Document Validation task's subject — `variant: 'document-validation'` only. |
137
137
  | `DoWhileOptions` | interface | `dist/flow-sdk.d.ts:451-460` | Option shapes | Do-while options. |
138
- | `dynamicExtract` | function | `dist/nodes/document/flow/factories.d.ts:20-90` | Actions | Extract fields from a document with an INLINE schema — Dynamic Extract (`uipath.ixp.extract-document-builder`), the… |
138
+ | `dynamicExtract` | function | `dist/nodes/document/flow/factories.d.ts:20-89` | Actions | Extract fields from a document with an INLINE schema — Dynamic Extract (`uipath.ixp.extract-document-builder`), the… |
139
139
  | `DynamicExtractInputs` | interface | `dist/nodes/document/flow/spec.d.ts:56-131` | Option shapes | What `dynamicExtract()` takes: the document and the fields to extract from it. |
140
140
  | `EdgeRoute` | interface | `dist/flow-sdk.d.ts:651-665` | Supporting types | One edge's route: user-dragged bends and/or the auto-router's waypoints. |
141
141
  | `endCall` | function | `dist/nodes/agent/flow/factories.d.ts:32-39` | Actions | Hang up (`uipath.conversational.voice.end-call`). |
@@ -197,7 +197,7 @@ could hand you spans for a version you do not have.
197
197
  | `InOutField` | interface | `dist/core/actions.d.ts:278-295` | Supporting types | A value the reviewer READS **and can correct**: pre-filled from the flow, editable on the form, and the (possibly… |
198
198
  | `input` | function | `dist/core/expr.d.ts:44-61` | Expressions and types | Reference a flow input by name → `$vars.<triggerId>.output.<name>`. |
199
199
  | `isLookupToken` | function | `dist/core/lookups.d.ts:53-54` | Generated descriptors | True when `v` is an unresolved LookupToken. |
200
- | `ixpExtract` | function | `dist/nodes/document/flow/factories.d.ts:91-145` | Actions | Extract fields from a document with a published IxP project — the platform's **Extract** node (`uipath.ixp.*`, service… |
200
+ | `ixpExtract` | function | `dist/nodes/document/flow/factories.d.ts:90-144` | Actions | Extract fields from a document with a published IxP project — the platform's **Extract** node (`uipath.ixp.*`, service… |
201
201
  | `IxpExtractInputs` | interface | `dist/nodes/document/flow/spec.d.ts:149-224` | Option shapes | What `ixpExtract()` takes: the IxP project's extractor, its identity on the tenant, and the document. |
202
202
  | `IxpToolRef` | interface | `dist/core/actions.d.ts:789-827` | Supporting types | A published IxP (Intelligent eXtraction Platform) project as a tool — the agent decides when to extract a document and… |
203
203
  | `js` | function | `dist/core/expr.d.ts:247-282` | Expressions and types | Build a raw JS *expression* (a condition or computation). |
@@ -168,14 +168,20 @@ export async function run(argv) {
168
168
  // The node registry cache `uip maestro flow registry pull` writes: a `rawNode`
169
169
  // without `manifest` resolves its definition there (#1981). Read on first use.
170
170
  const nodeCatalog = readNodeCatalog();
171
+ // The `.flow` this compile overwrites: a step reads the node it had there
172
+ // (Extract document keeps its taxonomy ids, #1985).
173
+ const overwrites = readJsonOrUndefined(resolve(out));
174
+ const notes = [];
171
175
  const warnings = [];
172
176
  let emitted;
173
177
  try {
174
178
  emitted = await withFetchedDefinitions(argv, (library) => {
175
179
  // One pass's warnings: a pass that missed a definition runs again.
176
180
  warnings.length = 0;
181
+ notes.length = 0;
177
182
  return serializeWithSidecars(built, {
178
183
  library, bindings, warn: (w) => warnings.push(w), resources, agentSource, nodeCatalog,
184
+ overwrites, note: (n) => notes.push(n),
179
185
  ...(solution !== undefined ? { solution } : {}),
180
186
  carriedDrafts: (d) => warnings.push(draftWarning(d)),
181
187
  });
@@ -247,6 +253,8 @@ export async function run(argv) {
247
253
  console.log(`compile: wrote ${sidecar.path}`);
248
254
  written.push(target);
249
255
  }
256
+ for (const n of notes)
257
+ console.log(`compile: ${JSON.stringify(n.step)} ${n.message}`);
250
258
  for (const path of processors?.written ?? [])
251
259
  console.log(`compile: wrote ${path} (IDP processor)`);
252
260
  for (const why of processors?.skipped ?? [])
@@ -267,7 +275,10 @@ export async function run(argv) {
267
275
  + `. To make this explicit, set source: "${to}" on "${step}" in the .flow.ts.`);
268
276
  }
269
277
  }
270
- reportResult({ path: resolve(out), nodes: flowJson.nodes.length, edges: flowJson.edges.length, sidecars: written });
278
+ reportResult({
279
+ path: resolve(out), nodes: flowJson.nodes.length, edges: flowJson.edges.length, sidecars: written,
280
+ ...(notes.length > 0 ? { notes } : {}),
281
+ });
271
282
  // PRUNE the agent resources this compile owns but did not write this time.
272
283
  // Compile otherwise only ever ADDS files, and an agent resource is keyed by a
273
284
  // uuid derived from the step name and the resource's identity — so dropping a
@@ -367,6 +367,14 @@ export declare const REFUSALS: {
367
367
  readonly EXTRACT_READ_NOT_OUTPUT: "lint";
368
368
  readonly EXTRACT_READ_UNKNOWN_FIELD: "lint";
369
369
  readonly EXTRACT_SCHEMA_SHAPE: "lint";
370
+ readonly EXTRACT_TAXONOMY_BARE: "lint";
371
+ readonly EXTRACT_TAXONOMY_DUPLICATE_ID: "lint";
372
+ readonly EXTRACT_TAXONOMY_FIELD_TYPE: "lint";
373
+ readonly EXTRACT_TAXONOMY_LEGACY: "lint";
374
+ readonly EXTRACT_TAXONOMY_LIMIT: "lint";
375
+ readonly EXTRACT_TAXONOMY_NESTING: "lint";
376
+ readonly EXTRACT_TAXONOMY_REF: "lint";
377
+ readonly EXTRACT_TAXONOMY_STRUCTURE: "lint";
370
378
  readonly FAKE_JOIN: "lint";
371
379
  readonly FILE_NOT_FOUND: "lowering";
372
380
  readonly FIRE_AND_FORGET_READ: "lint";
@@ -441,6 +441,14 @@ export const REFUSALS = {
441
441
  EXTRACT_READ_NOT_OUTPUT: 'lint',
442
442
  EXTRACT_READ_UNKNOWN_FIELD: 'lint',
443
443
  EXTRACT_SCHEMA_SHAPE: 'lint',
444
+ EXTRACT_TAXONOMY_BARE: 'lint',
445
+ EXTRACT_TAXONOMY_DUPLICATE_ID: 'lint',
446
+ EXTRACT_TAXONOMY_FIELD_TYPE: 'lint',
447
+ EXTRACT_TAXONOMY_LEGACY: 'lint',
448
+ EXTRACT_TAXONOMY_LIMIT: 'lint',
449
+ EXTRACT_TAXONOMY_NESTING: 'lint',
450
+ EXTRACT_TAXONOMY_REF: 'lint',
451
+ EXTRACT_TAXONOMY_STRUCTURE: 'lint',
444
452
  FAKE_JOIN: 'lint',
445
453
  FILE_NOT_FOUND: 'lowering',
446
454
  FIRE_AND_FORGET_READ: 'lint',
@@ -179,6 +179,13 @@ export interface FlowSerializeContext {
179
179
  * pair) or must pick an id that is not taken; add entries through `bind`.
180
180
  */
181
181
  readonly bindings: ReadonlyMap<string, Readonly<Record<string, unknown>>>;
182
+ /**
183
+ * The node this step had in the `.flow` the compile overwrites
184
+ * (`SerializeOpts.overwrites`): same id, same type; undefined when there is none.
185
+ */
186
+ overwrittenNode(): unknown;
187
+ /** Report an informational line about what was written (`SerializeOpts.note`). */
188
+ note(message: string, data?: unknown): void;
182
189
  /**
183
190
  * A symbolic `connection` or `folder` label resolved through the flow's
184
191
  * bindings.json, as a connector step's is: a self-referential label throws the
package/dist/merge-cli.js CHANGED
@@ -424,8 +424,12 @@ export async function run(argv) {
424
424
  if (editedIsSource) {
425
425
  // The edited source gets what `compile` gives it: check() with the same
426
426
  // options, and the serializer's warnings (CONNECTION_STUB, ...) printed.
427
+ // It compiles over the original, as `compile` over the same file does: a
428
+ // step reads the node it had there (`SerializeOpts.overwrites`), so an
429
+ // idless Extract taxonomy keeps the ids the saved .flow has (#1985).
427
430
  const compiled = await compileSourceDraftTolerant(resolve(editedPath), {
428
431
  ...compileOpts,
432
+ overwrites: original,
429
433
  warn: (w) => console.error(` ⚠ [${w.code}] ${w.message}`),
430
434
  });
431
435
  edited = compiled.flow;
@@ -26,9 +26,14 @@ export declare function documentClassify(inputs: DocumentClassifyInputs): Action
26
26
  * @remarks
27
27
  * `schema` is the extraction taxonomy: `prompt` (the instructions) and
28
28
  * `outputSchema`, whose `properties` are the field groups and whose `$defs`
29
- * are the field types the fields `$ref`. Its groups and fields are emitted as
30
- * written, so each carries its own stable id (`x-uipath-field-group-id`,
31
- * `x-uipath-field-id`).
29
+ * are the field types the fields `$ref`. Write it without ids or closing
30
+ * keys: compile gives every field group its `x-uipath-field-group-id`, every
31
+ * field its `x-uipath-field-id` and every nested group (`Invoice > Lines`)
32
+ * its parent's id, and closes the objects (`required` lists every property,
33
+ * `additionalProperties: false`), as `uip maestro flow nodes schema set` does.
34
+ * An id the source carries is kept. A missing one is the one the `.flow` being
35
+ * overwritten has for the same entry, or else one minted from the entry's
36
+ * place, so a recompile gives the same id.
32
37
  *
33
38
  * The output is a processed document: `version`, `type` (`'Extraction'`),
34
39
  * `result`, `taxonomy` and `metadata` (run ids and the model configuration).
@@ -56,20 +61,14 @@ export declare function documentClassify(inputs: DocumentClassifyInputs): Action
56
61
  * prompt: 'Extract the invoice header. Values are on the page; do not compute them.',
57
62
  * outputSchema: {
58
63
  * type: 'object',
59
- * additionalProperties: false,
60
- * required: ['Invoice'],
61
64
  * properties: {
62
65
  * Invoice: {
63
66
  * type: ['object', 'null'],
64
67
  * description: 'The invoice header, which appears once per document.',
65
- * additionalProperties: false,
66
- * required: ['Total'],
67
- * 'x-uipath-field-group-id': '3f9a1c2e-5b7d-4e8a-9c1f-2d6b8e0a4c13',
68
68
  * properties: {
69
69
  * Total: {
70
70
  * $ref: '#/$defs/ft-monetary-quantity',
71
71
  * description: 'The amount payable including tax.',
72
- * 'x-uipath-field-id': '7c2e4a91-0d3b-4f6e-a8c5-1b9d3f7e2a64',
73
72
  * },
74
73
  * },
75
74
  * },
@@ -27,9 +27,14 @@ export function documentClassify(inputs) {
27
27
  * @remarks
28
28
  * `schema` is the extraction taxonomy: `prompt` (the instructions) and
29
29
  * `outputSchema`, whose `properties` are the field groups and whose `$defs`
30
- * are the field types the fields `$ref`. Its groups and fields are emitted as
31
- * written, so each carries its own stable id (`x-uipath-field-group-id`,
32
- * `x-uipath-field-id`).
30
+ * are the field types the fields `$ref`. Write it without ids or closing
31
+ * keys: compile gives every field group its `x-uipath-field-group-id`, every
32
+ * field its `x-uipath-field-id` and every nested group (`Invoice > Lines`)
33
+ * its parent's id, and closes the objects (`required` lists every property,
34
+ * `additionalProperties: false`), as `uip maestro flow nodes schema set` does.
35
+ * An id the source carries is kept. A missing one is the one the `.flow` being
36
+ * overwritten has for the same entry, or else one minted from the entry's
37
+ * place, so a recompile gives the same id.
33
38
  *
34
39
  * The output is a processed document: `version`, `type` (`'Extraction'`),
35
40
  * `result`, `taxonomy` and `metadata` (run ids and the model configuration).
@@ -57,20 +62,14 @@ export function documentClassify(inputs) {
57
62
  * prompt: 'Extract the invoice header. Values are on the page; do not compute them.',
58
63
  * outputSchema: {
59
64
  * type: 'object',
60
- * additionalProperties: false,
61
- * required: ['Invoice'],
62
65
  * properties: {
63
66
  * Invoice: {
64
67
  * type: ['object', 'null'],
65
68
  * description: 'The invoice header, which appears once per document.',
66
- * additionalProperties: false,
67
- * required: ['Total'],
68
- * 'x-uipath-field-group-id': '3f9a1c2e-5b7d-4e8a-9c1f-2d6b8e0a4c13',
69
69
  * properties: {
70
70
  * Total: {
71
71
  * $ref: '#/$defs/ft-monetary-quantity',
72
72
  * description: 'The amount payable including tax.',
73
- * 'x-uipath-field-id': '7c2e4a91-0d3b-4f6e-a8c5-1b9d3f7e2a64',
74
73
  * },
75
74
  * },
76
75
  * },
@@ -13,11 +13,22 @@ import { declareKeys } from '../../../core/option-keys.js';
13
13
  import { stableId } from '../../../core/stable-id.js';
14
14
  import { buildDefaultSchemaDocument, buildScaffoldConfig } from './idp-processor.js';
15
15
  import { checkExtractRead, isLegacyExtractOutputs } from './extract-output.js';
16
+ import { closeObjectSchemas, derivedTaxonomyMint, settleTaxonomyIds } from './taxonomy.js';
17
+ import { checkTaxonomy, isBareJsonSchema, isLegacyTaxonomy, isReadableTaxonomy } from './taxonomy-check.js';
16
18
  export const DOCUMENT_DIAGNOSTICS = {
17
19
  DOC_NO_FILEREF: { severity: 'error', summary: 'no fileRef, so nothing to classify or extract from' },
18
- EXTRACT_SCHEMA_SHAPE: { severity: 'error', summary: 'a Dynamic Extract schema that is not an object' },
20
+ EXTRACT_SCHEMA_SHAPE: { severity: 'error', summary: 'a Dynamic Extract schema that is not a { prompt, outputSchema } document' },
19
21
  EXTRACT_READ_NOT_OUTPUT: { severity: 'error', summary: 'an Extract document step read outside output' },
20
22
  EXTRACT_READ_UNKNOWN_FIELD: { severity: 'error', summary: 'an Extract document step read of a field the processed document does not have' },
23
+ // The taxonomy rules `nodes schema set` refuses and `flow validate` reports (#1986).
24
+ EXTRACT_TAXONOMY_LEGACY: { severity: 'warning', summary: 'a taxonomy in the superseded { taxonomy, fieldTypes } shape' },
25
+ EXTRACT_TAXONOMY_BARE: { severity: 'warning', summary: 'a bare JSON Schema where the { prompt, outputSchema } taxonomy goes' },
26
+ EXTRACT_TAXONOMY_STRUCTURE: { severity: 'error', summary: 'a taxonomy container that is not the shape the Schema Editor reads' },
27
+ EXTRACT_TAXONOMY_REF: { severity: 'error', summary: 'a field with no $ref, or a $ref that names no field type in $defs' },
28
+ EXTRACT_TAXONOMY_NESTING: { severity: 'error', summary: 'a nested group (A > B) with no group A, or a top-level group naming a parent' },
29
+ EXTRACT_TAXONOMY_DUPLICATE_ID: { severity: 'error', summary: 'two field groups or two fields with one id' },
30
+ EXTRACT_TAXONOMY_FIELD_TYPE: { severity: 'error', summary: 'a $defs key a $ref cannot name unescaped, or a field type with no title' },
31
+ EXTRACT_TAXONOMY_LIMIT: { severity: 'error', summary: 'a name over 128 characters (a nested group\'s whole A > B key) or instructions over 4096' },
21
32
  };
22
33
  function checkFileRef(inputs, verb, ctx) {
23
34
  const fr = inputs.fileRef;
@@ -128,6 +139,31 @@ function withConfig(schema, modelConfig) {
128
139
  return schema;
129
140
  return { config: buildScaffoldConfig(modelConfig), ...schema };
130
141
  }
142
+ /**
143
+ * The schema as `nodes schema set` writes it: its taxonomy ids settled, then
144
+ * its objects closed so the Schema Editor opens it. A value with no
145
+ * `outputSchema` object is written as given.
146
+ */
147
+ function withTaxonomyIds(schema, flowId, nodeId, previous) {
148
+ if (!isObject(schema) || !isObject(schema.outputSchema))
149
+ return { document: schema };
150
+ const { document, counts } = settleTaxonomyIds(schema, isObject(previous) ? previous : undefined, derivedTaxonomyMint(flowId, nodeId));
151
+ closeObjectSchemas(document.outputSchema);
152
+ return { document, counts };
153
+ }
154
+ /** The schema document the overwritten `.flow` has for this step, if any. */
155
+ function overwrittenSchema(ctx) {
156
+ const node = ctx.overwrittenNode();
157
+ return node?.inputs?.schemaDocument;
158
+ }
159
+ /** Say what happened to the ids, as `nodes schema set` reports it; nothing for a taxonomy with no entries. */
160
+ function noteTaxonomyIds(ctx, c) {
161
+ if (c === undefined || c.groupIdsPreserved + c.groupIdsMinted + c.fieldIdsPreserved + c.fieldIdsMinted === 0)
162
+ return;
163
+ ctx.note(`taxonomy ids: ${c.groupIdsPreserved} group and ${c.fieldIdsPreserved} field id(s) kept, `
164
+ + `${c.groupIdsMinted} group and ${c.fieldIdsMinted} field id(s) minted`
165
+ + (c.businessChecksDropped > 0 ? `; ${c.businessChecksDropped} business check(s) dropped (they named a field or group that is gone)` : ''), c);
166
+ }
131
167
  /** The lifted schema without a `config` that is only the scaffold {@link withConfig} adds back. */
132
168
  function withoutScaffoldConfig(schema, modelConfig) {
133
169
  if (!isObject(schema) || JSON.stringify(schema.config) !== JSON.stringify(buildScaffoldConfig(modelConfig)))
@@ -135,6 +171,39 @@ function withoutScaffoldConfig(schema, modelConfig) {
135
171
  const { config: _scaffold, ...rest } = schema;
136
172
  return rest;
137
173
  }
174
+ const SET_HINT = 'The document is { prompt, outputSchema }, the one `uip maestro flow nodes schema set` takes; '
175
+ + 'see website/reference/document-pipeline.md.';
176
+ /**
177
+ * The taxonomy rules (#1986): what `nodes schema set` refuses, run on the
178
+ * document as compile writes it (config scaffolded, ids settled, objects
179
+ * closed), so nothing compile fills in is reported.
180
+ */
181
+ function checkSchema(inputs, ctx) {
182
+ const schema = inputs.schema;
183
+ if (schema === undefined)
184
+ return;
185
+ const at = `"${ctx.step}"'s schema`;
186
+ if (!isObject(schema)) {
187
+ ctx.report('EXTRACT_SCHEMA_SHAPE', `${at} must be an object (the inline extraction schema document).`, SET_HINT);
188
+ return;
189
+ }
190
+ if (isLegacyTaxonomy(schema)) {
191
+ ctx.report('EXTRACT_TAXONOMY_LEGACY', `${at} uses the superseded { taxonomy, fieldTypes } shape, which \`nodes schema set\` refuses.`, SET_HINT);
192
+ return;
193
+ }
194
+ if (!isReadableTaxonomy(schema)) {
195
+ if (isBareJsonSchema(schema)) {
196
+ ctx.report('EXTRACT_TAXONOMY_BARE', `${at} is a bare JSON Schema: no "prompt", no field types in "$defs", no field groups. \`nodes schema set\` refuses it, `
197
+ + 'and the processor built from it holds no fields.', 'Wrap the groups as { prompt: \'…\', outputSchema: { type: \'object\', properties: { <Group>: … }, $defs: { … } } }. ' + SET_HINT);
198
+ return;
199
+ }
200
+ ctx.report('EXTRACT_SCHEMA_SHAPE', `${at} must have "prompt" (the overall instructions, a string) and "outputSchema" (an object).`, SET_HINT);
201
+ return;
202
+ }
203
+ const { document } = withTaxonomyIds(withConfig(schema, undefined), 'check', ctx.step);
204
+ for (const finding of checkTaxonomy(document))
205
+ ctx.report(finding.code, `${at}: ${finding.path}: ${finding.message}`);
206
+ }
138
207
  /** A non-empty string input of the node, as the lift keeps it. */
139
208
  function liftText(inputs, key, ctx) {
140
209
  const v = ctx.plainValue(inputs[key]);
@@ -235,6 +304,13 @@ export const dynamicExtractNodeType = {
235
304
  const processorKey = inputs.processorKey !== undefined && inputs.processorKey !== ''
236
305
  ? inputs.processorKey
237
306
  : readOnly || folderPath !== undefined ? undefined : mintedProcessorKey(ctx.flowId, ctx.nodeId);
307
+ // One pass, as `nodes schema set` does it: the source's ids are claimed, a
308
+ // missing one is adopted from the overwritten `.flow` by name, else minted;
309
+ // business checks are pruned only after that.
310
+ const taxonomy = inputs.schema !== undefined
311
+ ? withTaxonomyIds(withConfig(inputs.schema, modelConfig ?? d.modelConfig), ctx.flowId, ctx.nodeId, overwrittenSchema(ctx))
312
+ : undefined;
313
+ noteTaxonomyIds(ctx, taxonomy?.counts);
238
314
  return {
239
315
  inputs: {
240
316
  ...d,
@@ -258,8 +334,11 @@ export const dynamicExtractNodeType = {
258
334
  ...(modelConfig !== undefined ? { modelConfig } : {}),
259
335
  // No schema: the empty taxonomy `nodes create` seeds, so the node opens in
260
336
  // the Schema Editor and its processor has a document to hold.
337
+ // Every field group and field gets its stable id (#1985), as
338
+ // `nodes schema set` gives them: kept when the source carries one,
339
+ // else minted from the flow, the node and the entry's place.
261
340
  schemaDocument: inputs.schema !== undefined
262
- ? withConfig(inputs.schema, modelConfig ?? d.modelConfig)
341
+ ? taxonomy.document
263
342
  : buildDefaultSchemaDocument(modelConfig ?? d.modelConfig),
264
343
  // The definition's model declares `source: true`: the platform mints a
265
344
  // stable storage slot per instance; omit it and the node validates then
@@ -286,6 +365,8 @@ export const dynamicExtractNodeType = {
286
365
  // not printed; anything else is the author's.
287
366
  const rawSchema = ctx.plainValue(inputs.schemaDocument);
288
367
  const seeded = buildDefaultSchemaDocument(inputs.modelConfig);
368
+ // Taxonomy ids are printed as the node has them (#1985): a recompile keeps
369
+ // an id the source carries, in place, so the file comes back byte for byte.
289
370
  const schema = rawSchema !== undefined && JSON.stringify(rawSchema) !== JSON.stringify(seeded)
290
371
  ? withoutScaffoldConfig(rawSchema, inputs.modelConfig) : undefined;
291
372
  // The processor a node already names is printed, so a recompile keeps it;
@@ -325,9 +406,7 @@ export const dynamicExtractNodeType = {
325
406
  }),
326
407
  check: ({ inputs }, ctx) => {
327
408
  checkFileRef(inputs, 'extract from', ctx);
328
- if (inputs.schema !== undefined && (typeof inputs.schema !== 'object' || Array.isArray(inputs.schema))) {
329
- ctx.report('EXTRACT_SCHEMA_SHAPE', `"${ctx.step}"'s schema must be an object (the inline extraction schema document).`);
330
- }
409
+ checkSchema(inputs, ctx);
331
410
  },
332
411
  // check collected no expressions for this kind before the port; unchanged by it.
333
412
  expressions: () => [],
@@ -0,0 +1,36 @@
1
+ type Json = Record<string, unknown>;
2
+ /** The check codes, by the rule each one stands for. */
3
+ export type TaxonomyCode = 'EXTRACT_TAXONOMY_STRUCTURE' | 'EXTRACT_TAXONOMY_REF' | 'EXTRACT_TAXONOMY_NESTING' | 'EXTRACT_TAXONOMY_DUPLICATE_ID' | 'EXTRACT_TAXONOMY_FIELD_TYPE' | 'EXTRACT_TAXONOMY_LIMIT';
4
+ export interface TaxonomyFinding {
5
+ code: TaxonomyCode;
6
+ /** Dot/bracket path into the schema document, e.g. `outputSchema.properties["Invoice"]`. */
7
+ path: string;
8
+ message: string;
9
+ }
10
+ /**
11
+ * The extraction API's limits, flow-schema's `IXP_MAX_*` (`ixp-schema/constants.ts`).
12
+ * The names are 128 since flow-workbench #5603 (flow-schema 0.138.0-develop,
13
+ * 2026-11-06), which matches IXP; the 0.135.x line still says 64. The
14
+ * newest line is copied, so `check` refuses nothing the platform accepts.
15
+ * tests/taxonomy-limits-drift.test.ts holds each one to the flow-schema the
16
+ * repo pins for it.
17
+ */
18
+ export declare const TAXONOMY_LIMITS: {
19
+ readonly fieldGroupName: 128;
20
+ readonly fieldName: 128;
21
+ readonly fieldTypeName: 128;
22
+ readonly instructions: 4096;
23
+ };
24
+ /**
25
+ * Every rule a `{ prompt, outputSchema }` document breaks, in the CLI
26
+ * validator's order, then the limits. Empty when `nodes schema set` would
27
+ * write it.
28
+ */
29
+ export declare function checkTaxonomy(document: Json): TaxonomyFinding[];
30
+ /** The superseded private `{ taxonomy, fieldTypes }` document. */
31
+ export declare function isLegacyTaxonomy(value: unknown): boolean;
32
+ /** A `{ prompt, outputSchema }` document — the shape `schema set` takes. */
33
+ export declare function isReadableTaxonomy(value: unknown): value is Json;
34
+ /** A bare JSON Schema — `{ type: 'object', properties }` with no `prompt` around it (flow-schema `readExtractionOutputSchema`). */
35
+ export declare function isBareJsonSchema(value: unknown): boolean;
36
+ export {};
@@ -0,0 +1,207 @@
1
+ /**
2
+ * `check`'s rules for an Extract document taxonomy (builder-sdk#1986): the
3
+ * refusals of `uip maestro flow nodes schema set`, which `flow validate`
4
+ * reports too, one code per rule.
5
+ *
6
+ * They run on the document as compile writes it (config scaffolded, ids
7
+ * settled, objects closed, `taxonomy.ts`), so nothing compile fills in is
8
+ * reported; for that reason the CLI validator's warnings for a missing id are
9
+ * left out.
10
+ *
11
+ * Copied from uipath-cli `flow-tool/src/services/extract-schema/validate-schema-document.ts`
12
+ * and flow-schema's `ixp-schema-limits` rule. Pure (FB015).
13
+ */
14
+ import { GROUP_PATH_SEPARATOR, PARENT_FIELD_GROUP_ID_EXTENSION, hasType, isRecord, quoteKey, readOutputSchema, } from './taxonomy.js';
15
+ /** A `$defs` key becomes a `$ref` token; one needing escaping is rejected downstream. */
16
+ const DEFS_KEY_PATTERN = /^[A-Za-z0-9._-]+$/;
17
+ const DEFS_REFERENCE_PREFIX = '#/$defs/';
18
+ /**
19
+ * The extraction API's limits, flow-schema's `IXP_MAX_*` (`ixp-schema/constants.ts`).
20
+ * The names are 128 since flow-workbench #5603 (flow-schema 0.138.0-develop,
21
+ * 2026-11-06), which matches IXP; the 0.135.x line still says 64. The
22
+ * newest line is copied, so `check` refuses nothing the platform accepts.
23
+ * tests/taxonomy-limits-drift.test.ts holds each one to the flow-schema the
24
+ * repo pins for it.
25
+ */
26
+ export const TAXONOMY_LIMITS = {
27
+ fieldGroupName: 128,
28
+ fieldName: 128,
29
+ fieldTypeName: 128,
30
+ instructions: 4096,
31
+ };
32
+ function referenceFindings(node, path, keys, out) {
33
+ if (!isRecord(node))
34
+ return;
35
+ const reference = node.$ref;
36
+ if (typeof reference === 'string') {
37
+ const key = reference.startsWith(DEFS_REFERENCE_PREFIX) ? reference.slice(DEFS_REFERENCE_PREFIX.length) : undefined;
38
+ if (key === undefined || !keys.has(key)) {
39
+ out.push({ code: 'EXTRACT_TAXONOMY_REF', path: `${path}.$ref`, message: `$ref "${reference}" does not name a field type in outputSchema.$defs.` });
40
+ }
41
+ }
42
+ for (const member of ['properties', '$defs']) {
43
+ const children = node[member];
44
+ if (!isRecord(children))
45
+ continue;
46
+ for (const [key, child] of Object.entries(children))
47
+ referenceFindings(child, `${path}.${member}${quoteKey(key)}`, keys, out);
48
+ }
49
+ referenceFindings(node.items, `${path}.items`, keys, out);
50
+ if (Array.isArray(node.anyOf))
51
+ node.anyOf.forEach((child, i) => referenceFindings(child, `${path}.anyOf[${i}]`, keys, out));
52
+ }
53
+ function measure(out, value, limit, subject, path) {
54
+ if (typeof value !== 'string' || value.length <= limit)
55
+ return;
56
+ out.push({ code: 'EXTRACT_TAXONOMY_LIMIT', path, message: `${subject} is ${value.length} characters; the maximum is ${limit}.` });
57
+ }
58
+ /** The limits flow-schema's `ixp-schema-limits` rule applies, with its subjects. */
59
+ function limitFindings(document, out) {
60
+ measure(out, document.prompt, TAXONOMY_LIMITS.instructions, 'Overall instructions', 'prompt');
61
+ const outputSchema = isRecord(document.outputSchema) ? document.outputSchema : {};
62
+ const groups = isRecord(outputSchema.properties) ? outputSchema.properties : {};
63
+ for (const [name, raw] of Object.entries(groups)) {
64
+ const group = isRecord(raw) ? raw : undefined;
65
+ const path = `outputSchema.properties${quoteKey(name)}`;
66
+ const where = name ? `field group "${name}"` : 'an unnamed field group';
67
+ measure(out, name, TAXONOMY_LIMITS.fieldGroupName, `Field group "${name}"`, path);
68
+ measure(out, group?.description, TAXONOMY_LIMITS.instructions, `Instructions on ${where}`, `${path}.description`);
69
+ const items = isRecord(group?.items) ? group.items : undefined;
70
+ const fields = (isRecord(items?.properties) ? items.properties : undefined) ?? (isRecord(group?.properties) ? group.properties : {});
71
+ for (const [fieldName, rawField] of Object.entries(fields)) {
72
+ const which = fieldName ? `field "${fieldName}"` : 'an unnamed field';
73
+ const fieldPath = `${path}.${items ? 'items.' : ''}properties${quoteKey(fieldName)}`;
74
+ measure(out, fieldName, TAXONOMY_LIMITS.fieldName, `${which.charAt(0).toUpperCase()}${which.slice(1)} in ${where}`, fieldPath);
75
+ measure(out, isRecord(rawField) ? rawField.description : undefined, TAXONOMY_LIMITS.instructions, `Instructions on ${which} in ${where}`, `${fieldPath}.description`);
76
+ }
77
+ }
78
+ const defs = isRecord(outputSchema.$defs) ? outputSchema.$defs : {};
79
+ for (const [key, raw] of Object.entries(defs)) {
80
+ const def = isRecord(raw) ? raw : undefined;
81
+ const which = typeof def?.title === 'string' && def.title ? `field type "${def.title}"` : 'an unnamed field type';
82
+ const path = `outputSchema.$defs${quoteKey(key)}`;
83
+ measure(out, def?.title, TAXONOMY_LIMITS.fieldTypeName, `${which.charAt(0).toUpperCase()}${which.slice(1)}`, `${path}.title`);
84
+ measure(out, def?.description, TAXONOMY_LIMITS.instructions, `Instructions on ${which}`, `${path}.description`);
85
+ }
86
+ }
87
+ /**
88
+ * Every rule a `{ prompt, outputSchema }` document breaks, in the CLI
89
+ * validator's order, then the limits. Empty when `nodes schema set` would
90
+ * write it.
91
+ */
92
+ export function checkTaxonomy(document) {
93
+ const out = [];
94
+ const structure = (path, message) => { out.push({ code: 'EXTRACT_TAXONOMY_STRUCTURE', path, message }); };
95
+ if (typeof document.prompt !== 'string')
96
+ structure('prompt', 'prompt must be a string (the overall instructions).');
97
+ const outputSchema = document.outputSchema;
98
+ if (!isRecord(outputSchema)) {
99
+ structure('outputSchema', 'outputSchema must be an object.');
100
+ return out;
101
+ }
102
+ if (outputSchema.$defs !== undefined && !isRecord(outputSchema.$defs)) {
103
+ structure('outputSchema.$defs', '$defs must be an object of field types.');
104
+ }
105
+ else if (isRecord(outputSchema.$defs)) {
106
+ for (const [key, def] of Object.entries(outputSchema.$defs)) {
107
+ if (!isRecord(def))
108
+ structure(`outputSchema.$defs${quoteKey(key)}`, 'A field type must be an object.');
109
+ }
110
+ }
111
+ if (outputSchema.type !== undefined && !hasType(outputSchema, 'object'))
112
+ structure('outputSchema.type', 'outputSchema must be of type object.');
113
+ const definitions = isRecord(outputSchema.$defs) ? outputSchema.$defs : undefined;
114
+ referenceFindings(outputSchema, 'outputSchema', new Set(definitions ? Object.keys(definitions) : []), out);
115
+ const { groups, issues } = readOutputSchema(outputSchema);
116
+ for (const issue of issues)
117
+ structure(issue.path, issue.message);
118
+ const groupIdByPathKey = new Map();
119
+ const pathKeys = new Set();
120
+ for (const group of groups) {
121
+ pathKeys.add(group.pathKey);
122
+ if (group.groupId)
123
+ groupIdByPathKey.set(group.pathKey, group.groupId);
124
+ }
125
+ const groupIdOwners = new Map();
126
+ const fieldIdOwners = new Map();
127
+ for (const group of groups) {
128
+ if (!group.multiInstance && !hasType(group.node, 'object')) {
129
+ structure(group.path, 'A field group must be an array of objects (a repeating group) or an object (a single-instance group).');
130
+ }
131
+ if (group.groupId)
132
+ groupIdOwners.set(group.groupId, [...(groupIdOwners.get(group.groupId) ?? []), group.path]);
133
+ if (group.segments.length > 1) {
134
+ const parentPathKey = group.segments.slice(0, -1).join(GROUP_PATH_SEPARATOR);
135
+ const parentId = groupIdByPathKey.get(parentPathKey);
136
+ if (!pathKeys.has(parentPathKey)) {
137
+ out.push({
138
+ code: 'EXTRACT_TAXONOMY_NESTING',
139
+ path: group.path,
140
+ message: `Nested field group "${group.pathKey}" has no parent group "${parentPathKey}" in outputSchema.properties.`,
141
+ });
142
+ }
143
+ else if (parentId !== undefined && group.parentGroupId !== undefined && group.parentGroupId !== parentId) {
144
+ out.push({
145
+ code: 'EXTRACT_TAXONOMY_NESTING',
146
+ path: `${group.path}.${PARENT_FIELD_GROUP_ID_EXTENSION}`,
147
+ message: `${PARENT_FIELD_GROUP_ID_EXTENSION} must be the id of "${parentPathKey}" (${parentId}).`,
148
+ });
149
+ }
150
+ }
151
+ else if (group.parentGroupId !== undefined) {
152
+ out.push({
153
+ code: 'EXTRACT_TAXONOMY_NESTING',
154
+ path: `${group.path}.${PARENT_FIELD_GROUP_ID_EXTENSION}`,
155
+ message: 'A top-level field group must not name a parent group. '
156
+ + `Nest it by renaming it "<parent>${GROUP_PATH_SEPARATOR}${group.pathKey}", or drop its ${PARENT_FIELD_GROUP_ID_EXTENSION} to leave it at the top level.`,
157
+ });
158
+ }
159
+ for (const field of group.fields) {
160
+ if (typeof field.node.$ref !== 'string') {
161
+ out.push({ code: 'EXTRACT_TAXONOMY_REF', path: field.path, message: 'A field must name its field type with "$ref": "#/$defs/<key>".' });
162
+ }
163
+ if (field.fieldId)
164
+ fieldIdOwners.set(field.fieldId, [...(fieldIdOwners.get(field.fieldId) ?? []), field.path]);
165
+ }
166
+ }
167
+ for (const [id, owners] of groupIdOwners) {
168
+ if (owners.length > 1)
169
+ out.push({ code: 'EXTRACT_TAXONOMY_DUPLICATE_ID', path: owners[0], message: `Field group id "${id}" is used by more than one group: ${owners.join(', ')}.` });
170
+ }
171
+ for (const [id, owners] of fieldIdOwners) {
172
+ if (owners.length > 1)
173
+ out.push({ code: 'EXTRACT_TAXONOMY_DUPLICATE_ID', path: owners[0], message: `Field id "${id}" is used by more than one field: ${owners.join(', ')}.` });
174
+ }
175
+ if (definitions) {
176
+ for (const [key, def] of Object.entries(definitions)) {
177
+ const path = `outputSchema.$defs${quoteKey(key)}`;
178
+ if (!DEFS_KEY_PATTERN.test(key)) {
179
+ out.push({
180
+ code: 'EXTRACT_TAXONOMY_FIELD_TYPE',
181
+ path,
182
+ message: `Field type key "${key}" must use only letters, digits, '.', '_' or '-', so the $ref that names it needs no escaping.`,
183
+ });
184
+ }
185
+ const title = isRecord(def) ? def.title : undefined;
186
+ if (typeof title !== 'string' || title.length === 0) {
187
+ out.push({ code: 'EXTRACT_TAXONOMY_FIELD_TYPE', path: `${path}.title`, message: `Field type "${key}" needs a non-empty title.` });
188
+ }
189
+ }
190
+ }
191
+ limitFindings(document, out);
192
+ return out;
193
+ }
194
+ /** The superseded private `{ taxonomy, fieldTypes }` document. */
195
+ export function isLegacyTaxonomy(value) {
196
+ if (!isRecord(value) || isReadableTaxonomy(value))
197
+ return false;
198
+ return 'taxonomy' in value || 'fieldTypes' in value;
199
+ }
200
+ /** A `{ prompt, outputSchema }` document — the shape `schema set` takes. */
201
+ export function isReadableTaxonomy(value) {
202
+ return isRecord(value) && typeof value.prompt === 'string' && isRecord(value.outputSchema);
203
+ }
204
+ /** A bare JSON Schema — `{ type: 'object', properties }` with no `prompt` around it (flow-schema `readExtractionOutputSchema`). */
205
+ export function isBareJsonSchema(value) {
206
+ return isRecord(value) && !isRecord(value.outputSchema) && (isRecord(value.properties) || value.type === 'object');
207
+ }
@@ -0,0 +1,92 @@
1
+ import { isRecord } from '../../../core/node-envelope.js';
2
+ /** Vendor extension carrying a field group's stable id. */
3
+ export declare const FIELD_GROUP_ID_EXTENSION = "x-uipath-field-group-id";
4
+ /** Vendor extension carrying a field's stable id. */
5
+ export declare const FIELD_ID_EXTENSION = "x-uipath-field-id";
6
+ /** Vendor extension naming the group a nested group hangs under. */
7
+ export declare const PARENT_FIELD_GROUP_ID_EXTENSION = "x-uipath-parent-field-group-id";
8
+ /** Vendor extension holding business checks, which reference fields by id. */
9
+ export declare const BUSINESS_CHECKS_EXTENSION = "x-uipath-business-checks";
10
+ /** Joins the segments of a nested field group's flattened property key: `Invoice > Line items`. */
11
+ export declare const GROUP_PATH_SEPARATOR = " > ";
12
+ type Json = Record<string, unknown>;
13
+ export { isRecord };
14
+ /** One problem with the taxonomy's shape, at a path into the schema document. */
15
+ export interface TaxonomyIssue {
16
+ /** Dot/bracket path into the document, e.g. `outputSchema.properties["Invoice"]`. */
17
+ path: string;
18
+ message: string;
19
+ }
20
+ export interface TaxonomyField {
21
+ name: string;
22
+ node: Json;
23
+ fieldId?: string;
24
+ path: string;
25
+ }
26
+ export interface TaxonomyGroup {
27
+ /** The property key, which for a nested group is its full path. */
28
+ pathKey: string;
29
+ segments: string[];
30
+ node: Json;
31
+ groupId?: string;
32
+ parentGroupId?: string;
33
+ /** True when the group repeats, carrying its fields under `items`. */
34
+ multiInstance: boolean;
35
+ fields: TaxonomyField[];
36
+ path: string;
37
+ }
38
+ export declare function hasType(node: Json, wanted: string): boolean;
39
+ export declare const quoteKey: (key: string) => string;
40
+ /**
41
+ * The field groups of an output schema with their fields, and the containers
42
+ * that could not be read as either. Every entry of the root `properties` is a
43
+ * group; a repeating group (`type: 'array'`) holds its fields under
44
+ * `items.properties`, a single one directly under `properties`. Nesting is by
45
+ * name: a nested group is another root entry keyed by its full path.
46
+ */
47
+ export declare function readOutputSchema(outputSchema: Json): {
48
+ groups: TaxonomyGroup[];
49
+ issues: TaxonomyIssue[];
50
+ };
51
+ /** Where a new id comes from: a group by its key, a field by its group's id and its name. */
52
+ export interface TaxonomyMint {
53
+ group(pathKey: string): string;
54
+ field(groupId: string, name: string): string;
55
+ }
56
+ /** The ids compile mints for one node: deterministic, so a recompile mints the same. */
57
+ export declare function derivedTaxonomyMint(flowId: string, nodeId: string): TaxonomyMint;
58
+ /** What {@link settleTaxonomyIds} did, counted as `nodes schema set` reports it. */
59
+ export interface TaxonomyIdCounts {
60
+ groupIdsPreserved: number;
61
+ groupIdsMinted: number;
62
+ fieldIdsPreserved: number;
63
+ fieldIdsMinted: number;
64
+ businessChecksDropped: number;
65
+ }
66
+ /**
67
+ * `document` with every field group and field given an id: its own when it has
68
+ * one, else the one the entry of the same place had in `existing`, else a new
69
+ * one from `mint`; and every nested group's parent reference set to its
70
+ * parent's id. Business checks that name an id no longer in the document are
71
+ * dropped. A document with no `outputSchema` object is returned as given.
72
+ * Never mutates its arguments.
73
+ *
74
+ * A nested group is matched only under its parent's OLD path, and only while
75
+ * the parent itself survived; a field only within the group of the same id.
76
+ */
77
+ export declare function settleTaxonomyIds(document: Json, existing: Json | undefined, mint: TaxonomyMint): {
78
+ document: Json;
79
+ counts: TaxonomyIdCounts;
80
+ };
81
+ /**
82
+ * Fill in the keywords the Schema Editor needs to open the document, wherever
83
+ * they follow from what is there (uipath-cli `close-object-schemas.ts`, which
84
+ * `nodes schema set` runs): every object is closed (`additionalProperties:
85
+ * false`) and lists every property in `required` (optionality is the
86
+ * `[type, "null"]` union, not omission), and the root is an object with a
87
+ * `$defs`. For instance `{ type: ['object', 'null'], properties: { Total: … } }`
88
+ * gains `additionalProperties: false, required: ['Total']`. Without them the
89
+ * editor shows "Could not load schema". MUTATES `outputSchema`; a malformed
90
+ * container is left as it is, for `check` to report.
91
+ */
92
+ export declare function closeObjectSchemas(outputSchema: unknown): void;
@@ -0,0 +1,301 @@
1
+ /**
2
+ * The Extract document node's taxonomy ids (builder-sdk#1985): every field
3
+ * group and field of `inputs.schemaDocument.outputSchema` carries a stable id
4
+ * (`x-uipath-field-group-id`, `x-uipath-field-id`) that annotations and
5
+ * evaluator settings are stored against.
6
+ *
7
+ * Invariant: an id the source carries is kept; a missing one is the id the
8
+ * overwritten `.flow` has for the entry of the same name (a group by its key,
9
+ * a field by its name within the group of the same id), else one minted from
10
+ * the flow, the node and that name, so a recompile mints the same one.
11
+ *
12
+ * Copied from uipath-cli `flow-tool/src/services/extract-schema/`
13
+ * (`merge-schema-ids.ts`, `close-object-schemas.ts`, and `readOutputSchema` from
14
+ * `validate-schema-document.ts`); only the source of new ids differs (the CLI
15
+ * mints random ones). Pure: the flow core is portable (FB015).
16
+ */
17
+ import { stableId } from '../../../core/stable-id.js';
18
+ import { isRecord } from '../../../core/node-envelope.js';
19
+ /** Vendor extension carrying a field group's stable id. */
20
+ export const FIELD_GROUP_ID_EXTENSION = 'x-uipath-field-group-id';
21
+ /** Vendor extension carrying a field's stable id. */
22
+ export const FIELD_ID_EXTENSION = 'x-uipath-field-id';
23
+ /** Vendor extension naming the group a nested group hangs under. */
24
+ export const PARENT_FIELD_GROUP_ID_EXTENSION = 'x-uipath-parent-field-group-id';
25
+ /** Vendor extension holding business checks, which reference fields by id. */
26
+ export const BUSINESS_CHECKS_EXTENSION = 'x-uipath-business-checks';
27
+ /** Joins the segments of a nested field group's flattened property key: `Invoice > Line items`. */
28
+ export const GROUP_PATH_SEPARATOR = ' > ';
29
+ export { isRecord };
30
+ export function hasType(node, wanted) {
31
+ const type = node.type;
32
+ if (typeof type === 'string')
33
+ return type === wanted;
34
+ if (Array.isArray(type))
35
+ return type.includes(wanted);
36
+ return false;
37
+ }
38
+ function readString(node, key) {
39
+ const value = node[key];
40
+ return typeof value === 'string' ? value : undefined;
41
+ }
42
+ export const quoteKey = (key) => `["${key}"]`;
43
+ /**
44
+ * The field groups of an output schema with their fields, and the containers
45
+ * that could not be read as either. Every entry of the root `properties` is a
46
+ * group; a repeating group (`type: 'array'`) holds its fields under
47
+ * `items.properties`, a single one directly under `properties`. Nesting is by
48
+ * name: a nested group is another root entry keyed by its full path.
49
+ */
50
+ export function readOutputSchema(outputSchema) {
51
+ const groups = [];
52
+ const issues = [];
53
+ const properties = outputSchema.properties;
54
+ if (!isRecord(properties)) {
55
+ issues.push({ path: 'outputSchema.properties', message: 'properties must be an object of field groups.' });
56
+ return { groups, issues };
57
+ }
58
+ for (const [pathKey, rawGroup] of Object.entries(properties)) {
59
+ const groupPath = `outputSchema.properties${quoteKey(pathKey)}`;
60
+ if (!isRecord(rawGroup)) {
61
+ issues.push({ path: groupPath, message: 'A field group must be an object.' });
62
+ continue;
63
+ }
64
+ const multiInstance = hasType(rawGroup, 'array');
65
+ const holder = multiInstance ? rawGroup.items : rawGroup;
66
+ const fieldsPath = multiInstance ? `${groupPath}.items.properties` : `${groupPath}.properties`;
67
+ if (multiInstance && !isRecord(holder)) {
68
+ issues.push({ path: `${groupPath}.items`, message: 'A repeating field group must declare its fields under an `items` object.' });
69
+ continue;
70
+ }
71
+ if (multiInstance && isRecord(holder) && holder.type !== undefined && !hasType(holder, 'object')) {
72
+ issues.push({ path: `${groupPath}.items.type`, message: "A repeating field group's `items` must be of type object." });
73
+ continue;
74
+ }
75
+ const fieldProperties = isRecord(holder) ? holder.properties : undefined;
76
+ if (fieldProperties !== undefined && !isRecord(fieldProperties)) {
77
+ issues.push({ path: fieldsPath, message: 'properties must be an object of fields.' });
78
+ continue;
79
+ }
80
+ const fields = [];
81
+ if (isRecord(fieldProperties)) {
82
+ for (const [name, rawField] of Object.entries(fieldProperties)) {
83
+ const fieldPath = `${fieldsPath}${quoteKey(name)}`;
84
+ if (!isRecord(rawField)) {
85
+ issues.push({ path: fieldPath, message: 'A field must be an object.' });
86
+ continue;
87
+ }
88
+ fields.push({ name, node: rawField, fieldId: readString(rawField, FIELD_ID_EXTENSION), path: fieldPath });
89
+ }
90
+ }
91
+ groups.push({
92
+ pathKey,
93
+ segments: pathKey.split(GROUP_PATH_SEPARATOR),
94
+ node: rawGroup,
95
+ groupId: readString(rawGroup, FIELD_GROUP_ID_EXTENSION),
96
+ parentGroupId: readString(rawGroup, PARENT_FIELD_GROUP_ID_EXTENSION),
97
+ multiInstance,
98
+ fields,
99
+ path: groupPath,
100
+ });
101
+ }
102
+ return { groups, issues };
103
+ }
104
+ /** Every object holding `x-uipath-business-checks`, wherever it sits. */
105
+ function businessCheckHolders(value, found = []) {
106
+ if (Array.isArray(value)) {
107
+ for (const entry of value)
108
+ businessCheckHolders(entry, found);
109
+ return found;
110
+ }
111
+ if (!isRecord(value))
112
+ return found;
113
+ if (Array.isArray(value[BUSINESS_CHECKS_EXTENSION]))
114
+ found.push(value);
115
+ for (const [key, child] of Object.entries(value)) {
116
+ if (key !== BUSINESS_CHECKS_EXTENSION)
117
+ businessCheckHolders(child, found);
118
+ }
119
+ return found;
120
+ }
121
+ /** The ids compile mints for one node: deterministic, so a recompile mints the same. */
122
+ export function derivedTaxonomyMint(flowId, nodeId) {
123
+ return {
124
+ group: (pathKey) => stableId(`${flowId}:${nodeId}:taxonomy-group:${pathKey}`),
125
+ field: (groupId, name) => stableId(`${flowId}:${nodeId}:taxonomy-field:${groupId}:${name}`),
126
+ };
127
+ }
128
+ /**
129
+ * `document` with every field group and field given an id: its own when it has
130
+ * one, else the one the entry of the same place had in `existing`, else a new
131
+ * one from `mint`; and every nested group's parent reference set to its
132
+ * parent's id. Business checks that name an id no longer in the document are
133
+ * dropped. A document with no `outputSchema` object is returned as given.
134
+ * Never mutates its arguments.
135
+ *
136
+ * A nested group is matched only under its parent's OLD path, and only while
137
+ * the parent itself survived; a field only within the group of the same id.
138
+ */
139
+ export function settleTaxonomyIds(document, existing, mint) {
140
+ const out = JSON.parse(JSON.stringify(document));
141
+ const counts = { groupIdsPreserved: 0, groupIdsMinted: 0, fieldIdsPreserved: 0, fieldIdsMinted: 0, businessChecksDropped: 0 };
142
+ if (!isRecord(out.outputSchema))
143
+ return { document: out, counts };
144
+ const groupIdByPath = new Map();
145
+ const pathByGroupId = new Map();
146
+ const fieldIdsByGroupId = new Map();
147
+ if (isRecord(existing?.outputSchema)) {
148
+ for (const group of readOutputSchema(existing.outputSchema).groups) {
149
+ if (group.groupId === undefined || group.groupId.length === 0)
150
+ continue;
151
+ const fieldIds = new Map();
152
+ for (const field of group.fields)
153
+ if (field.fieldId !== undefined && field.fieldId.length > 0)
154
+ fieldIds.set(field.name, field.fieldId);
155
+ groupIdByPath.set(group.pathKey, group.groupId);
156
+ pathByGroupId.set(group.groupId, group.pathKey);
157
+ fieldIdsByGroupId.set(group.groupId, fieldIds);
158
+ }
159
+ }
160
+ const groups = readOutputSchema(out.outputSchema).groups;
161
+ const claimedGroupIds = new Set();
162
+ const claimedFieldIds = new Set();
163
+ for (const group of groups) {
164
+ if (group.groupId !== undefined && group.groupId.length > 0)
165
+ claimedGroupIds.add(group.groupId);
166
+ for (const field of group.fields)
167
+ if (field.fieldId !== undefined && field.fieldId.length > 0)
168
+ claimedFieldIds.add(field.fieldId);
169
+ }
170
+ const finalGroupIdByPathKey = new Map();
171
+ const liveGroupIds = new Set();
172
+ const liveFieldIds = new Set();
173
+ const previousPathByPathKey = new Map();
174
+ const takenGroupIds = new Set(claimedGroupIds);
175
+ const fresh = (candidate, taken, again) => {
176
+ let id = candidate;
177
+ for (let n = 2; taken.has(id); n++)
178
+ id = again(n);
179
+ return id;
180
+ };
181
+ for (const group of [...groups].sort((a, b) => a.segments.length - b.segments.length)) {
182
+ const parentPath = group.segments.slice(0, -1).join(GROUP_PATH_SEPARATOR);
183
+ const leaf = group.segments[group.segments.length - 1];
184
+ const previousParentPath = previousPathByPathKey.get(parentPath);
185
+ const candidatePath = group.segments.length > 1
186
+ ? previousParentPath === undefined ? undefined : `${previousParentPath}${GROUP_PATH_SEPARATOR}${leaf}`
187
+ : group.pathKey;
188
+ let groupId = group.groupId;
189
+ if (groupId !== undefined && groupId.length > 0) {
190
+ counts.groupIdsPreserved++;
191
+ }
192
+ else {
193
+ const adopted = candidatePath === undefined ? undefined : groupIdByPath.get(candidatePath);
194
+ if (adopted !== undefined && !takenGroupIds.has(adopted)) {
195
+ groupId = adopted;
196
+ counts.groupIdsPreserved++;
197
+ }
198
+ else {
199
+ groupId = fresh(mint.group(group.pathKey), takenGroupIds, (n) => mint.group(`${group.pathKey}#${n}`));
200
+ counts.groupIdsMinted++;
201
+ }
202
+ group.node[FIELD_GROUP_ID_EXTENSION] = groupId;
203
+ }
204
+ finalGroupIdByPathKey.set(group.pathKey, groupId);
205
+ takenGroupIds.add(groupId);
206
+ liveGroupIds.add(groupId);
207
+ const previousPath = pathByGroupId.get(groupId);
208
+ if (previousPath !== undefined)
209
+ previousPathByPathKey.set(group.pathKey, previousPath);
210
+ }
211
+ const takenFieldIds = new Set(claimedFieldIds);
212
+ for (const group of groups) {
213
+ const groupId = finalGroupIdByPathKey.get(group.pathKey) ?? '';
214
+ const previousFieldIds = fieldIdsByGroupId.get(groupId);
215
+ for (const field of group.fields) {
216
+ if (field.fieldId !== undefined && field.fieldId.length > 0) {
217
+ counts.fieldIdsPreserved++;
218
+ liveFieldIds.add(field.fieldId);
219
+ continue;
220
+ }
221
+ const adopted = previousFieldIds?.get(field.name);
222
+ let fieldId;
223
+ if (adopted !== undefined && !takenFieldIds.has(adopted)) {
224
+ fieldId = adopted;
225
+ counts.fieldIdsPreserved++;
226
+ }
227
+ else {
228
+ fieldId = fresh(mint.field(groupId, field.name), takenFieldIds, (n) => mint.field(groupId, `${field.name}#${n}`));
229
+ counts.fieldIdsMinted++;
230
+ }
231
+ field.node[FIELD_ID_EXTENSION] = fieldId;
232
+ takenFieldIds.add(fieldId);
233
+ liveFieldIds.add(fieldId);
234
+ }
235
+ }
236
+ for (const group of groups) {
237
+ if (group.segments.length < 2)
238
+ continue;
239
+ const parentId = finalGroupIdByPathKey.get(group.segments.slice(0, -1).join(GROUP_PATH_SEPARATOR));
240
+ if (parentId !== undefined)
241
+ group.node[PARENT_FIELD_GROUP_ID_EXTENSION] = parentId;
242
+ }
243
+ for (const holder of businessCheckHolders(out)) {
244
+ const checks = holder[BUSINESS_CHECKS_EXTENSION];
245
+ const kept = checks.filter((check) => {
246
+ if (!isRecord(check))
247
+ return true;
248
+ if (typeof check.fieldId === 'string' && !liveFieldIds.has(check.fieldId))
249
+ return false;
250
+ if (typeof check.fieldGroupId === 'string' && !liveGroupIds.has(check.fieldGroupId))
251
+ return false;
252
+ return true;
253
+ });
254
+ counts.businessChecksDropped += checks.length - kept.length;
255
+ holder[BUSINESS_CHECKS_EXTENSION] = kept;
256
+ }
257
+ return { document: out, counts };
258
+ }
259
+ const declaresObject = (node) => hasType(node, 'object');
260
+ function closeNode(node) {
261
+ if (!isRecord(node))
262
+ return;
263
+ if (node.properties === undefined && declaresObject(node))
264
+ node.properties = {};
265
+ const properties = node.properties;
266
+ if (isRecord(properties)) {
267
+ if (node.type === undefined)
268
+ node.type = 'object';
269
+ node.additionalProperties = false;
270
+ node.required = Object.keys(properties);
271
+ for (const child of Object.values(properties))
272
+ closeNode(child);
273
+ }
274
+ if (isRecord(node.$defs))
275
+ for (const child of Object.values(node.$defs))
276
+ closeNode(child);
277
+ closeNode(node.items);
278
+ if (Array.isArray(node.anyOf))
279
+ for (const child of node.anyOf)
280
+ closeNode(child);
281
+ }
282
+ /**
283
+ * Fill in the keywords the Schema Editor needs to open the document, wherever
284
+ * they follow from what is there (uipath-cli `close-object-schemas.ts`, which
285
+ * `nodes schema set` runs): every object is closed (`additionalProperties:
286
+ * false`) and lists every property in `required` (optionality is the
287
+ * `[type, "null"]` union, not omission), and the root is an object with a
288
+ * `$defs`. For instance `{ type: ['object', 'null'], properties: { Total: … } }`
289
+ * gains `additionalProperties: false, required: ['Total']`. Without them the
290
+ * editor shows "Could not load schema". MUTATES `outputSchema`; a malformed
291
+ * container is left as it is, for `check` to report.
292
+ */
293
+ export function closeObjectSchemas(outputSchema) {
294
+ if (!isRecord(outputSchema))
295
+ return;
296
+ if (outputSchema.type === undefined)
297
+ outputSchema.type = 'object';
298
+ if (outputSchema.$defs === undefined)
299
+ outputSchema.$defs = {};
300
+ closeNode(outputSchema);
301
+ }
@@ -63,6 +63,23 @@ export interface CollectedRefusal {
63
63
  }
64
64
  export interface SerializeOpts {
65
65
  library?: Library;
66
+ /**
67
+ * The `.flow` this compile overwrites, parsed (`compile-cli` reads the output
68
+ * file before writing it). A type can read the node it had there through
69
+ * {@link FlowSerializeContext.overwrittenNode}: Extract document keeps the
70
+ * taxonomy ids that file has for entries the source names none for (#1985).
71
+ */
72
+ overwrites?: unknown;
73
+ /**
74
+ * Informational lines a type reports about what it wrote (`compile: <message>`),
75
+ * with the data behind them for `--json`. For instance Extract document's
76
+ * kept-vs-minted taxonomy id counts.
77
+ */
78
+ note?: (note: {
79
+ step: string;
80
+ message: string;
81
+ data?: unknown;
82
+ }) => void;
66
83
  /** The project's bindings.json (`Bindings`), or any view that answers the label rules. */
67
84
  bindings?: BindingsView;
68
85
  /**
package/dist/serialize.js CHANGED
@@ -196,6 +196,21 @@ export { CONNECTOR_INPUT_MISSING } from './core/connector-inputs.js';
196
196
  */
197
197
  const DRAFT_CODES_AGREE = true;
198
198
  void DRAFT_CODES_AGREE;
199
+ /** The node of `flow` emitted under `id`, when it is of type `typeName` (top level or a subflow). */
200
+ function overwrittenNodeOf(flow, id, typeName) {
201
+ if (flow === null || typeof flow !== 'object')
202
+ return undefined;
203
+ const f = flow;
204
+ const lists = [f.nodes, ...(f.subflows !== null && typeof f.subflows === 'object' ? Object.values(f.subflows).map((s) => s?.nodes) : [])];
205
+ for (const list of lists) {
206
+ if (!Array.isArray(list))
207
+ continue;
208
+ const node = list.find((n) => n !== null && typeof n === 'object' && n.id === id);
209
+ if (node !== undefined)
210
+ return node.type === typeName ? node : undefined;
211
+ }
212
+ return undefined;
213
+ }
199
214
  /**
200
215
  * `serialize`, plus the extra files the flow needs on disk beside it.
201
216
  *
@@ -2351,6 +2366,8 @@ function serializeFlow(built, opts) {
2351
2366
  ? resolved.carried
2352
2367
  : bundledDefinition(typeName, v) ?? carriedFor(typeName, v)),
2353
2368
  bindings: resourceBindings,
2369
+ overwrittenNode: () => overwrittenNodeOf(opts.overwrites, id, impl.typeName),
2370
+ note: (message, data) => opts.note?.({ step: step.name, message, ...(data !== undefined ? { data } : {}) }),
2354
2371
  resolveBinding: ((name, attribute, at, target) => resolveBinding(bindingOpts, name, attribute, at, target)),
2355
2372
  resolveBindingPair: (labels, at, target) => resolveBindingPair(bindingOpts, labels, at, target),
2356
2373
  bindConnection: (c) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.118.1",
3
+ "version": "6.119.0",
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",
@@ -124,5 +124,5 @@
124
124
  "@types/node": "^22.7.0",
125
125
  "esbuild": "^0.28.1"
126
126
  },
127
- "gitref": "0c0b4c5db91985dd7604ca295f9b32825d7a28bd"
127
+ "gitref": "737af3acc6d29c4b99c6e96e7c40d23dd3427b4b"
128
128
  }