@noetic-tools/core 5.19.1-next.1 → 5.20.0-next.1
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 +2 -2
- package/schema/noetic-workflow.schema.json +1170 -92
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NoeticConfigError } from '@noetic-tools/types';
|
|
2
2
|
import { getDefaultRegistrar } from '../types/step-registrar.js';
|
|
3
|
+
import { toStep } from './sequence.js';
|
|
3
4
|
//#endregion
|
|
4
5
|
//#region Public API
|
|
5
6
|
/**
|
|
@@ -36,7 +37,7 @@ export function spawn(opts) {
|
|
|
36
37
|
const built = {
|
|
37
38
|
kind: 'spawn',
|
|
38
39
|
id: opts.id,
|
|
39
|
-
child: opts.child,
|
|
40
|
+
child: toStep(opts.child),
|
|
40
41
|
context: opts.context,
|
|
41
42
|
timeout: opts.timeout,
|
|
42
43
|
steers: opts.steers,
|
|
@@ -48,7 +49,7 @@ export function spawn(opts) {
|
|
|
48
49
|
// Ensure the child is addressable by id — builders for `runCode`/`callModel`/`invokeTool`
|
|
49
50
|
// self-register, but a caller can construct a step literal and pass it as
|
|
50
51
|
// `child` without going through a builder.
|
|
51
|
-
getDefaultRegistrar().register(
|
|
52
|
+
getDefaultRegistrar().register(built.child);
|
|
52
53
|
return built;
|
|
53
54
|
}
|
|
54
55
|
//#endregion
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ContextData } from '@noetic-tools/context';
|
|
2
|
-
import type { AcpAgent, AcpClientCapabilityConfig, AcpContentBlock, AcpMcpServer, AcpPermissionHandler, AcpPermissionPolicy, AcpSessionPolicy, CustomItemMap, CustomItemsBrand, Lazy, ModelParams, OutputCodec, RetryPolicy, RunCodeExecute, ServerToolSpec, StandardSchemaV1, StepAcpAgent, StepCallModel, StepEmitItems, StepInvokeTool, StepReplay, StepRunCode, SubprocessAdapter, Tool, ToolChoice } from '@noetic-tools/types';
|
|
2
|
+
import type { AcpAgent, AcpClientCapabilityConfig, AcpContentBlock, AcpMcpServer, AcpPermissionHandler, AcpPermissionPolicy, AcpSessionPolicy, AnyProfile, ConnectionEvent, ConnectionHandle, Context, CustomItemMap, CustomItemsBrand, Lazy, ModelParams, OperationInput, OperationName, OperationOutput, OutputCodec, RetryPolicy, RunCodeExecute, ServerToolSpec, StandardSchemaV1, Step, StepAcpAgent, StepCall, StepCallModel, StepEmitItems, StepInvokeTool, StepReplay, StepRunCode, StepWait, StepWaitOutput, SubprocessAdapter, Tool, ToolChoice } from '@noetic-tools/types';
|
|
3
|
+
import { verify } from './verify-builder.js';
|
|
3
4
|
export interface RunCodeOpts<TContext, I, O, M extends CustomItemMap = CustomItemMap> extends StepReplay<TContext, I>, StepEmitItems<TContext, I, O, M> {
|
|
4
5
|
id: string;
|
|
5
6
|
/** Async, or a generator whose yields are events of the item `emitItems` names. */
|
|
@@ -76,6 +77,46 @@ export interface StepAcpAgentOpts<TContext, O, I = unknown> extends StepReplay<T
|
|
|
76
77
|
session?: AcpSessionPolicy;
|
|
77
78
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
78
79
|
}
|
|
80
|
+
/** The operation names a call on `P`'s handle may use: its profile's, or any for a handle without one. */
|
|
81
|
+
export type CallOpName<P> = [
|
|
82
|
+
P
|
|
83
|
+
] extends [
|
|
84
|
+
AnyProfile
|
|
85
|
+
] ? OperationName<P> : string;
|
|
86
|
+
/** A call's argument type: the profile operation's input, or `unknown` without a profile. */
|
|
87
|
+
export type CallInput<P, Op extends string> = [
|
|
88
|
+
P
|
|
89
|
+
] extends [
|
|
90
|
+
AnyProfile
|
|
91
|
+
] ? Op extends OperationName<P> ? OperationInput<P, Op> : never : Readonly<Record<string, unknown>>;
|
|
92
|
+
/** A call's output type: the profile operation's output, or `unknown` without a profile. */
|
|
93
|
+
export type CallOutput<P, Op extends string> = [
|
|
94
|
+
P
|
|
95
|
+
] extends [
|
|
96
|
+
AnyProfile
|
|
97
|
+
] ? Op extends OperationName<P> ? OperationOutput<P, Op> : unknown : unknown;
|
|
98
|
+
/** `step.call`'s options. With a profiled handle, `op`, `args` and the output are typed by the profile. */
|
|
99
|
+
export interface CallOpts<TContext, I, P extends AnyProfile | undefined, Op extends string> extends StepReplay<TContext, I>, StepEmitItems<TContext, I, CallOutput<P, Op>> {
|
|
100
|
+
id: string;
|
|
101
|
+
/** A handle from `connection()`, or a harness connection name. */
|
|
102
|
+
connection: ConnectionHandle<P> | string;
|
|
103
|
+
op: Op;
|
|
104
|
+
/** A value, or a function of the step's input. Secrets (`secret('name')`) go in `sensitive` fields. */
|
|
105
|
+
args?: CallInput<P, Op> | ((input: I, ctx: Context<TContext>) => CallInput<P, Op> | Promise<CallInput<P, Op>>);
|
|
106
|
+
}
|
|
107
|
+
/** `step.wait`'s options. */
|
|
108
|
+
export interface WaitOpts<TContext, I, A = unknown> extends StepReplay<TContext, I>, StepEmitItems<TContext, I, StepWaitOutput<unknown, A>> {
|
|
109
|
+
id: string;
|
|
110
|
+
connection: ConnectionHandle | string;
|
|
111
|
+
/** The event type, e.g. `chat.message.created`. */
|
|
112
|
+
event: string;
|
|
113
|
+
/** Picks the event that ends the wait; every event of the type matches without one. */
|
|
114
|
+
filter?: (event: ConnectionEvent, input: I, ctx: Context<TContext>) => boolean | Promise<boolean>;
|
|
115
|
+
/** A step, or an array of steps run in sequence, run once listening has started. */
|
|
116
|
+
around?: Step<TContext, I, A> | ReadonlyArray<Step<TContext, I, unknown>>;
|
|
117
|
+
/** How long to wait, in ms, from when listening starts. Must be positive. */
|
|
118
|
+
timeoutMs: number;
|
|
119
|
+
}
|
|
79
120
|
/**
|
|
80
121
|
* Creates a pure async computation step.
|
|
81
122
|
*
|
|
@@ -148,4 +189,42 @@ export declare const step: {
|
|
|
148
189
|
* @throws `NoeticConfigError` `EMPTY_STEP_ID` / `MISSING_ACP_AGENT` / `MISSING_PROMPT`.
|
|
149
190
|
*/
|
|
150
191
|
acpAgent<TContext = Readonly<Record<string, Record<string, unknown>>>, I = unknown, O = unknown>(opts: StepAcpAgentOpts<TContext, O, I>): StepAcpAgent<TContext, I, O>;
|
|
192
|
+
/**
|
|
193
|
+
* Creates a step that runs one connection operation and returns its result
|
|
194
|
+
* (spec 35). With a handle from `connection(name, profile)`, `op`, `args` and
|
|
195
|
+
* the output are typed by the profile. Long upstream operations are waited for.
|
|
196
|
+
*
|
|
197
|
+
* @public
|
|
198
|
+
* @param opts.id - Unique step identifier.
|
|
199
|
+
* @param opts.connection - A handle from `connection()`, or a harness connection name.
|
|
200
|
+
* @param opts.op - The operation, e.g. `ui.tap`.
|
|
201
|
+
* @param opts.args - A value, or a function of the step's input.
|
|
202
|
+
* @returns A `StepCall`, auto-registered in the step registry.
|
|
203
|
+
* @throws `NoeticConfigError` `EMPTY_STEP_ID`, or `CONNECTION_INVALID` for a missing connection or an operation name without a dot.
|
|
204
|
+
*/
|
|
205
|
+
call<TContext = Readonly<Record<string, Record<string, unknown>>>, I = unknown, P extends AnyProfile | undefined = undefined, const Op extends CallOpName<P> = CallOpName<P>>(opts: CallOpts<TContext, I, P, Op>): StepCall<TContext, I, CallOutput<P, Op>>;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a step that waits for a connection event (spec 35). With `around`,
|
|
208
|
+
* it starts listening, runs `around`, then waits, so the event an action
|
|
209
|
+
* causes cannot slip past. Its output is `{ event, around }`.
|
|
210
|
+
*
|
|
211
|
+
* @public
|
|
212
|
+
* @param opts.id - Unique step identifier.
|
|
213
|
+
* @param opts.connection - A handle from `connection()`, or a harness connection name.
|
|
214
|
+
* @param opts.event - The event type to wait for.
|
|
215
|
+
* @param opts.filter - Picks the matching event: `(event, input, ctx) => boolean`.
|
|
216
|
+
* @param opts.around - A step or an array of steps to run once listening has started.
|
|
217
|
+
* @param opts.timeoutMs - How long to wait, in ms.
|
|
218
|
+
* @returns A `StepWait`, auto-registered in the step registry.
|
|
219
|
+
* @throws `NoeticConfigError` `EMPTY_STEP_ID`, or `CONNECTION_INVALID` for a missing connection, an empty event or a timeout that is not positive.
|
|
220
|
+
*/
|
|
221
|
+
wait<TContext = Readonly<Record<string, Record<string, unknown>>>, I = unknown, A = unknown>(opts: WaitOpts<TContext, I, A>): StepWait<TContext, I, StepWaitOutput<unknown, A>>;
|
|
222
|
+
/**
|
|
223
|
+
* Creates a step that checks claims about what a connection shows (spec 37):
|
|
224
|
+
* it declares what should become true, runs `act`, watches the connection's
|
|
225
|
+
* senses, and answers with the evidence. See `verify` in `./verify-builder`.
|
|
226
|
+
*
|
|
227
|
+
* @public
|
|
228
|
+
*/
|
|
229
|
+
verify: typeof verify;
|
|
151
230
|
};
|
|
@@ -1,6 +1,55 @@
|
|
|
1
|
-
import { isServerToolSpec, NoeticConfigError } from '@noetic-tools/types';
|
|
1
|
+
import { frameworkCast, isServerToolSpec, NoeticConfigError } from '@noetic-tools/types';
|
|
2
2
|
import { getDefaultRegistrar } from '../types/step-registrar.js';
|
|
3
3
|
import { checkEmitItems, isGeneratorFunction } from './custom-item.js';
|
|
4
|
+
import { verify } from './verify-builder.js';
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region Connection step validation
|
|
7
|
+
function requireStepId(builder, id) {
|
|
8
|
+
if (id && id.trim() !== '') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
throw new NoeticConfigError({
|
|
12
|
+
code: 'EMPTY_STEP_ID',
|
|
13
|
+
message: `${builder}() requires a non-empty id.`,
|
|
14
|
+
hint: `Pass a unique string as the id field, e.g. ${builder}({ id: "my-step", ... }).`,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function requireConnection(builder, id, connection) {
|
|
18
|
+
const named = typeof connection === 'string' && connection.length > 0;
|
|
19
|
+
const handle = typeof connection === 'object' &&
|
|
20
|
+
connection !== null &&
|
|
21
|
+
'kind' in connection &&
|
|
22
|
+
connection.kind === 'connection-handle';
|
|
23
|
+
if (named || handle) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
throw new NoeticConfigError({
|
|
27
|
+
code: 'CONNECTION_INVALID',
|
|
28
|
+
message: `${builder}(${JSON.stringify(id)}) names no connection.`,
|
|
29
|
+
hint: "Pass a handle from connection('name', profile), or a harness connection name.",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const OP_NAME_RE = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)+$/;
|
|
33
|
+
function requireOpName(id, op) {
|
|
34
|
+
if (OP_NAME_RE.test(op)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
throw new NoeticConfigError({
|
|
38
|
+
code: 'CONNECTION_INVALID',
|
|
39
|
+
message: `step.call(${JSON.stringify(id)}) has operation ${JSON.stringify(op)}, which is not an operation name.`,
|
|
40
|
+
hint: "An operation name has at least one dot, e.g. 'ui.tap' or 'chat.reply'.",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function requireTimeout(id, timeoutMs) {
|
|
44
|
+
if (Number.isFinite(timeoutMs) && timeoutMs > 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw new NoeticConfigError({
|
|
48
|
+
code: 'CONNECTION_INVALID',
|
|
49
|
+
message: `step.wait(${JSON.stringify(id)}) has timeoutMs ${timeoutMs}; it must be a positive number.`,
|
|
50
|
+
hint: 'Give the longest the wait may take, in ms, e.g. timeoutMs: 18e5 for 30 minutes.',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
4
53
|
//#endregion
|
|
5
54
|
//#region ACP agent builder helper
|
|
6
55
|
/**
|
|
@@ -207,5 +256,70 @@ export const step = {
|
|
|
207
256
|
getDefaultRegistrar().register(built);
|
|
208
257
|
return built;
|
|
209
258
|
},
|
|
259
|
+
/**
|
|
260
|
+
* Creates a step that runs one connection operation and returns its result
|
|
261
|
+
* (spec 35). With a handle from `connection(name, profile)`, `op`, `args` and
|
|
262
|
+
* the output are typed by the profile. Long upstream operations are waited for.
|
|
263
|
+
*
|
|
264
|
+
* @public
|
|
265
|
+
* @param opts.id - Unique step identifier.
|
|
266
|
+
* @param opts.connection - A handle from `connection()`, or a harness connection name.
|
|
267
|
+
* @param opts.op - The operation, e.g. `ui.tap`.
|
|
268
|
+
* @param opts.args - A value, or a function of the step's input.
|
|
269
|
+
* @returns A `StepCall`, auto-registered in the step registry.
|
|
270
|
+
* @throws `NoeticConfigError` `EMPTY_STEP_ID`, or `CONNECTION_INVALID` for a missing connection or an operation name without a dot.
|
|
271
|
+
*/
|
|
272
|
+
call(opts) {
|
|
273
|
+
requireStepId('step.call', opts.id);
|
|
274
|
+
requireConnection('step.call', opts.id, opts.connection);
|
|
275
|
+
requireOpName(opts.id, opts.op);
|
|
276
|
+
const built = {
|
|
277
|
+
kind: 'call',
|
|
278
|
+
...frameworkCast(opts),
|
|
279
|
+
};
|
|
280
|
+
getDefaultRegistrar().register(built);
|
|
281
|
+
return built;
|
|
282
|
+
},
|
|
283
|
+
/**
|
|
284
|
+
* Creates a step that waits for a connection event (spec 35). With `around`,
|
|
285
|
+
* it starts listening, runs `around`, then waits, so the event an action
|
|
286
|
+
* causes cannot slip past. Its output is `{ event, around }`.
|
|
287
|
+
*
|
|
288
|
+
* @public
|
|
289
|
+
* @param opts.id - Unique step identifier.
|
|
290
|
+
* @param opts.connection - A handle from `connection()`, or a harness connection name.
|
|
291
|
+
* @param opts.event - The event type to wait for.
|
|
292
|
+
* @param opts.filter - Picks the matching event: `(event, input, ctx) => boolean`.
|
|
293
|
+
* @param opts.around - A step or an array of steps to run once listening has started.
|
|
294
|
+
* @param opts.timeoutMs - How long to wait, in ms.
|
|
295
|
+
* @returns A `StepWait`, auto-registered in the step registry.
|
|
296
|
+
* @throws `NoeticConfigError` `EMPTY_STEP_ID`, or `CONNECTION_INVALID` for a missing connection, an empty event or a timeout that is not positive.
|
|
297
|
+
*/
|
|
298
|
+
wait(opts) {
|
|
299
|
+
requireStepId('step.wait', opts.id);
|
|
300
|
+
requireConnection('step.wait', opts.id, opts.connection);
|
|
301
|
+
if (!opts.event) {
|
|
302
|
+
throw new NoeticConfigError({
|
|
303
|
+
code: 'CONNECTION_INVALID',
|
|
304
|
+
message: `step.wait(${JSON.stringify(opts.id)}) names no event.`,
|
|
305
|
+
hint: "Pass the event type to wait for, e.g. event: 'chat.message.created'.",
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
requireTimeout(opts.id, opts.timeoutMs);
|
|
309
|
+
const built = {
|
|
310
|
+
kind: 'wait',
|
|
311
|
+
...frameworkCast(opts),
|
|
312
|
+
};
|
|
313
|
+
getDefaultRegistrar().register(built);
|
|
314
|
+
return built;
|
|
315
|
+
},
|
|
316
|
+
/**
|
|
317
|
+
* Creates a step that checks claims about what a connection shows (spec 37):
|
|
318
|
+
* it declares what should become true, runs `act`, watches the connection's
|
|
319
|
+
* senses, and answers with the evidence. See `verify` in `./verify-builder`.
|
|
320
|
+
*
|
|
321
|
+
* @public
|
|
322
|
+
*/
|
|
323
|
+
verify,
|
|
210
324
|
};
|
|
211
325
|
//#endregion
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `step.verify` (spec 37): checks, from outside the thing making the claim,
|
|
3
|
+
* that an action did what it should — it says what should become true, runs
|
|
4
|
+
* `act` on a real connection, watches what the connection's senses report,
|
|
5
|
+
* and answers yes, no, unknown or no-fault with the evidence and the gaps.
|
|
6
|
+
*
|
|
7
|
+
* Core owns the step; the verifier that judges it is registered on the harness
|
|
8
|
+
* (`new AgentHarness({ verification: verifier() })`), so core never imports
|
|
9
|
+
* `@noetic-tools/verify` or `open-verification`.
|
|
10
|
+
*/
|
|
11
|
+
import type { ContextData } from '@noetic-tools/context';
|
|
12
|
+
import type { ConnectionHandle, CustomItemMap, StepEmitItemsOption, StepReplay, StepVerify, StepVerifyAct, StepVerifySubject } from '@noetic-tools/types';
|
|
13
|
+
import type { Claim, Constraint, RunOutcome, VerifyClose, VerifyMatcher, VerifyOutput } from '@noetic-tools/types/verify';
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
* An `expect` or `never` entry: a plain matcher, or a builder from
|
|
17
|
+
* `@noetic-tools/verify` (`net('POST /api/orders 201').once()`), which carries
|
|
18
|
+
* its matcher as `matcher`.
|
|
19
|
+
*/
|
|
20
|
+
export type VerifyMatcherLike = VerifyMatcher | {
|
|
21
|
+
readonly matcher: VerifyMatcher;
|
|
22
|
+
};
|
|
23
|
+
/** @public A connection named in `subject` or `witnesses`: a handle, or a harness connection name. */
|
|
24
|
+
export type VerifyConnectionRef = ConnectionHandle | string;
|
|
25
|
+
/** @public `step.verify`'s options (spec 37 § Writing a verify). */
|
|
26
|
+
export interface VerifyOpts<TContext = ContextData, I = unknown> extends StepReplay<TContext, I> {
|
|
27
|
+
id: string;
|
|
28
|
+
/** The connection checked — or a list, which runs one verify per connection in parallel. */
|
|
29
|
+
subject: StepVerifySubject<TContext, I>;
|
|
30
|
+
/** What must become true. Exactly one of `expect` or `claims`. */
|
|
31
|
+
expect?: ReadonlyArray<VerifyMatcherLike>;
|
|
32
|
+
/** What must not happen at any point while the action runs. */
|
|
33
|
+
never?: ReadonlyArray<VerifyMatcherLike>;
|
|
34
|
+
/** OVP claims given directly, instead of `expect`. */
|
|
35
|
+
claims?: ReadonlyArray<Claim>;
|
|
36
|
+
/** OVP constraints given directly, instead of `never`. */
|
|
37
|
+
constraints?: ReadonlyArray<Constraint>;
|
|
38
|
+
/**
|
|
39
|
+
* The action: a step, or an array of steps run in sequence — or, for a list
|
|
40
|
+
* subject, `(subject) => steps` giving each subject's action.
|
|
41
|
+
*/
|
|
42
|
+
act: StepVerifyAct<TContext, I>;
|
|
43
|
+
/** Connections that can confirm from outside the subject. */
|
|
44
|
+
witnesses?: ReadonlyArray<VerifyConnectionRef>;
|
|
45
|
+
/** When to stop watching. Default: quiet for 500 ms, at most 15 s. */
|
|
46
|
+
close?: VerifyClose;
|
|
47
|
+
/** A sentence saying why, kept in the run record. */
|
|
48
|
+
intent?: string;
|
|
49
|
+
emitItems?: StepEmitItemsOption<TContext, I, unknown>;
|
|
50
|
+
customItems?: CustomItemMap;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @public
|
|
54
|
+
* The output of a verify whose subject is a list: one verify per connection,
|
|
55
|
+
* with ids `<id>.<name>`, and the worst outcome among them.
|
|
56
|
+
*/
|
|
57
|
+
export interface VerifyEachOutput {
|
|
58
|
+
readonly outcome: RunOutcome;
|
|
59
|
+
/** Connection name → that connection's verify output. */
|
|
60
|
+
readonly subjects: Readonly<Record<string, VerifyOutput>>;
|
|
61
|
+
}
|
|
62
|
+
/** The plain matcher an `expect`/`never` entry stands for. */
|
|
63
|
+
export declare function plainMatcher(entry: VerifyMatcherLike): VerifyMatcher;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a verify step (spec 37). `expect` and `never` lower to OVP claims and
|
|
66
|
+
* constraints; OVP's `adjudicate()` decides each verdict. Its output's
|
|
67
|
+
* `outcome` is `pass`, `fail`, `partial` or `unknown` — a `no` or an `unknown`
|
|
68
|
+
* is an answer, never an error.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
* @returns A `StepVerify`, auto-registered in the step registry. With a list
|
|
72
|
+
* subject its output is a `VerifyEachOutput`, otherwise a `VerifyOutput`.
|
|
73
|
+
* @throws `NoeticConfigError` `EMPTY_STEP_ID`; `VERIFY_INVALID` without exactly one
|
|
74
|
+
* of `expect`/`claims`, with both `never` and `constraints`, or with an empty `act`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function verify<TContext = ContextData, I = unknown>(opts: VerifyOpts<TContext, I> & {
|
|
77
|
+
subject: ReadonlyArray<VerifyConnectionRef>;
|
|
78
|
+
}): StepVerify<TContext, I, VerifyEachOutput>;
|
|
79
|
+
export declare function verify<TContext = ContextData, I = unknown>(opts: VerifyOpts<TContext, I>): StepVerify<TContext, I, VerifyOutput>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `step.verify` (spec 37): checks, from outside the thing making the claim,
|
|
3
|
+
* that an action did what it should — it says what should become true, runs
|
|
4
|
+
* `act` on a real connection, watches what the connection's senses report,
|
|
5
|
+
* and answers yes, no, unknown or no-fault with the evidence and the gaps.
|
|
6
|
+
*
|
|
7
|
+
* Core owns the step; the verifier that judges it is registered on the harness
|
|
8
|
+
* (`new AgentHarness({ verification: verifier() })`), so core never imports
|
|
9
|
+
* `@noetic-tools/verify` or `open-verification`.
|
|
10
|
+
*/
|
|
11
|
+
import { NoeticConfigError } from '@noetic-tools/types';
|
|
12
|
+
import { VerifyConfigErrorCode } from '@noetic-tools/types/verify';
|
|
13
|
+
import { getDefaultRegistrar } from '../types/step-registrar.js';
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region Helpers
|
|
16
|
+
function invalid(id, message, hint) {
|
|
17
|
+
return new NoeticConfigError({
|
|
18
|
+
code: VerifyConfigErrorCode.Invalid,
|
|
19
|
+
message: `step.verify(${JSON.stringify(id)}) ${message}`,
|
|
20
|
+
hint,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** The plain matcher an `expect`/`never` entry stands for. */
|
|
24
|
+
export function plainMatcher(entry) {
|
|
25
|
+
return 'matcher' in entry ? entry.matcher : entry;
|
|
26
|
+
}
|
|
27
|
+
function checkOpts(opts) {
|
|
28
|
+
if (!opts.id || opts.id.trim() === '') {
|
|
29
|
+
throw new NoeticConfigError({
|
|
30
|
+
code: 'EMPTY_STEP_ID',
|
|
31
|
+
message: 'step.verify() requires a non-empty id.',
|
|
32
|
+
hint: 'Pass a unique string as the id field, e.g. step.verify({ id: "checkout", ... }).',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if ((opts.expect === undefined) === (opts.claims === undefined)) {
|
|
36
|
+
throw invalid(opts.id, 'needs exactly one of expect (matchers) or claims (OVP claims).', "Say what must become true with expect: [net('POST /api/orders 201')], or give OVP claims.");
|
|
37
|
+
}
|
|
38
|
+
if (opts.never !== undefined && opts.constraints !== undefined) {
|
|
39
|
+
throw invalid(opts.id, 'takes never (matchers) or constraints (OVP constraints), not both.', 'Keep one of the two.');
|
|
40
|
+
}
|
|
41
|
+
// A function of the subject builds its steps when the verify runs; they are checked then.
|
|
42
|
+
if (typeof opts.act !== 'function' && Array.isArray(opts.act) && opts.act.length === 0) {
|
|
43
|
+
throw invalid(opts.id, 'has nothing in act.', 'Give act the step that performs the action: an operation with effects or a model call.');
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(opts.subject) && opts.subject.length === 0) {
|
|
46
|
+
throw invalid(opts.id, 'has an empty subject list.', 'Name at least one connection to check.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function verify(opts) {
|
|
50
|
+
checkOpts(opts);
|
|
51
|
+
const { expect, never, ...rest } = opts;
|
|
52
|
+
const built = {
|
|
53
|
+
kind: 'verify',
|
|
54
|
+
...rest,
|
|
55
|
+
...(expect === undefined
|
|
56
|
+
? {}
|
|
57
|
+
: {
|
|
58
|
+
expect: expect.map(plainMatcher),
|
|
59
|
+
}),
|
|
60
|
+
...(never === undefined
|
|
61
|
+
? {}
|
|
62
|
+
: {
|
|
63
|
+
never: never.map(plainMatcher),
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66
|
+
getDefaultRegistrar().register(built);
|
|
67
|
+
return built;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hydrators for the JSON workflow nodes that run their children as child
|
|
3
|
+
* executions: `inParallel` (static and fan-out paths), `spawn`, `withContext`,
|
|
4
|
+
* and `subflow` (a named or inline sub-document).
|
|
5
|
+
*/
|
|
6
|
+
import type { ContextData } from '@noetic-tools/context';
|
|
7
|
+
import type { Step } from '@noetic-tools/types';
|
|
8
|
+
import type { WorkflowNode } from '../schemas/workflow.js';
|
|
9
|
+
import type { HydrationContext } from './workflow-hydrator.js';
|
|
10
|
+
export declare function hydrateInParallelNode(node: WorkflowNode, ctx: HydrationContext): Step<ContextData, string, string>;
|
|
11
|
+
export declare function hydrateSpawnNode(node: WorkflowNode, ctx: HydrationContext): Step<ContextData, string, string>;
|
|
12
|
+
export declare function hydrateWithContextNode(node: WorkflowNode, ctx: HydrationContext): Step<ContextData, string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Hydrates a `subflow` node lazily: the target document resolves and hydrates
|
|
15
|
+
* on first execution, memoized. Lazy because `HydrationContext.workflows` may
|
|
16
|
+
* be a live view that gains entries after hydration, and because a recursive
|
|
17
|
+
* ref must hydrate only the levels execution reaches — eager hydration of
|
|
18
|
+
* A→A would never end. Each level gets its own tree whose ids carry the
|
|
19
|
+
* calling node's (already suffixed) id, so levels never share step ids.
|
|
20
|
+
*/
|
|
21
|
+
export declare function hydrateSubflowNode(node: WorkflowNode, ctx: HydrationContext): Step<ContextData, string, string>;
|