@uipath/maestro-builder-sdk 6.117.4 → 6.118.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,87 @@
1
+ import { nearestName } from '../../../core/edit-distance.js';
2
+ import { ownEntry } from '../../../core/own-entry.js';
3
+ /**
4
+ * The processed document's keys, level by level. An object schema with
5
+ * `properties` is a closed level; one without (`result.output`, `taxonomy`, and
6
+ * `result.attribution`, keyed by JSON Pointer such as `'/Net pay'`) is open.
7
+ * One level is open although its schema lists properties: `metadata.modelConfig`
8
+ * "grows with the processor: read the keys you know and tolerate the rest" (its
9
+ * own description). `tests/document-processing.test.ts` derives this table from
10
+ * the bundled `outputDefinition` by the same rule and holds the two equal, so
11
+ * they cannot drift apart.
12
+ */
13
+ export const EXTRACT_OUTPUT_SHAPE = {
14
+ version: 'leaf',
15
+ type: 'leaf',
16
+ result: {
17
+ output: 'open',
18
+ attribution: 'open',
19
+ traceContext: { traceId: 'leaf', spanId: 'leaf', folderKey: 'leaf' },
20
+ },
21
+ taxonomy: 'open',
22
+ metadata: { pipelineRunId: 'leaf', folderKey: 'leaf', traceId: 'leaf', spanId: 'leaf', modelConfig: 'open' },
23
+ };
24
+ /** The published-project extractor's (`ixpExtract()`) top-level keys, a common wrong read here. */
25
+ const IXP_PROJECT_KEYS = new Set(['ExtractionResult', 'Taxonomy']);
26
+ /**
27
+ * Whether `outputs` (a node's `outputs`, or its definition's `outputDefinition`)
28
+ * is the declaration the SDK bundled for this node before #1987: the
29
+ * published-project extractor's `ExtractionResult` and `Taxonomy`. A file an
30
+ * older SDK compiled carries it in three places: the node's `outputs`, its
31
+ * `variables.nodes` entry and its `definitions[]` entry. The processed document
32
+ * has no `ExtractionResult` key, so the test cannot match a current declaration.
33
+ * Merge replaces it (`supersededOutputs`, merge-superseded-outputs.ts).
34
+ */
35
+ export function isLegacyExtractOutputs(outputs) {
36
+ const properties = outputs?.output?.schema?.properties;
37
+ return typeof properties === 'object' && properties !== null && Object.hasOwn(properties, 'ExtractionResult');
38
+ }
39
+ const list = (keys) => keys.map((k) => `"${k}"`).join(', ');
40
+ /**
41
+ * A read of a `dynamicExtract()` step's output: `out('<step>', '<path>')`.
42
+ *
43
+ * Only `output` (and the `error` envelope, which `check` handles before this
44
+ * rule) exists on the step. Under `output`, each segment of the path must name
45
+ * a key of {@link EXTRACT_OUTPUT_SHAPE} until it reaches an open level or a
46
+ * scalar; past that nothing is checked. A miss is undefined at run time.
47
+ */
48
+ export function checkExtractRead({ node: name, field, rest, reader: step }, report) {
49
+ if (field === undefined || field === 'error')
50
+ return;
51
+ if (field !== 'output') {
52
+ report('EXTRACT_READ_NOT_OUTPUT', `Extract document step "${name}" publishes its result under "output", but `
53
+ + `"$vars.${name}.${field}" (read in "${step}") asks for "${field}", which is undefined at run time.`, `out('${name}', 'result.output')`);
54
+ return;
55
+ }
56
+ const segments = rest.replace(/^\./, '').split('.').filter((s) => s !== '');
57
+ let level = EXTRACT_OUTPUT_SHAPE;
58
+ for (const [i, segment] of segments.entries()) {
59
+ if (level === 'leaf' || level === 'open')
60
+ return;
61
+ const next = ownEntry(level, segment);
62
+ if (next !== undefined) {
63
+ level = next;
64
+ continue;
65
+ }
66
+ const at = ['output', ...segments.slice(0, i)].join('.');
67
+ const read = `$vars.${name}.${at}.${segment}`;
68
+ const keys = Object.keys(level);
69
+ if (i === 0 && IXP_PROJECT_KEYS.has(segment)) {
70
+ report('EXTRACT_READ_UNKNOWN_FIELD', `"${read}" (read in "${step}") is the published-project extractor's `
71
+ + `(ixpExtract()) output shape, not Extract document's. Step "${name}" publishes a processed document `
72
+ + `(${list(keys)}); the extracted values are at "result.output", one property per taxonomy field. `
73
+ + 'This read is undefined at run time.', `out('${name}', 'result.output')`);
74
+ return;
75
+ }
76
+ const nearest = nearestName(segment, keys);
77
+ // At the top, a name that is no envelope key is most likely a taxonomy field read one level too high.
78
+ const suggestion = nearest !== undefined
79
+ ? `out('${name}', '${[...segments.slice(0, i), nearest].join('.')}')`
80
+ : i === 0 ? `out('${name}', 'result.output.${segment}')` : undefined;
81
+ report('EXTRACT_READ_UNKNOWN_FIELD', `"${read}" (read in "${step}") is not a field of Extract document step `
82
+ + `"${name}"'s output. "${at}" has ${list(keys)}`
83
+ + (i === 0 ? '; the extracted values are at "result.output", one property per taxonomy field' : '')
84
+ + '. This read is undefined at run time.', suggestion);
85
+ return;
86
+ }
87
+ }
@@ -21,7 +21,67 @@ export declare function documentClassify(inputs: DocumentClassifyInputs): Action
21
21
  * Extract fields from a document with an INLINE schema — Dynamic Extract
22
22
  * (`uipath.ixp.extract-document-builder`), the newer of the two extraction
23
23
  * shapes. No deployed IXP project is referenced: the extraction schema rides
24
- * the node. The result publishes `ExtractionResult` (and `Taxonomy`).
24
+ * the node.
25
+ *
26
+ * @remarks
27
+ * `schema` is the extraction taxonomy: `prompt` (the instructions) and
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`).
32
+ *
33
+ * The output is a processed document: `version`, `type` (`'Extraction'`),
34
+ * `result`, `taxonomy` and `metadata` (run ids and the model configuration).
35
+ * `result.output` holds the extracted values, shaped like `outputSchema`: one
36
+ * property per field group, each holding its fields. `result.attribution`
37
+ * gives each value's page provenance and `result.traceContext` the run's ids.
38
+ * Read a value at `out('<step>', 'result.output.<group>.<field>')`.
39
+ *
40
+ * `check` verifies the processed document's fixed keys: a read of a key it
41
+ * does not have is `EXTRACT_READ_UNKNOWN_FIELD`. That includes
42
+ * `ExtractionResult`, the published-project extractor's shape
43
+ * ({@link ixpExtract}), not this node's. It does not check the group and field
44
+ * names under `result.output` against the taxonomy, so a misspelt field name
45
+ * there still passes.
46
+ *
47
+ * @example
48
+ * **Extract an invoice total and return it**
49
+ * ```ts
50
+ * flow('InvoiceTotal')
51
+ * .input({ invoiceFile: types.file })
52
+ * .output({ total: types.string })
53
+ * .step('extract', dynamicExtract({
54
+ * fileRef: input('invoiceFile'),
55
+ * schema: {
56
+ * prompt: 'Extract the invoice header. Values are on the page; do not compute them.',
57
+ * outputSchema: {
58
+ * type: 'object',
59
+ * additionalProperties: false,
60
+ * required: ['Invoice'],
61
+ * properties: {
62
+ * Invoice: {
63
+ * type: ['object', 'null'],
64
+ * 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
+ * properties: {
69
+ * Total: {
70
+ * $ref: '#/$defs/ft-monetary-quantity',
71
+ * description: 'The amount payable including tax.',
72
+ * 'x-uipath-field-id': '7c2e4a91-0d3b-4f6e-a8c5-1b9d3f7e2a64',
73
+ * },
74
+ * },
75
+ * },
76
+ * },
77
+ * $defs: {
78
+ * 'ft-monetary-quantity': { title: 'Monetary Quantity', type: ['string', 'null'], format: 'monetary' },
79
+ * },
80
+ * },
81
+ * },
82
+ * }))
83
+ * .return({ total: out('extract', 'result.output.Invoice.Total') })
84
+ * ```
25
85
  *
26
86
  * @param inputs - The file reference, the inline extraction schema, and
27
87
  * optional page range / model settings.
@@ -22,7 +22,67 @@ export function documentClassify(inputs) {
22
22
  * Extract fields from a document with an INLINE schema — Dynamic Extract
23
23
  * (`uipath.ixp.extract-document-builder`), the newer of the two extraction
24
24
  * shapes. No deployed IXP project is referenced: the extraction schema rides
25
- * the node. The result publishes `ExtractionResult` (and `Taxonomy`).
25
+ * the node.
26
+ *
27
+ * @remarks
28
+ * `schema` is the extraction taxonomy: `prompt` (the instructions) and
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`).
33
+ *
34
+ * The output is a processed document: `version`, `type` (`'Extraction'`),
35
+ * `result`, `taxonomy` and `metadata` (run ids and the model configuration).
36
+ * `result.output` holds the extracted values, shaped like `outputSchema`: one
37
+ * property per field group, each holding its fields. `result.attribution`
38
+ * gives each value's page provenance and `result.traceContext` the run's ids.
39
+ * Read a value at `out('<step>', 'result.output.<group>.<field>')`.
40
+ *
41
+ * `check` verifies the processed document's fixed keys: a read of a key it
42
+ * does not have is `EXTRACT_READ_UNKNOWN_FIELD`. That includes
43
+ * `ExtractionResult`, the published-project extractor's shape
44
+ * ({@link ixpExtract}), not this node's. It does not check the group and field
45
+ * names under `result.output` against the taxonomy, so a misspelt field name
46
+ * there still passes.
47
+ *
48
+ * @example
49
+ * **Extract an invoice total and return it**
50
+ * ```ts
51
+ * flow('InvoiceTotal')
52
+ * .input({ invoiceFile: types.file })
53
+ * .output({ total: types.string })
54
+ * .step('extract', dynamicExtract({
55
+ * fileRef: input('invoiceFile'),
56
+ * schema: {
57
+ * prompt: 'Extract the invoice header. Values are on the page; do not compute them.',
58
+ * outputSchema: {
59
+ * type: 'object',
60
+ * additionalProperties: false,
61
+ * required: ['Invoice'],
62
+ * properties: {
63
+ * Invoice: {
64
+ * type: ['object', 'null'],
65
+ * 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
+ * properties: {
70
+ * Total: {
71
+ * $ref: '#/$defs/ft-monetary-quantity',
72
+ * description: 'The amount payable including tax.',
73
+ * 'x-uipath-field-id': '7c2e4a91-0d3b-4f6e-a8c5-1b9d3f7e2a64',
74
+ * },
75
+ * },
76
+ * },
77
+ * },
78
+ * $defs: {
79
+ * 'ft-monetary-quantity': { title: 'Monetary Quantity', type: ['string', 'null'], format: 'monetary' },
80
+ * },
81
+ * },
82
+ * },
83
+ * }))
84
+ * .return({ total: out('extract', 'result.output.Invoice.Total') })
85
+ * ```
26
86
  *
27
87
  * @param inputs - The file reference, the inline extraction schema, and
28
88
  * optional page range / model settings.
@@ -1,3 +1,8 @@
1
1
  /** The document node family, as flow-node-registry.ts lists it: Document Classify, Dynamic Extract and an IxP project's extractor. */
2
2
  import type { FlowNodeFamily } from '../../../flow-node-type.js';
3
3
  export declare const documentFlowFamily: FlowNodeFamily;
4
+ /**
5
+ * The IDP processor rules, for `compile` (`idp-processor-files.ts`) and
6
+ * `bindings_v2.json`: pure, and not part of the public surface.
7
+ */
8
+ export { buildIdpProcessorSpec, collectWorkflowNodes, DEFAULT_IDP_PROCESSOR_NAME, deriveIdpProcessorName, idpProcessorBindingRows, idpProcessorResourcePath, isIdpProcessorResource, isPublishedIdpProcessorLink, readAuthoringProcessorKey, readIdpProcessorName, readNodeLabel, updateIdpProcessorResource, withIdpProcessorRows, wrapIdpProcessorSpec, type IdpProcessorBindingRow, type WorkflowNodeLike, } from './idp-processor.js';
@@ -6,3 +6,8 @@ export const documentFlowFamily = {
6
6
  types: [documentClassifyNodeType, dynamicExtractNodeType, ixpExtractNodeType],
7
7
  diagnostics: { ...DOCUMENT_DIAGNOSTICS, ...IXP_DIAGNOSTICS },
8
8
  };
9
+ /**
10
+ * The IDP processor rules, for `compile` (`idp-processor-files.ts`) and
11
+ * `bindings_v2.json`: pure, and not part of the public surface.
12
+ */
13
+ export { buildIdpProcessorSpec, collectWorkflowNodes, DEFAULT_IDP_PROCESSOR_NAME, deriveIdpProcessorName, idpProcessorBindingRows, idpProcessorResourcePath, isIdpProcessorResource, isPublishedIdpProcessorLink, readAuthoringProcessorKey, readIdpProcessorName, readNodeLabel, updateIdpProcessorResource, withIdpProcessorRows, wrapIdpProcessorSpec, } from './idp-processor.js';
@@ -0,0 +1,122 @@
1
+ /** The node type this module serves, as the family registers it. */
2
+ export declare const DYNAMIC_EXTRACT_TYPE = "uipath.ixp.extract-document-builder";
3
+ /** Node inputs that name the processor (flow-schema `idp-processor-spec.ts`). */
4
+ export declare const PROCESSOR_KEY_INPUT = "processorKey";
5
+ export declare const PROCESSOR_NAME_INPUT = "processorName";
6
+ export declare const PROCESSOR_READONLY_INPUT = "processorReadOnly";
7
+ export declare const PROCESSOR_FOLDER_PATH_INPUT = "processorFolderPath";
8
+ /** The processor name a node with no label gets (the CLI's `DEFAULT_IDP_PROCESSOR_NAME`). */
9
+ export declare const DEFAULT_IDP_PROCESSOR_NAME = "IdpProcessor";
10
+ type Json = Record<string, unknown>;
11
+ /** A node of the file, as far as these rules read one. */
12
+ export interface WorkflowNodeLike {
13
+ id?: unknown;
14
+ type?: unknown;
15
+ inputs?: unknown;
16
+ display?: unknown;
17
+ [k: string]: unknown;
18
+ }
19
+ /** Every node of a `.flow`, subflow bodies included (flow-schema `collectWorkflowNodes`). */
20
+ export declare function collectWorkflowNodes(workflow: {
21
+ nodes?: unknown;
22
+ subflows?: unknown;
23
+ } | undefined | null): WorkflowNodeLike[];
24
+ export declare function isDynamicExtractNode(node: WorkflowNodeLike | undefined | null): boolean;
25
+ export declare function readIdpProcessorKey(inputs: unknown): string | undefined;
26
+ export declare function readIdpProcessorName(inputs: unknown): string | undefined;
27
+ export declare function readIdpProcessorFolderPath(inputs: unknown): string | undefined;
28
+ export declare function isIdpProcessorReadOnly(inputs: unknown): boolean;
29
+ /** The processor this node writes to: none for a read-only mirror (flow-schema `readAuthoringProcessorKey`). */
30
+ export declare function readAuthoringProcessorKey(node: WorkflowNodeLike): string | undefined;
31
+ /** A processor published to the tenant: the key comes with the folder it lives in, and no solution resource exists. */
32
+ export declare function isPublishedIdpProcessorLink(inputs: unknown): boolean;
33
+ /** The node's `display.label` (else a top-level `label`), the name a new processor takes. */
34
+ export declare function readNodeLabel(node: WorkflowNodeLike): string | undefined;
35
+ /** The spec of an `idpProcessor` resource (flow-schema `IdpProcessorSpec`). */
36
+ export interface IdpProcessorSpec {
37
+ name?: string;
38
+ description?: string;
39
+ prompt: string;
40
+ outputSchema: string;
41
+ extractionStrategy: string;
42
+ modelOverride?: string;
43
+ attributionStrategy?: string;
44
+ attributionModelOverride: string;
45
+ languageSupport?: string;
46
+ layoutEngine: string;
47
+ layoutModel: string;
48
+ overrides?: string;
49
+ }
50
+ /**
51
+ * The spec a node's processor holds (flow-schema `buildIdpProcessorSpec` over
52
+ * `collectIdpProcessorUpdates`' inputs): the taxonomy JSON-encoded, and the
53
+ * model settings in the backend's vocabulary. For instance the seeded node
54
+ * gives `{ description: '', prompt: '', outputSchema: '{"type":"object",…}',
55
+ * extractionStrategy: 'SingleExtract', modelOverride: 'gemini-2.5-flash', … }`.
56
+ */
57
+ export declare function buildIdpProcessorSpec(node: WorkflowNodeLike): IdpProcessorSpec;
58
+ /**
59
+ * A processor's name from the node's label, suffixed `_1`, `_2`, … when the
60
+ * solution already has it (case-insensitive); undefined for a blank label.
61
+ * For instance `deriveIdpProcessorName('Extract', ['extract'])` is `'Extract_1'`.
62
+ */
63
+ export declare function deriveIdpProcessorName(label: string | undefined, takenNames: Iterable<string>): string | undefined;
64
+ /** Solution-relative path a NEW processor's file is created at, e.g. `resources/solution_folder/idpProcessor/extraction/Extract_invoice.json`. */
65
+ export declare function idpProcessorResourcePath(name: string): string;
66
+ /** Whether a parsed resource file is an IDP processor's (its `kind`, case-insensitively). */
67
+ export declare function isIdpProcessorResource(file: unknown): boolean;
68
+ /** A brand-new resource file for a processor. */
69
+ export declare function wrapIdpProcessorSpec(input: {
70
+ key: string;
71
+ name: string;
72
+ spec: IdpProcessorSpec;
73
+ }): Json;
74
+ /**
75
+ * An existing resource file with a fresh spec merged in key by key: its key,
76
+ * name and any spec key the node does not manage stay; a managed optional key
77
+ * the fresh spec omits is cleared.
78
+ */
79
+ export declare function updateIdpProcessorResource(file: Json, spec: IdpProcessorSpec): Json;
80
+ /** One `bindings_v2.json` row, as `bindings-v2.ts` merges them. */
81
+ export interface IdpProcessorBindingRow {
82
+ resource: string;
83
+ key: string;
84
+ id: string;
85
+ value: Record<string, {
86
+ defaultValue?: string;
87
+ isExpression: boolean;
88
+ displayName: string;
89
+ }>;
90
+ metadata: Record<string, string>;
91
+ }
92
+ /**
93
+ * The `idpProcessor` row of each distinct processor the flow's Extract document
94
+ * nodes name, as pack derives it: `processorKey` with the key, `name` with the
95
+ * resource's name (`namesByKey`, else the node's `processorName`, else its
96
+ * label), `folderPath` with a published processor's folder. An attribute with no
97
+ * value carries no `defaultValue`, as pack writes it.
98
+ */
99
+ export declare function idpProcessorBindingRows(workflow: {
100
+ nodes?: unknown;
101
+ subflows?: unknown;
102
+ }, namesByKey?: ReadonlyMap<string, string>): IdpProcessorBindingRow[];
103
+ /**
104
+ * `bindings_v2.json` rows with the processor rows replaced by `rows`: a row
105
+ * for a key no node names any more goes, as pack drops it, unless some flow
106
+ * could not be read (`keepUnderived`), when the old rows stay. Every other
107
+ * row is kept as it is.
108
+ */
109
+ export declare function withIdpProcessorRows<R extends {
110
+ resource?: unknown;
111
+ key?: unknown;
112
+ }>(resources: R[], rows: readonly IdpProcessorBindingRow[], options?: {
113
+ keepUnderived?: boolean;
114
+ }): R[];
115
+ /** The `config` block the Schema Editor insists on, from the node's model settings (the CLI's `buildScaffoldConfig`). */
116
+ export declare function buildScaffoldConfig(modelConfig: unknown): Json;
117
+ /**
118
+ * The schema document `nodes create` seeds a node with: no field groups, and
119
+ * the default field types to reference. Fresh per call.
120
+ */
121
+ export declare function buildDefaultSchemaDocument(modelConfig?: unknown): Json;
122
+ export {};