@noetic-tools/core 5.13.0 → 5.14.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/decide-builders.d.ts +2 -2
- package/dist/builders/dynamic-workflow.js +2 -0
- package/dist/builders/provide-builder.d.ts +2 -2
- package/dist/builders/spawn-builder.d.ts +2 -2
- package/dist/builders/step-builders.d.ts +5 -5
- package/dist/builders/workflow-hydrator.d.ts +1 -1
- package/dist/builders/workflow-hydrator.js +53 -3
- package/dist/expression/check.js +14 -0
- package/dist/expression/jsonata.d.ts +7 -0
- package/dist/expression/jsonata.js +11 -1
- package/dist/harness/agent-harness.d.ts +59 -5
- package/dist/harness/agent-harness.js +176 -25
- package/dist/harness/deps/runtime.d.ts +4 -0
- package/dist/harness/deps/runtime.js +2 -0
- package/dist/harness/model-call.js +69 -0
- package/dist/harness/model-rounds.d.ts +52 -0
- package/dist/harness/model-rounds.js +115 -0
- package/dist/harness/thread-record.d.ts +54 -0
- package/dist/harness/thread-record.js +159 -0
- package/dist/index.d.ts +2 -2
- package/dist/interpreter/emit-items.d.ts +19 -0
- package/dist/interpreter/emit-items.js +106 -0
- package/dist/interpreter/execute-action.js +3 -0
- package/dist/interpreter/execute-control.js +3 -0
- package/dist/interpreter/execute.js +66 -9
- package/dist/runtime/context-impl.d.ts +106 -4
- package/dist/runtime/context-impl.js +224 -14
- package/dist/runtime/durable/harness-checkpoints.d.ts +13 -3
- package/dist/runtime/durable/harness-checkpoints.js +66 -7
- package/dist/runtime/durable/session-store.d.ts +37 -0
- package/dist/runtime/durable/session-store.js +58 -0
- package/dist/runtime/durable/step-ledger.d.ts +77 -40
- package/dist/runtime/durable/step-ledger.js +193 -73
- package/dist/runtime/item-log-impl.d.ts +6 -0
- package/dist/runtime/item-log-impl.js +12 -0
- package/dist/runtime/session-runner.d.ts +25 -1
- package/dist/runtime/session-runner.js +83 -11
- package/dist/schemas/workflow.d.ts +1 -1
- package/dist/types/checkpoint.d.ts +21 -4
- package/dist/types/checkpoint.js +33 -3
- package/package.json +2 -2
- package/schema/noetic-workflow.schema.json +391 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AnsweredAll, CaseKeyOf, Context, ContextData, DecideQuestions, DecideStep, DecideView, Lazy, ProjectionPolicy, Step, StepConditional, StepReplay } from '@noetic-tools/types';
|
|
1
|
+
import type { AnsweredAll, CaseKeyOf, Context, ContextData, DecideAnswers, DecideQuestions, DecideStep, DecideView, Lazy, ProjectionPolicy, Step, StepConditional, StepEmitItems, StepReplay } from '@noetic-tools/types';
|
|
2
2
|
/** @public Options for `decide()`. */
|
|
3
|
-
export interface StepDecideOpts<TContext, Q extends DecideQuestions, I = unknown> extends StepReplay<TContext, I
|
|
3
|
+
export interface StepDecideOpts<TContext, Q extends DecideQuestions, I = unknown> extends StepReplay<TContext, I>, StepEmitItems<TContext, DecideAnswers<Q>> {
|
|
4
4
|
id: string;
|
|
5
5
|
/** Decision model id. Falls back to `harness.config.decisionModel`. */
|
|
6
6
|
model?: Lazy<string, TContext>;
|
|
@@ -40,6 +40,8 @@ A WorkflowNode is one of:
|
|
|
40
40
|
|
|
41
41
|
Every entry of a callModel node's "tools" is an OBJECT, never a bare string. Use { "type": "<tool-name>" } to let the model call one of the tools listed below. Two provider-executed tools are also available without being listed: { "type": "openrouter:web_search" } and { "type": "openrouter:web_fetch" }, each accepting an optional "parameters" object.
|
|
42
42
|
|
|
43
|
+
Any node may carry "emitItems": true to show its output to the user as an assistant message the moment it finishes, or "emitItems": { "expr": "<JSONata expression on the output, e.g. 'Done ' & n & ' items'>" } to show computed text (no value shows nothing). Add "as": "items" to emit conversation items instead (the expression, or the output itself, must give an object with a string "type", or a list of them; only use custom "prefix:name" types the task says are registered). Use it for progress inside loops: only the workflow's final output is shown otherwise.
|
|
44
|
+
|
|
43
45
|
An acp-agent node delegates a turn to an external coding agent over the Agent Client Protocol; only emit one if a matching agent adapter is registered for the workflow.
|
|
44
46
|
|
|
45
47
|
An UntilPredicate (the "until" field of a loop) is one of:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContextConfig, ContextData, ContextLayer } from '@noetic-tools/context';
|
|
2
|
-
import type { Step, StepReplay, StepWithContext } from '@noetic-tools/types';
|
|
3
|
-
export interface WithContextOpts<TContext, I, O> extends StepReplay<TContext, I> {
|
|
2
|
+
import type { Step, StepEmitItems, StepReplay, StepWithContext } from '@noetic-tools/types';
|
|
3
|
+
export interface WithContextOpts<TContext, I, O> extends StepReplay<TContext, I>, StepEmitItems<TContext, O> {
|
|
4
4
|
id: string;
|
|
5
5
|
child: Step<TContext, I, O>;
|
|
6
6
|
context: ContextConfig | ContextLayer[];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ContextConfig, ContextData, ContextLayer } from '@noetic-tools/context';
|
|
2
|
-
import type { Step, StepReplay, StepSpawn, SubprocessAdapter } from '@noetic-tools/types';
|
|
2
|
+
import type { Step, StepEmitItems, StepReplay, StepSpawn, SubprocessAdapter } from '@noetic-tools/types';
|
|
3
3
|
/**
|
|
4
4
|
* Options for {@link spawn}.
|
|
5
5
|
*
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
export interface SpawnOpts<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I> {
|
|
8
|
+
export interface SpawnOpts<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I>, StepEmitItems<TContext, O> {
|
|
9
9
|
id: string;
|
|
10
10
|
child: Step<TContext, I, O>;
|
|
11
11
|
context?: ContextConfig | ContextLayer[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContextData } from '@noetic-tools/context';
|
|
2
|
-
import type { AcpAgent, AcpClientCapabilityConfig, AcpContentBlock, AcpMcpServer, AcpPermissionHandler, AcpPermissionPolicy, AcpSessionPolicy, Context, Lazy, ModelParams, OutputCodec, RetryPolicy, ServerToolSpec, StandardSchemaV1, StepAcpAgent, StepCallModel, StepInvokeTool, StepReplay, StepRunCode, SubprocessAdapter, Tool, ToolChoice } from '@noetic-tools/types';
|
|
3
|
-
export interface RunCodeOpts<TContext, I, O> extends StepReplay<TContext, I> {
|
|
2
|
+
import type { AcpAgent, AcpClientCapabilityConfig, AcpContentBlock, AcpMcpServer, AcpPermissionHandler, AcpPermissionPolicy, AcpSessionPolicy, Context, Lazy, ModelParams, OutputCodec, RetryPolicy, ServerToolSpec, StandardSchemaV1, StepAcpAgent, StepCallModel, StepEmitItems, StepInvokeTool, StepReplay, StepRunCode, SubprocessAdapter, Tool, ToolChoice } from '@noetic-tools/types';
|
|
3
|
+
export interface RunCodeOpts<TContext, I, O> extends StepReplay<TContext, I>, StepEmitItems<TContext, O> {
|
|
4
4
|
id: string;
|
|
5
5
|
execute: (input: I, ctx: Context<TContext>) => Promise<O>;
|
|
6
6
|
retry?: RetryPolicy;
|
|
@@ -11,7 +11,7 @@ export interface RunCodeOpts<TContext, I, O> extends StepReplay<TContext, I> {
|
|
|
11
11
|
*/
|
|
12
12
|
subprocess?: SubprocessAdapter;
|
|
13
13
|
}
|
|
14
|
-
export interface CallModelOpts<TContext, O, I = unknown> extends StepReplay<TContext, I> {
|
|
14
|
+
export interface CallModelOpts<TContext, O, I = unknown> extends StepReplay<TContext, I>, StepEmitItems<TContext, O> {
|
|
15
15
|
id: string;
|
|
16
16
|
/** Model id. Eager string or `(ctx) => string` getter (resolved at step execution). */
|
|
17
17
|
model: Lazy<string, TContext>;
|
|
@@ -38,12 +38,12 @@ export interface CallModelOpts<TContext, O, I = unknown> extends StepReplay<TCon
|
|
|
38
38
|
params?: ModelParams;
|
|
39
39
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
40
40
|
}
|
|
41
|
-
export interface InvokeToolOpts<I, O, TContext = ContextData> extends StepReplay<TContext, I> {
|
|
41
|
+
export interface InvokeToolOpts<I, O, TContext = ContextData> extends StepReplay<TContext, I>, StepEmitItems<TContext, O> {
|
|
42
42
|
id: string;
|
|
43
43
|
tool: Tool<StandardSchemaV1<unknown, I>, StandardSchemaV1<unknown, O>>;
|
|
44
44
|
args?: Partial<I>;
|
|
45
45
|
}
|
|
46
|
-
export interface StepAcpAgentOpts<TContext, O, I = unknown> extends StepReplay<TContext, I> {
|
|
46
|
+
export interface StepAcpAgentOpts<TContext, O, I = unknown> extends StepReplay<TContext, I>, StepEmitItems<TContext, O> {
|
|
47
47
|
id: string;
|
|
48
48
|
/** An ACP agent adapter, e.g. `claudeCode()` from `@noetic-tools/acp`. Eager or `(ctx) => AcpAgent`. */
|
|
49
49
|
agent: Lazy<AcpAgent, TContext>;
|
|
@@ -66,7 +66,7 @@ export interface HydrationContext {
|
|
|
66
66
|
* @throws `NoeticConfigError` with code `UNKNOWN_WORKFLOW_REFERENCE` (at execution time) if a subflow ref names no registered workflow.
|
|
67
67
|
* @throws `NoeticConfigError` with code `WORKFLOW_RECURSION_LIMIT` (at execution time) if named sub-workflow refs nest deeper than `maxRecursionDepth`.
|
|
68
68
|
* @throws `NoeticConfigError` with code `INVALID_MAX_RECURSION_DEPTH` (at execution time) when a named ref resolves under a `maxRecursionDepth` that is not a positive integer or `Infinity`.
|
|
69
|
-
* @throws `NoeticConfigError` with code `WORKFLOW_VALIDATION_FAILED` if a `compute` expression, a conditional route's `expr`,
|
|
69
|
+
* @throws `NoeticConfigError` with code `WORKFLOW_VALIDATION_FAILED` if a `compute` expression, a conditional route's `expr`, an `expr` until predicate, or an `emitItems` expression does not parse.
|
|
70
70
|
* @throws `NoeticConfigError` with code `INVALID_EXPRESSION_LIMITS` if an expression compiles under `expressionLimits` holding a value that is not a positive integer or `Infinity`.
|
|
71
71
|
* @throws `NoeticConfigError` with code `EXPRESSION_FAILED` or `EXPRESSION_LIMIT_EXCEEDED` (at execution time) if an expression fails or exceeds its limits.
|
|
72
72
|
*/
|
|
@@ -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, isServerToolSpec, NoeticConfigError } from '@noetic-tools/types';
|
|
9
|
-
import { compileExpression, compute, passes, readInput } from '../expression/jsonata.js';
|
|
8
|
+
import { frameworkCast, ItemSchema, isServerToolSpec, NoeticConfigError, } from '@noetic-tools/types';
|
|
9
|
+
import { compileExpression, compute, computeMaybe, 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';
|
|
@@ -650,6 +650,53 @@ function parseJsonObject(text) {
|
|
|
650
650
|
return text;
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
|
+
/**
|
|
654
|
+
* The object form of a node's `emitItems` builds an emit function: the value is the
|
|
655
|
+
* `expr` result, or the output itself read as JSON, and no value emits nothing, so one
|
|
656
|
+
* node can emit on some iterations of a loop and stay quiet on others.
|
|
657
|
+
*/
|
|
658
|
+
function workflowEmitItems(nodeId, option, ctx) {
|
|
659
|
+
if (typeof option === 'boolean') {
|
|
660
|
+
return option;
|
|
661
|
+
}
|
|
662
|
+
const where = `emitItems of node '${nodeId}'`;
|
|
663
|
+
const expr = option.expr === undefined
|
|
664
|
+
? undefined
|
|
665
|
+
: compileExpression(option.expr, where, ctx.expressionLimits);
|
|
666
|
+
const asItems = option.as === 'items';
|
|
667
|
+
if (!expr && !asItems) {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
return async (output) => {
|
|
671
|
+
const value = expr ? await computeMaybe(expr, readInput(output)) : readInput(output);
|
|
672
|
+
if (value === undefined) {
|
|
673
|
+
return undefined;
|
|
674
|
+
}
|
|
675
|
+
return asItems ? itemList(value, where) : stringifyResult(value);
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Reads a value as items: one object or a list of them, each with a string `type`.
|
|
680
|
+
* Whether a type is allowed is the item log's call, against the harness's item schemas.
|
|
681
|
+
*
|
|
682
|
+
* @throws `NoeticConfigError` with code `INVALID_EMIT_ITEMS` when the value is not an
|
|
683
|
+
* item or a list of items.
|
|
684
|
+
*/
|
|
685
|
+
function itemList(value, where) {
|
|
686
|
+
const list = Array.isArray(value)
|
|
687
|
+
? value
|
|
688
|
+
: [
|
|
689
|
+
value,
|
|
690
|
+
];
|
|
691
|
+
if (!list.every((entry) => ItemSchema.safeParse(entry).success)) {
|
|
692
|
+
throw new NoeticConfigError({
|
|
693
|
+
code: 'INVALID_EMIT_ITEMS',
|
|
694
|
+
message: `The ${where} gave ${JSON.stringify(value)}, which is not an item or a list of items.`,
|
|
695
|
+
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.',
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
return frameworkCast(list);
|
|
699
|
+
}
|
|
653
700
|
function stringifyResult(value) {
|
|
654
701
|
if (typeof value === 'string') {
|
|
655
702
|
return value;
|
|
@@ -815,7 +862,7 @@ async function runCodeViaSubprocess(opts) {
|
|
|
815
862
|
* @throws `NoeticConfigError` with code `UNKNOWN_WORKFLOW_REFERENCE` (at execution time) if a subflow ref names no registered workflow.
|
|
816
863
|
* @throws `NoeticConfigError` with code `WORKFLOW_RECURSION_LIMIT` (at execution time) if named sub-workflow refs nest deeper than `maxRecursionDepth`.
|
|
817
864
|
* @throws `NoeticConfigError` with code `INVALID_MAX_RECURSION_DEPTH` (at execution time) when a named ref resolves under a `maxRecursionDepth` that is not a positive integer or `Infinity`.
|
|
818
|
-
* @throws `NoeticConfigError` with code `WORKFLOW_VALIDATION_FAILED` if a `compute` expression, a conditional route's `expr`,
|
|
865
|
+
* @throws `NoeticConfigError` with code `WORKFLOW_VALIDATION_FAILED` if a `compute` expression, a conditional route's `expr`, an `expr` until predicate, or an `emitItems` expression does not parse.
|
|
819
866
|
* @throws `NoeticConfigError` with code `INVALID_EXPRESSION_LIMITS` if an expression compiles under `expressionLimits` holding a value that is not a positive integer or `Infinity`.
|
|
820
867
|
* @throws `NoeticConfigError` with code `EXPRESSION_FAILED` or `EXPRESSION_LIMIT_EXCEEDED` (at execution time) if an expression fails or exceeds its limits.
|
|
821
868
|
*/
|
|
@@ -836,6 +883,9 @@ export function hydrateNode(node, ctx) {
|
|
|
836
883
|
if (node.replayKey !== undefined) {
|
|
837
884
|
hydrated.replayKey = workflowReplayKey(node.id, node.replayKey);
|
|
838
885
|
}
|
|
886
|
+
if (node.emitItems !== undefined) {
|
|
887
|
+
hydrated.emitItems = workflowEmitItems(node.id, node.emitItems, ctx);
|
|
888
|
+
}
|
|
839
889
|
return hydrated;
|
|
840
890
|
}
|
|
841
891
|
/**
|
package/dist/expression/check.js
CHANGED
|
@@ -26,6 +26,20 @@ export function expressionErrors(root) {
|
|
|
26
26
|
//#endregion
|
|
27
27
|
//#region Helpers
|
|
28
28
|
function expressionsOf(node) {
|
|
29
|
+
const emitted = typeof node.emitItems === 'object' && node.emitItems.expr !== undefined
|
|
30
|
+
? [
|
|
31
|
+
{
|
|
32
|
+
where: `emitItems of node '${node.id}'`,
|
|
33
|
+
source: node.emitItems.expr,
|
|
34
|
+
},
|
|
35
|
+
]
|
|
36
|
+
: [];
|
|
37
|
+
return [
|
|
38
|
+
...emitted,
|
|
39
|
+
...kindExpressionsOf(node),
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
function kindExpressionsOf(node) {
|
|
29
43
|
if (node.kind === 'compute') {
|
|
30
44
|
return [
|
|
31
45
|
{
|
|
@@ -49,6 +49,13 @@ export declare function syntaxError(source: string): string | undefined;
|
|
|
49
49
|
* @throws `NoeticConfigError` with code `EXPRESSION_FAILED` or `EXPRESSION_LIMIT_EXCEEDED`.
|
|
50
50
|
*/
|
|
51
51
|
export declare function compute(expr: CompiledExpression, input: unknown): Promise<unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* Evaluates like `compute`, except that "no value" resolves to `undefined`
|
|
54
|
+
* instead of failing, for callers where nothing is a valid answer.
|
|
55
|
+
*
|
|
56
|
+
* @throws `NoeticConfigError` with code `EXPRESSION_FAILED` or `EXPRESSION_LIMIT_EXCEEDED`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function computeMaybe(expr: CompiledExpression, input: unknown): Promise<unknown>;
|
|
52
59
|
/**
|
|
53
60
|
* Evaluates an `expr` test. `true` passes; `false` and JSONata's "no value"
|
|
54
61
|
* (`undefined`, e.g. a path that matched nothing) do not; anything else fails.
|
|
@@ -89,10 +89,20 @@ export function syntaxError(source) {
|
|
|
89
89
|
* @throws `NoeticConfigError` with code `EXPRESSION_FAILED` or `EXPRESSION_LIMIT_EXCEEDED`.
|
|
90
90
|
*/
|
|
91
91
|
export async function compute(expr, input) {
|
|
92
|
-
const result = await expr
|
|
92
|
+
const result = await computeMaybe(expr, input);
|
|
93
93
|
if (result === undefined) {
|
|
94
94
|
throw failed(expr.where, 'the expression gave no value; check the paths it reads.');
|
|
95
95
|
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Evaluates like `compute`, except that "no value" resolves to `undefined`
|
|
100
|
+
* instead of failing, for callers where nothing is a valid answer.
|
|
101
|
+
*
|
|
102
|
+
* @throws `NoeticConfigError` with code `EXPRESSION_FAILED` or `EXPRESSION_LIMIT_EXCEEDED`.
|
|
103
|
+
*/
|
|
104
|
+
export async function computeMaybe(expr, input) {
|
|
105
|
+
const result = await expr.run(input);
|
|
96
106
|
if (holdsFunction(result)) {
|
|
97
107
|
throw failed(expr.where, 'the expression gave a function, which has no JSON form.');
|
|
98
108
|
}
|
|
@@ -19,16 +19,18 @@ export interface StorageEnvironmentConfig {
|
|
|
19
19
|
adapter?: StorageAdapter;
|
|
20
20
|
/**
|
|
21
21
|
* Checkpoint store used by `harness.checkpoint(ctx)` / `harness.restore()`.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* to
|
|
22
|
+
* Defaults to a store over `adapter` when one is given, so configuring durable
|
|
23
|
+
* storage is enough for a later harness on the same storage to resume this one's
|
|
24
|
+
* executions (see the harness `durability` option to turn that off). With no
|
|
25
|
+
* adapter and no store, checkpoint/restore are no-ops — a zero-config harness keeps
|
|
26
|
+
* its ephemeral semantics.
|
|
25
27
|
*/
|
|
26
28
|
checkpointStore?: CheckpointStore;
|
|
27
29
|
/** Layer-state store override. Defaults to an in-memory store. */
|
|
28
30
|
layerStateStore?: LayerStateStore;
|
|
29
31
|
/**
|
|
30
32
|
* Bounds on the step-completion ledger that backs step-level resume. Only meaningful
|
|
31
|
-
*
|
|
33
|
+
* when durability is on (a `checkpointStore`, given or defaulted). Defaults to `DEFAULT_STEP_LEDGER_RETENTION` — 128 KiB
|
|
32
34
|
* per entry, 1000 entries per execution — so an unbounded run cannot grow an unbounded
|
|
33
35
|
* ledger. Exceeding either cap costs resumability for the affected steps (they re-run),
|
|
34
36
|
* never correctness.
|
|
@@ -57,6 +59,14 @@ interface AgentHarnessOpts<TParams extends Record<string, unknown> = Record<stri
|
|
|
57
59
|
agentGraph?: Step<ContextData, string, string>;
|
|
58
60
|
/** Default context layers applied to every context created via `createContext()` / `execute()`. */
|
|
59
61
|
contextLayers?: ContextLayer[];
|
|
62
|
+
/**
|
|
63
|
+
* Whether runs and sessions are durable: checkpointed, recorded to the step ledger,
|
|
64
|
+
* and resumable on a later harness over the same storage. Defaults to true whenever
|
|
65
|
+
* `environment.storage` gives an adapter or a checkpoint store. `false` turns every
|
|
66
|
+
* durability surface off even then — the adapter still backs context-layer
|
|
67
|
+
* persistence.
|
|
68
|
+
*/
|
|
69
|
+
durability?: boolean;
|
|
60
70
|
hooks?: AgentHooks;
|
|
61
71
|
/**
|
|
62
72
|
* Harness-wide tool pool. Merged (identity-deduplicated) with tools
|
|
@@ -90,6 +100,13 @@ interface AgentHarnessOpts<TParams extends Record<string, unknown> = Record<stri
|
|
|
90
100
|
initialCwd?: string;
|
|
91
101
|
/** Default model for `decide` steps. */
|
|
92
102
|
decisionModel?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Whether a resumed run streams again the items its replayed steps emitted
|
|
105
|
+
* (`step.emitItems`), as `item_appended`. Defaults to `false`: a replay rebuilds the
|
|
106
|
+
* log quietly. Set it when a client that reconnects to a resumed run should see
|
|
107
|
+
* the progress it missed.
|
|
108
|
+
*/
|
|
109
|
+
emitItemsOnReplay?: boolean;
|
|
93
110
|
/**
|
|
94
111
|
* Approves or refuses calls to tools that declare `needsApproval`, after the
|
|
95
112
|
* `beforeToolCall` layers allow them. Without one, those calls run
|
|
@@ -147,7 +164,8 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
|
|
|
147
164
|
readonly checkpointStore?: CheckpointStore;
|
|
148
165
|
/**
|
|
149
166
|
* Append-only step ledger backing resume. Present exactly when durability is on
|
|
150
|
-
* (a `CheckpointStore` is configured), so a zero-config harness records
|
|
167
|
+
* (a `CheckpointStore` is configured or defaulted), so a zero-config harness records
|
|
168
|
+
* nothing.
|
|
151
169
|
* @internal
|
|
152
170
|
*/
|
|
153
171
|
readonly stepLedgerStore?: StepLedgerStore;
|
|
@@ -177,6 +195,10 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
|
|
|
177
195
|
* re-entrant run depth — see `executeClosingChannels`.
|
|
178
196
|
*/
|
|
179
197
|
private readonly liveRoots;
|
|
198
|
+
/** Stored sessions for `execute()` threads. Present exactly when durability is on. */
|
|
199
|
+
private readonly sessionStore?;
|
|
200
|
+
/** Checkpoint capture in flight per execution id — see `saveCheckpoint`. */
|
|
201
|
+
private readonly pendingCheckpoints;
|
|
180
202
|
private readonly callModelOverride?;
|
|
181
203
|
private readonly defaultDeliveryMode;
|
|
182
204
|
private readonly sessions;
|
|
@@ -268,6 +290,8 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
|
|
|
268
290
|
getUsage(scope?: SessionScope): SessionUsage;
|
|
269
291
|
seedSessionHistory(threadId: string, items: ReadonlyArray<Item>): void;
|
|
270
292
|
private getOrCreateSession;
|
|
293
|
+
/** The stored record for `threadId`, when durability is on. */
|
|
294
|
+
private threadRecord;
|
|
271
295
|
private requireSession;
|
|
272
296
|
callModel(request: CallModelRequest): Promise<LLMResponse>;
|
|
273
297
|
decide(request: DecideRequest): Promise<DecideResponse>;
|
|
@@ -292,6 +316,29 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
|
|
|
292
316
|
* close anything.
|
|
293
317
|
*/
|
|
294
318
|
private executeClosingChannels;
|
|
319
|
+
/**
|
|
320
|
+
* Fix the point a resume of this run starts from, and queue it for saving — so even
|
|
321
|
+
* a run whose first step dies leaves a snapshot to restore. The save is not awaited:
|
|
322
|
+
* the steps' own checkpoints queue behind it.
|
|
323
|
+
*
|
|
324
|
+
* When the context's last run never finished, the run repeats it, and it does so
|
|
325
|
+
* from storage — the stored baseline and ledger — exactly as a new harness resuming
|
|
326
|
+
* the execution would, not from what the failed attempt left in memory.
|
|
327
|
+
*/
|
|
328
|
+
private beginDurableRun;
|
|
329
|
+
/**
|
|
330
|
+
* Stand `ctx` at its stored baseline and give it the stored ledger. Without a
|
|
331
|
+
* snapshot (its save failed), the baseline the context fixed in memory when the run
|
|
332
|
+
* began is the best record left.
|
|
333
|
+
*/
|
|
334
|
+
private rebuildFromStorage;
|
|
335
|
+
/**
|
|
336
|
+
* A finished run is the next run's starting point: persist the live log and counts,
|
|
337
|
+
* then drop the run's positional ledger entries, which no later resume can reach.
|
|
338
|
+
* They are kept when the snapshot failed to land, since that snapshot still points
|
|
339
|
+
* at this run's start. A failed run skips this entirely — it is what a resume repeats.
|
|
340
|
+
*/
|
|
341
|
+
private endDurableRun;
|
|
295
342
|
/**
|
|
296
343
|
* Idempotently run layer `init` hooks for `ctx` (keyed by `ctx.id`). Init
|
|
297
344
|
* MUST complete before any recall/store fires so init-bearing layers are not
|
|
@@ -371,6 +418,13 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
|
|
|
371
418
|
* logic live beside the other durability machinery.
|
|
372
419
|
*/
|
|
373
420
|
checkpoint(ctx: Context): Promise<void>;
|
|
421
|
+
/**
|
|
422
|
+
* Capture `ctx` behind any capture still in flight for the same execution, and
|
|
423
|
+
* resolve true when this one landed. Every step in the tree checkpoints its root,
|
|
424
|
+
* and concurrent paths would otherwise race their writes: on a networked adapter an
|
|
425
|
+
* older snapshot could land last and win.
|
|
426
|
+
*/
|
|
427
|
+
private saveCheckpoint;
|
|
374
428
|
/**
|
|
375
429
|
* Rebuild a `Context` from what a previous run of `executionId` recorded: its
|
|
376
430
|
* checkpoint snapshot, its step-completion ledger, or both. Without a snapshot the
|