@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,83 @@
1
+ import { GenAI, NoeticAttr, ToolAttr } from '../observability/genai-attributes.js';
2
+ import { exportSpans } from './deps/context.js';
3
+ //#region Call span collector
4
+ /**
5
+ * Per-`callModel` span accumulator. Spans are created lazily from the calling
6
+ * context's span (so the trace tree mirrors the execution tree) and flushed to
7
+ * the harness `traceExporter` once the call settles — see issue #50, where the
8
+ * exporter was stored but never invoked.
9
+ */
10
+ export class CallSpanCollector {
11
+ harness;
12
+ exporter;
13
+ parent;
14
+ nodeId;
15
+ firstSpanAttributes;
16
+ spans = [];
17
+ constructor(harness, exporter, parent, nodeId,
18
+ /** Stamped on the first model span only, then dropped. */
19
+ firstSpanAttributes) {
20
+ this.harness = harness;
21
+ this.exporter = exporter;
22
+ this.parent = parent;
23
+ this.nodeId = nodeId;
24
+ this.firstSpanAttributes = firstSpanAttributes;
25
+ }
26
+ /** Link a span back to its declared workflow node, when the call carries one. */
27
+ stampNode(span) {
28
+ if (this.nodeId !== undefined) {
29
+ span.setAttribute(NoeticAttr.NODE_ID, this.nodeId);
30
+ }
31
+ }
32
+ /** Open a model-call span stamped with GenAI semantic-convention attributes. */
33
+ startModelSpan(model) {
34
+ const span = this.harness.createSpan('llm.call', this.parent);
35
+ span.setAttribute(GenAI.SYSTEM, 'openrouter');
36
+ span.setAttribute(GenAI.REQUEST_MODEL, model);
37
+ this.stampNode(span);
38
+ for (const [key, value] of Object.entries(this.firstSpanAttributes ?? {})) {
39
+ span.setAttribute(key, value);
40
+ }
41
+ this.firstSpanAttributes = undefined;
42
+ this.spans.push(span);
43
+ return span;
44
+ }
45
+ /** Record usage + cost on a model-call span. */
46
+ finishModelSpan(span, usage, cost) {
47
+ span.setAttribute(GenAI.USAGE_INPUT_TOKENS, usage.inputTokens);
48
+ span.setAttribute(GenAI.USAGE_OUTPUT_TOKENS, usage.outputTokens);
49
+ if (usage.cachedTokens !== undefined) {
50
+ span.setAttribute(GenAI.USAGE_CACHED_INPUT_TOKENS, usage.cachedTokens);
51
+ }
52
+ if (usage.cacheWriteTokens !== undefined) {
53
+ span.setAttribute(GenAI.USAGE_CACHE_WRITE_TOKENS, usage.cacheWriteTokens);
54
+ }
55
+ if (cost !== undefined) {
56
+ span.setAttribute(GenAI.COST, cost);
57
+ }
58
+ span.end();
59
+ }
60
+ /**
61
+ * Open and immediately close a tool-call span under the given model span, or under
62
+ * the call's parent when the round's model call ran in an earlier attempt.
63
+ */
64
+ recordToolSpan(parent, toolName, needsApproval, approval) {
65
+ const span = this.harness.createSpan('tool.call', parent ?? this.parent);
66
+ span.setAttribute(ToolAttr.NAME, toolName);
67
+ span.setAttribute(ToolAttr.NEEDS_APPROVAL, needsApproval);
68
+ if (approval !== undefined) {
69
+ span.setAttribute(ToolAttr.APPROVAL, approval);
70
+ }
71
+ this.stampNode(span);
72
+ span.end();
73
+ this.spans.push(span);
74
+ }
75
+ /** Flush all accumulated spans to the exporter. */
76
+ async flush() {
77
+ if (this.spans.length === 0) {
78
+ return;
79
+ }
80
+ await exportSpans(this.exporter, this.spans);
81
+ }
82
+ }
83
+ //#endregion
@@ -0,0 +1,78 @@
1
+ import type { ConnectionStatus } from '@noetic-tools/types';
2
+ import type { HarnessConnectionsOptions } from '../connections/harness-wiring.js';
3
+ import type { ConnectionRuntime } from '../connections/registry.js';
4
+ import type { Context, ContextLayer, Step, StorageAdapter, Tool } from './deps/types.js';
5
+ /**
6
+ * A harness's connections, as the harness drives them: providers and triggers,
7
+ * negotiation of each run root's needs, and the rerun allowances restores grant
8
+ * (spec 35). The harness holds it in a true private field, so nothing holding
9
+ * `ctx.harness` reaches the registry (spec 35 § Gates).
10
+ */
11
+ export declare class ConnectionGate {
12
+ #private;
13
+ /**
14
+ * Wires the harness's connections and triggers, when it has any, and records
15
+ * the registry and `verifier` as the harness's private internals, where steps
16
+ * and tools find them without anything public on the harness.
17
+ */
18
+ constructor(options: HarnessConnectionsOptions & {
19
+ readonly verifier?: unknown;
20
+ });
21
+ /** The connection registry, absent on a harness without connections or triggers. */
22
+ get registry(): ConnectionRuntime | undefined;
23
+ /** One view layer per non-pool connection. */
24
+ get views(): ReadonlyArray<ContextLayer>;
25
+ /** This turn's connection tools. */
26
+ tools(): Tool[];
27
+ /** Connects providers and starts triggers. Idempotent. */
28
+ start(): Promise<void>;
29
+ /** Each connection's state, identity and pool usage; one entry for `name`, or all. */
30
+ status(name?: string): ReadonlyArray<ConnectionStatus>;
31
+ /** Stops triggers and releases every connection. */
32
+ close(): Promise<void>;
33
+ /**
34
+ * Registers what the agent graph's handles need: their profiles (ref kinds) and
35
+ * requirements, negotiated at start and again on every manifest change
36
+ * (spec 35 § Connection registry). Names the harness lacks are left to fail
37
+ * with `CONNECTION_UNKNOWN` when the step runs.
38
+ */
39
+ registerGraphNeeds(agentGraph: Step | undefined): void;
40
+ /**
41
+ * Negotiates a `run()` root that is not the agent graph after the providers
42
+ * have connected: registers its handles' profiles and checks its requirements
43
+ * against each connection's manifest, so a root that needs more than a
44
+ * connection offers fails before it executes, as a document does (spec 35
45
+ * § Negotiation). A root is remembered as negotiated only once every
46
+ * connection it needs was checked; one whose connection was down (or whose
47
+ * pool has provisioned nothing yet) is checked again on its next run.
48
+ *
49
+ * @throws `NoeticConfigError` `CONNECTION_UNSATISFIED` when a connection falls short.
50
+ */
51
+ negotiateRoot(root: Step): void;
52
+ /** Holds the rerun allowance a restore grants on the context it returns. */
53
+ holdReruns(ctx: Context, rerun: ReadonlyArray<string>): void;
54
+ /** Ends the rerun allowance `ctx` carries, for a run that failed before executing. */
55
+ dropReruns(ctx: Context): void;
56
+ /**
57
+ * Hands the rerun allowance a restore left on `ctx` to its run, which ends it
58
+ * when it finishes (released or orphaned, see `endRun`).
59
+ */
60
+ grantReruns(ctx: Context): void;
61
+ /**
62
+ * Before a resumed run replays anything, checks the connections its ledger and
63
+ * pending entries were recorded against, discarding the ledger from the first
64
+ * entry whose connection was replaced (spec 35 § Durability).
65
+ *
66
+ * @throws NoeticErrorImpl `connection_resume_refused` when a replaced connection is unsafe to drive again.
67
+ */
68
+ reconcile(ctx: Context, storage: StorageAdapter | undefined): Promise<void>;
69
+ /**
70
+ * Ends a root run's hold on its connections. A failed run keeps its pool
71
+ * leases, unrenewed, so a resume within the reclaim window gets the same
72
+ * connections back and an abandoned one frees them (spec 35 § Pools and
73
+ * leases); a finished run releases them.
74
+ */
75
+ orphanRun(executionId: string): void;
76
+ /** Releases a finished root run's connections and pool leases. */
77
+ releaseRun(executionId: string): Promise<void>;
78
+ }
@@ -0,0 +1,170 @@
1
+ import { createHarnessConnections } from '../connections/harness-wiring.js';
2
+ import { setHarnessInternals } from '../util/harness-internals.js';
3
+ import { graphConnectionNeeds, reconcileResumedConnections } from './deps/interpreter.js';
4
+ import { ContextImpl } from './deps/runtime.js';
5
+ /**
6
+ * A harness's connections, as the harness drives them: providers and triggers,
7
+ * negotiation of each run root's needs, and the rerun allowances restores grant
8
+ * (spec 35). The harness holds it in a true private field, so nothing holding
9
+ * `ctx.harness` reaches the registry (spec 35 § Gates).
10
+ */
11
+ export class ConnectionGate {
12
+ #connections;
13
+ /** Roots whose connection needs are already registered or checked. */
14
+ #negotiatedRoots = new WeakSet();
15
+ /**
16
+ * Connections a `restore(id, { rerun })` let its restored context drive again
17
+ * live, held on that context until its run starts (then granted to the run,
18
+ * and ended with it), so a later plain restore of the same id never inherits
19
+ * them (spec 35 § Durability).
20
+ */
21
+ #reruns = new WeakMap();
22
+ /**
23
+ * Wires the harness's connections and triggers, when it has any, and records
24
+ * the registry and `verifier` as the harness's private internals, where steps
25
+ * and tools find them without anything public on the harness.
26
+ */
27
+ constructor(options) {
28
+ if (options.connections || (options.triggers && options.triggers.length > 0)) {
29
+ this.#connections = createHarnessConnections(options);
30
+ }
31
+ setHarnessInternals(options.harness, {
32
+ connectionRegistry: this.#connections?.registry,
33
+ verifier: options.verifier,
34
+ secrets: options.secrets,
35
+ });
36
+ }
37
+ /** The connection registry, absent on a harness without connections or triggers. */
38
+ get registry() {
39
+ return this.#connections?.registry;
40
+ }
41
+ /** One view layer per non-pool connection. */
42
+ get views() {
43
+ return this.#connections?.views ?? [];
44
+ }
45
+ /** This turn's connection tools. */
46
+ tools() {
47
+ return this.#connections?.tools() ?? [];
48
+ }
49
+ /** Connects providers and starts triggers. Idempotent. */
50
+ async start() {
51
+ await this.#connections?.start();
52
+ }
53
+ /** Each connection's state, identity and pool usage; one entry for `name`, or all. */
54
+ status(name) {
55
+ return this.#connections?.registry.status(name) ?? [];
56
+ }
57
+ /** Stops triggers and releases every connection. */
58
+ async close() {
59
+ await this.#connections?.close();
60
+ }
61
+ /**
62
+ * Registers what the agent graph's handles need: their profiles (ref kinds) and
63
+ * requirements, negotiated at start and again on every manifest change
64
+ * (spec 35 § Connection registry). Names the harness lacks are left to fail
65
+ * with `CONNECTION_UNKNOWN` when the step runs.
66
+ */
67
+ registerGraphNeeds(agentGraph) {
68
+ const registry = this.#connections?.registry;
69
+ if (!registry || !agentGraph) {
70
+ return;
71
+ }
72
+ this.#negotiatedRoots.add(agentGraph);
73
+ const known = new Set(registry.names());
74
+ for (const need of graphConnectionNeeds(agentGraph)) {
75
+ if (need.profile) {
76
+ registry.registerProfile(need.profile);
77
+ }
78
+ if (known.has(need.name)) {
79
+ registry.require(need.name, need.requirement, {
80
+ setup: need.setup,
81
+ });
82
+ }
83
+ }
84
+ }
85
+ /**
86
+ * Negotiates a `run()` root that is not the agent graph after the providers
87
+ * have connected: registers its handles' profiles and checks its requirements
88
+ * against each connection's manifest, so a root that needs more than a
89
+ * connection offers fails before it executes, as a document does (spec 35
90
+ * § Negotiation). A root is remembered as negotiated only once every
91
+ * connection it needs was checked; one whose connection was down (or whose
92
+ * pool has provisioned nothing yet) is checked again on its next run.
93
+ *
94
+ * @throws `NoeticConfigError` `CONNECTION_UNSATISFIED` when a connection falls short.
95
+ */
96
+ negotiateRoot(root) {
97
+ const registry = this.#connections?.registry;
98
+ if (!registry || this.#negotiatedRoots.has(root)) {
99
+ return;
100
+ }
101
+ const known = new Set(registry.names());
102
+ let checkedAll = true;
103
+ for (const need of graphConnectionNeeds(root)) {
104
+ if (need.profile) {
105
+ registry.registerProfile(need.profile);
106
+ }
107
+ if (known.has(need.name) &&
108
+ !registry.check(need.name, need.requirement, {
109
+ setup: need.setup,
110
+ })) {
111
+ checkedAll = false;
112
+ }
113
+ }
114
+ if (checkedAll) {
115
+ this.#negotiatedRoots.add(root);
116
+ }
117
+ }
118
+ /** Holds the rerun allowance a restore grants on the context it returns. */
119
+ holdReruns(ctx, rerun) {
120
+ this.#reruns.set(ctx, rerun);
121
+ }
122
+ /** Ends the rerun allowance `ctx` carries, for a run that failed before executing. */
123
+ dropReruns(ctx) {
124
+ this.#reruns.delete(ctx);
125
+ }
126
+ /**
127
+ * Hands the rerun allowance a restore left on `ctx` to its run, which ends it
128
+ * when it finishes (released or orphaned, see `endRun`).
129
+ */
130
+ grantReruns(ctx) {
131
+ const rerun = this.#reruns.get(ctx);
132
+ if (!rerun) {
133
+ return;
134
+ }
135
+ this.#reruns.delete(ctx);
136
+ this.#connections?.registry.allowRerun(ctx.id, rerun);
137
+ }
138
+ /**
139
+ * Before a resumed run replays anything, checks the connections its ledger and
140
+ * pending entries were recorded against, discarding the ledger from the first
141
+ * entry whose connection was replaced (spec 35 § Durability).
142
+ *
143
+ * @throws NoeticErrorImpl `connection_resume_refused` when a replaced connection is unsafe to drive again.
144
+ */
145
+ async reconcile(ctx, storage) {
146
+ const registry = this.#connections?.registry;
147
+ if (!registry || !(ctx instanceof ContextImpl) || !ctx.ledger) {
148
+ return;
149
+ }
150
+ await reconcileResumedConnections({
151
+ ctx,
152
+ registry,
153
+ storage,
154
+ signal: ctx.abortSignal,
155
+ });
156
+ }
157
+ /**
158
+ * Ends a root run's hold on its connections. A failed run keeps its pool
159
+ * leases, unrenewed, so a resume within the reclaim window gets the same
160
+ * connections back and an abandoned one frees them (spec 35 § Pools and
161
+ * leases); a finished run releases them.
162
+ */
163
+ orphanRun(executionId) {
164
+ this.#connections?.registry.orphanRun?.(executionId);
165
+ }
166
+ /** Releases a finished root run's connections and pool leases. */
167
+ async releaseRun(executionId) {
168
+ await this.#connections?.registry.releaseRun(executionId);
169
+ }
170
+ }
@@ -1,4 +1,5 @@
1
1
  export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
2
+ export { clearPendingEntries, graphConnectionNeeds, reconcileResumedConnections, } from '../../interpreter/connection-steps.js';
2
3
  export { prepareBandedView } from '../../interpreter/context-assembly.js';
3
4
  export { collectCustomItems } from '../../interpreter/emit-items.js';
4
5
  export { execute } from '../../interpreter/execute.js';
@@ -1,4 +1,5 @@
1
1
  export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
2
+ export { clearPendingEntries, graphConnectionNeeds, reconcileResumedConnections, } from '../../interpreter/connection-steps.js';
2
3
  export { prepareBandedView } from '../../interpreter/context-assembly.js';
3
4
  export { collectCustomItems } from '../../interpreter/emit-items.js';
4
5
  export { execute } from '../../interpreter/execute.js';
@@ -3,7 +3,7 @@ export { ChannelStore, warnToConsole } from '../../runtime/channel-store.js';
3
3
  export { ContextImpl, collectContextTree, laneBase, rootIdOf } from '../../runtime/context-impl.js';
4
4
  export { snapshotCwdState } from '../../runtime/cwd-helpers.js';
5
5
  export { Drains } from '../../runtime/drain.js';
6
- export type { CheckpointStore } from '../../runtime/durable/index.js';
6
+ export type { CheckpointStore } from '../../runtime/durable/checkpoint-store.js';
7
7
  export { createCheckpointStore } from '../../runtime/durable/checkpoint-store.js';
8
8
  export type { RestoreCheckpointOptions } from '../../runtime/durable/harness-checkpoints.js';
9
9
  export { captureCheckpoint, clearCheckpoint, restoreFromCheckpoint, } from '../../runtime/durable/harness-checkpoints.js';
@@ -1,4 +1,4 @@
1
1
  export type { ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, ExecutionContext, ProjectionPolicy, StorageAdapter, } from '@noetic-tools/context';
2
- export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, CancelOptions, Channel, ChannelHandle, Context, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DeliveryMode, DetachedHandle, DrainReport, ExecuteInput, ExecuteOptions, ExecutionScope, ExecutionStatus, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, PendingSpend, RecallLayerOutput, RecallOptions, ReconcileSpendOptions, SessionScope, SessionUsage, ShellAdapter, Span, SpendSettlement, SteeringDecision, SteerVerdict, Step, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, UsageCharge, WriteOffSpendOptions, } from '@noetic-tools/types';
2
+ export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, CancelOptions, Channel, ChannelHandle, Context, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DeliveryMode, DetachedHandle, DrainReport, ExecuteInput, ExecuteOptions, ExecutionScope, ExecutionStatus, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, PendingSpend, RecallLayerOutput, RecallOptions, ReconcileSpendOptions, SessionScope, SessionUsage, ShellAdapter, Span, SpendSettlement, SteeringDecision, SteerVerdict, Step, StepLike, Steps, StepsInput, StepsOutput, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, UsageCharge, ValidStepChain, WriteOffSpendOptions, } from '@noetic-tools/types';
3
3
  export { SteeringAction } from '@noetic-tools/types';
4
4
  export type { ZodType } from 'zod';
@@ -0,0 +1,153 @@
1
+ import type { ArtifactStore, ConnectionsConfig, ConnectionTrigger, SecretResolver } from '@noetic-tools/types';
2
+ import type { Verifier } from '@noetic-tools/types/verify';
3
+ import type { LayerStateStore } from './deps/context.js';
4
+ import type { CheckpointStore, StepLedgerRetention } from './deps/runtime.js';
5
+ import type { AgentHooks, CallModelRequest, ContextCacheConfig, ContextData, ContextLayer, CustomItem, CustomItemsBrand, DecideRequest, DecideResponse, DeliveryMode, FsAdapter, ItemSchemaConfig, LLMResponse, LlmProviderConfig, ProjectionPolicy, ShellAdapter, Steps, StorageAdapter, SubprocessAdapter, Tool, ToolApprover, TraceExporter, ZodType } from './deps/types.js';
6
+ /**
7
+ * Storage-scoped environment configuration for `AgentHarness`.
8
+ *
9
+ * @public
10
+ */
11
+ export interface StorageEnvironmentConfig {
12
+ /**
13
+ * Key-value storage adapter backing context-layer persistence and the
14
+ * step-completion ledger. Defaults to an in-memory adapter.
15
+ */
16
+ adapter?: StorageAdapter;
17
+ /**
18
+ * Checkpoint store used by `harness.checkpoint(ctx)` / `harness.restore()`.
19
+ * Defaults to a store over `adapter` when one is given, so configuring durable
20
+ * storage is enough for a later harness on the same storage to resume this one's
21
+ * executions (see the harness `durability` option to turn that off). With no
22
+ * adapter and no store, checkpoint/restore are no-ops — a zero-config harness keeps
23
+ * its ephemeral semantics.
24
+ */
25
+ checkpointStore?: CheckpointStore;
26
+ /** Layer-state store override. Defaults to an in-memory store. */
27
+ layerStateStore?: LayerStateStore;
28
+ /**
29
+ * Bounds on the step-completion ledger that backs step-level resume. Only meaningful
30
+ * when durability is on (a `checkpointStore`, given or defaulted). Defaults to `DEFAULT_STEP_LEDGER_RETENTION` — 128 KiB
31
+ * per entry, 1000 entries per execution — so an unbounded run cannot grow an unbounded
32
+ * ledger. Exceeding either cap costs resumability for the affected steps (they re-run),
33
+ * never correctness.
34
+ */
35
+ stepLedgerRetention?: StepLedgerRetention;
36
+ }
37
+ /**
38
+ * Execution-environment configuration for `AgentHarness`: the storage,
39
+ * filesystem, shell, and subprocess surfaces the agent runs against.
40
+ *
41
+ * @public
42
+ */
43
+ export interface AgentEnvironmentConfig {
44
+ /** Storage configuration: adapter, durability stores, ledger retention. */
45
+ storage?: StorageEnvironmentConfig;
46
+ /** Filesystem adapter. Defaults to an in-memory adapter. */
47
+ fs?: FsAdapter;
48
+ /** Shell adapter. Defaults to an in-memory adapter. */
49
+ shell?: ShellAdapter;
50
+ /** Subprocess adapter. Defaults to an in-memory, same-process adapter. */
51
+ subprocess?: SubprocessAdapter;
52
+ /** Resolves `secret()` names immediately before a connection call is sent (spec 35 § Secrets). */
53
+ secrets?: SecretResolver;
54
+ /** Where binary content is stored (spec 08 § Artifact Store). Defaults to an in-memory store. */
55
+ artifacts?: ArtifactStore;
56
+ }
57
+ /** `AgentHarness` constructor options. */
58
+ export interface AgentHarnessOpts<TParams extends Record<string, unknown> = Record<string, unknown>, TItem extends CustomItem = CustomItem> {
59
+ name: string;
60
+ /**
61
+ * Root step tree executed for every turn submitted via `execute()`. The custom items
62
+ * it declares (a `workflow()` step's brand) type `getItemStream`, `getFullStream`,
63
+ * and `getAgentResponse` (spec 34).
64
+ */
65
+ agentGraph?: Steps<ContextData, string, string> & CustomItemsBrand<TItem>;
66
+ /** Default context layers applied to every context created via `createContext()` / `execute()`. */
67
+ contextLayers?: ContextLayer[];
68
+ /**
69
+ * Whether runs and sessions are durable: checkpointed, recorded to the step ledger,
70
+ * and resumable on a later harness over the same storage. Defaults to true whenever
71
+ * `environment.storage` gives an adapter or a checkpoint store. `false` turns every
72
+ * durability surface off even then — the adapter still backs context-layer
73
+ * persistence.
74
+ */
75
+ durability?: boolean;
76
+ hooks?: AgentHooks;
77
+ /**
78
+ * Harness-wide tool pool. Merged (identity-deduplicated) with tools
79
+ * collected from `agentGraph` to form every context's `unifiedTools`.
80
+ * Use this when the workflow step tree is static and tools are supplied
81
+ * per harness instance rather than baked into individual `step.callModel` calls.
82
+ */
83
+ tools?: Tool[];
84
+ params: TParams;
85
+ paramsSchema?: ZodType<TParams>;
86
+ /** Execution environment: storage, filesystem, shell, subprocess. */
87
+ environment?: AgentEnvironmentConfig;
88
+ /** Default provider configuration for model calls made through this harness. */
89
+ callModelDefaults?: LlmProviderConfig;
90
+ /** Harness-wide item schema extensions and validation strictness. */
91
+ itemSchemas?: ItemSchemaConfig;
92
+ /** Default projection policy for all LLM steps. Individual steps override via `step.projection`. */
93
+ projection?: ProjectionPolicy;
94
+ /** When true, every layer is recalled atomically regardless of its `recallMode`. */
95
+ forceAtomicRecall?: boolean;
96
+ /** Tuning for prompt-cache anchoring. See `ContextCacheConfig` for the defaults. */
97
+ contextCache?: ContextCacheConfig;
98
+ traceExporter?: TraceExporter;
99
+ /** Default delivery mode for messages that don't specify one. Defaults to `next-turn`. */
100
+ defaultDeliveryMode?: DeliveryMode;
101
+ /**
102
+ * Initial working directory for the harness. Used as the seed value for the
103
+ * shared `cwdState.cwd` on every Context this harness creates, including
104
+ * those produced by spawn/fork. Defaults to `process.cwd()`.
105
+ */
106
+ initialCwd?: string;
107
+ /** Default model for `decide` steps. */
108
+ decisionModel?: string;
109
+ /**
110
+ * Whether a resumed run streams again the items its replayed steps emitted
111
+ * (`step.emitItems`), as `item_appended`. Defaults to `false`: a replay rebuilds the
112
+ * log quietly. Set it when a client that reconnects to a resumed run should see
113
+ * the progress it missed.
114
+ */
115
+ emitItemsOnReplay?: boolean;
116
+ /**
117
+ * Approves or refuses calls to tools that declare `needsApproval`, after the
118
+ * `beforeToolCall` layers allow them. Without one, those calls run
119
+ * unapproved and the harness warns once per tool name.
120
+ */
121
+ approveToolCall?: ToolApprover;
122
+ /**
123
+ * The live things the agent works with — browsers, devices, apps, chat workspaces,
124
+ * sources — by name (spec 35). Providers connect in `start()`.
125
+ */
126
+ connections?: ConnectionsConfig;
127
+ /** Connection events that start or join a turn (spec 35 § Triggers). */
128
+ triggers?: ReadonlyArray<ConnectionTrigger>;
129
+ /** The verifier `step.verify` uses (spec 37). */
130
+ verification?: Verifier;
131
+ /** @internal Test-only escape hatch to inject a mock callModel implementation. */
132
+ _testCallModel?: (request: CallModelRequest) => Promise<LLMResponse>;
133
+ /** @internal Test-only escape hatch to inject a mock decide implementation. */
134
+ _testDecide?: (request: DecideRequest) => Promise<DecideResponse>;
135
+ }
136
+ /** The platform surfaces a harness runs against, defaults filled in. */
137
+ export interface EnvironmentAdapters {
138
+ fs: FsAdapter;
139
+ shell: ShellAdapter;
140
+ subprocess: SubprocessAdapter;
141
+ artifacts: ArtifactStore;
142
+ }
143
+ /**
144
+ * The filesystem, shell, subprocess, and artifact store an environment configures,
145
+ * each defaulting to an in-memory implementation.
146
+ */
147
+ export declare function resolveEnvironmentAdapters(environment: AgentEnvironmentConfig | undefined): EnvironmentAdapters;
148
+ /**
149
+ * The checkpoint store a harness runs with: the one given, else a store over the
150
+ * configured storage adapter, so durable storage alone turns resume on. None when
151
+ * the harness sets `durability: false`.
152
+ */
153
+ export declare function resolveCheckpointStore(storage: StorageEnvironmentConfig | undefined, durability: boolean | undefined): CheckpointStore | undefined;
@@ -0,0 +1,36 @@
1
+ import { createInMemoryArtifactStore } from '../runtime/in-memory-artifact-store.js';
2
+ import { createInMemoryFsAdapter, createInMemoryShellAdapter, createInMemorySubprocessAdapter, } from './deps/adapters.js';
3
+ import { createCheckpointStore } from './deps/runtime.js';
4
+ //#endregion
5
+ //#region Resolution
6
+ /**
7
+ * The filesystem, shell, subprocess, and artifact store an environment configures,
8
+ * each defaulting to an in-memory implementation.
9
+ */
10
+ export function resolveEnvironmentAdapters(environment) {
11
+ return {
12
+ fs: environment?.fs ?? createInMemoryFsAdapter(),
13
+ shell: environment?.shell ?? createInMemoryShellAdapter(),
14
+ subprocess: environment?.subprocess ?? createInMemorySubprocessAdapter(),
15
+ artifacts: environment?.artifacts ?? createInMemoryArtifactStore(),
16
+ };
17
+ }
18
+ /**
19
+ * The checkpoint store a harness runs with: the one given, else a store over the
20
+ * configured storage adapter, so durable storage alone turns resume on. None when
21
+ * the harness sets `durability: false`.
22
+ */
23
+ export function resolveCheckpointStore(storage, durability) {
24
+ if (durability === false) {
25
+ return undefined;
26
+ }
27
+ if (storage?.checkpointStore) {
28
+ return storage.checkpointStore;
29
+ }
30
+ return storage?.adapter
31
+ ? createCheckpointStore({
32
+ storage: storage.adapter,
33
+ })
34
+ : undefined;
35
+ }
36
+ //#endregion
@@ -0,0 +1,16 @@
1
+ import type { ChannelWarning } from './deps/runtime.js';
2
+ import type { Context, Span, TraceExporter } from './deps/types.js';
3
+ /** The exporter a harness flushes spans to: the one configured, else a no-op exporter. */
4
+ export declare function resolveTraceExporter(exporter: TraceExporter | undefined): TraceExporter;
5
+ /** A harness span: one the harness's trace exporter receives. */
6
+ export declare function createHarnessSpan(name: string, parent: Span | null): Span;
7
+ /**
8
+ * Channel state is shared by every root on a harness, so a channel warning is
9
+ * recorded as a `channel.warning` event on each live root's span (spec 10). A
10
+ * root span counts only if it will reach the trace exporter — a harness span
11
+ * (`SpanImpl`) with a real exporter configured. With no such span the warning
12
+ * goes to the console, so it is never lost.
13
+ */
14
+ export declare function recordChannelWarning(warning: ChannelWarning, traceExporter: TraceExporter, liveRoots: Iterable<{
15
+ ctx: Context;
16
+ }>): void;
@@ -0,0 +1,35 @@
1
+ import { NoeticEvent } from '../observability/genai-attributes.js';
2
+ import { SpanImpl } from '../observability/span-impl.js';
3
+ import { NoopExporter } from '../observability/trace-exporter.js';
4
+ import { warnToConsole } from './deps/runtime.js';
5
+ /** The exporter a harness flushes spans to: the one configured, else a no-op exporter. */
6
+ export function resolveTraceExporter(exporter) {
7
+ return exporter ?? new NoopExporter();
8
+ }
9
+ /** A harness span: one the harness's trace exporter receives. */
10
+ export function createHarnessSpan(name, parent) {
11
+ return new SpanImpl(name, parent);
12
+ }
13
+ /**
14
+ * Channel state is shared by every root on a harness, so a channel warning is
15
+ * recorded as a `channel.warning` event on each live root's span (spec 10). A
16
+ * root span counts only if it will reach the trace exporter — a harness span
17
+ * (`SpanImpl`) with a real exporter configured. With no such span the warning
18
+ * goes to the console, so it is never lost.
19
+ */
20
+ export function recordChannelWarning(warning, traceExporter, liveRoots) {
21
+ const traced = traceExporter instanceof NoopExporter
22
+ ? []
23
+ : [
24
+ ...liveRoots,
25
+ ].filter(({ ctx }) => ctx.span instanceof SpanImpl);
26
+ if (traced.length === 0) {
27
+ warnToConsole(warning);
28
+ return;
29
+ }
30
+ for (const { ctx } of traced) {
31
+ ctx.span.addEvent(NoeticEvent.CHANNEL_WARNING, {
32
+ ...warning,
33
+ });
34
+ }
35
+ }