@uipath/maestro-builder-sdk 6.89.1 → 6.90.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 +24 -23
- package/dist/api-members.md +49 -49
- package/dist/case/check-cli.js +4 -114
- package/dist/case/check.d.ts +0 -7
- package/dist/case/check.js +0 -5
- package/dist/cli/commands/case.js +0 -7
- package/dist/core/actions.d.ts +35 -2
- package/dist/core/agent-sidecar.d.ts +28 -2
- package/dist/core/agent-sidecar.js +29 -8
- package/dist/core/expr.d.ts +19 -0
- package/dist/core/expr.js +25 -0
- package/dist/core/refusals.d.ts +6 -1
- package/dist/core/refusals.js +6 -3
- package/dist/core/tool-argument.d.ts +105 -0
- package/dist/core/tool-argument.js +207 -0
- package/dist/decompile.js +6 -0
- package/dist/flow-node-type.d.ts +7 -0
- package/dist/nodes/agent/flow/check.d.ts +2 -9
- package/dist/nodes/agent/flow/check.js +104 -8
- package/dist/nodes/agent/flow/inline-agent-lift.d.ts +22 -3
- package/dist/nodes/agent/flow/inline-agent-lift.js +333 -56
- package/dist/nodes/agent/flow/inline-agent.d.ts +22 -1
- package/dist/nodes/agent/flow/inline-agent.js +60 -4
- package/dist/nodes/agent/flow/node-type.js +9 -3
- package/dist/nodes/agent/flow/resources.d.ts +10 -2
- package/dist/nodes/agent/flow/resources.js +32 -6
- package/package.json +2 -2
- package/dist/case/registry-resolved.d.ts +0 -121
- package/dist/case/registry-resolved.js +0 -155
|
@@ -9,20 +9,23 @@
|
|
|
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
|
-
* the only expressions, kept as `Expr`s
|
|
12
|
+
* reading them raises still go through the context. The agent's own inputs and
|
|
13
|
+
* a process tool argument's Variable are the only expressions, kept as `Expr`s
|
|
14
|
+
* for the printer.
|
|
14
15
|
*/
|
|
15
|
-
import { agentSidecarInputs } from '../../../core/agent-sidecar.js';
|
|
16
|
+
import { agentInputRef, agentSidecarInputs } from '../../../core/agent-sidecar.js';
|
|
16
17
|
import { derivedContextSource, derivedEscalationSource, derivedResourceNodeId, derivedToolSource, } from '../../../core/agent-resource-identity.js';
|
|
17
18
|
import { CONTEXT_INDEX_DEFAULTS, CONTEXT_INDEX_DEFAULT_FILE_EXTENSION, contextIndexSlug, parseContextIndexType, } from '../../../core/context-index.js';
|
|
18
|
-
import { Expr } from '../../../core/expr.js';
|
|
19
|
+
import { Expr, flatNameReference } from '../../../core/expr.js';
|
|
19
20
|
import { formFieldRowLoss, formFieldRowLossMessage, formFieldSettingsSource, liftFormFieldSettings, sourceFormFieldType, } from '../../../core/form-field-type.js';
|
|
20
21
|
import { ownEntry } from '../../../core/own-entry.js';
|
|
22
|
+
import { isInlineAgentFieldType, jsonPathSegments } from '../../../core/tool-argument.js';
|
|
21
23
|
import { tsKey as key, tsLiteral, tsNumber, tsObject as objLit, tsOptions as opts, tsText } from '../../../core/ts-literal.js';
|
|
22
24
|
import { wireExprBody } from '../../../core/wire-expr.js';
|
|
23
25
|
import { BUILTIN_TOOL_DEFS, escalationDef, voiceAgentRevision } from './resources.js';
|
|
24
26
|
/** Where the agent's own `inputs` go in the option list: the printer writes them, as expressions. */
|
|
25
27
|
const INPUT_ROWS = Symbol('inputs');
|
|
28
|
+
const isObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
26
29
|
/** The per-instance resource tool kinds (process / api / flow / maestro / agent / function), by node-type prefix. */
|
|
27
30
|
const PROCESS_NS = [
|
|
28
31
|
['uipath.agent.resource.tool.processorchestration.', 'maestro'],
|
|
@@ -95,37 +98,6 @@ function clientsideSchema(v, fields, whole) {
|
|
|
95
98
|
}
|
|
96
99
|
return [[whole, dataSource(v)]];
|
|
97
100
|
}
|
|
98
|
-
const FIELD_TYPES = new Set(['string', 'number', 'integer', 'boolean', 'object', 'array']);
|
|
99
|
-
/**
|
|
100
|
-
* A tool's JSON schema as a `{ name: type }` map (`ProcessToolRef.inputs` /
|
|
101
|
-
* `returns`), or nothing for an empty one. The map carries only each
|
|
102
|
-
* property's `type`, so anything else the schema says (a property's
|
|
103
|
-
* `description` or `items`, a type it cannot name) is reported as lost.
|
|
104
|
-
* `required` is not: compile marks every input required.
|
|
105
|
-
*/
|
|
106
|
-
function fieldTypes(v, what, ctx) {
|
|
107
|
-
if (v === undefined || v === null || typeof v !== 'object' || Array.isArray(v))
|
|
108
|
-
return undefined;
|
|
109
|
-
const s = v;
|
|
110
|
-
const props = s.properties !== null && typeof s.properties === 'object' && !Array.isArray(s.properties)
|
|
111
|
-
? s.properties : {};
|
|
112
|
-
const lost = Object.keys(s).filter((k) => k !== 'type' && k !== 'properties' && k !== 'required');
|
|
113
|
-
const rows = [];
|
|
114
|
-
for (const [name, p] of Object.entries(props)) {
|
|
115
|
-
const type = p !== null && typeof p === 'object' ? p.type : undefined;
|
|
116
|
-
if (typeof type !== 'string' || !FIELD_TYPES.has(type)) {
|
|
117
|
-
lost.push(`${name} (type ${JSON.stringify(type)})`);
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
rows.push([name, tsLiteral(type)]);
|
|
121
|
-
for (const k of Object.keys(p))
|
|
122
|
-
if (k !== 'type')
|
|
123
|
-
lost.push(`${name}.${k}`);
|
|
124
|
-
}
|
|
125
|
-
if (lost.length > 0)
|
|
126
|
-
ctx.lossy(`${what}: the source keeps only each property's type, so ${lost.join(', ')} ${lost.length === 1 ? 'is' : 'are'} dropped.`);
|
|
127
|
-
return rows.length ? objLit(rows) : undefined;
|
|
128
|
-
}
|
|
129
101
|
/** Plain JSON data as source, in the `{ k: v }` / `[a, b]` spelling (a form field's `options`, `rules`, `defaultValue`). */
|
|
130
102
|
function dataSource(v) {
|
|
131
103
|
if (Array.isArray(v))
|
|
@@ -159,7 +131,7 @@ function dataSource(v) {
|
|
|
159
131
|
*/
|
|
160
132
|
function contextIndexIdentity(agent, c, rPlain, ctx) {
|
|
161
133
|
const fromType = parseContextIndexType(c.type);
|
|
162
|
-
const sidecar = resourceSidecar(agent, c, ctx,
|
|
134
|
+
const sidecar = resourceSidecar(agent, c, ctx, `context index "${c.id}"`, 'the resource decompiles from the node');
|
|
163
135
|
const sidecarText = (k) => typeof sidecar?.[k] === 'string' && sidecar[k] !== '' ? sidecar[k] : undefined;
|
|
164
136
|
const label = typeof c.display?.label === 'string' && c.display.label !== '' ? c.display.label : undefined;
|
|
165
137
|
// The canvas can set both sidecar `name` and `indexName`, and they can differ.
|
|
@@ -316,12 +288,13 @@ function contextIndexSettings(agent, c, sidecar, ctx) {
|
|
|
316
288
|
];
|
|
317
289
|
}
|
|
318
290
|
/**
|
|
319
|
-
*
|
|
320
|
-
* not beside the `.flow`, or (with a warning
|
|
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.
|
|
321
294
|
*/
|
|
322
|
-
function resourceSidecar(agent,
|
|
295
|
+
function resourceSidecar(agent, r, ctx, what, fallback) {
|
|
323
296
|
const agentSource = ctx.sourceText(agent.inputs?.source);
|
|
324
|
-
const resourceSource = ctx.sourceText(
|
|
297
|
+
const resourceSource = ctx.sourceText(r.inputs?.source);
|
|
325
298
|
if (!agentSource || !resourceSource)
|
|
326
299
|
return undefined;
|
|
327
300
|
const path = `${agentSource}/resources/${resourceSource}/resource.json`;
|
|
@@ -336,9 +309,284 @@ function resourceSidecar(agent, c, ctx, what) {
|
|
|
336
309
|
catch {
|
|
337
310
|
// Reported below with the non-object case.
|
|
338
311
|
}
|
|
339
|
-
ctx.warn(`${what}
|
|
312
|
+
ctx.warn(`${what}: ${path} is not valid JSON, so ${fallback}.`);
|
|
340
313
|
return undefined;
|
|
341
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* The keys of a tool's schema property that its flat type may drop unreported:
|
|
317
|
+
* the type it keeps, the title and the description (an argument's Prompt,
|
|
318
|
+
* docs/INLINE_AGENT_TOOL_ARGUMENTS_DESIGN.md), and the Int32 bounds Orchestrator
|
|
319
|
+
* copies onto a published contract (docs/AGENT_SDK_DESIGN.md, decision 11).
|
|
320
|
+
*/
|
|
321
|
+
const TOOL_FIELD_KEYS = new Set(['type', 'title', 'description', 'minimum', 'maximum']);
|
|
322
|
+
/**
|
|
323
|
+
* A process-family tool's `inputs` and `returns`, as source: the inverse of the
|
|
324
|
+
* `inputSchema` / `outputSchema` that `toolResourceJson` and `processToolDef`
|
|
325
|
+
* (resources.ts) write from them.
|
|
326
|
+
*
|
|
327
|
+
* Read from the tool's `resource.json` first, as {@link contextIndexSettings}
|
|
328
|
+
* reads a context's: it is the schema the runtime hands the model, and a tool
|
|
329
|
+
* the canvas or the CLI placed carries only `inputs.source` on its node. The
|
|
330
|
+
* definition's `inputDefaults` (compile writes the same schemas there) answers
|
|
331
|
+
* when there is no sidecar. Before either was read, a recompile wrote both
|
|
332
|
+
* schemas empty without a word.
|
|
333
|
+
*
|
|
334
|
+
* A property whose type the source cannot name (none, a type list, a type
|
|
335
|
+
* outside `InlineAgentFieldType`) is reported, a warning or an error under
|
|
336
|
+
* `--strict`, and left out. One whose type it can name but that carries more
|
|
337
|
+
* than {@link TOOL_FIELD_KEYS} (`items`, nested `properties`, `enum`, `format`,
|
|
338
|
+
* …) is reported the same way and kept as its bare type: that structure is
|
|
339
|
+
* part of the contract the model builds its call from.
|
|
340
|
+
*
|
|
341
|
+
* Each argument's source comes back with it, read as the canvas loads the tool:
|
|
342
|
+
*
|
|
343
|
+
* - from the NODE when it carries the canvas's mode-tagged argument inputs
|
|
344
|
+
* (the self-contained form, `services.agent-storage.self-contained-flow`,
|
|
345
|
+
* on everywhere), as an embedded agent node's prompts win over its
|
|
346
|
+
* `agent.json`. `resource.json` is then a derived copy: where it disagrees,
|
|
347
|
+
* the node wins and the difference is reported ({@link nodeArgument});
|
|
348
|
+
* - else from `resource.json` ({@link resourceArgument}). The definition
|
|
349
|
+
* declares types only.
|
|
350
|
+
*
|
|
351
|
+
* A Variable's reference is an `Expr`, so `inputs` is then printed once the
|
|
352
|
+
* print context is known, and `variables` lists the agent inputs the tool
|
|
353
|
+
* binds, in argument order.
|
|
354
|
+
*/
|
|
355
|
+
function processToolFields(t, where, sidecar, defaults, agentInputs, ctx) {
|
|
356
|
+
const fields = (schemaKey, option) => {
|
|
357
|
+
const schema = isObject(sidecar?.[schemaKey]) ? sidecar[schemaKey] : defaults?.[schemaKey];
|
|
358
|
+
const props = isObject(schema) && isObject(schema.properties) ? schema.properties : {};
|
|
359
|
+
const rows = [];
|
|
360
|
+
for (const [name, p] of Object.entries(props)) {
|
|
361
|
+
const type = isObject(p) ? p.type : undefined;
|
|
362
|
+
if (typeof type === 'string' && isInlineAgentFieldType(type)) {
|
|
363
|
+
rows.push([name, type, p]);
|
|
364
|
+
const dropped = Object.keys(p).filter((k) => !TOOL_FIELD_KEYS.has(k));
|
|
365
|
+
if (dropped.length > 0) {
|
|
366
|
+
ctx.lossy(`${where}: its ${schemaKey} property ${JSON.stringify(name)} carries `
|
|
367
|
+
+ `${dropped.map((k) => JSON.stringify(k)).join(', ')}, which \`${option}\` cannot express, so compile `
|
|
368
|
+
+ `writes it as a bare ${JSON.stringify(type)}. Edit the tool in the canvas after merging, or keep the original resource.json.`);
|
|
369
|
+
}
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
const what = type === undefined ? 'has no type' : `has type ${JSON.stringify(type)}`;
|
|
373
|
+
ctx.lossy(`${where}: its ${schemaKey} property ${JSON.stringify(name)} ${what}, which \`${option}\` cannot `
|
|
374
|
+
+ `express, so compile leaves it out. Edit the tool in the canvas after merging, or keep the original resource.json.`);
|
|
375
|
+
}
|
|
376
|
+
return { names: Object.keys(props), rows };
|
|
377
|
+
};
|
|
378
|
+
const returns = fields('outputSchema', 'returns').rows;
|
|
379
|
+
const inputs = fields('inputSchema', 'inputs');
|
|
380
|
+
// `argumentProperties` by the argument each key names (`$['order']['total']`
|
|
381
|
+
// is `order.total`, as `jsonPathKey` writes it).
|
|
382
|
+
const lossy = (what, then = 'leaves the argument to the model') => ctx.lossy(`${where}: ${what}, which `
|
|
383
|
+
+ `\`inputs\` cannot express, so compile ${then}. Edit the tool in the canvas after merging, or keep the original resource.json.`);
|
|
384
|
+
const entries = new Map();
|
|
385
|
+
for (const [k, entry] of Object.entries(isObject(sidecar?.argumentProperties) ? sidecar.argumentProperties : {})) {
|
|
386
|
+
const name = jsonPathSegments(k)?.join('.');
|
|
387
|
+
if (name !== undefined && inputs.names.includes(name))
|
|
388
|
+
entries.set(name, entry);
|
|
389
|
+
else
|
|
390
|
+
lossy(`its argumentProperties key ${JSON.stringify(k)} names no argument of its inputSchema`, 'drops the entry');
|
|
391
|
+
}
|
|
392
|
+
const own = (t.inputs ?? {});
|
|
393
|
+
const selfContained = inputs.rows.some(([name]) => isModeTagged(ownEntry(own, name)));
|
|
394
|
+
const resolve = (path) => argumentInput(path, agentInputs, ctx);
|
|
395
|
+
const variables = [];
|
|
396
|
+
const rows = inputs.rows.map(([name, type, p]) => {
|
|
397
|
+
const arg = `its argument ${JSON.stringify(name)}`;
|
|
398
|
+
const fromFile = resourceArgument(arg, p, entries.get(name), resolve);
|
|
399
|
+
let read = fromFile;
|
|
400
|
+
const onNode = selfContained ? nodeArgument(arg, ownEntry(own, name)) : undefined;
|
|
401
|
+
if (onNode !== undefined) {
|
|
402
|
+
read = onNode;
|
|
403
|
+
// Only a sidecar the canvas derived from this node is checked against it.
|
|
404
|
+
if (sidecar !== undefined && !agrees(onNode.source, entries.get(name), fromFile.source)) {
|
|
405
|
+
lossy(`${arg} is ${describeSource(onNode.source)} on the node but ${describeSource(fromFile.source)} in its resource.json`, 'writes the node\'s, which is what the canvas loads');
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
for (const [what, then] of read.losses)
|
|
409
|
+
lossy(what, then);
|
|
410
|
+
if (read.source.kind === 'variable')
|
|
411
|
+
variables.push({ id: read.source.id, ref: read.source.ref });
|
|
412
|
+
return [name, argumentSource(type, read.source)];
|
|
413
|
+
});
|
|
414
|
+
const deferred = rows.some(([, v]) => typeof v === 'function');
|
|
415
|
+
return {
|
|
416
|
+
inputs: !rows.length ? undefined
|
|
417
|
+
: deferred ? (print) => objLit(rows.map(([k, v]) => [k, typeof v === 'function' ? v(print) : v]))
|
|
418
|
+
: objLit(rows),
|
|
419
|
+
returns: returns.length ? objLit(returns.map(([name, type]) => [name, tsLiteral(type)])) : undefined,
|
|
420
|
+
variables,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/** An argument source as a `ToolArgument`: `{ type, <source> }`, or the bare type. */
|
|
424
|
+
function argumentSource(type, source) {
|
|
425
|
+
const bare = tsLiteral(type);
|
|
426
|
+
if (source.kind === 'prompt')
|
|
427
|
+
return objLit([['type', bare], ['prompt', tsLiteral(source.text)]]);
|
|
428
|
+
if (source.kind === 'value')
|
|
429
|
+
return objLit([['type', bare], ['value', dataSource(source.value)]]);
|
|
430
|
+
if (source.kind === 'variable') {
|
|
431
|
+
const variable = new Expr(source.body);
|
|
432
|
+
return (print) => objLit([['type', bare], ['variable', print.value(variable)]]);
|
|
433
|
+
}
|
|
434
|
+
return bare;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Whether `resource.json` says what a self-contained node does: the source read
|
|
438
|
+
* from it is the node's, and for a Variable, its `argument` entry's path names
|
|
439
|
+
* the node reference's flat name, as the canvas writes it (resolved or not).
|
|
440
|
+
*/
|
|
441
|
+
function agrees(onNode, entry, fromFile) {
|
|
442
|
+
if (onNode.kind === 'variable' && isObject(entry) && entry.variant === 'argument' && typeof entry.argumentPath === 'string') {
|
|
443
|
+
return jsonPathSegments(entry.argumentPath)?.join('__') === onNode.ref.flatName;
|
|
444
|
+
}
|
|
445
|
+
const key = (source) => {
|
|
446
|
+
if (source.kind === 'variable')
|
|
447
|
+
return `variable:${source.ref.flatName}`;
|
|
448
|
+
if (source.kind === 'prompt')
|
|
449
|
+
return `prompt:${source.text}`;
|
|
450
|
+
if (source.kind === 'value')
|
|
451
|
+
return `value:${JSON.stringify(source.value)}`;
|
|
452
|
+
return source.kind === 'unreadable' ? `unreadable:${source.what}` : 'bare';
|
|
453
|
+
};
|
|
454
|
+
return key(onNode) === key(fromFile);
|
|
455
|
+
}
|
|
456
|
+
/** An argument source in a warning. */
|
|
457
|
+
function describeSource(source) {
|
|
458
|
+
if (source.kind === 'prompt')
|
|
459
|
+
return `the prompt ${JSON.stringify(source.text)}`;
|
|
460
|
+
if (source.kind === 'value')
|
|
461
|
+
return `the fixed value ${JSON.stringify(source.value)}`;
|
|
462
|
+
if (source.kind === 'variable')
|
|
463
|
+
return `bound to ${source.body}`;
|
|
464
|
+
return source.kind === 'unreadable' ? 'an entry `inputs` cannot express' : 'left to the model';
|
|
465
|
+
}
|
|
466
|
+
/** Whether a node input is one of the canvas's mode-tagged argument objects (`{ mode, promptValue, … }`). */
|
|
467
|
+
function isModeTagged(raw) {
|
|
468
|
+
return isObject(raw) && typeof raw.mode === 'string';
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* One argument's source from a self-contained tool node, in the canvas's own
|
|
472
|
+
* shape (docs/INLINE_AGENT_TOOL_ARGUMENTS_DESIGN.md, "On the node"):
|
|
473
|
+
*
|
|
474
|
+
* - `prompt` with a `promptValue` → Prompt;
|
|
475
|
+
* - `text-builder` with a `textValue` → Fixed value: the canvas's text, a
|
|
476
|
+
* string even for a number or boolean argument (D2);
|
|
477
|
+
* - `variable` with an `argumentPath` that is one `$vars.` / `$metadata.`
|
|
478
|
+
* reference → Variable, that reference;
|
|
479
|
+
* - empty (`''`, missing, or a mode with no value) → the model fills it, as
|
|
480
|
+
* the canvas drops every empty source on save.
|
|
481
|
+
*
|
|
482
|
+
* `undefined` for any other value (an object editor's raw value), which
|
|
483
|
+
* `resource.json` answers. An unknown mode or a `variable` that is not one
|
|
484
|
+
* reference is unreadable.
|
|
485
|
+
*/
|
|
486
|
+
function nodeArgument(arg, raw) {
|
|
487
|
+
if (raw === undefined || raw === '')
|
|
488
|
+
return { source: { kind: 'bare' }, losses: [] };
|
|
489
|
+
if (!isModeTagged(raw))
|
|
490
|
+
return undefined;
|
|
491
|
+
const text = (k) => (typeof raw[k] === 'string' ? raw[k] : '');
|
|
492
|
+
if (raw.mode === 'prompt') {
|
|
493
|
+
return { source: text('promptValue').trim() === '' ? { kind: 'bare' } : { kind: 'prompt', text: text('promptValue') }, losses: [] };
|
|
494
|
+
}
|
|
495
|
+
if (raw.mode === 'text-builder') {
|
|
496
|
+
return { source: text('textValue') === '' ? { kind: 'bare' } : { kind: 'value', value: text('textValue') }, losses: [] };
|
|
497
|
+
}
|
|
498
|
+
const unreadable = (what) => ({ source: { kind: 'unreadable', what }, losses: [[what]] });
|
|
499
|
+
if (raw.mode === 'variable') {
|
|
500
|
+
const path = text('argumentPath');
|
|
501
|
+
if (path === '')
|
|
502
|
+
return { source: { kind: 'bare' }, losses: [] };
|
|
503
|
+
const ref = agentInputRef(`=js:${path}`);
|
|
504
|
+
return ref === undefined
|
|
505
|
+
? unreadable(`${arg} is bound to ${JSON.stringify(path)} on the node, which is not one $vars or $metadata reference`)
|
|
506
|
+
: { source: { kind: 'variable', body: path, id: ref.flatName, ref }, losses: [] };
|
|
507
|
+
}
|
|
508
|
+
return unreadable(`${arg} has mode ${JSON.stringify(raw.mode)} on the node`);
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* One argument's source from `resource.json`, the inverse of what
|
|
512
|
+
* `toolResourceJson` writes for each `ToolArgument`
|
|
513
|
+
* (docs/INLINE_AGENT_TOOL_ARGUMENTS_DESIGN.md, "Decompile"), from its
|
|
514
|
+
* `argumentProperties` `entry` and its schema property `p`:
|
|
515
|
+
*
|
|
516
|
+
* - `static` → Fixed value, in its JSON type;
|
|
517
|
+
* - `argument` → Variable: the reference its path names, see {@link argumentInput};
|
|
518
|
+
* - no entry, and a description → Prompt: compile writes a description only
|
|
519
|
+
* from a prompt, so lifting one keeps it;
|
|
520
|
+
* - no entry, no description → the bare type.
|
|
521
|
+
*
|
|
522
|
+
* An entry wins over a description, as the canvas writes none beside a Fixed
|
|
523
|
+
* value or a Variable; the description is reported, since compile drops it. Every
|
|
524
|
+
* entry `inputs` cannot express (`textBuilder`, `dynamic`, `objectBuilder`,
|
|
525
|
+
* `arrayBuilder`, which Agent Builder writes; an unknown variant; a path naming
|
|
526
|
+
* no reference) is unreadable. `isSensitive: true` is reported and the source
|
|
527
|
+
* kept: compile writes `false`.
|
|
528
|
+
*/
|
|
529
|
+
function resourceArgument(arg, p, entry, resolve) {
|
|
530
|
+
const description = typeof p.description === 'string' && p.description !== '' ? p.description : undefined;
|
|
531
|
+
if (entry === undefined) {
|
|
532
|
+
if (description === undefined)
|
|
533
|
+
return { source: { kind: 'bare' }, losses: [] };
|
|
534
|
+
if (description.trim() !== '')
|
|
535
|
+
return { source: { kind: 'prompt', text: description }, losses: [] };
|
|
536
|
+
return { source: { kind: 'bare' }, losses: [[`${arg} has a blank description`, 'drops it']] };
|
|
537
|
+
}
|
|
538
|
+
const losses = [];
|
|
539
|
+
if (description !== undefined) {
|
|
540
|
+
losses.push([`${arg} has a description beside its argumentProperties entry`, 'keeps the entry and drops the description']);
|
|
541
|
+
}
|
|
542
|
+
const e = isObject(entry) ? entry : {};
|
|
543
|
+
if (e.isSensitive === true)
|
|
544
|
+
losses.push([`${arg} is marked isSensitive`, 'writes it `false`']);
|
|
545
|
+
const unreadable = (what) => ({ source: { kind: 'unreadable', what }, losses: [...losses, [what]] });
|
|
546
|
+
if (e.variant === 'static' && 'value' in e)
|
|
547
|
+
return { source: { kind: 'value', value: e.value }, losses };
|
|
548
|
+
if (e.variant === 'argument' && typeof e.argumentPath === 'string') {
|
|
549
|
+
const source = resolve(e.argumentPath);
|
|
550
|
+
return source.kind === 'variable' ? { source, losses } : unreadable(`${arg} ${source.what}`);
|
|
551
|
+
}
|
|
552
|
+
return unreadable(`${arg} has an argumentProperties entry of variant ${JSON.stringify(e.variant)}`);
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* The reference an `argument` entry's path names. The path names one of the
|
|
556
|
+
* agent's inputs by its flat name (`$['node1__output__y']`, or the nested
|
|
557
|
+
* encoding's `$['node1']['output']['y']`):
|
|
558
|
+
*
|
|
559
|
+
* 1. the agent node's `agentInputVariables` entry of that name, whose binding is
|
|
560
|
+
* printed as an agent input's is;
|
|
561
|
+
* 2. else the flat name, decoded (`flatNameReference`). A self-contained canvas
|
|
562
|
+
* file writes `agentInputVariables: []` (the canvas derives the inputs
|
|
563
|
+
* only for the sidecar), so the name is all there is. A name whose id holds
|
|
564
|
+
* `__` decodes ambiguously, so the reference counts only when its root
|
|
565
|
+
* names a node or a variable of the flow; `$metadata` always does.
|
|
566
|
+
*
|
|
567
|
+
* `unreadable`, its `what` completing "its argument …", for anything else.
|
|
568
|
+
*/
|
|
569
|
+
function argumentInput(path, agentInputs, ctx) {
|
|
570
|
+
const unreadable = (what) => ({ kind: 'unreadable', what });
|
|
571
|
+
const segments = jsonPathSegments(path);
|
|
572
|
+
const flat = segments?.join('__');
|
|
573
|
+
const input = segments === undefined ? undefined
|
|
574
|
+
: agentInputs.find((v) => v.flatName === segments.join('.')) ?? agentInputs.find((v) => v.flatName === flat);
|
|
575
|
+
if (input !== undefined) {
|
|
576
|
+
// What compile renders the printed variable back to, and so the input it binds.
|
|
577
|
+
const body = wireExprBody(input.binding);
|
|
578
|
+
const ref = agentInputRef(`=js:${body}`);
|
|
579
|
+
return ref === undefined
|
|
580
|
+
? unreadable(`is bound to the agent input "${input.flatName}", whose binding ${JSON.stringify(input.binding)} is not a single reference`)
|
|
581
|
+
: { kind: 'variable', body, id: input.flatName, ref };
|
|
582
|
+
}
|
|
583
|
+
const body = flat === undefined ? undefined : flatNameReference(flat);
|
|
584
|
+
const root = body?.startsWith('$vars.') ? body.slice('$vars.'.length).split(/[.[]/)[0] : undefined;
|
|
585
|
+
const ref = body !== undefined && (root === undefined || ctx.declaresRoot(root)) ? agentInputRef(`=js:${body}`) : undefined;
|
|
586
|
+
return ref === undefined || body === undefined || flat === undefined
|
|
587
|
+
? unreadable(`is bound to ${JSON.stringify(path)}, which names no input of the agent`)
|
|
588
|
+
: { kind: 'variable', body, id: flat, ref };
|
|
589
|
+
}
|
|
342
590
|
/**
|
|
343
591
|
* An AGENT and its attached resources — the inline autonomous agent, the
|
|
344
592
|
* conversational agent, and the voice agent.
|
|
@@ -394,18 +642,35 @@ export function liftInlineAgent(node, ctx) {
|
|
|
394
642
|
const raw = plain(v);
|
|
395
643
|
return raw === undefined ? undefined : tsLiteral(unrender(raw));
|
|
396
644
|
};
|
|
397
|
-
|
|
398
|
-
|
|
645
|
+
// The inputs in the file's own order, not the length-sorted one.
|
|
646
|
+
const fileRefs = refs
|
|
399
647
|
.slice()
|
|
400
|
-
.sort((a, b) => vars.findIndex((v) => v.id === a.flatName) - vars.findIndex((v) => v.id === b.flatName))
|
|
401
|
-
.map((r) => {
|
|
402
|
-
return [r.flatName, new Expr(wireExprBody(r.binding))];
|
|
403
|
-
});
|
|
648
|
+
.sort((a, b) => vars.findIndex((v) => v.id === a.flatName) - vars.findIndex((v) => v.id === b.flatName));
|
|
404
649
|
const outVars = (Array.isArray(i.agentOutputVariables) ? i.agentOutputVariables : []);
|
|
405
650
|
const returns = outVars.length
|
|
406
651
|
? objLit(outVars.map((v) => [String(v.id ?? ''), tsLiteral(String(v.type ?? 'string'))]))
|
|
407
652
|
: undefined;
|
|
408
|
-
const resources = liftAgentResources(node, ctx, true);
|
|
653
|
+
const resources = liftAgentResources(node, ctx, true, fileRefs);
|
|
654
|
+
const toolVariables = resources.toolVariables;
|
|
655
|
+
// An input only tools' Variables bind (no prompt placeholder reads it) is left
|
|
656
|
+
// out of `inputs`: each tool's `variable` binds it again, and compile appends
|
|
657
|
+
// tool references after the declared inputs (`agentInputPlan`). Only when
|
|
658
|
+
// that plans the same inputs, in the same order, as printing all of them
|
|
659
|
+
// would; otherwise every input is printed, and a tool reference one of them
|
|
660
|
+
// binds is still one input, `refs` being deduped by flat name.
|
|
661
|
+
const placeholders = new Set([i.systemPrompt, i.userPrompt].flatMap((p) => {
|
|
662
|
+
const raw = plain(p);
|
|
663
|
+
return raw === undefined ? [] : [...unrender(raw).matchAll(/\{\{\s*input\.([A-Za-z_$][A-Za-z0-9_$]*)\s*\}\}/g)].map((m) => m[1]);
|
|
664
|
+
}));
|
|
665
|
+
const toolOnly = new Set(toolVariables.map((v) => v.id).filter((id) => !placeholders.has(id)));
|
|
666
|
+
/** The flat names compile plans from `declared` and the tools' references, deduped as `agentInputPlan` does. */
|
|
667
|
+
const planned = (declared) => JSON.stringify([...new Set([
|
|
668
|
+
...declared.flatMap((r) => agentInputRef(`=js:${wireExprBody(r.binding)}`)?.flatName ?? []),
|
|
669
|
+
...toolVariables.map((v) => v.ref.flatName),
|
|
670
|
+
])]);
|
|
671
|
+
const kept = fileRefs.filter((r) => !toolOnly.has(r.flatName));
|
|
672
|
+
const declared = kept.length < fileRefs.length && planned(kept) === planned(fileRefs) ? kept : fileRefs;
|
|
673
|
+
const inputRows = declared.map((r) => [r.flatName, new Expr(wireExprBody(r.binding))]);
|
|
409
674
|
const guardrails = Array.isArray(i.guardrails) && i.guardrails.length > 0
|
|
410
675
|
? JSON.stringify(i.guardrails)
|
|
411
676
|
: undefined;
|
|
@@ -436,8 +701,13 @@ export function liftInlineAgent(node, ctx) {
|
|
|
436
701
|
* the voice and conversational agents', which take the same three
|
|
437
702
|
* resources but no memory. With `withMemory` false a `memory` edge is left
|
|
438
703
|
* unclaimed, so decompile reports it as an edge the source cannot spell.
|
|
704
|
+
* `agentInputs` are the agent's inputs in the file's order, which a process
|
|
705
|
+
* tool's Variable argument resolves its `argumentPath` through;
|
|
706
|
+
* `toolVariables` are the inputs those Variables bind, in tool and argument
|
|
707
|
+
* order. A Variable's reference is an `Expr`, so `tools` is then printed once
|
|
708
|
+
* the print context is known.
|
|
439
709
|
*/
|
|
440
|
-
export function liftAgentResources(node, ctx, withMemory) {
|
|
710
|
+
export function liftAgentResources(node, ctx, withMemory, agentInputs = []) {
|
|
441
711
|
const num = (v) => {
|
|
442
712
|
const raw = ctx.plainValue(v);
|
|
443
713
|
return typeof raw === 'number' ? String(raw) : undefined;
|
|
@@ -495,6 +765,8 @@ export function liftAgentResources(node, ctx, withMemory) {
|
|
|
495
765
|
const raw = ctx.sourceText(rInputs(n)[k]);
|
|
496
766
|
return raw === undefined || raw === '' ? undefined : raw;
|
|
497
767
|
};
|
|
768
|
+
/** The agent inputs the process tools' Variables bind, in tool and argument order. */
|
|
769
|
+
const toolVariables = [];
|
|
498
770
|
const toolSrc = ctx.attached('tool', Infinity, liftable).map((t) => {
|
|
499
771
|
const ti = rInputs(t);
|
|
500
772
|
const type = t.type;
|
|
@@ -575,19 +847,21 @@ export function liftAgentResources(node, ctx, withMemory) {
|
|
|
575
847
|
// The tool's contract: compile writes `inputs` / `returns` as the
|
|
576
848
|
// definition's `inputDefaults.inputSchema` / `outputSchema` and the
|
|
577
849
|
// resource.json's, and `description` only into the resource.json.
|
|
578
|
-
const sidecar = resourceSidecar(node, t, ctx, `${ns[1]} tool`);
|
|
579
|
-
const defaults = (def?.inputDefaults ?? {});
|
|
580
850
|
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');
|
|
581
852
|
const description = typeof sidecar?.description === 'string' && sidecar.description !== '' ? sidecar.description : undefined;
|
|
582
|
-
|
|
853
|
+
const { inputs, returns, variables } = processToolFields(t, what, sidecar, def?.inputDefaults, agentInputs, ctx);
|
|
854
|
+
toolVariables.push(...variables);
|
|
855
|
+
const src = (inputsSrc) => toolOpts(t, { kind: 'process', name: '', folderPath: '', key }, [
|
|
583
856
|
['kind', tsLiteral(ns[1])],
|
|
584
857
|
['key', tsLiteral(key)],
|
|
585
858
|
['name', tsLiteral(bound('name') ?? rPlain(t, 'name') ?? '')],
|
|
586
859
|
['folderPath', tsLiteral(bound('folderPath') ?? '')],
|
|
587
860
|
['description', description !== undefined ? tsLiteral(description) : undefined],
|
|
588
|
-
['inputs',
|
|
589
|
-
['returns',
|
|
861
|
+
['inputs', inputsSrc],
|
|
862
|
+
['returns', returns],
|
|
590
863
|
]);
|
|
864
|
+
return typeof inputs === 'function' ? (print) => src(inputs(print)) : src(inputs);
|
|
591
865
|
}
|
|
592
866
|
// `liftableToolFor` admits no other type.
|
|
593
867
|
throw new Error(`internal SDK error: tool "${t.id}" of type ${type} has no lift.`);
|
|
@@ -676,7 +950,10 @@ export function liftAgentResources(node, ctx, withMemory) {
|
|
|
676
950
|
]);
|
|
677
951
|
})();
|
|
678
952
|
const list = (items) => (items.length ? `[${items.join(', ')}]` : undefined);
|
|
679
|
-
|
|
953
|
+
const tools = !toolSrc.length ? undefined
|
|
954
|
+
: toolSrc.every((x) => typeof x === 'string') ? list(toolSrc)
|
|
955
|
+
: (print) => `[${toolSrc.map((x) => (typeof x === 'function' ? x(print) : x)).join(', ')}]`;
|
|
956
|
+
return { context: list(contextSrc), tools, escalation: list(escalationSrc), memory: memorySrc, toolVariables };
|
|
680
957
|
}
|
|
681
958
|
export function printInlineAgent(spec, ctx) {
|
|
682
959
|
const { inputRows, options } = spec.inputs;
|
|
@@ -685,6 +962,6 @@ export function printInlineAgent(spec, ctx) {
|
|
|
685
962
|
: undefined;
|
|
686
963
|
return {
|
|
687
964
|
factory: 'inlineAgent',
|
|
688
|
-
options: options.map(([k, v]) => [k, v === INPUT_ROWS ? rows : v]),
|
|
965
|
+
options: options.map(([k, v]) => [k, v === INPUT_ROWS ? rows : typeof v === 'function' ? v(ctx) : v]),
|
|
689
966
|
};
|
|
690
967
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* definitions, bindings and files unchanged.
|
|
8
8
|
*/
|
|
9
9
|
import type { AgentResources, InlineAgentInputs } from './spec.js';
|
|
10
|
+
import { toolVariableRefs } from '../../../core/tool-argument.js';
|
|
10
11
|
import type { FlowNodeContribution, FlowSerializeContext } from '../../../flow-node-type.js';
|
|
11
12
|
import { CompileRefusal } from '../../../core/compile-refusal.js';
|
|
12
13
|
/** Every bundled version of the inline agent, oldest first; the newest is the default (#956). */
|
|
@@ -17,6 +18,22 @@ type Attached = NonNullable<FlowNodeContribution['attach']>[number];
|
|
|
17
18
|
export type AgentKindLabel = 'Inline agent' | 'Voice agent' | 'Conversational agent';
|
|
18
19
|
/** The inline agent's node, sidecar and resources. */
|
|
19
20
|
export declare function serializeInlineAgent(s: InlineAgentInputs, ctx: FlowSerializeContext): FlowNodeContribution;
|
|
21
|
+
/**
|
|
22
|
+
* Each process tool's arguments, judged before the agent's resources are
|
|
23
|
+
* attached: `toolArgument` is the first one compile cannot write
|
|
24
|
+
* ({@link toolArgumentRefusal}), in tool then argument order, for the caller to
|
|
25
|
+
* hold until it has judged the rest; `toolVariables` holds each tool's
|
|
26
|
+
* Variables, for the caller to bind as agent inputs, a refused argument left out.
|
|
27
|
+
*
|
|
28
|
+
* `bindsVariables` is false for the voice and conversational agents: compile
|
|
29
|
+
* extends only the inline agent's input plan with a tool's references, so a
|
|
30
|
+
* Variable there would bind nothing and the model would fill the argument. It
|
|
31
|
+
* is refused instead (`FLOW_AGENT_TOOL_ARGUMENT_VARIABLE`).
|
|
32
|
+
*/
|
|
33
|
+
export declare function processToolArguments(s: AgentResources, step: string, who: AgentKindLabel, render: (v: unknown) => unknown, bindsVariables: boolean): {
|
|
34
|
+
toolVariables: Map<object, ReturnType<typeof toolVariableRefs>>;
|
|
35
|
+
toolArgument: CompileRefusal | undefined;
|
|
36
|
+
};
|
|
20
37
|
/**
|
|
21
38
|
* The resources an agent attaches — a node per context index, tool and
|
|
22
39
|
* escalation on the agent's `context`, `tool` and `escalation` handles, and the
|
|
@@ -27,8 +44,12 @@ export declare function serializeInlineAgent(s: InlineAgentInputs, ctx: FlowSeri
|
|
|
27
44
|
*
|
|
28
45
|
* A connector tool with no library is not thrown here but returned as
|
|
29
46
|
* `libraryRequired`, for the caller to throw once it has judged the rest.
|
|
47
|
+
* `toolVariables` holds each process tool's Variable arguments, already bound
|
|
48
|
+
* to agent inputs by the caller's input plan (`toolVariableRefs`).
|
|
30
49
|
*/
|
|
31
|
-
export declare function attachAgentResources(s: AgentResources, ctx: FlowSerializeContext, source: string, who: AgentKindLabel
|
|
50
|
+
export declare function attachAgentResources(s: AgentResources, ctx: FlowSerializeContext, source: string, who: AgentKindLabel, toolVariables?: ReadonlyMap<object, Record<string, {
|
|
51
|
+
flatName: string;
|
|
52
|
+
}>>): {
|
|
32
53
|
attach: Attached[];
|
|
33
54
|
libraryRequired?: CompileRefusal;
|
|
34
55
|
};
|
|
@@ -8,6 +8,7 @@ import { jsonClone } from '../../../core/json-clone.js';
|
|
|
8
8
|
import { subNodeId } from '../../../core/node-id-placeholder.js';
|
|
9
9
|
import { ownEntry } from '../../../core/own-entry.js';
|
|
10
10
|
import { processResourceBindings } from '../../../core/process-resource.js';
|
|
11
|
+
import { toolArgumentRefusal, toolVariableRefs } from '../../../core/tool-argument.js';
|
|
11
12
|
import { fnv1aX4Uuid, schemaId } from '../../../core/stable-id.js';
|
|
12
13
|
import { synthesizedDefinitionRefusal } from '../../../core/synthesized-definition.js';
|
|
13
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';
|
|
@@ -66,9 +67,14 @@ export function serializeInlineAgent(s, ctx) {
|
|
|
66
67
|
properties: Object.fromEntries(Object.entries(returns).map(([k, t]) => [k, { type: t }])),
|
|
67
68
|
};
|
|
68
69
|
}
|
|
70
|
+
// A process tool's Variable arguments, by tool: each binds an agent input of
|
|
71
|
+
// its own, as the canvas derives one from every reference a tool node holds
|
|
72
|
+
// (`deriveAgentInputVariables`), so they are read before the plan is built.
|
|
73
|
+
// An argument compile cannot write is held like a composite input (below).
|
|
74
|
+
const { toolVariables, toolArgument } = processToolArguments(s, step, 'Inline agent', render, true);
|
|
69
75
|
// What the PLATFORM will call each of these — computed once and shared by the
|
|
70
76
|
// descriptor array below and the sidecar. See `agentInputPlan`.
|
|
71
|
-
const plan = agentInputPlan(s.inputs ?? {}, render);
|
|
77
|
+
const plan = agentInputPlan(s.inputs ?? {}, render, [...toolVariables.values()].flatMap((v) => Object.values(v)));
|
|
72
78
|
// A composite input is held, not thrown here: the agent's tools, context,
|
|
73
79
|
// escalations and memory are still judged, so `check` (one refusal per
|
|
74
80
|
// step) shows their errors in the same round. Thrown at the end.
|
|
@@ -128,7 +134,7 @@ export function serializeInlineAgent(s, ctx) {
|
|
|
128
134
|
// not exist yet: the `properties` object is filled in place when the scope
|
|
129
135
|
// closes.
|
|
130
136
|
ctx.typeAgentInputs(agentJson.inputSchema, plan.refs);
|
|
131
|
-
const { attach, libraryRequired } = attachAgentResources(s, ctx, source, 'Inline agent');
|
|
137
|
+
const { attach, libraryRequired } = attachAgentResources(s, ctx, source, 'Inline agent', toolVariables);
|
|
132
138
|
// MEMORY — one episodic-memory resource on the agent's `memory` handle (the
|
|
133
139
|
// 1.4 definition selected above). Same artifact shape as context.
|
|
134
140
|
if (s.memory !== undefined) {
|
|
@@ -150,8 +156,13 @@ export function serializeInlineAgent(s, ctx) {
|
|
|
150
156
|
// (AGENT_MEMORY_NOT_AUTHORABLE); its shape maps cleanly off `AgentMemoryRef`
|
|
151
157
|
// but cannot be exercised while the handle does not exist.
|
|
152
158
|
}
|
|
159
|
+
// The held refusals: the agent's own inputs, then its tools' arguments, and
|
|
160
|
+
// LIBRARY_REQUIRED last, because `check` drops it (failing open), so it must
|
|
161
|
+
// not hide either.
|
|
153
162
|
if (compositeInput)
|
|
154
163
|
throw compositeInput;
|
|
164
|
+
if (toolArgument)
|
|
165
|
+
throw toolArgument;
|
|
155
166
|
if (libraryRequired)
|
|
156
167
|
throw libraryRequired;
|
|
157
168
|
return {
|
|
@@ -170,6 +181,49 @@ export function serializeInlineAgent(s, ctx) {
|
|
|
170
181
|
attach,
|
|
171
182
|
};
|
|
172
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Each process tool's arguments, judged before the agent's resources are
|
|
186
|
+
* attached: `toolArgument` is the first one compile cannot write
|
|
187
|
+
* ({@link toolArgumentRefusal}), in tool then argument order, for the caller to
|
|
188
|
+
* hold until it has judged the rest; `toolVariables` holds each tool's
|
|
189
|
+
* Variables, for the caller to bind as agent inputs, a refused argument left out.
|
|
190
|
+
*
|
|
191
|
+
* `bindsVariables` is false for the voice and conversational agents: compile
|
|
192
|
+
* extends only the inline agent's input plan with a tool's references, so a
|
|
193
|
+
* Variable there would bind nothing and the model would fill the argument. It
|
|
194
|
+
* is refused instead (`FLOW_AGENT_TOOL_ARGUMENT_VARIABLE`).
|
|
195
|
+
*/
|
|
196
|
+
export function processToolArguments(s, step, who, render, bindsVariables) {
|
|
197
|
+
const toolRefs = s.tools === undefined ? [] : Array.isArray(s.tools) ? s.tools : [s.tools];
|
|
198
|
+
const toolVariables = new Map();
|
|
199
|
+
let toolArgument;
|
|
200
|
+
for (const tr of toolRefs) {
|
|
201
|
+
if (tr === null || typeof tr !== 'object' || !ownEntry(PROCESS_TOOL_META, tr.kind))
|
|
202
|
+
continue;
|
|
203
|
+
const p = tr;
|
|
204
|
+
const tool = `'${p.kind}' tool "${p.name ?? ''}"`;
|
|
205
|
+
const writable = {};
|
|
206
|
+
for (const [name, arg] of Object.entries(p.inputs ?? {})) {
|
|
207
|
+
const refusal = toolArgumentRefusal(who, step, tool, name, arg, render)
|
|
208
|
+
?? (bindsVariables ? undefined : variableRefusal(who, step, tool, name, arg));
|
|
209
|
+
if (refusal === undefined)
|
|
210
|
+
writable[name] = arg;
|
|
211
|
+
else
|
|
212
|
+
toolArgument ??= refusal;
|
|
213
|
+
}
|
|
214
|
+
toolVariables.set(tr, toolVariableRefs(writable, render));
|
|
215
|
+
}
|
|
216
|
+
return { toolVariables, toolArgument };
|
|
217
|
+
}
|
|
218
|
+
/** FLOW_AGENT_TOOL_ARGUMENT_VARIABLE: a Variable on an agent whose input plan compile does not extend. */
|
|
219
|
+
function variableRefusal(who, step, tool, name, arg) {
|
|
220
|
+
if (typeof arg !== 'object' || arg === null || !('variable' in arg))
|
|
221
|
+
return undefined;
|
|
222
|
+
return new CompileRefusal('FLOW_AGENT_TOOL_ARGUMENT_VARIABLE', `${who} step "${step}"'s ${tool} gives its argument \`${name}\` a \`variable\`. Compile binds a tool `
|
|
223
|
+
+ `argument's Variable as an agent input only on an inline agent; on a ${who.toLowerCase()} it would bind `
|
|
224
|
+
+ `nothing, and the model would fill the argument. Give it a fixed \`value\` or a \`prompt\`, or attach the `
|
|
225
|
+
+ `tool to an \`inlineAgent()\`.`, `${name}: { type: '${String(arg.type)}', value: … }`);
|
|
226
|
+
}
|
|
173
227
|
/**
|
|
174
228
|
* The resources an agent attaches — a node per context index, tool and
|
|
175
229
|
* escalation on the agent's `context`, `tool` and `escalation` handles, and the
|
|
@@ -180,8 +234,10 @@ export function serializeInlineAgent(s, ctx) {
|
|
|
180
234
|
*
|
|
181
235
|
* A connector tool with no library is not thrown here but returned as
|
|
182
236
|
* `libraryRequired`, for the caller to throw once it has judged the rest.
|
|
237
|
+
* `toolVariables` holds each process tool's Variable arguments, already bound
|
|
238
|
+
* to agent inputs by the caller's input plan (`toolVariableRefs`).
|
|
183
239
|
*/
|
|
184
|
-
export function attachAgentResources(s, ctx, source, who) {
|
|
240
|
+
export function attachAgentResources(s, ctx, source, who, toolVariables = new Map()) {
|
|
185
241
|
const step = ctx.step;
|
|
186
242
|
const render = (v) => ctx.render(v);
|
|
187
243
|
const attach = [];
|
|
@@ -480,7 +536,7 @@ export function attachAgentResources(s, ctx, source, who) {
|
|
|
480
536
|
? builtinToolResourceJson(tr.tool, label, toolInputs, { id: toolResourceId })
|
|
481
537
|
: tr.kind === 'httpRequest'
|
|
482
538
|
? httpRequestToolResourceJson(label, toolInputs, { id: toolResourceId, canvasNodeId: tid })
|
|
483
|
-
: toolResourceJson(tr, { id: toolResourceId });
|
|
539
|
+
: toolResourceJson(tr, { id: toolResourceId, variables: toolVariables.get(tr) });
|
|
484
540
|
if (toolResource !== undefined) {
|
|
485
541
|
ctx.sidecar({ path: `${source}/resources/${toolResourceId}/resource.json`, json: toolResource }, tr.source !== undefined ? `${who.toLowerCase()} step "${step}"'s ${tr.kind} tool` : undefined);
|
|
486
542
|
}
|