@capybara-hq/kernel 0.1.0-rc.12 → 0.1.0-rc.14

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 (267) hide show
  1. package/dist/admin/admin.schemas.d.ts +13 -0
  2. package/dist/agents/agent-lookup.d.ts +5 -0
  3. package/dist/agents/agent-lookup.js +15 -0
  4. package/dist/background/background.module.js +2 -2
  5. package/dist/background/launch-lock.d.ts +1 -1
  6. package/dist/background/launch-lock.js +1 -1
  7. package/dist/background/poll.job.d.ts +2 -2
  8. package/dist/background/poll.job.js +10 -10
  9. package/dist/background/stop.d.ts +1 -1
  10. package/dist/background/stop.js +3 -3
  11. package/dist/background/store.d.ts +5 -5
  12. package/dist/background/store.js +5 -5
  13. package/dist/background/tasks.service.d.ts +6 -6
  14. package/dist/background/tasks.service.js +13 -13
  15. package/dist/catalog/admin-catalog.controller.d.ts +13 -2
  16. package/dist/catalog/admin-catalog.controller.js +24 -3
  17. package/dist/catalog/admin-catalog.schemas.d.ts +10 -0
  18. package/dist/catalog/admin-catalog.schemas.js +7 -0
  19. package/dist/catalog/catalog-content.d.ts +9 -1
  20. package/dist/catalog/catalog-content.js +2 -1
  21. package/dist/catalog/catalog-files.d.ts +3 -2
  22. package/dist/catalog/catalog-files.js +8 -5
  23. package/dist/catalog/component-scope.service.d.ts +14 -1
  24. package/dist/catalog/component-scope.service.js +12 -2
  25. package/dist/catalog/marketplaces.service.d.ts +1 -1
  26. package/dist/catalog/org-catalog.controller.d.ts +5 -4
  27. package/dist/catalog/org-catalog.controller.js +5 -4
  28. package/dist/catalog/org-catalog.schemas.d.ts +18 -2
  29. package/dist/catalog/org-catalog.schemas.js +16 -2
  30. package/dist/catalog/org-catalog.service.js +8 -2
  31. package/dist/catalog/plugin-import.js +1 -1
  32. package/dist/catalog/plugin-package.js +37 -9
  33. package/dist/catalog/plugin-upgrade.d.ts +15 -1
  34. package/dist/catalog/plugin-upgrade.js +18 -5
  35. package/dist/channels/channels.module.js +2 -2
  36. package/dist/channels/connections.controller.d.ts +1 -1
  37. package/dist/channels/connections.controller.js +1 -1
  38. package/dist/channels/connections.service.d.ts +22 -5
  39. package/dist/channels/connections.service.js +56 -10
  40. package/dist/channels/inbound.d.ts +8 -8
  41. package/dist/channels/inbound.js +31 -31
  42. package/dist/channels/phrases.d.ts +27 -27
  43. package/dist/channels/phrases.js +27 -27
  44. package/dist/channels/webhook.d.ts +21 -1
  45. package/dist/channels/webhook.js +39 -4
  46. package/dist/config/docs.js +1 -1
  47. package/dist/config/schema.d.ts +2 -2
  48. package/dist/config/schema.js +21 -21
  49. package/dist/conversations/conversations.controller.d.ts +11 -11
  50. package/dist/conversations/conversations.controller.js +15 -15
  51. package/dist/conversations/conversations.module.d.ts +1 -1
  52. package/dist/conversations/conversations.module.js +7 -7
  53. package/dist/conversations/conversations.schemas.js +1 -1
  54. package/dist/conversations/conversations.service.d.ts +14 -14
  55. package/dist/conversations/conversations.service.js +19 -19
  56. package/dist/conversations/{environment-status.d.ts → device-status.d.ts} +9 -9
  57. package/dist/conversations/{environment-status.js → device-status.js} +18 -18
  58. package/dist/conversations/event-log.d.ts +1 -1
  59. package/dist/conversations/event-log.js +1 -1
  60. package/dist/conversations/events.d.ts +1 -1
  61. package/dist/conversations/events.js +2 -2
  62. package/dist/ctx/create-ctx.d.ts +26 -3
  63. package/dist/ctx/create-ctx.js +134 -26
  64. package/dist/db/kernel-schema.d.ts +37 -25
  65. package/dist/{environments → devices}/access.d.ts +19 -19
  66. package/dist/{environments → devices}/access.js +28 -28
  67. package/dist/devices/conversation-devices.d.ts +75 -0
  68. package/dist/{environments/conversation-environments.js → devices/conversation-devices.js} +71 -72
  69. package/dist/devices/devices.controller.d.ts +36 -0
  70. package/dist/{environments/environments.controller.js → devices/devices.controller.js} +37 -37
  71. package/dist/devices/devices.module.d.ts +5 -13
  72. package/dist/devices/devices.module.js +16 -29
  73. package/dist/devices/devices.schemas.d.ts +3 -0
  74. package/dist/devices/devices.schemas.js +14 -0
  75. package/dist/{environments/environments.service.d.ts → devices/devices.service.d.ts} +70 -70
  76. package/dist/{environments/environments.service.js → devices/devices.service.js} +122 -122
  77. package/dist/devices/dto.d.ts +13 -54
  78. package/dist/devices/dto.js +7 -39
  79. package/dist/devices/label.d.ts +11 -0
  80. package/dist/{environments → devices}/label.js +7 -7
  81. package/dist/{environments → devices}/legacy-cleanup.job.d.ts +3 -3
  82. package/dist/{environments → devices}/legacy-cleanup.job.js +3 -3
  83. package/dist/errors.d.ts +29 -25
  84. package/dist/errors.js +29 -25
  85. package/dist/evals/recorded-tools.d.ts +2 -2
  86. package/dist/evals/recorded-tools.js +6 -6
  87. package/dist/extensions/admin-ops.js +1 -0
  88. package/dist/extensions/admin-view.js +2 -0
  89. package/dist/extensions/effective-config.d.ts +6 -0
  90. package/dist/extensions/effective-config.js +18 -7
  91. package/dist/extensions/guide-places.d.ts +66 -0
  92. package/dist/extensions/guide-places.js +152 -0
  93. package/dist/extensions/host.d.ts +13 -2
  94. package/dist/extensions/host.js +27 -6
  95. package/dist/extensions/instance.d.ts +17 -2
  96. package/dist/extensions/instance.js +21 -0
  97. package/dist/extensions/ledger.d.ts +1 -1
  98. package/dist/extensions/permission-set.d.ts +16 -2
  99. package/dist/extensions/permission-set.js +17 -3
  100. package/dist/extensions/permission-view.d.ts +10 -1
  101. package/dist/extensions/plugin-guides.d.ts +207 -54
  102. package/dist/extensions/plugin-guides.js +436 -165
  103. package/dist/files/previewers.d.ts +1 -1
  104. package/dist/files/previewers.js +1 -1
  105. package/dist/http/api.module.js +16 -6
  106. package/dist/http/gateway-routes.d.ts +1 -1
  107. package/dist/http/gateway-routes.js +1 -1
  108. package/dist/identity/settings.d.ts +32 -0
  109. package/dist/identity/settings.js +26 -2
  110. package/dist/infra/config/kernel-config.service.js +4 -4
  111. package/dist/infra/lock/lock.service.d.ts +8 -0
  112. package/dist/infra/lock/lock.service.js +27 -0
  113. package/dist/infra/throttler/named-throttlers.d.ts +4 -1
  114. package/dist/infra/throttler/named-throttlers.js +16 -1
  115. package/dist/infra/throttler/throttler.guard.js +1 -1
  116. package/dist/kernel.module.js +3 -3
  117. package/dist/{devices → local-devices}/device-auth.controller.d.ts +6 -6
  118. package/dist/{devices → local-devices}/device-auth.controller.js +5 -5
  119. package/dist/{devices → local-devices}/device-auth.d.ts +20 -20
  120. package/dist/{devices → local-devices}/device-auth.js +51 -53
  121. package/dist/local-devices/device-auth.module.d.ts +7 -0
  122. package/dist/{devices → local-devices}/device-auth.module.js +5 -5
  123. package/dist/{devices → local-devices}/device-routes.d.ts +3 -3
  124. package/dist/{devices → local-devices}/device-routes.js +2 -2
  125. package/dist/local-devices/dto.d.ts +66 -0
  126. package/dist/local-devices/dto.js +44 -0
  127. package/dist/{devices → local-devices}/keys.d.ts +11 -11
  128. package/dist/{devices → local-devices}/keys.js +11 -11
  129. package/dist/{devices/device-gateway.d.ts → local-devices/local-device-gateway.d.ts} +14 -14
  130. package/dist/{devices/device-gateway.js → local-devices/local-device-gateway.js} +44 -44
  131. package/dist/{devices/device-provider.d.ts → local-devices/local-device-provider.d.ts} +15 -15
  132. package/dist/{devices/device-provider.js → local-devices/local-device-provider.js} +23 -23
  133. package/dist/local-devices/local-devices.module.d.ts +16 -0
  134. package/dist/local-devices/local-devices.module.js +44 -0
  135. package/dist/{devices → local-devices}/machines.d.ts +26 -26
  136. package/dist/{devices → local-devices}/machines.js +71 -71
  137. package/dist/{devices → local-devices}/relay.d.ts +15 -15
  138. package/dist/{devices → local-devices}/relay.js +55 -55
  139. package/dist/{devices → local-devices}/targets.d.ts +8 -8
  140. package/dist/{devices → local-devices}/targets.js +14 -14
  141. package/dist/orgs/offboarding.d.ts +6 -6
  142. package/dist/orgs/offboarding.js +12 -12
  143. package/dist/orgs/settings.service.d.ts +28 -0
  144. package/dist/orgs/settings.service.js +20 -1
  145. package/dist/overrides.d.ts +3 -1
  146. package/dist/overrides.js +2 -0
  147. package/dist/platform/exclusions.js +48 -8
  148. package/dist/platform/operation.js +10 -2
  149. package/dist/platform/ops/admin.ops.js +8 -2
  150. package/dist/platform/ops/connectors.ops.js +2 -0
  151. package/dist/platform/ops/conversations.ops.d.ts +3 -3
  152. package/dist/platform/ops/conversations.ops.js +9 -9
  153. package/dist/platform/ops/devices.ops.d.ts +26 -0
  154. package/dist/platform/ops/devices.ops.js +311 -0
  155. package/dist/platform/ops/org-settings.ops.js +2 -2
  156. package/dist/platform/ops/orgs.ops.js +1 -0
  157. package/dist/platform/ops/setup.ops.d.ts +24 -0
  158. package/dist/platform/ops/setup.ops.js +212 -0
  159. package/dist/platform/ops/ui.ops.d.ts +8 -0
  160. package/dist/platform/ops/ui.ops.js +41 -0
  161. package/dist/platform/platform-ops.module.d.ts +4 -2
  162. package/dist/platform/platform-ops.module.js +13 -5
  163. package/dist/platform/route-schemas.js +11 -3
  164. package/dist/roles/gateway-role.d.ts +3 -3
  165. package/dist/roles/gateway-role.js +4 -4
  166. package/dist/roles/gateway.module.d.ts +1 -1
  167. package/dist/roles/gateway.module.js +5 -5
  168. package/dist/roles/worker.module.js +1 -1
  169. package/dist/runtime/context/build.d.ts +1 -1
  170. package/dist/runtime/context/build.js +6 -6
  171. package/dist/runtime/context/compaction.js +1 -1
  172. package/dist/runtime/context/{environment-paths.d.ts → device-paths.d.ts} +11 -11
  173. package/dist/runtime/context/{environment-paths.js → device-paths.js} +13 -13
  174. package/dist/runtime/maintenance.d.ts +1 -1
  175. package/dist/sandbox/jobs.d.ts +13 -13
  176. package/dist/sandbox/jobs.js +20 -20
  177. package/dist/sandbox/leases.d.ts +9 -9
  178. package/dist/sandbox/leases.js +14 -14
  179. package/dist/sandbox/providers.d.ts +8 -8
  180. package/dist/sandbox/providers.js +8 -8
  181. package/dist/sandbox/sandbox.module.d.ts +1 -1
  182. package/dist/sandbox/sandbox.module.js +1 -1
  183. package/dist/sandbox/sandbox.service.d.ts +76 -76
  184. package/dist/sandbox/sandbox.service.js +230 -230
  185. package/dist/setup/kernel-checks.d.ts +91 -0
  186. package/dist/setup/kernel-checks.js +295 -0
  187. package/dist/setup/oauth-token-probe.d.ts +47 -0
  188. package/dist/setup/oauth-token-probe.js +108 -0
  189. package/dist/setup/redact-check.d.ts +18 -0
  190. package/dist/setup/redact-check.js +46 -0
  191. package/dist/setup/setup-check-registry.d.ts +86 -0
  192. package/dist/setup/setup-check-registry.js +75 -0
  193. package/dist/setup/setup-checks.controller.d.ts +28 -0
  194. package/dist/setup/setup-checks.controller.js +78 -0
  195. package/dist/setup/setup-checks.schemas.d.ts +38 -0
  196. package/dist/setup/setup-checks.schemas.js +43 -0
  197. package/dist/setup/setup-checks.service.d.ts +144 -0
  198. package/dist/setup/setup-checks.service.js +683 -0
  199. package/dist/setup/setup-guides.controller.d.ts +18 -0
  200. package/dist/setup/setup-guides.controller.js +48 -0
  201. package/dist/setup/setup-guides.schemas.d.ts +10 -0
  202. package/dist/setup/setup-guides.schemas.js +6 -0
  203. package/dist/setup/setup-guides.service.d.ts +126 -0
  204. package/dist/setup/setup-guides.service.js +315 -0
  205. package/dist/setup/setup.module.d.ts +8 -0
  206. package/dist/setup/setup.module.js +31 -0
  207. package/dist/tools/builtins/builtin-tools.d.ts +2 -2
  208. package/dist/tools/builtins/builtin-tools.js +5 -5
  209. package/dist/tools/builtins/platform.js +1 -1
  210. package/dist/tools/builtins/sandbox/bash.js +6 -6
  211. package/dist/tools/builtins/sandbox/common.d.ts +25 -25
  212. package/dist/tools/builtins/sandbox/common.js +51 -51
  213. package/dist/tools/builtins/sandbox/edit.js +2 -2
  214. package/dist/tools/builtins/sandbox/index.d.ts +1 -1
  215. package/dist/tools/builtins/sandbox/index.js +1 -1
  216. package/dist/tools/builtins/sandbox/task-output.d.ts +6 -6
  217. package/dist/tools/builtins/sandbox/task-output.js +10 -10
  218. package/dist/tools/builtins/sandbox/task-stop.js +2 -2
  219. package/dist/tools/builtins/sandbox/write.js +2 -2
  220. package/dist/tools/builtins/skill-load.d.ts +1 -1
  221. package/dist/tools/builtins/skill-load.js +2 -2
  222. package/dist/tools/connectors.controller.d.ts +28 -11
  223. package/dist/tools/connectors.controller.js +49 -14
  224. package/dist/tools/connectors.schemas.d.ts +4 -0
  225. package/dist/tools/connectors.schemas.js +4 -0
  226. package/dist/tools/connectors.service.d.ts +30 -2
  227. package/dist/tools/connectors.service.js +98 -3
  228. package/dist/tools/credentials.d.ts +20 -0
  229. package/dist/tools/credentials.js +90 -1
  230. package/dist/tools/oauth/tokens.d.ts +20 -0
  231. package/dist/tools/oauth/tokens.js +49 -24
  232. package/dist/tools/pipeline.js +4 -3
  233. package/dist/tools/registry.d.ts +2 -2
  234. package/dist/tools/tools.module.js +3 -3
  235. package/dist/ui/admin-ui.controller.d.ts +56 -0
  236. package/dist/ui/admin-ui.controller.js +192 -0
  237. package/dist/ui/arrangement.d.ts +74 -0
  238. package/dist/ui/arrangement.js +98 -0
  239. package/dist/ui/embed-token.d.ts +2 -2
  240. package/dist/ui/embed-token.js +30 -5
  241. package/dist/ui/registry.d.ts +29 -14
  242. package/dist/ui/registry.js +31 -10
  243. package/dist/ui/slots.controller.d.ts +11 -0
  244. package/dist/ui/slots.controller.js +25 -0
  245. package/dist/ui/ui-stream.d.ts +20 -3
  246. package/dist/ui/ui-stream.js +25 -7
  247. package/dist/ui/ui.schemas.d.ts +66 -0
  248. package/dist/ui/ui.schemas.js +65 -0
  249. package/dist/ui/views.controller.d.ts +35 -49
  250. package/dist/ui/views.controller.js +48 -70
  251. package/dist/ui/views.d.ts +84 -18
  252. package/dist/ui/views.js +201 -38
  253. package/package.json +3 -3
  254. package/src/migrations/0105_devices_rename.sql +136 -0
  255. package/src/migrations/0106_setup_guides_v2.sql +10 -0
  256. package/dist/devices/device-auth.module.d.ts +0 -7
  257. package/dist/environments/conversation-environments.d.ts +0 -75
  258. package/dist/environments/dto.d.ts +0 -25
  259. package/dist/environments/dto.js +0 -12
  260. package/dist/environments/environments.controller.d.ts +0 -36
  261. package/dist/environments/environments.module.d.ts +0 -8
  262. package/dist/environments/environments.module.js +0 -31
  263. package/dist/environments/environments.schemas.d.ts +0 -3
  264. package/dist/environments/environments.schemas.js +0 -14
  265. package/dist/environments/label.d.ts +0 -11
  266. package/dist/platform/ops/environments.ops.d.ts +0 -26
  267. package/dist/platform/ops/environments.ops.js +0 -311
@@ -20,13 +20,13 @@ import { LIST_TTL_MARGIN_MS } from "./relay.js";
20
20
  export const DEVICE_CLOSE = {
21
21
  /** The kernel is shutting down: reconnect (another gateway replica takes over). */
22
22
  shutdown: 1001,
23
- /** A frame larger than `environments.device.maxFrameBytes` (sent by `ws` itself). */
23
+ /** A frame larger than `devices.local.maxFrameBytes` (sent by `ws` itself). */
24
24
  tooBig: 1009,
25
25
  /** The kernel failed (e.g. the database): reconnect. */
26
26
  internal: 1011,
27
27
  /** The lease was lost (renewal kept failing or the key was taken): reconnect. */
28
28
  leaseLost: 4001,
29
- /** A newer connection of the environment took over: the program exits. */
29
+ /** A newer connection of the device took over: the program exits. */
30
30
  replaced: 4002,
31
31
  /** The machine's credential was revoked: the program exits. */
32
32
  revoked: 4003,
@@ -45,7 +45,7 @@ export const CLAIM_TIMEOUT_MS = 5_000;
45
45
  export const CLAIM_RETRY_MS = 250;
46
46
  /** Traffic marks the machine seen at most this often per connection (the row has its own gate). */
47
47
  const TOUCH_EVERY_MS = 30_000;
48
- /** How often a held connection re-checks its credential (membership, org, environment). */
48
+ /** How often a held connection re-checks its credential (membership, org, device). */
49
49
  const REAUTH_EVERY_MS = 60_000;
50
50
  /**
51
51
  * Puts a frame the holder popped but could not send back at the head of the list, keeping the
@@ -60,7 +60,7 @@ return 1
60
60
  `;
61
61
  /**
62
62
  * Pops the next frame of the request list (`KEYS[1]`) and, when it is a `req`, marks it taken in
63
- * the same step: `<ARGV[1]><id>` → the environment id `ARGV[2]`, for the reconnect grace
63
+ * the same step: `<ARGV[1]><id>` → the device id `ARGV[2]`, for the reconnect grace
64
64
  * `ARGV[3]` ms plus the request's deadline plus the margin `ARGV[4]` ms (ruling R20). Returns the
65
65
  * frame, or false when the list is empty. A frame that is not JSON is returned as is (the caller
66
66
  * drops it). The taken key cannot be declared in KEYS (its id is known only after the pop): like
@@ -79,7 +79,7 @@ return raw
79
79
  `;
80
80
  /**
81
81
  * Accepts a result (ruling R20): only when its request is marked taken (`KEYS[1]`) for the
82
- * environment `ARGV[1]`. Stores the frame `ARGV[2]` under `KEYS[2]` for what is left of the taken
82
+ * device `ARGV[1]`. Stores the frame `ARGV[2]` under `KEYS[2]` for what is left of the taken
83
83
  * mark's TTL (the caller's whole window, also after a reconnect) and clears the mark. Returns 1
84
84
  * when stored, 0 otherwise.
85
85
  */
@@ -120,8 +120,8 @@ class DeviceConnection {
120
120
  this.identity = identity;
121
121
  this.credential = credential;
122
122
  }
123
- get environmentId() {
124
- return this.identity.environmentId;
123
+ get deviceId() {
124
+ return this.identity.deviceId;
125
125
  }
126
126
  start() {
127
127
  const { socket } = this;
@@ -157,7 +157,7 @@ class DeviceConnection {
157
157
  }
158
158
  catch (e) {
159
159
  this.gw.log.warn("device sent an invalid frame", {
160
- environmentId: this.environmentId,
160
+ deviceId: this.deviceId,
161
161
  error: errMsg(e),
162
162
  });
163
163
  this.close(DEVICE_CLOSE.protocol, "invalid frame");
@@ -181,7 +181,7 @@ class DeviceConnection {
181
181
  }
182
182
  catch (e) {
183
183
  this.gw.log.warn("could not record a device hello", {
184
- environmentId: this.environmentId,
184
+ deviceId: this.deviceId,
185
185
  error: errMsg(e),
186
186
  });
187
187
  }
@@ -197,14 +197,14 @@ class DeviceConnection {
197
197
  }
198
198
  /**
199
199
  * Stores one result and announces it (the relay's wire, relay.ts), only for a request taken for
200
- * this environment (ruling R20); anything else is dropped.
200
+ * this device (ruling R20); anything else is dropped.
201
201
  */
202
202
  async store(res) {
203
203
  try {
204
- const stored = await this.gw.redis.eval(ACCEPT, 2, deviceTakenKey(res.id), deviceResKey(res.id), this.environmentId, JSON.stringify(res));
204
+ const stored = await this.gw.redis.eval(ACCEPT, 2, deviceTakenKey(res.id), deviceResKey(res.id), this.deviceId, JSON.stringify(res));
205
205
  if (Number(stored) !== 1) {
206
- this.gw.log.warn("dropping a device result for a request not taken for its environment", {
207
- environmentId: this.environmentId,
206
+ this.gw.log.warn("dropping a device result for a request not taken for its device", {
207
+ deviceId: this.deviceId,
208
208
  });
209
209
  return;
210
210
  }
@@ -212,19 +212,19 @@ class DeviceConnection {
212
212
  }
213
213
  catch (e) {
214
214
  this.gw.log.warn("could not store a device result", {
215
- environmentId: this.environmentId,
215
+ deviceId: this.deviceId,
216
216
  error: errMsg(e),
217
217
  });
218
218
  }
219
219
  }
220
220
  /**
221
- * Claims the environment's lease; true when this connection holds it. The newest connection
221
+ * Claims the device's lease; true when this connection holds it. The newest connection
222
222
  * wins (ruling R21): when another connection holds the lease, a takeover is published (the
223
223
  * holder yields to any takeover) and the lease retried every {@link CLAIM_RETRY_MS} for
224
224
  * {@link CLAIM_TIMEOUT_MS}, then 4409 (the program reconnects). A claimer never yields.
225
225
  */
226
226
  async claim() {
227
- const env = this.environmentId;
227
+ const env = this.deviceId;
228
228
  try {
229
229
  // subscribed before claiming, so a takeover right after the claim is not missed
230
230
  await this.subscribe(deviceTakeoverTopic(env), (p) => {
@@ -253,7 +253,7 @@ class DeviceConnection {
253
253
  return false;
254
254
  }
255
255
  if (!lease) {
256
- this.close(DEVICE_CLOSE.claimTimeout, "the environment is held by another connection");
256
+ this.close(DEVICE_CLOSE.claimTimeout, "the device is held by another connection");
257
257
  return false;
258
258
  }
259
259
  this.lease = lease;
@@ -276,7 +276,7 @@ class DeviceConnection {
276
276
  if (this.state !== "holding")
277
277
  return false;
278
278
  this.gw.log.info("device connected", {
279
- environmentId: env,
279
+ deviceId: env,
280
280
  machineId: this.identity.machineId,
281
281
  });
282
282
  // what was queued while nobody held the machine
@@ -285,7 +285,7 @@ class DeviceConnection {
285
285
  }
286
286
  catch (e) {
287
287
  this.gw.log.warn("could not claim a device connection", {
288
- environmentId: env,
288
+ deviceId: env,
289
289
  error: errMsg(e),
290
290
  });
291
291
  this.close(DEVICE_CLOSE.internal, "internal error");
@@ -306,17 +306,17 @@ class DeviceConnection {
306
306
  .then(() => this.drainOnce())
307
307
  .catch((e) => {
308
308
  this.gw.log.warn("device request drain failed", {
309
- environmentId: this.environmentId,
309
+ deviceId: this.deviceId,
310
310
  error: errMsg(e),
311
311
  });
312
312
  });
313
313
  }
314
314
  async drainOnce() {
315
- const key = deviceReqKey(this.environmentId);
315
+ const key = deviceReqKey(this.deviceId);
316
316
  while (this.state === "holding") {
317
317
  // no lease fencing needed: the pop is atomic, so each frame reaches one connection only, and
318
- // a holder that lost its lease still talks to the environment's own machine (or puts it back)
319
- const raw = (await this.gw.redis.eval(TAKE, 1, key, DEVICE_TAKEN_PREFIX, this.environmentId, String(this.gw.graceMs()), String(LIST_TTL_MARGIN_MS)));
318
+ // a holder that lost its lease still talks to the device's own machine (or puts it back)
319
+ const raw = (await this.gw.redis.eval(TAKE, 1, key, DEVICE_TAKEN_PREFIX, this.deviceId, String(this.gw.graceMs()), String(LIST_TTL_MARGIN_MS)));
320
320
  if (raw === null)
321
321
  return;
322
322
  let frame;
@@ -325,7 +325,7 @@ class DeviceConnection {
325
325
  }
326
326
  catch (e) {
327
327
  this.gw.log.warn("dropping an invalid device request", {
328
- environmentId: this.environmentId,
328
+ deviceId: this.deviceId,
329
329
  error: errMsg(e),
330
330
  });
331
331
  continue;
@@ -343,7 +343,7 @@ class DeviceConnection {
343
343
  ok: false,
344
344
  error: {
345
345
  kind: "error",
346
- message: "The request is larger than environments.device.maxFrameBytes",
346
+ message: "The request is larger than devices.local.maxFrameBytes",
347
347
  },
348
348
  });
349
349
  continue;
@@ -363,7 +363,7 @@ class DeviceConnection {
363
363
  if (this.state === "closed")
364
364
  return;
365
365
  if (this.missedPongs >= 2) {
366
- this.gw.log.info("device connection missed two pongs", { environmentId: this.environmentId });
366
+ this.gw.log.info("device connection missed two pongs", { deviceId: this.deviceId });
367
367
  this.socket.terminate();
368
368
  void this.shutdown();
369
369
  return;
@@ -378,7 +378,7 @@ class DeviceConnection {
378
378
  void this.reauthenticate();
379
379
  }
380
380
  }
381
- /** The credential still stands (membership, org and environment are read live). */
381
+ /** The credential still stands (membership, org and device are read live). */
382
382
  async reauthenticate() {
383
383
  try {
384
384
  const id = await this.gw.machines.authenticate(this.credential);
@@ -388,7 +388,7 @@ class DeviceConnection {
388
388
  }
389
389
  catch (e) {
390
390
  this.gw.log.warn("could not re-check a device credential", {
391
- environmentId: this.environmentId,
391
+ deviceId: this.deviceId,
392
392
  error: errMsg(e),
393
393
  });
394
394
  }
@@ -400,7 +400,7 @@ class DeviceConnection {
400
400
  this.lastTouch = now;
401
401
  this.gw.machines.touch(this.identity.machineId).catch((e) => {
402
402
  this.gw.log.warn("could not mark a machine seen", {
403
- environmentId: this.environmentId,
403
+ deviceId: this.deviceId,
404
404
  error: errMsg(e),
405
405
  });
406
406
  });
@@ -436,7 +436,7 @@ class DeviceConnection {
436
436
  }
437
437
  catch (e) {
438
438
  this.gw.log.warn("could not release a device lease", {
439
- environmentId: this.environmentId,
439
+ deviceId: this.deviceId,
440
440
  error: errMsg(e),
441
441
  });
442
442
  }
@@ -444,7 +444,7 @@ class DeviceConnection {
444
444
  this.gw.forget(this);
445
445
  if (lease) {
446
446
  this.gw.log.info("device disconnected", {
447
- environmentId: this.environmentId,
447
+ deviceId: this.deviceId,
448
448
  machineId: this.identity.machineId,
449
449
  });
450
450
  }
@@ -455,17 +455,17 @@ class DeviceConnection {
455
455
  /**
456
456
  * The gateway role's half of the device relay (environments spec §13.4): holds the WebSocket
457
457
  * connections of connected machines (`GET /device/connect`, device-routes.ts). One connection per
458
- * environment across replicas, under the lease `capk:device-lease:<environmentId>` (the newest
459
- * connection wins: it publishes `device.takeover.<environmentId>` and the holder lets go). The
460
- * holder drains `capk:device-req:<environmentId>` on every `device.req.<environmentId>` nudge,
461
- * once after claiming and on every ping, marking each forwarded request taken for its environment
458
+ * device across replicas, under the lease `capk:device-lease:<deviceId>` (the newest
459
+ * connection wins: it publishes `device.takeover.<deviceId>` and the holder lets go). The
460
+ * holder drains `capk:device-req:<deviceId>` on every `device.req.<deviceId>` nudge,
461
+ * once after claiming and on every ping, marking each forwarded request taken for its device
462
462
  * (`capk:device-taken:<id>`, TTL the reconnect grace plus the request's deadline plus a margin).
463
- * A `res` is accepted only for a request taken for the socket's environment: it is stored under
463
+ * A `res` is accepted only for a request taken for the socket's device: it is stored under
464
464
  * `capk:device-res:<id>` for the rest of that TTL and published on `device.res.<id>`.
465
- * `device.revoked.<environmentId>` closes the connection of that machine only (ruling R16). The
465
+ * `device.revoked.<deviceId>` closes the connection of that machine only (ruling R16). The
466
466
  * sockets are this process's own; everything other replicas need is in Redis.
467
467
  */
468
- let DeviceGateway = class DeviceGateway {
468
+ let LocalDeviceGateway = class LocalDeviceGateway {
469
469
  machines;
470
470
  locks;
471
471
  bus;
@@ -486,13 +486,13 @@ let DeviceGateway = class DeviceGateway {
486
486
  this.log = log;
487
487
  }
488
488
  graceMs() {
489
- return this.config.get().environments.device.reconnectGraceSeconds * 1000;
489
+ return this.config.get().devices.local.reconnectGraceSeconds * 1000;
490
490
  }
491
491
  leaseTtlMs() {
492
- return this.config.get().environments.device.leaseTtlMs;
492
+ return this.config.get().devices.local.leaseTtlMs;
493
493
  }
494
494
  maxFrameBytes() {
495
- return this.config.get().environments.device.maxFrameBytes;
495
+ return this.config.get().devices.local.maxFrameBytes;
496
496
  }
497
497
  /** Who a `Bearer` machine credential stands for, or null (checked before the upgrade). */
498
498
  authenticate(credential) {
@@ -518,7 +518,7 @@ let DeviceGateway = class DeviceGateway {
518
518
  await Promise.all([...this.connections].map((c) => c.close(DEVICE_CLOSE.shutdown, "shutting down")));
519
519
  }
520
520
  };
521
- DeviceGateway = __decorate([
521
+ LocalDeviceGateway = __decorate([
522
522
  Injectable(),
523
523
  __param(0, Inject(MachinesService)),
524
524
  __param(1, Inject(LockService)),
@@ -526,5 +526,5 @@ DeviceGateway = __decorate([
526
526
  __param(3, Inject(REDIS)),
527
527
  __param(4, Inject(KernelConfigService)),
528
528
  __param(5, Inject(KERNEL_LOGGER))
529
- ], DeviceGateway);
530
- export { DeviceGateway };
529
+ ], LocalDeviceGateway);
530
+ export { LocalDeviceGateway };
@@ -1,7 +1,7 @@
1
1
  import type { ExecResult, FileSystemHandle, SandboxHandle, SandboxLimits, SandboxProvider, SandboxRoots } from "@capybara-hq/plugin-sdk";
2
2
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
3
3
  import { SandboxService } from "../sandbox/sandbox.service.js";
4
- import { DeviceRelay } from "./relay.js";
4
+ import { LocalDeviceRelay } from "./relay.js";
5
5
  import { DeviceTargets } from "./targets.js";
6
6
  /** Extra time the machine gets beyond a command's own timeout (spawn, output, the trip back). */
7
7
  export declare const EXEC_DEADLINE_MARGIN_MS = 5000;
@@ -9,42 +9,42 @@ export declare const EXEC_DEADLINE_MARGIN_MS = 5000;
9
9
  export declare const OP_DEADLINE_MS = 30000;
10
10
  /**
11
11
  * Room left in a frame for everything around a `readFile` result's base64 data (the `res`
12
- * envelope): a read is clamped so the machine's answer fits `environments.device.maxFrameBytes`
12
+ * envelope): a read is clamped so the machine's answer fits `devices.local.maxFrameBytes`
13
13
  * (ruling R26).
14
14
  */
15
15
  export declare const FRAME_ENVELOPE_BYTES: number;
16
16
  /** The most raw bytes whose base64 plus {@link FRAME_ENVELOPE_BYTES} fit in `maxFrameBytes`. */
17
17
  export declare const maxReadBytes: (maxFrameBytes: number) => number;
18
18
  /**
19
- * The handle of an instance on a machine: the environment id (ruling R1: the relay is keyed by
20
- * environment), the roots the machine reported at `create`, and the org's effective limits at
19
+ * The handle of an instance on a machine: the device id (ruling R1: the relay is keyed by
20
+ * device), the roots the machine reported at `create`, and the org's effective limits at
21
21
  * creation (for the record: every `exec` carries the org's limits read at that moment, ruling
22
22
  * R27, so the machine intersects its local policy with the current egress).
23
23
  */
24
- export interface DeviceSandboxHandle extends SandboxHandle {
24
+ export interface LocalDeviceHandle extends SandboxHandle {
25
25
  roots: SandboxRoots;
26
26
  limits: SandboxLimits;
27
27
  }
28
- /** The environment id of a `cap-env-<environmentId>` name; undefined for any other name. */
29
- export declare const environmentIdOfName: (name: string) => string | undefined;
28
+ /** The device id of a `cap-device-<deviceId>` name; undefined for any other name. */
29
+ export declare const deviceIdOfName: (name: string) => string | undefined;
30
30
  /**
31
- * The kernel-internal provider `@device` (environments spec §13.5): every operation runs on the
32
- * environment's connected machine through the {@link DeviceRelay}. The file system is the
33
- * machine's environment directory (the program creates it on first use), so `createFileSystem`
31
+ * The kernel-internal provider `@local` (environments spec §13.5): every operation runs on the
32
+ * device's connected machine through the {@link LocalDeviceRelay}. The file system is the
33
+ * machine's device directory (the program creates it on first use), so `createFileSystem`
34
34
  * touches nothing; `suspend` and `destroy` do nothing (the machine is not the platform's to stop);
35
- * deleting the environment leaves the files on the machine where they are. Nothing here throws `environment.offline` on the cleanup paths (ruling R9).
35
+ * deleting the device leaves the files on the machine where they are. Nothing here throws `device.offline` on the cleanup paths (ruling R9).
36
36
  *
37
37
  * The files on a machine are its owner's: `destroyFileSystem` (a files reset, the deletion sweep)
38
38
  * does nothing; the deletion's `stop` comes from `MachinesService.revokeActive` (ruling R24).
39
39
  */
40
- export declare class DeviceSandboxProvider implements SandboxProvider {
40
+ export declare class LocalDeviceProvider implements SandboxProvider {
41
41
  private readonly relay;
42
42
  private readonly targets;
43
43
  private readonly sandbox;
44
44
  private readonly config;
45
45
  readonly concurrentExec: true;
46
46
  readonly sessionIsolation = false;
47
- constructor(relay: DeviceRelay, targets: Pick<DeviceTargets, "orgOf" | "machineRoots">, sandbox: Pick<SandboxService, "orgLimits">, config: Pick<KernelConfigService, "get">);
47
+ constructor(relay: LocalDeviceRelay, targets: Pick<DeviceTargets, "orgOf" | "machineRoots">, sandbox: Pick<SandboxService, "orgLimits">, config: Pick<KernelConfigService, "get">);
48
48
  createFileSystem(args: {
49
49
  name: string;
50
50
  limits: SandboxLimits;
@@ -59,7 +59,7 @@ export declare class DeviceSandboxProvider implements SandboxProvider {
59
59
  limits: SandboxLimits;
60
60
  fileSystem: FileSystemHandle;
61
61
  signal: AbortSignal;
62
- }): Promise<DeviceSandboxHandle>;
62
+ }): Promise<LocalDeviceHandle>;
63
63
  /**
64
64
  * Needs the machine online. `gone` (the kernel recreates the instance) when the active machine
65
65
  * last reported other roots than the instance was created with (a new login into another
@@ -84,6 +84,6 @@ export declare class DeviceSandboxProvider implements SandboxProvider {
84
84
  size: number;
85
85
  isDir: boolean;
86
86
  } | null>;
87
- /** The org's effective limits now (ruling R27); a deleted environment is not found. */
87
+ /** The org's effective limits now (ruling R27); a deleted device is not found. */
88
88
  private currentLimits;
89
89
  }
@@ -9,8 +9,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
12
- import { environmentNotFound, SandboxService } from "../sandbox/sandbox.service.js";
13
- import { DeviceRelay, environmentOffline } from "./relay.js";
12
+ import { deviceNotFound, SandboxService } from "../sandbox/sandbox.service.js";
13
+ import { deviceOffline, LocalDeviceRelay } from "./relay.js";
14
14
  import { DeviceTargets, sameRoots } from "./targets.js";
15
15
  /** Extra time the machine gets beyond a command's own timeout (spawn, output, the trip back). */
16
16
  export const EXEC_DEADLINE_MARGIN_MS = 5000;
@@ -18,30 +18,30 @@ export const EXEC_DEADLINE_MARGIN_MS = 5000;
18
18
  export const OP_DEADLINE_MS = 30_000;
19
19
  /**
20
20
  * Room left in a frame for everything around a `readFile` result's base64 data (the `res`
21
- * envelope): a read is clamped so the machine's answer fits `environments.device.maxFrameBytes`
21
+ * envelope): a read is clamped so the machine's answer fits `devices.local.maxFrameBytes`
22
22
  * (ruling R26).
23
23
  */
24
24
  export const FRAME_ENVELOPE_BYTES = 64 * 1024;
25
25
  /** The most raw bytes whose base64 plus {@link FRAME_ENVELOPE_BYTES} fit in `maxFrameBytes`. */
26
26
  export const maxReadBytes = (maxFrameBytes) => Math.max(0, Math.floor((maxFrameBytes - FRAME_ENVELOPE_BYTES) / 4) * 3);
27
- const NAME_PREFIX = "cap-env-";
28
- /** The environment id of a `cap-env-<environmentId>` name; undefined for any other name. */
29
- export const environmentIdOfName = (name) => name.startsWith(NAME_PREFIX) && name.length > NAME_PREFIX.length
27
+ const NAME_PREFIX = "cap-device-";
28
+ /** The device id of a `cap-device-<deviceId>` name; undefined for any other name. */
29
+ export const deviceIdOfName = (name) => name.startsWith(NAME_PREFIX) && name.length > NAME_PREFIX.length
30
30
  ? name.slice(NAME_PREFIX.length)
31
31
  : undefined;
32
32
  const rootsOf = (h) => h.roots;
33
33
  const bytesOf = (b64) => new Uint8Array(Buffer.from(b64, "base64"));
34
34
  /**
35
- * The kernel-internal provider `@device` (environments spec §13.5): every operation runs on the
36
- * environment's connected machine through the {@link DeviceRelay}. The file system is the
37
- * machine's environment directory (the program creates it on first use), so `createFileSystem`
35
+ * The kernel-internal provider `@local` (environments spec §13.5): every operation runs on the
36
+ * device's connected machine through the {@link LocalDeviceRelay}. The file system is the
37
+ * machine's device directory (the program creates it on first use), so `createFileSystem`
38
38
  * touches nothing; `suspend` and `destroy` do nothing (the machine is not the platform's to stop);
39
- * deleting the environment leaves the files on the machine where they are. Nothing here throws `environment.offline` on the cleanup paths (ruling R9).
39
+ * deleting the device leaves the files on the machine where they are. Nothing here throws `device.offline` on the cleanup paths (ruling R9).
40
40
  *
41
41
  * The files on a machine are its owner's: `destroyFileSystem` (a files reset, the deletion sweep)
42
42
  * does nothing; the deletion's `stop` comes from `MachinesService.revokeActive` (ruling R24).
43
43
  */
44
- let DeviceSandboxProvider = class DeviceSandboxProvider {
44
+ let LocalDeviceProvider = class LocalDeviceProvider {
45
45
  relay;
46
46
  targets;
47
47
  sandbox;
@@ -56,9 +56,9 @@ let DeviceSandboxProvider = class DeviceSandboxProvider {
56
56
  }
57
57
  async createFileSystem(args) {
58
58
  args.signal.throwIfAborted();
59
- const id = environmentIdOfName(args.name);
59
+ const id = deviceIdOfName(args.name);
60
60
  if (id === undefined)
61
- throw new Error(`not an environment name: ${args.name}`);
61
+ throw new Error(`not a device name: ${args.name}`);
62
62
  return { id };
63
63
  }
64
64
  /** The files are the machine owner's: nothing to do (ruling R24; never a `stop`). */
@@ -81,7 +81,7 @@ let DeviceSandboxProvider = class DeviceSandboxProvider {
81
81
  async resume(h, signal) {
82
82
  signal.throwIfAborted();
83
83
  if (!(await this.relay.holderLive(h.id)))
84
- throw environmentOffline();
84
+ throw deviceOffline();
85
85
  const had = rootsOf(h);
86
86
  const now = await this.targets.machineRoots(h.id);
87
87
  if (had === undefined || (now !== null && !sameRoots(had, now)))
@@ -122,7 +122,7 @@ let DeviceSandboxProvider = class DeviceSandboxProvider {
122
122
  }
123
123
  async readFile(h, path, opts) {
124
124
  // the answer must fit one frame: a larger file comes back truncated (Deliver: too large)
125
- const maxBytes = Math.min(opts.maxBytes, maxReadBytes(this.config.get().environments.device.maxFrameBytes));
125
+ const maxBytes = Math.min(opts.maxBytes, maxReadBytes(this.config.get().devices.local.maxFrameBytes));
126
126
  const r = await this.relay.call(h.id, "readFile", { path, maxBytes }, { deadlineMs: OP_DEADLINE_MS, signal: opts.signal });
127
127
  return r === null ? null : { data: bytesOf(r.dataB64), truncated: r.truncated };
128
128
  }
@@ -133,19 +133,19 @@ let DeviceSandboxProvider = class DeviceSandboxProvider {
133
133
  async stat(h, path, signal) {
134
134
  return this.relay.call(h.id, "stat", { path }, { deadlineMs: OP_DEADLINE_MS, signal });
135
135
  }
136
- /** The org's effective limits now (ruling R27); a deleted environment is not found. */
137
- async currentLimits(environmentId) {
138
- const orgId = await this.targets.orgOf(environmentId);
136
+ /** The org's effective limits now (ruling R27); a deleted device is not found. */
137
+ async currentLimits(deviceId) {
138
+ const orgId = await this.targets.orgOf(deviceId);
139
139
  if (orgId === null)
140
- throw environmentNotFound();
140
+ throw deviceNotFound();
141
141
  return this.sandbox.orgLimits(orgId);
142
142
  }
143
143
  };
144
- DeviceSandboxProvider = __decorate([
144
+ LocalDeviceProvider = __decorate([
145
145
  Injectable(),
146
- __param(0, Inject(DeviceRelay)),
146
+ __param(0, Inject(LocalDeviceRelay)),
147
147
  __param(1, Inject(DeviceTargets)),
148
148
  __param(2, Inject(SandboxService)),
149
149
  __param(3, Inject(KernelConfigService))
150
- ], DeviceSandboxProvider);
151
- export { DeviceSandboxProvider };
150
+ ], LocalDeviceProvider);
151
+ export { LocalDeviceProvider };
@@ -0,0 +1,16 @@
1
+ import { type OnModuleInit } from "@nestjs/common";
2
+ import { SandboxProviders } from "../sandbox/providers.js";
3
+ import { LocalDeviceProvider } from "./local-device-provider.js";
4
+ /**
5
+ * Connected machines (environments spec §6, §13): the caller side of the device relay and the
6
+ * kernel-internal `@local` sandbox provider, registered with {@link SandboxProviders} on init, and
7
+ * the machines and their credentials ({@link MachinesService}).
8
+ * Imported on every role: any replica may run a sandbox operation on a local device
9
+ * (the socket itself is held by the gateway role).
10
+ */
11
+ export declare class LocalDevicesModule implements OnModuleInit {
12
+ private readonly providers;
13
+ private readonly provider;
14
+ constructor(providers: SandboxProviders, provider: LocalDeviceProvider);
15
+ onModuleInit(): void;
16
+ }
@@ -0,0 +1,44 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Module } from "@nestjs/common";
11
+ import { LOCAL_PROVIDER, SandboxProviders } from "../sandbox/providers.js";
12
+ import { SandboxModule } from "../sandbox/sandbox.module.js";
13
+ import { LocalDeviceProvider } from "./local-device-provider.js";
14
+ import { MachinesService } from "./machines.js";
15
+ import { LocalDeviceRelay } from "./relay.js";
16
+ import { DeviceTargets } from "./targets.js";
17
+ /**
18
+ * Connected machines (environments spec §6, §13): the caller side of the device relay and the
19
+ * kernel-internal `@local` sandbox provider, registered with {@link SandboxProviders} on init, and
20
+ * the machines and their credentials ({@link MachinesService}).
21
+ * Imported on every role: any replica may run a sandbox operation on a local device
22
+ * (the socket itself is held by the gateway role).
23
+ */
24
+ let LocalDevicesModule = class LocalDevicesModule {
25
+ providers;
26
+ provider;
27
+ constructor(providers, provider) {
28
+ this.providers = providers;
29
+ this.provider = provider;
30
+ }
31
+ onModuleInit() {
32
+ this.providers.register({ plugin: LOCAL_PROVIDER, impl: this.provider });
33
+ }
34
+ };
35
+ LocalDevicesModule = __decorate([
36
+ Module({
37
+ imports: [SandboxModule],
38
+ providers: [DeviceTargets, LocalDeviceRelay, LocalDeviceProvider, MachinesService],
39
+ exports: [LocalDeviceRelay, LocalDeviceProvider, MachinesService],
40
+ }),
41
+ __param(0, Inject(SandboxProviders)),
42
+ __param(1, Inject(LocalDeviceProvider))
43
+ ], LocalDevicesModule);
44
+ export { LocalDevicesModule };