@noetic-tools/core 5.20.0-next.1 → 5.20.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/adapters/openrouter.d.ts +1 -48
- package/dist/adapters/openrouter.js +3 -204
- package/dist/builders/acp-agent-checks.d.ts +20 -0
- package/dist/builders/acp-agent-checks.js +68 -0
- package/dist/builders/acp-agent-tool.d.ts +4 -3
- package/dist/builders/acp-agent-tool.js +5 -2
- package/dist/builders/connection-ceiling.d.ts +13 -0
- package/dist/builders/connection-ceiling.js +17 -0
- package/dist/builders/document-entries.d.ts +13 -0
- package/dist/builders/document-entries.js +18 -0
- package/dist/builders/dynamic-workflow.d.ts +53 -8
- package/dist/builders/dynamic-workflow.js +53 -25
- package/dist/builders/mcp-url-pattern.d.ts +13 -0
- package/dist/builders/mcp-url-pattern.js +85 -0
- package/dist/builders/step-builders.d.ts +14 -6
- package/dist/builders/step-builders.js +25 -2
- package/dist/builders/workflow-acp-grants.d.ts +42 -0
- package/dist/builders/workflow-acp-grants.js +224 -0
- package/dist/builders/workflow-child-nodes.js +8 -0
- package/dist/builders/workflow-connection-nodes.d.ts +13 -3
- package/dist/builders/workflow-connection-nodes.js +129 -3
- package/dist/builders/workflow-connections.js +2 -1
- package/dist/builders/workflow-hydrator.d.ts +24 -1
- package/dist/builders/workflow-hydrator.js +8 -167
- package/dist/builders/workflow-mcp-servers.d.ts +44 -0
- package/dist/builders/workflow-mcp-servers.js +327 -0
- package/dist/builders/workflow-tool-entries.d.ts +84 -0
- package/dist/builders/workflow-tool-entries.js +216 -0
- package/dist/connections/durability.d.ts +11 -1
- package/dist/connections/durability.js +34 -0
- package/dist/connections/entries.d.ts +33 -0
- package/dist/connections/entries.js +118 -0
- package/dist/connections/errors.d.ts +6 -0
- package/dist/connections/errors.js +12 -0
- package/dist/connections/harness-wiring.d.ts +4 -4
- package/dist/connections/harness-wiring.js +1 -1
- package/dist/connections/in-memory-connection.d.ts +2 -0
- package/dist/connections/in-memory-connection.js +5 -0
- package/dist/connections/model-tools.d.ts +35 -12
- package/dist/connections/model-tools.js +348 -202
- package/dist/connections/registry-types.d.ts +7 -0
- package/dist/connections/registry.d.ts +35 -6
- package/dist/connections/registry.js +183 -39
- package/dist/connections/step-tools.d.ts +64 -0
- package/dist/connections/step-tools.js +154 -0
- package/dist/connections/views.d.ts +3 -2
- package/dist/connections/views.js +15 -6
- package/dist/harness/agent-harness.d.ts +11 -1
- package/dist/harness/agent-harness.js +69 -8
- package/dist/harness/connection-gate.d.ts +49 -8
- package/dist/harness/connection-gate.js +137 -26
- package/dist/harness/deps/interpreter.d.ts +3 -3
- package/dist/harness/deps/interpreter.js +3 -3
- package/dist/harness/harness-options.d.ts +4 -3
- package/dist/harness/model-request.js +3 -1
- package/dist/harness/model-schema.d.ts +1 -19
- package/dist/harness/model-schema.js +0 -28
- package/dist/harness/model-tool-round.js +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/interpreter/acp-events.d.ts +25 -1
- package/dist/interpreter/acp-events.js +53 -1
- package/dist/interpreter/acp-layers.d.ts +20 -0
- package/dist/interpreter/acp-layers.js +55 -0
- package/dist/interpreter/acp-tools.d.ts +108 -0
- package/dist/interpreter/acp-tools.js +462 -0
- package/dist/interpreter/collect-tools.d.ts +28 -0
- package/dist/interpreter/collect-tools.js +112 -15
- package/dist/interpreter/connection-steps.d.ts +0 -2
- package/dist/interpreter/connection-steps.js +30 -8
- package/dist/interpreter/execute-acp-agent.js +263 -72
- package/dist/interpreter/execute-action.d.ts +76 -1
- package/dist/interpreter/execute-action.js +35 -42
- package/dist/interpreter/execute.d.ts +2 -0
- package/dist/interpreter/execute.js +24 -1
- package/dist/interpreter/verify-host.js +2 -1
- package/dist/runtime/tool-call.d.ts +67 -0
- package/dist/runtime/tool-call.js +244 -0
- package/dist/runtime/tool-context.d.ts +1 -2
- package/dist/runtime/tool-context.js +6 -2
- package/dist/schemas/workflow.d.ts +1 -1
- package/dist/types/connection-entry.d.ts +22 -0
- package/dist/types/connection-entry.js +8 -0
- package/dist/util/harness-internals.d.ts +2 -0
- package/dist/util/root-context.d.ts +3 -0
- package/dist/util/root-context.js +8 -0
- package/dist/util/tool-name.d.ts +8 -0
- package/dist/util/tool-name.js +10 -0
- package/package.json +3 -3
- package/schema/noetic-workflow.schema.json +498 -128
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a document's `acp-agent` nodes may ask of an agent. A node's
|
|
3
|
+
* `permissions`, `mode`, `cwd`, `clientCapabilities` and `session` decide what
|
|
4
|
+
* the agent can do on the host — `terminal` alone hands it a shell, and a mode
|
|
5
|
+
* such as `bypassPermissions` lifts its prompts — so a document
|
|
6
|
+
* a host did not write may ask only for what the host's `acp` allowlist grants
|
|
7
|
+
* that agent (spec 26 § ACP agents).
|
|
8
|
+
*/
|
|
9
|
+
import { NoeticConfigError, walkWorkflow } from '@noetic-tools/types';
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region Public API
|
|
12
|
+
/**
|
|
13
|
+
* Checks every `acp-agent` node against the grant for its agent. Inline
|
|
14
|
+
* subflows count; named refs resolve from the host's own registry and are not
|
|
15
|
+
* checked.
|
|
16
|
+
*
|
|
17
|
+
* @throws `NoeticConfigError` `CONNECTION_NOT_ALLOWED` for a permission, mode, model, `cwd`, client capability or session setting the grant does not allow.
|
|
18
|
+
*/
|
|
19
|
+
export function checkAcpAgents(doc, grants, harnessCwd) {
|
|
20
|
+
for (const node of walkWorkflow(doc.root)) {
|
|
21
|
+
if (node.kind !== 'acp-agent') {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const grant = grantFor(grants, node.agent);
|
|
25
|
+
checkPermissions(node, grant.permissions);
|
|
26
|
+
checkChoice(node, 'mode', grant.modes ?? []);
|
|
27
|
+
checkChoice(node, 'model', grant.models);
|
|
28
|
+
checkCwd(node, grant.cwd ?? harnessCwd);
|
|
29
|
+
checkCapabilities(node, capabilityCeiling(grant));
|
|
30
|
+
checkSession(node, grant);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A new namespace for one run of a document's sessions, with the harness's
|
|
35
|
+
* working directory as it was when the document was checked.
|
|
36
|
+
*/
|
|
37
|
+
export function acpBounds(grants, harnessCwd) {
|
|
38
|
+
return {
|
|
39
|
+
grants: grants ?? {},
|
|
40
|
+
sessionScope: `document-${crypto.randomUUID()}`,
|
|
41
|
+
cwd: harnessCwd,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The node's settings as its step runs them. An omitted `cwd` takes the
|
|
46
|
+
* grant's, else the harness's as it was when the document was checked — never
|
|
47
|
+
* the harness's at run time, which may since have left the grant. An omitted
|
|
48
|
+
* capability takes the grant's value rather than the protocol client's default
|
|
49
|
+
* of on, and a `session.reuse` key moves into the document's namespace.
|
|
50
|
+
*/
|
|
51
|
+
export function boundedAcpSettings(node, bounds) {
|
|
52
|
+
const grant = grantFor(bounds.grants, node.agent);
|
|
53
|
+
const ceiling = capabilityCeiling(grant);
|
|
54
|
+
const capability = (name) => node.clientCapabilities?.[name] ?? ceiling[name] === true;
|
|
55
|
+
const reuse = node.session?.reuse;
|
|
56
|
+
return {
|
|
57
|
+
cwd: node.cwd ?? grant.cwd ?? bounds.cwd,
|
|
58
|
+
clientCapabilities: {
|
|
59
|
+
readTextFile: capability('readTextFile'),
|
|
60
|
+
writeTextFile: capability('writeTextFile'),
|
|
61
|
+
terminal: capability('terminal'),
|
|
62
|
+
},
|
|
63
|
+
session: reuse
|
|
64
|
+
? {
|
|
65
|
+
...node.session,
|
|
66
|
+
reuse: `${bounds.sessionScope}/${reuse}`,
|
|
67
|
+
}
|
|
68
|
+
: node.session,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** The planner's view of the agents it may run and the most it may ask of each. */
|
|
72
|
+
export function acpPrompt(agents, grants, harnessCwd) {
|
|
73
|
+
const ids = [
|
|
74
|
+
...(agents?.keys() ?? []),
|
|
75
|
+
];
|
|
76
|
+
if (ids.length === 0) {
|
|
77
|
+
return '\nNo ACP agents are available: do not emit acp-agent nodes.';
|
|
78
|
+
}
|
|
79
|
+
const lines = ids.map((id) => agentLine(id, grantFor(grants, id), harnessCwd));
|
|
80
|
+
return `\nACP agents an acp-agent node may run (no others), and the most a node may ask of each:
|
|
81
|
+
${lines.join('\n')}`;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region Checks
|
|
85
|
+
const NO_GRANT = {};
|
|
86
|
+
const DEFAULT_CAPABILITIES = {
|
|
87
|
+
readTextFile: true,
|
|
88
|
+
};
|
|
89
|
+
const CAPABILITIES = [
|
|
90
|
+
'readTextFile',
|
|
91
|
+
'writeTextFile',
|
|
92
|
+
'terminal',
|
|
93
|
+
];
|
|
94
|
+
const KEEP_ALIVE_ORDER = {
|
|
95
|
+
step: 0,
|
|
96
|
+
run: 1,
|
|
97
|
+
harness: 2,
|
|
98
|
+
};
|
|
99
|
+
/** A document's session namespace dies with its run, so no session outlives the run. */
|
|
100
|
+
const LONGEST_KEEP_ALIVE = 'run';
|
|
101
|
+
function grantFor(grants, agent) {
|
|
102
|
+
return grants && Object.hasOwn(grants, agent) ? (grants[agent] ?? NO_GRANT) : NO_GRANT;
|
|
103
|
+
}
|
|
104
|
+
function capabilityCeiling(grant) {
|
|
105
|
+
return grant.clientCapabilities ?? DEFAULT_CAPABILITIES;
|
|
106
|
+
}
|
|
107
|
+
function checkPermissions(node, grant) {
|
|
108
|
+
const policy = node.permissions;
|
|
109
|
+
if (!policy) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (policy.default === 'allow' && grant?.default !== 'allow') {
|
|
113
|
+
throw notAllowed(node, 'permissions.default "allow"', 'Leave `default` out, which denies.');
|
|
114
|
+
}
|
|
115
|
+
if (policy.persist && !grant?.persist) {
|
|
116
|
+
throw notAllowed(node, 'permissions.persist', 'Leave `persist` out.');
|
|
117
|
+
}
|
|
118
|
+
for (const rule of policy.allow ?? []) {
|
|
119
|
+
if (!(grant?.allow ?? []).some((ceiling) => covers(ceiling, rule))) {
|
|
120
|
+
throw notAllowed(node, `the permissions.allow rule ${JSON.stringify(rule)}`, `Allow only within ${JSON.stringify(grant?.allow ?? [])}.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Whether every tool call `rule` matches, `ceiling` matches too. Titles match
|
|
126
|
+
* as case-insensitive substrings, so a title containing the ceiling's title
|
|
127
|
+
* matches only calls the ceiling's title matches.
|
|
128
|
+
*/
|
|
129
|
+
function covers(ceiling, rule) {
|
|
130
|
+
if (ceiling.kind !== undefined && ceiling.kind !== rule.kind) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
if (ceiling.title === undefined) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
return rule.title?.toLowerCase().includes(ceiling.title.toLowerCase()) === true;
|
|
137
|
+
}
|
|
138
|
+
/** Refuses a node's `field` not in `granted`. Undefined `granted` allows any value; an empty one, none. */
|
|
139
|
+
function checkChoice(node, field, granted) {
|
|
140
|
+
const value = node[field];
|
|
141
|
+
if (value === undefined || granted === undefined || granted.includes(value)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
throw notAllowed(node, `${field} ${JSON.stringify(value)}`, granted.length > 0
|
|
145
|
+
? `Set \`${field}\` to one of ${JSON.stringify(granted)}, or leave it out.`
|
|
146
|
+
: `Leave \`${field}\` out.`);
|
|
147
|
+
}
|
|
148
|
+
function checkCwd(node, root) {
|
|
149
|
+
if (node.cwd === undefined || isUnder(node.cwd, root)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
throw notAllowed(node, `cwd ${JSON.stringify(node.cwd)}`, `Use ${root} or an absolute directory under it, written without '.', '..' or repeated '/'.`);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Lexical, with no `node:path`, so core stays runtime-neutral: `path` must
|
|
156
|
+
* already be absolute and plain, so no `..` can walk it back out of `root`.
|
|
157
|
+
*/
|
|
158
|
+
function isUnder(path, root) {
|
|
159
|
+
if (!path.startsWith('/') || path.includes('\\')) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
const segments = path === '/' ? [] : path.slice(1).split('/');
|
|
163
|
+
if (segments.some((s) => s === '' || s === '.' || s === '..')) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
const base = root.length > 1 && root.endsWith('/') ? root.slice(0, -1) : root;
|
|
167
|
+
return path === base || path.startsWith(base === '/' ? '/' : `${base}/`);
|
|
168
|
+
}
|
|
169
|
+
function checkCapabilities(node, ceiling) {
|
|
170
|
+
for (const name of CAPABILITIES) {
|
|
171
|
+
if (node.clientCapabilities?.[name] === true && ceiling[name] !== true) {
|
|
172
|
+
throw notAllowed(node, `clientCapabilities.${name}`, `Leave \`${name}\` out or set it to false.`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function checkSession(node, grant) {
|
|
177
|
+
const longest = longestKeepAlive(grant);
|
|
178
|
+
const keepAlive = node.session?.keepAlive ?? 'step';
|
|
179
|
+
if (KEEP_ALIVE_ORDER[keepAlive] > KEEP_ALIVE_ORDER[longest]) {
|
|
180
|
+
throw notAllowed(node, `session.keepAlive "${keepAlive}"`, `Keep the session alive no longer than "${longest}".`);
|
|
181
|
+
}
|
|
182
|
+
if (node.session?.load !== undefined && !grant.session?.load) {
|
|
183
|
+
throw notAllowed(node, 'session.load', 'Leave `load` out to start a new session.');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** The grant's `keepAlive`, capped at `'run'` for a grant from untyped code that says `'harness'`. */
|
|
187
|
+
function longestKeepAlive(grant) {
|
|
188
|
+
const granted = grant.session?.keepAlive ?? LONGEST_KEEP_ALIVE;
|
|
189
|
+
return KEEP_ALIVE_ORDER[granted] > KEEP_ALIVE_ORDER[LONGEST_KEEP_ALIVE]
|
|
190
|
+
? LONGEST_KEEP_ALIVE
|
|
191
|
+
: granted;
|
|
192
|
+
}
|
|
193
|
+
function notAllowed(node, what, hint) {
|
|
194
|
+
return new NoeticConfigError({
|
|
195
|
+
code: 'CONNECTION_NOT_ALLOWED',
|
|
196
|
+
message: `Node '${node.id}' asks agent '${node.agent}' for ${what}, which the host does not allow.`,
|
|
197
|
+
hint,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region Prompt
|
|
202
|
+
function agentLine(id, grant, harnessCwd) {
|
|
203
|
+
const permissions = grant.permissions;
|
|
204
|
+
const ceiling = capabilityCeiling(grant);
|
|
205
|
+
const on = CAPABILITIES.filter((name) => ceiling[name] === true);
|
|
206
|
+
return [
|
|
207
|
+
`- ${JSON.stringify(id)}:`,
|
|
208
|
+
`permissions default ${permissions?.default === 'allow' ? '"allow" or "deny"' : '"deny" only'},`,
|
|
209
|
+
`"allow" rules only within ${JSON.stringify(permissions?.allow ?? [])},`,
|
|
210
|
+
`${permissions?.persist ? '' : 'no '}"persist";`,
|
|
211
|
+
`${choiceLine('mode', grant.modes ?? [])};`,
|
|
212
|
+
`${choiceLine('model', grant.models)};`,
|
|
213
|
+
`cwd ${JSON.stringify(grant.cwd ?? harnessCwd)} or a directory under it;`,
|
|
214
|
+
`clientCapabilities ${on.length > 0 ? on.join(', ') : 'none'} (any other off);`,
|
|
215
|
+
`session keepAlive up to ${JSON.stringify(longestKeepAlive(grant))}, ${grant.session?.load ? '"load" allowed' : 'no "load"'}`,
|
|
216
|
+
].join(' ');
|
|
217
|
+
}
|
|
218
|
+
function choiceLine(field, granted) {
|
|
219
|
+
if (granted === undefined) {
|
|
220
|
+
return `any ${field}`;
|
|
221
|
+
}
|
|
222
|
+
return granted.length > 0 ? `${field} one of ${JSON.stringify(granted)}` : `no ${field}`;
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
@@ -311,11 +311,19 @@ function resolveSubflowDocument(node, ctx) {
|
|
|
311
311
|
].join(', ') || '(none)'}.`,
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
|
+
if (Object.keys(doc.connections ?? {}).length > 0) {
|
|
315
|
+
throw new NoeticConfigError({
|
|
316
|
+
code: 'CONNECTION_INVALID',
|
|
317
|
+
message: `Sub-workflow '${ref}' referenced in subflow node '${node.id}' declares connections, which a subflow cannot: its nodes use the root document's.`,
|
|
318
|
+
hint: `Move the connections of '${ref}' to the root document's "connections".`,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
314
321
|
return {
|
|
315
322
|
doc,
|
|
316
323
|
childCtx: {
|
|
317
324
|
...ctx,
|
|
318
325
|
recursionDepth: depth,
|
|
326
|
+
acpBounds: undefined,
|
|
319
327
|
},
|
|
320
328
|
};
|
|
321
329
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hydrators for the
|
|
3
|
-
* `wait
|
|
4
|
-
* manifest
|
|
2
|
+
* Hydrators for the JSON workflow nodes that reach outside the workflow:
|
|
3
|
+
* `call` and `wait` (spec 35), resolving the connection a node runs on against
|
|
4
|
+
* the document's manifest; `acp-agent` with its tools (spec 27); and `runCode`,
|
|
5
|
+
* which runs its code through a subprocess adapter.
|
|
5
6
|
*/
|
|
6
7
|
import type { ContextData } from '@noetic-tools/context';
|
|
7
8
|
import type { Step } from '@noetic-tools/types';
|
|
@@ -15,3 +16,12 @@ import type { HydrationContext } from './workflow-hydrator.js';
|
|
|
15
16
|
export declare function checkManifestName(name: string, where: string, ctx: HydrationContext): void;
|
|
16
17
|
export declare function hydrateCallNode(node: WorkflowNode, ctx: HydrationContext): Step<ContextData, string, string>;
|
|
17
18
|
export declare function hydrateWaitNode(node: WorkflowNode, ctx: HydrationContext): Step<ContextData, string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Hydrates an `acp-agent` node into `step.acpAgent`. Under `ctx.acpBounds` the
|
|
21
|
+
* node's cwd, client capabilities and session key are held to its agent's
|
|
22
|
+
* grant (see `boundedAcpSettings`).
|
|
23
|
+
*
|
|
24
|
+
* @throws `NoeticConfigError` `UNKNOWN_ACP_AGENT_REFERENCE` when `ctx.acpAgents` has no adapter for the node's agent.
|
|
25
|
+
*/
|
|
26
|
+
export declare function hydrateAcpAgentNode(node: WorkflowNode, ctx: HydrationContext): Step<ContextData, string, string>;
|
|
27
|
+
export declare function hydrateRunCodeNode(node: WorkflowNode, ctx: HydrationContext): Step<ContextData, string, string>;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hydrators for the
|
|
3
|
-
* `wait
|
|
4
|
-
* manifest
|
|
2
|
+
* Hydrators for the JSON workflow nodes that reach outside the workflow:
|
|
3
|
+
* `call` and `wait` (spec 35), resolving the connection a node runs on against
|
|
4
|
+
* the document's manifest; `acp-agent` with its tools (spec 27); and `runCode`,
|
|
5
|
+
* which runs its code through a subprocess adapter.
|
|
5
6
|
*/
|
|
6
7
|
import { frameworkCast, NoeticConfigError } from '@noetic-tools/types';
|
|
7
8
|
import { compileExpression, compute, passes, readInput } from '../expression/jsonata.js';
|
|
8
9
|
import { getDefaultRegistrar } from '../types/step-registrar.js';
|
|
10
|
+
import { DetachedHandleImpl } from '../util/detached-handle.js';
|
|
11
|
+
import { outputText } from './output-text.js';
|
|
12
|
+
import { runCode, step } from './step-builders.js';
|
|
13
|
+
import { boundedAcpSettings } from './workflow-acp-grants.js';
|
|
9
14
|
import { compileArgs, documentHandle, documentSecretsOf } from './workflow-connections.js';
|
|
10
15
|
import { bindingsFor, hydrateStepList } from './workflow-hydrator.js';
|
|
16
|
+
import { nodeTools, withCeiling } from './workflow-tool-entries.js';
|
|
11
17
|
//#region Connection Node Hydrators
|
|
12
18
|
/**
|
|
13
19
|
* Checks a connection name against the document's manifest, when there is one.
|
|
@@ -158,3 +164,123 @@ export function hydrateWaitNode(node, ctx) {
|
|
|
158
164
|
return registered(built);
|
|
159
165
|
}
|
|
160
166
|
//#endregion
|
|
167
|
+
//#region Agent and Code Node Hydrators
|
|
168
|
+
/**
|
|
169
|
+
* Hydrates an `acp-agent` node into `step.acpAgent`. Under `ctx.acpBounds` the
|
|
170
|
+
* node's cwd, client capabilities and session key are held to its agent's
|
|
171
|
+
* grant (see `boundedAcpSettings`).
|
|
172
|
+
*
|
|
173
|
+
* @throws `NoeticConfigError` `UNKNOWN_ACP_AGENT_REFERENCE` when `ctx.acpAgents` has no adapter for the node's agent.
|
|
174
|
+
*/
|
|
175
|
+
export function hydrateAcpAgentNode(node, ctx) {
|
|
176
|
+
if (node.kind !== 'acp-agent') {
|
|
177
|
+
return frameworkCast(undefined);
|
|
178
|
+
}
|
|
179
|
+
const agent = ctx.acpAgents?.get(node.agent);
|
|
180
|
+
if (!agent) {
|
|
181
|
+
throw new NoeticConfigError({
|
|
182
|
+
code: 'UNKNOWN_ACP_AGENT_REFERENCE',
|
|
183
|
+
message: `ACP agent '${node.agent}' referenced in workflow node '${node.id}' is not registered.`,
|
|
184
|
+
hint: 'Pass agent adapters via HydrationContext.acpAgents, e.g. createAcpAgentRegistry(claudeCode()) from @noetic-tools/acp.',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const bounded = ctx.acpBounds ? boundedAcpSettings(node, ctx.acpBounds) : node;
|
|
188
|
+
const built = step.acpAgent({
|
|
189
|
+
id: node.id,
|
|
190
|
+
agent,
|
|
191
|
+
prompt: node.prompt,
|
|
192
|
+
cwd: bounded.cwd,
|
|
193
|
+
mode: node.mode,
|
|
194
|
+
model: node.model,
|
|
195
|
+
tools: nodeTools(node, {
|
|
196
|
+
...ctx,
|
|
197
|
+
spawn: agent.spawn,
|
|
198
|
+
}),
|
|
199
|
+
permissions: node.permissions,
|
|
200
|
+
clientCapabilities: bounded.clientCapabilities,
|
|
201
|
+
session: bounded.session,
|
|
202
|
+
});
|
|
203
|
+
return withCeiling(built, node, ctx);
|
|
204
|
+
}
|
|
205
|
+
export function hydrateRunCodeNode(node, ctx) {
|
|
206
|
+
if (node.kind !== 'runCode') {
|
|
207
|
+
return frameworkCast(undefined);
|
|
208
|
+
}
|
|
209
|
+
const code = node.execute;
|
|
210
|
+
const subprocessRef = node.subprocess;
|
|
211
|
+
return frameworkCast(runCode({
|
|
212
|
+
id: node.id,
|
|
213
|
+
retry: node.retry,
|
|
214
|
+
execute: async (input, execCtx) => {
|
|
215
|
+
const adapter = resolveSubprocessAdapter({
|
|
216
|
+
ref: subprocessRef,
|
|
217
|
+
hydrationCtx: ctx,
|
|
218
|
+
execCtx,
|
|
219
|
+
nodeId: node.id,
|
|
220
|
+
});
|
|
221
|
+
return runCodeViaSubprocess({
|
|
222
|
+
adapter,
|
|
223
|
+
nodeId: node.id,
|
|
224
|
+
code,
|
|
225
|
+
input: outputText(input),
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region Run Node Helpers
|
|
232
|
+
/**
|
|
233
|
+
* Resolves the subprocess adapter for a `runCode` node. When the node names an
|
|
234
|
+
* adapter ref, the host must supply a `resolveSubprocess` resolver; otherwise
|
|
235
|
+
* the step falls back to the harness adapter on the execution context.
|
|
236
|
+
*/
|
|
237
|
+
function resolveSubprocessAdapter(opts) {
|
|
238
|
+
const { ref, hydrationCtx, execCtx, nodeId } = opts;
|
|
239
|
+
if (ref === undefined) {
|
|
240
|
+
return execCtx.subprocess;
|
|
241
|
+
}
|
|
242
|
+
const resolved = hydrationCtx.resolveSubprocess?.(ref);
|
|
243
|
+
if (!resolved) {
|
|
244
|
+
throw new NoeticConfigError({
|
|
245
|
+
code: 'UNKNOWN_SUBPROCESS_REFERENCE',
|
|
246
|
+
message: `Subprocess adapter '${ref}' referenced in run node '${nodeId}' could not be resolved.`,
|
|
247
|
+
hint: 'Pass a `resolveSubprocess(ref)` mapping in the HydrationContext, or omit `subprocess` to use the harness default (ctx.subprocess).',
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return resolved;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Dispatches a `runCode` node's code string through a subprocess adapter: ships the
|
|
254
|
+
* code plus the JSON-stringified input as a process request (input on stdin),
|
|
255
|
+
* waits for the handle to settle, and returns the captured stdout as the step
|
|
256
|
+
* output. A non-zero exit / failed handle surfaces as a thrown error.
|
|
257
|
+
*
|
|
258
|
+
* The code is never eval'd in-process (Cloudflare Workers forbid eval). The
|
|
259
|
+
* adapter owns running the code and capturing stdout into `handle.metadata.result`.
|
|
260
|
+
*/
|
|
261
|
+
async function runCodeViaSubprocess(opts) {
|
|
262
|
+
const { adapter, nodeId, code, input } = opts;
|
|
263
|
+
const request = {
|
|
264
|
+
kind: 'process',
|
|
265
|
+
command: 'node',
|
|
266
|
+
args: [
|
|
267
|
+
'-e',
|
|
268
|
+
code,
|
|
269
|
+
],
|
|
270
|
+
stdin: input,
|
|
271
|
+
metadata: {
|
|
272
|
+
noeticRun: true,
|
|
273
|
+
stepId: nodeId,
|
|
274
|
+
code,
|
|
275
|
+
input,
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
const handle = new DetachedHandleImpl({
|
|
279
|
+
id: `run-${nodeId}`,
|
|
280
|
+
stepId: nodeId,
|
|
281
|
+
spawned: adapter.spawn(request),
|
|
282
|
+
});
|
|
283
|
+
const result = await handle.await();
|
|
284
|
+
return outputText(result);
|
|
285
|
+
}
|
|
286
|
+
//#endregion
|
|
@@ -533,7 +533,8 @@ function checkUse(name, use, allowed) {
|
|
|
533
533
|
* @throws `NoeticConfigError` `CONNECTION_NOT_ALLOWED` when the document asks for more than the allowlist grants (or has connections and there is no allowlist); `CONNECTION_UNKNOWN` / `CONNECTION_INVALID` from `checkDocumentConnections`.
|
|
534
534
|
*/
|
|
535
535
|
export function checkConnectionAllowlist(doc, allowlist) {
|
|
536
|
-
|
|
536
|
+
// A document's own `{ "mcp" }` connections answer to the `mcp` allowlist instead.
|
|
537
|
+
const manifest = Object.fromEntries(Object.entries(doc.connections ?? {}).filter(([, entry]) => entry.mcp === undefined));
|
|
537
538
|
const uses = checkDocumentConnections(doc);
|
|
538
539
|
const names = Object.keys(manifest);
|
|
539
540
|
if (names.length === 0) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ones — they register in the step registry, carry retry policies, etc.
|
|
7
7
|
*/
|
|
8
8
|
import type { ContextData, ContextLayer } from '@noetic-tools/context';
|
|
9
|
-
import type { AcpAgent, Context, CustomItemMap, ExecuteStepFn, OutputCodec, Step, SubprocessAdapter, Tool } from '@noetic-tools/types';
|
|
9
|
+
import type { AcpAgent, AcpAllowlist, ConnectionAllowlist, Context, CustomItemMap, ExecuteStepFn, McpAllowlist, OutputCodec, Step, SubprocessAdapter, Tool } from '@noetic-tools/types';
|
|
10
10
|
import type { ExpressionBindings, ExpressionLimits } from '../expression/jsonata.js';
|
|
11
11
|
import type { WorkflowConnectionRef, WorkflowDocument, WorkflowNode, WorkflowStepList } from '../schemas/workflow.js';
|
|
12
12
|
import type { ConnectionManifestEntries, ConnectionUses } from './workflow-connections.js';
|
|
@@ -52,6 +52,18 @@ export interface HydrationContext {
|
|
|
52
52
|
recursionDepth?: number;
|
|
53
53
|
/** Bounds on each expression evaluation; unset fields use `DEFAULT_EXPRESSION_LIMITS`. */
|
|
54
54
|
expressionLimits?: ExpressionLimits;
|
|
55
|
+
/**
|
|
56
|
+
* What `acp-agent` nodes are held to when the host did not write the
|
|
57
|
+
* document: set by `parseAndRunWorkflow` and `dynamicWorkflow`, dropped for
|
|
58
|
+
* named subflow refs, which the host wrote. Callers never set it.
|
|
59
|
+
*/
|
|
60
|
+
acpBounds?: {
|
|
61
|
+
readonly grants: AcpAllowlist;
|
|
62
|
+
/** Prefixes every `session.reuse` key, so the document's sessions never meet the host's. */
|
|
63
|
+
readonly sessionScope: string;
|
|
64
|
+
/** The harness's working directory when the document was checked: a node's `cwd` when neither it nor its grant sets one. */
|
|
65
|
+
readonly cwd: string;
|
|
66
|
+
};
|
|
55
67
|
/**
|
|
56
68
|
* The hydrated document's identity for `$steps`: each `hydrateWorkflow` call
|
|
57
69
|
* makes a new one, so two documents in one run never read each other's node
|
|
@@ -79,6 +91,17 @@ export interface HydrationContext {
|
|
|
79
91
|
enclosingConnection?: WorkflowConnectionRef;
|
|
80
92
|
/** The connection name `$item` holds on a fan-out path (an `inParallel` whose `over` lists connections). */
|
|
81
93
|
fanOutItem?: string;
|
|
94
|
+
/**
|
|
95
|
+
* What the document may use of each connection. A `{ "connection" }` tool
|
|
96
|
+
* entry is narrowed to the operations it grants. Absent allows every
|
|
97
|
+
* connection the harness or the turn holds.
|
|
98
|
+
*/
|
|
99
|
+
allowlist?: ConnectionAllowlist;
|
|
100
|
+
/**
|
|
101
|
+
* The MCP servers the document may name (spec 26 § MCP servers): its
|
|
102
|
+
* `{ "mcp" }` entries, in `tools` or `connections`. Absent grants none.
|
|
103
|
+
*/
|
|
104
|
+
mcp?: McpAllowlist;
|
|
82
105
|
}
|
|
83
106
|
/** The `$steps` scope of the document `ctx` is hydrating. */
|
|
84
107
|
export declare function documentScopeOf(ctx: HydrationContext): object;
|