@capybara-hq/kernel 0.1.0-rc.6 → 0.1.0-rc.7
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 +27 -3
- package/dist/admin/admin.controller.d.ts +8 -72
- package/dist/admin/admin.controller.js +21 -46
- package/dist/admin/admin.schemas.d.ts +57 -0
- package/dist/admin/admin.schemas.js +50 -0
- package/dist/admin/extensions.controller.d.ts +10 -0
- package/dist/admin/extensions.controller.js +18 -0
- package/dist/admin/extensions.schemas.d.ts +7 -0
- package/dist/admin/extensions.schemas.js +10 -0
- package/dist/admin/limit-defaults.d.ts +20 -0
- package/dist/admin/limit-defaults.js +10 -0
- package/dist/agents/agent-profile.service.d.ts +7 -5
- package/dist/agents/agent-profile.service.js +14 -9
- package/dist/agents/agents.controller.d.ts +7 -287
- package/dist/agents/agents.controller.js +7 -67
- package/dist/agents/agents.schemas.d.ts +389 -0
- package/dist/agents/agents.schemas.js +126 -0
- package/dist/agents/agents.service.d.ts +13 -5
- package/dist/agents/agents.service.js +67 -13
- package/dist/agents/definition.d.ts +47 -19
- package/dist/agents/definition.js +119 -38
- package/dist/agents/from-template.d.ts +2 -2
- package/dist/agents/from-template.js +76 -45
- package/dist/agents/from-template.service.d.ts +12 -0
- package/dist/agents/from-template.service.js +20 -3
- package/dist/agents/models.controller.d.ts +1 -2
- package/dist/agents/models.controller.js +1 -1
- package/dist/agents/org-templates.d.ts +13 -3
- package/dist/agents/org-templates.js +69 -28
- package/dist/agents/pending-connector-requests.d.ts +2 -0
- package/dist/agents/pending-connector-requests.js +1 -1
- package/dist/agents/pending-connectors.controller.d.ts +1 -1
- package/dist/agents/pending-connectors.controller.js +2 -2
- package/dist/agents/pending-connectors.service.d.ts +2 -2
- package/dist/agents/pending-connectors.service.js +19 -19
- package/dist/agents/profile.d.ts +18 -0
- package/dist/agents/profile.js +5 -1
- package/dist/agents/templates.controller.d.ts +8 -17
- package/dist/agents/templates.controller.js +13 -31
- package/dist/agents/templates.schemas.d.ts +20 -0
- package/dist/agents/templates.schemas.js +45 -0
- package/dist/background/background.controller.js +3 -2
- package/dist/background/background.schemas.d.ts +10 -0
- package/dist/background/background.schemas.js +16 -0
- package/dist/background/tasks.service.d.ts +1 -1
- package/dist/background/tasks.service.js +7 -2
- package/dist/catalog/admin-catalog.controller.d.ts +4 -57
- package/dist/catalog/admin-catalog.controller.js +8 -45
- package/dist/catalog/admin-catalog.schemas.d.ts +72 -0
- package/dist/catalog/admin-catalog.schemas.js +92 -0
- package/dist/catalog/catalog-content.d.ts +12 -2
- package/dist/catalog/catalog-scope.service.js +8 -2
- package/dist/catalog/catalog.service.d.ts +2 -0
- package/dist/catalog/catalog.service.js +3 -0
- package/dist/catalog/component-scope.controller.d.ts +3 -65
- package/dist/catalog/component-scope.controller.js +3 -56
- package/dist/catalog/component-scope.schemas.d.ts +114 -0
- package/dist/catalog/component-scope.schemas.js +97 -0
- package/dist/catalog/component-scope.service.d.ts +28 -4
- package/dist/catalog/component-scope.service.js +55 -3
- package/dist/catalog/component-state.d.ts +9 -2
- package/dist/catalog/component-state.js +22 -13
- package/dist/catalog/marketplaces.controller.d.ts +5 -35
- package/dist/catalog/marketplaces.controller.js +6 -34
- package/dist/catalog/marketplaces.schemas.d.ts +48 -0
- package/dist/catalog/marketplaces.schemas.js +53 -0
- package/dist/catalog/marketplaces.service.d.ts +15 -1
- package/dist/catalog/marketplaces.service.js +22 -1
- package/dist/catalog/org-catalog.controller.d.ts +6 -62
- package/dist/catalog/org-catalog.controller.js +12 -66
- package/dist/catalog/org-catalog.schemas.d.ts +79 -0
- package/dist/catalog/org-catalog.schemas.js +82 -0
- package/dist/catalog/org-catalog.service.d.ts +9 -2
- package/dist/catalog/org-catalog.service.js +38 -5
- package/dist/catalog/org-extension.controller.d.ts +1 -12
- package/dist/catalog/org-extension.controller.js +1 -10
- package/dist/catalog/org-extension.schemas.d.ts +15 -0
- package/dist/catalog/org-extension.schemas.js +22 -0
- package/dist/catalog/org-plugin-uploads.controller.d.ts +2 -19
- package/dist/catalog/org-plugin-uploads.controller.js +15 -28
- package/dist/catalog/org-plugin-uploads.schemas.d.ts +20 -0
- package/dist/catalog/org-plugin-uploads.schemas.js +32 -0
- package/dist/catalog/owned-items.d.ts +6 -2
- package/dist/catalog/owned-items.js +16 -4
- package/dist/catalog/platform-components.d.ts +2 -0
- package/dist/catalog/platform-components.js +2 -0
- package/dist/catalog/plugin-import.js +1 -0
- package/dist/catalog/plugin-install.js +1 -1
- package/dist/catalog/requests.service.d.ts +2 -1
- package/dist/catalog/requests.service.js +6 -2
- package/dist/channels/channels.schemas.d.ts +33 -0
- package/dist/channels/channels.schemas.js +34 -0
- package/dist/channels/connections.controller.d.ts +2 -29
- package/dist/channels/connections.controller.js +1 -23
- package/dist/channels/connections.service.d.ts +8 -2
- package/dist/channels/connections.service.js +23 -5
- package/dist/channels/inbound.js +4 -0
- package/dist/conversations/conversations.controller.d.ts +16 -37
- package/dist/conversations/conversations.controller.js +16 -56
- package/dist/conversations/conversations.schemas.d.ts +52 -0
- package/dist/conversations/conversations.schemas.js +79 -0
- package/dist/conversations/conversations.service.d.ts +9 -1
- package/dist/conversations/conversations.service.js +23 -18
- package/dist/conversations/events.d.ts +80 -6
- package/dist/conversations/events.js +60 -5
- package/dist/conversations/message-context.d.ts +28 -0
- package/dist/conversations/message-context.js +56 -0
- package/dist/conversations/queue.d.ts +2 -1
- package/dist/conversations/queue.js +11 -2
- package/dist/db/kernel-schema.d.ts +20 -0
- package/dist/environments/environments.schemas.d.ts +3 -0
- package/dist/environments/environments.schemas.js +14 -0
- package/dist/environments/environments.service.d.ts +16 -4
- package/dist/environments/environments.service.js +58 -13
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +3 -0
- package/dist/evals/evals.schemas.d.ts +110 -0
- package/dist/evals/evals.schemas.js +107 -0
- package/dist/evals/reconstruct.js +18 -11
- package/dist/evals/recorded-tools.d.ts +2 -1
- package/dist/evals/recorded-tools.js +11 -3
- package/dist/evals/run-replay.d.ts +8 -1
- package/dist/evals/run-replay.js +13 -0
- package/dist/evals/runs.controller.d.ts +2 -57
- package/dist/evals/runs.controller.js +1 -42
- package/dist/evals/runs.service.d.ts +6 -6
- package/dist/evals/runs.service.js +32 -18
- package/dist/evals/sets.controller.d.ts +2 -28
- package/dist/evals/sets.controller.js +1 -31
- package/dist/evals/sets.service.d.ts +7 -7
- package/dist/evals/sets.service.js +23 -17
- package/dist/evals/snapshot.d.ts +3 -2
- package/dist/evals/snapshot.js +17 -4
- package/dist/extensions/admin-ops.d.ts +5 -3
- package/dist/extensions/admin-ops.js +17 -12
- package/dist/extensions/deployment-config.d.ts +16 -1
- package/dist/extensions/deployment-config.js +83 -0
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +33 -2
- package/dist/extensions/host.js +107 -1
- package/dist/extensions/installs.d.ts +5 -0
- package/dist/extensions/installs.js +12 -0
- package/dist/extensions/org-config.d.ts +17 -2
- package/dist/extensions/org-config.js +23 -4
- package/dist/extensions/point-defaults.controller.d.ts +2 -8
- package/dist/extensions/point-defaults.controller.js +1 -3
- package/dist/extensions/point-defaults.d.ts +3 -1
- package/dist/extensions/point-defaults.js +4 -2
- package/dist/extensions/point-defaults.schemas.d.ts +9 -0
- package/dist/extensions/point-defaults.schemas.js +14 -0
- package/dist/extensions/unavailable.d.ts +49 -0
- package/dist/extensions/unavailable.js +113 -0
- package/dist/files/previewers.controller.js +2 -3
- package/dist/files/previewers.d.ts +1 -1
- package/dist/files/previewers.js +4 -4
- package/dist/files/previewers.schemas.d.ts +10 -0
- package/dist/files/previewers.schemas.js +9 -0
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +43 -4
- package/dist/identity/accounts.js +74 -6
- package/dist/identity/auth.guard.js +10 -1
- package/dist/identity/cookies.d.ts +6 -0
- package/dist/identity/cookies.js +14 -0
- package/dist/identity/identity.module.js +3 -0
- package/dist/identity/initial-passwords.controller.d.ts +22 -0
- package/dist/identity/initial-passwords.controller.js +49 -0
- package/dist/identity/initial-passwords.d.ts +61 -0
- package/dist/identity/initial-passwords.job.d.ts +16 -0
- package/dist/identity/initial-passwords.job.js +46 -0
- package/dist/identity/initial-passwords.js +159 -0
- package/dist/identity/me.controller.d.ts +14 -0
- package/dist/identity/me.controller.js +39 -1
- package/dist/identity/principal.d.ts +8 -0
- package/dist/identity/principal.js +8 -0
- package/dist/identity/settings.d.ts +3 -1
- package/dist/identity/settings.js +6 -4
- package/dist/inbox/inbox.schemas.d.ts +8 -0
- package/dist/inbox/inbox.schemas.js +11 -0
- package/dist/inbox/platform-inbox.controller.d.ts +1 -1
- package/dist/inbox/platform-inbox.controller.js +2 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -0
- package/dist/lifecycle/kernel-lifecycle.js +4 -0
- package/dist/models/enablement.d.ts +2 -0
- package/dist/models/enablement.js +1 -0
- package/dist/models/org-models.schemas.d.ts +8 -0
- package/dist/models/org-models.schemas.js +22 -0
- package/dist/models/prices.d.ts +3 -1
- package/dist/models/prices.js +7 -5
- package/dist/models/purposes.d.ts +12 -2
- package/dist/models/purposes.js +22 -8
- package/dist/orgs/orgs.controller.d.ts +2 -5
- package/dist/orgs/orgs.controller.js +3 -6
- package/dist/orgs/orgs.schemas.d.ts +8 -0
- package/dist/orgs/orgs.schemas.js +16 -0
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +6 -4
- package/dist/orgs/settings.service.d.ts +9 -1
- package/dist/orgs/settings.service.js +20 -5
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/errors.d.ts +21 -4
- package/dist/platform/errors.js +45 -6
- package/dist/platform/exclusions.d.ts +2 -3
- package/dist/platform/exclusions.js +68 -849
- package/dist/platform/method.js +1 -1
- package/dist/platform/operation.d.ts +82 -5
- package/dist/platform/operation.js +62 -7
- package/dist/platform/ops/accounts.ops.d.ts +32 -0
- package/dist/platform/ops/accounts.ops.js +291 -0
- package/dist/platform/ops/admin.ops.d.ts +36 -0
- package/dist/platform/ops/admin.ops.js +389 -0
- package/dist/platform/ops/agent-skills.ops.d.ts +24 -0
- package/dist/platform/ops/agent-skills.ops.js +226 -0
- package/dist/platform/ops/agent-templates.ops.d.ts +4 -1
- package/dist/platform/ops/agent-templates.ops.js +194 -14
- package/dist/platform/ops/agents.ops.d.ts +19 -1
- package/dist/platform/ops/agents.ops.js +481 -58
- package/dist/platform/ops/approvals.ops.d.ts +30 -0
- package/dist/platform/ops/approvals.ops.js +116 -0
- package/dist/platform/ops/background.ops.d.ts +14 -0
- package/dist/platform/ops/background.ops.js +134 -0
- package/dist/platform/ops/catalog-admin.ops.d.ts +74 -0
- package/dist/platform/ops/catalog-admin.ops.js +587 -0
- package/dist/platform/ops/channels.ops.d.ts +16 -0
- package/dist/platform/ops/channels.ops.js +195 -0
- package/dist/platform/ops/components.ops.d.ts +46 -0
- package/dist/platform/ops/components.ops.js +853 -0
- package/dist/platform/ops/connectors.ops.d.ts +4 -2
- package/dist/platform/ops/connectors.ops.js +68 -6
- package/dist/platform/ops/conversations.ops.d.ts +30 -0
- package/dist/platform/ops/conversations.ops.js +470 -0
- package/dist/platform/ops/environments.ops.d.ts +26 -0
- package/dist/platform/ops/environments.ops.js +289 -0
- package/dist/platform/ops/errors.d.ts +10 -5
- package/dist/platform/ops/errors.js +19 -11
- package/dist/platform/ops/evals.ops.d.ts +28 -0
- package/dist/platform/ops/evals.ops.js +783 -0
- package/dist/platform/ops/extensions-admin.ops.d.ts +25 -0
- package/dist/platform/ops/extensions-admin.ops.js +344 -0
- package/dist/platform/ops/extensions.ops.d.ts +7 -1
- package/dist/platform/ops/extensions.ops.js +248 -17
- package/dist/platform/ops/inbox.ops.d.ts +25 -0
- package/dist/platform/ops/inbox.ops.js +378 -0
- package/dist/platform/ops/marketplaces.ops.d.ts +7 -1
- package/dist/platform/ops/marketplaces.ops.js +326 -17
- package/dist/platform/ops/models.ops.d.ts +25 -0
- package/dist/platform/ops/models.ops.js +232 -0
- package/dist/platform/ops/org-plugins.ops.d.ts +29 -0
- package/dist/platform/ops/org-plugins.ops.js +329 -0
- package/dist/platform/ops/org-settings.ops.d.ts +16 -0
- package/dist/platform/ops/org-settings.ops.js +102 -0
- package/dist/platform/ops/orgs.ops.d.ts +28 -0
- package/dist/platform/ops/orgs.ops.js +295 -0
- package/dist/platform/ops/other-orgs.d.ts +20 -0
- package/dist/platform/ops/other-orgs.js +72 -0
- package/dist/platform/ops/platform.ops.d.ts +4 -4
- package/dist/platform/ops/platform.ops.js +23 -24
- package/dist/platform/ops/plugins.ops.d.ts +10 -8
- package/dist/platform/ops/plugins.ops.js +176 -77
- package/dist/platform/ops/previewers.ops.d.ts +14 -0
- package/dist/platform/ops/previewers.ops.js +109 -0
- package/dist/platform/ops/requests.ops.js +57 -19
- package/dist/platform/ops/skills.ops.d.ts +5 -1
- package/dist/platform/ops/skills.ops.js +129 -11
- package/dist/platform/ops/unavailable.d.ts +23 -0
- package/dist/platform/ops/unavailable.js +111 -0
- package/dist/platform/parity.d.ts +33 -0
- package/dist/platform/parity.js +272 -0
- package/dist/platform/platform-ops.module.d.ts +32 -0
- package/dist/platform/platform-ops.module.js +78 -11
- package/dist/platform/route-schemas.d.ts +18 -0
- package/dist/platform/route-schemas.js +60 -0
- package/dist/roles/worker.module.js +2 -0
- package/dist/runtime/context/build.d.ts +2 -0
- package/dist/runtime/context/build.js +28 -2
- package/dist/runtime/context/compaction.js +10 -1
- package/dist/runtime/context/run-context.d.ts +65 -0
- package/dist/runtime/context/run-context.js +215 -0
- package/dist/runtime/model-call.js +2 -1
- package/dist/runtime/providers.js +8 -1
- package/dist/runtime/run-context.service.d.ts +65 -0
- package/dist/runtime/run-context.service.js +220 -0
- package/dist/runtime/run-worker.d.ts +5 -0
- package/dist/runtime/run-worker.js +31 -6
- package/dist/runtime/runtime.module.js +2 -0
- package/dist/runtime/subagents/definition.d.ts +15 -15
- package/dist/runtime/subagents/definition.js +46 -115
- package/dist/skills/changes.controller.js +2 -1
- package/dist/skills/changes.service.d.ts +1 -1
- package/dist/skills/changes.service.js +4 -4
- package/dist/skills/invocable.controller.d.ts +1 -1
- package/dist/skills/invocable.controller.js +2 -2
- package/dist/skills/invoke.d.ts +2 -2
- package/dist/skills/invoke.js +8 -1
- package/dist/skills/skills.controller.d.ts +4 -13
- package/dist/skills/skills.controller.js +8 -24
- package/dist/skills/skills.schemas.d.ts +48 -0
- package/dist/skills/skills.schemas.js +61 -0
- package/dist/skills/skills.service.d.ts +11 -1
- package/dist/skills/skills.service.js +37 -14
- package/dist/time-zone.d.ts +5 -0
- package/dist/time-zone.js +19 -0
- package/dist/tools/approvals.controller.js +2 -3
- package/dist/tools/approvals.schemas.d.ts +21 -0
- package/dist/tools/approvals.schemas.js +15 -0
- package/dist/tools/builtin-names.d.ts +10 -8
- package/dist/tools/builtin-names.js +16 -11
- package/dist/tools/builtins/builtin-tools.d.ts +3 -1
- package/dist/tools/builtins/builtin-tools.js +15 -3
- package/dist/tools/builtins/current-time.d.ts +26 -0
- package/dist/tools/builtins/current-time.js +99 -0
- package/dist/tools/builtins/platform.d.ts +19 -2
- package/dist/tools/builtins/platform.js +105 -16
- package/dist/tools/connectors.controller.d.ts +1 -2
- package/dist/tools/connectors.controller.js +1 -4
- package/dist/tools/connectors.schemas.d.ts +12 -0
- package/dist/tools/connectors.schemas.js +19 -0
- package/dist/tools/connectors.service.d.ts +5 -2
- package/dist/tools/connectors.service.js +7 -5
- package/dist/tools/org-tool-switches.d.ts +16 -2
- package/dist/tools/org-tool-switches.js +26 -9
- package/dist/tools/pipeline.js +3 -1
- package/dist/tools/registry.d.ts +48 -51
- package/dist/tools/registry.js +222 -233
- package/package.json +3 -3
- package/src/migrations/0090_initial_passwords.sql +27 -0
- package/src/migrations/0091_account_time_zone.sql +4 -0
- package/src/migrations/0092_tools_default_on.sql +27 -0
- package/dist/platform/redact-orgs.d.ts +0 -7
- package/dist/platform/redact-orgs.js +0 -52
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { EnvironmentsService } from "../../environments/environments.service.js";
|
|
3
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
4
|
+
import { PlatformOperations } from "../registry.js";
|
|
5
|
+
/**
|
|
6
|
+
* Environment operations of the `Platform` tool (environments design, phase 1): a person's own
|
|
7
|
+
* cloud environments. Phase 1 has personal environments only, visible to their owner alone, so
|
|
8
|
+
* these are `personal` writes. A cloud environment carries no credentials or device connection;
|
|
9
|
+
* deleting one and wiping its files are `personal` writes that are never remembered.
|
|
10
|
+
*/
|
|
11
|
+
export declare class EnvironmentsOperations implements OnModuleInit {
|
|
12
|
+
private readonly registry;
|
|
13
|
+
private readonly environments;
|
|
14
|
+
private readonly kdb;
|
|
15
|
+
constructor(registry: PlatformOperations, environments: EnvironmentsService, kdb: KernelDb);
|
|
16
|
+
/**
|
|
17
|
+
* Whether `id` is the environment the run works in: the one its root conversation is bound to
|
|
18
|
+
* (sub-agents use the root's). Deleting or wiping it would pull the sandbox from under the run.
|
|
19
|
+
*/
|
|
20
|
+
private isRunsEnvironment;
|
|
21
|
+
/** The precheck of a destructive write: never the run's own environment, then the service's. */
|
|
22
|
+
private precheckDestructive;
|
|
23
|
+
/** The environment's name for a card; its id when it cannot be read. */
|
|
24
|
+
private label;
|
|
25
|
+
onModuleInit(): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { EnvironmentNameBody, EnvironmentParams } from "../../environments/dto.js";
|
|
13
|
+
import { EnvironmentsService, } from "../../environments/environments.service.js";
|
|
14
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
15
|
+
import { rootConversationOf } from "../../runtime/subagents/child.js";
|
|
16
|
+
import { defineOperation } from "../operation.js";
|
|
17
|
+
import { PlatformOperations } from "../registry.js";
|
|
18
|
+
import { precheckBy, viaAgent } from "./errors.js";
|
|
19
|
+
import { named, orElse } from "./summary.js";
|
|
20
|
+
const EnvironmentId = z.object({ environmentId: EnvironmentParams.shape.id }).strict();
|
|
21
|
+
const Name = z.object({ name: EnvironmentNameBody.shape.name }).strict();
|
|
22
|
+
/** The default environment has no name; the web shows it as 「个人环境」 / "Personal". */
|
|
23
|
+
const labelOf = (e) => e.name ?? "Personal";
|
|
24
|
+
/** A row's state: why it cannot be used now, else whether its instance runs. */
|
|
25
|
+
function stateOf(e) {
|
|
26
|
+
if (!e.available) {
|
|
27
|
+
return {
|
|
28
|
+
state: "unavailable",
|
|
29
|
+
reason: "Its sandbox provider is no longer the deployment's current one.",
|
|
30
|
+
next: "Ask an org admin; use another environment meanwhile.",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (e.filesLost) {
|
|
34
|
+
return {
|
|
35
|
+
state: "files_lost",
|
|
36
|
+
reason: "Its file system is gone at the provider.",
|
|
37
|
+
next: "Wipe its files with environments.reset-files to use it again.",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return { state: e.instance?.status ?? "ready" };
|
|
41
|
+
}
|
|
42
|
+
const row = (e) => ({
|
|
43
|
+
id: e.id,
|
|
44
|
+
name: labelOf(e),
|
|
45
|
+
...stateOf(e),
|
|
46
|
+
isDefault: e.isDefault,
|
|
47
|
+
provider: e.provider,
|
|
48
|
+
lastUsedAt: e.instance?.lastUsedAt ?? null,
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Environment operations of the `Platform` tool (environments design, phase 1): a person's own
|
|
52
|
+
* cloud environments. Phase 1 has personal environments only, visible to their owner alone, so
|
|
53
|
+
* these are `personal` writes. A cloud environment carries no credentials or device connection;
|
|
54
|
+
* deleting one and wiping its files are `personal` writes that are never remembered.
|
|
55
|
+
*/
|
|
56
|
+
let EnvironmentsOperations = class EnvironmentsOperations {
|
|
57
|
+
registry;
|
|
58
|
+
environments;
|
|
59
|
+
kdb;
|
|
60
|
+
constructor(registry, environments, kdb) {
|
|
61
|
+
this.registry = registry;
|
|
62
|
+
this.environments = environments;
|
|
63
|
+
this.kdb = kdb;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Whether `id` is the environment the run works in: the one its root conversation is bound to
|
|
67
|
+
* (sub-agents use the root's). Deleting or wiping it would pull the sandbox from under the run.
|
|
68
|
+
*/
|
|
69
|
+
async isRunsEnvironment(id, ctx) {
|
|
70
|
+
const root = await rootConversationOf(this.kdb.db, ctx.conversationId);
|
|
71
|
+
const row = await this.kdb.db
|
|
72
|
+
.selectFrom("conversations")
|
|
73
|
+
.select("environment_id")
|
|
74
|
+
.where("id", "=", root)
|
|
75
|
+
.where("org_id", "=", ctx.orgId)
|
|
76
|
+
.executeTakeFirst();
|
|
77
|
+
return row?.environment_id === id;
|
|
78
|
+
}
|
|
79
|
+
/** The precheck of a destructive write: never the run's own environment, then the service's. */
|
|
80
|
+
async precheckDestructive(id, ctx, verb, read) {
|
|
81
|
+
if (await this.isRunsEnvironment(id, ctx)) {
|
|
82
|
+
return {
|
|
83
|
+
ok: false,
|
|
84
|
+
code: "environment.current",
|
|
85
|
+
message: `The environment you are running in cannot be ${verb} from here.`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return precheckBy(read);
|
|
89
|
+
}
|
|
90
|
+
/** The environment's name for a card; its id when it cannot be read. */
|
|
91
|
+
label(ctx, id) {
|
|
92
|
+
return orElse(async () => named(labelOf(await this.environments.get(ctx.orgId, ctx.actorAccountId, id))), id);
|
|
93
|
+
}
|
|
94
|
+
onModuleInit() {
|
|
95
|
+
this.registry.register([
|
|
96
|
+
defineOperation({
|
|
97
|
+
id: "environments.list",
|
|
98
|
+
description: "List your own cloud environments in this org: one compact row each (name, state, whether it is the default, provider, last use), plus the default and last used ids and whether new cloud environments can be made. The default environment is shown as Personal.",
|
|
99
|
+
input: z.object({}).strict(),
|
|
100
|
+
example: {},
|
|
101
|
+
authz: { orgAction: "agents.use" },
|
|
102
|
+
mirrors: ["GET /api/v1/orgs/:orgId/environments"],
|
|
103
|
+
confirm: "read",
|
|
104
|
+
run: async (_input, ctx) => {
|
|
105
|
+
const l = await this.environments.list(ctx.orgId, ctx.actorAccountId);
|
|
106
|
+
return {
|
|
107
|
+
items: l.items.map(row),
|
|
108
|
+
defaultId: l.defaultId,
|
|
109
|
+
lastUsedId: l.lastUsedId,
|
|
110
|
+
cloudAvailable: l.cloudAvailable,
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
defineOperation({
|
|
115
|
+
id: "environments.get",
|
|
116
|
+
description: "Read one of your environments with its provider, state, instance, limits and creation time. Takes the id from environments.list.",
|
|
117
|
+
input: EnvironmentId,
|
|
118
|
+
example: { environmentId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20" },
|
|
119
|
+
authz: { orgAction: "agents.use" },
|
|
120
|
+
mirrors: ["GET /api/v1/orgs/:orgId/environments/:id"],
|
|
121
|
+
renames: { environmentId: "id" },
|
|
122
|
+
confirm: "read",
|
|
123
|
+
errors: [
|
|
124
|
+
{
|
|
125
|
+
code: "environment.not_found",
|
|
126
|
+
next: "Check the id with environments.list: you only see your own environments.",
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
run: async (input, ctx) => {
|
|
130
|
+
const e = await this.environments.get(ctx.orgId, ctx.actorAccountId, input.environmentId);
|
|
131
|
+
return { environment: { ...e, name: labelOf(e), ...stateOf(e) } };
|
|
132
|
+
},
|
|
133
|
+
}),
|
|
134
|
+
defineOperation({
|
|
135
|
+
id: "environments.create",
|
|
136
|
+
description: "Create a personal cloud environment with a name (1-64 characters, unique among yours, case-insensitive). It is ready at once; its instance and files are made on first use. It needs a sandbox provider and is limited per person.",
|
|
137
|
+
input: Name,
|
|
138
|
+
example: { name: "Data analysis" },
|
|
139
|
+
authz: { orgAction: "agents.use" },
|
|
140
|
+
mirrors: ["POST /api/v1/orgs/:orgId/environments"],
|
|
141
|
+
confirm: "personal",
|
|
142
|
+
errors: [
|
|
143
|
+
{
|
|
144
|
+
code: "environment.name_taken",
|
|
145
|
+
next: "You have an environment with this name: pick another name, or read yours with environments.list.",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
code: "environment.limit_reached",
|
|
149
|
+
next: "You are at the limit: delete an environment you no longer need with environments.delete, or use an existing one.",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
code: "environment.current",
|
|
153
|
+
next: "This conversation works in it: ask the person to wipe it on the web, or wipe a different one.",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
code: "environment.unavailable",
|
|
157
|
+
next: {
|
|
158
|
+
superAdmin: "No sandbox provider is current: set one up in the admin console under extensions, then call again.",
|
|
159
|
+
orgAdmin: "No sandbox provider is set up; ask the super admin.",
|
|
160
|
+
member: "No sandbox provider is set up in this deployment; ask an org admin.",
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
precheck: (i, ctx) => precheckBy(() => this.environments.checkCreate(ctx.orgId, ctx.actorAccountId, i.name)),
|
|
165
|
+
summary: (i) => ({
|
|
166
|
+
zh: `新建个人云环境「${named(i.name)}」`,
|
|
167
|
+
en: `Create personal cloud environment "${named(i.name)}"`,
|
|
168
|
+
}),
|
|
169
|
+
run: async (input, ctx) => {
|
|
170
|
+
const e = await this.environments.create(ctx.orgId, ctx.actorAccountId, { name: input.name }, undefined, viaAgent("environments.create", ctx));
|
|
171
|
+
return { environment: row(e) };
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
defineOperation({
|
|
175
|
+
id: "environments.delete",
|
|
176
|
+
description: "Delete one of your environments, the default one included: its instance and ALL its files are destroyed after the response and cannot be recovered. Conversations bound to it keep pointing at it and their sandbox tools then fail. The person confirms every delete; it is never remembered. The environment this conversation works in cannot be deleted. Takes the id from environments.list.",
|
|
177
|
+
input: EnvironmentId,
|
|
178
|
+
example: { environmentId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20" },
|
|
179
|
+
authz: { orgAction: "agents.use" },
|
|
180
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/environments/:id"],
|
|
181
|
+
renames: { environmentId: "id" },
|
|
182
|
+
confirm: "personal",
|
|
183
|
+
// destructive: asked every time and never remembered
|
|
184
|
+
rememberable: false,
|
|
185
|
+
errors: [
|
|
186
|
+
{
|
|
187
|
+
code: "environment.not_found",
|
|
188
|
+
next: "Check the id with environments.list: you only see your own environments.",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
code: "environment.current",
|
|
192
|
+
next: "This conversation works in it: ask the person to delete it on the web, or delete a different one.",
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
precheck: (i, ctx) => this.precheckDestructive(i.environmentId, ctx, "deleted", () => this.environments.get(ctx.orgId, ctx.actorAccountId, i.environmentId)),
|
|
196
|
+
summary: async (i, ctx) => {
|
|
197
|
+
const n = await this.label(ctx, i.environmentId);
|
|
198
|
+
const c = await orElse(() => this.environments.boundConversations(ctx.orgId, ctx.actorAccountId, i.environmentId), 0);
|
|
199
|
+
return {
|
|
200
|
+
zh: `删除环境「${n}」:其中所有文件将被销毁且无法恢复;使用它的 ${c} 个对话将失去沙箱(沙箱工具会失败)`,
|
|
201
|
+
en: `Delete environment "${n}": all its files are destroyed and cannot be recovered; the ${c} conversations using it lose their sandbox (their sandbox tools fail)`,
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
run: async (input, ctx) => {
|
|
205
|
+
await this.environments.remove(ctx.orgId, ctx.actorAccountId, input.environmentId, undefined, viaAgent("environments.delete", ctx));
|
|
206
|
+
return { id: input.environmentId, deleted: true };
|
|
207
|
+
},
|
|
208
|
+
}),
|
|
209
|
+
defineOperation({
|
|
210
|
+
id: "environments.reset-files",
|
|
211
|
+
description: "Wipe one of your environments' files so it starts empty: ALL its files are destroyed (after running commands finish) and cannot be recovered; the next use creates a fresh workspace. Use it when an environment reports its files are lost. The person confirms every reset; it is never remembered. The environment this conversation works in cannot be wiped. Takes the id from environments.list.",
|
|
212
|
+
input: EnvironmentId,
|
|
213
|
+
example: { environmentId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20" },
|
|
214
|
+
authz: { orgAction: "agents.use" },
|
|
215
|
+
mirrors: ["POST /api/v1/orgs/:orgId/environments/:id/files/reset"],
|
|
216
|
+
renames: { environmentId: "id" },
|
|
217
|
+
confirm: "personal",
|
|
218
|
+
rememberable: false,
|
|
219
|
+
errors: [
|
|
220
|
+
{
|
|
221
|
+
code: "environment.not_found",
|
|
222
|
+
next: "Check the id with environments.list: you only see your own environments.",
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
code: "environment.current",
|
|
226
|
+
next: "This conversation works in it: ask the person to wipe it on the web, or wipe a different one.",
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
code: "environment.unavailable",
|
|
230
|
+
next: {
|
|
231
|
+
orgAdmin: "Its sandbox provider is no longer the current one: use another environment, or ask the super admin about the provider.",
|
|
232
|
+
member: "Its sandbox provider is no longer the current one: use another environment, or ask an org admin.",
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
precheck: (i, ctx) => this.precheckDestructive(i.environmentId, ctx, "wiped", () => this.environments.checkReset(ctx.orgId, ctx.actorAccountId, i.environmentId)),
|
|
237
|
+
summary: async (i, ctx) => {
|
|
238
|
+
const n = await this.label(ctx, i.environmentId);
|
|
239
|
+
return {
|
|
240
|
+
zh: `清空环境「${n}」的文件:所有文件将被销毁且无法恢复`,
|
|
241
|
+
en: `Wipe the files of environment "${n}": all files are destroyed and cannot be recovered`,
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
run: async (input, ctx) => {
|
|
245
|
+
await this.environments.resetFiles(ctx.orgId, ctx.actorAccountId, input.environmentId, undefined, viaAgent("environments.reset-files", ctx));
|
|
246
|
+
return { id: input.environmentId, reset: true };
|
|
247
|
+
},
|
|
248
|
+
}),
|
|
249
|
+
defineOperation({
|
|
250
|
+
id: "environments.rename",
|
|
251
|
+
description: "Rename one of your environments, the default one included (it then has a name). The new name is 1-64 characters and unique among yours, case-insensitive. Takes the id from environments.list.",
|
|
252
|
+
input: EnvironmentId.extend({ name: EnvironmentNameBody.shape.name }).strict(),
|
|
253
|
+
example: { environmentId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20", name: "Reports" },
|
|
254
|
+
authz: { orgAction: "agents.use" },
|
|
255
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId/environments/:id"],
|
|
256
|
+
renames: { environmentId: "id" },
|
|
257
|
+
confirm: "personal",
|
|
258
|
+
errors: [
|
|
259
|
+
{
|
|
260
|
+
code: "environment.not_found",
|
|
261
|
+
next: "Check the id with environments.list: you only see your own environments.",
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
code: "environment.name_taken",
|
|
265
|
+
next: "You have an environment with this name: pick another name.",
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
precheck: (i, ctx) => precheckBy(() => this.environments.checkRename(ctx.orgId, ctx.actorAccountId, i.environmentId, i.name)),
|
|
269
|
+
summary: async (i, ctx) => {
|
|
270
|
+
const from = await orElse(async () => named(labelOf(await this.environments.get(ctx.orgId, ctx.actorAccountId, i.environmentId))), i.environmentId);
|
|
271
|
+
return {
|
|
272
|
+
zh: `将环境「${from}」重命名为「${named(i.name)}」`,
|
|
273
|
+
en: `Rename environment "${from}" to "${named(i.name)}"`,
|
|
274
|
+
};
|
|
275
|
+
},
|
|
276
|
+
run: async (input, ctx) => ({
|
|
277
|
+
environment: row(await this.environments.rename(ctx.orgId, ctx.actorAccountId, input.environmentId, input.name, undefined, viaAgent("environments.rename", ctx))),
|
|
278
|
+
}),
|
|
279
|
+
}),
|
|
280
|
+
]);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
EnvironmentsOperations = __decorate([
|
|
284
|
+
Injectable(),
|
|
285
|
+
__param(0, Inject(PlatformOperations)),
|
|
286
|
+
__param(1, Inject(EnvironmentsService)),
|
|
287
|
+
__param(2, Inject(KernelDb))
|
|
288
|
+
], EnvironmentsOperations);
|
|
289
|
+
export { EnvironmentsOperations };
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import type { PrecheckResult } from "../operation.js";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* An operation's precheck from a service read that throws the write's own refusal: the
|
|
4
|
+
* {@link ApiError} it throws becomes the failure (its code and message), a return passes. Anything
|
|
5
|
+
* else propagates, and the tool skips the precheck.
|
|
6
|
+
*/
|
|
7
|
+
export declare function precheckBy(read: () => Promise<unknown>): Promise<PrecheckResult>;
|
|
8
|
+
/**
|
|
9
|
+
* The audit detail of a write made through the tool (spec §6): who, where and which operation. The
|
|
10
|
+
* keys are distinct from any business field (`agentConversationId`, not `conversationId`), so
|
|
11
|
+
* merging it into a write's own detail never overwrites the conversation or run the write is about.
|
|
5
12
|
*/
|
|
6
|
-
export declare function asToolError<T>(call: () => Promise<T>): Promise<T>;
|
|
7
|
-
/** The audit detail of a write made through the tool (spec §6): who, where and which operation. */
|
|
8
13
|
export declare function viaAgent(operation: string, ctx: {
|
|
9
14
|
conversationId: string;
|
|
10
15
|
runId: string | null;
|
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
2
1
|
import { ApiError } from "../../errors.js";
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* An operation's precheck from a service read that throws the write's own refusal: the
|
|
4
|
+
* {@link ApiError} it throws becomes the failure (its code and message), a return passes. Anything
|
|
5
|
+
* else propagates, and the tool skips the precheck.
|
|
7
6
|
*/
|
|
8
|
-
export async function
|
|
7
|
+
export async function precheckBy(read) {
|
|
9
8
|
try {
|
|
10
|
-
|
|
9
|
+
await read();
|
|
10
|
+
return { ok: true };
|
|
11
11
|
}
|
|
12
12
|
catch (e) {
|
|
13
|
-
if (e instanceof ApiError)
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
if (e instanceof ApiError)
|
|
14
|
+
return { ok: false, code: e.code, message: e.message };
|
|
16
15
|
throw e;
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* The audit detail of a write made through the tool (spec §6): who, where and which operation. The
|
|
20
|
+
* keys are distinct from any business field (`agentConversationId`, not `conversationId`), so
|
|
21
|
+
* merging it into a write's own detail never overwrites the conversation or run the write is about.
|
|
22
|
+
*/
|
|
20
23
|
export function viaAgent(operation, ctx) {
|
|
21
|
-
return {
|
|
24
|
+
return {
|
|
25
|
+
via: "agent",
|
|
26
|
+
operation,
|
|
27
|
+
agentConversationId: ctx.conversationId,
|
|
28
|
+
agentRunId: ctx.runId,
|
|
29
|
+
};
|
|
22
30
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { EvalRunsService } from "../../evals/runs.service.js";
|
|
3
|
+
import { EvalSetsService } from "../../evals/sets.service.js";
|
|
4
|
+
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
5
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
6
|
+
import { PlatformOperations } from "../registry.js";
|
|
7
|
+
/**
|
|
8
|
+
* Eval operations of the `Platform` tool (spec §14): eval sets, their cases, runs and results,
|
|
9
|
+
* all for org admins (`evals.manage`), like the routes. Cases and full results are copies of
|
|
10
|
+
* conversation content: reading one is audited (`trajectory.viewed`, `eval.results_viewed`) with
|
|
11
|
+
* the operation that did it.
|
|
12
|
+
*/
|
|
13
|
+
export declare class EvalsOperations implements OnModuleInit {
|
|
14
|
+
private readonly registry;
|
|
15
|
+
private readonly sets;
|
|
16
|
+
private readonly runs;
|
|
17
|
+
private readonly kdb;
|
|
18
|
+
private readonly config;
|
|
19
|
+
constructor(registry: PlatformOperations, sets: EvalSetsService, runs: EvalRunsService, kdb: KernelDb, config: Pick<KernelConfigService, "get">);
|
|
20
|
+
/** The position of a case in its set, from 1 (0 when it is not there): the case's label. */
|
|
21
|
+
private caseNo;
|
|
22
|
+
/** The set's eval-set row of the org, or the refusal the routes give. */
|
|
23
|
+
private setCheck;
|
|
24
|
+
/** Whether the set may take one more case (the configured maximum). */
|
|
25
|
+
private roomCheck;
|
|
26
|
+
private setName;
|
|
27
|
+
onModuleInit(): void;
|
|
28
|
+
}
|