@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
|
@@ -46,7 +46,7 @@ export declare class BackgroundTaskPollJob {
|
|
|
46
46
|
private readonly stopper;
|
|
47
47
|
/** The marker that logs a left-alone legacy instance once across the replicas. */
|
|
48
48
|
private readonly redis?;
|
|
49
|
-
constructor(store: Pick<BackgroundTaskStore, "runningLegacy" | "runningManaged" | "owedCancels" | "pruneFinished" | "failAbandonedLaunches">, finisher: BackgroundTaskFinisher, eventLog: Pick<EventLog, "publishChanged">, sandbox: Pick<SandboxService, "
|
|
49
|
+
constructor(store: Pick<BackgroundTaskStore, "runningLegacy" | "runningManaged" | "owedCancels" | "pruneFinished" | "failAbandonedLaunches">, finisher: BackgroundTaskFinisher, eventLog: Pick<EventLog, "publishChanged">, sandbox: Pick<SandboxService, "availableFor" | "providerLoaded" | "ifRunning">, config: KernelConfigService, lockService: LockService, log: KernelLogger, stopper: Pick<BackgroundTaskStopper, "stop">,
|
|
50
50
|
/** The marker that logs a left-alone legacy instance once across the replicas. */
|
|
51
51
|
redis?: Pick<Redis, "set"> | undefined);
|
|
52
52
|
poll(signal?: AbortSignal): Promise<void>;
|
|
@@ -106,10 +106,11 @@ let BackgroundTaskPollJob = class BackgroundTaskPollJob {
|
|
|
106
106
|
if (signal.aborted)
|
|
107
107
|
break;
|
|
108
108
|
try {
|
|
109
|
-
// the device's provider
|
|
110
|
-
// its tasks stay as they are until it
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
// the device's provider does not serve its org now (off in the org, not loaded, `@local`
|
|
110
|
+
// not registered): its tasks stay as they are until it does. A task without a device
|
|
111
|
+
// needs no provider: pollLegacy finishes it as gone.
|
|
112
|
+
const first = tasks[0];
|
|
113
|
+
if (first?.deviceId && !(await this.sandbox.availableFor(first.deviceId, first.orgId))) {
|
|
113
114
|
continue;
|
|
114
115
|
}
|
|
115
116
|
finished += await this.pollLegacy(tasks, signal);
|
|
@@ -162,7 +163,7 @@ let BackgroundTaskPollJob = class BackgroundTaskPollJob {
|
|
|
162
163
|
break;
|
|
163
164
|
const [first] = tasks;
|
|
164
165
|
try {
|
|
165
|
-
if (!(await this.sandbox.availableFor(first.deviceId)))
|
|
166
|
+
if (!(await this.sandbox.availableFor(first.deviceId, first.orgId)))
|
|
166
167
|
continue;
|
|
167
168
|
n += await this.pollManagedInstance(tasks, signal);
|
|
168
169
|
}
|
|
@@ -183,7 +184,8 @@ let BackgroundTaskPollJob = class BackgroundTaskPollJob {
|
|
|
183
184
|
if (signal.aborted || attempts >= MANAGED_STOPS_PER_TICK)
|
|
184
185
|
break;
|
|
185
186
|
try {
|
|
186
|
-
|
|
187
|
+
// revocation delivery needs the provider loaded only (not on in the org)
|
|
188
|
+
if (!(await this.sandbox.providerLoaded(t.deviceId)))
|
|
187
189
|
continue;
|
|
188
190
|
attempts++;
|
|
189
191
|
const after = await this.stopper.stop(t, "revoked", signal);
|
|
@@ -205,7 +205,7 @@ let BackgroundTasks = class BackgroundTasks {
|
|
|
205
205
|
reason: task.status === "running" ? "starting" : "not_started",
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
if (!(await this.sandbox.availableFor(task.deviceId))) {
|
|
208
|
+
if (!(await this.sandbox.availableFor(task.deviceId, orgId))) {
|
|
209
209
|
return { kind: "unavailable", reason: "unavailable" };
|
|
210
210
|
}
|
|
211
211
|
if (!(await this.deviceUsable(orgId, task.conversationId))) {
|
|
@@ -203,7 +203,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
203
203
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
204
204
|
export declare const HOST_VERSIONS: {
|
|
205
205
|
readonly kernel: string;
|
|
206
|
-
readonly sdk: "0.1.0-rc.
|
|
206
|
+
readonly sdk: "0.1.0-rc.51";
|
|
207
207
|
};
|
|
208
208
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
209
209
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -77,9 +77,8 @@ export declare class ChannelInbound {
|
|
|
77
77
|
/**
|
|
78
78
|
* Direct-message `/device` (environments spec §4.2 item 8): lists the person's usable devices,
|
|
79
79
|
* or with a name sets the IM default their next new conversation is bound to. The name matches
|
|
80
|
-
* case-insensitively against each label (`deviceLabel
|
|
81
|
-
*
|
|
82
|
-
* answers to 个人设备 / Personal.
|
|
80
|
+
* case-insensitively against each label (`deviceLabel`); the default device also answers to
|
|
81
|
+
* its zh or en "Personal" label (`PERSONAL` in devices/label.ts).
|
|
83
82
|
*/
|
|
84
83
|
private deviceCommand;
|
|
85
84
|
/**
|
package/dist/channels/inbound.js
CHANGED
|
@@ -316,9 +316,8 @@ let ChannelInbound = class ChannelInbound {
|
|
|
316
316
|
/**
|
|
317
317
|
* Direct-message `/device` (environments spec §4.2 item 8): lists the person's usable devices,
|
|
318
318
|
* or with a name sets the IM default their next new conversation is bound to. The name matches
|
|
319
|
-
* case-insensitively against each label (`deviceLabel
|
|
320
|
-
*
|
|
321
|
-
* answers to 个人设备 / Personal.
|
|
319
|
+
* case-insensitively against each label (`deviceLabel`); the default device also answers to
|
|
320
|
+
* its zh or en "Personal" label (`PERSONAL` in devices/label.ts).
|
|
322
321
|
*/
|
|
323
322
|
async deviceCommand(orgId, accountId, name, locale, replyText) {
|
|
324
323
|
const { items, defaultId } = await this.devices.list(orgId, accountId);
|
|
@@ -29,10 +29,10 @@ export declare const CHANNEL_PHRASES: {
|
|
|
29
29
|
};
|
|
30
30
|
/** `/device <name>` names an existing device that is unavailable now (`{list}` as in deviceList). */
|
|
31
31
|
readonly deviceUnavailable: {
|
|
32
|
-
readonly zh: "设备「{name}
|
|
33
|
-
readonly en: "The device “{name}” is unavailable: its
|
|
32
|
+
readonly zh: "设备「{name}」当前不可用(它的设备提供方在该组织未启用或未安装,文件仍保留)。你的设备:\n{list}";
|
|
33
|
+
readonly en: "The device “{name}” is unavailable: its device provider is off in this organization or not installed (its files are kept). Your devices:\n{list}";
|
|
34
34
|
};
|
|
35
|
-
/** Direct message `/device` when the person has no usable device (no
|
|
35
|
+
/** Direct message `/device` when the person has no usable device (no device provider on in the org). */
|
|
36
36
|
readonly deviceNone: {
|
|
37
37
|
readonly zh: "你目前没有可用的设备。";
|
|
38
38
|
readonly en: "You have no usable devices.";
|
package/dist/channels/phrases.js
CHANGED
|
@@ -24,10 +24,10 @@ export const CHANNEL_PHRASES = {
|
|
|
24
24
|
},
|
|
25
25
|
/** `/device <name>` names an existing device that is unavailable now (`{list}` as in deviceList). */
|
|
26
26
|
deviceUnavailable: {
|
|
27
|
-
zh: "设备「{name}
|
|
28
|
-
en: "The device \u201c{name}\u201d is unavailable: its
|
|
27
|
+
zh: "设备「{name}」当前不可用(它的设备提供方在该组织未启用或未安装,文件仍保留)。你的设备:\n{list}",
|
|
28
|
+
en: "The device \u201c{name}\u201d is unavailable: its device provider is off in this organization or not installed (its files are kept). Your devices:\n{list}",
|
|
29
29
|
},
|
|
30
|
-
/** Direct message `/device` when the person has no usable device (no
|
|
30
|
+
/** Direct message `/device` when the person has no usable device (no device provider on in the org). */
|
|
31
31
|
deviceNone: {
|
|
32
32
|
zh: "你目前没有可用的设备。",
|
|
33
33
|
en: "You have no usable devices.",
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -283,6 +283,7 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
283
283
|
allowed: "allowed";
|
|
284
284
|
off: "off";
|
|
285
285
|
}>>;
|
|
286
|
+
defaultProvider: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>>;
|
|
286
287
|
network: z.ZodPrefault<z.ZodObject<{
|
|
287
288
|
default: z.ZodOptional<z.ZodEnum<{
|
|
288
289
|
allowlist: "allowlist";
|
package/dist/config/schema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isIP } from "node:net";
|
|
2
|
-
import { CATALOG_ITEM_NAME_RE, DOCUMENT_MEDIA_TYPES, IMAGE_MEDIA_TYPES, validateAllowHost, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { CATALOG_ITEM_NAME_RE, DOCUMENT_MEDIA_TYPES, EXTENSION_NAME_RE, IMAGE_MEDIA_TYPES, validateAllowHost, } from "@capybara-hq/plugin-sdk";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { LOG_FORMATS, LOG_LEVELS } from "../log.js";
|
|
5
5
|
import { noProxyEntryProblem, proxyUrlProblem } from "../net/proxy.js";
|
|
@@ -1659,6 +1659,19 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1659
1659
|
hot: true,
|
|
1660
1660
|
description: "Whether a device may be granted running a call outside its sandbox (default allowed): a person, the review model or Auto then approves such an escalation per call, within the organization's and the device owner's settings; off refuses every escalation, and devices only run in their sandbox. An organization may turn it off and follow the platform. Set here, it is read-only in the admin console. Replaces devices.fullAccess (CAPYBARA_DEVICES__FULL_ACCESS) and devices.autoMode, which are refused: rename them (the same values; off also needs devices.network.ceiling: allowlist to keep devices on the allowlist), or convert a config file with capybara config migrate-permissions",
|
|
1661
1661
|
})),
|
|
1662
|
+
/**
|
|
1663
|
+
* The device provider that makes a person's default device (several `device-provider@1`
|
|
1664
|
+
* extensions may coexist). Also a deployment setting the super admin changes in the admin
|
|
1665
|
+
* console (`devicesDefaultProvider`); the startup config wins over it, so this field is
|
|
1666
|
+
* optional with no schema default. An empty string means none. An org may override it.
|
|
1667
|
+
*/
|
|
1668
|
+
defaultProvider: z
|
|
1669
|
+
.union([z.literal(""), z.string().regex(EXTENSION_NAME_RE)])
|
|
1670
|
+
.optional()
|
|
1671
|
+
.meta(meta({
|
|
1672
|
+
hot: true,
|
|
1673
|
+
description: "The name of the device provider extension that makes a person's default device, needed with a single device provider too (default none: nobody gets a default device, and creating a device needs an explicit provider). An empty string means none. An organization may choose another provider that is on in it. Set here, it is read-only in the admin console",
|
|
1674
|
+
})),
|
|
1662
1675
|
/**
|
|
1663
1676
|
* The platform's device sandbox network (approval-only profiles design, "Settings model"):
|
|
1664
1677
|
* the default mode and the widest mode an org or device may choose, `open` (the public
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ConversationSource } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { AgentLookup } from "../agents/agent-lookup.js";
|
|
3
3
|
import type { ModelRef } from "../agents/definition.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { AgentAvatarView } from "../agents/profile.js";
|
|
5
5
|
import type { TitleSource } from "../db/kernel-schema.js";
|
|
6
6
|
import { ConversationDevices, type NewConversationDevice } from "../devices/conversation-devices.js";
|
|
7
7
|
import { DeviceProjectsService } from "../devices/device-projects.service.js";
|
|
@@ -97,7 +97,7 @@ export interface ConversationGroup {
|
|
|
97
97
|
id: string;
|
|
98
98
|
name: string;
|
|
99
99
|
profile: {
|
|
100
|
-
avatar:
|
|
100
|
+
avatar: AgentAvatarView;
|
|
101
101
|
updatedAt: string;
|
|
102
102
|
};
|
|
103
103
|
};
|
|
@@ -371,7 +371,8 @@ export declare class ConversationsService {
|
|
|
371
371
|
* checks the owner and the device's current mode (refused with `device.not_found`,
|
|
372
372
|
* `device.projects_unsupported`, `device.project_not_found` or `device.project_outside_mode`).
|
|
373
373
|
* Called inside the transaction that writes the conversation. A conversation without a device
|
|
374
|
-
* (no
|
|
374
|
+
* (no default device provider on in the org, an anonymous IM sender) cannot have one. Undefined
|
|
375
|
+
* name: free mode.
|
|
375
376
|
*/
|
|
376
377
|
private bindingFor;
|
|
377
378
|
/**
|
|
@@ -11,6 +11,7 @@ import { randomUUID } from "node:crypto";
|
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { AgentLookup, visibleTo } from "../agents/agent-lookup.js";
|
|
14
|
+
import { avatarView } from "../agents/avatar-view.js";
|
|
14
15
|
import { unbindConversation } from "../channels/threads.js";
|
|
15
16
|
import { ConversationDevices, } from "../devices/conversation-devices.js";
|
|
16
17
|
import { DeviceProjectsService } from "../devices/device-projects.service.js";
|
|
@@ -344,7 +345,8 @@ let ConversationsService = class ConversationsService {
|
|
|
344
345
|
* checks the owner and the device's current mode (refused with `device.not_found`,
|
|
345
346
|
* `device.projects_unsupported`, `device.project_not_found` or `device.project_outside_mode`).
|
|
346
347
|
* Called inside the transaction that writes the conversation. A conversation without a device
|
|
347
|
-
* (no
|
|
348
|
+
* (no default device provider on in the org, an anonymous IM sender) cannot have one. Undefined
|
|
349
|
+
* name: free mode.
|
|
348
350
|
*/
|
|
349
351
|
async bindingFor(orgId, accountId, deviceId, name) {
|
|
350
352
|
if (name === undefined)
|
|
@@ -676,7 +678,7 @@ let ConversationsService = class ConversationsService {
|
|
|
676
678
|
id: r.agent_id,
|
|
677
679
|
name: r.agent_name ?? "",
|
|
678
680
|
profile: {
|
|
679
|
-
avatar: r.profile_avatar,
|
|
681
|
+
avatar: avatarView(r.profile_avatar),
|
|
680
682
|
updatedAt: r.profile_updated_at.toISOString(),
|
|
681
683
|
},
|
|
682
684
|
},
|
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { DEVICE_PROVIDER_EXTENSION_POINT, EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { Command, ConnectionBuilder, ControlledTransactionBuilder, Kysely, TransactionBuilder, } from "kysely";
|
|
3
3
|
import { conversationTopic } from "../conversations/event-log.js";
|
|
4
4
|
import { kernelDb } from "../db/kernel-schema.js";
|
|
@@ -10,6 +10,7 @@ import { audit } from "../identity/audit.js";
|
|
|
10
10
|
import { PrefixedStorage } from "../storage/storage.service.js";
|
|
11
11
|
import { canUseSlot, orgUiTopic, PLATFORM_UI_TOPIC, PluginUiRegistration, } from "../ui/registry.js";
|
|
12
12
|
import { createBus } from "./bus.js";
|
|
13
|
+
import { checkDeviceProvider } from "./device-provider-check.js";
|
|
13
14
|
import { createKv } from "./kv.js";
|
|
14
15
|
import { createLock } from "./lock.js";
|
|
15
16
|
import { createExtensionNet } from "./net.js";
|
|
@@ -658,7 +659,9 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
|
|
|
658
659
|
}
|
|
659
660
|
const served = extensionPoint === FILE_PREVIEW_EXTENSION_POINT
|
|
660
661
|
? checkFilePreviewProvider(manifest, impl, uiResolution, deps.log)
|
|
661
|
-
:
|
|
662
|
+
: extensionPoint === DEVICE_PROVIDER_EXTENSION_POINT
|
|
663
|
+
? checkDeviceProvider(name, impl)
|
|
664
|
+
: impl;
|
|
662
665
|
provided.set(extensionPoint, served);
|
|
663
666
|
ledger.add({
|
|
664
667
|
kind: "provide",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DeviceProvider } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Checks a plugin's `device-provider@1` implementation when it is provided: the declarations
|
|
4
|
+
* (`networkAllowlist`, `concurrentExec`) must be `true` and the required methods must exist. A
|
|
5
|
+
* failure fails the plugin's setup, so it never loads.
|
|
6
|
+
*/
|
|
7
|
+
export declare function checkDeviceProvider(plugin: string, impl: unknown): DeviceProvider;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const REQUIRED_FUNCTIONS = ["report", "killTagged", "exec", "create", "createFileSystem"];
|
|
2
|
+
/**
|
|
3
|
+
* Checks a plugin's `device-provider@1` implementation when it is provided: the declarations
|
|
4
|
+
* (`networkAllowlist`, `concurrentExec`) must be `true` and the required methods must exist. A
|
|
5
|
+
* failure fails the plugin's setup, so it never loads.
|
|
6
|
+
*/
|
|
7
|
+
export function checkDeviceProvider(plugin, impl) {
|
|
8
|
+
const p = (impl ?? {});
|
|
9
|
+
const need = (member) => {
|
|
10
|
+
throw new Error(`plugin ${plugin}: device-provider@1 requires ${member}`);
|
|
11
|
+
};
|
|
12
|
+
if (p.networkAllowlist !== true)
|
|
13
|
+
need("networkAllowlist");
|
|
14
|
+
if (p.concurrentExec !== true)
|
|
15
|
+
need("concurrentExec");
|
|
16
|
+
for (const m of REQUIRED_FUNCTIONS) {
|
|
17
|
+
if (typeof p[m] !== "function")
|
|
18
|
+
need(m);
|
|
19
|
+
}
|
|
20
|
+
return impl;
|
|
21
|
+
}
|
|
@@ -1139,6 +1139,13 @@ export interface DevicesTable {
|
|
|
1139
1139
|
network_mode: ColumnType<"open" | "allowlist" | "none" | null, "open" | "allowlist" | "none" | null | undefined, "open" | "allowlist" | "none" | null>;
|
|
1140
1140
|
/** 0165: a cloud device's allowlist hosts (a JSON array), used while the mode is `allowlist`. */
|
|
1141
1141
|
network_hosts: ColumnType<string[], string | undefined, string>;
|
|
1142
|
+
/**
|
|
1143
|
+
* 0176: what the device's provider last reported (a `DeviceReport` as JSON; read back through
|
|
1144
|
+
* `parseDeviceReport`, see `DeviceReports`); null until the first create or resume stores one.
|
|
1145
|
+
*/
|
|
1146
|
+
report: ColumnType<unknown, string | null | undefined, string | null>;
|
|
1147
|
+
/** 0176: when {@link report} was stored. */
|
|
1148
|
+
report_at: TsNullable;
|
|
1142
1149
|
created_at: Ts;
|
|
1143
1150
|
updated_at: Ts;
|
|
1144
1151
|
deleted_at: TsNullable;
|
package/dist/devices/access.d.ts
CHANGED
|
@@ -1,49 +1,16 @@
|
|
|
1
1
|
import { ApiError } from "../errors.js";
|
|
2
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
-
import {
|
|
4
|
-
/** What decides a device's provider: its own record and its instance row's (if any). */
|
|
5
|
-
export interface ProviderFacts {
|
|
6
|
-
/** `devices.provider`: the provider current when it was created. */
|
|
7
|
-
provider: string | null;
|
|
8
|
-
/** `device_instances.provider`; null without an instance row. */
|
|
9
|
-
instanceProvider: string | null;
|
|
10
|
-
/** The instance row's `fs_status`; null without an instance row. */
|
|
11
|
-
fsStatus: "none" | "ready" | "lost" | null;
|
|
12
|
-
/** The instance row records an instance handle. */
|
|
13
|
-
hasInstance: boolean;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* The provider a device works with: a kernel-internal one (`@local`) as recorded; for a
|
|
17
|
-
* cloud device the one keeping its files or instance once it has any (they are never
|
|
18
|
-
* migrated, spec §4.2 item 13); before that, the current cloud provider (its first use creates
|
|
19
|
-
* them there), else the one recorded at creation. The same rule as `SandboxService`'s use.
|
|
20
|
-
*/
|
|
21
|
-
export declare function deviceProvider(f: ProviderFacts, current: string | undefined): string | null;
|
|
22
|
-
/** It has files or an instance at some provider (a file system, even a lost one, or a handle). */
|
|
23
|
-
export declare const holdsResources: (f: ProviderFacts) => boolean;
|
|
24
|
-
/** `device_instances.status`. */
|
|
25
|
-
export type InstanceStatus = "none" | "creating" | "running" | "suspended" | "destroyed";
|
|
3
|
+
import { DeviceProviderSelection } from "./device-provider-selection.js";
|
|
26
4
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* be creating the instance before any file system or handle is recorded). Lost files count as
|
|
30
|
-
* none here, unlike {@link holdsResources}, which decides the provider.
|
|
5
|
+
* The device's provider is off in its org or not installed, or the device has none (503). Its
|
|
6
|
+
* files and instance are kept: nothing is demoted, recreated or moved to another provider.
|
|
31
7
|
*/
|
|
32
|
-
export declare const
|
|
33
|
-
status: InstanceStatus | null;
|
|
34
|
-
}) => boolean;
|
|
35
|
-
/**
|
|
36
|
-
* The provider a former default belongs to (its label and the provider whose switch back restores
|
|
37
|
-
* it): the one holding its resources once it holds any, else the one it was demoted from (the
|
|
38
|
-
* marker). A former default demoted while empty and used afterwards keeps a stale marker; its
|
|
39
|
-
* resources decide. null for a device that is not a former default.
|
|
40
|
-
*/
|
|
41
|
-
export declare function demotedProvider(marker: string | null, f: ProviderFacts): string | null;
|
|
8
|
+
export declare const deviceUnavailable: (provider: string | null) => ApiError;
|
|
42
9
|
/**
|
|
43
|
-
* The device's
|
|
44
|
-
*
|
|
10
|
+
* The device's instance row names another provider than the device's own (503): never written by
|
|
11
|
+
* this kernel (a device is bound to its provider for life), so nothing is taken over.
|
|
45
12
|
*/
|
|
46
|
-
export declare const
|
|
13
|
+
export declare const deviceInstanceForeign: (provider: string, instanceProvider: string) => ApiError;
|
|
47
14
|
/**
|
|
48
15
|
* Who may use a device (spec §4.2 item 12): in phase 1 only the owner of a personal
|
|
49
16
|
* device. Anyone else gets `device.not_found`, never `forbidden`, so ids cannot be
|
|
@@ -51,16 +18,19 @@ export declare const deviceUnavailable: (provider: string | null) => ApiError;
|
|
|
51
18
|
*/
|
|
52
19
|
export declare class DeviceAccess {
|
|
53
20
|
private readonly db;
|
|
54
|
-
private readonly
|
|
55
|
-
constructor(db: KernelDb,
|
|
21
|
+
private readonly selection;
|
|
22
|
+
constructor(db: KernelDb, selection: Pick<DeviceProviderSelection, "isOnInOrg">);
|
|
56
23
|
/**
|
|
57
24
|
* The device if `accountId` may use it in `orgId` now: `device.not_found` when it is
|
|
58
|
-
* missing, deleted, in another org or someone else's; `device.unavailable` when
|
|
59
|
-
* provider
|
|
60
|
-
*
|
|
25
|
+
* missing, deleted, in another org or someone else's; `device.unavailable` when it has no
|
|
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
|
+
* `@local` not registered), or its instance row names another provider (never written by this
|
|
29
|
+
* kernel). A local device is usable while `@local` is registered: whether its machine is online
|
|
30
|
+
* is the relay's concern, not access.
|
|
61
31
|
*/
|
|
62
32
|
usable(orgId: string, accountId: string, deviceId: string): Promise<{
|
|
63
33
|
id: string;
|
|
64
|
-
provider: string
|
|
34
|
+
provider: string;
|
|
65
35
|
}>;
|
|
66
36
|
}
|
package/dist/devices/access.js
CHANGED
|
@@ -10,52 +10,20 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { ApiError } from "../errors.js";
|
|
12
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
|
-
import {
|
|
13
|
+
import { DeviceProviderSelection } from "./device-provider-selection.js";
|
|
14
14
|
import { deviceNotFound } from "./errors.js";
|
|
15
15
|
/**
|
|
16
|
-
* The provider
|
|
17
|
-
*
|
|
18
|
-
* migrated, spec §4.2 item 13); before that, the current cloud provider (its first use creates
|
|
19
|
-
* them there), else the one recorded at creation. The same rule as `SandboxService`'s use.
|
|
16
|
+
* The device's provider is off in its org or not installed, or the device has none (503). Its
|
|
17
|
+
* files and instance are kept: nothing is demoted, recreated or moved to another provider.
|
|
20
18
|
*/
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (holdsResources(f))
|
|
25
|
-
return f.instanceProvider;
|
|
26
|
-
return current ?? f.provider;
|
|
27
|
-
}
|
|
28
|
-
/** It has files or an instance at some provider (a file system, even a lost one, or a handle). */
|
|
29
|
-
export const holdsResources = (f) => f.fsStatus !== null && (f.fsStatus !== "none" || f.hasInstance);
|
|
30
|
-
/**
|
|
31
|
-
* For replacing a default (which one is the person's default): it holds healthy files or an
|
|
32
|
-
* instance, or an instance row is under way (`creating`, `running`, `suspended`: a first use may
|
|
33
|
-
* be creating the instance before any file system or handle is recorded). Lost files count as
|
|
34
|
-
* none here, unlike {@link holdsResources}, which decides the provider.
|
|
35
|
-
*/
|
|
36
|
-
export const inUseForDefault = (f) => f.fsStatus === "ready" ||
|
|
37
|
-
f.hasInstance ||
|
|
38
|
-
(f.status !== null && f.status !== "none" && f.status !== "destroyed");
|
|
39
|
-
/**
|
|
40
|
-
* The provider a former default belongs to (its label and the provider whose switch back restores
|
|
41
|
-
* it): the one holding its resources once it holds any, else the one it was demoted from (the
|
|
42
|
-
* marker). A former default demoted while empty and used afterwards keeps a stale marker; its
|
|
43
|
-
* resources decide. null for a device that is not a former default.
|
|
44
|
-
*/
|
|
45
|
-
export function demotedProvider(marker, f) {
|
|
46
|
-
if (marker === null)
|
|
47
|
-
return null;
|
|
48
|
-
return (holdsResources(f) ? f.instanceProvider : null) ?? marker;
|
|
49
|
-
}
|
|
19
|
+
export const deviceUnavailable = (provider) => new ApiError("device.unavailable", provider === null
|
|
20
|
+
? "This device has no provider; delete it and create a new one"
|
|
21
|
+
: `This device's provider ${provider} is off in this organization or not installed; its files are kept, and the device works again once an org admin switches the provider back on`);
|
|
50
22
|
/**
|
|
51
|
-
* The device's
|
|
52
|
-
*
|
|
23
|
+
* The device's instance row names another provider than the device's own (503): never written by
|
|
24
|
+
* this kernel (a device is bound to its provider for life), so nothing is taken over.
|
|
53
25
|
*/
|
|
54
|
-
export const
|
|
55
|
-
? "No cloud sandbox is available in this deployment; ask the super admin to enable a sandbox plugin"
|
|
56
|
-
: isInternalProvider(provider)
|
|
57
|
-
? `This device runs on a connected machine (${provider}), which this deployment does not serve`
|
|
58
|
-
: `This device is kept by the sandbox provider ${provider}, which is not the current provider; it can be used again once ${provider} is the deployment's sandbox provider`);
|
|
26
|
+
export const deviceInstanceForeign = (provider, instanceProvider) => new ApiError("device.unavailable", `This device's provider is ${provider}, but its instance was made by ${instanceProvider}; it cannot be used as it is: delete it and create a new one`);
|
|
59
27
|
/**
|
|
60
28
|
* Who may use a device (spec §4.2 item 12): in phase 1 only the owner of a personal
|
|
61
29
|
* device. Anyone else gets `device.not_found`, never `forbidden`, so ids cannot be
|
|
@@ -63,22 +31,25 @@ export const deviceUnavailable = (provider) => new ApiError("device.unavailable"
|
|
|
63
31
|
*/
|
|
64
32
|
let DeviceAccess = class DeviceAccess {
|
|
65
33
|
db;
|
|
66
|
-
|
|
67
|
-
constructor(db,
|
|
34
|
+
selection;
|
|
35
|
+
constructor(db, selection) {
|
|
68
36
|
this.db = db;
|
|
69
|
-
this.
|
|
37
|
+
this.selection = selection;
|
|
70
38
|
}
|
|
71
39
|
/**
|
|
72
40
|
* The device if `accountId` may use it in `orgId` now: `device.not_found` when it is
|
|
73
|
-
* missing, deleted, in another org or someone else's; `device.unavailable` when
|
|
74
|
-
* provider
|
|
75
|
-
*
|
|
41
|
+
* missing, deleted, in another org or someone else's; `device.unavailable` when it has no
|
|
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
|
+
* `@local` not registered), or its instance row names another provider (never written by this
|
|
45
|
+
* kernel). A local device is usable while `@local` is registered: whether its machine is online
|
|
46
|
+
* is the relay's concern, not access.
|
|
76
47
|
*/
|
|
77
48
|
async usable(orgId, accountId, deviceId) {
|
|
78
49
|
const row = await this.db
|
|
79
50
|
.selectFrom("devices as e")
|
|
80
51
|
.leftJoin("device_instances as i", "i.device_id", "e.id")
|
|
81
|
-
.select(["e.id", "e.provider", "i.provider as instance_provider"
|
|
52
|
+
.select(["e.id", "e.provider", "i.provider as instance_provider"])
|
|
82
53
|
.where("e.id", "=", deviceId)
|
|
83
54
|
.where("e.org_id", "=", orgId)
|
|
84
55
|
.where("e.owner_kind", "=", "personal")
|
|
@@ -87,20 +58,13 @@ let DeviceAccess = class DeviceAccess {
|
|
|
87
58
|
.executeTakeFirst();
|
|
88
59
|
if (!row)
|
|
89
60
|
throw deviceNotFound();
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
61
|
+
const provider = row.provider;
|
|
62
|
+
if (provider === null)
|
|
63
|
+
throw deviceUnavailable(null);
|
|
64
|
+
if (row.instance_provider !== null && row.instance_provider !== provider) {
|
|
65
|
+
throw deviceInstanceForeign(provider, row.instance_provider);
|
|
95
66
|
}
|
|
96
|
-
|
|
97
|
-
const provider = deviceProvider({
|
|
98
|
-
provider: row.provider,
|
|
99
|
-
instanceProvider: row.instance_provider,
|
|
100
|
-
fsStatus: row.fs_status,
|
|
101
|
-
hasInstance: row.handle !== null,
|
|
102
|
-
}, current);
|
|
103
|
-
if (current === undefined || provider !== current)
|
|
67
|
+
if (!(await this.selection.isOnInOrg(orgId, provider)))
|
|
104
68
|
throw deviceUnavailable(provider);
|
|
105
69
|
return { id: row.id, provider };
|
|
106
70
|
}
|
|
@@ -108,6 +72,6 @@ let DeviceAccess = class DeviceAccess {
|
|
|
108
72
|
DeviceAccess = __decorate([
|
|
109
73
|
Injectable(),
|
|
110
74
|
__param(0, Inject(KernelDb)),
|
|
111
|
-
__param(1, Inject(
|
|
75
|
+
__param(1, Inject(DeviceProviderSelection))
|
|
112
76
|
], DeviceAccess);
|
|
113
77
|
export { DeviceAccess };
|
|
@@ -5,13 +5,13 @@ 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 { SandboxProviderRegistryModule } from "../sandbox/providers.module.js";
|
|
9
8
|
import { DeviceAccess } from "./access.js";
|
|
9
|
+
import { DeviceProviderSelectionModule } from "./device-provider-selection.module.js";
|
|
10
10
|
let DeviceAccessModule = class DeviceAccessModule {
|
|
11
11
|
};
|
|
12
12
|
DeviceAccessModule = __decorate([
|
|
13
13
|
Module({
|
|
14
|
-
imports: [
|
|
14
|
+
imports: [DeviceProviderSelectionModule],
|
|
15
15
|
providers: [DeviceAccess],
|
|
16
16
|
exports: [DeviceAccess],
|
|
17
17
|
})
|