@noetic-tools/core 5.19.1-next.1 → 5.19.2
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.js +5 -0
- package/dist/builders/control-flow-builders.d.ts +15 -6
- package/dist/builders/control-flow-builders.js +8 -0
- package/dist/builders/decide-builders.d.ts +2 -5
- package/dist/builders/dynamic-workflow.d.ts +16 -1
- package/dist/builders/dynamic-workflow.js +222 -11
- package/dist/builders/every.d.ts +3 -3
- package/dist/builders/every.js +2 -1
- package/dist/builders/provide-builder.d.ts +3 -2
- package/dist/builders/provide-builder.js +2 -1
- package/dist/builders/sequence.d.ts +14 -0
- package/dist/builders/sequence.js +103 -0
- package/dist/builders/spawn-builder.d.ts +3 -2
- package/dist/builders/spawn-builder.js +3 -2
- package/dist/builders/step-builders.d.ts +80 -1
- package/dist/builders/step-builders.js +115 -1
- package/dist/builders/verify-builder.d.ts +79 -0
- package/dist/builders/verify-builder.js +69 -0
- package/dist/builders/workflow-child-nodes.d.ts +21 -0
- package/dist/builders/workflow-child-nodes.js +335 -0
- package/dist/builders/workflow-connection-nodes.d.ts +17 -0
- package/dist/builders/workflow-connection-nodes.js +160 -0
- package/dist/builders/workflow-connections.d.ts +90 -0
- package/dist/builders/workflow-connections.js +560 -0
- package/dist/builders/workflow-control-nodes.d.ts +13 -0
- package/dist/builders/workflow-control-nodes.js +213 -0
- package/dist/builders/workflow-hydrator.d.ts +44 -3
- package/dist/builders/workflow-hydrator.js +53 -495
- package/dist/builders/workflow-verify.d.ts +19 -0
- package/dist/builders/workflow-verify.js +194 -0
- package/dist/conditions/conditions.d.ts +7 -5
- package/dist/conditions/conditions.js +7 -4
- package/dist/connections/blobs.d.ts +33 -0
- package/dist/connections/blobs.js +77 -0
- package/dist/connections/cron-schedule.d.ts +32 -0
- package/dist/connections/cron-schedule.js +213 -0
- package/dist/connections/durability.d.ts +65 -0
- package/dist/connections/durability.js +54 -0
- package/dist/connections/errors.d.ts +30 -0
- package/dist/connections/errors.js +100 -0
- package/dist/connections/event-stream.d.ts +24 -0
- package/dist/connections/event-stream.js +176 -0
- package/dist/connections/gates.d.ts +94 -0
- package/dist/connections/gates.js +271 -0
- package/dist/connections/glob.d.ts +10 -0
- package/dist/connections/glob.js +46 -0
- package/dist/connections/handle.d.ts +22 -0
- package/dist/connections/handle.js +84 -0
- package/dist/connections/harness-wiring.d.ts +52 -0
- package/dist/connections/harness-wiring.js +143 -0
- package/dist/connections/in-memory-connection.d.ts +147 -0
- package/dist/connections/in-memory-connection.js +593 -0
- package/dist/connections/index.d.ts +34 -0
- package/dist/connections/index.js +23 -0
- package/dist/connections/json-schema.d.ts +28 -0
- package/dist/connections/json-schema.js +338 -0
- package/dist/connections/model-tools.d.ts +46 -0
- package/dist/connections/model-tools.js +466 -0
- package/dist/connections/negotiation.d.ts +30 -0
- package/dist/connections/negotiation.js +159 -0
- package/dist/connections/policy.d.ts +21 -0
- package/dist/connections/policy.js +34 -0
- package/dist/connections/pool.d.ts +111 -0
- package/dist/connections/pool.js +339 -0
- package/dist/connections/refs.d.ts +74 -0
- package/dist/connections/refs.js +316 -0
- package/dist/connections/registry-types.d.ts +141 -0
- package/dist/connections/registry-types.js +14 -0
- package/dist/connections/registry.d.ts +125 -0
- package/dist/connections/registry.js +775 -0
- package/dist/connections/secrets.d.ts +59 -0
- package/dist/connections/secrets.js +153 -0
- package/dist/connections/settle.d.ts +9 -0
- package/dist/connections/settle.js +26 -0
- package/dist/connections/sources.d.ts +27 -0
- package/dist/connections/sources.js +300 -0
- package/dist/connections/triggers.d.ts +78 -0
- package/dist/connections/triggers.js +310 -0
- package/dist/connections/values.d.ts +26 -0
- package/dist/connections/values.js +93 -0
- package/dist/connections/views.d.ts +31 -0
- package/dist/connections/views.js +176 -0
- package/dist/expression/check.js +80 -1
- package/dist/expression/jsonata.d.ts +14 -4
- package/dist/expression/jsonata.js +27 -9
- package/dist/expression/step-outputs.d.ts +25 -0
- package/dist/expression/step-outputs.js +78 -0
- package/dist/harness/agent-harness.d.ts +69 -166
- package/dist/harness/agent-harness.js +170 -262
- package/dist/harness/call-span-collector.d.ts +33 -0
- package/dist/harness/call-span-collector.js +83 -0
- package/dist/harness/call-spend.d.ts +2 -0
- package/dist/harness/call-spend.js +10 -14
- package/dist/harness/connection-gate.d.ts +78 -0
- package/dist/harness/connection-gate.js +169 -0
- package/dist/harness/deps/interpreter.d.ts +1 -0
- package/dist/harness/deps/interpreter.js +1 -0
- package/dist/harness/deps/runtime.d.ts +1 -1
- package/dist/harness/deps/types.d.ts +1 -1
- package/dist/harness/harness-options.d.ts +153 -0
- package/dist/harness/harness-options.js +36 -0
- package/dist/harness/harness-tracing.d.ts +16 -0
- package/dist/harness/harness-tracing.js +35 -0
- package/dist/harness/llm-client.d.ts +71 -0
- package/dist/harness/llm-client.js +218 -0
- package/dist/harness/model-call.d.ts +2 -7
- package/dist/harness/model-call.js +141 -558
- package/dist/harness/model-request.d.ts +42 -0
- package/dist/harness/model-request.js +159 -0
- package/dist/harness/model-rounds.d.ts +18 -2
- package/dist/harness/model-rounds.js +39 -8
- package/dist/harness/model-stream.d.ts +39 -0
- package/dist/harness/model-stream.js +131 -0
- package/dist/harness/model-tool-round.d.ts +37 -0
- package/dist/harness/model-tool-round.js +197 -0
- package/dist/harness/spend.d.ts +2 -0
- package/dist/harness/spend.js +5 -1
- package/dist/index.d.ts +31 -6
- package/dist/index.js +18 -1
- package/dist/interpreter/connection-steps.d.ts +194 -0
- package/dist/interpreter/connection-steps.js +537 -0
- package/dist/interpreter/execute-action.d.ts +2 -8
- package/dist/interpreter/execute-action.js +3 -178
- package/dist/interpreter/execute-call.d.ts +19 -0
- package/dist/interpreter/execute-call.js +99 -0
- package/dist/interpreter/execute-control.d.ts +6 -1
- package/dist/interpreter/execute-control.js +14 -0
- package/dist/interpreter/execute-invoke-tool.d.ts +11 -0
- package/dist/interpreter/execute-invoke-tool.js +183 -0
- package/dist/interpreter/execute-verify.d.ts +21 -0
- package/dist/interpreter/execute-verify.js +391 -0
- package/dist/interpreter/execute-wait.d.ts +21 -0
- package/dist/interpreter/execute-wait.js +233 -0
- package/dist/interpreter/execute.js +24 -133
- package/dist/interpreter/step-kind-dispatch.d.ts +24 -0
- package/dist/interpreter/step-kind-dispatch.js +157 -0
- package/dist/interpreter/step-walk.d.ts +2 -0
- package/dist/interpreter/step-walk.js +24 -0
- package/dist/interpreter/verify-host.d.ts +40 -0
- package/dist/interpreter/verify-host.js +245 -0
- package/dist/runtime/durable/step-ledger.d.ts +34 -2
- package/dist/runtime/durable/step-ledger.js +97 -3
- package/dist/runtime/in-memory-artifact-store.d.ts +24 -0
- package/dist/runtime/in-memory-artifact-store.js +240 -0
- package/dist/schemas/workflow.d.ts +2 -2
- package/dist/schemas/workflow.js +1 -1
- package/dist/util/harness-internals.d.ts +23 -0
- package/dist/util/harness-internals.js +35 -0
- package/package.json +3 -3
- package/schema/noetic-workflow.schema.json +1170 -92
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { frameworkCast, NoeticErrorImpl } from '@noetic-tools/types';
|
|
2
|
+
import { recordedScopeOf, recordStepOutput } from '../expression/step-outputs.js';
|
|
2
3
|
import { emitFrameworkEvent, getBroadcaster, shouldEmit } from '../runtime/broadcaster-utils.js';
|
|
3
4
|
import { ContextImpl } from '../runtime/context-impl.js';
|
|
4
5
|
import { drainsOf } from '../runtime/drain.js';
|
|
5
6
|
import { REPLAY_KEY_PREFIX } from '../runtime/durable/step-ledger.js';
|
|
6
|
-
import { DetachedHandleImpl } from '../util/detached-handle.js';
|
|
7
7
|
import { allowCustomItems, appendReplayed, beginEmitItems, emitStepItems } from './emit-items.js';
|
|
8
|
-
import {
|
|
9
|
-
import { executeCallModel, executeInvokeTool, executeRunCode, executeSpawn, executeWithContext, } from './execute-action.js';
|
|
10
|
-
import { executeConditional, executeInParallel, executeLoop, executeSchedule, } from './execute-control.js';
|
|
11
|
-
import { executeDecide } from './execute-decide.js';
|
|
8
|
+
import { dispatchStepKind, executeLocally } from './step-kind-dispatch.js';
|
|
12
9
|
import { isMutableContext } from './typeguards.js';
|
|
13
10
|
//#region Constants
|
|
14
11
|
const MAX_DEPTH = 64;
|
|
@@ -23,17 +20,6 @@ const MAX_DEPTH = 64;
|
|
|
23
20
|
function asContextImpl(ctx) {
|
|
24
21
|
return ctx instanceof ContextImpl ? ctx : null;
|
|
25
22
|
}
|
|
26
|
-
function harnessWithLayerStore(ctx) {
|
|
27
|
-
return frameworkCast(ctx.harness);
|
|
28
|
-
}
|
|
29
|
-
function buildSpawnOpts(ctx) {
|
|
30
|
-
const baseCtx = frameworkCast(ctx);
|
|
31
|
-
return {
|
|
32
|
-
itemSchemas: baseCtx.itemSchemas,
|
|
33
|
-
parentLayers: baseCtx.layers,
|
|
34
|
-
layerStore: harnessWithLayerStore(baseCtx).layerStateStore,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
23
|
/**
|
|
38
24
|
* Resolve the per-step framework-event emit option. `callModel`, `decide`, and
|
|
39
25
|
* the harness step kinds carry an `emit` field; every other kind defaults to
|
|
@@ -45,51 +31,6 @@ function resolveStepEmit(step) {
|
|
|
45
31
|
}
|
|
46
32
|
return undefined;
|
|
47
33
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Resolve the subprocess adapter that should handle dispatch for this step.
|
|
50
|
-
* Precedence is `step.subprocess ?? ctx.harness.subprocess`. Per-call
|
|
51
|
-
* `detachedSpawn` overrides layer above this in the harness itself.
|
|
52
|
-
*/
|
|
53
|
-
function resolveStepAdapter(step, ctx) {
|
|
54
|
-
if ((step.kind === 'runCode' || step.kind === 'spawn') && step.subprocess) {
|
|
55
|
-
return step.subprocess;
|
|
56
|
-
}
|
|
57
|
-
return ctx.harness.subprocess;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Dispatch a run/spawn step through the resolved subprocess adapter.
|
|
61
|
-
*
|
|
62
|
-
* The `_localExecutor` closure carries the in-process fallback path — the
|
|
63
|
-
* in-memory adapter invokes it directly, preserving the pre-refactor
|
|
64
|
-
* dispatch semantics including parent-context inheritance, layer lifecycle,
|
|
65
|
-
* and synchronous error propagation. Out-of-process adapters ignore
|
|
66
|
-
* `_localExecutor` and run the step in a child runtime.
|
|
67
|
-
*
|
|
68
|
-
* `executionId` names the context the step body runs in: `ctx.id` for a
|
|
69
|
-
* `runCode`, the pre-allocated child id for a `spawn` (whose request then
|
|
70
|
-
* also names `ctx` as the parent).
|
|
71
|
-
*/
|
|
72
|
-
async function dispatchViaAdapter(step, input, ctx, executionId, executor) {
|
|
73
|
-
const adapter = resolveStepAdapter(step, ctx);
|
|
74
|
-
const request = {
|
|
75
|
-
kind: 'step',
|
|
76
|
-
stepId: step.id,
|
|
77
|
-
serializedInput: input,
|
|
78
|
-
executionId,
|
|
79
|
-
parentExecutionId: executionId === ctx.id ? undefined : ctx.id,
|
|
80
|
-
overrides: {
|
|
81
|
-
threadId: ctx.threadId,
|
|
82
|
-
resourceId: ctx.resourceId,
|
|
83
|
-
},
|
|
84
|
-
_localExecutor: () => executor(),
|
|
85
|
-
};
|
|
86
|
-
const handle = new DetachedHandleImpl({
|
|
87
|
-
id: executionId,
|
|
88
|
-
stepId: step.id,
|
|
89
|
-
spawned: adapter.spawn(request),
|
|
90
|
-
});
|
|
91
|
-
return handle.await();
|
|
92
|
-
}
|
|
93
34
|
/**
|
|
94
35
|
* @internal
|
|
95
36
|
* Dispatch a step at the per-kind handler level without adapter routing.
|
|
@@ -103,19 +44,7 @@ async function dispatchViaAdapter(step, input, ctx, executionId, executor) {
|
|
|
103
44
|
* continue to work.
|
|
104
45
|
*/
|
|
105
46
|
export async function executeNoAdapter(step, input, ctx) {
|
|
106
|
-
|
|
107
|
-
case 'runCode':
|
|
108
|
-
return executeRunCode(step, input, ctx);
|
|
109
|
-
case 'spawn':
|
|
110
|
-
return executeSpawn(step, input, ctx, (s, i, c) => execute(s, i, c), buildSpawnOpts(ctx));
|
|
111
|
-
default:
|
|
112
|
-
// Kinds that don't currently route through the adapter (callModel,
|
|
113
|
-
// invokeTool, conditional, inParallel, withContext, loop, schedule).
|
|
114
|
-
// Delegate back to `execute()`
|
|
115
|
-
// so they exercise the normal dispatch table, framework-event emits,
|
|
116
|
-
// abort checks, and depth guard.
|
|
117
|
-
return execute(step, input, ctx);
|
|
118
|
-
}
|
|
47
|
+
return executeLocally(step, input, ctx, (s, i, c) => execute(s, i, c));
|
|
119
48
|
}
|
|
120
49
|
/**
|
|
121
50
|
* @internal
|
|
@@ -327,73 +256,35 @@ export async function execute(step, input, ctx) {
|
|
|
327
256
|
});
|
|
328
257
|
if (replay.hit) {
|
|
329
258
|
lane?.leaveStep(frame);
|
|
259
|
+
const replayScope = recordedScopeOf(step);
|
|
260
|
+
if (replayScope) {
|
|
261
|
+
recordStepOutput(baseCtx, {
|
|
262
|
+
scope: replayScope,
|
|
263
|
+
id: step.id,
|
|
264
|
+
}, replay.output);
|
|
265
|
+
}
|
|
330
266
|
return replay.output;
|
|
331
267
|
}
|
|
332
268
|
let result;
|
|
333
269
|
try {
|
|
334
270
|
await beginEmitItems(step, input, stepCtx);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
break;
|
|
342
|
-
case 'acp-agent':
|
|
343
|
-
result = await executeAcpAgent(step, input, stepCtx, baseCtx.layers);
|
|
344
|
-
break;
|
|
345
|
-
case 'invokeTool':
|
|
346
|
-
result = await executeInvokeTool(step, input, stepCtx, baseCtx.harness, baseCtx.layers);
|
|
347
|
-
break;
|
|
348
|
-
case 'decide':
|
|
349
|
-
result = await executeDecide(step, input, stepCtx, baseCtx.layers);
|
|
350
|
-
break;
|
|
351
|
-
case 'conditional':
|
|
352
|
-
result = await executeConditional(step, input, stepCtx, (s, i, c) => execute(s, i, c));
|
|
353
|
-
break;
|
|
354
|
-
case 'inParallel':
|
|
355
|
-
result = await executeInParallel(step, input, stepCtx, (s, i, c) => execute(s, i, c), {
|
|
356
|
-
// Fork paths are child executions: the layer store lets their
|
|
357
|
-
// `onSpawn`/`onReturn` boundary run (see `createForkLayerBridge`).
|
|
358
|
-
layerStore: harnessWithLayerStore(baseCtx).layerStateStore,
|
|
359
|
-
itemSchemas: baseCtx.itemSchemas,
|
|
360
|
-
});
|
|
361
|
-
break;
|
|
362
|
-
case 'spawn': {
|
|
363
|
-
// Allocated here so the adapter request names the child it runs.
|
|
364
|
-
const childId = crypto.randomUUID();
|
|
365
|
-
result = await dispatchViaAdapter(step, input, stepCtx, childId, () => executeSpawn(step, input, stepCtx, (s, i, c) => execute(s, i, c), {
|
|
366
|
-
...buildSpawnOpts(stepCtx),
|
|
367
|
-
childId,
|
|
368
|
-
}));
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
case 'withContext':
|
|
372
|
-
result = await executeWithContext(step, input, stepCtx, (s, i, c) => execute(s, i, c), {
|
|
373
|
-
layerStore: harnessWithLayerStore(baseCtx).layerStateStore,
|
|
374
|
-
storage: harnessWithLayerStore(baseCtx).config?.storage,
|
|
375
|
-
});
|
|
376
|
-
break;
|
|
377
|
-
case 'loop':
|
|
378
|
-
result = await executeLoop(step, input, stepCtx, (s, i, c) => execute(s, i, c));
|
|
379
|
-
break;
|
|
380
|
-
case 'schedule':
|
|
381
|
-
result = await executeSchedule(step, input, stepCtx, (s, i, c) => execute(s, i, c));
|
|
382
|
-
break;
|
|
383
|
-
default: {
|
|
384
|
-
const _exhaustive = step;
|
|
385
|
-
void _exhaustive;
|
|
386
|
-
throw new NoeticErrorImpl({
|
|
387
|
-
kind: 'step_failed',
|
|
388
|
-
stepId: 'unknown',
|
|
389
|
-
cause: new Error('Unknown step kind'),
|
|
390
|
-
retriesExhausted: false,
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
}
|
|
271
|
+
result = await dispatchStepKind(step, input, {
|
|
272
|
+
stepCtx,
|
|
273
|
+
baseCtx,
|
|
274
|
+
ledgerKey,
|
|
275
|
+
executeStep: (s, i, c) => execute(s, i, c),
|
|
276
|
+
});
|
|
394
277
|
// Inside the try, so an item the schemas refuse fails the dispatch like any other
|
|
395
278
|
// error; before the ledger record, so the entry holds the items and replays them.
|
|
396
279
|
await emitStepItems(step, result, stepCtx);
|
|
280
|
+
// A JSON workflow node's output is readable as `$steps.<id>` from here on (spec 33).
|
|
281
|
+
const outputScope = recordedScopeOf(step);
|
|
282
|
+
if (outputScope) {
|
|
283
|
+
recordStepOutput(baseCtx, {
|
|
284
|
+
scope: outputScope,
|
|
285
|
+
id: step.id,
|
|
286
|
+
}, result);
|
|
287
|
+
}
|
|
397
288
|
}
|
|
398
289
|
catch (error) {
|
|
399
290
|
lane?.releaseDispatch();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-kind step routing: maps each step kind to its handler, and sends
|
|
3
|
+
* `runCode`/`spawn` through the resolved subprocess adapter. `execute()` owns
|
|
4
|
+
* the step lifecycle around this (depth/abort guards, events, ledger, checkpoint).
|
|
5
|
+
*/
|
|
6
|
+
import type { Context, ExecuteStepFn, Step } from '@noetic-tools/types';
|
|
7
|
+
/** What a kind handler needs beyond the step and its input. */
|
|
8
|
+
export interface StepKindScope<TContext> {
|
|
9
|
+
/** The step's own lane — the context its body runs in. */
|
|
10
|
+
stepCtx: Context<TContext>;
|
|
11
|
+
/** The dispatching context, which carries the layers and the harness. */
|
|
12
|
+
baseCtx: Context;
|
|
13
|
+
/** The ledger key `execute()` resolved for this dispatch. */
|
|
14
|
+
ledgerKey: string | undefined;
|
|
15
|
+
/** Re-enters `execute()` for nested steps. */
|
|
16
|
+
executeStep: ExecuteStepFn;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Run a `runCode`/`spawn` step's handler in-process, without adapter routing;
|
|
20
|
+
* every other kind re-enters `executeStep` so it gets the full dispatch path.
|
|
21
|
+
*/
|
|
22
|
+
export declare function executeLocally<TContext, I, O>(step: Step<TContext, I, O>, input: I, ctx: Context<TContext>, executeStep: ExecuteStepFn): Promise<O>;
|
|
23
|
+
/** Route a step to its kind's handler and return the handler's output. */
|
|
24
|
+
export declare function dispatchStepKind<TContext, I, O>(step: Step<TContext, I, O>, input: I, scope: StepKindScope<TContext>): Promise<O>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-kind step routing: maps each step kind to its handler, and sends
|
|
3
|
+
* `runCode`/`spawn` through the resolved subprocess adapter. `execute()` owns
|
|
4
|
+
* the step lifecycle around this (depth/abort guards, events, ledger, checkpoint).
|
|
5
|
+
*/
|
|
6
|
+
import { frameworkCast, NoeticErrorImpl } from '@noetic-tools/types';
|
|
7
|
+
import { DetachedHandleImpl } from '../util/detached-handle.js';
|
|
8
|
+
import { executeAcpAgent } from './execute-acp-agent.js';
|
|
9
|
+
import { executeCallModel, executeRunCode, executeSpawn, executeWithContext, } from './execute-action.js';
|
|
10
|
+
import { executeCall } from './execute-call.js';
|
|
11
|
+
import { executeConditional, executeInParallel, executeLoop, executeSchedule, executeSequence, } from './execute-control.js';
|
|
12
|
+
import { executeDecide } from './execute-decide.js';
|
|
13
|
+
import { executeInvokeTool } from './execute-invoke-tool.js';
|
|
14
|
+
import { executeVerify } from './execute-verify.js';
|
|
15
|
+
import { executeWait } from './execute-wait.js';
|
|
16
|
+
function harnessWithLayerStore(ctx) {
|
|
17
|
+
return frameworkCast(ctx.harness);
|
|
18
|
+
}
|
|
19
|
+
function buildSpawnOpts(ctx) {
|
|
20
|
+
const baseCtx = frameworkCast(ctx);
|
|
21
|
+
return {
|
|
22
|
+
itemSchemas: baseCtx.itemSchemas,
|
|
23
|
+
parentLayers: baseCtx.layers,
|
|
24
|
+
layerStore: harnessWithLayerStore(baseCtx).layerStateStore,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the subprocess adapter that should handle dispatch for this step.
|
|
29
|
+
* Precedence is `step.subprocess ?? ctx.harness.subprocess`. Per-call
|
|
30
|
+
* `detachedSpawn` overrides layer above this in the harness itself.
|
|
31
|
+
*/
|
|
32
|
+
function resolveStepAdapter(step, ctx) {
|
|
33
|
+
if ((step.kind === 'runCode' || step.kind === 'spawn') && step.subprocess) {
|
|
34
|
+
return step.subprocess;
|
|
35
|
+
}
|
|
36
|
+
return ctx.harness.subprocess;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Dispatch a run/spawn step through the resolved subprocess adapter.
|
|
40
|
+
*
|
|
41
|
+
* The `_localExecutor` closure carries the in-process fallback path — the
|
|
42
|
+
* in-memory adapter invokes it directly, preserving the pre-refactor
|
|
43
|
+
* dispatch semantics including parent-context inheritance, layer lifecycle,
|
|
44
|
+
* and synchronous error propagation. Out-of-process adapters ignore
|
|
45
|
+
* `_localExecutor` and run the step in a child runtime.
|
|
46
|
+
*
|
|
47
|
+
* `executionId` names the context the step body runs in: `ctx.id` for a
|
|
48
|
+
* `runCode`, the pre-allocated child id for a `spawn` (whose request then
|
|
49
|
+
* also names `ctx` as the parent).
|
|
50
|
+
*/
|
|
51
|
+
async function dispatchViaAdapter(step, input, ctx, executionId, executor) {
|
|
52
|
+
const adapter = resolveStepAdapter(step, ctx);
|
|
53
|
+
const request = {
|
|
54
|
+
kind: 'step',
|
|
55
|
+
stepId: step.id,
|
|
56
|
+
serializedInput: input,
|
|
57
|
+
executionId,
|
|
58
|
+
parentExecutionId: executionId === ctx.id ? undefined : ctx.id,
|
|
59
|
+
overrides: {
|
|
60
|
+
threadId: ctx.threadId,
|
|
61
|
+
resourceId: ctx.resourceId,
|
|
62
|
+
},
|
|
63
|
+
_localExecutor: () => executor(),
|
|
64
|
+
};
|
|
65
|
+
const handle = new DetachedHandleImpl({
|
|
66
|
+
id: executionId,
|
|
67
|
+
stepId: step.id,
|
|
68
|
+
spawned: adapter.spawn(request),
|
|
69
|
+
});
|
|
70
|
+
return handle.await();
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region Public API
|
|
74
|
+
/**
|
|
75
|
+
* Run a `runCode`/`spawn` step's handler in-process, without adapter routing;
|
|
76
|
+
* every other kind re-enters `executeStep` so it gets the full dispatch path.
|
|
77
|
+
*/
|
|
78
|
+
export function executeLocally(step, input, ctx, executeStep) {
|
|
79
|
+
switch (step.kind) {
|
|
80
|
+
case 'runCode':
|
|
81
|
+
return executeRunCode(step, input, ctx);
|
|
82
|
+
case 'spawn':
|
|
83
|
+
return executeSpawn(step, input, ctx, executeStep, buildSpawnOpts(ctx));
|
|
84
|
+
default:
|
|
85
|
+
// Kinds that don't currently route through the adapter (callModel,
|
|
86
|
+
// invokeTool, conditional, inParallel, withContext, loop, schedule).
|
|
87
|
+
// Delegate back to `execute()`
|
|
88
|
+
// so they exercise the normal dispatch table, framework-event emits,
|
|
89
|
+
// abort checks, and depth guard.
|
|
90
|
+
return executeStep(step, input, ctx);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Route a step to its kind's handler and return the handler's output. */
|
|
94
|
+
export async function dispatchStepKind(step, input, scope) {
|
|
95
|
+
const { stepCtx, baseCtx, ledgerKey, executeStep } = scope;
|
|
96
|
+
switch (step.kind) {
|
|
97
|
+
case 'runCode':
|
|
98
|
+
return dispatchViaAdapter(step, input, stepCtx, stepCtx.id, () => executeRunCode(step, input, stepCtx));
|
|
99
|
+
case 'callModel':
|
|
100
|
+
return executeCallModel(step, input, stepCtx, baseCtx.layers);
|
|
101
|
+
case 'acp-agent':
|
|
102
|
+
return executeAcpAgent(step, input, stepCtx, baseCtx.layers);
|
|
103
|
+
case 'invokeTool':
|
|
104
|
+
return executeInvokeTool(step, input, stepCtx, baseCtx.harness, baseCtx.layers);
|
|
105
|
+
case 'decide':
|
|
106
|
+
return executeDecide(step, input, stepCtx, baseCtx.layers);
|
|
107
|
+
case 'conditional':
|
|
108
|
+
return executeConditional(step, input, stepCtx, executeStep);
|
|
109
|
+
case 'inParallel':
|
|
110
|
+
return executeInParallel(step, input, stepCtx, executeStep, {
|
|
111
|
+
// Fork paths are child executions: the layer store lets their
|
|
112
|
+
// `onSpawn`/`onReturn` boundary run (see `createForkLayerBridge`).
|
|
113
|
+
layerStore: harnessWithLayerStore(baseCtx).layerStateStore,
|
|
114
|
+
itemSchemas: baseCtx.itemSchemas,
|
|
115
|
+
});
|
|
116
|
+
case 'spawn': {
|
|
117
|
+
// Allocated here so the adapter request names the child it runs.
|
|
118
|
+
const childId = crypto.randomUUID();
|
|
119
|
+
return dispatchViaAdapter(step, input, stepCtx, childId, () => executeSpawn(step, input, stepCtx, executeStep, {
|
|
120
|
+
...buildSpawnOpts(stepCtx),
|
|
121
|
+
childId,
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
case 'withContext':
|
|
125
|
+
return executeWithContext(step, input, stepCtx, executeStep, {
|
|
126
|
+
layerStore: harnessWithLayerStore(baseCtx).layerStateStore,
|
|
127
|
+
storage: harnessWithLayerStore(baseCtx).config?.storage,
|
|
128
|
+
});
|
|
129
|
+
case 'loop':
|
|
130
|
+
return executeLoop(step, input, stepCtx, executeStep);
|
|
131
|
+
case 'schedule':
|
|
132
|
+
return executeSchedule(step, input, stepCtx, executeStep);
|
|
133
|
+
case 'call':
|
|
134
|
+
return executeCall(step, input, stepCtx, {
|
|
135
|
+
ledgerKey,
|
|
136
|
+
});
|
|
137
|
+
case 'wait':
|
|
138
|
+
return executeWait(step, input, stepCtx, executeStep, {
|
|
139
|
+
ledgerKey,
|
|
140
|
+
});
|
|
141
|
+
case 'verify':
|
|
142
|
+
return executeVerify(step, input, stepCtx, executeStep);
|
|
143
|
+
case 'sequence':
|
|
144
|
+
return executeSequence(step, input, stepCtx, executeStep);
|
|
145
|
+
default: {
|
|
146
|
+
const _exhaustive = step;
|
|
147
|
+
void _exhaustive;
|
|
148
|
+
throw new NoeticErrorImpl({
|
|
149
|
+
kind: 'step_failed',
|
|
150
|
+
stepId: 'unknown',
|
|
151
|
+
cause: new Error('Unknown step kind'),
|
|
152
|
+
retriesExhausted: false,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
@@ -7,5 +7,7 @@ import type { Step } from '@noetic-tools/types';
|
|
|
7
7
|
* `_optimizable` only when the builder could enumerate them.
|
|
8
8
|
*/
|
|
9
9
|
export declare function someStep(step: Step, test: (step: Step) => boolean): boolean;
|
|
10
|
+
/** Whether a step-or-steps field holds an array; `Array.isArray` does not narrow readonly arrays. */
|
|
11
|
+
export declare function isStepList<S>(value: S | ReadonlyArray<S>): value is ReadonlyArray<S>;
|
|
10
12
|
/** The steps nested directly inside `step`, as far as they are statically known. */
|
|
11
13
|
export declare function stepChildren(step: Step): ReadonlyArray<Step>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { frameworkCast } from '@noetic-tools/types';
|
|
1
2
|
/**
|
|
2
3
|
* Whether `step` or any step nested in it satisfies `test`.
|
|
3
4
|
*
|
|
@@ -11,6 +12,21 @@ export function someStep(step, test) {
|
|
|
11
12
|
}
|
|
12
13
|
return stepChildren(step).some((child) => someStep(child, test));
|
|
13
14
|
}
|
|
15
|
+
/** Whether a step-or-steps field holds an array; `Array.isArray` does not narrow readonly arrays. */
|
|
16
|
+
export function isStepList(value) {
|
|
17
|
+
return Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
/** A wait's `around` or a verify's `act`: one step or an array of steps. */
|
|
20
|
+
function waitAround(around) {
|
|
21
|
+
if (around === undefined) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
return isStepList(around)
|
|
25
|
+
? around
|
|
26
|
+
: [
|
|
27
|
+
around,
|
|
28
|
+
];
|
|
29
|
+
}
|
|
14
30
|
/** The steps nested directly inside `step`, as far as they are statically known. */
|
|
15
31
|
export function stepChildren(step) {
|
|
16
32
|
switch (step.kind) {
|
|
@@ -19,7 +35,13 @@ export function stepChildren(step) {
|
|
|
19
35
|
case 'invokeTool':
|
|
20
36
|
case 'decide':
|
|
21
37
|
case 'acp-agent':
|
|
38
|
+
case 'call':
|
|
22
39
|
return [];
|
|
40
|
+
case 'wait':
|
|
41
|
+
return waitAround(step.around);
|
|
42
|
+
case 'verify':
|
|
43
|
+
// An act built per subject is not statically known.
|
|
44
|
+
return typeof step.act === 'function' ? [] : waitAround(step.act);
|
|
23
45
|
case 'conditional':
|
|
24
46
|
case 'inParallel':
|
|
25
47
|
return step._optimizable ?? [];
|
|
@@ -41,6 +63,8 @@ export function stepChildren(step) {
|
|
|
41
63
|
return [
|
|
42
64
|
step.step,
|
|
43
65
|
];
|
|
66
|
+
case 'sequence':
|
|
67
|
+
return frameworkCast(step.steps);
|
|
44
68
|
default:
|
|
45
69
|
step;
|
|
46
70
|
return [];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What core hands the verifier for one verify (spec 37 § Under the hood): the
|
|
3
|
+
* subject and witnesses as gated `VerifyConnection`s, `act` run through the
|
|
4
|
+
* usual gates, and the run document stored as a blob. Built against the
|
|
5
|
+
* registry contract and `@noetic-tools/types/verify` only — core never imports
|
|
6
|
+
* `@noetic-tools/verify` or `open-verification`.
|
|
7
|
+
*/
|
|
8
|
+
import type { ArtifactStore, BlobRef, Context, ExecuteStepFn, Step } from '@noetic-tools/types';
|
|
9
|
+
import type { VerificationRun, VerifyActResult, VerifyConnection, VerifyParticipant } from '@noetic-tools/types/verify';
|
|
10
|
+
import type { ResolvedConnection } from '../connections/registry-types.js';
|
|
11
|
+
/** The verifier the harness registered (`new AgentHarness({ verification })`), if any. */
|
|
12
|
+
export declare function verificationOf(ctx: Context): unknown;
|
|
13
|
+
/** The harness artifact store (`environment.artifacts`), or an in-memory one per harness. */
|
|
14
|
+
export declare function artifactsOf(ctx: Context): ArtifactStore;
|
|
15
|
+
/** A participant as `Verifier.prepare` sees it. */
|
|
16
|
+
export declare function participantOf(resolved: ResolvedConnection, role: 'subject' | 'witness'): VerifyParticipant;
|
|
17
|
+
/**
|
|
18
|
+
* A resolved connection as the verifier may use it: every call goes through the
|
|
19
|
+
* registry's gates, and a witness refuses anything with effects.
|
|
20
|
+
*/
|
|
21
|
+
export declare function verifyConnectionOf(opts: {
|
|
22
|
+
resolved: ResolvedConnection;
|
|
23
|
+
role: 'subject' | 'witness';
|
|
24
|
+
ctx: Context;
|
|
25
|
+
stepId: string;
|
|
26
|
+
}): VerifyConnection;
|
|
27
|
+
/** Runs `act` in sequence, each step's output the next one's input. Never rejects: a throw becomes `error`. */
|
|
28
|
+
export declare function runAct<TContext, I>(opts: {
|
|
29
|
+
steps: ReadonlyArray<Step<TContext, I, unknown>>;
|
|
30
|
+
input: I;
|
|
31
|
+
ctx: Context<TContext>;
|
|
32
|
+
executeStep: ExecuteStepFn;
|
|
33
|
+
touched: ReadonlyArray<string>;
|
|
34
|
+
}): Promise<VerifyActResult>;
|
|
35
|
+
/** Stores a run document as a blob linked to the run, pinned, and notes it on the trace. */
|
|
36
|
+
export declare function storeRun(opts: {
|
|
37
|
+
ctx: Context;
|
|
38
|
+
stepId: string;
|
|
39
|
+
run: VerificationRun;
|
|
40
|
+
}): Promise<BlobRef>;
|