@nylorun/core 0.19.0-beta → 0.21.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 (98) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/README.md +2 -2
  3. package/dist/compatibility.d.ts +148 -32
  4. package/dist/compatibility.js +154 -33
  5. package/dist/contracts.d.ts +2714 -495
  6. package/dist/contracts.js +1395 -493
  7. package/dist/define.d.ts +15 -12
  8. package/dist/define.js +11 -7
  9. package/dist/definition/approval.d.ts +16 -0
  10. package/dist/definition/approval.js +33 -0
  11. package/dist/definition/assemble.d.ts +6 -10
  12. package/dist/definition/assemble.js +48 -105
  13. package/dist/definition/bind-agent.d.ts +3 -4
  14. package/dist/definition/bind-agent.js +12 -30
  15. package/dist/definition/binding.d.ts +2 -2
  16. package/dist/definition/bound.d.ts +10 -10
  17. package/dist/definition/builder.d.ts +16 -20
  18. package/dist/definition/builder.js +29 -81
  19. package/dist/definition/code-tools.d.ts +4 -4
  20. package/dist/definition/code-tools.js +7 -22
  21. package/dist/definition/declaration.d.ts +4 -7
  22. package/dist/definition/declaration.js +29 -99
  23. package/dist/definition/{tools-capability.d.ts → deferred-tools.d.ts} +3 -13
  24. package/dist/definition/{tools-capability.js → deferred-tools.js} +2 -18
  25. package/dist/definition/delegate.d.ts +2 -4
  26. package/dist/definition/delegate.js +8 -10
  27. package/dist/definition/flow/compile.js +0 -2
  28. package/dist/definition/from.d.ts +7 -4
  29. package/dist/definition/from.js +72 -117
  30. package/dist/definition/helpers.d.ts +0 -7
  31. package/dist/definition/helpers.js +0 -5
  32. package/dist/definition/http-tool.d.ts +7 -4
  33. package/dist/definition/http-tool.js +6 -10
  34. package/dist/definition/implementations.d.ts +6 -8
  35. package/dist/definition/manifest.d.ts +11 -5
  36. package/dist/definition/manifest.js +27 -26
  37. package/dist/definition/mcp.d.ts +1 -52
  38. package/dist/definition/mcp.js +11 -60
  39. package/dist/definition/media-reference.d.ts +23 -0
  40. package/dist/definition/media-reference.js +26 -0
  41. package/dist/definition/removed.d.ts +3 -10
  42. package/dist/definition/removed.js +10 -17
  43. package/dist/definition/runtime-manifest.d.ts +30 -0
  44. package/dist/definition/runtime-manifest.js +132 -0
  45. package/dist/definition/sandbox-tools.d.ts +1 -1
  46. package/dist/definition/sandbox-tools.js +1 -1
  47. package/dist/definition/skill-tools.d.ts +13 -7
  48. package/dist/definition/skill-tools.js +23 -10
  49. package/dist/definition/trace.d.ts +18 -0
  50. package/dist/definition/trace.js +42 -0
  51. package/dist/definition/variant.d.ts +5 -4
  52. package/dist/definition/variant.js +23 -55
  53. package/dist/definition/workflow/runnable.js +1 -1
  54. package/dist/errors.d.ts +1 -1
  55. package/dist/harness-api/entries.d.ts +242 -0
  56. package/dist/harness-api/entries.js +118 -0
  57. package/dist/harness-api/gates.d.ts +167 -0
  58. package/dist/harness-api/gates.js +117 -0
  59. package/dist/harness-api/harness-api.schema.json +4975 -0
  60. package/dist/harness-api/index.d.ts +19 -3
  61. package/dist/harness-api/index.js +16 -3
  62. package/dist/harness-api/json-schema.d.ts +12 -0
  63. package/dist/harness-api/json-schema.js +61 -0
  64. package/dist/harness-api/mcp.d.ts +57 -0
  65. package/dist/harness-api/mcp.js +39 -0
  66. package/dist/harness-api/messages.d.ts +11 -5
  67. package/dist/harness-api/messages.js +5 -3
  68. package/dist/harness-api/schema.d.ts +346 -36
  69. package/dist/harness-api/schema.js +143 -22
  70. package/dist/harness-api/transport.d.ts +55 -0
  71. package/dist/harness-api/transport.js +61 -0
  72. package/dist/index.d.ts +1 -1
  73. package/dist/manifest-schemas.d.ts +6 -0
  74. package/dist/manifest-schemas.js +34 -0
  75. package/dist/schemas/agent-manifest.schema.json +897 -0
  76. package/dist/schemas/environment-manifest.schema.json +329 -0
  77. package/dist/types/agent.d.ts +1 -1
  78. package/dist/types/manifest.d.ts +48 -28
  79. package/dist/types/model.d.ts +2 -2
  80. package/dist/types/observe.d.ts +8 -20
  81. package/dist/types/part.d.ts +25 -0
  82. package/dist/types/tool.d.ts +1 -1
  83. package/dist/types/transcript.d.ts +5 -0
  84. package/dist/utils/definition-files.d.ts +11 -6
  85. package/dist/utils/definition-files.js +19 -9
  86. package/dist/utils/harness-id.d.ts +9 -0
  87. package/dist/utils/harness-id.js +11 -0
  88. package/dist/utils/runtime-tools.d.ts +19 -0
  89. package/dist/utils/runtime-tools.js +30 -0
  90. package/dist/utils/sandbox.d.ts +1 -1
  91. package/dist/utils/sandbox.js +1 -1
  92. package/package.json +11 -4
  93. package/dist/definition/capability.d.ts +0 -43
  94. package/dist/definition/capability.js +0 -82
  95. package/dist/definition/sandbox-capability.d.ts +0 -44
  96. package/dist/definition/sandbox-capability.js +0 -139
  97. package/dist/types/middleware.d.ts +0 -94
  98. /package/dist/types/{middleware.js → part.js} +0 -0
@@ -3,148 +3,107 @@ import { assembleAgent } from "./assemble.js";
3
3
  import { schemaFromJSON } from "./schema-json.js";
4
4
  import { assertJson, deepFreeze } from "../utils/immutable.js";
5
5
  import { delegateFromManifest, delegateOf } from "./delegate.js";
6
- import { SKILL_TOOL_NAMES } from "./skill-tools.js";
7
6
  import { httpToolFromManifest, httpToolOf } from "./http-tool.js";
7
+ import { RUNTIME_PART_ID } from "./manifest.js";
8
+ import { ToolError } from "./tool-error.js";
8
9
  import { AgentManifestSchema } from "../contracts.js";
9
- /** Tools the engine or the Runtime runs, which need no implementation: agents and HTTP tools. */
10
- const declarative = (tool) => delegateOf(tool) !== undefined || httpToolOf(tool) !== undefined;
11
- /** Rebuild an agent from manifest JSON + in-process implementations (T28). */
10
+ /**
11
+ * Rebuild an agent from its manifest and the code of its tools, by name (T28). Agents used as
12
+ * tools and HTTP tools need no code; neither do the tools in `runtime`, which the Runtime serves.
13
+ * A session tool (`sessionTools`) is offered with the `runtime` part and needs its code.
14
+ */
12
15
  export function agentFrom(json, implementations, options) {
13
16
  const manifest = normalizeManifest(json);
14
17
  const sessionTools = options?.sessionTools ?? [];
15
18
  assertSessionTools(manifest, sessionTools);
16
- const entries = [];
17
- const dynamics = new Map();
18
- for (const capability of manifest.capabilities) {
19
- const impl = implementations[capability.id] ?? {};
20
- const tools = resolveTools(capability, impl.tools);
21
- const owned = sessionTools.filter((item) => item.capabilityId === capability.id);
22
- const instructions = [
23
- ...(capability.instructions ?? []),
24
- ...owned.flatMap((item) => item.instructions ?? []),
25
- ];
26
- const session = owned
27
- .map((item) => {
28
- const live = impl.tools?.[item.name];
29
- if (!live)
30
- throw new HarnessError("agent.build-failed", `Missing session tool implementation '${item.name}' for capability '${capability.id}'`);
31
- return live;
32
- });
33
- const handle = impl.middleware ??
34
- (async (request, next) => {
35
- const advertised = [...tools, ...session];
36
- if (advertised.length)
37
- request.configuration.tools.set(capability.id, advertised.map((tool) => (declarative(tool)
38
- ? tool
39
- : implementations[capability.id]?.tools?.[tool.name]) ?? tool));
40
- if (instructions.length > 0)
41
- request.configuration.instructions.set(capability.id, instructions);
42
- return next();
43
- });
44
- entries.push(Object.freeze({
45
- id: capability.id,
46
- ...(capability.name === undefined ? {} : { name: capability.name }),
47
- ...(capability.description === undefined
19
+ const code = implementations.tools ?? {};
20
+ const parts = [];
21
+ const own = (manifest.tools ?? []).map((declared) => authoredTool(declared, code[declared.name]));
22
+ if (own.length > 0 ||
23
+ manifest.instructions !== undefined ||
24
+ manifest.skills !== undefined ||
25
+ manifest.mcpServers !== undefined)
26
+ parts.push(Object.freeze({
27
+ id: "agent",
28
+ ...(manifest.tools === undefined ? {} : { tools: own }),
29
+ ...(manifest.instructions === undefined ? {} : { instructions: manifest.instructions }),
30
+ ...(manifest.skills === undefined ? {} : { skills: manifest.skills }),
31
+ ...(manifest.mcpServers === undefined ? {} : { mcpServers: manifest.mcpServers }),
32
+ }));
33
+ const runtime = manifest.runtime;
34
+ const session = sessionTools.map((item) => {
35
+ const live = code[item.name];
36
+ if (!live)
37
+ throw new HarnessError("agent.build-failed", `Missing session tool implementation '${item.name}'`);
38
+ return live;
39
+ });
40
+ const sessionInstructions = sessionTools.flatMap((item) => item.instructions ?? []);
41
+ if (runtime !== undefined || session.length > 0)
42
+ parts.push(Object.freeze({
43
+ id: RUNTIME_PART_ID,
44
+ ...(runtime?.tools === undefined
48
45
  ? {}
49
- : { description: capability.description }),
50
- handle,
51
- hasMiddleware: impl.middleware !== undefined,
52
- tools: capability.tools !== undefined
53
- ? tools.map((tool) => {
54
- const live = declarative(tool) ? tool : impl.tools?.[tool.name];
55
- if (!live)
56
- throw new HarnessError("agent.build-failed", `Missing tool implementation '${tool.name}' for capability '${capability.id}'`);
57
- return live;
58
- })
59
- : undefined,
46
+ : { tools: runtime.tools.map((declared) => code[declared.name] ?? runtimeTool(declared)) }),
60
47
  ...(session.length === 0 ? {} : { sessionTools: session }),
61
- contributions: Object.freeze({
62
- ...(capability.instructions
63
- ? { instructions: capability.instructions }
64
- : {}),
65
- ...(capability.tools
66
- ? {
67
- tools: capability.tools.map((tool) => Object.freeze({
68
- name: tool.name,
69
- ...(tool.description === undefined
70
- ? {}
71
- : { description: tool.description }),
72
- })),
73
- }
74
- : {}),
75
- }),
76
- manifestType: capability.type,
77
- ...(capability.metadata === undefined
78
- ? {}
79
- : { metadata: capability.metadata }),
80
- ...(capability.mcpServers === undefined
81
- ? {}
82
- : { mcpServers: capability.mcpServers }),
83
- ...(capability.sandbox === undefined
84
- ? {}
85
- : { sandbox: capability.sandbox }),
86
- ...(capability.skills === undefined
87
- ? {}
88
- : { skills: capability.skills }),
48
+ ...(runtime?.instructions === undefined ? {} : { instructions: runtime.instructions }),
49
+ ...(sessionInstructions.length === 0 ? {} : { sessionInstructions }),
89
50
  }));
90
- dynamics.set(capability.id, impl.middleware ? { middleware: impl.middleware } : {});
91
- }
92
51
  const outputSchema = manifest.outputSchema
93
52
  ? schemaFromJSON(manifest.outputSchema)
94
53
  : undefined;
95
- const result = assembleAgent(entries, {
54
+ const result = assembleAgent(parts, {
96
55
  id: manifest.id,
97
56
  name: manifest.name,
98
57
  description: manifest.description,
99
58
  metadata: manifest.metadata,
100
59
  outputSchema,
60
+ ...(manifest.requires === undefined ? {} : { requires: manifest.requires }),
101
61
  runtime: manifest.runtime,
102
- manifestSchemaVersion: manifest.manifestSchemaVersion,
103
- }, dynamics);
62
+ });
104
63
  if (!result.ok)
105
64
  throw new HarnessError("agent.build-failed", result.diagnostics.map((item) => item.message).join("; "));
106
65
  return result.agent;
107
66
  }
108
67
  function assertSessionTools(manifest, sessionTools) {
68
+ const taken = new Set([
69
+ ...(manifest.tools ?? []).map((tool) => tool.name),
70
+ ...(manifest.runtime?.tools ?? []).map((tool) => tool.name),
71
+ ]);
109
72
  const seen = new Set();
110
73
  for (const item of sessionTools) {
111
74
  if (seen.has(item.name))
112
75
  throw new HarnessError("agent.build-failed", `Duplicate session tool '${item.name}'`);
113
76
  seen.add(item.name);
114
- const capability = manifest.capabilities.find((entry) => entry.id === item.capabilityId);
115
- if (!capability)
116
- throw new HarnessError("agent.build-failed", `Session tool '${item.name}' references unknown capability '${item.capabilityId}'`);
117
- if (capability.tools?.some((tool) => tool.name === item.name))
77
+ if (taken.has(item.name))
118
78
  throw new HarnessError("agent.build-failed", `Session tool '${item.name}' collides with a declared tool`);
119
79
  }
120
80
  }
121
- function resolveTools(capability, tools) {
122
- if (!capability.tools?.length)
123
- return [];
124
- return capability.tools.flatMap((declared) => {
125
- const live = tools?.[declared.name];
126
- // The engine runs agents used as tools; an authored delegate keeps its local child.
127
- if (declared.agent)
128
- return [
129
- live && delegateOf(live)?.manifest.id === declared.agent.id
130
- ? live
131
- : delegateFromManifest(declared.agent, declared),
132
- ];
133
- // The Runtime runs HTTP tools; a host's own (its engine's routing) is kept.
134
- if (declared.http)
135
- return [
136
- live && httpToolOf(live)
137
- ? live
138
- : httpToolFromManifest({ ...declared, http: declared.http }),
139
- ];
140
- if (live)
141
- return [live];
142
- // The build attaches the skill tools again; the Runtime serves them.
143
- if (SKILL_TOOL_NAMES.has(declared.name) &&
144
- capability.skills &&
145
- Object.keys(capability.skills).length > 0)
146
- return [];
147
- throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}' for capability '${capability.id}'`);
81
+ /**
82
+ * An authored tool: the engine runs agents used as tools (an authored delegate keeps its local
83
+ * child), the Runtime runs HTTP tools (a host's own keeps its routing), and any other tool is the
84
+ * caller's code.
85
+ */
86
+ function authoredTool(declared, live) {
87
+ if (declared.agent)
88
+ return live && delegateOf(live)?.manifest.id === declared.agent.id
89
+ ? live
90
+ : delegateFromManifest(declared.agent, declared);
91
+ if (declared.http)
92
+ return live && httpToolOf(live) ? live : httpToolFromManifest({ ...declared, http: declared.http });
93
+ if (live)
94
+ return live;
95
+ throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}'`);
96
+ }
97
+ /** A tool the Runtime serves, as a process without a Runtime sees it: calling it says so. */
98
+ function runtimeTool(declared) {
99
+ return Object.freeze({
100
+ name: declared.name,
101
+ ...(declared.description === undefined ? {} : { description: declared.description }),
102
+ inputSchema: schemaFromJSON(declared.inputSchema),
103
+ ...(declared.outputSchema === undefined ? {} : { outputSchema: schemaFromJSON(declared.outputSchema) }),
104
+ async execute() {
105
+ throw new ToolError("tool.runtime-only", `'${declared.name}' runs in the Nylorun Runtime. Connect the agent to a Runtime to use it.`);
106
+ },
148
107
  });
149
108
  }
150
109
  /**
@@ -163,11 +122,7 @@ function normalizeManifest(json) {
163
122
  .join("; "));
164
123
  // The schema checks no value of a JSON object; metadata must be JSON data, as before.
165
124
  const manifest = parsed.data;
166
- for (const metadata of [
167
- manifest.metadata,
168
- ...manifest.capabilities.map((capability) => capability.metadata),
169
- ])
170
- if (metadata !== undefined)
171
- assertJson(metadata, "metadata");
125
+ if (manifest.metadata !== undefined)
126
+ assertJson(manifest.metadata, "metadata");
172
127
  return deepFreeze(JSON.parse(JSON.stringify(manifest)));
173
128
  }
@@ -1,10 +1,3 @@
1
- import type { ModelAdapter } from "../types/model.js";
2
- import type { StepMiddleware } from "../types/middleware.js";
3
1
  import type { ToolDefinition, ToolInputSchema, ToolOutputSchema, ToolSchemaSource } from "../types/tool.js";
4
2
  export declare const tool: <InputSchema extends ToolInputSchema, Info = unknown, OutputSchema extends ToolOutputSchema | undefined = undefined>(value: ToolDefinition<InputSchema, Info, OutputSchema>) => ToolDefinition<InputSchema, Info, OutputSchema>;
5
- /** @deprecated Prefer Runtime model resolution. Capability-disguised `.use({ model })` is not the taught path. */
6
- export declare const model: <T extends ModelAdapter>(value: T) => T;
7
- /** @deprecated Runs in the local engine only. Kept through 1.0. */
8
- export declare const middleware: <T extends StepMiddleware>(value: T) => T;
9
- export { capability } from "./capability.js";
10
3
  export type { ToolSchemaSource };
@@ -1,7 +1,2 @@
1
1
  import { prepareTool } from "./schema.js";
2
2
  export const tool = (value) => prepareTool(value);
3
- /** @deprecated Prefer Runtime model resolution. Capability-disguised `.use({ model })` is not the taught path. */
4
- export const model = (value) => value;
5
- /** @deprecated Runs in the local engine only. Kept through 1.0. */
6
- export const middleware = (value) => value;
7
- export { capability } from "./capability.js";
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * HTTP tools (R2 M3): a tool the manifest describes as one HTTP request, which the Runtime makes
3
3
  * itself through its Tool Gate. No developer code runs for it: the tool value carries its target
4
- * (`http`) and static approval into the manifest, and its `execute` only says where it runs.
4
+ * (`http`) into the manifest, and its `execute` only says where it runs. Whether a call waits for
5
+ * a person is the Tenant's tool policy, decided at the Tool Gate (R5 step 2), never the tool's.
5
6
  * An HTTP tool is also a flow stage. `http({ url })` without a name and an input is a bare
6
7
  * target, a Loop's HTTP verifier: its manifest form is itself, `{ http: { url, … } }`.
7
8
  */
@@ -18,6 +19,11 @@ export declare const HTTP_TOOL_MAX_TIMEOUT_MS = 300000;
18
19
  /** What an HTTP tool puts in its manifest entry besides its name and schemas. */
19
20
  export interface HttpTool {
20
21
  readonly http: HttpToolTarget;
22
+ /**
23
+ * @deprecated A pinned manifest's `approval`, from before R5 step 2: kept so the rebuilt
24
+ * definition hashes as pinned, and held by the Tool Gate. Nothing asks for it here, and
25
+ * `http()` refuses it.
26
+ */
21
27
  readonly approval?: ApprovalMode;
22
28
  }
23
29
  export interface HttpToolOptions<InputSchema extends ToolInputSchema | JsonObject = ToolInputSchema, OutputSchema extends ToolOutputSchema | JsonObject | undefined = undefined> extends HttpToolTarget {
@@ -27,8 +33,6 @@ export interface HttpToolOptions<InputSchema extends ToolInputSchema | JsonObjec
27
33
  readonly input: InputSchema;
28
34
  /** Checked against the answer; a mismatch is a tool error the model sees. */
29
35
  readonly output?: OutputSchema;
30
- /** `always`: each call waits for approval. Default `never`. */
31
- readonly approval?: ApprovalMode;
32
36
  }
33
37
  /** A bare HTTP target: a Loop's HTTP verifier, `.loop(body, { verify: http({ url }), max })`. */
34
38
  export interface HttpTarget {
@@ -54,7 +58,6 @@ export declare function httpToolFromManifest(declared: ToolManifest & {
54
58
  /**
55
59
  * Marks `tool` as an HTTP tool. A host gives its own `execute` (the Runtime's engine routes the
56
60
  * call to its Tool Gate); without one, calling it explains that only the Runtime runs it.
57
- * `approval: "always"` makes each call wait for approval.
58
61
  */
59
62
  export declare function withHttpTarget(tool: Omit<AnyTool, "execute"> & Pick<Partial<AnyTool>, "execute">, target: HttpTool): AnyTool;
60
63
  /** The HTTP target behind a tool definition, or behind the bound snapshot of one. */
@@ -1,3 +1,4 @@
1
+ import { APPROVAL_REMOVED } from "./approval.js";
1
2
  import { HarnessError } from "../errors.js";
2
3
  import { ToolError } from "./tool-error.js";
3
4
  import { prepareTool } from "./schema.js";
@@ -14,9 +15,11 @@ export const HTTP_TOOL_MAX_TIMEOUT_MS = 300_000;
14
15
  export function http(options) {
15
16
  if (!("name" in options) && !("input" in options))
16
17
  return httpTarget(options);
17
- const { name, description, input, output, approval } = options;
18
+ const { name, description, input, output } = options;
18
19
  const target = targetOf(options);
19
- const issue = (input === undefined ? "input is required" : undefined) ?? httpTargetIssue(target) ?? approvalIssue(approval);
20
+ const issue = (input === undefined ? "input is required" : undefined) ??
21
+ httpTargetIssue(target) ??
22
+ ("approval" in options ? APPROVAL_REMOVED : undefined);
20
23
  if (issue)
21
24
  throw new HarnessError("tool.invalid", `HTTP tool '${name}': ${issue}`);
22
25
  return prepareTool(withHttpTarget({
@@ -24,7 +27,7 @@ export function http(options) {
24
27
  ...(description === undefined ? {} : { description }),
25
28
  inputSchema: schemaSource(input),
26
29
  ...(output === undefined ? {} : { outputSchema: schemaSource(output) }),
27
- }, { http: target, ...(approval === undefined ? {} : { approval }) }));
30
+ }, { http: target }));
28
31
  }
29
32
  function targetOf({ url, method, credential, timeoutMs }) {
30
33
  return {
@@ -63,13 +66,11 @@ export function httpToolFromManifest(declared) {
63
66
  /**
64
67
  * Marks `tool` as an HTTP tool. A host gives its own `execute` (the Runtime's engine routes the
65
68
  * call to its Tool Gate); without one, calling it explains that only the Runtime runs it.
66
- * `approval: "always"` makes each call wait for approval.
67
69
  */
68
70
  export function withHttpTarget(tool, target) {
69
71
  const definition = {
70
72
  ...tool,
71
73
  execute: tool.execute ?? runtimeOnly,
72
- ...(target.approval === "always" ? { approval: () => true } : {}),
73
74
  };
74
75
  Object.defineProperty(definition, HTTP, {
75
76
  value: Object.freeze({ http: Object.freeze({ ...target.http }), ...(target.approval ? { approval: target.approval } : {}) }),
@@ -115,11 +116,6 @@ export function httpUrlIssue(url) {
115
116
  return "url must not have a fragment";
116
117
  return undefined;
117
118
  }
118
- function approvalIssue(approval) {
119
- return approval === undefined || APPROVAL_MODES.includes(approval)
120
- ? undefined
121
- : `approval must be one of ${APPROVAL_MODES.join(", ")}`;
122
- }
123
119
  async function runtimeOnly() {
124
120
  throw new ToolError("http.runtime-only", "HTTP tools are run by the Nylorun Runtime, not in this process");
125
121
  }
@@ -1,13 +1,11 @@
1
1
  import type { ToolDefinition } from "../types/tool.js";
2
- import type { StepMiddleware } from "../types/middleware.js";
3
- /** In-process implementations table keyed by capability id (never serialized). */
2
+ /**
3
+ * The code of an agent's tools, by tool name, for `Agent.from(manifest, implementations)` (never
4
+ * serialized). Agents used as tools, HTTP tools and the Runtime's tools need none.
5
+ */
4
6
  export interface Implementations<Info = unknown> {
5
- readonly [capabilityId: string]: {
6
- readonly tools?: {
7
- readonly [toolName: string]: ToolDefinition<any, Info, any>;
8
- };
9
- /** @deprecated Local engine only through 1.0. */
10
- readonly middleware?: StepMiddleware<Info>;
7
+ readonly tools?: {
8
+ readonly [toolName: string]: ToolDefinition<any, Info, any>;
11
9
  };
12
10
  }
13
11
  export declare function emptyImplementations(): Implementations;
@@ -1,15 +1,21 @@
1
- import type { BoundMiddleware } from "./bound.js";
2
- import type { AgentManifest, ManifestSchemaVersion, RuntimeManifest } from "../types/manifest.js";
1
+ import type { DefinitionPart } from "./bound.js";
2
+ import type { AgentManifest, AgentRequirements, RuntimeManifest } from "../types/manifest.js";
3
3
  import type { JsonObject } from "../types/shared.js";
4
4
  import type { ToolSchemaSource } from "../types/tool.js";
5
+ /** The id of the part an agent rebuilt from a pinned manifest gets for its `runtime` block. */
6
+ export declare const RUNTIME_PART_ID = "runtime";
7
+ /**
8
+ * The agent's manifest (v7): its parts merged in order, the instructions and tools concatenated,
9
+ * the skills and servers keyed by name. The `runtime` part is not projected: `runtime` comes as
10
+ * it was pinned.
11
+ */
5
12
  export declare function createManifest(input: {
6
13
  id: string;
7
14
  name?: string;
8
15
  description?: string;
9
16
  metadata?: JsonObject;
10
17
  outputSchema?: ToolSchemaSource;
18
+ requires?: AgentRequirements;
11
19
  runtime?: RuntimeManifest;
12
- middleware: readonly BoundMiddleware[];
13
- /** The version a manifest rebuilt from JSON had; it never goes below what the capabilities need. */
14
- manifestSchemaVersion?: ManifestSchemaVersion;
20
+ parts: readonly DefinitionPart[];
15
21
  }): AgentManifest;
@@ -2,14 +2,26 @@ import { bindOutputContract } from "./output-contract.js";
2
2
  import { normalizedSchemasFor } from "./schema.js";
3
3
  import { delegateOf } from "./delegate.js";
4
4
  import { httpToolOf } from "./http-tool.js";
5
- import { manifestVersionFor } from "./mcp.js";
6
5
  import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
6
+ /** The id of the part an agent rebuilt from a pinned manifest gets for its `runtime` block. */
7
+ export const RUNTIME_PART_ID = "runtime";
8
+ /**
9
+ * The agent's manifest (v7): its parts merged in order, the instructions and tools concatenated,
10
+ * the skills and servers keyed by name. The `runtime` part is not projected: `runtime` comes as
11
+ * it was pinned.
12
+ */
7
13
  export function createManifest(input) {
8
- const capabilities = input.middleware.map((item) => projectCapability(item));
9
- // 6 only when an MCP server sets `tools` or `deferred` (R2b C9), so other hashes stay.
10
- const needed = manifestVersionFor(capabilities);
14
+ const authored = input.parts.filter((part) => part.id !== RUNTIME_PART_ID);
15
+ const instructions = authored.flatMap((part) => part.instructions ?? []);
16
+ const tools = authored.flatMap((part) => (part.tools ?? []).map((tool) => projectTool(tool)));
17
+ const skills = {};
18
+ const mcpServers = {};
19
+ for (const part of authored) {
20
+ Object.assign(skills, part.skills ?? {});
21
+ Object.assign(mcpServers, part.mcpServers ?? {});
22
+ }
11
23
  return deepFreeze({
12
- manifestSchemaVersion: Math.max(needed, input.manifestSchemaVersion ?? needed),
24
+ manifestSchemaVersion: 7,
13
25
  id: input.id,
14
26
  ...(input.name === undefined ? {} : { name: input.name }),
15
27
  ...(input.description === undefined
@@ -24,31 +36,19 @@ export function createManifest(input) {
24
36
  outputSchema: bindOutputContract(input.outputSchema).schema
25
37
  .jsonSchema,
26
38
  }),
27
- capabilities,
39
+ ...(instructions.length === 0 ? {} : { instructions }),
40
+ ...(tools.length === 0 ? {} : { tools }),
41
+ ...(Object.keys(skills).length === 0 ? {} : { skills }),
42
+ ...(Object.keys(mcpServers).length === 0 ? {} : { mcpServers }),
43
+ ...(input.requires === undefined ? {} : { requires: copyRequirements(input.requires) }),
28
44
  ...(input.runtime === undefined ? {} : { runtime: input.runtime }),
29
45
  });
30
46
  }
31
- function projectCapability(item) {
32
- const contributions = item.contributions;
47
+ /** `requires` as plain data, its secret names sorted and each once. */
48
+ function copyRequirements(requires) {
33
49
  return {
34
- id: item.id,
35
- type: item.manifestType ?? "agent",
36
- ...(item.name === undefined ? {} : { name: item.name }),
37
- ...(item.description === undefined ? {} : { description: item.description }),
38
- ...(item.metadata === undefined
39
- ? {}
40
- : { metadata: copyJsonObject(item.metadata, "metadata") }),
41
- ...(contributions?.instructions === undefined
42
- ? {}
43
- : { instructions: contributions.instructions }),
44
- ...(item.tools === undefined
45
- ? {}
46
- : { tools: item.tools.map((tool) => projectTool(tool)) }),
47
- ...(item.skills === undefined ? {} : { skills: item.skills }),
48
- ...(item.mcpServers === undefined ? {} : { mcpServers: item.mcpServers }),
49
- ...(item.sandbox === undefined
50
- ? {}
51
- : { sandbox: copyJsonObject(item.sandbox, "sandbox") }),
50
+ ...(requires.sandbox === undefined ? {} : { sandbox: requires.sandbox }),
51
+ ...(requires.secrets === undefined ? {} : { secrets: [...new Set(requires.secrets)].sort() }),
52
52
  };
53
53
  }
54
54
  function projectTool(tool) {
@@ -66,6 +66,7 @@ function projectTool(tool) {
66
66
  : { outputSchema: schemas.outputSchema.jsonSchema }),
67
67
  ...(delegate === undefined ? {} : { agent: delegate.manifest }),
68
68
  ...(http === undefined ? {} : { http: { ...http.http } }),
69
+ // A pinned manifest's, from before R5 step 2: identity only.
69
70
  ...(http?.approval === undefined ? {} : { approval: http.approval }),
70
71
  };
71
72
  }
@@ -1,5 +1,4 @@
1
- import type { CapabilityDeclaration } from "../types/middleware.js";
2
- import type { ApprovalMode, ManifestSchemaVersion, McpServerManifest } from "../types/manifest.js";
1
+ import type { ApprovalMode, McpServerManifest } from "../types/manifest.js";
3
2
  type WithOptionalName<T> = T extends {
4
3
  readonly name: string;
5
4
  } ? Omit<T, "name"> & {
@@ -7,49 +6,10 @@ type WithOptionalName<T> = T extends {
7
6
  } : never;
8
7
  /** An MCP server as written by an author: `name` defaults to the server's key. */
9
8
  export type McpServerSpec = WithOptionalName<McpServerManifest>;
10
- export interface McpOptions {
11
- /** Capability id. Defaults to `"mcp"`. */
12
- readonly id?: string;
13
- }
14
- export interface McpCapability extends CapabilityDeclaration {
15
- readonly mcpServers: Readonly<Record<string, McpServerManifest>>;
16
- }
17
9
  export declare class McpError extends Error {
18
10
  readonly code: string;
19
11
  constructor(code: string, message: string);
20
12
  }
21
- /**
22
- * Declare MCP servers as one capability.
23
- *
24
- * Prefer `Agent(...).mcp({ ... })`. Each key names a server; its `name` defaults to
25
- * the key and, when given, must equal it. Nylorun accepts remote servers only:
26
- * `streamable-http` and `sse` (see https://agent-plugins.org/plugin-authors/mcp-servers).
27
- *
28
- * ```ts
29
- * Agent({ id: "assistant" }).mcp({
30
- * github: { type: "streamable-http", url: "https://mcp.example.com/github" },
31
- * })
32
- * ```
33
- *
34
- * `tools` sets tools by the server's own names, with `"*"` for the rest: an allowlist, approval
35
- * per tool, deferral per tool (R2b C9, C10). `deferred` defers every tool of the server. Either
36
- * makes the manifest v6.
37
- *
38
- * ```ts
39
- * Agent({ id: "assistant" }).mcp({
40
- * github: {
41
- * type: "streamable-http",
42
- * url: "https://api.githubcopilot.com/mcp/",
43
- * tools: {
44
- * "*": { enabled: false },
45
- * search_issues: { enabled: true },
46
- * create_issue: { enabled: true, approval: "always" },
47
- * },
48
- * },
49
- * })
50
- * ```
51
- */
52
- export declare function mcp(servers: Readonly<Record<string, McpServerSpec>>, options?: McpOptions): McpCapability;
53
13
  /** Why a `stdio` MCP server is refused: the one message the builder, plugins and manifests give. */
54
14
  export declare function stdioMcpRefusal(name: string): string;
55
15
  /** Validate a map of MCP servers and fill each `name` from its key. */
@@ -69,15 +29,4 @@ export interface ResolvedMcpToolSettings {
69
29
  * (enabled, approval `never`, deferral automatic).
70
30
  */
71
31
  export declare function mcpToolSettings(server: McpServerManifest, serverToolName: string): ResolvedMcpToolSettings;
72
- /** True when the server sets `tools` or `deferred`, which need manifest v6 (R2b C9, Q19). */
73
- export declare function usesMcpToolSettings(server: McpServerManifest): boolean;
74
- /** Why a manifest v5 with this server is refused (R2b C9, Q19). */
75
- export declare function mcpToolSettingsVersionIssue(serverName: string): string;
76
- /**
77
- * The manifest version a definition with these capabilities needs: 6 when an MCP server sets
78
- * `tools` or `deferred`, else 5, so a manifest that uses neither keeps its hash (Q19).
79
- */
80
- export declare function manifestVersionFor(capabilities: readonly {
81
- readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
82
- }[]): ManifestSchemaVersion;
83
32
  export {};