@nylorun/core 0.13.0-beta → 0.15.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 (90) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/dist/compatibility.d.ts +49 -25
  3. package/dist/compatibility.js +48 -27
  4. package/dist/contracts.d.ts +318 -956
  5. package/dist/contracts.js +280 -515
  6. package/dist/define.d.ts +13 -10
  7. package/dist/define.js +7 -4
  8. package/dist/definition/assemble.d.ts +0 -3
  9. package/dist/definition/assemble.js +13 -19
  10. package/dist/definition/bind-agent.js +0 -2
  11. package/dist/definition/bind-tool.js +0 -1
  12. package/dist/definition/bound.d.ts +3 -10
  13. package/dist/definition/builder.d.ts +19 -55
  14. package/dist/definition/builder.js +19 -130
  15. package/dist/definition/capability.d.ts +3 -15
  16. package/dist/definition/capability.js +3 -25
  17. package/dist/definition/code-tools.d.ts +22 -0
  18. package/dist/definition/code-tools.js +46 -0
  19. package/dist/definition/declaration.d.ts +0 -3
  20. package/dist/definition/declaration.js +8 -11
  21. package/dist/definition/delegate.d.ts +7 -7
  22. package/dist/definition/flow/compile.d.ts +4 -5
  23. package/dist/definition/flow/compile.js +120 -72
  24. package/dist/definition/flow/from.d.ts +2 -2
  25. package/dist/definition/flow/from.js +14 -33
  26. package/dist/definition/flow/index.d.ts +2 -2
  27. package/dist/definition/flow/index.js +2 -2
  28. package/dist/definition/flow/paths.d.ts +32 -17
  29. package/dist/definition/flow/paths.js +35 -14
  30. package/dist/definition/flow/spec.d.ts +6 -9
  31. package/dist/definition/flow/spec.js +49 -31
  32. package/dist/definition/flow/types.d.ts +40 -116
  33. package/dist/definition/from.js +36 -41
  34. package/dist/definition/helpers.d.ts +1 -1
  35. package/dist/definition/helpers.js +1 -1
  36. package/dist/definition/http-tool.d.ts +66 -0
  37. package/dist/definition/http-tool.js +131 -0
  38. package/dist/definition/implementations.d.ts +0 -3
  39. package/dist/definition/manifest.js +5 -4
  40. package/dist/definition/mcp.d.ts +4 -2
  41. package/dist/definition/mcp.js +14 -18
  42. package/dist/definition/removed.d.ts +10 -0
  43. package/dist/definition/removed.js +26 -0
  44. package/dist/definition/sandbox-capability.d.ts +2 -0
  45. package/dist/definition/sandbox-capability.js +11 -1
  46. package/dist/definition/schema.js +0 -3
  47. package/dist/definition/skill-tools.d.ts +16 -2
  48. package/dist/definition/skill-tools.js +38 -31
  49. package/dist/definition/variant.d.ts +1 -1
  50. package/dist/definition/variant.js +3 -14
  51. package/dist/definition/workflow/diagnostics.d.ts +1 -7
  52. package/dist/definition/workflow/diagnostics.js +1 -24
  53. package/dist/definition/workflow/index.d.ts +3 -17
  54. package/dist/definition/workflow/index.js +2 -9
  55. package/dist/definition/workflow/runnable.d.ts +2 -34
  56. package/dist/definition/workflow/runnable.js +8 -142
  57. package/dist/definition/workflow/types.d.ts +1 -10
  58. package/dist/harness-api/messages.d.ts +24 -27
  59. package/dist/harness-api/messages.js +1 -1
  60. package/dist/harness-api/schema.d.ts +0 -16
  61. package/dist/harness-api/schema.js +5 -12
  62. package/dist/index.d.ts +1 -1
  63. package/dist/types/manifest.d.ts +41 -14
  64. package/dist/types/middleware.d.ts +11 -16
  65. package/dist/types/observe.d.ts +0 -6
  66. package/dist/types/tool.d.ts +0 -6
  67. package/dist/types/workflow.d.ts +54 -110
  68. package/dist/utils/definition-files.d.ts +31 -0
  69. package/dist/utils/definition-files.js +84 -0
  70. package/package.json +1 -1
  71. package/dist/definition/hooks.d.ts +0 -19
  72. package/dist/definition/hooks.js +0 -67
  73. package/dist/definition/workflow/build.d.ts +0 -28
  74. package/dist/definition/workflow/build.js +0 -40
  75. package/dist/definition/workflow/chain.d.ts +0 -49
  76. package/dist/definition/workflow/chain.js +0 -40
  77. package/dist/definition/workflow/loop.d.ts +0 -54
  78. package/dist/definition/workflow/loop.js +0 -100
  79. package/dist/definition/workflow/map.d.ts +0 -17
  80. package/dist/definition/workflow/map.js +0 -45
  81. package/dist/definition/workflow/parallel.d.ts +0 -19
  82. package/dist/definition/workflow/parallel.js +0 -36
  83. package/dist/definition/workflow/patch.d.ts +0 -11
  84. package/dist/definition/workflow/patch.js +0 -45
  85. package/dist/definition/workflow/slot.d.ts +0 -23
  86. package/dist/definition/workflow/slot.js +0 -16
  87. package/dist/definition/workflow/switch.d.ts +0 -26
  88. package/dist/definition/workflow/switch.js +0 -64
  89. package/dist/types/dynamics.d.ts +0 -101
  90. package/dist/types/dynamics.js +0 -1
package/dist/contracts.js CHANGED
@@ -1,10 +1,14 @@
1
1
  /** Public wire contracts only. Never import checkpoint or engine modules here. */
2
2
  import { z } from "zod";
3
3
  import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
4
- import { hookListIssue } from "./definition/hooks.js";
4
+ import { REMOVED_CAPABILITY_FIELDS, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.js";
5
5
  import { DELEGATE_INPUT_SCHEMA } from "./definition/delegate.js";
6
+ import { stdioMcpRefusal } from "./definition/mcp.js";
7
+ import { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpUrlIssue, } from "./definition/http-tool.js";
6
8
  import { canonical } from "./utils/canonical.js";
9
+ import { DEFINITION_FILE_MAX_BYTES, skillFilesIssue } from "./utils/definition-files.js";
7
10
  export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
11
+ export { DEFINITION_FILE_MAX_BYTES, SKILL_FILES_MAX, definitionFilesOf, isDefinitionFileHash, } from "./utils/definition-files.js";
8
12
  import { ERROR_CODES } from "./compatibility.js";
9
13
  export const RequestIdSchema = z.string().min(1);
10
14
  export const IdempotencyKeySchema = z.string().min(1).max(256);
@@ -22,22 +26,13 @@ const jsonValue = z
22
26
  ]))
23
27
  .meta({ id: "JsonValue" });
24
28
  const mcpServerSchema = z.discriminatedUnion("type", [
25
- z
26
- .object({
27
- name: z.string().min(1),
28
- type: z.literal("stdio"),
29
- command: z.string().min(1),
30
- args: z.array(z.string()).optional(),
31
- env: z.record(z.string(), z.string()).optional(),
32
- cwd: z.string().optional(),
33
- })
34
- .strict(),
35
29
  z
36
30
  .object({
37
31
  name: z.string().min(1),
38
32
  type: z.literal("streamable-http"),
39
33
  url: z.string().min(1),
40
34
  headers: z.record(z.string(), z.string()).optional(),
35
+ approval: z.enum(APPROVAL_MODES).optional(),
41
36
  })
42
37
  .strict(),
43
38
  z
@@ -46,13 +41,28 @@ const mcpServerSchema = z.discriminatedUnion("type", [
46
41
  type: z.literal("sse"),
47
42
  url: z.string().min(1),
48
43
  headers: z.record(z.string(), z.string()).optional(),
44
+ approval: z.enum(APPROVAL_MODES).optional(),
49
45
  })
50
46
  .strict(),
51
- ]);
47
+ ], { error: (issue) => stdioIssue(issue.input) });
48
+ /** The refusal of a `stdio` server; other bad declarations keep zod's own message. */
49
+ function stdioIssue(input) {
50
+ if (!input || typeof input !== "object")
51
+ return undefined;
52
+ const server = input;
53
+ if (server.type !== "stdio")
54
+ return undefined;
55
+ return stdioMcpRefusal(typeof server.name === "string" ? server.name : "(unnamed)");
56
+ }
52
57
  const skillManifestSchema = z
53
58
  .object({
54
59
  name: z.string().min(1),
55
60
  description: z.string().min(1),
61
+ files: z.record(z.string(), z.string()).superRefine((files, ctx) => {
62
+ const issue = skillFilesIssue(files);
63
+ if (issue)
64
+ ctx.addIssue({ code: "custom", message: `Skill ${issue}` });
65
+ }),
56
66
  })
57
67
  .strict();
58
68
  const sandboxManifestSchema = z
@@ -89,6 +99,26 @@ const sandboxManifestSchema = z
89
99
  .optional(),
90
100
  })
91
101
  .strict();
102
+ const httpToolTargetSchema = z
103
+ .object({
104
+ url: z.string().superRefine((url, ctx) => {
105
+ const issue = httpUrlIssue(url);
106
+ if (issue)
107
+ ctx.addIssue({ code: "custom", message: issue });
108
+ }),
109
+ method: z.enum(HTTP_TOOL_METHODS).optional(),
110
+ credential: z.string().min(1).optional(),
111
+ timeoutMs: z.number().int().positive().max(HTTP_TOOL_MAX_TIMEOUT_MS).optional(),
112
+ })
113
+ .strict();
114
+ /** A name kept for a later kind of `what` (tool, verifier), refused for now. */
115
+ const reservedKind = (what) => z
116
+ .unknown()
117
+ .refine((value) => value === undefined, { message: "Functions are not available yet" })
118
+ .optional()
119
+ .meta({ description: `Reserved for a later kind of ${what}; refused for now.` });
120
+ /** Names kept for later kinds of tool, beside `agent` and `http`. */
121
+ const reservedToolKind = reservedKind("tool");
92
122
  const toolManifestSchema = z
93
123
  .object({
94
124
  name: z.string().min(1),
@@ -96,27 +126,44 @@ const toolManifestSchema = z
96
126
  inputSchema: jsonObject,
97
127
  outputSchema: jsonObject.optional(),
98
128
  agent: z
99
- .lazy(() => z.union([workflowV2ManifestSchema, AgentManifestSchema]))
129
+ .lazy(() => z.union([workflowManifestSchema, AgentManifestSchema]))
100
130
  .meta({ id: "ToolAgentManifest" })
101
131
  .optional(),
132
+ http: httpToolTargetSchema.optional(),
133
+ approval: z.enum(APPROVAL_MODES).optional(),
134
+ fn: reservedToolKind,
135
+ command: reservedToolKind,
102
136
  })
103
- .strict();
104
- const hookPointSchema = z
105
- .object({
106
- at: z.enum(["before", "after"]),
107
- scope: z.enum(["turn", "step"]),
108
- })
109
- .strict();
137
+ .strict()
138
+ .superRefine((tool, ctx) => {
139
+ if (tool.agent !== undefined && tool.http !== undefined)
140
+ ctx.addIssue({
141
+ code: "custom",
142
+ message: `Tool '${tool.name}' is an agent or an HTTP request, not both`,
143
+ });
144
+ if (tool.approval !== undefined && tool.http === undefined)
145
+ ctx.addIssue({
146
+ code: "custom",
147
+ path: ["approval"],
148
+ message: `Tool '${tool.name}' takes approval only as an HTTP tool`,
149
+ });
150
+ });
151
+ /** A capability naming a field manifest v5 removed is refused with what replaces it. */
152
+ const removedFieldError = (issue) => {
153
+ if (issue.code !== "unrecognized_keys")
154
+ return undefined;
155
+ const removed = issue.keys?.find((key) => REMOVED_CAPABILITY_FIELDS[key] !== undefined);
156
+ return removed === undefined ? undefined : REMOVED_CAPABILITY_FIELDS[removed];
157
+ };
110
158
  export const AgentManifestSchema = z
111
159
  .object({
112
- manifestSchemaVersion: z.literal(4),
160
+ manifestSchemaVersion: z.literal(5, { error: (issue) => manifestVersionIssue(issue.input) }),
113
161
  id: z.string().min(1),
114
162
  name: z.string().min(1).optional(),
115
163
  description: z.string().optional(),
116
164
  metadata: jsonObject.optional(),
117
165
  outputSchema: jsonObject.optional(),
118
- capabilities: z.array(z
119
- .object({
166
+ capabilities: z.array(z.strictObject({
120
167
  id: z.string().min(1),
121
168
  type: z.enum(["agent", "agent-plugin"]),
122
169
  name: z.string().min(1).optional(),
@@ -127,20 +174,16 @@ export const AgentManifestSchema = z
127
174
  tools: z.array(toolManifestSchema).optional(),
128
175
  mcpServers: z.record(z.string(), mcpServerSchema).optional(),
129
176
  sandbox: sandboxManifestSchema.optional(),
130
- hooks: z
131
- .array(hookPointSchema)
132
- .optional()
133
- .superRefine((hooks, ctx) => {
134
- const issue = hooks === undefined ? undefined : hookListIssue(hooks);
135
- if (issue)
136
- ctx.addIssue({ code: "custom", message: issue });
137
- }),
138
- })
139
- .strict()),
177
+ }, { error: removedFieldError })),
140
178
  runtime: z.object({}).strict().optional(),
179
+ // Reserved for Functions, which are deferred: developer code the Runtime will run from
180
+ // uploaded definition files (a `functions/` folder). Any value is refused below.
181
+ functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
141
182
  })
142
183
  .strict()
143
184
  .superRefine((manifest, ctx) => {
185
+ if (manifest.functions !== undefined)
186
+ ctx.addIssue({ code: "custom", path: ["functions"], message: "Functions are not available yet" });
144
187
  delegationIssues(manifest, (message) => ctx.addIssue({ code: "custom", message }));
145
188
  const ids = new Set();
146
189
  const names = new Set();
@@ -256,10 +299,38 @@ function delegationIssues(manifest, issue) {
256
299
  if (sandboxes.size > 1)
257
300
  issue("An agent and the agents it uses as tools must declare identical sandboxes");
258
301
  }
259
- const absolutePath = z.string().min(1).refine((value) => value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value), { message: "plugin root must be an absolute path" });
260
- const workflowFnRefSchema = z.object({ fn: z.literal(true) }).strict();
302
+ // Workflow manifest v3 (flow agents): `id` on any node, embedded agents, no functions.
303
+ const workflowNodeOptions = { id: z.string().min(1).optional() };
304
+ const workflowAgentNodeSchema = z
305
+ .object({ agent: z.string().min(1), ...workflowNodeOptions })
306
+ .strict();
307
+ /**
308
+ * What judges a Loop attempt: a verifier agent (`{ agent, id? }`) or an HTTP verifier
309
+ * (`{ http }`). `fn` and `command` are reserved for later kinds of verifier.
310
+ */
311
+ const workflowLoopVerifySchema = z
312
+ .object({
313
+ agent: z.string().min(1).optional(),
314
+ http: httpToolTargetSchema.optional(),
315
+ fn: reservedKind("verifier"),
316
+ command: reservedKind("verifier"),
317
+ ...workflowNodeOptions,
318
+ })
319
+ .strict()
320
+ .superRefine((verify, ctx) => {
321
+ if (verify.fn !== undefined || verify.command !== undefined)
322
+ return;
323
+ if ((verify.agent === undefined) === (verify.http === undefined))
324
+ ctx.addIssue({
325
+ code: "custom",
326
+ message: "A Loop's verify is a verifier agent ({ agent }) or an HTTP verifier ({ http }): exactly one",
327
+ });
328
+ else if (verify.http !== undefined && verify.id !== undefined)
329
+ ctx.addIssue({ code: "custom", path: ["id"], message: "An HTTP verifier takes no id" });
330
+ })
331
+ .meta({ id: "WorkflowLoopVerify" });
261
332
  const workflowNodeSchema = z.lazy(() => z.union([
262
- z.object({ agent: z.string().min(1) }).strict(),
333
+ workflowAgentNodeSchema,
263
334
  z
264
335
  .object({
265
336
  tool: z
@@ -268,173 +339,60 @@ const workflowNodeSchema = z.lazy(() => z.union([
268
339
  description: z.string().optional(),
269
340
  inputSchema: jsonObject.optional(),
270
341
  outputSchema: jsonObject.optional(),
342
+ /** An HTTP stage: the Runtime makes the request, as for an agent's HTTP tool. */
343
+ http: httpToolTargetSchema.optional(),
271
344
  })
272
345
  .strict(),
346
+ ...workflowNodeOptions,
273
347
  })
274
348
  .strict(),
275
- z
276
- .object({
277
- chain: z
278
- .object({
279
- id: z.string().min(1),
280
- steps: z.array(workflowNodeSchema).min(1),
281
- })
282
- .strict(),
283
- })
284
- .strict(),
349
+ z.object({ chain: z.array(workflowNodeSchema).min(1), ...workflowNodeOptions }).strict(),
285
350
  z
286
351
  .object({
287
352
  switch: z
288
353
  .object({
289
- id: z.string().min(1),
290
- on: workflowFnRefSchema,
291
354
  cases: z.record(z.string(), workflowNodeSchema),
292
355
  default: workflowNodeSchema.optional(),
293
356
  })
294
357
  .strict(),
358
+ ...workflowNodeOptions,
295
359
  })
296
360
  .strict(),
297
361
  z
298
362
  .object({
299
363
  parallel: z
300
- .object({
301
- id: z.string().min(1),
302
- branches: z.record(z.string(), workflowNodeSchema),
303
- })
304
- .strict(),
305
- })
306
- .strict(),
307
- z
308
- .object({
309
- map: z
310
- .object({
311
- id: z.string().min(1),
312
- over: workflowFnRefSchema,
313
- each: workflowNodeSchema,
314
- })
315
- .strict(),
316
- })
317
- .strict(),
318
- z
319
- .object({
320
- loop: z
321
- .object({
322
- id: z.string().min(1),
323
- run: workflowNodeSchema,
324
- verify: z.union([
325
- workflowFnRefSchema,
326
- z.object({ agent: z.string().min(1) }).strict(),
327
- z
328
- .object({
329
- slot: z
330
- .object({
331
- id: z.string().min(1).optional(),
332
- input: workflowFnRefSchema.optional(),
333
- run: workflowNodeSchema,
334
- })
335
- .strict(),
336
- })
337
- .strict(),
338
- ]),
339
- decide: workflowFnRefSchema,
340
- })
341
- .strict(),
342
- })
343
- .strict(),
344
- z
345
- .object({
346
- slot: z
347
- .object({
348
- id: z.string().min(1).optional(),
349
- input: workflowFnRefSchema.optional(),
350
- run: workflowNodeSchema,
351
- })
352
- .strict(),
353
- })
354
- .strict(),
355
- ])).meta({ id: "WorkflowNode" });
356
- const workflowV1ManifestSchema = z
357
- .object({
358
- kind: z.literal("workflow"),
359
- workflowSchemaVersion: z.literal(1),
360
- id: z.string().min(1),
361
- root: workflowNodeSchema,
362
- sandbox: sandboxManifestSchema.optional(),
363
- })
364
- .strict();
365
- // v2 (Flow Agents): `id` and `input` on any node, no slots, embedded agents.
366
- const workflowNodeOptionsV2 = {
367
- id: z.string().min(1).optional(),
368
- input: workflowFnRefSchema.optional(),
369
- };
370
- const workflowAgentNodeV2Schema = z
371
- .object({ agent: z.string().min(1), ...workflowNodeOptionsV2 })
372
- .strict();
373
- const workflowNodeV2Schema = z.lazy(() => z.union([
374
- workflowAgentNodeV2Schema,
375
- z
376
- .object({
377
- tool: z
378
- .object({
379
- name: z.string().min(1),
380
- description: z.string().optional(),
381
- inputSchema: jsonObject.optional(),
382
- outputSchema: jsonObject.optional(),
383
- })
384
- .strict(),
385
- ...workflowNodeOptionsV2,
386
- })
387
- .strict(),
388
- z.object({ chain: z.array(workflowNodeV2Schema).min(1), ...workflowNodeOptionsV2 }).strict(),
389
- z
390
- .object({
391
- switch: z
392
- .object({
393
- on: workflowFnRefSchema,
394
- cases: z.record(z.string(), workflowNodeV2Schema),
395
- default: workflowNodeV2Schema.optional(),
396
- })
397
- .strict(),
398
- ...workflowNodeOptionsV2,
399
- })
400
- .strict(),
401
- z
402
- .object({
403
- parallel: z
404
- .record(z.string(), workflowNodeV2Schema)
364
+ .record(z.string(), workflowNodeSchema)
405
365
  .refine((branches) => Object.keys(branches).length > 0, {
406
366
  message: "parallel needs at least one branch",
407
367
  }),
408
- ...workflowNodeOptionsV2,
368
+ ...workflowNodeOptions,
409
369
  })
410
370
  .strict(),
411
371
  z
412
372
  .object({
413
- map: z.object({ each: workflowNodeV2Schema }).strict(),
414
- ...workflowNodeOptionsV2,
373
+ map: z.object({ each: workflowNodeSchema }).strict(),
374
+ ...workflowNodeOptions,
415
375
  })
416
376
  .strict(),
417
377
  z
418
378
  .object({
419
379
  loop: z
420
380
  .object({
421
- run: workflowNodeV2Schema,
422
- verify: z.union([workflowFnRefSchema, workflowAgentNodeV2Schema]),
423
- max: z.number().int().positive().optional(),
424
- decide: workflowFnRefSchema.optional(),
381
+ run: workflowNodeSchema,
382
+ verify: workflowLoopVerifySchema,
383
+ max: z.number().int().positive(),
425
384
  })
426
- .strict()
427
- .refine((loop) => loop.max !== undefined || loop.decide !== undefined, {
428
- message: "loop needs max or decide",
429
- }),
430
- ...workflowNodeOptionsV2,
385
+ .strict(),
386
+ ...workflowNodeOptions,
431
387
  })
432
388
  .strict(),
433
- ])).meta({ id: "WorkflowNodeV2" });
434
- const workflowV2ManifestSchema = z.lazy(() => z
389
+ ])).meta({ id: "WorkflowNode" });
390
+ const workflowManifestSchema = z.lazy(() => z
435
391
  .object({
436
392
  kind: z.literal("workflow"),
437
- workflowSchemaVersion: z.literal(2),
393
+ workflowSchemaVersion: z.literal(3, {
394
+ error: (issue) => workflowVersionIssue(issue.input),
395
+ }),
438
396
  id: z.string().min(1),
439
397
  name: z.string().min(1).optional(),
440
398
  description: z.string().optional(),
@@ -442,8 +400,8 @@ const workflowV2ManifestSchema = z.lazy(() => z
442
400
  inputSchema: jsonObject.optional(),
443
401
  outputSchema: jsonObject.optional(),
444
402
  sandbox: sandboxManifestSchema.optional(),
445
- root: workflowNodeV2Schema,
446
- agents: z.record(z.string().min(1), z.union([workflowV2ManifestSchema, AgentManifestSchema])),
403
+ root: workflowNodeSchema,
404
+ agents: z.record(z.string().min(1), z.union([workflowManifestSchema, AgentManifestSchema])),
447
405
  })
448
406
  .strict()
449
407
  .superRefine((manifest, ctx) => {
@@ -463,7 +421,7 @@ const workflowV2ManifestSchema = z.lazy(() => z
463
421
  message: `Embedded agent '${agent.id}' must be keyed by its id`,
464
422
  });
465
423
  }
466
- })).meta({ id: "WorkflowV2Manifest" });
424
+ })).meta({ id: "WorkflowManifest" });
467
425
  function referencedAgents(node) {
468
426
  const out = [];
469
427
  const visit = (child) => {
@@ -490,10 +448,7 @@ function referencedAgents(node) {
490
448
  return out;
491
449
  }
492
450
  /** Workflow definition document. `kind: "workflow"`; a missing `kind` is never a workflow. */
493
- export const WorkflowManifestSchema = z.union([
494
- workflowV1ManifestSchema,
495
- workflowV2ManifestSchema,
496
- ]);
451
+ export const WorkflowManifestSchema = workflowManifestSchema;
497
452
  /** Registry document: agent (no `kind`, or legacy) or workflow (`kind: "workflow"`). */
498
453
  export const DefinitionDocumentSchema = z.union([
499
454
  AgentManifestSchema,
@@ -505,7 +460,6 @@ export const PutAgentRequestSchema = z
505
460
  /** Agent or workflow document. Registry `kind` is carried on the document. */
506
461
  manifest: DefinitionDocumentSchema,
507
462
  implementationVersion: z.string().min(1),
508
- pluginRoots: z.record(z.string(), absolutePath).optional(),
509
463
  })
510
464
  .strict();
511
465
  export const CredentialSelectionSchema = z
@@ -873,7 +827,7 @@ export const CreateVaultRequestSchema = z
873
827
  /**
874
828
  * `user` (the default): one person's vault, owned by `ownerUserId`. `installation`: the
875
829
  * installation's own vault, owned by `installation`, which any session may attach;
876
- * application keys only.
830
+ * management keys only (the Management API).
877
831
  */
878
832
  scope: z.enum(["user", "installation"]).optional(),
879
833
  /** Required for a `user` vault; absent (or `installation`) for an installation vault. */
@@ -1054,7 +1008,8 @@ export const MessageEventBodySchema = z.union([
1054
1008
  })
1055
1009
  .strict(),
1056
1010
  ]);
1057
- export const ActionOutcomeSchema = z
1011
+ /** What one effect came to: its value, and the agent state it changes. */
1012
+ export const EffectOutcomeSchema = z
1058
1013
  .object({
1059
1014
  value: z.unknown(),
1060
1015
  statePatch: jsonObject.optional(),
@@ -1181,82 +1136,6 @@ export const AgentRefSchema = z
1181
1136
  delegationId: z.string().min(1).optional(),
1182
1137
  })
1183
1138
  .strict();
1184
- const actionBase = {
1185
- actionId: z.string(),
1186
- sessionId: z.string(),
1187
- turnId: z.string(),
1188
- agentId: z.string(),
1189
- manifestHash: z.string(),
1190
- implementationVersion: z.string(),
1191
- input: z.unknown(),
1192
- context: jsonObject,
1193
- /** `delivering`: sent to the agent's Action endpoint, not answered yet. */
1194
- status: z.enum(["pending", "delivering", "completed", "uncertain", "cancelled"]),
1195
- /** How many times it was delivered; a delivery token names the one it is for. */
1196
- generation: z.number().int().nonnegative(),
1197
- /** When an unanswered delivery counts as lost. Set only while `delivering`. */
1198
- deadlineAt: z.string().nullable().optional(),
1199
- agent: AgentRefSchema.optional(),
1200
- };
1201
- /** The hook point an action runs, and the capabilities that registered it (manifest order). */
1202
- export const ActionHookSchema = z
1203
- .object({
1204
- at: z.enum(["before", "after"]),
1205
- scope: z.enum(["turn", "step"]),
1206
- capabilityIds: z.array(z.string().min(1)).min(1),
1207
- })
1208
- .strict();
1209
- const agentToolActionSchema = z
1210
- .object({
1211
- ...actionBase,
1212
- kind: z.literal("tool"),
1213
- capabilityId: z.string(),
1214
- toolName: z.string(),
1215
- inputSchema: jsonObject.optional(),
1216
- outputSchema: jsonObject.optional(),
1217
- })
1218
- .strict();
1219
- /** Tool node on a workflow: routed by path + key instead of capabilityId. */
1220
- const workflowToolActionSchema = z
1221
- .object({
1222
- ...actionBase,
1223
- kind: z.literal("tool"),
1224
- path: z.string().min(1),
1225
- key: z.string().min(1),
1226
- inputSchema: jsonObject.optional(),
1227
- outputSchema: jsonObject.optional(),
1228
- })
1229
- .strict();
1230
- const hookActionSchema = z
1231
- .object({
1232
- ...actionBase,
1233
- kind: z.literal("hook"),
1234
- hook: ActionHookSchema,
1235
- })
1236
- .strict();
1237
- const fnActionSchema = z
1238
- .object({
1239
- ...actionBase,
1240
- kind: z.literal("fn"),
1241
- path: z.string().min(1),
1242
- key: z.string().min(1),
1243
- })
1244
- .strict();
1245
- const verifyActionSchema = z
1246
- .object({
1247
- ...actionBase,
1248
- kind: z.literal("verify"),
1249
- path: z.string().min(1),
1250
- key: z.string().min(1),
1251
- })
1252
- .strict();
1253
- export const ActionSchema = z.union([
1254
- agentToolActionSchema,
1255
- workflowToolActionSchema,
1256
- hookActionSchema,
1257
- fnActionSchema,
1258
- verifyActionSchema,
1259
- ]);
1260
1139
  /**
1261
1140
  * Transcript events (Host feature `transcript-events`): the log entries a chat UI
1262
1141
  * renders. They are part of the event catalog (`EVENT_CATALOG`); `parseTranscriptEvent`
@@ -1320,7 +1199,7 @@ export const ContextCompactedPayloadSchema = z
1320
1199
  ...eventAgent,
1321
1200
  })
1322
1201
  .passthrough();
1323
- /** `tool.completed`: an MCP or sandbox tool the Runtime ran. `error` for a tool error. */
1202
+ /** `tool.completed`: a tool the Runtime ran (HTTP, MCP, sandbox, built-in). `error` for a tool error. */
1324
1203
  export const ToolCompletedPayloadSchema = z
1325
1204
  .object({
1326
1205
  ...toolIds,
@@ -1331,27 +1210,6 @@ export const ToolCompletedPayloadSchema = z
1331
1210
  ...eventAgent,
1332
1211
  })
1333
1212
  .passthrough();
1334
- /** `action.pending` and `action.completed`; tool actions carry `callId` and `invocationId`. */
1335
- const actionEventBase = {
1336
- actionId: z.string().min(1),
1337
- kind: z.string(),
1338
- toolName: z.string().optional(),
1339
- /** A workflow Action: its node's path and key. */
1340
- path: z.string().optional(),
1341
- key: z.string().optional(),
1342
- callId: z.string().optional(),
1343
- invocationId: z.string().optional(),
1344
- ...eventAgent,
1345
- };
1346
- export const ActionPendingPayloadSchema = z
1347
- .object({ ...actionEventBase, input: z.unknown() })
1348
- .passthrough();
1349
- export const ActionCompletedPayloadSchema = z
1350
- .object({ ...actionEventBase, result: z.unknown() })
1351
- .passthrough();
1352
- export const ActionUncertainPayloadSchema = z
1353
- .object({ actionId: z.string().min(1), ...eventAgent })
1354
- .passthrough();
1355
1213
  export const EffectUncertainPayloadSchema = z
1356
1214
  .object({ effectId: z.string().min(1), message: z.string().optional() })
1357
1215
  .passthrough();
@@ -1363,6 +1221,8 @@ export const TurnPausedPayloadSchema = z
1363
1221
  interactions: z.array(z
1364
1222
  .object({
1365
1223
  invocationId: z.string().min(1),
1224
+ /** The model's tool call id, when an agent's tool call asked. */
1225
+ callId: z.string().min(1).optional(),
1366
1226
  interaction: z
1367
1227
  .object({ id: z.string().min(1), kind: z.string() })
1368
1228
  .passthrough(),
@@ -1396,9 +1256,6 @@ const TRANSCRIPT_PAYLOADS = {
1396
1256
  "model.failed": ModelFailedPayloadSchema,
1397
1257
  "context.compacted": ContextCompactedPayloadSchema,
1398
1258
  "tool.completed": ToolCompletedPayloadSchema,
1399
- "action.pending": ActionPendingPayloadSchema,
1400
- "action.completed": ActionCompletedPayloadSchema,
1401
- "action.uncertain": ActionUncertainPayloadSchema,
1402
1259
  "effect.uncertain": EffectUncertainPayloadSchema,
1403
1260
  "turn.completed": TurnCompletedPayloadSchema,
1404
1261
  "turn.paused": TurnPausedPayloadSchema,
@@ -1439,24 +1296,6 @@ export const CommandRespondPayloadSchema = z
1439
1296
  value: z.unknown(),
1440
1297
  })
1441
1298
  .passthrough();
1442
- /** `action.delivered`: the Runtime sent an Action to its endpoint. */
1443
- export const ActionDeliveredPayloadSchema = z
1444
- .object({
1445
- actionId: z.string().min(1),
1446
- generation: z.number().int().positive(),
1447
- ...eventAgent,
1448
- })
1449
- .passthrough();
1450
- /** `action.delivery_failed`: a delivery did not reach its endpoint, or was refused; it is retried. */
1451
- export const ActionDeliveryFailedPayloadSchema = z
1452
- .object({
1453
- actionId: z.string().min(1),
1454
- generation: z.number().int().positive(),
1455
- reason: z.string(),
1456
- message: z.string().optional(),
1457
- retryInMs: z.number().int().nonnegative(),
1458
- })
1459
- .passthrough();
1460
1299
  /** `sandbox.state`: the session's sandbox changed state. */
1461
1300
  export const SandboxStatePayloadSchema = z
1462
1301
  .object({
@@ -1488,7 +1327,7 @@ export const SandboxExecPayloadSchema = z
1488
1327
  durationMs: z.number().nonnegative(),
1489
1328
  })
1490
1329
  .passthrough();
1491
- /** `node.started`: a workflow node that runs an Action started. */
1330
+ /** `node.started`: a workflow tool node started. */
1492
1331
  export const NodeStartedPayloadSchema = z
1493
1332
  .object({
1494
1333
  path: z.string(),
@@ -1526,15 +1365,6 @@ export const LoopVerifiedPayloadSchema = z
1526
1365
  data: z.unknown().optional(),
1527
1366
  })
1528
1367
  .passthrough();
1529
- /** `loop.decided`: a Loop's decide step chose to iterate again (`input`) or finish (`output`). */
1530
- export const LoopDecidedPayloadSchema = z
1531
- .object({
1532
- path: z.string(),
1533
- n: z.number().int(),
1534
- next: z.enum(["input", "output"]),
1535
- patched: z.boolean(),
1536
- })
1537
- .passthrough();
1538
1368
  /**
1539
1369
  * `transcript.updated` (internal; blueprint P0.3): the own loop's model-facing transcript after a
1540
1370
  * settled segment, as an edit of the previous one: keep its first `keep` entries, then append
@@ -1621,6 +1451,30 @@ export const ArtifactExportSkippedPayloadSchema = z
1621
1451
  export const ArtifactExportFailedPayloadSchema = z
1622
1452
  .object({ name: z.string(), message: z.string() })
1623
1453
  .passthrough();
1454
+ /** What readying one declared MCP server found (`mcp.discovered`). */
1455
+ export const McpServerOutcomeSchema = z
1456
+ .object({
1457
+ /** The agent used as a tool that declares the server; absent for the session's root agent. */
1458
+ agentId: z.string().optional(),
1459
+ capabilityId: z.string(),
1460
+ serverName: z.string(),
1461
+ /** `refused`: the vault has no usable credential for it; `failed`: it could not be reached or listed. */
1462
+ outcome: z.enum(["connected", "refused", "failed"]),
1463
+ message: z.string(),
1464
+ /** The tools it added to the session; 0 unless connected. */
1465
+ tools: z.number().int().nonnegative(),
1466
+ /** The credentials a refusal names. */
1467
+ credentialIds: z.array(z.string()).optional(),
1468
+ })
1469
+ .passthrough();
1470
+ /**
1471
+ * `mcp.discovered`: the session's first turn readied its MCP servers and pinned the tools they
1472
+ * offer, one outcome per declared server. A server that did not connect adds no tools for the
1473
+ * session's life, so this is where the model's missing tools show (also `mcpDiagnostics`).
1474
+ */
1475
+ export const McpDiscoveredPayloadSchema = z
1476
+ .object({ servers: z.array(McpServerOutcomeSchema) })
1477
+ .passthrough();
1624
1478
  /**
1625
1479
  * The event catalog (Durable Streams §9.5): every session event type, its payload schema, its
1626
1480
  * payload schema version and who writes it. A type not listed here cannot be written. A type
@@ -1643,18 +1497,10 @@ export const EVENT_CATALOG = {
1643
1497
  "model.failed": { payload: ModelFailedPayloadSchema, source: "loop", version: 1 },
1644
1498
  "context.compacted": { payload: ContextCompactedPayloadSchema, source: "loop", version: 1 },
1645
1499
  "tool.completed": { payload: ToolCompletedPayloadSchema, source: "loop", version: 1 },
1646
- "action.pending": { payload: ActionPendingPayloadSchema, source: "loop", version: 1 },
1647
- "action.delivered": { payload: ActionDeliveredPayloadSchema, source: "loop", version: 1 },
1648
- "action.delivery_failed": {
1649
- payload: ActionDeliveryFailedPayloadSchema,
1650
- source: "loop",
1651
- version: 1,
1652
- },
1653
- "action.completed": { payload: ActionCompletedPayloadSchema, source: "api", version: 1 },
1654
- "action.uncertain": { payload: ActionUncertainPayloadSchema, source: "loop", version: 1 },
1655
1500
  "effect.uncertain": { payload: EffectUncertainPayloadSchema, source: "loop", version: 1 },
1656
1501
  "delegation.started": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
1657
1502
  "delegation.completed": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
1503
+ "mcp.discovered": { payload: McpDiscoveredPayloadSchema, source: "loop", version: 1 },
1658
1504
  "sandbox.state": { payload: SandboxStatePayloadSchema, source: "loop", version: 1 },
1659
1505
  "sandbox.exec": { payload: SandboxExecPayloadSchema, source: "loop", version: 1 },
1660
1506
  "sandbox.attached": { payload: SandboxAttachedPayloadSchema, source: "api", version: 1 },
@@ -1662,7 +1508,6 @@ export const EVENT_CATALOG = {
1662
1508
  "node.agent": { payload: NodeAgentPayloadSchema, source: "loop", version: 1 },
1663
1509
  "loop.iteration": { payload: LoopIterationPayloadSchema, source: "loop", version: 1 },
1664
1510
  "loop.verified": { payload: LoopVerifiedPayloadSchema, source: "api", version: 1 },
1665
- "loop.decided": { payload: LoopDecidedPayloadSchema, source: "api", version: 1 },
1666
1511
  "artifact.created": { payload: ArtifactVersionPayloadSchema, source: "api", version: 1 },
1667
1512
  "artifact.version.created": {
1668
1513
  payload: ArtifactVersionPayloadSchema,
@@ -1748,6 +1593,10 @@ export const ReadyResponseSchema = z.object({
1748
1593
  status: z.enum(["ready", "not_ready"]),
1749
1594
  service: z.string(),
1750
1595
  checks: z.record(z.string(), z.boolean()),
1596
+ /** The open Tenant's harnesses: `connected` counts those on the Harness API listener. */
1597
+ harness: z
1598
+ .object({ mode: z.enum(["remote", "in-process"]), connected: z.number().int().nonnegative() })
1599
+ .optional(),
1751
1600
  });
1752
1601
  export const ProtocolRejectedResponseSchema = z
1753
1602
  .object({
@@ -1788,8 +1637,8 @@ export const TenantCauseSchema = z
1788
1637
  })
1789
1638
  .strict();
1790
1639
  /**
1791
- * The Host's one Tenant, as `/v1/admin/status` reports it. `unavailable` while it opens, when
1792
- * opening it failed (`cause`), or when it is closing.
1640
+ * The Host's one Tenant. `unavailable` while it opens, when opening it failed (`cause`), or
1641
+ * when it is closing.
1793
1642
  */
1794
1643
  export const HostTenantSchema = z
1795
1644
  .object({
@@ -1831,52 +1680,9 @@ export const HarnessStatusSchema = z
1831
1680
  workspace: z.boolean(),
1832
1681
  })
1833
1682
  .strict();
1834
- export const HostAggregateSchema = z
1835
- .object({
1836
- runningSessions: z.number().int().nonnegative(),
1837
- /** Deliveries to Action endpoints in flight on this Host. */
1838
- inFlightDeliveries: z.number().int().nonnegative(),
1839
- pendingActions: z.number().int().nonnegative(),
1840
- uncertainEffects: z.number().int().nonnegative(),
1841
- /** This process's stream relay, when it runs one (a Host with S2). */
1842
- relay: StreamRelayStatusSchema.optional(),
1843
- /** The open Tenant's harnesses. */
1844
- harness: HarnessStatusSchema.optional(),
1845
- })
1846
- .strict();
1847
- export const AdminHostStatusSchema = z
1848
- .object({
1849
- hostId: z.string().min(1),
1850
- url: z.string().min(1),
1851
- pid: z.number().int(),
1852
- version: z.string().min(1),
1853
- protocol: ProtocolRangeSchema,
1854
- tenant: HostTenantSchema,
1855
- aggregate: HostAggregateSchema,
1856
- })
1857
- .strict();
1858
- /** Shared Admin API status (D§4.1). OSS fills `host`; Cloud omits it. */
1859
- export const AdminStatusSchema = z
1860
- .object({
1861
- service: z.string().min(1),
1862
- version: z.string().min(1),
1863
- protocol: ProtocolRangeSchema,
1864
- /** The Tenant this installation serves. */
1865
- tenant: HostTenantSchema,
1866
- aggregate: HostAggregateSchema,
1867
- host: z
1868
- .object({
1869
- hostId: z.string().min(1),
1870
- url: z.string().min(1),
1871
- pid: z.number().int(),
1872
- })
1873
- .strict()
1874
- .optional(),
1875
- })
1876
- .strict();
1877
1683
  /**
1878
- * An operator key (Host feature `operator-keys`): a revocable application key of the Tenant,
1879
- * named by its id (`APPLICATION_KEY_ID_PATTERN`). The Runtime keeps only its hash.
1684
+ * A key of the Tenant (`/v1/tenant/keys`, `nylorun-operate keys`), named by its id
1685
+ * (`APPLICATION_KEY_ID_PATTERN`), with its role. The Runtime keeps only its hash.
1880
1686
  */
1881
1687
  export const OperatorKeySchema = z
1882
1688
  .object({
@@ -1886,16 +1692,16 @@ export const OperatorKeySchema = z
1886
1692
  createdAt: z.string().min(1),
1887
1693
  })
1888
1694
  .strict();
1889
- /** `GET /v1/admin/keys`: every key of the Tenant (Studio's and derived ones too), by id. */
1695
+ /** `GET /v1/tenant/keys`: the Tenant's keys, by id. */
1890
1696
  export const ListOperatorKeysResponseSchema = z
1891
1697
  .object({ keys: z.array(OperatorKeySchema) })
1892
1698
  .strict();
1893
- /** `PUT /v1/admin/keys/{id}`: the new key, shown this once; `rotated` when it replaced one. */
1699
+ /** `PUT /v1/tenant/keys/{keyId}`: the new key, shown this once; `rotated` when it replaced one. */
1894
1700
  export const PutOperatorKeyResponseSchema = OperatorKeySchema.extend({
1895
1701
  key: z.string().regex(/^[0-9a-f]{64}$/),
1896
1702
  rotated: z.boolean(),
1897
1703
  }).strict();
1898
- /** `DELETE /v1/admin/keys/{id}`: the key no longer authenticates. */
1704
+ /** `DELETE /v1/tenant/keys/{keyId}`: the key no longer authenticates. */
1899
1705
  export const DeleteOperatorKeyResponseSchema = z
1900
1706
  .object({ id: z.string().min(1), deleted: z.literal(true) })
1901
1707
  .strict();
@@ -1917,11 +1723,17 @@ export const ProjectLinkFileSchema = z
1917
1723
  tenantId: z.string().min(1).optional(),
1918
1724
  })
1919
1725
  .passthrough();
1726
+ /**
1727
+ * `.nylorun/credentials.json`: the Project's application key and, from protocol 8, its
1728
+ * management key. Still format 1: readers that predate the management key ignore it.
1729
+ */
1920
1730
  export const ProjectCredentialsFileSchema = z
1921
1731
  .object({
1922
1732
  format: z.union([z.literal(0), z.literal(1)]).default(0),
1923
1733
  applicationKey: z.string().regex(/^[0-9a-f]{64}$/),
1924
1734
  principalId: z.string().min(1),
1735
+ managementKey: z.string().regex(/^[0-9a-f]{64}$/).optional(),
1736
+ managementPrincipalId: z.string().min(1).optional(),
1925
1737
  })
1926
1738
  .passthrough();
1927
1739
  export const HostModelViewSchema = z.union([
@@ -1946,24 +1758,16 @@ export const TenantStatusSchema = z
1946
1758
  store: z.boolean(),
1947
1759
  scheduler: z.boolean(),
1948
1760
  model: z.boolean(),
1949
- endpoints: z.boolean(),
1950
1761
  schema: z.boolean(),
1951
1762
  })
1952
1763
  .strict(),
1953
1764
  model: HostModelViewSchema,
1954
- agents: z.array(z
1955
- .object({
1956
- agentId: z.string(),
1957
- registered: z.boolean(),
1958
- /** The agent has a registered Action endpoint. */
1959
- endpoint: z.boolean(),
1960
- })
1961
- .strict()),
1765
+ /** The registered agents. */
1766
+ agents: z.array(z.object({ agentId: z.string() }).strict()),
1962
1767
  counts: z
1963
1768
  .object({
1964
1769
  sessions: z.number().int().nonnegative(),
1965
1770
  runningSessions: z.number().int().nonnegative(),
1966
- pendingActions: z.number().int().nonnegative(),
1967
1771
  uncertainEffects: z.number().int().nonnegative(),
1968
1772
  })
1969
1773
  .strict(),
@@ -2063,20 +1867,20 @@ export const ResetTenantRequestSchema = z
2063
1867
  * narrow a request to. `sessions:own` reaches only the subject's own sessions; the others reach
2064
1868
  * Tenant-wide resources. `sandboxes:write` creates and deletes sandboxes (Host feature
2065
1869
  * `sandboxes`); a token caller's reach only the ids its sandbox grants name. Vaults are the
2066
- * installation's, managed by application keys acting for no one (protocol 7).
1870
+ * installation's, managed with management keys on the Management API (protocol 8).
2067
1871
  */
2068
1872
  export const SUBJECT_SCOPES = [
2069
1873
  "agents:read",
2070
1874
  "agents:write",
2071
1875
  "sessions:own",
2072
- "tenant:settings",
2073
1876
  "sandboxes:write",
2074
1877
  ];
2075
1878
  /**
2076
- * Scopes protocol 7 retired: `Nylorun-Scopes` may still name them (protocol 6 clients do), and
2077
- * they grant nothing.
1879
+ * Retired scopes: `Nylorun-Scopes` may still name them (older clients do), and they grant
1880
+ * nothing. `vaults:own` left in protocol 7; `tenant:settings` in protocol 8, when the Tenant's
1881
+ * settings moved to the Management API, which no subject reaches.
2078
1882
  */
2079
- const RETIRED_SUBJECT_SCOPES = ["vaults:own"];
1883
+ const RETIRED_SUBJECT_SCOPES = ["vaults:own", "tenant:settings"];
2080
1884
  /** 1–200 visible ASCII characters; spaces only inside. */
2081
1885
  const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
2082
1886
  /**
@@ -2120,8 +1924,7 @@ export function parseSubjectHeaders(subject, scopes) {
2120
1924
  }
2121
1925
  // --- token callers (Host feature `trusted-issuers`) ------------------------------------------
2122
1926
  /**
2123
- * Scopes a token caller (a trusted issuer's token) may carry: never `agents:write` or
2124
- * `tenant:settings`.
1927
+ * Scopes a token caller (a trusted issuer's token) may carry: never `agents:write`.
2125
1928
  */
2126
1929
  export const TOKEN_SCOPES = [
2127
1930
  "agents:read",
@@ -2131,14 +1934,13 @@ export const TOKEN_SCOPES = [
2131
1934
  /** The most sandbox grants one token caller carries. */
2132
1935
  export const TOKEN_SANDBOX_GRANTS_MAX = 16;
2133
1936
  /**
2134
- * The longest a token the Runtime signs itself lives, in seconds (delivery tokens, capability
2135
- * links): rotating signing keys revokes the previous key once the longest token it may have
2136
- * signed has expired.
1937
+ * The longest a token the Runtime signs itself lives, in seconds (capability links): rotating
1938
+ * signing keys revokes the previous key once the longest token it may have signed has expired.
2137
1939
  */
2138
1940
  export const TOKEN_TTL_MAX_SECONDS = 900;
2139
1941
  /**
2140
- * The `iss` of every token a Tenant's Runtime signs itself: delivery tokens, capability links,
2141
- * run, host and egress tokens.
1942
+ * The `iss` of every token a Tenant's Runtime signs itself: capability links, run, host and
1943
+ * egress tokens.
2142
1944
  */
2143
1945
  export function tenantTokenIssuer(tenantId) {
2144
1946
  return `urn:nylorun:tenant:${tenantId}`;
@@ -2218,7 +2020,7 @@ export const MeResponseSchema = z
2218
2020
  description: "A token caller's sandbox grants (empty reaches none); absent when no grant limits the caller",
2219
2021
  }),
2220
2022
  via: z.string().meta({
2221
- description: "How the caller authenticated: `application:<principalId>`, `subject` or `issuer:<name>`",
2023
+ description: "How the caller authenticated: `application:<principalId>`, `management:<principalId>`, `subject` or `issuer:<name>`",
2222
2024
  }),
2223
2025
  })
2224
2026
  .strict();
@@ -2237,7 +2039,7 @@ export function isSerializedOrigin(value) {
2237
2039
  // Host names only: no wildcards or other characters URL parsing lets through.
2238
2040
  /^(?:[a-z0-9-]+(?:\.[a-z0-9-]+)*|\[[0-9a-f:.]+\])$/.test(url.hostname));
2239
2041
  }
2240
- // Successful answers of the Tenant and Admin APIs that had no schema of their own. With the
2042
+ // Successful answers of the Runtime and Management APIs that had no schema of their own. With the
2241
2043
  // request schemas above they describe every body the Runtime sends (its OpenAPI document).
2242
2044
  /** `GET /v1/agents` with an application key: every definition, manifest included. */
2243
2045
  export const AgentDefinitionViewSchema = z
@@ -2319,8 +2121,6 @@ export const SessionViewSchema = z
2319
2121
  /** What the session waits on: interactions, approvals, timers. */
2320
2122
  waits: z.unknown().optional(),
2321
2123
  error: z.string().optional(),
2322
- /** Its Actions that are pending, being delivered or uncertain. */
2323
- actions: z.array(ActionSchema),
2324
2124
  uncertainEffects: z.array(z
2325
2125
  .object({
2326
2126
  effectId: z.string(),
@@ -2524,9 +2324,6 @@ export const StartOAuthResponseSchema = z
2524
2324
  .strict();
2525
2325
  /** A deleted vault or credential. */
2526
2326
  export const DeletedResponseSchema = z.object({ id: z.string() }).strict();
2527
- export const HostShutdownResponseSchema = z
2528
- .object({ status: z.literal("shutting_down") })
2529
- .strict();
2530
2327
  /**
2531
2328
  * The last frame of a session stream the Runtime ends: `event: nylorun.closed`, when the
2532
2329
  * token caller's token expires.
@@ -2543,125 +2340,6 @@ export const AgUiRunErrorCodeSchema = z.enum([
2543
2340
  "session_busy",
2544
2341
  "runtime_error",
2545
2342
  ]);
2546
- // --- Action endpoints: the Runtime delivers Actions over HTTP ------------------------------
2547
- /** The JWT `typ` of a delivery token (RFC 8725 explicit typing). */
2548
- export const DELIVERY_TOKEN_TYPE = "nylorun-delivery+jwt";
2549
- /** A delivery token lives no longer than any token the Runtime signs (`TOKEN_TTL_MAX_SECONDS`). */
2550
- export const DELIVERY_TOKEN_MAX_TTL_SECONDS = TOKEN_TTL_MAX_SECONDS;
2551
- /** Inline delivery timeouts, in milliseconds. The maximum keeps a token within its lifetime. */
2552
- export const ENDPOINT_TIMEOUT_DEFAULT_MS = 60_000;
2553
- export const ENDPOINT_TIMEOUT_MAX_MS = (DELIVERY_TOKEN_MAX_TTL_SECONDS - 60) * 1000;
2554
- /** In-flight deliveries per endpoint when the registration does not say. */
2555
- export const ENDPOINT_MAX_CONCURRENT_DEFAULT = 16;
2556
- const isEndpointUrl = (value) => {
2557
- try {
2558
- const url = new URL(value);
2559
- return ((url.protocol === "http:" || url.protocol === "https:") &&
2560
- !url.username &&
2561
- !url.password &&
2562
- !url.hash);
2563
- }
2564
- catch {
2565
- return false;
2566
- }
2567
- };
2568
- const EndpointUrlSchema = z
2569
- .string()
2570
- .max(2048)
2571
- .refine(isEndpointUrl, {
2572
- message: "An endpoint URL is an http or https URL without credentials or a fragment",
2573
- });
2574
- /** One agent's or workflow's Action endpoint, as the application registers it. */
2575
- export const EndpointRegistrationSchema = z
2576
- .object({
2577
- agentId: z.string().min(1),
2578
- url: EndpointUrlSchema,
2579
- implementationVersion: z.string().min(1),
2580
- manifestHash: z.string().min(1).optional(),
2581
- timeoutMs: z.number().int().min(1000).max(ENDPOINT_TIMEOUT_MAX_MS).optional(),
2582
- maxConcurrent: z.number().int().min(1).max(256).optional(),
2583
- })
2584
- .strict();
2585
- export const PutEndpointsRequestSchema = z
2586
- .object({
2587
- endpoints: z
2588
- .array(EndpointRegistrationSchema)
2589
- .min(1)
2590
- .max(64)
2591
- .refine((endpoints) => new Set(endpoints.map((e) => e.agentId)).size === endpoints.length, { message: "Endpoint registrations must be unique per agent" }),
2592
- })
2593
- .strict();
2594
- /** What recent deliveries and the last ping say about an endpoint. */
2595
- export const EndpointHealthSchema = z
2596
- .object({
2597
- lastDeliveryAt: z.string().optional(),
2598
- lastSuccessAt: z.string().optional(),
2599
- lastError: z.object({ code: z.string(), message: z.string() }).optional(),
2600
- consecutiveFailures: z.number().int().nonnegative(),
2601
- /** What the handler reported serving on the last ping. */
2602
- served: z
2603
- .object({
2604
- implementationVersion: z.string(),
2605
- manifestHash: z.string().optional(),
2606
- })
2607
- .strict()
2608
- .optional(),
2609
- })
2610
- .strict();
2611
- export const EndpointSchema = z
2612
- .object({
2613
- agentId: z.string(),
2614
- url: z.string(),
2615
- implementationVersion: z.string(),
2616
- manifestHash: z.string().optional(),
2617
- timeoutMs: z.number().int(),
2618
- maxConcurrent: z.number().int(),
2619
- health: EndpointHealthSchema,
2620
- updatedAt: z.string(),
2621
- })
2622
- .strict();
2623
- export const ListEndpointsResponseSchema = z
2624
- .object({
2625
- endpoints: z.array(EndpointSchema),
2626
- })
2627
- .strict();
2628
- export const DeleteEndpointResponseSchema = z
2629
- .object({ agentId: z.string(), deleted: z.literal(true) })
2630
- .strict();
2631
- /** The body the Runtime POSTs to an Action endpoint. */
2632
- export const ActionDeliverySchema = z.discriminatedUnion("type", [
2633
- z
2634
- .object({
2635
- type: z.literal("action"),
2636
- action: ActionSchema,
2637
- /** The Action's session has a sandbox, so `ctx.sandbox` is available. */
2638
- sandbox: z.boolean(),
2639
- })
2640
- .strict(),
2641
- z
2642
- .object({
2643
- type: z.literal("ping"),
2644
- agentId: z.string().min(1),
2645
- manifestHash: z.string().min(1).optional(),
2646
- })
2647
- .strict(),
2648
- ]);
2649
- /** An Action endpoint's answer to a ping. */
2650
- export const EndpointPingResponseSchema = z.object({
2651
- agentId: z.string(),
2652
- implementationVersion: z.string(),
2653
- manifestHash: z.string().optional(),
2654
- });
2655
- /** The answer to a background delivery's heartbeat: a fresh token and the new deadline. */
2656
- export const DeliveryHeartbeatResponseSchema = z.object({
2657
- token: z.string().min(1),
2658
- deadlineAt: z.string(),
2659
- });
2660
- /**
2661
- * The receipt of a background result (`POST /v1/actions/:id/result`): a session command's
2662
- * receipt without `requestId`, since the result carries none. The same result again returns it.
2663
- */
2664
- export const ActionResultReceiptSchema = AcceptedResponseSchema.omit({ requestId: true });
2665
2343
  // --- Studio embedding (Studio design §8) ---------------------------------------------------
2666
2344
  /** A Tenant id as Studio's routes accept it. */
2667
2345
  const STUDIO_TENANT_ID = /^[A-Za-z0-9_-]{1,128}$/;
@@ -2843,6 +2521,16 @@ export const ListArtifactsResponseSchema = z
2843
2521
  export const UploadArtifactResponseSchema = z
2844
2522
  .object({ artifact: ArtifactViewSchema, version: ArtifactVersionViewSchema })
2845
2523
  .strict();
2524
+ /**
2525
+ * `PUT /v1/files/sha256:{hex}`: a definition file the Runtime holds (track R2 M4), named by the
2526
+ * SHA-256 of its bytes. `201` stored it, `200` already had it.
2527
+ */
2528
+ export const DefinitionFileViewSchema = z
2529
+ .object({
2530
+ sha256: z.string().regex(/^sha256:[0-9a-f]{64}$/),
2531
+ size: z.number().int().nonnegative().max(DEFINITION_FILE_MAX_BYTES),
2532
+ })
2533
+ .strict();
2846
2534
  export const DeleteArtifactResponseSchema = z
2847
2535
  .object({ artifactId: z.string(), deleted: z.boolean() })
2848
2536
  .strict();
@@ -2955,3 +2643,80 @@ export const TenantArtifactsViewSchema = z
2955
2643
  usedBytes: z.number().int().nonnegative(),
2956
2644
  })
2957
2645
  .strict();
2646
+ /** Opt-in session reads (Host feature `session-reads`). */
2647
+ export const SessionListItemSchema = SessionSummarySchema.extend({
2648
+ lastTurnId: z.string().nullable(),
2649
+ sandboxId: z.string().nullable(),
2650
+ createdAt: z.string().nullable(),
2651
+ lastEventAt: z.string().nullable(),
2652
+ }).strict();
2653
+ export const SessionPageSchema = z
2654
+ .object({ sessions: z.array(SessionListItemSchema), nextCursor: z.string().nullable() })
2655
+ .strict();
2656
+ export const SessionManifestViewSchema = z
2657
+ .object({
2658
+ sessionId: z.string(),
2659
+ agentId: z.string(),
2660
+ manifestHash: z.string(),
2661
+ implementationVersion: z.string(),
2662
+ manifest: z.record(z.string(), z.unknown()),
2663
+ })
2664
+ .strict();
2665
+ export const HistoryPageSchema = SessionItemsResponseSchema.extend({ tail: z.boolean() });
2666
+ const usageNumbers = {
2667
+ inputTokens: z.number().int().nonnegative(),
2668
+ outputTokens: z.number().int().nonnegative(),
2669
+ totalTokens: z.number().int().nonnegative(),
2670
+ cachedTokens: z.number().int().nonnegative(),
2671
+ cacheWriteTokens: z.number().int().nonnegative(),
2672
+ reasoningTokens: z.number().int().nonnegative(),
2673
+ costUsd: z.number().nonnegative(),
2674
+ };
2675
+ export const SessionUsageTotalsSchema = z
2676
+ .object({
2677
+ sessionId: z.string(),
2678
+ turnId: z.string().nullable(),
2679
+ asOf: z.string(),
2680
+ ...usageNumbers,
2681
+ calls: z.number().int().nonnegative(),
2682
+ duplicates: z.number().int().nonnegative(),
2683
+ unpricedCalls: z.number().int().nonnegative(),
2684
+ unreportedCalls: z.number().int().nonnegative(),
2685
+ unknownQualityCalls: z.number().int().nonnegative(),
2686
+ })
2687
+ .strict();
2688
+ export const ModelCallSchema = z
2689
+ .object({
2690
+ id: z.string(),
2691
+ sessionId: z.string(),
2692
+ turnId: z.string(),
2693
+ agentId: z.string(),
2694
+ provider: z.string().nullable(),
2695
+ model: z.string().nullable(),
2696
+ at: z.string(),
2697
+ outcome: z.enum(["completed", "failed"]),
2698
+ usage: z
2699
+ .object({
2700
+ ...usageNumbers,
2701
+ duplicate: z.boolean(),
2702
+ tokensReported: z.boolean().nullable(),
2703
+ costKnown: z.boolean().nullable(),
2704
+ })
2705
+ .strict()
2706
+ .nullable(),
2707
+ })
2708
+ .strict();
2709
+ export const ModelCallsPageSchema = z
2710
+ .object({ calls: z.array(ModelCallSchema), nextCursor: z.string().nullable(), asOf: z.string() })
2711
+ .strict();
2712
+ export const ModelCallExportPageSchema = z
2713
+ .object({
2714
+ calls: z.array(ModelCallSchema),
2715
+ next: z.string().nullable(),
2716
+ caughtUp: z.boolean(),
2717
+ asOf: z.string(),
2718
+ })
2719
+ .strict();
2720
+ export const SandboxPageSchema = z
2721
+ .object({ sandboxes: z.array(SandboxViewSchema), nextCursor: z.string().nullable() })
2722
+ .strict();