@nylorun/harness 0.26.0-beta → 0.27.1-beta

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 (37) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/HOST_CONTRACT.md +13 -11
  3. package/README.md +11 -12
  4. package/dist/api/harness.d.ts +1 -1
  5. package/dist/api/harness.js +2 -2
  6. package/dist/definition/agent-definition.d.ts +2 -2
  7. package/dist/definition/agent-definition.js +2 -2
  8. package/dist/definition/registry.d.ts +3 -3
  9. package/dist/definition/registry.js +12 -15
  10. package/dist/loop/compaction/index.d.ts +4 -2
  11. package/dist/loop/compaction/index.js +78 -8
  12. package/dist/loop/dispatch.js +1 -1
  13. package/dist/loop/model/project.d.ts +6 -0
  14. package/dist/loop/model/project.js +59 -18
  15. package/dist/loop/run.js +2 -2
  16. package/dist/loop/state.js +0 -1
  17. package/dist/loop/step/canonicalize.d.ts +1 -3
  18. package/dist/loop/step/canonicalize.js +0 -15
  19. package/dist/loop/step/model-configuration.d.ts +4 -13
  20. package/dist/loop/step/model-configuration.js +12 -70
  21. package/dist/loop/step/resolve.js +0 -1
  22. package/dist/loop/step/run.js +33 -12
  23. package/dist/loop/step/runtime.d.ts +2 -2
  24. package/dist/loop/step/seal.js +0 -17
  25. package/dist/loop/step/slot-assembly.d.ts +5 -5
  26. package/dist/loop/step/slot-assembly.js +5 -5
  27. package/dist/loop/step/step-context.d.ts +5 -19
  28. package/dist/loop/step/step-context.js +9 -195
  29. package/dist/loop/transcript.js +7 -1
  30. package/dist/run/durable.d.ts +1 -3
  31. package/dist/run/durable.js +25 -27
  32. package/dist/types/execution.d.ts +0 -1
  33. package/package.json +2 -2
  34. package/dist/loop/step/compose.d.ts +0 -5
  35. package/dist/loop/step/compose.js +0 -109
  36. package/dist/loop/step/context-draft.d.ts +0 -8
  37. package/dist/loop/step/context-draft.js +0 -48
@@ -1,11 +1,29 @@
1
- import { copyJson, freezeGraph } from "@nylorun/core/define";
1
+ import { copyJson, freezeGraph, mediaReferenceLine, mediaReferenceOf } from "@nylorun/core/define";
2
2
  import { summaryPrompt } from "../compaction/index.js";
3
+ /**
4
+ * The model call for `request`. Every file in the transcript is its reference line (protocol 12),
5
+ * so a message projects the same in every later call. The files of the turn in progress (its
6
+ * messages, tool results and `read_artifact` loads) also go once, as media, in one user message
7
+ * after the conversation and the context: their bytes reach the model only in their own turn.
8
+ */
3
9
  export function projectModelCall(request) {
10
+ const live = new Map();
11
+ const collect = (entry, line, part) => {
12
+ if (entry.turnId !== request.turnId)
13
+ return;
14
+ const reference = mediaReferenceOf(part.reference);
15
+ const key = reference
16
+ ? `${reference.artifactId}@${reference.version}`
17
+ : JSON.stringify(part.reference);
18
+ if (!live.has(key))
19
+ live.set(key, { line, part });
20
+ };
4
21
  return freezeGraph({
5
22
  prompt: Object.freeze([
6
23
  ...projectInstructions(request.instructions),
7
- ...request.transcript.flatMap((entry) => projectEntry(entry, request.turnId)),
24
+ ...request.transcript.flatMap((entry) => projectEntry(entry, request.turnId, collect)),
8
25
  ...projectContext(request.context),
26
+ ...projectFiles([...live.values()]),
9
27
  ]),
10
28
  tools: Object.freeze(request.configuration.tools.map((tool) => Object.freeze({
11
29
  name: tool.name,
@@ -43,7 +61,29 @@ function renderContext(items) {
43
61
  "</runtime-context>",
44
62
  ].join("\n");
45
63
  }
46
- function projectEntry(entry, turnId) {
64
+ /** The files of the turn in progress, each labelled with its reference line. */
65
+ function projectFiles(files) {
66
+ if (files.length === 0)
67
+ return [];
68
+ return [
69
+ freezeItem({
70
+ kind: "message",
71
+ role: "user",
72
+ content: [
73
+ textPart("Files for this turn:"),
74
+ ...files.flatMap(({ line, part }) => [
75
+ textPart(line),
76
+ Object.freeze({
77
+ type: "media",
78
+ mediaType: part.mediaType,
79
+ reference: copyJson(part.reference),
80
+ }),
81
+ ]),
82
+ ],
83
+ }),
84
+ ];
85
+ }
86
+ function projectEntry(entry, turnId, collect) {
47
87
  if (entry.kind === "input") {
48
88
  if (entry.event.kind !== "user-message" && entry.event.kind !== "interrupt")
49
89
  return [];
@@ -52,13 +92,13 @@ function projectEntry(entry, turnId) {
52
92
  kind: "message",
53
93
  role: "user",
54
94
  content: "content" in entry.event
55
- ? entry.event.content.map((part) => part.type === "text"
56
- ? textPart(part.text)
57
- : Object.freeze({
58
- type: "media",
59
- mediaType: part.mediaType,
60
- reference: copyJson(part.reference),
61
- }))
95
+ ? entry.event.content.map((part) => {
96
+ if (part.type === "text")
97
+ return textPart(part.text);
98
+ const line = mediaReferenceLine(part, "uploaded");
99
+ collect(entry, line, part);
100
+ return textPart(line);
101
+ })
62
102
  : [textPart(entry.event.text)],
63
103
  }),
64
104
  ];
@@ -101,14 +141,14 @@ function projectEntry(entry, turnId) {
101
141
  ];
102
142
  }
103
143
  if (entry.kind === "tool-results")
104
- return entry.results.map(projectToolResult);
144
+ return entry.results.map((result) => projectToolResult(result, (line, part) => collect(entry, line, part)));
105
145
  if (entry.kind === "compaction")
106
146
  return [
107
147
  freezeItem({ kind: "message", role: "user", content: [textPart(summaryPrompt(entry))] }),
108
148
  ];
109
149
  return [];
110
150
  }
111
- function projectToolResult(result) {
151
+ function projectToolResult(result, collect) {
112
152
  return freezeItem({
113
153
  kind: "tool-result",
114
154
  toolCallId: result.callId,
@@ -116,13 +156,14 @@ function projectToolResult(result) {
116
156
  status: result.kind,
117
157
  content: [
118
158
  textPart(JSON.stringify(toolResultPayload(result))),
119
- // Images the tool returned, stored by the host (R2b C11): the model call resolves them.
159
+ // Files the tool returned, stored by the host (R2b C11): each is its reference line, and
160
+ // goes to the model in its own turn with the turn's files.
120
161
  ...(result.kind === "completed" && result.files
121
- ? result.files.map((file) => Object.freeze({
122
- type: "media",
123
- mediaType: file.mediaType,
124
- reference: copyJson(file.reference),
125
- }))
162
+ ? result.files.map((file) => {
163
+ const line = mediaReferenceLine(file, { tool: result.toolName });
164
+ collect(line, file);
165
+ return textPart(line);
166
+ })
126
167
  : []),
127
168
  ],
128
169
  });
package/dist/loop/run.js CHANGED
@@ -112,7 +112,7 @@ export async function execute(agent, options, internals = {}) {
112
112
  // Keep the next prompt inside the model's window, before it is sent.
113
113
  const budget = contextBudget(invocation.state.transcript);
114
114
  if (budget &&
115
- estimateTokens(invocation.state.transcript) > budget.contextWindow - budget.reserve)
115
+ estimateTokens(invocation.state.transcript, turnId) > budget.contextWindow - budget.reserve)
116
116
  await compactHistory("threshold", stepId);
117
117
  const snapshot = {
118
118
  id: invocation.state.executionId,
@@ -123,7 +123,7 @@ export async function execute(agent, options, internals = {}) {
123
123
  };
124
124
  const result = await runStep({
125
125
  agent: {
126
- middleware: agent.middleware,
126
+ parts: agent.parts,
127
127
  invoke: options.onModelCall,
128
128
  registry: agent.registry,
129
129
  sessionState: invocation.sessionBag,
@@ -36,7 +36,6 @@ const outcome = z.discriminatedUnion("kind", [
36
36
  ]);
37
37
  const reference = z
38
38
  .object({
39
- capabilityId: id,
40
39
  toolName: id,
41
40
  descriptor: z
42
41
  .object({
@@ -1,4 +1,4 @@
1
- import type { ModelCandidate, ModelOutputBlock, ModelToolCall } from "@nylorun/core/define";
1
+ import type { ModelCandidate, ModelOutputBlock } from "@nylorun/core/define";
2
2
  import type { JsonObject } from "@nylorun/core/define";
3
3
  export interface CanonicalCall {
4
4
  readonly id: string;
@@ -12,10 +12,8 @@ export declare function canonicalizeCalls(calls: readonly {
12
12
  readonly name?: string;
13
13
  readonly args: JsonObject;
14
14
  }[]): readonly CanonicalCall[];
15
- export declare function callsFromCanonical(calls: readonly CanonicalCall[]): readonly ModelToolCall[];
16
15
  export declare function canonicalizeOutput(output: readonly ModelOutputBlock[]): {
17
16
  readonly output: readonly ModelOutputBlock[];
18
17
  readonly calls: readonly CanonicalCall[];
19
18
  };
20
19
  export declare function candidateFromCanonical(candidate: ModelCandidate, output: readonly ModelOutputBlock[]): ModelCandidate;
21
- export declare function identityKey(name: string, args: unknown): string;
@@ -18,13 +18,6 @@ export function canonicalizeCalls(calls) {
18
18
  });
19
19
  }));
20
20
  }
21
- export function callsFromCanonical(calls) {
22
- return Object.freeze(calls.map((call) => Object.freeze({
23
- id: call.id,
24
- name: call.name,
25
- args: call.args,
26
- })));
27
- }
28
21
  export function canonicalizeOutput(output) {
29
22
  const calls = canonicalizeCalls(output.flatMap((block) => (block.type === "tool-call" ? [block] : [])));
30
23
  let index = 0;
@@ -55,11 +48,3 @@ export function candidateFromCanonical(candidate, output) {
55
48
  ...(candidate.evidence === undefined ? {} : { evidence: candidate.evidence }),
56
49
  });
57
50
  }
58
- export function identityKey(name, args) {
59
- try {
60
- return `${name}:${JSON.stringify(copyJson(args))}`;
61
- }
62
- catch {
63
- return `${name}:${String(args)}`;
64
- }
65
- }
@@ -1,19 +1,10 @@
1
1
  import type { InternalModelConfigurationSnapshot } from "./describe.js";
2
- import type { ModelConfigurationMutationOptions, ModelDirective } from "@nylorun/core/define";
2
+ import type { ModelConfigurationMutationOptions } from "@nylorun/core/define";
3
3
  import type { ToolDefinition } from "@nylorun/core/define";
4
- /** Per-step, middleware-owned model configuration draft. It never persists past the call. */
4
+ /** Per-step model configuration draft, set from the definition's parts. It never persists past the call. */
5
5
  export declare class ModelConfigurationDraft {
6
6
  #private;
7
- constructor(directive?: ModelDirective);
8
- setInstructions(middlewareId: string, middlewareOrder: number, slot: string, items: readonly string[], options?: ModelConfigurationMutationOptions): void;
9
- setTools(middlewareId: string, middlewareOrder: number, slot: string, tools: readonly ToolDefinition[], options?: ModelConfigurationMutationOptions): void;
10
- select(middlewareId: string, middlewareOrder: number, directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
11
- replace(middlewareId: string, middlewareOrder: number, directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
12
- /** Hide tools from this model call: every tool a capability contributed, or tools by name. */
13
- exclude(input: {
14
- readonly capabilities?: readonly string[];
15
- readonly tools?: readonly string[];
16
- }): void;
17
- clear(options?: Omit<ModelConfigurationMutationOptions, "order">): void;
7
+ setInstructions(partId: string, partOrder: number, slot: string, items: readonly string[], options?: ModelConfigurationMutationOptions): void;
8
+ setTools(partId: string, partOrder: number, slot: string, tools: readonly ToolDefinition[], options?: ModelConfigurationMutationOptions): void;
18
9
  snapshot(): InternalModelConfigurationSnapshot;
19
10
  }
@@ -1,25 +1,17 @@
1
1
  import { bindTool } from "@nylorun/core/define";
2
- import { HarnessError, isHarnessError } from "@nylorun/core/define";
3
- import { normalizeDirective, sameDirective } from "../model/normalize.js";
2
+ import { HarnessError } from "@nylorun/core/define";
4
3
  import { copyJson } from "@nylorun/core/define";
5
- import { checkedReason, slotOwner, SlotDraft } from "./slot-assembly.js";
6
- /** Per-step, middleware-owned model configuration draft. It never persists past the call. */
4
+ import { SlotDraft } from "./slot-assembly.js";
5
+ /** Per-step model configuration draft, set from the definition's parts. It never persists past the call. */
7
6
  export class ModelConfigurationDraft {
8
7
  #instructions = new SlotDraft();
9
8
  #tools = new SlotDraft();
10
- #model;
11
- #excludedOwners = new Set();
12
- #excludedTools = new Set();
13
- constructor(directive) {
14
- if (directive !== undefined)
15
- this.#model = Object.freeze({ directive: checkedDirective(directive) });
16
- }
17
- setInstructions(middlewareId, middlewareOrder, slot, items, options) {
9
+ setInstructions(partId, partOrder, slot, items, options) {
18
10
  if (!Array.isArray(items) || items.some((item) => typeof item !== "string"))
19
11
  throw new HarnessError("configuration.invalid-instructions", "Model configuration instructions must be strings");
20
12
  this.#instructions.set({
21
- middlewareId,
22
- middlewareOrder,
13
+ partId,
14
+ partOrder,
23
15
  slot,
24
16
  value: Object.freeze([...items]),
25
17
  order: options?.order,
@@ -30,14 +22,14 @@ export class ModelConfigurationDraft {
30
22
  label: "Model configuration",
31
23
  });
32
24
  }
33
- setTools(middlewareId, middlewareOrder, slot, tools, options) {
25
+ setTools(partId, partOrder, slot, tools, options) {
34
26
  if (!Array.isArray(tools))
35
27
  throw new HarnessError("configuration.invalid-tools", "Model configuration tools must be an array");
36
28
  this.#tools.set({
37
- middlewareId,
38
- middlewareOrder,
29
+ partId,
30
+ partOrder,
39
31
  slot,
40
- value: Object.freeze(tools.map((tool) => bindTool(tool, { middlewareId, slot }))),
32
+ value: Object.freeze(tools.map((tool) => bindTool(tool, { partId, slot }))),
41
33
  order: options?.order,
42
34
  reason: options?.reason,
43
35
  invalidSlot: "configuration.invalid-slot",
@@ -46,43 +38,6 @@ export class ModelConfigurationDraft {
46
38
  label: "Model configuration",
47
39
  });
48
40
  }
49
- select(middlewareId, middlewareOrder, directive, options) {
50
- const normalized = checkedDirective(directive);
51
- if (this.#model && !sameDirective(this.#model.directive, normalized))
52
- throw new HarnessError("configuration.model-selection-conflict", "A different model directive is already selected; use model.replace() to change it");
53
- this.#model = Object.freeze({
54
- directive: normalized,
55
- owner: slotOwner(middlewareId, middlewareOrder, "model"),
56
- ...(options?.reason === undefined
57
- ? {}
58
- : {
59
- reason: checkedReason(options.reason, "configuration.invalid-reason", "Model configuration"),
60
- }),
61
- });
62
- }
63
- replace(middlewareId, middlewareOrder, directive, options) {
64
- this.#model = Object.freeze({
65
- directive: checkedDirective(directive),
66
- owner: slotOwner(middlewareId, middlewareOrder, "model"),
67
- ...(options?.reason === undefined
68
- ? {}
69
- : {
70
- reason: checkedReason(options.reason, "configuration.invalid-reason", "Model configuration"),
71
- }),
72
- });
73
- }
74
- /** Hide tools from this model call: every tool a capability contributed, or tools by name. */
75
- exclude(input) {
76
- for (const id of input.capabilities ?? [])
77
- this.#excludedOwners.add(id);
78
- for (const name of input.tools ?? [])
79
- this.#excludedTools.add(name);
80
- }
81
- clear(options) {
82
- if (options?.reason !== undefined)
83
- checkedReason(options.reason, "configuration.invalid-reason", "Model configuration");
84
- this.#model = undefined;
85
- }
86
41
  snapshot() {
87
42
  const instructionSlots = this.#instructions.values();
88
43
  const toolSlots = this.#tools.values();
@@ -90,11 +45,7 @@ export class ModelConfigurationDraft {
90
45
  text,
91
46
  contributor: contributor(slot.owner, slot.reason),
92
47
  })));
93
- const sourcedTools = toolSlots
94
- .filter((slot) => !this.#excludedOwners.has(slot.owner.middlewareId))
95
- .flatMap((slot) => slot.value
96
- .filter((tool) => !this.#excludedTools.has(tool.name))
97
- .map((tool) => Object.freeze({ tool, contributor: contributor(slot.owner, slot.reason) })));
48
+ const sourcedTools = toolSlots.flatMap((slot) => slot.value.map((tool) => Object.freeze({ tool, contributor: contributor(slot.owner, slot.reason) })));
98
49
  const seen = new Set();
99
50
  const duplicate = new Set();
100
51
  for (const item of sourcedTools) {
@@ -105,30 +56,21 @@ export class ModelConfigurationDraft {
105
56
  if (duplicate.size)
106
57
  throw new HarnessError("configuration.duplicate-tool-name", `Duplicate Tool '${[...duplicate].sort().join("', '")}'`);
107
58
  const toolContracts = sourcedTools.map(({ tool, contributor: source }) => toolContract(tool, source));
108
- const model = this.#model?.directive;
109
59
  return Object.freeze({
110
60
  version: 1,
111
- ...(model === undefined ? {} : { model }),
112
61
  instructions: Object.freeze(instructions),
113
62
  tools: Object.freeze(sourcedTools.map((item) => item.tool)),
114
63
  toolContracts: Object.freeze(toolContracts),
115
64
  contributors: Object.freeze([
116
65
  ...instructionSlots.map((slot) => contributor(slot.owner, slot.reason)),
117
66
  ...toolSlots.map((slot) => contributor(slot.owner, slot.reason)),
118
- ...(this.#model?.owner ? [contributor(this.#model.owner, this.#model.reason)] : []),
119
67
  ]),
120
68
  });
121
69
  }
122
70
  }
123
- function checkedDirective(value) {
124
- const normalized = normalizeDirective(value);
125
- if (isHarnessError(normalized))
126
- throw normalized;
127
- return normalized;
128
- }
129
71
  function contributor(owner, reason) {
130
72
  return Object.freeze({
131
- middlewareId: owner.middlewareId,
73
+ partId: owner.partId,
132
74
  slot: owner.slot,
133
75
  order: owner.order,
134
76
  ...(reason === undefined ? {} : { reason }),
@@ -6,7 +6,6 @@ export function resolveModelRequest(input) {
6
6
  executionId: ctx.input.executionId,
7
7
  turnId: ctx.input.turnId,
8
8
  stepId: ctx.input.stepId,
9
- ...(ctx.selectedDirective === undefined ? {} : { model: ctx.selectedDirective }),
10
9
  configuration,
11
10
  instructions: Object.freeze([...ctx.instructions]),
12
11
  context: ctx.contextSnapshot(),
@@ -2,8 +2,6 @@ import { HostSuspension } from "../host-suspension.js";
2
2
  import { normalizeCandidate } from "../model/normalize.js";
3
3
  import { HarnessError, isHarnessError, isModelFailureOutcome } from "@nylorun/core/define";
4
4
  import { copyJson } from "@nylorun/core/define";
5
- import { runMiddleware } from "./compose.js";
6
- import { ContextDraft } from "./context-draft.js";
7
5
  import { StepContext } from "./step-context.js";
8
6
  import { projectModelCall } from "../model/project.js";
9
7
  import { resolveModelRequest } from "./resolve.js";
@@ -25,8 +23,7 @@ export async function runStep(input) {
25
23
  transcript: Object.freeze([...input.state.transcript]),
26
24
  });
27
25
  const configuration = new ModelConfigurationDraft();
28
- const runtimeContext = new ContextDraft();
29
- const context = new StepContext(stepInput, input.observe, configuration, runtimeContext);
26
+ const context = new StepContext(stepInput, configuration);
30
27
  input.observe(() => ({
31
28
  type: "step.started",
32
29
  turnId: input.turnId,
@@ -35,25 +32,26 @@ export async function runStep(input) {
35
32
  stepNumber: input.stepNumber,
36
33
  attributes: snapshotStepStart(stepInput),
37
34
  }));
38
- await runMiddleware(input.agent.middleware, context, async () => {
35
+ /** Seal the step's configuration and call the model; a failure ends the step as a tripwire. */
36
+ const invokeModel = async () => {
39
37
  input.signal.throwIfAborted();
40
38
  if (context.currentTripwire)
41
- return context.tripwire(context.currentTripwire);
39
+ return;
42
40
  try {
43
41
  const selected = configuration.snapshot();
44
42
  for (const tool of selected.tools)
45
43
  input.agent.registry.reference(tool);
46
44
  context.sealConfiguration(selected);
47
- context.sealContext(runtimeContext.snapshot());
48
45
  }
49
46
  catch (error) {
50
47
  if (error instanceof HostSuspension)
51
48
  throw error;
52
49
  const message = error instanceof Error ? error.message : String(error);
53
- return context.tripwire({
50
+ context.tripwire({
54
51
  code: isHarnessError(error) ? error.code : "configuration.invalid",
55
52
  message,
56
53
  });
54
+ return;
57
55
  }
58
56
  const request = resolveModelRequest({
59
57
  context,
@@ -110,22 +108,23 @@ export async function runStep(input) {
110
108
  ...(outcome.retryAfterMs === undefined ? {} : { retryAfterMs: outcome.retryAfterMs }),
111
109
  },
112
110
  });
113
- const minted = context.mintFromModel(normalizeCandidate(outcome));
111
+ context.mintFromModel(normalizeCandidate(outcome));
114
112
  if (!context.currentCandidate)
115
113
  throw new HarnessError("model.candidate-missing", "Model candidate missing after mint");
116
- return minted;
117
114
  }
118
115
  catch (error) {
119
116
  if (error instanceof HostSuspension)
120
117
  throw error;
121
118
  if (input.signal.aborted)
122
119
  throw input.signal.reason;
123
- return context.tripwire({
120
+ context.tripwire({
124
121
  code: isHarnessError(error) ? error.code : "model.failed",
125
122
  message: error instanceof Error ? error.message : String(error),
126
123
  });
127
124
  }
128
- }, input.observe);
125
+ };
126
+ configureParts(input.agent.parts, configuration, context);
127
+ await invokeModel();
129
128
  const output = sealStep(context, input.output);
130
129
  const candidate = output.kind === "tools" ? output.plan.candidate : context.currentCandidate;
131
130
  return Object.freeze({
@@ -146,3 +145,25 @@ function snapshotStepStart(input) {
146
145
  function snapshotConfiguration(configuration) {
147
146
  return copyJson(configuration);
148
147
  }
148
+ /**
149
+ * Offer each part's tools and instructions to the model, in part order. A part whose tools or
150
+ * text the configuration refuses ends the step with that error.
151
+ */
152
+ function configureParts(parts, configuration, context) {
153
+ parts.forEach((part, order) => {
154
+ const tools = [...(part.tools ?? []), ...(part.sessionTools ?? [])];
155
+ const instructions = [...(part.instructions ?? []), ...(part.sessionInstructions ?? [])];
156
+ try {
157
+ if (tools.length)
158
+ configuration.setTools(part.id, order, part.id, tools);
159
+ if (instructions.length)
160
+ configuration.setInstructions(part.id, order, part.id, instructions);
161
+ }
162
+ catch (cause) {
163
+ context.tripwire({
164
+ code: isHarnessError(cause) ? cause.code : "tool.invalid-schema",
165
+ message: cause instanceof Error ? cause.message : String(cause),
166
+ });
167
+ }
168
+ });
169
+ }
@@ -2,11 +2,11 @@ import type { ToolRegistry } from "../../definition/registry.js";
2
2
  import type { ModelAdapter } from "@nylorun/core/define";
3
3
  import type { InputEvent, TranscriptEntry } from "@nylorun/core/define";
4
4
  import type { ToolResult } from "@nylorun/core/define";
5
- import type { BoundMiddleware } from "@nylorun/core/define";
5
+ import type { DefinitionPart } from "@nylorun/core/define";
6
6
  import type { JsonValue } from "@nylorun/core/define";
7
7
  /** Compiled definition pieces plus the per-run model adapter for one step. */
8
8
  export interface StepRuntime {
9
- readonly middleware: readonly BoundMiddleware[];
9
+ readonly parts: readonly DefinitionPart[];
10
10
  readonly invoke: ModelAdapter;
11
11
  readonly registry: ToolRegistry;
12
12
  /** Mutable session memory bag shared with tools. */
@@ -93,22 +93,6 @@ function sealCall(context, catalog, candidate) {
93
93
  canonical,
94
94
  immediate: failed(candidate.id, candidate.name, "tool.invalid-arguments", args.message, args.details),
95
95
  };
96
- const denial = context.denialFor(candidate.id);
97
- if (denial)
98
- return {
99
- order,
100
- canonical,
101
- immediate: Object.freeze({
102
- kind: "denied",
103
- callId: candidate.id,
104
- toolName: candidate.name,
105
- reason: denial,
106
- }),
107
- };
108
- const requested = context.interactionFor(candidate.id);
109
- const interaction = requested
110
- ? Object.freeze({ ...requested, id: requested.id ?? createId("interaction") })
111
- : undefined;
112
96
  return {
113
97
  order,
114
98
  canonical,
@@ -124,7 +108,6 @@ function sealCall(context, catalog, candidate) {
124
108
  owner: tool.owner,
125
109
  execute: tool.execute,
126
110
  ...(tool.outputSchema === undefined ? {} : { outputSchema: tool.outputSchema }),
127
- ...(interaction ? { interaction } : {}),
128
111
  }),
129
112
  };
130
113
  }
@@ -1,7 +1,7 @@
1
1
  import { type HarnessErrorCode } from "@nylorun/core/define";
2
2
  export interface SlotOwner {
3
- readonly middlewareId: string;
4
- readonly middlewareOrder: number;
3
+ readonly partId: string;
4
+ readonly partOrder: number;
5
5
  readonly slot: string;
6
6
  readonly order: number;
7
7
  }
@@ -18,8 +18,8 @@ export interface SlotDeclaration<Value> {
18
18
  export declare class SlotDraft<Value> {
19
19
  #private;
20
20
  set(input: {
21
- readonly middlewareId: string;
22
- readonly middlewareOrder: number;
21
+ readonly partId: string;
22
+ readonly partOrder: number;
23
23
  readonly slot: string;
24
24
  readonly value: Value;
25
25
  readonly order?: number;
@@ -31,7 +31,7 @@ export declare class SlotDraft<Value> {
31
31
  }): void;
32
32
  values(): readonly SlotDeclaration<Value>[];
33
33
  }
34
- export declare function slotOwner(middlewareId: string, middlewareOrder: number, slot: string): SlotOwner;
34
+ export declare function slotOwner(partId: string, partOrder: number, slot: string): SlotOwner;
35
35
  export declare function slotKey(value: SlotOwner): string;
36
36
  export declare function checkedSlot(value: string, code: HarnessErrorCode, label: string): void;
37
37
  export declare function checkedReason(value: string, code: HarnessErrorCode, label: string): string;
@@ -8,7 +8,7 @@ export class SlotDraft {
8
8
  #slots = new Map();
9
9
  set(input) {
10
10
  checkedSlot(input.slot, input.invalidSlot, input.label);
11
- const base = slotOwner(input.middlewareId, input.middlewareOrder, input.slot);
11
+ const base = slotOwner(input.partId, input.partOrder, input.slot);
12
12
  const key = slotKey(base);
13
13
  const prior = this.#slots.get(key);
14
14
  const owner = withOrder(base, input.order, prior?.owner.order, input.invalidOrder, input.label);
@@ -24,11 +24,11 @@ export class SlotDraft {
24
24
  return Object.freeze([...this.#slots.values()].sort((left, right) => compareSlotOwners(left.owner, right.owner)));
25
25
  }
26
26
  }
27
- export function slotOwner(middlewareId, middlewareOrder, slot) {
28
- return Object.freeze({ middlewareId, middlewareOrder, slot, order: 0 });
27
+ export function slotOwner(partId, partOrder, slot) {
28
+ return Object.freeze({ partId, partOrder, slot, order: 0 });
29
29
  }
30
30
  export function slotKey(value) {
31
- return `${value.middlewareId}\u0000${value.slot}`;
31
+ return `${value.partId}\u0000${value.slot}`;
32
32
  }
33
33
  export function checkedSlot(value, code, label) {
34
34
  if (typeof value !== "string" || value.length === 0)
@@ -47,6 +47,6 @@ export function withOrder(owner, requested, previousOrder, code, label) {
47
47
  }
48
48
  export function compareSlotOwners(left, right) {
49
49
  return (left.order - right.order ||
50
- left.middlewareOrder - right.middlewareOrder ||
50
+ left.partOrder - right.partOrder ||
51
51
  left.slot.localeCompare(right.slot));
52
52
  }
@@ -1,38 +1,24 @@
1
1
  import type { BoundToolDefinition } from "@nylorun/core/define";
2
2
  import type { StepInput } from "./runtime.js";
3
3
  import type { InternalModelConfigurationSnapshot } from "./describe.js";
4
- import type { ContextSnapshot, ModelCandidate, ModelDirective } from "@nylorun/core/define";
5
- import type { StepRequest, StepResponse } from "@nylorun/core/define";
4
+ import type { ContextSnapshot, ModelCandidate } from "@nylorun/core/define";
6
5
  import type { Tripwire } from "@nylorun/core/define";
7
- import type { ObserveEmit } from "../observe.js";
8
- import type { Interaction } from "@nylorun/core/define";
9
6
  import { type CanonicalCall } from "./canonicalize.js";
10
- import { ContextDraft } from "./context-draft.js";
11
7
  import { ModelConfigurationDraft } from "./model-configuration.js";
12
- export declare function isBrandedResponse(value: unknown): value is StepResponse;
13
- /** Mutable Step state. Middleware receives leased request views and one branded response. */
8
+ /** Mutable Step state: the configuration the definition's parts set, and the model's answer. */
14
9
  export declare class StepContext {
15
10
  #private;
16
11
  readonly input: Readonly<StepInput>;
17
- constructor(input: Readonly<StepInput>, observe: ObserveEmit, configuration: ModelConfigurationDraft, context: ContextDraft);
12
+ constructor(input: Readonly<StepInput>, configuration: ModelConfigurationDraft);
18
13
  get currentTripwire(): Tripwire | undefined;
19
14
  get currentCandidate(): Readonly<ModelCandidate> | undefined;
20
- get selectedDirective(): ModelDirective | undefined;
21
15
  get instructions(): readonly string[];
22
16
  contextSnapshot(): ContextSnapshot;
23
17
  get offeredTools(): readonly BoundToolDefinition[];
24
18
  get catalogByName(): ReadonlyMap<string, BoundToolDefinition>;
25
19
  configurationSnapshot(): InternalModelConfigurationSnapshot;
26
20
  sealConfiguration(snapshot: InternalModelConfigurationSnapshot): void;
27
- sealContext(snapshot: ContextSnapshot): void;
28
- denialFor(callId: string): string | undefined;
29
- interactionFor(callId: string): Interaction | undefined;
30
21
  canonicalCalls(): readonly CanonicalCall[];
31
- mintFromModel(candidate: Readonly<ModelCandidate>): StepResponse;
32
- tripwire(error: Tripwire): StepResponse;
33
- seal(): void;
34
- requestFacade(middlewareId: string, middlewareOrder: number): {
35
- readonly value: StepRequest;
36
- revokeMutators(): void;
37
- };
22
+ mintFromModel(candidate: Readonly<ModelCandidate>): void;
23
+ tripwire(error: Tripwire): void;
38
24
  }