@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
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AgentHarnessContract, Context, Item, LLMResponse, StandardSchemaV1, Tool } from '@noetic-tools/types';
|
|
1
|
+
import type { Item, LLMResponse, Tool } from '@noetic-tools/types';
|
|
3
2
|
import type * as OpenRouterAgent from '@openrouter/agent';
|
|
4
|
-
import type { ApprovalOutcome } from '../runtime/tool-approval.js';
|
|
5
3
|
import type { EmbedFn } from '../types/embed.js';
|
|
6
4
|
type ProviderOutputItem = OpenRouterAgent.OpenResponsesResult['output'][number];
|
|
7
5
|
type OpenRouterInputItem = OpenRouterAgent.EasyInputMessage | OpenRouterAgent.FunctionCallItem | OpenRouterAgent.FunctionCallOutputItem | ProviderOutputItem;
|
|
@@ -33,25 +31,6 @@ export declare function extractOutputItems(response: OpenRouterAgent.OpenRespons
|
|
|
33
31
|
* cached".
|
|
34
32
|
*/
|
|
35
33
|
export declare function extractUsage(usage: OpenRouterAgent.Usage | null | undefined): LLMResponse['usage'];
|
|
36
|
-
/**
|
|
37
|
-
* Provider APIs (Anthropic via OpenRouter) enforce tool names match
|
|
38
|
-
* `^[a-zA-Z0-9_-]{1,64}$`. Noetic's internal layer-tool names use `layerId/fn`
|
|
39
|
-
* which contains a forbidden `/`. We translate to a wire-safe form only at
|
|
40
|
-
* the SDK boundary; internal tool-name identity (and every codebase reference
|
|
41
|
-
* to names like `plan/updatePrd`) is preserved.
|
|
42
|
-
*/
|
|
43
|
-
export declare function sanitizeToolNameForWire(name: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Resolve the JSON Schema sent to the model. Zod keeps its legacy-compatible
|
|
46
|
-
* fast path. For other validators, an explicit override wins over the Standard
|
|
47
|
-
* JSON Schema v1 companion trait.
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
export declare function resolveWireJsonSchema(params: {
|
|
51
|
-
schema: StandardSchemaV1;
|
|
52
|
-
explicitJsonSchema?: Record<string, unknown>;
|
|
53
|
-
what: string;
|
|
54
|
-
}): Record<string, unknown>;
|
|
55
34
|
/** @internal */
|
|
56
35
|
export declare function convertTools({ tools }: ConvertToolsParams): SdkTool[];
|
|
57
36
|
/**
|
|
@@ -61,32 +40,6 @@ export declare function convertTools({ tools }: ConvertToolsParams): SdkTool[];
|
|
|
61
40
|
* output would drop every description and constraint the provider bills for.
|
|
62
41
|
*/
|
|
63
42
|
export declare function toolsOnWire(tools: ReadonlyArray<SdkTool>): unknown[];
|
|
64
|
-
/** @internal */
|
|
65
|
-
export interface ExecuteToolCallParams {
|
|
66
|
-
toolName: string;
|
|
67
|
-
args: unknown;
|
|
68
|
-
tools: ReadonlyArray<Tool>;
|
|
69
|
-
context: Context;
|
|
70
|
-
harness: AgentHarnessContract;
|
|
71
|
-
layers?: ContextLayer[];
|
|
72
|
-
/** The model's `function_call` id — keys this call's tool-UI region. */
|
|
73
|
-
callId?: string;
|
|
74
|
-
}
|
|
75
|
-
/** @internal What one model-requested tool call produced. */
|
|
76
|
-
export interface ToolCallResult {
|
|
77
|
-
output: string;
|
|
78
|
-
result?: unknown;
|
|
79
|
-
error?: boolean;
|
|
80
|
-
/** Set when the tool declares `needsApproval` and the call reached the approver. */
|
|
81
|
-
approval?: ApprovalOutcome;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @internal Execute a single tool call. Gates run in order: the
|
|
85
|
-
* `beforeToolCall` layers, input validation, then — for a tool that declares
|
|
86
|
-
* `needsApproval` — the harness approver. A refusal at any gate becomes an
|
|
87
|
-
* error tool result; the tool never runs.
|
|
88
|
-
*/
|
|
89
|
-
export declare function executeToolCall(params: ExecuteToolCallParams): Promise<ToolCallResult>;
|
|
90
43
|
/**
|
|
91
44
|
* Creates an `EmbedFn` that calls the OpenRouter embeddings API.
|
|
92
45
|
*
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { frameworkCast, isAssistantMessage,
|
|
1
|
+
import { frameworkCast, isAssistantMessage, isZodSchema, NoeticConfigError, } from '@noetic-tools/types';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { emitToolUi } from '../runtime/tool-ui.js';
|
|
3
|
+
import { resolveWireJsonSchema } from '../runtime/tool-call.js';
|
|
4
|
+
import { sanitizeToolNameForWire } from '../util/tool-name.js';
|
|
6
5
|
const EmbeddingsResponseSchema = z.object({
|
|
7
6
|
data: z.array(z.object({
|
|
8
7
|
embedding: z.array(z.number()),
|
|
@@ -206,65 +205,6 @@ function cacheWriteTokensOf(details) {
|
|
|
206
205
|
// This prevents the SDK from handling tool calls internally, which would
|
|
207
206
|
// make tool interactions invisible to Noetic's itemLog, token tracking,
|
|
208
207
|
// and observability. Instead, the AgentHarness manages the tool loop.
|
|
209
|
-
/**
|
|
210
|
-
* Provider APIs (Anthropic via OpenRouter) enforce tool names match
|
|
211
|
-
* `^[a-zA-Z0-9_-]{1,64}$`. Noetic's internal layer-tool names use `layerId/fn`
|
|
212
|
-
* which contains a forbidden `/`. We translate to a wire-safe form only at
|
|
213
|
-
* the SDK boundary; internal tool-name identity (and every codebase reference
|
|
214
|
-
* to names like `plan/updatePrd`) is preserved.
|
|
215
|
-
*/
|
|
216
|
-
export function sanitizeToolNameForWire(name) {
|
|
217
|
-
return name.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Resolve the JSON Schema sent to the model. Zod keeps its legacy-compatible
|
|
221
|
-
* fast path. For other validators, an explicit override wins over the Standard
|
|
222
|
-
* JSON Schema v1 companion trait.
|
|
223
|
-
* @internal
|
|
224
|
-
*/
|
|
225
|
-
export function resolveWireJsonSchema(params) {
|
|
226
|
-
const { schema, explicitJsonSchema, what } = params;
|
|
227
|
-
if (isZodSchema(schema)) {
|
|
228
|
-
return sanitizeJsonSchema(z.toJSONSchema(schema, {
|
|
229
|
-
target: 'draft-07',
|
|
230
|
-
}));
|
|
231
|
-
}
|
|
232
|
-
if (explicitJsonSchema) {
|
|
233
|
-
return sanitizeJsonSchema(explicitJsonSchema);
|
|
234
|
-
}
|
|
235
|
-
if (isStandardJsonSchema(schema)) {
|
|
236
|
-
try {
|
|
237
|
-
return sanitizeJsonSchema(schema['~standard'].jsonSchema.input({
|
|
238
|
-
target: 'draft-07',
|
|
239
|
-
}));
|
|
240
|
-
}
|
|
241
|
-
catch {
|
|
242
|
-
// Fall through to the actionable configuration error below.
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
throw new NoeticConfigError({
|
|
246
|
-
code: 'MISSING_JSON_SCHEMA',
|
|
247
|
-
message: `The ${what} cannot be converted to JSON Schema.`,
|
|
248
|
-
hint: 'Use a schema implementing StandardJSONSchemaV1 or pass `inputJsonSchema` on tool() / `outputJsonSchema` on step.llm().',
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
function sanitizeJsonSchema(value) {
|
|
252
|
-
return Object.fromEntries(Object.entries(value)
|
|
253
|
-
.filter(([key]) => !key.startsWith('~'))
|
|
254
|
-
.map(([key, nested]) => [
|
|
255
|
-
key,
|
|
256
|
-
sanitizeJsonSchemaValue(nested),
|
|
257
|
-
]));
|
|
258
|
-
}
|
|
259
|
-
function sanitizeJsonSchemaValue(value) {
|
|
260
|
-
if (Array.isArray(value)) {
|
|
261
|
-
return value.map(sanitizeJsonSchemaValue);
|
|
262
|
-
}
|
|
263
|
-
if (typeof value === 'object' && value !== null) {
|
|
264
|
-
return sanitizeJsonSchema(frameworkCast(value));
|
|
265
|
-
}
|
|
266
|
-
return value;
|
|
267
|
-
}
|
|
268
208
|
/**
|
|
269
209
|
* The OpenRouter SDK requires a live Zod `inputSchema` and runs
|
|
270
210
|
* `z.toJSONSchema` over it; it never executes these tool objects (Noetic owns
|
|
@@ -316,147 +256,6 @@ export function toolsOnWire(tools) {
|
|
|
316
256
|
};
|
|
317
257
|
});
|
|
318
258
|
}
|
|
319
|
-
function isAsyncGenerator(value) {
|
|
320
|
-
if (typeof value !== 'object' || value === null) {
|
|
321
|
-
return false;
|
|
322
|
-
}
|
|
323
|
-
return Symbol.asyncIterator in value;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* @internal Execute a single tool call. Gates run in order: the
|
|
327
|
-
* `beforeToolCall` layers, input validation, then — for a tool that declares
|
|
328
|
-
* `needsApproval` — the harness approver. A refusal at any gate becomes an
|
|
329
|
-
* error tool result; the tool never runs.
|
|
330
|
-
*/
|
|
331
|
-
export async function executeToolCall(params) {
|
|
332
|
-
// Model sees sanitised tool names (see `sanitizeToolNameForWire`). Match
|
|
333
|
-
// against both the original and sanitised name so internal identity (e.g.
|
|
334
|
-
// `plan/updatePrd` used by steering whitelists, skill docs, and the
|
|
335
|
-
// `plan()` layer's `beforeToolCall` hook) stays intact while the wire name is
|
|
336
|
-
// provider-compliant.
|
|
337
|
-
const matchedTool = params.tools.find((t) => t.name === params.toolName || sanitizeToolNameForWire(t.name) === params.toolName);
|
|
338
|
-
if (!matchedTool) {
|
|
339
|
-
return {
|
|
340
|
-
output: `Error: unknown tool '${params.toolName}'`,
|
|
341
|
-
error: true,
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
if (params.layers && params.layers.length > 0) {
|
|
345
|
-
const decision = await params.harness.beforeToolCall(params.layers, params.toolName, params.args, params.context, params.callId);
|
|
346
|
-
if (decision.action !== SteeringAction.Allow) {
|
|
347
|
-
return refusedResult(decision);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
const validated = await validateSchema(matchedTool.input, params.args);
|
|
351
|
-
if (!validated.success) {
|
|
352
|
-
return {
|
|
353
|
-
output: `Error: invalid arguments for tool '${params.toolName}': ${validated.zodError.message}`,
|
|
354
|
-
error: true,
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
const parsedArgs = validated.value;
|
|
358
|
-
const approval = matchedTool.needsApproval
|
|
359
|
-
? await askApproval({
|
|
360
|
-
harness: params.harness,
|
|
361
|
-
toolName: matchedTool.name,
|
|
362
|
-
toolArgs: parsedArgs,
|
|
363
|
-
callId: params.callId,
|
|
364
|
-
ctx: params.context,
|
|
365
|
-
})
|
|
366
|
-
: undefined;
|
|
367
|
-
if (approval && approval.decision.action !== SteeringAction.Allow) {
|
|
368
|
-
return {
|
|
369
|
-
...refusedResult(approval.decision),
|
|
370
|
-
approval: approval.outcome,
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
const executed = await runMatchedTool(params, matchedTool, parsedArgs);
|
|
374
|
-
return {
|
|
375
|
-
...executed,
|
|
376
|
-
approval: approval?.outcome,
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
function refusedResult(decision) {
|
|
380
|
-
if (decision.action === SteeringAction.Guide) {
|
|
381
|
-
return {
|
|
382
|
-
output: `Tool call redirected: ${decision.guidance}`,
|
|
383
|
-
error: true,
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
return {
|
|
387
|
-
output: `Tool call denied: ${decision.guidance ?? 'steering rule violation'}`,
|
|
388
|
-
error: true,
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
async function runMatchedTool(params, matchedTool, parsedArgs) {
|
|
392
|
-
const toolCtx = buildToolExecutionContext(params.context, params.harness);
|
|
393
|
-
const callId = params.callId;
|
|
394
|
-
const uiBase = callId !== undefined
|
|
395
|
-
? {
|
|
396
|
-
ctx: params.context,
|
|
397
|
-
tool: matchedTool,
|
|
398
|
-
callId,
|
|
399
|
-
args: parsedArgs,
|
|
400
|
-
}
|
|
401
|
-
: undefined;
|
|
402
|
-
if (uiBase) {
|
|
403
|
-
emitToolUi({
|
|
404
|
-
...uiBase,
|
|
405
|
-
phase: 'call',
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
try {
|
|
409
|
-
const executionResult = matchedTool.execute(parsedArgs, toolCtx);
|
|
410
|
-
// Generator tools stream progress; drive them here so tool-UI `progress`
|
|
411
|
-
// fragments emit per yield (the non-UI case just consumes to the return).
|
|
412
|
-
let result;
|
|
413
|
-
if (isAsyncGenerator(executionResult)) {
|
|
414
|
-
const events = [];
|
|
415
|
-
for (;;) {
|
|
416
|
-
const next = await executionResult.next();
|
|
417
|
-
if (next.done) {
|
|
418
|
-
result = next.value;
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
|
-
events.push(next.value);
|
|
422
|
-
if (uiBase) {
|
|
423
|
-
emitToolUi({
|
|
424
|
-
...uiBase,
|
|
425
|
-
phase: 'progress',
|
|
426
|
-
events,
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
result = await executionResult;
|
|
433
|
-
}
|
|
434
|
-
if (uiBase) {
|
|
435
|
-
emitToolUi({
|
|
436
|
-
...uiBase,
|
|
437
|
-
phase: 'result',
|
|
438
|
-
output: result,
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
return {
|
|
442
|
-
output: typeof result === 'string' ? result : JSON.stringify(result),
|
|
443
|
-
result,
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
catch (e) {
|
|
447
|
-
if (uiBase) {
|
|
448
|
-
emitToolUi({
|
|
449
|
-
...uiBase,
|
|
450
|
-
phase: 'error',
|
|
451
|
-
error: e,
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
return {
|
|
455
|
-
output: `Error: ${e instanceof Error ? e.message : String(e)}`,
|
|
456
|
-
error: true,
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
259
|
//#endregion
|
|
461
260
|
//#region Public API
|
|
462
261
|
/**
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks on the tools given to `step.acpAgent`, shared by the builder (for an
|
|
3
|
+
* eager `tools` array) and the interpreter (for a getter, when the step runs).
|
|
4
|
+
*/
|
|
5
|
+
import type { AcpAgent, ServerToolSpec, Tool } from '@noetic-tools/types';
|
|
6
|
+
/** The MCP server name agents see the step's tools under; they prefix tool names with it. */
|
|
7
|
+
export declare const ACP_TOOL_SERVER_NAME = "noetic";
|
|
8
|
+
/** Record that `tool` runs the ACP step `stepId`. */
|
|
9
|
+
export declare function markAcpDelegate(tool: Tool, stepId: string): void;
|
|
10
|
+
/** The ACP step `tool` runs, when it is an `acpAgentTool`. */
|
|
11
|
+
export declare function acpDelegateStepOf(tool: Tool): string | undefined;
|
|
12
|
+
/** An agent that names the fix it is missing fails with it. */
|
|
13
|
+
export declare function assertAgentTakesTools(stepId: string, agent: AcpAgent): void;
|
|
14
|
+
/**
|
|
15
|
+
* Narrow to client tools, as the agent will see them: the first tool of each
|
|
16
|
+
* name wins, as in the `callModel` tool set. Server tools (only a model
|
|
17
|
+
* provider can run them) and two names that reach the agent as the same wire
|
|
18
|
+
* name are configuration errors.
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkedAcpTools(stepId: string, entries: ReadonlyArray<Tool | ServerToolSpec>): Tool[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks on the tools given to `step.acpAgent`, shared by the builder (for an
|
|
3
|
+
* eager `tools` array) and the interpreter (for a getter, when the step runs).
|
|
4
|
+
*/
|
|
5
|
+
import { isServerToolSpec, NoeticConfigError } from '@noetic-tools/types';
|
|
6
|
+
import { sanitizeToolNameForWire } from '../util/tool-name.js';
|
|
7
|
+
/** The MCP server name agents see the step's tools under; they prefix tool names with it. */
|
|
8
|
+
export const ACP_TOOL_SERVER_NAME = 'noetic';
|
|
9
|
+
/**
|
|
10
|
+
* Tools that run an ACP step, by the step they run (`acpAgentTool`). A step
|
|
11
|
+
* never serves its own delegate: the agent calling it would wait on its own
|
|
12
|
+
* session for ever.
|
|
13
|
+
*/
|
|
14
|
+
const delegates = new WeakMap();
|
|
15
|
+
/** Record that `tool` runs the ACP step `stepId`. */
|
|
16
|
+
export function markAcpDelegate(tool, stepId) {
|
|
17
|
+
delegates.set(tool, stepId);
|
|
18
|
+
}
|
|
19
|
+
/** The ACP step `tool` runs, when it is an `acpAgentTool`. */
|
|
20
|
+
export function acpDelegateStepOf(tool) {
|
|
21
|
+
return delegates.get(tool);
|
|
22
|
+
}
|
|
23
|
+
/** An agent that names the fix it is missing fails with it. */
|
|
24
|
+
export function assertAgentTakesTools(stepId, agent) {
|
|
25
|
+
const refusal = agent.refusesTools;
|
|
26
|
+
if (!refusal) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
throw new NoeticConfigError({
|
|
30
|
+
code: refusal.code,
|
|
31
|
+
message: `step.acpAgent(${JSON.stringify(stepId)}) gives tools to the '${agent.agentId}' agent, which cannot take them: ${refusal.reason}`,
|
|
32
|
+
hint: refusal.hint,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Narrow to client tools, as the agent will see them: the first tool of each
|
|
37
|
+
* name wins, as in the `callModel` tool set. Server tools (only a model
|
|
38
|
+
* provider can run them) and two names that reach the agent as the same wire
|
|
39
|
+
* name are configuration errors.
|
|
40
|
+
*/
|
|
41
|
+
export function checkedAcpTools(stepId, entries) {
|
|
42
|
+
const owners = new Map();
|
|
43
|
+
const tools = [];
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
if (isServerToolSpec(entry)) {
|
|
46
|
+
throw new NoeticConfigError({
|
|
47
|
+
code: 'ACP_SERVER_TOOL',
|
|
48
|
+
message: `step.acpAgent(${JSON.stringify(stepId)}) was given the server tool '${entry.type}', which only a model provider can run.`,
|
|
49
|
+
hint: 'Pass only client tools built with tool() to an ACP step.',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const wire = sanitizeToolNameForWire(entry.name);
|
|
53
|
+
const owner = owners.get(wire);
|
|
54
|
+
if (owner === entry.name) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (owner !== undefined) {
|
|
58
|
+
throw new NoeticConfigError({
|
|
59
|
+
code: 'ACP_TOOL_NAME_COLLISION',
|
|
60
|
+
message: `step.acpAgent(${JSON.stringify(stepId)}) has tools '${owner}' and '${entry.name}', which both reach the agent as '${wire}'.`,
|
|
61
|
+
hint: 'Tool names are reduced to letters, digits, `_` and `-` on the wire. Rename one of them.',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
owners.set(wire, entry.name);
|
|
65
|
+
tools.push(entry);
|
|
66
|
+
}
|
|
67
|
+
return tools;
|
|
68
|
+
}
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
* bridge, usage accounting — is identical, because the tool runs the very same
|
|
10
10
|
* step underneath.
|
|
11
11
|
*/
|
|
12
|
-
import type { AcpAgent, AcpClientCapabilityConfig,
|
|
12
|
+
import type { AcpAgent, AcpClientCapabilityConfig, AcpPermissionHandler, AcpPermissionPolicy, AcpSessionPolicy, ContextData, Tool } from '@noetic-tools/types';
|
|
13
13
|
import { z } from 'zod';
|
|
14
|
+
import type { StepAcpAgentOpts } from './step-builders.js';
|
|
14
15
|
/** @public Options for {@link acpAgentTool}. */
|
|
15
16
|
export interface AcpAgentToolOptions {
|
|
16
17
|
/** The ACP agent adapter to delegate to, e.g. `claudeCode()`. */
|
|
@@ -32,8 +33,8 @@ export interface AcpAgentToolOptions {
|
|
|
32
33
|
mode?: string;
|
|
33
34
|
/** Model to select before each delegated turn. */
|
|
34
35
|
model?: string;
|
|
35
|
-
/**
|
|
36
|
-
|
|
36
|
+
/** Noetic tools to give the agent, served to it over MCP — as `step.acpAgent` takes them. */
|
|
37
|
+
tools?: StepAcpAgentOpts<ContextData, string, string>['tools'];
|
|
37
38
|
/** Declarative answer to the agent's permission requests. Defaults to denying. */
|
|
38
39
|
permissions?: AcpPermissionPolicy;
|
|
39
40
|
/** Async resolver consulted when policy and steering both abstain. */
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { NoeticConfigError } from '@noetic-tools/types';
|
|
13
13
|
import { z } from 'zod';
|
|
14
|
+
import { markAcpDelegate } from './acp-agent-checks.js';
|
|
14
15
|
import { step } from './step-builders.js';
|
|
15
16
|
import { tool } from './tool-builder.js';
|
|
16
17
|
const AcpAgentToolInputSchema = z.object({
|
|
@@ -62,13 +63,13 @@ export function acpAgentTool(opts) {
|
|
|
62
63
|
cwd: opts.cwd,
|
|
63
64
|
mode: opts.mode,
|
|
64
65
|
model: opts.model,
|
|
65
|
-
|
|
66
|
+
tools: opts.tools,
|
|
66
67
|
permissions: opts.permissions,
|
|
67
68
|
onPermissionRequest: opts.onPermissionRequest,
|
|
68
69
|
clientCapabilities: opts.clientCapabilities,
|
|
69
70
|
session: opts.session,
|
|
70
71
|
});
|
|
71
|
-
|
|
72
|
+
const delegate = tool({
|
|
72
73
|
name,
|
|
73
74
|
description: opts.description ?? defaultDescription(opts.agent.agentId),
|
|
74
75
|
input: AcpAgentToolInputSchema,
|
|
@@ -83,5 +84,7 @@ export function acpAgentTool(opts) {
|
|
|
83
84
|
};
|
|
84
85
|
},
|
|
85
86
|
});
|
|
87
|
+
markAcpDelegate(delegate, delegated.id);
|
|
88
|
+
return delegate;
|
|
86
89
|
}
|
|
87
90
|
//#endregion
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The most of the turn's connections a document node with no `tools` may be
|
|
3
|
+
* offered (spec 26 § Tools): the connections the host's allowlist grants, with
|
|
4
|
+
* exactly their granted operations, and the MCP servers the document attaches.
|
|
5
|
+
* The hydrator records it on the step it builds for the node. Unlike a `tools`
|
|
6
|
+
* list, it narrows only connection tools: the node keeps every other tool a
|
|
7
|
+
* step with no `tools` is offered.
|
|
8
|
+
*/
|
|
9
|
+
import type { ConnectionPick, Step } from '@noetic-tools/types';
|
|
10
|
+
/** Records `picks` as the most of the turn's connections `step` may be offered. */
|
|
11
|
+
export declare function setConnectionCeiling(step: object, picks: ReadonlyArray<ConnectionPick>): void;
|
|
12
|
+
/** The ceiling recorded on `step`, when a document node built it. */
|
|
13
|
+
export declare function connectionCeilingOf(step: Step | object): ReadonlyArray<ConnectionPick> | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The most of the turn's connections a document node with no `tools` may be
|
|
3
|
+
* offered (spec 26 § Tools): the connections the host's allowlist grants, with
|
|
4
|
+
* exactly their granted operations, and the MCP servers the document attaches.
|
|
5
|
+
* The hydrator records it on the step it builds for the node. Unlike a `tools`
|
|
6
|
+
* list, it narrows only connection tools: the node keeps every other tool a
|
|
7
|
+
* step with no `tools` is offered.
|
|
8
|
+
*/
|
|
9
|
+
const CEILINGS = new WeakMap();
|
|
10
|
+
/** Records `picks` as the most of the turn's connections `step` may be offered. */
|
|
11
|
+
export function setConnectionCeiling(step, picks) {
|
|
12
|
+
CEILINGS.set(step, picks);
|
|
13
|
+
}
|
|
14
|
+
/** The ceiling recorded on `step`, when a document node built it. */
|
|
15
|
+
export function connectionCeilingOf(step) {
|
|
16
|
+
return CEILINGS.get(step);
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connections a JSON document declares as `{ "mcp": … }` entries in its
|
|
3
|
+
* `connections`. The hydrator records them on the step it builds for the
|
|
4
|
+
* document, and the turn attaches them, as it does a step's `tools` entries,
|
|
5
|
+
* before the tool set is built: every node of the document reaches them by
|
|
6
|
+
* name, and they are released with the turn.
|
|
7
|
+
*/
|
|
8
|
+
import type { Step } from '@noetic-tools/types';
|
|
9
|
+
import type { AttachedEntry } from '../types/connection-entry.js';
|
|
10
|
+
/** Records the entries a document declares on the step built for it. */
|
|
11
|
+
export declare function setDocumentEntries(step: Step, entries: ReadonlyArray<AttachedEntry>): void;
|
|
12
|
+
/** The entries a document declares, when `step` is the one built for it. */
|
|
13
|
+
export declare function documentEntriesOf(step: Step): ReadonlyArray<AttachedEntry>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connections a JSON document declares as `{ "mcp": … }` entries in its
|
|
3
|
+
* `connections`. The hydrator records them on the step it builds for the
|
|
4
|
+
* document, and the turn attaches them, as it does a step's `tools` entries,
|
|
5
|
+
* before the tool set is built: every node of the document reaches them by
|
|
6
|
+
* name, and they are released with the turn.
|
|
7
|
+
*/
|
|
8
|
+
const ENTRIES = new WeakMap();
|
|
9
|
+
/** Records the entries a document declares on the step built for it. */
|
|
10
|
+
export function setDocumentEntries(step, entries) {
|
|
11
|
+
if (entries.length > 0) {
|
|
12
|
+
ENTRIES.set(step, entries);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** The entries a document declares, when `step` is the one built for it. */
|
|
16
|
+
export function documentEntriesOf(step) {
|
|
17
|
+
return ENTRIES.get(step) ?? [];
|
|
18
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* then hydrates and runs it within the same harness session.
|
|
4
4
|
*/
|
|
5
5
|
import type { ContextData, ContextLayer } from '@noetic-tools/context';
|
|
6
|
-
import type { AgentHarnessContract, ConnectionAllowlist, Context, Step, Tool } from '@noetic-tools/types';
|
|
6
|
+
import type { AcpAgent, AcpAllowlist, AgentHarnessContract, ConnectionAllowlist, Context, McpAllowlist, Step, Tool } from '@noetic-tools/types';
|
|
7
7
|
import type { ExpressionLimits } from '../expression/jsonata.js';
|
|
8
8
|
import type { WorkflowDocument } from '../schemas/workflow.js';
|
|
9
9
|
/** @public Options for creating a dynamic workflow step. */
|
|
@@ -17,11 +17,29 @@ export interface DynamicWorkflowOpts {
|
|
|
17
17
|
expressionLimits?: ExpressionLimits;
|
|
18
18
|
/**
|
|
19
19
|
* What a generated document may use of the harness's connections (spec 35 §
|
|
20
|
-
* What a document may use).
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* What a document may use). Absent grants none, like `{}`: a document asking
|
|
21
|
+
* for a connection fails validation with `CONNECTION_NOT_ALLOWED`, and a
|
|
22
|
+
* node with no `tools` gets only the granted connections. The planner is
|
|
23
|
+
* shown only these connections.
|
|
23
24
|
*/
|
|
24
25
|
connections?: ConnectionAllowlist;
|
|
26
|
+
/** ACP agent adapters, keyed by `agentId`, that the document's `acp-agent` nodes may run. Default: none. */
|
|
27
|
+
acpAgents?: ReadonlyMap<string, AcpAgent>;
|
|
28
|
+
/**
|
|
29
|
+
* The most a generated `acp-agent` node may ask of each agent: permissions,
|
|
30
|
+
* `cwd`, client capabilities and sessions (spec 26 § ACP agents). An agent
|
|
31
|
+
* without an entry gets the narrowest defaults; a node asking for more fails
|
|
32
|
+
* validation with `CONNECTION_NOT_ALLOWED`. The planner is shown these limits.
|
|
33
|
+
*/
|
|
34
|
+
acp?: AcpAllowlist;
|
|
35
|
+
/**
|
|
36
|
+
* The MCP servers a generated document may attach — `{ "mcp" }` entries in
|
|
37
|
+
* `tools` or `connections` — with the secrets and policy each grant sets
|
|
38
|
+
* and the `provider` that builds them (spec 26 § MCP servers). Without it, a
|
|
39
|
+
* node naming any server fails validation with `CONNECTION_NOT_ALLOWED`. The
|
|
40
|
+
* planner is shown only the granted URLs.
|
|
41
|
+
*/
|
|
42
|
+
mcp?: McpAllowlist;
|
|
25
43
|
}
|
|
26
44
|
/**
|
|
27
45
|
* Creates a step that uses an LLM to generate a workflow as JSON, then
|
|
@@ -38,6 +56,7 @@ export interface DynamicWorkflowOpts {
|
|
|
38
56
|
* @returns A `Step` that dynamically plans and executes.
|
|
39
57
|
* @throws `NoeticConfigError` with code `INVALID_EXPRESSION_LIMITS` (at execution) if `expressionLimits` holds a value that is not a positive integer or `Infinity`.
|
|
40
58
|
* @throws `NoeticConfigError` with code `EXPRESSION_LIMIT_EXCEEDED` (at execution) if an expression in the generated workflow exceeds its limits.
|
|
59
|
+
* @throws `NoeticConfigError` with code `CONNECTION_NOT_ALLOWED` (at execution) if, on the last revision, the document asks for more than `connections`, `acp` or `mcp` grants.
|
|
41
60
|
*/
|
|
42
61
|
export declare function dynamicWorkflow(opts: DynamicWorkflowOpts): Step<ContextData, string, string>;
|
|
43
62
|
/** @public Options for `parseAndRunWorkflow`. */
|
|
@@ -54,7 +73,12 @@ export interface ParseAndRunWorkflowOpts {
|
|
|
54
73
|
* host that runs layer-bearing workflows must pass its layers here.
|
|
55
74
|
*/
|
|
56
75
|
layers?: ReadonlyMap<string, ContextLayer>;
|
|
57
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Named sub-workflows the document's `subflow` nodes may reference via `ref`.
|
|
78
|
+
* A named workflow runs as the host wrote it, not held to `connections`,
|
|
79
|
+
* `acp` or `mcp`: register only workflows you would let any document run
|
|
80
|
+
* with their own settings.
|
|
81
|
+
*/
|
|
58
82
|
workflows?: ReadonlyMap<string, WorkflowDocument>;
|
|
59
83
|
/**
|
|
60
84
|
* Deepest allowed chain of named-ref resolutions on one execution path —
|
|
@@ -66,10 +90,30 @@ export interface ParseAndRunWorkflowOpts {
|
|
|
66
90
|
expressionLimits?: ExpressionLimits;
|
|
67
91
|
/**
|
|
68
92
|
* What the document may use of the harness's connections (spec 35 § What a
|
|
69
|
-
* document may use).
|
|
70
|
-
* `
|
|
93
|
+
* document may use). Absent grants none, like `{}`, as `acp` and `mcp` do:
|
|
94
|
+
* a manifest entry, `{ "connection" }` pick or connection node asking for an
|
|
95
|
+
* ungranted connection fails with `CONNECTION_NOT_ALLOWED`, and a
|
|
96
|
+
* `callModel` or `acp-agent` node with no `tools` gets only the granted
|
|
97
|
+
* connections. A host that trusts the document passes the grants it wants.
|
|
71
98
|
*/
|
|
72
99
|
connections?: ConnectionAllowlist;
|
|
100
|
+
/** ACP agent adapters, keyed by `agentId`, that the document's `acp-agent` nodes may run. Default: none. */
|
|
101
|
+
acpAgents?: ReadonlyMap<string, AcpAgent>;
|
|
102
|
+
/**
|
|
103
|
+
* The most the document's `acp-agent` nodes may ask of each agent:
|
|
104
|
+
* permissions, `cwd`, client capabilities and sessions (spec 26 § ACP
|
|
105
|
+
* agents). An agent without an entry gets the narrowest defaults; a node
|
|
106
|
+
* asking for more fails validation with `CONNECTION_NOT_ALLOWED`.
|
|
107
|
+
*/
|
|
108
|
+
acp?: AcpAllowlist;
|
|
109
|
+
/**
|
|
110
|
+
* The MCP servers the document may attach — `{ "mcp" }` entries in `tools`
|
|
111
|
+
* or `connections` — with the secrets and policy each grant sets and
|
|
112
|
+
* the `provider` that builds them (spec 26 § MCP servers). Unlike
|
|
113
|
+
* `connections`, absence grants nothing: a node naming any server fails
|
|
114
|
+
* validation with `CONNECTION_NOT_ALLOWED`.
|
|
115
|
+
*/
|
|
116
|
+
mcp?: McpAllowlist;
|
|
73
117
|
}
|
|
74
118
|
/**
|
|
75
119
|
* Parses raw JSON into a `WorkflowDocument`, hydrates it into a live step
|
|
@@ -90,6 +134,7 @@ export interface ParseAndRunWorkflowOpts {
|
|
|
90
134
|
* @throws `NoeticConfigError` with code `INVALID_EXPRESSION_LIMITS` if `expressionLimits` holds a value that is not a positive integer or `Infinity`.
|
|
91
135
|
* @throws `NoeticConfigError` with code `EXPRESSION_LIMIT_EXCEEDED` if an expression exceeds its limits.
|
|
92
136
|
* @throws `NoeticConfigError` with code `CONNECTION_UNKNOWN` if a node uses a connection the document does not declare, or the allowlist names one the harness does not have.
|
|
93
|
-
* @throws `NoeticConfigError` with code `CONNECTION_NOT_ALLOWED` if the document asks for more than `connections` grants.
|
|
137
|
+
* @throws `NoeticConfigError` with code `CONNECTION_NOT_ALLOWED` if the document asks for more than `connections` grants (none when absent), an `acp-agent` node asks for more than `acp` grants, or the document names an MCP server `mcp` does not grant.
|
|
138
|
+
* @throws `NoeticConfigError` with code `CONNECTION_INVALID` if an MCP server uses a `$secret` and the harness has no `environment.secrets`.
|
|
94
139
|
*/
|
|
95
140
|
export declare function parseAndRunWorkflow(opts: ParseAndRunWorkflowOpts): Promise<string>;
|