@nylorun/runtime 0.26.0-beta → 0.28.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 (379) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +18 -14
  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.d.ts +4 -3
  12. package/dist/api/a2a/card.js +4 -4
  13. package/dist/api/a2a/endpoint.js +3 -4
  14. package/dist/api/a2a/protocol.js +4 -0
  15. package/dist/api/a2a/routes.d.ts +2 -6
  16. package/dist/api/a2a/routes.js +30 -25
  17. package/dist/api/ag-ui/endpoint.js +2 -3
  18. package/dist/api/ag-ui/routes.js +8 -11
  19. package/dist/api/components.d.ts +6789 -3405
  20. package/dist/api/components.js +43 -30
  21. package/dist/api/gate/keys.js +7 -4
  22. package/dist/api/gate/routes.d.ts +6 -2
  23. package/dist/api/gate/routes.js +15 -11
  24. package/dist/api/http/app.js +9 -4
  25. package/dist/api/http/body.d.ts +17 -3
  26. package/dist/api/http/body.js +35 -7
  27. package/dist/api/http/respond.js +6 -2
  28. package/dist/api/http/routes/access.js +5 -4
  29. package/dist/api/http/routes/agent-manifests.d.ts +10 -0
  30. package/dist/api/http/routes/agent-manifests.js +135 -0
  31. package/dist/api/http/routes/agents.d.ts +11 -0
  32. package/dist/api/http/routes/agents.js +418 -0
  33. package/dist/api/http/routes/artifacts.js +21 -9
  34. package/dist/api/http/routes/coverage.d.ts +4 -4
  35. package/dist/api/http/routes/coverage.js +13 -7
  36. package/dist/api/http/routes/files.d.ts +2 -1
  37. package/dist/api/http/routes/files.js +31 -5
  38. package/dist/api/http/routes/mcp.js +3 -3
  39. package/dist/api/http/routes/me.d.ts +1 -1
  40. package/dist/api/http/routes/me.js +1 -2
  41. package/dist/api/http/routes/memories.d.ts +9 -0
  42. package/dist/api/http/routes/memories.js +152 -0
  43. package/dist/api/http/routes/reads.d.ts +10 -111
  44. package/dist/api/http/routes/reads.js +51 -29
  45. package/dist/api/http/routes/sessions.js +26 -54
  46. package/dist/api/http/routes/tenant.d.ts +2 -2
  47. package/dist/api/http/routes/tenant.js +77 -24
  48. package/dist/api/http/routes/triggers.d.ts +10 -0
  49. package/dist/api/http/routes/triggers.js +180 -0
  50. package/dist/api/inbound-files.d.ts +3 -9
  51. package/dist/api/inbound-files.js +18 -24
  52. package/dist/api/openapi.js +73 -47
  53. package/dist/artifacts/disk.d.ts +10 -14
  54. package/dist/artifacts/disk.js +99 -95
  55. package/dist/artifacts/files.d.ts +13 -4
  56. package/dist/artifacts/files.js +27 -9
  57. package/dist/artifacts/folder-upload.d.ts +75 -0
  58. package/dist/artifacts/folder-upload.js +263 -0
  59. package/dist/artifacts/folders.d.ts +14 -8
  60. package/dist/artifacts/folders.js +19 -11
  61. package/dist/artifacts/links.js +7 -6
  62. package/dist/artifacts/parts.d.ts +9 -14
  63. package/dist/artifacts/parts.js +11 -9
  64. package/dist/artifacts/pipe.d.ts +15 -0
  65. package/dist/artifacts/pipe.js +71 -0
  66. package/dist/artifacts/quota.d.ts +36 -0
  67. package/dist/artifacts/quota.js +44 -0
  68. package/dist/artifacts/service.d.ts +25 -1
  69. package/dist/artifacts/service.js +72 -27
  70. package/dist/blob/fs.js +2 -1
  71. package/dist/blob/s3.d.ts +6 -2
  72. package/dist/blob/s3.js +9 -7
  73. package/dist/blob/types.d.ts +1 -1
  74. package/dist/blob/types.js +1 -1
  75. package/dist/core/flow-host.d.ts +0 -1
  76. package/dist/core/limits.d.ts +11 -35
  77. package/dist/core/limits.js +5 -73
  78. package/dist/core/sandbox-routes.js +0 -1
  79. package/dist/core/turn-manifest.d.ts +1 -2
  80. package/dist/core/turn-manifest.js +4 -28
  81. package/dist/execution/memory.d.ts +8 -5
  82. package/dist/execution/memory.js +8 -6
  83. package/dist/execution/types.d.ts +1 -6
  84. package/dist/execution/types.js +0 -5
  85. package/dist/gates/contract.d.ts +3 -2
  86. package/dist/gates/contract.js +1 -1
  87. package/dist/gates/egress-credentials.js +5 -4
  88. package/dist/gates/egress.d.ts +13 -13
  89. package/dist/gates/egress.js +19 -21
  90. package/dist/gates/fixture-model.js +13 -2
  91. package/dist/gates/handler.d.ts +1 -3
  92. package/dist/gates/handler.js +4 -3
  93. package/dist/gates/http-client.d.ts +4 -3
  94. package/dist/gates/http-client.js +5 -7
  95. package/dist/gates/http-tool.d.ts +24 -4
  96. package/dist/gates/http-tool.js +41 -13
  97. package/dist/gates/in-process.d.ts +2 -1
  98. package/dist/gates/in-process.js +17 -9
  99. package/dist/gates/inflight.d.ts +2 -2
  100. package/dist/gates/inflight.js +3 -2
  101. package/dist/gates/journal.js +5 -7
  102. package/dist/gates/mcp-handler.d.ts +4 -3
  103. package/dist/gates/mcp-handler.js +15 -5
  104. package/dist/gates/meter.js +6 -5
  105. package/dist/gates/model-gate.d.ts +11 -2
  106. package/dist/gates/policy.d.ts +34 -6
  107. package/dist/gates/policy.js +66 -18
  108. package/dist/gates/provider-gate.d.ts +22 -0
  109. package/dist/gates/provider-gate.js +30 -0
  110. package/dist/gates/tool-calls.d.ts +1 -3
  111. package/dist/gates/tool-calls.js +2 -3
  112. package/dist/gates/tool-client.d.ts +1 -1
  113. package/dist/gates/tool-client.js +5 -6
  114. package/dist/gates/tool-contract.d.ts +8 -5
  115. package/dist/gates/tool-contract.js +1 -1
  116. package/dist/gates/tool-gate.d.ts +18 -7
  117. package/dist/gates/tool-gate.js +49 -7
  118. package/dist/harness/calls.d.ts +27 -25
  119. package/dist/harness/calls.js +40 -46
  120. package/dist/harness/executors.d.ts +10 -3
  121. package/dist/harness/executors.js +53 -23
  122. package/dist/harness/main.js +2 -2
  123. package/dist/harness/pod.d.ts +2 -2
  124. package/dist/harness/pod.js +7 -6
  125. package/dist/harness/run-tokens.d.ts +4 -1
  126. package/dist/harness/run-tokens.js +6 -2
  127. package/dist/harness/service.d.ts +17 -14
  128. package/dist/harness/service.js +21 -35
  129. package/dist/harness/setup.d.ts +0 -2
  130. package/dist/harness/setup.js +21 -15
  131. package/dist/harness/ws-client.d.ts +2 -2
  132. package/dist/harness/ws-client.js +7 -5
  133. package/dist/harness/ws-port.d.ts +3 -4
  134. package/dist/harness/ws-port.js +3 -4
  135. package/dist/harness-api/artifacts.d.ts +20 -0
  136. package/dist/harness-api/artifacts.js +478 -0
  137. package/dist/harness-api/in-process.d.ts +2 -2
  138. package/dist/harness-api/in-process.js +18 -16
  139. package/dist/harness-api/record.d.ts +10 -9
  140. package/dist/harness-api/record.js +113 -157
  141. package/dist/harness-api/renew.d.ts +1 -1
  142. package/dist/harness-api/renew.js +2 -2
  143. package/dist/harness-api/server.d.ts +1 -16
  144. package/dist/harness-api/server.js +86 -73
  145. package/dist/harness-api/start.d.ts +27 -5
  146. package/dist/harness-api/start.js +102 -19
  147. package/dist/harness-api/tool-journal.d.ts +15 -10
  148. package/dist/harness-api/tool-journal.js +26 -24
  149. package/dist/harness-api/workspace.d.ts +0 -4
  150. package/dist/harness-api/workspace.js +4 -47
  151. package/dist/harness-api/ws-server.js +10 -10
  152. package/dist/host/create-host.js +2 -3
  153. package/dist/host/execution.js +2 -3
  154. package/dist/host/gates.d.ts +2 -9
  155. package/dist/host/gates.js +15 -12
  156. package/dist/host/http.d.ts +2 -4
  157. package/dist/host/http.js +5 -29
  158. package/dist/host/main.js +10 -3
  159. package/dist/host/operate.js +12 -3
  160. package/dist/host/stack-config.d.ts +11 -0
  161. package/dist/host/stack-config.js +21 -1
  162. package/dist/index.d.ts +0 -1
  163. package/dist/index.js +0 -1
  164. package/dist/infra/index.js +2 -1
  165. package/dist/infra/readiness.d.ts +0 -2
  166. package/dist/infra/readiness.js +4 -3
  167. package/dist/keys/client.d.ts +1 -0
  168. package/dist/keys/client.js +2 -3
  169. package/dist/keys/contract.d.ts +0 -2
  170. package/dist/keys/contract.js +0 -2
  171. package/dist/keys/egress-ca.d.ts +0 -2
  172. package/dist/keys/egress-ca.js +2 -3
  173. package/dist/keys/keys.d.ts +15 -4
  174. package/dist/keys/keys.js +22 -1
  175. package/dist/keys/webhooks.d.ts +25 -0
  176. package/dist/keys/webhooks.js +62 -0
  177. package/dist/keys/x509.d.ts +8 -4
  178. package/dist/keys/x509.js +14 -5
  179. package/dist/management-openapi.json +3043 -1954
  180. package/dist/mcp/connect.d.ts +35 -26
  181. package/dist/mcp/connect.js +112 -141
  182. package/dist/mcp/pool.d.ts +27 -22
  183. package/dist/mcp/pool.js +34 -48
  184. package/dist/mcp/preview.d.ts +12 -5
  185. package/dist/mcp/preview.js +43 -26
  186. package/dist/mcp/snapshot.d.ts +35 -86
  187. package/dist/mcp/snapshot.js +93 -135
  188. package/dist/memory/service.d.ts +97 -0
  189. package/dist/memory/service.js +335 -0
  190. package/dist/memory/tool.d.ts +36 -0
  191. package/dist/memory/tool.js +84 -0
  192. package/dist/model/auth-store.js +5 -3
  193. package/dist/model/capabilities.d.ts +1 -1
  194. package/dist/model/catalog.d.ts +9 -36
  195. package/dist/model/catalog.js +6 -33
  196. package/dist/model/descriptor.d.ts +51 -0
  197. package/dist/model/descriptor.js +83 -0
  198. package/dist/model/models.d.ts +0 -3
  199. package/dist/model/models.js +3 -5
  200. package/dist/model/native-blocks.js +1 -1
  201. package/dist/model/pi-model.d.ts +16 -5
  202. package/dist/model/pi-model.js +86 -105
  203. package/dist/openapi.json +13653 -9986
  204. package/dist/reads/cursor.js +3 -1
  205. package/dist/reads/types.d.ts +3 -3
  206. package/dist/record/agent.d.ts +27 -0
  207. package/dist/record/agent.js +46 -0
  208. package/dist/record/append.d.ts +34 -2
  209. package/dist/record/append.js +50 -1
  210. package/dist/record/index.d.ts +2 -2
  211. package/dist/record/index.js +2 -2
  212. package/dist/redact.d.ts +1 -1
  213. package/dist/redact.js +3 -2
  214. package/dist/sandbox/egress-token.d.ts +3 -3
  215. package/dist/sandbox/egress-token.js +3 -3
  216. package/dist/sandbox/join.js +8 -7
  217. package/dist/sandbox/manager.d.ts +41 -41
  218. package/dist/sandbox/manager.js +112 -44
  219. package/dist/sandbox/placement.d.ts +2 -2
  220. package/dist/sandbox/placement.js +7 -10
  221. package/dist/sandbox/pods/client.d.ts +1 -10
  222. package/dist/sandbox/pods/client.js +8 -4
  223. package/dist/sandbox/pods/lifecycle.d.ts +25 -17
  224. package/dist/sandbox/pods/lifecycle.js +51 -29
  225. package/dist/sandbox/pods/network-gate.d.ts +4 -5
  226. package/dist/sandbox/pods/network-gate.js +7 -7
  227. package/dist/sandbox/pods/reconcile.js +14 -3
  228. package/dist/sandbox/pods/spec.js +8 -5
  229. package/dist/sandbox/policy.d.ts +7 -1
  230. package/dist/sandbox/policy.js +10 -3
  231. package/dist/sandbox/resolve.d.ts +11 -6
  232. package/dist/sandbox/resolve.js +19 -9
  233. package/dist/sandbox/setup.d.ts +6 -2
  234. package/dist/sandbox/setup.js +47 -14
  235. package/dist/sandbox/share.d.ts +5 -14
  236. package/dist/sandbox/share.js +5 -34
  237. package/dist/sandbox/skills.d.ts +7 -13
  238. package/dist/sandbox/skills.js +16 -31
  239. package/dist/sandbox/tenant-config.d.ts +2 -2
  240. package/dist/sandbox/tenant-config.js +4 -3
  241. package/dist/sandbox/tools.d.ts +7 -1
  242. package/dist/sandbox/tools.js +26 -26
  243. package/dist/sandbox/types.d.ts +10 -3
  244. package/dist/sandbox/types.js +9 -0
  245. package/dist/store/postgres/connect.d.ts +6 -5
  246. package/dist/store/postgres/connect.js +14 -11
  247. package/dist/store/postgres/control.js +13 -13
  248. package/dist/store/postgres/drizzle/0028_artifact_write_keys.sql +2 -0
  249. package/dist/store/postgres/drizzle/0029_protocol_15.sql +11 -0
  250. package/dist/store/postgres/drizzle/0030_protocol_15_runtime_block.sql +11 -0
  251. package/dist/store/postgres/drizzle/0031_protocol_15_mcp_snapshot.sql +8 -0
  252. package/dist/store/postgres/drizzle/0032_agents.sql +54 -0
  253. package/dist/store/postgres/drizzle/0033_agent_versions.sql +7 -0
  254. package/dist/store/postgres/drizzle/0034_protocol_17_session_queue.sql +13 -0
  255. package/dist/store/postgres/drizzle/0035_t4_triggers.sql +41 -0
  256. package/dist/store/postgres/drizzle/0036_t5_memories.sql +30 -0
  257. package/dist/store/postgres/drizzle/meta/_journal.json +63 -0
  258. package/dist/store/postgres/reads.js +17 -82
  259. package/dist/store/postgres/record-writer.d.ts +4 -4
  260. package/dist/store/postgres/record-writer.js +9 -9
  261. package/dist/store/postgres/schema.d.ts +1382 -151
  262. package/dist/store/postgres/schema.js +191 -37
  263. package/dist/store/postgres/store.js +384 -105
  264. package/dist/store/postgres/tenant.js +1 -2
  265. package/dist/store/types.d.ts +172 -57
  266. package/dist/store/types.js +0 -1
  267. package/dist/streams/relay/core.d.ts +3 -3
  268. package/dist/streams/relay/core.js +9 -10
  269. package/dist/tenant/advance.js +41 -39
  270. package/dist/tenant/agent-manifests.d.ts +72 -0
  271. package/dist/tenant/agent-manifests.js +359 -0
  272. package/dist/tenant/agent-versions.d.ts +126 -0
  273. package/dist/tenant/agent-versions.js +389 -0
  274. package/dist/tenant/agents.d.ts +230 -0
  275. package/dist/tenant/{environments.js → agents.js} +493 -328
  276. package/dist/tenant/auth.d.ts +1 -1
  277. package/dist/tenant/auth.js +3 -3
  278. package/dist/tenant/commands.d.ts +63 -2
  279. package/dist/tenant/commands.js +240 -90
  280. package/dist/tenant/context.d.ts +57 -33
  281. package/dist/tenant/context.js +6 -2
  282. package/dist/tenant/definition-files.d.ts +25 -4
  283. package/dist/tenant/definition-files.js +85 -47
  284. package/dist/tenant/effects.js +15 -51
  285. package/dist/tenant/ephemeral.js +2 -1
  286. package/dist/tenant/history.d.ts +1 -1
  287. package/dist/tenant/history.js +1 -1
  288. package/dist/tenant/host-token.d.ts +3 -3
  289. package/dist/tenant/host-token.js +11 -10
  290. package/dist/tenant/http.d.ts +5 -8
  291. package/dist/tenant/http.js +9 -0
  292. package/dist/tenant/identity-file.d.ts +29 -6
  293. package/dist/tenant/identity-file.js +45 -15
  294. package/dist/tenant/issuers.d.ts +5 -5
  295. package/dist/tenant/issuers.js +34 -26
  296. package/dist/tenant/jwt.d.ts +8 -2
  297. package/dist/tenant/jwt.js +10 -2
  298. package/dist/tenant/limits.d.ts +87 -0
  299. package/dist/tenant/limits.js +172 -0
  300. package/dist/tenant/memories.d.ts +38 -0
  301. package/dist/tenant/memories.js +119 -0
  302. package/dist/tenant/module.d.ts +4 -1
  303. package/dist/tenant/module.js +9 -8
  304. package/dist/tenant/outbound.d.ts +11 -14
  305. package/dist/tenant/outbound.js +10 -15
  306. package/dist/tenant/reset.js +2 -2
  307. package/dist/tenant/run-grants.d.ts +6 -0
  308. package/dist/tenant/run-grants.js +7 -2
  309. package/dist/tenant/run-token.d.ts +0 -4
  310. package/dist/tenant/run-token.js +6 -11
  311. package/dist/tenant/runtime-limits.d.ts +24 -0
  312. package/dist/tenant/runtime-limits.js +27 -0
  313. package/dist/tenant/runtime.d.ts +1 -1
  314. package/dist/tenant/runtime.js +38 -43
  315. package/dist/tenant/session-streams.js +7 -6
  316. package/dist/tenant/session.d.ts +1 -1
  317. package/dist/tenant/session.js +1 -1
  318. package/dist/tenant/sessions.d.ts +28 -45
  319. package/dist/tenant/sessions.js +89 -209
  320. package/dist/tenant/signing-keys.d.ts +1 -1
  321. package/dist/tenant/signing-keys.js +5 -6
  322. package/dist/tenant/status.js +10 -10
  323. package/dist/tenant/streams.js +18 -20
  324. package/dist/tenant/sweep.d.ts +1 -21
  325. package/dist/tenant/sweep.js +51 -51
  326. package/dist/tenant/transcript.d.ts +70 -23
  327. package/dist/tenant/transcript.js +28 -22
  328. package/dist/tenant/triggers.d.ts +143 -0
  329. package/dist/tenant/triggers.js +715 -0
  330. package/dist/tenant/turn-timing.d.ts +11 -1
  331. package/dist/tenant/turn-timing.js +3 -1
  332. package/dist/tenant/types.d.ts +9 -14
  333. package/dist/tenant/worker.d.ts +4 -10
  334. package/dist/tenant/worker.js +10 -14
  335. package/dist/traces/ids.js +5 -1
  336. package/dist/traces/map.d.ts +10 -7
  337. package/dist/traces/map.js +16 -12
  338. package/dist/traces/otlp.d.ts +3 -3
  339. package/dist/traces/otlp.js +5 -3
  340. package/dist/traces/projector.d.ts +9 -4
  341. package/dist/traces/projector.js +13 -7
  342. package/dist/traces/read.js +6 -1
  343. package/dist/tuning.d.ts +390 -0
  344. package/dist/tuning.js +677 -0
  345. package/dist/vault/headers.js +4 -2
  346. package/dist/vault/service.d.ts +13 -8
  347. package/dist/vault/service.js +61 -17
  348. package/dist/version.d.ts +1 -1
  349. package/dist/version.js +1 -1
  350. package/package.json +13 -12
  351. package/dist/api/http/routes/environment-manifests.d.ts +0 -9
  352. package/dist/api/http/routes/environment-manifests.js +0 -118
  353. package/dist/api/http/routes/environments.d.ts +0 -11
  354. package/dist/api/http/routes/environments.js +0 -332
  355. package/dist/artifacts/export.d.ts +0 -8
  356. package/dist/artifacts/export.js +0 -204
  357. package/dist/artifacts/media-types.d.ts +0 -30
  358. package/dist/artifacts/media-types.js +0 -137
  359. package/dist/artifacts/workspace.d.ts +0 -60
  360. package/dist/artifacts/workspace.js +0 -45
  361. package/dist/media.d.ts +0 -10
  362. package/dist/media.js +0 -58
  363. package/dist/record/environment.d.ts +0 -25
  364. package/dist/record/environment.js +0 -44
  365. package/dist/sandbox/runtime-tools.d.ts +0 -9
  366. package/dist/sandbox/runtime-tools.js +0 -16
  367. package/dist/sandbox/session-sandbox.d.ts +0 -16
  368. package/dist/sandbox/session-sandbox.js +0 -77
  369. package/dist/tenant/artifact-tool.d.ts +0 -13
  370. package/dist/tenant/artifact-tool.js +0 -243
  371. package/dist/tenant/environment-manifests.d.ts +0 -57
  372. package/dist/tenant/environment-manifests.js +0 -200
  373. package/dist/tenant/environments.d.ts +0 -174
  374. package/dist/tenant/skill-tool.d.ts +0 -20
  375. package/dist/tenant/skill-tool.js +0 -67
  376. package/dist/tenant/tool-results.d.ts +0 -57
  377. package/dist/tenant/tool-results.js +0 -298
  378. package/dist/tenant/tool-search.d.ts +0 -39
  379. package/dist/tenant/tool-search.js +0 -103
@@ -4,7 +4,7 @@ import { TenantEnvelopeSchema, } from "@nylorun/core/contracts";
4
4
  import { openError, TenantOpenError } from "../../tenant/cause.js";
5
5
  import { database, driverError } from "./db.js";
6
6
  import { applyMigrations, assertCurrentLayout, isStatementError, lockMigrations, shippedMigrations, } from "./migrate.js";
7
- import { definitions, principals, sessions, signingKeys, TENANT_SCHEMA, tenant, vaultAudit, vaults, } from "./schema.js";
7
+ import { principals, sessions, signingKeys, TENANT_SCHEMA, tenant, vaultAudit, vaults, } from "./schema.js";
8
8
  import { createPostgresSessionStore } from "./store.js";
9
9
  /** The migration that deletes the vault's `oauth` credentials, each with an audit row. */
10
10
  const OAUTH_REMOVED_MIGRATION = "0016_mcp_oauth_removed";
@@ -114,7 +114,6 @@ async function ensureTenant(tx, create, migrated, now) {
114
114
  const [data] = await tx.execute(sql `
115
115
  SELECT EXISTS (SELECT 1 FROM ${principals})
116
116
  OR EXISTS (SELECT 1 FROM ${sessions})
117
- OR EXISTS (SELECT 1 FROM ${definitions})
118
117
  OR EXISTS (SELECT 1 FROM ${vaults})
119
118
  OR EXISTS (SELECT 1 FROM ${signingKeys}) AS held`);
120
119
  if (data?.held)
@@ -63,11 +63,11 @@
63
63
  import type { KeyRole } from "@nylorun/core/compatibility";
64
64
  import type { RecordReader } from "../streams/relay/types.js";
65
65
  import type { SandboxSignal, Wake } from "../execution/types.js";
66
- import type { EventPayload, EventType, EventWriter, LiveEvent, EnvironmentEvent, EnvironmentEventPayload, EnvironmentEventType, EnvironmentKind, EnvironmentManifest, EnvironmentRecipe, PodDesired, PodObserved, SessionEventOf } from "@nylorun/core/contracts";
66
+ import type { EventPayload, EventType, EventWriter, LiveEvent, AgentEvent, AgentEventPayload, AgentEventType, AgentManifestV8, EnvironmentKind, EnvironmentRecipe, PodDesired, PodObserved, SessionEventOf } from "@nylorun/core/contracts";
67
67
  import type { HostEffect } from "@nylorun/harness/run";
68
- import type { ArtifactRow, ArtifactVersionRow, DefinitionFileRow, ModelBudgetRow, ModelUsageRow, ModelUsageWrite, PrincipalRow, ToolCrossingRow, SigningKeyRow, VaultAuditRow, VaultCredentialRow, VaultIdempotencyRow, VaultRow } from "./postgres/schema.js";
68
+ import type { ArtifactRow, ArtifactVersionRow, DefinitionFileRow, ModelBudgetRow, ModelUsageRow, ModelUsageWrite, PrincipalRow, ToolCrossingRow, QueuedMessageRow, AgentTriggerRow, TriggerRunRow, MemoryRow, MemoryVersionRow, SigningKeyRow, VaultAuditRow, VaultCredentialRow, VaultIdempotencyRow, VaultRow } from "./postgres/schema.js";
69
69
  /** Tables holding JSON documents keyed by `id`. */
70
- export type DocTable = "definitions" | "sessions" | "commands" | "effects" | "sandboxes" | "links";
70
+ export type DocTable = "sessions" | "commands" | "effects" | "sandboxes" | "links";
71
71
  export declare const DOC_TABLES: readonly DocTable[];
72
72
  /** Session lifecycle (architecture §10.2). */
73
73
  export type SessionStatus = "idle" | "runnable" | "running" | "waiting" | "paused" | "uncertain" | "completed" | "failed" | "cancelled";
@@ -117,17 +117,15 @@ export interface LinkDoc {
117
117
  effectId: string;
118
118
  turnId: string;
119
119
  }
120
- /** A definition document. Indexed: `manifest.id`. */
121
- export interface DefinitionDoc {
122
- manifest: {
123
- id: string;
124
- };
125
- }
126
120
  /** A sandbox record, keyed by sandbox key. */
127
121
  export interface SandboxDoc {
128
122
  key: string;
129
123
  }
130
- /** An Environment (`environments`, D55): what `PUT /v1/environments/{id}` created. */
124
+ /**
125
+ * An Agent's row (`agents`; an Environment's before protocol 16): what `PUT /v1/agents/{id}`
126
+ * created. The Runtime's own code calls the part it runs on (its kind, recipe, pod, disk and
127
+ * vault) the Agent's environment, keyed by the Agent's id.
128
+ */
131
129
  export interface Environment {
132
130
  id: string;
133
131
  kind: EnvironmentKind;
@@ -138,7 +136,7 @@ export interface Environment {
138
136
  applied: EnvironmentRecipe;
139
137
  version: number;
140
138
  appliedVersion: number;
141
- /** The owner guard: only this owner's sessions may name it. */
139
+ /** The owner guard (`owner` on the API): only this owner's sessions may run on it. */
142
140
  ownerUserId?: string;
143
141
  /** ISO time it was last used (`lifecycle.deleteAfter` counts from it). */
144
142
  lastUsedAt: string;
@@ -153,16 +151,39 @@ export interface Environment {
153
151
  * Q17): the setup runs once the version is written (`written`), and the seed stays until it is done.
154
152
  */
155
153
  diskSeed?: DiskSeed;
156
- /** The environment manifest it was made from and its version (D63); absent for an inline one. */
157
- manifestName?: string;
158
- manifestVersion?: number;
159
- /** The hash of what it runs (`recipe`), recorded at creation (protocol 14). */
160
- manifestHash?: string;
161
- /** The Environment it was forked from and the disk version it started from (Q15). */
154
+ /** The agent manifest it was made from and the version it resolved then, which it runs. */
155
+ manifestName: string;
156
+ manifestVersion: number;
157
+ /** How it names the manifest: `tracking` (`name`) or `pinned` (`name@n`). */
158
+ manifestRef: "tracking" | "pinned";
159
+ /** The hash of that manifest version. */
160
+ manifestHash: string;
161
+ /** `on`, or `off` once paused (track T6). */
162
+ desiredState: "on" | "off";
163
+ /** The Agent it was forked from and the disk version it started from (Q15). */
162
164
  forkedFrom?: {
163
- environment: string;
165
+ agent: string;
164
166
  disk: number | null;
165
167
  };
168
+ /**
169
+ * The manifest version it moves to while it is outdated (track T3, D73): it waits for its
170
+ * required secrets or its pod's next start. Absent when it runs the version it should.
171
+ */
172
+ targetVersion?: number;
173
+ /** A version that failed to start (T3): a tracking Agent does not move to it again on its own. */
174
+ failedVersion?: number;
175
+ /** While a pod starts on a new version (T3): what it ran before, which a failed start reverts to. */
176
+ startCheck?: AgentStartCheck;
177
+ }
178
+ /** What a pod Agent ran before it started on a new version (track T3), and since when it starts. */
179
+ export interface AgentStartCheck {
180
+ from: {
181
+ manifestVersion: number;
182
+ manifestHash: string;
183
+ applied: EnvironmentRecipe;
184
+ imageDigest?: string;
185
+ };
186
+ startedAt: string;
166
187
  }
167
188
  /** A pending seed of an Environment's disk (`disk_seed`). */
168
189
  export interface DiskSeed {
@@ -173,11 +194,11 @@ export interface DiskSeed {
173
194
  /** The version is written; with `setup`, the seed waits for the setup to be done. */
174
195
  written?: true;
175
196
  }
176
- /** One version of an environment manifest (`environment_manifests`, D63). */
177
- export interface EnvironmentManifestRow {
197
+ /** One version of an agent manifest (`agent_manifests`, protocol 16). */
198
+ export interface AgentManifestRow {
178
199
  name: string;
179
200
  version: number;
180
- body: EnvironmentManifest;
201
+ body: AgentManifestV8;
181
202
  hash: string;
182
203
  savedBy: {
183
204
  actor: string;
@@ -260,11 +281,11 @@ export type CommitListener = (commit: Commit) => void;
260
281
  * `bytea` columns, never inside a JSON body), the vault's audit and idempotency records, the
261
282
  * Tenant's signing keys, a model call in the usage ledger and a model budget.
262
283
  */
263
- export type { ArtifactRow, ArtifactVersionRow, DefinitionFileRow, ModelBudgetRow, ModelUsageRow, ModelUsageWrite, ToolCrossingRow, PrincipalRow, SigningKeyRow, VaultAuditRow, VaultCredentialRow, VaultIdempotencyRow, VaultRow, };
284
+ export type { ArtifactRow, ArtifactVersionRow, DefinitionFileRow, ModelBudgetRow, ModelUsageRow, ModelUsageWrite, ToolCrossingRow, QueuedMessageRow, AgentTriggerRow, TriggerRunRow, MemoryRow, MemoryVersionRow, PrincipalRow, SigningKeyRow, VaultAuditRow, VaultCredentialRow, VaultIdempotencyRow, VaultRow, };
264
285
  /** Which rows of the usage ledger a total covers. */
265
286
  export interface ModelUsageQuery {
266
- scope: "tenant" | "agent" | "turn";
267
- /** The agent or turn id; ignored for `tenant`. */
287
+ scope: "tenant" | "manifest" | "turn";
288
+ /** The agent manifest's name or the turn id; ignored for `tenant`. */
268
289
  id?: string;
269
290
  /** Only rows created at or after this ISO time. */
270
291
  since?: string;
@@ -289,9 +310,9 @@ export interface StoreCounts {
289
310
  /** Effects `uncertain`. */
290
311
  uncertainEffects: number;
291
312
  sandboxes: number;
292
- definitions: number;
313
+ agentManifests: number;
293
314
  }
294
- export type ResetScope = "sessions" | "environments" | "all";
315
+ export type ResetScope = "sessions" | "agents" | "all";
295
316
  /** Result of `takeOwnership`. */
296
317
  export type TakeOwnership = {
297
318
  status: "owned";
@@ -408,7 +429,7 @@ export type ControlSignal = {
408
429
  epoch: number;
409
430
  };
410
431
  export interface FollowSignalsOptions {
411
- /** How often recent signals are read back. Default 5 s. */
432
+ /** How often recent signals are read back. Default `postgres.controlPollMs` (Host tuning, 5 s). */
412
433
  pollMs?: number;
413
434
  onError?: (error: unknown) => void;
414
435
  }
@@ -541,9 +562,8 @@ export interface Tx {
541
562
  agentId?: string;
542
563
  ownerUserId?: string;
543
564
  }): Promise<StoredSession<T>[]>;
544
- listDefinitions<T extends DefinitionDoc = DefinitionDoc>(): Promise<T[]>;
545
565
  listSandboxes<T extends SandboxDoc = SandboxDoc>(): Promise<T[]>;
546
- /** Environment `id`; with `lock`, its row is locked until the transaction ends. */
566
+ /** Agent `id`'s row; with `lock`, it is locked until the transaction ends. */
547
567
  environment(id: string, options?: {
548
568
  lock?: boolean;
549
569
  }): Promise<Environment | undefined>;
@@ -554,8 +574,8 @@ export interface Tx {
554
574
  createEnvironment(row: Environment, limit: number): Promise<"created" | "exists" | "limit">;
555
575
  /**
556
576
  * Changes an Environment's columns other than its pod's (the caller holds the row's lock):
557
- * labels, recipe and version, the applied recipe and its version, the owner guard (`null`
558
- * clears it), and when it was last used.
577
+ * labels, recipe and version, the applied recipe and its version, the manifest version it runs
578
+ * and how it names it (track T3), the owner guard (`null` clears it), and when it was last used.
559
579
  */
560
580
  updateEnvironment(id: string, patch: {
561
581
  labels?: Record<string, string>;
@@ -563,6 +583,12 @@ export interface Tx {
563
583
  version?: number;
564
584
  applied?: EnvironmentRecipe;
565
585
  appliedVersion?: number;
586
+ manifestVersion?: number;
587
+ manifestHash?: string;
588
+ manifestRef?: "tracking" | "pinned";
589
+ targetVersion?: number | null;
590
+ failedVersion?: number | null;
591
+ startCheck?: AgentStartCheck | null;
566
592
  ownerUserId?: string | null;
567
593
  lastUsedAt?: string;
568
594
  diskOp?: DiskOperation | null;
@@ -576,32 +602,32 @@ export interface Tx {
576
602
  listEnvironments(filter?: {
577
603
  labels?: Record<string, string>;
578
604
  }): Promise<Environment[]>;
579
- /** Sessions that name Environment `environmentId` (`Session.environmentId`), by id. */
605
+ /** Sessions on Agent `environmentId` (`Session.environmentId`), by id. */
580
606
  sessionsOnEnvironment<T extends SessionDoc = SessionDoc>(environmentId: string): Promise<StoredSession<T>[]>;
581
607
  /**
582
- * Appends an event to the Environment's lifecycle stream through the record module. The
583
- * caller holds the Environment row's lock (or created the row in this transaction).
608
+ * Appends an event to the Agent's lifecycle stream through the record module. The caller holds
609
+ * the Agent row's lock (or created the row in this transaction).
584
610
  */
585
- environmentEvent<T extends EnvironmentEventType>(environmentId: string, type: T, payload: EnvironmentEventPayload<T>): Promise<EnvironmentEvent>;
611
+ agentEvent<T extends AgentEventType>(agentId: string, type: T, payload: AgentEventPayload<T>): Promise<AgentEvent>;
586
612
  /**
587
- * The Environment's stream, from `fromSeq` on, at most `limit` events: only `types` when given,
588
- * and only events recorded at or after `since` and before `until` (ISO times) when given.
613
+ * The Agent's stream, from `fromSeq` on, at most `limit` events: only `types` when given, and
614
+ * only events recorded at or after `since` and before `until` (ISO times) when given.
589
615
  */
590
- environmentEvents(environmentId: string, options?: EnvironmentEventsQuery): Promise<EnvironmentEvent[]>;
616
+ agentEvents(agentId: string, options?: AgentEventsQuery): Promise<AgentEvent[]>;
591
617
  /** Holds manifest `name`'s save lock until the transaction ends, so saves of one name are serial. */
592
- lockEnvironmentManifest(name: string): Promise<void>;
618
+ lockAgentManifest(name: string): Promise<void>;
593
619
  /** Version `version` of manifest `name`, or its latest when `version` is omitted. */
594
- environmentManifest(name: string, version?: number): Promise<EnvironmentManifestRow | undefined>;
620
+ agentManifest(name: string, version?: number): Promise<AgentManifestRow | undefined>;
595
621
  /** Writes a new version (the caller holds the name's lock and chose the next number). */
596
- insertEnvironmentManifest(row: EnvironmentManifestRow): Promise<void>;
622
+ insertAgentManifest(row: AgentManifestRow): Promise<void>;
597
623
  /** Each manifest's latest version, by name. */
598
- listEnvironmentManifests(): Promise<EnvironmentManifestRow[]>;
624
+ listAgentManifests(): Promise<AgentManifestRow[]>;
599
625
  /** Every version of manifest `name`, newest first. */
600
- environmentManifestVersions(name: string): Promise<EnvironmentManifestRow[]>;
626
+ agentManifestVersions(name: string): Promise<AgentManifestRow[]>;
601
627
  /** Deletes every version of manifest `name`; how many there were. */
602
- deleteEnvironmentManifest(name: string): Promise<number>;
603
- /** How many Environments were made from each version of manifest `name` (deleting ones too). */
604
- environmentsOfManifest(name: string): Promise<Map<number, number>>;
628
+ deleteAgentManifest(name: string): Promise<number>;
629
+ /** How many Agents were made from each version of manifest `name` (deleting ones too). */
630
+ agentsOfManifest(name: string): Promise<Map<number, number>>;
605
631
  /** `invoking` effects of one session; takeover turns them `uncertain`. */
606
632
  invokingEffects<T extends EffectDoc = EffectDoc>(sessionId: string): Promise<T[]>;
607
633
  effectsForSession<T extends EffectDoc = EffectDoc>(sessionId: string, filter?: SessionEffectFilter): Promise<T[]>;
@@ -609,6 +635,86 @@ export interface Tx {
609
635
  effectsWithStatus<T extends EffectDoc = EffectDoc>(statuses: readonly (EffectStatus | (string & {}))[], filter?: {
610
636
  kinds?: readonly EffectKind[];
611
637
  }): Promise<T[]>;
638
+ /** Adds a message at the end of its session's queue; returns its position in the queue's order. */
639
+ enqueueMessage(row: Omit<QueuedMessageRow, "seq">): Promise<number>;
640
+ /** A session's queued messages, first to go first. */
641
+ queuedMessages(sessionId: string): Promise<QueuedMessageRow[]>;
642
+ countQueuedMessages(sessionId: string): Promise<number>;
643
+ /** Removes queued messages a turn took. */
644
+ deleteQueuedMessages(ids: readonly string[]): Promise<void>;
645
+ agentTriggers(agentId: string): Promise<AgentTriggerRow[]>;
646
+ /** One trigger's state; with `lock`, its row is locked until the transaction ends. */
647
+ agentTrigger(agentId: string, triggerId: string, options?: {
648
+ lock?: boolean;
649
+ }): Promise<AgentTriggerRow | undefined>;
650
+ /** Inserts or replaces a trigger's state (its `createdAt` is kept). */
651
+ putAgentTrigger(row: AgentTriggerRow): Promise<void>;
652
+ deleteAgentTrigger(agentId: string, triggerId: string): Promise<void>;
653
+ /** Deletes an Agent's triggers and runs. */
654
+ deleteAgentTriggers(agentId: string): Promise<void>;
655
+ /**
656
+ * Active triggers with a next fire time (due by `dueBefore`, changed since `changedSince`, when
657
+ * given), by Agent and trigger id.
658
+ */
659
+ activeTriggers(options: {
660
+ dueBefore?: string;
661
+ changedSince?: string;
662
+ after?: {
663
+ agentId: string;
664
+ triggerId: string;
665
+ };
666
+ limit: number;
667
+ }): Promise<AgentTriggerRow[]>;
668
+ /** The webhook trigger whose endpoint id is `endpointId`. */
669
+ agentTriggerByEndpoint(endpointId: string): Promise<AgentTriggerRow | undefined>;
670
+ /** The earliest next fire time of an Agent's active triggers, or `null`. */
671
+ nextWakeAt(agentId: string): Promise<string | null>;
672
+ /** Records a run; false when one with the same `runKey` exists for the Agent. */
673
+ insertTriggerRun(row: TriggerRunRow): Promise<boolean>;
674
+ triggerRunByKey(agentId: string, runKey: string): Promise<TriggerRunRow | undefined>;
675
+ updateTriggerRun(id: string, patch: Partial<Omit<TriggerRunRow, "id">>): Promise<void>;
676
+ /** An Agent's runs fired at or after `since` with one of `statuses`. */
677
+ countTriggerRuns(agentId: string, since: string, statuses: readonly TriggerRunRow["status"][]): Promise<number>;
678
+ /** An Agent's runs, newest first, before run id `before`. */
679
+ listTriggerRuns(agentId: string, options: {
680
+ triggerId?: string;
681
+ before?: string;
682
+ limit: number;
683
+ }): Promise<TriggerRunRow[]>;
684
+ /** Deletes runs fired before `before`; returns how many. */
685
+ pruneTriggerRuns(before: string): Promise<number>;
686
+ /** One memory; with `lock`, its path is locked until the transaction ends, whether or not a row has it. */
687
+ memory(agentId: string, path: string, options?: {
688
+ lock?: boolean;
689
+ }): Promise<MemoryRow | undefined>;
690
+ /**
691
+ * An Agent's memories by path: those inside `folder` (a normalised folder path, `/memories` for
692
+ * all), after path `after`; with `lock`, their rows are locked until the transaction ends.
693
+ */
694
+ memories(agentId: string, options: {
695
+ folder?: string;
696
+ after?: string;
697
+ limit?: number;
698
+ lock?: boolean;
699
+ }): Promise<MemoryRow[]>;
700
+ countMemories(agentId: string): Promise<number>;
701
+ /** An Agent's newest memories first (by `updatedAt`, then path): what the pinned index lists. */
702
+ recentMemories(agentId: string, limit: number): Promise<Pick<MemoryRow, "path" | "description" | "bytes">[]>;
703
+ /** Inserts or replaces a memory. */
704
+ putMemory(row: MemoryRow): Promise<void>;
705
+ deleteMemory(agentId: string, path: string): Promise<void>;
706
+ insertMemoryVersion(row: MemoryVersionRow): Promise<void>;
707
+ /** An Agent's memory versions, newest first, before version id `before`; `path` keeps one path's. */
708
+ memoryVersions(agentId: string, options: {
709
+ path?: string;
710
+ before?: string;
711
+ limit: number;
712
+ }): Promise<MemoryVersionRow[]>;
713
+ memoryVersion(agentId: string, id: string): Promise<MemoryVersionRow | undefined>;
714
+ /** Copies Agent `from`'s memories to new Agent `to`, each at version 1, with no history (a fork). */
715
+ copyMemories(from: string, to: string, now: string): Promise<number>;
716
+ /** Deletes an Agent's memories and their versions. */
717
+ deleteAgentMemories(agentId: string): Promise<void>;
612
718
  /** Links of one workflow session joined to their existing agent sessions, ordered by agent session id. */
613
719
  linkedSessions<S extends SessionDoc = SessionDoc>(workflowSessionId: string): Promise<LinkedSession<S>[]>;
614
720
  counts(): Promise<StoreCounts>;
@@ -732,6 +838,8 @@ export interface Tx {
732
838
  /** One version, or every version oldest first. */
733
839
  artifactVersion(artifactId: string, version: number): Promise<ArtifactVersionRow | undefined>;
734
840
  artifactVersions(artifactId: string): Promise<ArtifactVersionRow[]>;
841
+ /** The version a harness write with this key stored (`artifact_versions.write_key`), if any. */
842
+ artifactVersionByWriteKey(writeKey: string): Promise<ArtifactVersionRow | undefined>;
735
843
  /** Deletes the artifact and its versions; returns the versions' blob keys (empty when none). */
736
844
  deleteArtifact(id: string): Promise<string[]>;
737
845
  /**
@@ -746,9 +854,12 @@ export interface Tx {
746
854
  lockArtifactQuota(): Promise<void>;
747
855
  /**
748
856
  * The bytes the artifacts store: every file version, plus each distinct content-addressed file
749
- * of the folders once (F8.2).
857
+ * of the folders once (F8.2). With `environmentId`, only that Environment's artifacts: its disk
858
+ * versions and its sessions' artifacts.
750
859
  */
751
- artifactBytes(): Promise<number>;
860
+ artifactBytes(scope?: {
861
+ environmentId: string;
862
+ }): Promise<number>;
752
863
  /**
753
864
  * The blob keys of every artifact version (a folder's: its manifests): of session artifacts
754
865
  * only, or of all of them.
@@ -759,8 +870,13 @@ export interface Tx {
759
870
  sha256: string;
760
871
  size: number;
761
872
  }[]): Promise<void>;
762
- /** Those of `shas` some committed folder version references. */
763
- referencedArtifactContent(shas: readonly string[]): Promise<Set<string>>;
873
+ /**
874
+ * Those of `shas` some committed folder version references; with `environmentId`, a version
875
+ * of one of that Environment's artifacts.
876
+ */
877
+ referencedArtifactContent(shas: readonly string[], scope?: {
878
+ environmentId: string;
879
+ }): Promise<Set<string>>;
764
880
  /**
765
881
  * The distinct content-addressed files folder versions reference: of one artifact, of session
766
882
  * artifacts only, or of all of them.
@@ -772,8 +888,8 @@ export interface Tx {
772
888
  definitionFile(sha256: string): Promise<DefinitionFileRow | undefined>;
773
889
  /** Records a stored definition file; false when the Tenant held it already. */
774
890
  insertDefinitionFile(row: DefinitionFileRow): Promise<boolean>;
775
- /** Those of `shas` the Tenant holds. */
776
- heldDefinitionFiles(shas: readonly string[]): Promise<Set<string>>;
891
+ /** Those of `shas` the Tenant holds, with each one's size in bytes. */
892
+ heldDefinitionFiles(shas: readonly string[]): Promise<Map<string, number>>;
777
893
  /** Records that version `manifestHash` of definition `agentId` names each of `shas`. */
778
894
  insertDefinitionFileUses(agentId: string, manifestHash: string, shas: readonly string[]): Promise<void>;
779
895
  getSetting(key: string): Promise<string | undefined>;
@@ -784,16 +900,15 @@ export interface Tx {
784
900
  * Tenant's record rows and log heads. The Tenant moves to the next basin
785
901
  * generation and the current one is retired, so session ids it frees start again in an
786
902
  * empty basin;
787
- * - `environments`: sandbox records, Environments with their vaults, and their lifecycle
788
- * streams;
789
- * - `all`: both, plus definitions (and which definition files they use),
903
+ * - `agents`: sandbox records, Agents with their vaults, and their lifecycle streams;
904
+ * - `all`: both, plus agent manifests (and which definition files they use),
790
905
  * the model usage ledger, the model budgets and Tenant-wide artifacts. The host vault, principals, signing keys,
791
906
  * settings, audit and vault idempotency rows stay.
792
907
  */
793
908
  reset(scope: ResetScope): Promise<void>;
794
909
  }
795
- /** Which of an Environment's events to read (`Tx.environmentEvents`). */
796
- export interface EnvironmentEventsQuery {
910
+ /** Which of an Agent's events to read (`Tx.agentEvents`). */
911
+ export interface AgentEventsQuery {
797
912
  readonly fromSeq?: number;
798
913
  readonly limit?: number;
799
914
  readonly types?: readonly string[];
@@ -1,5 +1,4 @@
1
1
  export const DOC_TABLES = [
2
- "definitions",
3
2
  "sessions",
4
3
  "commands",
5
4
  "effects",
@@ -6,11 +6,11 @@ export interface StreamRelayOptions {
6
6
  streams: DurableStreams;
7
7
  /** Relay events: lag, errors, reconciliations. */
8
8
  log?: (message: string, fields?: Record<string, unknown>) => void;
9
- /** Records per append (S2 allows 1000). */
9
+ /** Records per append (S2 allows 1000). Default `streams.relayBatchRecords` (Host tuning, 500). */
10
10
  maxBatchRecords?: number;
11
- /** Bytes per append (S2 allows 1 MiB). */
11
+ /** Bytes per append (S2 allows 1 MiB). Default `streams.relayBatchBytes` (768 KiB). */
12
12
  maxBatchBytes?: number;
13
- /** Sessions reconciled at once. */
13
+ /** Sessions reconciled at once. Default `streams.relayReconcileConcurrency` (8). */
14
14
  reconcileConcurrency?: number;
15
15
  }
16
16
  export interface StreamRelayStatus {
@@ -23,17 +23,16 @@
23
23
  * The relay never writes the record and never deletes from S2.
24
24
  */
25
25
  import { sleep } from "../../retry.js";
26
+ import { hostTuning } from "../../tuning.js";
26
27
  import { basinOf } from "../basin.js";
27
28
  import { sessionStream } from "../types.js";
28
- const RETRY_MIN_MS = 50;
29
- const RETRY_MAX_MS = 2000;
30
- const HEADS_PAGE = 500;
31
29
  export function createStreamRelay(options) {
32
30
  const { source, record, streams } = options;
33
31
  const log = options.log ?? (() => { });
34
- const maxRecords = options.maxBatchRecords ?? 500;
35
- const maxBytes = options.maxBatchBytes ?? 768 * 1024;
36
- const concurrency = options.reconcileConcurrency ?? 8;
32
+ const tuning = hostTuning().streams;
33
+ const maxRecords = options.maxBatchRecords ?? tuning.relayBatchRecords;
34
+ const maxBytes = options.maxBatchBytes ?? tuning.relayBatchBytes;
35
+ const concurrency = options.reconcileConcurrency ?? tuning.relayReconcileConcurrency;
37
36
  /** Committed transactions not yet fully in S2, in commit order. */
38
37
  const txs = [];
39
38
  const sessions = new Map();
@@ -101,7 +100,7 @@ export function createStreamRelay(options) {
101
100
  }
102
101
  async function pump(queue) {
103
102
  queue.running = true;
104
- let delay = RETRY_MIN_MS;
103
+ let delay = tuning.relayRetry.minMs;
105
104
  try {
106
105
  while (queue.rows.length > 0 && !stopped) {
107
106
  // Duplicates (a replay overlapping a refill) and stale rows sort out here.
@@ -122,7 +121,7 @@ export function createStreamRelay(options) {
122
121
  // S2 is behind the record: re-send the gap first.
123
122
  await refill(queue, first.generation, result.tail, first.seq);
124
123
  }
125
- delay = RETRY_MIN_MS;
124
+ delay = tuning.relayRetry.minMs;
126
125
  lastError = null;
127
126
  }
128
127
  catch (error) {
@@ -143,7 +142,7 @@ export function createStreamRelay(options) {
143
142
  // The basin may be missing (S2 lost it, or it was never created).
144
143
  await streams.ensureTenant(basin).catch(() => undefined);
145
144
  await sleep(delay, stopping.signal);
146
- delay = Math.min(delay * 2, RETRY_MAX_MS);
145
+ delay = Math.min(delay * 2, tuning.relayRetry.maxMs);
147
146
  }
148
147
  }
149
148
  }
@@ -243,7 +242,7 @@ export function createStreamRelay(options) {
243
242
  for (;;) {
244
243
  if (!current())
245
244
  return false;
246
- const page = await record.heads(after, HEADS_PAGE);
245
+ const page = await record.heads(after, tuning.relayHeadsPage);
247
246
  if (page.length === 0)
248
247
  break;
249
248
  let next = 0;