@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
@@ -13,6 +13,8 @@ export interface TurnTiming {
13
13
  turnStartedAt?: string;
14
14
  /** The trace context the turn's message arrived with (R7.4); it ends with the turn. */
15
15
  turnTrace?: unknown;
16
+ /** What started the turn when not a client (track T4); it ends with the turn. */
17
+ turnCause?: unknown;
16
18
  pausedMs?: number;
17
19
  pausedAt?: string;
18
20
  }
@@ -25,16 +27,24 @@ export declare function resumeTurn(s: TurnTiming, now?: Date): void;
25
27
  /**
26
28
  * The facts the event that ends turn `turnId` carries: `durationMs` from its start to now, waits
27
29
  * included, so the turn's span holds every crossing in it; `pausedMs`, how long it waited paused
28
- * (a wait still open ends now, as for a cancel); the session's agent;
30
+ * (a wait still open ends now, as for a cancel); the session's Agent and the manifest version it runs;
29
31
  * and the turn's totals from the usage ledger (one read, as `/v1/tenant/usage` totals a turn;
30
32
  * `steps` are the model calls the gate metered). Clears the turn's timing from `s`.
31
33
  */
32
34
  export declare function endTurn(t: Tx, s: TurnTiming & {
33
35
  agentId: string;
36
+ definition?: {
37
+ name: string;
38
+ version: number;
39
+ };
34
40
  }, turnId: string | null, now?: Date): Promise<{
35
41
  durationMs?: number;
36
42
  pausedMs?: number;
37
43
  agentId: string;
44
+ manifest?: {
45
+ name: string;
46
+ version: number;
47
+ };
38
48
  totals?: {
39
49
  steps: number;
40
50
  tokens: number;
@@ -19,7 +19,7 @@ export function resumeTurn(s, now = new Date()) {
19
19
  /**
20
20
  * The facts the event that ends turn `turnId` carries: `durationMs` from its start to now, waits
21
21
  * included, so the turn's span holds every crossing in it; `pausedMs`, how long it waited paused
22
- * (a wait still open ends now, as for a cancel); the session's agent;
22
+ * (a wait still open ends now, as for a cancel); the session's Agent and the manifest version it runs;
23
23
  * and the turn's totals from the usage ledger (one read, as `/v1/tenant/usage` totals a turn;
24
24
  * `steps` are the model calls the gate metered). Clears the turn's timing from `s`.
25
25
  */
@@ -30,10 +30,12 @@ export async function endTurn(t, s, turnId, now = new Date()) {
30
30
  const facts = {
31
31
  ...(elapsed === undefined ? {} : { durationMs: Math.max(0, elapsed), pausedMs: s.pausedMs ?? 0 }),
32
32
  agentId: s.agentId,
33
+ ...(s.definition ? { manifest: { name: s.definition.name, version: s.definition.version } } : {}),
33
34
  ...(totals ? { totals: { steps: totals.calls, tokens: totals.tokens, costUsd: totals.costUsd } } : {}),
34
35
  };
35
36
  delete s.turnStartedAt;
36
37
  delete s.pausedMs;
37
38
  delete s.turnTrace;
39
+ delete s.turnCause;
38
40
  return facts;
39
41
  }
@@ -1,7 +1,6 @@
1
1
  import type { IncomingMessage, ServerResponse } from "node:http";
2
2
  import type { HarnessStatus, HostTenant, TenantEnvelope } from "@nylorun/core/contracts";
3
3
  import type { HarnessChannel } from "@nylorun/core/harness-api";
4
- import type { FlowLimits } from "../core/limits.js";
5
4
  import type { HarnessPeer } from "../harness-api/server.js";
6
5
  import type { HostAuthority } from "../sandbox/join.js";
7
6
  import type { SessionStore } from "../store/types.js";
@@ -45,35 +44,31 @@ export interface TenantConfig {
45
44
  /**
46
45
  * Segment rollover (Model Calls §10): a turn ends its segment at a step boundary after this
47
46
  * many steps or milliseconds and continues in a new one, so no advance reaches its
48
- * deadline. Default 50 steps or 20 minutes.
47
+ * deadline. Default the Host tuning's `harnessApi.rolloverSteps` and `rolloverMs` (50 steps,
48
+ * 20 minutes).
49
49
  */
50
50
  rollover?: {
51
51
  steps?: number;
52
52
  ms?: number;
53
53
  };
54
- /** Retries and timeouts for model calls (Model Calls §5, §6). Defaults in `piModel`. */
55
- modelCall?: import("../gates/model-gate.js").ModelCallSettings;
56
54
  /**
57
55
  * How the Runtime may call MCP servers and HTTP tools (Host settings). Default: http and
58
56
  * private addresses allowed.
59
57
  */
60
58
  delivery?: OutboundPolicy;
61
- /** Bounds the default Tenant sweep interval (`sweepIntervalMs`). Default 30 s. */
59
+ /** Bounds the default Tenant sweep interval (`sweepIntervalMs`). Default: no bound. */
62
60
  leaseMs?: number;
63
- /** Ownership lease of an advance (§10.6); renewed every third while it runs. Default 30 s. */
61
+ /**
62
+ * Ownership lease of an advance (§10.6); renewed every third while it runs. Default the Host
63
+ * tuning's `tenant.ownerLeaseMs` (30 s).
64
+ */
64
65
  ownerLeaseMs?: number;
65
66
  /**
66
67
  * Delay between Tenant sweep passes when the Tenant runs its own in-process execution.
67
- * Default `min(leaseMs, 5 s)`. A Host-level execution sets its own.
68
+ * Default `min(leaseMs, sweep.intervalMs)` (Host tuning, 5 s). A Host-level execution sets its
69
+ * own.
68
70
  */
69
71
  sweepIntervalMs?: number;
70
- /** Operator flow limits (`RuntimeOptions.flow` / `workflows.md` §13). */
71
- flow?: Partial<FlowLimits>;
72
- /**
73
- * Optional env snapshot for `NYLORUN_FLOW_*`. Host passes this; the Runtime
74
- * never reads ambient process environment for flow limits.
75
- */
76
- flowEnv?: Readonly<Record<string, string | undefined>>;
77
72
  /**
78
73
  * The trusted issuers whose JWTs the Runtime API accepts (Host feature `trusted-issuers`), from
79
74
  * the identity file (`NYLORUN_IDENTITY_FILE`). Absent: none.
@@ -4,14 +4,6 @@ import type { AdvanceResult, SandboxResult, SandboxTrigger, DurableExecution, St
4
4
  import type { Logger } from "./types.js";
5
5
  /** This process's Worker id: the `owner` it writes on the sessions it advances (§10.6). */
6
6
  export declare const WORKER_ID: string;
7
- /**
8
- * Default advance deadline: 50 minutes, below the one-hour inactivity and abort timeouts the
9
- * Restate adapter sets on the session object, so an advance always ends before Restate gives
10
- * up on it.
11
- */
12
- export declare const DEFAULT_ADVANCE_DEADLINE_MS: number;
13
- /** Default time an aborted advance has to settle before it is abandoned. */
14
- export declare const DEFAULT_ADVANCE_GRACE_MS = 30000;
15
7
  /** Why an advance's signal aborted (see "Abort reasons" above). */
16
8
  export type AdvanceAbortKind = AbortReason;
17
9
  /**
@@ -44,15 +36,17 @@ export interface TenantWorker {
44
36
  sweep(): Promise<void>;
45
37
  /** Reconciles one pod sandbox (F7.2). Only infrastructure errors throw. */
46
38
  sandbox?(sandboxId: string, trigger: SandboxTrigger, signal: AbortSignal): Promise<SandboxResult>;
39
+ /** A durable timer it armed fired (track T4's triggers). Only infrastructure errors throw. */
40
+ fire?(key: string): Promise<void>;
47
41
  }
48
42
  export interface TenantWorkersOptions {
49
43
  /** Finds or opens a Tenant that is not registered on this process. */
50
44
  resolve?: (tenantId: string) => Promise<TenantWorker | undefined>;
51
- /** How long one advance may run before its signal aborts. Default `DEFAULT_ADVANCE_DEADLINE_MS`. */
45
+ /** How long one advance may run before its signal aborts. Default `execution.advanceDeadlineMs` (Host tuning, 50 minutes). */
52
46
  advanceDeadlineMs?: number;
53
47
  /**
54
48
  * How long an advance whose signal aborted has to return before it is abandoned.
55
- * Default `DEFAULT_ADVANCE_GRACE_MS`.
49
+ * Default `execution.advanceGraceMs` (Host tuning, 30 s).
56
50
  */
57
51
  advanceGraceMs?: number;
58
52
  /** Receives a warning for each abandoned advance. */
@@ -51,16 +51,9 @@
51
51
  import { hostname } from "node:os";
52
52
  import { randomBytes } from "node:crypto";
53
53
  import { RunAbort } from "@nylorun/harness/api";
54
+ import { hostTuning, MAX_TIMER_MS } from "../tuning.js";
54
55
  /** This process's Worker id: the `owner` it writes on the sessions it advances (§10.6). */
55
56
  export const WORKER_ID = `worker-${hostname()}-${process.pid}-${randomBytes(4).toString("hex")}`;
56
- /**
57
- * Default advance deadline: 50 minutes, below the one-hour inactivity and abort timeouts the
58
- * Restate adapter sets on the session object, so an advance always ends before Restate gives
59
- * up on it.
60
- */
61
- export const DEFAULT_ADVANCE_DEADLINE_MS = 50 * 60_000;
62
- /** Default time an aborted advance has to settle before it is abandoned. */
63
- export const DEFAULT_ADVANCE_GRACE_MS = 30_000;
64
57
  /**
65
58
  * The abort reason of an advance. A harness run's reason (`RunAbort`) has the same kinds, so the
66
59
  * executors read either one.
@@ -109,8 +102,8 @@ export class TenantWorkers {
109
102
  graceMs;
110
103
  constructor(options = {}) {
111
104
  this.options = options;
112
- this.deadlineMs = positive("advanceDeadlineMs", options.advanceDeadlineMs ?? DEFAULT_ADVANCE_DEADLINE_MS);
113
- this.graceMs = positive("advanceGraceMs", options.advanceGraceMs ?? DEFAULT_ADVANCE_GRACE_MS);
105
+ this.deadlineMs = positive("advanceDeadlineMs", options.advanceDeadlineMs ?? hostTuning().execution.advanceDeadlineMs);
106
+ this.graceMs = positive("advanceGraceMs", options.advanceGraceMs ?? hostTuning().execution.advanceGraceMs);
114
107
  }
115
108
  /** Registers an open Tenant's worker; the returned function unregisters exactly it. */
116
109
  register(tenantId, worker) {
@@ -139,6 +132,11 @@ export class TenantWorkers {
139
132
  const worker = await this.find(tenantId);
140
133
  return worker?.sandbox ? worker.sandbox(sandboxId, trigger, signal) : {};
141
134
  },
135
+ // A timer of a Tenant that is not open here does nothing: the Tenant's sweep arms what is due
136
+ // once it opens.
137
+ fire: async (tenantId, key) => {
138
+ await (await this.find(tenantId))?.fire?.(key);
139
+ },
142
140
  };
143
141
  /** Runs one advance under the deadline and the grace period (see the module comment). */
144
142
  async bounded(tenantId, sessionId, worker, signal) {
@@ -187,10 +185,8 @@ export class TenantWorkers {
187
185
  }
188
186
  }
189
187
  }
190
- /** The longest delay `setTimeout` keeps (about 24.8 days). */
191
- const MAX_TIMEOUT_MS = 2 ** 31 - 1;
192
188
  function positive(name, value) {
193
- if (!Number.isFinite(value) || value <= 0 || value > MAX_TIMEOUT_MS)
194
- throw new Error(`${name} must be positive and at most ${MAX_TIMEOUT_MS}`);
189
+ if (!Number.isFinite(value) || value <= 0 || value > MAX_TIMER_MS)
190
+ throw new Error(`${name} must be positive and at most ${MAX_TIMER_MS}`);
195
191
  return value;
196
192
  }
@@ -45,7 +45,11 @@ export function parseTraceparent(value) {
45
45
  return undefined;
46
46
  return { traceId: traceId, spanId: spanId };
47
47
  }
48
- /** The most `tracestate` the Runtime keeps (W3C: 32 members, 512 characters is enough). */
48
+ /**
49
+ * The most `tracestate` the Runtime keeps: W3C Trace Context (Level 1, section 3.3.1.1) has
50
+ * vendors propagate at least 512 characters of it, and lets one cut what is past that. A
51
+ * standard's constant, not a limit (B15).
52
+ */
49
53
  const TRACESTATE_MAX = 512;
50
54
  /**
51
55
  * The trace context a request's headers carry (R7.4), or undefined without a valid
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * | Row | Span |
7
7
  * | --- | --- |
8
- * | `turn.completed`, `turn.failed`, `turn.cancelled` | `invoke_agent {agentId}`, the turn's root (INTERNAL) |
8
+ * | `turn.completed`, `turn.failed`, `turn.cancelled` | `invoke_agent {manifest name}`, the turn's root (INTERNAL) |
9
9
  * | `message.assistant`, `model.failed`, `context.compacted` | `chat {model}` (CLIENT) |
10
10
  * | `tool.completed` | `execute_tool {toolName}` (INTERNAL) |
11
11
  * | `node.completed` | `execute_tool {key}`, a flow's HTTP stage (INTERNAL) |
@@ -25,7 +25,8 @@
25
25
  * never carries a person's id (`ownerUserId`, a subject, who approved), an identity header, an
26
26
  * idempotency key or a credential value (the log holds none). Content (what a person said, the
27
27
  * model's output, tool results and error messages) is left out unless the installation opts in
28
- * per kind (`TraceContent`), each value cut at 8 KiB. Prompts are not in the log, so never here.
28
+ * per kind (`TraceContent`), each value cut at the Tenant's Runtime limit `traceContentBytes`
29
+ * (`SpanSettings.contentBytes`). Prompts are not in the log, so never here.
29
30
  */
30
31
  import type { LiveEvent } from "@nylorun/core/contracts";
31
32
  import { type TraceKey } from "./ids.js";
@@ -39,8 +40,6 @@ export declare const GENAI_SEMCONV = "open-telemetry/semantic-conventions-genai@
39
40
  export declare const TRACE_CONTENT_KINDS: readonly ["user", "outputs", "tool-results", "errors"];
40
41
  export type TraceContentKind = (typeof TRACE_CONTENT_KINDS)[number];
41
42
  export type TraceContent = ReadonlySet<TraceContentKind>;
42
- /** The most bytes of one content attribute or status message. */
43
- export declare const CONTENT_MAX_BYTES: number;
44
43
  /** OTLP span kinds and status codes (opentelemetry-proto `trace.proto`). */
45
44
  export declare const SPAN_KIND: {
46
45
  readonly internal: 1;
@@ -93,10 +92,14 @@ export interface TurnTrace {
93
92
  /** What a person sent, as `gen_ai.input.messages` (only with `user` content). */
94
93
  readonly input?: string;
95
94
  }
96
- /** How spans are made: the trace key and the content the installation exports. */
95
+ /**
96
+ * How spans are made: the trace key, the content the installation exports, and the most UTF-8
97
+ * bytes of one content attribute (the Tenant's Runtime limit `traceContentBytes`).
98
+ */
97
99
  export interface SpanSettings {
98
100
  readonly key: TraceKey;
99
101
  readonly content: TraceContent;
102
+ readonly contentBytes: number;
100
103
  }
101
104
  /**
102
105
  * The trace of turn `turnId` of session `sessionId`, from its `command.message` when the log has
@@ -109,5 +112,5 @@ export declare function turnTraceOf(settings: SpanSettings, ids: {
109
112
  }, message?: Pick<LiveEvent, "payload" | "principal"> | undefined): TurnTrace;
110
113
  /** The span `row` makes in its turn's trace, or undefined when it makes none. */
111
114
  export declare function spanOf(row: LiveEvent, turn: TurnTrace, settings: SpanSettings): OtlpSpan | undefined;
112
- /** `value` cut to `CONTENT_MAX_BYTES` of UTF-8, never in the middle of a character. */
113
- export declare function truncate(value: string): string;
115
+ /** `value` cut to `maxBytes` of UTF-8, never in the middle of a character. */
116
+ export declare function truncate(value: string, maxBytes: number): string;
@@ -7,8 +7,6 @@ export const GENAI_SEMCONV = "open-telemetry/semantic-conventions-genai@6fd0d763
7
7
  * (error messages; their codes are always exported).
8
8
  */
9
9
  export const TRACE_CONTENT_KINDS = ["user", "outputs", "tool-results", "errors"];
10
- /** The most bytes of one content attribute or status message. */
11
- export const CONTENT_MAX_BYTES = 8 * 1024;
12
10
  /** OTLP span kinds and status codes (opentelemetry-proto `trace.proto`). */
13
11
  export const SPAN_KIND = { internal: 1, client: 3 };
14
12
  export const STATUS = { unset: 0, ok: 1, error: 2 };
@@ -19,7 +17,7 @@ export const STATUS = { unset: 0, ok: 1, error: 2 };
19
17
  export function turnTraceOf(settings, ids, message) {
20
18
  const payload = (message?.payload ?? {});
21
19
  const inbound = typeof payload.trace?.traceparent === "string" ? parseTraceparent(payload.trace.traceparent) : undefined;
22
- const input = settings.content.has("user") && message ? userMessages(payload) : undefined;
20
+ const input = settings.content.has("user") && message ? userMessages(payload, settings.contentBytes) : undefined;
23
21
  return {
24
22
  traceId: inbound?.traceId ?? traceIdOf(settings.key, ids.tenantId, ids.sessionId, ids.turnId),
25
23
  spanId: turnSpanOf(settings.key, ids.turnId),
@@ -52,17 +50,23 @@ export function spanOf(row, turn, settings) {
52
50
  const effectSpan = (effectId) => typeof effectId === "string" && effectId.length > 0
53
51
  ? effectSpanOf(settings.key, effectId)
54
52
  : eventSpanOf(settings.key, row.sessionId, row.seq);
55
- const content = (kind, value) => settings.content.has(kind) && value !== undefined ? truncate(typeof value === "string" ? value : JSON.stringify(value)) : undefined;
53
+ const content = (kind, value) => settings.content.has(kind) && value !== undefined ? truncate(typeof value === "string" ? value : JSON.stringify(value), settings.contentBytes) : undefined;
56
54
  switch (row.type) {
57
55
  case "turn.completed":
58
56
  case "turn.failed":
59
57
  case "turn.cancelled": {
60
58
  const status = row.type.slice("turn.".length);
59
+ // The agent the turn ran: its manifest's name (protocol 16), else the Agent's id.
60
+ const manifest = p.manifest;
61
+ const agentName = typeof manifest?.name === "string" ? manifest.name : typeof p.agentId === "string" ? p.agentId : undefined;
61
62
  const totals = p.totals;
62
63
  const error = row.type === "turn.failed" ? (p.error ?? {}) : undefined;
63
64
  const attributes = base
64
65
  .str("gen_ai.operation.name", "invoke_agent")
65
66
  .str("gen_ai.agent.id", p.agentId)
67
+ .str("gen_ai.agent.name", agentName)
68
+ // The agent manifest version the turn ran (T3): an Agent moves between versions.
69
+ .int("nylorun.manifest.version", typeof manifest?.version === "number" ? manifest.version : undefined)
66
70
  .str("nylorun.turn.status", status)
67
71
  .int("nylorun.turn.paused_ms", p.pausedMs)
68
72
  .int("nylorun.turn.steps", totals?.steps)
@@ -78,7 +82,7 @@ export function spanOf(row, turn, settings) {
78
82
  traceId: turn.traceId,
79
83
  spanId: turn.spanId,
80
84
  ...(turn.parentSpanId ? { parentSpanId: turn.parentSpanId } : {}),
81
- name: typeof p.agentId === "string" ? `invoke_agent ${p.agentId}` : "invoke_agent",
85
+ name: agentName === undefined ? "invoke_agent" : `invoke_agent ${agentName}`,
82
86
  kind: SPAN_KIND.internal,
83
87
  ...window(row.time, p.durationMs),
84
88
  attributes: attributes.list,
@@ -132,7 +136,6 @@ export function spanOf(row, turn, settings) {
132
136
  .str("nylorun.effect.id", p.effectId)
133
137
  .int("nylorun.effect.window_ms", p.durationMs)
134
138
  .str("nylorun.compaction.trigger", row.type === "context.compacted" ? p.trigger : undefined)
135
- .bool("nylorun.compaction.partial", row.type === "context.compacted" && p.partial === true ? true : undefined)
136
139
  .str("error.type", row.type === "model.failed" ? p.code : undefined)
137
140
  .str("gen_ai.output.messages", output);
138
141
  return {
@@ -158,6 +161,7 @@ export function spanOf(row, turn, settings) {
158
161
  .str("gen_ai.agent.id", p.agent?.id)
159
162
  .str("nylorun.tool.kind", kind)
160
163
  .str("nylorun.tool.server", p.server)
164
+ .str("nylorun.tool.identity", p.tool)
161
165
  .str("nylorun.tool.status", p.status)
162
166
  .int("nylorun.tool.attempts", p.attempts)
163
167
  .int("nylorun.tool.redacted", p.redacted)
@@ -264,7 +268,7 @@ function textPart(value) {
264
268
  return { type: "text", content: typeof value === "string" ? value : JSON.stringify(value) };
265
269
  }
266
270
  /** What a person sent (`command.message`), as `gen_ai.input.messages`. */
267
- function userMessages(payload) {
271
+ function userMessages(payload, maxBytes) {
268
272
  const parts = typeof payload.content === "string"
269
273
  ? [{ type: "text", content: payload.content }]
270
274
  : Array.isArray(payload.parts)
@@ -274,14 +278,14 @@ function userMessages(payload) {
274
278
  : payload.data !== undefined
275
279
  ? [textPart(payload.data)]
276
280
  : undefined;
277
- return parts ? truncate(JSON.stringify([{ role: "user", parts }])) : undefined;
281
+ return parts ? truncate(JSON.stringify([{ role: "user", parts }]), maxBytes) : undefined;
278
282
  }
279
- /** `value` cut to `CONTENT_MAX_BYTES` of UTF-8, never in the middle of a character. */
280
- export function truncate(value) {
283
+ /** `value` cut to `maxBytes` of UTF-8, never in the middle of a character. */
284
+ export function truncate(value, maxBytes) {
281
285
  const bytes = Buffer.from(value, "utf8");
282
- if (bytes.length <= CONTENT_MAX_BYTES)
286
+ if (bytes.length <= maxBytes)
283
287
  return value;
284
- let end = CONTENT_MAX_BYTES;
288
+ let end = maxBytes;
285
289
  // Back up over continuation bytes (10xxxxxx) to the start of the cut character.
286
290
  while (end > 0 && (bytes[end] & 0xc0) === 0x80)
287
291
  end -= 1;
@@ -28,11 +28,11 @@ export interface OtlpPosterOptions {
28
28
  /** `OTEL_EXPORTER_OTLP_HEADERS`. */
29
29
  readonly headers?: Readonly<Record<string, string>>;
30
30
  readonly resource: TraceResource;
31
- /** Tries after the first, for a `429`, a `5xx` or a lost connection. Default 3. */
31
+ /** Tries after the first, for a `429`, a `5xx` or a lost connection. Default `traces.retries` (Host tuning, 3). */
32
32
  readonly retries?: number;
33
- /** The wait before the first retry, doubled for each one after. Default 500 ms. */
33
+ /** The wait before the first retry, doubled for each one after. Default `traces.backoffMs` (500 ms). */
34
34
  readonly backoffMs?: number;
35
- /** How long one request may take. Default 10 s. */
35
+ /** How long one request may take. Default `traces.timeoutMs` (10 s). */
36
36
  readonly timeoutMs?: number;
37
37
  readonly fetch?: typeof fetch;
38
38
  readonly log?: (message: string, fields?: Record<string, unknown>) => void;
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { RUNTIME_VERSION } from "../version.js";
12
12
  import { GENAI_SEMCONV } from "./map.js";
13
+ import { hostTuning } from "../tuning.js";
13
14
  export const DEFAULT_SERVICE_NAME = "nylorun";
14
15
  /** The instrumentation scope of every span. */
15
16
  const SCOPE = { name: "@nylorun/runtime", version: RUNTIME_VERSION };
@@ -27,9 +28,10 @@ export function resourceSpans(resource, spans) {
27
28
  }
28
29
  export function createOtlpPoster(options) {
29
30
  const send = options.fetch ?? fetch;
30
- const retries = options.retries ?? 3;
31
- const backoffMs = options.backoffMs ?? 500;
32
- const timeoutMs = options.timeoutMs ?? 10_000;
31
+ const tuning = hostTuning().traces;
32
+ const retries = options.retries ?? tuning.retries;
33
+ const backoffMs = options.backoffMs ?? tuning.backoffMs;
34
+ const timeoutMs = options.timeoutMs ?? tuning.timeoutMs;
33
35
  const log = options.log ?? (() => { });
34
36
  return async (spans, signal) => {
35
37
  if (spans.length === 0)
@@ -27,16 +27,21 @@ export interface TraceProjectorOptions {
27
27
  readonly post: OtlpPoster;
28
28
  /** The Tenant's trace key (`traces/key.ts`). */
29
29
  readonly key: () => Promise<TraceKey>;
30
+ /** The Tenant's Runtime limit `traceContentBytes`, read for each transaction mapped. */
31
+ readonly contentBytes: () => Promise<number>;
30
32
  /** The `command.message` that started turn `turnId`, or undefined when the log has none. */
31
33
  readonly turnMessage: (sessionId: string, turnId: string) => Promise<LiveEvent | undefined>;
32
34
  readonly content: TraceContent;
33
- /** Spans per post. Default 512. */
35
+ /** Spans per post. Default `traces.batchSpans` (Host tuning, 512). */
34
36
  readonly maxBatch?: number;
35
- /** How long a span waits for its batch to fill. Default 2 s. */
37
+ /** How long a span waits for its batch to fill. Default `traces.batchDelayMs` (2 s). */
36
38
  readonly maxDelayMs?: number;
37
- /** Spans waiting while a post is out, past which the waiting ones are dropped. Default 8192. */
39
+ /**
40
+ * Spans waiting while a post is out, past which the waiting ones are dropped. Default
41
+ * `traces.queuedSpansMax` (8192).
42
+ */
38
43
  readonly maxQueuedSpans?: number;
39
- /** Turns whose trace is kept. Default 1024. */
44
+ /** Turns whose trace is kept. Default `traces.turnCacheSize` (1024). */
40
45
  readonly turnCacheSize?: number;
41
46
  readonly log?: (message: string, fields?: Record<string, unknown>) => void;
42
47
  }
@@ -1,13 +1,15 @@
1
1
  import { spanOf, turnTraceOf } from "./map.js";
2
+ import { hostTuning } from "../tuning.js";
2
3
  /** The projector's replication slot. */
3
4
  export const TRACE_SLOT = "nylorun_trace_export";
4
5
  export function createTraceProjector(options) {
5
6
  const { source, post } = options;
6
7
  const log = options.log ?? (() => { });
7
- const maxBatch = options.maxBatch ?? 512;
8
- const maxDelayMs = options.maxDelayMs ?? 2000;
9
- const maxQueued = options.maxQueuedSpans ?? 8192;
10
- const cacheSize = options.turnCacheSize ?? 1024;
8
+ const tuning = hostTuning().traces;
9
+ const maxBatch = options.maxBatch ?? tuning.batchSpans;
10
+ const maxDelayMs = options.maxDelayMs ?? tuning.batchDelayMs;
11
+ const maxQueued = options.maxQueuedSpans ?? tuning.queuedSpansMax;
12
+ const cacheSize = options.turnCacheSize ?? tuning.turnCacheSize;
11
13
  const turns = new Map();
12
14
  const stopping = new AbortController();
13
15
  /** Mapped transactions not yet posted, in commit order. */
@@ -17,6 +19,8 @@ export function createTraceProjector(options) {
17
19
  let mapping = Promise.resolve();
18
20
  let mappingCount = 0;
19
21
  let posting;
22
+ /** Transactions of the batch being posted: not acknowledged until the post settles. */
23
+ let postingTxs = 0;
20
24
  let timer;
21
25
  let active = false;
22
26
  let confirmed = null;
@@ -45,7 +49,7 @@ export function createTraceProjector(options) {
45
49
  const spans = [];
46
50
  if (tx.rows.length === 0)
47
51
  return spans;
48
- const settings = { key: await options.key(), content: options.content };
52
+ const settings = { key: await options.key(), content: options.content, contentBytes: await options.contentBytes() };
49
53
  for (const record of tx.rows) {
50
54
  const row = record.body;
51
55
  if (!row || typeof row !== "object" || row.turnId == null)
@@ -72,7 +76,7 @@ export function createTraceProjector(options) {
72
76
  if (of !== activation || stopping.signal.aborted)
73
77
  return;
74
78
  log("trace_projector_retry", { message: error instanceof Error ? error.message : String(error) });
75
- await new Promise((resolve) => setTimeout(resolve, 1000));
79
+ await new Promise((resolve) => setTimeout(resolve, tuning.retryMs));
76
80
  }
77
81
  }
78
82
  if (of !== activation)
@@ -115,6 +119,7 @@ export function createTraceProjector(options) {
115
119
  const batch = waiting;
116
120
  waiting = [];
117
121
  waitingSpans = 0;
122
+ postingTxs = batch.length;
118
123
  posting = (async () => {
119
124
  const spans = batch.flatMap((tx) => tx.spans);
120
125
  // A post a shutdown cut short is not the collector's failure: those rows go again.
@@ -129,6 +134,7 @@ export function createTraceProjector(options) {
129
134
  }
130
135
  })().finally(() => {
131
136
  posting = undefined;
137
+ postingTxs = 0;
132
138
  schedule();
133
139
  settle();
134
140
  });
@@ -186,7 +192,7 @@ export function createTraceProjector(options) {
186
192
  },
187
193
  status: () => ({
188
194
  active,
189
- pendingTxs: waiting.length + mappingCount,
195
+ pendingTxs: waiting.length + mappingCount + postingTxs,
190
196
  pendingSpans: waitingSpans,
191
197
  confirmed,
192
198
  }),
@@ -1,9 +1,14 @@
1
1
  import { traceKey } from "./key.js";
2
+ import { readRuntimeLimits } from "../tenant/runtime-limits.js";
2
3
  import { spanOf, turnTraceOf } from "./map.js";
3
4
  import { DEFAULT_SERVICE_NAME, resourceSpans } from "./otlp.js";
4
5
  /** Turn `turnId`'s spans as an OTLP `ExportTraceServiceRequest`, from its rows in log order. */
5
6
  export async function turnTrace(ctx, sessionId, turnId, events) {
6
- const settings = { key: await traceKey(ctx.store), content: ctx.traces?.content ?? new Set() };
7
+ const settings = {
8
+ key: await traceKey(ctx.store),
9
+ content: ctx.traces?.content ?? new Set(),
10
+ contentBytes: (await ctx.store.tx((t) => readRuntimeLimits(t))).traceContentBytes,
11
+ };
7
12
  const message = events.find((event) => event.type === "command.message");
8
13
  const turn = turnTraceOf(settings, { tenantId: ctx.store.tenantId, sessionId, turnId }, message);
9
14
  const spans = [];