@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,198 @@
1
+ /**
2
+ * Hydrators for the JSON workflow nodes that reach outside the workflow:
3
+ * `call` and `wait` (spec 35), resolving the connection a node runs on against
4
+ * the document's manifest, and `acp-agent` with its MCP servers (spec 27).
5
+ */
6
+ import { frameworkCast, NoeticConfigError } from '@noetic-tools/types';
7
+ import { compileExpression, compute, passes, readInput } from '../expression/jsonata.js';
8
+ import { getDefaultRegistrar } from '../types/step-registrar.js';
9
+ import { step } from './step-builders.js';
10
+ import { boundedAcpSettings } from './workflow-acp-grants.js';
11
+ import { compileArgs, documentHandle, documentSecretsOf } from './workflow-connections.js';
12
+ import { bindingsFor, hydrateStepList } from './workflow-hydrator.js';
13
+ import { stepMcpServers } from './workflow-mcp-servers.js';
14
+ //#region Connection Node Hydrators
15
+ /**
16
+ * Checks a connection name against the document's manifest, when there is one.
17
+ *
18
+ * @throws `NoeticConfigError` `CONNECTION_UNKNOWN` for a name the manifest does not declare.
19
+ */
20
+ export function checkManifestName(name, where, ctx) {
21
+ if (!ctx.connections || Object.hasOwn(ctx.connections, name)) {
22
+ return;
23
+ }
24
+ const declared = Object.keys(ctx.connections);
25
+ throw new NoeticConfigError({
26
+ code: 'CONNECTION_UNKNOWN',
27
+ message: `${where} uses connection '${name}', which the document's connections do not declare.`,
28
+ hint: `Use one of ${declared.join(', ') || '(none)'}, or add '${name}' to the document's "connections".`,
29
+ });
30
+ }
31
+ /** The connection a document name binds to: a handle carrying its manifest entry, or the bare name without a manifest. */
32
+ function documentTarget(name, where, ctx) {
33
+ checkManifestName(name, where, ctx);
34
+ const entry = ctx.connections?.[name];
35
+ return entry ? documentHandle(name, entry, ctx.connectionUses?.get(name)) : name;
36
+ }
37
+ /**
38
+ * The connection a `call` or `wait` node runs on: its own, else the enclosing
39
+ * one, else the document's only connection. An expression is evaluated per run.
40
+ *
41
+ * @throws `NoeticConfigError` `CONNECTION_UNKNOWN` for an undeclared name, `CONNECTION_INVALID` when none is named or implied (or an expression gives no name).
42
+ */
43
+ function connectionTargetFor(ref, where, ctx) {
44
+ const effective = ref ?? ctx.enclosingConnection ?? onlyConnection(ctx);
45
+ if (effective === undefined) {
46
+ throw new NoeticConfigError({
47
+ code: 'CONNECTION_INVALID',
48
+ message: `${where} names no connection, and none is implied.`,
49
+ hint: 'Give the node a "connection", or run it inside a verify whose subject is the connection.',
50
+ });
51
+ }
52
+ if (typeof effective === 'string') {
53
+ return documentTarget(effective, where, ctx);
54
+ }
55
+ const compiled = compileExpression(effective.$expr, `connection of ${where}`, ctx.expressionLimits);
56
+ return async (input, execCtx) => {
57
+ const name = await compute(compiled, readInput(input), bindingsFor(execCtx, ctx));
58
+ if (typeof name !== 'string' || name.length === 0) {
59
+ throw new NoeticConfigError({
60
+ code: 'CONNECTION_INVALID',
61
+ message: `The connection expression of ${where} gave ${JSON.stringify(name)}, not a connection name.`,
62
+ hint: 'Write an expression that gives a declared connection name, e.g. { "$expr": "$item" } inside a fan-out.',
63
+ });
64
+ }
65
+ const target = documentTarget(name, where, ctx);
66
+ return typeof target === 'function' ? name : target;
67
+ };
68
+ }
69
+ /** The document's only connection, which a node without one runs on. */
70
+ function onlyConnection(ctx) {
71
+ const names = Object.keys(ctx.connections ?? {});
72
+ return names.length === 1 ? names[0] : undefined;
73
+ }
74
+ /** The operations the document uses on a node's connection (gate 1), when the name is static. */
75
+ function declaredOpsFor(ref, op, ctx) {
76
+ const name = typeof ref === 'string' ? ref : undefined;
77
+ const used = name === undefined ? undefined : ctx.connectionUses?.get(name)?.ops;
78
+ if (used && used.size > 0) {
79
+ return [
80
+ ...used,
81
+ ];
82
+ }
83
+ const all = new Set([
84
+ op,
85
+ ]);
86
+ for (const use of ctx.connectionUses?.values() ?? []) {
87
+ for (const usedOp of use.ops) {
88
+ all.add(usedOp);
89
+ }
90
+ }
91
+ return [
92
+ ...all,
93
+ ];
94
+ }
95
+ /** Registers a step built here as an object literal, like the builders do. */
96
+ function registered(built) {
97
+ getDefaultRegistrar().register(frameworkCast(built));
98
+ return built;
99
+ }
100
+ export function hydrateCallNode(node, ctx) {
101
+ if (node.kind !== 'call') {
102
+ return frameworkCast(undefined);
103
+ }
104
+ const where = `call node '${node.id}'`;
105
+ const connection = connectionTargetFor(node.connection, where, ctx);
106
+ const args = compileArgs(node.args, `args of ${where}`, ctx.expressionLimits);
107
+ const built = {
108
+ kind: 'call',
109
+ id: node.id,
110
+ connection,
111
+ op: node.op,
112
+ args: (input, execCtx) => args(readInput(input), bindingsFor(execCtx, ctx)),
113
+ _caller: 'document',
114
+ _declaredOps: declaredOpsFor(node.connection ?? ctx.enclosingConnection, node.op, ctx),
115
+ _documentSecrets: documentSecretsOf(node.args),
116
+ };
117
+ return registered(built);
118
+ }
119
+ /** A wait filter expression: a test against `{ event, input }`. */
120
+ function waitFilter(compiled, ctx) {
121
+ return (event, input, execCtx) => passes(compiled, {
122
+ event,
123
+ input: readInput(input),
124
+ }, bindingsFor(execCtx, ctx));
125
+ }
126
+ export function hydrateWaitNode(node, ctx) {
127
+ if (node.kind !== 'wait') {
128
+ return frameworkCast(undefined);
129
+ }
130
+ const where = `wait node '${node.id}'`;
131
+ const connectionRef = node.connection ?? ctx.enclosingConnection ?? onlyConnection(ctx);
132
+ const connection = connectionTargetFor(node.connection, where, ctx);
133
+ const filter = node.filter === undefined
134
+ ? undefined
135
+ : waitFilter(compileExpression(node.filter, `filter of ${where}`, ctx.expressionLimits), ctx);
136
+ const around = node.around === undefined
137
+ ? undefined
138
+ : hydrateStepList({
139
+ list: node.around,
140
+ parentId: node.id,
141
+ ctx,
142
+ enclosing: connectionRef,
143
+ });
144
+ const built = {
145
+ kind: 'wait',
146
+ id: node.id,
147
+ connection,
148
+ event: node.event,
149
+ timeoutMs: node.timeoutMs,
150
+ ...(filter
151
+ ? {
152
+ filter,
153
+ }
154
+ : {}),
155
+ ...(around
156
+ ? {
157
+ around,
158
+ }
159
+ : {}),
160
+ };
161
+ return registered(built);
162
+ }
163
+ //#endregion
164
+ //#region ACP Agent Node Hydrator
165
+ /**
166
+ * Hydrates an `acp-agent` node into `step.acpAgent`. Under `ctx.acpBounds` the
167
+ * node's cwd, client capabilities and session key are held to its agent's
168
+ * grant (see `boundedAcpSettings`).
169
+ *
170
+ * @throws `NoeticConfigError` `UNKNOWN_ACP_AGENT_REFERENCE` when `ctx.acpAgents` has no adapter for the node's agent.
171
+ */
172
+ export function hydrateAcpAgentNode(node, ctx) {
173
+ if (node.kind !== 'acp-agent') {
174
+ return frameworkCast(undefined);
175
+ }
176
+ const agent = ctx.acpAgents?.get(node.agent);
177
+ if (!agent) {
178
+ throw new NoeticConfigError({
179
+ code: 'UNKNOWN_ACP_AGENT_REFERENCE',
180
+ message: `ACP agent '${node.agent}' referenced in workflow node '${node.id}' is not registered.`,
181
+ hint: 'Pass agent adapters via HydrationContext.acpAgents, e.g. createAcpAgentRegistry(claudeCode()) from @noetic-tools/acp.',
182
+ });
183
+ }
184
+ const bounded = ctx.acpBounds ? boundedAcpSettings(node, ctx.acpBounds) : node;
185
+ return step.acpAgent({
186
+ id: node.id,
187
+ agent,
188
+ prompt: node.prompt,
189
+ cwd: bounded.cwd,
190
+ mode: node.mode,
191
+ model: node.model,
192
+ mcpServers: stepMcpServers(node.mcpServers),
193
+ permissions: node.permissions,
194
+ clientCapabilities: bounded.clientCapabilities,
195
+ session: bounded.session,
196
+ });
197
+ }
198
+ //#endregion
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The connection side of JSON workflows (spec 35 § JSON workflows, § What a
3
+ * document may use): which connection each `call`, `wait` and `verify` node
4
+ * runs on, the operations and events a document uses per manifest entry, the
5
+ * requirement each entry negotiates, value wrappers, and the host allowlist.
6
+ */
7
+ import type { ConnectionAllowlist, ConnectionHandle, ConnectionRequirement } from '@noetic-tools/types';
8
+ import type { ExpressionBindings, ExpressionLimits } from '../expression/jsonata.js';
9
+ import type { WorkflowArgs, WorkflowConnectionRequirement, WorkflowDocument, WorkflowValue } from '../schemas/workflow.js';
10
+ /** The manifest a document declares, by the names its nodes use. */
11
+ export type ConnectionManifestEntries = Readonly<Record<string, WorkflowConnectionRequirement>>;
12
+ /** A secret a document uses: its name and the `op.field` it fills. */
13
+ export interface SecretUse {
14
+ name: string;
15
+ op: string;
16
+ field: string;
17
+ }
18
+ /** What a document uses of one manifest entry, worked out from its nodes. */
19
+ export interface ConnectionUse {
20
+ ops: Set<string>;
21
+ events: Set<string>;
22
+ secrets: SecretUse[];
23
+ }
24
+ /** Manifest name → what the document uses of it. */
25
+ export type ConnectionUses = Map<string, ConnectionUse>;
26
+ /** A compiled argument value: resolves against a node's input and bindings. */
27
+ export type ValueTemplate = (input: unknown, bindings: ExpressionBindings) => Promise<unknown>;
28
+ /**
29
+ * Compiles a connection argument value (spec 35 § JSON workflows, Values):
30
+ * `{ "$expr" }` evaluates against the node's input, `{ "$literal" }` passes its
31
+ * value through untouched, `{ "$secret" }`, `{ "$ref" }` and `{ "$blob" }` pass
32
+ * through for the registry to resolve, and arrays and objects compile field by field.
33
+ *
34
+ * @throws `NoeticConfigError` `WORKFLOW_VALIDATION_FAILED` when an expression does not parse.
35
+ */
36
+ export declare function compileValue(value: WorkflowValue, where: string, limits: ExpressionLimits | undefined): ValueTemplate;
37
+ /**
38
+ * Compiles a node's `args`: an object of values, or one `{ "$expr" }` computing
39
+ * them all (which must give a value).
40
+ */
41
+ export declare function compileArgs(args: WorkflowArgs | undefined, where: string, limits: ExpressionLimits | undefined): ValueTemplate;
42
+ /**
43
+ * The secrets a node's `args` write out, each with the dotted field it fills.
44
+ * The gates refuse any other secret a document call sends — one an expression
45
+ * produced at run time is never something the allowlist was checked against.
46
+ */
47
+ export declare function documentSecretsOf(args: WorkflowArgs | undefined): Array<{
48
+ name: string;
49
+ field: string;
50
+ }>;
51
+ /**
52
+ * Works out what a document uses of each manifest entry — the operations and
53
+ * events its nodes use and the secrets it passes — checking every connection a
54
+ * node names against the manifest. An inline subflow's nodes count against the
55
+ * enclosing document's manifest.
56
+ *
57
+ * @throws `NoeticConfigError` `CONNECTION_UNKNOWN` for a connection the manifest does not declare, `CONNECTION_INVALID` for a node whose connection is neither named nor implied.
58
+ */
59
+ export declare function documentConnectionUses(doc: WorkflowDocument): ConnectionUses;
60
+ /**
61
+ * Checks a document's connection nodes against its manifest: every name is
62
+ * declared, and a source entry (one declaring only `events`) is waited on only
63
+ * for the events it lists and never called.
64
+ *
65
+ * @throws `NoeticConfigError` `CONNECTION_UNKNOWN`, `CONNECTION_INVALID`, or `CONNECTION_UNSATISFIED`-shaped `CONNECTION_INVALID` for a source used beyond its events.
66
+ */
67
+ export declare function checkDocumentConnections(doc: WorkflowDocument): ConnectionUses;
68
+ /**
69
+ * The requirement a manifest entry negotiates: its profile and extension ranges,
70
+ * plus the operations and events the document uses of it.
71
+ */
72
+ export declare function manifestRequirement(entry: WorkflowConnectionRequirement, use: ConnectionUse | undefined): ConnectionRequirement;
73
+ /**
74
+ * A handle for a manifest entry, carrying the entry's requirement in place of a
75
+ * profile object (core never imports profile packages).
76
+ */
77
+ export declare function documentHandle(name: string, entry: WorkflowConnectionRequirement, use: ConnectionUse | undefined): ConnectionHandle;
78
+ /** The requirement a document handle carries, when it is one. */
79
+ export declare function documentRequirementOf(handle: ConnectionHandle): ConnectionRequirement | undefined;
80
+ /** `*` matches any run of characters; everything else literally. */
81
+ export declare function globMatches(pattern: string, value: string): boolean;
82
+ /**
83
+ * Checks a document against the host's allowlist (spec 35 § What a document may
84
+ * use). Each manifest entry binds to the harness connection `from ?? name`, which
85
+ * the allowlist must name; the operations, events, setup values and secrets the
86
+ * document uses of it must all be granted.
87
+ *
88
+ * @throws `NoeticConfigError` `CONNECTION_NOT_ALLOWED` when the document asks for more than the allowlist grants (or has connections and there is no allowlist); `CONNECTION_UNKNOWN` / `CONNECTION_INVALID` from `checkDocumentConnections`.
89
+ */
90
+ export declare function checkConnectionAllowlist(doc: WorkflowDocument, allowlist: ConnectionAllowlist | undefined): void;