@nylorun/core 0.7.0-beta → 0.9.0-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 (61) hide show
  1. package/CHANGELOG.md +249 -0
  2. package/dist/compatibility.d.ts +42 -4
  3. package/dist/compatibility.js +65 -3
  4. package/dist/contracts.d.ts +2165 -328
  5. package/dist/contracts.js +1246 -100
  6. package/dist/define.d.ts +13 -5
  7. package/dist/define.js +7 -2
  8. package/dist/definition/assemble.js +16 -14
  9. package/dist/definition/bind-tool.js +1 -0
  10. package/dist/definition/bound.d.ts +2 -0
  11. package/dist/definition/builder.d.ts +116 -16
  12. package/dist/definition/builder.js +330 -53
  13. package/dist/definition/capability.d.ts +55 -0
  14. package/dist/definition/capability.js +104 -0
  15. package/dist/definition/declaration.js +6 -2
  16. package/dist/definition/delegate.d.ts +25 -4
  17. package/dist/definition/delegate.js +34 -6
  18. package/dist/definition/flow/compile.d.ts +23 -0
  19. package/dist/definition/flow/compile.js +274 -0
  20. package/dist/definition/flow/from.d.ts +11 -0
  21. package/dist/definition/flow/from.js +78 -0
  22. package/dist/definition/flow/index.d.ts +11 -0
  23. package/dist/definition/flow/index.js +11 -0
  24. package/dist/definition/flow/paths.d.ts +60 -0
  25. package/dist/definition/flow/paths.js +90 -0
  26. package/dist/definition/flow/spec.d.ts +66 -0
  27. package/dist/definition/flow/spec.js +130 -0
  28. package/dist/definition/flow/types.d.ts +157 -0
  29. package/dist/definition/flow/types.js +1 -0
  30. package/dist/definition/from.js +5 -1
  31. package/dist/definition/helpers.d.ts +1 -16
  32. package/dist/definition/helpers.js +1 -30
  33. package/dist/definition/mcp.d.ts +37 -0
  34. package/dist/definition/mcp.js +81 -0
  35. package/dist/definition/model-failure.d.ts +4 -0
  36. package/dist/definition/model-failure.js +22 -0
  37. package/dist/definition/sandbox-capability.d.ts +12 -0
  38. package/dist/definition/sandbox-capability.js +33 -0
  39. package/dist/definition/schema.js +3 -0
  40. package/dist/definition/workflow/build.d.ts +3 -13
  41. package/dist/definition/workflow/build.js +3 -25
  42. package/dist/definition/workflow/chain.js +0 -1
  43. package/dist/definition/workflow/loop.js +2 -4
  44. package/dist/definition/workflow/map.js +0 -1
  45. package/dist/definition/workflow/parallel.js +0 -1
  46. package/dist/definition/workflow/runnable.d.ts +13 -5
  47. package/dist/definition/workflow/runnable.js +11 -41
  48. package/dist/definition/workflow/switch.js +0 -2
  49. package/dist/errors.d.ts +3 -1
  50. package/dist/types/manifest.d.ts +4 -2
  51. package/dist/types/middleware.d.ts +1 -3
  52. package/dist/types/model.d.ts +32 -1
  53. package/dist/types/observe.d.ts +7 -1
  54. package/dist/types/tool.d.ts +6 -0
  55. package/dist/types/transcript.d.ts +14 -1
  56. package/dist/types/workflow.d.ts +72 -3
  57. package/dist/utils/deprecate.d.ts +3 -0
  58. package/dist/utils/deprecate.js +25 -0
  59. package/dist/utils/sandbox.d.ts +0 -4
  60. package/dist/utils/sandbox.js +0 -16
  61. package/package.json +1 -1
@@ -0,0 +1,22 @@
1
+ export const MODEL_FAILURE_CODES = Object.freeze([
2
+ "context_overflow",
3
+ "rate_limited",
4
+ "overloaded",
5
+ "timeout",
6
+ "transient",
7
+ "content_policy",
8
+ "auth",
9
+ "invalid_request",
10
+ "invalid_output",
11
+ ]);
12
+ /** True for a model adapter's failure outcome (`{ kind: "failed", code, message, retryable }`). */
13
+ export function isModelFailureOutcome(value) {
14
+ if (!value || typeof value !== "object" || Array.isArray(value))
15
+ return false;
16
+ const outcome = value;
17
+ return (outcome.kind === "failed" &&
18
+ typeof outcome.code === "string" &&
19
+ MODEL_FAILURE_CODES.includes(outcome.code) &&
20
+ typeof outcome.message === "string" &&
21
+ typeof outcome.retryable === "boolean");
22
+ }
@@ -0,0 +1,12 @@
1
+ import type { CapabilityManifest, SandboxManifest } from "../types/manifest.js";
2
+ /** Id of the capability the Runtime adds to a session whose sandbox was chosen at open. */
3
+ export declare const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
4
+ /**
5
+ * The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
6
+ * instructions and the resolved spec. The Runtime adds it to a session's pinned manifest. Its
7
+ * tools are projected the way the builder projects any tool.
8
+ */
9
+ export declare function sandboxCapabilityManifest(spec: SandboxManifest, options?: {
10
+ /** The workspace path the backend uses, named in the tools' text. Default `/workspace`. */
11
+ readonly workspace?: string;
12
+ }): CapabilityManifest;
@@ -0,0 +1,33 @@
1
+ import { SANDBOX_INSTRUCTIONS, createSandboxTools } from "./sandbox-tools.js";
2
+ import { SANDBOX_WORKSPACE } from "../utils/sandbox.js";
3
+ import { normalizedSchemasFor } from "./schema.js";
4
+ import { copyJsonObject } from "../utils/immutable.js";
5
+ /** Id of the capability the Runtime adds to a session whose sandbox was chosen at open. */
6
+ export const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
7
+ /**
8
+ * The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
9
+ * instructions and the resolved spec. The Runtime adds it to a session's pinned manifest. Its
10
+ * tools are projected the way the builder projects any tool.
11
+ */
12
+ export function sandboxCapabilityManifest(spec, options = {}) {
13
+ const workspace = options.workspace ?? SANDBOX_WORKSPACE;
14
+ const text = (value) => value.replaceAll(SANDBOX_WORKSPACE, workspace);
15
+ const tools = createSandboxTools().map((tool) => {
16
+ const schemas = normalizedSchemasFor(tool);
17
+ return {
18
+ name: tool.name,
19
+ ...(tool.description === undefined ? {} : { description: text(tool.description) }),
20
+ inputSchema: schemas.inputSchema.jsonSchema,
21
+ ...(schemas.outputSchema === undefined
22
+ ? {}
23
+ : { outputSchema: schemas.outputSchema.jsonSchema }),
24
+ };
25
+ });
26
+ return {
27
+ id: SANDBOX_CAPABILITY_ID,
28
+ type: "agent",
29
+ instructions: [text(SANDBOX_INSTRUCTIONS)],
30
+ tools,
31
+ sandbox: copyJsonObject(spec, "sandbox"),
32
+ };
33
+ }
@@ -49,6 +49,9 @@ export function normalizeToolDefinition(definition) {
49
49
  ...(definition.effects === undefined
50
50
  ? {}
51
51
  : { effects: definition.effects }),
52
+ ...(definition.background === undefined
53
+ ? {}
54
+ : { background: definition.background }),
52
55
  };
53
56
  }
54
57
  /** Returns cached normalized contracts, preparing raw definitions on first bind. */
@@ -1,27 +1,17 @@
1
1
  import type { AgentBinding } from "../binding.js";
2
- import type { BuildDiagnostic, JsonObject, JsonValue } from "../../types/shared.js";
2
+ import type { BuildDiagnostic, JsonValue } from "../../types/shared.js";
3
3
  import type { WorkflowNode, WorkflowNodeImplementation } from "../../types/workflow.js";
4
4
  import type { ToolSchemaSource } from "../../types/tool.js";
5
5
  import type { BuiltWorkflow } from "./types.js";
6
6
  export type BuildAccumulator = {
7
7
  readonly agents: Record<string, AgentBinding>;
8
8
  readonly nodes: Record<string, WorkflowNodeImplementation>;
9
- readonly sandboxSpecs: JsonObject[];
10
9
  };
11
10
  export declare function emptyAccumulator(): BuildAccumulator;
12
11
  export declare function mergeChild(acc: BuildAccumulator, child: {
13
12
  readonly agents: Record<string, AgentBinding>;
14
13
  readonly nodes: Record<string, WorkflowNodeImplementation>;
15
- readonly sandboxSpecs: readonly JsonObject[];
16
14
  }): void;
17
- /**
18
- * Every agent in the tree that declares a sandbox must declare an identical spec
19
- * (workflows.md §8). Returns the common spec, or undefined when none declare one.
20
- */
21
- export declare function resolveWorkflowSandbox(specs: readonly JsonObject[]): {
22
- sandbox?: JsonObject;
23
- diagnostics: BuildDiagnostic[];
24
- };
25
15
  export type FinishOptions<In = JsonValue, Out = JsonValue> = {
26
16
  readonly id: string;
27
17
  readonly root: WorkflowNode;
@@ -32,7 +22,7 @@ export type FinishOptions<In = JsonValue, Out = JsonValue> = {
32
22
  readonly diagnostics?: readonly BuildDiagnostic[];
33
23
  };
34
24
  /**
35
- * Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON,
36
- * optional document-level sandbox (workflows.md §18).
25
+ * Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON. A workflow
26
+ * declares no sandbox: the session it runs in is opened with one (Sandboxes v3).
37
27
  */
38
28
  export declare function finishWorkflow<In = JsonValue, Out = JsonValue>(options: FinishOptions<In, Out>): BuiltWorkflow<In, Out>;
@@ -1,38 +1,17 @@
1
- import { canonical } from "../../utils/canonical.js";
2
1
  import { diagnostic, fail } from "./diagnostics.js";
3
2
  export function emptyAccumulator() {
4
- return { agents: {}, nodes: {}, sandboxSpecs: [] };
3
+ return { agents: {}, nodes: {} };
5
4
  }
6
5
  export function mergeChild(acc, child) {
7
6
  Object.assign(acc.agents, child.agents);
8
7
  Object.assign(acc.nodes, child.nodes);
9
- for (const spec of child.sandboxSpecs)
10
- acc.sandboxSpecs.push(spec);
11
8
  }
12
9
  /**
13
- * Every agent in the tree that declares a sandbox must declare an identical spec
14
- * (workflows.md §8). Returns the common spec, or undefined when none declare one.
15
- */
16
- export function resolveWorkflowSandbox(specs) {
17
- if (specs.length === 0)
18
- return { diagnostics: [] };
19
- const keys = new Set(specs.map((s) => canonical(s)));
20
- if (keys.size > 1)
21
- return {
22
- diagnostics: [
23
- diagnostic("workflow.sandbox-mismatch", "Every agent in the tree that declares a sandbox must declare an identical spec"),
24
- ],
25
- };
26
- return { sandbox: specs[0], diagnostics: [] };
27
- }
28
- /**
29
- * Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON,
30
- * optional document-level sandbox (workflows.md §18).
10
+ * Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON. A workflow
11
+ * declares no sandbox: the session it runs in is opened with one (Sandboxes v3).
31
12
  */
32
13
  export function finishWorkflow(options) {
33
14
  const diagnostics = [...(options.diagnostics ?? [])];
34
- const { sandbox, diagnostics: sandboxDiagnostics } = resolveWorkflowSandbox(options.acc.sandboxSpecs);
35
- diagnostics.push(...sandboxDiagnostics);
36
15
  if (diagnostics.length)
37
16
  fail(diagnostics);
38
17
  const manifest = {
@@ -40,7 +19,6 @@ export function finishWorkflow(options) {
40
19
  workflowSchemaVersion: 1,
41
20
  id: options.id,
42
21
  root: options.root,
43
- ...(sandbox === undefined ? {} : { sandbox: sandbox }),
44
22
  };
45
23
  const binding = Object.freeze({
46
24
  manifest,
@@ -27,7 +27,6 @@ export function Chain(options) {
27
27
  mergeChild(acc, {
28
28
  agents: resolved.agents,
29
29
  nodes: remapNodeKeys(resolved.nodes, resolved.id, stepPath),
30
- sandboxSpecs: resolved.sandboxSpecs,
31
30
  });
32
31
  stepNodes.push(resolved.node);
33
32
  }
@@ -46,7 +46,6 @@ export function Loop(options) {
46
46
  mergeChild(acc, {
47
47
  agents: runResolved.agents,
48
48
  nodes: remapNodeKeys(runResolved.nodes, runResolved.id, runPath),
49
- sandboxSpecs: runResolved.sandboxSpecs,
50
49
  });
51
50
  let verifyField;
52
51
  if (isVerifyFn(verify)) {
@@ -67,11 +66,10 @@ export function Loop(options) {
67
66
  id: agentEntry.manifest.id,
68
67
  getBinding: () => agentEntry,
69
68
  });
70
- // Verifier agent sessions are derived separately; local fn keys (slot input) sit under verify.
69
+ // Keys follow the harness path for the verifier, `<loop>/<part>` (workflows.md §6).
71
70
  mergeChild(acc, {
72
71
  agents: verifyChild.agents,
73
- nodes: remapNodeKeys(verifyChild.nodes, verifyChild.id, `${id}/verify`),
74
- sandboxSpecs: verifyChild.sandboxSpecs,
72
+ nodes: remapNodeKeys(verifyChild.nodes, verifyChild.id, `${id}/${verifyChild.id}`),
75
73
  });
76
74
  const node = verifyChild.node;
77
75
  if (!("agent" in node) && !("slot" in node)) {
@@ -22,7 +22,6 @@ export function Map(options) {
22
22
  mergeChild(acc, {
23
23
  agents: resolved.agents,
24
24
  nodes: remapNodeKeys(resolved.nodes, resolved.id, eachPath),
25
- sandboxSpecs: resolved.sandboxSpecs,
26
25
  });
27
26
  acc.nodes[`${id}/over`] = {
28
27
  kind: "fn",
@@ -23,7 +23,6 @@ export function Parallel(options) {
23
23
  mergeChild(acc, {
24
24
  agents: resolved.agents,
25
25
  nodes: remapNodeKeys(resolved.nodes, resolved.id, branchPath),
26
- sandboxSpecs: resolved.sandboxSpecs,
27
26
  });
28
27
  branchNodes[name] = resolved.node;
29
28
  }
@@ -1,7 +1,6 @@
1
1
  import type { AgentTool, BuiltAgent } from "../../types/agent.js";
2
- import type { JsonObject } from "../../types/shared.js";
3
2
  import type { ToolDefinition } from "../../types/tool.js";
4
- import type { WorkflowNode } from "../../types/workflow.js";
3
+ import type { WorkflowNode, WorkflowToolNode } from "../../types/workflow.js";
5
4
  import type { AgentBinding } from "../binding.js";
6
5
  import type { BoundToolDefinition } from "../bound.js";
7
6
  import { type BuiltWorkflow } from "./types.js";
@@ -17,11 +16,20 @@ export type ResolvedChild = {
17
16
  /** Nested workflow implementations, keyed relative to the child root id. */
18
17
  readonly nodes: Record<string, import("../../types/workflow.js").WorkflowNodeImplementation>;
19
18
  readonly tool?: BoundToolDefinition;
20
- readonly sandboxSpecs: readonly JsonObject[];
21
19
  readonly isReshapingSlot: boolean;
22
20
  };
23
- /** Collect sandbox specs declared on an agent (and its delegates, one level). */
24
- export declare function sandboxSpecsOf(agent: BuiltAgent | AgentTool): JsonObject[];
21
+ export declare function isToolDefinition(value: unknown): value is ToolDefinition;
22
+ export declare function isAgentLike(value: unknown): value is BuiltAgent | AgentTool;
23
+ export declare function builtAgentOf(run: BuiltAgent | AgentTool | {
24
+ build(): BuiltAgent;
25
+ }): BuiltAgent;
26
+ /**
27
+ * Project a tool for use as a workflow node.
28
+ * Unlike agent tools, workflow tool nodes may take any JSON Schema root type (workflows.md §9).
29
+ * Built without `bindTool` so we skip the agent-only object-input rule in `normalizeSchema`.
30
+ */
31
+ export declare function bindToolNode(tool: ToolDefinition): BoundToolDefinition;
32
+ export declare function toolManifestNode(bound: BoundToolDefinition): WorkflowToolNode;
25
33
  /**
26
34
  * Resolve a runnable or slot into a manifest node plus local bindings.
27
35
  * When the slot has `input`, the node is wrapped as `{ slot: { id?, input, run } }`.
@@ -4,7 +4,7 @@ import { HarnessError } from "../../errors.js";
4
4
  import { isBuiltWorkflow } from "./types.js";
5
5
  import { failOne } from "./diagnostics.js";
6
6
  import { isSlot } from "./slot.js";
7
- function isToolDefinition(value) {
7
+ export function isToolDefinition(value) {
8
8
  if (!value || typeof value !== "object")
9
9
  return false;
10
10
  if (!("name" in value) || typeof value.name !== "string")
@@ -15,7 +15,7 @@ function isToolDefinition(value) {
15
15
  v.inputSchema !== undefined ||
16
16
  v.input !== undefined);
17
17
  }
18
- function isAgentLike(value) {
18
+ export function isAgentLike(value) {
19
19
  if (!value || typeof value !== "object")
20
20
  return false;
21
21
  if (isBuiltWorkflow(value))
@@ -25,7 +25,7 @@ function isAgentLike(value) {
25
25
  "manifest" in value &&
26
26
  typeof value.getBinding === "function");
27
27
  }
28
- function builtAgentOf(run) {
28
+ export function builtAgentOf(run) {
29
29
  if (run &&
30
30
  typeof run === "object" &&
31
31
  "getBinding" in run &&
@@ -37,31 +37,12 @@ function builtAgentOf(run) {
37
37
  return run.build();
38
38
  failOne("workflow.invalid-runnable", "Expected a built agent or Agent builder");
39
39
  }
40
- /** Collect sandbox specs declared on an agent (and its delegates, one level). */
41
- export function sandboxSpecsOf(agent) {
42
- const specs = [];
43
- const binding = bindingFromAgent(agent);
44
- for (const cap of binding.manifest.capabilities) {
45
- if (cap.sandbox)
46
- specs.push(cap.sandbox);
47
- }
48
- for (const tool of binding.tools) {
49
- const child = tool.delegate?.agent;
50
- if (!child)
51
- continue;
52
- for (const cap of child.manifest.capabilities) {
53
- if (cap.sandbox)
54
- specs.push(cap.sandbox);
55
- }
56
- }
57
- return specs;
58
- }
59
40
  /**
60
41
  * Project a tool for use as a workflow node.
61
42
  * Unlike agent tools, workflow tool nodes may take any JSON Schema root type (workflows.md §9).
62
43
  * Built without `bindTool` so we skip the agent-only object-input rule in `normalizeSchema`.
63
44
  */
64
- function bindToolNode(tool) {
45
+ export function bindToolNode(tool) {
65
46
  const normalized = normalizeToolDefinition(tool);
66
47
  if (!normalized.name)
67
48
  throw new HarnessError("tool.invalid-name", "Tool name must not be empty");
@@ -97,7 +78,7 @@ function schemaForNode(source, role) {
97
78
  // Pass role "output" so normalizeSchema does not require an object root.
98
79
  return normalizeSchema(source, role === "input" ? "output" : role);
99
80
  }
100
- function toolManifestNode(bound) {
81
+ export function toolManifestNode(bound) {
101
82
  return {
102
83
  tool: {
103
84
  name: bound.name,
@@ -114,19 +95,21 @@ function agentNode(agent) {
114
95
  return {
115
96
  node: { agent: agent.id },
116
97
  agents: { [agent.id]: binding },
117
- sandboxSpecs: sandboxSpecsOf(agent),
118
98
  };
119
99
  }
120
100
  function resolveRunnable(run, rename) {
121
101
  if (isBuiltWorkflow(run)) {
122
102
  const binding = run.getBinding();
103
+ if (binding.manifest.workflowSchemaVersion !== 1)
104
+ failOne("workflow.flow-agent-child", `Flow agent '${run.id}' can't be a child of Chain, Switch, Parallel, Map or Loop. Use it as a step of another flow agent: Agent({ id }).step(${run.id}).`);
105
+ const manifest = binding.manifest;
123
106
  const id = rename ?? run.id;
124
107
  return {
125
108
  id,
126
- node: binding.manifest.root,
109
+ node: manifest.root,
127
110
  agents: { ...binding.agents },
128
- nodes: { ...binding.nodes },
129
- sandboxSpecs: sandboxSpecsFromAgents(binding.agents),
111
+ // A rename moves the whole subtree: the harness path uses the new part, not run.id.
112
+ nodes: remapNodeKeys({ ...binding.nodes }, run.id, id),
130
113
  isReshapingSlot: false,
131
114
  };
132
115
  }
@@ -139,7 +122,6 @@ function resolveRunnable(run, rename) {
139
122
  agents: {},
140
123
  nodes: { [id]: { kind: "tool", tool: bound } },
141
124
  tool: bound,
142
- sandboxSpecs: [],
143
125
  isReshapingSlot: false,
144
126
  };
145
127
  }
@@ -153,22 +135,11 @@ function resolveRunnable(run, rename) {
153
135
  node: resolved.node,
154
136
  agents: resolved.agents,
155
137
  nodes: {},
156
- sandboxSpecs: resolved.sandboxSpecs,
157
138
  isReshapingSlot: false,
158
139
  };
159
140
  }
160
141
  failOne("workflow.invalid-runnable", "Unsupported workflow runnable");
161
142
  }
162
- function sandboxSpecsFromAgents(agents) {
163
- const specs = [];
164
- for (const binding of Object.values(agents)) {
165
- for (const cap of binding.manifest.capabilities) {
166
- if (cap.sandbox)
167
- specs.push(cap.sandbox);
168
- }
169
- }
170
- return specs;
171
- }
172
143
  /**
173
144
  * Resolve a runnable or slot into a manifest node plus local bindings.
174
145
  * When the slot has `input`, the node is wrapped as `{ slot: { id?, input, run } }`.
@@ -202,7 +173,6 @@ export function resolveChild(child, defaultRename) {
202
173
  agents: resolved.agents,
203
174
  nodes: remapped,
204
175
  tool: resolved.tool,
205
- sandboxSpecs: resolved.sandboxSpecs,
206
176
  isReshapingSlot: hasInput,
207
177
  };
208
178
  }
@@ -30,7 +30,6 @@ export function Switch(options) {
30
30
  mergeChild(acc, {
31
31
  agents: resolved.agents,
32
32
  nodes: remapNodeKeys(resolved.nodes, resolved.id, casePath),
33
- sandboxSpecs: resolved.sandboxSpecs,
34
33
  });
35
34
  caseNodes[key] = resolved.node;
36
35
  }
@@ -41,7 +40,6 @@ export function Switch(options) {
41
40
  mergeChild(acc, {
42
41
  agents: resolved.agents,
43
42
  nodes: remapNodeKeys(resolved.nodes, resolved.id, defaultPath),
44
- sandboxSpecs: resolved.sandboxSpecs,
45
43
  });
46
44
  defaultNode = resolved.node;
47
45
  }
package/dist/errors.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /** Machine-readable error raised by Harness-owned code. */
2
- export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "middleware.next-after-return" | "middleware.next-called-twice" | "middleware.request-mutators-revoked" | "model.candidate-missing" | "model.adapter-invalid-options" | "model.adapter-invalid-response" | "model.invalid-candidate" | "model.invalid-directive" | "model.unsupported-content" | "model.unsupported-output-schema" | "configuration.duplicate-tool-name" | "configuration.invalid" | "configuration.invalid-instructions" | "configuration.invalid-order" | "configuration.invalid-reason" | "configuration.invalid-slot" | "configuration.invalid-tools" | "configuration.model-selection-conflict" | "response.invalid-replacement" | "tool.invalid" | "tool.invalid-arguments" | "tool.invalid-output" | "tool.invalid-name" | "tool.invalid-schema" | "tool.invalid-tool-result";
2
+ export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "middleware.next-after-return" | "middleware.next-called-twice" | "middleware.request-mutators-revoked" | "model.candidate-missing" | "model.adapter-invalid-options" | "model.adapter-invalid-response" | "model.invalid-candidate" | "model.invalid-directive" | "model.unsupported-content" | "model.unsupported-output-schema"
3
+ /** A provider failure the model adapter classified (Model Calls §6.1). */
4
+ | `model.${import("./types/model.js").ModelFailureCode}` | "configuration.duplicate-tool-name" | "configuration.invalid" | "configuration.invalid-instructions" | "configuration.invalid-order" | "configuration.invalid-reason" | "configuration.invalid-slot" | "configuration.invalid-tools" | "configuration.model-selection-conflict" | "response.invalid-replacement" | "tool.invalid" | "tool.invalid-arguments" | "tool.invalid-output" | "tool.invalid-name" | "tool.invalid-schema" | "tool.invalid-tool-result";
3
5
  export type HarnessErrorDetails = Readonly<Record<string, string | number | boolean>>;
4
6
  export interface HarnessErrorOptions {
5
7
  readonly cause?: unknown;
@@ -1,5 +1,6 @@
1
1
  import type { JsonObject } from "./shared.js";
2
2
  import type { HookManifest } from "./dynamics.js";
3
+ import type { WorkflowManifestV2 } from "./workflow.js";
3
4
  /** Published manifest schema version (no top-level model — Runtime-owned). */
4
5
  export type ManifestSchemaVersion = 4;
5
6
  export interface ToolManifest {
@@ -9,9 +10,10 @@ export interface ToolManifest {
9
10
  readonly outputSchema?: JsonObject;
10
11
  /**
11
12
  * Present when this tool is another agent. The engine runs it with a fresh context and
12
- * returns its final output; its input is always `{ task: string }`. One level deep.
13
+ * returns its final output; its input is always `{ task: string }`. One level deep. A flow
14
+ * agent (workflow manifest v2) runs in its own linked session on the Runtime.
13
15
  */
14
- readonly agent?: AgentManifest;
16
+ readonly agent?: AgentManifest | WorkflowManifestV2;
15
17
  }
16
18
  export interface SkillManifest {
17
19
  readonly name: string;
@@ -1,7 +1,7 @@
1
1
  import type { ContextMutationOptions, ModelCandidate, ModelDirective, ModelToolCall, ModelConfigurationMutationOptions } from "./model.js";
2
2
  import type { InputEvent, TranscriptEntry } from "./transcript.js";
3
3
  import type { AgentTool } from "./agent.js";
4
- import type { McpServerManifest, SandboxManifest, SkillManifest } from "./manifest.js";
4
+ import type { McpServerManifest, SkillManifest } from "./manifest.js";
5
5
  /** Skill files held on the developer binding. Not a manifest field. */
6
6
  export interface SkillRecord {
7
7
  readonly name: string;
@@ -70,8 +70,6 @@ export interface CapabilityDeclaration<Info = unknown> {
70
70
  /** File contents for load_skill. Omitted from the manifest. */
71
71
  readonly skillRecords?: Readonly<Record<string, SkillRecord>>;
72
72
  readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
73
- /** Runtime-owned sandbox requirements. Declare the built-in sandbox tools alongside it. */
74
- readonly sandbox?: SandboxManifest;
75
73
  /** Resolved package directory. Not projected into the manifest. */
76
74
  readonly pluginRoot?: string;
77
75
  /**
@@ -30,6 +30,8 @@ export interface ModelUsage {
30
30
  readonly outputTokens?: number;
31
31
  readonly totalTokens?: number;
32
32
  readonly cachedTokens?: number;
33
+ /** Input tokens written to the provider's prompt cache. */
34
+ readonly cacheWriteTokens?: number;
33
35
  readonly reasoningTokens?: number;
34
36
  readonly costUsd?: number;
35
37
  }
@@ -46,6 +48,19 @@ export interface ModelCandidate {
46
48
  readonly usage?: ModelUsage;
47
49
  readonly evidence?: ModelEvidence;
48
50
  }
51
+ /** Why a model call failed in a known way (Model Calls §6.1). */
52
+ export type ModelFailureCode = "context_overflow" | "rate_limited" | "overloaded" | "timeout" | "transient" | "content_policy" | "auth" | "invalid_request" | "invalid_output";
53
+ /**
54
+ * A model call that failed in a known way. It is a completed outcome, not a lost one:
55
+ * the engine fails the step with `model.<code>` instead of treating the call as uncertain.
56
+ */
57
+ export interface ModelFailureOutcome {
58
+ readonly kind: "failed";
59
+ readonly code: ModelFailureCode;
60
+ readonly message: string;
61
+ readonly retryable: boolean;
62
+ readonly retryAfterMs?: number;
63
+ }
49
64
  export interface ModelControls {
50
65
  readonly temperature?: number;
51
66
  readonly maxOutputTokens?: number;
@@ -138,6 +153,12 @@ export type PromptContentPart = {
138
153
  readonly name: string;
139
154
  readonly args: JsonObject;
140
155
  };
156
+ /** The provider, API and model that produced an assistant message (Model Calls §12). */
157
+ export interface ModelProducer {
158
+ readonly provider: string;
159
+ readonly api?: string;
160
+ readonly model: string;
161
+ }
141
162
  export type PromptItem = {
142
163
  readonly kind: "instructions";
143
164
  readonly role: "system";
@@ -146,6 +167,8 @@ export type PromptItem = {
146
167
  readonly kind: "message";
147
168
  readonly role: "user" | "assistant";
148
169
  readonly content: readonly PromptContentPart[];
170
+ /** For assistant messages: the model that produced it, when the adapter recorded one. */
171
+ readonly producer?: ModelProducer;
149
172
  } | {
150
173
  readonly kind: "tool-result";
151
174
  readonly toolCallId: string;
@@ -174,6 +197,14 @@ export interface ModelAdapterContext {
174
197
  readonly request: ModelRequest;
175
198
  readonly invocationId: string;
176
199
  readonly signal: AbortSignal;
200
+ /** Set when the engine calls the model to summarize history (Model Calls §8). */
201
+ readonly compaction?: {
202
+ readonly trigger: "threshold" | "overflow";
203
+ readonly tokensBefore: number;
204
+ readonly keptTokens: number;
205
+ /** An intermediate call of a chunked summary; only the last one completes the compaction. */
206
+ readonly partial?: boolean;
207
+ };
177
208
  /** Publishes one JSON-safe provider request derived from the canonical ModelCall. */
178
209
  reportPreparedCall(prepared: ModelPreparedCall): void;
179
210
  }
@@ -181,4 +212,4 @@ export interface ModelPreparedCall {
181
212
  readonly adapter: string;
182
213
  readonly call: JsonValue;
183
214
  }
184
- export type ModelAdapter = (call: ModelCall, context: ModelAdapterContext) => Promise<ModelCandidate | string>;
215
+ export type ModelAdapter = (call: ModelCall, context: ModelAdapterContext) => Promise<ModelCandidate | ModelFailureOutcome | string>;
@@ -8,7 +8,13 @@ export interface WorkflowErrorPayload {
8
8
  readonly message: string;
9
9
  readonly path?: string;
10
10
  }
11
- /** LiveEvent payloads for workflow sessions (`workflows.md` §11, `loops.md` §4.6). */
11
+ /**
12
+ * LiveEvent payloads for workflow sessions (`workflows.md` §11, `loops.md` §4.6).
13
+ *
14
+ * @deprecated Use the event catalog (`EVENT_CATALOG`, `SessionEventOf<"node.agent">` in
15
+ * `@nylorun/core/contracts`): it types the events the Runtime writes. `node.completed`,
16
+ * `node.failed`, `switch.selected`, `map.items` and `loop.waiting` are not written.
17
+ */
12
18
  export type WorkflowLiveEventPayload = {
13
19
  readonly type: "node.started";
14
20
  readonly path: string;
@@ -79,6 +79,12 @@ export interface ToolDefinition<InputSchema extends ToolInputSchema = ToolInputS
79
79
  readonly approval?: ToolApproval<InputSchema>;
80
80
  /** Code-only metadata — never serialized into the manifest. */
81
81
  readonly effects?: ToolEffects;
82
+ /**
83
+ * Runs in the background when an Action endpoint serves it: the endpoint answers the delivery
84
+ * at once (`202`), heartbeats while the tool runs, and posts its outcome when it ends. For
85
+ * tools that run longer than an endpoint's timeout. Code-only metadata — never serialized.
86
+ */
87
+ readonly background?: boolean;
82
88
  }
83
89
  /** A plain return value is treated as `{ kind: "completed", output }`. Legacy tagged outcomes remain valid. */
84
90
  export type ToolRunResult<Output = ToolContent> = Output | ToolOutcome<Output>;
@@ -62,4 +62,17 @@ export interface TranscriptFinalEntry {
62
62
  readonly stepId: string;
63
63
  readonly output: JsonValue;
64
64
  }
65
- export type TranscriptEntry = TranscriptInputEntry | TranscriptCandidateEntry | TranscriptToolsEntry | TranscriptFinalEntry;
65
+ /**
66
+ * A summary that replaced the older part of the transcript (Model Calls §8). It is always
67
+ * the first entry; the entries after it are the kept tail, sent verbatim.
68
+ */
69
+ export interface TranscriptCompactionEntry {
70
+ readonly kind: "compaction";
71
+ readonly turnId: string;
72
+ readonly stepId: string;
73
+ readonly summary: string;
74
+ readonly trigger: "threshold" | "overflow";
75
+ readonly tokensBefore: number;
76
+ readonly tokensAfter: number;
77
+ }
78
+ export type TranscriptEntry = TranscriptInputEntry | TranscriptCandidateEntry | TranscriptToolsEntry | TranscriptFinalEntry | TranscriptCompactionEntry;