@noetic-tools/core 5.19.1 → 5.19.3

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.
Files changed (152) hide show
  1. package/dist/adapters/openrouter.js +5 -0
  2. package/dist/builders/control-flow-builders.d.ts +15 -6
  3. package/dist/builders/control-flow-builders.js +8 -0
  4. package/dist/builders/decide-builders.d.ts +2 -5
  5. package/dist/builders/dynamic-workflow.d.ts +54 -2
  6. package/dist/builders/dynamic-workflow.js +247 -12
  7. package/dist/builders/every.d.ts +3 -3
  8. package/dist/builders/every.js +2 -1
  9. package/dist/builders/mcp-url-pattern.d.ts +13 -0
  10. package/dist/builders/mcp-url-pattern.js +85 -0
  11. package/dist/builders/provide-builder.d.ts +3 -2
  12. package/dist/builders/provide-builder.js +2 -1
  13. package/dist/builders/sequence.d.ts +14 -0
  14. package/dist/builders/sequence.js +103 -0
  15. package/dist/builders/spawn-builder.d.ts +3 -2
  16. package/dist/builders/spawn-builder.js +3 -2
  17. package/dist/builders/step-builders.d.ts +80 -1
  18. package/dist/builders/step-builders.js +115 -1
  19. package/dist/builders/verify-builder.d.ts +79 -0
  20. package/dist/builders/verify-builder.js +69 -0
  21. package/dist/builders/workflow-acp-grants.d.ts +42 -0
  22. package/dist/builders/workflow-acp-grants.js +224 -0
  23. package/dist/builders/workflow-child-nodes.d.ts +21 -0
  24. package/dist/builders/workflow-child-nodes.js +336 -0
  25. package/dist/builders/workflow-connection-nodes.d.ts +25 -0
  26. package/dist/builders/workflow-connection-nodes.js +198 -0
  27. package/dist/builders/workflow-connections.d.ts +90 -0
  28. package/dist/builders/workflow-connections.js +560 -0
  29. package/dist/builders/workflow-control-nodes.d.ts +13 -0
  30. package/dist/builders/workflow-control-nodes.js +213 -0
  31. package/dist/builders/workflow-hydrator.d.ts +56 -3
  32. package/dist/builders/workflow-hydrator.js +53 -520
  33. package/dist/builders/workflow-mcp-servers.d.ts +24 -0
  34. package/dist/builders/workflow-mcp-servers.js +220 -0
  35. package/dist/builders/workflow-verify.d.ts +19 -0
  36. package/dist/builders/workflow-verify.js +194 -0
  37. package/dist/conditions/conditions.d.ts +7 -5
  38. package/dist/conditions/conditions.js +7 -4
  39. package/dist/connections/blobs.d.ts +33 -0
  40. package/dist/connections/blobs.js +77 -0
  41. package/dist/connections/cron-schedule.d.ts +32 -0
  42. package/dist/connections/cron-schedule.js +213 -0
  43. package/dist/connections/durability.d.ts +65 -0
  44. package/dist/connections/durability.js +54 -0
  45. package/dist/connections/errors.d.ts +30 -0
  46. package/dist/connections/errors.js +100 -0
  47. package/dist/connections/event-stream.d.ts +24 -0
  48. package/dist/connections/event-stream.js +176 -0
  49. package/dist/connections/gates.d.ts +94 -0
  50. package/dist/connections/gates.js +271 -0
  51. package/dist/connections/glob.d.ts +10 -0
  52. package/dist/connections/glob.js +46 -0
  53. package/dist/connections/handle.d.ts +22 -0
  54. package/dist/connections/handle.js +84 -0
  55. package/dist/connections/harness-wiring.d.ts +52 -0
  56. package/dist/connections/harness-wiring.js +143 -0
  57. package/dist/connections/in-memory-connection.d.ts +147 -0
  58. package/dist/connections/in-memory-connection.js +593 -0
  59. package/dist/connections/index.d.ts +34 -0
  60. package/dist/connections/index.js +23 -0
  61. package/dist/connections/json-schema.d.ts +28 -0
  62. package/dist/connections/json-schema.js +338 -0
  63. package/dist/connections/model-tools.d.ts +46 -0
  64. package/dist/connections/model-tools.js +466 -0
  65. package/dist/connections/negotiation.d.ts +30 -0
  66. package/dist/connections/negotiation.js +159 -0
  67. package/dist/connections/policy.d.ts +21 -0
  68. package/dist/connections/policy.js +34 -0
  69. package/dist/connections/pool.d.ts +111 -0
  70. package/dist/connections/pool.js +339 -0
  71. package/dist/connections/refs.d.ts +74 -0
  72. package/dist/connections/refs.js +316 -0
  73. package/dist/connections/registry-types.d.ts +141 -0
  74. package/dist/connections/registry-types.js +14 -0
  75. package/dist/connections/registry.d.ts +125 -0
  76. package/dist/connections/registry.js +775 -0
  77. package/dist/connections/secrets.d.ts +59 -0
  78. package/dist/connections/secrets.js +153 -0
  79. package/dist/connections/settle.d.ts +9 -0
  80. package/dist/connections/settle.js +26 -0
  81. package/dist/connections/sources.d.ts +27 -0
  82. package/dist/connections/sources.js +300 -0
  83. package/dist/connections/triggers.d.ts +78 -0
  84. package/dist/connections/triggers.js +310 -0
  85. package/dist/connections/values.d.ts +26 -0
  86. package/dist/connections/values.js +93 -0
  87. package/dist/connections/views.d.ts +31 -0
  88. package/dist/connections/views.js +176 -0
  89. package/dist/expression/check.js +80 -1
  90. package/dist/expression/jsonata.d.ts +14 -4
  91. package/dist/expression/jsonata.js +27 -9
  92. package/dist/expression/step-outputs.d.ts +25 -0
  93. package/dist/expression/step-outputs.js +78 -0
  94. package/dist/harness/agent-harness.d.ts +69 -166
  95. package/dist/harness/agent-harness.js +170 -262
  96. package/dist/harness/call-span-collector.d.ts +33 -0
  97. package/dist/harness/call-span-collector.js +83 -0
  98. package/dist/harness/connection-gate.d.ts +78 -0
  99. package/dist/harness/connection-gate.js +170 -0
  100. package/dist/harness/deps/interpreter.d.ts +1 -0
  101. package/dist/harness/deps/interpreter.js +1 -0
  102. package/dist/harness/deps/runtime.d.ts +1 -1
  103. package/dist/harness/deps/types.d.ts +1 -1
  104. package/dist/harness/harness-options.d.ts +153 -0
  105. package/dist/harness/harness-options.js +36 -0
  106. package/dist/harness/harness-tracing.d.ts +16 -0
  107. package/dist/harness/harness-tracing.js +35 -0
  108. package/dist/harness/llm-client.d.ts +71 -0
  109. package/dist/harness/llm-client.js +218 -0
  110. package/dist/harness/model-call.d.ts +2 -7
  111. package/dist/harness/model-call.js +21 -549
  112. package/dist/harness/model-request.d.ts +42 -0
  113. package/dist/harness/model-request.js +159 -0
  114. package/dist/harness/model-stream.d.ts +39 -0
  115. package/dist/harness/model-stream.js +131 -0
  116. package/dist/harness/model-tool-round.d.ts +37 -0
  117. package/dist/harness/model-tool-round.js +197 -0
  118. package/dist/harness/spend.d.ts +2 -0
  119. package/dist/harness/spend.js +5 -1
  120. package/dist/index.d.ts +33 -8
  121. package/dist/index.js +18 -1
  122. package/dist/interpreter/connection-steps.d.ts +194 -0
  123. package/dist/interpreter/connection-steps.js +537 -0
  124. package/dist/interpreter/execute-action.d.ts +2 -8
  125. package/dist/interpreter/execute-action.js +3 -178
  126. package/dist/interpreter/execute-call.d.ts +19 -0
  127. package/dist/interpreter/execute-call.js +99 -0
  128. package/dist/interpreter/execute-control.d.ts +6 -1
  129. package/dist/interpreter/execute-control.js +14 -0
  130. package/dist/interpreter/execute-invoke-tool.d.ts +11 -0
  131. package/dist/interpreter/execute-invoke-tool.js +183 -0
  132. package/dist/interpreter/execute-verify.d.ts +21 -0
  133. package/dist/interpreter/execute-verify.js +391 -0
  134. package/dist/interpreter/execute-wait.d.ts +21 -0
  135. package/dist/interpreter/execute-wait.js +233 -0
  136. package/dist/interpreter/execute.js +24 -133
  137. package/dist/interpreter/step-kind-dispatch.d.ts +24 -0
  138. package/dist/interpreter/step-kind-dispatch.js +157 -0
  139. package/dist/interpreter/step-walk.d.ts +2 -0
  140. package/dist/interpreter/step-walk.js +24 -0
  141. package/dist/interpreter/verify-host.d.ts +40 -0
  142. package/dist/interpreter/verify-host.js +245 -0
  143. package/dist/runtime/durable/step-ledger.d.ts +31 -1
  144. package/dist/runtime/durable/step-ledger.js +87 -1
  145. package/dist/runtime/in-memory-artifact-store.d.ts +24 -0
  146. package/dist/runtime/in-memory-artifact-store.js +240 -0
  147. package/dist/schemas/workflow.d.ts +2 -2
  148. package/dist/schemas/workflow.js +1 -1
  149. package/dist/util/harness-internals.d.ts +25 -0
  150. package/dist/util/harness-internals.js +35 -0
  151. package/package.json +3 -3
  152. package/schema/noetic-workflow.schema.json +1309 -180
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The URL patterns of a host's `mcp` allowlist (spec 26 § MCP servers). A
3
+ * pattern is matched part by part — scheme, host, port, then path — so a `*`
4
+ * can never stand for a `/`, `?`, `#` or `@` that moves the URL to another
5
+ * host: `https://*.example.com/*` does not match
6
+ * `https://evil.com/.example.com/`.
7
+ */
8
+ import { NoeticConfigError } from '@noetic-tools/types';
9
+ import { globMatches } from './workflow-connections.js';
10
+ //#endregion
11
+ //#region Public API
12
+ /**
13
+ * Whether `url` matches the host's pattern.
14
+ *
15
+ * @throws `NoeticConfigError` `CONNECTION_INVALID` when the pattern is not `<scheme>://<host>[:<port>]<path>` with `*` only as a leading host label, the port, or in the path, or when a leading `*.` is followed by fewer than two labels (`*.com`).
16
+ */
17
+ export function urlPatternMatches(pattern, url) {
18
+ const parts = parsePattern(pattern);
19
+ if (url.protocol !== parts.scheme) {
20
+ return false;
21
+ }
22
+ if (!hostMatches(parts, url.hostname)) {
23
+ return false;
24
+ }
25
+ if (parts.port !== '*' && url.port !== parts.port) {
26
+ return false;
27
+ }
28
+ return globMatches(parts.path, url.pathname);
29
+ }
30
+ //#endregion
31
+ //#region Parsing
32
+ const PATTERN = /^(https?):\/\/(\*\.)?(\[[0-9A-Fa-f:.]+\]|[^/:?#*@\\[\]]+)(?::(\d+|\*))?(\/[^?#]*)?$/;
33
+ function parsePattern(pattern) {
34
+ const match = PATTERN.exec(pattern);
35
+ const [, scheme, wildcard, host, port, path] = match ?? [];
36
+ if (!scheme || !host) {
37
+ throw invalid(pattern);
38
+ }
39
+ // Read the host and port back through `URL`, so the pattern is normalized
40
+ // exactly as the URLs it is matched against: lowercase, punycode, and the
41
+ // scheme's default port dropped.
42
+ const origin = `${scheme}://${host}${port && port !== '*' ? `:${port}` : ''}/`;
43
+ if (!URL.canParse(origin)) {
44
+ throw invalid(pattern);
45
+ }
46
+ const parsed = new URL(origin);
47
+ // `*.com` would grant every host under a top-level domain.
48
+ if (wildcard !== undefined && !hasTwoLabels(parsed.hostname)) {
49
+ throw invalid(pattern);
50
+ }
51
+ return {
52
+ scheme: parsed.protocol,
53
+ host: parsed.hostname,
54
+ subdomains: wildcard !== undefined,
55
+ port: port === '*' ? '*' : parsed.port,
56
+ path: new URL(path ?? '/', parsed).pathname,
57
+ };
58
+ }
59
+ function hostMatches(pattern, hostname) {
60
+ if (!pattern.subdomains) {
61
+ return hostname === pattern.host;
62
+ }
63
+ const suffix = `.${pattern.host}`;
64
+ if (!hostname.endsWith(suffix)) {
65
+ return false;
66
+ }
67
+ // `URL` reads `https://.example.com/` as host `.example.com`: an empty label.
68
+ const labels = hostname.slice(0, -suffix.length).split('.');
69
+ return labels.every((label) => label !== '');
70
+ }
71
+ function hasTwoLabels(host) {
72
+ if (host.startsWith('[')) {
73
+ return false;
74
+ }
75
+ const labels = host.split('.');
76
+ return labels.length >= 2 && labels.every((label) => label !== '');
77
+ }
78
+ function invalid(pattern) {
79
+ return new NoeticConfigError({
80
+ code: 'CONNECTION_INVALID',
81
+ message: `The host's mcp allowlist has URL pattern ${JSON.stringify(pattern)}, which is not <scheme>://<host>[:<port>]<path>.`,
82
+ hint: 'Use http or https, a host that may start with `*.` followed by at least two labels, a port number or `*`, and a path where `*` matches any run of characters, e.g. https://*.example.com/mcp/*.',
83
+ });
84
+ }
85
+ //#endregion
@@ -1,8 +1,9 @@
1
1
  import type { ContextConfig, ContextData, ContextLayer } from '@noetic-tools/context';
2
- import type { Step, StepEmitItems, StepReplay, StepWithContext } from '@noetic-tools/types';
2
+ import type { StepEmitItems, StepReplay, Steps, StepWithContext } from '@noetic-tools/types';
3
3
  export interface WithContextOpts<TContext, I, O> extends StepReplay<TContext, I>, StepEmitItems<TContext, I, O> {
4
4
  id: string;
5
- child: Step<TContext, I, O>;
5
+ /** The child step, or an array of steps run in sequence. */
6
+ child: Steps<TContext, I, O>;
6
7
  context: ContextConfig | ContextLayer[];
7
8
  }
8
9
  /**
@@ -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
  /**
4
5
  * Creates a provide step that attaches context layers to its child without creating an isolated context.
5
6
  * Like React's Context.Provider — layers are available to all descendant steps.
@@ -40,7 +41,7 @@ export function withContext(opts) {
40
41
  const built = {
41
42
  kind: 'withContext',
42
43
  id: opts.id,
43
- child: opts.child,
44
+ child: toStep(opts.child),
44
45
  context: layers,
45
46
  durable: opts.durable,
46
47
  replayKey: opts.replayKey,
@@ -0,0 +1,14 @@
1
+ import type { ContextData, Step, Steps } from '@noetic-tools/types';
2
+ /**
3
+ * A step from a step or an array of steps. An array of two or more becomes a
4
+ * `sequence` step whose id joins its children's ids; a one-element array is its
5
+ * element. The sequence holds a frozen copy of the array, so changing the
6
+ * array afterwards changes nothing. Builders that take `Steps` call this, so an
7
+ * array runs in sequence wherever they take a step.
8
+ *
9
+ * @throws `NoeticConfigError` with code `EMPTY_STEP_ARRAY` for an empty array.
10
+ * @throws `NoeticConfigError` with code `INVALID_STEP_IN_ARRAY` when an element
11
+ * is not a step (a nested array, `null`, or an object without a step kind
12
+ * and string id). Nested arrays are rejected, not flattened.
13
+ */
14
+ export declare function toStep<TContext = ContextData, I = unknown, O = unknown>(steps: Steps<TContext, I, O>): Step<TContext, I, O>;
@@ -0,0 +1,103 @@
1
+ import { frameworkCast, NoeticConfigError } from '@noetic-tools/types';
2
+ //#region Helpers
3
+ /** Every step kind, so an array element can be checked before it runs. */
4
+ const STEP_KINDS = {
5
+ runCode: true,
6
+ callModel: true,
7
+ 'acp-agent': true,
8
+ invokeTool: true,
9
+ decide: true,
10
+ conditional: true,
11
+ inParallel: true,
12
+ spawn: true,
13
+ withContext: true,
14
+ loop: true,
15
+ schedule: true,
16
+ call: true,
17
+ wait: true,
18
+ verify: true,
19
+ sequence: true,
20
+ };
21
+ function isStepList(steps) {
22
+ return Array.isArray(steps);
23
+ }
24
+ function isStepKind(kind) {
25
+ return typeof kind === 'string' && Object.hasOwn(STEP_KINDS, kind);
26
+ }
27
+ /** What is wrong with an array element, or `undefined` when it is a step. */
28
+ function elementProblem(element) {
29
+ if (Array.isArray(element)) {
30
+ return 'is a nested array';
31
+ }
32
+ if (typeof element !== 'object' || element === null) {
33
+ return `is ${element === null ? 'null' : typeof element}, not a step`;
34
+ }
35
+ const { kind, id } = frameworkCast(element);
36
+ if (!isStepKind(kind)) {
37
+ return `has no known step kind (got ${JSON.stringify(kind)})`;
38
+ }
39
+ if (typeof id !== 'string') {
40
+ return 'has no string id';
41
+ }
42
+ return undefined;
43
+ }
44
+ /**
45
+ * Checks every element is a step, so a bad array fails where it is built
46
+ * rather than as a raw TypeError when it runs.
47
+ *
48
+ * @throws `NoeticConfigError` `INVALID_STEP_IN_ARRAY` naming the first bad element.
49
+ */
50
+ function requireSteps(list) {
51
+ for (const [index, element] of list.entries()) {
52
+ const problem = elementProblem(element);
53
+ if (problem === undefined) {
54
+ continue;
55
+ }
56
+ throw new NoeticConfigError({
57
+ code: 'INVALID_STEP_IN_ARRAY',
58
+ message: `Element ${index} of an array of steps ${problem}.`,
59
+ hint: 'An array of steps holds steps only. Spread a nested array into its parent (`[a, ...rest]`); arrays are not flattened.',
60
+ });
61
+ }
62
+ return frameworkCast(list);
63
+ }
64
+ //#endregion
65
+ //#region Public API
66
+ /**
67
+ * A step from a step or an array of steps. An array of two or more becomes a
68
+ * `sequence` step whose id joins its children's ids; a one-element array is its
69
+ * element. The sequence holds a frozen copy of the array, so changing the
70
+ * array afterwards changes nothing. Builders that take `Steps` call this, so an
71
+ * array runs in sequence wherever they take a step.
72
+ *
73
+ * @throws `NoeticConfigError` with code `EMPTY_STEP_ARRAY` for an empty array.
74
+ * @throws `NoeticConfigError` with code `INVALID_STEP_IN_ARRAY` when an element
75
+ * is not a step (a nested array, `null`, or an object without a step kind
76
+ * and string id). Nested arrays are rejected, not flattened.
77
+ */
78
+ export function toStep(steps) {
79
+ if (!isStepList(steps)) {
80
+ return frameworkCast(steps);
81
+ }
82
+ const list = requireSteps(steps);
83
+ const [first] = list;
84
+ if (!first) {
85
+ throw new NoeticConfigError({
86
+ code: 'EMPTY_STEP_ARRAY',
87
+ message: 'An array of steps must contain at least one step.',
88
+ hint: 'Pass the steps to run in sequence, or a single step.',
89
+ });
90
+ }
91
+ if (list.length === 1) {
92
+ return frameworkCast(first);
93
+ }
94
+ const children = Object.freeze(frameworkCast([
95
+ ...list,
96
+ ]));
97
+ return {
98
+ kind: 'sequence',
99
+ id: children.map((child) => child.id).join(' > '),
100
+ steps: children,
101
+ };
102
+ }
103
+ //#endregion
@@ -1,5 +1,5 @@
1
1
  import type { ContextConfig, ContextData, ContextLayer } from '@noetic-tools/context';
2
- import type { Step, StepEmitItems, StepReplay, StepSpawn, SubprocessAdapter } from '@noetic-tools/types';
2
+ import type { StepEmitItems, StepReplay, StepSpawn, Steps, SubprocessAdapter } from '@noetic-tools/types';
3
3
  /**
4
4
  * Options for {@link spawn}.
5
5
  *
@@ -7,7 +7,8 @@ import type { Step, StepEmitItems, StepReplay, StepSpawn, SubprocessAdapter } fr
7
7
  */
8
8
  export interface SpawnOpts<TContext = ContextData, I = unknown, O = unknown> extends StepReplay<TContext, I>, StepEmitItems<TContext, I, O> {
9
9
  id: string;
10
- child: Step<TContext, I, O>;
10
+ /** The child step, or an array of steps run in sequence. */
11
+ child: Steps<TContext, I, O>;
11
12
  context?: ContextConfig | ContextLayer[];
12
13
  timeout?: number;
13
14
  /**
@@ -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(opts.child);
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