@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
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -187,7 +187,12 @@ export class LiveConfig {
|
|
|
187
187
|
* (through `deps.net`, see `ctx/net.ts`);
|
|
188
188
|
* - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
|
|
189
189
|
* only with `permissions.models` (`embed` only its `embedding` purposes, `generateImage` only its
|
|
190
|
-
* `image_generation` ones, through `deps.models`); `
|
|
190
|
+
* `image_generation` ones, through `deps.models`); `dialIn` only with `permissions.dialIn`, each
|
|
191
|
+
* call only for a device whose provider is this extension and that it serves in the device's org
|
|
192
|
+
* (through `deps.dialIn`; another device throws `ExtensionPermissionError`); `devices` only for
|
|
193
|
+
* an extension that provides `device-provider@1`, `reportChanged` only for a live device bound to
|
|
194
|
+
* this extension (through `deps.devices`; another device throws `ExtensionPermissionError`);
|
|
195
|
+
* `http.route`
|
|
191
196
|
* only the method + path declared in `permissions.http` (the record carries the declared access and
|
|
192
197
|
* its mount, see {@link Route}); `tools.register` only names declared in
|
|
193
198
|
* `permissions.tools`; `ui.view` / `ui.action` only ids declared in `permissions.ui.views` or
|
|
@@ -276,6 +281,70 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
|
|
|
276
281
|
},
|
|
277
282
|
}
|
|
278
283
|
: undefined;
|
|
284
|
+
// ctx.dialIn: only with permissions.dialIn, and each call only for a device this extension serves:
|
|
285
|
+
// `devices.provider` is this extension and the extension is enabled in the device's org (read
|
|
286
|
+
// per call). The full availability check (valid org and effective config) runs at the machine's
|
|
287
|
+
// hello (`DialInHandlers`), so a machine of a provider that is not available never connects.
|
|
288
|
+
const dialInApi = perms.dialIn
|
|
289
|
+
? (() => {
|
|
290
|
+
const access = deps.dialIn;
|
|
291
|
+
const served = async (deviceId) => {
|
|
292
|
+
if (!access)
|
|
293
|
+
throw new Error(`plugin ${name}: ctx.dialIn is not available`);
|
|
294
|
+
if (typeof deviceId !== "string" || !(await access.serves(name, deviceId))) {
|
|
295
|
+
const item = `dialIn:device ${String(deviceId)}`;
|
|
296
|
+
const p = recordDenial(deps, name, item).finally(() => audits.delete(p));
|
|
297
|
+
audits.add(p);
|
|
298
|
+
const e = new ExtensionPermissionError(name, "permissions.dialIn");
|
|
299
|
+
e.message = `device ${String(deviceId)} is not served by ${name}`;
|
|
300
|
+
throw e;
|
|
301
|
+
}
|
|
302
|
+
return deviceId;
|
|
303
|
+
};
|
|
304
|
+
return {
|
|
305
|
+
request: async (deviceId, frame, opts) => {
|
|
306
|
+
const id = await served(deviceId);
|
|
307
|
+
const signal = opts?.signal
|
|
308
|
+
? AbortSignal.any([lifecycle.signal, opts.signal])
|
|
309
|
+
: lifecycle.signal;
|
|
310
|
+
// only the options an extension may pass: never the kernel's connection fences
|
|
311
|
+
return access.request(id, frame, {
|
|
312
|
+
timeoutMs: Number(opts?.timeoutMs),
|
|
313
|
+
signal,
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
online: async (deviceId) => access.online(await served(deviceId)),
|
|
317
|
+
stop: async (deviceId, reason) => {
|
|
318
|
+
if (reason !== "drain" && reason !== "stop")
|
|
319
|
+
throw new TypeError(`plugin ${name}: ctx.dialIn.stop reason must be drain or stop`);
|
|
320
|
+
await access.stop(await served(deviceId), reason);
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
})()
|
|
324
|
+
: undefined;
|
|
325
|
+
// ctx.devices: only for a device provider, and each call only for a device bound to it
|
|
326
|
+
// (`devices.provider`, read per call): the kernel reads the report again from this extension
|
|
327
|
+
// and, when its revision changed, moves the device authority epoch (device-provider spec §6.7)
|
|
328
|
+
const devicesApi = manifest.provides.includes(DEVICE_PROVIDER_EXTENSION_POINT)
|
|
329
|
+
? {
|
|
330
|
+
reportChanged: async (deviceId) => {
|
|
331
|
+
const reports = deps.devices;
|
|
332
|
+
if (!reports)
|
|
333
|
+
throw new Error(`plugin ${name}: ctx.devices is not available`);
|
|
334
|
+
const outcome = typeof deviceId === "string"
|
|
335
|
+
? await reports.changed(name, deviceId, lifecycle.signal)
|
|
336
|
+
: "not-served";
|
|
337
|
+
if (outcome === "not-served") {
|
|
338
|
+
const item = `devices:device ${String(deviceId)}`;
|
|
339
|
+
const p = recordDenial(deps, name, item).finally(() => audits.delete(p));
|
|
340
|
+
audits.add(p);
|
|
341
|
+
const e = new ExtensionPermissionError(name, `provides ${DEVICE_PROVIDER_EXTENSION_POINT}`);
|
|
342
|
+
e.message = `device ${String(deviceId)} is not served by ${name}`;
|
|
343
|
+
throw e;
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
}
|
|
347
|
+
: undefined;
|
|
279
348
|
// "METHOD path" -> the access the manifest declares for it (the approved manifest)
|
|
280
349
|
const declaredRoutes = new Map((perms.http ?? []).map((r) => [`${r.method} ${r.path}`, r.access]));
|
|
281
350
|
const declaredTools = new Set(perms.tools ?? []);
|
|
@@ -660,7 +729,7 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
|
|
|
660
729
|
const served = extensionPoint === FILE_PREVIEW_EXTENSION_POINT
|
|
661
730
|
? checkFilePreviewProvider(manifest, impl, uiResolution, deps.log)
|
|
662
731
|
: extensionPoint === DEVICE_PROVIDER_EXTENSION_POINT
|
|
663
|
-
? checkDeviceProvider(name, impl)
|
|
732
|
+
? checkDeviceProvider(name, impl, manifest.permissions?.dialIn)
|
|
664
733
|
: impl;
|
|
665
734
|
provided.set(extensionPoint, served);
|
|
666
735
|
ledger.add({
|
|
@@ -721,15 +790,15 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
|
|
|
721
790
|
return closing;
|
|
722
791
|
},
|
|
723
792
|
};
|
|
724
|
-
// secrets / storage / models: a plain property when declared; otherwise a
|
|
725
|
-
// that throws, so spreading or printing ctx triggers no denial and no audit
|
|
726
|
-
const gated = (key, api) => {
|
|
793
|
+
// secrets / storage / models / dialIn / devices: a plain property when declared; otherwise a
|
|
794
|
+
// non-enumerable getter that throws, so spreading or printing ctx triggers no denial and no audit
|
|
795
|
+
const gated = (key, api, item = `permissions.${key}`) => {
|
|
727
796
|
if (api) {
|
|
728
797
|
Object.assign(ctx, { [key]: api });
|
|
729
798
|
return;
|
|
730
799
|
}
|
|
731
800
|
Object.defineProperty(ctx, key, {
|
|
732
|
-
get: () => deny(
|
|
801
|
+
get: () => deny(item),
|
|
733
802
|
enumerable: false,
|
|
734
803
|
configurable: false,
|
|
735
804
|
});
|
|
@@ -737,6 +806,8 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
|
|
|
737
806
|
gated("secrets", secretsApi);
|
|
738
807
|
gated("storage", storageApi);
|
|
739
808
|
gated("models", modelsApi);
|
|
809
|
+
gated("dialIn", dialInApi);
|
|
810
|
+
gated("devices", devicesApi, `provides ${DEVICE_PROVIDER_EXTENSION_POINT}`);
|
|
740
811
|
return ctx;
|
|
741
812
|
}
|
|
742
813
|
/**
|
|
@@ -2,6 +2,10 @@ import type { DeviceProvider } from "@capybara-hq/plugin-sdk";
|
|
|
2
2
|
/**
|
|
3
3
|
* Checks a plugin's `device-provider@1` implementation when it is provided: the declarations
|
|
4
4
|
* (`networkAllowlist`, `concurrentExec`) must be `true` and the required methods must exist. A
|
|
5
|
-
*
|
|
5
|
+
* provider declaring `permissions.dialIn` (`dialIn` given) must implement `dialIn.onHello` (its
|
|
6
|
+
* `onFrame` and `onClose`, when present, are functions); one that does not declare it must not
|
|
7
|
+
* implement `dialIn`. A failure fails the plugin's setup, so it never loads.
|
|
6
8
|
*/
|
|
7
|
-
export declare function checkDeviceProvider(plugin: string, impl: unknown
|
|
9
|
+
export declare function checkDeviceProvider(plugin: string, impl: unknown, dialIn?: {
|
|
10
|
+
protocol: string;
|
|
11
|
+
}): DeviceProvider;
|
|
@@ -2,9 +2,11 @@ const REQUIRED_FUNCTIONS = ["report", "killTagged", "exec", "create", "createFil
|
|
|
2
2
|
/**
|
|
3
3
|
* Checks a plugin's `device-provider@1` implementation when it is provided: the declarations
|
|
4
4
|
* (`networkAllowlist`, `concurrentExec`) must be `true` and the required methods must exist. A
|
|
5
|
-
*
|
|
5
|
+
* provider declaring `permissions.dialIn` (`dialIn` given) must implement `dialIn.onHello` (its
|
|
6
|
+
* `onFrame` and `onClose`, when present, are functions); one that does not declare it must not
|
|
7
|
+
* implement `dialIn`. A failure fails the plugin's setup, so it never loads.
|
|
6
8
|
*/
|
|
7
|
-
export function checkDeviceProvider(plugin, impl) {
|
|
9
|
+
export function checkDeviceProvider(plugin, impl, dialIn) {
|
|
8
10
|
const p = (impl ?? {});
|
|
9
11
|
const need = (member) => {
|
|
10
12
|
throw new Error(`plugin ${plugin}: device-provider@1 requires ${member}`);
|
|
@@ -17,5 +19,18 @@ export function checkDeviceProvider(plugin, impl) {
|
|
|
17
19
|
if (typeof p[m] !== "function")
|
|
18
20
|
need(m);
|
|
19
21
|
}
|
|
22
|
+
const handler = p.dialIn;
|
|
23
|
+
if (dialIn === undefined) {
|
|
24
|
+
if (handler !== undefined)
|
|
25
|
+
throw new Error(`plugin ${plugin}: device-provider@1 implements dialIn without declaring permissions.dialIn`);
|
|
26
|
+
return impl;
|
|
27
|
+
}
|
|
28
|
+
if (handler === null || typeof handler !== "object" || typeof handler.onHello !== "function")
|
|
29
|
+
need("dialIn.onHello (it declares permissions.dialIn)");
|
|
30
|
+
for (const m of ["onFrame", "onClose"]) {
|
|
31
|
+
const fn = handler[m];
|
|
32
|
+
if (fn !== undefined && typeof fn !== "function")
|
|
33
|
+
need(`dialIn.${m} to be a function`);
|
|
34
|
+
}
|
|
20
35
|
return impl;
|
|
21
36
|
}
|
|
@@ -1110,8 +1110,8 @@ type InstanceHandle = ColumnType<{
|
|
|
1110
1110
|
[k: string]: unknown;
|
|
1111
1111
|
} | null, string | null | undefined, string | null>;
|
|
1112
1112
|
/**
|
|
1113
|
-
* 0088_environments.sql, renamed in 0105: a device
|
|
1114
|
-
*
|
|
1113
|
+
* 0088_environments.sql, renamed in 0105: a device, served by its provider (`provider`): one
|
|
1114
|
+
* instance plus a kept file system; a dial-in device's machine signs in (device_machines).
|
|
1115
1115
|
*/
|
|
1116
1116
|
export interface DevicesTable {
|
|
1117
1117
|
id: string;
|
|
@@ -1120,8 +1120,6 @@ export interface DevicesTable {
|
|
|
1120
1120
|
owner_account_id: string;
|
|
1121
1121
|
name: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1122
1122
|
is_default: ColumnType<boolean, boolean | undefined, boolean>;
|
|
1123
|
-
/** 0093, renamed in 0105: `local` is a person's machine (device_machines). */
|
|
1124
|
-
source: "cloud" | "local";
|
|
1125
1123
|
provider: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1126
1124
|
/** 0096: the provider a demoted default was demoted from; null for every other device. */
|
|
1127
1125
|
demoted_from_provider: ColumnType<string | null, string | null | undefined, string | null>;
|
|
@@ -1140,8 +1138,10 @@ export interface DevicesTable {
|
|
|
1140
1138
|
/** 0165: a cloud device's allowlist hosts (a JSON array), used while the mode is `allowlist`. */
|
|
1141
1139
|
network_hosts: ColumnType<string[], string | undefined, string>;
|
|
1142
1140
|
/**
|
|
1143
|
-
* 0176: what the device's provider last reported (a `DeviceReport` as JSON
|
|
1144
|
-
*
|
|
1141
|
+
* 0176: what the device's provider last reported (a `DeviceReport` as JSON, with the instance's
|
|
1142
|
+
* permission support under the key `support` or null; read back through `parseDeviceReport`,
|
|
1143
|
+
* see `DeviceReports`); null until the first report is stored. Its `revision` drives the device
|
|
1144
|
+
* authority epoch.
|
|
1145
1145
|
*/
|
|
1146
1146
|
report: ColumnType<unknown, string | null | undefined, string | null>;
|
|
1147
1147
|
/** 0176: when {@link report} was stored. */
|
|
@@ -1186,12 +1186,13 @@ export interface DeviceInstancesTable {
|
|
|
1186
1186
|
instance_limits: ColumnType<unknown | null, string | null | undefined, string | null>;
|
|
1187
1187
|
}
|
|
1188
1188
|
/**
|
|
1189
|
-
* 0093_connected_environments.sql, renamed in 0105: the machine of a
|
|
1190
|
-
* unrevoked row per device; revoking sets `revoked_at` and keeps the row.
|
|
1189
|
+
* 0093_connected_environments.sql, renamed in 0105: the signed-in machine of a dial-in device. At
|
|
1190
|
+
* most one unrevoked row per device; revoking sets `revoked_at` and keeps the row. 0177 dropped
|
|
1191
|
+
* what the kernel's former local provider kept here (a provider keeps its own machine facts).
|
|
1191
1192
|
*/
|
|
1192
1193
|
export interface DeviceMachinesTable {
|
|
1193
1194
|
id: Generated<string>;
|
|
1194
|
-
/** 0157: the
|
|
1195
|
+
/** 0157: the OS boot identity its last connection reported; null: none reported. */
|
|
1195
1196
|
boot_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1196
1197
|
org_id: string;
|
|
1197
1198
|
device_id: string;
|
|
@@ -1202,23 +1203,9 @@ export interface DeviceMachinesTable {
|
|
|
1202
1203
|
os: string;
|
|
1203
1204
|
arch: string;
|
|
1204
1205
|
program_version: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1205
|
-
mode: ColumnType<"os" | "docker" | null, "os" | "docker" | null | undefined, "os" | "docker" | null>;
|
|
1206
|
-
/** The roots the program exposes, as it reported them (a JSON array). */
|
|
1207
|
-
roots: ColumnType<unknown, string | null | undefined, string | null>;
|
|
1208
|
-
session_isolation: ColumnType<boolean, boolean | undefined, boolean>;
|
|
1209
1206
|
last_seen_at: TsNullable;
|
|
1210
1207
|
created_at: Ts;
|
|
1211
1208
|
revoked_at: TsNullable;
|
|
1212
|
-
/** 0114: the features the program reported in its hello (`networkReport`, `policyOp`). */
|
|
1213
|
-
features: ColumnType<string[], string[] | undefined, string[]>;
|
|
1214
|
-
/** 0114: the program's local network policy summary (hello, refreshed by each `policy` op). */
|
|
1215
|
-
local_policy: ColumnType<unknown | null, string | null | undefined, string | null>;
|
|
1216
|
-
/** 0118: the `policy` ops sent whose answer is not recorded yet (`PendingPolicyOp[]`). */
|
|
1217
|
-
pending_policy_ops: ColumnType<unknown, string | undefined, string>;
|
|
1218
|
-
/** 0133: the owner's home directory the program reported in its hello; null when not reported. */
|
|
1219
|
-
home: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1220
|
-
/** 0156: the authenticated owner report (`StoredOwnerReport`, B2); null before any. */
|
|
1221
|
-
owner_report: ColumnType<unknown | null, string | null | undefined, string | null>;
|
|
1222
1209
|
}
|
|
1223
1210
|
/** 0133: a device's projects (project root design §4.1), written only by the kernel. */
|
|
1224
1211
|
export interface DeviceProjectsTable {
|
|
@@ -1598,20 +1585,6 @@ export interface DeviceGenerationHighWaterTable {
|
|
|
1598
1585
|
high_water_ms: ColumnType<string, string | number, string | number>;
|
|
1599
1586
|
updated_at: Ts;
|
|
1600
1587
|
}
|
|
1601
|
-
export interface DeviceInstanceBindingsTable {
|
|
1602
|
-
device_id: string;
|
|
1603
|
-
instance_generation: string;
|
|
1604
|
-
binding_id: string;
|
|
1605
|
-
provider: string;
|
|
1606
|
-
previous_generation: string | null;
|
|
1607
|
-
status: "awaiting-device" | "installed";
|
|
1608
|
-
machine_id: string | null;
|
|
1609
|
-
runtime_identity: ColumnType<PermissionRuntimeIdentity | null, string | null | undefined, string | null>;
|
|
1610
|
-
created_at: Ts;
|
|
1611
|
-
installed_at: TsNullable;
|
|
1612
|
-
/** Migration 0168: the device connection whose bind answer installed it. */
|
|
1613
|
-
installed_connection_id: string | null;
|
|
1614
|
-
}
|
|
1615
1588
|
export interface LegacyLaunchFreezeTable {
|
|
1616
1589
|
id: "platform";
|
|
1617
1590
|
frozen_at: Generated<Date>;
|
|
@@ -1647,13 +1620,6 @@ export interface DeviceRetirementMembersTable {
|
|
|
1647
1620
|
settled: ColumnType<boolean, boolean | undefined, boolean>;
|
|
1648
1621
|
created_at: Generated<Date>;
|
|
1649
1622
|
}
|
|
1650
|
-
export interface DeviceMachineBootsTable {
|
|
1651
|
-
machine_id: string;
|
|
1652
|
-
boot_id: string;
|
|
1653
|
-
/** bigserial: read as a decimal string. */
|
|
1654
|
-
seq: ColumnType<string, string | number | undefined, never>;
|
|
1655
|
-
first_seen_at: Generated<Date>;
|
|
1656
|
-
}
|
|
1657
1623
|
export interface DeviceInstanceDestructionsTable {
|
|
1658
1624
|
device_id: string;
|
|
1659
1625
|
provider: string;
|
|
@@ -1679,16 +1645,12 @@ export interface KernelDatabase {
|
|
|
1679
1645
|
device_permission_reports: DevicePermissionReportsTable;
|
|
1680
1646
|
/** Migration 0155: per-device generation high-water mark; outlives instance rows. */
|
|
1681
1647
|
device_generation_high_water: DeviceGenerationHighWaterTable;
|
|
1682
|
-
/** Migration 0155: post-commit binding of a local instance generation. */
|
|
1683
|
-
device_instance_bindings: DeviceInstanceBindingsTable;
|
|
1684
1648
|
/** Migration 0157: the durable legacy-launch freeze (one row, never removed). */
|
|
1685
1649
|
legacy_launch_freeze: LegacyLaunchFreezeTable;
|
|
1686
1650
|
/** Migration 0157: the physical no-reuse obligation of one old instance incarnation. */
|
|
1687
1651
|
device_retirement_obligations: DeviceRetirementObligationsTable;
|
|
1688
1652
|
/** Migration 0157: what put a retirement obligation there. */
|
|
1689
1653
|
device_retirement_members: DeviceRetirementMembersTable;
|
|
1690
|
-
/** Migration 0157: the OS boot identities a machine reported, in the order first seen. */
|
|
1691
|
-
device_machine_boots: DeviceMachineBootsTable;
|
|
1692
1654
|
/** Migration 0157: provider-confirmed destruction of a cloud instance incarnation. */
|
|
1693
1655
|
device_instance_destructions: DeviceInstanceDestructionsTable;
|
|
1694
1656
|
sandbox_operation_intents: SandboxOperationIntentsTable;
|
package/dist/devices/access.d.ts
CHANGED
|
@@ -24,10 +24,9 @@ export declare class DeviceAccess {
|
|
|
24
24
|
* The device if `accountId` may use it in `orgId` now: `device.not_found` when it is
|
|
25
25
|
* missing, deleted, in another org or someone else's; `device.unavailable` when it has no
|
|
26
26
|
* provider, its provider (`devices.provider`, fixed at creation) does not serve the org now
|
|
27
|
-
* ({@link DeviceProviderSelection.isOnInOrg}: off in the org, not installed, invalid config
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* is the relay's concern, not access.
|
|
27
|
+
* ({@link DeviceProviderSelection.isOnInOrg}: off in the org, not installed, invalid config),
|
|
28
|
+
* or its instance row names another provider (never written by this kernel). Whether a dial-in
|
|
29
|
+
* device's machine is online is its provider's concern, not access.
|
|
31
30
|
*/
|
|
32
31
|
usable(orgId: string, accountId: string, deviceId: string): Promise<{
|
|
33
32
|
id: string;
|
package/dist/devices/access.js
CHANGED
|
@@ -40,10 +40,9 @@ let DeviceAccess = class DeviceAccess {
|
|
|
40
40
|
* The device if `accountId` may use it in `orgId` now: `device.not_found` when it is
|
|
41
41
|
* missing, deleted, in another org or someone else's; `device.unavailable` when it has no
|
|
42
42
|
* provider, its provider (`devices.provider`, fixed at creation) does not serve the org now
|
|
43
|
-
* ({@link DeviceProviderSelection.isOnInOrg}: off in the org, not installed, invalid config
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* is the relay's concern, not access.
|
|
43
|
+
* ({@link DeviceProviderSelection.isOnInOrg}: off in the org, not installed, invalid config),
|
|
44
|
+
* or its instance row names another provider (never written by this kernel). Whether a dial-in
|
|
45
|
+
* device's machine is online is its provider's concern, not access.
|
|
47
46
|
*/
|
|
48
47
|
async usable(orgId, accountId, deviceId) {
|
|
49
48
|
const row = await this.db
|
|
@@ -83,14 +83,12 @@ export declare class ConversationDevices {
|
|
|
83
83
|
private readonly devices;
|
|
84
84
|
private readonly facts;
|
|
85
85
|
private readonly ceilings;
|
|
86
|
-
constructor(db: KernelDb, txHost: TransactionHost, selection: Pick<DeviceProviderSelection, "onInOrg" | "isOnInOrg" | "defaultFor">, access: Pick<DeviceAccess, "usable">, devices: Pick<DevicesService, "ensureDefault" | "modeLevel"
|
|
86
|
+
constructor(db: KernelDb, txHost: TransactionHost, selection: Pick<DeviceProviderSelection, "onInOrg" | "isOnInOrg" | "defaultFor">, access: Pick<DeviceAccess, "usable">, devices: Pick<DevicesService, "ensureDefault" | "modeLevel">, facts: Pick<PermissionFacts, "readWorkingFacts" | "workingProject">, ceilings: PermissionCeilingWrites);
|
|
87
87
|
/**
|
|
88
88
|
* The mode and network a call in the device runs at now ({@link DevicesService.modeLevel}),
|
|
89
89
|
* recorded for the model in `device_paths` (auto mode spec §4.2).
|
|
90
90
|
*/
|
|
91
91
|
modeLevel(orgId: string, deviceId: string): Promise<DeviceModeLevel | null>;
|
|
92
|
-
/** How far restricted work may root outside the workspace now (B2; {@link DevicesService.projectReach}). */
|
|
93
|
-
projectReach(orgId: string, deviceId: string): Promise<"workspace" | "os-user">;
|
|
94
92
|
/**
|
|
95
93
|
* The facts the command review reads for a call in the conversation tree rooted at
|
|
96
94
|
* `rootConversationId` (auto mode spec §5.1): the device `forTool` would enter, its mode and
|
|
@@ -63,10 +63,6 @@ let ConversationDevices = class ConversationDevices {
|
|
|
63
63
|
modeLevel(orgId, deviceId) {
|
|
64
64
|
return this.devices.modeLevel(orgId, deviceId);
|
|
65
65
|
}
|
|
66
|
-
/** How far restricted work may root outside the workspace now (B2; {@link DevicesService.projectReach}). */
|
|
67
|
-
projectReach(orgId, deviceId) {
|
|
68
|
-
return this.devices.projectReach(orgId, deviceId);
|
|
69
|
-
}
|
|
70
66
|
/**
|
|
71
67
|
* The facts the command review reads for a call in the conversation tree rooted at
|
|
72
68
|
* `rootConversationId` (auto mode spec §5.1): the device `forTool` would enter, its mode and
|
|
@@ -95,7 +91,7 @@ let ConversationDevices = class ConversationDevices {
|
|
|
95
91
|
return null;
|
|
96
92
|
throw e;
|
|
97
93
|
}
|
|
98
|
-
const [device, level
|
|
94
|
+
const [device, level] = await Promise.all([
|
|
99
95
|
this.db
|
|
100
96
|
.selectFrom("devices")
|
|
101
97
|
.select("name")
|
|
@@ -103,7 +99,6 @@ let ConversationDevices = class ConversationDevices {
|
|
|
103
99
|
.where("org_id", "=", orgId)
|
|
104
100
|
.executeTakeFirst(),
|
|
105
101
|
this.modeLevel(orgId, deviceId),
|
|
106
|
-
this.projectReach(orgId, deviceId),
|
|
107
102
|
]);
|
|
108
103
|
if (device === undefined)
|
|
109
104
|
return null;
|
|
@@ -118,7 +113,7 @@ let ConversationDevices = class ConversationDevices {
|
|
|
118
113
|
workspace,
|
|
119
114
|
home,
|
|
120
115
|
deviceHome: homeOf(workspace),
|
|
121
|
-
workingRoot: workingRootOf(project, {
|
|
116
|
+
workingRoot: workingRootOf(project, { workspace, home }),
|
|
122
117
|
};
|
|
123
118
|
}
|
|
124
119
|
/**
|
|
@@ -8,24 +8,25 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { posix } from "node:path";
|
|
11
|
-
import {
|
|
11
|
+
import { isDeviceOfflineError, isDeviceProjectName, isFileSystemGoneError, isProjectPathRefusedError, isSandboxGoneError, isSandboxScopeDeniedError, MAX_DEVICE_SCAN_RESULTS, ToolError, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
12
|
+
import { DeviceProtocolError } from "@capybara-hq/plugin-sdk/device-protocol";
|
|
12
13
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
13
14
|
import { sql } from "kysely";
|
|
15
|
+
import { deviceOffline } from "../dial-in/relay.js";
|
|
14
16
|
import { ApiError } from "../errors.js";
|
|
15
17
|
import { audit } from "../identity/audit.js";
|
|
16
18
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
17
19
|
import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
|
|
18
20
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
19
21
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
20
|
-
import { projectsUnsupported } from "../local-devices/local-device-provider.js";
|
|
21
|
-
import { POLICY_REFUSAL_PREFIX } from "../local-devices/relay.js";
|
|
22
22
|
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
23
23
|
import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "../sandbox/permission-context-types.js";
|
|
24
24
|
import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
25
25
|
import { deviceNotFound, SandboxService } from "../sandbox/sandbox.service.js";
|
|
26
26
|
import { SandboxProviderUnreachableError } from "../sandbox/unreachable.js";
|
|
27
27
|
import { DeviceAccess } from "./access.js";
|
|
28
|
-
import {
|
|
28
|
+
import { projectsUnsupported } from "./errors.js";
|
|
29
|
+
import { baseOf, clipped, nameInvalid, nameTaken, outsideMode, tooBroad, withinMode, } from "./project-rules.js";
|
|
29
30
|
// a path above the owner's home is never stored as a project: the working root would fall back for
|
|
30
31
|
// it anyway (project root §4.3), so both use the one rule; the home itself may be one
|
|
31
32
|
import { aboveHome } from "./working-root.js";
|
|
@@ -128,14 +129,12 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
128
129
|
if (!scope.supported) {
|
|
129
130
|
return { candidates: [], mode: scope.mode, base: baseOf(scope), supported: false };
|
|
130
131
|
}
|
|
131
|
-
if (baseOf(scope) === null)
|
|
132
|
-
throw homeUnknown();
|
|
133
132
|
return this.onDevice(orgId, accountId, deviceId, scope, signal, async (r, sig) => {
|
|
134
133
|
const workspace = r.workspace;
|
|
135
134
|
const base = baseOf(scope, workspace);
|
|
136
135
|
const scan = r.scan;
|
|
137
136
|
if (scan === undefined)
|
|
138
|
-
throw projectsUnsupported(
|
|
137
|
+
throw projectsUnsupported();
|
|
139
138
|
let found;
|
|
140
139
|
try {
|
|
141
140
|
found = await scan(base, sig);
|
|
@@ -176,9 +175,7 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
176
175
|
await this.access.usable(orgId, accountId, deviceId);
|
|
177
176
|
const scope = await this.scope(orgId, accountId, deviceId);
|
|
178
177
|
if (!scope.supported)
|
|
179
|
-
throw projectsUnsupported(
|
|
180
|
-
if (baseOf(scope) === null)
|
|
181
|
-
throw homeUnknown();
|
|
178
|
+
throw projectsUnsupported();
|
|
182
179
|
if (name !== undefined && !isDeviceProjectName(name))
|
|
183
180
|
throw nameInvalid(name);
|
|
184
181
|
const rows = await this.db
|
|
@@ -205,12 +202,10 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
205
202
|
// a path too broad for any project is refused before the device is leased (a cloud device
|
|
206
203
|
// started): against the last known base; the held instance's base is checked again inside
|
|
207
204
|
const early = baseOf(scope);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
throw tooBroad(path);
|
|
213
|
-
}
|
|
205
|
+
const path = trimSlash(posix.normalize(posix.join(early, input.path === "" ? "." : input.path)));
|
|
206
|
+
// outside the mode stays the device-side refusal it is (the held workspace decides it)
|
|
207
|
+
if (withinMode(scope, path) && aboveHome(path, scope.home))
|
|
208
|
+
throw tooBroad(path);
|
|
214
209
|
const resolved = await this.onDevice(orgId, accountId, deviceId, scope, signal, async (r, sig) => {
|
|
215
210
|
const path = resolve(scope, r.workspace, input.path);
|
|
216
211
|
const name = input.name ?? posix.basename(path);
|
|
@@ -218,7 +213,7 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
218
213
|
throw nameInvalid(name);
|
|
219
214
|
const list = r.list;
|
|
220
215
|
if (list === undefined)
|
|
221
|
-
throw projectsUnsupported(
|
|
216
|
+
throw projectsUnsupported();
|
|
222
217
|
let answer;
|
|
223
218
|
try {
|
|
224
219
|
answer = await list(path, 1, sig);
|
|
@@ -382,6 +377,9 @@ let DeviceProjectsService = class DeviceProjectsService {
|
|
|
382
377
|
catch (e) {
|
|
383
378
|
if (e instanceof ApiError)
|
|
384
379
|
throw e;
|
|
380
|
+
// a dial-in device's machine that is not connected: the relay's offline error
|
|
381
|
+
if (isDeviceOfflineError(e))
|
|
382
|
+
throw deviceOffline();
|
|
385
383
|
if (e instanceof SandboxProviderUnreachableError)
|
|
386
384
|
throw providerUnreachable();
|
|
387
385
|
// the answer hides the cause (a provider's text is not for people): ops read it here
|
|
@@ -436,14 +434,12 @@ const limitReached = () => new ApiError("device.project_limit_reached", `This de
|
|
|
436
434
|
/** `path` without a trailing `/` (except `/` itself). */
|
|
437
435
|
const trimSlash = (path) => path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
438
436
|
/**
|
|
439
|
-
* The absolute path of `relative` against the scope's base (the
|
|
440
|
-
*
|
|
441
|
-
*
|
|
437
|
+
* The absolute path of `relative` against the scope's base (the home its provider reported, else
|
|
438
|
+
* the instance's `workspace`), normalized; refused when the result is not a valid path, or it
|
|
439
|
+
* leaves what the scope reaches.
|
|
442
440
|
*/
|
|
443
441
|
function resolve(scope, workspace, relative) {
|
|
444
442
|
const base = baseOf(scope, workspace);
|
|
445
|
-
if (base === null)
|
|
446
|
-
throw homeUnknown();
|
|
447
443
|
const path = trimSlash(posix.normalize(posix.join(base, relative === "" ? "." : relative)));
|
|
448
444
|
if (validateSandboxPathShape(path).length > 0 || !withinMode(scope, path, workspace)) {
|
|
449
445
|
throw outsideMode(path, scope.mode);
|
|
@@ -464,7 +460,7 @@ function passThrough(e) {
|
|
|
464
460
|
if (e instanceof SandboxProviderUnreachableError)
|
|
465
461
|
return e;
|
|
466
462
|
if (e instanceof DeviceProtocolError) {
|
|
467
|
-
return new ApiError("device.projects_unavailable", "The device answered in a form this kernel does not accept; update
|
|
463
|
+
return new ApiError("device.projects_unavailable", "The device answered in a form this kernel does not accept; update its device program or plugin");
|
|
468
464
|
}
|
|
469
465
|
return undefined;
|
|
470
466
|
}
|
|
@@ -480,10 +476,10 @@ function unavailable(e) {
|
|
|
480
476
|
}
|
|
481
477
|
const pathMissing = (path) => new ApiError("device.project_path_missing", `${clipped(path)} does not exist on the device; check the path`);
|
|
482
478
|
/**
|
|
483
|
-
* What a failed `list(path)` becomes. A
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
* unreadable directory from a failure on the device, so the device is asked `stat(path)`: a file
|
|
479
|
+
* What a failed `list(path)` becomes. A provider's `ProjectPathRefusedError` is
|
|
480
|
+
* `device.project_refused` with its reason; the owner browse scope refusing the path is the
|
|
481
|
+
* device refusing it (`device.project_outside_mode`). Any other error alone cannot tell a file or
|
|
482
|
+
* an unreadable directory from a failure on the device, so the device is asked `stat(path)`: a file
|
|
487
483
|
* or a directory it cannot list is the path's problem (422 `device.project_path_unreadable`), a
|
|
488
484
|
* missing path `device.project_path_missing`, and a `stat` that fails too means the device could
|
|
489
485
|
* not be asked (503 `device.projects_unavailable`).
|
|
@@ -498,8 +494,7 @@ async function listFailure(e, r, path, mode, signal, logUnavailable) {
|
|
|
498
494
|
}
|
|
499
495
|
const why = e instanceof ToolError ? ` (${clipped(e.message)})` : "";
|
|
500
496
|
// the owner browse scope refusing the path is the device refusing it (gate on only)
|
|
501
|
-
if (
|
|
502
|
-
(r.browse && isSandboxScopeDeniedError(e))) {
|
|
497
|
+
if (r.browse && isSandboxScopeDeniedError(e)) {
|
|
503
498
|
return new ApiError("device.project_outside_mode", `The device refused ${clipped(path)} in ${mode} mode${why}`);
|
|
504
499
|
}
|
|
505
500
|
let st;
|
|
@@ -7,7 +7,7 @@ import { type DeviceProviderEntry, DeviceProviders } from "../sandbox/providers.
|
|
|
7
7
|
/**
|
|
8
8
|
* Which device providers serve an org: the loaded `device-provider@1` extensions switched on in it
|
|
9
9
|
* (valid config), and the provider a new device gets by default. Everything is read at every call
|
|
10
|
-
* (PG; no in-process cache).
|
|
10
|
+
* (PG; no in-process cache). In-process providers (`DeviceProviders.register`) are never listed.
|
|
11
11
|
*/
|
|
12
12
|
export declare class DeviceProviderSelection {
|
|
13
13
|
private readonly providers;
|
|
@@ -16,15 +16,14 @@ export declare class DeviceProviderSelection {
|
|
|
16
16
|
private readonly config;
|
|
17
17
|
private readonly kdb;
|
|
18
18
|
private readonly log;
|
|
19
|
-
constructor(providers: Pick<DeviceProviders, "forDevice">, points: Pick<ExtensionPointDefaults, "providersFor" | "serves">, orgSettings: Pick<OrgSettingsService, "get">, config: Pick<KernelConfigService, "get" | "fieldSource">, kdb: Pick<KernelDb, "db">, log: KernelLogger);
|
|
19
|
+
constructor(providers: Pick<DeviceProviders, "forDevice" | "registered">, points: Pick<ExtensionPointDefaults, "providersFor" | "serves">, orgSettings: Pick<OrgSettingsService, "get">, config: Pick<KernelConfigService, "get" | "fieldSource">, kdb: Pick<KernelDb, "db">, log: KernelLogger);
|
|
20
20
|
/** The providers that serve `orgId` now, in extension-name order. */
|
|
21
21
|
onInOrg(orgId: string): Promise<DeviceProviderEntry[]>;
|
|
22
22
|
/**
|
|
23
23
|
* Whether the provider `plugin` (a device's `devices.provider`) serves `orgId` now: an extension
|
|
24
|
-
* that {@link onInOrg} lists;
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* that provider ({@link ExtensionPointDefaults.serves}, the criteria {@link onInOrg} applies).
|
|
24
|
+
* that {@link onInOrg} lists; an in-process provider is no catalog item and has no org switch,
|
|
25
|
+
* so for it "on in the org" means registered in this process. Evaluates only that provider
|
|
26
|
+
* ({@link ExtensionPointDefaults.serves}, the criteria {@link onInOrg} applies).
|
|
28
27
|
*/
|
|
29
28
|
isOnInOrg(orgId: string, plugin: string): Promise<boolean>;
|
|
30
29
|
/**
|
|
@@ -13,12 +13,12 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
|
13
13
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
14
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
15
15
|
import { OrgSettingsService } from "../orgs/settings.service.js";
|
|
16
|
-
import { DeviceProviders
|
|
16
|
+
import { DeviceProviders } from "../sandbox/providers.js";
|
|
17
17
|
import { readPlatformDefaultProvider } from "./default-provider-setting.js";
|
|
18
18
|
/**
|
|
19
19
|
* Which device providers serve an org: the loaded `device-provider@1` extensions switched on in it
|
|
20
20
|
* (valid config), and the provider a new device gets by default. Everything is read at every call
|
|
21
|
-
* (PG; no in-process cache).
|
|
21
|
+
* (PG; no in-process cache). In-process providers (`DeviceProviders.register`) are never listed.
|
|
22
22
|
*/
|
|
23
23
|
let DeviceProviderSelection = class DeviceProviderSelection {
|
|
24
24
|
providers;
|
|
@@ -41,21 +41,20 @@ let DeviceProviderSelection = class DeviceProviderSelection {
|
|
|
41
41
|
const out = [];
|
|
42
42
|
for (const p of providers) {
|
|
43
43
|
const e = this.providers.forDevice(p.extension);
|
|
44
|
-
if (e
|
|
44
|
+
if (e)
|
|
45
45
|
out.push(e);
|
|
46
46
|
}
|
|
47
47
|
return out;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Whether the provider `plugin` (a device's `devices.provider`) serves `orgId` now: an extension
|
|
51
|
-
* that {@link onInOrg} lists;
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* that provider ({@link ExtensionPointDefaults.serves}, the criteria {@link onInOrg} applies).
|
|
51
|
+
* that {@link onInOrg} lists; an in-process provider is no catalog item and has no org switch,
|
|
52
|
+
* so for it "on in the org" means registered in this process. Evaluates only that provider
|
|
53
|
+
* ({@link ExtensionPointDefaults.serves}, the criteria {@link onInOrg} applies).
|
|
55
54
|
*/
|
|
56
55
|
async isOnInOrg(orgId, plugin) {
|
|
57
|
-
if (
|
|
58
|
-
return
|
|
56
|
+
if (this.providers.registered(plugin))
|
|
57
|
+
return true;
|
|
59
58
|
if (this.providers.forDevice(plugin) === undefined)
|
|
60
59
|
return false;
|
|
61
60
|
return this.points.serves(orgId, "device-provider", plugin);
|