@uipath/maestro-builder-sdk 6.93.9 → 6.94.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.
- package/dist/api-index.md +27 -26
- package/dist/api-members.md +77 -75
- package/dist/case/decompile.js +15 -0
- package/dist/case/preserve.d.ts +19 -12
- package/dist/case/serialize.js +8 -1
- package/dist/core/actions.d.ts +43 -4
- package/dist/core/agent-resource-identity.d.ts +17 -0
- package/dist/core/agent-resource-identity.js +23 -0
- package/dist/core/refusals.d.ts +9 -0
- package/dist/core/refusals.js +9 -0
- package/dist/decompile.d.ts +4 -1
- package/dist/merge-sidecars.js +13 -4
- package/dist/nodes/agent/flow/builtin-tool-lift.d.ts +60 -0
- package/dist/nodes/agent/flow/builtin-tool-lift.js +255 -0
- package/dist/nodes/agent/flow/check.d.ts +1 -1
- package/dist/nodes/agent/flow/check.js +115 -11
- package/dist/nodes/agent/flow/inline-agent-lift.js +52 -40
- package/dist/nodes/agent/flow/inline-agent.d.ts +13 -7
- package/dist/nodes/agent/flow/inline-agent.js +66 -18
- package/dist/nodes/agent/flow/node-type.js +5 -5
- package/dist/nodes/agent/flow/resource-sidecar.d.ts +22 -0
- package/dist/nodes/agent/flow/resource-sidecar.js +25 -0
- package/dist/nodes/agent/flow/resources.d.ts +76 -8
- package/dist/nodes/agent/flow/resources.js +345 -39
- package/dist/nodes/ai-patterns/flow/spec.d.ts +1 -7
- package/package.json +2 -2
|
@@ -28,6 +28,10 @@ export const AGENT_DIAGNOSTICS = {
|
|
|
28
28
|
GUARDRAIL_NO_SCOPE: { severity: 'error', summary: 'a guardrail whose selector names no scope' },
|
|
29
29
|
GUARDRAIL_NO_VALIDATOR: { severity: 'error', summary: 'a built-in validator guardrail with no validatorType' },
|
|
30
30
|
GUARDRAIL_TYPE_UNKNOWN: { severity: 'error', summary: 'a guardrail whose type is unknown' },
|
|
31
|
+
FLOW_AGENT_BATCH_TRANSFORM_COLUMN_DESCRIPTION: { severity: 'error', summary: 'a Batch Transform output column whose description is empty or over 20,000 characters' },
|
|
32
|
+
FLOW_AGENT_BATCH_TRANSFORM_COLUMN_NAME: { severity: 'error', summary: 'a Batch Transform output column whose name the canvas does not accept' },
|
|
33
|
+
FLOW_AGENT_BATCH_TRANSFORM_NO_COLUMNS: { severity: 'error', summary: 'a Batch Transform tool with no output columns' },
|
|
34
|
+
FLOW_AGENT_BATCH_TRANSFORM_TOO_MANY_COLUMNS: { severity: 'error', summary: 'a Batch Transform tool with more than 10 output columns' },
|
|
31
35
|
INLINE_AGENT_COMPOSITE_INPUT: { severity: 'error', summary: 'an inline agent input bound to a computed expression' },
|
|
32
36
|
INLINE_AGENT_EMPTY_RETURNS: { severity: 'warning', summary: 'an inline agent with returns: {}' },
|
|
33
37
|
FLOW_AGENT_ESCALATION_APP_KEY_NOT_GUID: { severity: 'error', summary: 'an app escalation whose app key is not a GUID' },
|
|
@@ -375,6 +379,106 @@ function checkToolArguments(tool, args, ctx, who) {
|
|
|
375
379
|
}
|
|
376
380
|
}
|
|
377
381
|
}
|
|
382
|
+
// ─── a built-in tool's settings ──────────────────────────────────────────────────
|
|
383
|
+
/** The canvas's Output columns editor: `maxColumns`, and the name and description fields' limits. */
|
|
384
|
+
const BATCH_TRANSFORM_MAX_COLUMNS = 10;
|
|
385
|
+
const COLUMN_NAME_MAX = 64;
|
|
386
|
+
const COLUMN_NAME_RE = /^[a-zA-Z0-9_-]+$/;
|
|
387
|
+
const COLUMN_DESCRIPTION_MAX = 20_000;
|
|
388
|
+
const COLUMN_DESCRIPTION_MAX_TEXT = '20,000';
|
|
389
|
+
/** The built-ins whose definition has a task (`inputs.query`). */
|
|
390
|
+
const BUILTIN_TOOLS_WITH_QUERY = ['summarize', 'batchtransform'];
|
|
391
|
+
/** A `{ … }` literal, the only value a named task source can be; an `Expr`, an array or a string is not one. */
|
|
392
|
+
const isPlainObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v)
|
|
393
|
+
&& (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
|
|
394
|
+
/**
|
|
395
|
+
* The flat names of the agent inputs a tool's Variables bind: a process tool's
|
|
396
|
+
* arguments (`toolVariableRefs`), or a built-in's task, `{ variable: <one
|
|
397
|
+
* reference> }`. Both go through `agentInputRef`, as `agentInputPlan` names them,
|
|
398
|
+
* so a declared input bound to the same reference is that one input.
|
|
399
|
+
*/
|
|
400
|
+
function toolVariableNames(tool) {
|
|
401
|
+
const t = tool;
|
|
402
|
+
if (isProcessToolKind(t?.kind))
|
|
403
|
+
return Object.values(toolVariableRefs(t.inputs, rendered)).map((r) => r.flatName);
|
|
404
|
+
if (t?.kind !== 'builtin' || !BUILTIN_TOOLS_WITH_QUERY.includes(t.tool) || !isPlainObject(t.query))
|
|
405
|
+
return [];
|
|
406
|
+
const keys = Object.keys(t.query);
|
|
407
|
+
if (keys.length !== 1 || keys[0] !== 'variable')
|
|
408
|
+
return [];
|
|
409
|
+
const ref = agentInputRef(rendered(t.query.variable));
|
|
410
|
+
return ref === undefined ? [] : [ref.flatName];
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* A built-in tool's settings (docs/INLINE_AGENT_BATCH_TRANSFORM_DESIGN.md,
|
|
414
|
+
* "What `check` reports"). Compile writes them as given, into the tool node and
|
|
415
|
+
* its `resource.json`, and nothing downstream reads them before a run: the
|
|
416
|
+
* node's definition types `outputColumns` only as an array, and the storage
|
|
417
|
+
* schema refines none of them. The column rules are the canvas's Output
|
|
418
|
+
* columns editor's. Where the canvas drops a bad column on save, `check`
|
|
419
|
+
* refuses it, because a column the author wrote and the tool never fills is
|
|
420
|
+
* worse than an error. Like the canvas, it does not require distinct names.
|
|
421
|
+
*
|
|
422
|
+
* What compile refuses is not judged here: a task object it cannot write
|
|
423
|
+
* (`FLOW_AGENT_BUILTIN_QUERY_SOURCE`), a task Variable that is no single
|
|
424
|
+
* reference (`FLOW_AGENT_BUILTIN_COMPOSITE_REF`) or that the agent cannot bind
|
|
425
|
+
* (`FLOW_AGENT_BUILTIN_TASK_VARIABLE`), a grounding the select does not offer
|
|
426
|
+
* (`FLOW_AGENT_BATCH_TRANSFORM_GROUNDING`) and a Batch Transform setting on
|
|
427
|
+
* another built-in (`FLOW_AGENT_BUILTIN_SETTING_NOT_APPLICABLE`) are held by
|
|
428
|
+
* `toolArguments` and reported from there in collect mode, so they are skipped
|
|
429
|
+
* here, as `checkToolArguments` skips a process argument's.
|
|
430
|
+
*/
|
|
431
|
+
function checkBuiltinTool(t, ctx, who) {
|
|
432
|
+
const tool = t.tool;
|
|
433
|
+
const where = `${who} step "${ctx.step}"'s ${String(tool)} tool`;
|
|
434
|
+
if (tool === 'batchtransform')
|
|
435
|
+
checkBatchTransformColumns(t.outputColumns, where, ctx);
|
|
436
|
+
}
|
|
437
|
+
/** Batch Transform's `outputColumns`, under the canvas's Output columns editor's rules. */
|
|
438
|
+
function checkBatchTransformColumns(columns, where, ctx) {
|
|
439
|
+
const example = `outputColumns: [{ name: 'Category', description: 'One of: Utility, Software, Travel, Other' }]`;
|
|
440
|
+
if (!Array.isArray(columns) || columns.length === 0) {
|
|
441
|
+
ctx.report('FLOW_AGENT_BATCH_TRANSFORM_NO_COLUMNS', `${where} ${columns === undefined ? 'has no `outputColumns`'
|
|
442
|
+
: Array.isArray(columns) ? 'has an empty `outputColumns`'
|
|
443
|
+
: `has \`outputColumns\` ${JSON.stringify(columns) ?? String(columns)}, which is not a list`}. `
|
|
444
|
+
+ `The columns are what the tool adds to each row of the file — without one it has nothing to fill. `
|
|
445
|
+
+ `The canvas's definition requires at least one ("At least one output column is required").`, example);
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (columns.length > BATCH_TRANSFORM_MAX_COLUMNS) {
|
|
449
|
+
ctx.report('FLOW_AGENT_BATCH_TRANSFORM_TOO_MANY_COLUMNS', `${where} has ${columns.length} \`outputColumns\`. The canvas allows at most ${BATCH_TRANSFORM_MAX_COLUMNS} `
|
|
450
|
+
+ `(its Add button is disabled past that), so a flow with more is one the canvas cannot have written, and `
|
|
451
|
+
+ `cannot edit. Keep the ${BATCH_TRANSFORM_MAX_COLUMNS} that matter, or split the work over two tools.`);
|
|
452
|
+
}
|
|
453
|
+
// `Array.from`, not `forEach`: every index, so a hole in a sparse list is
|
|
454
|
+
// read as `undefined` and reported like the `null` compile's clone writes there.
|
|
455
|
+
Array.from(columns).forEach((c, i) => {
|
|
456
|
+
const col = (c ?? {});
|
|
457
|
+
const label = typeof col.name === 'string' && col.name !== '' ? `"${col.name}"` : `outputColumns[${i}]`;
|
|
458
|
+
const name = col.name;
|
|
459
|
+
const nameProblem = typeof name !== 'string' || name.trim() === '' ? 'has no name'
|
|
460
|
+
: name.length > COLUMN_NAME_MAX ? `has a name of ${name.length} characters, over the ${COLUMN_NAME_MAX} the canvas allows`
|
|
461
|
+
: !COLUMN_NAME_RE.test(name)
|
|
462
|
+
? `has a name with ${/^\s|\s$/.test(name) ? 'spaces around it' : 'a character other than a letter, a digit, `_` or `-`'}`
|
|
463
|
+
: undefined;
|
|
464
|
+
if (nameProblem !== undefined) {
|
|
465
|
+
const fixed = typeof name === 'string' ? name.trim().replace(/[^a-zA-Z0-9_-]+/g, '_').slice(0, COLUMN_NAME_MAX) : '';
|
|
466
|
+
ctx.report('FLOW_AGENT_BATCH_TRANSFORM_COLUMN_NAME', `${where}'s column ${label} ${nameProblem}. The name is the new column's header, and the canvas accepts `
|
|
467
|
+
+ `only 1 to ${COLUMN_NAME_MAX} letters (a-z, A-Z), digits, underscores or hyphens: it drops any other `
|
|
468
|
+
+ `column when it saves, so the tool would never fill it.`, `{ name: '${fixed || 'Category'}', description: … }`);
|
|
469
|
+
}
|
|
470
|
+
const d = col.description;
|
|
471
|
+
const descriptionProblem = typeof d !== 'string' || d.trim() === '' ? 'has no description'
|
|
472
|
+
: d.length > COLUMN_DESCRIPTION_MAX
|
|
473
|
+
? `has a description of ${d.length} characters, over the ${COLUMN_DESCRIPTION_MAX_TEXT} the canvas allows`
|
|
474
|
+
: undefined;
|
|
475
|
+
if (descriptionProblem !== undefined) {
|
|
476
|
+
ctx.report('FLOW_AGENT_BATCH_TRANSFORM_COLUMN_DESCRIPTION', `${where}'s column ${label} ${descriptionProblem}. The description is what the model is told to put in `
|
|
477
|
+
+ `the column, and the canvas requires one of 1 to ${COLUMN_DESCRIPTION_MAX_TEXT} characters `
|
|
478
|
+
+ `("Description is required").`, `{ name: ${typeof name === 'string' ? JSON.stringify(name) : `'Category'`}, description: 'One of: Utility, Software, Travel, Other' }`);
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}
|
|
378
482
|
/**
|
|
379
483
|
* Check an `inlineAgent(...)` call.
|
|
380
484
|
*
|
|
@@ -392,7 +496,7 @@ function checkToolArguments(tool, args, ctx, who) {
|
|
|
392
496
|
* - `INLINE_AGENT_UNREFERENCED_INPUT` — flow-v1 derives the deployed input list by
|
|
393
497
|
* scanning the PROMPTS for `$vars.*` references and only falls back to the
|
|
394
498
|
* authored `agentInputVariables` when that pre-pass did not run. So a declared
|
|
395
|
-
* input the prompts never mention, and no tool argument binds as its
|
|
499
|
+
* input the prompts never mention, and no tool argument or built-in's task binds as its
|
|
396
500
|
* `variable`, is pruned deployed while arriving locally: a
|
|
397
501
|
* disagreement between rungs and the platform, which is the one class that has to
|
|
398
502
|
* be said out loud rather than left to a run.
|
|
@@ -503,25 +607,22 @@ export function checkInlineAgent(inputs, ctx) {
|
|
|
503
607
|
// searched, because flow-v1's pre-pass scans both.
|
|
504
608
|
const placeholders = promptPlaceholders(inputs ?? {});
|
|
505
609
|
const declaredInputs = Object.keys(inputs?.inputs ?? {});
|
|
506
|
-
// The agent inputs a process tool's
|
|
507
|
-
// declared input bound to the same
|
|
508
|
-
// (`agentInputPlan`), so a tool
|
|
610
|
+
// The agent inputs the tools' Variables bind (a process tool's arguments, a
|
|
611
|
+
// built-in's task), by flat name. A declared input bound to the same
|
|
612
|
+
// reference is that one input (`agentInputPlan`), so a tool reads it.
|
|
509
613
|
const tools = inputs?.tools === undefined ? [] : Array.isArray(inputs.tools) ? inputs.tools : [inputs.tools];
|
|
510
|
-
const toolBound = new Set(tools
|
|
511
|
-
.filter((t) => isProcessToolKind(t?.kind))
|
|
512
|
-
.flatMap((t) => Object.values(toolVariableRefs(t.inputs, rendered)))
|
|
513
|
-
.map((r) => r.flatName));
|
|
614
|
+
const toolBound = new Set(tools.flatMap(toolVariableNames));
|
|
514
615
|
const boundForTool = (k) => {
|
|
515
616
|
const ref = agentInputRef(rendered(inputs?.inputs?.[k]));
|
|
516
617
|
return ref !== undefined && toolBound.has(ref.flatName);
|
|
517
618
|
};
|
|
518
|
-
// Direction 1: a declared input no prompt references and no tool
|
|
619
|
+
// Direction 1: a declared input no prompt references and no tool's Variable
|
|
519
620
|
// binds. The platform may prune it, in which case the agent receives nothing
|
|
520
621
|
// and the authored list sits unused.
|
|
521
622
|
const unreferenced = declaredInputs.filter((k) => !placeholders.includes(k) && !boundForTool(k));
|
|
522
623
|
if (declaredInputs.length && unreferenced.length === declaredInputs.length) {
|
|
523
624
|
warn('INLINE_AGENT_UNREFERENCED_INPUT', `Inline agent step "${step}" declares input(s) ${unreferenced.map((u) => `\`${u}\``).join(', ')} that `
|
|
524
|
-
+ `neither prompt references as \`{{input.<name>}}\` and no tool argument binds as its \`variable\` — so `
|
|
625
|
+
+ `neither prompt references as \`{{input.<name>}}\` and no tool argument or tool's task binds as its \`variable\` — so `
|
|
525
626
|
+ `NONE of them is referenced. Deployed, the `
|
|
526
627
|
+ `authored list is not necessarily what the platform sends: flow-v1's `
|
|
527
628
|
+ `\`preDeriveAgentInputDefinitions\` pre-pass builds the input list by scanning the node's prompts for `
|
|
@@ -533,7 +634,7 @@ export function checkInlineAgent(inputs, ctx) {
|
|
|
533
634
|
}
|
|
534
635
|
else if (unreferenced.length) {
|
|
535
636
|
warn('INLINE_AGENT_UNREFERENCED_INPUT', `Inline agent step "${step}" declares input(s) ${unreferenced.map((u) => `\`${u}\``).join(', ')} that `
|
|
536
|
-
+ `neither prompt references as \`{{input.<name>}}\` and no tool argument binds as its \`variable\`. `
|
|
637
|
+
+ `neither prompt references as \`{{input.<name>}}\` and no tool argument or tool's task binds as its \`variable\`. `
|
|
537
638
|
+ `The platform may prune an unreferenced input, so `
|
|
538
639
|
+ `it is not reliably sent — and an input the prompts never mention is one the agent cannot use anyway.`);
|
|
539
640
|
}
|
|
@@ -780,6 +881,9 @@ export function checkAgentResources(inputs, ctx, who) {
|
|
|
780
881
|
+ `calling application dispatches on it.`);
|
|
781
882
|
}
|
|
782
883
|
}
|
|
884
|
+
else if (kind === 'builtin') {
|
|
885
|
+
checkBuiltinTool(t, ctx, who);
|
|
886
|
+
}
|
|
783
887
|
else if (kind === 'httpRequest') {
|
|
784
888
|
const h = t;
|
|
785
889
|
const m = h.method === undefined ? undefined : String(h.method).toUpperCase();
|
|
@@ -9,19 +9,21 @@
|
|
|
9
9
|
* id, a setting, a form row; an expression query is printed as the text compile
|
|
10
10
|
* reads it from — so the lift writes each resource's options as source once,
|
|
11
11
|
* through the core literal writers, while the warnings and refusals that
|
|
12
|
-
* reading them raises still go through the context. The agent's own inputs
|
|
13
|
-
*
|
|
14
|
-
* for the printer.
|
|
12
|
+
* reading them raises still go through the context. The agent's own inputs, a
|
|
13
|
+
* process tool argument's Variable and a built-in tool's task Variable are the
|
|
14
|
+
* only expressions, kept as `Expr`s for the printer.
|
|
15
15
|
*/
|
|
16
|
-
import { agentInputRef, agentSidecarInputs } from '../../../core/agent-sidecar.js';
|
|
16
|
+
import { agentInputRef, agentSidecarInputs, promptPlaceholders } from '../../../core/agent-sidecar.js';
|
|
17
17
|
import { derivedContextSource, derivedEscalationSource, derivedResourceNodeId, derivedToolSource, } from '../../../core/agent-resource-identity.js';
|
|
18
18
|
import { CONTEXT_INDEX_DEFAULTS, CONTEXT_INDEX_DEFAULT_FILE_EXTENSION, contextIndexSlug, parseContextIndexType, } from '../../../core/context-index.js';
|
|
19
|
-
import { Expr, flatNameReference } from '../../../core/expr.js';
|
|
19
|
+
import { Expr, flatNameOf, flatNameReference } from '../../../core/expr.js';
|
|
20
20
|
import { formFieldRowLoss, formFieldRowLossMessage, formFieldSettingsSource, liftFormFieldSettings, sourceFormFieldType, } from '../../../core/form-field-type.js';
|
|
21
21
|
import { ownEntry } from '../../../core/own-entry.js';
|
|
22
|
-
import { isInlineAgentFieldType, jsonPathSegments } from '../../../core/tool-argument.js';
|
|
22
|
+
import { isInlineAgentFieldType, jsonPathKey, jsonPathSegments } from '../../../core/tool-argument.js';
|
|
23
23
|
import { tsKey as key, tsLiteral, tsNumber, tsObject as objLit, tsOptions as opts, tsText } from '../../../core/ts-literal.js';
|
|
24
24
|
import { wireExprBody } from '../../../core/wire-expr.js';
|
|
25
|
+
import { liftBatchTransformTool, reportUnreadBuiltinTask } from './builtin-tool-lift.js';
|
|
26
|
+
import { resourceSidecar } from './resource-sidecar.js';
|
|
25
27
|
import { BUILTIN_TOOL_DEFS, escalationDef, voiceAgentRevision } from './resources.js';
|
|
26
28
|
/** Where the agent's own `inputs` go in the option list: the printer writes them, as expressions. */
|
|
27
29
|
const INPUT_ROWS = Symbol('inputs');
|
|
@@ -40,8 +42,8 @@ const PROCESS_NS = [
|
|
|
40
42
|
* `tools` entry. Only tools compile writes back to the same node, at the same
|
|
41
43
|
* version, are claimed; any other edge stays reported as dropped. Compile
|
|
42
44
|
* writes the HTTP request tool at 1.0 and a bundled built-in at its
|
|
43
|
-
* definition's version (1.1, or 1.2 on a voice agent
|
|
44
|
-
* version to carry another.
|
|
45
|
+
* definition's version (1.1, or 1.2 on a voice agent; `batchtransform` 1.2 on
|
|
46
|
+
* every agent); `BuiltinToolRef` has no version to carry another.
|
|
45
47
|
*/
|
|
46
48
|
function liftableToolFor(agentType) {
|
|
47
49
|
const builtinVersion = (def) => (agentType === VOICE_AGENT_TYPE ? voiceAgentRevision(def).version : def.version);
|
|
@@ -131,7 +133,7 @@ function dataSource(v) {
|
|
|
131
133
|
*/
|
|
132
134
|
function contextIndexIdentity(agent, c, rPlain, ctx) {
|
|
133
135
|
const fromType = parseContextIndexType(c.type);
|
|
134
|
-
const sidecar = resourceSidecar(agent, c, ctx, `context index "${c.id}"`, 'the resource decompiles from the node');
|
|
136
|
+
const sidecar = resourceSidecar(agent, ctx.sourceText(c.inputs?.source), ctx, `context index "${c.id}"`, 'the resource decompiles from the node');
|
|
135
137
|
const sidecarText = (k) => typeof sidecar?.[k] === 'string' && sidecar[k] !== '' ? sidecar[k] : undefined;
|
|
136
138
|
const label = typeof c.display?.label === 'string' && c.display.label !== '' ? c.display.label : undefined;
|
|
137
139
|
// The canvas can set both sidecar `name` and `indexName`, and they can differ.
|
|
@@ -287,31 +289,6 @@ function contextIndexSettings(agent, c, sidecar, ctx) {
|
|
|
287
289
|
['fileExtension', extensionSrc],
|
|
288
290
|
];
|
|
289
291
|
}
|
|
290
|
-
/**
|
|
291
|
-
* Resource node `r`'s `<agent source>/resources/<r's source>/resource.json`,
|
|
292
|
-
* parsed; `undefined` when it is not beside the `.flow`, or (with a warning
|
|
293
|
-
* that `fallback` completes) when it is not a JSON object.
|
|
294
|
-
*/
|
|
295
|
-
function resourceSidecar(agent, r, ctx, what, fallback) {
|
|
296
|
-
const agentSource = ctx.sourceText(agent.inputs?.source);
|
|
297
|
-
const resourceSource = ctx.sourceText(r.inputs?.source);
|
|
298
|
-
if (!agentSource || !resourceSource)
|
|
299
|
-
return undefined;
|
|
300
|
-
const path = `${agentSource}/resources/${resourceSource}/resource.json`;
|
|
301
|
-
const raw = ctx.sidecar(path);
|
|
302
|
-
if (raw === undefined)
|
|
303
|
-
return undefined;
|
|
304
|
-
try {
|
|
305
|
-
const json = JSON.parse(raw);
|
|
306
|
-
if (json && typeof json === 'object' && !Array.isArray(json))
|
|
307
|
-
return json;
|
|
308
|
-
}
|
|
309
|
-
catch {
|
|
310
|
-
// Reported below with the non-object case.
|
|
311
|
-
}
|
|
312
|
-
ctx.warn(`${what}: ${path} is not valid JSON, so ${fallback}.`);
|
|
313
|
-
return undefined;
|
|
314
|
-
}
|
|
315
292
|
/**
|
|
316
293
|
* The keys of a tool's schema property that its flat type may drop unreported:
|
|
317
294
|
* the type it keeps, the title and the description (an argument's Prompt,
|
|
@@ -658,10 +635,8 @@ export function liftInlineAgent(node, ctx) {
|
|
|
658
635
|
// that plans the same inputs, in the same order, as printing all of them
|
|
659
636
|
// would; otherwise every input is printed, and a tool reference one of them
|
|
660
637
|
// binds is still one input, `refs` being deduped by flat name.
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
return raw === undefined ? [] : [...unrender(raw).matchAll(/\{\{\s*input\.([A-Za-z_$][A-Za-z0-9_$]*)\s*\}\}/g)].map((m) => m[1]);
|
|
664
|
-
}));
|
|
638
|
+
const prompt = (p) => (plain(p) === undefined ? undefined : unrender(plain(p)));
|
|
639
|
+
const placeholders = new Set(promptPlaceholders({ systemPrompt: prompt(i.systemPrompt), userPrompt: prompt(i.userPrompt) }));
|
|
665
640
|
const toolOnly = new Set(toolVariables.map((v) => v.id).filter((id) => !placeholders.has(id)));
|
|
666
641
|
/** The flat names compile plans from `declared` and the tools' references, deduped as `agentInputPlan` does. */
|
|
667
642
|
const planned = (declared) => JSON.stringify([...new Set([
|
|
@@ -765,8 +740,27 @@ export function liftAgentResources(node, ctx, withMemory, agentInputs = []) {
|
|
|
765
740
|
const raw = ctx.sourceText(rInputs(n)[k]);
|
|
766
741
|
return raw === undefined || raw === '' ? undefined : raw;
|
|
767
742
|
};
|
|
768
|
-
/** The agent inputs the
|
|
743
|
+
/** The agent inputs the tools' Variables bind (a process tool's arguments, a built-in's task), in tool and argument order. */
|
|
769
744
|
const toolVariables = [];
|
|
745
|
+
/**
|
|
746
|
+
* A built-in tool's task Variable, as the reference of the agent input it
|
|
747
|
+
* names: by its `{{<flatName>}}` in the sidecar, by `$agent.<flatName>`, or by
|
|
748
|
+
* its `$vars.<path>` on a canvas node (the canvas's own form, which it derives
|
|
749
|
+
* the flat name from). Resolved as a process tool argument's path is
|
|
750
|
+
* ({@link argumentInput}), and recorded with the tools' Variables.
|
|
751
|
+
*/
|
|
752
|
+
const taskVariable = (task) => {
|
|
753
|
+
const text = task.text.trim();
|
|
754
|
+
const braced = /^\{\{\s*(.*?)\s*\}\}$/.exec(text)?.[1];
|
|
755
|
+
const name = braced ?? (text.startsWith('$agent.') ? text.slice('$agent.'.length) : flatNameOf(text));
|
|
756
|
+
if (name === undefined || name === '')
|
|
757
|
+
return undefined;
|
|
758
|
+
const input = argumentInput(jsonPathKey(name), agentInputs, ctx);
|
|
759
|
+
if (input.kind !== 'variable')
|
|
760
|
+
return undefined;
|
|
761
|
+
toolVariables.push({ id: input.id, ref: input.ref });
|
|
762
|
+
return new Expr(input.body);
|
|
763
|
+
};
|
|
770
764
|
const toolSrc = ctx.attached('tool', Infinity, liftable).map((t) => {
|
|
771
765
|
const ti = rInputs(t);
|
|
772
766
|
const type = t.type;
|
|
@@ -816,8 +810,26 @@ export function liftAgentResources(node, ctx, withMemory, agentInputs = []) {
|
|
|
816
810
|
['folderPath', rPlain(t, 'folderPath') !== undefined ? tsLiteral(rPlain(t, 'folderPath')) : undefined],
|
|
817
811
|
]);
|
|
818
812
|
}
|
|
813
|
+
if (type === 'uipath.agent.resource.tool.builtin.batchtransform') {
|
|
814
|
+
// Every setting, node first, with the sidecar as the fallback (D8 of
|
|
815
|
+
// docs/INLINE_AGENT_BATCH_TRANSFORM_DESIGN.md). The directory is the node's
|
|
816
|
+
// `source`, or the canvas's `inputs.id` when `source` is empty or a file
|
|
817
|
+
// binding: kept as the tool's `source`, so a recompile writes back into it.
|
|
818
|
+
const { entries, dir } = liftBatchTransformTool(node, t, ctx, taskVariable);
|
|
819
|
+
const derived = derivedToolSource(ctx.flowId, node.id, { kind: 'builtin', tool: 'batchtransform' });
|
|
820
|
+
const all = [
|
|
821
|
+
...entries,
|
|
822
|
+
['nodeId', keepIds.has(t.id) ? tsLiteral(t.id) : undefined],
|
|
823
|
+
['source', dir !== undefined && dir !== derived ? tsLiteral(dir) : undefined],
|
|
824
|
+
];
|
|
825
|
+
return all.every(([, v]) => typeof v !== 'function') ? opts(all)
|
|
826
|
+
: (print) => opts(all.map(([k, v]) => [k, typeof v === 'function' ? v(print) : v]));
|
|
827
|
+
}
|
|
819
828
|
if (type.startsWith('uipath.agent.resource.tool.builtin.')) {
|
|
820
829
|
const tool = type.slice('uipath.agent.resource.tool.builtin.'.length);
|
|
830
|
+
// Only batchtransform's task is read back (above); any other built-in
|
|
831
|
+
// with a task (summarize) reports one it would drop.
|
|
832
|
+
reportUnreadBuiltinTask(node, t, tool, ctx);
|
|
821
833
|
return toolOpts(t, { kind: 'builtin', tool }, [
|
|
822
834
|
['kind', tsLiteral('builtin')],
|
|
823
835
|
['tool', tsLiteral(tool)],
|
|
@@ -848,7 +860,7 @@ export function liftAgentResources(node, ctx, withMemory, agentInputs = []) {
|
|
|
848
860
|
// definition's `inputDefaults.inputSchema` / `outputSchema` and the
|
|
849
861
|
// resource.json's, and `description` only into the resource.json.
|
|
850
862
|
const what = `${ns[1]} tool ${JSON.stringify(t.id)} on agent ${JSON.stringify(node.id)}`;
|
|
851
|
-
const sidecar = resourceSidecar(node, t, ctx, what, 'its inputs and returns decompile from its definition');
|
|
863
|
+
const sidecar = resourceSidecar(node, ctx.sourceText(t.inputs?.source), ctx, what, 'its inputs and returns decompile from its definition');
|
|
852
864
|
const description = typeof sidecar?.description === 'string' && sidecar.description !== '' ? sidecar.description : undefined;
|
|
853
865
|
const { inputs, returns, variables } = processToolFields(t, what, sidecar, def?.inputDefaults, agentInputs, ctx);
|
|
854
866
|
toolVariables.push(...variables);
|
|
@@ -19,18 +19,24 @@ export type AgentKindLabel = 'Inline agent' | 'Voice agent' | 'Conversational ag
|
|
|
19
19
|
/** The inline agent's node, sidecar and resources. */
|
|
20
20
|
export declare function serializeInlineAgent(s: InlineAgentInputs, ctx: FlowSerializeContext): FlowNodeContribution;
|
|
21
21
|
/**
|
|
22
|
-
* Each process tool's arguments,
|
|
23
|
-
* attached: `toolArgument` is the first one
|
|
24
|
-
* ({@link toolArgumentRefusal}
|
|
25
|
-
*
|
|
26
|
-
*
|
|
22
|
+
* Each process tool's arguments, and each built-in's task and settings, judged
|
|
23
|
+
* before the agent's resources are attached: `toolArgument` is the first one
|
|
24
|
+
* compile cannot write ({@link toolArgumentRefusal}, {@link builtinToolQueryRefusal},
|
|
25
|
+
* {@link builtinToolSettingRefusal}), in tool then argument order, for the
|
|
26
|
+
* caller to hold until it has judged the rest; `toolVariables` holds each
|
|
27
|
+
* tool's Variables in `tools` order (a process tool's by argument name,
|
|
28
|
+
* {@link toolVariableRefs}; a built-in's task as `query`,
|
|
29
|
+
* {@link builtinToolQueryRef}), for the caller to bind as agent inputs, a
|
|
30
|
+
* refused one left out. It is the only collector of the tools' references:
|
|
31
|
+
* decompile's tool-only `inputs` row rule relies on their order.
|
|
27
32
|
*
|
|
28
33
|
* `bindsVariables` is false for the voice and conversational agents: compile
|
|
29
34
|
* extends only the inline agent's input plan with a tool's references, so a
|
|
30
35
|
* Variable there would bind nothing and the model would fill the argument. It
|
|
31
|
-
* is refused instead (`FLOW_AGENT_TOOL_ARGUMENT_VARIABLE
|
|
36
|
+
* is refused instead (`FLOW_AGENT_TOOL_ARGUMENT_VARIABLE`; for a built-in's
|
|
37
|
+
* task, `FLOW_AGENT_BUILTIN_TASK_VARIABLE`).
|
|
32
38
|
*/
|
|
33
|
-
export declare function
|
|
39
|
+
export declare function toolArguments(s: AgentResources, step: string, who: AgentKindLabel, render: (v: unknown) => unknown, bindsVariables: boolean): {
|
|
34
40
|
toolVariables: Map<object, ReturnType<typeof toolVariableRefs>>;
|
|
35
41
|
toolArgument: CompileRefusal | undefined;
|
|
36
42
|
};
|
|
@@ -11,7 +11,7 @@ import { processResourceBindings } from '../../../core/process-resource.js';
|
|
|
11
11
|
import { toolArgumentRefusal, toolVariableRefs } from '../../../core/tool-argument.js';
|
|
12
12
|
import { fnv1aX4Uuid, schemaId } from '../../../core/stable-id.js';
|
|
13
13
|
import { synthesizedDefinitionRefusal } from '../../../core/synthesized-definition.js';
|
|
14
|
-
import { BUILTIN_TOOL_DEFS, INLINE_AGENT, PROCESS_TOOL_META, a2aToolDef, builtinToolResourceJson, connectorToolDef, connectorToolDescription, connectorToolDetail, connectorToolResourceJson, contextIndexDef, contextResourceJson, declaresMemoryHandle, escalationAppFolder, escalationDef, escalationResourceJson, fieldSchema, httpRequestToolResourceJson, inlineAgentDef, ixpToolDef, mcpToolDef, memoryResourceDef, processToolDef, renderContextQuery, toolResourceJson, voiceAgentRevision, } from './resources.js';
|
|
14
|
+
import { BUILTIN_TOOL_DEFS, builtinToolQueryRefusal, builtinToolSettingRefusal, INLINE_AGENT, PROCESS_TOOL_META, a2aToolDef, builtinToolResourceJson, connectorToolDef, connectorToolDescription, connectorToolDetail, connectorToolResourceJson, contextIndexDef, contextResourceJson, declaresMemoryHandle, escalationAppFolder, escalationDef, escalationResourceJson, fieldSchema, httpRequestToolResourceJson, inlineAgentDef, ixpToolDef, mcpToolDef, memoryResourceDef, processToolDef, builtinToolQueryRef, renderBuiltinToolQuery, renderContextQuery, toolResourceJson, voiceAgentRevision, } from './resources.js';
|
|
15
15
|
import { CompileRefusal } from '../../../core/compile-refusal.js';
|
|
16
16
|
/** Every bundled version of the inline agent, oldest first; the newest is the default (#956). */
|
|
17
17
|
export const INLINE_AGENT_VERSIONS = ['1.2', '1.3', '1.4'];
|
|
@@ -67,11 +67,12 @@ export function serializeInlineAgent(s, ctx) {
|
|
|
67
67
|
properties: Object.fromEntries(Object.entries(returns).map(([k, t]) => [k, { type: t }])),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
// A
|
|
71
|
-
// its own, as the canvas derives one from
|
|
72
|
-
// (`deriveAgentInputVariables`), so they are
|
|
73
|
-
// An argument compile cannot write is
|
|
74
|
-
|
|
70
|
+
// A tool's Variables, by tool (a process tool's arguments, a built-in's
|
|
71
|
+
// task): each binds an agent input of its own, as the canvas derives one from
|
|
72
|
+
// every reference a tool node holds (`deriveAgentInputVariables`), so they are
|
|
73
|
+
// read before the plan is built. An argument or task compile cannot write is
|
|
74
|
+
// held like a composite input (below).
|
|
75
|
+
const { toolVariables, toolArgument } = toolArguments(s, step, 'Inline agent', render, true);
|
|
75
76
|
// What the PLATFORM will call each of these — computed once and shared by the
|
|
76
77
|
// descriptor array below and the sidecar. See `agentInputPlan`.
|
|
77
78
|
const plan = agentInputPlan(s.inputs ?? {}, render, [...toolVariables.values()].flatMap((v) => Object.values(v)));
|
|
@@ -156,9 +157,9 @@ export function serializeInlineAgent(s, ctx) {
|
|
|
156
157
|
// (AGENT_MEMORY_NOT_AUTHORABLE); its shape maps cleanly off `AgentMemoryRef`
|
|
157
158
|
// but cannot be exercised while the handle does not exist.
|
|
158
159
|
}
|
|
159
|
-
// The held refusals: the agent's own inputs, then its tools' arguments
|
|
160
|
-
// LIBRARY_REQUIRED last, because `check` drops it
|
|
161
|
-
// not hide either.
|
|
160
|
+
// The held refusals: the agent's own inputs, then its tools' arguments and
|
|
161
|
+
// built-in tasks, and LIBRARY_REQUIRED last, because `check` drops it
|
|
162
|
+
// (failing open), so it must not hide either.
|
|
162
163
|
if (compositeInput)
|
|
163
164
|
throw compositeInput;
|
|
164
165
|
if (toolArgument)
|
|
@@ -182,22 +183,46 @@ export function serializeInlineAgent(s, ctx) {
|
|
|
182
183
|
};
|
|
183
184
|
}
|
|
184
185
|
/**
|
|
185
|
-
* Each process tool's arguments,
|
|
186
|
-
* attached: `toolArgument` is the first one
|
|
187
|
-
* ({@link toolArgumentRefusal}
|
|
188
|
-
*
|
|
189
|
-
*
|
|
186
|
+
* Each process tool's arguments, and each built-in's task and settings, judged
|
|
187
|
+
* before the agent's resources are attached: `toolArgument` is the first one
|
|
188
|
+
* compile cannot write ({@link toolArgumentRefusal}, {@link builtinToolQueryRefusal},
|
|
189
|
+
* {@link builtinToolSettingRefusal}), in tool then argument order, for the
|
|
190
|
+
* caller to hold until it has judged the rest; `toolVariables` holds each
|
|
191
|
+
* tool's Variables in `tools` order (a process tool's by argument name,
|
|
192
|
+
* {@link toolVariableRefs}; a built-in's task as `query`,
|
|
193
|
+
* {@link builtinToolQueryRef}), for the caller to bind as agent inputs, a
|
|
194
|
+
* refused one left out. It is the only collector of the tools' references:
|
|
195
|
+
* decompile's tool-only `inputs` row rule relies on their order.
|
|
190
196
|
*
|
|
191
197
|
* `bindsVariables` is false for the voice and conversational agents: compile
|
|
192
198
|
* extends only the inline agent's input plan with a tool's references, so a
|
|
193
199
|
* Variable there would bind nothing and the model would fill the argument. It
|
|
194
|
-
* is refused instead (`FLOW_AGENT_TOOL_ARGUMENT_VARIABLE
|
|
200
|
+
* is refused instead (`FLOW_AGENT_TOOL_ARGUMENT_VARIABLE`; for a built-in's
|
|
201
|
+
* task, `FLOW_AGENT_BUILTIN_TASK_VARIABLE`).
|
|
195
202
|
*/
|
|
196
|
-
export function
|
|
203
|
+
export function toolArguments(s, step, who, render, bindsVariables) {
|
|
197
204
|
const toolRefs = s.tools === undefined ? [] : Array.isArray(s.tools) ? s.tools : [s.tools];
|
|
198
205
|
const toolVariables = new Map();
|
|
199
206
|
let toolArgument;
|
|
200
207
|
for (const tr of toolRefs) {
|
|
208
|
+
if (tr !== null && typeof tr === 'object' && tr.kind === 'builtin') {
|
|
209
|
+
// Its task, for the built-ins whose definition has one (`renderBuiltinToolQuery`
|
|
210
|
+
// reads `query` for those alone), then its Batch Transform settings. An
|
|
211
|
+
// unknown built-in is refused when the tool is attached.
|
|
212
|
+
const defaults = ownEntry(BUILTIN_TOOL_DEFS, tr.tool)?.inputDefaults;
|
|
213
|
+
if (defaults === undefined)
|
|
214
|
+
continue;
|
|
215
|
+
const where = `${who} step "${step}"'s ${tr.tool} tool`;
|
|
216
|
+
const taskRefusal = 'query' in defaults
|
|
217
|
+
? builtinToolQueryRefusal(tr.query, where, render)
|
|
218
|
+
?? (bindsVariables ? undefined : taskVariableRefusal(who, where, tr.query, render))
|
|
219
|
+
: undefined;
|
|
220
|
+
const ref = 'query' in defaults && taskRefusal === undefined ? builtinToolQueryRef(tr.query, render) : undefined;
|
|
221
|
+
if (ref !== undefined)
|
|
222
|
+
toolVariables.set(tr, { query: ref });
|
|
223
|
+
toolArgument ??= taskRefusal ?? builtinToolSettingRefusal(tr, defaults, where);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
201
226
|
if (tr === null || typeof tr !== 'object' || !ownEntry(PROCESS_TOOL_META, tr.kind))
|
|
202
227
|
continue;
|
|
203
228
|
const p = tr;
|
|
@@ -224,6 +249,19 @@ function variableRefusal(who, step, tool, name, arg) {
|
|
|
224
249
|
+ `nothing, and the model would fill the argument. Give it a fixed \`value\` or a \`prompt\`, or attach the `
|
|
225
250
|
+ `tool to an \`inlineAgent()\`.`, `${name}: { type: '${String(arg.type)}', value: … }`);
|
|
226
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* FLOW_AGENT_BUILTIN_TASK_VARIABLE: a built-in's task Variable on an agent whose
|
|
254
|
+
* input plan compile does not extend, as {@link variableRefusal} is for a
|
|
255
|
+
* process tool argument's. Only a single reference reaches here: one that is
|
|
256
|
+
* not is FLOW_AGENT_BUILTIN_COMPOSITE_REF first.
|
|
257
|
+
*/
|
|
258
|
+
function taskVariableRefusal(who, where, query, render) {
|
|
259
|
+
if (builtinToolQueryRef(query, render) === undefined)
|
|
260
|
+
return undefined;
|
|
261
|
+
return new CompileRefusal('FLOW_AGENT_BUILTIN_TASK_VARIABLE', `${where} takes its task from a \`variable\`. Compile binds a task's Variable as an agent input only on an `
|
|
262
|
+
+ `inline agent; on a ${who.toLowerCase()} it would bind nothing, and the task would never reach the tool. `
|
|
263
|
+
+ `Give it a fixed \`value\` or a \`prompt\`, or attach the tool to an \`inlineAgent()\`.`, `query: { value: … }`);
|
|
264
|
+
}
|
|
227
265
|
/**
|
|
228
266
|
* The resources an agent attaches — a node per context index, tool and
|
|
229
267
|
* escalation on the agent's `context`, `tool` and `escalation` handles, and the
|
|
@@ -360,7 +398,17 @@ export function attachAgentResources(s, ctx, source, who, toolVariables = new Ma
|
|
|
360
398
|
if (tr.description !== undefined)
|
|
361
399
|
extraInputs.description = tr.description;
|
|
362
400
|
if ('query' in extraInputs && tr.query !== undefined) {
|
|
363
|
-
extraInputs.query =
|
|
401
|
+
extraInputs.query = renderBuiltinToolQuery(tr.query, render);
|
|
402
|
+
}
|
|
403
|
+
// batchtransform's columns and grounding, as the canvas's form writes them:
|
|
404
|
+
// the rows as given, and the select's lowercase value (the resource
|
|
405
|
+
// capitalizes it). Their rules are `check`'s, as the canvas's are its form's,
|
|
406
|
+
// except the two `toolArguments` holds (`builtinToolSettingRefusal`).
|
|
407
|
+
if ('outputColumns' in extraInputs && tr.outputColumns !== undefined) {
|
|
408
|
+
extraInputs.outputColumns = jsonClone(tr.outputColumns);
|
|
409
|
+
}
|
|
410
|
+
if ('webSearchGrounding' in extraInputs && tr.webSearchGrounding !== undefined) {
|
|
411
|
+
extraInputs.webSearchGrounding = { value: tr.webSearchGrounding };
|
|
364
412
|
}
|
|
365
413
|
if ('fileExtension' in extraInputs && tr.fileExtension !== undefined) {
|
|
366
414
|
extraInputs.fileExtension = { value: tr.fileExtension };
|
|
@@ -533,7 +581,7 @@ export function attachAgentResources(s, ctx, source, who, toolVariables = new Ma
|
|
|
533
581
|
const toolResource = connectorTool
|
|
534
582
|
? connectorToolResourceJson(connectorTool, toolResourceId)
|
|
535
583
|
: tr.kind === 'builtin'
|
|
536
|
-
? builtinToolResourceJson(tr.tool, label, toolInputs, { id: toolResourceId })
|
|
584
|
+
? builtinToolResourceJson(tr.tool, label, toolInputs, { id: toolResourceId, canvasNodeId: tid })
|
|
537
585
|
: tr.kind === 'httpRequest'
|
|
538
586
|
? httpRequestToolResourceJson(label, toolInputs, { id: toolResourceId, canvasNodeId: tid })
|
|
539
587
|
: toolResourceJson(tr, { id: toolResourceId, variables: toolVariables.get(tr) });
|
|
@@ -15,7 +15,7 @@ import { agentInputPlan, agentSidecarInputs, conversationalAgentJson, voiceAgent
|
|
|
15
15
|
import { Expr, toExpr } from '../../../core/expr.js';
|
|
16
16
|
import { wireExprBody } from '../../../core/wire-expr.js';
|
|
17
17
|
import { checkAgentResources, checkConversationalAgent, checkInlineAgent, checkInlineAgentRead, checkVoice } from './check.js';
|
|
18
|
-
import { INLINE_AGENT_DEFAULT_VERSION, INLINE_AGENT_VERSIONS, attachAgentResources,
|
|
18
|
+
import { INLINE_AGENT_DEFAULT_VERSION, INLINE_AGENT_VERSIONS, attachAgentResources, toolArguments, serializeInlineAgent, } from './inline-agent.js';
|
|
19
19
|
import { liftAgentResources, liftInlineAgent, printInlineAgent } from './inline-agent-lift.js';
|
|
20
20
|
import { INLINE_AGENT } from './resources.js';
|
|
21
21
|
const CREATE_OUTGOING_CALL = 'uipath.conversational.voice.create-outgoing-call';
|
|
@@ -127,10 +127,10 @@ function serializeVoiceAgent(s, ctx) {
|
|
|
127
127
|
* resource nodes and `resource.json` files, under this agent's `source` (#1670).
|
|
128
128
|
*/
|
|
129
129
|
function shellResources(s, ctx, source, who) {
|
|
130
|
-
// A process tool argument compile cannot write, a Variable included,
|
|
131
|
-
// until the resources are judged, and
|
|
132
|
-
// `check` drops, as on the inline agent.
|
|
133
|
-
const { toolArgument } =
|
|
130
|
+
// A process tool argument compile cannot write, a Variable included, or a
|
|
131
|
+
// built-in task it cannot write, is held until the resources are judged, and
|
|
132
|
+
// thrown before LIBRARY_REQUIRED, which `check` drops, as on the inline agent.
|
|
133
|
+
const { toolArgument } = toolArguments(s, ctx.step, who, (v) => ctx.render(v), false);
|
|
134
134
|
const { attach, libraryRequired } = attachAgentResources(s, ctx, source, who);
|
|
135
135
|
if (toolArgument)
|
|
136
136
|
throw toolArgument;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An agent resource's `resource.json`, as decompile reads it beside the `.flow`:
|
|
3
|
+
* `<agent source>/resources/<dir>/resource.json`. Shared by the context index
|
|
4
|
+
* and process tool lifts, which name the directory by the node's
|
|
5
|
+
* `inputs.source`, and the built-in tool lift, which falls back to `inputs.id`
|
|
6
|
+
* (`builtinResourceDirectory`, core/agent-resource-identity.ts, shared with
|
|
7
|
+
* merge's resource pairing).
|
|
8
|
+
*/
|
|
9
|
+
import type { FlowDeserializeContext } from '../../../flow-node-type.js';
|
|
10
|
+
/** The part of a `.flow` node the sidecar lookup reads. */
|
|
11
|
+
interface ResourceNode {
|
|
12
|
+
id: string;
|
|
13
|
+
inputs?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The sidecar `<agent source>/resources/<dir>/resource.json` of a resource on
|
|
17
|
+
* `agent`, parsed; `undefined` when the agent has no source, `dir` is undefined
|
|
18
|
+
* or empty, the file is not beside the `.flow`, or (with a warning that
|
|
19
|
+
* `fallback` completes) it is not a JSON object.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resourceSidecar(agent: ResourceNode, dir: string | undefined, ctx: FlowDeserializeContext, what: string, fallback: string): Record<string, unknown> | undefined;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sidecar `<agent source>/resources/<dir>/resource.json` of a resource on
|
|
3
|
+
* `agent`, parsed; `undefined` when the agent has no source, `dir` is undefined
|
|
4
|
+
* or empty, the file is not beside the `.flow`, or (with a warning that
|
|
5
|
+
* `fallback` completes) it is not a JSON object.
|
|
6
|
+
*/
|
|
7
|
+
export function resourceSidecar(agent, dir, ctx, what, fallback) {
|
|
8
|
+
const agentSource = ctx.sourceText(agent.inputs?.source);
|
|
9
|
+
if (!agentSource || !dir)
|
|
10
|
+
return undefined;
|
|
11
|
+
const path = `${agentSource}/resources/${dir}/resource.json`;
|
|
12
|
+
const raw = ctx.sidecar(path);
|
|
13
|
+
if (raw === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
try {
|
|
16
|
+
const json = JSON.parse(raw);
|
|
17
|
+
if (json && typeof json === 'object' && !Array.isArray(json))
|
|
18
|
+
return json;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Reported below with the non-object case.
|
|
22
|
+
}
|
|
23
|
+
ctx.warn(`${what}: ${path} is not valid JSON, so ${fallback}.`);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|