@nylorun/runtime 0.25.0-beta → 0.27.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 (326) hide show
  1. package/CHANGELOG.md +169 -0
  2. package/README.md +26 -16
  3. package/dist/adapters/execution/restate.d.ts +15 -18
  4. package/dist/adapters/execution/restate.js +31 -27
  5. package/dist/adapters/replication/pgoutput.d.ts +1 -1
  6. package/dist/adapters/replication/pgoutput.js +3 -2
  7. package/dist/adapters/sandbox/local.js +8 -5
  8. package/dist/adapters/sandbox/virtual.js +2 -2
  9. package/dist/adapters/streams/s2.d.ts +1 -1
  10. package/dist/adapters/streams/s2.js +18 -14
  11. package/dist/api/a2a/card.js +1 -1
  12. package/dist/api/a2a/endpoint.js +3 -4
  13. package/dist/api/a2a/protocol.js +4 -0
  14. package/dist/api/a2a/routes.d.ts +2 -6
  15. package/dist/api/a2a/routes.js +12 -18
  16. package/dist/api/ag-ui/endpoint.js +2 -3
  17. package/dist/api/ag-ui/routes.js +4 -4
  18. package/dist/api/components.d.ts +326 -45
  19. package/dist/api/components.js +5 -1
  20. package/dist/api/gate/keys.js +7 -4
  21. package/dist/api/gate/routes.d.ts +6 -2
  22. package/dist/api/gate/routes.js +15 -11
  23. package/dist/api/http/app.d.ts +2 -2
  24. package/dist/api/http/app.js +2 -2
  25. package/dist/api/http/body.d.ts +15 -3
  26. package/dist/api/http/body.js +15 -7
  27. package/dist/api/http/define.d.ts +1 -1
  28. package/dist/api/http/respond.js +7 -3
  29. package/dist/api/http/routes/access.js +5 -4
  30. package/dist/api/http/routes/artifacts.js +19 -7
  31. package/dist/api/http/routes/coverage.js +1 -1
  32. package/dist/api/http/routes/environment-manifests.js +1 -1
  33. package/dist/api/http/routes/environments.js +6 -6
  34. package/dist/api/http/routes/files.d.ts +2 -1
  35. package/dist/api/http/routes/files.js +31 -5
  36. package/dist/api/http/routes/mcp.js +1 -1
  37. package/dist/api/http/routes/reads.d.ts +35 -0
  38. package/dist/api/http/routes/reads.js +50 -22
  39. package/dist/api/http/routes/sessions.js +12 -11
  40. package/dist/api/http/routes/tenant.d.ts +2 -2
  41. package/dist/api/http/routes/tenant.js +69 -16
  42. package/dist/api/inbound-files.d.ts +3 -9
  43. package/dist/api/inbound-files.js +18 -24
  44. package/dist/api/openapi.js +6 -2
  45. package/dist/artifacts/disk.d.ts +0 -4
  46. package/dist/artifacts/disk.js +77 -73
  47. package/dist/artifacts/files.d.ts +13 -4
  48. package/dist/artifacts/files.js +27 -9
  49. package/dist/artifacts/folder-upload.d.ts +75 -0
  50. package/dist/artifacts/folder-upload.js +263 -0
  51. package/dist/artifacts/folders.d.ts +14 -8
  52. package/dist/artifacts/folders.js +19 -11
  53. package/dist/artifacts/links.js +7 -6
  54. package/dist/artifacts/parts.d.ts +9 -14
  55. package/dist/artifacts/parts.js +11 -9
  56. package/dist/artifacts/pipe.d.ts +15 -0
  57. package/dist/artifacts/pipe.js +71 -0
  58. package/dist/artifacts/quota.d.ts +36 -0
  59. package/dist/artifacts/quota.js +44 -0
  60. package/dist/artifacts/service.d.ts +25 -1
  61. package/dist/artifacts/service.js +70 -25
  62. package/dist/blob/fs.js +2 -1
  63. package/dist/blob/s3.d.ts +6 -2
  64. package/dist/blob/s3.js +9 -7
  65. package/dist/blob/types.d.ts +1 -1
  66. package/dist/blob/types.js +1 -1
  67. package/dist/core/limits.d.ts +11 -35
  68. package/dist/core/limits.js +5 -73
  69. package/dist/core/sandbox-routes.js +0 -1
  70. package/dist/core/turn-manifest.d.ts +1 -2
  71. package/dist/core/turn-manifest.js +4 -28
  72. package/dist/execution/memory.d.ts +8 -5
  73. package/dist/execution/memory.js +8 -6
  74. package/dist/execution/types.d.ts +1 -6
  75. package/dist/execution/types.js +0 -5
  76. package/dist/gates/contract.d.ts +3 -2
  77. package/dist/gates/contract.js +1 -1
  78. package/dist/gates/egress-credentials.js +4 -3
  79. package/dist/gates/egress.d.ts +9 -9
  80. package/dist/gates/egress.js +19 -19
  81. package/dist/gates/fixture-model.js +13 -2
  82. package/dist/gates/handler.d.ts +1 -3
  83. package/dist/gates/handler.js +4 -3
  84. package/dist/gates/http-client.d.ts +4 -3
  85. package/dist/gates/http-client.js +5 -7
  86. package/dist/gates/http-tool.d.ts +24 -4
  87. package/dist/gates/http-tool.js +53 -17
  88. package/dist/gates/in-process.d.ts +2 -1
  89. package/dist/gates/in-process.js +17 -9
  90. package/dist/gates/inflight.d.ts +2 -2
  91. package/dist/gates/inflight.js +3 -2
  92. package/dist/gates/journal.js +5 -7
  93. package/dist/gates/mcp-handler.d.ts +4 -3
  94. package/dist/gates/mcp-handler.js +15 -5
  95. package/dist/gates/model-gate.d.ts +11 -2
  96. package/dist/gates/policy.d.ts +28 -5
  97. package/dist/gates/policy.js +60 -17
  98. package/dist/gates/provider-gate.d.ts +22 -0
  99. package/dist/gates/provider-gate.js +30 -0
  100. package/dist/gates/tool-calls.d.ts +1 -3
  101. package/dist/gates/tool-calls.js +2 -3
  102. package/dist/gates/tool-client.d.ts +1 -1
  103. package/dist/gates/tool-client.js +5 -6
  104. package/dist/gates/tool-contract.d.ts +8 -5
  105. package/dist/gates/tool-contract.js +1 -1
  106. package/dist/gates/tool-gate.d.ts +18 -7
  107. package/dist/gates/tool-gate.js +49 -7
  108. package/dist/harness/calls.d.ts +27 -25
  109. package/dist/harness/calls.js +40 -46
  110. package/dist/harness/executors.d.ts +10 -3
  111. package/dist/harness/executors.js +53 -23
  112. package/dist/harness/main.js +2 -2
  113. package/dist/harness/pod.d.ts +0 -2
  114. package/dist/harness/pod.js +7 -6
  115. package/dist/harness/run-tokens.d.ts +4 -1
  116. package/dist/harness/run-tokens.js +6 -2
  117. package/dist/harness/service.d.ts +17 -14
  118. package/dist/harness/service.js +21 -35
  119. package/dist/harness/setup.d.ts +0 -2
  120. package/dist/harness/setup.js +4 -9
  121. package/dist/harness/ws-client.d.ts +2 -2
  122. package/dist/harness/ws-client.js +7 -5
  123. package/dist/harness/ws-port.d.ts +3 -4
  124. package/dist/harness/ws-port.js +3 -4
  125. package/dist/harness-api/artifacts.d.ts +20 -0
  126. package/dist/harness-api/artifacts.js +478 -0
  127. package/dist/harness-api/in-process.d.ts +2 -2
  128. package/dist/harness-api/in-process.js +18 -16
  129. package/dist/harness-api/record.d.ts +10 -9
  130. package/dist/harness-api/record.js +102 -157
  131. package/dist/harness-api/renew.d.ts +1 -1
  132. package/dist/harness-api/renew.js +2 -2
  133. package/dist/harness-api/server.d.ts +1 -16
  134. package/dist/harness-api/server.js +82 -73
  135. package/dist/harness-api/start.d.ts +20 -2
  136. package/dist/harness-api/start.js +57 -18
  137. package/dist/harness-api/tool-journal.d.ts +15 -10
  138. package/dist/harness-api/tool-journal.js +26 -24
  139. package/dist/harness-api/workspace.d.ts +0 -4
  140. package/dist/harness-api/workspace.js +2 -45
  141. package/dist/harness-api/ws-server.js +10 -10
  142. package/dist/host/create-host.js +2 -3
  143. package/dist/host/execution.js +2 -3
  144. package/dist/host/gates.d.ts +2 -9
  145. package/dist/host/gates.js +15 -12
  146. package/dist/host/http.d.ts +0 -2
  147. package/dist/host/http.js +0 -27
  148. package/dist/host/main.js +10 -3
  149. package/dist/host/operate.js +12 -3
  150. package/dist/host/stack-config.d.ts +11 -0
  151. package/dist/host/stack-config.js +21 -1
  152. package/dist/index.d.ts +0 -1
  153. package/dist/index.js +0 -1
  154. package/dist/infra/index.js +2 -1
  155. package/dist/infra/readiness.d.ts +0 -2
  156. package/dist/infra/readiness.js +4 -3
  157. package/dist/keys/client.d.ts +1 -0
  158. package/dist/keys/client.js +2 -3
  159. package/dist/keys/contract.d.ts +1 -3
  160. package/dist/keys/contract.js +1 -3
  161. package/dist/keys/egress-ca.d.ts +0 -2
  162. package/dist/keys/egress-ca.js +2 -3
  163. package/dist/keys/keys.js +6 -1
  164. package/dist/keys/x509.d.ts +8 -4
  165. package/dist/keys/x509.js +14 -5
  166. package/dist/management-openapi.json +1961 -994
  167. package/dist/mcp/connect.d.ts +35 -26
  168. package/dist/mcp/connect.js +112 -141
  169. package/dist/mcp/pool.d.ts +27 -22
  170. package/dist/mcp/pool.js +34 -48
  171. package/dist/mcp/preview.d.ts +13 -6
  172. package/dist/mcp/preview.js +37 -20
  173. package/dist/mcp/snapshot.d.ts +35 -86
  174. package/dist/mcp/snapshot.js +93 -135
  175. package/dist/model/auth-store.js +5 -3
  176. package/dist/model/capabilities.d.ts +1 -1
  177. package/dist/model/catalog.d.ts +9 -36
  178. package/dist/model/catalog.js +6 -33
  179. package/dist/model/descriptor.d.ts +51 -0
  180. package/dist/model/descriptor.js +83 -0
  181. package/dist/model/models.d.ts +0 -3
  182. package/dist/model/models.js +3 -5
  183. package/dist/model/native-blocks.js +1 -1
  184. package/dist/model/pi-model.d.ts +16 -5
  185. package/dist/model/pi-model.js +86 -105
  186. package/dist/openapi.json +866 -1218
  187. package/dist/reads/cursor.js +3 -1
  188. package/dist/record/append.d.ts +34 -2
  189. package/dist/record/append.js +50 -1
  190. package/dist/record/environment.d.ts +2 -0
  191. package/dist/record/environment.js +2 -0
  192. package/dist/record/index.d.ts +1 -1
  193. package/dist/record/index.js +1 -1
  194. package/dist/redact.d.ts +1 -1
  195. package/dist/redact.js +3 -2
  196. package/dist/sandbox/egress-token.d.ts +3 -3
  197. package/dist/sandbox/egress-token.js +3 -3
  198. package/dist/sandbox/join.js +3 -2
  199. package/dist/sandbox/manager.d.ts +41 -41
  200. package/dist/sandbox/manager.js +112 -44
  201. package/dist/sandbox/placement.d.ts +1 -1
  202. package/dist/sandbox/placement.js +5 -8
  203. package/dist/sandbox/pods/client.d.ts +1 -10
  204. package/dist/sandbox/pods/client.js +8 -4
  205. package/dist/sandbox/pods/lifecycle.d.ts +19 -11
  206. package/dist/sandbox/pods/lifecycle.js +45 -23
  207. package/dist/sandbox/pods/network-gate.d.ts +4 -5
  208. package/dist/sandbox/pods/network-gate.js +7 -7
  209. package/dist/sandbox/pods/reconcile.js +4 -1
  210. package/dist/sandbox/pods/spec.js +8 -5
  211. package/dist/sandbox/policy.d.ts +7 -1
  212. package/dist/sandbox/policy.js +10 -3
  213. package/dist/sandbox/resolve.d.ts +8 -3
  214. package/dist/sandbox/resolve.js +12 -2
  215. package/dist/sandbox/setup.d.ts +3 -1
  216. package/dist/sandbox/setup.js +34 -11
  217. package/dist/sandbox/share.d.ts +5 -14
  218. package/dist/sandbox/share.js +5 -34
  219. package/dist/sandbox/skills.d.ts +7 -13
  220. package/dist/sandbox/skills.js +16 -31
  221. package/dist/sandbox/tenant-config.d.ts +2 -2
  222. package/dist/sandbox/tenant-config.js +4 -3
  223. package/dist/sandbox/tools.d.ts +7 -1
  224. package/dist/sandbox/tools.js +26 -26
  225. package/dist/sandbox/types.d.ts +10 -3
  226. package/dist/sandbox/types.js +9 -0
  227. package/dist/store/postgres/connect.d.ts +6 -5
  228. package/dist/store/postgres/connect.js +14 -11
  229. package/dist/store/postgres/control.js +13 -13
  230. package/dist/store/postgres/drizzle/0028_artifact_write_keys.sql +2 -0
  231. package/dist/store/postgres/drizzle/0029_protocol_15.sql +11 -0
  232. package/dist/store/postgres/drizzle/0030_protocol_15_runtime_block.sql +11 -0
  233. package/dist/store/postgres/drizzle/0031_protocol_15_mcp_snapshot.sql +8 -0
  234. package/dist/store/postgres/drizzle/meta/_journal.json +28 -0
  235. package/dist/store/postgres/migrate.js +1 -1
  236. package/dist/store/postgres/reads.js +10 -2
  237. package/dist/store/postgres/schema.d.ts +19 -0
  238. package/dist/store/postgres/schema.js +7 -0
  239. package/dist/store/postgres/store.js +55 -26
  240. package/dist/store/types.d.ts +17 -7
  241. package/dist/streams/relay/core.d.ts +3 -3
  242. package/dist/streams/relay/core.js +9 -10
  243. package/dist/tenant/advance.js +21 -31
  244. package/dist/tenant/commands.js +9 -16
  245. package/dist/tenant/context.d.ts +14 -17
  246. package/dist/tenant/definition-files.d.ts +25 -4
  247. package/dist/tenant/definition-files.js +85 -47
  248. package/dist/tenant/effects.js +9 -36
  249. package/dist/tenant/environment-manifests.js +9 -1
  250. package/dist/tenant/environments.d.ts +0 -2
  251. package/dist/tenant/environments.js +54 -30
  252. package/dist/tenant/ephemeral.d.ts +1 -1
  253. package/dist/tenant/ephemeral.js +2 -1
  254. package/dist/tenant/history.d.ts +1 -1
  255. package/dist/tenant/history.js +1 -1
  256. package/dist/tenant/host-token.d.ts +3 -3
  257. package/dist/tenant/host-token.js +12 -11
  258. package/dist/tenant/http.d.ts +5 -8
  259. package/dist/tenant/http.js +9 -0
  260. package/dist/tenant/identity-file.d.ts +24 -1
  261. package/dist/tenant/identity-file.js +35 -7
  262. package/dist/tenant/issuers.d.ts +5 -5
  263. package/dist/tenant/issuers.js +31 -23
  264. package/dist/tenant/jwt.d.ts +8 -2
  265. package/dist/tenant/jwt.js +10 -2
  266. package/dist/tenant/limits.d.ts +90 -0
  267. package/dist/tenant/limits.js +175 -0
  268. package/dist/tenant/module.d.ts +4 -1
  269. package/dist/tenant/module.js +9 -8
  270. package/dist/tenant/outbound.d.ts +17 -19
  271. package/dist/tenant/outbound.js +18 -21
  272. package/dist/tenant/run-grants.js +3 -2
  273. package/dist/tenant/run-token.d.ts +0 -4
  274. package/dist/tenant/run-token.js +6 -11
  275. package/dist/tenant/runtime-limits.d.ts +24 -0
  276. package/dist/tenant/runtime-limits.js +27 -0
  277. package/dist/tenant/runtime.js +30 -43
  278. package/dist/tenant/session-streams.js +7 -6
  279. package/dist/tenant/session.d.ts +1 -1
  280. package/dist/tenant/session.js +1 -1
  281. package/dist/tenant/sessions.js +32 -29
  282. package/dist/tenant/signing-keys.d.ts +1 -1
  283. package/dist/tenant/signing-keys.js +5 -6
  284. package/dist/tenant/status.js +4 -3
  285. package/dist/tenant/streams.js +18 -20
  286. package/dist/tenant/sweep.d.ts +1 -21
  287. package/dist/tenant/sweep.js +39 -48
  288. package/dist/tenant/transcript.d.ts +70 -23
  289. package/dist/tenant/transcript.js +28 -22
  290. package/dist/tenant/types.d.ts +11 -16
  291. package/dist/tenant/worker.d.ts +2 -10
  292. package/dist/tenant/worker.js +5 -14
  293. package/dist/traces/ids.js +5 -1
  294. package/dist/traces/map.d.ts +9 -6
  295. package/dist/traces/map.js +9 -11
  296. package/dist/traces/otlp.d.ts +3 -3
  297. package/dist/traces/otlp.js +5 -3
  298. package/dist/traces/projector.d.ts +9 -4
  299. package/dist/traces/projector.js +13 -7
  300. package/dist/traces/read.js +6 -1
  301. package/dist/tuning.d.ts +383 -0
  302. package/dist/tuning.js +658 -0
  303. package/dist/vault/headers.js +4 -2
  304. package/dist/version.d.ts +1 -1
  305. package/dist/version.js +1 -1
  306. package/package.json +3 -3
  307. package/dist/artifacts/export.d.ts +0 -8
  308. package/dist/artifacts/export.js +0 -204
  309. package/dist/artifacts/media-types.d.ts +0 -30
  310. package/dist/artifacts/media-types.js +0 -137
  311. package/dist/artifacts/workspace.d.ts +0 -60
  312. package/dist/artifacts/workspace.js +0 -45
  313. package/dist/media.d.ts +0 -10
  314. package/dist/media.js +0 -58
  315. package/dist/sandbox/runtime-tools.d.ts +0 -9
  316. package/dist/sandbox/runtime-tools.js +0 -16
  317. package/dist/sandbox/session-sandbox.d.ts +0 -16
  318. package/dist/sandbox/session-sandbox.js +0 -77
  319. package/dist/tenant/artifact-tool.d.ts +0 -13
  320. package/dist/tenant/artifact-tool.js +0 -243
  321. package/dist/tenant/skill-tool.d.ts +0 -20
  322. package/dist/tenant/skill-tool.js +0 -67
  323. package/dist/tenant/tool-results.d.ts +0 -57
  324. package/dist/tenant/tool-results.js +0 -298
  325. package/dist/tenant/tool-search.d.ts +0 -39
  326. package/dist/tenant/tool-search.js +0 -103
@@ -137,7 +137,7 @@ export interface DurableExecution {
137
137
  start(handlers: WorkerHandlers): Promise<void>;
138
138
  /**
139
139
  * Stops delivering, aborts running advances' signals and waits for them, up to the
140
- * implementation's stop grace (`DEFAULT_STOP_GRACE_MS`). Handlers still running then are
140
+ * implementation's stop grace (Host tuning `execution.stopGraceMs`). Handlers still running then are
141
141
  * abandoned: their sessions' leases lapse and the next advance takes over (§11.4).
142
142
  */
143
143
  stop(): Promise<void>;
@@ -178,11 +178,6 @@ export declare function parseSessionKey(key: string): {
178
178
  tenantId: string;
179
179
  sessionId: string;
180
180
  };
181
- /**
182
- * Default time `DurableExecution.stop` waits for running handlers after aborting them: the
183
- * advance grace period (`DEFAULT_ADVANCE_GRACE_MS` in `tenant/worker.ts`).
184
- */
185
- export declare const DEFAULT_STOP_GRACE_MS = 30000;
186
181
  /**
187
182
  * Waits until `inflight` is empty (it shrinks as its promises settle and may grow meanwhile),
188
183
  * for at most `graceMs`. Resolves to how many were still running when the grace ran out.
@@ -62,11 +62,6 @@ export function parseSessionKey(key) {
62
62
  throw new Error(`Invalid session key: ${key}`);
63
63
  return { tenantId: key.slice(0, at), sessionId: key.slice(at + 1) };
64
64
  }
65
- /**
66
- * Default time `DurableExecution.stop` waits for running handlers after aborting them: the
67
- * advance grace period (`DEFAULT_ADVANCE_GRACE_MS` in `tenant/worker.ts`).
68
- */
69
- export const DEFAULT_STOP_GRACE_MS = 30_000;
70
65
  /**
71
66
  * Waits until `inflight` is empty (it shrinks as its promises settle and may grow meanwhile),
72
67
  * for at most `graceMs`. Resolves to how many were still running when the grace ran out.
@@ -6,7 +6,8 @@
6
6
  * - Headers: `Authorization: Bearer <run token>` (F5, `tenant/run-token.ts`), `Idempotency-Key:
7
7
  * <effect id>`, and optionally `Nylorun-Tenant: <tenant id>`, which must then be the token's
8
8
  * Tenant. Core's credential (`NYLORUN_GATES_TOKEN`) is refused: only a run calls the model.
9
- * - Body: `ModelCallBody`, at most `MAX_MODEL_CALL_BYTES`. It names no session, turn or agent:
9
+ * - Body: `ModelCallBody`, at most the Tenant's Runtime limit `modelCallBytes` (`PUT
10
+ * /v1/tenant/limits`, default 32 MiB). It names no session, turn or agent:
10
11
  * the gate takes them from the token, and refuses a body that names them.
11
12
  * - `200 {outcome}` once the call has finished, whether the outcome is a candidate or a
12
13
  * failure; nothing is sent while it runs. `401 gate_unauthorized` for a missing, malformed,
@@ -23,7 +24,7 @@
23
24
  * need not be live: a user cancel makes it stale, and still stops its call.
24
25
  */
25
26
  import type { ModelGateOutcome } from "./model-gate.js";
26
- export { MAX_MODEL_CALL_BYTES, MODEL_CALLS_PATH, ModelCallBodySchema, type GateErrorBody, type ModelCallBody, } from "@nylorun/core/harness-api";
27
+ export { MODEL_CALLS_PATH, ModelCallBodySchema, type GateErrorBody, type ModelCallBody, } from "@nylorun/core/harness-api";
27
28
  /** Header naming the Tenant a call is for: optional, and checked against the gate's Tenant. */
28
29
  export declare const TENANT_HEADER = "nylorun-tenant";
29
30
  export interface ModelCallResponse {
@@ -1,3 +1,3 @@
1
- export { MAX_MODEL_CALL_BYTES, MODEL_CALLS_PATH, ModelCallBodySchema, } from "@nylorun/core/harness-api";
1
+ export { MODEL_CALLS_PATH, ModelCallBodySchema, } from "@nylorun/core/harness-api";
2
2
  /** Header naming the Tenant a call is for: optional, and checked against the gate's Tenant. */
3
3
  export const TENANT_HEADER = "nylorun-tenant";
@@ -6,7 +6,7 @@
6
6
  * (keys holds its key; the pod trusts its certificate, `harness/pod.ts`), and reads HTTP/1.1
7
7
  * requests. For each request it reads the vault (one Postgres query, no cache, so a rotation
8
8
  * applies to the next request), sets the credential's header (replacing any of that name, such
9
- * as the `nylorun-managed` sentinel the CLI sent), and forwards it over TLS to the address the
9
+ * as the `nylorun_managed` sentinel the CLI sent), and forwards it over TLS to the address the
10
10
  * gate already checked, verifying the host's certificate by name against the public roots.
11
11
  *
12
12
  * Nothing here knows a tool: the header name and its format are the credential's. A release the
@@ -18,6 +18,7 @@
18
18
  import { createServer } from "node:http";
19
19
  import { Agent, request } from "node:https";
20
20
  import { createSecureContext, TLSSocket } from "node:tls";
21
+ import { hostTuning } from "../tuning.js";
21
22
  /** The answer to a CONNECT the gate serves; a tunnel's byte counts leave it out. */
22
23
  export const CONNECT_ESTABLISHED = "HTTP/1.1 200 Connection Established\r\n\r\n";
23
24
  /** Headers that describe one hop and are never forwarded. */
@@ -62,7 +63,7 @@ export function credentialTerminator(options) {
62
63
  });
63
64
  });
64
65
  http.keepAliveTimeout = options.idleMs;
65
- http.headersTimeout = 60_000;
66
+ http.headersTimeout = hostTuning().egress.credentialsHeadersTimeoutMs;
66
67
  // Uploads may be long; the client socket's idle timeout still applies.
67
68
  http.requestTimeout = 0;
68
69
  http.on("upgrade", (req, socket) => {
@@ -131,7 +132,7 @@ export function credentialTerminator(options) {
131
132
  };
132
133
  const agent = new Agent({
133
134
  keepAlive: true,
134
- maxSockets: 8,
135
+ maxSockets: hostTuning().egress.credentialsMaxSockets,
135
136
  lookup,
136
137
  ...(credentials.upstreamCa ? { ca: credentials.upstreamCa } : {}),
137
138
  });
@@ -18,7 +18,11 @@ export interface EgressSandboxes {
18
18
  }
19
19
  /** One connection's record (R7.3, D67): `environment.egress`'s payload. */
20
20
  export type EgressConnection = EnvironmentEventPayload<"environment.egress">;
21
- /** How many running turns one connection names, at most. */
21
+ /**
22
+ * How many running turns one connection names, at most: fixed by the `environment.egress` event
23
+ * contract (`runningTurns` holds at most 16 in `/core/contracts`), which every reader
24
+ * validates against, so not a setting here.
25
+ */
22
26
  export declare const EGRESS_RUNNING_TURNS_MAX = 16;
23
27
  /** Where egress-gate records connections (R7.3, D67). */
24
28
  export interface EgressRecord {
@@ -29,14 +33,6 @@ export interface EgressRecord {
29
33
  }
30
34
  /** Ports a tunnel may open. */
31
35
  export declare const EGRESS_PORTS: readonly number[];
32
- /** Tunnels one sandbox may hold open at once. */
33
- export declare const EGRESS_MAX_PER_SANDBOX = 64;
34
- /** A tunnel with no traffic either way for this long is closed. */
35
- export declare const EGRESS_IDLE_MS: number;
36
- /** How long a sandbox's epoch and allowlist are reused before they are read again. */
37
- export declare const EGRESS_CACHE_MS = 5000;
38
- /** How long the gate waits for the upstream connection. */
39
- export declare const EGRESS_CONNECT_TIMEOUT_MS = 10000;
40
36
  export interface StartEgressGateOptions {
41
37
  readonly listen: {
42
38
  readonly host: string;
@@ -46,9 +42,13 @@ export interface StartEgressGateOptions {
46
42
  /** Verifies a presented egress token (`verifyEgressToken` over the Tenant's keys). */
47
43
  verify(raw: string): Promise<EgressTokenVerdict>;
48
44
  readonly sandboxes: EgressSandboxes;
45
+ /** A tunnel with no traffic either way for this long is closed. Default `egress.idleMs`. */
49
46
  readonly idleMs?: number;
47
+ /** Tunnels one sandbox may hold open at once. Default `egress.maxTunnelsPerSandbox`. */
50
48
  readonly maxPerSandbox?: number;
49
+ /** How long a sandbox's epoch and allowlist are reused. Default `egress.cacheMs`. */
51
50
  readonly cacheMs?: number;
51
+ /** How long the gate waits for the upstream connection. Default `egress.connectTimeoutMs`. */
52
52
  readonly connectTimeoutMs?: number;
53
53
  /** Tests replace name resolution. */
54
54
  readonly lookup?: (host: string) => Promise<readonly {
@@ -27,8 +27,9 @@
27
27
  * Every connection to a named host on a live token is recorded once (R7.3, D67), when it closes
28
28
  * or at once when the gate refuses it, as `environment.egress` on the Environment's own stream:
29
29
  * the connection is the Environment's, since its token names the pod and turns run in parallel
30
- * (D66). `runningTurns` lists the turns active on the Environment as it opened (read as the name
31
- * resolves), as context and never as an owner. Host, port, outcome, bytes, duration and, for a
30
+ * (D66). `runningTurns` lists the turns active on the Environment as it opened, as context and
31
+ * never as an owner: one read, started as the name resolves and never waited for, so a turn that
32
+ * moves while it is in flight may show either way. Host, port, outcome, bytes, duration and, for a
32
33
  * credential host, the request count and credential ids; never a header value, a path or a body. A refusal
33
34
  * before that (no token, a stale one, no `host:port`) stays a log line, and a client that hangs up
34
35
  * before the gate answers leaves nothing. A write never holds the tunnel up, and a failed one is
@@ -40,19 +41,16 @@ import { BlockList, connect, isIP } from "node:net";
40
41
  import { isSandboxHostPattern } from "@nylorun/core/define";
41
42
  import { isPrivateAddress } from "../tenant/outbound.js";
42
43
  import { bindListener } from "../host/http.js";
44
+ import { hostTuning } from "../tuning.js";
43
45
  import { CONNECT_ESTABLISHED, credentialTerminator, } from "./egress-credentials.js";
44
- /** How many running turns one connection names, at most. */
46
+ /**
47
+ * How many running turns one connection names, at most: fixed by the `environment.egress` event
48
+ * contract (`runningTurns` holds at most 16 in `/core/contracts`), which every reader
49
+ * validates against, so not a setting here.
50
+ */
45
51
  export const EGRESS_RUNNING_TURNS_MAX = 16;
46
52
  /** Ports a tunnel may open. */
47
53
  export const EGRESS_PORTS = [443, 80];
48
- /** Tunnels one sandbox may hold open at once. */
49
- export const EGRESS_MAX_PER_SANDBOX = 64;
50
- /** A tunnel with no traffic either way for this long is closed. */
51
- export const EGRESS_IDLE_MS = 5 * 60_000;
52
- /** How long a sandbox's epoch and allowlist are reused before they are read again. */
53
- export const EGRESS_CACHE_MS = 5_000;
54
- /** How long the gate waits for the upstream connection. */
55
- export const EGRESS_CONNECT_TIMEOUT_MS = 10_000;
56
54
  /** Ranges beyond `isPrivateAddress`'s that a tunnel never reaches. */
57
55
  const RESERVED = new BlockList();
58
56
  for (const [network, prefix] of [
@@ -193,10 +191,11 @@ function connectionRecord(sink, logger, client, at) {
193
191
  }
194
192
  export async function startEgressGate(options) {
195
193
  const { logger, sandboxes } = options;
196
- const idleMs = options.idleMs ?? EGRESS_IDLE_MS;
197
- const maxPerSandbox = options.maxPerSandbox ?? EGRESS_MAX_PER_SANDBOX;
198
- const cacheMs = options.cacheMs ?? EGRESS_CACHE_MS;
199
- const connectTimeoutMs = options.connectTimeoutMs ?? EGRESS_CONNECT_TIMEOUT_MS;
194
+ const tuning = hostTuning().egress;
195
+ const idleMs = options.idleMs ?? tuning.idleMs;
196
+ const maxPerSandbox = options.maxPerSandbox ?? tuning.maxTunnelsPerSandbox;
197
+ const cacheMs = options.cacheMs ?? tuning.cacheMs;
198
+ const connectTimeoutMs = options.connectTimeoutMs ?? tuning.connectTimeoutMs;
200
199
  const blocked = options.blocked ?? isEgressBlocked;
201
200
  const lookup = options.lookup ?? ((host) => dnsLookup(host, { all: true, verbatim: true }));
202
201
  const dial = options.dial ?? ((address, port) => connect({ host: address, port }));
@@ -208,7 +207,7 @@ export async function startEgressGate(options) {
208
207
  return cached.value;
209
208
  const value = await sandboxes.live(sandboxId);
210
209
  cache.set(sandboxId, { at: Date.now(), value });
211
- if (cache.size > 4096)
210
+ if (cache.size > tuning.cacheEntries)
212
211
  cache.delete(cache.keys().next().value);
213
212
  return value;
214
213
  }
@@ -260,7 +259,8 @@ export async function startEgressGate(options) {
260
259
  return refuse(403, "not_a_host_name", { sandboxId }, `${host} is not a host name; IP literals are refused`);
261
260
  if (!egressAllows(host, sandbox.allow))
262
261
  return refuse(403, "host_not_allowed", { sandboxId }, `${host} is not in this sandbox's network.allow`);
263
- // The turns running on the Environment as the connection opens, read while the name resolves.
262
+ // The turns running on the Environment as the connection opens: the read starts as the
263
+ // name resolves, and the 200 does not wait for it.
264
264
  record.opened();
265
265
  let mine = open.get(sandboxId);
266
266
  if (!mine)
@@ -353,8 +353,8 @@ export async function startEgressGate(options) {
353
353
  res.writeHead(405, { allow: "CONNECT", "content-type": "text/plain; charset=utf-8", connection: "close" });
354
354
  res.end("egress-gate: only CONNECT is served; set HTTPS_PROXY and HTTP_PROXY to this address\n");
355
355
  });
356
- server.headersTimeout = 10_000;
357
- server.requestTimeout = 15_000;
356
+ server.headersTimeout = tuning.headersTimeoutMs;
357
+ server.requestTimeout = tuning.requestTimeoutMs;
358
358
  server.on("connect", (req, client, head) => {
359
359
  // A client socket: idle from the request on, through the tunnel's life.
360
360
  client.on("error", () => { });
@@ -1,9 +1,13 @@
1
+ import { FILES_MESSAGE_HEADER } from "@nylorun/harness";
1
2
  export const FIXTURE_PROVIDER = "fixture";
2
3
  const MARKER = /^fixture:(\w+)(?:\s+([\s\S]*))?$/;
3
4
  /** The fixture model's answer to `call`. */
4
5
  export async function fixtureAnswer(call, signal) {
5
- const last = call.prompt.at(-1);
6
- const users = call.prompt.filter((item) => item.kind === "message" && item.role === "user");
6
+ // Our harness ends a turn that has files with a user message listing them; the script is in
7
+ // the message before it, and a tool result before it is still the last thing that happened.
8
+ const prompt = call.prompt.filter((item) => !isFilesMessage(item));
9
+ const last = prompt.at(-1);
10
+ const users = prompt.filter((item) => item.kind === "message" && item.role === "user");
7
11
  const marker = MARKER.exec(textOf(users.at(-1)?.content ?? []).trim());
8
12
  if (marker)
9
13
  return scripted(call, marker[1], marker[2]?.trim() ?? "", last, signal);
@@ -74,6 +78,13 @@ function candidate(call, output) {
74
78
  }
75
79
  /** About four characters a token, at least one. */
76
80
  const tokens = (text) => Math.max(1, Math.ceil(text.length / 4));
81
+ /** The user message our harness adds for the turn's files (`FILES_MESSAGE_HEADER`). */
82
+ function isFilesMessage(item) {
83
+ if (item.kind !== "message" || item.role !== "user")
84
+ return false;
85
+ const first = item.content[0];
86
+ return first?.type === "text" && first.text === FILES_MESSAGE_HEADER;
87
+ }
77
88
  function textOf(content, json = false) {
78
89
  return content
79
90
  .map((part) => (part.type === "text" ? (part.text ?? "") : json ? JSON.stringify(part) : ""))
@@ -1,12 +1,10 @@
1
1
  import type { Logger } from "../tenant/types.js";
2
2
  import type { BlobStore } from "../blob/index.js";
3
- import type { ModelCallSettings, ModelGate, ModelGateRequest } from "./model-gate.js";
3
+ import type { ModelGate, ModelGateRequest } from "./model-gate.js";
4
4
  import { type TenantVaults } from "./tenant-vaults.js";
5
5
  export interface ModelCallHandlerOptions {
6
6
  readonly vaults: TenantVaults;
7
7
  readonly logger: Logger;
8
- /** Retries and timeouts; `piModel`'s defaults when absent. */
9
- readonly settings?: ModelCallSettings;
10
8
  /** The Object store, for the files a prompt names (protocol 6). */
11
9
  readonly blobs?: BlobStore;
12
10
  }
@@ -6,11 +6,11 @@
6
6
  * the Tenant's ledger. Logs one line per call, never the prompt, the output or a credential.
7
7
  */
8
8
  import { classifyThrown } from "../model/classify.js";
9
- import { callFiles, inProcessModelGate, serve } from "./in-process.js";
9
+ import { callFiles, inProcessModelGate, modelCallSettings, serve } from "./in-process.js";
10
10
  import { createMeter } from "./meter.js";
11
11
  import { GateRefusal } from "./tenant-vaults.js";
12
12
  export function createModelCallHandler(options) {
13
- const { vaults, logger, settings, blobs } = options;
13
+ const { vaults, logger, blobs } = options;
14
14
  const meter = createMeter({ logger });
15
15
  return {
16
16
  async call(named, signal) {
@@ -25,7 +25,8 @@ export function createModelCallHandler(options) {
25
25
  root: vault.root,
26
26
  readHostModel: () => vault.readHostModel(),
27
27
  writeHostCredential: (credential) => vault.writeHostCredential(credential),
28
- ...(settings ? { settings } : {}),
28
+ // The Tenant's Runtime limits `model*`, read for this call.
29
+ settings: await modelCallSettings(vault.store),
29
30
  ...(blobs ? { files: callFiles(vault.store, blobs) } : {}),
30
31
  });
31
32
  outcome = await meter.call(vault.store, call, () => serve(vault.store, gate, call, signal));
@@ -1,13 +1,14 @@
1
1
  import type { ModelGate } from "./model-gate.js";
2
2
  import type { RunTokens } from "../tenant/run-grants.js";
3
- /** Above the gate's 600 s provider request timeout. */
4
- export declare const GATE_CLIENT_TIMEOUT_MS = 630000;
5
3
  export interface HttpModelGateOptions {
6
4
  /** The gates service, e.g. `http://gateway:4100` (`NYLORUN_GATES_URL`). */
7
5
  readonly url: string;
8
6
  /** The run token of each session an advance of this process owns: a call's credential. */
9
7
  readonly runTokens: RunTokens;
10
- /** How long the connection may stay silent. Default `GATE_CLIENT_TIMEOUT_MS`. */
8
+ /**
9
+ * How long the connection may stay silent. Default `gates.clientTimeoutMs` (Host tuning, 630 s),
10
+ * above the gate's 600 s provider request timeout.
11
+ */
11
12
  readonly timeoutMs?: number;
12
13
  }
13
14
  export declare function httpModelGate(options: HttpModelGateOptions): ModelGate;
@@ -19,14 +19,11 @@ import { request as httpRequest } from "node:http";
19
19
  import { request as httpsRequest } from "node:https";
20
20
  import { failure } from "../model/classify.js";
21
21
  import { MODEL_CALLS_PATH, TENANT_HEADER, } from "./contract.js";
22
- /** How long a cancel may take; the call it stops ends with the provider timeout anyway. */
23
- const CANCEL_TIMEOUT_MS = 2_000;
24
- /** Above the gate's 600 s provider request timeout. */
25
- export const GATE_CLIENT_TIMEOUT_MS = 630_000;
22
+ import { hostTuning } from "../tuning.js";
26
23
  export function httpModelGate(options) {
27
24
  const endpoint = new URL(MODEL_CALLS_PATH, options.url);
28
25
  const send = endpoint.protocol === "https:" ? httpsRequest : httpRequest;
29
- const timeoutMs = options.timeoutMs ?? GATE_CLIENT_TIMEOUT_MS;
26
+ const timeoutMs = options.timeoutMs ?? hostTuning().gates.clientTimeoutMs;
30
27
  const where = new URL(options.url).origin;
31
28
  return {
32
29
  recovers: true,
@@ -44,7 +41,8 @@ export function httpModelGate(options) {
44
41
  [TENANT_HEADER]: request.tenantId,
45
42
  "content-length": 0,
46
43
  },
47
- timeout: CANCEL_TIMEOUT_MS,
44
+ // A cancel is short; the call it stops ends with the provider timeout anyway.
45
+ timeout: hostTuning().gates.shortTimeoutMs,
48
46
  }, (response) => {
49
47
  response.resume();
50
48
  response.on("end", resolve);
@@ -107,7 +105,7 @@ export function httpModelGate(options) {
107
105
  responded = true;
108
106
  readBody(response).then((text) => settle(answer(response.statusCode ?? 0, text)), (error) => lost(error));
109
107
  });
110
- outgoing.on("socket", (socket) => socket.setKeepAlive(true, 30_000));
108
+ outgoing.on("socket", (socket) => socket.setKeepAlive(true, hostTuning().gates.keepAliveMs));
111
109
  outgoing.on("finish", () => {
112
110
  sent = true;
113
111
  });
@@ -1,12 +1,11 @@
1
1
  import { type HttpToolTarget, type JsonObject, type ToolManifest } from "@nylorun/core/define";
2
2
  import type { HostEffect } from "@nylorun/harness/run";
3
+ import type { RuntimeLimits } from "@nylorun/core/contracts";
3
4
  import { type OutboundPolicy } from "../tenant/outbound.js";
4
5
  import type { Logger } from "../tenant/types.js";
5
6
  import type { AuthorizeResult } from "../vault/service.js";
6
7
  import type { McpCredentialRequest } from "../vault/sources.js";
7
8
  import type { TenantVaults } from "./tenant-vaults.js";
8
- /** How much of a failed answer's body the model sees. */
9
- export declare const HTTP_ERROR_BODY_CHARS = 2000;
10
9
  /** What an HTTP request came to, as a tool outcome. */
11
10
  export type HttpOutcome = {
12
11
  readonly kind: "completed";
@@ -49,17 +48,29 @@ export interface HttpToolCall {
49
48
  */
50
49
  readonly traceparent?: string;
51
50
  }
52
- /** What `runHttpTool` reads of the Tenant: the session's pinned manifest and its credentials. */
51
+ /**
52
+ * What `runHttpTool` reads of the Tenant: the session's pinned manifest, its credentials, and its
53
+ * Runtime limits (`toolAnswerBytes`, `httpToolTimeoutMs`, `errorExcerptChars`), read for each call.
54
+ */
53
55
  export interface HttpToolTenant {
54
56
  session(sessionId: string): Promise<{
55
57
  readonly manifest: unknown;
56
58
  } | undefined>;
57
59
  authorize(sessionId: string, request: McpCredentialRequest): Promise<AuthorizeResult>;
60
+ limits(): Promise<HttpToolLimits>;
58
61
  }
62
+ /** The Runtime limits an HTTP tool call keeps to. */
63
+ export type HttpToolLimits = Pick<RuntimeLimits, "toolAnswerBytes" | "httpToolTimeoutMs" | "errorExcerptChars">;
59
64
  /** The HTTP tool `toolName` of the agent `agentId` (the root when absent). */
60
65
  export declare function declaredHttpTool(manifest: unknown, agentId: string | undefined, toolName: string | undefined): (ToolManifest & {
61
66
  readonly http: HttpToolTarget;
62
67
  }) | undefined;
68
+ /**
69
+ * Why `manifest` cannot be deployed: each HTTP tool of it, or of an agent it uses as a tool, whose
70
+ * `timeoutMs` is longer than the Tenant's Runtime limit `httpToolTimeoutMs`. A call also waits at
71
+ * most the limit in force then (`callHttpTarget`).
72
+ */
73
+ export declare function httpToolTimeoutIssues(manifest: unknown, limitMs: number): string[];
63
74
  /** The HTTP stage or HTTP verifier at stage key `stage` of a flow session's `manifest`. */
64
75
  export declare function declaredFlowHttp(manifest: unknown, stage: string | undefined): import("@nylorun/core/define").FlowHttpTarget | undefined;
65
76
  /**
@@ -67,7 +78,10 @@ export declare function declaredFlowHttp(manifest: unknown, stage: string | unde
67
78
  * flow's HTTP stages or HTTP verifiers (a flow `tool` effect, named by its stage key).
68
79
  */
69
80
  export declare function isHttpToolCall(manifest: unknown, request: HostEffect): boolean;
70
- /** The ref a `tool` effect calls the Tool Gate with: its agent's HTTP tool, or its flow stage. */
81
+ /**
82
+ * The ref a `tool` effect calls the Tool Gate with: its agent's HTTP tool, by the declared name
83
+ * its target names, or its flow stage.
84
+ */
71
85
  export declare function httpToolRefOf(request: HostEffect): HttpToolRef;
72
86
  /**
73
87
  * Sends `input` to `target` and reads the answer. Never throws: everything that can happen to
@@ -77,6 +91,12 @@ export declare function callHttpTarget(target: HttpToolTarget, input: unknown, o
77
91
  readonly headers: Readonly<Record<string, string>>;
78
92
  readonly policy: OutboundPolicy;
79
93
  readonly signal: AbortSignal;
94
+ /**
95
+ * The Tenant's Runtime limits: the largest answer read (`toolAnswerBytes`; past it,
96
+ * `http.too-large`), the longest the tool may wait (`httpToolTimeoutMs`, which its own
97
+ * `timeoutMs` may not pass) and how much of an error answer is quoted (`errorExcerptChars`).
98
+ */
99
+ readonly limits: HttpToolLimits;
80
100
  /** Checked against the answer; a mismatch is `tool.invalid-output`. */
81
101
  readonly outputSchema?: JsonObject;
82
102
  }): Promise<HttpOutcome>;
@@ -3,8 +3,10 @@
3
3
  * The loop names the tool; the gate finds its URL, method and credential in the session's pinned
4
4
  * manifest, as it finds a remote MCP server, so the loop never chooses a URL or a credential.
5
5
  *
6
- * `callHttpTarget` is the request and its answer, for any declared HTTP target: the input as a
7
- * JSON body under the Host's address policy (`tenant/outbound.ts`), a 2xx answer as the output
6
+ * `callHttpTarget` is the request and its answer, for any declared HTTP target: the input as
7
+ * core's `httpToolRequest` maps it (path parameters in the URL, the rest as a JSON body or, for
8
+ * `GET` and `DELETE`, the query string) under the Host's address policy (`tenant/outbound.ts`),
9
+ * a 2xx answer as the output
8
10
  * (JSON, or text when the answer is not JSON and no output schema asks for JSON), and every other
9
11
  * answer, a timeout or a refused address as a failed outcome the model sees. `runHttpTool` adds
10
12
  * what a tool call needs: the declaration, the vault credential and the identity headers.
@@ -14,12 +16,11 @@
14
16
  * `Nylorun-Agent-Id` is the flow agent's.
15
17
  */
16
18
  import { AGENT_ID_HEADER, SESSION_ID_HEADER, TURN_ID_HEADER, } from "@nylorun/core/compatibility";
17
- import { HTTP_TOOL_DEFAULT_TIMEOUT_MS, delegateManifest, flowHttpTarget, isWorkflowManifest, schemaFromJSON, } from "@nylorun/core/define";
19
+ import { HTTP_TOOL_DEFAULT_TIMEOUT_MS, delegateManifest, delegatesOf, flowHttpTarget, httpPathParameters, httpToolRequest, isWorkflowManifest, schemaFromJSON, } from "@nylorun/core/define";
18
20
  import { scrubValues } from "../redact.js";
19
- import { MAX_RESPONSE_BYTES, post } from "../tenant/outbound.js";
21
+ import { send } from "../tenant/outbound.js";
20
22
  import { credentialSecrets } from "../vault/headers.js";
21
- /** How much of a failed answer's body the model sees. */
22
- export const HTTP_ERROR_BODY_CHARS = 2_000;
23
+ import { readRuntimeLimits } from "../tenant/runtime-limits.js";
23
24
  /** The HTTP tool `toolName` of the agent `agentId` (the root when absent). */
24
25
  export function declaredHttpTool(manifest, agentId, toolName) {
25
26
  const root = manifest;
@@ -29,6 +30,24 @@ export function declaredHttpTool(manifest, agentId, toolName) {
29
30
  const tool = agent?.tools?.find((item) => item.name === toolName);
30
31
  return tool?.http ? tool : undefined;
31
32
  }
33
+ /**
34
+ * Why `manifest` cannot be deployed: each HTTP tool of it, or of an agent it uses as a tool, whose
35
+ * `timeoutMs` is longer than the Tenant's Runtime limit `httpToolTimeoutMs`. A call also waits at
36
+ * most the limit in force then (`callHttpTarget`).
37
+ */
38
+ export function httpToolTimeoutIssues(manifest, limitMs) {
39
+ const root = manifest;
40
+ if (!root || typeof root !== "object" || isWorkflowManifest(root))
41
+ return [];
42
+ return [root, ...delegatesOf(root).map((delegate) => delegate.manifest)].flatMap((agent) => (agent.tools ?? []).flatMap((tool) => {
43
+ const asked = tool.http?.timeoutMs;
44
+ return asked !== undefined && asked > limitMs
45
+ ? [
46
+ `HTTP tool '${tool.name}' of agent '${agent.id}' asks for timeoutMs ${asked}; the Runtime limit httpToolTimeoutMs allows at most ${limitMs} (PUT /v1/tenant/limits).`,
47
+ ]
48
+ : [];
49
+ }));
50
+ }
32
51
  /** The HTTP stage or HTTP verifier at stage key `stage` of a flow session's `manifest`. */
33
52
  export function declaredFlowHttp(manifest, stage) {
34
53
  return stage !== undefined && isWorkflowManifest(manifest)
@@ -42,18 +61,24 @@ export function declaredFlowHttp(manifest, stage) {
42
61
  export function isHttpToolCall(manifest, request) {
43
62
  if (request.kind !== "tool")
44
63
  return false;
45
- if (request.toolName === undefined)
64
+ // An agent's call names what runs it (protocol 15): an `http` call names its declared tool.
65
+ if (request.target?.kind === "http")
66
+ return declaredHttpTool(manifest, request.agent?.id, request.target.tool) !== undefined;
67
+ if (request.target === undefined && request.toolName === undefined)
46
68
  return declaredFlowHttp(manifest, request.key) !== undefined;
47
- return declaredHttpTool(manifest, request.agent?.id, request.toolName) !== undefined;
69
+ return false;
48
70
  }
49
- /** The ref a `tool` effect calls the Tool Gate with: its agent's HTTP tool, or its flow stage. */
71
+ /**
72
+ * The ref a `tool` effect calls the Tool Gate with: its agent's HTTP tool, by the declared name
73
+ * its target names, or its flow stage.
74
+ */
50
75
  export function httpToolRefOf(request) {
51
- if (request.toolName === undefined)
76
+ if (request.target?.kind !== "http")
52
77
  return { sessionId: request.sessionId, stage: request.key };
53
78
  return {
54
79
  sessionId: request.sessionId,
55
80
  ...(request.agent ? { agentId: request.agent.id } : {}),
56
- toolName: request.toolName,
81
+ toolName: request.target.tool,
57
82
  };
58
83
  }
59
84
  /**
@@ -61,12 +86,17 @@ export function httpToolRefOf(request) {
61
86
  * the request is an outcome. Rejects only when `signal` aborts, with its reason.
62
87
  */
63
88
  export async function callHttpTarget(target, input, options) {
64
- const timeoutMs = target.timeoutMs ?? HTTP_TOOL_DEFAULT_TIMEOUT_MS;
89
+ const request = httpToolRequest(target, input);
90
+ if ("issue" in request)
91
+ return failed("tool.invalid-input", request.issue);
92
+ const { limits } = options;
93
+ const timeoutMs = Math.min(target.timeoutMs ?? HTTP_TOOL_DEFAULT_TIMEOUT_MS, limits.httpToolTimeoutMs);
65
94
  const timeout = AbortSignal.timeout(timeoutMs);
66
- const result = await post(target.url, JSON.stringify(input ?? {}), { ...options.headers }, {
95
+ const result = await send(request.url, request.body, { ...options.headers }, {
67
96
  policy: options.policy,
68
- method: target.method ?? "POST",
97
+ method: request.method,
69
98
  signal: AbortSignal.any([options.signal, timeout]),
99
+ maxResponseBytes: limits.toolAnswerBytes,
70
100
  });
71
101
  if (options.signal.aborted)
72
102
  throw options.signal.reason;
@@ -80,14 +110,15 @@ export async function callHttpTarget(target, input, options) {
80
110
  case "lost":
81
111
  return failed("http.lost", `The connection was lost after the request was sent, so the call may have run: ${result.message}`);
82
112
  case "too_large":
83
- return failed("http.too-large", `The answer (HTTP ${result.status}) is larger than ${MAX_RESPONSE_BYTES} bytes`);
113
+ return failed("http.too-large", `The answer (HTTP ${result.status}) is larger than ${limits.toolAnswerBytes} bytes (the Runtime limit toolAnswerBytes)`);
84
114
  }
85
115
  // The service answered, so the outcome is known; never retried, and its body is not shown (R2b C1).
86
116
  if (result.status === 401)
87
117
  return failed("credential_rejected", "The service answered HTTP 401: it rejected the credential, or needs one");
88
118
  const text = result.body.toString("utf8");
89
119
  if (result.status < 200 || result.status > 299) {
90
- const body = text.length > HTTP_ERROR_BODY_CHARS ? `${text.slice(0, HTTP_ERROR_BODY_CHARS)}…` : text;
120
+ const chars = limits.errorExcerptChars;
121
+ const body = text.length > chars ? `${text.slice(0, chars)}…` : text;
91
122
  return failed("http.status", `The service answered HTTP ${result.status}${body ? `: ${body}` : ""}`);
92
123
  }
93
124
  const type = String(result.headers["content-type"] ?? "");
@@ -170,7 +201,10 @@ export async function runHttpTool(tenant, call, options) {
170
201
  return failed("http.credential", `The session's Environment holds no credential '${http.credential}' for ${authorized.url}`);
171
202
  credential = authorized.headers;
172
203
  identity = authorized.identity;
173
- // A credential with `via` sends the call there, a gateway (R2b C2, Q9).
204
+ // A credential with `via` sends the call there, a gateway (R2b C2, Q9): to its one URL, so
205
+ // it has no place for the tool's URL parameters.
206
+ if (authorized.via !== undefined && httpPathParameters(http.url).length > 0)
207
+ return failed("http.credential", `The credential '${http.credential}' sends calls to its via URL, which cannot take the tool's {field} URL parameters`);
174
208
  if (authorized.via !== undefined)
175
209
  target = { ...http, url: authorized.via };
176
210
  }
@@ -185,6 +219,7 @@ export async function runHttpTool(tenant, call, options) {
185
219
  },
186
220
  policy: options.policy,
187
221
  signal: options.signal,
222
+ limits: await tenant.limits(),
188
223
  ...(declared.outputSchema === undefined ? {} : { outputSchema: declared.outputSchema }),
189
224
  });
190
225
  // Nothing the service echoes of the credential reaches the model, an event or the gate's
@@ -205,6 +240,7 @@ export function gateHttpTools(vaults, policy, logger) {
205
240
  call: (tenantId, call, signal) => runHttpTool({
206
241
  session: async (sessionId) => (await vaults.open(tenantId)).session(sessionId),
207
242
  authorize: async (sessionId, request) => (await vaults.open(tenantId)).authorizeMcp(sessionId, request),
243
+ limits: async () => (await vaults.open(tenantId)).store.tx((t) => readRuntimeLimits(t)),
208
244
  }, call, { policy, signal, logger }),
209
245
  };
210
246
  }
@@ -37,10 +37,11 @@ export declare function tenantModelGate(options: {
37
37
  readonly kek: () => Buffer;
38
38
  readonly root: string;
39
39
  readonly logger: Logger;
40
- readonly settings?: ModelCallSettings;
41
40
  /** The Tenant's Object store, for the files a prompt names. */
42
41
  readonly blobs?: BlobStore;
43
42
  }): ModelGate;
43
+ /** The Tenant's model call settings: its Runtime limits `model*`, read now. */
44
+ export declare function modelCallSettings(store: SessionStore): Promise<Required<ModelCallSettings>>;
44
45
  /**
45
46
  * Serves one call: from the fixture model while the Tenant's `model.fixture` setting is on (R4.3),
46
47
  * else from `gate`. Read per call, so a seed applies to the next call.
@@ -1,4 +1,5 @@
1
- import { piModel } from "../model/pi-model.js";
1
+ import { modelCallSettingsOf, piModel } from "../model/pi-model.js";
2
+ import { readRuntimeLimits } from "../tenant/runtime-limits.js";
2
3
  import { HostModelVault } from "../vault/host-model.js";
3
4
  import { createMeter } from "./meter.js";
4
5
  import { artifactFiles } from "../artifacts/files.js";
@@ -19,18 +20,25 @@ export function callFiles(store, blobs) {
19
20
  */
20
21
  export function tenantModelGate(options) {
21
22
  const vault = new HostModelVault({ store: options.store, kek: options.kek });
22
- const gate = inProcessModelGate({
23
- root: options.root,
24
- readHostModel: () => vault.readHostModel(),
25
- writeHostCredential: (credential) => vault.updateHostCredential(credential),
26
- ...(options.settings ? { settings: options.settings } : {}),
27
- ...(options.blobs ? { files: callFiles(options.store, options.blobs) } : {}),
28
- });
29
23
  const meter = createMeter({ logger: options.logger });
30
24
  return {
31
- call: (request, signal) => meter.call(options.store, request, () => serve(options.store, gate, request, signal)),
25
+ call: (request, signal) => meter.call(options.store, request, async () => {
26
+ // The Tenant's Runtime limits `model*`, read for this call.
27
+ const gate = inProcessModelGate({
28
+ root: options.root,
29
+ readHostModel: () => vault.readHostModel(),
30
+ writeHostCredential: (credential) => vault.updateHostCredential(credential),
31
+ settings: await modelCallSettings(options.store),
32
+ ...(options.blobs ? { files: callFiles(options.store, options.blobs) } : {}),
33
+ });
34
+ return serve(options.store, gate, request, signal);
35
+ }),
32
36
  };
33
37
  }
38
+ /** The Tenant's model call settings: its Runtime limits `model*`, read now. */
39
+ export async function modelCallSettings(store) {
40
+ return modelCallSettingsOf(await store.tx((t) => readRuntimeLimits(t)));
41
+ }
34
42
  /**
35
43
  * Serves one call: from the fixture model while the Tenant's `model.fixture` setting is on (R4.3),
36
44
  * else from `gate`. Read per call, so a seed applies to the next call.
@@ -49,9 +49,9 @@ export interface InflightCalls<T = ModelGateOutcome> {
49
49
  readonly size: number;
50
50
  }
51
51
  export interface InflightCallsOptions {
52
- /** How long a settled outcome is kept. Default 30 minutes. */
52
+ /** How long a settled outcome is kept. Default `gates.inflightTtlMs` (Host tuning, 30 min). */
53
53
  readonly ttlMs?: number;
54
- /** Most entries; the oldest settled ones go first. Default 10,000. */
54
+ /** Most entries; the oldest settled ones go first. Default `gates.inflightMax` (10,000). */
55
55
  readonly max?: number;
56
56
  readonly now?: () => number;
57
57
  }