@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.
Files changed (150) 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 +16 -1
  6. package/dist/builders/dynamic-workflow.js +222 -11
  7. package/dist/builders/every.d.ts +3 -3
  8. package/dist/builders/every.js +2 -1
  9. package/dist/builders/provide-builder.d.ts +3 -2
  10. package/dist/builders/provide-builder.js +2 -1
  11. package/dist/builders/sequence.d.ts +14 -0
  12. package/dist/builders/sequence.js +103 -0
  13. package/dist/builders/spawn-builder.d.ts +3 -2
  14. package/dist/builders/spawn-builder.js +3 -2
  15. package/dist/builders/step-builders.d.ts +80 -1
  16. package/dist/builders/step-builders.js +115 -1
  17. package/dist/builders/verify-builder.d.ts +79 -0
  18. package/dist/builders/verify-builder.js +69 -0
  19. package/dist/builders/workflow-child-nodes.d.ts +21 -0
  20. package/dist/builders/workflow-child-nodes.js +335 -0
  21. package/dist/builders/workflow-connection-nodes.d.ts +17 -0
  22. package/dist/builders/workflow-connection-nodes.js +160 -0
  23. package/dist/builders/workflow-connections.d.ts +90 -0
  24. package/dist/builders/workflow-connections.js +560 -0
  25. package/dist/builders/workflow-control-nodes.d.ts +13 -0
  26. package/dist/builders/workflow-control-nodes.js +213 -0
  27. package/dist/builders/workflow-hydrator.d.ts +44 -3
  28. package/dist/builders/workflow-hydrator.js +53 -495
  29. package/dist/builders/workflow-verify.d.ts +19 -0
  30. package/dist/builders/workflow-verify.js +194 -0
  31. package/dist/conditions/conditions.d.ts +7 -5
  32. package/dist/conditions/conditions.js +7 -4
  33. package/dist/connections/blobs.d.ts +33 -0
  34. package/dist/connections/blobs.js +77 -0
  35. package/dist/connections/cron-schedule.d.ts +32 -0
  36. package/dist/connections/cron-schedule.js +213 -0
  37. package/dist/connections/durability.d.ts +65 -0
  38. package/dist/connections/durability.js +54 -0
  39. package/dist/connections/errors.d.ts +30 -0
  40. package/dist/connections/errors.js +100 -0
  41. package/dist/connections/event-stream.d.ts +24 -0
  42. package/dist/connections/event-stream.js +176 -0
  43. package/dist/connections/gates.d.ts +94 -0
  44. package/dist/connections/gates.js +271 -0
  45. package/dist/connections/glob.d.ts +10 -0
  46. package/dist/connections/glob.js +46 -0
  47. package/dist/connections/handle.d.ts +22 -0
  48. package/dist/connections/handle.js +84 -0
  49. package/dist/connections/harness-wiring.d.ts +52 -0
  50. package/dist/connections/harness-wiring.js +143 -0
  51. package/dist/connections/in-memory-connection.d.ts +147 -0
  52. package/dist/connections/in-memory-connection.js +593 -0
  53. package/dist/connections/index.d.ts +34 -0
  54. package/dist/connections/index.js +23 -0
  55. package/dist/connections/json-schema.d.ts +28 -0
  56. package/dist/connections/json-schema.js +338 -0
  57. package/dist/connections/model-tools.d.ts +46 -0
  58. package/dist/connections/model-tools.js +466 -0
  59. package/dist/connections/negotiation.d.ts +30 -0
  60. package/dist/connections/negotiation.js +159 -0
  61. package/dist/connections/policy.d.ts +21 -0
  62. package/dist/connections/policy.js +34 -0
  63. package/dist/connections/pool.d.ts +111 -0
  64. package/dist/connections/pool.js +339 -0
  65. package/dist/connections/refs.d.ts +74 -0
  66. package/dist/connections/refs.js +316 -0
  67. package/dist/connections/registry-types.d.ts +141 -0
  68. package/dist/connections/registry-types.js +14 -0
  69. package/dist/connections/registry.d.ts +125 -0
  70. package/dist/connections/registry.js +775 -0
  71. package/dist/connections/secrets.d.ts +59 -0
  72. package/dist/connections/secrets.js +153 -0
  73. package/dist/connections/settle.d.ts +9 -0
  74. package/dist/connections/settle.js +26 -0
  75. package/dist/connections/sources.d.ts +27 -0
  76. package/dist/connections/sources.js +300 -0
  77. package/dist/connections/triggers.d.ts +78 -0
  78. package/dist/connections/triggers.js +310 -0
  79. package/dist/connections/values.d.ts +26 -0
  80. package/dist/connections/values.js +93 -0
  81. package/dist/connections/views.d.ts +31 -0
  82. package/dist/connections/views.js +176 -0
  83. package/dist/expression/check.js +80 -1
  84. package/dist/expression/jsonata.d.ts +14 -4
  85. package/dist/expression/jsonata.js +27 -9
  86. package/dist/expression/step-outputs.d.ts +25 -0
  87. package/dist/expression/step-outputs.js +78 -0
  88. package/dist/harness/agent-harness.d.ts +69 -166
  89. package/dist/harness/agent-harness.js +170 -262
  90. package/dist/harness/call-span-collector.d.ts +33 -0
  91. package/dist/harness/call-span-collector.js +83 -0
  92. package/dist/harness/call-spend.d.ts +2 -0
  93. package/dist/harness/call-spend.js +10 -14
  94. package/dist/harness/connection-gate.d.ts +78 -0
  95. package/dist/harness/connection-gate.js +169 -0
  96. package/dist/harness/deps/interpreter.d.ts +1 -0
  97. package/dist/harness/deps/interpreter.js +1 -0
  98. package/dist/harness/deps/runtime.d.ts +1 -1
  99. package/dist/harness/deps/types.d.ts +1 -1
  100. package/dist/harness/harness-options.d.ts +153 -0
  101. package/dist/harness/harness-options.js +36 -0
  102. package/dist/harness/harness-tracing.d.ts +16 -0
  103. package/dist/harness/harness-tracing.js +35 -0
  104. package/dist/harness/llm-client.d.ts +71 -0
  105. package/dist/harness/llm-client.js +218 -0
  106. package/dist/harness/model-call.d.ts +2 -7
  107. package/dist/harness/model-call.js +141 -558
  108. package/dist/harness/model-request.d.ts +42 -0
  109. package/dist/harness/model-request.js +159 -0
  110. package/dist/harness/model-rounds.d.ts +18 -2
  111. package/dist/harness/model-rounds.js +39 -8
  112. package/dist/harness/model-stream.d.ts +39 -0
  113. package/dist/harness/model-stream.js +131 -0
  114. package/dist/harness/model-tool-round.d.ts +37 -0
  115. package/dist/harness/model-tool-round.js +197 -0
  116. package/dist/harness/spend.d.ts +2 -0
  117. package/dist/harness/spend.js +5 -1
  118. package/dist/index.d.ts +31 -6
  119. package/dist/index.js +18 -1
  120. package/dist/interpreter/connection-steps.d.ts +194 -0
  121. package/dist/interpreter/connection-steps.js +537 -0
  122. package/dist/interpreter/execute-action.d.ts +2 -8
  123. package/dist/interpreter/execute-action.js +3 -178
  124. package/dist/interpreter/execute-call.d.ts +19 -0
  125. package/dist/interpreter/execute-call.js +99 -0
  126. package/dist/interpreter/execute-control.d.ts +6 -1
  127. package/dist/interpreter/execute-control.js +14 -0
  128. package/dist/interpreter/execute-invoke-tool.d.ts +11 -0
  129. package/dist/interpreter/execute-invoke-tool.js +183 -0
  130. package/dist/interpreter/execute-verify.d.ts +21 -0
  131. package/dist/interpreter/execute-verify.js +391 -0
  132. package/dist/interpreter/execute-wait.d.ts +21 -0
  133. package/dist/interpreter/execute-wait.js +233 -0
  134. package/dist/interpreter/execute.js +24 -133
  135. package/dist/interpreter/step-kind-dispatch.d.ts +24 -0
  136. package/dist/interpreter/step-kind-dispatch.js +157 -0
  137. package/dist/interpreter/step-walk.d.ts +2 -0
  138. package/dist/interpreter/step-walk.js +24 -0
  139. package/dist/interpreter/verify-host.d.ts +40 -0
  140. package/dist/interpreter/verify-host.js +245 -0
  141. package/dist/runtime/durable/step-ledger.d.ts +34 -2
  142. package/dist/runtime/durable/step-ledger.js +97 -3
  143. package/dist/runtime/in-memory-artifact-store.d.ts +24 -0
  144. package/dist/runtime/in-memory-artifact-store.js +240 -0
  145. package/dist/schemas/workflow.d.ts +2 -2
  146. package/dist/schemas/workflow.js +1 -1
  147. package/dist/util/harness-internals.d.ts +23 -0
  148. package/dist/util/harness-internals.js +35 -0
  149. package/package.json +2 -2
  150. package/schema/noetic-workflow.schema.json +1170 -92
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Hydrators for the control-flow nodes of a JSON workflow: `conditional`,
3
+ * `decide`, `routeSwitch`, `loop` (with its until predicates), and `schedule`.
4
+ */
5
+ import { frameworkCast, NoeticConfigError } from '@noetic-tools/types';
6
+ import { compileExpression, passes, readInput } from '../expression/jsonata.js';
7
+ import { stepOutputsOf } from '../expression/step-outputs.js';
8
+ import { all, any } from '../until/combinators.js';
9
+ import { until } from '../until/predicates.js';
10
+ import { conditional } from './control-flow-builders.js';
11
+ import { decide, routeSwitch } from './decide-builders.js';
12
+ import { schedule } from './every.js';
13
+ import { loop } from './loop-builder.js';
14
+ import { bindingsFor, documentScopeOf, hydrateNode } from './workflow-hydrator.js';
15
+ //#region Control-Flow Node Hydrators
16
+ /**
17
+ * A `decide` predicate hydrates to the decide step itself; the loop runs it as
18
+ * the decider. `where` names the loop in errors from its `expr` predicates.
19
+ */
20
+ function hydrateUntilPredicate(pred, ctx, where) {
21
+ const hydrate = (p) => hydrateUntilPredicate(p, ctx, where);
22
+ switch (pred.kind) {
23
+ case 'maxSteps':
24
+ return until.maxSteps(pred.n);
25
+ case 'maxCost':
26
+ return until.maxCost(pred.usd);
27
+ case 'maxDuration':
28
+ return until.maxDuration(pred.duration);
29
+ case 'noToolCalls':
30
+ return until.noToolCalls();
31
+ case 'never':
32
+ return until.never();
33
+ case 'outputContains':
34
+ return until.outputContains(pred.marker);
35
+ case 'outputEquals':
36
+ return until.outputEquals(pred.sentinel);
37
+ case 'converged':
38
+ return until.converged({
39
+ threshold: pred.threshold,
40
+ });
41
+ case 'expr':
42
+ return untilExpr(pred.expr, where, ctx);
43
+ case 'any':
44
+ return any(...pred.predicates.map(hydrate));
45
+ case 'all':
46
+ return all(...pred.predicates.map(hydrate));
47
+ case 'decide':
48
+ return frameworkCast(hydrateNode(pred, ctx));
49
+ default:
50
+ throw new NoeticConfigError({
51
+ code: 'UNKNOWN_UNTIL_PREDICATE',
52
+ message: `Unknown until predicate kind: '${frameworkCast(pred).kind}'.`,
53
+ hint: 'Supported kinds: maxSteps, maxCost, maxDuration, noToolCalls, never, outputContains, outputEquals, converged, expr, any, all, decide.',
54
+ });
55
+ }
56
+ }
57
+ /**
58
+ * Stops when `expr` gives `true` against the loop's last output, read as an
59
+ * expression input. A failing expression throws `NoeticConfigError`, which
60
+ * fails the loop instead of stopping it (spec 05, Error Behavior).
61
+ */
62
+ function untilExpr(expr, where, ctx) {
63
+ const compiled = compileExpression(expr, where, ctx.expressionLimits);
64
+ const scope = documentScopeOf(ctx);
65
+ return async (snap, run) => {
66
+ const stop = await passes(compiled, readInput(snap.lastOutput), {
67
+ steps: run ? stepOutputsOf(frameworkCast(run.ctx), scope) : {},
68
+ });
69
+ return {
70
+ stop,
71
+ reason: stop ? `expr gave true: ${expr}` : undefined,
72
+ };
73
+ };
74
+ }
75
+ export function hydrateConditionalNode(node, ctx) {
76
+ if (node.kind !== 'conditional') {
77
+ return frameworkCast(undefined);
78
+ }
79
+ const hydratedRoutes = node.routes.map((r, i) => ({
80
+ passes: routeTest(r, `route ${i} of conditional node '${node.id}'`, ctx.expressionLimits),
81
+ target: hydrateNode(r.target, ctx),
82
+ }));
83
+ const defaultTarget = node.default ? hydrateNode(node.default, ctx) : null;
84
+ const allTargets = hydratedRoutes.map((r) => r.target);
85
+ if (defaultTarget) {
86
+ allTargets.push(defaultTarget);
87
+ }
88
+ return conditional({
89
+ id: node.id,
90
+ route: async (input, execCtx) => {
91
+ const view = {
92
+ text: routeText(input).trim().toLowerCase(),
93
+ value: readInput(input),
94
+ bindings: bindingsFor(execCtx, ctx),
95
+ };
96
+ for (const r of hydratedRoutes) {
97
+ if (await r.passes(view)) {
98
+ return r.target;
99
+ }
100
+ }
101
+ return defaultTarget;
102
+ },
103
+ _optimizable: frameworkCast(allTargets),
104
+ });
105
+ }
106
+ function routeTest(route, where, limits) {
107
+ if (route.expr !== undefined) {
108
+ const compiled = compileExpression(route.expr, where, limits);
109
+ return (input) => passes(compiled, input.value, input.bindings);
110
+ }
111
+ const needle = (route.match ?? '').toLowerCase();
112
+ return (input) => input.text.includes(needle);
113
+ }
114
+ /**
115
+ * The text a branch matches against. An object input — a `decide` node's
116
+ * answers, or their JSON once a sequence has stringified them — matches on its
117
+ * string values only: its keys and probability maps name every choice, so
118
+ * matching the JSON would hit every route.
119
+ */
120
+ function routeText(input) {
121
+ const value = typeof input === 'string' ? parseJsonObject(input) : input;
122
+ if (typeof value === 'string') {
123
+ return value;
124
+ }
125
+ const values = [];
126
+ const walk = (value) => {
127
+ if (typeof value === 'string') {
128
+ values.push(value);
129
+ return;
130
+ }
131
+ if (typeof value !== 'object' || value === null) {
132
+ return;
133
+ }
134
+ for (const child of Object.values(value)) {
135
+ walk(child);
136
+ }
137
+ };
138
+ walk(value);
139
+ return values.join('\n');
140
+ }
141
+ /** The parsed object or array when `text` is one in JSON, else `text` itself. */
142
+ function parseJsonObject(text) {
143
+ const trimmed = text.trim();
144
+ if (!trimmed.startsWith('{') && !trimmed.startsWith('[')) {
145
+ return text;
146
+ }
147
+ try {
148
+ const parsed = JSON.parse(trimmed);
149
+ return typeof parsed === 'object' && parsed !== null ? parsed : text;
150
+ }
151
+ catch {
152
+ return text;
153
+ }
154
+ }
155
+ export function hydrateDecideNode(node, _ctx) {
156
+ if (node.kind !== 'decide') {
157
+ return frameworkCast(undefined);
158
+ }
159
+ return frameworkCast(decideFromNode(node));
160
+ }
161
+ function decideFromNode(node) {
162
+ return decide({
163
+ id: node.id,
164
+ model: node.model,
165
+ instructions: node.instructions,
166
+ questions: node.questions,
167
+ view: node.view,
168
+ samples: node.samples,
169
+ });
170
+ }
171
+ export function hydrateRouteSwitchNode(node, ctx) {
172
+ if (node.kind !== 'routeSwitch') {
173
+ return frameworkCast(undefined);
174
+ }
175
+ const cases = {};
176
+ for (const [key, target] of Object.entries(node.cases)) {
177
+ cases[key] = hydrateNode(target, ctx);
178
+ }
179
+ // A JSON node's outcomes are only known at runtime; the builder checks them.
180
+ return frameworkCast(routeSwitch({
181
+ id: node.id,
182
+ decide: decideFromNode(node.decide),
183
+ on: node.on,
184
+ cases: frameworkCast(cases),
185
+ minConfidence: node.minConfidence,
186
+ uncertain: hydrateNode(node.uncertain, ctx),
187
+ }));
188
+ }
189
+ export function hydrateLoopNode(node, ctx) {
190
+ if (node.kind !== 'loop') {
191
+ return frameworkCast(undefined);
192
+ }
193
+ return loop({
194
+ id: node.id,
195
+ steps: [
196
+ hydrateNode(node.body, ctx),
197
+ ],
198
+ until: hydrateUntilPredicate(node.until, ctx, `until of loop node '${node.id}'`),
199
+ maxIterations: node.maxIterations === 'infinity' ? Number.POSITIVE_INFINITY : node.maxIterations,
200
+ });
201
+ }
202
+ export function hydrateScheduleNode(node, ctx) {
203
+ if (node.kind !== 'schedule') {
204
+ return frameworkCast(undefined);
205
+ }
206
+ return schedule({
207
+ id: node.id,
208
+ step: hydrateNode(node.step, ctx),
209
+ interval: node.interval,
210
+ onError: node.onError,
211
+ });
212
+ }
213
+ //#endregion
@@ -6,9 +6,10 @@
6
6
  * ones — they register in the step registry, carry retry policies, etc.
7
7
  */
8
8
  import type { ContextData, ContextLayer } from '@noetic-tools/context';
9
- import type { AcpAgent, CustomItemMap, ExecuteStepFn, OutputCodec, Step, SubprocessAdapter, Tool } from '@noetic-tools/types';
10
- import type { ExpressionLimits } from '../expression/jsonata.js';
11
- import type { WorkflowDocument, WorkflowNode } from '../schemas/workflow.js';
9
+ import type { AcpAgent, Context, CustomItemMap, ExecuteStepFn, OutputCodec, Step, SubprocessAdapter, Tool } from '@noetic-tools/types';
10
+ import type { ExpressionBindings, ExpressionLimits } from '../expression/jsonata.js';
11
+ import type { WorkflowConnectionRef, WorkflowDocument, WorkflowNode, WorkflowStepList } from '../schemas/workflow.js';
12
+ import type { ConnectionManifestEntries, ConnectionUses } from './workflow-connections.js';
12
13
  /** @public Context required to hydrate a JSON workflow into live steps. */
13
14
  export interface HydrationContext {
14
15
  tools: ReadonlyMap<string, Tool>;
@@ -51,12 +52,51 @@ export interface HydrationContext {
51
52
  recursionDepth?: number;
52
53
  /** Bounds on each expression evaluation; unset fields use `DEFAULT_EXPRESSION_LIMITS`. */
53
54
  expressionLimits?: ExpressionLimits;
55
+ /**
56
+ * The hydrated document's identity for `$steps`: each `hydrateWorkflow` call
57
+ * makes a new one, so two documents in one run never read each other's node
58
+ * outputs. Set internally — callers never set it.
59
+ */
60
+ documentScope?: object;
54
61
  /**
55
62
  * Custom items the nodes being hydrated may emit (spec 34): the enclosing document's
56
63
  * root scope. Threaded by `hydrateWorkflow` and the subflow hydrator.
57
64
  */
58
65
  customItems?: CustomItemMap;
66
+ /**
67
+ * The connections the enclosing document declares (spec 35 § JSON workflows).
68
+ * Threaded by `hydrateWorkflow`; a node naming a connection outside it fails
69
+ * with `CONNECTION_UNKNOWN`. Without a manifest, names pass to the registry as they are.
70
+ */
71
+ connections?: ConnectionManifestEntries;
72
+ /** What the document uses of each connection, for negotiation and gate 1. Threaded by `hydrateWorkflow`. */
73
+ connectionUses?: ConnectionUses;
74
+ /**
75
+ * The connection an operation written by name, or a node without
76
+ * `connection`, runs on: a `verify` subject or a `wait`'s connection. Without
77
+ * one, the document's only connection.
78
+ */
79
+ enclosingConnection?: WorkflowConnectionRef;
80
+ /** The connection name `$item` holds on a fan-out path (an `inParallel` whose `over` lists connections). */
81
+ fanOutItem?: string;
59
82
  }
83
+ /** The `$steps` scope of the document `ctx` is hydrating. */
84
+ export declare function documentScopeOf(ctx: HydrationContext): object;
85
+ /** The bindings an expression evaluated in `execCtx` sees: `$steps`, and `$item` on a fan-out path. */
86
+ export declare function bindingsFor(execCtx: Context, ctx: HydrationContext): ExpressionBindings;
87
+ /**
88
+ * Hydrates a step list (`around`, `act`, a sequence's steps): each entry a node,
89
+ * or an operation written by name that becomes a `call` with id `<parentId>[i]`
90
+ * on `enclosing` (when given).
91
+ *
92
+ * @public
93
+ */
94
+ export declare function hydrateStepList(opts: {
95
+ list: WorkflowStepList;
96
+ parentId: string;
97
+ ctx: HydrationContext;
98
+ enclosing?: WorkflowConnectionRef;
99
+ }): Step<ContextData, string, unknown>[];
60
100
  /**
61
101
  * Hydrates a single `WorkflowNode` into a live `Step`.
62
102
  *
@@ -85,5 +125,6 @@ export declare function hydrateNode(node: WorkflowNode, ctx: HydrationContext):
85
125
  * @param customItems - TypeScript declarations of the document's root custom items (spec 34).
86
126
  * @returns The root `Step` of the hydrated workflow.
87
127
  * @throws `NoeticConfigError` with code `CUSTOM_ITEM_MISMATCH` when `customItems` and the document give one name different types.
128
+ * @throws `NoeticConfigError` with code `CONNECTION_UNKNOWN` when a node uses a connection the document's `connections` do not declare, or `CONNECTION_INVALID` when a node's connection is neither named nor implied, or a source entry is used beyond its events.
88
129
  */
89
130
  export declare function hydrateWorkflow(doc: WorkflowDocument, ctx: HydrationContext, customItems?: CustomItemMap): Step<ContextData, string, string>;