@nylorun/runtime 0.22.0-beta → 0.24.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 (273) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/README.md +95 -30
  3. package/dist/adapters/execution/restate.d.ts +15 -3
  4. package/dist/adapters/execution/restate.js +78 -84
  5. package/dist/adapters/replication/pgoutput.d.ts +2 -0
  6. package/dist/adapters/replication/pgoutput.js +6 -3
  7. package/dist/adapters/sandbox/local.d.ts +9 -1
  8. package/dist/adapters/sandbox/local.js +16 -4
  9. package/dist/adapters/sandbox/virtual.js +4 -1
  10. package/dist/adapters/streams/s2.js +1 -13
  11. package/dist/api/a2a/endpoint.js +5 -1
  12. package/dist/api/a2a/routes.d.ts +2 -0
  13. package/dist/api/a2a/routes.js +2 -2
  14. package/dist/api/a2a/tasks.js +2 -1
  15. package/dist/api/ag-ui/endpoint.js +4 -2
  16. package/dist/api/ag-ui/history.js +4 -1
  17. package/dist/api/ag-ui/routes.d.ts +4 -1
  18. package/dist/api/ag-ui/routes.js +11 -10
  19. package/dist/api/ag-ui/translate.js +3 -2
  20. package/dist/api/components.d.ts +4953 -1204
  21. package/dist/api/components.js +25 -16
  22. package/dist/api/gate/keys.js +7 -1
  23. package/dist/api/gate/routes.d.ts +6 -0
  24. package/dist/api/gate/routes.js +39 -3
  25. package/dist/api/http/app.js +4 -4
  26. package/dist/api/http/define.d.ts +6 -0
  27. package/dist/api/http/define.js +13 -1
  28. package/dist/api/http/respond.js +1 -1
  29. package/dist/api/http/routes/artifacts.js +35 -8
  30. package/dist/api/http/routes/coverage.d.ts +9 -0
  31. package/dist/api/http/routes/coverage.js +34 -0
  32. package/dist/api/http/routes/environments.d.ts +11 -0
  33. package/dist/api/http/routes/environments.js +283 -0
  34. package/dist/api/http/routes/mcp.d.ts +1 -1
  35. package/dist/api/http/routes/mcp.js +2 -2
  36. package/dist/api/http/routes/me.js +1 -1
  37. package/dist/api/http/routes/reads.d.ts +45 -9
  38. package/dist/api/http/routes/reads.js +54 -5
  39. package/dist/api/http/routes/sessions.js +11 -6
  40. package/dist/api/http/routes/tenant.js +32 -10
  41. package/dist/api/openapi.js +31 -26
  42. package/dist/artifacts/disk.d.ts +59 -0
  43. package/dist/artifacts/disk.js +563 -0
  44. package/dist/artifacts/export.d.ts +1 -1
  45. package/dist/artifacts/export.js +2 -3
  46. package/dist/artifacts/folders.d.ts +6 -3
  47. package/dist/artifacts/folders.js +17 -12
  48. package/dist/artifacts/service.d.ts +2 -1
  49. package/dist/artifacts/service.js +6 -1
  50. package/dist/artifacts/workspace.d.ts +1 -1
  51. package/dist/artifacts/workspace.js +1 -1
  52. package/dist/core/flow-host.d.ts +3 -22
  53. package/dist/core/flow-host.js +11 -37
  54. package/dist/core/provider.d.ts +3 -2
  55. package/dist/core/provider.js +5 -37
  56. package/dist/core/sandbox-routes.d.ts +2 -21
  57. package/dist/core/sandbox-routes.js +10 -43
  58. package/dist/execution/types.d.ts +11 -9
  59. package/dist/execution/types.js +5 -7
  60. package/dist/gates/contract.d.ts +3 -24
  61. package/dist/gates/contract.js +1 -36
  62. package/dist/gates/egress-credentials.d.ts +9 -0
  63. package/dist/gates/egress-credentials.js +11 -4
  64. package/dist/gates/egress.d.ts +28 -1
  65. package/dist/gates/egress.js +115 -10
  66. package/dist/gates/fixture-model.d.ts +28 -0
  67. package/dist/gates/fixture-model.js +92 -0
  68. package/dist/gates/handler.js +4 -4
  69. package/dist/gates/http-tool.d.ts +6 -2
  70. package/dist/gates/http-tool.js +3 -5
  71. package/dist/gates/in-process.d.ts +5 -0
  72. package/dist/gates/in-process.js +12 -1
  73. package/dist/gates/journal.d.ts +30 -0
  74. package/dist/gates/journal.js +52 -0
  75. package/dist/gates/mcp-handler.d.ts +4 -0
  76. package/dist/gates/mcp-handler.js +5 -1
  77. package/dist/gates/meter.d.ts +10 -2
  78. package/dist/gates/meter.js +20 -5
  79. package/dist/gates/policy.d.ts +49 -0
  80. package/dist/gates/policy.js +134 -0
  81. package/dist/gates/tenant-vaults.d.ts +7 -7
  82. package/dist/gates/tenant-vaults.js +5 -5
  83. package/dist/gates/tool-calls.d.ts +10 -5
  84. package/dist/gates/tool-calls.js +28 -10
  85. package/dist/gates/tool-client.d.ts +8 -0
  86. package/dist/gates/tool-client.js +27 -11
  87. package/dist/gates/tool-contract.d.ts +10 -68
  88. package/dist/gates/tool-contract.js +1 -85
  89. package/dist/gates/tool-gate.d.ts +1 -1
  90. package/dist/harness/calls.d.ts +12 -5
  91. package/dist/harness/calls.js +21 -12
  92. package/dist/harness/executors.js +12 -9
  93. package/dist/harness/main.js +18 -5
  94. package/dist/harness/pod.d.ts +34 -0
  95. package/dist/harness/pod.js +41 -0
  96. package/dist/harness/service.d.ts +0 -1
  97. package/dist/harness/service.js +13 -5
  98. package/dist/harness/setup.d.ts +27 -0
  99. package/dist/harness/setup.js +150 -0
  100. package/dist/harness/ws-client.js +3 -2
  101. package/dist/harness/ws-port.d.ts +1 -5
  102. package/dist/harness/ws-port.js +1 -5
  103. package/dist/harness-api/in-process.js +3 -3
  104. package/dist/harness-api/record.d.ts +15 -1
  105. package/dist/harness-api/record.js +174 -44
  106. package/dist/harness-api/redact.d.ts +3 -0
  107. package/dist/harness-api/redact.js +45 -0
  108. package/dist/harness-api/server.d.ts +8 -0
  109. package/dist/harness-api/server.js +93 -13
  110. package/dist/harness-api/start.d.ts +10 -3
  111. package/dist/harness-api/start.js +40 -10
  112. package/dist/harness-api/tool-journal.d.ts +96 -0
  113. package/dist/harness-api/tool-journal.js +102 -0
  114. package/dist/harness-api/tool-status.d.ts +13 -0
  115. package/dist/harness-api/tool-status.js +26 -0
  116. package/dist/harness-api/workspace.d.ts +6 -3
  117. package/dist/harness-api/workspace.js +27 -11
  118. package/dist/harness-api/ws-server.d.ts +11 -3
  119. package/dist/harness-api/ws-server.js +94 -15
  120. package/dist/host/execution.d.ts +8 -6
  121. package/dist/host/gates.d.ts +2 -1
  122. package/dist/host/gates.js +10 -2
  123. package/dist/host/main.js +64 -21
  124. package/dist/host/operate.js +67 -5
  125. package/dist/host/stack-config.d.ts +70 -0
  126. package/dist/host/stack-config.js +67 -1
  127. package/dist/infra/execution.d.ts +18 -1
  128. package/dist/infra/execution.js +28 -4
  129. package/dist/infra/index.d.ts +1 -1
  130. package/dist/keys/client.js +4 -1
  131. package/dist/keys/keys.d.ts +5 -5
  132. package/dist/keys/keys.js +5 -7
  133. package/dist/management-openapi.json +999 -2211
  134. package/dist/mcp/connect.d.ts +25 -20
  135. package/dist/mcp/connect.js +29 -30
  136. package/dist/mcp/pool.d.ts +2 -2
  137. package/dist/mcp/pool.js +1 -1
  138. package/dist/mcp/preview.d.ts +3 -3
  139. package/dist/mcp/preview.js +10 -20
  140. package/dist/mcp/snapshot.d.ts +5 -11
  141. package/dist/mcp/snapshot.js +6 -7
  142. package/dist/model/pi-model.js +8 -0
  143. package/dist/openapi.json +6955 -2526
  144. package/dist/reads/types.d.ts +16 -3
  145. package/dist/record/append.d.ts +3 -1
  146. package/dist/record/append.js +1 -0
  147. package/dist/record/envelope.d.ts +5 -1
  148. package/dist/record/envelope.js +7 -3
  149. package/dist/record/environment.d.ts +25 -0
  150. package/dist/record/environment.js +44 -0
  151. package/dist/record/index.d.ts +1 -1
  152. package/dist/record/index.js +1 -1
  153. package/dist/retry.d.ts +21 -0
  154. package/dist/retry.js +34 -0
  155. package/dist/sandbox/disk-fs.d.ts +95 -0
  156. package/dist/sandbox/disk-fs.js +206 -0
  157. package/dist/sandbox/join.d.ts +17 -18
  158. package/dist/sandbox/join.js +46 -20
  159. package/dist/sandbox/manager.d.ts +16 -8
  160. package/dist/sandbox/manager.js +33 -17
  161. package/dist/sandbox/placement.d.ts +13 -12
  162. package/dist/sandbox/placement.js +29 -12
  163. package/dist/sandbox/pods/client.d.ts +6 -1
  164. package/dist/sandbox/pods/lifecycle.d.ts +28 -27
  165. package/dist/sandbox/pods/lifecycle.js +14 -26
  166. package/dist/sandbox/pods/reconcile.js +21 -15
  167. package/dist/sandbox/pods/spec.d.ts +15 -13
  168. package/dist/sandbox/pods/spec.js +16 -20
  169. package/dist/sandbox/records.d.ts +2 -2
  170. package/dist/sandbox/records.js +3 -3
  171. package/dist/sandbox/resolve.d.ts +35 -27
  172. package/dist/sandbox/resolve.js +66 -41
  173. package/dist/sandbox/session-sandbox.js +1 -1
  174. package/dist/sandbox/setup.d.ts +61 -0
  175. package/dist/sandbox/setup.js +123 -0
  176. package/dist/sandbox/share.d.ts +11 -21
  177. package/dist/sandbox/share.js +12 -41
  178. package/dist/sandbox/tenant-config.d.ts +12 -14
  179. package/dist/sandbox/tenant-config.js +12 -17
  180. package/dist/sandbox/types.d.ts +6 -0
  181. package/dist/store/postgres/control.js +8 -1
  182. package/dist/store/postgres/drizzle/0018_wake_outbox_retries.sql +3 -0
  183. package/dist/store/postgres/drizzle/0019_sandbox_signal_outbox.sql +18 -0
  184. package/dist/store/postgres/drizzle/0020_environments.sql +63 -0
  185. package/dist/store/postgres/drizzle/0021_disk_versions.sql +7 -0
  186. package/dist/store/postgres/drizzle/0022_model_usage_timing.sql +5 -0
  187. package/dist/store/postgres/drizzle/0023_artifact_pages.sql +1 -0
  188. package/dist/store/postgres/drizzle/meta/_journal.json +42 -0
  189. package/dist/store/postgres/reads.js +117 -17
  190. package/dist/store/postgres/record-writer.d.ts +4 -4
  191. package/dist/store/postgres/record-writer.js +9 -9
  192. package/dist/store/postgres/record.d.ts +7 -0
  193. package/dist/store/postgres/record.js +23 -2
  194. package/dist/store/postgres/schema.d.ts +1213 -779
  195. package/dist/store/postgres/schema.js +136 -76
  196. package/dist/store/postgres/store.js +283 -117
  197. package/dist/store/types.d.ts +206 -88
  198. package/dist/streams/relay/core.js +1 -13
  199. package/dist/tenant/advance.d.ts +7 -6
  200. package/dist/tenant/advance.js +121 -49
  201. package/dist/tenant/artifact-tool.js +3 -4
  202. package/dist/tenant/commands.d.ts +15 -2
  203. package/dist/tenant/commands.js +94 -14
  204. package/dist/tenant/context.d.ts +67 -33
  205. package/dist/tenant/context.js +4 -15
  206. package/dist/tenant/control.d.ts +8 -1
  207. package/dist/tenant/control.js +2 -0
  208. package/dist/tenant/effects.d.ts +1 -1
  209. package/dist/tenant/effects.js +37 -20
  210. package/dist/tenant/environments.d.ts +167 -0
  211. package/dist/tenant/environments.js +823 -0
  212. package/dist/tenant/harness-tokens.d.ts +21 -0
  213. package/dist/tenant/harness-tokens.js +61 -0
  214. package/dist/tenant/host-token.d.ts +1 -1
  215. package/dist/tenant/host-token.js +2 -4
  216. package/dist/tenant/identity-file.d.ts +4 -4
  217. package/dist/tenant/identity-file.js +17 -8
  218. package/dist/tenant/issuers.js +3 -3
  219. package/dist/tenant/principals.js +1 -1
  220. package/dist/tenant/reset.js +3 -3
  221. package/dist/tenant/runtime.d.ts +6 -1
  222. package/dist/tenant/runtime.js +30 -4
  223. package/dist/tenant/scheduler.d.ts +7 -0
  224. package/dist/tenant/scheduler.js +38 -7
  225. package/dist/tenant/session-streams.d.ts +0 -1
  226. package/dist/tenant/session-streams.js +1 -13
  227. package/dist/tenant/session.d.ts +3 -3
  228. package/dist/tenant/session.js +0 -14
  229. package/dist/tenant/sessions.d.ts +13 -13
  230. package/dist/tenant/sessions.js +61 -138
  231. package/dist/tenant/signing-keys.d.ts +5 -1
  232. package/dist/tenant/status.js +3 -3
  233. package/dist/tenant/streams.js +14 -29
  234. package/dist/tenant/sweep.d.ts +39 -12
  235. package/dist/tenant/sweep.js +168 -63
  236. package/dist/tenant/transcript.d.ts +210 -20
  237. package/dist/tenant/transcript.js +62 -11
  238. package/dist/tenant/turn-timing.d.ts +43 -0
  239. package/dist/tenant/turn-timing.js +39 -0
  240. package/dist/tenant/types.d.ts +2 -0
  241. package/dist/traces/ids.d.ts +42 -0
  242. package/dist/traces/ids.js +85 -0
  243. package/dist/traces/key.d.ts +6 -0
  244. package/dist/traces/key.js +37 -0
  245. package/dist/traces/map.d.ts +113 -0
  246. package/dist/traces/map.js +317 -0
  247. package/dist/traces/options.d.ts +7 -0
  248. package/dist/traces/options.js +1 -0
  249. package/dist/traces/otlp.d.ts +42 -0
  250. package/dist/traces/otlp.js +84 -0
  251. package/dist/traces/projector.d.ts +58 -0
  252. package/dist/traces/projector.js +200 -0
  253. package/dist/traces/read.d.ts +23 -0
  254. package/dist/traces/read.js +16 -0
  255. package/dist/vault/coverage.d.ts +26 -0
  256. package/dist/vault/coverage.js +64 -0
  257. package/dist/vault/error.d.ts +11 -1
  258. package/dist/vault/error.js +5 -1
  259. package/dist/vault/service.d.ts +47 -48
  260. package/dist/vault/service.js +321 -382
  261. package/dist/vault/sources.d.ts +5 -16
  262. package/dist/vault/sources.js +6 -8
  263. package/dist/version.d.ts +1 -1
  264. package/dist/version.js +2 -2
  265. package/package.json +14 -13
  266. package/dist/api/http/routes/sandboxes.d.ts +0 -9
  267. package/dist/api/http/routes/sandboxes.js +0 -153
  268. package/dist/api/http/routes/vaults.d.ts +0 -10
  269. package/dist/api/http/routes/vaults.js +0 -139
  270. package/dist/record/sandbox.d.ts +0 -25
  271. package/dist/record/sandbox.js +0 -43
  272. package/dist/tenant/sandboxes.d.ts +0 -122
  273. package/dist/tenant/sandboxes.js +0 -562
@@ -36,8 +36,14 @@
36
36
  * The Postgres, Restate and S2 endpoints are parsed and validated here;
37
37
  * `infra/*` builds the clients from them. So is the Object store (`NYLORUN_OBJECT_STORE_*`),
38
38
  * which every service may read; `host/main.ts` builds the `BlobStore` from it. So is who the Host's Tenant is when its database
39
- * holds none yet (`NYLORUN_TENANT_ID`, `NYLORUN_TENANT_NAME`).
39
+ * holds none yet (`NYLORUN_TENANT_ID`, `NYLORUN_TENANT_NAME`). So are traces (R7.2), for a
40
+ * process running core: where they go (`OTEL_EXPORTER_OTLP_ENDPOINT`, or
41
+ * `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`, with `OTEL_EXPORTER_OTLP_HEADERS`), what they say of
42
+ * their source (`OTEL_SERVICE_NAME`, `OTEL_RESOURCE_ATTRIBUTES`) and which content they carry
43
+ * (`NYLORUN_TRACE_CONTENT`, or all of it with `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true`).
40
44
  */
45
+ import { DEFAULT_SERVICE_NAME } from "../traces/otlp.js";
46
+ import { TRACE_CONTENT_KINDS } from "../traces/map.js";
41
47
  import { isTenantId } from "@nylorun/core/compatibility";
42
48
  import { blockedAddresses } from "../sandbox/pods/network-gate.js";
43
49
  export const RUNTIME_SERVICES = ["core", "loop", "gates", "keys", "egress", "harness"];
@@ -281,6 +287,12 @@ export function parseStackConfig(env, argv) {
281
287
  const workerUrl = parseUrl(env, "NYLORUN_WORKER_URL", http);
282
288
  if (workerUrl)
283
289
  endpoints.workerUrl = workerUrl;
290
+ const workerVersion = read(env, "NYLORUN_WORKER_VERSION");
291
+ if (workerVersion !== undefined) {
292
+ if (!/^[A-Za-z0-9._-]{1,64}$/.test(workerVersion))
293
+ throw new StackConfigError("NYLORUN_WORKER_VERSION must be 1 to 64 letters, digits, `.`, `_` or `-` (it is a URL path segment)");
294
+ endpoints.workerVersion = workerVersion;
295
+ }
284
296
  const s2Endpoint = parseUrl(env, "NYLORUN_S2_ENDPOINT", http);
285
297
  if (s2Endpoint)
286
298
  endpoints.s2Endpoint = s2Endpoint;
@@ -310,6 +322,7 @@ export function parseStackConfig(env, argv) {
310
322
  const delivery = parseDelivery(env);
311
323
  const tenant = servesApi ? parseTenant(env) : undefined;
312
324
  const objectStore = parseObjectStore(env);
325
+ const traces = services.has("core") ? parseTraces(env) : undefined;
313
326
  const removedResolverVariables = Object.keys(env)
314
327
  .filter((name) => name.startsWith(REMOVED_RESOLVER_PREFIX) && read(env, name) !== undefined)
315
328
  .sort();
@@ -331,8 +344,61 @@ export function parseStackConfig(env, argv) {
331
344
  ...(delivery ? { delivery } : {}),
332
345
  ...(tenant ? { tenant } : {}),
333
346
  ...(objectStore ? { objectStore } : {}),
347
+ ...(traces ? { traces } : {}),
334
348
  };
335
349
  }
350
+ /**
351
+ * `StackConfig.traces` (R7.2). The OTLP endpoint is the collector's base URL, to which
352
+ * `/v1/traces` is added; `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` is the full URL and wins. Headers
353
+ * and resource attributes are `key=value` lists separated by commas, values percent-encoded (the
354
+ * OTel SDK environment specification).
355
+ */
356
+ function parseTraces(env) {
357
+ const traces = parseUrl(env, "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", ["http:", "https:"]);
358
+ const base = parseUrl(env, "OTEL_EXPORTER_OTLP_ENDPOINT", ["http:", "https:"]);
359
+ const url = traces ?? (base === undefined ? undefined : `${base.replace(/\/+$/, "")}/v1/traces`);
360
+ const resource = keyValues(env, "OTEL_RESOURCE_ATTRIBUTES");
361
+ const all = read(env, "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT")?.toLowerCase() === "true";
362
+ const content = new Set(all ? TRACE_CONTENT_KINDS : []);
363
+ for (const kind of (read(env, "NYLORUN_TRACE_CONTENT") ?? "").split(",").map((part) => part.trim())) {
364
+ if (kind === "")
365
+ continue;
366
+ if (!TRACE_CONTENT_KINDS.includes(kind))
367
+ throw new StackConfigError(`NYLORUN_TRACE_CONTENT lists ${TRACE_CONTENT_KINDS.join(", ")}, not ${kind}`);
368
+ content.add(kind);
369
+ }
370
+ const serviceName = read(env, "OTEL_SERVICE_NAME") ?? resource["service.name"];
371
+ // Nothing set: the defaults (`service.name` nylorun, no content, no export).
372
+ if (url === undefined && serviceName === undefined && Object.keys(resource).length === 0 && content.size === 0)
373
+ return undefined;
374
+ return {
375
+ resource: {
376
+ serviceName: serviceName ?? DEFAULT_SERVICE_NAME,
377
+ attributes: resource,
378
+ },
379
+ content: TRACE_CONTENT_KINDS.filter((kind) => content.has(kind)),
380
+ ...(url ? { export: { url, headers: keyValues(env, "OTEL_EXPORTER_OTLP_HEADERS") } } : {}),
381
+ };
382
+ }
383
+ /** A `key=value,key=value` variable, values percent-decoded; a malformed one is refused. */
384
+ function keyValues(env, name) {
385
+ const out = {};
386
+ for (const pair of (read(env, name) ?? "").split(",")) {
387
+ if (pair.trim() === "")
388
+ continue;
389
+ const at = pair.indexOf("=");
390
+ const key = at < 0 ? "" : pair.slice(0, at).trim();
391
+ if (key === "")
392
+ throw new StackConfigError(`${name} must be key=value pairs separated by commas`);
393
+ try {
394
+ out[key] = decodeURIComponent(pair.slice(at + 1).trim());
395
+ }
396
+ catch {
397
+ throw new StackConfigError(`${name} has a value that is not percent-encoded: ${key}`);
398
+ }
399
+ }
400
+ return out;
401
+ }
336
402
  /** S3 bucket names: 3 to 63 lowercase letters, digits, dots and hyphens. */
337
403
  const BUCKET = /^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/;
338
404
  /** `StackConfig.objectStore` from `NYLORUN_OBJECT_STORE_*`, or `undefined` without an endpoint. */
@@ -29,7 +29,24 @@ export declare function executionKind(config: Pick<StackConfig, "endpoints">): "
29
29
  export declare function validateExecutionConfig(config: Pick<StackConfig, "endpoints"> & {
30
30
  services?: RuntimeServices;
31
31
  }): void;
32
- export declare function createExecution(config: Pick<StackConfig, "endpoints"> & {
32
+ /**
33
+ * The deployment a Worker registers with Restate (§14.6): `<NYLORUN_WORKER_URL>/nylorun/<version>`,
34
+ * the version being `NYLORUN_WORKER_VERSION` or the Runtime's. Restate sends new invocations to
35
+ * the latest deployment of a service and keeps each running invocation on the deployment it
36
+ * started on, so during a rolling upgrade the Workers of one version share that version's
37
+ * deployment (behind one load-balanced `NYLORUN_WORKER_URL`) and the old one finishes what it
38
+ * started; the endpoint answers on any path, so an older deployment's URL still reaches it.
39
+ * `force` replaces a deployment already registered at the URL with different code: only
40
+ * outside a container (a development Host, whose code changes under one version). Without
41
+ * it Restate keeps the deployment it already has at the URL, and a Worker whose services that
42
+ * deployment lacks refuses to start: a build whose code changed under the same version sets
43
+ * its own `NYLORUN_WORKER_VERSION`.
44
+ */
45
+ export declare function workerDeployment(config: Pick<StackConfig, "endpoints" | "listen">): {
46
+ url: string;
47
+ force: boolean;
48
+ } | undefined;
49
+ export declare function createExecution(config: Pick<StackConfig, "endpoints" | "listen"> & {
33
50
  services?: RuntimeServices;
34
51
  }, options?: CreateExecutionOptions): DurableExecution;
35
52
  /**
@@ -8,8 +8,8 @@
8
8
  * - wakes, timers and sweep arming go through the ingress, so every process can
9
9
  * call them;
10
10
  * - a Worker (a process running the loop service) serves the Restate endpoint on
11
- * `0.0.0.0:9080` and registers `NYLORUN_WORKER_URL` with the admin API when
12
- * `infra/workers.ts` starts it;
11
+ * `0.0.0.0:9080` and registers it with the admin API when `infra/workers.ts` starts it,
12
+ * as a versioned deployment (`workerDeployment`);
13
13
  * - with `NYLORUN_RESTATE_IDENTITY_KEY` the endpoint accepts only requests
14
14
  * signed by the Restate server holding the matching private key.
15
15
  *
@@ -17,6 +17,7 @@
17
17
  * only unit tests and a local development Host use.
18
18
  */
19
19
  import { createRestateExecution } from "../adapters/execution/restate.js";
20
+ import { RUNTIME_VERSION } from "../version.js";
20
21
  import { MemoryExecution } from "../execution/memory.js";
21
22
  import { DEFAULT_SERVICES, describeServices, } from "../host/stack-config.js";
22
23
  /** Where a Worker serves the Restate endpoint (architecture §14.3). */
@@ -46,16 +47,39 @@ export function validateExecutionConfig(config) {
46
47
  if (services.has("loop") && !workerUrl)
47
48
  throw new Error(`NYLORUN_WORKER_URL is required for --service ${describeServices(services)}: the Worker endpoint URL Restate calls`);
48
49
  }
50
+ /**
51
+ * The deployment a Worker registers with Restate (§14.6): `<NYLORUN_WORKER_URL>/nylorun/<version>`,
52
+ * the version being `NYLORUN_WORKER_VERSION` or the Runtime's. Restate sends new invocations to
53
+ * the latest deployment of a service and keeps each running invocation on the deployment it
54
+ * started on, so during a rolling upgrade the Workers of one version share that version's
55
+ * deployment (behind one load-balanced `NYLORUN_WORKER_URL`) and the old one finishes what it
56
+ * started; the endpoint answers on any path, so an older deployment's URL still reaches it.
57
+ * `force` replaces a deployment already registered at the URL with different code: only
58
+ * outside a container (a development Host, whose code changes under one version). Without
59
+ * it Restate keeps the deployment it already has at the URL, and a Worker whose services that
60
+ * deployment lacks refuses to start: a build whose code changed under the same version sets
61
+ * its own `NYLORUN_WORKER_VERSION`.
62
+ */
63
+ export function workerDeployment(config) {
64
+ const { workerUrl, workerVersion } = config.endpoints;
65
+ if (!workerUrl)
66
+ return undefined;
67
+ const version = encodeURIComponent(workerVersion ?? RUNTIME_VERSION);
68
+ return { url: `${workerUrl.replace(/\/+$/, "")}/nylorun/${version}`, force: !config.listen };
69
+ }
49
70
  export function createExecution(config, options = {}) {
50
71
  validateExecutionConfig(config);
51
- const { restateIngressUrl, restateAdminUrl, workerUrl, restateIdentityKeys } = config.endpoints;
72
+ const { restateIngressUrl, restateAdminUrl, restateIdentityKeys } = config.endpoints;
52
73
  if (!restateIngressUrl || !restateAdminUrl)
53
74
  return new MemoryExecution();
75
+ const deployment = workerDeployment(config);
54
76
  return createRestateExecution({
55
77
  ingressUrl: restateIngressUrl,
56
78
  adminUrl: restateAdminUrl,
57
79
  workerListen: options.workerListen ?? { ...WORKER_LISTEN },
58
- ...(workerUrl ? { workerAdvertisedUrl: workerUrl } : {}),
80
+ ...(deployment
81
+ ? { workerAdvertisedUrl: deployment.url, forceRegistration: deployment.force }
82
+ : {}),
59
83
  ...(restateIdentityKeys?.length ? { identityKeys: [...restateIdentityKeys] } : {}),
60
84
  ...(options.servicePrefix ? { servicePrefix: options.servicePrefix } : {}),
61
85
  ...(options.logger ? { logger: options.logger } : {}),
@@ -36,7 +36,7 @@ export interface Infra {
36
36
  * Builds the configured clients. Throws naming the variable when endpoints are
37
37
  * incomplete (e.g. a Restate ingress without an admin URL).
38
38
  */
39
- export declare function createInfra(config: Pick<StackConfig, "services" | "endpoints">, options?: {
39
+ export declare function createInfra(config: Pick<StackConfig, "services" | "endpoints" | "listen">, options?: {
40
40
  logger?: Logger;
41
41
  execution?: CreateExecutionOptions;
42
42
  streams?: CreateStreamsOptions;
@@ -51,7 +51,10 @@ export function httpKeys(options) {
51
51
  return resolve(answer.result);
52
52
  const error = answer.error;
53
53
  reject(error.kind === "vault"
54
- ? new VaultError(error.status, error.message)
54
+ ? new VaultError(error.status, error.message, {
55
+ ...(error.code === undefined ? {} : { code: error.code }),
56
+ ...(error.details === undefined ? {} : { details: error.details }),
57
+ })
55
58
  : new HttpError(error.status, error.message, {
56
59
  ...(error.code === undefined ? {} : { code: error.code }),
57
60
  ...(error.details === undefined ? {} : { details: error.details }),
@@ -1,4 +1,4 @@
1
- import type { CreateCredentialRequest, CredentialInfo, HostModelView, McpPreview, McpPreviewRequest, PutHostModelRequest, RotateCredentialRequest, SelectHostModelRequest, SigningKeyView } from "@nylorun/core/contracts";
1
+ import type { EnvironmentSecretView, HostModelView, McpPreview, McpPreviewRequest, PutEnvironmentSecretRequest, PutHostModelRequest, SelectHostModelRequest, SigningKeyView } from "@nylorun/core/contracts";
2
2
  import type { SessionStore } from "../store/types.js";
3
3
  import type { OutboundPolicy } from "../tenant/outbound.js";
4
4
  import { type SigningKeys } from "../tenant/signing-keys.js";
@@ -14,8 +14,8 @@ export interface Signed {
14
14
  readonly keyId: string;
15
15
  }
16
16
  export interface Keys {
17
- createCredential(vaultId: string, body: CreateCredentialRequest): Promise<CredentialInfo>;
18
- rotateCredential(vaultId: string, id: string, body: RotateCredentialRequest): Promise<CredentialInfo>;
17
+ /** `PUT /v1/environments/{id}/secrets/{name}` (`VaultService.putEnvironmentSecret`). */
18
+ putEnvironmentSecret(environmentId: string, name: string, body: PutEnvironmentSecretRequest, actor: string): Promise<EnvironmentSecretView>;
19
19
  putHostModel(body: PutHostModelRequest): Promise<HostModelView>;
20
20
  selectHostModel(body: SelectHostModelRequest): Promise<HostModelView>;
21
21
  /** Signs with the current key, creating the Tenant's keys if it has none. */
@@ -28,7 +28,7 @@ export interface Keys {
28
28
  /** Creates the current and standby keys when the Tenant has none. */
29
29
  ensureSigningKeys(): Promise<void>;
30
30
  /**
31
- * Lists a remote MCP server's tools with the installation vault's credential for its URL
31
+ * Lists a remote MCP server's tools with the Environment's credential for its URL
32
32
  * (R2b C12, `mcp/preview.ts`); never calls a tool.
33
33
  */
34
34
  previewMcp(body: McpPreviewRequest): Promise<McpPreview>;
@@ -41,7 +41,7 @@ export interface Keys {
41
41
  signEgressLeaf(host: string, publicKey: string): Promise<string>;
42
42
  }
43
43
  /** The operations, by the name the HTTP route carries. */
44
- export declare const KEYS_OPERATIONS: readonly ["createCredential", "rotateCredential", "putHostModel", "selectHostModel", "sign", "rotateSigningKeys", "ensureSigningKeys", "previewMcp", "egressCa", "signEgressLeaf"];
44
+ export declare const KEYS_OPERATIONS: readonly ["putEnvironmentSecret", "putHostModel", "selectHostModel", "sign", "rotateSigningKeys", "ensureSigningKeys", "previewMcp", "egressCa", "signEgressLeaf"];
45
45
  export type KeysOperation = (typeof KEYS_OPERATIONS)[number];
46
46
  export interface InProcessKeysOptions {
47
47
  readonly store: SessionStore;
package/dist/keys/keys.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * The keys seam (blueprint §14, F4.2): everything that needs the vault key. Vault writes that
3
- * touch a secret (creating and rotating a credential, setting and selecting the host model;
3
+ * touch a secret (writing an Environment's secret, setting and selecting the host model;
4
4
  * rotation and selection decrypt the old secret first) and all token signing (capability
5
5
  * links, run and host tokens, signing-key rotation) run here, whole, so the process that calls them never
6
6
  * holds the key or a private signing key.
7
7
  *
8
- * A tool preview (R2b C12, `previewMcp`) runs here too: it sends an installation vault's
9
- * credential to the server it lists, so the process that reads the plaintext makes the request.
8
+ * A tool preview (R2b C12, `previewMcp`) runs here too: it sends an Environment's credential to
9
+ * the server it lists, so the process that reads the plaintext makes the request.
10
10
  *
11
11
  * Two implementations: `inProcessKeys` (embedding, the ephemeral Runtime, tests, and the gates
12
12
  * service itself, which serves the HTTP routes with it), and `httpKeys` (`client.ts`), the
@@ -18,8 +18,7 @@ import { previewMcpServer } from "../mcp/preview.js";
18
18
  import { signingKeyView } from "../tenant/signing-keys.js";
19
19
  /** The operations, by the name the HTTP route carries. */
20
20
  export const KEYS_OPERATIONS = [
21
- "createCredential",
22
- "rotateCredential",
21
+ "putEnvironmentSecret",
23
22
  "putHostModel",
24
23
  "selectHostModel",
25
24
  "sign",
@@ -33,8 +32,7 @@ export function inProcessKeys(options) {
33
32
  const { store, vault, signingKeys, kek } = options;
34
33
  const egress = new EgressAuthority(store, kek);
35
34
  return {
36
- createCredential: (vaultId, body) => vault.createCredential(vaultId, body),
37
- rotateCredential: (vaultId, id, body) => vault.rotateCredential(vaultId, id, body),
35
+ putEnvironmentSecret: (environmentId, name, body, actor) => vault.putEnvironmentSecret(environmentId, name, body, actor),
38
36
  putHostModel: (body) => vault.putHostModel(body),
39
37
  selectHostModel: (body) => vault.selectHostModel(body),
40
38
  async sign(request) {