@nylorun/core 0.1.1-beta → 0.3.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.
package/dist/contracts.js CHANGED
@@ -1,50 +1,151 @@
1
1
  /** Public wire contracts only. Never import checkpoint or engine modules here. */
2
2
  import { z } from "zod";
3
+ import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
4
+ import { hookListIssue } from "./definition/hooks.js";
3
5
  export const PROTOCOL_VERSION = 1;
4
6
  export const RequestIdSchema = z.string().min(1);
5
7
  export const IdempotencyKeySchema = z.string().min(1).max(256);
6
8
  const jsonObject = z.record(z.string(), z.unknown());
9
+ const mcpServerSchema = z.discriminatedUnion("type", [
10
+ z
11
+ .object({
12
+ name: z.string().min(1),
13
+ type: z.literal("stdio"),
14
+ command: z.string().min(1),
15
+ args: z.array(z.string()).optional(),
16
+ env: z.record(z.string(), z.string()).optional(),
17
+ cwd: z.string().optional(),
18
+ })
19
+ .strict(),
20
+ z
21
+ .object({
22
+ name: z.string().min(1),
23
+ type: z.literal("streamable-http"),
24
+ url: z.string().min(1),
25
+ headers: z.record(z.string(), z.string()).optional(),
26
+ })
27
+ .strict(),
28
+ z
29
+ .object({
30
+ name: z.string().min(1),
31
+ type: z.literal("sse"),
32
+ url: z.string().min(1),
33
+ headers: z.record(z.string(), z.string()).optional(),
34
+ })
35
+ .strict(),
36
+ ]);
37
+ const skillManifestSchema = z
38
+ .object({
39
+ name: z.string().min(1),
40
+ description: z.string().min(1),
41
+ })
42
+ .strict();
43
+ const sandboxManifestSchema = z
44
+ .object({
45
+ image: z.string().min(1).optional(),
46
+ network: z
47
+ .object({
48
+ preset: z.enum(SANDBOX_NETWORK_PRESETS).optional(),
49
+ allow: z
50
+ .array(z.string().refine(isSandboxHostPattern, {
51
+ message: "network.allow entries must be host names such as api.github.com or *.example.com",
52
+ }))
53
+ .optional(),
54
+ })
55
+ .strict()
56
+ .optional(),
57
+ resources: z
58
+ .object({
59
+ cpus: z.number().int().min(1).max(64).optional(),
60
+ memory: z
61
+ .string()
62
+ .refine((value) => parseSandboxSize(value) !== undefined, {
63
+ message: "resources.memory must be a size such as 512MiB or 2GiB",
64
+ })
65
+ .optional(),
66
+ })
67
+ .strict()
68
+ .optional(),
69
+ idle: z
70
+ .string()
71
+ .refine((value) => parseSandboxDuration(value) !== undefined, {
72
+ message: "idle must be a duration such as 30s, 15m or 1h",
73
+ })
74
+ .optional(),
75
+ })
76
+ .strict();
77
+ const toolManifestSchema = z
78
+ .object({
79
+ name: z.string().min(1),
80
+ description: z.string().optional(),
81
+ inputSchema: jsonObject,
82
+ outputSchema: jsonObject.optional(),
83
+ })
84
+ .strict();
85
+ const hookPointSchema = z
86
+ .object({
87
+ at: z.enum(["before", "after"]),
88
+ scope: z.enum(["turn", "step"]),
89
+ })
90
+ .strict();
7
91
  export const AgentManifestSchema = z
8
92
  .object({
9
- schemaVersion: z.literal(2),
93
+ manifestSchemaVersion: z.literal(4),
10
94
  id: z.string().min(1),
11
- name: z.string().min(1),
95
+ name: z.string().min(1).optional(),
96
+ description: z.string().optional(),
97
+ metadata: jsonObject.optional(),
12
98
  outputSchema: jsonObject.optional(),
13
99
  capabilities: z.array(z
14
100
  .object({
15
101
  id: z.string().min(1),
16
- kind: z.enum(["agent", "capability", "middleware"]),
17
- hasMiddleware: z.boolean(),
102
+ type: z.enum(["agent", "agent-plugin"]),
103
+ name: z.string().min(1).optional(),
104
+ description: z.string().optional(),
105
+ metadata: jsonObject.optional(),
18
106
  instructions: z.array(z.string()).optional(),
19
- tools: z
20
- .array(z
21
- .object({
22
- name: z.string().min(1),
23
- description: z.string().optional(),
24
- inputSchema: jsonObject,
25
- outputSchema: jsonObject.optional(),
26
- })
27
- .strict())
28
- .optional(),
29
- beforeModelCall: z.boolean().optional(),
30
- afterModelCall: z.boolean().optional(),
107
+ skills: z.record(z.string(), skillManifestSchema).optional(),
108
+ tools: z.array(toolManifestSchema).optional(),
109
+ mcpServers: z.record(z.string(), mcpServerSchema).optional(),
110
+ sandbox: sandboxManifestSchema.optional(),
111
+ hooks: z
112
+ .array(hookPointSchema)
113
+ .optional()
114
+ .superRefine((hooks, ctx) => {
115
+ const issue = hooks === undefined ? undefined : hookListIssue(hooks);
116
+ if (issue)
117
+ ctx.addIssue({ code: "custom", message: issue });
118
+ }),
31
119
  })
32
120
  .strict()),
121
+ runtime: z.object({}).strict().optional(),
33
122
  })
34
123
  .strict()
35
124
  .superRefine((manifest, ctx) => {
36
125
  const ids = new Set();
37
126
  const names = new Set();
127
+ const servers = new Set();
128
+ const skills = new Set();
129
+ let sandboxes = 0;
38
130
  for (const capability of manifest.capabilities) {
131
+ if (capability.sandbox) {
132
+ sandboxes += 1;
133
+ if (sandboxes > 1)
134
+ ctx.addIssue({
135
+ code: "custom",
136
+ message: "At most one capability may declare a sandbox",
137
+ });
138
+ const declared = new Set((capability.tools ?? []).map((tool) => tool.name));
139
+ for (const name of SANDBOX_TOOL_NAMES)
140
+ if (!declared.has(name))
141
+ ctx.addIssue({
142
+ code: "custom",
143
+ message: `Sandbox capability '${capability.id}' must declare the built-in '${name}' tool`,
144
+ });
145
+ }
39
146
  if (ids.has(capability.id))
40
147
  ctx.addIssue({ code: "custom", message: "Duplicate capability id" });
41
148
  ids.add(capability.id);
42
- // Arbitrary middleware closures cannot be transported. Hooks are explicit remote actions.
43
- if (capability.hasMiddleware)
44
- ctx.addIssue({
45
- code: "custom",
46
- message: "Hosted definitions support declarative capabilities and before/after hooks, not middleware closures",
47
- });
48
149
  for (const tool of capability.tools ?? []) {
49
150
  if (names.has(tool.name))
50
151
  ctx.addIssue({
@@ -53,13 +154,57 @@ export const AgentManifestSchema = z
53
154
  });
54
155
  names.add(tool.name);
55
156
  }
157
+ if (capability.skills && Object.keys(capability.skills).length === 0)
158
+ ctx.addIssue({
159
+ code: "custom",
160
+ message: "skills must be omitted when a capability declares no skills",
161
+ });
162
+ for (const [key, skill] of Object.entries(capability.skills ?? {})) {
163
+ if (key !== skill.name)
164
+ ctx.addIssue({
165
+ code: "custom",
166
+ message: `skills key '${key}' must equal the skill name`,
167
+ });
168
+ if (skills.has(skill.name))
169
+ ctx.addIssue({
170
+ code: "custom",
171
+ message: `Duplicate skill '${skill.name}'`,
172
+ });
173
+ skills.add(skill.name);
174
+ }
175
+ if (capability.mcpServers && Object.keys(capability.mcpServers).length === 0)
176
+ ctx.addIssue({
177
+ code: "custom",
178
+ message: "mcpServers must be omitted when a capability declares no servers",
179
+ });
180
+ for (const [key, server] of Object.entries(capability.mcpServers ?? {})) {
181
+ if (key !== server.name)
182
+ ctx.addIssue({
183
+ code: "custom",
184
+ message: `mcpServers key '${key}' must equal the server name`,
185
+ });
186
+ if (servers.has(server.name))
187
+ ctx.addIssue({
188
+ code: "custom",
189
+ message: `Duplicate MCP server '${server.name}'`,
190
+ });
191
+ servers.add(server.name);
192
+ }
56
193
  }
57
194
  });
195
+ const absolutePath = z.string().min(1).refine((value) => value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value), { message: "plugin root must be an absolute path" });
58
196
  export const PutAgentRequestSchema = z
59
197
  .object({
60
198
  requestId: RequestIdSchema,
61
199
  manifest: AgentManifestSchema,
62
200
  implementationVersion: z.string().min(1),
201
+ pluginRoots: z.record(z.string(), absolutePath).optional(),
202
+ })
203
+ .strict();
204
+ export const CredentialSelectionSchema = z
205
+ .object({
206
+ serverName: z.string().min(1),
207
+ credentialId: z.string().min(1),
63
208
  })
64
209
  .strict();
65
210
  export const PutSessionRequestSchema = z
@@ -68,6 +213,120 @@ export const PutSessionRequestSchema = z
68
213
  agentId: z.string().min(1),
69
214
  ownerUserId: z.string().min(1),
70
215
  info: jsonObject.optional(),
216
+ vaultIds: z.array(z.string().min(1)).optional(),
217
+ credentialSelections: z.array(CredentialSelectionSchema).optional(),
218
+ })
219
+ .strict();
220
+ const vaultWriteBase = {
221
+ requestId: RequestIdSchema,
222
+ idempotencyKey: IdempotencyKeySchema,
223
+ };
224
+ const tokenEndpointAuthSchema = z.discriminatedUnion("type", [
225
+ z.object({ type: z.literal("none") }).strict(),
226
+ z
227
+ .object({
228
+ type: z.literal("client_secret_basic"),
229
+ clientSecret: z.string().min(1),
230
+ })
231
+ .strict(),
232
+ z
233
+ .object({
234
+ type: z.literal("client_secret_post"),
235
+ clientSecret: z.string().min(1),
236
+ })
237
+ .strict(),
238
+ ]);
239
+ const oauthRefreshSchema = z
240
+ .object({
241
+ tokenEndpoint: z.string().min(1),
242
+ clientId: z.string().min(1),
243
+ refreshToken: z.string().min(1),
244
+ tokenEndpointAuth: tokenEndpointAuthSchema,
245
+ })
246
+ .strict();
247
+ export const CreateVaultRequestSchema = z
248
+ .object({
249
+ ...vaultWriteBase,
250
+ name: z.string().min(1),
251
+ ownerUserId: z.string().min(1),
252
+ metadata: z.record(z.string(), z.string()).optional(),
253
+ })
254
+ .strict();
255
+ export const CreateCredentialRequestSchema = z
256
+ .object({
257
+ ...vaultWriteBase,
258
+ name: z.string().min(1),
259
+ auth: z.discriminatedUnion("type", [
260
+ z
261
+ .object({
262
+ type: z.literal("bearer"),
263
+ url: z.string().min(1),
264
+ token: z.string().min(1),
265
+ })
266
+ .strict(),
267
+ z
268
+ .object({
269
+ type: z.literal("oauth"),
270
+ url: z.string().min(1),
271
+ accessToken: z.string().min(1),
272
+ expiresAt: z.string().min(1).nullable().optional(),
273
+ refresh: oauthRefreshSchema.optional(),
274
+ })
275
+ .strict(),
276
+ ]),
277
+ })
278
+ .strict();
279
+ export const RotateCredentialRequestSchema = z
280
+ .object({
281
+ ...vaultWriteBase,
282
+ auth: z.discriminatedUnion("type", [
283
+ z
284
+ .object({
285
+ type: z.literal("bearer"),
286
+ token: z.string().min(1),
287
+ })
288
+ .strict(),
289
+ z
290
+ .object({
291
+ type: z.literal("oauth"),
292
+ accessToken: z.string().min(1),
293
+ expiresAt: z.string().min(1).nullable().optional(),
294
+ })
295
+ .strict(),
296
+ ]),
297
+ })
298
+ .strict();
299
+ export const PutHostModelRequestSchema = z
300
+ .object({
301
+ ...vaultWriteBase,
302
+ provider: z.string().min(1),
303
+ model: z.string().min(1),
304
+ baseUrl: z.string().min(1).optional(),
305
+ auth: z.discriminatedUnion("type", [
306
+ z
307
+ .object({
308
+ type: z.literal("api_key"),
309
+ key: z.string().min(1),
310
+ env: z.record(z.string(), z.string()).optional(),
311
+ })
312
+ .strict(),
313
+ z
314
+ .object({
315
+ type: z.literal("oauth"),
316
+ refresh: z.string().min(1),
317
+ access: z.string().min(1),
318
+ expires: z.number(),
319
+ })
320
+ .passthrough(),
321
+ ]),
322
+ })
323
+ .strict();
324
+ export const SelectHostModelRequestSchema = z
325
+ .object({
326
+ ...vaultWriteBase,
327
+ provider: z.string().min(1),
328
+ model: z.string().min(1),
329
+ baseUrl: z.string().min(1).optional(),
71
330
  })
72
331
  .strict();
73
332
  const commandBase = {
@@ -153,27 +412,46 @@ export const RejectedResponseSchema = z.object({
153
412
  activeTurnId: z.string().optional(),
154
413
  requestId: z.string().optional(),
155
414
  });
156
- export const ActionSchema = z.object({
415
+ const actionBase = {
157
416
  actionId: z.string(),
158
417
  sessionId: z.string(),
159
418
  turnId: z.string(),
160
419
  agentId: z.string(),
161
420
  manifestHash: z.string(),
162
421
  implementationVersion: z.string(),
163
- kind: z.enum(["tool", "beforeModelCall", "afterModelCall"]),
164
- capabilityId: z.string(),
165
- toolName: z.string().optional(),
166
422
  input: z.unknown(),
167
423
  context: jsonObject,
168
424
  status: z.enum(["pending", "claimed", "completed", "uncertain", "cancelled"]),
169
425
  generation: z.number().int().nonnegative(),
170
426
  claimId: z.string().nullable(),
171
427
  leaseExpiresAt: z.string().nullable(),
172
- });
428
+ };
429
+ /** The hook point an action runs, and the capabilities that registered it (manifest order). */
430
+ export const ActionHookSchema = z
431
+ .object({
432
+ at: z.enum(["before", "after"]),
433
+ scope: z.enum(["turn", "step"]),
434
+ capabilityIds: z.array(z.string().min(1)).min(1),
435
+ })
436
+ .strict();
437
+ export const ActionSchema = z.discriminatedUnion("kind", [
438
+ z.object({
439
+ ...actionBase,
440
+ kind: z.literal("tool"),
441
+ capabilityId: z.string(),
442
+ toolName: z.string(),
443
+ inputSchema: jsonObject.optional(),
444
+ outputSchema: jsonObject.optional(),
445
+ }),
446
+ z.object({
447
+ ...actionBase,
448
+ kind: z.literal("hook"),
449
+ hook: ActionHookSchema,
450
+ }),
451
+ ]);
173
452
  export const ActionClaimRequestSchema = z
174
453
  .object({
175
454
  requestId: RequestIdSchema,
176
- manifestHash: z.string().min(1),
177
455
  implementationVersion: z.string().min(1),
178
456
  })
179
457
  .strict();
@@ -193,9 +471,43 @@ export const ActionClaimResponseSchema = z.object({
193
471
  export const ExecutorNotificationSchema = z.object({
194
472
  type: z.literal("work_available"),
195
473
  });
474
+ export const ExecutorRegistrationSchema = z
475
+ .object({
476
+ agentId: z.string().min(1),
477
+ implementationVersion: z.string().min(1),
478
+ manifestHash: z.string().min(1).optional(),
479
+ token: z.string().min(16),
480
+ })
481
+ .strict();
482
+ export const RegisterExecutorsRequestSchema = z
483
+ .object({
484
+ executors: z.array(ExecutorRegistrationSchema).min(1).max(64),
485
+ })
486
+ .strict();
487
+ export const RegisterExecutorsResponseSchema = z.object({
488
+ executors: z.array(z.object({
489
+ agentId: z.string(),
490
+ implementationVersion: z.string(),
491
+ rotated: z.boolean(),
492
+ })),
493
+ });
494
+ export const ExecutorSummarySchema = z.object({
495
+ agentId: z.string(),
496
+ implementationVersion: z.string(),
497
+ manifestHash: z.string().optional(),
498
+ connected: z.boolean(),
499
+ updatedAt: z.string(),
500
+ });
501
+ export const ListExecutorsResponseSchema = z.object({
502
+ executors: z.array(ExecutorSummarySchema),
503
+ });
504
+ // Health fields added after the beta stay optional so a new client can parse an older Runtime.
196
505
  export const HealthResponseSchema = z.object({
197
506
  status: z.literal("ok"),
198
507
  service: z.string(),
508
+ version: z.string().optional(),
509
+ scopeId: z.string().optional(),
510
+ pid: z.number().int().positive().optional(),
199
511
  });
200
512
  export const ReadyResponseSchema = z.object({
201
513
  status: z.enum(["ready", "not_ready"]),
package/dist/define.d.ts CHANGED
@@ -7,10 +7,14 @@ export { capability, middleware, model, tool } from "./definition/helpers.js";
7
7
  export { ToolError, isToolError } from "./definition/tool-error.js";
8
8
  export { defineSchema } from "./definition/schema.js";
9
9
  export { hashManifest } from "./utils/hash.js";
10
+ export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
11
+ export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
12
+ export type { SandboxToolName } from "./utils/sandbox.js";
10
13
  export type { Implementations } from "./definition/implementations.js";
11
- export type { AgentManifest, CapabilityManifest, ManifestTool, ManifestSchemaVersion, } from "./types/manifest.js";
12
- export type { CapabilityDeclaration, CapabilityItems, MiddlewareContributions, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
13
- export type { Patch, Decision, BeforeModelCallFn, AfterModelCallFn, } from "./types/dynamics.js";
14
+ export type { AgentManifest, CapabilityManifest, McpServerManifest, RuntimeManifest, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
15
+ export type { CapabilityDeclaration, CapabilityItems, MiddlewareContributions, SkillRecord, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
16
+ export type { Patch, Decision, TurnDecision, HookAt, HookScope, HookManifest, HookState, HookToolCall, BeforeHook, AfterHook, BeforeHooks, AfterHooks, BeforeTurnArgs, BeforeStepArgs, AfterStepArgs, AfterTurnArgs, } from "./types/dynamics.js";
17
+ export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
14
18
  export type { ModelCandidate, ModelControls, ModelDirective, ModelEvidence, ModelFinishReason, ModelAdapter, ModelAdapterContext, ModelPreparedCall, ContextContributor, ContextMutationOptions, ContextSnapshot, ModelCall, ModelCallTool, ModelOutputBlock, PromptContentPart, PromptItem, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationMutationOptions, ModelConfigurationSnapshot, ModelConfigurationTool, ModelRequest, ModelToolCall, ModelUsage, } from "./types/model.js";
15
19
  export type { BuildDiagnostic, ContextItem, DeferredOutcome, JsonObject, JsonPrimitive, JsonValue, Tripwire, } from "./types/shared.js";
16
20
  export type { ObserveEvent, ObserveModelConfigurationSnapshot, ObserveModelRequested, ObserveSealedCall, ObserveToolSnapshot, Observer, } from "./types/observe.js";
@@ -24,6 +28,7 @@ export { bindTool } from "./definition/bind-tool.js";
24
28
  export { bindOutputContract } from "./definition/output-contract.js";
25
29
  export type { TurnOutputContract } from "./definition/output-contract.js";
26
30
  export { agentFrom } from "./definition/from.js";
31
+ export type { SessionToolRef } from "./definition/from.js";
27
32
  export { schemaFromJSON } from "./definition/schema-json.js";
28
33
  export { normalizeSchema } from "./definition/schema.js";
29
34
  export * from "./utils/immutable.js";
package/dist/define.js CHANGED
@@ -4,6 +4,9 @@ export { capability, middleware, model, tool } from "./definition/helpers.js";
4
4
  export { ToolError, isToolError } from "./definition/tool-error.js";
5
5
  export { defineSchema } from "./definition/schema.js";
6
6
  export { hashManifest } from "./utils/hash.js";
7
+ export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
8
+ export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
9
+ export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
7
10
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
8
11
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
9
12
  export { bindTool } from "./definition/bind-tool.js";
@@ -1,9 +1,9 @@
1
1
  import type { BoundMiddleware } from "./bound.js";
2
2
  import type { BuiltAgent } from "../types/agent.js";
3
- import type { AgentManifest } from "../types/manifest.js";
4
- import type { BuildDiagnostic } from "../types/shared.js";
3
+ import type { AgentManifest, RuntimeManifest } from "../types/manifest.js";
4
+ import type { BuildDiagnostic, JsonObject } from "../types/shared.js";
5
5
  import type { ToolSchemaSource } from "../types/tool.js";
6
- import type { AfterModelCallFn, BeforeModelCallFn } from "../types/dynamics.js";
6
+ import type { AfterHooks, BeforeHooks } from "../types/dynamics.js";
7
7
  import type { StepMiddleware } from "../types/middleware.js";
8
8
  type BuildResult<Agent> = {
9
9
  readonly ok: true;
@@ -14,13 +14,16 @@ type BuildResult<Agent> = {
14
14
  readonly diagnostics: readonly BuildDiagnostic[];
15
15
  };
16
16
  export interface CapabilityDynamics {
17
- readonly beforeModelCall?: BeforeModelCallFn<any>;
18
- readonly afterModelCall?: AfterModelCallFn<any>;
17
+ readonly before?: BeforeHooks<any>;
18
+ readonly after?: AfterHooks<any>;
19
19
  readonly middleware?: StepMiddleware<any>;
20
20
  }
21
21
  export declare function assembleAgent(middleware: readonly BoundMiddleware[], identity: Readonly<{
22
22
  id: string;
23
- name: string;
23
+ name?: string;
24
+ description?: string;
25
+ metadata?: JsonObject;
24
26
  outputSchema?: ToolSchemaSource;
27
+ runtime?: RuntimeManifest;
25
28
  }>, dynamics?: ReadonlyMap<string, CapabilityDynamics>): BuildResult<BuiltAgent>;
26
29
  export {};
@@ -1,12 +1,14 @@
1
1
  import { bindAgent } from "./bind-agent.js";
2
2
  import { createManifest } from "./manifest.js";
3
+ import { createSkillTools } from "./skill-tools.js";
3
4
  const diagnostic = (code, message, extra = {}) => Object.freeze({ code, message, ...extra });
4
5
  export function assembleAgent(middleware, identity, dynamics = new Map()) {
5
6
  const diagnostics = [];
6
7
  if (typeof identity.id !== "string" || identity.id.length === 0) {
7
8
  diagnostics.push(diagnostic("agent.invalid-id", "Agent id must be a non-empty string"));
8
9
  }
9
- if (typeof identity.name !== "string" || identity.name.length === 0) {
10
+ if (identity.name !== undefined &&
11
+ (typeof identity.name !== "string" || identity.name.length === 0)) {
10
12
  diagnostics.push(diagnostic("agent.invalid-name", "Agent name must be a non-empty string"));
11
13
  }
12
14
  const middlewareIds = new Set();
@@ -18,33 +20,115 @@ export function assembleAgent(middleware, identity, dynamics = new Map()) {
18
20
  diagnostics.push(diagnostic("middleware.duplicate-id", `Duplicate middleware id '${item.id}'`));
19
21
  else if (typeof item.handle !== "function")
20
22
  diagnostics.push(diagnostic("middleware.invalid", `Middleware '${item.id}' must provide a function`));
23
+ else if (item.name !== undefined && item.name.length === 0)
24
+ diagnostics.push(diagnostic("middleware.invalid", `Capability '${item.id}' name must be a non-empty string`));
21
25
  else {
22
26
  middlewareIds.add(item.id);
23
27
  frozen.push(Object.freeze({
24
28
  id: item.id,
29
+ ...(item.name === undefined ? {} : { name: item.name }),
30
+ ...(item.description === undefined
31
+ ? {}
32
+ : { description: item.description }),
25
33
  handle: item.handle,
26
34
  hasMiddleware: item.hasMiddleware,
27
35
  ...(item.tools === undefined ? {} : { tools: item.tools }),
28
36
  ...(item.contributions === undefined
29
37
  ? {}
30
38
  : { contributions: item.contributions }),
31
- ...(item.beforeModelCall ? { beforeModelCall: true } : {}),
32
- ...(item.afterModelCall ? { afterModelCall: true } : {}),
39
+ ...(item.hooks === undefined ? {} : { hooks: item.hooks }),
40
+ ...(item.manifestType === undefined
41
+ ? {}
42
+ : { manifestType: item.manifestType }),
43
+ ...(item.metadata === undefined ? {} : { metadata: item.metadata }),
44
+ ...(item.mcpServers === undefined
45
+ ? {}
46
+ : { mcpServers: item.mcpServers }),
47
+ ...(item.sandbox === undefined ? {} : { sandbox: item.sandbox }),
48
+ ...(item.skills === undefined ? {} : { skills: item.skills }),
49
+ ...(item.skillRecords === undefined
50
+ ? {}
51
+ : { skillRecords: item.skillRecords }),
52
+ ...(item.sessionTools === undefined
53
+ ? {}
54
+ : { sessionTools: item.sessionTools }),
55
+ ...(item.pluginRoot === undefined ? {} : { pluginRoot: item.pluginRoot }),
33
56
  }));
34
57
  }
35
58
  }
59
+ const skilled = attachSkillTools(frozen);
60
+ diagnostics.push(...skilled.diagnostics);
61
+ // The wire schema rejects tool names shared across capabilities; report them at build time
62
+ // with both owners. Duplicates within one capability keep their registration-time error.
63
+ const toolOwners = new Map();
64
+ for (const item of skilled.items)
65
+ for (const entry of item.tools ?? []) {
66
+ const owner = toolOwners.get(entry.name);
67
+ if (owner !== undefined && owner !== item.id)
68
+ diagnostics.push(diagnostic("tool.duplicate-name", `Tool '${entry.name}' is declared by capabilities '${owner}' and '${item.id}'` +
69
+ (owner === "sandbox" || item.id === "sandbox"
70
+ ? "; sandbox() provides built-in bash, read, write, edit, grep and glob tools, so rename yours"
71
+ : "")));
72
+ else
73
+ toolOwners.set(entry.name, item.id);
74
+ }
36
75
  if (diagnostics.length)
37
76
  return Object.freeze({
38
77
  ok: false,
39
78
  diagnostics: Object.freeze(diagnostics),
40
79
  });
41
- const frozenMiddleware = Object.freeze(frozen);
80
+ const frozenMiddleware = Object.freeze(skilled.items.map((item) => Object.freeze(item)));
42
81
  const manifest = createManifest({
43
82
  id: identity.id,
44
83
  name: identity.name,
84
+ description: identity.description,
85
+ metadata: identity.metadata,
45
86
  outputSchema: identity.outputSchema,
87
+ runtime: identity.runtime,
46
88
  middleware: frozenMiddleware,
47
89
  });
48
90
  const agent = bindAgent(frozenMiddleware, manifest, identity, dynamics);
49
91
  return Object.freeze({ ok: true, agent, manifest });
50
92
  }
93
+ const SKILL_TOOL_NAMES = new Set(["load_skill", "read_skill_resource"]);
94
+ function attachSkillTools(items) {
95
+ const skills = new Map();
96
+ const diagnostics = [];
97
+ const seen = new Set();
98
+ let ownerId;
99
+ for (const item of items) {
100
+ for (const [key, skill] of Object.entries(item.skills ?? {})) {
101
+ if (key !== skill.name || seen.has(skill.name)) {
102
+ diagnostics.push(diagnostic("skill.duplicate-name", `Duplicate skill '${skill.name}' on capability '${item.id}'`));
103
+ continue;
104
+ }
105
+ seen.add(skill.name);
106
+ }
107
+ for (const [key, skill] of Object.entries(item.skillRecords ?? {})) {
108
+ if (key !== skill.name || skills.has(skill.name)) {
109
+ diagnostics.push(diagnostic("skill.duplicate-name", `Duplicate skill '${skill.name}' on capability '${item.id}'`));
110
+ continue;
111
+ }
112
+ skills.set(skill.name, skill);
113
+ ownerId ??= item.id;
114
+ }
115
+ }
116
+ if (diagnostics.length > 0 || ownerId === undefined)
117
+ return { items: [...items], diagnostics };
118
+ const skillTools = createSkillTools(skills);
119
+ const next = items.map((item) => {
120
+ if (item.id !== ownerId)
121
+ return item;
122
+ const tools = [
123
+ ...(item.tools ?? []).filter((entry) => !SKILL_TOOL_NAMES.has(entry.name)),
124
+ ...skillTools,
125
+ ];
126
+ const advertised = [...tools, ...(item.sessionTools ?? [])];
127
+ const handle = async (request, next) => item.handle(request, async () => {
128
+ request.configuration.tools.set(item.id, advertised);
129
+ return next();
130
+ });
131
+ return { ...item, tools, handle };
132
+ });
133
+ return { items: next, diagnostics };
134
+ }