@noetic-tools/core 5.20.0-next.1 → 5.20.0

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 (90) hide show
  1. package/dist/adapters/openrouter.d.ts +1 -48
  2. package/dist/adapters/openrouter.js +3 -204
  3. package/dist/builders/acp-agent-checks.d.ts +20 -0
  4. package/dist/builders/acp-agent-checks.js +68 -0
  5. package/dist/builders/acp-agent-tool.d.ts +4 -3
  6. package/dist/builders/acp-agent-tool.js +5 -2
  7. package/dist/builders/connection-ceiling.d.ts +13 -0
  8. package/dist/builders/connection-ceiling.js +17 -0
  9. package/dist/builders/document-entries.d.ts +13 -0
  10. package/dist/builders/document-entries.js +18 -0
  11. package/dist/builders/dynamic-workflow.d.ts +53 -8
  12. package/dist/builders/dynamic-workflow.js +53 -25
  13. package/dist/builders/mcp-url-pattern.d.ts +13 -0
  14. package/dist/builders/mcp-url-pattern.js +85 -0
  15. package/dist/builders/step-builders.d.ts +14 -6
  16. package/dist/builders/step-builders.js +25 -2
  17. package/dist/builders/workflow-acp-grants.d.ts +42 -0
  18. package/dist/builders/workflow-acp-grants.js +224 -0
  19. package/dist/builders/workflow-child-nodes.js +8 -0
  20. package/dist/builders/workflow-connection-nodes.d.ts +13 -3
  21. package/dist/builders/workflow-connection-nodes.js +129 -3
  22. package/dist/builders/workflow-connections.js +2 -1
  23. package/dist/builders/workflow-hydrator.d.ts +24 -1
  24. package/dist/builders/workflow-hydrator.js +8 -167
  25. package/dist/builders/workflow-mcp-servers.d.ts +44 -0
  26. package/dist/builders/workflow-mcp-servers.js +327 -0
  27. package/dist/builders/workflow-tool-entries.d.ts +84 -0
  28. package/dist/builders/workflow-tool-entries.js +216 -0
  29. package/dist/connections/durability.d.ts +11 -1
  30. package/dist/connections/durability.js +34 -0
  31. package/dist/connections/entries.d.ts +33 -0
  32. package/dist/connections/entries.js +118 -0
  33. package/dist/connections/errors.d.ts +6 -0
  34. package/dist/connections/errors.js +12 -0
  35. package/dist/connections/harness-wiring.d.ts +4 -4
  36. package/dist/connections/harness-wiring.js +1 -1
  37. package/dist/connections/in-memory-connection.d.ts +2 -0
  38. package/dist/connections/in-memory-connection.js +5 -0
  39. package/dist/connections/model-tools.d.ts +35 -12
  40. package/dist/connections/model-tools.js +348 -202
  41. package/dist/connections/registry-types.d.ts +7 -0
  42. package/dist/connections/registry.d.ts +35 -6
  43. package/dist/connections/registry.js +183 -39
  44. package/dist/connections/step-tools.d.ts +64 -0
  45. package/dist/connections/step-tools.js +154 -0
  46. package/dist/connections/views.d.ts +3 -2
  47. package/dist/connections/views.js +15 -6
  48. package/dist/harness/agent-harness.d.ts +11 -1
  49. package/dist/harness/agent-harness.js +69 -8
  50. package/dist/harness/connection-gate.d.ts +49 -8
  51. package/dist/harness/connection-gate.js +137 -26
  52. package/dist/harness/deps/interpreter.d.ts +3 -3
  53. package/dist/harness/deps/interpreter.js +3 -3
  54. package/dist/harness/harness-options.d.ts +4 -3
  55. package/dist/harness/model-request.js +3 -1
  56. package/dist/harness/model-schema.d.ts +1 -19
  57. package/dist/harness/model-schema.js +0 -28
  58. package/dist/harness/model-tool-round.js +2 -2
  59. package/dist/index.d.ts +5 -5
  60. package/dist/index.js +1 -1
  61. package/dist/interpreter/acp-events.d.ts +25 -1
  62. package/dist/interpreter/acp-events.js +53 -1
  63. package/dist/interpreter/acp-layers.d.ts +20 -0
  64. package/dist/interpreter/acp-layers.js +55 -0
  65. package/dist/interpreter/acp-tools.d.ts +108 -0
  66. package/dist/interpreter/acp-tools.js +462 -0
  67. package/dist/interpreter/collect-tools.d.ts +28 -0
  68. package/dist/interpreter/collect-tools.js +112 -15
  69. package/dist/interpreter/connection-steps.d.ts +0 -2
  70. package/dist/interpreter/connection-steps.js +30 -8
  71. package/dist/interpreter/execute-acp-agent.js +263 -72
  72. package/dist/interpreter/execute-action.d.ts +76 -1
  73. package/dist/interpreter/execute-action.js +35 -42
  74. package/dist/interpreter/execute.d.ts +2 -0
  75. package/dist/interpreter/execute.js +24 -1
  76. package/dist/interpreter/verify-host.js +2 -1
  77. package/dist/runtime/tool-call.d.ts +67 -0
  78. package/dist/runtime/tool-call.js +244 -0
  79. package/dist/runtime/tool-context.d.ts +1 -2
  80. package/dist/runtime/tool-context.js +6 -2
  81. package/dist/schemas/workflow.d.ts +1 -1
  82. package/dist/types/connection-entry.d.ts +22 -0
  83. package/dist/types/connection-entry.js +8 -0
  84. package/dist/util/harness-internals.d.ts +2 -0
  85. package/dist/util/root-context.d.ts +3 -0
  86. package/dist/util/root-context.js +8 -0
  87. package/dist/util/tool-name.d.ts +8 -0
  88. package/dist/util/tool-name.js +10 -0
  89. package/package.json +3 -3
  90. package/schema/noetic-workflow.schema.json +498 -128
@@ -72,6 +72,12 @@ async function readOne(runtime, request) {
72
72
  try {
73
73
  const resolved = await runtime.resolve({
74
74
  name: request.name,
75
+ caller: 'model',
76
+ ...(request.rootId === undefined
77
+ ? {}
78
+ : {
79
+ rootId: request.rootId,
80
+ }),
75
81
  scope: {
76
82
  executionId: request.ctx.executionId,
77
83
  threadId: request.ctx.threadId,
@@ -92,9 +98,10 @@ async function readOne(runtime, request) {
92
98
  //#region Public API
93
99
  /**
94
100
  * The view layer for one connection. It renders nothing while the connection
95
- * is not ready or has no `'turn'`/`'effect'` reads.
101
+ * is not ready or has no `'turn'`/`'effect'` reads. For a connection a turn
102
+ * attaches, `rootOf` names the turn once its context exists.
96
103
  */
97
- export function connectionViewLayer(runtime, name) {
104
+ export function connectionViewLayer(runtime, name, rootOf = () => undefined) {
98
105
  return {
99
106
  id: `noetic/connection-view/${name}`,
100
107
  name: `connection view: ${name}`,
@@ -111,15 +118,16 @@ export function connectionViewLayer(runtime, name) {
111
118
  },
112
119
  async recall({ state, budget, ctx }) {
113
120
  const current = state ?? EMPTY_STATE;
114
- const manifest = runtime.current(name)?.manifest;
121
+ const rootId = rootOf();
122
+ const manifest = runtime.current(name, rootId)?.manifest;
115
123
  if (!manifest) {
116
124
  return null;
117
125
  }
118
- const effects = runtime.effectCount(name);
126
+ const effects = runtime.effectCount(name, rootId);
119
127
  const effectsChanged = effects !== current.effects;
120
128
  const rendered = [];
121
129
  for (const resource of Object.values(manifest.resources)) {
122
- const mode = modeOf(runtime.config(name)?.look, resource.name, resource.look);
130
+ const mode = modeOf(runtime.config(name, rootId)?.look, resource.name, resource.look);
123
131
  const previous = current.previous[resource.name];
124
132
  if (!wantsRead(mode, effectsChanged, effects)) {
125
133
  continue;
@@ -128,6 +136,7 @@ export function connectionViewLayer(runtime, name) {
128
136
  name,
129
137
  read: resource.name,
130
138
  ctx,
139
+ rootId,
131
140
  });
132
141
  ctx.trace.addEvent('connection.read', {
133
142
  connection: name,
@@ -170,7 +179,7 @@ export function connectionViewLayer(runtime, name) {
170
179
  export function connectionViewLayers(runtime) {
171
180
  return runtime
172
181
  .names()
173
- .filter((name) => !runtime.config(name)?.pool)
182
+ .filter((name) => runtime.viewed(name))
174
183
  .map((name) => connectionViewLayer(runtime, name));
175
184
  }
176
185
  //#endregion
@@ -208,9 +208,17 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
208
208
  /**
209
209
  * Everything `run()` does before the root executes: fail fast on a missing
210
210
  * model provider, connect, negotiate the root, wire the tool pool and run the
211
- * layers' `init` hooks.
211
+ * layers' `init` hooks. Returns what puts the tool pool back when the run
212
+ * attached connections into a pool it found already built.
212
213
  */
213
214
  private prepareRun;
215
+ /**
216
+ * Attaches the entries a graph built mid-turn lists (a JSON document a step
217
+ * hydrates) and adds their tools to `ctx`'s pool for this run only, so the
218
+ * rest of the turn keeps the tool set — and the prompt cache — it started
219
+ * with. Returns what restores the pool.
220
+ */
221
+ private attachGraphTools;
214
222
  /**
215
223
  * Runs `prepare`, ending any rerun allowance `ctx` carries from its restore
216
224
  * when it throws: a run that fails before executing still ends the restore's
@@ -291,6 +299,8 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
291
299
  * isolation to root a child agent at the worktree path.
292
300
  */
293
301
  cwdInit?: string;
302
+ /** View layers for the connections the turn attaches, after the harness's own. */
303
+ _connectionViews?: ContextLayer[];
294
304
  _broadcaster?: EventBroadcaster;
295
305
  }): Context;
296
306
  send<T>(channel: Channel<T>, value: NoInfer<T>, ctx: Context): Promise<void>;
@@ -4,7 +4,7 @@ import { runEvery } from '../connections/settle.js';
4
4
  import { AcpSessionStore } from '../runtime/acp-session-store.js';
5
5
  import { ConnectionGate } from './connection-gate.js';
6
6
  import { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, initLayers, notifyDecision, onSteerLayers, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from './deps/context.js';
7
- import { clearPendingEntries, collectAllTools, collectCustomItems, deduplicateTools, dispatchStepThroughAdapter, execute, prepareBandedView, } from './deps/interpreter.js';
7
+ import { clearPendingEntries, collectAllTools, collectCustomItems, deduplicateTools, dispatchStepThroughAdapter, execute, isRootRunning, prepareBandedView, runRootOf, } from './deps/interpreter.js';
8
8
  import { buildItemStream, ChannelStore, ContextImpl, captureCheckpoint, clearCheckpoint, collectContextTree, createInMemoryStorage, createSessionStore, createSpendLog, createStepLedgerStore, customItemGates, Drains, filterReasoningStream, filterTextStream, INTERRUPT_REASON, isSteer, resolveStepLedgerRetention, restoreFromCheckpoint, rootIdOf, SessionRunner, StepLedger, snapshotCwdState, } from './deps/runtime.js';
9
9
  import { SteeringAction } from './deps/types.js';
10
10
  import { resolveCheckpointStore, resolveEnvironmentAdapters } from './harness-options.js';
@@ -525,6 +525,8 @@ export class AgentHarness {
525
525
  const perTurnOptions = messages[0]?.options ?? {};
526
526
  const messageIds = messages.map((m) => m.id);
527
527
  const history = record ? await record.history() : session.accumulatedItems;
528
+ const graph = this.agentGraph ? frameworkCast(this.agentGraph) : undefined;
529
+ const views = this.#connections.turnViews(perTurnOptions.connections, graph);
528
530
  // A re-delivery of a cut-off turn's messages picks that turn up where it died.
529
531
  const resumed = await record?.resume(messageIds, {
530
532
  state: perTurnOptions.state,
@@ -542,11 +544,16 @@ export class AgentHarness {
542
544
  state: perTurnOptions.state,
543
545
  contextLayers: perTurnOptions.contextLayers,
544
546
  extraContextLayers: perTurnOptions.extraContextLayers,
547
+ _connectionViews: views.layers,
545
548
  _broadcaster: session.runner.broadcaster,
546
549
  });
550
+ // A resumed context was made without the turn's view layers.
551
+ if (!resumed) {
552
+ views.bind(ctx);
553
+ }
547
554
  frameworkCast(ctx)._sessionQueue = session.runner.queue;
548
555
  await this.start();
549
- const connectionTools = this.#connections.tools();
556
+ const connectionTools = await this.#connections.openTurn(ctx, perTurnOptions.connections, graph);
550
557
  if (this.agentGraph || this.harnessTools.length > 0 || connectionTools.length > 0) {
551
558
  const stepTools = this.agentGraph ? collectAllTools(this.agentGraph) : [];
552
559
  this.setUnifiedTools(ctx, [
@@ -568,6 +575,7 @@ export class AgentHarness {
568
575
  },
569
576
  runTurn: async (ctx, _turn, signal) => {
570
577
  if (!this.agentGraph) {
578
+ await this.#connections.release(ctx.id);
571
579
  throw new NoeticConfigError({
572
580
  code: 'NO_STEP_CONFIGURED',
573
581
  message: 'No agentGraph configured on this harness.',
@@ -657,13 +665,29 @@ export class AgentHarness {
657
665
  }
658
666
  async run(s, input, ctx) {
659
667
  const root = toStep(s);
660
- await this.dropRerunsOnFailure(ctx, () => this.prepareRun(root, ctx));
661
- return this.executeClosingChannels(root, input, ctx);
668
+ // Called from inside a step that a bare `execute()` is running on this
669
+ // root (a tool running a step on `toolCtx.ctx`): join that run. Treating
670
+ // the context as a fresh root would initialize its layers mid-run and, on
671
+ // return, close its channels and ACP sessions under the outer step.
672
+ if (ctx.parent === null && !this.liveRoots.has(ctx.id) && isRootRunning(ctx)) {
673
+ return execute(root, input, ctx);
674
+ }
675
+ let restore;
676
+ await this.dropRerunsOnFailure(ctx, async () => {
677
+ restore = await this.prepareRun(root, ctx);
678
+ });
679
+ try {
680
+ return await this.executeClosingChannels(root, input, ctx);
681
+ }
682
+ finally {
683
+ restore?.();
684
+ }
662
685
  }
663
686
  /**
664
687
  * Everything `run()` does before the root executes: fail fast on a missing
665
688
  * model provider, connect, negotiate the root, wire the tool pool and run the
666
- * layers' `init` hooks.
689
+ * layers' `init` hooks. Returns what puts the tool pool back when the run
690
+ * attached connections into a pool it found already built.
667
691
  */
668
692
  async prepareRun(root, ctx) {
669
693
  const missingModel = this.llm.missingModelFor(root);
@@ -677,16 +701,45 @@ export class AgentHarness {
677
701
  await this.start();
678
702
  this.#connections.negotiateRoot(frameworkCast(root));
679
703
  if (!ctx.unifiedTools) {
704
+ // A root run is its own turn: it attaches the entries its steps list.
705
+ const connectionTools = ctx.parent === null
706
+ ? await this.#connections.openTurn(ctx, undefined, frameworkCast(root))
707
+ : this.#connections.tools(runRootOf(ctx).id);
680
708
  this.setUnifiedTools(ctx, [
681
709
  ...collectAllTools(root),
682
710
  ...this.harnessTools,
683
- ...this.#connections.tools(),
711
+ ...connectionTools,
684
712
  ]);
685
713
  }
714
+ const restore = ctx.unifiedTools
715
+ ? await this.attachGraphTools(frameworkCast(root), ctx)
716
+ : undefined;
686
717
  // Hydrate/recall/persist context on the bare `run()` path too (issue #48):
687
718
  // configuring `context` + `storage` must "just work" without going through
688
719
  // `execute()`/`seedSessionHistory`. Idempotent — see `ensureLayersInit`.
689
720
  await this.ensureLayersInit(ctx);
721
+ return restore;
722
+ }
723
+ /**
724
+ * Attaches the entries a graph built mid-turn lists (a JSON document a step
725
+ * hydrates) and adds their tools to `ctx`'s pool for this run only, so the
726
+ * rest of the turn keeps the tool set — and the prompt cache — it started
727
+ * with. Returns what restores the pool.
728
+ */
729
+ async attachGraphTools(root, ctx) {
730
+ const tools = await this.#connections.attachGraph(runRootOf(ctx), root);
731
+ if (!tools) {
732
+ return undefined;
733
+ }
734
+ const pool = frameworkCast(ctx);
735
+ const before = pool.unifiedTools;
736
+ pool.unifiedTools = deduplicateTools([
737
+ ...(before ?? []),
738
+ ...tools,
739
+ ]);
740
+ return () => {
741
+ pool.unifiedTools = before;
742
+ };
690
743
  }
691
744
  /**
692
745
  * Runs `prepare`, ending any rerun allowance `ctx` carries from its restore
@@ -699,6 +752,9 @@ export class AgentHarness {
699
752
  }
700
753
  catch (error) {
701
754
  this.#connections.dropReruns(ctx);
755
+ if (ctx.parent === null && !this.liveRoots.has(ctx.id)) {
756
+ await this.#connections.release(ctx.id);
757
+ }
702
758
  throw error;
703
759
  }
704
760
  }
@@ -761,6 +817,8 @@ export class AgentHarness {
761
817
  await this.#connections.releaseRun(ctx.id);
762
818
  await this.endDurableRun(ctx);
763
819
  }
820
+ // The turn's own connections end with it; a resume attaches them again.
821
+ await this.#connections.release(ctx.id);
764
822
  }
765
823
  }
766
824
  }
@@ -869,9 +927,12 @@ export class AgentHarness {
869
927
  const resolved = opts ?? {};
870
928
  // `ContextImpl` takes the layers as `layers`, so the option spelling is
871
929
  // dropped from `rest` rather than spread through under the wrong name.
872
- const { contextLayers, extraContextLayers, cwdInit, ...rest } = resolved;
930
+ const { contextLayers, extraContextLayers, cwdInit, _connectionViews, ...rest } = resolved;
873
931
  const configuredLayers = contextLayers ?? this._contextLayers;
874
- const views = this.#connections.views;
932
+ const views = [
933
+ ...this.#connections.views,
934
+ ...(_connectionViews ?? []),
935
+ ];
875
936
  const baseLayers = views.length > 0
876
937
  ? [
877
938
  ...(configuredLayers ?? []),
@@ -1,4 +1,4 @@
1
- import type { ConnectionStatus } from '@noetic-tools/types';
1
+ import type { ConnectionEntries, ConnectionStatus } from '@noetic-tools/types';
2
2
  import type { HarnessConnectionsOptions } from '../connections/harness-wiring.js';
3
3
  import type { ConnectionRuntime } from '../connections/registry.js';
4
4
  import type { Context, ContextLayer, Step, StorageAdapter, Tool } from './deps/types.js';
@@ -11,19 +11,58 @@ import type { Context, ContextLayer, Step, StorageAdapter, Tool } from './deps/t
11
11
  export declare class ConnectionGate {
12
12
  #private;
13
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.
14
+ * Wires the harness's connections and triggers, and records the registry and
15
+ * `verifier` as the harness's private internals, where steps and tools find
16
+ * them without anything public on the harness. A harness with no connections
17
+ * still has a registry, for the ones its turns and steps attach.
17
18
  */
18
19
  constructor(options: HarnessConnectionsOptions & {
19
20
  readonly verifier?: unknown;
20
21
  });
21
- /** The connection registry, absent on a harness without connections or triggers. */
22
- get registry(): ConnectionRuntime | undefined;
22
+ /** The connection registry. */
23
+ get registry(): ConnectionRuntime;
23
24
  /** One view layer per non-pool connection. */
24
25
  get views(): ReadonlyArray<ContextLayer>;
25
- /** This turn's connection tools. */
26
- tools(): Tool[];
26
+ /** The connection tools of the turn rooted at `rootId`, or the harness's alone. */
27
+ tools(rootId?: string): Tool[];
28
+ /**
29
+ * Starts a turn's connections: attaches the turn's own `connections` and
30
+ * every entry `graph`'s model steps list, connects them, and returns the
31
+ * turn's connection tools, checking each forced `toolChoice` against them.
32
+ * What it attached is released by `release(root.id)`, and at once when it
33
+ * throws.
34
+ *
35
+ * @throws NoeticConfigError `CONNECTION_INVALID`, `CONNECTION_NAME_TAKEN`,
36
+ * `CONNECTION_TOOL_COLLISION`, `CONNECTION_UNKNOWN` (a pick naming no
37
+ * connection) or `UNKNOWN_TOOL_CHOICE`.
38
+ */
39
+ openTurn(root: Context, connections: ConnectionEntries | undefined, graph: Step | undefined): Promise<Tool[]>;
40
+ /**
41
+ * Attaches the entries a graph built during a turn lists — a JSON document a
42
+ * step hydrates, with the connections it declares — which the walk at the
43
+ * turn's start could not see. They
44
+ * join the turn's attachment and are released with it. Returns the turn's
45
+ * connection tools, or undefined when the graph lists no entries.
46
+ *
47
+ * @throws NoeticConfigError `CONNECTION_INVALID`, `CONNECTION_NAME_TAKEN`,
48
+ * `CONNECTION_TOOL_COLLISION`, `CONNECTION_UNKNOWN` (a pick naming no
49
+ * connection) or `UNKNOWN_TOOL_CHOICE`.
50
+ */
51
+ attachGraph(root: Context, graph: Step): Promise<Tool[] | undefined>;
52
+ /** Releases what the turn rooted at `rootId` attached, once nothing holds it. */
53
+ release(rootId: string): Promise<void>;
54
+ /**
55
+ * View layers for the connections a turn will attach, made before its
56
+ * context exists so they sit where a harness entry's would. `bind(root)`
57
+ * names the turn once its context is made.
58
+ *
59
+ * @throws NoeticConfigError `CONNECTION_INVALID` or `CONNECTION_NAME_TAKEN`
60
+ * for a malformed `connections` option.
61
+ */
62
+ turnViews(connections: ConnectionEntries | undefined, graph: Step | undefined): {
63
+ readonly layers: ContextLayer[];
64
+ bind(root: Context): void;
65
+ };
27
66
  /** Connects providers and starts triggers. Idempotent. */
28
67
  start(): Promise<void>;
29
68
  /** Each connection's state, identity and pool usage; one entry for `name`, or all. */
@@ -75,4 +114,6 @@ export declare class ConnectionGate {
75
114
  orphanRun(executionId: string): void;
76
115
  /** Releases a finished root run's connections and pool leases. */
77
116
  releaseRun(executionId: string): Promise<void>;
117
+ /** A turn's own entries, then the ones its graph's steps list. */
118
+ private turnEntries;
78
119
  }
@@ -1,6 +1,8 @@
1
+ import { namedEntries } from '../connections/entries.js';
1
2
  import { createHarnessConnections } from '../connections/harness-wiring.js';
3
+ import { connectionViewLayer } from '../connections/views.js';
2
4
  import { setHarnessInternals } from '../util/harness-internals.js';
3
- import { graphConnectionNeeds, reconcileResumedConnections } from './deps/interpreter.js';
5
+ import { checkPickNames, checkToolChoices, collectStepEntries, graphConnectionNeeds, reconcileResumedConnections, } from './deps/interpreter.js';
4
6
  import { ContextImpl } from './deps/runtime.js';
5
7
  /**
6
8
  * A harness's connections, as the harness drives them: providers and triggers,
@@ -19,43 +21,132 @@ export class ConnectionGate {
19
21
  * them (spec 35 § Durability).
20
22
  */
21
23
  #reruns = new WeakMap();
24
+ /** The attached names each turn's context has a view layer for, by root id. */
25
+ #viewed = new Map();
22
26
  /**
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.
27
+ * Wires the harness's connections and triggers, and records the registry and
28
+ * `verifier` as the harness's private internals, where steps and tools find
29
+ * them without anything public on the harness. A harness with no connections
30
+ * still has a registry, for the ones its turns and steps attach.
26
31
  */
27
32
  constructor(options) {
28
- if (options.connections || (options.triggers && options.triggers.length > 0)) {
29
- this.#connections = createHarnessConnections(options);
30
- }
33
+ this.#connections = createHarnessConnections(options);
31
34
  setHarnessInternals(options.harness, {
32
- connectionRegistry: this.#connections?.registry,
35
+ connectionRegistry: this.#connections.registry,
33
36
  verifier: options.verifier,
37
+ secrets: options.secrets,
34
38
  });
35
39
  }
36
- /** The connection registry, absent on a harness without connections or triggers. */
40
+ /** The connection registry. */
37
41
  get registry() {
38
- return this.#connections?.registry;
42
+ return this.#connections.registry;
39
43
  }
40
44
  /** One view layer per non-pool connection. */
41
45
  get views() {
42
- return this.#connections?.views ?? [];
46
+ return this.#connections.views;
47
+ }
48
+ /** The connection tools of the turn rooted at `rootId`, or the harness's alone. */
49
+ tools(rootId) {
50
+ return this.#connections.tools(rootId);
51
+ }
52
+ /**
53
+ * Starts a turn's connections: attaches the turn's own `connections` and
54
+ * every entry `graph`'s model steps list, connects them, and returns the
55
+ * turn's connection tools, checking each forced `toolChoice` against them.
56
+ * What it attached is released by `release(root.id)`, and at once when it
57
+ * throws.
58
+ *
59
+ * @throws NoeticConfigError `CONNECTION_INVALID`, `CONNECTION_NAME_TAKEN`,
60
+ * `CONNECTION_TOOL_COLLISION`, `CONNECTION_UNKNOWN` (a pick naming no
61
+ * connection) or `UNKNOWN_TOOL_CHOICE`.
62
+ */
63
+ async openTurn(root, connections, graph) {
64
+ const viewed = this.#viewed.get(root.id);
65
+ const entries = this.turnEntries(connections, graph).map((entry) => ({
66
+ ...entry,
67
+ viewed: viewed?.has(entry.name) === true,
68
+ }));
69
+ try {
70
+ await this.#connections.registry.attach(root, entries);
71
+ const tools = this.#connections.tools(root.id);
72
+ if (graph) {
73
+ checkGraph(graph, tools, {
74
+ runtime: this.#connections.registry,
75
+ rootId: root.id,
76
+ });
77
+ }
78
+ return tools;
79
+ }
80
+ catch (error) {
81
+ await this.release(root.id);
82
+ throw error;
83
+ }
84
+ }
85
+ /**
86
+ * Attaches the entries a graph built during a turn lists — a JSON document a
87
+ * step hydrates, with the connections it declares — which the walk at the
88
+ * turn's start could not see. They
89
+ * join the turn's attachment and are released with it. Returns the turn's
90
+ * connection tools, or undefined when the graph lists no entries.
91
+ *
92
+ * @throws NoeticConfigError `CONNECTION_INVALID`, `CONNECTION_NAME_TAKEN`,
93
+ * `CONNECTION_TOOL_COLLISION`, `CONNECTION_UNKNOWN` (a pick naming no
94
+ * connection) or `UNKNOWN_TOOL_CHOICE`.
95
+ */
96
+ async attachGraph(root, graph) {
97
+ const entries = collectStepEntries(graph);
98
+ const registry = this.#connections.registry;
99
+ if (entries.length > 0) {
100
+ await registry.attach(root, entries);
101
+ }
102
+ const tools = this.#connections.tools(root.id);
103
+ checkGraph(graph, tools, {
104
+ runtime: registry,
105
+ rootId: root.id,
106
+ });
107
+ return entries.length > 0 ? tools : undefined;
43
108
  }
44
- /** This turn's connection tools. */
45
- tools() {
46
- return this.#connections?.tools() ?? [];
109
+ /** Releases what the turn rooted at `rootId` attached, once nothing holds it. */
110
+ async release(rootId) {
111
+ this.#viewed.delete(rootId);
112
+ await this.#connections.registry.detach(rootId);
113
+ }
114
+ /**
115
+ * View layers for the connections a turn will attach, made before its
116
+ * context exists so they sit where a harness entry's would. `bind(root)`
117
+ * names the turn once its context is made.
118
+ *
119
+ * @throws NoeticConfigError `CONNECTION_INVALID` or `CONNECTION_NAME_TAKEN`
120
+ * for a malformed `connections` option.
121
+ */
122
+ turnViews(connections, graph) {
123
+ const registry = this.#connections.registry;
124
+ const harness = new Set(registry.names());
125
+ const names = new Set(this.turnEntries(connections, graph)
126
+ .filter((entry) => !harness.has(entry.name) && entry.config.expose !== 'call')
127
+ .map((entry) => entry.name));
128
+ let rootId;
129
+ return {
130
+ layers: [
131
+ ...names,
132
+ ].map((name) => connectionViewLayer(registry, name, () => rootId)),
133
+ bind: (root) => {
134
+ rootId = root.id;
135
+ this.#viewed.set(root.id, names);
136
+ },
137
+ };
47
138
  }
48
139
  /** Connects providers and starts triggers. Idempotent. */
49
140
  async start() {
50
- await this.#connections?.start();
141
+ await this.#connections.start();
51
142
  }
52
143
  /** Each connection's state, identity and pool usage; one entry for `name`, or all. */
53
144
  status(name) {
54
- return this.#connections?.registry.status(name) ?? [];
145
+ return this.#connections.registry.status(name);
55
146
  }
56
147
  /** Stops triggers and releases every connection. */
57
148
  async close() {
58
- await this.#connections?.close();
149
+ await this.#connections.close();
59
150
  }
60
151
  /**
61
152
  * Registers what the agent graph's handles need: their profiles (ref kinds) and
@@ -64,8 +155,8 @@ export class ConnectionGate {
64
155
  * with `CONNECTION_UNKNOWN` when the step runs.
65
156
  */
66
157
  registerGraphNeeds(agentGraph) {
67
- const registry = this.#connections?.registry;
68
- if (!registry || !agentGraph) {
158
+ const registry = this.#connections.registry;
159
+ if (!agentGraph) {
69
160
  return;
70
161
  }
71
162
  this.#negotiatedRoots.add(agentGraph);
@@ -93,8 +184,8 @@ export class ConnectionGate {
93
184
  * @throws `NoeticConfigError` `CONNECTION_UNSATISFIED` when a connection falls short.
94
185
  */
95
186
  negotiateRoot(root) {
96
- const registry = this.#connections?.registry;
97
- if (!registry || this.#negotiatedRoots.has(root)) {
187
+ const registry = this.#connections.registry;
188
+ if (this.#negotiatedRoots.has(root)) {
98
189
  return;
99
190
  }
100
191
  const known = new Set(registry.names());
@@ -132,7 +223,7 @@ export class ConnectionGate {
132
223
  return;
133
224
  }
134
225
  this.#reruns.delete(ctx);
135
- this.#connections?.registry.allowRerun(ctx.id, rerun);
226
+ this.#connections.registry.allowRerun(ctx.id, rerun);
136
227
  }
137
228
  /**
138
229
  * Before a resumed run replays anything, checks the connections its ledger and
@@ -142,8 +233,11 @@ export class ConnectionGate {
142
233
  * @throws NoeticErrorImpl `connection_resume_refused` when a replaced connection is unsafe to drive again.
143
234
  */
144
235
  async reconcile(ctx, storage) {
145
- const registry = this.#connections?.registry;
146
- if (!registry || !(ctx instanceof ContextImpl) || !ctx.ledger) {
236
+ const registry = this.#connections.registry;
237
+ // A run with no connections has none to check.
238
+ if (!(ctx instanceof ContextImpl) ||
239
+ !ctx.ledger ||
240
+ registry.visibleNames(ctx.id).length === 0) {
147
241
  return;
148
242
  }
149
243
  await reconcileResumedConnections({
@@ -160,10 +254,27 @@ export class ConnectionGate {
160
254
  * leases); a finished run releases them.
161
255
  */
162
256
  orphanRun(executionId) {
163
- this.#connections?.registry.orphanRun?.(executionId);
257
+ this.#connections.registry.orphanRun(executionId);
164
258
  }
165
259
  /** Releases a finished root run's connections and pool leases. */
166
260
  async releaseRun(executionId) {
167
- await this.#connections?.registry.releaseRun(executionId);
261
+ await this.#connections.registry.releaseRun(executionId);
168
262
  }
263
+ /** A turn's own entries, then the ones its graph's steps list. */
264
+ turnEntries(connections, graph) {
265
+ const where = 'execute() connections';
266
+ return [
267
+ ...namedEntries(connections, where).map((entry) => ({
268
+ ...entry,
269
+ scope: 'turn',
270
+ where,
271
+ })),
272
+ ...(graph ? collectStepEntries(graph) : []),
273
+ ];
274
+ }
275
+ }
276
+ /** Checks a graph against the turn's attached connections: each pick's name, then each forced tool. */
277
+ function checkGraph(graph, tools, turn) {
278
+ checkPickNames(graph, turn);
279
+ checkToolChoices(graph, tools, turn);
169
280
  }
@@ -1,8 +1,8 @@
1
- export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
2
- export { clearPendingEntries, graphConnectionNeeds, reconcileResumedConnections, } from '../../interpreter/connection-steps.js';
1
+ export { checkPickNames, checkToolChoices, collectAllTools, collectStepEntries, deduplicateTools, } from '../../interpreter/collect-tools.js';
2
+ export { clearPendingEntries, graphConnectionNeeds, reconcileResumedConnections, runRootOf, } from '../../interpreter/connection-steps.js';
3
3
  export { prepareBandedView } from '../../interpreter/context-assembly.js';
4
4
  export { collectCustomItems } from '../../interpreter/emit-items.js';
5
- export { execute } from '../../interpreter/execute.js';
5
+ export { execute, isRootRunning } from '../../interpreter/execute.js';
6
6
  export type { DetachedSpawnOverrides } from '../../interpreter/step-dispatcher.js';
7
7
  export { dispatchStepThroughAdapter } from '../../interpreter/step-dispatcher.js';
8
8
  export { someStep } from '../../interpreter/step-walk.js';
@@ -1,8 +1,8 @@
1
- export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
2
- export { clearPendingEntries, graphConnectionNeeds, reconcileResumedConnections, } from '../../interpreter/connection-steps.js';
1
+ export { checkPickNames, checkToolChoices, collectAllTools, collectStepEntries, deduplicateTools, } from '../../interpreter/collect-tools.js';
2
+ export { clearPendingEntries, graphConnectionNeeds, reconcileResumedConnections, runRootOf, } from '../../interpreter/connection-steps.js';
3
3
  export { prepareBandedView } from '../../interpreter/context-assembly.js';
4
4
  export { collectCustomItems } from '../../interpreter/emit-items.js';
5
- export { execute } from '../../interpreter/execute.js';
5
+ export { execute, isRootRunning } from '../../interpreter/execute.js';
6
6
  export { dispatchStepThroughAdapter } from '../../interpreter/step-dispatcher.js';
7
7
  export { someStep } from '../../interpreter/step-walk.js';
8
8
  export { isFunctionCall } from '../../interpreter/typeguards.js';
@@ -1,4 +1,4 @@
1
- import type { ArtifactStore, ConnectionsConfig, ConnectionTrigger, SecretResolver } from '@noetic-tools/types';
1
+ import type { ArtifactStore, ConnectionEntries, ConnectionTrigger, SecretResolver } from '@noetic-tools/types';
2
2
  import type { Verifier } from '@noetic-tools/types/verify';
3
3
  import type { LayerStateStore } from './deps/context.js';
4
4
  import type { CheckpointStore, StepLedgerRetention } from './deps/runtime.js';
@@ -121,9 +121,10 @@ export interface AgentHarnessOpts<TParams extends Record<string, unknown> = Reco
121
121
  approveToolCall?: ToolApprover;
122
122
  /**
123
123
  * The live things the agent works with — browsers, devices, apps, chat workspaces,
124
- * sources — by name (spec 35). Providers connect in `start()`.
124
+ * sources — keyed by name, or as a list of named entries (`[mcp({ name, … })]`)
125
+ * (spec 35). Providers connect in `start()` and live as long as the harness.
125
126
  */
126
- connections?: ConnectionsConfig;
127
+ connections?: ConnectionEntries;
127
128
  /** Connection events that start or join a turn (spec 35 § Triggers). */
128
129
  triggers?: ReadonlyArray<ConnectionTrigger>;
129
130
  /** The verifier `step.verify` uses (spec 37). */
@@ -1,7 +1,9 @@
1
1
  import { frameworkCast, NoeticConfigError, ToolChoiceMode } from '@noetic-tools/types';
2
2
  import { serverTool } from '@openrouter/agent';
3
- import { convertTools, extractSystemInstruction, resolveWireJsonSchema, sanitizeToolNameForWire, } from '../adapters/openrouter.js';
3
+ import { convertTools, extractSystemInstruction } from '../adapters/openrouter.js';
4
4
  import { emitFrameworkEvent, getBroadcaster, shouldEmit } from '../runtime/broadcaster-utils.js';
5
+ import { resolveWireJsonSchema } from '../runtime/tool-call.js';
6
+ import { sanitizeToolNameForWire } from '../util/tool-name.js';
5
7
  /**
6
8
  * Shapes a `callModel` request for the wire: system instructions, the SDK tool
7
9
  * list, the per-round tool choice, and the structured-output text format.
@@ -1,25 +1,7 @@
1
1
  import type { ContextLayer } from '@noetic-tools/context';
2
- import type { Item, ItemSchemaRegistry, Tool } from '@noetic-tools/types';
2
+ import type { ItemSchemaRegistry, Tool } from '@noetic-tools/types';
3
3
  export declare function buildItemSchemaRegistry({ base, layers, tools, }: {
4
4
  base: ItemSchemaRegistry;
5
5
  layers?: ReadonlyArray<ContextLayer>;
6
6
  tools?: ReadonlyArray<Tool>;
7
7
  }): ItemSchemaRegistry;
8
- /**
9
- * Build and validate a `function_call_output` item for a tool result.
10
- *
11
- * `roundItemSchemas` must be the OWNER-SCOPED registry for the called tool
12
- * (harness base extended with only that tool's `itemSchemas`), so one tool's
13
- * `toolResults` schemas never reject a sibling tool's result items. Tools
14
- * without `itemSchemas` fall back to the base structural parse.
15
- */
16
- export declare function createToolResultItem({ output, callId, roundItemSchemas, tool, callItem, args, result, error, }: {
17
- output: string;
18
- callId: string;
19
- roundItemSchemas: ItemSchemaRegistry;
20
- tool?: Tool;
21
- callItem?: Item;
22
- args?: unknown;
23
- result?: unknown;
24
- error?: boolean;
25
- }): Item;