@nylorun/runtime 0.23.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 (252) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/README.md +79 -28
  3. package/dist/adapters/execution/restate.js +1 -1
  4. package/dist/adapters/replication/pgoutput.d.ts +2 -0
  5. package/dist/adapters/replication/pgoutput.js +6 -3
  6. package/dist/adapters/sandbox/local.d.ts +9 -1
  7. package/dist/adapters/sandbox/local.js +16 -4
  8. package/dist/adapters/sandbox/virtual.js +4 -1
  9. package/dist/api/a2a/endpoint.js +5 -1
  10. package/dist/api/a2a/routes.d.ts +2 -0
  11. package/dist/api/a2a/routes.js +2 -2
  12. package/dist/api/a2a/tasks.js +2 -1
  13. package/dist/api/ag-ui/endpoint.js +4 -2
  14. package/dist/api/ag-ui/history.js +4 -1
  15. package/dist/api/ag-ui/routes.d.ts +4 -1
  16. package/dist/api/ag-ui/routes.js +11 -10
  17. package/dist/api/ag-ui/translate.js +3 -2
  18. package/dist/api/components.d.ts +4953 -1204
  19. package/dist/api/components.js +25 -16
  20. package/dist/api/gate/keys.js +7 -1
  21. package/dist/api/gate/routes.d.ts +6 -0
  22. package/dist/api/gate/routes.js +39 -3
  23. package/dist/api/http/app.js +4 -4
  24. package/dist/api/http/define.d.ts +6 -0
  25. package/dist/api/http/define.js +13 -1
  26. package/dist/api/http/respond.js +1 -1
  27. package/dist/api/http/routes/artifacts.js +35 -8
  28. package/dist/api/http/routes/coverage.d.ts +9 -0
  29. package/dist/api/http/routes/coverage.js +34 -0
  30. package/dist/api/http/routes/environments.d.ts +11 -0
  31. package/dist/api/http/routes/environments.js +283 -0
  32. package/dist/api/http/routes/mcp.d.ts +1 -1
  33. package/dist/api/http/routes/mcp.js +2 -2
  34. package/dist/api/http/routes/me.js +1 -1
  35. package/dist/api/http/routes/reads.d.ts +45 -9
  36. package/dist/api/http/routes/reads.js +54 -5
  37. package/dist/api/http/routes/sessions.js +11 -6
  38. package/dist/api/http/routes/tenant.js +32 -10
  39. package/dist/api/openapi.js +31 -26
  40. package/dist/artifacts/disk.d.ts +59 -0
  41. package/dist/artifacts/disk.js +563 -0
  42. package/dist/artifacts/export.d.ts +1 -1
  43. package/dist/artifacts/export.js +2 -3
  44. package/dist/artifacts/folders.d.ts +6 -3
  45. package/dist/artifacts/folders.js +17 -12
  46. package/dist/artifacts/service.d.ts +2 -1
  47. package/dist/artifacts/service.js +6 -1
  48. package/dist/artifacts/workspace.d.ts +1 -1
  49. package/dist/artifacts/workspace.js +1 -1
  50. package/dist/core/flow-host.d.ts +2 -3
  51. package/dist/core/flow-host.js +3 -0
  52. package/dist/core/provider.d.ts +3 -2
  53. package/dist/core/provider.js +5 -37
  54. package/dist/core/sandbox-routes.d.ts +2 -21
  55. package/dist/core/sandbox-routes.js +10 -43
  56. package/dist/execution/types.d.ts +1 -1
  57. package/dist/gates/contract.d.ts +3 -24
  58. package/dist/gates/contract.js +1 -36
  59. package/dist/gates/egress-credentials.d.ts +9 -0
  60. package/dist/gates/egress-credentials.js +11 -4
  61. package/dist/gates/egress.d.ts +28 -1
  62. package/dist/gates/egress.js +115 -10
  63. package/dist/gates/fixture-model.d.ts +28 -0
  64. package/dist/gates/fixture-model.js +92 -0
  65. package/dist/gates/handler.js +4 -4
  66. package/dist/gates/http-tool.d.ts +6 -2
  67. package/dist/gates/http-tool.js +3 -5
  68. package/dist/gates/in-process.d.ts +5 -0
  69. package/dist/gates/in-process.js +12 -1
  70. package/dist/gates/journal.d.ts +30 -0
  71. package/dist/gates/journal.js +52 -0
  72. package/dist/gates/mcp-handler.d.ts +4 -0
  73. package/dist/gates/mcp-handler.js +5 -1
  74. package/dist/gates/meter.d.ts +10 -2
  75. package/dist/gates/meter.js +20 -5
  76. package/dist/gates/policy.d.ts +49 -0
  77. package/dist/gates/policy.js +134 -0
  78. package/dist/gates/tenant-vaults.d.ts +7 -7
  79. package/dist/gates/tenant-vaults.js +5 -5
  80. package/dist/gates/tool-calls.d.ts +10 -5
  81. package/dist/gates/tool-calls.js +28 -10
  82. package/dist/gates/tool-client.d.ts +8 -0
  83. package/dist/gates/tool-client.js +27 -11
  84. package/dist/gates/tool-contract.d.ts +10 -68
  85. package/dist/gates/tool-contract.js +1 -85
  86. package/dist/gates/tool-gate.d.ts +1 -1
  87. package/dist/harness/calls.d.ts +12 -5
  88. package/dist/harness/calls.js +21 -12
  89. package/dist/harness/executors.js +12 -9
  90. package/dist/harness/main.js +18 -5
  91. package/dist/harness/pod.d.ts +34 -0
  92. package/dist/harness/pod.js +41 -0
  93. package/dist/harness/service.d.ts +0 -1
  94. package/dist/harness/service.js +13 -5
  95. package/dist/harness/setup.d.ts +27 -0
  96. package/dist/harness/setup.js +150 -0
  97. package/dist/harness/ws-client.js +3 -2
  98. package/dist/harness/ws-port.d.ts +1 -5
  99. package/dist/harness/ws-port.js +1 -5
  100. package/dist/harness-api/in-process.js +3 -3
  101. package/dist/harness-api/record.d.ts +15 -1
  102. package/dist/harness-api/record.js +174 -44
  103. package/dist/harness-api/redact.d.ts +3 -0
  104. package/dist/harness-api/redact.js +45 -0
  105. package/dist/harness-api/server.d.ts +8 -0
  106. package/dist/harness-api/server.js +93 -13
  107. package/dist/harness-api/start.d.ts +10 -3
  108. package/dist/harness-api/start.js +40 -10
  109. package/dist/harness-api/tool-journal.d.ts +96 -0
  110. package/dist/harness-api/tool-journal.js +102 -0
  111. package/dist/harness-api/tool-status.d.ts +13 -0
  112. package/dist/harness-api/tool-status.js +26 -0
  113. package/dist/harness-api/workspace.d.ts +6 -3
  114. package/dist/harness-api/workspace.js +27 -11
  115. package/dist/harness-api/ws-server.d.ts +11 -3
  116. package/dist/harness-api/ws-server.js +94 -15
  117. package/dist/host/gates.d.ts +2 -1
  118. package/dist/host/gates.js +10 -2
  119. package/dist/host/main.js +54 -5
  120. package/dist/host/operate.js +67 -5
  121. package/dist/host/stack-config.d.ts +64 -0
  122. package/dist/host/stack-config.js +61 -1
  123. package/dist/keys/client.js +4 -1
  124. package/dist/keys/keys.d.ts +5 -5
  125. package/dist/keys/keys.js +5 -7
  126. package/dist/management-openapi.json +999 -2211
  127. package/dist/mcp/connect.d.ts +25 -20
  128. package/dist/mcp/connect.js +29 -30
  129. package/dist/mcp/pool.d.ts +2 -2
  130. package/dist/mcp/pool.js +1 -1
  131. package/dist/mcp/preview.d.ts +3 -3
  132. package/dist/mcp/preview.js +10 -20
  133. package/dist/mcp/snapshot.d.ts +5 -11
  134. package/dist/mcp/snapshot.js +6 -7
  135. package/dist/model/pi-model.js +8 -0
  136. package/dist/openapi.json +6955 -2526
  137. package/dist/reads/types.d.ts +16 -3
  138. package/dist/record/append.d.ts +3 -1
  139. package/dist/record/append.js +1 -0
  140. package/dist/record/envelope.d.ts +5 -1
  141. package/dist/record/envelope.js +7 -3
  142. package/dist/record/environment.d.ts +25 -0
  143. package/dist/record/environment.js +44 -0
  144. package/dist/record/index.d.ts +1 -1
  145. package/dist/record/index.js +1 -1
  146. package/dist/sandbox/disk-fs.d.ts +95 -0
  147. package/dist/sandbox/disk-fs.js +206 -0
  148. package/dist/sandbox/join.d.ts +17 -18
  149. package/dist/sandbox/join.js +42 -15
  150. package/dist/sandbox/manager.d.ts +16 -8
  151. package/dist/sandbox/manager.js +33 -17
  152. package/dist/sandbox/placement.d.ts +13 -12
  153. package/dist/sandbox/placement.js +29 -12
  154. package/dist/sandbox/pods/client.d.ts +6 -1
  155. package/dist/sandbox/pods/lifecycle.d.ts +28 -27
  156. package/dist/sandbox/pods/lifecycle.js +14 -26
  157. package/dist/sandbox/pods/reconcile.js +18 -12
  158. package/dist/sandbox/pods/spec.d.ts +15 -13
  159. package/dist/sandbox/pods/spec.js +16 -20
  160. package/dist/sandbox/records.d.ts +2 -2
  161. package/dist/sandbox/records.js +3 -3
  162. package/dist/sandbox/resolve.d.ts +35 -27
  163. package/dist/sandbox/resolve.js +66 -41
  164. package/dist/sandbox/session-sandbox.js +1 -1
  165. package/dist/sandbox/setup.d.ts +61 -0
  166. package/dist/sandbox/setup.js +123 -0
  167. package/dist/sandbox/share.d.ts +11 -21
  168. package/dist/sandbox/share.js +12 -41
  169. package/dist/sandbox/tenant-config.d.ts +12 -14
  170. package/dist/sandbox/tenant-config.js +12 -17
  171. package/dist/sandbox/types.d.ts +6 -0
  172. package/dist/store/postgres/drizzle/0020_environments.sql +63 -0
  173. package/dist/store/postgres/drizzle/0021_disk_versions.sql +7 -0
  174. package/dist/store/postgres/drizzle/0022_model_usage_timing.sql +5 -0
  175. package/dist/store/postgres/drizzle/0023_artifact_pages.sql +1 -0
  176. package/dist/store/postgres/drizzle/meta/_journal.json +28 -0
  177. package/dist/store/postgres/reads.js +117 -17
  178. package/dist/store/postgres/record-writer.d.ts +4 -4
  179. package/dist/store/postgres/record-writer.js +9 -9
  180. package/dist/store/postgres/record.d.ts +7 -0
  181. package/dist/store/postgres/record.js +23 -2
  182. package/dist/store/postgres/schema.d.ts +934 -761
  183. package/dist/store/postgres/schema.js +102 -73
  184. package/dist/store/postgres/store.js +119 -66
  185. package/dist/store/types.d.ts +109 -48
  186. package/dist/tenant/advance.d.ts +7 -6
  187. package/dist/tenant/advance.js +115 -42
  188. package/dist/tenant/artifact-tool.js +3 -4
  189. package/dist/tenant/commands.d.ts +15 -2
  190. package/dist/tenant/commands.js +93 -12
  191. package/dist/tenant/context.d.ts +48 -22
  192. package/dist/tenant/context.js +4 -15
  193. package/dist/tenant/effects.d.ts +1 -1
  194. package/dist/tenant/effects.js +37 -20
  195. package/dist/tenant/environments.d.ts +167 -0
  196. package/dist/tenant/environments.js +823 -0
  197. package/dist/tenant/harness-tokens.d.ts +21 -0
  198. package/dist/tenant/harness-tokens.js +61 -0
  199. package/dist/tenant/host-token.d.ts +1 -1
  200. package/dist/tenant/host-token.js +2 -4
  201. package/dist/tenant/identity-file.d.ts +4 -4
  202. package/dist/tenant/identity-file.js +17 -8
  203. package/dist/tenant/issuers.js +3 -3
  204. package/dist/tenant/principals.js +1 -1
  205. package/dist/tenant/reset.js +3 -3
  206. package/dist/tenant/runtime.d.ts +6 -1
  207. package/dist/tenant/runtime.js +7 -1
  208. package/dist/tenant/session.d.ts +3 -3
  209. package/dist/tenant/session.js +0 -14
  210. package/dist/tenant/sessions.d.ts +13 -13
  211. package/dist/tenant/sessions.js +61 -138
  212. package/dist/tenant/signing-keys.d.ts +5 -1
  213. package/dist/tenant/status.js +3 -3
  214. package/dist/tenant/sweep.js +12 -6
  215. package/dist/tenant/transcript.d.ts +210 -20
  216. package/dist/tenant/transcript.js +62 -11
  217. package/dist/tenant/turn-timing.d.ts +43 -0
  218. package/dist/tenant/turn-timing.js +39 -0
  219. package/dist/tenant/types.d.ts +2 -0
  220. package/dist/traces/ids.d.ts +42 -0
  221. package/dist/traces/ids.js +85 -0
  222. package/dist/traces/key.d.ts +6 -0
  223. package/dist/traces/key.js +37 -0
  224. package/dist/traces/map.d.ts +113 -0
  225. package/dist/traces/map.js +317 -0
  226. package/dist/traces/options.d.ts +7 -0
  227. package/dist/traces/options.js +1 -0
  228. package/dist/traces/otlp.d.ts +42 -0
  229. package/dist/traces/otlp.js +84 -0
  230. package/dist/traces/projector.d.ts +58 -0
  231. package/dist/traces/projector.js +200 -0
  232. package/dist/traces/read.d.ts +23 -0
  233. package/dist/traces/read.js +16 -0
  234. package/dist/vault/coverage.d.ts +26 -0
  235. package/dist/vault/coverage.js +64 -0
  236. package/dist/vault/error.d.ts +11 -1
  237. package/dist/vault/error.js +5 -1
  238. package/dist/vault/service.d.ts +47 -48
  239. package/dist/vault/service.js +321 -382
  240. package/dist/vault/sources.d.ts +5 -16
  241. package/dist/vault/sources.js +6 -8
  242. package/dist/version.d.ts +1 -1
  243. package/dist/version.js +2 -2
  244. package/package.json +13 -13
  245. package/dist/api/http/routes/sandboxes.d.ts +0 -9
  246. package/dist/api/http/routes/sandboxes.js +0 -153
  247. package/dist/api/http/routes/vaults.d.ts +0 -10
  248. package/dist/api/http/routes/vaults.js +0 -139
  249. package/dist/record/sandbox.d.ts +0 -25
  250. package/dist/record/sandbox.js +0 -43
  251. package/dist/tenant/sandboxes.d.ts +0 -123
  252. package/dist/tenant/sandboxes.js +0 -566
@@ -63,8 +63,7 @@
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, LiveEvent, SandboxEvent, SandboxEventPayload, SandboxEventType, SandboxKind, SandboxPodDesired, SandboxPodObserved, SessionEventOf } from "@nylorun/core/contracts";
67
- import type { SandboxManifest } from "@nylorun/core/define";
66
+ import type { EventPayload, EventType, EventWriter, LiveEvent, EnvironmentEvent, EnvironmentEventPayload, EnvironmentEventType, EnvironmentKind, EnvironmentRecipe, PodDesired, PodObserved, SessionEventOf } from "@nylorun/core/contracts";
68
67
  import type { HostEffect } from "@nylorun/harness/run";
69
68
  import type { ArtifactRow, ArtifactVersionRow, DefinitionFileRow, ModelBudgetRow, ModelUsageRow, ModelUsageWrite, PrincipalRow, ToolCrossingRow, SigningKeyRow, VaultAuditRow, VaultCredentialRow, VaultIdempotencyRow, VaultRow } from "./postgres/schema.js";
70
69
  /** Tables holding JSON documents keyed by `id`. */
@@ -73,7 +72,9 @@ export declare const DOC_TABLES: readonly DocTable[];
73
72
  /** Session lifecycle (architecture §10.2). */
74
73
  export type SessionStatus = "idle" | "runnable" | "running" | "waiting" | "paused" | "uncertain" | "completed" | "failed" | "cancelled";
75
74
  /** Effect states (§10.3), plus the flow host's `queued` and `cancelled`. */
76
- export type EffectStatus = "pending" | "invoking" | "completed" | "uncertain" | "queued" | "cancelled";
75
+ export type EffectStatus = "pending" | "invoking"
76
+ /** A tool call the Tool Gate held for a person's approval (R5 step 2): nothing was sent. */
77
+ | "held" | "completed" | "uncertain" | "queued" | "cancelled";
77
78
  export type EffectKind = HostEffect["kind"];
78
79
  /**
79
80
  * Ownership of a session by a Worker (§10.6). Read with the session; written
@@ -126,28 +127,51 @@ export interface DefinitionDoc {
126
127
  export interface SandboxDoc {
127
128
  key: string;
128
129
  }
129
- /** A sandbox resource (`sandbox_resources`): what `PUT /v1/sandboxes/{id}` created. */
130
- export interface SandboxResource {
130
+ /** An Environment (`environments`, D55): what `PUT /v1/environments/{id}` created. */
131
+ export interface Environment {
131
132
  id: string;
132
- kind: SandboxKind;
133
- /** The spec resolved against the Tenant's limits when the sandbox was created. */
134
- spec: SandboxManifest;
133
+ kind: EnvironmentKind;
135
134
  labels: Record<string, string>;
135
+ /** What the app asked for, resolved against the Tenant's limits. */
136
+ recipe: EnvironmentRecipe;
137
+ /** The recipe the current pod or workspace runs (copied from `recipe` at the next wake). */
138
+ applied: EnvironmentRecipe;
139
+ version: number;
140
+ appliedVersion: number;
141
+ /** The owner guard: only this owner's sessions may name it. */
142
+ ownerUserId?: string;
143
+ /** ISO time it was last used (`lifecycle.deleteAfter` counts from it). */
144
+ lastUsedAt: string;
136
145
  createdAt: string;
137
146
  updatedAt: string;
138
- /** Kind `pod`: the pod's lifecycle (F7.2). Absent for a virtual sandbox. */
147
+ /** Kind `pod`: the pod's lifecycle (F7.2). Absent otherwise. */
139
148
  pod?: SandboxPodState;
149
+ /** The disk lease while a snapshot, restore or seed copies the disk (R2d step 3). */
150
+ diskOp?: DiskOperation;
151
+ /** The disk version the next volume starts from (R2d step 3). */
152
+ diskSeed?: {
153
+ artifactId: string;
154
+ version: number;
155
+ };
156
+ }
157
+ /** A disk lease (R2d step 3): what holds the disk, since when, and until when unless renewed. */
158
+ export interface DiskOperation {
159
+ kind: "snapshot" | "restore" | "seed";
160
+ version?: number;
161
+ /** ISO times. */
162
+ startedAt: string;
163
+ until: string;
140
164
  }
141
165
  /**
142
- * A pod sandbox's lifecycle columns (`sandbox_resources`, F7.2, D34): what the Runtime wants
166
+ * A pod Environment's lifecycle columns (`environments`, F7.2, D34): what the Runtime wants
143
167
  * (`desired`), what it last saw (`observed`), and the fences of its incarnations.
144
168
  */
145
169
  export interface SandboxPodState {
146
170
  /** The agent-sandbox Sandbox's name (`podName`), of generation `volumeGen`. */
147
171
  k8sName: string;
148
172
  volumeGen: number;
149
- desired: SandboxPodDesired;
150
- observed: SandboxPodObserved;
173
+ desired: PodDesired;
174
+ observed: PodObserved;
151
175
  /** The UID of the pod that last joined. */
152
176
  podUid?: string;
153
177
  /** Bumped by every join, relaunch, loss and reset; host and egress tokens carry it. */
@@ -158,7 +182,6 @@ export interface SandboxPodState {
158
182
  rev: number;
159
183
  /** ISO times. */
160
184
  lastActiveAt?: string;
161
- expiresAt?: string;
162
185
  startedAt?: string;
163
186
  reason?: string;
164
187
  /** An earlier incarnation's Sandbox still to delete (after a reset or a loss). */
@@ -233,7 +256,7 @@ export interface StoreCounts {
233
256
  sandboxes: number;
234
257
  definitions: number;
235
258
  }
236
- export type ResetScope = "sessions" | "sandboxes" | "all";
259
+ export type ResetScope = "sessions" | "environments" | "all";
237
260
  /** Result of `takeOwnership`. */
238
261
  export type TakeOwnership = {
239
262
  status: "owned";
@@ -406,7 +429,9 @@ export interface Tx {
406
429
  * commit listeners. Rejects when the session does not exist. The returned
407
430
  * cursor is final.
408
431
  */
409
- event<T extends EventType>(sessionId: string, turnId: string | null, type: T, payload: EventPayload<T>): Promise<SessionEventOf<T>>;
432
+ event<T extends EventType>(sessionId: string, turnId: string | null, type: T, payload: EventPayload<T>,
433
+ /** Who wrote it (R4.9): absent, core, observed. */
434
+ writer?: EventWriter): Promise<SessionEventOf<T>>;
410
435
  /**
411
436
  * Asks for an advance of `sessionId` once this transaction commits. The request is a row
412
437
  * of the wake outbox written in this transaction, so it commits, or rolls back, with what
@@ -483,37 +508,54 @@ export interface Tx {
483
508
  }): Promise<StoredSession<T>[]>;
484
509
  listDefinitions<T extends DefinitionDoc = DefinitionDoc>(): Promise<T[]>;
485
510
  listSandboxes<T extends SandboxDoc = SandboxDoc>(): Promise<T[]>;
486
- /** The sandbox resource `id`; with `lock`, its row is locked until the transaction ends. */
487
- sandboxResource(id: string, options?: {
511
+ /** Environment `id`; with `lock`, its row is locked until the transaction ends. */
512
+ environment(id: string, options?: {
488
513
  lock?: boolean;
489
- }): Promise<SandboxResource | undefined>;
490
- /**
491
- * Creates the sandbox resource unless one with its id exists, while the Tenant holds fewer
492
- * than `limit`: `exists` and `limit` write nothing. Serialized with every other create.
493
- */
494
- createSandboxResource(row: SandboxResource, limit: number): Promise<"created" | "exists" | "limit">;
495
- updateSandboxLabels(id: string, labels: Record<string, string>, updatedAt: string): Promise<void>;
496
- /** Replaces a sandbox's spec (a pod's new `lifecycle.ttl`; the caller holds the row's lock). */
497
- updateSandboxSpec(id: string, spec: SandboxManifest, updatedAt: string): Promise<void>;
498
- /** Changes a pod sandbox's lifecycle columns (the caller holds the row's lock). */
499
- updateSandboxPod(id: string, patch: SandboxPodPatch, updatedAt: string): Promise<void>;
500
- deleteSandboxResource(id: string): Promise<void>;
501
- /** Sandbox resources by id, those with every label in `labels` when it is given. */
502
- listSandboxResources(filter?: {
514
+ }): Promise<Environment | undefined>;
515
+ /**
516
+ * Creates the Environment unless one with its id exists, while the Tenant holds fewer than
517
+ * `limit`: `exists` and `limit` write nothing. Serialized with every other create.
518
+ */
519
+ createEnvironment(row: Environment, limit: number): Promise<"created" | "exists" | "limit">;
520
+ /**
521
+ * Changes an Environment's columns other than its pod's (the caller holds the row's lock):
522
+ * labels, recipe and version, the applied recipe and its version, the owner guard (`null`
523
+ * clears it), and when it was last used.
524
+ */
525
+ updateEnvironment(id: string, patch: {
526
+ labels?: Record<string, string>;
527
+ recipe?: EnvironmentRecipe;
528
+ version?: number;
529
+ applied?: EnvironmentRecipe;
530
+ appliedVersion?: number;
531
+ ownerUserId?: string | null;
532
+ lastUsedAt?: string;
533
+ diskOp?: DiskOperation | null;
534
+ diskSeed?: {
535
+ artifactId: string;
536
+ version: number;
537
+ } | null;
538
+ }, updatedAt: string): Promise<void>;
539
+ /** Changes a pod Environment's lifecycle columns (the caller holds the row's lock). */
540
+ updateEnvironmentPod(id: string, patch: SandboxPodPatch, updatedAt: string): Promise<void>;
541
+ /** Deletes the Environment; its vault and credentials go with it (foreign key). */
542
+ deleteEnvironment(id: string): Promise<void>;
543
+ /** Environments by id, those with every label in `labels` when it is given. */
544
+ listEnvironments(filter?: {
503
545
  labels?: Record<string, string>;
504
- }): Promise<SandboxResource[]>;
505
- /** Sessions attached to sandbox resource `sandboxId` (`Session.sandboxId`), by id. */
506
- sessionsOnSandbox<T extends SessionDoc = SessionDoc>(sandboxId: string): Promise<StoredSession<T>[]>;
546
+ }): Promise<Environment[]>;
547
+ /** Sessions that name Environment `environmentId` (`Session.environmentId`), by id. */
548
+ sessionsOnEnvironment<T extends SessionDoc = SessionDoc>(environmentId: string): Promise<StoredSession<T>[]>;
507
549
  /**
508
- * Appends an event to the sandbox's lifecycle stream through the record module. The caller
509
- * holds the sandbox row's lock (or created the row in this transaction).
550
+ * Appends an event to the Environment's lifecycle stream through the record module. The
551
+ * caller holds the Environment row's lock (or created the row in this transaction).
510
552
  */
511
- sandboxEvent<T extends SandboxEventType>(sandboxId: string, type: T, payload: SandboxEventPayload<T>): Promise<SandboxEvent>;
512
- /** The sandbox's lifecycle stream, from `fromSeq` on, at most `limit` events. */
513
- sandboxEvents(sandboxId: string, options?: {
553
+ environmentEvent<T extends EnvironmentEventType>(environmentId: string, type: T, payload: EnvironmentEventPayload<T>): Promise<EnvironmentEvent>;
554
+ /** The Environment's lifecycle stream, from `fromSeq` on, at most `limit` events. */
555
+ environmentEvents(environmentId: string, options?: {
514
556
  fromSeq?: number;
515
557
  limit?: number;
516
- }): Promise<SandboxEvent[]>;
558
+ }): Promise<EnvironmentEvent[]>;
517
559
  /** `invoking` effects of one session; takeover turns them `uncertain`. */
518
560
  invokingEffects<T extends EffectDoc = EffectDoc>(sessionId: string): Promise<T[]>;
519
561
  effectsForSession<T extends EffectDoc = EffectDoc>(sessionId: string, filter?: SessionEffectFilter): Promise<T[]>;
@@ -549,20 +591,20 @@ export interface Tx {
549
591
  putPrincipal(id: string, tokenHash: string, createdAt: string, role?: KeyRole): Promise<PrincipalRow>;
550
592
  /** Deletes principal `id`; false when there was none. */
551
593
  deletePrincipal(id: string): Promise<boolean>;
552
- /** Rejects on a duplicate id, or a second `host` vault. */
594
+ /** Rejects on a duplicate id, or a second vault for one Environment. */
553
595
  insertVault(row: VaultRow): Promise<void>;
554
596
  getVault(id: string): Promise<VaultRow | undefined>;
555
- /** User vaults of one owner, ordered by `createdAt`, then id. */
556
- vaultsByOwner(ownerUserId: string): Promise<VaultRow[]>;
557
- /** Installation vaults (any session may attach them), ordered by `createdAt`, then id. */
558
- installationVaults(): Promise<VaultRow[]>;
597
+ /** The vault of Environment `environmentId` (D56). */
598
+ vaultOfEnvironment(environmentId: string): Promise<VaultRow | undefined>;
559
599
  updateVaultMetadata(id: string, metadataJson: string | null): Promise<void>;
560
600
  /** Deletes the vault and its credentials. */
561
601
  deleteVault(id: string): Promise<void>;
562
602
  /** Rejects on a duplicate id or an unknown vault. */
563
603
  insertCredential(row: VaultCredentialRow): Promise<void>;
564
- /** Looks a credential up by id alone (attachment checks); callers compare `vaultId`. */
604
+ /** Looks a credential up by id alone; callers compare `vaultId`. */
565
605
  getCredential(id: string): Promise<VaultCredentialRow | undefined>;
606
+ /** The credential named `name` in vault `vaultId` (names are unique per vault). */
607
+ credentialByName(vaultId: string, name: string): Promise<VaultCredentialRow | undefined>;
566
608
  /** Credentials of one vault, ordered by `createdAt`, then id. */
567
609
  credentialsForVault(vaultId: string, filter?: {
568
610
  type?: VaultCredentialRow["type"];
@@ -600,6 +642,11 @@ export interface Tx {
600
642
  countSigningKeys(): Promise<number>;
601
643
  /** Appends a row, setting `duplicate` when one with the same `effectKey` exists; returns it. */
602
644
  recordModelUsage(row: ModelUsageWrite): Promise<ModelUsageRow>;
645
+ /**
646
+ * The first row the gate recorded for the model call `effectKey` (R7.1), never a `duplicate`;
647
+ * undefined when no gate metered it.
648
+ */
649
+ modelUsageOf(effectKey: string): Promise<ModelUsageRow | undefined>;
603
650
  modelUsageTotals(query: ModelUsageQuery): Promise<ModelUsageTotals>;
604
651
  /** Every budget, ordered by scope, then scope id. */
605
652
  listModelBudgets(): Promise<ModelBudgetRow[]>;
@@ -608,6 +655,11 @@ export interface Tx {
608
655
  toolCrossing(key: string): Promise<ToolCrossingRow | undefined>;
609
656
  /** Inserts the running call's row; false when a row with `key` already exists. */
610
657
  startToolCrossing(row: Pick<ToolCrossingRow, "key" | "hash" | "startedAt">): Promise<boolean>;
658
+ /**
659
+ * Starts a lost call's row again (R5.3): `startedAt` moves on, on a row with no answer and
660
+ * `hash`. False when the row is gone, settled, or another request's.
661
+ */
662
+ restartToolCrossing(row: Pick<ToolCrossingRow, "key" | "hash" | "startedAt">): Promise<boolean>;
611
663
  /** Records the call's answer. */
612
664
  settleToolCrossing(key: string, answer: unknown, settledAt: string): Promise<void>;
613
665
  /** Deletes rows that settled before `before`; returns how many. */
@@ -616,6 +668,10 @@ export interface Tx {
616
668
  artifact(id: string, options?: {
617
669
  lock?: boolean;
618
670
  }): Promise<ArtifactRow | undefined>;
671
+ /** The folder artifact that holds Environment `environmentId`'s disk versions (R2d step 3). */
672
+ diskArtifact(environmentId: string, options?: {
673
+ lock?: boolean;
674
+ }): Promise<ArtifactRow | undefined>;
619
675
  /** Artifacts by creation time, then id: those of one session when `sessionId` is given. */
620
676
  listArtifacts(filter?: {
621
677
  sessionId?: string;
@@ -632,6 +688,11 @@ export interface Tx {
632
688
  artifactVersions(artifactId: string): Promise<ArtifactVersionRow[]>;
633
689
  /** Deletes the artifact and its versions; returns the versions' blob keys (empty when none). */
634
690
  deleteArtifact(id: string): Promise<string[]>;
691
+ /**
692
+ * Deletes one version of a locked artifact (its content rows go with it) and returns its blob
693
+ * key; the latest version becomes the newest one left. The artifact itself stays, even empty.
694
+ */
695
+ deleteArtifactVersion(artifactId: string, version: number): Promise<string | undefined>;
635
696
  /**
636
697
  * Serializes the Tenant's artifact writes: held until the transaction ends. Take it before
637
698
  * reading the total a new version must fit under.
@@ -677,9 +738,9 @@ export interface Tx {
677
738
  * Tenant's record rows and log heads. The Tenant moves to the next basin
678
739
  * generation and the current one is retired, so session ids it frees start again in an
679
740
  * empty basin;
680
- * - `sandboxes`: sandbox records, sandbox resources and their lifecycle streams;
741
+ * - `environments`: sandbox records, Environments with their vaults, and their lifecycle
742
+ * streams;
681
743
  * - `all`: both, plus definitions (and which definition files they use),
682
- * user vaults with their credentials,
683
744
  * the model usage ledger, the model budgets and Tenant-wide artifacts. The host vault, principals, signing keys,
684
745
  * settings, audit and vault idempotency rows stay.
685
746
  */
@@ -1,6 +1,6 @@
1
1
  import type { AdvanceResult } from "../execution/types.js";
2
2
  import type { Tx } from "../store/types.js";
3
- import type { Session, TenantContext } from "./context.js";
3
+ import { type Session, type TenantContext } from "./context.js";
4
4
  /**
5
5
  * Advance session `id` if it has a runnable checkpoint (`WorkerHandlers.advance`). Returns
6
6
  * `busy` when another advance holds a live lease, `done` otherwise.
@@ -9,12 +9,13 @@ export declare function advance(ctx: TenantContext, id: string, signal: AbortSig
9
9
  /**
10
10
  * Takeover (§10.5 step 2, §11.4), inside the transaction that took ownership: the dead
11
11
  * owner's `invoking` effects become `uncertain` and are never invoked again, except model
12
- * calls when the gate recovers them (P1.2) and remote MCP and HTTP tool calls when the Tool
13
- * Gate does (F4.1 G3): those stay `invoking`, and the replay re-sends them. When one belongs
14
- * to the active turn, the session becomes `uncertain` too, with an `effect.uncertain` event.
15
- * Mutates and writes `s`. Returns the effect ids it marked.
12
+ * calls when the gate recovers them (P1.2) and every tool call (R5.3): those stay `invoking`,
13
+ * and the replay decides. It re-sends a model call, and an MCP or HTTP tool call with the same
14
+ * key; a sandbox or core-served tool call fails to the model as `tool.interrupted`
15
+ * (`harness-api/tool-journal.ts`). When an effect marked `uncertain` belongs to the active
16
+ * turn, the session becomes `uncertain` too, with an `effect.uncertain` event. Mutates and
17
+ * writes `s`. Returns the effect ids it marked.
16
18
  */
17
19
  export declare function takeOver(t: Tx, s: Session, options?: {
18
20
  recoversModelCalls?: boolean;
19
- recoversToolCalls?: boolean;
20
21
  }): Promise<string[]>;