@capybara-hq/kernel 0.1.0-rc.66 → 0.1.0-rc.67
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 +0 -8
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/agents/admin-agents.d.ts +2 -2
- package/dist/agents/admin-agents.js +2 -1
- package/dist/agents/agent-lookup.js +2 -1
- package/dist/agents/agent-profile.service.d.ts +5 -2
- package/dist/agents/agent-profile.service.js +13 -2
- package/dist/agents/agents.controller.d.ts +4 -3
- package/dist/agents/agents.controller.js +7 -3
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.schemas.d.ts +6 -6
- package/dist/agents/agents.service.d.ts +23 -2
- package/dist/agents/agents.service.js +61 -6
- package/dist/agents/avatar-view.d.ts +8 -0
- package/dist/agents/avatar-view.js +12 -0
- package/dist/agents/profile.d.ts +38 -13
- package/dist/agents/profile.js +31 -20
- package/dist/background/poll.job.d.ts +1 -1
- package/dist/background/poll.job.js +8 -6
- package/dist/background/tasks.service.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/inbound.d.ts +2 -3
- package/dist/channels/inbound.js +2 -3
- package/dist/channels/phrases.d.ts +3 -3
- package/dist/channels/phrases.js +3 -3
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.js +14 -1
- package/dist/conversations/conversations.service.d.ts +4 -3
- package/dist/conversations/conversations.service.js +4 -2
- package/dist/ctx/create-ctx.js +5 -2
- package/dist/ctx/device-provider-check.d.ts +7 -0
- package/dist/ctx/device-provider-check.js +21 -0
- package/dist/db/kernel-schema.d.ts +7 -0
- package/dist/devices/access.d.ts +16 -46
- package/dist/devices/access.js +26 -62
- package/dist/devices/access.module.js +2 -2
- package/dist/devices/conversation-devices.d.ts +38 -18
- package/dist/devices/conversation-devices.js +69 -51
- package/dist/devices/default-provider-setting.d.ts +45 -0
- package/dist/devices/default-provider-setting.js +59 -0
- package/dist/devices/device-projects.service.js +7 -2
- package/dist/devices/device-provider-selection.d.ts +37 -0
- package/dist/devices/device-provider-selection.js +86 -0
- package/dist/devices/device-provider-selection.module.d.ts +3 -0
- package/dist/devices/device-provider-selection.module.js +22 -0
- package/dist/devices/devices.controller.d.ts +8 -5
- package/dist/devices/devices.controller.js +7 -4
- package/dist/devices/devices.module.js +3 -1
- package/dist/devices/devices.schemas.js +2 -2
- package/dist/devices/devices.service.d.ts +72 -83
- package/dist/devices/devices.service.js +139 -248
- package/dist/devices/dto.d.ts +9 -0
- package/dist/devices/dto.js +15 -2
- package/dist/devices/label.d.ts +3 -5
- package/dist/devices/label.js +3 -14
- package/dist/devices/legacy-cleanup.job.d.ts +2 -2
- package/dist/devices/legacy-cleanup.job.js +6 -6
- package/dist/errors.d.ts +15 -1
- package/dist/errors.js +15 -1
- package/dist/extensions/guide-places.d.ts +2 -1
- package/dist/extensions/guide-places.js +8 -2
- package/dist/extensions/locks.d.ts +1 -1
- package/dist/extensions/locks.js +1 -1
- package/dist/extensions/org-config.d.ts +20 -4
- package/dist/extensions/org-config.js +23 -6
- package/dist/extensions/permission-view.d.ts +2 -2
- package/dist/extensions/permission-view.js +2 -2
- package/dist/extensions/plugin-guides.d.ts +1 -1
- package/dist/extensions/plugin-guides.js +11 -3
- package/dist/extensions/point-defaults.d.ts +14 -0
- package/dist/extensions/point-defaults.js +70 -47
- package/dist/extensions/resolve.js +7 -2
- package/dist/identity/settings.d.ts +8 -0
- package/dist/identity/settings.js +24 -1
- package/dist/infra/config/kernel-config.service.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.js +7 -6
- package/dist/local-devices/device-routes.d.ts +1 -1
- package/dist/local-devices/device-routes.js +1 -1
- package/dist/local-devices/local-device-provider.d.ts +14 -11
- package/dist/local-devices/local-device-provider.js +14 -0
- package/dist/local-devices/local-devices.module.d.ts +4 -4
- package/dist/local-devices/local-devices.module.js +5 -3
- package/dist/local-devices/owner-report.js +2 -1
- package/dist/local-devices/targets.d.ts +2 -0
- package/dist/local-devices/targets.js +10 -0
- package/dist/orgs/settings.service.d.ts +26 -1
- package/dist/orgs/settings.service.js +44 -3
- package/dist/platform/ops/admin.ops.js +8 -3
- package/dist/platform/ops/agents.ops.d.ts +6 -1
- package/dist/platform/ops/agents.ops.js +38 -11
- package/dist/platform/ops/devices.ops.js +25 -20
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/themes.ops.js +1 -1
- package/dist/runtime/plugin-context.service.js +1 -12
- package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
- package/dist/sandbox/cloud-permission-snapshot.js +3 -3
- package/dist/sandbox/device-reports.d.ts +50 -0
- package/dist/sandbox/device-reports.js +157 -0
- package/dist/sandbox/held-operations.d.ts +8 -8
- package/dist/sandbox/leases.d.ts +1 -1
- package/dist/sandbox/leases.js +1 -1
- package/dist/sandbox/operation-authority.d.ts +5 -2
- package/dist/sandbox/operation-authority.js +12 -11
- package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
- package/dist/sandbox/operation-reconcile.job.js +5 -5
- package/dist/sandbox/permission-availability.d.ts +2 -2
- package/dist/sandbox/permission-call-types.d.ts +5 -0
- package/dist/sandbox/permission-facts.d.ts +2 -2
- package/dist/sandbox/permission-facts.js +5 -5
- package/dist/sandbox/providers.d.ts +23 -24
- package/dist/sandbox/providers.js +38 -46
- package/dist/sandbox/providers.module.js +3 -3
- package/dist/sandbox/sandbox.module.d.ts +1 -1
- package/dist/sandbox/sandbox.module.js +7 -2
- package/dist/sandbox/sandbox.service.d.ts +95 -68
- package/dist/sandbox/sandbox.service.js +212 -208
- package/dist/setup/setup-guides.service.d.ts +4 -1
- package/dist/setup/setup-guides.service.js +6 -1
- package/dist/themes/avatar-preset-key.d.ts +6 -0
- package/dist/themes/avatar-preset-key.js +9 -0
- package/dist/themes/theme-state.d.ts +29 -1
- package/dist/themes/theme-state.js +40 -1
- package/dist/themes/themes.service.d.ts +28 -1
- package/dist/themes/themes.service.js +36 -2
- package/dist/tools/builtins/image/generate.d.ts +3 -0
- package/dist/tools/builtins/image/generate.js +21 -11
- package/dist/tools/builtins/image/index.d.ts +1 -1
- package/dist/tools/builtins/image/index.js +1 -1
- package/dist/tools/builtins/sandbox/common.d.ts +36 -12
- package/dist/tools/builtins/sandbox/common.js +62 -18
- package/dist/tools/builtins/sandbox/read.d.ts +5 -2
- package/dist/tools/builtins/sandbox/read.js +9 -6
- package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
- package/dist/tools/builtins/sandbox/task-output.js +6 -5
- package/dist/tools/builtins/skill-load.js +13 -4
- package/dist/until-aborted.d.ts +5 -0
- package/dist/until-aborted.js +16 -0
- package/package.json +4 -4
- package/src/migrations/0176_device_report.sql +6 -0
package/dist/devices/label.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { DeviceView } from "./devices.service.js";
|
|
2
2
|
/**
|
|
3
3
|
* A device's name for people outside the web (the IM `/device` list, the `Platform` tool): its
|
|
4
|
-
* own name, else
|
|
5
|
-
*
|
|
6
|
-
* e.g. 「个人设备(Docker 沙箱)」 / "Personal (Docker sandbox)", with " 2", " 3", … after the
|
|
7
|
-
* first of the same provider. The web builds the same label from its own messages.
|
|
4
|
+
* own name, else the localized "Personal" (`PERSONAL`, for the default device). The web builds
|
|
5
|
+
* the same label from its own messages.
|
|
8
6
|
*/
|
|
9
|
-
export declare function deviceLabel(v: Pick<DeviceView, "name"
|
|
7
|
+
export declare function deviceLabel(v: Pick<DeviceView, "name">, locale: "zh" | "en"): string;
|
|
10
8
|
/** The words the default device answers to in `/device <name>` besides its label. */
|
|
11
9
|
export declare const DEFAULT_DEVICE_ALIASES: readonly string[];
|
package/dist/devices/label.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
const PERSONAL = { zh: "个人设备", en: "Personal" };
|
|
2
2
|
/**
|
|
3
3
|
* A device's name for people outside the web (the IM `/device` list, the `Platform` tool): its
|
|
4
|
-
* own name, else
|
|
5
|
-
*
|
|
6
|
-
* e.g. 「个人设备(Docker 沙箱)」 / "Personal (Docker sandbox)", with " 2", " 3", … after the
|
|
7
|
-
* first of the same provider. The web builds the same label from its own messages.
|
|
4
|
+
* own name, else the localized "Personal" (`PERSONAL`, for the default device). The web builds
|
|
5
|
+
* the same label from its own messages.
|
|
8
6
|
*/
|
|
9
7
|
export function deviceLabel(v, locale) {
|
|
10
|
-
|
|
11
|
-
return v.name;
|
|
12
|
-
const d = v.demotedFrom;
|
|
13
|
-
if (d === null)
|
|
14
|
-
return PERSONAL[locale];
|
|
15
|
-
const provider = d.displayName?.[locale] ?? d.provider;
|
|
16
|
-
const nth = d.ordinal > 1 ? ` ${d.ordinal}` : "";
|
|
17
|
-
return locale === "zh"
|
|
18
|
-
? `${PERSONAL.zh}(${provider})${nth}`
|
|
19
|
-
: `${PERSONAL.en} (${provider})${nth}`;
|
|
8
|
+
return v.name ?? PERSONAL[locale];
|
|
20
9
|
}
|
|
21
10
|
/** The words the default device answers to in `/device <name>` besides its label. */
|
|
22
11
|
export const DEFAULT_DEVICE_ALIASES = [
|
|
@@ -2,7 +2,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
|
2
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
3
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
4
4
|
import type { KernelLogger } from "../log.js";
|
|
5
|
-
import {
|
|
5
|
+
import { DeviceProviders } from "../sandbox/providers.js";
|
|
6
6
|
/** The job's name (`@LockedInterval`, run lock `cron:devices-legacy-cleanup`). */
|
|
7
7
|
export declare const LEGACY_CLEANUP_JOB = "devices-legacy-cleanup";
|
|
8
8
|
/** What one run did: rows destroyed and deleted, rows kept because their provider is not loaded. */
|
|
@@ -27,7 +27,7 @@ export declare class LegacySandboxCleanupJob {
|
|
|
27
27
|
readonly config: KernelConfigService;
|
|
28
28
|
readonly lockService: LockService;
|
|
29
29
|
readonly log: KernelLogger;
|
|
30
|
-
constructor(db: KernelDb, providers: Pick<
|
|
30
|
+
constructor(db: KernelDb, providers: Pick<DeviceProviders, "forDevice">, config: KernelConfigService, lockService: LockService, log: KernelLogger);
|
|
31
31
|
tick(signal?: AbortSignal): Promise<void>;
|
|
32
32
|
/** One run (see the class); `signal` (the stop, or a lost run lock) is read between rows. */
|
|
33
33
|
runOnce(now?: Date, signal?: AbortSignal): Promise<LegacyCleanupResult>;
|
|
@@ -13,7 +13,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
13
13
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
14
14
|
import { LockedInterval } from "../infra/schedule/locked-interval.js";
|
|
15
15
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
16
|
-
import {
|
|
16
|
+
import { DeviceProviders } from "../sandbox/providers.js";
|
|
17
17
|
/** The job's name (`@LockedInterval`, run lock `cron:devices-legacy-cleanup`). */
|
|
18
18
|
export const LEGACY_CLEANUP_JOB = "devices-legacy-cleanup";
|
|
19
19
|
/** Every 5 minutes, once per tick across replicas. */
|
|
@@ -65,8 +65,8 @@ let LegacySandboxCleanupJob = class LegacySandboxCleanupJob {
|
|
|
65
65
|
.select(["provider", (eb) => eb.fn.countAll().as("n")])
|
|
66
66
|
.groupBy("provider")
|
|
67
67
|
.execute();
|
|
68
|
-
const loaded = byProvider.filter((p) => this.providers.
|
|
69
|
-
const unloaded = byProvider.filter((p) => this.providers.
|
|
68
|
+
const loaded = byProvider.filter((p) => this.providers.forDevice(p.provider) !== undefined);
|
|
69
|
+
const unloaded = byProvider.filter((p) => this.providers.forDevice(p.provider) === undefined);
|
|
70
70
|
const kept = unloaded.reduce((sum, p) => sum + Number(p.n), 0);
|
|
71
71
|
if (unloaded.length > 0 && now.getTime() % 3_600_000 < PERIOD_MS) {
|
|
72
72
|
this.log.warn("legacy sandboxes kept: their provider is not loaded", {
|
|
@@ -89,7 +89,7 @@ let LegacySandboxCleanupJob = class LegacySandboxCleanupJob {
|
|
|
89
89
|
if (signal?.aborted)
|
|
90
90
|
break;
|
|
91
91
|
const name = `cap-${row.conversation_id}`;
|
|
92
|
-
const impl = this.providers.
|
|
92
|
+
const impl = this.providers.forDevice(row.provider)?.impl;
|
|
93
93
|
if (impl === undefined)
|
|
94
94
|
continue; // unloaded since the query: kept for a later tick
|
|
95
95
|
const callSignal = () => signal
|
|
@@ -99,7 +99,7 @@ let LegacySandboxCleanupJob = class LegacySandboxCleanupJob {
|
|
|
99
99
|
await impl.destroyByName(name, callSignal());
|
|
100
100
|
await impl.destroyFileSystemByName(name, callSignal());
|
|
101
101
|
if (row.prev_provider !== null && row.prev_provider !== row.provider) {
|
|
102
|
-
const prev = this.providers.
|
|
102
|
+
const prev = this.providers.forDevice(row.prev_provider)?.impl;
|
|
103
103
|
if (prev !== undefined)
|
|
104
104
|
await prev.destroyByName(name, callSignal());
|
|
105
105
|
else {
|
|
@@ -133,7 +133,7 @@ __decorate([
|
|
|
133
133
|
LegacySandboxCleanupJob = __decorate([
|
|
134
134
|
Injectable(),
|
|
135
135
|
__param(0, Inject(KernelDb)),
|
|
136
|
-
__param(1, Inject(
|
|
136
|
+
__param(1, Inject(DeviceProviders)),
|
|
137
137
|
__param(2, Inject(KernelConfigService)),
|
|
138
138
|
__param(3, Inject(LockService)),
|
|
139
139
|
__param(4, Inject(KERNEL_LOGGER))
|
package/dist/errors.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ export declare const ERROR_CODES: {
|
|
|
55
55
|
* through an API token or the Platform tool.
|
|
56
56
|
*/
|
|
57
57
|
readonly "org.network_not_allowed": 400;
|
|
58
|
+
/** The org's default device provider names an extension that is not a `device-provider@1` provider on in the org. */
|
|
59
|
+
readonly "org.device_provider_not_available": 400;
|
|
58
60
|
/** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
|
|
59
61
|
readonly "org.network_allowance_invalid": 400;
|
|
60
62
|
readonly "org.network_allowance_not_found": 404;
|
|
@@ -321,6 +323,11 @@ export declare const ERROR_CODES: {
|
|
|
321
323
|
readonly "agent.version_conflict": 409;
|
|
322
324
|
/** The profile was changed since the client read it (`expectedUpdatedAt` is stale). */
|
|
323
325
|
readonly "agent.profile_conflict": 409;
|
|
326
|
+
/**
|
|
327
|
+
* An avatar input's theme preset key is not a preset of the writing org's effective default
|
|
328
|
+
* theme (theme brand coverage spec §4): choose one of the presets the picker shows.
|
|
329
|
+
*/
|
|
330
|
+
readonly "agent.avatar_unavailable": 400;
|
|
324
331
|
readonly "agent.model_unavailable": 400;
|
|
325
332
|
/** A save gave `instructionFiles` and an `instructions` that is not their join. */
|
|
326
333
|
readonly "agent.instructions_mismatch": 400;
|
|
@@ -441,8 +448,13 @@ export declare const ERROR_CODES: {
|
|
|
441
448
|
readonly "device.files_lost": 409;
|
|
442
449
|
/** The caller may see the device but not use it (shared devices, later phases). */
|
|
443
450
|
readonly "device.forbidden": 403;
|
|
444
|
-
/** The device's provider is
|
|
451
|
+
/** The device's provider is off in its org or not loaded, or it has none. */
|
|
445
452
|
readonly "device.unavailable": 503;
|
|
453
|
+
/**
|
|
454
|
+
* A new device names no provider and its org has no default device provider serving it; the
|
|
455
|
+
* message lists the providers on in the org.
|
|
456
|
+
*/
|
|
457
|
+
readonly "device.provider_required": 400;
|
|
446
458
|
/** The person already has a live device with this name (case-insensitive). */
|
|
447
459
|
readonly "device.name_taken": 409;
|
|
448
460
|
/** The person already has `devices.maxPersonal` live personal devices. */
|
|
@@ -525,6 +537,8 @@ export declare const ERROR_CODES: {
|
|
|
525
537
|
readonly "device.project_path_missing": 422;
|
|
526
538
|
/** The project's path is a file, cannot be read, or the device refused it in its current mode. */
|
|
527
539
|
readonly "device.project_path_unreadable": 422;
|
|
540
|
+
/** The device provider refused the project's directory (its reason is the message and details). */
|
|
541
|
+
readonly "device.project_refused": 422;
|
|
528
542
|
/** Device sign-in (RFC 8628 style): the person has not approved the code yet; keep polling. */
|
|
529
543
|
readonly "device_sign_in.authorization_pending": 400;
|
|
530
544
|
/** Device sign-in: the program polls faster than the interval; add 5 seconds and keep polling. */
|
package/dist/errors.js
CHANGED
|
@@ -55,6 +55,8 @@ export const ERROR_CODES = {
|
|
|
55
55
|
* through an API token or the Platform tool.
|
|
56
56
|
*/
|
|
57
57
|
"org.network_not_allowed": 400,
|
|
58
|
+
/** The org's default device provider names an extension that is not a `device-provider@1` provider on in the org. */
|
|
59
|
+
"org.device_provider_not_available": 400,
|
|
58
60
|
/** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
|
|
59
61
|
"org.network_allowance_invalid": 400,
|
|
60
62
|
"org.network_allowance_not_found": 404,
|
|
@@ -321,6 +323,11 @@ export const ERROR_CODES = {
|
|
|
321
323
|
"agent.version_conflict": 409,
|
|
322
324
|
/** The profile was changed since the client read it (`expectedUpdatedAt` is stale). */
|
|
323
325
|
"agent.profile_conflict": 409,
|
|
326
|
+
/**
|
|
327
|
+
* An avatar input's theme preset key is not a preset of the writing org's effective default
|
|
328
|
+
* theme (theme brand coverage spec §4): choose one of the presets the picker shows.
|
|
329
|
+
*/
|
|
330
|
+
"agent.avatar_unavailable": 400,
|
|
324
331
|
"agent.model_unavailable": 400,
|
|
325
332
|
/** A save gave `instructionFiles` and an `instructions` that is not their join. */
|
|
326
333
|
"agent.instructions_mismatch": 400,
|
|
@@ -441,8 +448,13 @@ export const ERROR_CODES = {
|
|
|
441
448
|
"device.files_lost": 409,
|
|
442
449
|
/** The caller may see the device but not use it (shared devices, later phases). */
|
|
443
450
|
"device.forbidden": 403,
|
|
444
|
-
/** The device's provider is
|
|
451
|
+
/** The device's provider is off in its org or not loaded, or it has none. */
|
|
445
452
|
"device.unavailable": 503,
|
|
453
|
+
/**
|
|
454
|
+
* A new device names no provider and its org has no default device provider serving it; the
|
|
455
|
+
* message lists the providers on in the org.
|
|
456
|
+
*/
|
|
457
|
+
"device.provider_required": 400,
|
|
446
458
|
/** The person already has a live device with this name (case-insensitive). */
|
|
447
459
|
"device.name_taken": 409,
|
|
448
460
|
/** The person already has `devices.maxPersonal` live personal devices. */
|
|
@@ -525,6 +537,8 @@ export const ERROR_CODES = {
|
|
|
525
537
|
"device.project_path_missing": 422,
|
|
526
538
|
/** The project's path is a file, cannot be read, or the device refused it in its current mode. */
|
|
527
539
|
"device.project_path_unreadable": 422,
|
|
540
|
+
/** The device provider refused the project's directory (its reason is the message and details). */
|
|
541
|
+
"device.project_refused": 422,
|
|
528
542
|
/** Device sign-in (RFC 8628 style): the person has not approved the code yet; keep polling. */
|
|
529
543
|
"device_sign_in.authorization_pending": 400,
|
|
530
544
|
/** Device sign-in: the program polls faster than the interval; add 5 seconds and keep polling. */
|
|
@@ -19,7 +19,8 @@ export type UnresolvedReason =
|
|
|
19
19
|
/**
|
|
20
20
|
* The org action each audience of a place needs besides `catalog.read` (spec §9.1).
|
|
21
21
|
* `extension-deployment` has none: its guides are the super admin's (the admin extension routes),
|
|
22
|
-
* so an org route refuses them (`forbidden`).
|
|
22
|
+
* so an org route refuses them (`forbidden`). `device-connection` is for members: the action of
|
|
23
|
+
* the devices routes (`agents.use`).
|
|
23
24
|
*/
|
|
24
25
|
export declare const PLACE_ACTIONS: Readonly<Record<SetupGuidePlace, Readonly<Partial<Record<SetupGuideAudience, OrgAction>>>>>;
|
|
25
26
|
/** The object a guide is rendered for. */
|
|
@@ -11,12 +11,14 @@ import { OAUTH_CALLBACK_PATH } from "../tools/oauth/flow-paths.js";
|
|
|
11
11
|
/**
|
|
12
12
|
* The org action each audience of a place needs besides `catalog.read` (spec §9.1).
|
|
13
13
|
* `extension-deployment` has none: its guides are the super admin's (the admin extension routes),
|
|
14
|
-
* so an org route refuses them (`forbidden`).
|
|
14
|
+
* so an org route refuses them (`forbidden`). `device-connection` is for members: the action of
|
|
15
|
+
* the devices routes (`agents.use`).
|
|
15
16
|
*/
|
|
16
17
|
export const PLACE_ACTIONS = {
|
|
17
18
|
"channel-connection": { admin: "channels.manage" },
|
|
18
19
|
"connector-template": { admin: "connectors.manage", member: "connectors.use" },
|
|
19
20
|
"extension-deployment": {},
|
|
21
|
+
"device-connection": { member: "agents.use" },
|
|
20
22
|
};
|
|
21
23
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
22
24
|
const invalidQuery = (path, message) => new ApiError("validation_failed", "Request validation failed", [{ path, message }]);
|
|
@@ -25,6 +27,7 @@ const TARGET_PARAMS = {
|
|
|
25
27
|
"channel-connection": ["connectionId", "name"],
|
|
26
28
|
"connector-template": ["connectorId"],
|
|
27
29
|
"extension-deployment": [],
|
|
30
|
+
"device-connection": [],
|
|
28
31
|
};
|
|
29
32
|
/**
|
|
30
33
|
* The variable values of a place for one rendering (spec §6.3): the common ones, then the place's
|
|
@@ -43,6 +46,7 @@ export async function resolvePlace(ctx) {
|
|
|
43
46
|
const values = {
|
|
44
47
|
publicUrl,
|
|
45
48
|
orgName: ctx.org?.name ?? null,
|
|
49
|
+
orgId: ctx.org?.orgId ?? null,
|
|
46
50
|
pluginName: ctx.item.name,
|
|
47
51
|
pluginVersion: ctx.item.version,
|
|
48
52
|
};
|
|
@@ -83,11 +87,13 @@ export async function resolvePlace(ctx) {
|
|
|
83
87
|
if (connector !== undefined)
|
|
84
88
|
target = { kind: "connector", id: connector.id };
|
|
85
89
|
}
|
|
86
|
-
// `extension-deployment`: the common variables only, no org and no target (the deployment)
|
|
90
|
+
// `extension-deployment`: the common variables only, no org and no target (the deployment);
|
|
91
|
+
// `device-connection`: the common ones and `orgId`; the new device's target comes with phase 3
|
|
87
92
|
reasons.publicUrl = "public_url";
|
|
88
93
|
reasons.signInCallbackUrl = "public_url";
|
|
89
94
|
reasons.oauthCallbackUrl = "public_url";
|
|
90
95
|
reasons.orgName = "no_org";
|
|
96
|
+
reasons.orgId = "no_org";
|
|
91
97
|
// keep only the reasons of variables that are the place's and have no value
|
|
92
98
|
const known = SETUP_GUIDE_PLACE_INFO[place].variables;
|
|
93
99
|
for (const name of Object.keys(reasons)) {
|
|
@@ -32,7 +32,7 @@ export declare class PluginDeploymentConfigLock {
|
|
|
32
32
|
lock(name: string): Promise<void>;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Serializes the enables of the providers of one single-provider extension point (`
|
|
35
|
+
* Serializes the enables of the providers of one single-provider extension point (`object-store@1`, …):
|
|
36
36
|
* two concurrent enables of different providers cannot both see the point free. Joins the
|
|
37
37
|
* caller's transaction (`mandatory`); taken after the install lock of the extension's name, the
|
|
38
38
|
* points in sorted order.
|
package/dist/extensions/locks.js
CHANGED
|
@@ -85,7 +85,7 @@ PluginDeploymentConfigLock = __decorate([
|
|
|
85
85
|
], PluginDeploymentConfigLock);
|
|
86
86
|
export { PluginDeploymentConfigLock };
|
|
87
87
|
/**
|
|
88
|
-
* Serializes the enables of the providers of one single-provider extension point (`
|
|
88
|
+
* Serializes the enables of the providers of one single-provider extension point (`object-store@1`, …):
|
|
89
89
|
* two concurrent enables of different providers cannot both see the point free. Joins the
|
|
90
90
|
* caller's transaction (`mandatory`); taken after the install lock of the extension's name, the
|
|
91
91
|
* points in sorted order.
|
|
@@ -172,7 +172,9 @@ export declare class OrgExtensionConfigs {
|
|
|
172
172
|
/**
|
|
173
173
|
* The state of every loaded extension the org sees, in load order (no row: `enabled` false,
|
|
174
174
|
* `config` null), then the installed extensions not loaded right now (disabled on the deployment
|
|
175
|
-
* and the like) as `available: false`, sorted by name.
|
|
175
|
+
* and the like) as `available: false`, sorted by name. The rows and secrets are read in a
|
|
176
|
+
* `requires_new` snapshot on a second pool connection: never call it inside a transaction that
|
|
177
|
+
* holds a pool connection (unlike {@link get}, it does not join one).
|
|
176
178
|
*/
|
|
177
179
|
list(orgId: string): Promise<OrgExtensionView[]>;
|
|
178
180
|
/**
|
|
@@ -181,7 +183,12 @@ export declare class OrgExtensionConfigs {
|
|
|
181
183
|
* loaded valid). Reads the org's copy rows once and the effective config of each such extension.
|
|
182
184
|
*/
|
|
183
185
|
private withLayers;
|
|
184
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* `REPEATABLE READ` read-only: the config rows and the secrets come from one snapshot. It is
|
|
188
|
+
* `requires_new`: it always takes a second pool connection, so never call `list` inside a
|
|
189
|
+
* transaction that holds one (a locked transaction waiting on the pool can starve it; `get`
|
|
190
|
+
* joins the caller's transaction instead).
|
|
191
|
+
*/
|
|
185
192
|
private listSnapshot;
|
|
186
193
|
/**
|
|
187
194
|
* How an `enabled` write of this extension is handled: `direct` through {@link put} (a required
|
|
@@ -224,7 +231,10 @@ export declare class OrgExtensionConfigs {
|
|
|
224
231
|
* An always-on extension (a required bootstrap plugin, or its plugin is builtin: `enabled.ts`) is
|
|
225
232
|
* enabled without a row (its stored config, or `{}`, is validated).
|
|
226
233
|
* 无记录 → undefined;插件无 `config.org` 或已停用(`enabled=false`,不校验、不读密钥)时 `config` 为 null。
|
|
227
|
-
*
|
|
234
|
+
* Inside a caller's transaction it joins that transaction (its connection and isolation, and it
|
|
235
|
+
* sees the caller's uncommitted writes): the config row and its secrets are consistent there when
|
|
236
|
+
* the caller holds the org row, as every writer of org configs and their secrets locks it first.
|
|
237
|
+
* On its own it reads them in one `REPEATABLE READ` read-only snapshot.
|
|
228
238
|
* A stored config that no longer matches the schema (e.g. after a plugin upgrade) throws
|
|
229
239
|
* {@link OrgConfigInvalidError} (plugin, org ID and the failing paths, no values); other errors are
|
|
230
240
|
* read errors.
|
|
@@ -233,7 +243,13 @@ export declare class OrgExtensionConfigs {
|
|
|
233
243
|
enabled: boolean;
|
|
234
244
|
config: unknown;
|
|
235
245
|
} | undefined>;
|
|
236
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* On its own, `REPEATABLE READ` read-only: the config row and the secrets come from one snapshot.
|
|
248
|
+
* Inside a caller's transaction it reads in that transaction instead (`required`; consistent when
|
|
249
|
+
* the caller holds the org row, see {@link get}): a caller holding a
|
|
250
|
+
* connection never waits for a second one from the pool (the device provider check runs inside
|
|
251
|
+
* locked transactions; concurrent runs would starve the pool).
|
|
252
|
+
*/
|
|
237
253
|
private getSnapshot;
|
|
238
254
|
private decode;
|
|
239
255
|
/**
|
|
@@ -166,7 +166,9 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
166
166
|
/**
|
|
167
167
|
* The state of every loaded extension the org sees, in load order (no row: `enabled` false,
|
|
168
168
|
* `config` null), then the installed extensions not loaded right now (disabled on the deployment
|
|
169
|
-
* and the like) as `available: false`, sorted by name.
|
|
169
|
+
* and the like) as `available: false`, sorted by name. The rows and secrets are read in a
|
|
170
|
+
* `requires_new` snapshot on a second pool connection: never call it inside a transaction that
|
|
171
|
+
* holds a pool connection (unlike {@link get}, it does not join one).
|
|
170
172
|
*/
|
|
171
173
|
async list(orgId) {
|
|
172
174
|
const installed = (await this.installs.list()).map((r) => ({
|
|
@@ -206,7 +208,12 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
206
208
|
}
|
|
207
209
|
return views;
|
|
208
210
|
}
|
|
209
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* `REPEATABLE READ` read-only: the config rows and the secrets come from one snapshot. It is
|
|
213
|
+
* `requires_new`: it always takes a second pool connection, so never call `list` inside a
|
|
214
|
+
* transaction that holds one (a locked transaction waiting on the pool can starve it; `get`
|
|
215
|
+
* joins the caller's transaction instead).
|
|
216
|
+
*/
|
|
210
217
|
async listSnapshot(orgId, installed) {
|
|
211
218
|
const t = this.db;
|
|
212
219
|
const rows = await t
|
|
@@ -467,7 +474,10 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
467
474
|
* An always-on extension (a required bootstrap plugin, or its plugin is builtin: `enabled.ts`) is
|
|
468
475
|
* enabled without a row (its stored config, or `{}`, is validated).
|
|
469
476
|
* 无记录 → undefined;插件无 `config.org` 或已停用(`enabled=false`,不校验、不读密钥)时 `config` 为 null。
|
|
470
|
-
*
|
|
477
|
+
* Inside a caller's transaction it joins that transaction (its connection and isolation, and it
|
|
478
|
+
* sees the caller's uncommitted writes): the config row and its secrets are consistent there when
|
|
479
|
+
* the caller holds the org row, as every writer of org configs and their secrets locks it first.
|
|
480
|
+
* On its own it reads them in one `REPEATABLE READ` read-only snapshot.
|
|
471
481
|
* A stored config that no longer matches the schema (e.g. after a plugin upgrade) throws
|
|
472
482
|
* {@link OrgConfigInvalidError} (plugin, org ID and the failing paths, no values); other errors are
|
|
473
483
|
* read errors.
|
|
@@ -475,13 +485,20 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
475
485
|
async get(orgId, plugin) {
|
|
476
486
|
const manifest = this.manifest(plugin);
|
|
477
487
|
const result = await this.getSnapshot(orgId, plugin, manifest);
|
|
478
|
-
//
|
|
488
|
+
// the read is done (its own snapshot has ended, or it ran in the caller's transaction); a
|
|
489
|
+
// non-null config means the plugin has an org schema and the config was decrypted
|
|
479
490
|
const schema = manifest.config?.org;
|
|
480
491
|
if (schema && result?.config != null)
|
|
481
492
|
this.reportSecrets({ schema, config: result.config });
|
|
482
493
|
return result;
|
|
483
494
|
}
|
|
484
|
-
/**
|
|
495
|
+
/**
|
|
496
|
+
* On its own, `REPEATABLE READ` read-only: the config row and the secrets come from one snapshot.
|
|
497
|
+
* Inside a caller's transaction it reads in that transaction instead (`required`; consistent when
|
|
498
|
+
* the caller holds the org row, see {@link get}): a caller holding a
|
|
499
|
+
* connection never waits for a second one from the pool (the device provider check runs inside
|
|
500
|
+
* locked transactions; concurrent runs would starve the pool).
|
|
501
|
+
*/
|
|
485
502
|
async getSnapshot(orgId, plugin, manifest) {
|
|
486
503
|
const t = this.db;
|
|
487
504
|
const row = await t
|
|
@@ -707,7 +724,7 @@ __decorate([
|
|
|
707
724
|
], OrgExtensionConfigs.prototype, "write", null);
|
|
708
725
|
__decorate([
|
|
709
726
|
Transactional({
|
|
710
|
-
propagation: "
|
|
727
|
+
propagation: "required",
|
|
711
728
|
isolationLevel: "repeatable read",
|
|
712
729
|
accessMode: "read only",
|
|
713
730
|
})
|
|
@@ -30,7 +30,7 @@ export interface PermissionGroup {
|
|
|
30
30
|
* ({@link SENSITIVE_EXTENSION_POINTS}; the code is the extension point name without `@<major>`, with
|
|
31
31
|
* `-` replaced by `_`).
|
|
32
32
|
*/
|
|
33
|
-
export type SensitiveReason = "secrets" | "public_routes" | "embed_routes" | "tools" | "hooks" | "ui_embed" | "client_code" | "ui_component" | "channel" | "directory" | "identity_source" | "
|
|
33
|
+
export type SensitiveReason = "secrets" | "public_routes" | "embed_routes" | "tools" | "hooks" | "ui_embed" | "client_code" | "ui_component" | "channel" | "directory" | "identity_source" | "device_provider" | "object_store" | "context" | "push_provider" | "migration_warnings";
|
|
34
34
|
/** 权限清单里的一项(分组里的一项,或 `added` 里的一个权限键)。 */
|
|
35
35
|
export interface PermissionItem {
|
|
36
36
|
value: string;
|
|
@@ -39,7 +39,7 @@ export interface PermissionItem {
|
|
|
39
39
|
reason?: SensitiveReason;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* Sensitive capabilities (D10 + planned extensions, F-AI): `
|
|
42
|
+
* Sensitive capabilities (D10 + planned extensions, F-AI): `device-provider@1` runs arbitrary commands in
|
|
43
43
|
* the deployment, `object-store@1` holds every attachment and plugin package (D10); `channel@1`
|
|
44
44
|
* receives the org's IM conversations (Ruling A33), `directory@1` can add people to orgs (creating
|
|
45
45
|
* their accounts and identities), `identity-source@1` decides who can sign in as which account;
|
|
@@ -18,7 +18,7 @@ export function reviewHash(set, warnings = []) {
|
|
|
18
18
|
return h.digest("hex").slice(0, 16);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Sensitive capabilities (D10 + planned extensions, F-AI): `
|
|
21
|
+
* Sensitive capabilities (D10 + planned extensions, F-AI): `device-provider@1` runs arbitrary commands in
|
|
22
22
|
* the deployment, `object-store@1` holds every attachment and plugin package (D10); `channel@1`
|
|
23
23
|
* receives the org's IM conversations (Ruling A33), `directory@1` can add people to orgs (creating
|
|
24
24
|
* their accounts and identities), `identity-source@1` decides who can sign in as which account;
|
|
@@ -33,7 +33,7 @@ export const SENSITIVE_EXTENSION_POINTS = [
|
|
|
33
33
|
"channel@1",
|
|
34
34
|
"directory@1",
|
|
35
35
|
"identity-source@1",
|
|
36
|
-
"
|
|
36
|
+
"device-provider@1",
|
|
37
37
|
"object-store@1",
|
|
38
38
|
"context@1",
|
|
39
39
|
"push-provider@1",
|
|
@@ -293,7 +293,7 @@ export declare class PluginGuides {
|
|
|
293
293
|
renderForDeployment(plugin: string, guideId: string, q: {
|
|
294
294
|
locale?: "en" | "zh" | undefined;
|
|
295
295
|
}): Promise<RenderedSetupGuide>;
|
|
296
|
-
/** A guide rendered without an org: the
|
|
296
|
+
/** A guide rendered without an org: the place's default audience, no target, `orgName` unresolved. */
|
|
297
297
|
private renderPlatformDoc;
|
|
298
298
|
/** The audience asked for, after checking `mode` and `audience` against the place. */
|
|
299
299
|
private checkQuery;
|
|
@@ -72,6 +72,11 @@ function guidesOf(manifest) {
|
|
|
72
72
|
const guides = raw.filter(isV2Guide);
|
|
73
73
|
return { guides, skipped: raw.length - guides.length };
|
|
74
74
|
}
|
|
75
|
+
/** The audience shown by default: admin, else the place's first (a device-connection guide is for members). */
|
|
76
|
+
const defaultAudience = (place) => {
|
|
77
|
+
const { audiences } = SETUP_GUIDE_PLACE_INFO[place];
|
|
78
|
+
return audiences.includes("admin") ? "admin" : (audiences[0] ?? "admin");
|
|
79
|
+
};
|
|
75
80
|
/** A plugin's guide for a place (and template): the manifest allows at most one. */
|
|
76
81
|
const guideFor = (manifest, place, templateId) => guidesOf(manifest).guides.find((g) => g.place === place && (templateId === undefined || g.template === templateId));
|
|
77
82
|
/**
|
|
@@ -524,7 +529,7 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
524
529
|
throw guideNotFound();
|
|
525
530
|
return this.renderPlatformDoc(row, guide, q.locale ?? "en");
|
|
526
531
|
}
|
|
527
|
-
/** A guide rendered without an org: the
|
|
532
|
+
/** A guide rendered without an org: the place's default audience, no target, `orgName` unresolved. */
|
|
528
533
|
async renderPlatformDoc(row, guide, locale) {
|
|
529
534
|
const docs = await this.documents(row, guide, locale);
|
|
530
535
|
const resolution = await resolvePlace({
|
|
@@ -536,12 +541,15 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
536
541
|
org: null,
|
|
537
542
|
query: {},
|
|
538
543
|
});
|
|
539
|
-
return this.renderDoc(row, guide, docs, resolution, {
|
|
544
|
+
return this.renderDoc(row, guide, docs, resolution, {
|
|
545
|
+
mode: undefined,
|
|
546
|
+
audience: defaultAudience(guide.place),
|
|
547
|
+
});
|
|
540
548
|
}
|
|
541
549
|
/** The audience asked for, after checking `mode` and `audience` against the place. */
|
|
542
550
|
checkQuery(guide, q) {
|
|
543
551
|
const info = SETUP_GUIDE_PLACE_INFO[guide.place];
|
|
544
|
-
const audience = q.audience ??
|
|
552
|
+
const audience = q.audience ?? defaultAudience(guide.place);
|
|
545
553
|
if (!info.audiences.includes(audience)) {
|
|
546
554
|
throw invalidQuery("audience", `audience must be one of ${info.audiences.join(", ")} for a ${guide.place} guide`);
|
|
547
555
|
}
|
|
@@ -94,6 +94,20 @@ export declare class ExtensionPointDefaults {
|
|
|
94
94
|
* org config or effective config is invalid is excluded but not `failed`: it is known to be off.
|
|
95
95
|
*/
|
|
96
96
|
private candidates;
|
|
97
|
+
/**
|
|
98
|
+
* Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`. The
|
|
99
|
+
* provider must be loaded on this replica and provide `point`; the org must have it enabled; its
|
|
100
|
+
* org config and effective config must be valid; and its `configured()` must not return false.
|
|
101
|
+
* These are exactly the criteria of {@link providersFor} / {@link resolve}, with only that one
|
|
102
|
+
* provider evaluated. A provider whose status cannot be read counts as not serving (logged).
|
|
103
|
+
*/
|
|
104
|
+
serves(orgId: string, point: string, extension: string): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* One enabled provider's candidacy: valid org config, valid effective config and `configured()`
|
|
107
|
+
* not false. Undefined when it is off; a provider whose status could not be read is also added
|
|
108
|
+
* to `failed`.
|
|
109
|
+
*/
|
|
110
|
+
private evaluate;
|
|
97
111
|
private choose;
|
|
98
112
|
/** The org's stored defaults, point → extension. */
|
|
99
113
|
private storedDefaults;
|