@nylorun/core 0.2.0-beta → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @nylorun/core
2
2
 
3
+ ## 0.4.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - 1cd7dc7: Add subagents: put an agent in another agent's `tools` (`Agent({ tools: [lookupOrder, researcher] })` or `.use({ tools: [researcher] })`) and the model can delegate to it. The tool is named after the agent's id, takes `{ task: string }`, and its description is the agent's `description`, which is now required for an agent used as a tool. The engine runs the child inside the parent's turn as a durable branch: fresh context, its own tools and hooks served by the root agent's executor, its own MCP servers, the session's sandbox, and only its final output (or `outputSchema` result) returned. Empty output, failures (with partial output marked as evidence), and requests for input or approval inside a child reach the parent as failed tool results. Parallel delegation calls run concurrently, completed child work is never re-run on replay, and cancelling the session cancels every child.
8
+
9
+ v1 is one level deep and non-interactive. Nested delegation, child tools that declare `approval`, and differing sandboxes across the tree fail the build with a named diagnostic. The manifest adds an optional `agent` body on a tool (schema version unchanged), actions and effects carry `agent: { id, path, delegationId }`, tool context gains `ctx.agent`, the durable host resolves a new `delegation` effect kind, and the Runtime emits `delegation.started` / `delegation.completed` events and filters history with `?agent=` (`session.history({ agent })`). Studio shows delegations, labels child actions with their agent, and filters events by agent.
10
+
11
+ ## 0.3.0-beta
12
+
13
+ ### Minor Changes
14
+
15
+ - b8d822a: Studio Model Settings lists multiple vault-stored providers, adds credentials through a sheet, and switches the active provider/model via Runtime host vault APIs.
16
+ - b8d822a: Let a running Runtime learn its executors instead of receiving them all at startup.
17
+ `PUT /v1/executors` registers or rotates scoped executor credentials with the application
18
+ credential, `DELETE /v1/executors/:agentId` removes one, and `GET /v1/executors` lists them
19
+ without disclosing secrets. Registrations persist in SQLite with the token hashed at rest and
20
+ are restored on the next start; scopes supplied through `NYLORUN_EXECUTORS_JSON` still apply
21
+ to that process, take precedence for their agent, and are never written to the database. An
22
+ unchanged registration is idempotent and keeps open streams, while a rotation ends the
23
+ replaced token's work stream and stops it authorizing. Unauthenticated `/health` now also
24
+ reports the Runtime version, a non-reversible scope digest of the database path, and the
25
+ process id; all three are optional in the contract so an older host still parses. Token
26
+ hashing is adequate only because these credentials are high-entropy values minted by the
27
+ host; it is not a password derivation.
28
+ - b8d822a: Add `sandbox()`: one `.use(sandbox())` gives an agent Runtime-executed `bash`, `read`, `write`, `edit`, `grep` and `glob` tools on an isolated machine with a persistent `/workspace`. The Runtime selects a microsandbox microVM where available, otherwise an in-process virtual shell, enforces deny-by-default egress presets, owns sandbox lifecycle, and reports its choice through `GET /v1/host/sandbox`, the `nylorun dev` banner and `nylorun doctor sandbox`.
29
+ - b8d822a: Breaking beta: replace `beforeModelCall` / `afterModelCall` with scoped hooks. Register `before("turn" | "step", fn)` and `after("step" | "turn", fn)` on the agent, or `before: { turn, step }` / `after: { step, turn }` on a capability. `before("turn")` runs once per turn and its `Patch` applies to every model call in the turn; the new `after("turn")` returns a `TurnDecision` for the final answer. `after` hooks take one argument and receive `attempt`, and `retry` now retries instead of failing the run. The manifest moves to `manifestSchemaVersion: 4` with `capabilities[].hooks`, and `BeforeModelCallFn`, `AfterModelCallFn` and the `beforeModelCall` / `afterModelCall` action kinds are removed. Every capability registered at a hook point now runs in one `hook` executor action, an expired hook claim is offered again instead of becoming uncertain, and the durable engine version is `hosted-2`. Hook toggles now hide a capability's tools, or one tool of a multi-tool capability, instead of having no effect or failing. Studio lists each capability's hooks with how often they run and labels hook actions. See MIGRATION.md.
30
+
3
31
  ## 0.2.0-beta
4
32
 
5
33
  ### Minor Changes
@@ -81,6 +81,50 @@ export declare const RotateCredentialRequestSchema: z.ZodObject<{
81
81
  }, z.core.$strict>], "type">;
82
82
  }, z.core.$strict>;
83
83
  export type RotateCredentialRequest = z.infer<typeof RotateCredentialRequestSchema>;
84
+ export declare const PutHostModelRequestSchema: z.ZodObject<{
85
+ requestId: z.ZodString;
86
+ idempotencyKey: z.ZodString;
87
+ provider: z.ZodString;
88
+ model: z.ZodString;
89
+ baseUrl: z.ZodOptional<z.ZodString>;
90
+ auth: z.ZodDiscriminatedUnion<[z.ZodObject<{
91
+ type: z.ZodLiteral<"api_key">;
92
+ key: z.ZodString;
93
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
94
+ }, z.core.$strict>, z.ZodObject<{
95
+ type: z.ZodLiteral<"oauth">;
96
+ refresh: z.ZodString;
97
+ access: z.ZodString;
98
+ expires: z.ZodNumber;
99
+ }, z.core.$loose>], "type">;
100
+ }, z.core.$strict>;
101
+ export type PutHostModelRequest = z.infer<typeof PutHostModelRequestSchema>;
102
+ export type HostModelView = {
103
+ readonly configured: false;
104
+ } | {
105
+ readonly configured: true;
106
+ readonly provider: string;
107
+ readonly model: string;
108
+ readonly authType: "api_key" | "oauth";
109
+ readonly baseUrl?: string;
110
+ };
111
+ export declare const SelectHostModelRequestSchema: z.ZodObject<{
112
+ requestId: z.ZodString;
113
+ idempotencyKey: z.ZodString;
114
+ provider: z.ZodString;
115
+ model: z.ZodString;
116
+ baseUrl: z.ZodOptional<z.ZodString>;
117
+ }, z.core.$strict>;
118
+ export type SelectHostModelRequest = z.infer<typeof SelectHostModelRequestSchema>;
119
+ export type HostModelProviderInfo = {
120
+ readonly id: string;
121
+ readonly name: string;
122
+ readonly model: string;
123
+ readonly authType: "api_key" | "oauth";
124
+ readonly baseUrl?: string;
125
+ readonly lastUpdated: string;
126
+ readonly active: boolean;
127
+ };
84
128
  export interface VaultInfo {
85
129
  readonly id: string;
86
130
  readonly name: string;
@@ -232,22 +276,61 @@ export declare const RejectedResponseSchema: z.ZodObject<{
232
276
  requestId: z.ZodOptional<z.ZodString>;
233
277
  }, z.core.$strip>;
234
278
  export type RejectedResponse = z.infer<typeof RejectedResponseSchema>;
235
- export declare const ActionSchema: z.ZodObject<{
279
+ /** The agent a call belongs to. Set on work for an agent used as a tool; absent for the root. */
280
+ export declare const AgentRefSchema: z.ZodObject<{
281
+ id: z.ZodString;
282
+ path: z.ZodString;
283
+ delegationId: z.ZodOptional<z.ZodString>;
284
+ }, z.core.$strict>;
285
+ /** The hook point an action runs, and the capabilities that registered it (manifest order). */
286
+ export declare const ActionHookSchema: z.ZodObject<{
287
+ at: z.ZodEnum<{
288
+ after: "after";
289
+ before: "before";
290
+ }>;
291
+ scope: z.ZodEnum<{
292
+ step: "step";
293
+ turn: "turn";
294
+ }>;
295
+ capabilityIds: z.ZodArray<z.ZodString>;
296
+ }, z.core.$strict>;
297
+ export type ActionHook = z.infer<typeof ActionHookSchema>;
298
+ export declare const ActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
236
299
  actionId: z.ZodString;
237
300
  sessionId: z.ZodString;
238
301
  turnId: z.ZodString;
239
302
  agentId: z.ZodString;
240
303
  manifestHash: z.ZodString;
241
304
  implementationVersion: z.ZodString;
242
- kind: z.ZodEnum<{
243
- afterModelCall: "afterModelCall";
244
- beforeModelCall: "beforeModelCall";
245
- tool: "tool";
305
+ input: z.ZodUnknown;
306
+ context: z.ZodRecord<z.ZodString, z.ZodUnknown>;
307
+ status: z.ZodEnum<{
308
+ cancelled: "cancelled";
309
+ claimed: "claimed";
310
+ completed: "completed";
311
+ pending: "pending";
312
+ uncertain: "uncertain";
246
313
  }>;
314
+ generation: z.ZodNumber;
315
+ claimId: z.ZodNullable<z.ZodString>;
316
+ leaseExpiresAt: z.ZodNullable<z.ZodString>;
317
+ agent: z.ZodOptional<z.ZodObject<{
318
+ id: z.ZodString;
319
+ path: z.ZodString;
320
+ delegationId: z.ZodOptional<z.ZodString>;
321
+ }, z.core.$strict>>;
322
+ kind: z.ZodLiteral<"tool">;
247
323
  capabilityId: z.ZodString;
248
- toolName: z.ZodOptional<z.ZodString>;
324
+ toolName: z.ZodString;
249
325
  inputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
250
326
  outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
327
+ }, z.core.$strip>, z.ZodObject<{
328
+ actionId: z.ZodString;
329
+ sessionId: z.ZodString;
330
+ turnId: z.ZodString;
331
+ agentId: z.ZodString;
332
+ manifestHash: z.ZodString;
333
+ implementationVersion: z.ZodString;
251
334
  input: z.ZodUnknown;
252
335
  context: z.ZodRecord<z.ZodString, z.ZodUnknown>;
253
336
  status: z.ZodEnum<{
@@ -260,7 +343,24 @@ export declare const ActionSchema: z.ZodObject<{
260
343
  generation: z.ZodNumber;
261
344
  claimId: z.ZodNullable<z.ZodString>;
262
345
  leaseExpiresAt: z.ZodNullable<z.ZodString>;
263
- }, z.core.$strip>;
346
+ agent: z.ZodOptional<z.ZodObject<{
347
+ id: z.ZodString;
348
+ path: z.ZodString;
349
+ delegationId: z.ZodOptional<z.ZodString>;
350
+ }, z.core.$strict>>;
351
+ kind: z.ZodLiteral<"hook">;
352
+ hook: z.ZodObject<{
353
+ at: z.ZodEnum<{
354
+ after: "after";
355
+ before: "before";
356
+ }>;
357
+ scope: z.ZodEnum<{
358
+ step: "step";
359
+ turn: "turn";
360
+ }>;
361
+ capabilityIds: z.ZodArray<z.ZodString>;
362
+ }, z.core.$strict>;
363
+ }, z.core.$strip>], "kind">;
264
364
  export type Action = z.infer<typeof ActionSchema>;
265
365
  export declare const ActionClaimRequestSchema: z.ZodObject<{
266
366
  requestId: z.ZodString;
@@ -272,22 +372,42 @@ export declare const ActionHeartbeatRequestSchema: z.ZodObject<{
272
372
  generation: z.ZodNumber;
273
373
  }, z.core.$strict>;
274
374
  export declare const ActionClaimResponseSchema: z.ZodObject<{
275
- action: z.ZodObject<{
375
+ action: z.ZodDiscriminatedUnion<[z.ZodObject<{
276
376
  actionId: z.ZodString;
277
377
  sessionId: z.ZodString;
278
378
  turnId: z.ZodString;
279
379
  agentId: z.ZodString;
280
380
  manifestHash: z.ZodString;
281
381
  implementationVersion: z.ZodString;
282
- kind: z.ZodEnum<{
283
- afterModelCall: "afterModelCall";
284
- beforeModelCall: "beforeModelCall";
285
- tool: "tool";
382
+ input: z.ZodUnknown;
383
+ context: z.ZodRecord<z.ZodString, z.ZodUnknown>;
384
+ status: z.ZodEnum<{
385
+ cancelled: "cancelled";
386
+ claimed: "claimed";
387
+ completed: "completed";
388
+ pending: "pending";
389
+ uncertain: "uncertain";
286
390
  }>;
391
+ generation: z.ZodNumber;
392
+ claimId: z.ZodNullable<z.ZodString>;
393
+ leaseExpiresAt: z.ZodNullable<z.ZodString>;
394
+ agent: z.ZodOptional<z.ZodObject<{
395
+ id: z.ZodString;
396
+ path: z.ZodString;
397
+ delegationId: z.ZodOptional<z.ZodString>;
398
+ }, z.core.$strict>>;
399
+ kind: z.ZodLiteral<"tool">;
287
400
  capabilityId: z.ZodString;
288
- toolName: z.ZodOptional<z.ZodString>;
401
+ toolName: z.ZodString;
289
402
  inputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
290
403
  outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
404
+ }, z.core.$strip>, z.ZodObject<{
405
+ actionId: z.ZodString;
406
+ sessionId: z.ZodString;
407
+ turnId: z.ZodString;
408
+ agentId: z.ZodString;
409
+ manifestHash: z.ZodString;
410
+ implementationVersion: z.ZodString;
291
411
  input: z.ZodUnknown;
292
412
  context: z.ZodRecord<z.ZodString, z.ZodUnknown>;
293
413
  status: z.ZodEnum<{
@@ -300,7 +420,24 @@ export declare const ActionClaimResponseSchema: z.ZodObject<{
300
420
  generation: z.ZodNumber;
301
421
  claimId: z.ZodNullable<z.ZodString>;
302
422
  leaseExpiresAt: z.ZodNullable<z.ZodString>;
303
- }, z.core.$strip>;
423
+ agent: z.ZodOptional<z.ZodObject<{
424
+ id: z.ZodString;
425
+ path: z.ZodString;
426
+ delegationId: z.ZodOptional<z.ZodString>;
427
+ }, z.core.$strict>>;
428
+ kind: z.ZodLiteral<"hook">;
429
+ hook: z.ZodObject<{
430
+ at: z.ZodEnum<{
431
+ after: "after";
432
+ before: "before";
433
+ }>;
434
+ scope: z.ZodEnum<{
435
+ step: "step";
436
+ turn: "turn";
437
+ }>;
438
+ capabilityIds: z.ZodArray<z.ZodString>;
439
+ }, z.core.$strict>;
440
+ }, z.core.$strip>], "kind">;
304
441
  claimId: z.ZodString;
305
442
  generation: z.ZodNumber;
306
443
  leaseExpiresAt: z.ZodString;
@@ -314,9 +451,52 @@ export interface ExecutorScope {
314
451
  export declare const ExecutorNotificationSchema: z.ZodObject<{
315
452
  type: z.ZodLiteral<"work_available">;
316
453
  }, z.core.$strip>;
454
+ export declare const ExecutorRegistrationSchema: z.ZodObject<{
455
+ agentId: z.ZodString;
456
+ implementationVersion: z.ZodString;
457
+ manifestHash: z.ZodOptional<z.ZodString>;
458
+ token: z.ZodString;
459
+ }, z.core.$strict>;
460
+ export declare const RegisterExecutorsRequestSchema: z.ZodObject<{
461
+ executors: z.ZodArray<z.ZodObject<{
462
+ agentId: z.ZodString;
463
+ implementationVersion: z.ZodString;
464
+ manifestHash: z.ZodOptional<z.ZodString>;
465
+ token: z.ZodString;
466
+ }, z.core.$strict>>;
467
+ }, z.core.$strict>;
468
+ export declare const RegisterExecutorsResponseSchema: z.ZodObject<{
469
+ executors: z.ZodArray<z.ZodObject<{
470
+ agentId: z.ZodString;
471
+ implementationVersion: z.ZodString;
472
+ rotated: z.ZodBoolean;
473
+ }, z.core.$strip>>;
474
+ }, z.core.$strip>;
475
+ export declare const ExecutorSummarySchema: z.ZodObject<{
476
+ agentId: z.ZodString;
477
+ implementationVersion: z.ZodString;
478
+ manifestHash: z.ZodOptional<z.ZodString>;
479
+ connected: z.ZodBoolean;
480
+ updatedAt: z.ZodString;
481
+ }, z.core.$strip>;
482
+ export declare const ListExecutorsResponseSchema: z.ZodObject<{
483
+ executors: z.ZodArray<z.ZodObject<{
484
+ agentId: z.ZodString;
485
+ implementationVersion: z.ZodString;
486
+ manifestHash: z.ZodOptional<z.ZodString>;
487
+ connected: z.ZodBoolean;
488
+ updatedAt: z.ZodString;
489
+ }, z.core.$strip>>;
490
+ }, z.core.$strip>;
491
+ export type ExecutorRegistration = z.infer<typeof ExecutorRegistrationSchema>;
492
+ export type RegisterExecutorsResponse = z.infer<typeof RegisterExecutorsResponseSchema>;
493
+ export type ExecutorSummary = z.infer<typeof ExecutorSummarySchema>;
317
494
  export declare const HealthResponseSchema: z.ZodObject<{
318
495
  status: z.ZodLiteral<"ok">;
319
496
  service: z.ZodString;
497
+ version: z.ZodOptional<z.ZodString>;
498
+ scopeId: z.ZodOptional<z.ZodString>;
499
+ pid: z.ZodOptional<z.ZodNumber>;
320
500
  }, z.core.$strip>;
321
501
  export declare const ReadyResponseSchema: z.ZodObject<{
322
502
  status: z.ZodEnum<{
package/dist/contracts.js CHANGED
@@ -1,5 +1,9 @@
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";
5
+ import { DELEGATE_INPUT_SCHEMA } from "./definition/delegate.js";
6
+ import { canonical } from "./utils/canonical.js";
3
7
  export const PROTOCOL_VERSION = 1;
4
8
  export const RequestIdSchema = z.string().min(1);
5
9
  export const IdempotencyKeySchema = z.string().min(1).max(256);
@@ -38,17 +42,58 @@ const skillManifestSchema = z
38
42
  description: z.string().min(1),
39
43
  })
40
44
  .strict();
45
+ const sandboxManifestSchema = z
46
+ .object({
47
+ image: z.string().min(1).optional(),
48
+ network: z
49
+ .object({
50
+ preset: z.enum(SANDBOX_NETWORK_PRESETS).optional(),
51
+ allow: z
52
+ .array(z.string().refine(isSandboxHostPattern, {
53
+ message: "network.allow entries must be host names such as api.github.com or *.example.com",
54
+ }))
55
+ .optional(),
56
+ })
57
+ .strict()
58
+ .optional(),
59
+ resources: z
60
+ .object({
61
+ cpus: z.number().int().min(1).max(64).optional(),
62
+ memory: z
63
+ .string()
64
+ .refine((value) => parseSandboxSize(value) !== undefined, {
65
+ message: "resources.memory must be a size such as 512MiB or 2GiB",
66
+ })
67
+ .optional(),
68
+ })
69
+ .strict()
70
+ .optional(),
71
+ idle: z
72
+ .string()
73
+ .refine((value) => parseSandboxDuration(value) !== undefined, {
74
+ message: "idle must be a duration such as 30s, 15m or 1h",
75
+ })
76
+ .optional(),
77
+ })
78
+ .strict();
41
79
  const toolManifestSchema = z
42
80
  .object({
43
81
  name: z.string().min(1),
44
82
  description: z.string().optional(),
45
83
  inputSchema: jsonObject,
46
84
  outputSchema: jsonObject.optional(),
85
+ agent: z.lazy(() => AgentManifestSchema).optional(),
86
+ })
87
+ .strict();
88
+ const hookPointSchema = z
89
+ .object({
90
+ at: z.enum(["before", "after"]),
91
+ scope: z.enum(["turn", "step"]),
47
92
  })
48
93
  .strict();
49
94
  export const AgentManifestSchema = z
50
95
  .object({
51
- manifestSchemaVersion: z.literal(3),
96
+ manifestSchemaVersion: z.literal(4),
52
97
  id: z.string().min(1),
53
98
  name: z.string().min(1).optional(),
54
99
  description: z.string().optional(),
@@ -65,19 +110,43 @@ export const AgentManifestSchema = z
65
110
  skills: z.record(z.string(), skillManifestSchema).optional(),
66
111
  tools: z.array(toolManifestSchema).optional(),
67
112
  mcpServers: z.record(z.string(), mcpServerSchema).optional(),
68
- beforeModelCall: z.boolean().optional(),
69
- afterModelCall: z.boolean().optional(),
113
+ sandbox: sandboxManifestSchema.optional(),
114
+ hooks: z
115
+ .array(hookPointSchema)
116
+ .optional()
117
+ .superRefine((hooks, ctx) => {
118
+ const issue = hooks === undefined ? undefined : hookListIssue(hooks);
119
+ if (issue)
120
+ ctx.addIssue({ code: "custom", message: issue });
121
+ }),
70
122
  })
71
123
  .strict()),
72
124
  runtime: z.object({}).strict().optional(),
73
125
  })
74
126
  .strict()
75
127
  .superRefine((manifest, ctx) => {
128
+ delegationIssues(manifest, (message) => ctx.addIssue({ code: "custom", message }));
76
129
  const ids = new Set();
77
130
  const names = new Set();
78
131
  const servers = new Set();
79
132
  const skills = new Set();
133
+ let sandboxes = 0;
80
134
  for (const capability of manifest.capabilities) {
135
+ if (capability.sandbox) {
136
+ sandboxes += 1;
137
+ if (sandboxes > 1)
138
+ ctx.addIssue({
139
+ code: "custom",
140
+ message: "At most one capability may declare a sandbox",
141
+ });
142
+ const declared = new Set((capability.tools ?? []).map((tool) => tool.name));
143
+ for (const name of SANDBOX_TOOL_NAMES)
144
+ if (!declared.has(name))
145
+ ctx.addIssue({
146
+ code: "custom",
147
+ message: `Sandbox capability '${capability.id}' must declare the built-in '${name}' tool`,
148
+ });
149
+ }
81
150
  if (ids.has(capability.id))
82
151
  ctx.addIssue({ code: "custom", message: "Duplicate capability id" });
83
152
  ids.add(capability.id);
@@ -127,6 +196,36 @@ export const AgentManifestSchema = z
127
196
  }
128
197
  }
129
198
  });
199
+ /** Agents used as tools: one level deep, `{ task }` input, one shared sandbox spec. */
200
+ function delegationIssues(manifest, issue) {
201
+ const sandboxes = new Set();
202
+ const addSandboxes = (agent) => {
203
+ for (const capability of agent.capabilities)
204
+ if (capability.sandbox)
205
+ sandboxes.add(canonical(capability.sandbox));
206
+ };
207
+ addSandboxes(manifest);
208
+ for (const capability of manifest.capabilities)
209
+ for (const tool of capability.tools ?? []) {
210
+ const child = tool.agent;
211
+ if (!child)
212
+ continue;
213
+ if (tool.name !== child.id)
214
+ issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
215
+ if (!child.description?.trim() || tool.description !== child.description)
216
+ issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
217
+ if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
218
+ issue(`Agent tool '${tool.name}' must take the standard { task } input`);
219
+ if (tool.outputSchema !== undefined)
220
+ issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
221
+ for (const inner of child.capabilities)
222
+ if (inner.tools?.some((item) => item.agent !== undefined))
223
+ issue(`'${child.id}' delegates to another agent; nested delegation is not supported yet`);
224
+ addSandboxes(child);
225
+ }
226
+ if (sandboxes.size > 1)
227
+ issue("An agent and the agents it uses as tools must declare identical sandboxes");
228
+ }
130
229
  const absolutePath = z.string().min(1).refine((value) => value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value), { message: "plugin root must be an absolute path" });
131
230
  export const PutAgentRequestSchema = z
132
231
  .object({
@@ -231,6 +330,39 @@ export const RotateCredentialRequestSchema = z
231
330
  ]),
232
331
  })
233
332
  .strict();
333
+ export const PutHostModelRequestSchema = z
334
+ .object({
335
+ ...vaultWriteBase,
336
+ provider: z.string().min(1),
337
+ model: z.string().min(1),
338
+ baseUrl: z.string().min(1).optional(),
339
+ auth: z.discriminatedUnion("type", [
340
+ z
341
+ .object({
342
+ type: z.literal("api_key"),
343
+ key: z.string().min(1),
344
+ env: z.record(z.string(), z.string()).optional(),
345
+ })
346
+ .strict(),
347
+ z
348
+ .object({
349
+ type: z.literal("oauth"),
350
+ refresh: z.string().min(1),
351
+ access: z.string().min(1),
352
+ expires: z.number(),
353
+ })
354
+ .passthrough(),
355
+ ]),
356
+ })
357
+ .strict();
358
+ export const SelectHostModelRequestSchema = z
359
+ .object({
360
+ ...vaultWriteBase,
361
+ provider: z.string().min(1),
362
+ model: z.string().min(1),
363
+ baseUrl: z.string().min(1).optional(),
364
+ })
365
+ .strict();
234
366
  const commandBase = {
235
367
  requestId: RequestIdSchema,
236
368
  idempotencyKey: IdempotencyKeySchema,
@@ -314,25 +446,52 @@ export const RejectedResponseSchema = z.object({
314
446
  activeTurnId: z.string().optional(),
315
447
  requestId: z.string().optional(),
316
448
  });
317
- export const ActionSchema = z.object({
449
+ /** The agent a call belongs to. Set on work for an agent used as a tool; absent for the root. */
450
+ export const AgentRefSchema = z
451
+ .object({
452
+ id: z.string().min(1),
453
+ path: z.string().min(1),
454
+ delegationId: z.string().min(1).optional(),
455
+ })
456
+ .strict();
457
+ const actionBase = {
318
458
  actionId: z.string(),
319
459
  sessionId: z.string(),
320
460
  turnId: z.string(),
321
461
  agentId: z.string(),
322
462
  manifestHash: z.string(),
323
463
  implementationVersion: z.string(),
324
- kind: z.enum(["tool", "beforeModelCall", "afterModelCall"]),
325
- capabilityId: z.string(),
326
- toolName: z.string().optional(),
327
- inputSchema: jsonObject.optional(),
328
- outputSchema: jsonObject.optional(),
329
464
  input: z.unknown(),
330
465
  context: jsonObject,
331
466
  status: z.enum(["pending", "claimed", "completed", "uncertain", "cancelled"]),
332
467
  generation: z.number().int().nonnegative(),
333
468
  claimId: z.string().nullable(),
334
469
  leaseExpiresAt: z.string().nullable(),
335
- });
470
+ agent: AgentRefSchema.optional(),
471
+ };
472
+ /** The hook point an action runs, and the capabilities that registered it (manifest order). */
473
+ export const ActionHookSchema = z
474
+ .object({
475
+ at: z.enum(["before", "after"]),
476
+ scope: z.enum(["turn", "step"]),
477
+ capabilityIds: z.array(z.string().min(1)).min(1),
478
+ })
479
+ .strict();
480
+ export const ActionSchema = z.discriminatedUnion("kind", [
481
+ z.object({
482
+ ...actionBase,
483
+ kind: z.literal("tool"),
484
+ capabilityId: z.string(),
485
+ toolName: z.string(),
486
+ inputSchema: jsonObject.optional(),
487
+ outputSchema: jsonObject.optional(),
488
+ }),
489
+ z.object({
490
+ ...actionBase,
491
+ kind: z.literal("hook"),
492
+ hook: ActionHookSchema,
493
+ }),
494
+ ]);
336
495
  export const ActionClaimRequestSchema = z
337
496
  .object({
338
497
  requestId: RequestIdSchema,
@@ -355,9 +514,43 @@ export const ActionClaimResponseSchema = z.object({
355
514
  export const ExecutorNotificationSchema = z.object({
356
515
  type: z.literal("work_available"),
357
516
  });
517
+ export const ExecutorRegistrationSchema = z
518
+ .object({
519
+ agentId: z.string().min(1),
520
+ implementationVersion: z.string().min(1),
521
+ manifestHash: z.string().min(1).optional(),
522
+ token: z.string().min(16),
523
+ })
524
+ .strict();
525
+ export const RegisterExecutorsRequestSchema = z
526
+ .object({
527
+ executors: z.array(ExecutorRegistrationSchema).min(1).max(64),
528
+ })
529
+ .strict();
530
+ export const RegisterExecutorsResponseSchema = z.object({
531
+ executors: z.array(z.object({
532
+ agentId: z.string(),
533
+ implementationVersion: z.string(),
534
+ rotated: z.boolean(),
535
+ })),
536
+ });
537
+ export const ExecutorSummarySchema = z.object({
538
+ agentId: z.string(),
539
+ implementationVersion: z.string(),
540
+ manifestHash: z.string().optional(),
541
+ connected: z.boolean(),
542
+ updatedAt: z.string(),
543
+ });
544
+ export const ListExecutorsResponseSchema = z.object({
545
+ executors: z.array(ExecutorSummarySchema),
546
+ });
547
+ // Health fields added after the beta stay optional so a new client can parse an older Runtime.
358
548
  export const HealthResponseSchema = z.object({
359
549
  status: z.literal("ok"),
360
550
  service: z.string(),
551
+ version: z.string().optional(),
552
+ scopeId: z.string().optional(),
553
+ pid: z.number().int().positive().optional(),
361
554
  });
362
555
  export const ReadyResponseSchema = z.object({
363
556
  status: z.enum(["ready", "not_ready"]),
package/dist/define.d.ts CHANGED
@@ -2,20 +2,26 @@ export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./de
2
2
  export type { AgentOptions } from "./definition/builder.js";
3
3
  export { HarnessError, isHarnessError } from "./errors.js";
4
4
  export type { HarnessErrorCode, HarnessErrorDetails, HarnessErrorOptions, } from "./errors.js";
5
- export type { BuiltAgent } from "./types/agent.js";
5
+ export type { AgentTool, BuiltAgent } from "./types/agent.js";
6
+ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
7
+ export type { Delegate } from "./definition/delegate.js";
6
8
  export { capability, middleware, model, tool } from "./definition/helpers.js";
7
9
  export { ToolError, isToolError } from "./definition/tool-error.js";
8
10
  export { defineSchema } from "./definition/schema.js";
9
11
  export { hashManifest } from "./utils/hash.js";
12
+ export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
13
+ export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
14
+ export type { SandboxToolName } from "./utils/sandbox.js";
10
15
  export type { Implementations } from "./definition/implementations.js";
11
- export type { AgentManifest, CapabilityManifest, McpServerManifest, RuntimeManifest, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
12
- export type { CapabilityDeclaration, CapabilityItems, MiddlewareContributions, SkillRecord, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
13
- export type { Patch, Decision, BeforeModelCallFn, AfterModelCallFn, } from "./types/dynamics.js";
16
+ export type { AgentManifest, CapabilityManifest, McpServerManifest, RuntimeManifest, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
17
+ export type { CapabilityDeclaration, CapabilityInput, CapabilityItems, MiddlewareContributions, SkillRecord, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
18
+ export type { Patch, Decision, TurnDecision, HookAt, HookScope, HookManifest, HookState, HookToolCall, BeforeHook, AfterHook, BeforeHooks, AfterHooks, BeforeTurnArgs, BeforeStepArgs, AfterStepArgs, AfterTurnArgs, } from "./types/dynamics.js";
19
+ export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
14
20
  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
21
  export type { BuildDiagnostic, ContextItem, DeferredOutcome, JsonObject, JsonPrimitive, JsonValue, Tripwire, } from "./types/shared.js";
16
22
  export type { ObserveEvent, ObserveModelConfigurationSnapshot, ObserveModelRequested, ObserveSealedCall, ObserveToolSnapshot, Observer, } from "./types/observe.js";
17
23
  export type { InputEvent, MessageInput, InteractionReply, TranscriptEntry, UserContentPart, } from "./types/transcript.js";
18
- export type { Interaction, RequiredInteraction, ToolContent, ToolDefinition, ToolDescriptor, ToolExecutionContext, ToolExecutionResume, ToolInputSchema, ToolOutputSchema, ToolSchema, ToolSchemaSource, StandardToolSchema, StandardSchemaIssue, SchemaIssue, SchemaValidation, SchemaOutput, ToolOwner, ToolOutcome, ToolResult, ToolValidationFailureDetails, ToolEffects, ToolApproval, ToolRunResult, SessionStateBag, } from "./types/tool.js";
24
+ export type { Interaction, RequiredInteraction, ToolContent, ToolDefinition, ToolDescriptor, ToolExecutionContext, AgentRef, ToolExecutionResume, ToolInputSchema, ToolOutputSchema, ToolSchema, ToolSchemaSource, StandardToolSchema, StandardSchemaIssue, SchemaIssue, SchemaValidation, SchemaOutput, ToolOwner, ToolOutcome, ToolResult, ToolValidationFailureDetails, ToolEffects, ToolApproval, ToolRunResult, SessionStateBag, } from "./types/tool.js";
19
25
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
20
26
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
21
27
  export type { AgentBinding } from "./definition/binding.js";
package/dist/define.js CHANGED
@@ -1,9 +1,13 @@
1
1
  export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./definition/builder.js";
2
2
  export { HarnessError, isHarnessError } from "./errors.js";
3
+ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
3
4
  export { capability, middleware, model, tool } from "./definition/helpers.js";
4
5
  export { ToolError, isToolError } from "./definition/tool-error.js";
5
6
  export { defineSchema } from "./definition/schema.js";
6
7
  export { hashManifest } from "./utils/hash.js";
8
+ export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
9
+ export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
10
+ export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
7
11
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
8
12
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
9
13
  export { bindTool } from "./definition/bind-tool.js";
@@ -3,7 +3,7 @@ import type { BuiltAgent } from "../types/agent.js";
3
3
  import type { AgentManifest, RuntimeManifest } from "../types/manifest.js";
4
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,8 +14,8 @@ 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<{