@nylorun/runtime 0.23.0-beta → 0.25.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 (301) hide show
  1. package/CHANGELOG.md +252 -0
  2. package/README.md +87 -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/card.d.ts +11 -1
  10. package/dist/api/a2a/card.js +26 -2
  11. package/dist/api/a2a/endpoint.js +9 -3
  12. package/dist/api/a2a/protocol.d.ts +25 -2
  13. package/dist/api/a2a/protocol.js +20 -3
  14. package/dist/api/a2a/routes.d.ts +6 -1
  15. package/dist/api/a2a/routes.js +67 -9
  16. package/dist/api/a2a/tasks.js +2 -1
  17. package/dist/api/ag-ui/endpoint.js +8 -3
  18. package/dist/api/ag-ui/history.d.ts +6 -1
  19. package/dist/api/ag-ui/history.js +39 -3
  20. package/dist/api/ag-ui/routes.d.ts +4 -1
  21. package/dist/api/ag-ui/routes.js +63 -20
  22. package/dist/api/ag-ui/translate.js +3 -2
  23. package/dist/api/components.d.ts +5327 -1091
  24. package/dist/api/components.js +40 -16
  25. package/dist/api/gate/keys.d.ts +2 -1
  26. package/dist/api/gate/keys.js +14 -1
  27. package/dist/api/gate/routes.d.ts +6 -0
  28. package/dist/api/gate/routes.js +52 -3
  29. package/dist/api/http/app.js +17 -6
  30. package/dist/api/http/body.d.ts +3 -3
  31. package/dist/api/http/body.js +7 -7
  32. package/dist/api/http/define.d.ts +6 -0
  33. package/dist/api/http/define.js +13 -1
  34. package/dist/api/http/respond.js +1 -1
  35. package/dist/api/http/routes/artifacts.js +35 -8
  36. package/dist/api/http/routes/coverage.d.ts +9 -0
  37. package/dist/api/http/routes/coverage.js +34 -0
  38. package/dist/api/http/routes/environment-manifests.d.ts +9 -0
  39. package/dist/api/http/routes/environment-manifests.js +118 -0
  40. package/dist/api/http/routes/environments.d.ts +11 -0
  41. package/dist/api/http/routes/environments.js +332 -0
  42. package/dist/api/http/routes/mcp.d.ts +1 -1
  43. package/dist/api/http/routes/mcp.js +2 -2
  44. package/dist/api/http/routes/me.js +1 -1
  45. package/dist/api/http/routes/reads.d.ts +94 -9
  46. package/dist/api/http/routes/reads.js +54 -5
  47. package/dist/api/http/routes/sessions.js +24 -9
  48. package/dist/api/http/routes/tenant.js +65 -15
  49. package/dist/api/inbound-files.d.ts +65 -0
  50. package/dist/api/inbound-files.js +115 -0
  51. package/dist/api/openapi.js +48 -28
  52. package/dist/artifacts/disk.d.ts +59 -0
  53. package/dist/artifacts/disk.js +569 -0
  54. package/dist/artifacts/export.d.ts +1 -1
  55. package/dist/artifacts/export.js +2 -3
  56. package/dist/artifacts/folders.d.ts +6 -3
  57. package/dist/artifacts/folders.js +17 -12
  58. package/dist/artifacts/media-types.d.ts +15 -0
  59. package/dist/artifacts/media-types.js +56 -4
  60. package/dist/artifacts/parts.d.ts +12 -3
  61. package/dist/artifacts/parts.js +15 -4
  62. package/dist/artifacts/service.d.ts +2 -1
  63. package/dist/artifacts/service.js +6 -1
  64. package/dist/artifacts/workspace.d.ts +5 -5
  65. package/dist/artifacts/workspace.js +7 -19
  66. package/dist/core/flow-host.d.ts +3 -4
  67. package/dist/core/flow-host.js +5 -2
  68. package/dist/core/provider.d.ts +3 -2
  69. package/dist/core/provider.js +5 -37
  70. package/dist/core/sandbox-routes.d.ts +2 -21
  71. package/dist/core/sandbox-routes.js +11 -44
  72. package/dist/core/turn-manifest.d.ts +3 -2
  73. package/dist/core/turn-manifest.js +29 -5
  74. package/dist/execution/types.d.ts +1 -1
  75. package/dist/gates/contract.d.ts +3 -24
  76. package/dist/gates/contract.js +1 -36
  77. package/dist/gates/egress-credentials.d.ts +9 -0
  78. package/dist/gates/egress-credentials.js +11 -4
  79. package/dist/gates/egress.d.ts +22 -1
  80. package/dist/gates/egress.js +116 -10
  81. package/dist/gates/fixture-model.d.ts +28 -0
  82. package/dist/gates/fixture-model.js +92 -0
  83. package/dist/gates/handler.js +4 -4
  84. package/dist/gates/http-tool.d.ts +9 -6
  85. package/dist/gates/http-tool.js +11 -17
  86. package/dist/gates/in-process.d.ts +5 -0
  87. package/dist/gates/in-process.js +12 -1
  88. package/dist/gates/journal.d.ts +30 -0
  89. package/dist/gates/journal.js +51 -0
  90. package/dist/gates/mcp-handler.d.ts +4 -0
  91. package/dist/gates/mcp-handler.js +7 -4
  92. package/dist/gates/meter.d.ts +10 -2
  93. package/dist/gates/meter.js +20 -5
  94. package/dist/gates/policy.d.ts +49 -0
  95. package/dist/gates/policy.js +132 -0
  96. package/dist/gates/tenant-vaults.d.ts +7 -7
  97. package/dist/gates/tenant-vaults.js +5 -5
  98. package/dist/gates/tool-calls.d.ts +10 -5
  99. package/dist/gates/tool-calls.js +28 -10
  100. package/dist/gates/tool-client.d.ts +8 -0
  101. package/dist/gates/tool-client.js +27 -11
  102. package/dist/gates/tool-contract.d.ts +11 -69
  103. package/dist/gates/tool-contract.js +1 -85
  104. package/dist/gates/tool-gate.d.ts +1 -1
  105. package/dist/harness/calls.d.ts +14 -7
  106. package/dist/harness/calls.js +30 -24
  107. package/dist/harness/executors.js +12 -9
  108. package/dist/harness/main.js +24 -5
  109. package/dist/harness/pod.d.ts +39 -0
  110. package/dist/harness/pod.js +46 -0
  111. package/dist/harness/service.d.ts +0 -1
  112. package/dist/harness/service.js +17 -9
  113. package/dist/harness/setup.d.ts +29 -0
  114. package/dist/harness/setup.js +174 -0
  115. package/dist/harness/ws-client.js +3 -2
  116. package/dist/harness/ws-port.d.ts +1 -5
  117. package/dist/harness/ws-port.js +1 -5
  118. package/dist/harness-api/in-process.js +3 -3
  119. package/dist/harness-api/record.d.ts +15 -1
  120. package/dist/harness-api/record.js +180 -50
  121. package/dist/harness-api/redact.d.ts +3 -0
  122. package/dist/harness-api/redact.js +45 -0
  123. package/dist/harness-api/server.d.ts +35 -4
  124. package/dist/harness-api/server.js +130 -17
  125. package/dist/harness-api/start.d.ts +10 -3
  126. package/dist/harness-api/start.js +40 -10
  127. package/dist/harness-api/tool-journal.d.ts +105 -0
  128. package/dist/harness-api/tool-journal.js +132 -0
  129. package/dist/harness-api/tool-status.d.ts +13 -0
  130. package/dist/harness-api/tool-status.js +26 -0
  131. package/dist/harness-api/workspace.d.ts +12 -7
  132. package/dist/harness-api/workspace.js +47 -25
  133. package/dist/harness-api/ws-server.d.ts +11 -3
  134. package/dist/harness-api/ws-server.js +94 -15
  135. package/dist/host/gates.d.ts +2 -1
  136. package/dist/host/gates.js +10 -2
  137. package/dist/host/main.js +54 -5
  138. package/dist/host/operate.js +67 -5
  139. package/dist/host/stack-config.d.ts +64 -0
  140. package/dist/host/stack-config.js +62 -2
  141. package/dist/keys/client.js +4 -1
  142. package/dist/keys/keys.d.ts +13 -6
  143. package/dist/keys/keys.js +9 -8
  144. package/dist/management-openapi.json +1264 -2171
  145. package/dist/mcp/connect.d.ts +26 -22
  146. package/dist/mcp/connect.js +30 -34
  147. package/dist/mcp/pool.d.ts +3 -6
  148. package/dist/mcp/pool.js +14 -28
  149. package/dist/mcp/preview.d.ts +3 -3
  150. package/dist/mcp/preview.js +10 -21
  151. package/dist/mcp/snapshot.d.ts +16 -24
  152. package/dist/mcp/snapshot.js +33 -45
  153. package/dist/model/capabilities.d.ts +26 -0
  154. package/dist/model/capabilities.js +44 -0
  155. package/dist/model/catalog.d.ts +34 -3
  156. package/dist/model/catalog.js +38 -2
  157. package/dist/model/models.d.ts +2 -0
  158. package/dist/model/models.js +1 -1
  159. package/dist/model/native-blocks.d.ts +35 -0
  160. package/dist/model/native-blocks.js +170 -0
  161. package/dist/model/pi-model.js +114 -94
  162. package/dist/openapi.json +12822 -3943
  163. package/dist/reads/types.d.ts +16 -3
  164. package/dist/record/append.d.ts +3 -1
  165. package/dist/record/append.js +1 -0
  166. package/dist/record/envelope.d.ts +5 -1
  167. package/dist/record/envelope.js +7 -3
  168. package/dist/record/environment.d.ts +25 -0
  169. package/dist/record/environment.js +44 -0
  170. package/dist/record/index.d.ts +1 -1
  171. package/dist/record/index.js +1 -1
  172. package/dist/sandbox/disk-fs.d.ts +95 -0
  173. package/dist/sandbox/disk-fs.js +206 -0
  174. package/dist/sandbox/join.d.ts +17 -18
  175. package/dist/sandbox/join.js +46 -15
  176. package/dist/sandbox/manager.d.ts +47 -21
  177. package/dist/sandbox/manager.js +162 -107
  178. package/dist/sandbox/placement.d.ts +14 -13
  179. package/dist/sandbox/placement.js +31 -14
  180. package/dist/sandbox/pods/client.d.ts +9 -2
  181. package/dist/sandbox/pods/lifecycle.d.ts +36 -27
  182. package/dist/sandbox/pods/lifecycle.js +29 -26
  183. package/dist/sandbox/pods/reconcile.js +18 -12
  184. package/dist/sandbox/pods/spec.d.ts +15 -13
  185. package/dist/sandbox/pods/spec.js +17 -20
  186. package/dist/sandbox/records.d.ts +2 -2
  187. package/dist/sandbox/records.js +3 -3
  188. package/dist/sandbox/resolve.d.ts +37 -27
  189. package/dist/sandbox/resolve.js +73 -41
  190. package/dist/sandbox/runtime-tools.d.ts +9 -0
  191. package/dist/sandbox/runtime-tools.js +16 -0
  192. package/dist/sandbox/session-sandbox.d.ts +4 -6
  193. package/dist/sandbox/session-sandbox.js +47 -94
  194. package/dist/sandbox/setup.d.ts +64 -0
  195. package/dist/sandbox/setup.js +160 -0
  196. package/dist/sandbox/share.d.ts +21 -26
  197. package/dist/sandbox/share.js +36 -63
  198. package/dist/sandbox/skills.d.ts +8 -6
  199. package/dist/sandbox/skills.js +24 -23
  200. package/dist/sandbox/tenant-config.d.ts +12 -14
  201. package/dist/sandbox/tenant-config.js +12 -17
  202. package/dist/sandbox/types.d.ts +6 -0
  203. package/dist/store/postgres/drizzle/0020_environments.sql +63 -0
  204. package/dist/store/postgres/drizzle/0021_disk_versions.sql +7 -0
  205. package/dist/store/postgres/drizzle/0022_model_usage_timing.sql +5 -0
  206. package/dist/store/postgres/drizzle/0023_artifact_pages.sql +1 -0
  207. package/dist/store/postgres/drizzle/0024_flat_manifest.sql +7 -0
  208. package/dist/store/postgres/drizzle/0025_environment_manifests.sql +14 -0
  209. package/dist/store/postgres/drizzle/0026_environment_forks.sql +1 -0
  210. package/dist/store/postgres/drizzle/0027_environment_image_digest.sql +1 -0
  211. package/dist/store/postgres/drizzle/meta/_journal.json +56 -0
  212. package/dist/store/postgres/reads.js +123 -17
  213. package/dist/store/postgres/record-writer.d.ts +4 -4
  214. package/dist/store/postgres/record-writer.js +9 -9
  215. package/dist/store/postgres/record.d.ts +7 -0
  216. package/dist/store/postgres/record.js +23 -2
  217. package/dist/store/postgres/schema.d.ts +1126 -736
  218. package/dist/store/postgres/schema.js +136 -73
  219. package/dist/store/postgres/store.js +195 -67
  220. package/dist/store/types.d.ts +165 -50
  221. package/dist/tenant/advance.d.ts +7 -6
  222. package/dist/tenant/advance.js +118 -42
  223. package/dist/tenant/artifact-tool.d.ts +1 -1
  224. package/dist/tenant/artifact-tool.js +46 -26
  225. package/dist/tenant/commands.d.ts +15 -2
  226. package/dist/tenant/commands.js +115 -14
  227. package/dist/tenant/context.d.ts +56 -24
  228. package/dist/tenant/context.js +4 -15
  229. package/dist/tenant/effects.d.ts +1 -1
  230. package/dist/tenant/effects.js +44 -29
  231. package/dist/tenant/environment-manifests.d.ts +57 -0
  232. package/dist/tenant/environment-manifests.js +200 -0
  233. package/dist/tenant/environments.d.ts +174 -0
  234. package/dist/tenant/environments.js +1044 -0
  235. package/dist/tenant/harness-tokens.d.ts +21 -0
  236. package/dist/tenant/harness-tokens.js +61 -0
  237. package/dist/tenant/host-token.d.ts +1 -1
  238. package/dist/tenant/host-token.js +2 -4
  239. package/dist/tenant/identity-file.d.ts +4 -4
  240. package/dist/tenant/identity-file.js +17 -8
  241. package/dist/tenant/issuers.js +3 -3
  242. package/dist/tenant/model-setting.d.ts +14 -0
  243. package/dist/tenant/model-setting.js +51 -0
  244. package/dist/tenant/principals.js +1 -1
  245. package/dist/tenant/reset.js +3 -3
  246. package/dist/tenant/runtime.d.ts +6 -1
  247. package/dist/tenant/runtime.js +7 -1
  248. package/dist/tenant/session.d.ts +3 -3
  249. package/dist/tenant/session.js +0 -14
  250. package/dist/tenant/sessions.d.ts +18 -14
  251. package/dist/tenant/sessions.js +99 -143
  252. package/dist/tenant/signing-keys.d.ts +5 -1
  253. package/dist/tenant/skill-tool.d.ts +3 -3
  254. package/dist/tenant/skill-tool.js +6 -11
  255. package/dist/tenant/status.js +3 -3
  256. package/dist/tenant/sweep.js +13 -7
  257. package/dist/tenant/tool-results.js +1 -1
  258. package/dist/tenant/tool-search.d.ts +7 -11
  259. package/dist/tenant/tool-search.js +8 -5
  260. package/dist/tenant/transcript.d.ts +245 -36
  261. package/dist/tenant/transcript.js +64 -12
  262. package/dist/tenant/turn-timing.d.ts +43 -0
  263. package/dist/tenant/turn-timing.js +39 -0
  264. package/dist/tenant/types.d.ts +2 -0
  265. package/dist/traces/ids.d.ts +41 -0
  266. package/dist/traces/ids.js +81 -0
  267. package/dist/traces/key.d.ts +6 -0
  268. package/dist/traces/key.js +37 -0
  269. package/dist/traces/map.d.ts +113 -0
  270. package/dist/traces/map.js +289 -0
  271. package/dist/traces/options.d.ts +7 -0
  272. package/dist/traces/options.js +1 -0
  273. package/dist/traces/otlp.d.ts +42 -0
  274. package/dist/traces/otlp.js +84 -0
  275. package/dist/traces/projector.d.ts +58 -0
  276. package/dist/traces/projector.js +200 -0
  277. package/dist/traces/read.d.ts +23 -0
  278. package/dist/traces/read.js +16 -0
  279. package/dist/vault/coverage.d.ts +26 -0
  280. package/dist/vault/coverage.js +62 -0
  281. package/dist/vault/error.d.ts +11 -1
  282. package/dist/vault/error.js +5 -1
  283. package/dist/vault/host-model.d.ts +4 -1
  284. package/dist/vault/host-model.js +10 -2
  285. package/dist/vault/service.d.ts +92 -48
  286. package/dist/vault/service.js +462 -376
  287. package/dist/vault/sources.d.ts +5 -16
  288. package/dist/vault/sources.js +6 -8
  289. package/dist/version.d.ts +1 -1
  290. package/dist/version.js +2 -2
  291. package/package.json +13 -13
  292. package/dist/api/http/routes/sandboxes.d.ts +0 -9
  293. package/dist/api/http/routes/sandboxes.js +0 -153
  294. package/dist/api/http/routes/vaults.d.ts +0 -10
  295. package/dist/api/http/routes/vaults.js +0 -139
  296. package/dist/record/sandbox.d.ts +0 -25
  297. package/dist/record/sandbox.js +0 -43
  298. package/dist/sandbox/capability.d.ts +0 -3
  299. package/dist/sandbox/capability.js +0 -10
  300. package/dist/tenant/sandboxes.d.ts +0 -123
  301. 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, EnvironmentManifest, 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,81 @@ 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
+ /**
152
+ * The disk version the next volume starts from (R2d step 3). `setup` (a fork onto other setup,
153
+ * Q17): the setup runs once the version is written (`written`), and the seed stays until it is done.
154
+ */
155
+ diskSeed?: DiskSeed;
156
+ /** The environment manifest it was made from and its version (D63); absent for an inline one. */
157
+ manifestName?: string;
158
+ manifestVersion?: number;
159
+ /** The hash of what it runs (`recipe`), recorded at creation (protocol 14). */
160
+ manifestHash?: string;
161
+ /** The Environment it was forked from and the disk version it started from (Q15). */
162
+ forkedFrom?: {
163
+ environment: string;
164
+ disk: number | null;
165
+ };
166
+ }
167
+ /** A pending seed of an Environment's disk (`disk_seed`). */
168
+ export interface DiskSeed {
169
+ artifactId: string;
170
+ version: number;
171
+ /** Run the setup on the seeded disk (a fork onto other setup, Q17). */
172
+ setup?: true;
173
+ /** The version is written; with `setup`, the seed waits for the setup to be done. */
174
+ written?: true;
175
+ }
176
+ /** One version of an environment manifest (`environment_manifests`, D63). */
177
+ export interface EnvironmentManifestRow {
178
+ name: string;
179
+ version: number;
180
+ body: EnvironmentManifest;
181
+ hash: string;
182
+ savedBy: {
183
+ actor: string;
184
+ };
185
+ createdAt: string;
186
+ }
187
+ /** A disk lease (R2d step 3): what holds the disk, since when, and until when unless renewed. */
188
+ export interface DiskOperation {
189
+ kind: "snapshot" | "restore" | "seed";
190
+ version?: number;
191
+ /** ISO times. */
192
+ startedAt: string;
193
+ until: string;
140
194
  }
141
195
  /**
142
- * A pod sandbox's lifecycle columns (`sandbox_resources`, F7.2, D34): what the Runtime wants
196
+ * A pod Environment's lifecycle columns (`environments`, F7.2, D34): what the Runtime wants
143
197
  * (`desired`), what it last saw (`observed`), and the fences of its incarnations.
144
198
  */
145
199
  export interface SandboxPodState {
146
200
  /** The agent-sandbox Sandbox's name (`podName`), of generation `volumeGen`. */
147
201
  k8sName: string;
148
202
  volumeGen: number;
149
- desired: SandboxPodDesired;
150
- observed: SandboxPodObserved;
203
+ desired: PodDesired;
204
+ observed: PodObserved;
151
205
  /** The UID of the pod that last joined. */
152
206
  podUid?: string;
153
207
  /** Bumped by every join, relaunch, loss and reset; host and egress tokens carry it. */
@@ -158,13 +212,17 @@ export interface SandboxPodState {
158
212
  rev: number;
159
213
  /** ISO times. */
160
214
  lastActiveAt?: string;
161
- expiresAt?: string;
162
215
  startedAt?: string;
163
216
  reason?: string;
164
217
  /** An earlier incarnation's Sandbox still to delete (after a reset or a loss). */
165
218
  retiring?: string;
166
219
  /** The id the engine keeps on the volume, from the first join. */
167
220
  volumeId?: string;
221
+ /**
222
+ * The workload image by digest (`repo@sha256:…`), recorded the first time a pod of the
223
+ * Environment is ready (Q14): every later pod, after a stop, a relaunch or a reset, runs it.
224
+ */
225
+ imageDigest?: string;
168
226
  }
169
227
  /** A change to a pod's columns: `null` clears an optional one. */
170
228
  export type SandboxPodPatch = {
@@ -233,7 +291,7 @@ export interface StoreCounts {
233
291
  sandboxes: number;
234
292
  definitions: number;
235
293
  }
236
- export type ResetScope = "sessions" | "sandboxes" | "all";
294
+ export type ResetScope = "sessions" | "environments" | "all";
237
295
  /** Result of `takeOwnership`. */
238
296
  export type TakeOwnership = {
239
297
  status: "owned";
@@ -406,7 +464,9 @@ export interface Tx {
406
464
  * commit listeners. Rejects when the session does not exist. The returned
407
465
  * cursor is final.
408
466
  */
409
- event<T extends EventType>(sessionId: string, turnId: string | null, type: T, payload: EventPayload<T>): Promise<SessionEventOf<T>>;
467
+ event<T extends EventType>(sessionId: string, turnId: string | null, type: T, payload: EventPayload<T>,
468
+ /** Who wrote it (R4.9): absent, core, observed. */
469
+ writer?: EventWriter): Promise<SessionEventOf<T>>;
410
470
  /**
411
471
  * Asks for an advance of `sessionId` once this transaction commits. The request is a row
412
472
  * of the wake outbox written in this transaction, so it commits, or rolls back, with what
@@ -483,37 +543,65 @@ export interface Tx {
483
543
  }): Promise<StoredSession<T>[]>;
484
544
  listDefinitions<T extends DefinitionDoc = DefinitionDoc>(): Promise<T[]>;
485
545
  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?: {
546
+ /** Environment `id`; with `lock`, its row is locked until the transaction ends. */
547
+ environment(id: string, options?: {
488
548
  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?: {
549
+ }): Promise<Environment | undefined>;
550
+ /**
551
+ * Creates the Environment unless one with its id exists, while the Tenant holds fewer than
552
+ * `limit`: `exists` and `limit` write nothing. Serialized with every other create.
553
+ */
554
+ createEnvironment(row: Environment, limit: number): Promise<"created" | "exists" | "limit">;
555
+ /**
556
+ * Changes an Environment's columns other than its pod's (the caller holds the row's lock):
557
+ * labels, recipe and version, the applied recipe and its version, the owner guard (`null`
558
+ * clears it), and when it was last used.
559
+ */
560
+ updateEnvironment(id: string, patch: {
561
+ labels?: Record<string, string>;
562
+ recipe?: EnvironmentRecipe;
563
+ version?: number;
564
+ applied?: EnvironmentRecipe;
565
+ appliedVersion?: number;
566
+ ownerUserId?: string | null;
567
+ lastUsedAt?: string;
568
+ diskOp?: DiskOperation | null;
569
+ diskSeed?: DiskSeed | null;
570
+ }, updatedAt: string): Promise<void>;
571
+ /** Changes a pod Environment's lifecycle columns (the caller holds the row's lock). */
572
+ updateEnvironmentPod(id: string, patch: SandboxPodPatch, updatedAt: string): Promise<void>;
573
+ /** Deletes the Environment; its vault and credentials go with it (foreign key). */
574
+ deleteEnvironment(id: string): Promise<void>;
575
+ /** Environments by id, those with every label in `labels` when it is given. */
576
+ listEnvironments(filter?: {
503
577
  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>[]>;
578
+ }): Promise<Environment[]>;
579
+ /** Sessions that name Environment `environmentId` (`Session.environmentId`), by id. */
580
+ sessionsOnEnvironment<T extends SessionDoc = SessionDoc>(environmentId: string): Promise<StoredSession<T>[]>;
507
581
  /**
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).
582
+ * Appends an event to the Environment's lifecycle stream through the record module. The
583
+ * caller holds the Environment row's lock (or created the row in this transaction).
510
584
  */
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?: {
514
- fromSeq?: number;
515
- limit?: number;
516
- }): Promise<SandboxEvent[]>;
585
+ environmentEvent<T extends EnvironmentEventType>(environmentId: string, type: T, payload: EnvironmentEventPayload<T>): Promise<EnvironmentEvent>;
586
+ /**
587
+ * The Environment's stream, from `fromSeq` on, at most `limit` events: only `types` when given,
588
+ * and only events recorded at or after `since` and before `until` (ISO times) when given.
589
+ */
590
+ environmentEvents(environmentId: string, options?: EnvironmentEventsQuery): Promise<EnvironmentEvent[]>;
591
+ /** Holds manifest `name`'s save lock until the transaction ends, so saves of one name are serial. */
592
+ lockEnvironmentManifest(name: string): Promise<void>;
593
+ /** Version `version` of manifest `name`, or its latest when `version` is omitted. */
594
+ environmentManifest(name: string, version?: number): Promise<EnvironmentManifestRow | undefined>;
595
+ /** Writes a new version (the caller holds the name's lock and chose the next number). */
596
+ insertEnvironmentManifest(row: EnvironmentManifestRow): Promise<void>;
597
+ /** Each manifest's latest version, by name. */
598
+ listEnvironmentManifests(): Promise<EnvironmentManifestRow[]>;
599
+ /** Every version of manifest `name`, newest first. */
600
+ environmentManifestVersions(name: string): Promise<EnvironmentManifestRow[]>;
601
+ /** Deletes every version of manifest `name`; how many there were. */
602
+ deleteEnvironmentManifest(name: string): Promise<number>;
603
+ /** How many Environments were made from each version of manifest `name` (deleting ones too). */
604
+ environmentsOfManifest(name: string): Promise<Map<number, number>>;
517
605
  /** `invoking` effects of one session; takeover turns them `uncertain`. */
518
606
  invokingEffects<T extends EffectDoc = EffectDoc>(sessionId: string): Promise<T[]>;
519
607
  effectsForSession<T extends EffectDoc = EffectDoc>(sessionId: string, filter?: SessionEffectFilter): Promise<T[]>;
@@ -549,20 +637,20 @@ export interface Tx {
549
637
  putPrincipal(id: string, tokenHash: string, createdAt: string, role?: KeyRole): Promise<PrincipalRow>;
550
638
  /** Deletes principal `id`; false when there was none. */
551
639
  deletePrincipal(id: string): Promise<boolean>;
552
- /** Rejects on a duplicate id, or a second `host` vault. */
640
+ /** Rejects on a duplicate id, or a second vault for one Environment. */
553
641
  insertVault(row: VaultRow): Promise<void>;
554
642
  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[]>;
643
+ /** The vault of Environment `environmentId` (D56). */
644
+ vaultOfEnvironment(environmentId: string): Promise<VaultRow | undefined>;
559
645
  updateVaultMetadata(id: string, metadataJson: string | null): Promise<void>;
560
646
  /** Deletes the vault and its credentials. */
561
647
  deleteVault(id: string): Promise<void>;
562
648
  /** Rejects on a duplicate id or an unknown vault. */
563
649
  insertCredential(row: VaultCredentialRow): Promise<void>;
564
- /** Looks a credential up by id alone (attachment checks); callers compare `vaultId`. */
650
+ /** Looks a credential up by id alone; callers compare `vaultId`. */
565
651
  getCredential(id: string): Promise<VaultCredentialRow | undefined>;
652
+ /** The credential named `name` in vault `vaultId` (names are unique per vault). */
653
+ credentialByName(vaultId: string, name: string): Promise<VaultCredentialRow | undefined>;
566
654
  /** Credentials of one vault, ordered by `createdAt`, then id. */
567
655
  credentialsForVault(vaultId: string, filter?: {
568
656
  type?: VaultCredentialRow["type"];
@@ -600,6 +688,11 @@ export interface Tx {
600
688
  countSigningKeys(): Promise<number>;
601
689
  /** Appends a row, setting `duplicate` when one with the same `effectKey` exists; returns it. */
602
690
  recordModelUsage(row: ModelUsageWrite): Promise<ModelUsageRow>;
691
+ /**
692
+ * The first row the gate recorded for the model call `effectKey` (R7.1), never a `duplicate`;
693
+ * undefined when no gate metered it.
694
+ */
695
+ modelUsageOf(effectKey: string): Promise<ModelUsageRow | undefined>;
603
696
  modelUsageTotals(query: ModelUsageQuery): Promise<ModelUsageTotals>;
604
697
  /** Every budget, ordered by scope, then scope id. */
605
698
  listModelBudgets(): Promise<ModelBudgetRow[]>;
@@ -608,6 +701,11 @@ export interface Tx {
608
701
  toolCrossing(key: string): Promise<ToolCrossingRow | undefined>;
609
702
  /** Inserts the running call's row; false when a row with `key` already exists. */
610
703
  startToolCrossing(row: Pick<ToolCrossingRow, "key" | "hash" | "startedAt">): Promise<boolean>;
704
+ /**
705
+ * Starts a lost call's row again (R5.3): `startedAt` moves on, on a row with no answer and
706
+ * `hash`. False when the row is gone, settled, or another request's.
707
+ */
708
+ restartToolCrossing(row: Pick<ToolCrossingRow, "key" | "hash" | "startedAt">): Promise<boolean>;
611
709
  /** Records the call's answer. */
612
710
  settleToolCrossing(key: string, answer: unknown, settledAt: string): Promise<void>;
613
711
  /** Deletes rows that settled before `before`; returns how many. */
@@ -616,6 +714,10 @@ export interface Tx {
616
714
  artifact(id: string, options?: {
617
715
  lock?: boolean;
618
716
  }): Promise<ArtifactRow | undefined>;
717
+ /** The folder artifact that holds Environment `environmentId`'s disk versions (R2d step 3). */
718
+ diskArtifact(environmentId: string, options?: {
719
+ lock?: boolean;
720
+ }): Promise<ArtifactRow | undefined>;
619
721
  /** Artifacts by creation time, then id: those of one session when `sessionId` is given. */
620
722
  listArtifacts(filter?: {
621
723
  sessionId?: string;
@@ -632,6 +734,11 @@ export interface Tx {
632
734
  artifactVersions(artifactId: string): Promise<ArtifactVersionRow[]>;
633
735
  /** Deletes the artifact and its versions; returns the versions' blob keys (empty when none). */
634
736
  deleteArtifact(id: string): Promise<string[]>;
737
+ /**
738
+ * Deletes one version of a locked artifact (its content rows go with it) and returns its blob
739
+ * key; the latest version becomes the newest one left. The artifact itself stays, even empty.
740
+ */
741
+ deleteArtifactVersion(artifactId: string, version: number): Promise<string | undefined>;
635
742
  /**
636
743
  * Serializes the Tenant's artifact writes: held until the transaction ends. Take it before
637
744
  * reading the total a new version must fit under.
@@ -677,11 +784,19 @@ export interface Tx {
677
784
  * Tenant's record rows and log heads. The Tenant moves to the next basin
678
785
  * generation and the current one is retired, so session ids it frees start again in an
679
786
  * empty basin;
680
- * - `sandboxes`: sandbox records, sandbox resources and their lifecycle streams;
787
+ * - `environments`: sandbox records, Environments with their vaults, and their lifecycle
788
+ * streams;
681
789
  * - `all`: both, plus definitions (and which definition files they use),
682
- * user vaults with their credentials,
683
790
  * the model usage ledger, the model budgets and Tenant-wide artifacts. The host vault, principals, signing keys,
684
791
  * settings, audit and vault idempotency rows stay.
685
792
  */
686
793
  reset(scope: ResetScope): Promise<void>;
687
794
  }
795
+ /** Which of an Environment's events to read (`Tx.environmentEvents`). */
796
+ export interface EnvironmentEventsQuery {
797
+ readonly fromSeq?: number;
798
+ readonly limit?: number;
799
+ readonly types?: readonly string[];
800
+ readonly since?: string;
801
+ readonly until?: string;
802
+ }
@@ -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[]>;