@nylorun/core 0.24.0-beta → 0.26.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 (57) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/compatibility.d.ts +51 -37
  3. package/dist/compatibility.js +51 -36
  4. package/dist/contracts.d.ts +262 -93
  5. package/dist/contracts.js +262 -141
  6. package/dist/definition/approval.d.ts +1 -1
  7. package/dist/definition/bound.d.ts +2 -0
  8. package/dist/definition/builder.d.ts +2 -2
  9. package/dist/definition/builder.js +1 -1
  10. package/dist/definition/code-tools.d.ts +1 -1
  11. package/dist/definition/declaration.js +3 -0
  12. package/dist/definition/delegate.d.ts +1 -1
  13. package/dist/definition/delegate.js +1 -1
  14. package/dist/definition/from.d.ts +2 -2
  15. package/dist/definition/from.js +1 -1
  16. package/dist/definition/http-tool.d.ts +3 -3
  17. package/dist/definition/mcp.d.ts +4 -4
  18. package/dist/definition/mcp.js +3 -3
  19. package/dist/definition/sections.d.ts +5 -4
  20. package/dist/definition/sections.js +30 -7
  21. package/dist/definition/variant.d.ts +1 -1
  22. package/dist/definition/variant.js +4 -4
  23. package/dist/harness-api/entries.d.ts +1 -1
  24. package/dist/harness-api/entries.js +1 -1
  25. package/dist/harness-api/gates.d.ts +1 -1
  26. package/dist/harness-api/gates.js +1 -1
  27. package/dist/harness-api/json-schema.d.ts +1 -1
  28. package/dist/harness-api/json-schema.js +1 -1
  29. package/dist/harness-api/mcp.js +1 -1
  30. package/dist/harness-api/messages.d.ts +6 -6
  31. package/dist/harness-api/schema.d.ts +7 -7
  32. package/dist/harness-api/schema.js +16 -16
  33. package/dist/harness-api/transcript.d.ts +1 -1
  34. package/dist/harness-api/transport.d.ts +1 -1
  35. package/dist/harness-api/transport.js +1 -1
  36. package/dist/manifest-schemas.js +2 -1
  37. package/dist/schemas/agent-manifest.schema.json +3 -3
  38. package/dist/schemas/harness-manifest.schema.json +1 -1
  39. package/dist/schemas/runtime-manifest.schema.json +2 -2
  40. package/dist/types/manifest.d.ts +21 -17
  41. package/dist/types/model.d.ts +1 -1
  42. package/dist/types/observe.d.ts +1 -1
  43. package/dist/types/part.d.ts +5 -0
  44. package/dist/types/tool.d.ts +4 -4
  45. package/dist/utils/definition-files.d.ts +3 -2
  46. package/dist/utils/definition-files.js +4 -3
  47. package/dist/utils/file-systems.d.ts +1 -1
  48. package/dist/utils/file-systems.js +1 -1
  49. package/dist/utils/harness-id.d.ts +1 -1
  50. package/dist/utils/harness-id.js +1 -1
  51. package/dist/utils/memory.d.ts +2 -2
  52. package/dist/utils/memory.js +2 -2
  53. package/dist/utils/runtime-limits.d.ts +5 -5
  54. package/dist/utils/runtime-limits.js +5 -5
  55. package/dist/utils/runtime-tools.d.ts +3 -3
  56. package/dist/utils/runtime-tools.js +3 -3
  57. package/package.json +1 -1
package/dist/contracts.js CHANGED
@@ -41,7 +41,7 @@ const jsonValue = z
41
41
  ]))
42
42
  .meta({ id: "JsonValue" });
43
43
  /**
44
- * A name the model sees in a tool name (R2b C6): a declared tool's, or an MCP server's, which
44
+ * A name the model sees in a tool name: a declared tool's, or an MCP server's, which
45
45
  * prefixes its tools' names. Letters, digits, `_` and `-`, up to 64: what every provider accepts.
46
46
  */
47
47
  const modelFacingName = (what) => z.string().regex(DELEGATE_NAME_PATTERN, {
@@ -52,7 +52,7 @@ const pluginLabelSchema = z
52
52
  .object({ name: z.string().min(1), version: z.string().min(1).optional() })
53
53
  .strict()
54
54
  .meta({ id: "PluginLabel" });
55
- /** One tool's settings on an MCP server (R2b C9). */
55
+ /** One tool's settings on an MCP server. */
56
56
  const mcpToolSettingsSchema = z
57
57
  .object({
58
58
  enabled: z.boolean().optional(),
@@ -61,7 +61,7 @@ const mcpToolSettingsSchema = z
61
61
  })
62
62
  .strict()
63
63
  .meta({ id: "McpToolSettings" });
64
- /** Per-tool settings keyed by the server's tool names, `"*"` for the rest (R2b C9, C10). */
64
+ /** Per-tool settings keyed by the server's tool names, `"*"` for the rest. */
65
65
  const mcpServerSettings = {
66
66
  deferred: z.boolean().optional(),
67
67
  tools: z.record(z.string().min(1), mcpToolSettingsSchema).optional(),
@@ -208,13 +208,13 @@ const removedFieldError = (removedFields) => (issue) => {
208
208
  return removed === undefined ? undefined : removedFields[removed];
209
209
  };
210
210
  /**
211
- * An environment variable name a shell secret or plain variable may take (R2c, D50): a POSIX
211
+ * An environment variable name a shell secret or plain variable may take: a POSIX
212
212
  * name, of any length (POSIX and Linux set none; a request's body bounds it). Names the sandbox
213
213
  * needs for itself (the proxy, the trust store, `PATH`, `HOME`) and `NYLORUN_*` are reserved.
214
214
  */
215
215
  export const ENVIRONMENT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
216
216
  /**
217
- * What an agent needs of the Environment its session opens on (protocol 14, D65), checked when a
217
+ * What an agent needs of the Environment its session opens on (protocol 14), checked when a
218
218
  * session opens (`409 environment_unsuitable`). `sandbox`: `any` needs kind `virtual` or `pod`,
219
219
  * `pod` needs kind `pod`, `none` needs nothing. `secrets`: names its skills' scripts read, which
220
220
  * the Environment's vault must hold. The agent names no Environment: the app still maps.
@@ -495,7 +495,7 @@ const resourcesSchema = z
495
495
  */
496
496
  const AGENT_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/;
497
497
  /**
498
- * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
498
+ * An identifier's grammar is the protocol's: it crosses the Runtime API, tokens and grants
499
499
  * and means the same in every installation, so its length is a constant of the protocol, not a
500
500
  * setting.
501
501
  */
@@ -553,7 +553,7 @@ export const EnvironmentLabelsSchema = z.record(z.string().regex(LABEL_KEY_PATTE
553
553
  }), z.string().regex(LABEL_VALUE_PATTERN, {
554
554
  message: "Label values are printable ASCII characters",
555
555
  }));
556
- /** A harness id (track R4): what a harness names itself in `hello`. */
556
+ /** A harness id: what a harness names itself in `hello`. */
557
557
  export const HarnessIdSchema = z.string().regex(HARNESS_ID_PATTERN, {
558
558
  message: "harness must be a harness id: lowercase letters, digits and dashes, starting with a letter",
559
559
  });
@@ -608,7 +608,7 @@ const relativeFilePath = z
608
608
  .refine((value) => !value.startsWith("/") && !value.includes("\0") && value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== ".."), { message: "a file's path is relative, without empty, . or .. segments" });
609
609
  /**
610
610
  * One input file entry (pods only): an artifact version copied to `path` (a file artifact, or a
611
- * folder's files under it), or (Q6) files by content hash, each `sha256:<hex>` of a definition
611
+ * folder's files under it), or files by content hash, each `sha256:<hex>` of a definition
612
612
  * file the Tenant holds (`PUT /v1/files/sha256:<hex>`, at most 2 GiB each), copied under `path`
613
613
  * at its relative path. A manifest by hash moves to another Tenant with its files.
614
614
  */
@@ -647,7 +647,7 @@ export const AgentManifestNameSchema = z
647
647
  .meta({ description: "An agent manifest's name, such as `triage`" });
648
648
  /**
649
649
  * Which agent manifest an Agent is made from: `name` (tracking: the latest version when the Agent
650
- * is created; track T3 moves it on) or `name@n` (pinned to version `n`).
650
+ * is created, and each version saved later) or `name@n` (pinned to version `n`).
651
651
  */
652
652
  export function parseAgentManifestRef(ref) {
653
653
  const at = ref.lastIndexOf("@");
@@ -737,8 +737,8 @@ const runtimeFields = {
737
737
  * the live instance of one version of an agent manifest: `manifest: "name"` records that it
738
738
  * tracks the manifest (its latest version, and every version saved later) and `"name@n"` that it
739
739
  * is pinned to one; the version it runs is `resolvedVersion`. On an existing Agent, `labels`
740
- * replace its labels, `owner` sets or clears its owner guard, and `manifest` moves it (track T3,
741
- * D73): to another version of its manifest, tracking or pinned. A move changes no data: its id,
740
+ * replace its labels, `owner` sets or clears its owner guard, and `manifest` moves it:
741
+ * to another version of its manifest, tracking or pinned. A move changes no data: its id,
742
742
  * disk, vault and sessions stay. A harness-only change applies at once; a runtime change of a pod
743
743
  * waits for its next start; one that adds a required secret waits for its value. Its manifest's
744
744
  * name, kind, harness and storage are fixed (`409 agent_fixed_field`); fork it to change them.
@@ -769,9 +769,10 @@ export const PutAgentRequestSchema = z
769
769
  })
770
770
  .strict();
771
771
  /**
772
- * What an Agent's environment runs: its manifest version's runtime section resolved against the
773
- * Tenant's limits when the Agent was made, with the harness that runs its loop. It never changes
774
- * after that.
772
+ * What an Agent's environment runs: the runtime section of the manifest version it runs, resolved
773
+ * against the Tenant's limits when the Agent was made or moved to that version, with the harness
774
+ * that runs its loop. A move to another version changes it; its kind, harness and storage never
775
+ * change.
775
776
  */
776
777
  export const EnvironmentRecipeSchema = z
777
778
  .object({
@@ -788,7 +789,7 @@ export const EnvironmentRecipeSchema = z
788
789
  secrets: z.lazy(() => EnvironmentSecretSlotsSchema).optional(),
789
790
  })
790
791
  .strict();
791
- /** A session on an Agent, as the Agent's view lists it: none is special (D71). */
792
+ /** A session on an Agent, as the Agent's view lists it: none is special. */
792
793
  export const AgentSessionSchema = z
793
794
  .object({
794
795
  id: z.string(),
@@ -818,8 +819,8 @@ export const AgentPodViewSchema = z
818
819
  /** Why it failed, or was lost. */
819
820
  reason: z.string().optional(),
820
821
  /**
821
- * The workload image by digest (`repo@sha256:…`), pinned the first time a pod was ready
822
- * (Q14): every later pod runs it. Absent before then, or for an image with no repository.
822
+ * The workload image by digest (`repo@sha256:…`), pinned the first time a pod was ready:
823
+ * every later pod runs it. Absent before then, or for an image with no repository.
823
824
  */
824
825
  imageDigest: z.string().optional(),
825
826
  })
@@ -833,7 +834,7 @@ export const COMPUTE_STATES = ["ready", "creating", "running", "stopped"];
833
834
  /**
834
835
  * An Agent's state (protocol 16), derived when it is read, the first that holds:
835
836
  *
836
- * - `paused`: its desired state is `off` (nothing in protocol 16 sets it; track T6 adds the control).
837
+ * - `paused`: its desired state is `off` (nothing in protocol 16 sets it).
837
838
  * - `failing`: its compute failed or was lost, or a session's latest finished turn failed.
838
839
  * - `input_required`: a session waits on a person (an approval or interaction, or an uncertain
839
840
  * effect), even while another works.
@@ -866,7 +867,7 @@ export const AgentViewSchema = z
866
867
  /** Whether `manifest` tracks the manifest's latest version or pins one. */
867
868
  tracking: z.enum(["tracking", "pinned"]),
868
869
  /**
869
- * Track T3: the version it moves to while it is outdated, else `null`. It waits for a value of
870
+ * The version it moves to while it is outdated, else `null`. It waits for a value of
870
871
  * each required secret the version adds (`waitingFor: "secrets"`) or for its pod's next start
871
872
  * (`"start"`); turns run `resolvedVersion` meanwhile.
872
873
  */
@@ -896,9 +897,9 @@ export const AgentViewSchema = z
896
897
  state: z.string().meta({ description: "working, sleeping, input_required, failing or paused; an open set" }),
897
898
  /** Every state that holds, with the session behind each: what made `state` first. */
898
899
  attention: z.array(AgentAttentionSchema),
899
- /** `on`, or `off` once paused (track T6). */
900
+ /** `on`, or `off` once paused. */
900
901
  desired: z.enum(["on", "off"]),
901
- /** When its next trigger fires: the earliest next run of its active triggers (D74), or `null`. */
902
+ /** When its next trigger fires: the earliest next run of its active triggers, or `null`. */
902
903
  nextWakeAt: z.string().nullable(),
903
904
  compute: z
904
905
  .object({
@@ -1015,20 +1016,20 @@ export const AgentDiskVersionsSchema = z
1015
1016
  export const DeleteAgentResponseSchema = z
1016
1017
  .object({ id: z.string(), deleted: z.boolean() })
1017
1018
  .strict();
1018
- /** A turn that was running on an Agent when one of its connections opened (D67). */
1019
+ /** A turn that was running on an Agent when one of its connections opened. */
1019
1020
  export const EgressRunningTurnSchema = z
1020
1021
  .object({ sessionId: z.string(), turnId: z.string() })
1021
1022
  .strict();
1022
1023
  /**
1023
- * One connection a pod Agent opened through egress-gate (track R7, Q6): written when it closes,
1024
- * or at once when the gate refused it, to the Agent's own stream as `agent.egress` (D67). The
1024
+ * One connection a pod Agent opened through egress-gate: written when it closes,
1025
+ * or at once when the gate refused it, to the Agent's own stream as `agent.egress`. The
1025
1026
  * connection is the Agent's: its egress token names the pod, and the Agent's sessions run turns
1026
- * in parallel (D66). `runningTurns` lists the turns active on it as the connection opened, at
1027
+ * in parallel. `runningTurns` lists the turns active on it as the connection opened, at
1027
1028
  * most 16, as context and never as the owner.
1028
1029
  *
1029
1030
  * `startedAt` is the gate's clock at CONNECT and `durationMs` runs from there to the close, so
1030
1031
  * the span is the gate's own measurement. `bytesUp` is what the sandbox sent, `bytesDown` what it
1031
- * got. `mode: "credential"` is a host an `environment_secret` is bound to (R2c): the gate read
1032
+ * got. `mode: "credential"` is a host an `environment_secret` is bound to: the gate read
1032
1033
  * each request (`requests`) and set a credential on it (`credentialIds`, ids only). It never
1033
1034
  * carries a header value, a URL path or a body.
1034
1035
  */
@@ -1056,7 +1057,7 @@ export const EgressConnectionPayloadSchema = z
1056
1057
  /** The schema id of an Agent's lifecycle events (its stream in the record). */
1057
1058
  export const AGENT_EVENT_SCHEMA = "nylorun.agent-event/1";
1058
1059
  /**
1059
- * `memory.updated` (track T5, D72): the session's agent changed the Agent's memory with its
1060
+ * `memory.updated`: the session's agent changed the Agent's memory with its
1060
1061
  * `memory` tool: each memory the call changed, what changed it and its version after. The Agent's
1061
1062
  * stream carries the same as `agent.memory_updated`, with the session.
1062
1063
  */
@@ -1106,7 +1107,7 @@ export const AGENT_EVENT_PAYLOADS = {
1106
1107
  manifest: z
1107
1108
  .object({ name: z.string(), version: z.number().int().positive(), tracking: z.enum(["tracking", "pinned"]) })
1108
1109
  .strict(),
1109
- /** The Agent it was forked from, and the disk version it started from (Q15). */
1110
+ /** The Agent it was forked from, and the disk version it started from. */
1110
1111
  forkedFrom: z
1111
1112
  .object({ agent: z.string(), disk: z.number().int().positive().nullable() })
1112
1113
  .strict()
@@ -1143,7 +1144,7 @@ export const AGENT_EVENT_PAYLOADS = {
1143
1144
  })
1144
1145
  .passthrough(),
1145
1146
  /**
1146
- * Asked to move to version `to` of its manifest, which waits (track T3): for a value of each
1147
+ * Asked to move to version `to` of its manifest, which waits: for a value of each
1147
1148
  * required secret it adds (`secrets`), or for its pod's next start (`start`).
1148
1149
  */
1149
1150
  "agent.outdated": z
@@ -1153,13 +1154,13 @@ export const AGENT_EVENT_PAYLOADS = {
1153
1154
  waitingFor: z.enum(["secrets", "start"]),
1154
1155
  })
1155
1156
  .passthrough(),
1156
- /** Runs version `to` of its manifest now: turns that start from here run it (track T3). */
1157
+ /** Runs version `to` of its manifest now: turns that start from here run it. */
1157
1158
  "agent.version_changed": z
1158
1159
  .object({ from: z.number().int().positive(), to: z.number().int().positive() })
1159
1160
  .passthrough(),
1160
1161
  /**
1161
1162
  * Its pod did not start on version `to` (its setup failed, the pod failed, or it took longer
1162
- * than the Host allows): it went back to version `from`, with its disk as it was (track T3).
1163
+ * than the Host allows): it went back to version `from`, with its disk as it was.
1163
1164
  */
1164
1165
  "agent.start_failed": z
1165
1166
  .object({
@@ -1169,7 +1170,7 @@ export const AGENT_EVENT_PAYLOADS = {
1169
1170
  reverted: z.boolean(),
1170
1171
  })
1171
1172
  .passthrough(),
1172
- /** A connection through egress-gate, with the turns running as it opened (D67). */
1173
+ /** A connection through egress-gate, with the turns running as it opened. */
1173
1174
  "agent.egress": EgressConnectionPayloadSchema,
1174
1175
  /** A trigger fired, or was run by hand: the run and what came of it (`TriggerRunSchema`). */
1175
1176
  "agent.run": z
@@ -1209,7 +1210,7 @@ export const ListAgentEventsResponseSchema = z
1209
1210
  /**
1210
1211
  * `PUT /v1/sessions/{id}` (protocol 16): the session's Agent, owner and info. The session runs on
1211
1212
  * the Agent for its life (its sandbox, its vault's credentials) and pins the manifest version the
1212
- * Agent runs when it opens. No session is special (D71): an app that keeps one conversation
1213
+ * Agent runs when it opens. No session is special: an app that keeps one conversation
1213
1214
  * going reuses its id.
1214
1215
  */
1215
1216
  export const PutSessionRequestSchema = z
@@ -1221,7 +1222,7 @@ export const PutSessionRequestSchema = z
1221
1222
  info: jsonObject.optional(),
1222
1223
  })
1223
1224
  .strict();
1224
- /** The hosts a harness can run on (blueprint D38). */
1225
+ /** The hosts a harness can run on. */
1225
1226
  export const PLACEMENT_HOSTS = ["harness-container", "sandbox"];
1226
1227
  /**
1227
1228
  * A Tenant's Environment settings (Tenant setting `environments.config`): the limits every
@@ -1253,7 +1254,7 @@ export const TenantEnvironmentsConfigSchema = z
1253
1254
  .strict()
1254
1255
  .optional(),
1255
1256
  /**
1256
- * Where each harness may run (blueprint D38), by harness id (`nylorun`, or `*` for the rest):
1257
+ * Where each harness may run, by harness id (`nylorun`, or `*` for the rest):
1257
1258
  * `harness-container` (the Runtime's harness) and `sandbox` (the engine in a pod).
1258
1259
  * Default `{ "*": { hosts: ["harness-container", "sandbox"] } }`. Checked when a session
1259
1260
  * opens; a host left out is refused (`placement_refused`). `"*": { hosts: [] }` refuses every
@@ -1282,7 +1283,7 @@ const CredentialHeaderValueSchema = z
1282
1283
  .string()
1283
1284
  .min(1)
1284
1285
  .refine((value) => !/[\r\n\0]/.test(value), "A header value has no CR, LF or NUL");
1285
- /** A `headers` credential's map (Q6): one or more headers sent on every request. */
1286
+ /** A `headers` credential's map: one or more headers sent on every request. */
1286
1287
  const CredentialHeadersSchema = z
1287
1288
  .record(CredentialHeaderNameSchema, CredentialHeaderValueSchema)
1288
1289
  .refine((value) => Object.keys(value).length > 0, "At least one header is required")
@@ -1290,7 +1291,7 @@ const CredentialHeadersSchema = z
1290
1291
  /** A loopback host as a URL's `hostname` names it: plain `http` reaches only these. */
1291
1292
  export const LOOPBACK_HOSTS = /^(?:localhost|127(?:\.\d{1,3}){3}|\[::1\])$/i;
1292
1293
  /**
1293
- * `via` (R2b C2, Q11): where this installation reaches the credential's server, such as a
1294
+ * `via`: where this installation reaches the credential's server, such as a
1294
1295
  * gateway's endpoint for it. An absolute `https` URL (`http` only to a loopback host), with no
1295
1296
  * userinfo, query string or fragment. Credentials are still matched by the URL the manifest
1296
1297
  * names; `via` changes only where the request goes.
@@ -1314,16 +1315,34 @@ export const CredentialViaSchema = z.string().superRefine((value, ctx) => {
1314
1315
  ctx.addIssue({ code: "custom", message: "via may not carry a fragment" });
1315
1316
  });
1316
1317
  /**
1317
- * The identity header (R2b C2, Q1–Q3): each request carries the session owner's subject in
1318
+ * The identity header: each request carries the session owner's subject in
1318
1319
  * `header`, for a gateway that keeps each person's accounts. A session with no person as its
1319
1320
  * owner (the reserved `installation`) sends none.
1320
1321
  */
1321
1322
  export const CredentialIdentitySchema = z.object({ header: CredentialHeaderNameSchema }).strict();
1323
+ /**
1324
+ * `toolPrefix`: what the gateway at `via` puts before each tool name it lists, such as
1325
+ * LiteLLM's `github-` (Host feature `gateway-credentials`). The Runtime lists the server's tools
1326
+ * without it, so tool names, a manifest's `tools` settings and tool policy rules name the server's
1327
+ * own tools, and calls a tool by the name the gateway listed. Only with `via`, and only on an
1328
+ * Agent's secret: how a gateway names tools is the installation's routing, never a manifest's.
1329
+ */
1330
+ export const CredentialToolPrefixSchema = z
1331
+ .string()
1332
+ .min(1)
1333
+ .max(64)
1334
+ .regex(/^[\x21-\x7e]+$/, "A tool prefix is printable ASCII with no spaces");
1322
1335
  /** Where a credential's requests go, and whom they name. Neither is secret. */
1323
1336
  const credentialRouting = {
1324
1337
  via: CredentialViaSchema.optional(),
1325
1338
  identity: CredentialIdentitySchema.optional(),
1326
1339
  };
1340
+ /** A `toolPrefix` names how a gateway lists tools, so it needs the gateway's `via`. */
1341
+ const prefixNeedsVia = (routing) => routing.toolPrefix === undefined || routing.via !== undefined;
1342
+ const PREFIX_NEEDS_VIA = {
1343
+ message: "toolPrefix needs via: it is how the gateway there names tools",
1344
+ path: ["toolPrefix"],
1345
+ };
1327
1346
  /** On rotate: absent keeps the current value, `null` removes it. */
1328
1347
  const credentialRoutingChange = {
1329
1348
  via: CredentialViaSchema.nullable().optional(),
@@ -1356,13 +1375,13 @@ const EnvironmentNameSchema = z
1356
1375
  .regex(ENVIRONMENT_NAME_PATTERN, "An environment variable name is a letter or _ followed by letters, digits or _")
1357
1376
  .refine((name) => !isReservedEnvironmentName(name), "That environment variable name is reserved");
1358
1377
  /**
1359
- * The value a sandbox sees for every `environment_secret` (R2c, D50): never the secret. Word
1378
+ * The value a sandbox sees for every `environment_secret`: never the secret. Word
1360
1379
  * characters only, so CLIs that check a token's format before sending it (the Vercel CLI
1361
1380
  * refuses anything matching `\W`) still send the request egress-gate sets the header on.
1362
1381
  */
1363
1382
  export const ENVIRONMENT_SECRET_SENTINEL = "nylorun_managed";
1364
1383
  /**
1365
- * How egress-gate writes an `environment_secret` into a request (R2c, D50): one header, set on
1384
+ * How egress-gate writes an `environment_secret` into a request: one header, set on
1366
1385
  * every request to a bound host. `format` is text with `{value}` once, optionally inside a
1367
1386
  * `{base64:…}` group, for example `Bearer {value}` (the default),
1368
1387
  * `Basic {base64:x-access-token:{value}}` or `{value}`.
@@ -1409,13 +1428,13 @@ const EnvironmentValueSchema = z
1409
1428
  .refine((value) => !/[\r\n\0]/.test(value), "A value has no CR, LF or NUL");
1410
1429
  /**
1411
1430
  * The name of a credential for a tool (`bearer` or `headers`): a label of 1–64 characters.
1412
- * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
1431
+ * An identifier's grammar is the protocol's: it crosses the Runtime API, tokens and grants
1413
1432
  * and means the same in every installation, so its length is a constant of protocol 15, not a
1414
1433
  * setting.
1415
1434
  */
1416
1435
  export const TOOL_SECRET_NAME_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
1417
1436
  /**
1418
- * `PUT /v1/agents/{agentId}/secrets/{name}` (D56): creates or replaces one credential
1437
+ * `PUT /v1/agents/{agentId}/secrets/{name}`: creates or replaces one credential
1419
1438
  * in the Environment's vault. For `environment_secret` and `environment_variable` the name is
1420
1439
  * the variable's name (a POSIX name, not reserved); for `bearer` and `headers` it is a label.
1421
1440
  * The same name and type keeps the credential and re-seals its value and binding; another type
@@ -1447,8 +1466,10 @@ export const PutAgentSecretRequestSchema = z.discriminatedUnion("type", [
1447
1466
  url: z.string().min(1),
1448
1467
  value: z.string().min(1),
1449
1468
  ...credentialRouting,
1469
+ toolPrefix: CredentialToolPrefixSchema.optional(),
1450
1470
  })
1451
- .strict(),
1471
+ .strict()
1472
+ .refine(prefixNeedsVia, PREFIX_NEEDS_VIA),
1452
1473
  z
1453
1474
  .object({
1454
1475
  requestId: RequestIdSchema.optional(),
@@ -1456,18 +1477,38 @@ export const PutAgentSecretRequestSchema = z.discriminatedUnion("type", [
1456
1477
  url: z.string().min(1),
1457
1478
  headers: CredentialHeadersSchema,
1458
1479
  ...credentialRouting,
1480
+ toolPrefix: CredentialToolPrefixSchema.optional(),
1481
+ })
1482
+ .strict()
1483
+ .refine(prefixNeedsVia, PREFIX_NEEDS_VIA),
1484
+ /**
1485
+ * The Runtime's workload token as the bearer (#496): no value is stored. Each request reads
1486
+ * `NYLORUN_WORKLOAD_TOKEN_FILE` and sends `Authorization: Bearer <token>` to `via` only, a
1487
+ * gateway whose origin the operator lists in `NYLORUN_WORKLOAD_TOKEN_ORIGINS`.
1488
+ */
1489
+ z
1490
+ .object({
1491
+ requestId: RequestIdSchema.optional(),
1492
+ type: z.literal("workload"),
1493
+ url: z.string().min(1),
1494
+ via: CredentialViaSchema,
1495
+ identity: CredentialIdentitySchema.optional(),
1496
+ toolPrefix: CredentialToolPrefixSchema.optional(),
1459
1497
  })
1460
1498
  .strict(),
1461
1499
  ]);
1462
1500
  /**
1463
- * A secret write on an Environment whose manifest declares the secret's slot (D64): only the
1464
- * value, `value` (or `headers` for a `headers` slot). Its type and binding come from the slot.
1501
+ * A secret write on an Environment whose manifest declares the secret's slot: only the
1502
+ * value, `value` (or `headers` for a `headers` slot). Its type and binding come from the slot,
1503
+ * except the gateway's `toolPrefix`, which this installation's write may add to a slot with `via`.
1465
1504
  */
1466
1505
  export const PutAgentSecretValueRequestSchema = z
1467
1506
  .object({
1468
1507
  requestId: RequestIdSchema.optional(),
1469
1508
  value: z.string().min(1).optional(),
1470
1509
  headers: CredentialHeadersSchema.optional(),
1510
+ /** A `bearer` or `headers` slot with `via`: how the gateway there prefixes tool names. */
1511
+ toolPrefix: CredentialToolPrefixSchema.optional(),
1471
1512
  })
1472
1513
  .strict()
1473
1514
  .refine((body) => (body.value === undefined) !== (body.headers === undefined), {
@@ -1494,7 +1535,7 @@ const slotBase = {
1494
1535
  description: z.string().optional(),
1495
1536
  };
1496
1537
  /**
1497
- * One secret an Environment of a kind needs (D64): its type and binding, never its value. The
1538
+ * One secret an Environment of a kind needs: its type and binding, never its value. The
1498
1539
  * value is written into each Environment's vault (`PUT /v1/agents/{id}/secrets/{name}`
1499
1540
  * with `{ value }`, or `{ headers }` for `headers`), and the binding comes from here.
1500
1541
  */
@@ -1560,7 +1601,7 @@ const harnessLoopField = definitionJson
1560
1601
  .optional()
1561
1602
  .meta({ description: "The harness's own settings, passed to it in turn.start; the Runtime never reads them" });
1562
1603
  /**
1563
- * `harness.memory` (track T5, D72): turns the Agent's memory on. Its `access` holds in every turn,
1604
+ * `harness.memory`: turns the Agent's memory on. Its `access` holds in every turn,
1564
1605
  * whoever starts it; `instructions` follow the engine's own memory rules.
1565
1606
  */
1566
1607
  const harnessMemoryField = z
@@ -1573,7 +1614,7 @@ const harnessMemoryField = z
1573
1614
  .meta({ description: "What this agent should remember, after the engine's own memory rules" }),
1574
1615
  })
1575
1616
  .optional()
1576
- .meta({ description: "The Agent's memory: Markdown files under /memories it keeps across sessions (D72)" });
1617
+ .meta({ description: "The Agent's memory: Markdown files under /memories it keeps across sessions" });
1577
1618
  /** Fields the harness section refuses with where they went. */
1578
1619
  const REMOVED_HARNESS_FIELDS = Object.freeze({
1579
1620
  requires: "harness.requires left the API in agent manifest v8: the Runtime checks the harness against the runtime section when the manifest is saved. Keep requires in harness.manifest.json, where the CLI checks it",
@@ -1659,7 +1700,7 @@ export const WorkflowHarnessSectionSchema = workflowHarnessObject.meta({
1659
1700
  /** The `harness` section: an agent's loop, or a flow (`kind: "workflow"`). */
1660
1701
  export const HarnessSectionSchema = z.union([WorkflowHarnessSectionSchema, AgentHarnessSectionSchema]);
1661
1702
  /**
1662
- * A trigger's id in `runtime.triggers` (track T4, D74): 1–64 letters, digits, `.`, `_` and `-`,
1703
+ * A trigger's id in `runtime.triggers`: 1–64 letters, digits, `.`, `_` and `-`,
1663
1704
  * starting with a letter or digit. The map key; it names the trigger in routes and runs.
1664
1705
  */
1665
1706
  export const TriggerIdSchema = z
@@ -1668,17 +1709,17 @@ export const TriggerIdSchema = z
1668
1709
  message: "A trigger id is 1-64 letters, digits, '.', '_' and '-', starting with a letter or digit",
1669
1710
  })
1670
1711
  .meta({ description: "A trigger's id, such as `hourly-check`" });
1671
- /** The signature schemes a webhook trigger verifies (D75): Standard Webhooks only in T4. */
1712
+ /** The signature schemes a webhook trigger verifies: Standard Webhooks only. */
1672
1713
  export const WEBHOOK_SCHEMES = ["standard-webhooks"];
1673
1714
  /**
1674
- * One trigger of an agent manifest's `runtime.triggers` (track T4, D74): exactly one of
1715
+ * One trigger of an agent manifest's `runtime.triggers`: exactly one of
1675
1716
  * `schedule` (five-field cron, minute granularity, in `timezone`, an IANA name, default UTC), `at`
1676
1717
  * (one run at an RFC 3339 time with an offset) or `webhook` (a webhook endpoint verified with the
1677
1718
  * named scheme), plus the `session` each run goes to and the author's `prompt`.
1678
1719
  *
1679
1720
  * `session` is a session id of the Agent, opened on the trigger's first run if it does not
1680
- * exist, or `"new"` for a new session per run (`run-<runId>`). The Runtime keeps no main session
1681
- * (D71). The cron's smallest gap, the `at` time, the prompt's length and how many triggers a
1721
+ * exist, or `"new"` for a new session per run (`run-<runId>`). The Runtime keeps no main session.
1722
+ * The cron's smallest gap, the `at` time, the prompt's length and how many triggers a
1682
1723
  * manifest holds are checked against the Tenant's Runtime limits when it is saved.
1683
1724
  */
1684
1725
  export const TriggerSchema = z
@@ -1701,14 +1742,14 @@ export const TriggerSchema = z
1701
1742
  ctx.addIssue({ code: "custom", path: ["timezone"], message: "timezone goes with schedule" });
1702
1743
  })
1703
1744
  .meta({ id: "Trigger" });
1704
- /** What a trigger is: the field it has, or `wake` for a session's own booking (D77). */
1745
+ /** What a trigger is: the field it has, or `wake` for a session's own booking. */
1705
1746
  export const TRIGGER_KINDS = ["schedule", "at", "webhook", "wake"];
1706
1747
  /** A trigger's kind, from its manifest entry. */
1707
1748
  export function triggerKindOf(trigger) {
1708
1749
  return trigger.schedule !== undefined ? "schedule" : trigger.at !== undefined ? "at" : "webhook";
1709
1750
  }
1710
1751
  /**
1711
- * A trigger's status on an Agent (D74): `active` fires, `paused` does not (`pausedReason`
1752
+ * A trigger's status on an Agent: `active` fires, `paused` does not (`pausedReason`
1712
1753
  * `manual`, or `new` for one an upgrade added), `completed` is an `at` that ran.
1713
1754
  */
1714
1755
  export const TRIGGER_STATUSES = ["active", "paused", "completed"];
@@ -1728,7 +1769,7 @@ export const TriggerViewSchema = z
1728
1769
  nextRunAt: z.string().nullable(),
1729
1770
  lastRunAt: z.string().nullable(),
1730
1771
  /**
1731
- * A webhook trigger's endpoint (D75): `POST` Standard Webhooks deliveries to it. The origin is
1772
+ * A webhook trigger's endpoint: `POST` Standard Webhooks deliveries to it. The origin is
1732
1773
  * the one this read reached.
1733
1774
  */
1734
1775
  webhookUrl: z.string().optional(),
@@ -1738,7 +1779,7 @@ export const TriggerViewSchema = z
1738
1779
  .strict();
1739
1780
  export const TriggerListSchema = z.object({ triggers: z.array(TriggerViewSchema) }).strict();
1740
1781
  /**
1741
- * What a run came to (D74): `started` a turn, `queued` a message behind a running turn,
1782
+ * What a run came to: `started` a turn, `queued` a message behind a running turn,
1742
1783
  * `skipped` (nothing started: `overlap`, `rate_limited`, `paused`) or `failed` (`queue_full`,
1743
1784
  * `session_conflict`, `agent_unavailable`).
1744
1785
  */
@@ -1766,7 +1807,7 @@ export const TriggerRunPageSchema = z
1766
1807
  .object({ runs: z.array(TriggerRunSchema), nextCursor: z.string().nullable() })
1767
1808
  .strict();
1768
1809
  /**
1769
- * `POST /v1/agents/{id}/triggers/{triggerId}/secret` (D75): a webhook trigger's new signing secret,
1810
+ * `POST /v1/agents/{id}/triggers/{triggerId}/secret`: a webhook trigger's new signing secret,
1770
1811
  * in the Standard Webhooks format (`whsec_` and 32 random bytes in base64), shown this once. It
1771
1812
  * replaces the one before at once.
1772
1813
  */
@@ -1780,7 +1821,7 @@ export const WebhookAcceptedResponseSchema = z
1780
1821
  /** `POST /v1/agents/{id}/triggers/{triggerId}/run`: the run it made. */
1781
1822
  export const RunTriggerResponseSchema = z.object({ run: TriggerRunSchema }).strict();
1782
1823
  /**
1783
- * One of an Agent's memories (track T5, D72), as `GET /v1/agents/{id}/memories` lists it: its
1824
+ * One of an Agent's memories, as `GET /v1/agents/{id}/memories` lists it: its
1784
1825
  * path under `/memories`, size, content hash (the precondition a `PUT` may send), the
1785
1826
  * `description` of its frontmatter when it has one, and its version, which every change bumps.
1786
1827
  */
@@ -1843,8 +1884,8 @@ export const MemoryVersionPageSchema = z
1843
1884
  /**
1844
1885
  * What the Runtime provides around the loop: the `runtime` section of agent manifest v8, with
1845
1886
  * environment manifest v1's fields but its identity and its `harness` (now `harness.id`).
1846
- * `triggers` (track T4, D74) start the Agent's turns with no client connected; `selfWake` offers
1847
- * the agent `schedule_wake`, which books its session's next turn (D77).
1887
+ * `triggers` start the Agent's turns with no client connected; `selfWake` offers
1888
+ * the agent `schedule_wake`, which books its session's next turn.
1848
1889
  */
1849
1890
  const runtimeSectionObject = z
1850
1891
  .strictObject({
@@ -1863,16 +1904,16 @@ const runtimeSectionObject = z
1863
1904
  triggers: z
1864
1905
  .record(TriggerIdSchema, TriggerSchema)
1865
1906
  .optional()
1866
- .meta({ description: "What starts the Agent's turns with no client connected, by trigger id (D74)" }),
1907
+ .meta({ description: "What starts the Agent's turns with no client connected, by trigger id" }),
1867
1908
  selfWake: z
1868
1909
  .boolean()
1869
1910
  .optional()
1870
- .meta({ description: "Offer the agent schedule_wake: it books its session's next turn itself (D77)" }),
1911
+ .meta({ description: "Offer the agent schedule_wake: it books its session's next turn itself" }),
1871
1912
  }, { error: removedFieldError(REMOVED_RUNTIME_SECTION_FIELDS) })
1872
1913
  .meta({ id: "RuntimeSection" });
1873
1914
  export const RuntimeSectionSchema = runtimeSectionObject;
1874
1915
  /**
1875
- * Agent manifest v8 (protocol 16, track T2): one versioned document with what runs inside the
1916
+ * Agent manifest v8 (protocol 16): one versioned document with what runs inside the
1876
1917
  * agent loop (`harness`) and what the Runtime provides around it (`runtime`), saved at
1877
1918
  * `PUT /v1/agent-manifests/{name}`. Without `runtime`, an Agent made from it is kind `none`.
1878
1919
  * The Runtime also checks the two sections against each other when it is saved (`sectionGaps`).
@@ -2010,7 +2051,7 @@ export const AgentManifestChangeSchema = z
2010
2051
  * `PUT /v1/agent-manifests/{name}?dryRun=true`: what saving it would do, with nothing saved.
2011
2052
  * `errors` lists every reason the Runtime would refuse it: the gaps between its sections, the
2012
2053
  * Tenant's limits, its files; a save with errors is refused. A save moves every Agent that tracks
2013
- * the manifest (track T3): `moves` counts them by when the new version applies. `behind` counts
2054
+ * the manifest: `moves` counts them by when the new version applies. `behind` counts
2014
2055
  * the Agents that stay on an older version: pinned ones, and tracking ones it cannot move.
2015
2056
  */
2016
2057
  export const AgentManifestPlanSchema = z
@@ -2047,7 +2088,7 @@ export const DeleteAgentManifestResponseSchema = z
2047
2088
  .object({ name: z.string(), deleted: z.boolean() })
2048
2089
  .strict();
2049
2090
  /**
2050
- * `POST /v1/agents/{id}/fork` (Q15): copies an Agent, with its disk and vault, into a new one,
2091
+ * `POST /v1/agents/{id}/fork`: copies an Agent, with its disk and vault, into a new one,
2051
2092
  * made from `manifest` (default the source's manifest at its latest version): how an Agent
2052
2093
  * changes what is fixed for its life (its kind, harness, storage or manifest). The source keeps
2053
2094
  * what it runs, its disk and its sessions.
@@ -2095,7 +2136,7 @@ export const AgentForkPlanSchema = z
2095
2136
  changes: z.array(z.object({ path: z.string(), from: z.unknown().optional(), to: z.unknown().optional() }).strict()),
2096
2137
  /** The source's sessions: they stay on it. */
2097
2138
  sessions: z.number().int().nonnegative(),
2098
- /** The source's memories (track T5): copied as they are now, each at version 1, with no history. */
2139
+ /** The source's memories: copied as they are now, each at version 1, with no history. */
2099
2140
  memories: z.number().int().nonnegative(),
2100
2141
  })
2101
2142
  .strict();
@@ -2105,7 +2146,7 @@ export const ForkAgentResponseSchema = z.union([
2105
2146
  z.object({ agent: AgentViewSchema, plan: AgentForkPlanSchema }).strict(),
2106
2147
  ]);
2107
2148
  /**
2108
- * `PUT /v1/agents/{id}?dryRun=true` on an existing Agent (track T3): what moving it to the
2149
+ * `PUT /v1/agents/{id}?dryRun=true` on an existing Agent: what moving it to the
2109
2150
  * version `manifest` names would do, with nothing changed. `applies`: `none` (it runs that
2110
2151
  * version), `now` (turns that start from here run it), `next_start` (a runtime change: its pod's
2111
2152
  * next start applies it), `secrets` (it waits for a value of each of `missingSecrets`), or
@@ -2142,7 +2183,7 @@ export const AgentMovePlanSchema = z
2142
2183
  })
2143
2184
  .strict();
2144
2185
  /**
2145
- * `POST /v1/agents/{id}/restart` (track T3): applies a pending version now. A running pod stops,
2186
+ * `POST /v1/agents/{id}/restart`: applies a pending version now. A running pod stops,
2146
2187
  * so the next turn starts it on the version (a stopped one starts at once); `retry` first moves
2147
2188
  * it to the version that failed to start (`failedVersion`) again.
2148
2189
  */
@@ -2164,11 +2205,24 @@ export const ModelInputSchema = z.enum(MODEL_INPUTS);
2164
2205
  * failed call.
2165
2206
  */
2166
2207
  export const CUSTOM_MODEL_SETTING_DEFAULTS = Object.freeze({ contextWindow: 32_768, maxTokens: 8_192 });
2208
+ /**
2209
+ * Where a custom endpoint's per-call header takes its value from the call (#493): one of the
2210
+ * calling Agent's labels (`key`, such as `org`), the Agent's id, or the session's owner when it
2211
+ * is a person. A call whose source has no value sends no header.
2212
+ */
2213
+ export const ModelCallHeaderSourceSchema = z.discriminatedUnion("from", [
2214
+ z.object({ from: z.literal("agent.label"), key: z.string().min(1) }).strict(),
2215
+ z.object({ from: z.literal("agent.id") }).strict(),
2216
+ z.object({ from: z.literal("session.owner") }).strict(),
2217
+ ]);
2167
2218
  /**
2168
2219
  * What the Runtime cannot learn from a custom OpenAI-compatible endpoint (Model Calls §7):
2169
2220
  * its context window and output limit (default `CUSTOM_MODEL_SETTING_DEFAULTS`), whether it
2170
2221
  * reasons, what it reads (`inputs`; default text only) and pi-ai `compat` settings
2171
- * (`thinkingFormat`, `thinkingTokenBudgetField`, `chatTemplateKwargs`, …).
2222
+ * (`thinkingFormat`, `thinkingTokenBudgetField`, `chatTemplateKwargs`, …). `headers` are sent on
2223
+ * every call and `callHeaders` resolved per call from the calling Agent, for a gateway that
2224
+ * attributes or budgets each call (#493): they are settings, never secrets, and read back as such,
2225
+ * so neither may set `authorization`.
2172
2226
  */
2173
2227
  export const CustomModelSettingsSchema = z
2174
2228
  .object({
@@ -2177,8 +2231,16 @@ export const CustomModelSettingsSchema = z
2177
2231
  reasoning: z.boolean().optional(),
2178
2232
  inputs: z.array(ModelInputSchema).optional(),
2179
2233
  compat: z.record(z.string(), z.unknown()).optional(),
2234
+ headers: z.record(CredentialHeaderNameSchema, CredentialHeaderValueSchema).optional(),
2235
+ callHeaders: z.record(CredentialHeaderNameSchema, ModelCallHeaderSourceSchema).optional(),
2180
2236
  })
2181
2237
  .strict();
2238
+ /**
2239
+ * How the Runtime authenticates to the model: a stored key, a stored OAuth grant, or (a custom
2240
+ * endpoint only) the Runtime's workload token, read from `NYLORUN_WORKLOAD_TOKEN_FILE` on every
2241
+ * call and never stored (#496).
2242
+ */
2243
+ export const HOST_MODEL_AUTH_TYPES = ["api_key", "oauth", "workload"];
2182
2244
  export const PutHostModelRequestSchema = z
2183
2245
  .object({
2184
2246
  ...vaultWriteBase,
@@ -2202,6 +2264,7 @@ export const PutHostModelRequestSchema = z
2202
2264
  expires: z.number(),
2203
2265
  })
2204
2266
  .passthrough(),
2267
+ z.object({ type: z.literal("workload") }).strict(),
2205
2268
  ]),
2206
2269
  })
2207
2270
  .strict();
@@ -2216,6 +2279,7 @@ export const SelectHostModelRequestSchema = z
2216
2279
  export const ENVIRONMENT_SECRET_TYPES = [
2217
2280
  "bearer",
2218
2281
  "headers",
2282
+ "workload",
2219
2283
  "environment_secret",
2220
2284
  "environment_variable",
2221
2285
  ];
@@ -2237,6 +2301,8 @@ export const AgentSecretViewSchema = z
2237
2301
  /** A `headers` credential's header names (lower case), never their values. */
2238
2302
  headerNames: z.array(z.string()).optional(),
2239
2303
  via: z.string().optional(),
2304
+ /** How the gateway at `via` prefixes tool names (Host feature `gateway-credentials`). */
2305
+ toolPrefix: z.string().optional(),
2240
2306
  identity: CredentialIdentitySchema.optional(),
2241
2307
  createdAt: z.string(),
2242
2308
  rotatedAt: z.string().optional(),
@@ -2248,7 +2314,7 @@ export const ListAgentSecretsResponseSchema = z
2248
2314
  /** The MCP transports a preview speaks: a manifest's remote server types. */
2249
2315
  export const MCP_PREVIEW_TYPES = ["streamable-http", "sse"];
2250
2316
  /**
2251
- * `POST /v1/tenant/mcp/preview` (R2b C12): what a remote MCP server offers, before an agent
2317
+ * `POST /v1/tenant/mcp/preview`: what a remote MCP server offers, before an agent
2252
2318
  * names it. The Runtime connects with the credential for `url` in the vault of Agent `agentId`
2253
2319
  * (none without one), lists the tools and closes the connection; it never calls a tool.
2254
2320
  */
@@ -2287,7 +2353,7 @@ export const McpPreviewToolSchema = z
2287
2353
  /** The server's own name for the tool. */
2288
2354
  serverToolName: z.string(),
2289
2355
  /**
2290
- * What the model would call it as Nylorun's engine names MCP tools (R2b C6); absent when the
2356
+ * What the model would call it as Nylorun's engine names MCP tools; absent when the
2291
2357
  * engine leaves the tool out (its input schema is not one it can use). A harness of your own
2292
2358
  * names tools itself.
2293
2359
  */
@@ -2300,7 +2366,7 @@ export const McpPreviewToolSchema = z
2300
2366
  })
2301
2367
  .strict();
2302
2368
  /**
2303
- * A preview (R2b C12). A server that answered `401` is `authRequired`, with its RFC 9728
2369
+ * A preview. A server that answered `401` is `authRequired`, with its RFC 9728
2304
2370
  * protected-resource metadata when it publishes any: it needs a person's sign-in or a key the
2305
2371
  * Environment's vault does not hold, so reach it with a key or through a gateway (`via`).
2306
2372
  */
@@ -2317,7 +2383,7 @@ export const McpPreviewSchema = z
2317
2383
  /** The server's instructions from `initialize`. */
2318
2384
  instructions: z.string().optional(),
2319
2385
  tools: z.array(McpPreviewToolSchema),
2320
- /** Tools Nylorun's engine names otherwise than `server__tool` (R2b C6). */
2386
+ /** Tools Nylorun's engine names otherwise than `server__tool`. */
2321
2387
  renamed: z.array(z.object({ serverToolName: z.string(), name: z.string() }).strict()),
2322
2388
  authRequired: z
2323
2389
  .object({
@@ -2396,7 +2462,7 @@ const commandBase = {
2396
2462
  idempotencyKey: IdempotencyKeySchema,
2397
2463
  };
2398
2464
  /**
2399
- * What a message to a busy session does (protocol 17, D76): `queue` waits for the running turn to
2465
+ * What a message to a busy session does (protocol 17): `queue` waits for the running turn to
2400
2466
  * end and starts the next one; `reject` is refused with `409 session_busy`. A protocol 17 client's
2401
2467
  * default is `queue`, a protocol 16 client's `reject`.
2402
2468
  */
@@ -2485,11 +2551,11 @@ export const SessionEventBodySchema = SessionCommandSchema;
2485
2551
  /** The envelope every session event carries (`nylorun.event/2`, Durable Streams §9.5). */
2486
2552
  export const EVENT_SCHEMA = "nylorun.event/2";
2487
2553
  /**
2488
- * Who wrote an event (track R4, R4.9): the writer says so, not the event's type. `client` is a
2554
+ * Who wrote an event: the writer says so, not the event's type. `client` is a
2489
2555
  * command over the Runtime API (its `principal` says who sent it), `core` is core's own logic
2490
2556
  * (settle, sweeps, the flow host, exports, the tools core serves), `harness` is what a harness
2491
2557
  * reported (`source.id` is its harness id, `runId` its run), and the gates are themselves.
2492
- * `loop` and `api` are what events written before R4 say.
2558
+ * `loop` and `api` are what older events say.
2493
2559
  */
2494
2560
  export const EventSourceKindSchema = z.enum([
2495
2561
  "client",
@@ -2522,10 +2588,10 @@ export const EvidenceClassSchema = z.enum([
2522
2588
  "claimed",
2523
2589
  "asserted",
2524
2590
  ]);
2525
- /** A command's sender (R4.9): from the request's credential, never from its body. */
2591
+ /** A command's sender: from the request's credential, never from its body. */
2526
2592
  export const EventPrincipalSchema = z
2527
2593
  .object({
2528
- /** `trigger`: core, for an Agent's trigger (track T4); its id is the trigger's. */
2594
+ /** `trigger`: core, for an Agent's trigger; its id is the trigger's. */
2529
2595
  kind: z.enum(["application", "subject", "flow-host", "core", "trigger"]),
2530
2596
  id: z.string(),
2531
2597
  })
@@ -2556,7 +2622,7 @@ const eventEnvelope = {
2556
2622
  schemaVersion: z.number().int().positive(),
2557
2623
  source: z.object({ kind: EventSourceKindSchema, id: z.string() }),
2558
2624
  evidence: EvidenceClassSchema,
2559
- /** Who sent a command (`command.*`, a cancel's `turn.cancelled`), from its credential (R4.9). */
2625
+ /** Who sent a command (`command.*`, a cancel's `turn.cancelled`), from its credential. */
2560
2626
  principal: EventPrincipalSchema.optional(),
2561
2627
  trace: z
2562
2628
  .object({
@@ -2626,7 +2692,7 @@ const toolIds = {
2626
2692
  invocationId: z.string().min(1),
2627
2693
  };
2628
2694
  /**
2629
- * When a gate served a call (R7.1): its own start and end, as it measured them. Absent when no
2695
+ * When a gate served a call: its own start and end, as it measured them. Absent when no
2630
2696
  * gate measured the call (a fixture model, a sandbox or core-served tool, a call refused before
2631
2697
  * it was sent).
2632
2698
  */
@@ -2634,7 +2700,7 @@ export const GateTimesSchema = z
2634
2700
  .object({ startedAt: z.string(), endedAt: z.string() })
2635
2701
  .passthrough();
2636
2702
  /**
2637
- * What the Model Gate's meter recorded for a model call (R7.1), from the usage ledger: the
2703
+ * What the Model Gate's meter recorded for a model call, from the usage ledger: the
2638
2704
  * tokens and cost the Runtime counts, beside the `usage` the harness reported. `cachedTokens`
2639
2705
  * and `costUsd` are absent when zero.
2640
2706
  */
@@ -2648,7 +2714,7 @@ export const MeteredUsageSchema = z
2648
2714
  })
2649
2715
  .passthrough();
2650
2716
  /**
2651
- * The timing of a model call's outcome (R7.1), on `message.assistant`, `model.failed` and
2717
+ * The timing of a model call's outcome, on `message.assistant`, `model.failed` and
2652
2718
  * `context.compacted`. `durationMs` is the journal's window, from the intent to the outcome;
2653
2719
  * `gate`, `firstTokenMs` and `meteredUsage` are the meter's, absent when no gate metered the
2654
2720
  * call.
@@ -2690,7 +2756,7 @@ export const AssistantMessagePayloadSchema = z
2690
2756
  ...eventAgent,
2691
2757
  })
2692
2758
  .passthrough();
2693
- /** True when a `message.assistant` said nothing: no text and no tool calls (R7.1). */
2759
+ /** True when a `message.assistant` said nothing: no text and no tool calls. */
2694
2760
  export function isEmptyAssistantMessage(payload) {
2695
2761
  return ((typeof payload.text !== "string" || payload.text === "") &&
2696
2762
  (payload.toolCalls?.length ?? 0) === 0);
@@ -2725,17 +2791,17 @@ export const ContextCompactedPayloadSchema = z
2725
2791
  ...eventAgent,
2726
2792
  })
2727
2793
  .passthrough();
2728
- /** How a tool call ended (R5.1): the tool answered, the Runtime ended it, or a cancel did. */
2794
+ /** How a tool call ended: the tool answered, the Runtime ended it, or a cancel did. */
2729
2795
  export const TOOL_CALL_STATUSES = ["completed", "failed", "cancelled"];
2730
2796
  /**
2731
- * Where a tool call ran (R5.1), its effect's target kind (protocol 15): an MCP server, an HTTP
2797
+ * Where a tool call ran, its effect's target kind (protocol 15): an MCP server, an HTTP
2732
2798
  * tool's URL, the session's sandbox, the harness that runs the turn (`harness`: a tool it runs
2733
2799
  * in its own process, such as our engine's skill, artifact and `tool_search` tools), or the
2734
- * Runtime itself (`runtime`: `schedule_wake`, track T4).
2800
+ * Runtime itself (`runtime`: `schedule_wake`).
2735
2801
  */
2736
2802
  export const TOOL_CALL_KINDS = ["mcp", "http", "sandbox", "harness", "runtime"];
2737
2803
  /**
2738
- * What the Tenant's tool policy did with a tool call (R5 step 2), when it did more than allow
2804
+ * What the Tenant's tool policy did with a tool call, when it did more than allow
2739
2805
  * it: `deny` refused it unsent; `ask` held it for a person, who approved it (`approvedBy`, when
2740
2806
  * known) or denied it.
2741
2807
  */
@@ -2747,7 +2813,7 @@ export const ToolPolicyFactSchema = z
2747
2813
  })
2748
2814
  .passthrough();
2749
2815
  /**
2750
- * `tool.completed`: how one tool call ended, written once per call (R5.1). `status`
2816
+ * `tool.completed`: how one tool call ended, written once per call. `status`
2751
2817
  * `completed`: the tool answered, with its output or the tool error it reported (`error`).
2752
2818
  * `failed`: the Runtime ended the call (`tool.disabled`, `tool.unavailable`, `tool.denied`, or
2753
2819
  * `tool.interrupted` for a call a crash interrupted, which may have run). `cancelled`: the turn
@@ -2757,7 +2823,7 @@ export const ToolPolicyFactSchema = z
2757
2823
  export const ToolCompletedPayloadSchema = z
2758
2824
  .object({
2759
2825
  ...toolIds,
2760
- /** The tool call's effect id (R7.1). */
2826
+ /** The tool call's effect id. */
2761
2827
  effectId: z.string().min(1).optional(),
2762
2828
  /** The name the model called the tool by, as its harness named it: for display. */
2763
2829
  toolName: z.string().min(1),
@@ -2782,7 +2848,7 @@ export const ToolCompletedPayloadSchema = z
2782
2848
  /** From the first send to the outcome; absent when the call never ran. */
2783
2849
  durationMs: z.number().int().nonnegative().optional(),
2784
2850
  /**
2785
- * The Tool Gate's own start and end of the call's last send (R7.1): an MCP or HTTP tool
2851
+ * The Tool Gate's own start and end of the call's last send: an MCP or HTTP tool
2786
2852
  * through the gateway. Absent for a sandbox or core-served tool.
2787
2853
  */
2788
2854
  gate: GateTimesSchema.optional(),
@@ -2793,18 +2859,24 @@ export const ToolCompletedPayloadSchema = z
2793
2859
  code: z.string(),
2794
2860
  message: z.string(),
2795
2861
  /**
2796
- * With `credential_rejected` (R2b C1): the MCP server, or the HTTP tool's `credential`,
2797
- * whose server answered `401`.
2862
+ * With `credential_rejected`: the MCP server, or the HTTP tool's `credential`,
2863
+ * whose server answered `401` (or, through a credential's `via`, whose gateway
2864
+ * reported that the server behind it did): the integration refused the credential.
2798
2865
  */
2799
2866
  server: z.string().optional(),
2800
- /** An MCP tool error (R2b C7): true when calling again may work, as for `mcp.unreachable`. */
2867
+ /**
2868
+ * With `credential_rejected` of the Runtime's workload token: the origin of the gateway
2869
+ * that refused it (#496), an expired or unrotated token.
2870
+ */
2871
+ gateway: z.string().optional(),
2872
+ /** An MCP tool error: true when calling again may work, as for `mcp.unreachable`. */
2801
2873
  retryable: z.boolean().optional(),
2802
2874
  })
2803
2875
  .passthrough()
2804
2876
  .optional(),
2805
2877
  /**
2806
- * How many credential values the Runtime replaced with `[redacted]` in `output` or `error`
2807
- * (R2b C8): the server echoed what it was sent. Absent when none.
2878
+ * How many credential values the Runtime replaced with `[redacted]` in `output` or `error`:
2879
+ * the server echoed what it was sent. Absent when none.
2808
2880
  */
2809
2881
  redacted: z.number().int().positive().optional(),
2810
2882
  ...eventAgent,
@@ -2814,7 +2886,7 @@ export const EffectUncertainPayloadSchema = z
2814
2886
  .object({ effectId: z.string().min(1), message: z.string().optional() })
2815
2887
  .passthrough();
2816
2888
  /**
2817
- * How a turn that ended went (R7.1), on `turn.completed`, `turn.failed` and `turn.cancelled`:
2889
+ * How a turn that ended went, on `turn.completed`, `turn.failed` and `turn.cancelled`:
2818
2890
  * `durationMs` from the turn's start to its end, waits for a person included, so the turn's span
2819
2891
  * holds every crossing in it; `pausedMs`, how much of that it waited paused; `totals` from the
2820
2892
  * usage ledger (`steps`: the model calls the gate metered). Absent on a turn
@@ -2877,7 +2949,7 @@ export const MessageQueuedPayloadSchema = z
2877
2949
  .object({ queuedMessageId: z.string(), position: z.number().int().positive(), requestId: z.string() })
2878
2950
  .passthrough();
2879
2951
  /**
2880
- * `wake.booked` (track T4, D77): the session's agent booked its next turn with `schedule_wake`,
2952
+ * `wake.booked`: the session's agent booked its next turn with `schedule_wake`,
2881
2953
  * at `at`, replacing any booking before. `wake.cancelled`: it cancelled its booking.
2882
2954
  */
2883
2955
  export const WakeBookedPayloadSchema = z
@@ -2924,7 +2996,7 @@ export const CommandMessagePayloadSchema = z
2924
2996
  /** Set when the message waited in the session's queue (protocol 17): its id there. */
2925
2997
  queuedMessageId: z.string().optional(),
2926
2998
  /**
2927
- * What sent it, when not a client (track T4): a trigger's run (`trigger`, with the trigger
2999
+ * What sent it, when not a client: a trigger's run (`trigger`, with the trigger
2928
3000
  * and run ids), or the session's own booked wake (`self`).
2929
3001
  */
2930
3002
  cause: z
@@ -2932,7 +3004,7 @@ export const CommandMessagePayloadSchema = z
2932
3004
  .strict()
2933
3005
  .optional(),
2934
3006
  /**
2935
- * The W3C trace context the message was sent with (R7.4): the turn's trace is the caller's,
3007
+ * The W3C trace context the message was sent with: the turn's trace is the caller's,
2936
3008
  * and its root span the child of the caller's span.
2937
3009
  */
2938
3010
  trace: z
@@ -3001,7 +3073,7 @@ export const NodeStartedPayloadSchema = z
3001
3073
  .passthrough();
3002
3074
  /**
3003
3075
  * `node.completed`: a flow's HTTP stage or HTTP verifier ended, or a tool stage the Runtime
3004
- * refused to run (R7.1), named as its `node.started` names it. `status` reads as
3076
+ * refused to run, named as its `node.started` names it. `status` reads as
3005
3077
  * `tool.completed`'s: `completed` when the stage's server answered (an error answer included),
3006
3078
  * `failed` when the Runtime ended it, `cancelled` when a cancel did. `gate` is the Tool Gate's
3007
3079
  * own start and end of its last send.
@@ -3049,7 +3121,7 @@ export const LoopVerifiedPayloadSchema = z
3049
3121
  })
3050
3122
  .passthrough();
3051
3123
  /**
3052
- * `transcript.updated` (internal; blueprint P0.3): the own loop's model-facing transcript after a
3124
+ * `transcript.updated` (internal): the own loop's model-facing transcript after a
3053
3125
  * settled segment, as an edit of the previous one: keep its first `keep` entries, then append
3054
3126
  * `entries`; the result has `length` entries. `keep` is 0 for a snapshot (after compaction, or
3055
3127
  * for a session written before transcripts were recorded). Large edits are split into
@@ -3071,7 +3143,7 @@ export const TranscriptUpdatedPayloadSchema = z
3071
3143
  */
3072
3144
  export const ArtifactSourceSchema = z.enum(["upload", "engine", "export", "snapshot"]);
3073
3145
  /**
3074
- * What an artifact holds: one file, or a folder (F8.2), whose versions are manifests of paths to
3146
+ * What an artifact holds: one file, or a folder, whose versions are manifests of paths to
3075
3147
  * content-addressed files.
3076
3148
  */
3077
3149
  export const ArtifactKindSchema = z.enum(["file", "folder"]);
@@ -3114,7 +3186,7 @@ export const ArtifactExportSkipReasonSchema = z.enum([
3114
3186
  "file_too_large",
3115
3187
  "too_large",
3116
3188
  "tenant_total",
3117
- /** Past the session's Environment's own total (its manifest's `limits.artifacts.totalBytes`). */
3189
+ /** Past the session's Agent's own total (its manifest's `runtime.limits.artifacts.totalBytes`). */
3118
3190
  "environment_total",
3119
3191
  ]);
3120
3192
  /**
@@ -3154,10 +3226,10 @@ export const McpServerOutcomeSchema = z
3154
3226
  message: z.string(),
3155
3227
  /** The tools it added to the session that its `tools` settings leave enabled; 0 unless connected. */
3156
3228
  tools: z.number().int().nonnegative(),
3157
- /** Listed tools the server's `tools` settings disable (R2b C9); absent when none. */
3229
+ /** Listed tools the server's `tools` settings disable; absent when none. */
3158
3230
  disabled: z.number().int().positive().optional(),
3159
3231
  /**
3160
- * Keys of the server's `tools` settings that name no tool it listed (R2b C9): a diagnostic,
3232
+ * Keys of the server's `tools` settings that name no tool it listed: a diagnostic,
3161
3233
  * since servers change their lists.
3162
3234
  */
3163
3235
  unknownTools: z.array(z.string()).optional(),
@@ -3373,7 +3445,7 @@ export const StreamRelayStatusSchema = z
3373
3445
  })
3374
3446
  .strict();
3375
3447
  /**
3376
- * The Tenant's harnesses (F6.2): `in-process` runs one in core's process; `remote` waits for
3448
+ * The Tenant's harnesses: `in-process` runs one in core's process; `remote` waits for
3377
3449
  * harnesses on the Harness API listener. `workspace` says one that serves the Tenant's
3378
3450
  * workspaces is connected.
3379
3451
  */
@@ -3447,7 +3519,7 @@ export const HostModelViewSchema = z.union([
3447
3519
  configured: z.literal(true),
3448
3520
  provider: z.string(),
3449
3521
  model: z.string(),
3450
- authType: z.enum(["api_key", "oauth"]),
3522
+ authType: z.enum(HOST_MODEL_AUTH_TYPES),
3451
3523
  baseUrl: z.string().optional(),
3452
3524
  settings: CustomModelSettingsSchema.optional(),
3453
3525
  })
@@ -3481,7 +3553,7 @@ export const TenantStatusSchema = z
3481
3553
  retained: z.number().int().nonnegative(),
3482
3554
  })
3483
3555
  .strict(),
3484
- /** The Tenant's harnesses (F6.2). */
3556
+ /** The Tenant's harnesses. */
3485
3557
  harness: HarnessStatusSchema.optional(),
3486
3558
  /**
3487
3559
  * Durable Session Execution invocations of this Tenant that need an operator: paused
@@ -3587,14 +3659,14 @@ export const SUBJECT_SCOPES = [
3587
3659
  const RETIRED_SUBJECT_SCOPES = ["vaults:own", "tenant:settings"];
3588
3660
  /**
3589
3661
  * 1–200 visible ASCII characters; spaces only inside.
3590
- * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
3662
+ * An identifier's grammar is the protocol's: it crosses the Runtime API, tokens and grants
3591
3663
  * and means the same in every installation, so its length is a constant of protocol 15, not a
3592
3664
  * setting.
3593
3665
  */
3594
3666
  const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
3595
3667
  /**
3596
3668
  * The owner of a session opened for no person: an MCP server's or HTTP tool's identity header
3597
- * (R2b C2) names nobody for it. A reserved subject.
3669
+ * names nobody for it. A reserved subject.
3598
3670
  */
3599
3671
  export const INSTALLATION_OWNER = "installation";
3600
3672
  /** Owner ids the Runtime uses itself: `host` (the model vault's) and `installation`. */
@@ -3792,7 +3864,7 @@ export const SessionViewSchema = z
3792
3864
  /** Messages waiting in the session's queue for the next turn (protocol 17). */
3793
3865
  queuedMessages: z.number().int().nonnegative(),
3794
3866
  /**
3795
- * The harness that runs the session's turns, pinned when it opened (track R4): its
3867
+ * The harness that runs the session's turns, pinned when it opened: its
3796
3868
  * manifest's `harness.id`, else `nylorun`.
3797
3869
  */
3798
3870
  harness: z.string(),
@@ -3854,7 +3926,7 @@ export const HostModelProviderInfoSchema = z
3854
3926
  id: z.string(),
3855
3927
  name: z.string(),
3856
3928
  model: z.string(),
3857
- authType: z.enum(["api_key", "oauth"]),
3929
+ authType: z.enum(HOST_MODEL_AUTH_TYPES),
3858
3930
  baseUrl: z.string().optional(),
3859
3931
  settings: CustomModelSettingsSchema.optional(),
3860
3932
  /** What the provider's selected model reads (protocol 12); absent for a model unknown here. */
@@ -3905,7 +3977,7 @@ export const EffectiveSandboxConfigSchema = z
3905
3977
  .strict(),
3906
3978
  /** Pods (Host feature `sandbox-pods`): the pod's stop grace. */
3907
3979
  lifecycle: z.object({ stopGrace: z.string() }).strict().optional(),
3908
- /** Where each harness may run (D38). */
3980
+ /** Where each harness may run. */
3909
3981
  placement: z
3910
3982
  .record(z.string(), z.object({ hosts: z.array(z.enum(PLACEMENT_HOSTS)) }).strict())
3911
3983
  .optional(),
@@ -4023,7 +4095,7 @@ export const PutModelBudgetsRequestSchema = z
4023
4095
  }
4024
4096
  });
4025
4097
  export const ModelBudgetsSchema = z.object({ budgets: z.array(ModelBudgetSchema) }).strict();
4026
- /** What a tool policy rule does to a call it matches (R5 step 2). */
4098
+ /** What a tool policy rule does to a call it matches. */
4027
4099
  export const TOOL_POLICY_EFFECTS = ["allow", "ask", "deny"];
4028
4100
  /** A test of one field of a tool call's input; every test it sets must hold. */
4029
4101
  export const ToolInputConditionSchema = z
@@ -4053,12 +4125,13 @@ export const ToolInputConditionSchema = z
4053
4125
  }
4054
4126
  });
4055
4127
  /**
4056
- * One rule of the Tenant's tool policy (R5 step 2), applied at the Tool Gate to every MCP and
4057
- * HTTP tool call of every harness. A rule matches a call when every selector it sets matches:
4058
- * `tool` (the tool's identity: an MCP tool's own name on its server, or an HTTP tool's declared
4059
- * name; never the name a harness gave the model; `*` for any run of characters), `server` (an MCP
4060
- * server's name), `kind`, `agent` (the agent that calls it) and `when` (fields of the input, by
4061
- * dotted path). The strictest matching rule decides: `deny` refuses the call before it is sent,
4128
+ * One rule of the Tenant's tool policy, applied at the Tool Gate to every MCP and HTTP tool call
4129
+ * of every harness. A rule matches a call when every selector it sets matches: `tool` (the tool's
4130
+ * identity: an MCP tool's own name on its server, or an HTTP tool's declared name; never the name
4131
+ * a harness gave the model; `*` for any run of characters), `server` (an MCP server's name),
4132
+ * `kind`, `agent` (the agent that calls it: the agent manifest's name, or the id of an agent used
4133
+ * as a tool or of a flow's agent; never an Agent's id) and `when` (fields of the input, by dotted
4134
+ * path). The strictest matching rule decides: `deny` refuses the call before it is sent,
4062
4135
  * `ask` holds it until a person approves it on the session (`approve`), `allow` runs it. A call no
4063
4136
  * rule matches runs. Sandbox tools never cross the gate; their network side is egress policy.
4064
4137
  *
@@ -4070,11 +4143,26 @@ export const ToolRuleSchema = z
4070
4143
  effect: z.enum(TOOL_POLICY_EFFECTS),
4071
4144
  // The selectors, and `when`'s paths, are at most the Tenant's Runtime limit
4072
4145
  // `toolRuleFieldChars` long; `reason` at most `toolRuleTextChars` (checked when put).
4073
- tool: z.string().min(1).optional(),
4074
- server: z.string().min(1).optional(),
4146
+ tool: z
4147
+ .string()
4148
+ .min(1)
4149
+ .optional()
4150
+ .meta({
4151
+ description: "The tool's identity: an MCP tool's own name on its `server`, or an HTTP tool's declared name, never the name the model calls it by. `*` matches any run of characters; a name with `__` in it is refused",
4152
+ }),
4153
+ server: z.string().min(1).optional().meta({ description: "An MCP server's name; `*` matches any run of characters" }),
4075
4154
  kind: z.enum(["mcp", "http"]).optional(),
4076
- agent: z.string().min(1).optional(),
4077
- when: z.record(z.string().min(1), ToolInputConditionSchema).optional(),
4155
+ agent: z
4156
+ .string()
4157
+ .min(1)
4158
+ .optional()
4159
+ .meta({
4160
+ description: "The agent that calls the tool: the agent manifest's name, or the id of an agent used as a tool or of a flow's agent, never an Agent's id. `*` matches any run of characters",
4161
+ }),
4162
+ when: z
4163
+ .record(z.string().min(1), ToolInputConditionSchema)
4164
+ .optional()
4165
+ .meta({ description: "Fields of the call's input by dotted path, each tested by every test its condition sets" }),
4078
4166
  /** Why the rule exists: shown with a held or denied call. */
4079
4167
  reason: z.string().min(1).optional(),
4080
4168
  })
@@ -4119,7 +4207,7 @@ export const AgUiRunErrorCodeSchema = z.enum([
4119
4207
  // --- Studio embedding (Studio design §8) ---------------------------------------------------
4120
4208
  /**
4121
4209
  * A Tenant id as Studio's routes accept it.
4122
- * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
4210
+ * An identifier's grammar is the protocol's: it crosses the Runtime API, tokens and grants
4123
4211
  * and means the same in every installation, so its length is a constant of protocol 15, not a
4124
4212
  * setting.
4125
4213
  */
@@ -4258,7 +4346,7 @@ export const ARTIFACT_TOTAL_BYTES_DEFAULT = 10 * 1024 * 1024 * 1024;
4258
4346
  /**
4259
4347
  * The longest artifact name, in characters: the longest file name a workspace's file system takes
4260
4348
  * (`NAME_MAX`), since a name becomes one when the artifact is copied into a sandbox or downloaded.
4261
- * A standard's constant, not a limit (B15).
4349
+ * A standard's constant, not a limit.
4262
4350
  */
4263
4351
  export const ARTIFACT_NAME_MAX = FILE_NAME_MAX;
4264
4352
  /**
@@ -4287,7 +4375,7 @@ export const ArtifactVersionViewSchema = z
4287
4375
  .strict();
4288
4376
  /**
4289
4377
  * An artifact: an id, a name and numbered versions, its bytes in the Object store. A file's
4290
- * version is its bytes; a folder's (F8.2) is a manifest of paths to content-addressed files.
4378
+ * version is its bytes; a folder's is a manifest of paths to content-addressed files.
4291
4379
  */
4292
4380
  export const ArtifactViewSchema = z
4293
4381
  .object({
@@ -4298,7 +4386,7 @@ export const ArtifactViewSchema = z
4298
4386
  /** The session it belongs to; absent for a Tenant-wide artifact an application made. */
4299
4387
  sessionId: z.string().optional(),
4300
4388
  /**
4301
- * The Agent whose disk versions it holds (R2d step 3); absent otherwise. Such an artifact
4389
+ * The Agent whose disk versions it holds; absent otherwise. Such an artifact
4302
4390
  * changes only through `/v1/agents/{id}/snapshot` and its versions routes.
4303
4391
  */
4304
4392
  agentId: z.string().optional(),
@@ -4323,7 +4411,7 @@ export const UploadArtifactResponseSchema = z
4323
4411
  .object({ artifact: ArtifactViewSchema, version: ArtifactVersionViewSchema })
4324
4412
  .strict();
4325
4413
  /**
4326
- * `PUT /v1/files/sha256:{hex}`: a definition file the Runtime holds (track R2 M4), named by the
4414
+ * `PUT /v1/files/sha256:{hex}`: a definition file the Runtime holds, named by the
4327
4415
  * SHA-256 of its bytes. `201` stored it, `200` already had it.
4328
4416
  */
4329
4417
  export const DefinitionFileViewSchema = z
@@ -4368,7 +4456,7 @@ export const FOLDER_CONTENT_TYPE = "application/vnd.nylorun.folder+json";
4368
4456
  /** The manifest format a folder version is stored as. */
4369
4457
  export const FOLDER_MANIFEST_FORMAT = "nylorun.folder.v1";
4370
4458
  /**
4371
- * The manifest format of an Environment's disk versions (R2d step 3): v1's entries, plus file
4459
+ * The manifest format of an Environment's disk versions: v1's entries, plus file
4372
4460
  * modes and modification times, symbolic links and empty directories. Readers accept both.
4373
4461
  */
4374
4462
  export const FOLDER_MANIFEST_FORMAT_V2 = "nylorun.folder.v2";
@@ -4398,7 +4486,7 @@ export const FolderEntrySchema = z
4398
4486
  .strict();
4399
4487
  /**
4400
4488
  * A folder version as stored: the files, sorted by path, each naming its content-addressed
4401
- * bytes by SHA-256. The one manifest format for folders, reused by P5's snapshots.
4489
+ * bytes by SHA-256. The one manifest format for folders, reused by disk snapshots.
4402
4490
  */
4403
4491
  export const FolderManifestSchema = z
4404
4492
  .object({
@@ -4481,7 +4569,7 @@ export const TenantSkillsViewSchema = z
4481
4569
  .object({ limits: z.object({ totalBytes: z.number().int() }).strict() })
4482
4570
  .strict();
4483
4571
  /**
4484
- * A Tenant's Runtime limits (harness boundary S0), stored as Tenant setting `limits.config`: what
4572
+ * A Tenant's Runtime limits, stored as Tenant setting `limits.config`: what
4485
4573
  * one record entry, model call, model file, tool answer, harness state and Harness API chunk may
4486
4574
  * hold. Each limit left out is its default (`RUNTIME_LIMIT_DEFAULTS`); none may pass its ceiling
4487
4575
  * (`RUNTIME_LIMIT_CEILINGS`, a `400` naming it).
@@ -4526,6 +4614,18 @@ const usageNumbers = {
4526
4614
  reasoningTokens: z.number().int().nonnegative(),
4527
4615
  costUsd: z.number().nonnegative(),
4528
4616
  };
4617
+ /**
4618
+ * A cost by the token kind it paid for, at the prices in force when the call was made:
4619
+ * uncached input, input read from the provider's cache, input written to it, and output.
4620
+ */
4621
+ export const CostSplitSchema = z
4622
+ .object({
4623
+ input: z.number().nonnegative(),
4624
+ cacheRead: z.number().nonnegative(),
4625
+ cacheWrite: z.number().nonnegative(),
4626
+ output: z.number().nonnegative(),
4627
+ })
4628
+ .strict();
4529
4629
  export const SessionUsageTotalsSchema = z
4530
4630
  .object({
4531
4631
  sessionId: z.string(),
@@ -4537,14 +4637,27 @@ export const SessionUsageTotalsSchema = z
4537
4637
  unpricedCalls: z.number().int().nonnegative(),
4538
4638
  unreportedCalls: z.number().int().nonnegative(),
4539
4639
  unknownQualityCalls: z.number().int().nonnegative(),
4640
+ /**
4641
+ * `costUsd` by token kind, summed over the `splitCalls` calls that kept their split. A call
4642
+ * recorded before the split was kept counts in `costUsd` only. Protocol 18, like
4643
+ * `modelTimeMs` and `timedCalls`: an older client's read leaves all four out.
4644
+ */
4645
+ costSplit: CostSplitSchema,
4646
+ splitCalls: z.number().int().nonnegative(),
4647
+ /**
4648
+ * The calls' durations added up, from when the gate sent each call to when its answer was
4649
+ * complete, over the `timedCalls` calls the gate timed. Calls that overlap each count in full.
4650
+ */
4651
+ modelTimeMs: z.number().int().nonnegative(),
4652
+ timedCalls: z.number().int().nonnegative(),
4540
4653
  })
4541
4654
  .strict();
4542
4655
  export const ModelCallSchema = z
4543
4656
  .object({
4544
4657
  id: z.string(),
4545
4658
  /**
4546
- * The model effect the call served: the effect id its harness sent as `Idempotency-Key`
4547
- * (track R4), so a call is joined to the journal.
4659
+ * The model effect the call served: the effect id its harness sent as `Idempotency-Key`,
4660
+ * so a call is joined to the journal.
4548
4661
  */
4549
4662
  effectId: z.string(),
4550
4663
  sessionId: z.string(),
@@ -4554,6 +4667,12 @@ export const ModelCallSchema = z
4554
4667
  provider: z.string().nullable(),
4555
4668
  model: z.string().nullable(),
4556
4669
  at: z.string(),
4670
+ /**
4671
+ * When the gate sent the call, and when its answer was complete; null when untimed. Protocol
4672
+ * 18, like `usage.costSplit`: an older client's read leaves them out.
4673
+ */
4674
+ startedAt: z.string().nullable(),
4675
+ endedAt: z.string().nullable(),
4557
4676
  outcome: z.enum(["completed", "failed"]),
4558
4677
  usage: z
4559
4678
  .object({
@@ -4561,6 +4680,8 @@ export const ModelCallSchema = z
4561
4680
  duplicate: z.boolean(),
4562
4681
  tokensReported: z.boolean().nullable(),
4563
4682
  costKnown: z.boolean().nullable(),
4683
+ /** `costUsd` by token kind; null for a call recorded before the split was kept. */
4684
+ costSplit: CostSplitSchema.nullable(),
4564
4685
  })
4565
4686
  .strict()
4566
4687
  .nullable(),
@@ -4578,9 +4699,9 @@ export const ModelCallExportPageSchema = z
4578
4699
  })
4579
4700
  .strict();
4580
4701
  /**
4581
- * One tool call of a session (R5.2), read from the effect journal: what ran, with what input,
4702
+ * One tool call of a session, read from the effect journal: what ran, with what input,
4582
4703
  * how many sends, and how it ended. `invoking` while it runs. `uncertain` only for a call
4583
- * recorded before R5. The output is in the session's log (`tool.completed`).
4704
+ * recorded by an older Runtime. The output is in the session's log (`tool.completed`).
4584
4705
  */
4585
4706
  export const ToolCallSchema = z
4586
4707
  .object({
@@ -4597,7 +4718,7 @@ export const ToolCallSchema = z
4597
4718
  skill: z.string().nullable(),
4598
4719
  /** The Agent Plugin that brought its MCP server or skill. */
4599
4720
  plugin: pluginLabelSchema.nullable(),
4600
- /** `held`: the Tool Gate holds it for a person's approval (R5 step 2). */
4721
+ /** `held`: the Tool Gate holds it for a person's approval. */
4601
4722
  status: z.enum(["invoking", "held", ...TOOL_CALL_STATUSES, "uncertain"]),
4602
4723
  attempts: z.number().int().nonnegative(),
4603
4724
  input: z.unknown(),
@@ -4610,12 +4731,12 @@ export const ToolCallSchema = z
4610
4731
  export const ToolCallsPageSchema = z
4611
4732
  .object({ calls: z.array(ToolCallSchema), nextCursor: z.string().nullable(), asOf: z.string() })
4612
4733
  .strict();
4613
- /** One OTLP attribute (R7.5): a key and an `AnyValue` (`stringValue`, `intValue`, …). */
4734
+ /** One OTLP attribute: a key and an `AnyValue` (`stringValue`, `intValue`, …). */
4614
4735
  export const OtlpKeyValueSchema = z
4615
4736
  .object({ key: z.string(), value: z.record(z.string(), z.unknown()) })
4616
4737
  .passthrough();
4617
4738
  /**
4618
- * One span as OTLP/HTTP JSON encodes it (R7.5): hex ids, times in nanoseconds as decimal strings,
4739
+ * One span as OTLP/HTTP JSON encodes it: hex ids, times in nanoseconds as decimal strings,
4619
4740
  * `kind` (1 internal, 3 client) and `status.code` (0 unset, 1 ok, 2 error) as numbers.
4620
4741
  */
4621
4742
  export const OtlpSpanSchema = z
@@ -4632,7 +4753,7 @@ export const OtlpSpanSchema = z
4632
4753
  })
4633
4754
  .passthrough();
4634
4755
  /**
4635
- * A turn's trace (R7.5, feature `traces`): the OTLP `ExportTraceServiceRequest` JSON the Runtime
4756
+ * A turn's trace (feature `traces`): the OTLP `ExportTraceServiceRequest` JSON the Runtime
4636
4757
  * posts to a collector, built from the turn's log rows. One resource, one scope.
4637
4758
  */
4638
4759
  export const TurnTraceSchema = z