@capybara-hq/kernel 0.1.0-rc.68 → 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/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/marketplaces.service.d.ts +1 -1
- 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/network-asks.d.ts +19 -22
- package/dist/tools/network-asks.js +15 -21
- 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
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { DEVICE_PROTOCOL_VERSION } from "@capybara-hq/plugin-sdk";
|
|
2
1
|
import websocket, {} from "@fastify/websocket";
|
|
3
2
|
import { errorBody } from "../errors.js";
|
|
4
3
|
/** The device connection route (environments spec §13.4). */
|
|
5
4
|
export const DEVICE_CONNECT_ROUTE = "/device/connect";
|
|
6
|
-
/** The header carrying the
|
|
5
|
+
/** The header carrying the dial-in protocol the program speaks (`<name>/<major>`). */
|
|
7
6
|
export const DEVICE_PROTOCOL_HEADER = "x-capybara-device-protocol";
|
|
8
7
|
/** The comma-separated tokens of a header, lowercased. */
|
|
9
8
|
function tokens(v) {
|
|
@@ -32,14 +31,36 @@ function bearer(req) {
|
|
|
32
31
|
const m = typeof h === "string" ? /^Bearer\s+(\S+)\s*$/i.exec(h) : null;
|
|
33
32
|
return m?.[1] ?? "";
|
|
34
33
|
}
|
|
34
|
+
/** A `<name>/<major>` protocol split in two; null for anything else. */
|
|
35
|
+
function protocolParts(v) {
|
|
36
|
+
const m = /^([a-z][a-z0-9-]{0,40})\/([1-9][0-9]{0,3})$/.exec(v);
|
|
37
|
+
return m ? { name: m[1], major: Number(m[2]) } : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The text of a 426: the device's provider speaks `expected`, the program `spoken`. A program of
|
|
41
|
+
* the same protocol family with a newer major is told the deployment is the one to upgrade; an
|
|
42
|
+
* older one (or another protocol) to update the program. The program's protocol is named only
|
|
43
|
+
* when it is a well-formed `<name>/<major>` (header input).
|
|
44
|
+
*/
|
|
45
|
+
export function protocolMismatchMessage(plugin, expected, spoken) {
|
|
46
|
+
const theirs = typeof spoken === "string" ? protocolParts(spoken) : null;
|
|
47
|
+
const ours = protocolParts(expected);
|
|
48
|
+
const said = theirs
|
|
49
|
+
? `this program speaks ${theirs.name}/${theirs.major}`
|
|
50
|
+
: "this program speaks another protocol";
|
|
51
|
+
const fix = theirs && ours && theirs.name === ours.name && theirs.major > ours.major
|
|
52
|
+
? "This deployment is older than the program; ask the platform's super admin to upgrade it, or install the program release that matches this deployment."
|
|
53
|
+
: "Update the program on the machine to the release that speaks this protocol (for capybara-device: npm install -g @capybara-hq/device@next), then start it again.";
|
|
54
|
+
return `This device is served by ${plugin}, which speaks ${expected}; ${said}. ${fix}`;
|
|
55
|
+
}
|
|
35
56
|
/**
|
|
36
57
|
* Registers `GET /device/connect` (the gateway role only) in its own encapsulated scope with
|
|
37
58
|
* `@fastify/websocket`: a raw Fastify route outside Nest, so neither the API's `AuthGuard` nor its
|
|
38
|
-
* CSRF check applies
|
|
39
|
-
* `device.credential_invalid`), then the
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
59
|
+
* CSRF check applies. Before the upgrade the route checks the machine credential (401
|
|
60
|
+
* `device.credential_invalid`), then the device's provider: off in the org, not loaded or not a
|
|
61
|
+
* dial-in provider is 403 `device.provider_unavailable`; then the protocol header, which must
|
|
62
|
+
* equal the provider's `permissions.dialIn.protocol` (426 `device.program_outdated`, naming the
|
|
63
|
+
* provider's protocol).
|
|
43
64
|
* Must be called before Nest `app.init()`, on the root instance.
|
|
44
65
|
*
|
|
45
66
|
* `@fastify/websocket` sends every upgrade request of the server through the Fastify router; the
|
|
@@ -62,41 +83,40 @@ export async function registerDeviceConnectRoute(fastify, opts) {
|
|
|
62
83
|
});
|
|
63
84
|
await fastify.register(async (scope) => {
|
|
64
85
|
await scope.register(websocket, { options: { maxPayload: opts.maxFrameBytes } });
|
|
65
|
-
const
|
|
86
|
+
const admitted = new WeakMap();
|
|
66
87
|
scope.get(DEVICE_CONNECT_ROUTE, {
|
|
67
88
|
websocket: true,
|
|
68
89
|
preValidation: async (req, reply) => {
|
|
69
90
|
const cred = bearer(req);
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
91
|
+
const admission = cred === "" ? null : await opts.gateway.admit(cred);
|
|
92
|
+
if (admission === null) {
|
|
72
93
|
return reply
|
|
73
94
|
.code(401)
|
|
74
95
|
.send(errorBody("device.credential_invalid", "The machine credential is unknown or revoked. Run capybara-device logout, then capybara-device login."));
|
|
75
96
|
}
|
|
97
|
+
if ("unavailable" in admission) {
|
|
98
|
+
return reply
|
|
99
|
+
.code(403)
|
|
100
|
+
.send(errorBody("device.provider_unavailable", admission.unavailable === "off"
|
|
101
|
+
? "The provider serving this device is switched off in its organization; ask an organization admin to switch it on."
|
|
102
|
+
: "The provider serving this device cannot accept machine connections now; ask the platform's super admin to check it."));
|
|
103
|
+
}
|
|
104
|
+
const { serving } = admission;
|
|
76
105
|
const spoken = req.headers[DEVICE_PROTOCOL_HEADER];
|
|
77
|
-
if (spoken !==
|
|
78
|
-
// the program's own protocol, named only when it is a plain number (header input)
|
|
79
|
-
const number = typeof spoken === "string" && /^[0-9]{1,3}$/.test(spoken) ? Number(spoken) : null;
|
|
80
|
-
const theirs = number !== null
|
|
81
|
-
? `this capybara-device protocol ${number}`
|
|
82
|
-
: "this capybara-device an older protocol";
|
|
83
|
-
// a newer program than this deployment: the deployment is the one to upgrade
|
|
84
|
-
const fix = number !== null && number > DEVICE_PROTOCOL_VERSION
|
|
85
|
-
? "This deployment is older than the program; ask the platform's super admin to upgrade it, or install the capybara-device release that matches this deployment."
|
|
86
|
-
: "Update capybara-device on the machine (npm install -g @capybara-hq/device@next), then start it again.";
|
|
106
|
+
if (spoken !== serving.protocol) {
|
|
87
107
|
return reply
|
|
88
108
|
.code(426)
|
|
89
|
-
.send(errorBody("device.program_outdated",
|
|
109
|
+
.send(errorBody("device.program_outdated", protocolMismatchMessage(serving.plugin, serving.protocol, spoken)));
|
|
90
110
|
}
|
|
91
|
-
|
|
111
|
+
admitted.set(req, { credential: cred, protocol: serving.protocol });
|
|
92
112
|
},
|
|
93
113
|
}, (socket, req) => {
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
114
|
+
const a = admitted.get(req);
|
|
115
|
+
if (a === undefined) {
|
|
96
116
|
socket.close(4400, "not authenticated");
|
|
97
117
|
return;
|
|
98
118
|
}
|
|
99
|
-
void opts.gateway.accept(socket,
|
|
119
|
+
void opts.gateway.accept(socket, a.credential, a.protocol);
|
|
100
120
|
});
|
|
101
121
|
});
|
|
102
122
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { DeviceFeature, SandboxRoots } from "@capybara-hq/plugin-sdk";
|
|
2
1
|
import type { Redis } from "ioredis";
|
|
3
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
3
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
5
4
|
/**
|
|
6
|
-
* Whether a
|
|
5
|
+
* Whether a dial-in device can still be served: `active` (live and an unrevoked machine),
|
|
7
6
|
* `revoked` (live, no active machine: disconnected or signed out) or `deleted` (missing or
|
|
8
7
|
* deleted, or its org deleted).
|
|
9
8
|
*/
|
|
@@ -14,13 +13,11 @@ export interface DeviceConnectionInfo {
|
|
|
14
13
|
maxFrameBytes: number;
|
|
15
14
|
programRunId?: string;
|
|
16
15
|
}
|
|
17
|
-
/** Whether two sets of roots name the same three directories. */
|
|
18
|
-
export declare const sameRoots: (a: SandboxRoots, b: SandboxRoots) => boolean;
|
|
19
16
|
/**
|
|
20
|
-
* Reads a
|
|
17
|
+
* Reads a dial-in device and its machine connection (PG and Redis) for the relay.
|
|
21
18
|
* The relay asks {@link state} when a machine has no connection, so a revoked machine or a deleted
|
|
22
19
|
* device fails a waiting call at once instead of after the reconnect grace (ruling R27).
|
|
23
|
-
* Kept apart from `
|
|
20
|
+
* Kept apart from `DialInMachines` (which depends on the relay) so there is no dependency cycle.
|
|
24
21
|
*/
|
|
25
22
|
export declare class DeviceTargets {
|
|
26
23
|
private readonly db;
|
|
@@ -47,16 +44,4 @@ export declare class DeviceTargets {
|
|
|
47
44
|
state(deviceId: string): Promise<DeviceTargetState>;
|
|
48
45
|
/** The org of a live device, or null (missing or deleted). */
|
|
49
46
|
orgOf(deviceId: string): Promise<string | null>;
|
|
50
|
-
/**
|
|
51
|
-
* The roots the device's active machine last reported in its hello frame, or null (no
|
|
52
|
-
* active machine, or none reported yet).
|
|
53
|
-
*/
|
|
54
|
-
machineRoots(deviceId: string): Promise<SandboxRoots | null>;
|
|
55
|
-
/** The owner's home directory the active machine reported in its hello, or null. */
|
|
56
|
-
machineHome(deviceId: string): Promise<string | null>;
|
|
57
|
-
/**
|
|
58
|
-
* The features the device's active machine announced in its last hello (known ones only);
|
|
59
|
-
* empty without an active machine.
|
|
60
|
-
*/
|
|
61
|
-
machineFeatures(deviceId: string): Promise<DeviceFeature[]>;
|
|
62
47
|
}
|
|
@@ -12,15 +12,11 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
12
12
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
13
13
|
import { REDIS } from "../infra/tokens.js";
|
|
14
14
|
import { deviceLeaseKey, deviceTransportKey } from "./keys.js";
|
|
15
|
-
import { deviceFeaturesOf } from "./policy-summary.js";
|
|
16
|
-
const ROOT_KEYS = ["workspace", "skills", "tmp"];
|
|
17
|
-
/** Whether two sets of roots name the same three directories. */
|
|
18
|
-
export const sameRoots = (a, b) => ROOT_KEYS.every((k) => a[k] === b[k]);
|
|
19
15
|
/**
|
|
20
|
-
* Reads a
|
|
16
|
+
* Reads a dial-in device and its machine connection (PG and Redis) for the relay.
|
|
21
17
|
* The relay asks {@link state} when a machine has no connection, so a revoked machine or a deleted
|
|
22
18
|
* device fails a waiting call at once instead of after the reconnect grace (ruling R27).
|
|
23
|
-
* Kept apart from `
|
|
19
|
+
* Kept apart from `DialInMachines` (which depends on the relay) so there is no dependency cycle.
|
|
24
20
|
*/
|
|
25
21
|
let DeviceTargets = class DeviceTargets {
|
|
26
22
|
db;
|
|
@@ -63,7 +59,7 @@ let DeviceTargets = class DeviceTargets {
|
|
|
63
59
|
Number.isSafeInteger(cap.maxFrameBytes) &&
|
|
64
60
|
cap.maxFrameBytes >= 1024;
|
|
65
61
|
if (!ok || (await this.locks.holderOf(deviceLeaseKey(deviceId))) !== lease)
|
|
66
|
-
throw new Error("The machine's connection is not ready yet; retry once
|
|
62
|
+
throw new Error("The machine's connection is not ready yet; retry once the machine has reconnected");
|
|
67
63
|
const { connectionId, maxFrameBytes, programRunId } = cap;
|
|
68
64
|
return {
|
|
69
65
|
connectionId,
|
|
@@ -95,47 +91,6 @@ let DeviceTargets = class DeviceTargets {
|
|
|
95
91
|
.executeTakeFirst();
|
|
96
92
|
return row?.org_id ?? null;
|
|
97
93
|
}
|
|
98
|
-
/**
|
|
99
|
-
* The roots the device's active machine last reported in its hello frame, or null (no
|
|
100
|
-
* active machine, or none reported yet).
|
|
101
|
-
*/
|
|
102
|
-
async machineRoots(deviceId) {
|
|
103
|
-
const row = await this.db
|
|
104
|
-
.selectFrom("device_machines")
|
|
105
|
-
.select("roots")
|
|
106
|
-
.where("device_id", "=", deviceId)
|
|
107
|
-
.where("revoked_at", "is", null)
|
|
108
|
-
.executeTakeFirst();
|
|
109
|
-
const r = row?.roots;
|
|
110
|
-
if (!r || typeof r !== "object")
|
|
111
|
-
return null;
|
|
112
|
-
if (!ROOT_KEYS.every((k) => typeof r[k] === "string"))
|
|
113
|
-
return null;
|
|
114
|
-
return r;
|
|
115
|
-
}
|
|
116
|
-
/** The owner's home directory the active machine reported in its hello, or null. */
|
|
117
|
-
async machineHome(deviceId) {
|
|
118
|
-
const row = await this.db
|
|
119
|
-
.selectFrom("device_machines")
|
|
120
|
-
.select("home")
|
|
121
|
-
.where("device_id", "=", deviceId)
|
|
122
|
-
.where("revoked_at", "is", null)
|
|
123
|
-
.executeTakeFirst();
|
|
124
|
-
return row?.home ?? null;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* The features the device's active machine announced in its last hello (known ones only);
|
|
128
|
-
* empty without an active machine.
|
|
129
|
-
*/
|
|
130
|
-
async machineFeatures(deviceId) {
|
|
131
|
-
const row = await this.db
|
|
132
|
-
.selectFrom("device_machines")
|
|
133
|
-
.select("features")
|
|
134
|
-
.where("device_id", "=", deviceId)
|
|
135
|
-
.where("revoked_at", "is", null)
|
|
136
|
-
.executeTakeFirst();
|
|
137
|
-
return deviceFeaturesOf(row?.features);
|
|
138
|
-
}
|
|
139
94
|
};
|
|
140
95
|
DeviceTargets = __decorate([
|
|
141
96
|
Injectable(),
|
package/dist/errors.d.ts
CHANGED
|
@@ -460,32 +460,24 @@ export declare const ERROR_CODES: {
|
|
|
460
460
|
/** The person already has `devices.maxPersonal` live personal devices. */
|
|
461
461
|
readonly "device.limit_reached": 409;
|
|
462
462
|
/**
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
* (ruling R24).
|
|
463
|
+
* The device's provider offers no file reset (its report's `reset` is false): its files are
|
|
464
|
+
* kept where the provider keeps them; the message carries the provider's description.
|
|
466
465
|
*/
|
|
467
466
|
readonly "device.files_on_device": 409;
|
|
468
|
-
/**
|
|
467
|
+
/** A dial-in device's machine is not connected now (no replica holds its lease). */
|
|
469
468
|
readonly "device.offline": 503;
|
|
470
|
-
/** The
|
|
469
|
+
/** The device's machine speaks another dial-in protocol than its provider declares. */
|
|
471
470
|
readonly "device.program_outdated": 426;
|
|
472
471
|
/**
|
|
473
|
-
*
|
|
474
|
-
*
|
|
472
|
+
* A machine connected for a device whose provider is off in the org, not loaded, or serves no
|
|
473
|
+
* dial-in channel (`GET /device/connect`).
|
|
475
474
|
*/
|
|
476
|
-
readonly "device.
|
|
477
|
-
/** The device cannot change its network policy from the platform (cloud, or an older program). */
|
|
478
|
-
readonly "device.policy_unsupported": 409;
|
|
475
|
+
readonly "device.provider_unavailable": 403;
|
|
479
476
|
/**
|
|
480
477
|
* B1: a cloud device's snapshot found applied limits it could not establish exactly; no operation
|
|
481
478
|
* is admitted until a lifecycle action (a file reset) establishes them.
|
|
482
479
|
*/
|
|
483
480
|
readonly "device.permission_reconcile_required": 409;
|
|
484
|
-
readonly "device.owner_report_stale": 409;
|
|
485
|
-
/** A local device's old instance may still run legacy work until the computer restarts (8.5). */
|
|
486
|
-
readonly "device.restart_required": 503;
|
|
487
|
-
/** A local device's old instance may still run legacy work and no restart can prove it (8.5). */
|
|
488
|
-
readonly "device.replace_required": 503;
|
|
489
481
|
/** A cloud device's earlier instance may run legacy work no evidence can cover (8.5). */
|
|
490
482
|
readonly "device.recreate_required": 503;
|
|
491
483
|
/**
|
|
@@ -495,16 +487,7 @@ export declare const ERROR_CODES: {
|
|
|
495
487
|
readonly "device.network_not_allowed": 400;
|
|
496
488
|
/** Running outside the sandbox where the device, its org, the platform or its provider forbids it. */
|
|
497
489
|
readonly "device.outside_sandbox_not_allowed": 409;
|
|
498
|
-
/**
|
|
499
|
-
* A local device's sandbox settings live on its machine: the web narrows them with
|
|
500
|
-
* `POST /devices/:id/policy`, the owner widens them on the machine (`capybara-device ceiling set`,
|
|
501
|
-
* `capybara-device policy add allowedDomains`).
|
|
502
|
-
*/
|
|
503
|
-
readonly "device.ceiling_on_machine": 409;
|
|
504
|
-
/**
|
|
505
|
-
* The device offers no projects (project root §4.1): its `capybara-device` does not announce
|
|
506
|
-
* `projects` (update it), or its cloud sandbox provider has no `list` / `scan`.
|
|
507
|
-
*/
|
|
490
|
+
/** The device offers no projects (project root §4.1): its provider has no `list` / `scan`. */
|
|
508
491
|
readonly "device.projects_unsupported": 409;
|
|
509
492
|
/** The device could not be asked about its directories now; the message says why. */
|
|
510
493
|
readonly "device.projects_unavailable": 503;
|
|
@@ -526,8 +509,6 @@ export declare const ERROR_CODES: {
|
|
|
526
509
|
* cloud devices: the workspace; project root §4.2).
|
|
527
510
|
*/
|
|
528
511
|
readonly "device.project_outside_mode": 422;
|
|
529
|
-
/** Auto mode resolves a relative path against the owner's home, which the device has not reported. */
|
|
530
|
-
readonly "device.project_home_unknown": 409;
|
|
531
512
|
/**
|
|
532
513
|
* The project's path lies above the owner's home (`/`, `/home`, `/Users`, an ancestor of the
|
|
533
514
|
* reported home): too broad to be a project.
|
package/dist/errors.js
CHANGED
|
@@ -460,32 +460,24 @@ export const ERROR_CODES = {
|
|
|
460
460
|
/** The person already has `devices.maxPersonal` live personal devices. */
|
|
461
461
|
"device.limit_reached": 409,
|
|
462
462
|
/**
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
* (ruling R24).
|
|
463
|
+
* The device's provider offers no file reset (its report's `reset` is false): its files are
|
|
464
|
+
* kept where the provider keeps them; the message carries the provider's description.
|
|
466
465
|
*/
|
|
467
466
|
"device.files_on_device": 409,
|
|
468
|
-
/**
|
|
467
|
+
/** A dial-in device's machine is not connected now (no replica holds its lease). */
|
|
469
468
|
"device.offline": 503,
|
|
470
|
-
/** The
|
|
469
|
+
/** The device's machine speaks another dial-in protocol than its provider declares. */
|
|
471
470
|
"device.program_outdated": 426,
|
|
472
471
|
/**
|
|
473
|
-
*
|
|
474
|
-
*
|
|
472
|
+
* A machine connected for a device whose provider is off in the org, not loaded, or serves no
|
|
473
|
+
* dial-in channel (`GET /device/connect`).
|
|
475
474
|
*/
|
|
476
|
-
"device.
|
|
477
|
-
/** The device cannot change its network policy from the platform (cloud, or an older program). */
|
|
478
|
-
"device.policy_unsupported": 409,
|
|
475
|
+
"device.provider_unavailable": 403,
|
|
479
476
|
/**
|
|
480
477
|
* B1: a cloud device's snapshot found applied limits it could not establish exactly; no operation
|
|
481
478
|
* is admitted until a lifecycle action (a file reset) establishes them.
|
|
482
479
|
*/
|
|
483
480
|
"device.permission_reconcile_required": 409,
|
|
484
|
-
"device.owner_report_stale": 409,
|
|
485
|
-
/** A local device's old instance may still run legacy work until the computer restarts (8.5). */
|
|
486
|
-
"device.restart_required": 503,
|
|
487
|
-
/** A local device's old instance may still run legacy work and no restart can prove it (8.5). */
|
|
488
|
-
"device.replace_required": 503,
|
|
489
481
|
/** A cloud device's earlier instance may run legacy work no evidence can cover (8.5). */
|
|
490
482
|
"device.recreate_required": 503,
|
|
491
483
|
/**
|
|
@@ -495,16 +487,7 @@ export const ERROR_CODES = {
|
|
|
495
487
|
"device.network_not_allowed": 400,
|
|
496
488
|
/** Running outside the sandbox where the device, its org, the platform or its provider forbids it. */
|
|
497
489
|
"device.outside_sandbox_not_allowed": 409,
|
|
498
|
-
/**
|
|
499
|
-
* A local device's sandbox settings live on its machine: the web narrows them with
|
|
500
|
-
* `POST /devices/:id/policy`, the owner widens them on the machine (`capybara-device ceiling set`,
|
|
501
|
-
* `capybara-device policy add allowedDomains`).
|
|
502
|
-
*/
|
|
503
|
-
"device.ceiling_on_machine": 409,
|
|
504
|
-
/**
|
|
505
|
-
* The device offers no projects (project root §4.1): its `capybara-device` does not announce
|
|
506
|
-
* `projects` (update it), or its cloud sandbox provider has no `list` / `scan`.
|
|
507
|
-
*/
|
|
490
|
+
/** The device offers no projects (project root §4.1): its provider has no `list` / `scan`. */
|
|
508
491
|
"device.projects_unsupported": 409,
|
|
509
492
|
/** The device could not be asked about its directories now; the message says why. */
|
|
510
493
|
"device.projects_unavailable": 503,
|
|
@@ -526,8 +509,6 @@ export const ERROR_CODES = {
|
|
|
526
509
|
* cloud devices: the workspace; project root §4.2).
|
|
527
510
|
*/
|
|
528
511
|
"device.project_outside_mode": 422,
|
|
529
|
-
/** Auto mode resolves a relative path against the owner's home, which the device has not reported. */
|
|
530
|
-
"device.project_home_unknown": 409,
|
|
531
512
|
/**
|
|
532
513
|
* The project's path lies above the owner's home (`/`, `/home`, `/Users`, an ancestor of the
|
|
533
514
|
* reported home): too broad to be a project.
|
|
@@ -45,6 +45,11 @@ import type { SingleProviderNote } from "./single-provider.js";
|
|
|
45
45
|
* the first pass (`deferBuiltin`: skipped, not a failure; the run is then not recorded and the
|
|
46
46
|
* start runs the second pass), so it may ship skills and templates. A required entry is imported
|
|
47
47
|
* by the first pass and must succeed; a builtin one that fails is logged like an optional one.
|
|
48
|
+
* - An optional preinstall (neither required nor builtin) may carry `scope: "all"`: its catalog
|
|
49
|
+
* item is created with that scope (on in every org, switchable) instead of `optional`. The
|
|
50
|
+
* scope is read only when the item is first imported (a new version of a live item keeps the
|
|
51
|
+
* item's scope), so a later change of `scope` in the manifest never rewrites it: the super
|
|
52
|
+
* admin owns the scope after import.
|
|
48
53
|
* - Only entries new to the manifest are installed (Ruling 5): an optional entry that the last
|
|
49
54
|
* completed run already handled and that is not installed now (a super admin uninstalled
|
|
50
55
|
* it) stays uninstalled -> `kept`. A required or builtin entry is always installed (a
|
|
@@ -71,6 +71,11 @@ import { ExtensionRegistry } from "./registry.js";
|
|
|
71
71
|
* the first pass (`deferBuiltin`: skipped, not a failure; the run is then not recorded and the
|
|
72
72
|
* start runs the second pass), so it may ship skills and templates. A required entry is imported
|
|
73
73
|
* by the first pass and must succeed; a builtin one that fails is logged like an optional one.
|
|
74
|
+
* - An optional preinstall (neither required nor builtin) may carry `scope: "all"`: its catalog
|
|
75
|
+
* item is created with that scope (on in every org, switchable) instead of `optional`. The
|
|
76
|
+
* scope is read only when the item is first imported (a new version of a live item keeps the
|
|
77
|
+
* item's scope), so a later change of `scope` in the manifest never rewrites it: the super
|
|
78
|
+
* admin owns the scope after import.
|
|
74
79
|
* - Only entries new to the manifest are installed (Ruling 5): an optional entry that the last
|
|
75
80
|
* completed run already handled and that is not installed now (a super admin uninstalled
|
|
76
81
|
* it) stays uninstalled -> `kept`. A required or builtin entry is always installed (a
|
|
@@ -833,7 +838,10 @@ let BootstrapService = class BootstrapService {
|
|
|
833
838
|
const { stagingId, review } = git !== undefined
|
|
834
839
|
? await this.prepareGitEntry(e, git, source, imports)
|
|
835
840
|
: await imports.prepare(null, bytes, source);
|
|
836
|
-
await imports.confirm(null, stagingId, {
|
|
841
|
+
await imports.confirm(null, stagingId, {
|
|
842
|
+
reviewHash: review.reviewHash,
|
|
843
|
+
scope: e.scope ?? "optional",
|
|
844
|
+
});
|
|
837
845
|
return true;
|
|
838
846
|
}
|
|
839
847
|
catch (err) {
|
|
@@ -865,6 +873,7 @@ let BootstrapService = class BootstrapService {
|
|
|
865
873
|
const r = await imports.confirm(null, staged.stagingId, {
|
|
866
874
|
reviewHash: staged.review.reviewHash,
|
|
867
875
|
enable,
|
|
876
|
+
scope: e.scope ?? "optional",
|
|
868
877
|
});
|
|
869
878
|
if (r.deploy?.result === "failed") {
|
|
870
879
|
throw new ApiError((r.deploy.code ?? "internal"), r.deploy.message ?? `installing extension ${e.name} failed`);
|
|
@@ -5,10 +5,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
|
+
import { DialInRelayModule } from "../dial-in/relay.module.js";
|
|
8
9
|
import { SuperAdminLockModule } from "../identity/super-admin.js";
|
|
9
10
|
import { ModelsModule } from "../models/models.module.js";
|
|
10
11
|
import { OrgNetworkAllowancesModule } from "../orgs/network-allowances.service.js";
|
|
11
12
|
import { OrgLockModule } from "../orgs/org-lock.js";
|
|
13
|
+
import { DeviceReportsModule } from "../sandbox/device-reports.module.js";
|
|
12
14
|
import { ShareLivenessModule } from "../shares/liveness.js";
|
|
13
15
|
import { StorageModule } from "../storage/storage.module.js";
|
|
14
16
|
import { EmbedTokensModule } from "../ui/embed-token.js";
|
|
@@ -57,6 +59,10 @@ ExtensionsModule = __decorate([
|
|
|
57
59
|
UsageSubscribersModule,
|
|
58
60
|
// ctx.net reads each org's allowed internal endpoints per call
|
|
59
61
|
OrgNetworkAllowancesModule,
|
|
62
|
+
// ctx.dialIn: the dial-in relay (global infrastructure only: no cycle)
|
|
63
|
+
DialInRelayModule,
|
|
64
|
+
// ctx.devices: the stored device reports and the authority epoch (registry and ceiling writes)
|
|
65
|
+
DeviceReportsModule,
|
|
60
66
|
],
|
|
61
67
|
providers: [
|
|
62
68
|
PluginInstallLock,
|
|
@@ -6,6 +6,7 @@ import type { BusSubscriber } from "../ctx/bus.js";
|
|
|
6
6
|
import { type Route } from "../ctx/create-ctx.js";
|
|
7
7
|
import { type ExtensionNetSeams } from "../ctx/net.js";
|
|
8
8
|
import type { Keyring } from "../ctx/secrets.js";
|
|
9
|
+
import { DialInAccess } from "../dial-in/access.js";
|
|
9
10
|
import type { PluginRouteTable } from "../http/plugin-dispatch.js";
|
|
10
11
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
11
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -14,6 +15,7 @@ import type { KernelLogger } from "../log.js";
|
|
|
14
15
|
import { ModelEmbeddings } from "../models/embeddings.js";
|
|
15
16
|
import { ModelImages } from "../models/images.js";
|
|
16
17
|
import { OrgNetworkAllowances } from "../orgs/network-allowances.service.js";
|
|
18
|
+
import { DeviceReports } from "../sandbox/device-reports.js";
|
|
17
19
|
import { ShareLiveness } from "../shares/liveness.js";
|
|
18
20
|
import { EmbedTokens } from "../ui/embed-token.js";
|
|
19
21
|
import type { UiActionHandler, UiRender } from "../ui/registry.js";
|
|
@@ -275,6 +277,10 @@ export declare class ExtensionHost {
|
|
|
275
277
|
images: Pick<ModelImages, "generateForExtension" | "describeForExtension">,
|
|
276
278
|
/** `ctx.net`: the internal endpoints each org's extension requests may reach (read per call). */
|
|
277
279
|
allowances: OrgNetworkAllowances,
|
|
280
|
+
/** `ctx.dialIn`: the dial-in relay and the check that a device is the extension's own. */
|
|
281
|
+
dialIn: DialInAccess,
|
|
282
|
+
/** `ctx.devices`: the stored device reports, read again when a provider says they changed. */
|
|
283
|
+
devices: DeviceReports,
|
|
278
284
|
/** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
|
|
279
285
|
netSeams?: ExtensionNetSeams);
|
|
280
286
|
/** The startup config's `extensionConfig` (file / Nacos merged with env). */
|
package/dist/extensions/host.js
CHANGED
|
@@ -19,6 +19,7 @@ import { EXTENSION_NET_SEAMS } from "../ctx/net.js";
|
|
|
19
19
|
import { kernelDb } from "../db/kernel-schema.js";
|
|
20
20
|
import { migrate } from "../db/migrator.js";
|
|
21
21
|
import { createDb } from "../db/pool.js";
|
|
22
|
+
import { DialInAccess } from "../dial-in/access.js";
|
|
22
23
|
import { waitWithin } from "../infra/close-within.js";
|
|
23
24
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
24
25
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -29,6 +30,7 @@ import { ModelEmbeddings } from "../models/embeddings.js";
|
|
|
29
30
|
import { ModelImages } from "../models/images.js";
|
|
30
31
|
import { OrgNetworkAllowances } from "../orgs/network-allowances.service.js";
|
|
31
32
|
import { packagePath } from "../packages/tgz.js";
|
|
33
|
+
import { DeviceReports } from "../sandbox/device-reports.js";
|
|
32
34
|
import { ShareLiveness } from "../shares/liveness.js";
|
|
33
35
|
import { EmbedTokens } from "../ui/embed-token.js";
|
|
34
36
|
import { ExtensionApprovals, planApprovals, readSnapshots, withPreApproved, } from "./approvals.js";
|
|
@@ -422,6 +424,10 @@ let ExtensionHost = class ExtensionHost {
|
|
|
422
424
|
images,
|
|
423
425
|
/** `ctx.net`: the internal endpoints each org's extension requests may reach (read per call). */
|
|
424
426
|
allowances,
|
|
427
|
+
/** `ctx.dialIn`: the dial-in relay and the check that a device is the extension's own. */
|
|
428
|
+
dialIn,
|
|
429
|
+
/** `ctx.devices`: the stored device reports, read again when a provider says they changed. */
|
|
430
|
+
devices,
|
|
425
431
|
/** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
|
|
426
432
|
netSeams) {
|
|
427
433
|
this.registry = registry;
|
|
@@ -456,6 +462,8 @@ let ExtensionHost = class ExtensionHost {
|
|
|
456
462
|
hooks: this.hooks,
|
|
457
463
|
shares,
|
|
458
464
|
net: { config, allowances, ...(netSeams !== undefined && { seams: netSeams }) },
|
|
465
|
+
dialIn,
|
|
466
|
+
devices,
|
|
459
467
|
locks,
|
|
460
468
|
runWorkers: c.roles.includes("worker"),
|
|
461
469
|
log,
|
|
@@ -2405,7 +2413,9 @@ ExtensionHost = __decorate([
|
|
|
2405
2413
|
__param(15, Inject(ModelEmbeddings)),
|
|
2406
2414
|
__param(16, Inject(ModelImages)),
|
|
2407
2415
|
__param(17, Inject(OrgNetworkAllowances)),
|
|
2408
|
-
__param(18,
|
|
2409
|
-
__param(
|
|
2416
|
+
__param(18, Inject(DialInAccess)),
|
|
2417
|
+
__param(19, Inject(DeviceReports)),
|
|
2418
|
+
__param(20, Optional()),
|
|
2419
|
+
__param(20, Inject(EXTENSION_NET_SEAMS))
|
|
2410
2420
|
], ExtensionHost);
|
|
2411
2421
|
export { ExtensionHost };
|
|
@@ -63,6 +63,14 @@ export interface PermissionSet {
|
|
|
63
63
|
* already gets for the same target). Absent when none are declared (and in older snapshots).
|
|
64
64
|
*/
|
|
65
65
|
setupChecks?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* The dial-in protocol of a device provider whose machines connect to the deployment
|
|
68
|
+
* (`permissions.dialIn`, device provider spec §5): blocking like any other permission. Absent
|
|
69
|
+
* when not declared (and in older snapshots).
|
|
70
|
+
*/
|
|
71
|
+
dialIn?: {
|
|
72
|
+
protocol: string;
|
|
73
|
+
};
|
|
66
74
|
};
|
|
67
75
|
/**
|
|
68
76
|
* 安装记录包迁移警告的摘要(`warningsDigest`,Ruling P4);没有警告或不是安装记录时省略。
|
|
@@ -110,7 +118,8 @@ export declare function buildPermissionSet(input: {
|
|
|
110
118
|
* The stable string keys of a permission set (sorted), such as `provides:channel@1`,
|
|
111
119
|
* `config.org.secret:apiKey`, `table:todos`, `permissions.tools:write`,
|
|
112
120
|
* `permissions.http.<access>:<METHOD> <path>` (`permissions.http.public:POST /events`),
|
|
113
|
-
* `ui.view:tasks`, `ui.embed:board`, `permissions.client`, `ui.component:hud
|
|
121
|
+
* `ui.view:tasks`, `ui.embed:board`, `permissions.client`, `ui.component:hud`,
|
|
122
|
+
* `permissions.dialin:capybara-device/5`.
|
|
114
123
|
* Tolerates old snapshots missing fields (read as empty), so format changes never throw.
|
|
115
124
|
*/
|
|
116
125
|
export declare function permissionKeys(set: PermissionSet): string[];
|
|
@@ -124,6 +133,11 @@ export declare const POLICY_HOOK_KEY_PREFIX = "permissions.hooks.policy:";
|
|
|
124
133
|
* bundle's bytes, is reviewed: an upgrade that only changes the bundle adds no key.
|
|
125
134
|
*/
|
|
126
135
|
export declare const CLIENT_KEY = "permissions.client";
|
|
136
|
+
/**
|
|
137
|
+
* Key prefix of a dial-in protocol (`permissions.dialIn`): blocking. Lower-case letters and dots
|
|
138
|
+
* before the colon, as catalog permission keys require (`PERMISSION_KEY_RE`).
|
|
139
|
+
*/
|
|
140
|
+
export declare const DIAL_IN_KEY_PREFIX = "permissions.dialin:";
|
|
127
141
|
/** Key prefix of a client component (`ui.component:<id>`): sensitive and blocking. */
|
|
128
142
|
export declare const UI_COMPONENT_KEY_PREFIX = "ui.component:";
|
|
129
143
|
/** 渲染 schema 视图的权限键前缀:记入快照但不卡加载(见 {@link blockingKeys})。 */
|
|
@@ -117,6 +117,8 @@ export function buildPermissionSet(input) {
|
|
|
117
117
|
...(p.setupChecks && p.setupChecks.length > 0
|
|
118
118
|
? { setupChecks: sortedUnique(p.setupChecks) }
|
|
119
119
|
: {}),
|
|
120
|
+
// only when declared: sets (and snapshots) of plugins without a dial-in channel stay as they were
|
|
121
|
+
...(p.dialIn ? { dialIn: { protocol: p.dialIn.protocol } } : {}),
|
|
120
122
|
},
|
|
121
123
|
...(input.warningsDigest ? { warningsDigest: input.warningsDigest } : {}),
|
|
122
124
|
};
|
|
@@ -125,7 +127,8 @@ export function buildPermissionSet(input) {
|
|
|
125
127
|
* The stable string keys of a permission set (sorted), such as `provides:channel@1`,
|
|
126
128
|
* `config.org.secret:apiKey`, `table:todos`, `permissions.tools:write`,
|
|
127
129
|
* `permissions.http.<access>:<METHOD> <path>` (`permissions.http.public:POST /events`),
|
|
128
|
-
* `ui.view:tasks`, `ui.embed:board`, `permissions.client`, `ui.component:hud
|
|
130
|
+
* `ui.view:tasks`, `ui.embed:board`, `permissions.client`, `ui.component:hud`,
|
|
131
|
+
* `permissions.dialin:capybara-device/5`.
|
|
129
132
|
* Tolerates old snapshots missing fields (read as empty), so format changes never throw.
|
|
130
133
|
*/
|
|
131
134
|
export function permissionKeys(set) {
|
|
@@ -174,6 +177,8 @@ export function permissionKeys(set) {
|
|
|
174
177
|
keys.push(`${UI_COMPONENT_KEY_PREFIX}${c}`);
|
|
175
178
|
for (const c of p.setupChecks ?? [])
|
|
176
179
|
keys.push(`${SETUP_CHECK_KEY_PREFIX}${c}`);
|
|
180
|
+
if (p.dialIn?.protocol)
|
|
181
|
+
keys.push(`${DIAL_IN_KEY_PREFIX}${p.dialIn.protocol}`);
|
|
177
182
|
if (s.warningsDigest)
|
|
178
183
|
keys.push(`${WARNINGS_KEY_PREFIX}${s.warningsDigest}`);
|
|
179
184
|
return sortedUnique(keys);
|
|
@@ -188,6 +193,11 @@ export const POLICY_HOOK_KEY_PREFIX = "permissions.hooks.policy:";
|
|
|
188
193
|
* bundle's bytes, is reviewed: an upgrade that only changes the bundle adds no key.
|
|
189
194
|
*/
|
|
190
195
|
export const CLIENT_KEY = "permissions.client";
|
|
196
|
+
/**
|
|
197
|
+
* Key prefix of a dial-in protocol (`permissions.dialIn`): blocking. Lower-case letters and dots
|
|
198
|
+
* before the colon, as catalog permission keys require (`PERMISSION_KEY_RE`).
|
|
199
|
+
*/
|
|
200
|
+
export const DIAL_IN_KEY_PREFIX = "permissions.dialin:";
|
|
191
201
|
/** Key prefix of a client component (`ui.component:<id>`): sensitive and blocking. */
|
|
192
202
|
export const UI_COMPONENT_KEY_PREFIX = "ui.component:";
|
|
193
203
|
/** 渲染 schema 视图的权限键前缀:记入快照但不卡加载(见 {@link blockingKeys})。 */
|
|
@@ -12,7 +12,7 @@ import type { ExtensionSource } from "./sources.js";
|
|
|
12
12
|
export declare function reviewHash(set: PermissionSet, warnings?: readonly PackageWarning[]): string;
|
|
13
13
|
/** 权限清单展示用的一组:按类别分组,`sensitive` 标出需要管理员特别留意的类别。 */
|
|
14
14
|
export interface PermissionGroup {
|
|
15
|
-
category: "provides" | "requires" | "optional" | "config" | "tables" | "secrets" | "storage" | "http" | "publicRoutes" | "embedRoutes" | "tools" | "hooks" | "models" | "network" | "ui" | "components" | "client";
|
|
15
|
+
category: "provides" | "requires" | "optional" | "config" | "tables" | "secrets" | "storage" | "http" | "publicRoutes" | "embedRoutes" | "tools" | "hooks" | "models" | "network" | "ui" | "components" | "client" | "dialIn";
|
|
16
16
|
/**
|
|
17
17
|
* Sensitive category: secrets, public routes, tools, hooks, client components, client code; also
|
|
18
18
|
* the "provides" group when it holds one of {@link SENSITIVE_EXTENSION_POINTS}, and the "UI" group
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { pluginSchemaName } from "../ctx/create-ctx.js";
|
|
3
3
|
import { isDestructiveSql, splitSqlStatements } from "../db/sql-statements.js";
|
|
4
|
-
import { CLIENT_KEY, permissionKeys, UI_COMPONENT_KEY_PREFIX, WARNINGS_KEY_PREFIX, } from "./permission-set.js";
|
|
4
|
+
import { CLIENT_KEY, DIAL_IN_KEY_PREFIX, permissionKeys, UI_COMPONENT_KEY_PREFIX, WARNINGS_KEY_PREFIX, } from "./permission-set.js";
|
|
5
5
|
/**
|
|
6
6
|
* Review digest: the first 16 hex digits of `sha256(permissionKeys(set).join("\n"))`; with migration
|
|
7
7
|
* warnings their digest (kind, file, line and statement) is folded in, without warnings it equals the
|
|
@@ -105,6 +105,7 @@ function keyItem(key) {
|
|
|
105
105
|
["ui.embed:", "ui", "embed:"],
|
|
106
106
|
[UI_COMPONENT_KEY_PREFIX, "components", ""],
|
|
107
107
|
["ui.view:", "ui", "view:"],
|
|
108
|
+
[DIAL_IN_KEY_PREFIX, "dialIn", ""],
|
|
108
109
|
];
|
|
109
110
|
for (const [prefix, category, itemPrefix] of table) {
|
|
110
111
|
const rest = after(prefix);
|
|
@@ -179,6 +180,8 @@ export function permissionGroups(set) {
|
|
|
179
180
|
},
|
|
180
181
|
{ category: "components", items: components },
|
|
181
182
|
{ category: "client", items: p.client === true ? [CLIENT_ITEM] : [] },
|
|
183
|
+
// machines that connect to the deployment for this provider's devices, speaking its protocol
|
|
184
|
+
{ category: "dialIn", items: p.dialIn ? [p.dialIn.protocol] : [] },
|
|
182
185
|
];
|
|
183
186
|
return groups
|
|
184
187
|
.filter((g) => g.items.length > 0)
|