@uipath/maestro-builder-sdk 6.118.0 → 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 +2 -2
- package/dist/check.d.ts +0 -10
- package/dist/check.js +70 -8
- package/dist/compile-cli.js +12 -1
- package/dist/core/refusals.d.ts +10 -0
- package/dist/core/refusals.js +10 -0
- package/dist/core-definitions.json +178 -1637
- package/dist/flow-node-type.d.ts +21 -0
- package/dist/merge-cli.js +4 -0
- package/dist/merge-roundtrip.d.ts +8 -3
- package/dist/merge-roundtrip.js +7 -1
- package/dist/merge-superseded-outputs.d.ts +12 -0
- package/dist/merge-superseded-outputs.js +111 -0
- package/dist/merge.d.ts +10 -0
- package/dist/merge.js +13 -1
- package/dist/nodes/document/flow/extract-output.d.ts +61 -0
- package/dist/nodes/document/flow/extract-output.js +87 -0
- package/dist/nodes/document/flow/factories.d.ts +60 -1
- package/dist/nodes/document/flow/factories.js +60 -1
- package/dist/nodes/document/flow/node-type.js +91 -6
- package/dist/nodes/document/flow/taxonomy-check.d.ts +36 -0
- package/dist/nodes/document/flow/taxonomy-check.js +207 -0
- package/dist/nodes/document/flow/taxonomy.d.ts +92 -0
- package/dist/nodes/document/flow/taxonomy.js +301 -0
- package/dist/serialize.d.ts +17 -0
- package/dist/serialize.js +17 -0
- package/package.json +2 -2
|
@@ -12,9 +12,23 @@ import { jsonClone } from '../../../core/json-clone.js';
|
|
|
12
12
|
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
|
+
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';
|
|
15
18
|
export const DOCUMENT_DIAGNOSTICS = {
|
|
16
19
|
DOC_NO_FILEREF: { severity: 'error', summary: 'no fileRef, so nothing to classify or extract from' },
|
|
17
|
-
EXTRACT_SCHEMA_SHAPE: { severity: 'error', summary: 'a Dynamic Extract schema that is not
|
|
20
|
+
EXTRACT_SCHEMA_SHAPE: { severity: 'error', summary: 'a Dynamic Extract schema that is not a { prompt, outputSchema } document' },
|
|
21
|
+
EXTRACT_READ_NOT_OUTPUT: { severity: 'error', summary: 'an Extract document step read outside output' },
|
|
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' },
|
|
18
32
|
};
|
|
19
33
|
function checkFileRef(inputs, verb, ctx) {
|
|
20
34
|
const fr = inputs.fileRef;
|
|
@@ -125,6 +139,31 @@ function withConfig(schema, modelConfig) {
|
|
|
125
139
|
return schema;
|
|
126
140
|
return { config: buildScaffoldConfig(modelConfig), ...schema };
|
|
127
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
|
+
}
|
|
128
167
|
/** The lifted schema without a `config` that is only the scaffold {@link withConfig} adds back. */
|
|
129
168
|
function withoutScaffoldConfig(schema, modelConfig) {
|
|
130
169
|
if (!isObject(schema) || JSON.stringify(schema.config) !== JSON.stringify(buildScaffoldConfig(modelConfig)))
|
|
@@ -132,6 +171,39 @@ function withoutScaffoldConfig(schema, modelConfig) {
|
|
|
132
171
|
const { config: _scaffold, ...rest } = schema;
|
|
133
172
|
return rest;
|
|
134
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
|
+
}
|
|
135
207
|
/** A non-empty string input of the node, as the lift keeps it. */
|
|
136
208
|
function liftText(inputs, key, ctx) {
|
|
137
209
|
const v = ctx.plainValue(inputs[key]);
|
|
@@ -232,6 +304,13 @@ export const dynamicExtractNodeType = {
|
|
|
232
304
|
const processorKey = inputs.processorKey !== undefined && inputs.processorKey !== ''
|
|
233
305
|
? inputs.processorKey
|
|
234
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);
|
|
235
314
|
return {
|
|
236
315
|
inputs: {
|
|
237
316
|
...d,
|
|
@@ -255,8 +334,11 @@ export const dynamicExtractNodeType = {
|
|
|
255
334
|
...(modelConfig !== undefined ? { modelConfig } : {}),
|
|
256
335
|
// No schema: the empty taxonomy `nodes create` seeds, so the node opens in
|
|
257
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.
|
|
258
340
|
schemaDocument: inputs.schema !== undefined
|
|
259
|
-
?
|
|
341
|
+
? taxonomy.document
|
|
260
342
|
: buildDefaultSchemaDocument(modelConfig ?? d.modelConfig),
|
|
261
343
|
// The definition's model declares `source: true`: the platform mints a
|
|
262
344
|
// stable storage slot per instance; omit it and the node validates then
|
|
@@ -283,6 +365,8 @@ export const dynamicExtractNodeType = {
|
|
|
283
365
|
// not printed; anything else is the author's.
|
|
284
366
|
const rawSchema = ctx.plainValue(inputs.schemaDocument);
|
|
285
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.
|
|
286
370
|
const schema = rawSchema !== undefined && JSON.stringify(rawSchema) !== JSON.stringify(seeded)
|
|
287
371
|
? withoutScaffoldConfig(rawSchema, inputs.modelConfig) : undefined;
|
|
288
372
|
// The processor a node already names is printed, so a recompile keeps it;
|
|
@@ -322,11 +406,12 @@ export const dynamicExtractNodeType = {
|
|
|
322
406
|
}),
|
|
323
407
|
check: ({ inputs }, ctx) => {
|
|
324
408
|
checkFileRef(inputs, 'extract from', ctx);
|
|
325
|
-
|
|
326
|
-
ctx.report('EXTRACT_SCHEMA_SHAPE', `"${ctx.step}"'s schema must be an object (the inline extraction schema document).`);
|
|
327
|
-
}
|
|
409
|
+
checkSchema(inputs, ctx);
|
|
328
410
|
},
|
|
329
411
|
// check collected no expressions for this kind before the port; unchanged by it.
|
|
330
412
|
expressions: () => [],
|
|
331
|
-
|
|
413
|
+
// The processed document's fixed keys (`extract-output.ts`).
|
|
414
|
+
output: () => ({ kind: 'reader', read: checkExtractRead }),
|
|
415
|
+
// A file an SDK before #1987 compiled declares ExtractionResult; merge writes the processed document.
|
|
416
|
+
supersededOutputs: isLegacyExtractOutputs,
|
|
332
417
|
};
|
|
@@ -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;
|