@nylorun/core 0.1.1-beta → 0.2.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.
@@ -55,9 +55,6 @@ export class AgentBuilder {
55
55
  get manifest() {
56
56
  return this.ensure().manifest;
57
57
  }
58
- get hash() {
59
- return this.ensure().hash;
60
- }
61
58
  toJSON() {
62
59
  return this.ensure().toJSON();
63
60
  }
@@ -144,6 +141,8 @@ export class AgentBuilder {
144
141
  const result = assembleAgent(this.#snapshot.entries, {
145
142
  id: this.#snapshot.id,
146
143
  name: this.#snapshot.name,
144
+ description: this.#snapshot.description,
145
+ metadata: this.#snapshot.metadata,
147
146
  outputSchema: this.#snapshot.outputSchema,
148
147
  }, this.#snapshot.dynamics);
149
148
  if (!result.ok) {
@@ -173,7 +172,11 @@ function createSnapshot(options) {
173
172
  }
174
173
  return {
175
174
  id: options.id,
176
- name: options.name,
175
+ ...(options.name === undefined ? {} : { name: options.name }),
176
+ ...(options.description === undefined
177
+ ? {}
178
+ : { description: options.description }),
179
+ ...(options.metadata === undefined ? {} : { metadata: options.metadata }),
177
180
  outputSchema: options.outputSchema,
178
181
  entries: Object.freeze(entries),
179
182
  dynamics,
@@ -17,12 +17,35 @@ export function compileDeclaration(declaration) {
17
17
  return {
18
18
  bound: {
19
19
  id: declaration.id,
20
+ ...(declaration.name === undefined ? {} : { name: declaration.name }),
21
+ ...(declaration.description === undefined
22
+ ? {}
23
+ : { description: declaration.description }),
20
24
  handle,
21
25
  hasMiddleware: declaration.middleware !== undefined,
22
26
  tools: tools?.items,
23
27
  ...(contributions === undefined ? {} : { contributions }),
24
28
  ...(declaration.beforeModelCall ? { beforeModelCall: true } : {}),
25
29
  ...(declaration.afterModelCall ? { afterModelCall: true } : {}),
30
+ ...(declaration.type === undefined ? {} : { manifestType: declaration.type }),
31
+ ...(declaration.metadata === undefined
32
+ ? {}
33
+ : { metadata: declaration.metadata }),
34
+ ...(declaration.skills === undefined ||
35
+ Object.keys(declaration.skills).length === 0
36
+ ? {}
37
+ : { skills: declaration.skills }),
38
+ ...(declaration.skillRecords === undefined ||
39
+ Object.keys(declaration.skillRecords).length === 0
40
+ ? {}
41
+ : { skillRecords: declaration.skillRecords }),
42
+ ...(declaration.mcpServers === undefined ||
43
+ Object.keys(declaration.mcpServers).length === 0
44
+ ? {}
45
+ : { mcpServers: declaration.mcpServers }),
46
+ ...(declaration.pluginRoot === undefined
47
+ ? {}
48
+ : { pluginRoot: declaration.pluginRoot }),
26
49
  },
27
50
  ...(declaration.beforeModelCall
28
51
  ? { beforeModelCall: declaration.beforeModelCall }
@@ -2,5 +2,12 @@ import type { AgentManifest } from "../types/manifest.js";
2
2
  import type { BuiltAgent } from "../types/agent.js";
3
3
  import type { JsonObject } from "../types/shared.js";
4
4
  import type { Implementations } from "./implementations.js";
5
+ /** A tool that exists for one execution and is not part of the hashed manifest. */
6
+ export interface SessionToolRef {
7
+ readonly capabilityId: string;
8
+ readonly name: string;
9
+ }
5
10
  /** Rebuild an agent from manifest JSON + in-process implementations (T28). */
6
- export declare function agentFrom<Info = unknown>(json: AgentManifest | JsonObject, implementations: Implementations<Info>): BuiltAgent<Info>;
11
+ export declare function agentFrom<Info = unknown>(json: AgentManifest | JsonObject, implementations: Implementations<Info>, options?: {
12
+ readonly sessionTools?: readonly SessionToolRef[];
13
+ }): BuiltAgent<Info>;
@@ -1,31 +1,46 @@
1
1
  import { HarnessError } from "../errors.js";
2
2
  import { assembleAgent } from "./assemble.js";
3
3
  import { schemaFromJSON } from "./schema-json.js";
4
- import { deepFreeze } from "../utils/immutable.js";
4
+ import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
5
5
  /** Rebuild an agent from manifest JSON + in-process implementations (T28). */
6
- export function agentFrom(json, implementations) {
6
+ export function agentFrom(json, implementations, options) {
7
7
  const manifest = normalizeManifest(json);
8
+ const sessionTools = options?.sessionTools ?? [];
9
+ assertSessionTools(manifest, sessionTools);
8
10
  const entries = [];
9
11
  const dynamics = new Map();
10
12
  for (const capability of manifest.capabilities) {
11
13
  const impl = implementations[capability.id] ?? {};
12
14
  const tools = resolveTools(capability, impl.tools);
15
+ const session = sessionTools
16
+ .filter((item) => item.capabilityId === capability.id)
17
+ .map((item) => {
18
+ const live = impl.tools?.[item.name];
19
+ if (!live)
20
+ throw new HarnessError("agent.build-failed", `Missing session tool implementation '${item.name}' for capability '${capability.id}'`);
21
+ return live;
22
+ });
13
23
  if (capability.beforeModelCall && !impl.beforeModelCall)
14
24
  throw new HarnessError("agent.build-failed", `Missing beforeModelCall implementation for capability '${capability.id}'`);
15
25
  if (capability.afterModelCall && !impl.afterModelCall)
16
26
  throw new HarnessError("agent.build-failed", `Missing afterModelCall implementation for capability '${capability.id}'`);
17
27
  const handle = impl.middleware ??
18
28
  (async (request, next) => {
19
- if (tools.length)
20
- request.configuration.tools.set(capability.id, tools.map((tool) => implementations[capability.id]?.tools?.[tool.name] ?? tool));
29
+ const advertised = [...tools, ...session];
30
+ if (advertised.length)
31
+ request.configuration.tools.set(capability.id, advertised.map((tool) => implementations[capability.id]?.tools?.[tool.name] ?? tool));
21
32
  if (capability.instructions)
22
33
  request.configuration.instructions.set(capability.id, capability.instructions);
23
34
  return next();
24
35
  });
25
36
  entries.push(Object.freeze({
26
37
  id: capability.id,
38
+ ...(capability.name === undefined ? {} : { name: capability.name }),
39
+ ...(capability.description === undefined
40
+ ? {}
41
+ : { description: capability.description }),
27
42
  handle,
28
- hasMiddleware: impl.middleware !== undefined || capability.hasMiddleware,
43
+ hasMiddleware: impl.middleware !== undefined,
29
44
  tools: capability.tools !== undefined
30
45
  ? tools.map((tool) => {
31
46
  const live = impl.tools?.[tool.name];
@@ -34,6 +49,7 @@ export function agentFrom(json, implementations) {
34
49
  return live;
35
50
  })
36
51
  : undefined,
52
+ ...(session.length === 0 ? {} : { sessionTools: session }),
37
53
  contributions: Object.freeze({
38
54
  ...(capability.instructions
39
55
  ? { instructions: capability.instructions }
@@ -51,6 +67,16 @@ export function agentFrom(json, implementations) {
51
67
  }),
52
68
  ...(capability.beforeModelCall ? { beforeModelCall: true } : {}),
53
69
  ...(capability.afterModelCall ? { afterModelCall: true } : {}),
70
+ manifestType: capability.type,
71
+ ...(capability.metadata === undefined
72
+ ? {}
73
+ : { metadata: capability.metadata }),
74
+ ...(capability.mcpServers === undefined
75
+ ? {}
76
+ : { mcpServers: capability.mcpServers }),
77
+ ...(capability.skills === undefined
78
+ ? {}
79
+ : { skills: capability.skills }),
54
80
  }));
55
81
  dynamics.set(capability.id, {
56
82
  ...(impl.beforeModelCall
@@ -65,19 +91,43 @@ export function agentFrom(json, implementations) {
65
91
  const outputSchema = manifest.outputSchema
66
92
  ? schemaFromJSON(manifest.outputSchema)
67
93
  : undefined;
68
- const result = assembleAgent(entries, { id: manifest.id, name: manifest.name, outputSchema }, dynamics);
94
+ const result = assembleAgent(entries, {
95
+ id: manifest.id,
96
+ name: manifest.name,
97
+ description: manifest.description,
98
+ metadata: manifest.metadata,
99
+ outputSchema,
100
+ runtime: manifest.runtime,
101
+ }, dynamics);
69
102
  if (!result.ok)
70
103
  throw new HarnessError("agent.build-failed", result.diagnostics.map((item) => item.message).join("; "));
71
104
  return result.agent;
72
105
  }
106
+ function assertSessionTools(manifest, sessionTools) {
107
+ const seen = new Set();
108
+ for (const item of sessionTools) {
109
+ if (seen.has(item.name))
110
+ throw new HarnessError("agent.build-failed", `Duplicate session tool '${item.name}'`);
111
+ seen.add(item.name);
112
+ const capability = manifest.capabilities.find((entry) => entry.id === item.capabilityId);
113
+ if (!capability)
114
+ throw new HarnessError("agent.build-failed", `Session tool '${item.name}' references unknown capability '${item.capabilityId}'`);
115
+ if (capability.tools?.some((tool) => tool.name === item.name))
116
+ throw new HarnessError("agent.build-failed", `Session tool '${item.name}' collides with a declared tool`);
117
+ }
118
+ }
73
119
  function resolveTools(capability, tools) {
74
120
  if (!capability.tools?.length)
75
121
  return [];
76
- return capability.tools.map((tool) => {
77
- const live = tools?.[tool.name];
78
- if (!live)
79
- throw new HarnessError("agent.build-failed", `Missing tool implementation '${tool.name}' for capability '${capability.id}'`);
80
- return live;
122
+ return capability.tools.flatMap((declared) => {
123
+ const live = tools?.[declared.name];
124
+ if (live)
125
+ return [live];
126
+ if ((declared.name === "load_skill" || declared.name === "read_skill_resource") &&
127
+ capability.skills &&
128
+ Object.keys(capability.skills).length > 0)
129
+ return [];
130
+ throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}' for capability '${capability.id}'`);
81
131
  });
82
132
  }
83
133
  function normalizeManifest(json) {
@@ -86,41 +136,150 @@ function normalizeManifest(json) {
86
136
  const value = json;
87
137
  if (typeof value.id !== "string" || !value.id)
88
138
  throw new HarnessError("agent.build-failed", "Manifest id must be a non-empty string");
89
- if (typeof value.name !== "string" || !value.name)
90
- throw new HarnessError("agent.build-failed", "Manifest name must be a non-empty string");
139
+ if ("name" in value && value.name !== undefined) {
140
+ if (typeof value.name !== "string" || !value.name)
141
+ throw new HarnessError("agent.build-failed", "Manifest name must be a non-empty string");
142
+ }
91
143
  if (!Array.isArray(value.capabilities))
92
144
  throw new HarnessError("agent.build-failed", "Manifest capabilities must be an array");
93
- const schemaVersion = value.schemaVersion === undefined ? 2 : value.schemaVersion;
94
- if (schemaVersion !== 2)
95
- throw new HarnessError("agent.build-failed", `Unsupported manifest schemaVersion ${schemaVersion}`);
145
+ if ("schemaVersion" in value && value.schemaVersion !== undefined)
146
+ throw new HarnessError("agent.build-failed", "Manifest field schemaVersion was renamed to manifestSchemaVersion");
147
+ if (value.manifestSchemaVersion !== 3)
148
+ throw new HarnessError("agent.build-failed", `Unsupported manifestSchemaVersion ${String(value.manifestSchemaVersion)}`);
96
149
  // Reject top-level model (Runtime-owned).
97
150
  if ("model" in value && value.model !== undefined)
98
151
  throw new HarnessError("agent.build-failed", "Manifest must not include top-level model; Runtime owns model resolution");
152
+ if ("description" in value && value.description !== undefined) {
153
+ if (typeof value.description !== "string")
154
+ throw new HarnessError("agent.build-failed", "Manifest description must be a string");
155
+ }
156
+ const metadata = "metadata" in value && value.metadata !== undefined
157
+ ? copyJsonObject(value.metadata, "metadata")
158
+ : undefined;
159
+ const runtime = normalizeRuntime(value.runtime);
160
+ const capabilities = value.capabilities.map(normalizeCapability);
161
+ const servers = new Set();
162
+ for (const capability of capabilities)
163
+ for (const name of Object.keys(capability.mcpServers ?? {})) {
164
+ if (servers.has(name))
165
+ throw new HarnessError("agent.build-failed", `Duplicate MCP server '${name}'`);
166
+ servers.add(name);
167
+ }
99
168
  return deepFreeze({
100
- schemaVersion: 2,
169
+ manifestSchemaVersion: 3,
101
170
  id: value.id,
102
- name: value.name,
171
+ ...(typeof value.name === "string" && value.name ? { name: value.name } : {}),
172
+ ...(typeof value.description === "string"
173
+ ? { description: value.description }
174
+ : {}),
175
+ ...(metadata === undefined ? {} : { metadata }),
103
176
  ...(value.outputSchema && typeof value.outputSchema === "object"
104
177
  ? { outputSchema: value.outputSchema }
105
178
  : {}),
106
- capabilities: value.capabilities.map(normalizeCapability),
179
+ capabilities,
180
+ ...(runtime === undefined ? {} : { runtime }),
107
181
  });
108
182
  }
183
+ function normalizeRuntime(value) {
184
+ if (value === undefined)
185
+ return undefined;
186
+ if (!value ||
187
+ typeof value !== "object" ||
188
+ Array.isArray(value) ||
189
+ Object.keys(value).length > 0)
190
+ throw new HarnessError("agent.build-failed", "runtime must be an empty object when present");
191
+ return {};
192
+ }
109
193
  function normalizeCapability(capability) {
194
+ const raw = capability;
195
+ if ("name" in raw && raw.name !== undefined) {
196
+ if (typeof raw.name !== "string" || !raw.name)
197
+ throw new HarnessError("agent.build-failed", `Capability '${capability.id}' name must be a non-empty string`);
198
+ }
199
+ if ("description" in raw && raw.description !== undefined) {
200
+ if (typeof raw.description !== "string")
201
+ throw new HarnessError("agent.build-failed", `Capability '${capability.id}' description must be a string`);
202
+ }
203
+ if ("model" in raw && raw.model !== undefined)
204
+ throw new HarnessError("agent.build-failed", `Capability '${capability.id}' must not include model; Runtime owns model resolution`);
205
+ if (capability.type !== "agent" && capability.type !== "agent-plugin")
206
+ throw new HarnessError("agent.build-failed", `Capability '${capability.id}' type must be agent or agent-plugin`);
207
+ const metadata = capability.metadata === undefined
208
+ ? undefined
209
+ : copyJsonObject(capability.metadata, "metadata");
210
+ const mcpServers = normalizeMcpServers(capability.id, capability.mcpServers);
211
+ const skills = normalizeSkills(capability.id, capability.skills);
110
212
  return Object.freeze({
111
213
  id: capability.id,
112
- kind: capability.kind ?? "capability",
113
- hasMiddleware: capability.hasMiddleware ?? false,
214
+ type: capability.type,
215
+ ...(typeof raw.name === "string" && raw.name ? { name: raw.name } : {}),
216
+ ...(typeof raw.description === "string"
217
+ ? { description: raw.description }
218
+ : {}),
219
+ ...(metadata === undefined ? {} : { metadata }),
114
220
  ...(capability.instructions
115
221
  ? { instructions: Object.freeze([...capability.instructions]) }
116
222
  : {}),
117
223
  ...(capability.tools
118
224
  ? { tools: Object.freeze(capability.tools.map(normalizeTool)) }
119
225
  : {}),
226
+ ...(skills === undefined ? {} : { skills }),
227
+ ...(mcpServers === undefined ? {} : { mcpServers }),
120
228
  ...(capability.beforeModelCall ? { beforeModelCall: true } : {}),
121
229
  ...(capability.afterModelCall ? { afterModelCall: true } : {}),
122
230
  });
123
231
  }
232
+ function normalizeSkills(capabilityId, skills) {
233
+ if (skills === undefined)
234
+ return undefined;
235
+ if (!skills ||
236
+ typeof skills !== "object" ||
237
+ Array.isArray(skills) ||
238
+ Object.keys(skills).length === 0)
239
+ throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills must be a non-empty map or omitted`);
240
+ const normalized = {};
241
+ for (const [key, skill] of Object.entries(skills)) {
242
+ if (!skill ||
243
+ typeof skill !== "object" ||
244
+ skill.name !== key ||
245
+ typeof skill.description !== "string" ||
246
+ skill.description.length === 0)
247
+ throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills key '${key}' must equal the skill name`);
248
+ normalized[key] = Object.freeze({
249
+ name: skill.name,
250
+ description: skill.description,
251
+ });
252
+ }
253
+ return Object.freeze(normalized);
254
+ }
255
+ function normalizeMcpServers(capabilityId, servers) {
256
+ if (servers === undefined)
257
+ return undefined;
258
+ if (!servers ||
259
+ typeof servers !== "object" ||
260
+ Array.isArray(servers) ||
261
+ Object.keys(servers).length === 0)
262
+ throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers must be a non-empty map or omitted`);
263
+ const normalized = {};
264
+ for (const [key, server] of Object.entries(servers)) {
265
+ if (!isMcpServer(server) || server.name !== key)
266
+ throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers key '${key}' must equal the server name`);
267
+ normalized[key] = server;
268
+ }
269
+ return Object.freeze(normalized);
270
+ }
271
+ function isMcpServer(value) {
272
+ if (!value || typeof value !== "object" || Array.isArray(value))
273
+ return false;
274
+ const server = value;
275
+ if (typeof server.name !== "string" || !server.name)
276
+ return false;
277
+ if (server.type === "stdio")
278
+ return typeof server.command === "string" && server.command.length > 0;
279
+ if (server.type === "streamable-http" || server.type === "sse")
280
+ return typeof server.url === "string" && server.url.length > 0;
281
+ return false;
282
+ }
124
283
  function normalizeTool(tool) {
125
284
  return Object.freeze({
126
285
  name: tool.name,
@@ -9,6 +9,8 @@ export declare const middleware: <T extends StepMiddleware>(value: T) => T;
9
9
  /** Compose a reusable capability bundle (tools, instructions, optional dynamics). */
10
10
  export declare function capability<Info = unknown>(declaration: {
11
11
  readonly id: string;
12
+ readonly name?: string;
13
+ readonly description?: string;
12
14
  readonly tools?: readonly ToolDefinition<any, Info, any>[];
13
15
  readonly instructions?: string | readonly string[];
14
16
  readonly beforeModelCall?: import("../types/dynamics.js").BeforeModelCallFn<Info>;
@@ -13,6 +13,10 @@ export function capability(declaration) {
13
13
  : declaration.instructions;
14
14
  return {
15
15
  id: declaration.id,
16
+ ...(declaration.name === undefined ? {} : { name: declaration.name }),
17
+ ...(declaration.description === undefined
18
+ ? {}
19
+ : { description: declaration.description }),
16
20
  ...(declaration.tools === undefined ? {} : { tools: declaration.tools }),
17
21
  ...(instructions === undefined ? {} : { instructions }),
18
22
  ...(declaration.beforeModelCall === undefined
@@ -1,9 +1,13 @@
1
1
  import type { BoundMiddleware } from "./bound.js";
2
- import type { AgentManifest } from "../types/manifest.js";
2
+ import type { AgentManifest, RuntimeManifest } from "../types/manifest.js";
3
+ import type { JsonObject } from "../types/shared.js";
3
4
  import type { ToolSchemaSource } from "../types/tool.js";
4
5
  export declare function createManifest(input: {
5
6
  id: string;
6
- name: string;
7
+ name?: string;
8
+ description?: string;
9
+ metadata?: JsonObject;
7
10
  outputSchema?: ToolSchemaSource;
11
+ runtime?: RuntimeManifest;
8
12
  middleware: readonly BoundMiddleware[];
9
13
  }): AgentManifest;
@@ -1,12 +1,18 @@
1
1
  import { bindOutputContract } from "./output-contract.js";
2
2
  import { normalizedSchemasFor } from "./schema.js";
3
- import { deepFreeze } from "../utils/immutable.js";
3
+ import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
4
4
  export function createManifest(input) {
5
5
  const capabilities = input.middleware.map((item) => projectCapability(item));
6
6
  return deepFreeze({
7
- schemaVersion: 2,
7
+ manifestSchemaVersion: 3,
8
8
  id: input.id,
9
- name: input.name,
9
+ ...(input.name === undefined ? {} : { name: input.name }),
10
+ ...(input.description === undefined
11
+ ? {}
12
+ : { description: input.description }),
13
+ ...(input.metadata === undefined
14
+ ? {}
15
+ : { metadata: copyJsonObject(input.metadata, "metadata") }),
10
16
  ...(input.outputSchema === undefined
11
17
  ? {}
12
18
  : {
@@ -14,34 +20,31 @@ export function createManifest(input) {
14
20
  .jsonSchema,
15
21
  }),
16
22
  capabilities,
23
+ ...(input.runtime === undefined ? {} : { runtime: input.runtime }),
17
24
  });
18
25
  }
19
26
  function projectCapability(item) {
20
27
  const contributions = item.contributions;
21
28
  return {
22
29
  id: item.id,
23
- kind: capabilityKind(item),
24
- hasMiddleware: item.hasMiddleware,
30
+ type: item.manifestType ?? "agent",
31
+ ...(item.name === undefined ? {} : { name: item.name }),
32
+ ...(item.description === undefined ? {} : { description: item.description }),
33
+ ...(item.metadata === undefined
34
+ ? {}
35
+ : { metadata: copyJsonObject(item.metadata, "metadata") }),
25
36
  ...(contributions?.instructions === undefined
26
37
  ? {}
27
38
  : { instructions: contributions.instructions }),
28
39
  ...(item.tools === undefined
29
40
  ? {}
30
41
  : { tools: item.tools.map((tool) => projectTool(tool)) }),
42
+ ...(item.skills === undefined ? {} : { skills: item.skills }),
43
+ ...(item.mcpServers === undefined ? {} : { mcpServers: item.mcpServers }),
31
44
  ...(item.beforeModelCall ? { beforeModelCall: true } : {}),
32
45
  ...(item.afterModelCall ? { afterModelCall: true } : {}),
33
- // Deliberately omit capability.model from new manifests (Runtime-owned).
34
46
  };
35
47
  }
36
- function capabilityKind(item) {
37
- if (item.id === "agent")
38
- return "agent";
39
- if (item.contributions !== undefined ||
40
- item.beforeModelCall ||
41
- item.afterModelCall)
42
- return "capability";
43
- return "middleware";
44
- }
45
48
  function projectTool(tool) {
46
49
  const schemas = normalizedSchemasFor(tool);
47
50
  return {
@@ -91,11 +91,14 @@ export function normalizeSchema(source, role) {
91
91
  return normalized;
92
92
  }
93
93
  function normalizeZodSchema(source, role) {
94
- if (hasDeclaredAsyncWork(source))
94
+ // Classic parse/JSON Schema helpers are typed on ZodType; concrete schemas
95
+ // are $ZodType-compatible but may not assign to ZodType under zod 4.6+.
96
+ const classic = source;
97
+ if (hasDeclaredAsyncWork(classic))
95
98
  throw new HarnessError("tool.invalid-schema", "Tool schema must validate synchronously");
96
99
  let jsonSchema;
97
100
  try {
98
- jsonSchema = copyJsonObject(z.toJSONSchema(source, { target: "draft-07" }), `tool.${role}Schema.jsonSchema`);
101
+ jsonSchema = copyJsonObject(z.toJSONSchema(classic, { target: "draft-07" }), `tool.${role}Schema.jsonSchema`);
99
102
  }
100
103
  catch (error) {
101
104
  throw new HarnessError("tool.invalid-schema", `Tool ${role}Schema must convert to JSON Schema: ${message(error)}`, { cause: error });
@@ -104,7 +107,7 @@ function normalizeZodSchema(source, role) {
104
107
  jsonSchema,
105
108
  validate(value) {
106
109
  try {
107
- const result = source.safeParse(value);
110
+ const result = classic.safeParse(value);
108
111
  if (result.success)
109
112
  return { ok: true, value: result.data };
110
113
  return {
@@ -0,0 +1,3 @@
1
+ import type { SkillRecord } from "../types/middleware.js";
2
+ import type { ToolDefinition } from "../types/tool.js";
3
+ export declare function createSkillTools(skills: ReadonlyMap<string, SkillRecord>): readonly ToolDefinition[];
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import { tool } from "./helpers.js";
3
+ const USAGE = "Load the full instructions for a named skill. Call this before following a skill.";
4
+ export function createSkillTools(skills) {
5
+ const names = [...skills.keys()].sort();
6
+ const nameSchema = names.length === 1
7
+ ? z.literal(names[0])
8
+ : z.enum(names);
9
+ const definitions = [
10
+ tool({
11
+ name: "load_skill",
12
+ description: USAGE,
13
+ inputSchema: z.object({ name: nameSchema }),
14
+ effects: "read",
15
+ async execute(args) {
16
+ const name = args.name;
17
+ const skill = skills.get(name);
18
+ if (!skill)
19
+ return { unknown: name, available: names };
20
+ const loaded = {
21
+ name: skill.name,
22
+ content: skill.instructions,
23
+ };
24
+ const resources = Object.keys(skill.resources ?? {}).sort();
25
+ if (resources.length === 0)
26
+ return loaded;
27
+ return { ...loaded, resources };
28
+ },
29
+ }),
30
+ ];
31
+ const hasResources = [...skills.values()].some((skill) => skill.resources !== undefined && Object.keys(skill.resources).length > 0);
32
+ if (hasResources) {
33
+ definitions.push(tool({
34
+ name: "read_skill_resource",
35
+ description: "Read one text resource from a skill after load_skill.",
36
+ inputSchema: z.object({
37
+ name: nameSchema,
38
+ path: z.string().min(1),
39
+ }),
40
+ effects: "read",
41
+ async execute(args) {
42
+ const { name, path } = args;
43
+ const skill = skills.get(name);
44
+ const content = skill?.resources?.[path];
45
+ if (!skill || content === undefined)
46
+ return {
47
+ kind: "failed",
48
+ code: "skill.unknown_resource",
49
+ message: `Skill '${name}' has no resource '${path}'.`,
50
+ };
51
+ return { kind: "completed", output: { name, path, content } };
52
+ },
53
+ }));
54
+ }
55
+ return definitions;
56
+ }
@@ -3,10 +3,8 @@ import type { AgentManifest } from "./manifest.js";
3
3
  /** An agent definition composed with Agent(...).use(...). Optional `.build()` is a no-op facade. */
4
4
  export interface BuiltAgent<Info = unknown, Output = string> {
5
5
  readonly id: string;
6
- readonly name: string;
6
+ readonly name?: string;
7
7
  readonly manifest: AgentManifest;
8
- /** Canonical SHA-256 of `manifest` — durable definition identity. */
9
- readonly hash: string;
10
8
  toJSON(): AgentManifest;
11
9
  getBinding(): AgentBinding;
12
10
  }
@@ -1,34 +1,57 @@
1
- import type { ModelDirective } from "./model.js";
2
1
  import type { JsonObject } from "./shared.js";
3
2
  /** Published manifest schema version (no top-level model — Runtime-owned). */
4
- export type ManifestSchemaVersion = 2;
5
- export interface ManifestTool {
3
+ export type ManifestSchemaVersion = 3;
4
+ export interface ToolManifest {
6
5
  readonly name: string;
7
6
  readonly description?: string;
8
7
  readonly inputSchema: JsonObject;
9
8
  readonly outputSchema?: JsonObject;
10
9
  }
10
+ export interface SkillManifest {
11
+ readonly name: string;
12
+ readonly description: string;
13
+ }
14
+ export type McpServerManifest = {
15
+ readonly name: string;
16
+ readonly type: "stdio";
17
+ readonly command: string;
18
+ readonly args?: readonly string[];
19
+ readonly env?: Readonly<Record<string, string>>;
20
+ readonly cwd?: string;
21
+ } | {
22
+ readonly name: string;
23
+ readonly type: "streamable-http";
24
+ readonly url: string;
25
+ readonly headers?: Readonly<Record<string, string>>;
26
+ } | {
27
+ readonly name: string;
28
+ readonly type: "sse";
29
+ readonly url: string;
30
+ readonly headers?: Readonly<Record<string, string>>;
31
+ };
11
32
  export interface CapabilityManifest {
12
33
  readonly id: string;
13
- readonly kind: "agent" | "capability" | "middleware";
14
- /** @deprecated Prefer beforeModelCall / afterModelCall flags. */
15
- readonly hasMiddleware: boolean;
34
+ readonly type: "agent" | "agent-plugin";
35
+ readonly name?: string;
36
+ readonly description?: string;
37
+ readonly metadata?: JsonObject;
16
38
  readonly instructions?: readonly string[];
17
- readonly tools?: readonly ManifestTool[];
18
- /** True when an implementations entry provides beforeModelCall for this capability. */
39
+ readonly skills?: Readonly<Record<string, SkillManifest>>;
40
+ readonly tools?: readonly ToolManifest[];
41
+ readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
19
42
  readonly beforeModelCall?: boolean;
20
- /** True when an implementations entry provides afterModelCall for this capability. */
21
43
  readonly afterModelCall?: boolean;
22
- /**
23
- * @deprecated Model resolution is Runtime-owned. Legacy local snapshots may still carry this;
24
- * new manifests omit it.
25
- */
26
- readonly model?: Pick<ModelDirective, "id" | "controls">;
44
+ }
45
+ /** Reserved. Empty until later fields are defined. Omit `runtime` while it has no fields. */
46
+ export interface RuntimeManifest {
27
47
  }
28
48
  export interface AgentManifest {
29
- readonly schemaVersion: ManifestSchemaVersion;
49
+ readonly manifestSchemaVersion: ManifestSchemaVersion;
30
50
  readonly id: string;
31
- readonly name: string;
51
+ readonly name?: string;
52
+ readonly description?: string;
53
+ readonly metadata?: JsonObject;
32
54
  readonly outputSchema?: JsonObject;
33
55
  readonly capabilities: readonly CapabilityManifest[];
56
+ readonly runtime?: RuntimeManifest;
34
57
  }