@noetic-tools/core 5.15.0 → 5.16.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/builders/custom-item.d.ts +37 -0
- package/dist/builders/custom-item.js +118 -0
- package/dist/builders/decide-builders.d.ts +1 -1
- package/dist/builders/dynamic-workflow.js +1 -1
- package/dist/builders/output-text.d.ts +5 -0
- package/dist/builders/output-text.js +13 -0
- package/dist/builders/provide-builder.d.ts +1 -1
- package/dist/builders/spawn-builder.d.ts +1 -1
- package/dist/builders/step-builders.d.ts +8 -7
- package/dist/builders/step-builders.js +2 -0
- package/dist/builders/workflow-custom-items.d.ts +38 -0
- package/dist/builders/workflow-custom-items.js +118 -0
- package/dist/builders/workflow-hydrator.d.ts +9 -2
- package/dist/builders/workflow-hydrator.js +41 -71
- package/dist/builders/workflow-step.d.ts +23 -5
- package/dist/builders/workflow-step.js +28 -13
- package/dist/expression/check.js +9 -5
- package/dist/harness/agent-harness.d.ts +19 -9
- package/dist/harness/agent-harness.js +14 -3
- package/dist/harness/deps/interpreter.d.ts +1 -0
- package/dist/harness/deps/interpreter.js +1 -0
- package/dist/harness/deps/types.d.ts +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +6 -0
- package/dist/interpreter/emit-items.d.ts +44 -8
- package/dist/interpreter/emit-items.js +280 -17
- package/dist/interpreter/execute-action.js +3 -1
- package/dist/interpreter/execute.js +4 -1
- package/dist/runtime/context-impl.d.ts +9 -1
- package/dist/runtime/context-impl.js +13 -0
- package/dist/runtime/durable/step-ledger.js +80 -15
- package/dist/runtime/item-log-impl.d.ts +7 -1
- package/dist/runtime/item-log-impl.js +8 -0
- package/dist/runtime/session-streams.js +8 -0
- package/dist/schemas/workflow.d.ts +1 -1
- package/package.json +2 -2
- package/schema/noetic-workflow.schema.json +803 -119
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* `loop`, etc.) so hydrated steps are indistinguishable from programmatic
|
|
6
6
|
* ones — they register in the step registry, carry retry policies, etc.
|
|
7
7
|
*/
|
|
8
|
-
import { frameworkCast,
|
|
9
|
-
import { compileExpression, compute,
|
|
8
|
+
import { frameworkCast, isServerToolSpec, NoeticConfigError } from '@noetic-tools/types';
|
|
9
|
+
import { compileExpression, compute, passes, readInput } from '../expression/jsonata.js';
|
|
10
10
|
import { all, any } from '../until/combinators.js';
|
|
11
11
|
import { until } from '../until/predicates.js';
|
|
12
12
|
import { DetachedHandleImpl } from '../util/detached-handle.js';
|
|
@@ -14,9 +14,11 @@ import { conditional, inParallel } from './control-flow-builders.js';
|
|
|
14
14
|
import { decide, routeSwitch } from './decide-builders.js';
|
|
15
15
|
import { schedule } from './every.js';
|
|
16
16
|
import { loop } from './loop-builder.js';
|
|
17
|
+
import { outputText } from './output-text.js';
|
|
17
18
|
import { withContext } from './provide-builder.js';
|
|
18
19
|
import { spawn } from './spawn-builder.js';
|
|
19
20
|
import { callModel, runCode, step } from './step-builders.js';
|
|
21
|
+
import { documentScope, everyDocumentItem, hydrateEmitItems, nodeScope, } from './workflow-custom-items.js';
|
|
20
22
|
import { workflowReplayKey } from './workflow-replay-key.js';
|
|
21
23
|
//#endregion
|
|
22
24
|
//#region Constants
|
|
@@ -193,7 +195,7 @@ function hydrateInvokeToolNode(node, ctx) {
|
|
|
193
195
|
lastStepMeta: execCtx.lastStepMeta,
|
|
194
196
|
};
|
|
195
197
|
const result = await resolved.execute(args, toolCtx);
|
|
196
|
-
return
|
|
198
|
+
return outputText(result);
|
|
197
199
|
},
|
|
198
200
|
}));
|
|
199
201
|
}
|
|
@@ -217,7 +219,7 @@ function hydrateRunCodeNode(node, ctx) {
|
|
|
217
219
|
adapter,
|
|
218
220
|
nodeId: node.id,
|
|
219
221
|
code,
|
|
220
|
-
input:
|
|
222
|
+
input: outputText(input),
|
|
221
223
|
});
|
|
222
224
|
},
|
|
223
225
|
}));
|
|
@@ -229,7 +231,7 @@ function hydrateComputeNode(node, ctx) {
|
|
|
229
231
|
const expr = compileExpression(node.expr, `compute node '${node.id}'`, ctx.expressionLimits);
|
|
230
232
|
return frameworkCast(runCode({
|
|
231
233
|
id: node.id,
|
|
232
|
-
execute: async (input) =>
|
|
234
|
+
execute: async (input) => outputText(await compute(expr, readInput(input))),
|
|
233
235
|
}));
|
|
234
236
|
}
|
|
235
237
|
function hydrateConditionalNode(node, ctx) {
|
|
@@ -443,10 +445,10 @@ function hydrateSequenceNode(node, ctx) {
|
|
|
443
445
|
execute: async (input, execCtx) => {
|
|
444
446
|
let current = input;
|
|
445
447
|
for (const child of children) {
|
|
446
|
-
const childInput =
|
|
448
|
+
const childInput = outputText(current);
|
|
447
449
|
current = await ctx.executeStep(child, childInput, execCtx);
|
|
448
450
|
}
|
|
449
|
-
return
|
|
451
|
+
return outputText(current);
|
|
450
452
|
},
|
|
451
453
|
}));
|
|
452
454
|
}
|
|
@@ -502,7 +504,10 @@ function hydrateSubflowNode(node, ctx) {
|
|
|
502
504
|
const resolve = () => {
|
|
503
505
|
if (!cached) {
|
|
504
506
|
const { doc, childCtx } = resolveSubflowDocument(node, ctx);
|
|
505
|
-
cached = hydrateNode(suffixNodeIds(doc.root, `-${node.id}`),
|
|
507
|
+
cached = hydrateNode(suffixNodeIds(doc.root, `-${node.id}`), {
|
|
508
|
+
...childCtx,
|
|
509
|
+
customItems: documentScope(doc, ctx.customItems),
|
|
510
|
+
});
|
|
506
511
|
}
|
|
507
512
|
return cached;
|
|
508
513
|
};
|
|
@@ -510,7 +515,7 @@ function hydrateSubflowNode(node, ctx) {
|
|
|
510
515
|
id: node.id,
|
|
511
516
|
execute: async (input, execCtx) => {
|
|
512
517
|
const child = resolve();
|
|
513
|
-
return
|
|
518
|
+
return outputText(await ctx.executeStep(child, node.input ?? input, execCtx));
|
|
514
519
|
},
|
|
515
520
|
}));
|
|
516
521
|
}
|
|
@@ -606,7 +611,7 @@ function buildMerge(strategy) {
|
|
|
606
611
|
return (r) => r[0] ?? '';
|
|
607
612
|
}
|
|
608
613
|
if (strategy === 'concat') {
|
|
609
|
-
return (r) => r.map(
|
|
614
|
+
return (r) => r.map(outputText).join('\n');
|
|
610
615
|
}
|
|
611
616
|
return (r) => r[r.length - 1] ?? '';
|
|
612
617
|
}
|
|
@@ -651,62 +656,6 @@ function parseJsonObject(text) {
|
|
|
651
656
|
return text;
|
|
652
657
|
}
|
|
653
658
|
}
|
|
654
|
-
/**
|
|
655
|
-
* The object form of a node's `emitItems` builds an emit function: the value is the
|
|
656
|
-
* `expr` result, or the output itself read as JSON, and no value emits nothing, so one
|
|
657
|
-
* node can emit on some iterations of a loop and stay quiet on others.
|
|
658
|
-
*/
|
|
659
|
-
function workflowEmitItems(nodeId, option, ctx) {
|
|
660
|
-
if (typeof option === 'boolean') {
|
|
661
|
-
return option;
|
|
662
|
-
}
|
|
663
|
-
const where = `emitItems of node '${nodeId}'`;
|
|
664
|
-
const expr = option.expr === undefined
|
|
665
|
-
? undefined
|
|
666
|
-
: compileExpression(option.expr, where, ctx.expressionLimits);
|
|
667
|
-
const asItems = option.as === 'items';
|
|
668
|
-
if (!expr && !asItems) {
|
|
669
|
-
return true;
|
|
670
|
-
}
|
|
671
|
-
return async (output) => {
|
|
672
|
-
const value = expr ? await computeMaybe(expr, readInput(output)) : readInput(output);
|
|
673
|
-
if (value === undefined) {
|
|
674
|
-
return undefined;
|
|
675
|
-
}
|
|
676
|
-
return asItems ? itemList(value, where) : stringifyResult(value);
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Reads a value as items: one object or a list of them, each with a string `type`.
|
|
681
|
-
* Whether a type is allowed is the item log's call, against the harness's item schemas.
|
|
682
|
-
*
|
|
683
|
-
* @throws `NoeticConfigError` with code `INVALID_EMIT_ITEMS` when the value is not an
|
|
684
|
-
* item or a list of items.
|
|
685
|
-
*/
|
|
686
|
-
function itemList(value, where) {
|
|
687
|
-
const list = Array.isArray(value)
|
|
688
|
-
? value
|
|
689
|
-
: [
|
|
690
|
-
value,
|
|
691
|
-
];
|
|
692
|
-
if (!list.every((entry) => ItemSchema.safeParse(entry).success)) {
|
|
693
|
-
throw new NoeticConfigError({
|
|
694
|
-
code: 'INVALID_EMIT_ITEMS',
|
|
695
|
-
message: `The ${where} gave ${JSON.stringify(value)}, which is not an item or a list of items.`,
|
|
696
|
-
hint: 'With "as": "items", give an object with a string "type" (e.g. { "type": "message", "role": "assistant", ... } or a registered custom type like "myapp:progress"), or a list of them.',
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
return frameworkCast(list);
|
|
700
|
-
}
|
|
701
|
-
function stringifyResult(value) {
|
|
702
|
-
if (typeof value === 'string') {
|
|
703
|
-
return value;
|
|
704
|
-
}
|
|
705
|
-
if (value === null || value === undefined) {
|
|
706
|
-
return '';
|
|
707
|
-
}
|
|
708
|
-
return JSON.stringify(value);
|
|
709
|
-
}
|
|
710
659
|
//#endregion
|
|
711
660
|
//#region Dynamic Fork Helpers
|
|
712
661
|
/**
|
|
@@ -751,7 +700,7 @@ function buildPerItemStep(opts) {
|
|
|
751
700
|
id: `${forkId}-item-${index}`,
|
|
752
701
|
execute: async (_input, execCtx) => {
|
|
753
702
|
const itemInput = JSON.stringify(item);
|
|
754
|
-
return
|
|
703
|
+
return outputText(await ctx.executeStep(hydratedEach, itemInput, execCtx));
|
|
755
704
|
},
|
|
756
705
|
}));
|
|
757
706
|
}
|
|
@@ -845,7 +794,7 @@ async function runCodeViaSubprocess(opts) {
|
|
|
845
794
|
spawned: adapter.spawn(request),
|
|
846
795
|
});
|
|
847
796
|
const result = await handle.await();
|
|
848
|
-
return
|
|
797
|
+
return outputText(result);
|
|
849
798
|
}
|
|
850
799
|
//#endregion
|
|
851
800
|
//#region Public API
|
|
@@ -884,8 +833,17 @@ export function hydrateNode(node, ctx) {
|
|
|
884
833
|
if (node.replayKey !== undefined) {
|
|
885
834
|
hydrated.replayKey = workflowReplayKey(node.id, node.replayKey);
|
|
886
835
|
}
|
|
836
|
+
const scope = nodeScope(node, ctx.customItems);
|
|
837
|
+
if (Object.keys(scope).length > 0) {
|
|
838
|
+
hydrated.customItems = scope;
|
|
839
|
+
}
|
|
887
840
|
if (node.emitItems !== undefined) {
|
|
888
|
-
hydrated.emitItems =
|
|
841
|
+
hydrated.emitItems = hydrateEmitItems({
|
|
842
|
+
nodeId: node.id,
|
|
843
|
+
option: node.emitItems,
|
|
844
|
+
scope,
|
|
845
|
+
limits: ctx.expressionLimits,
|
|
846
|
+
});
|
|
889
847
|
}
|
|
890
848
|
return hydrated;
|
|
891
849
|
}
|
|
@@ -895,9 +853,21 @@ export function hydrateNode(node, ctx) {
|
|
|
895
853
|
* @public
|
|
896
854
|
* @param doc - Validated workflow document (version 1).
|
|
897
855
|
* @param ctx - Hydration context with tool registry and step executor.
|
|
856
|
+
* @param customItems - TypeScript declarations of the document's root custom items (spec 34).
|
|
898
857
|
* @returns The root `Step` of the hydrated workflow.
|
|
858
|
+
* @throws `NoeticConfigError` with code `CUSTOM_ITEM_MISMATCH` when `customItems` and the document give one name different types.
|
|
899
859
|
*/
|
|
900
|
-
export function hydrateWorkflow(doc, ctx) {
|
|
901
|
-
|
|
860
|
+
export function hydrateWorkflow(doc, ctx, customItems) {
|
|
861
|
+
const root = hydrateNode(doc.root, {
|
|
862
|
+
...ctx,
|
|
863
|
+
customItems: documentScope(doc, ctx.customItems, customItems),
|
|
864
|
+
});
|
|
865
|
+
// The root's dispatch accepts every item the document declares before anything
|
|
866
|
+
// runs or replays; keyed by type, they cannot shadow the root's own names.
|
|
867
|
+
root.customItems = {
|
|
868
|
+
...everyDocumentItem(doc),
|
|
869
|
+
...root.customItems,
|
|
870
|
+
};
|
|
871
|
+
return root;
|
|
902
872
|
}
|
|
903
873
|
//#endregion
|
|
@@ -6,13 +6,22 @@
|
|
|
6
6
|
* import cycle.
|
|
7
7
|
*/
|
|
8
8
|
import type { ContextData, ContextLayer } from '@noetic-tools/context';
|
|
9
|
-
import type { AcpAgent, OutputCodec, StepRunCode, SubprocessAdapter, Tool, WorkflowDocument } from '@noetic-tools/types';
|
|
9
|
+
import type { AcpAgent, CustomItemMap, CustomItemsBrand, DeepReadonly, DocumentCustomItems, OutputCodec, StepRunCode, SubprocessAdapter, Tool, WorkflowDocument } from '@noetic-tools/types';
|
|
10
10
|
import type { ExpressionLimits } from '../expression/jsonata.js';
|
|
11
11
|
/** @public Options for `workflow`. */
|
|
12
|
-
export interface WorkflowOpts {
|
|
12
|
+
export interface WorkflowOpts<D extends WorkflowDocumentInput = WorkflowDocumentInput, M extends CustomItemMap = CustomItemMap> {
|
|
13
13
|
id: string;
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Inline workflow document. Mutually exclusive with `ref`. Written `as const`, its
|
|
16
|
+
* declared custom items type the step (spec 34 § Typing the harness).
|
|
17
|
+
*/
|
|
18
|
+
document?: D;
|
|
19
|
+
/**
|
|
20
|
+
* Custom items any node in the document may emit, in TypeScript. A name the document
|
|
21
|
+
* also declares must carry the same `type`; this declaration then validates and types
|
|
22
|
+
* it.
|
|
23
|
+
*/
|
|
24
|
+
customItems?: M;
|
|
16
25
|
/** Named workflow resolved from `workflows`. Mutually exclusive with `document`. */
|
|
17
26
|
ref?: string;
|
|
18
27
|
/** Client tools the document's `callModel`/`invokeTool` nodes may reference by name. Default: none. */
|
|
@@ -34,6 +43,15 @@ export interface WorkflowOpts {
|
|
|
34
43
|
/** `'inherit'` (default) runs in the caller's session; `'spawn'` isolates via `spawn()`. */
|
|
35
44
|
isolation?: 'inherit' | 'spawn';
|
|
36
45
|
}
|
|
46
|
+
/** @public A workflow document as `workflow()` takes it: plain, or `as const`. */
|
|
47
|
+
export type WorkflowDocumentInput = WorkflowDocument | DeepReadonly<WorkflowDocument>;
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
* The step `workflow()` returns, branded with the custom items it may emit: its
|
|
51
|
+
* TypeScript map plus those an `as const` document declares. `AgentHarness` reads the
|
|
52
|
+
* brand off `agentGraph` to type its results.
|
|
53
|
+
*/
|
|
54
|
+
export type TypedWorkflowStep<D, M extends CustomItemMap> = StepRunCode<ContextData, string, string> & CustomItemsBrand<M[keyof M] | DocumentCustomItems<D>>;
|
|
37
55
|
/**
|
|
38
56
|
* Creates a step that hydrates and executes a JSON workflow document.
|
|
39
57
|
*
|
|
@@ -53,4 +71,4 @@ export interface WorkflowOpts {
|
|
|
53
71
|
* @throws `NoeticConfigError` with code `WORKFLOW_RECURSION_LIMIT` (at execution) if named refs nest deeper than `maxRecursionDepth`.
|
|
54
72
|
* @throws `NoeticConfigError` with code `INVALID_MAX_RECURSION_DEPTH` (at execution) if a nested ref resolves under an invalid `maxRecursionDepth`.
|
|
55
73
|
*/
|
|
56
|
-
export declare function workflow(opts: WorkflowOpts):
|
|
74
|
+
export declare function workflow<const D extends WorkflowDocumentInput = WorkflowDocument, const M extends CustomItemMap = Record<never, never>>(opts: WorkflowOpts<D, M>): TypedWorkflowStep<D, M>;
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* import cycle.
|
|
7
7
|
*/
|
|
8
8
|
import { frameworkCast, NoeticConfigError } from '@noetic-tools/types';
|
|
9
|
+
import { outputText } from './output-text.js';
|
|
9
10
|
import { spawn } from './spawn-builder.js';
|
|
10
11
|
import { runCode } from './step-builders.js';
|
|
12
|
+
import { everyDocumentItem } from './workflow-custom-items.js';
|
|
11
13
|
import { hydrateWorkflow } from './workflow-hydrator.js';
|
|
12
14
|
//#endregion
|
|
13
15
|
//#region Builder
|
|
@@ -50,8 +52,9 @@ export function workflow(opts) {
|
|
|
50
52
|
// across sessions re-hydrates when it runs under a different harness
|
|
51
53
|
// instead of routing nested steps through the first one.
|
|
52
54
|
let cached;
|
|
53
|
-
|
|
55
|
+
const step = runCode({
|
|
54
56
|
id: opts.id,
|
|
57
|
+
customItems: workflowItems(opts),
|
|
55
58
|
execute: async (input, ctx) => {
|
|
56
59
|
const harness = ctx.harness;
|
|
57
60
|
if (!harness) {
|
|
@@ -68,14 +71,35 @@ export function workflow(opts) {
|
|
|
68
71
|
step: hydrate(opts, executeStep),
|
|
69
72
|
};
|
|
70
73
|
}
|
|
71
|
-
return
|
|
74
|
+
return outputText(await executeStep(cached.step, input, ctx));
|
|
72
75
|
},
|
|
73
76
|
});
|
|
77
|
+
return frameworkCast(step);
|
|
74
78
|
}
|
|
75
79
|
//#endregion
|
|
76
80
|
//#region Helpers
|
|
77
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Every custom item the workflow can emit, keyed by `type`: its TypeScript map and all
|
|
83
|
+
* the document declares at any level. The step carries them so a harness accepts them
|
|
84
|
+
* in a log before any node runs.
|
|
85
|
+
*/
|
|
86
|
+
function workflowItems(opts) {
|
|
87
|
+
const doc = documentOf(opts);
|
|
88
|
+
const found = [
|
|
89
|
+
...Object.values(doc ? everyDocumentItem(doc) : {}),
|
|
90
|
+
...Object.values(opts.customItems ?? {}),
|
|
91
|
+
];
|
|
92
|
+
return Object.fromEntries(found.map((item) => [
|
|
93
|
+
item.type,
|
|
94
|
+
item,
|
|
95
|
+
]));
|
|
96
|
+
}
|
|
97
|
+
function documentOf(opts) {
|
|
78
98
|
const doc = opts.document ?? (opts.ref ? opts.workflows?.get(opts.ref) : undefined);
|
|
99
|
+
return frameworkCast(doc);
|
|
100
|
+
}
|
|
101
|
+
function hydrate(opts, executeStep) {
|
|
102
|
+
const doc = documentOf(opts);
|
|
79
103
|
if (!doc) {
|
|
80
104
|
throw new NoeticConfigError({
|
|
81
105
|
code: 'UNKNOWN_WORKFLOW_REFERENCE',
|
|
@@ -100,7 +124,7 @@ function hydrate(opts, executeStep) {
|
|
|
100
124
|
expressionLimits: opts.expressionLimits,
|
|
101
125
|
recursionDepth: opts.ref ? 1 : undefined,
|
|
102
126
|
};
|
|
103
|
-
const hydrated = hydrateWorkflow(doc, hydrationCtx);
|
|
127
|
+
const hydrated = hydrateWorkflow(doc, hydrationCtx, opts.customItems);
|
|
104
128
|
if (opts.isolation !== 'spawn') {
|
|
105
129
|
return hydrated;
|
|
106
130
|
}
|
|
@@ -109,13 +133,4 @@ function hydrate(opts, executeStep) {
|
|
|
109
133
|
child: hydrated,
|
|
110
134
|
});
|
|
111
135
|
}
|
|
112
|
-
function stringify(value) {
|
|
113
|
-
if (typeof value === 'string') {
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
if (value === null || value === undefined) {
|
|
117
|
-
return '';
|
|
118
|
-
}
|
|
119
|
-
return JSON.stringify(value);
|
|
120
|
-
}
|
|
121
136
|
//#endregion
|
package/dist/expression/check.js
CHANGED
|
@@ -26,14 +26,18 @@ export function expressionErrors(root) {
|
|
|
26
26
|
//#endregion
|
|
27
27
|
//#region Helpers
|
|
28
28
|
function expressionsOf(node) {
|
|
29
|
-
const
|
|
30
|
-
|
|
29
|
+
const option = typeof node.emitItems === 'object' ? node.emitItems : {};
|
|
30
|
+
const emitted = [
|
|
31
|
+
option.onStart,
|
|
32
|
+
option.onDone,
|
|
33
|
+
].flatMap((source) => source === undefined
|
|
34
|
+
? []
|
|
35
|
+
: [
|
|
31
36
|
{
|
|
32
37
|
where: `emitItems of node '${node.id}'`,
|
|
33
|
-
source
|
|
38
|
+
source,
|
|
34
39
|
},
|
|
35
|
-
]
|
|
36
|
-
: [];
|
|
40
|
+
]);
|
|
37
41
|
return [
|
|
38
42
|
...emitted,
|
|
39
43
|
...kindExpressionsOf(node),
|
|
@@ -4,7 +4,7 @@ import type { LayerStateStore, RecallCache } from './deps/context.js';
|
|
|
4
4
|
import type { DetachedSpawnOverrides } from './deps/interpreter.js';
|
|
5
5
|
import type { CheckpointStore, EventBroadcaster, RestoreCheckpointOptions, StepLedgerRetention, StepLedgerStore } from './deps/runtime.js';
|
|
6
6
|
import { ChannelStore } from './deps/runtime.js';
|
|
7
|
-
import type { AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, Channel, ChannelHandle, Context, ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeliveryMode, DetachedHandle, ExecuteInput, ExecuteOptions, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, LLMResponse, LlmProviderConfig, OnSteerParams, ProjectionPolicy, RecallLayerOutput, RecallOptions, SessionScope, SessionUsage, ShellAdapter, Span, SteeringDecision, SteerVerdict, Step, StorageAdapter, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, ZodType } from './deps/types.js';
|
|
7
|
+
import type { AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, Channel, ChannelHandle, Context, ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DeliveryMode, DetachedHandle, ExecuteInput, ExecuteOptions, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, LLMResponse, LlmProviderConfig, OnSteerParams, ProjectionPolicy, RecallLayerOutput, RecallOptions, SessionScope, SessionUsage, ShellAdapter, Span, SteeringDecision, SteerVerdict, Step, StorageAdapter, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, ZodType } from './deps/types.js';
|
|
8
8
|
export { createStreamIdleWatchdog } from './model-call.js';
|
|
9
9
|
/**
|
|
10
10
|
* Storage-scoped environment configuration for `AgentHarness`.
|
|
@@ -53,10 +53,14 @@ export interface AgentEnvironmentConfig {
|
|
|
53
53
|
/** Subprocess adapter. Defaults to an in-memory, same-process adapter. */
|
|
54
54
|
subprocess?: SubprocessAdapter;
|
|
55
55
|
}
|
|
56
|
-
interface AgentHarnessOpts<TParams extends Record<string, unknown> = Record<string, unknown
|
|
56
|
+
interface AgentHarnessOpts<TParams extends Record<string, unknown> = Record<string, unknown>, TItem extends CustomItem = CustomItem> {
|
|
57
57
|
name: string;
|
|
58
|
-
/**
|
|
59
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Root step tree executed for every turn submitted via `execute()`. The custom items
|
|
60
|
+
* it declares (a `workflow()` step's brand) type `getItemStream`, `getFullStream`,
|
|
61
|
+
* and `getAgentResponse` (spec 34).
|
|
62
|
+
*/
|
|
63
|
+
agentGraph?: Step<ContextData, string, string> & CustomItemsBrand<TItem>;
|
|
60
64
|
/** Default context layers applied to every context created via `createContext()` / `execute()`. */
|
|
61
65
|
contextLayers?: ContextLayer[];
|
|
62
66
|
/**
|
|
@@ -151,7 +155,7 @@ export declare function resolveLlmClient(config: LlmProviderConfig | undefined,
|
|
|
151
155
|
*
|
|
152
156
|
* @public
|
|
153
157
|
*/
|
|
154
|
-
export declare class AgentHarness<TParams extends Record<string, unknown> = Record<string, unknown
|
|
158
|
+
export declare class AgentHarness<TParams extends Record<string, unknown> = Record<string, unknown>, TItem extends CustomItem = never> implements AgentHarnessContract<TParams> {
|
|
155
159
|
readonly config: AgentConfig<TParams>;
|
|
156
160
|
readonly fs: FsAdapter;
|
|
157
161
|
readonly shell: ShellAdapter;
|
|
@@ -268,7 +272,7 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
|
|
|
268
272
|
* in `runtime/durable/` (restore) can parse persisted items. Do not
|
|
269
273
|
* access from outside core. */
|
|
270
274
|
readonly itemSchemas: ItemSchemaRegistry;
|
|
271
|
-
constructor(opts: AgentHarnessOpts<TParams>);
|
|
275
|
+
constructor(opts: AgentHarnessOpts<TParams, TItem>);
|
|
272
276
|
/**
|
|
273
277
|
* Update the harness-wide root cwd. The TUI calls this in response to a
|
|
274
278
|
* user-issued `! cd`, so the next root Context (and any tool inspecting
|
|
@@ -277,11 +281,17 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
|
|
|
277
281
|
*/
|
|
278
282
|
setRootCwd(nextCwd: string): void;
|
|
279
283
|
execute(input: ExecuteInput, options?: ExecuteOptions): Promise<void>;
|
|
280
|
-
|
|
281
|
-
|
|
284
|
+
/** The turn's response. `items` holds final items: standard ones and the graph's declared custom items. */
|
|
285
|
+
getAgentResponse(scope?: SessionScope): Promise<HarnessResponse<Item | CustomItemOf<DeclaredItems<TItem>>>>;
|
|
286
|
+
/**
|
|
287
|
+
* Item snapshots as they stream. A declared custom item streams like a model reply:
|
|
288
|
+
* each event in progress (`isComplete: false`), then its final item, under one `id`.
|
|
289
|
+
*/
|
|
290
|
+
getItemStream(scope?: SessionScope): AsyncIterable<StreamingItem | CustomStreamingItem<DeclaredItems<TItem>>>;
|
|
282
291
|
getTextStream(scope?: SessionScope): AsyncIterable<string>;
|
|
283
292
|
getReasoningStream(scope?: SessionScope): AsyncIterable<string>;
|
|
284
|
-
|
|
293
|
+
/** Every event raw, including each declared custom item's `custom_item_event`. */
|
|
294
|
+
getFullStream(scope?: SessionScope): AsyncIterable<StreamEvent | CustomItemStreamEvent<DeclaredItems<TItem>>>;
|
|
285
295
|
abort(scope?: SessionScope & {
|
|
286
296
|
reason?: string;
|
|
287
297
|
}): Promise<void>;
|
|
@@ -6,7 +6,7 @@ import { AcpSessionStore } from '../runtime/acp-session-store.js';
|
|
|
6
6
|
import { callDecide } from './decide-call.js';
|
|
7
7
|
import { createInMemoryFsAdapter, createInMemoryShellAdapter, createInMemorySubprocessAdapter, OpenRouter, OpenRouterSdk, } from './deps/adapters.js';
|
|
8
8
|
import { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, initLayers, notifyDecision, onSteerLayers, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from './deps/context.js';
|
|
9
|
-
import { collectAllTools, deduplicateTools, dispatchStepThroughAdapter, execute, prepareBandedView, someStep, } from './deps/interpreter.js';
|
|
9
|
+
import { collectAllTools, collectCustomItems, customItemGates, deduplicateTools, dispatchStepThroughAdapter, execute, prepareBandedView, someStep, } from './deps/interpreter.js';
|
|
10
10
|
import { buildItemStream, ChannelStore, ContextImpl, captureCheckpoint, clearCheckpoint, collectContextTree, createCheckpointStore, createInMemoryStorage, createSessionStore, createStepLedgerStore, filterReasoningStream, filterTextStream, INTERRUPT_REASON, resolveStepLedgerRetention, restoreFromCheckpoint, rootIdOf, SessionRunner, StepLedger, snapshotCwdState, warnToConsole, } from './deps/runtime.js';
|
|
11
11
|
import { SteeringAction } from './deps/types.js';
|
|
12
12
|
import { AgentHarnessModelCaller, noLlmProviderError } from './model-call.js';
|
|
@@ -369,8 +369,13 @@ export class AgentHarness {
|
|
|
369
369
|
this.recallCache = createRecallCache();
|
|
370
370
|
this.contextCache = createContextCacheStore();
|
|
371
371
|
this.defaultDeliveryMode = opts.defaultDeliveryMode ?? 'next-turn';
|
|
372
|
+
// The graph's custom items join before any log is restored or rebuilt (spec 34).
|
|
372
373
|
this.itemSchemas = new ItemSchemaRegistry(opts.itemSchemas?.schemas, {
|
|
373
374
|
strictUnknownExtensions: opts.itemSchemas?.strict ?? true,
|
|
375
|
+
}).extend({
|
|
376
|
+
items: opts.agentGraph
|
|
377
|
+
? customItemGates(collectCustomItems(frameworkCast(opts.agentGraph)))
|
|
378
|
+
: [],
|
|
374
379
|
});
|
|
375
380
|
this.rootCwdState = {
|
|
376
381
|
cwd: opts.initialCwd ?? '/',
|
|
@@ -420,13 +425,18 @@ export class AgentHarness {
|
|
|
420
425
|
session.runner.enqueue(message);
|
|
421
426
|
return Promise.resolve();
|
|
422
427
|
}
|
|
428
|
+
/** The turn's response. `items` holds final items: standard ones and the graph's declared custom items. */
|
|
423
429
|
getAgentResponse(scope) {
|
|
424
430
|
const session = this.requireSession(scope);
|
|
425
|
-
return session.runner.getAgentResponse();
|
|
431
|
+
return frameworkCast(session.runner.getAgentResponse());
|
|
426
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Item snapshots as they stream. A declared custom item streams like a model reply:
|
|
435
|
+
* each event in progress (`isComplete: false`), then its final item, under one `id`.
|
|
436
|
+
*/
|
|
427
437
|
getItemStream(scope) {
|
|
428
438
|
const session = this.requireSession(scope);
|
|
429
|
-
return buildItemStream(session.runner.broadcaster, this.itemSchemas);
|
|
439
|
+
return frameworkCast(buildItemStream(session.runner.broadcaster, this.itemSchemas));
|
|
430
440
|
}
|
|
431
441
|
getTextStream(scope) {
|
|
432
442
|
const session = this.requireSession(scope);
|
|
@@ -436,6 +446,7 @@ export class AgentHarness {
|
|
|
436
446
|
const session = this.requireSession(scope);
|
|
437
447
|
return filterReasoningStream(session.runner.broadcaster);
|
|
438
448
|
}
|
|
449
|
+
/** Every event raw, including each declared custom item's `custom_item_event`. */
|
|
439
450
|
getFullStream(scope) {
|
|
440
451
|
const session = this.requireSession(scope);
|
|
441
452
|
return session.runner.broadcaster;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
|
|
2
2
|
export { prepareBandedView } from '../../interpreter/context-assembly.js';
|
|
3
|
+
export { collectCustomItems, customItemGates } from '../../interpreter/emit-items.js';
|
|
3
4
|
export { execute } from '../../interpreter/execute.js';
|
|
4
5
|
export type { DetachedSpawnOverrides } from '../../interpreter/step-dispatcher.js';
|
|
5
6
|
export { dispatchStepThroughAdapter } from '../../interpreter/step-dispatcher.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
|
|
2
2
|
export { prepareBandedView } from '../../interpreter/context-assembly.js';
|
|
3
|
+
export { collectCustomItems, customItemGates } from '../../interpreter/emit-items.js';
|
|
3
4
|
export { execute } from '../../interpreter/execute.js';
|
|
4
5
|
export { dispatchStepThroughAdapter } from '../../interpreter/step-dispatcher.js';
|
|
5
6
|
export { someStep } from '../../interpreter/step-walk.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, ExecutionContext, ProjectionPolicy, StorageAdapter, } from '@noetic-tools/context';
|
|
2
|
-
export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, Channel, ChannelHandle, Context, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeliveryMode, DetachedHandle, ExecuteInput, ExecuteOptions, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, RecallLayerOutput, RecallOptions, SessionScope, SessionUsage, ShellAdapter, Span, SteeringDecision, SteerVerdict, Step, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, } from '@noetic-tools/types';
|
|
2
|
+
export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, Channel, ChannelHandle, Context, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DeliveryMode, DetachedHandle, ExecuteInput, ExecuteOptions, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, RecallLayerOutput, RecallOptions, SessionScope, SessionUsage, ShellAdapter, Span, SteeringDecision, SteerVerdict, Step, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, } from '@noetic-tools/types';
|
|
3
3
|
export { SteeringAction } from '@noetic-tools/types';
|
|
4
4
|
export type { ZodType } from 'zod';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export { createInMemorySubprocessAdapter } from './adapters/in-memory-subprocess
|
|
|
7
7
|
/** @public */
|
|
8
8
|
export { createOpenRouterEmbed } from './adapters/openrouter.js';
|
|
9
9
|
/** @public */
|
|
10
|
+
export { isCustomItem, isCustomItemEvent } from '@noetic-tools/types';
|
|
11
|
+
/** @public */
|
|
10
12
|
export type { AcpAgentToolOptions } from './builders/acp-agent-tool.js';
|
|
11
13
|
/** @public */
|
|
12
14
|
export { acpAgentTool } from './builders/acp-agent-tool.js';
|
|
@@ -19,6 +21,8 @@ export type { ConditionalOpts, InParallelOpts } from './builders/control-flow-bu
|
|
|
19
21
|
/** @public */
|
|
20
22
|
export { conditional, inParallel } from './builders/control-flow-builders.js';
|
|
21
23
|
/** @public */
|
|
24
|
+
export { customItem } from './builders/custom-item.js';
|
|
25
|
+
/** @public */
|
|
22
26
|
export { decide, routeSwitch } from './builders/decide-builders.js';
|
|
23
27
|
/** @public */
|
|
24
28
|
export type { ScheduleOptions } from './builders/every.js';
|
|
@@ -49,7 +53,7 @@ export type { HydrationContext } from './builders/workflow-hydrator.js';
|
|
|
49
53
|
/** @public */
|
|
50
54
|
export { hydrateNode, hydrateWorkflow } from './builders/workflow-hydrator.js';
|
|
51
55
|
/** @public */
|
|
52
|
-
export type { WorkflowOpts } from './builders/workflow-step.js';
|
|
56
|
+
export type { TypedWorkflowStep, WorkflowDocumentInput, WorkflowOpts, } from './builders/workflow-step.js';
|
|
53
57
|
/** @public */
|
|
54
58
|
export { workflow } from './builders/workflow-step.js';
|
|
55
59
|
/** @public */
|
|
@@ -119,7 +123,7 @@ export type { Expression } from '@noetic-tools/types';
|
|
|
119
123
|
/** @public */
|
|
120
124
|
export { defaultItemSchemaRegistry, ExpressionSchema, ItemSchema, ItemSchemaRegistry, } from '@noetic-tools/types';
|
|
121
125
|
/** @public */
|
|
122
|
-
export type { AcpAgentWorkflowNode, CallModelWorkflowNode, ComputeWorkflowNode, ConditionalRoute, ConditionalWorkflowNode, DecideWorkflowNode, InParallelWorkflowNode, InvokeToolWorkflowNode, LoopWorkflowNode, MergeStrategy, RouteSwitchWorkflowNode, ScheduleWorkflowNode, SequenceWorkflowNode, SpawnWorkflowNode, SubflowWorkflowNode, UntilPredicate, WithContextWorkflowNode, WorkflowDocument, WorkflowEmitItems, WorkflowNode, } from './schemas/workflow.js';
|
|
126
|
+
export type { AcpAgentWorkflowNode, CallModelWorkflowNode, ComputeWorkflowNode, ConditionalRoute, ConditionalWorkflowNode, DecideWorkflowNode, InParallelWorkflowNode, InvokeToolWorkflowNode, LoopWorkflowNode, MergeStrategy, RouteSwitchWorkflowNode, ScheduleWorkflowNode, SequenceWorkflowNode, SpawnWorkflowNode, SubflowWorkflowNode, UntilPredicate, WithContextWorkflowNode, WorkflowCustomItem, WorkflowDocument, WorkflowEmitItems, WorkflowNode, } from './schemas/workflow.js';
|
|
123
127
|
/** @public */
|
|
124
128
|
export { MergeStrategySchema, UntilPredicateSchema, validateWorkflow, WorkflowDocumentSchema, WorkflowNodeSchema, walkWorkflow, workflowDepth, } from './schemas/workflow.js';
|
|
125
129
|
/** @public */
|
|
@@ -166,7 +170,7 @@ export type { AfterModelCallParams, AfterModelCallResult, ApproveToolCallParams,
|
|
|
166
170
|
/** @public */
|
|
167
171
|
export { LedgerEntryKind, SteerAction, SteeringAction, SteerPoint } from '@noetic-tools/types';
|
|
168
172
|
/** @public */
|
|
169
|
-
export type { ExecuteStepFn, MergeFn, SettleResult, Snapshot, Step, StepAcpAgent, StepCallModel, StepConditional, StepEmitItems, StepEmitItemsFn, StepEmitItemsOption, StepEmitItemsResult, StepInParallel, StepInParallelAll, StepInParallelRace, StepInParallelSettle, StepInvokeTool, StepLoop, StepReplay, StepRunCode, StepSpawn, StepWithContext, Until, UntilRun, Verdict, } from '@noetic-tools/types';
|
|
173
|
+
export type { CustomItem, CustomItemEventOf, CustomItemMap, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomItemType, CustomStreamingItem, DeclaredItems, DeepReadonly, DocumentCustomItems, EmitHook, EmitHookResult, ExecuteStepFn, FromJsonSchema, InferShape, ItemShape, JsonSchema, MergeFn, PlainEmitHook, RunCodeExecute, SettleResult, Snapshot, Step, StepAcpAgent, StepCallModel, StepConditional, StepEmitItems, StepEmitItemsConfig, StepEmitItemsFn, StepEmitItemsOption, StepEmitItemsResult, StepInParallel, StepInParallelAll, StepInParallelRace, StepInParallelSettle, StepInvokeTool, StepLoop, StepReplay, StepRunCode, StepSpawn, StepWithContext, Until, UntilRun, Verdict, } from '@noetic-tools/types';
|
|
170
174
|
/** @public */
|
|
171
175
|
export type { AnsweredAll, AnswerFor, BooleanAnswer, BooleanQuestion, CaseKeyOf, ChoiceAnswer, ChoiceQuestion, ChoiceValues, DecideAnswer, DecideAnswers, DecideQuestion, DecideQuestions, DecideRequest, DecideResponse, DecideStatePart, DecideStep, DecideView, DecisionMeta, DecisionRecord, DecisionSource, LevelLabels, OnDecisionParams, RecallOptions, ScoreAnswer, ScoreLevel, ScoreQuestion, StepDecide, } from '@noetic-tools/types';
|
|
172
176
|
/** @public */
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,10 @@ export { createInMemoryShellAdapter } from './adapters/in-memory-shell-adapter.j
|
|
|
7
7
|
export { createInMemorySubprocessAdapter } from './adapters/in-memory-subprocess-adapter.js';
|
|
8
8
|
/** @public */
|
|
9
9
|
export { createOpenRouterEmbed } from './adapters/openrouter.js';
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region Builders
|
|
12
|
+
/** @public */
|
|
13
|
+
export { isCustomItem, isCustomItemEvent } from '@noetic-tools/types';
|
|
10
14
|
/** @public */
|
|
11
15
|
export { acpAgentTool } from './builders/acp-agent-tool.js';
|
|
12
16
|
/** @public */
|
|
@@ -16,6 +20,8 @@ export { context } from './builders/context-builder.js';
|
|
|
16
20
|
/** @public */
|
|
17
21
|
export { conditional, inParallel } from './builders/control-flow-builders.js';
|
|
18
22
|
/** @public */
|
|
23
|
+
export { customItem } from './builders/custom-item.js';
|
|
24
|
+
/** @public */
|
|
19
25
|
export { decide, routeSwitch } from './builders/decide-builders.js';
|
|
20
26
|
/** @public */
|
|
21
27
|
export { schedule } from './builders/every.js';
|
|
@@ -1,15 +1,51 @@
|
|
|
1
|
-
import type { Context, Item, Step } from '@noetic-tools/types';
|
|
1
|
+
import type { Context, CustomItem, Item, Step } from '@noetic-tools/types';
|
|
2
|
+
import type { ZodTypeAny } from 'zod';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `step.emit` filtering. Each item is marked in the step's lane record, so the ledger
|
|
7
|
-
* entry that holds it can stream it again on replay.
|
|
4
|
+
* Starts what a step emits (spec 34 § Emitting): opens the dispatch's custom item, if
|
|
5
|
+
* `emitItems` names one, and runs `onStart` with the step's input. Events stream at
|
|
6
|
+
* once as `custom_item_event`; a final item appends and streams as `item_appended`.
|
|
8
7
|
*
|
|
9
|
-
* @throws `
|
|
10
|
-
*
|
|
8
|
+
* @throws `NoeticConfigError` with code `UNKNOWN_CUSTOM_ITEM`, `CUSTOM_ITEM_HAS_NO_EVENTS`,
|
|
9
|
+
* `CUSTOM_ITEM_ALREADY_FINAL`, or `INVALID_CUSTOM_ITEM`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function beginEmitItems<TContext, I, O>(step: Step<TContext, I, O>, input: I, ctx: Context<TContext>): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Finishes what a step emits: runs `onDone` with its output, or for `emitItems: true`
|
|
14
|
+
* emits the output itself as a final item, or for a function emits what it returns.
|
|
15
|
+
* Like the SDK item events, none of it is subject to `step.emit` filtering.
|
|
16
|
+
*
|
|
17
|
+
* @throws `NoeticConfigError` as `beginEmitItems`, and `NoeticError` with kind
|
|
18
|
+
* `item_schema_mismatch` when a standard item's type is not one the context accepts.
|
|
11
19
|
*/
|
|
12
20
|
export declare function emitStepItems<TContext, I, O>(step: Step<TContext, I, O>, output: O, ctx: Context<TContext>): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Streams one event a generator `runCode` yielded, as an event of the item its
|
|
23
|
+
* `emitItems` names.
|
|
24
|
+
*
|
|
25
|
+
* @throws `NoeticConfigError` with code `CUSTOM_ITEM_HAS_NO_EVENTS` or `INVALID_CUSTOM_ITEM`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function emitStepEvent<TContext>(stepId: string, event: unknown, ctx: Context<TContext>): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Runs a tool-style body to its return value: awaits a promise, or drains a
|
|
30
|
+
* generator, passing each yield to `onYield`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function runToReturn(result: unknown, onYield: (value: unknown) => Promise<void>): Promise<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Lets `ctx` accept the final items of every custom item `step` declares, before one
|
|
35
|
+
* is appended or replayed from the ledger. Contexts created from `ctx` later inherit
|
|
36
|
+
* the wider schemas.
|
|
37
|
+
*/
|
|
38
|
+
export declare function allowCustomItems<TContext, I, O>(step: Step<TContext, I, O>, ctx: Context<TContext>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Every custom item declared anywhere in `step`'s static tree, for a harness to accept
|
|
41
|
+
* before it rebuilds or restores a log that may hold them.
|
|
42
|
+
*/
|
|
43
|
+
export declare function collectCustomItems(step: Step): CustomItem[];
|
|
44
|
+
/**
|
|
45
|
+
* Schemas that let a context's item log accept these items' final forms. They gate on
|
|
46
|
+
* `type` and `id` only: the emitter has already checked the fields against `output`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function customItemGates(items: ReadonlyArray<CustomItem>): ZodTypeAny[];
|
|
13
49
|
/**
|
|
14
50
|
* Puts a replayed entry's items back on the log. The ones at `emitted` (the entry's
|
|
15
51
|
* `streamed` indices) keep their mark, so a parent that records on this resumed run
|