@capybara-hq/kernel 0.1.0-rc.67 → 0.1.0-rc.69
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.
- package/bootstrap.json +9 -1
- package/dist/admin/admin.module.js +2 -0
- package/dist/admin/health.service.d.ts +11 -4
- package/dist/admin/health.service.js +33 -17
- package/dist/background/poll.job.js +2 -2
- package/dist/background/tasks.service.d.ts +5 -5
- package/dist/background/tasks.service.js +9 -8
- package/dist/catalog/credential-key.d.ts +10 -0
- package/dist/catalog/credential-key.js +28 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-upgrade.js +1 -19
- package/dist/catalog/requests.service.js +1 -1
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +9 -9
- package/dist/conversations/conversations.controller.d.ts +8 -3
- package/dist/conversations/conversations.controller.js +8 -3
- package/dist/conversations/conversations.service.d.ts +33 -15
- package/dist/conversations/conversations.service.js +60 -10
- package/dist/conversations/events.d.ts +21 -41
- package/dist/conversations/events.js +57 -31
- package/dist/conversations/permission-profiles.controller.d.ts +6 -4
- package/dist/conversations/permission-profiles.service.d.ts +6 -4
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +77 -6
- package/dist/ctx/device-provider-check.d.ts +6 -2
- package/dist/ctx/device-provider-check.js +17 -2
- package/dist/db/kernel-schema.d.ts +10 -48
- package/dist/devices/access.d.ts +3 -4
- package/dist/devices/access.js +3 -4
- package/dist/devices/conversation-devices.d.ts +1 -3
- package/dist/devices/conversation-devices.js +2 -7
- package/dist/devices/device-projects.service.js +24 -29
- package/dist/devices/device-provider-selection.d.ts +5 -6
- package/dist/devices/device-provider-selection.js +8 -9
- package/dist/devices/devices.controller.d.ts +8 -21
- package/dist/devices/devices.controller.js +9 -34
- package/dist/devices/devices.module.js +6 -4
- package/dist/devices/devices.schemas.d.ts +1 -5
- package/dist/devices/devices.schemas.js +1 -5
- package/dist/devices/devices.service.d.ts +84 -147
- package/dist/devices/devices.service.js +134 -229
- package/dist/devices/dto.d.ts +5 -32
- package/dist/devices/dto.js +5 -37
- package/dist/devices/errors.d.ts +6 -5
- package/dist/devices/errors.js +7 -8
- package/dist/devices/project-rules.d.ts +9 -11
- package/dist/devices/project-rules.js +7 -7
- package/dist/devices/working-root.d.ts +3 -6
- package/dist/devices/working-root.js +3 -8
- package/dist/dial-in/access.d.ts +23 -0
- package/dist/dial-in/access.js +64 -0
- package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
- package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
- package/dist/dial-in/auth.module.d.ts +7 -0
- package/dist/dial-in/auth.module.js +27 -0
- package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
- package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
- package/dist/dial-in/dial-in.module.d.ts +9 -0
- package/dist/dial-in/dial-in.module.js +37 -0
- package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
- package/dist/{local-devices → dial-in}/dto.js +14 -2
- package/dist/dial-in/envelope.d.ts +95 -0
- package/dist/dial-in/envelope.js +89 -0
- package/dist/dial-in/gateway.d.ts +214 -0
- package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
- package/dist/dial-in/handlers.d.ts +47 -0
- package/dist/dial-in/handlers.js +84 -0
- package/dist/dial-in/machines.d.ts +155 -0
- package/dist/dial-in/machines.js +383 -0
- package/dist/dial-in/relay.d.ts +135 -0
- package/dist/dial-in/relay.js +444 -0
- package/dist/dial-in/relay.module.d.ts +7 -0
- package/dist/dial-in/relay.module.js +24 -0
- package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
- package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
- package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
- package/dist/{local-devices → dial-in}/targets.js +3 -48
- package/dist/errors.d.ts +8 -27
- package/dist/errors.js +8 -27
- package/dist/extensions/bootstrap.d.ts +5 -0
- package/dist/extensions/bootstrap.js +10 -1
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +6 -0
- package/dist/extensions/host.js +12 -2
- package/dist/extensions/permission-set.d.ts +15 -1
- package/dist/extensions/permission-set.js +11 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/http/api.module.js +4 -4
- package/dist/http/gateway-routes.d.ts +1 -1
- package/dist/http/gateway-routes.js +1 -1
- package/dist/http/meta.controller.js +1 -1
- package/dist/identity/settings.d.ts +1 -1
- package/dist/identity/settings.js +6 -8
- package/dist/infra/config/kernel-config.service.js +2 -2
- package/dist/infra/outbox/registry.d.ts +0 -14
- package/dist/infra/outbox/registry.js +0 -15
- package/dist/infra/throttler/named-throttlers.d.ts +1 -1
- package/dist/infra/throttler/named-throttlers.js +1 -1
- package/dist/kernel.module.js +0 -3
- package/dist/orgs/settings.service.js +5 -10
- package/dist/overrides.d.ts +0 -4
- package/dist/overrides.js +0 -2
- package/dist/platform/exclusions.js +5 -5
- package/dist/platform/ops/admin.ops.js +1 -1
- package/dist/platform/ops/conversations.ops.js +5 -2
- package/dist/platform/ops/devices.ops.js +11 -24
- package/dist/platform/ops/inbox.ops.js +1 -1
- package/dist/roles/gateway-role.d.ts +3 -3
- package/dist/roles/gateway-role.js +4 -4
- package/dist/roles/gateway.module.d.ts +1 -1
- package/dist/roles/gateway.module.js +5 -5
- package/dist/runtime/context/device-paths.d.ts +4 -1
- package/dist/runtime/context/permission-profile.js +5 -5
- package/dist/runtime/maintenance.d.ts +2 -5
- package/dist/runtime/maintenance.js +9 -19
- package/dist/runtime/project/knowledge.js +4 -5
- package/dist/runtime/project/knowledge.service.js +2 -1
- package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
- package/dist/sandbox/cloud-permission-snapshot.js +1 -3
- package/dist/sandbox/device-reports.d.ts +74 -14
- package/dist/sandbox/device-reports.js +190 -33
- package/dist/sandbox/device-reports.module.d.ts +7 -0
- package/dist/sandbox/device-reports.module.js +25 -0
- package/dist/sandbox/device-sandbox.d.ts +39 -41
- package/dist/sandbox/device-sandbox.js +44 -83
- package/dist/sandbox/kernel-read.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.d.ts +11 -59
- package/dist/sandbox/legacy-retirement.js +34 -186
- package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.module.js +2 -2
- package/dist/sandbox/managed-device-context.d.ts +16 -4
- package/dist/sandbox/managed-device-context.js +25 -8
- package/dist/sandbox/managed-device-context.module.js +4 -0
- package/dist/sandbox/modes.d.ts +3 -12
- package/dist/sandbox/modes.js +2 -14
- package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
- package/dist/{local-devices → sandbox}/network-grants.js +4 -49
- package/dist/sandbox/operation-authority-types.d.ts +2 -1
- package/dist/sandbox/operation-authority.d.ts +6 -20
- package/dist/sandbox/operation-authority.js +43 -104
- package/dist/sandbox/operation-authority.module.js +1 -1
- package/dist/sandbox/operation-intents.d.ts +4 -1
- package/dist/sandbox/operation-intents.js +11 -2
- package/dist/sandbox/operation-reconcile.job.js +2 -4
- package/dist/sandbox/permission-availability.d.ts +6 -7
- package/dist/sandbox/permission-availability.js +7 -10
- package/dist/sandbox/permission-call-grants.d.ts +2 -1
- package/dist/sandbox/permission-call-grants.js +1 -7
- package/dist/sandbox/permission-call-types.d.ts +4 -4
- package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
- package/dist/sandbox/permission-ceiling-writes.js +8 -35
- package/dist/sandbox/permission-config-publication.d.ts +9 -1
- package/dist/sandbox/permission-config-publication.js +29 -21
- package/dist/sandbox/permission-context-types.d.ts +17 -10
- package/dist/sandbox/permission-facts.d.ts +98 -95
- package/dist/sandbox/permission-facts.js +160 -314
- package/dist/sandbox/permission-instance-writes.d.ts +23 -37
- package/dist/sandbox/permission-instance-writes.js +44 -121
- package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
- package/dist/sandbox/permission-runtime-reports.js +105 -122
- package/dist/sandbox/providers.d.ts +26 -38
- package/dist/sandbox/providers.js +36 -18
- package/dist/sandbox/request-not-sent.d.ts +2 -13
- package/dist/sandbox/request-not-sent.js +2 -13
- package/dist/sandbox/review/permission-candidate.d.ts +13 -8
- package/dist/sandbox/review/permission-candidate.js +38 -48
- package/dist/sandbox/sandbox.module.js +7 -3
- package/dist/sandbox/sandbox.service.d.ts +49 -59
- package/dist/sandbox/sandbox.service.js +139 -259
- package/dist/schedules/fire.d.ts +15 -6
- package/dist/schedules/fire.js +27 -13
- package/dist/schedules/grant-rules.js +1 -1
- package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
- package/dist/schedules/scheduled-tasks.service.js +1 -4
- package/dist/schedules/schedules.module.js +5 -3
- package/dist/skills/invoke.d.ts +1 -1
- package/dist/skills/invoke.js +2 -3
- package/dist/tools/approvals.service.d.ts +8 -5
- package/dist/tools/approvals.service.js +5 -5
- package/dist/tools/builtins/sandbox/bash.js +1 -2
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +37 -38
- package/dist/tools/connectors.controller.d.ts +2 -0
- package/dist/tools/connectors.schemas.d.ts +2 -0
- package/dist/tools/credentials.d.ts +2 -0
- package/dist/tools/network-asks.d.ts +19 -22
- package/dist/tools/network-asks.js +15 -21
- package/dist/tools/oauth/authorization-params.d.ts +7 -0
- package/dist/tools/oauth/authorization-params.js +19 -0
- package/dist/tools/oauth/flow.js +7 -0
- package/dist/tools/oauth/tokens.js +2 -1
- package/dist/tools/pipeline.d.ts +6 -7
- package/dist/tools/pipeline.js +17 -21
- package/dist/tools/tools.module.js +3 -7
- package/package.json +3 -4
- package/src/migrations/0177_dial_in_contract.sql +32 -0
- package/dist/local-devices/device-auth.module.d.ts +0 -7
- package/dist/local-devices/device-auth.module.js +0 -25
- package/dist/local-devices/device-policy.service.d.ts +0 -213
- package/dist/local-devices/device-policy.service.js +0 -605
- package/dist/local-devices/instance-bindings.d.ts +0 -82
- package/dist/local-devices/instance-bindings.js +0 -307
- package/dist/local-devices/local-device-gateway.d.ts +0 -153
- package/dist/local-devices/local-device-provider.d.ts +0 -122
- package/dist/local-devices/local-device-provider.js +0 -326
- package/dist/local-devices/local-devices.module.d.ts +0 -31
- package/dist/local-devices/local-devices.module.js +0 -100
- package/dist/local-devices/machines.d.ts +0 -211
- package/dist/local-devices/machines.js +0 -766
- package/dist/local-devices/owner-report.d.ts +0 -81
- package/dist/local-devices/owner-report.js +0 -150
- package/dist/local-devices/owner-reports.d.ts +0 -48
- package/dist/local-devices/owner-reports.js +0 -208
- package/dist/local-devices/policy-op-jobs.d.ts +0 -15
- package/dist/local-devices/policy-op-jobs.js +0 -12
- package/dist/local-devices/policy-summary.d.ts +0 -102
- package/dist/local-devices/policy-summary.js +0 -155
- package/dist/local-devices/relay.d.ts +0 -166
- package/dist/local-devices/relay.js +0 -559
- package/dist/tools/device-op-resolver.d.ts +0 -34
- package/dist/tools/device-op-resolver.js +0 -120
- /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
- /package/dist/{local-devices → dial-in}/keys.js +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
|
@@ -7,14 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { isDeviceBootId } from "@capybara-hq/plugin-sdk";
|
|
11
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
11
|
import { sql } from "kysely";
|
|
13
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
13
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
15
14
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
16
15
|
import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
17
|
-
import { isInternalProvider, LOCAL_PROVIDER } from "./providers.js";
|
|
18
16
|
/**
|
|
19
17
|
* Legacy retirement (permission runtime cutover phase 8.5): the durable legacy-launch freeze and
|
|
20
18
|
* the physical no-reuse obligations of old instance incarnations (migration 0157).
|
|
@@ -35,11 +33,10 @@ import { isInternalProvider, LOCAL_PROVIDER } from "./providers.js";
|
|
|
35
33
|
* names the row. Obligations live apart from the task rows, so output retention never removes
|
|
36
34
|
* them, and task finish and event semantics stay with the task's own finisher.
|
|
37
35
|
* - **Resolution** is the sandbox service's, under the device's exclusive lifecycle lease
|
|
38
|
-
* (`SandboxService` gate):
|
|
39
|
-
* destruction, the file system kept) or found destroyed by a recorded
|
|
40
|
-
*
|
|
41
|
-
* quarantined. Nothing here resolves on a new generation, a
|
|
42
|
-
* timeout or a process scan.
|
|
36
|
+
* (`SandboxService` gate), the same for every provider: an incarnation is destroyed whole by its
|
|
37
|
+
* provider (confirmed destruction, the file system kept) or found destroyed by a recorded
|
|
38
|
+
* confirmed destruction; a replaced one without recorded destruction and an unknown one are
|
|
39
|
+
* quarantined. Nothing here resolves on a new generation, a timeout or a process scan.
|
|
43
40
|
*/
|
|
44
41
|
/** The freeze's single row id. */
|
|
45
42
|
const FREEZE_ID = "platform";
|
|
@@ -85,25 +82,27 @@ const MAY_HAVE_DISPATCHED = sql `(
|
|
|
85
82
|
OR t.kill_pending
|
|
86
83
|
OR (t.sid IS NULL AND t.legacy_dispatch <> 'reserved')
|
|
87
84
|
)`;
|
|
88
|
-
/**
|
|
89
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Whether `provider` names a provider (one whose whole-instance destroy is confirmed): any
|
|
87
|
+
* recorded provider, the same for every one, never the `unknown` of an incarnation the kernel
|
|
88
|
+
* cannot name.
|
|
89
|
+
*/
|
|
90
|
+
export const isKnownProvider = (provider) => provider !== "unknown";
|
|
90
91
|
/** The epoch millisecond of `d` as recorded generation text. */
|
|
91
92
|
const generationOf = (d) => String(d.getTime());
|
|
92
93
|
/**
|
|
93
94
|
* The incarnation a legacy row's obligation is keyed by: the one it started in, else the one its
|
|
94
95
|
* dispatch was admitted for; a historical reservation without either is `unknown`, never the
|
|
95
|
-
* instance current now (I2). Its own provider:
|
|
96
|
-
*
|
|
96
|
+
* instance current now (I2). Its own provider: the admitted one, else the instance row's only
|
|
97
|
+
* when it is that incarnation, else `unknown` (M6).
|
|
97
98
|
*/
|
|
98
99
|
function legacyKey(r) {
|
|
99
100
|
const generation = r.sandbox_created_at !== null
|
|
100
101
|
? generationOf(new Date(r.sandbox_created_at))
|
|
101
102
|
: (r.legacy_dispatch_generation ?? "unknown");
|
|
102
103
|
const current = r.instance_created_at !== null && generationOf(r.instance_created_at) === generation;
|
|
103
|
-
const provider = r.
|
|
104
|
-
?
|
|
105
|
-
: (r.legacy_dispatch_provider ??
|
|
106
|
-
(current && r.instance_provider ? r.instance_provider : "unknown"));
|
|
104
|
+
const provider = r.legacy_dispatch_provider ??
|
|
105
|
+
(current && r.instance_provider ? r.instance_provider : "unknown");
|
|
107
106
|
return { provider, generation };
|
|
108
107
|
}
|
|
109
108
|
const toObligation = (r) => ({
|
|
@@ -115,7 +114,6 @@ const toObligation = (r) => ({
|
|
|
115
114
|
state: r.state,
|
|
116
115
|
reason: r.reason,
|
|
117
116
|
attempts: r.attempts,
|
|
118
|
-
bootId: r.boot_id,
|
|
119
117
|
createdAt: r.created_at,
|
|
120
118
|
});
|
|
121
119
|
let LegacyRetirementStore = class LegacyRetirementStore {
|
|
@@ -204,11 +202,11 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
204
202
|
/**
|
|
205
203
|
* The worker's sweep of obligations whose device is gone (its row missing, `deleted_at` set, or
|
|
206
204
|
* its org soft-deleted), at most `limit` per call:
|
|
207
|
-
* -
|
|
205
|
+
* - one waits while the device's instance row exists:
|
|
208
206
|
* its destroy is still owed (the destroy job or the destruction sweep deletes the row when it
|
|
209
207
|
* is done) and records the destruction then;
|
|
210
208
|
* - one whose exact incarnation has a recorded confirmed destruction resolves
|
|
211
|
-
* `provider-destroyed`, an already `abandoned`
|
|
209
|
+
* `provider-destroyed`, an already `abandoned` one too (provider evidence, not a
|
|
212
210
|
* reopen);
|
|
213
211
|
* - every other one becomes `abandoned`. Device ids are never reused, so no device can acquire
|
|
214
212
|
* that incarnation again, but abandonment is no evidence that its processes ended (they may
|
|
@@ -217,7 +215,7 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
217
215
|
*/
|
|
218
216
|
async abandonDeleted(limit) {
|
|
219
217
|
let resolved = 0, abandoned = 0;
|
|
220
|
-
// abandoned
|
|
218
|
+
// abandoned obligations that gained a matching recorded destruction
|
|
221
219
|
const evidenced = await this.db
|
|
222
220
|
.selectFrom("device_retirement_obligations as o")
|
|
223
221
|
.innerJoin("device_instance_destructions as x", (j) => j
|
|
@@ -254,14 +252,11 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
254
252
|
eb("d.deleted_at", "is not", null),
|
|
255
253
|
eb("g.deleted_at", "is not", null),
|
|
256
254
|
]))
|
|
257
|
-
// a
|
|
258
|
-
.where((eb) => eb.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
.select("i.device_id")
|
|
263
|
-
.whereRef("i.device_id", "=", "o.device_id"))),
|
|
264
|
-
]))
|
|
255
|
+
// a destroy still owed keeps its instance row (R2-I2)
|
|
256
|
+
.where((eb) => eb.not(eb.exists(eb
|
|
257
|
+
.selectFrom("device_instances as i")
|
|
258
|
+
.select("i.device_id")
|
|
259
|
+
.whereRef("i.device_id", "=", "o.device_id"))))
|
|
265
260
|
.orderBy("o.created_at")
|
|
266
261
|
.limit(limit)
|
|
267
262
|
.execute();
|
|
@@ -330,7 +325,6 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
330
325
|
"t.sandbox_created_at",
|
|
331
326
|
"t.legacy_dispatch_generation",
|
|
332
327
|
"t.legacy_dispatch_provider",
|
|
333
|
-
"d.source",
|
|
334
328
|
"i.provider as instance_provider",
|
|
335
329
|
"i.created_at as instance_created_at",
|
|
336
330
|
])
|
|
@@ -399,9 +393,6 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
399
393
|
}
|
|
400
394
|
/** The obligation of the incarnation (created when missing), with the member added. */
|
|
401
395
|
async addMember(deviceId, orgId, provider, generation, kind, refId) {
|
|
402
|
-
// a local incarnation keeps the boot its machine reported last: only a later boot of that
|
|
403
|
-
// machine proves its processes gone (none reported: never by itself)
|
|
404
|
-
const boot = isCloudProvider(provider) ? null : await this.currentBoot(deviceId);
|
|
405
396
|
await this.db
|
|
406
397
|
.insertInto("device_retirement_obligations")
|
|
407
398
|
.values({
|
|
@@ -409,8 +400,6 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
409
400
|
org_id: orgId,
|
|
410
401
|
provider,
|
|
411
402
|
instance_generation: generation,
|
|
412
|
-
boot_machine_id: boot?.machineId ?? null,
|
|
413
|
-
boot_id: boot?.bootId ?? null,
|
|
414
403
|
})
|
|
415
404
|
.onConflict((oc) => oc.columns(["device_id", "provider", "instance_generation"]).doNothing())
|
|
416
405
|
.execute();
|
|
@@ -428,138 +417,20 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
428
417
|
.onConflict((oc) => oc.columns(["kind", "ref_id", "obligation_id"]).doNothing())
|
|
429
418
|
.returning("ref_id")
|
|
430
419
|
.executeTakeFirst();
|
|
431
|
-
//
|
|
432
|
-
//
|
|
433
|
-
//
|
|
420
|
+
// an exact cancel covers only the refs it stopped, and the incarnation lives on (B-22): a
|
|
421
|
+
// member found later (a row of an old replica) reopens the obligation; so does one found on
|
|
422
|
+
// an incarnation an old replica resolved by a restart of its computer
|
|
434
423
|
if (r !== undefined &&
|
|
435
424
|
obligation.state === "resolved" &&
|
|
436
425
|
(obligation.resolution === "host-rebooted" || obligation.resolution === "exact-cancelled")) {
|
|
437
|
-
// read under the obligation's lock: a hello that resolved it meanwhile is seen (M1); a
|
|
438
|
-
// cloud incarnation has no boot
|
|
439
|
-
const now = isCloudProvider(provider) ? null : await this.currentBoot(deviceId);
|
|
440
426
|
await this.db
|
|
441
427
|
.updateTable("device_retirement_obligations")
|
|
442
|
-
.set({
|
|
443
|
-
state: "open",
|
|
444
|
-
resolution: null,
|
|
445
|
-
resolved_at: null,
|
|
446
|
-
boot_machine_id: now?.machineId ?? null,
|
|
447
|
-
boot_id: now?.bootId ?? null,
|
|
448
|
-
})
|
|
428
|
+
.set({ state: "open", resolution: null, resolved_at: null })
|
|
449
429
|
.where("id", "=", obligation.id)
|
|
450
430
|
.execute();
|
|
451
431
|
}
|
|
452
432
|
return r !== undefined;
|
|
453
433
|
}
|
|
454
|
-
/** The device's active machine and the boot it reported last (null: no machine). */
|
|
455
|
-
async currentBoot(deviceId) {
|
|
456
|
-
const m = await this.db
|
|
457
|
-
.selectFrom("device_machines")
|
|
458
|
-
.select(["id", "boot_id"])
|
|
459
|
-
.where("device_id", "=", deviceId)
|
|
460
|
-
.where("revoked_at", "is", null)
|
|
461
|
-
.orderBy("created_at", "desc")
|
|
462
|
-
.orderBy("id", "desc")
|
|
463
|
-
.limit(1)
|
|
464
|
-
.executeTakeFirst();
|
|
465
|
-
return m ? { machineId: m.id, bootId: m.boot_id } : null;
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Records the OS boot identity an authenticated hello of `machineId` reported. The caller is the
|
|
469
|
-
* gateway's hello record, after the connection authenticated with the machine's credential and
|
|
470
|
-
* claimed the device, inside its transaction with the machine row locked. A boot first seen for
|
|
471
|
-
* the machine becomes its current one; the current one again is a reconnect; one seen before a
|
|
472
|
-
* later one (stale, replayed) changes nothing. A new or current boot then settles the device's
|
|
473
|
-
* local obligations recorded under another boot of the computer ({@link settleRebooted}).
|
|
474
|
-
*/
|
|
475
|
-
async recordBoot(machineId, bootId) {
|
|
476
|
-
if (!isDeviceBootId(bootId))
|
|
477
|
-
return "ignored";
|
|
478
|
-
const machine = await this.db
|
|
479
|
-
.selectFrom("device_machines")
|
|
480
|
-
.select(["device_id", "boot_id"])
|
|
481
|
-
.where("id", "=", machineId)
|
|
482
|
-
.where("revoked_at", "is", null)
|
|
483
|
-
.executeTakeFirst();
|
|
484
|
-
if (!machine)
|
|
485
|
-
return "ignored";
|
|
486
|
-
const inserted = await this.db
|
|
487
|
-
.insertInto("device_machine_boots")
|
|
488
|
-
.values({ machine_id: machineId, boot_id: bootId })
|
|
489
|
-
.onConflict((oc) => oc.columns(["machine_id", "boot_id"]).doNothing())
|
|
490
|
-
.returning("seq")
|
|
491
|
-
.executeTakeFirst();
|
|
492
|
-
let report;
|
|
493
|
-
if (inserted !== undefined) {
|
|
494
|
-
await this.db
|
|
495
|
-
.updateTable("device_machines")
|
|
496
|
-
.set({ boot_id: bootId })
|
|
497
|
-
.where("id", "=", machineId)
|
|
498
|
-
.execute();
|
|
499
|
-
report = "new";
|
|
500
|
-
}
|
|
501
|
-
else if (machine.boot_id === bootId)
|
|
502
|
-
report = "current";
|
|
503
|
-
else
|
|
504
|
-
return "stale";
|
|
505
|
-
await this.settleRebooted(machine.device_id);
|
|
506
|
-
return report;
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* A hello without a boot identity: the machine has no current boot any more, so a boot it
|
|
510
|
-
* reported earlier is never taken as the one its later work ran under (M2).
|
|
511
|
-
*/
|
|
512
|
-
async clearBoot(machineId) {
|
|
513
|
-
await this.db
|
|
514
|
-
.updateTable("device_machines")
|
|
515
|
-
.set({ boot_id: null })
|
|
516
|
-
.where("id", "=", machineId)
|
|
517
|
-
.execute();
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Resolves (`host-rebooted`) every unresolved local obligation of the device for which a current
|
|
521
|
-
* (non-revoked) machine of the device has recorded a boot other than the obligation's: the
|
|
522
|
-
* evidence is the OS instance, not the credential, so a re-login on the same computer reporting
|
|
523
|
-
* the same boot changes nothing, and one after a restart (or any later boot) resolves it. A boot
|
|
524
|
-
* that some machine of the device had already reported when the obligation's boot was first
|
|
525
|
-
* seen is an older boot, never evidence (a replay through another credential). An obligation
|
|
526
|
-
* without a recorded boot never resolves here. Returns how many resolved.
|
|
527
|
-
*/
|
|
528
|
-
async settleRebooted(deviceId) {
|
|
529
|
-
const r = await this.db
|
|
530
|
-
.updateTable("device_retirement_obligations as o")
|
|
531
|
-
.set({
|
|
532
|
-
state: "resolved",
|
|
533
|
-
resolution: "host-rebooted",
|
|
534
|
-
resolved_at: sql `now()`,
|
|
535
|
-
last_error: null,
|
|
536
|
-
})
|
|
537
|
-
.where("o.device_id", "=", deviceId)
|
|
538
|
-
.where("o.state", "in", ["open", "quarantined"])
|
|
539
|
-
.where("o.provider", "like", "@%")
|
|
540
|
-
.where("o.boot_id", "is not", null)
|
|
541
|
-
.where(({ exists, selectFrom }) => exists(selectFrom("device_machines as m")
|
|
542
|
-
.select("m.id")
|
|
543
|
-
.whereRef("m.device_id", "=", "o.device_id")
|
|
544
|
-
.where("m.revoked_at", "is", null)
|
|
545
|
-
.where("m.boot_id", "is not", null)
|
|
546
|
-
.whereRef("m.boot_id", "<>", "o.boot_id")
|
|
547
|
-
// not a boot the device's machines had already reported by the obligation's boot
|
|
548
|
-
.where((inner) => inner.not(inner.exists(inner
|
|
549
|
-
.selectFrom("device_machine_boots as seen")
|
|
550
|
-
.innerJoin("device_machines as sm", "sm.id", "seen.machine_id")
|
|
551
|
-
.select("seen.boot_id")
|
|
552
|
-
.whereRef("sm.device_id", "=", "o.device_id")
|
|
553
|
-
.whereRef("seen.boot_id", "=", "m.boot_id")
|
|
554
|
-
.where((e) => e("seen.seq", "<=", e
|
|
555
|
-
.selectFrom("device_machine_boots as ob")
|
|
556
|
-
.innerJoin("device_machines as om", "om.id", "ob.machine_id")
|
|
557
|
-
.select((f) => f.fn.min("ob.seq").as("first"))
|
|
558
|
-
.whereRef("om.device_id", "=", "o.device_id")
|
|
559
|
-
.whereRef("ob.boot_id", "=", "o.boot_id"))))))))
|
|
560
|
-
.executeTakeFirst();
|
|
561
|
-
return Number(r.numUpdatedRows);
|
|
562
|
-
}
|
|
563
434
|
/** The device's unresolved obligations (open and quarantined), oldest first. */
|
|
564
435
|
async unresolved(deviceId) {
|
|
565
436
|
const rows = await this.db
|
|
@@ -573,7 +444,6 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
573
444
|
"state",
|
|
574
445
|
"reason",
|
|
575
446
|
"attempts",
|
|
576
|
-
"boot_id",
|
|
577
447
|
"created_at",
|
|
578
448
|
])
|
|
579
449
|
.where("device_id", "=", deviceId)
|
|
@@ -755,11 +625,11 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
755
625
|
return rows.map((r) => ({ obligationId: r.obligation_id, kind: r.kind, refId: r.ref_id }));
|
|
756
626
|
}
|
|
757
627
|
/**
|
|
758
|
-
* Records the provider-confirmed destruction of
|
|
759
|
-
* provider
|
|
628
|
+
* Records the provider-confirmed destruction of an incarnation, the same for every provider (a
|
|
629
|
+
* provider is trusted like every extension). An `unknown` provider names nothing and is refused.
|
|
760
630
|
*/
|
|
761
631
|
async recordDestruction(deviceId, provider, generation) {
|
|
762
|
-
if (!
|
|
632
|
+
if (!isKnownProvider(provider))
|
|
763
633
|
throw new Error(`A ${provider} destroy is not evidence of destruction`);
|
|
764
634
|
if (!GENERATION_RE.test(generation))
|
|
765
635
|
throw new Error(`invalid generation ${generation}`);
|
|
@@ -769,9 +639,9 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
769
639
|
.onConflict((oc) => oc.columns(["device_id", "provider", "instance_generation"]).doNothing())
|
|
770
640
|
.execute();
|
|
771
641
|
}
|
|
772
|
-
/** Whether a confirmed destruction of exactly that
|
|
642
|
+
/** Whether a confirmed destruction of exactly that incarnation was recorded. */
|
|
773
643
|
async destructionRecorded(deviceId, provider, generation) {
|
|
774
|
-
if (!
|
|
644
|
+
if (!isKnownProvider(provider) || !GENERATION_RE.test(generation))
|
|
775
645
|
return false;
|
|
776
646
|
const row = await this.db
|
|
777
647
|
.selectFrom("device_instance_destructions")
|
|
@@ -897,27 +767,13 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
897
767
|
.executeTakeFirstOrThrow();
|
|
898
768
|
const unresolved = await this.db
|
|
899
769
|
.selectFrom("device_retirement_obligations")
|
|
900
|
-
.select(["device_id", "provider", "instance_generation", "state", "reason"
|
|
770
|
+
.select(["device_id", "provider", "instance_generation", "state", "reason"])
|
|
901
771
|
.where("state", "in", ["open", "quarantined"])
|
|
902
772
|
.orderBy("created_at", "asc")
|
|
903
773
|
.execute();
|
|
904
|
-
const withoutBoot = await this.db
|
|
905
|
-
.selectFrom("background_tasks as t")
|
|
906
|
-
.innerJoin("devices as d", "d.id", "t.device_id")
|
|
907
|
-
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "d.id").on("m.revoked_at", "is", null))
|
|
908
|
-
.select(["t.device_id", "m.id as machine_id"])
|
|
909
|
-
.distinct()
|
|
910
|
-
.where("d.source", "=", "local")
|
|
911
|
-
.where("d.deleted_at", "is", null)
|
|
912
|
-
.where("t.launch_state", "=", "legacy")
|
|
913
|
-
.where(MAY_STILL_RUN)
|
|
914
|
-
.where(MAY_HAVE_DISPATCHED)
|
|
915
|
-
.where((eb) => eb.or([eb("m.id", "is", null), eb("m.boot_id", "is", null)]))
|
|
916
|
-
.orderBy("t.device_id")
|
|
917
|
-
.execute();
|
|
918
774
|
const abandonedRows = await this.db
|
|
919
775
|
.selectFrom("device_retirement_obligations")
|
|
920
|
-
.select(["device_id", "provider", "instance_generation", "
|
|
776
|
+
.select(["device_id", "provider", "instance_generation", "abandoned_at"])
|
|
921
777
|
.where("state", "=", "abandoned")
|
|
922
778
|
.orderBy("abandoned_at", "asc")
|
|
923
779
|
.execute();
|
|
@@ -943,7 +799,6 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
943
799
|
"i.handle as instance_handle",
|
|
944
800
|
"i.had_instance",
|
|
945
801
|
])
|
|
946
|
-
.where("d.source", "=", "cloud")
|
|
947
802
|
.where("d.deleted_at", "is", null)
|
|
948
803
|
.where("t.launch_state", "=", "legacy")
|
|
949
804
|
.where(MAY_STILL_RUN)
|
|
@@ -952,7 +807,7 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
952
807
|
.execute();
|
|
953
808
|
const cloudUnknown = new Map();
|
|
954
809
|
for (const r of cloudCandidates) {
|
|
955
|
-
const key = legacyKey(
|
|
810
|
+
const key = legacyKey(r);
|
|
956
811
|
if (key.generation !== "unknown" && key.provider !== "unknown")
|
|
957
812
|
continue;
|
|
958
813
|
if (cloudUnknown.has(r.device_id))
|
|
@@ -994,22 +849,15 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
994
849
|
deviceId: r.device_id,
|
|
995
850
|
provider: r.provider,
|
|
996
851
|
instanceGeneration: r.instance_generation,
|
|
997
|
-
local: isInternalProvider(r.provider),
|
|
998
|
-
bootKnown: r.boot_id !== null,
|
|
999
852
|
abandonedAt: r.abandoned_at,
|
|
1000
853
|
})),
|
|
1001
854
|
cloudUnknown: [...cloudUnknown].map(([deviceId, flags]) => ({ deviceId, ...flags })),
|
|
1002
|
-
localWithoutBoot: withoutBoot.map((r) => ({
|
|
1003
|
-
deviceId: r.device_id,
|
|
1004
|
-
machineId: r.machine_id,
|
|
1005
|
-
})),
|
|
1006
855
|
unresolved: unresolved.map((r) => ({
|
|
1007
856
|
deviceId: r.device_id,
|
|
1008
857
|
provider: r.provider,
|
|
1009
858
|
instanceGeneration: r.instance_generation,
|
|
1010
859
|
state: r.state,
|
|
1011
860
|
reason: r.reason,
|
|
1012
|
-
bootKnown: r.boot_id !== null,
|
|
1013
861
|
})),
|
|
1014
862
|
};
|
|
1015
863
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The legacy-launch freeze and the retirement obligations (permission runtime cutover 8.5), with
|
|
3
3
|
* only the authority lock they publish and check under: the sandbox service gates every
|
|
4
|
-
* lifecycle acquisition on it, the legacy launch checks the freeze
|
|
5
|
-
*
|
|
4
|
+
* lifecycle acquisition on it (the same for every provider), the legacy launch checks the freeze
|
|
5
|
+
* and the worker's retirement job drives it.
|
|
6
6
|
*/
|
|
7
7
|
export declare class LegacyRetirementModule {
|
|
8
8
|
}
|
|
@@ -10,8 +10,8 @@ import { PermissionCeilingWritesModule } from "./permission-authority.module.js"
|
|
|
10
10
|
/**
|
|
11
11
|
* The legacy-launch freeze and the retirement obligations (permission runtime cutover 8.5), with
|
|
12
12
|
* only the authority lock they publish and check under: the sandbox service gates every
|
|
13
|
-
* lifecycle acquisition on it, the legacy launch checks the freeze
|
|
14
|
-
*
|
|
13
|
+
* lifecycle acquisition on it (the same for every provider), the legacy launch checks the freeze
|
|
14
|
+
* and the worker's retirement job drives it.
|
|
15
15
|
*/
|
|
16
16
|
let LegacyRetirementModule = class LegacyRetirementModule {
|
|
17
17
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { EventLog } from "../conversations/event-log.js";
|
|
2
2
|
import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
|
|
3
|
+
import { DialInMachines } from "../dial-in/machines.js";
|
|
4
|
+
import { ApiError } from "../errors.js";
|
|
3
5
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
6
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
5
7
|
import type { KernelLogger } from "../log.js";
|
|
@@ -9,6 +11,7 @@ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
|
9
11
|
import { PermissionConfigPublication } from "./permission-config-publication.js";
|
|
10
12
|
import { type HeldDeviceContextEvidence, type PermissionContextSubject } from "./permission-context-types.js";
|
|
11
13
|
import { PermissionFacts } from "./permission-facts.js";
|
|
14
|
+
import { DeviceProviders } from "./providers.js";
|
|
12
15
|
/** The tool error text of a managed operation whose held device context went stale (spec B3). */
|
|
13
16
|
export declare const MANAGED_DEVICE_CONTEXT_STALE_TEXT = "Device context changed before this operation. Retry the tool call.";
|
|
14
17
|
/**
|
|
@@ -47,7 +50,7 @@ export declare class ManagedDeviceContextUnavailable extends Error {
|
|
|
47
50
|
constructor();
|
|
48
51
|
}
|
|
49
52
|
/** The managed dependency `common.ts` requires on an activated managed route (spec B3). */
|
|
50
|
-
export type ManagedDeviceContextPort = Pick<ManagedDeviceContextRecorder, "record"
|
|
53
|
+
export type ManagedDeviceContextPort = Pick<ManagedDeviceContextRecorder, "record"> & Partial<Pick<ManagedDeviceContextRecorder, "goneFor">>;
|
|
51
54
|
/**
|
|
52
55
|
* The writer of a managed operation's model-facing device paths (permission context replay spec,
|
|
53
56
|
* "Task 8 exact common.ts handoff"): after a managed tool entered its held instance and before any
|
|
@@ -76,13 +79,21 @@ export declare class ManagedDeviceContextRecorder {
|
|
|
76
79
|
private readonly facts;
|
|
77
80
|
private readonly authority;
|
|
78
81
|
private readonly log;
|
|
79
|
-
|
|
82
|
+
private readonly providers;
|
|
83
|
+
private readonly machines;
|
|
84
|
+
constructor(db: KernelDb, txHost: TransactionHost, events: Pick<EventLog, "appendIn" | "notify">, profiles: Pick<PermissionProfileStore, "readRoot">, locks: Pick<PermissionAuthorityLock, "acquire">, publication: Pick<PermissionConfigPublication, "assertCurrent">, facts: Pick<PermissionFacts, "readAppliedEnvironmentLocked">, authority: Pick<SandboxOperationAuthority, "workingRootFor" | "isActiveMember">, log: Pick<KernelLogger, "warn">, providers: Pick<DeviceProviders, "forDevice">, machines: Pick<DialInMachines, "activeFor">);
|
|
80
85
|
/**
|
|
81
86
|
* Records the managed device paths of `held` into the calling conversation's log, or nothing
|
|
82
87
|
* when unchanged. Requires the run's real execution claim (`RunExecution.withClaim`) and no open
|
|
83
88
|
* transaction. A revoked execution keeps its identical `ExecutionRevoked`, an abort its reason.
|
|
84
89
|
*/
|
|
85
90
|
record(input: PermissionContextSubject, held: Readonly<HeldDeviceContextEvidence>, signal: AbortSignal): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* The gone error of a held instance whose evidence is missing (its device deleted, its machine
|
|
93
|
+
* revoked): what never comes back says so instead of the unavailable answer. Undefined while the
|
|
94
|
+
* device is live (or the conversation moved to another device).
|
|
95
|
+
*/
|
|
96
|
+
goneFor(input: PermissionContextSubject, deviceId: string): Promise<ApiError | undefined>;
|
|
86
97
|
/**
|
|
87
98
|
* The gone error to answer instead of a stale context: only while the conversation's root still
|
|
88
99
|
* works on the held device (a conversation moved to another device keeps the stale "retry", the
|
|
@@ -91,8 +102,9 @@ export declare class ManagedDeviceContextRecorder {
|
|
|
91
102
|
private goneInstead;
|
|
92
103
|
/**
|
|
93
104
|
* The error of a device state that never comes back: the device (or its org) deleted, or a
|
|
94
|
-
*
|
|
95
|
-
*
|
|
105
|
+
* device of a dial-in provider without an active machine (revoked, signed out:
|
|
106
|
+
* {@link DialInMachines.activeFor}). Undefined while it is live; a provider that is not loaded
|
|
107
|
+
* here is not asked.
|
|
96
108
|
*/
|
|
97
109
|
private goneError;
|
|
98
110
|
private mapped;
|
|
@@ -13,6 +13,7 @@ import { EventLog } from "../conversations/event-log.js";
|
|
|
13
13
|
import { ManagedDevicePathsV1Schema, } from "../conversations/events.js";
|
|
14
14
|
import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
|
|
15
15
|
import { deviceNotFound, machineRevoked } from "../devices/errors.js";
|
|
16
|
+
import { DialInMachines } from "../dial-in/machines.js";
|
|
16
17
|
import { ApiError } from "../errors.js";
|
|
17
18
|
import { afterCommit } from "../infra/database/after-commit.js";
|
|
18
19
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -27,6 +28,7 @@ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
|
27
28
|
import { PermissionConfigPublication } from "./permission-config-publication.js";
|
|
28
29
|
import { PermissionContextSubjectChanged, } from "./permission-context-types.js";
|
|
29
30
|
import { PermissionFacts } from "./permission-facts.js";
|
|
31
|
+
import { DeviceProviders, servesDialIn } from "./providers.js";
|
|
30
32
|
/** The tool error text of a managed operation whose held device context went stale (spec B3). */
|
|
31
33
|
export const MANAGED_DEVICE_CONTEXT_STALE_TEXT = "Device context changed before this operation. Retry the tool call.";
|
|
32
34
|
/**
|
|
@@ -103,7 +105,9 @@ let ManagedDeviceContextRecorder = class ManagedDeviceContextRecorder {
|
|
|
103
105
|
facts;
|
|
104
106
|
authority;
|
|
105
107
|
log;
|
|
106
|
-
|
|
108
|
+
providers;
|
|
109
|
+
machines;
|
|
110
|
+
constructor(db, txHost, events, profiles, locks, publication, facts, authority, log, providers, machines) {
|
|
107
111
|
this.db = db;
|
|
108
112
|
this.txHost = txHost;
|
|
109
113
|
this.events = events;
|
|
@@ -113,6 +117,8 @@ let ManagedDeviceContextRecorder = class ManagedDeviceContextRecorder {
|
|
|
113
117
|
this.facts = facts;
|
|
114
118
|
this.authority = authority;
|
|
115
119
|
this.log = log;
|
|
120
|
+
this.providers = providers;
|
|
121
|
+
this.machines = machines;
|
|
116
122
|
}
|
|
117
123
|
/**
|
|
118
124
|
* Records the managed device paths of `held` into the calling conversation's log, or nothing
|
|
@@ -146,6 +152,14 @@ let ManagedDeviceContextRecorder = class ManagedDeviceContextRecorder {
|
|
|
146
152
|
throw mapped;
|
|
147
153
|
}
|
|
148
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* The gone error of a held instance whose evidence is missing (its device deleted, its machine
|
|
157
|
+
* revoked): what never comes back says so instead of the unavailable answer. Undefined while the
|
|
158
|
+
* device is live (or the conversation moved to another device).
|
|
159
|
+
*/
|
|
160
|
+
async goneFor(input, deviceId) {
|
|
161
|
+
return this.goneInstead(input, deviceId);
|
|
162
|
+
}
|
|
149
163
|
/**
|
|
150
164
|
* The gone error to answer instead of a stale context: only while the conversation's root still
|
|
151
165
|
* works on the held device (a conversation moved to another device keeps the stale "retry", the
|
|
@@ -168,15 +182,15 @@ let ManagedDeviceContextRecorder = class ManagedDeviceContextRecorder {
|
|
|
168
182
|
}
|
|
169
183
|
/**
|
|
170
184
|
* The error of a device state that never comes back: the device (or its org) deleted, or a
|
|
171
|
-
*
|
|
172
|
-
*
|
|
185
|
+
* device of a dial-in provider without an active machine (revoked, signed out:
|
|
186
|
+
* {@link DialInMachines.activeFor}). Undefined while it is live; a provider that is not loaded
|
|
187
|
+
* here is not asked.
|
|
173
188
|
*/
|
|
174
189
|
async goneError(orgId, deviceId) {
|
|
175
190
|
const row = await this.db
|
|
176
191
|
.selectFrom("devices as e")
|
|
177
192
|
.innerJoin("orgs as o", "o.id", "e.org_id")
|
|
178
|
-
.
|
|
179
|
-
.select(["e.source", "m.id as machine_id"])
|
|
193
|
+
.select(["e.provider"])
|
|
180
194
|
.where("e.id", "=", deviceId)
|
|
181
195
|
.where("e.org_id", "=", orgId)
|
|
182
196
|
.where("e.deleted_at", "is", null)
|
|
@@ -184,7 +198,8 @@ let ManagedDeviceContextRecorder = class ManagedDeviceContextRecorder {
|
|
|
184
198
|
.executeTakeFirst();
|
|
185
199
|
if (row === undefined)
|
|
186
200
|
return deviceNotFound();
|
|
187
|
-
|
|
201
|
+
const p = this.providers.forDevice(row.provider);
|
|
202
|
+
if (p !== undefined && servesDialIn(p) && (await this.machines.activeFor(deviceId)) === null)
|
|
188
203
|
return machineRevoked();
|
|
189
204
|
return undefined;
|
|
190
205
|
}
|
|
@@ -298,7 +313,7 @@ let ManagedDeviceContextRecorder = class ManagedDeviceContextRecorder {
|
|
|
298
313
|
applied.provider !== held.provider ||
|
|
299
314
|
applied.instanceId !== held.instanceId ||
|
|
300
315
|
applied.instanceGeneration !== held.instanceGeneration ||
|
|
301
|
-
applied.
|
|
316
|
+
applied.revision !== held.revision ||
|
|
302
317
|
!sameRoots(applied.roots, held.roots))
|
|
303
318
|
throw new ManagedDeviceContextStale();
|
|
304
319
|
const workingRoot = await this.authority.workingRootFor({
|
|
@@ -351,6 +366,8 @@ ManagedDeviceContextRecorder = __decorate([
|
|
|
351
366
|
__param(5, Inject(PermissionConfigPublication)),
|
|
352
367
|
__param(6, Inject(PermissionFacts)),
|
|
353
368
|
__param(7, Inject(SandboxOperationAuthority)),
|
|
354
|
-
__param(8, Inject(KERNEL_LOGGER))
|
|
369
|
+
__param(8, Inject(KERNEL_LOGGER)),
|
|
370
|
+
__param(9, Inject(DeviceProviders)),
|
|
371
|
+
__param(10, Inject(DialInMachines))
|
|
355
372
|
], ManagedDeviceContextRecorder);
|
|
356
373
|
export { ManagedDeviceContextRecorder };
|
|
@@ -7,10 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
8
|
import { EventLogModule } from "../conversations/event-log.js";
|
|
9
9
|
import { PermissionProfileStoreModule } from "../conversations/permission-profile-store.module.js";
|
|
10
|
+
import { DialInModule } from "../dial-in/dial-in.module.js";
|
|
10
11
|
import { ManagedDeviceContextRecorder } from "./managed-device-context.js";
|
|
11
12
|
import { OperationAuthorityModule } from "./operation-authority.module.js";
|
|
12
13
|
import { PermissionAuthorityModule } from "./permission-authority.module.js";
|
|
13
14
|
import { PermissionFactsModule } from "./permission-facts.module.js";
|
|
15
|
+
import { SandboxProviderRegistryModule } from "./providers.module.js";
|
|
14
16
|
/**
|
|
15
17
|
* The managed device context writer (a leaf: no runtime or tools import), which `ToolsModule`
|
|
16
18
|
* imports so `BuiltinTools` can hand it to the managed sandbox route.
|
|
@@ -25,6 +27,8 @@ ManagedDeviceContextModule = __decorate([
|
|
|
25
27
|
PermissionAuthorityModule,
|
|
26
28
|
OperationAuthorityModule,
|
|
27
29
|
PermissionFactsModule,
|
|
30
|
+
SandboxProviderRegistryModule,
|
|
31
|
+
DialInModule,
|
|
28
32
|
],
|
|
29
33
|
providers: [ManagedDeviceContextRecorder],
|
|
30
34
|
exports: [ManagedDeviceContextRecorder],
|
package/dist/sandbox/modes.d.ts
CHANGED
|
@@ -8,8 +8,7 @@ import { type OutsideSandboxPermission as FullAccessPermission } from "./device-
|
|
|
8
8
|
* Device modes (auto mode spec §4.1–§4.3): who may choose auto mode, and the network each mode
|
|
9
9
|
* gets. One pure function, {@link effectiveDevicePolicy}, combines the platform's switch
|
|
10
10
|
* (`devices.outsideSandbox`), the org's (`outsideSandbox`, `deviceNetwork`) and the device's owner
|
|
11
|
-
* ceiling (
|
|
12
|
-
* and the org).
|
|
11
|
+
* ceiling (its B1 snapshot; null follows the platform and the org).
|
|
13
12
|
* It is a ceiling only: no device-chosen default mode selects how an operation runs (permission
|
|
14
13
|
* runtime cutover 8.6); the conversation's permission profile does, within this ceiling.
|
|
15
14
|
*/
|
|
@@ -78,13 +77,6 @@ export interface EffectiveDevicePolicy {
|
|
|
78
77
|
/** The cloud network (auto mode's open network, the org's allowlist, or the kill switch). */
|
|
79
78
|
network: DeviceNetwork;
|
|
80
79
|
}
|
|
81
|
-
/**
|
|
82
|
-
* How far restricted work may root outside the workspace now (B2), the one rule the command
|
|
83
|
-
* review (`DevicesService.projectReach`) and admission's working root both read: a local device
|
|
84
|
-
* follows its owner's reported reach within a device ceiling that allows auto; a cloud device
|
|
85
|
-
* reaches beyond its workspace only in auto mode.
|
|
86
|
-
*/
|
|
87
|
-
export declare function projectReachOf(source: string, policy: Pick<EffectiveDevicePolicy, "mode" | "allowedMode">, ownerReach: string | null | undefined): "workspace" | "os-user";
|
|
88
80
|
/** The mode the platform and the org allow: `auto` only when neither turns it off. */
|
|
89
81
|
export declare function allowedDeviceMode(platform: FullAccessPermission, org: OrgDeviceSettings["outsideSandbox"]): SandboxMode;
|
|
90
82
|
/** The org's allowlist (the hosts a local device in sandbox mode may reach): {@link orgEffectiveHosts}. */
|
|
@@ -96,9 +88,8 @@ export declare function orgAllowedDomains(deployment: DeploymentDevicePolicy, or
|
|
|
96
88
|
*/
|
|
97
89
|
export declare function deviceNetwork(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, mode: SandboxMode): DeviceNetwork;
|
|
98
90
|
/**
|
|
99
|
-
* The effective device policy. `deviceMode` is the device's owner ceiling (
|
|
100
|
-
*
|
|
101
|
-
* org). A stored mode the platform or org forbids is cut, never honoured; the network follows the
|
|
91
|
+
* The effective device policy. `deviceMode` is the device's owner ceiling (its B1 snapshot or
|
|
92
|
+
* narrowing switch; null = follow the platform and the org). A stored mode the platform or org forbids is cut, never honoured; the network follows the
|
|
102
93
|
* resulting mode.
|
|
103
94
|
*/
|
|
104
95
|
export declare function effectiveDevicePolicy(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, deviceMode: SandboxMode | null,
|